Compare commits
281 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 02b0bf622c | |||
| 39d1b338b7 | |||
| b27b458557 | |||
| f642e2f5a8 | |||
| 50ded155ed | |||
| eab453413e | |||
| 2304a17dd0 | |||
| be4837cccf | |||
| 2235103efe | |||
| 466eb49c55 | |||
| a842880123 | |||
| 897ff4c9ff | |||
| d93866146a | |||
| 1d0c0088d6 | |||
| 99a8ab3a21 | |||
| c944c7bca0 | |||
| 39330bc6f2 | |||
| 300d3cd825 | |||
| 8adbe38617 | |||
| dd5ef0c8a4 | |||
| 27b368c2fb | |||
| 107ffb0997 | |||
| 36186578f8 | |||
| 52b21f8b88 | |||
| b9912ad80f | |||
| 666464dd06 | |||
| c0f4f7af5f | |||
| 102fe92c3a | |||
| 87118049ab | |||
| 7e55719983 | |||
| 9b66e07c06 | |||
| f657012d8e | |||
| 1f674b9c34 | |||
| 6192270040 | |||
| 2574c74e6b | |||
| 0ea3993103 | |||
| 2cd1038468 | |||
| c7c2d54183 | |||
| c57b031156 | |||
| 6d4430da13 | |||
| 7d37a58e6e | |||
| a3f3608f76 | |||
| f13609c02b | |||
| d2b2e1f978 | |||
| 825cd1fcb7 | |||
| 48a6dae50c | |||
| 911b17df7e | |||
| 308c58e761 | |||
| 6c69828f1a | |||
| 194f7b6275 | |||
| 132b8b071f | |||
| f563d5d873 | |||
| 668c9f9457 | |||
| 8cd1106818 | |||
| 4858ccd812 | |||
| 64e637dbfb | |||
| 419d3500bd | |||
| 0d9bfa966d | |||
| acba5c670f | |||
| 73a68911e8 | |||
| b1531139c0 | |||
| 7dd00c75a9 | |||
| 4284d163d8 | |||
| ba5aad0296 | |||
| ea60cfb507 | |||
| b6052620be | |||
| 0df83632d0 | |||
| b8f7d8f554 | |||
| 01d0203de6 | |||
| 97daebdf83 | |||
| acfa708332 | |||
| 3e22d31c42 | |||
| d2d1ae723d | |||
| e34c9856ec | |||
| ff9305144b | |||
| 12c4e66cc2 | |||
| 1c9239bade | |||
| 80ae6ecac8 | |||
| 90f1df105b | |||
| a409ee696c | |||
| 81049d2765 | |||
| a81793f695 | |||
| 9916fb946d | |||
| 4442ca0250 | |||
| b324173d8e | |||
| b5635f50f8 | |||
| a8e7caa0b3 | |||
| de14d61835 | |||
| 9acb542689 | |||
| af56b6d2c6 | |||
| aced59ea7a | |||
| 42c5c496dc | |||
| cd367fe5bd | |||
| 160cf24642 | |||
| 8656222be3 | |||
| e1b4bd32c9 | |||
| fcc43e24c5 | |||
| 12f8e44cb4 | |||
| 4793b072ae | |||
| 4190a9e03d | |||
| 9602773021 | |||
| d6f8fb8917 | |||
| fba31bfc8d | |||
| 8b4f353182 | |||
| a3a1396e6c | |||
| fd4138c7cc | |||
| 476e22b368 | |||
| 40ed4c9c9a | |||
| 13c061323c | |||
| 16bfaf8910 | |||
| 4bbb31b0c6 | |||
| cbe6480da6 | |||
| 63538088d2 | |||
| 0d3da65ca7 | |||
| d65615da16 | |||
| d7b1e66f88 | |||
| 912fec458f | |||
| 5c9242a156 | |||
| 15954c9576 | |||
| 52e6dafad1 | |||
| 5842d70094 | |||
| 9a6c0b6c9a | |||
| 8db058871f | |||
| 26dc50930b | |||
| 6468af6eb7 | |||
| e8fcf2884a | |||
| 8926c22eae | |||
| 46dd11fab0 | |||
| 2b3cc6bcdf | |||
| 2de37a4733 | |||
| 10dfd8aa5c | |||
| 1291de4387 | |||
| d7bb3b3576 | |||
| 24c5ad1d06 | |||
| dcbfeebc37 | |||
| bcaa2a493e | |||
| f2f8d64d44 | |||
| 7ac7d7c360 | |||
| 9995f9cca8 | |||
| 10ab688207 | |||
| f333a88aaf | |||
| aead8aae71 | |||
| 3226efab1e | |||
| 036049a13f | |||
| 5ebf73779c | |||
| bfe8391cc9 | |||
| 4904c356f7 | |||
| 71ebf01b0b | |||
| 1a72f7c90a | |||
| 6224479d76 | |||
| e18c3fc43d | |||
| 276284cd39 | |||
| 8c183a6f0c | |||
| 8c6ccd1cfe | |||
| 47f07bbc51 | |||
| c053d87a6c | |||
| 9f78790e14 | |||
| 148d327d9f | |||
| 53a9b527e4 | |||
| 3ef2f76705 | |||
| 95346118f0 | |||
| a963c3316c | |||
| 0c12e6c4bc | |||
| 65c08667cc | |||
| 0386d14638 | |||
| ee837712aa | |||
| 27e95ee343 | |||
| 25b6c594bd | |||
| d6eee92645 | |||
| d60404ff0a | |||
| e1f584984f | |||
| 368d6ad93b | |||
| 615ea8d7b0 | |||
| 5ab2a215b5 | |||
| db282cb533 | |||
| 5e93076243 | |||
| c4153f5f6e | |||
| 2c95782687 | |||
| 3cd13863cb | |||
| bdb0c05220 | |||
| afd93047c1 | |||
| 54a734e049 | |||
| 9ec72212cf | |||
| 5cba72934f | |||
| cf3a09a241 | |||
| 4ae23f4eff | |||
| de3ea6b850 | |||
| dbd6c59a0b | |||
| 03c26b587a | |||
| 7ae87f9949 | |||
| 81d0353144 | |||
| 780dbd769c | |||
| 695e53a714 | |||
| f813ed68df | |||
| a7b3c496d0 | |||
| 65813b7170 | |||
| fc672978d8 | |||
| 90a3be7803 | |||
| 8dc5e9f281 | |||
| 6654030bd3 | |||
| 4f2e333d6c | |||
| 617cf73c5e | |||
| 42fa3955d8 | |||
| 4509d9f37b | |||
| 91e484e514 | |||
| b733f4e199 | |||
| 31ecf917af | |||
| f954a7f834 | |||
| 42e2301a8e | |||
| 35845ea49b | |||
| c4e3eb238f | |||
| e98d01d7e9 | |||
| b6f71fffbf | |||
| 38469119ad | |||
| e56d572585 | |||
| 58011c5a00 | |||
| 42a4a599dc | |||
| 5e05b3d11f | |||
| a06aa2f1fa | |||
| 3b9a76eec8 | |||
| 06ba95ed97 | |||
| be83cafe0d | |||
| 0007a1af56 | |||
| a7dbfd9781 | |||
| 2ed6427773 | |||
| dd1c5a2d0c | |||
| b4946f5f1e | |||
| 4c248c5ee5 | |||
| b58f354c41 | |||
| dcebc61b13 | |||
| c48a998750 | |||
| b281eecfee | |||
| 40ca249b8a | |||
| 077bfb2e7d | |||
| fadc0e9f71 | |||
| 3dda420c3a | |||
| 618d9180cd | |||
| 032f0bb2c5 | |||
| f92822fff0 | |||
| 7426c5ad1f | |||
| 45cac5a084 | |||
| 5ef5ddcbae | |||
| 59bfa66dad | |||
| 711bbf0a21 | |||
| 2291d758ac | |||
| dc7277a2a4 | |||
| 2f19f5ce0b | |||
| cf0902b6ed | |||
| eebffc0d13 | |||
| 60dd22a7f6 | |||
| dc9112dfdd | |||
| f45a76af13 | |||
| 47ac90ea6b | |||
| f05641a8b9 | |||
| cfcdd6acad | |||
| a3249ab19b | |||
| 7af363fec4 | |||
| 4ba5689b25 | |||
| 838e53a91e | |||
| 6cdbc3e8e0 | |||
| 30cc5fbb44 | |||
| b935760d64 | |||
| 2932488d00 | |||
| 612f305c3a | |||
| 61a9a0ce8d | |||
| 159f80cce3 | |||
| a35d835f31 | |||
| 3418afcc66 | |||
| d5ececfa87 | |||
| aea43781ea | |||
| 707b021c88 | |||
| 5e07075977 | |||
| 85072e9db9 | |||
| 2fcc77772f | |||
| 8b4785eb36 | |||
| ef0f33351a | |||
| c5f05de082 | |||
| 2c5f0ea904 | |||
| f45516d359 | |||
| be6cff7b89 | |||
| 6fde0f186f |
@@ -0,0 +1,28 @@
|
||||
Standard: c++20
|
||||
BasedOnStyle: LLVM
|
||||
IndentWidth: 2
|
||||
ColumnLimit: 0
|
||||
AccessModifierOffset: -2
|
||||
NamespaceIndentation: None
|
||||
BreakBeforeBraces: Custom
|
||||
PointerAlignment: Left
|
||||
IndentCaseLabels: true
|
||||
PackConstructorInitializers: CurrentLine
|
||||
BraceWrapping:
|
||||
AfterEnum: false
|
||||
AfterStruct: false
|
||||
AfterClass: false
|
||||
SplitEmptyFunction: false
|
||||
AfterControlStatement: false
|
||||
AfterNamespace: false
|
||||
AfterFunction: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: false
|
||||
AlignTrailingComments: false
|
||||
AlignAfterOpenBracket: DontAlign
|
||||
AlignOperands: DontAlign
|
||||
AlignEscapedNewlines: Left
|
||||
@@ -29,7 +29,6 @@ system/patch-bb/.metadata-cache.json
|
||||
# repository
|
||||
files
|
||||
make_release.py
|
||||
notes
|
||||
old-khyller
|
||||
old-newserv
|
||||
release
|
||||
|
||||
+84
-62
@@ -40,68 +40,78 @@ find_package(resource_file QUIET)
|
||||
# Executable definition
|
||||
|
||||
add_executable(newserv
|
||||
src/CatSession.cc
|
||||
src/Channel.cc
|
||||
src/ChatCommands.cc
|
||||
src/Client.cc
|
||||
src/Compression.cc
|
||||
src/DNSServer.cc
|
||||
src/Episode3/AssistServer.cc
|
||||
src/Episode3/BattleRecord.cc
|
||||
src/Episode3/Card.cc
|
||||
src/Episode3/CardSpecial.cc
|
||||
src/Episode3/DataIndex.cc
|
||||
src/Episode3/DeckState.cc
|
||||
src/Episode3/MapState.cc
|
||||
src/Episode3/PlayerState.cc
|
||||
src/Episode3/PlayerStateSubordinates.cc
|
||||
src/Episode3/RulerServer.cc
|
||||
src/Episode3/Server.cc
|
||||
src/Episode3/Tournament.cc
|
||||
src/FileContentsCache.cc
|
||||
src/FunctionCompiler.cc
|
||||
src/GSLArchive.cc
|
||||
src/IPFrameInfo.cc
|
||||
src/IPStackSimulator.cc
|
||||
src/Items.cc
|
||||
src/LevelTable.cc
|
||||
src/License.cc
|
||||
src/Lobby.cc
|
||||
src/Loggers.cc
|
||||
src/Main.cc
|
||||
src/Map.cc
|
||||
src/Menu.cc
|
||||
src/NetworkAddresses.cc
|
||||
src/PatchFileIndex.cc
|
||||
src/Player.cc
|
||||
src/ProxyCommands.cc
|
||||
src/ProxyServer.cc
|
||||
src/PSOEncryption.cc
|
||||
src/PSOGCObjectGraph.cc
|
||||
src/PSOProtocol.cc
|
||||
src/Quest.cc
|
||||
src/RareItemSet.cc
|
||||
src/ReceiveCommands.cc
|
||||
src/ReceiveSubcommands.cc
|
||||
src/ReplaySession.cc
|
||||
src/SendCommands.cc
|
||||
src/Server.cc
|
||||
src/ServerShell.cc
|
||||
src/ServerState.cc
|
||||
src/Shell.cc
|
||||
src/StaticGameData.cc
|
||||
src/Text.cc
|
||||
src/Version.cc
|
||||
src/BattleParamsIndex.cc
|
||||
src/BMLArchive.cc
|
||||
src/CatSession.cc
|
||||
src/Channel.cc
|
||||
src/ChatCommands.cc
|
||||
src/Client.cc
|
||||
src/CommonItemSet.cc
|
||||
src/Compression.cc
|
||||
src/DNSServer.cc
|
||||
src/EnemyType.cc
|
||||
src/Episode3/AssistServer.cc
|
||||
src/Episode3/BattleRecord.cc
|
||||
src/Episode3/Card.cc
|
||||
src/Episode3/CardSpecial.cc
|
||||
src/Episode3/DataIndexes.cc
|
||||
src/Episode3/DeckState.cc
|
||||
src/Episode3/MapState.cc
|
||||
src/Episode3/PlayerState.cc
|
||||
src/Episode3/PlayerStateSubordinates.cc
|
||||
src/Episode3/RulerServer.cc
|
||||
src/Episode3/Server.cc
|
||||
src/Episode3/Tournament.cc
|
||||
src/FileContentsCache.cc
|
||||
src/FunctionCompiler.cc
|
||||
src/GSLArchive.cc
|
||||
src/IPFrameInfo.cc
|
||||
src/IPStackSimulator.cc
|
||||
src/ItemCreator.cc
|
||||
src/ItemData.cc
|
||||
src/ItemParameterTable.cc
|
||||
src/Items.cc
|
||||
src/LevelTable.cc
|
||||
src/License.cc
|
||||
src/Lobby.cc
|
||||
src/Loggers.cc
|
||||
src/Main.cc
|
||||
src/Map.cc
|
||||
src/Menu.cc
|
||||
src/NetworkAddresses.cc
|
||||
src/PatchFileIndex.cc
|
||||
src/Player.cc
|
||||
src/Product.cc
|
||||
src/ProxyCommands.cc
|
||||
src/ProxyServer.cc
|
||||
src/PSOEncryption.cc
|
||||
src/PSOGCObjectGraph.cc
|
||||
src/PSOProtocol.cc
|
||||
src/Quest.cc
|
||||
src/QuestScript.cc
|
||||
src/RareItemSet.cc
|
||||
src/ReceiveCommands.cc
|
||||
src/ReceiveSubcommands.cc
|
||||
src/ReplaySession.cc
|
||||
src/SaveFileFormats.cc
|
||||
src/SendCommands.cc
|
||||
src/Server.cc
|
||||
src/ServerShell.cc
|
||||
src/ServerState.cc
|
||||
src/Shell.cc
|
||||
src/StaticGameData.cc
|
||||
src/Text.cc
|
||||
src/Version.cc
|
||||
)
|
||||
target_include_directories(newserv PUBLIC ${LIBEVENT_INCLUDE_DIR})
|
||||
target_link_libraries(newserv phosg ${LIBEVENT_LIBRARIES} pthread)
|
||||
|
||||
if(resource_file_FOUND)
|
||||
target_compile_definitions(newserv PUBLIC HAVE_RESOURCE_FILE)
|
||||
target_link_libraries(newserv resource_file)
|
||||
message(STATUS "libresource_file found; enabling patch support")
|
||||
target_compile_definitions(newserv PUBLIC HAVE_RESOURCE_FILE)
|
||||
target_link_libraries(newserv resource_file)
|
||||
message(STATUS "libresource_file found; enabling patch support")
|
||||
else()
|
||||
message(WARNING "libresource_file not found; disabling patch support")
|
||||
message(WARNING "libresource_file not found; disabling patch support")
|
||||
endif()
|
||||
|
||||
|
||||
@@ -113,18 +123,30 @@ enable_testing()
|
||||
file(GLOB TestCases ${CMAKE_SOURCE_DIR}/tests/*.test.txt)
|
||||
|
||||
foreach(TestCase IN ITEMS ${TestCases})
|
||||
add_test(
|
||||
NAME ${TestCase}
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
COMMAND ${CMAKE_BINARY_DIR}/newserv replay-log ${TestCase} --config=${CMAKE_SOURCE_DIR}/tests/config.json --require-password=password --require-access-key=111111111111)
|
||||
add_test(
|
||||
NAME ${TestCase}
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
COMMAND ${CMAKE_BINARY_DIR}/newserv replay-log ${TestCase} --config=${CMAKE_SOURCE_DIR}/tests/config.json --require-password=11111111 --require-access-key=111111111111)
|
||||
endforeach()
|
||||
|
||||
add_test(
|
||||
NAME compression
|
||||
NAME "compression-prs"
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/test-compression.sh ${CMAKE_BINARY_DIR}/newserv)
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/tests/test-compression.sh prs ${CMAKE_BINARY_DIR}/newserv)
|
||||
add_test(
|
||||
NAME "compression-bc0"
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/tests/test-compression.sh bc0 ${CMAKE_BINARY_DIR}/newserv)
|
||||
|
||||
add_test(
|
||||
NAME "decode-vms"
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/tests/test-decode-vms.sh ${CMAKE_BINARY_DIR}/newserv)
|
||||
|
||||
add_test(
|
||||
NAME "decode-gci"
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/tests/test-decode-gci.sh ${CMAKE_BINARY_DIR}/newserv)
|
||||
|
||||
# Installation configuration
|
||||
|
||||
|
||||
@@ -4,9 +4,30 @@ newserv is a game server and proxy for Phantasy Star Online (PSO).
|
||||
|
||||
This project includes code that was reverse-engineered by the community in ages long past, and has been included in many projects since then. It also includes some game data from Phantasy Star Online itself, which was originally created by Sega.
|
||||
|
||||
* Background
|
||||
* [History](#history)
|
||||
* [Future (and to-do list)](#future)
|
||||
* [Compatibility](#compatibility)
|
||||
* Setup
|
||||
* [Configuration](#configuration)
|
||||
* [Installing quests](#installing-quests)
|
||||
* [Episode 3 features](#episode-3-features)
|
||||
* [Client patch directories for PC and BB](#client-patch-directories)
|
||||
* [Memory patches and DOL files for GC](#memory-patches-and-dol-files)
|
||||
* [Using newserv as a proxy](#using-newserv-as-a-proxy)
|
||||
* [Chat commands](#chat-commands)
|
||||
* How to connect
|
||||
* Connecting local clients
|
||||
* [PSO DC](#pso-dc)
|
||||
* [PSO PC](#pso-pc)
|
||||
* [PSO GC on a real GameCube](#pso-gc-on-a-real-gamecube)
|
||||
* [PSO GC on Dolphin](#pso-gc-on-dolphin)
|
||||
* [Connecting external clients](#connecting-external-clients)
|
||||
* [Non-server features](#non-server-features)
|
||||
|
||||
## History
|
||||
|
||||
The history of this project essentially mirrors my development as a software engineer from the beginning of my hobby until now. If you don't care about the story, skip to the "Compatibility" or "Usage" sections below.
|
||||
The history of this project essentially mirrors my development as a software engineer from the beginning of my hobby until now. If you don't care about the story, skip to the "Compatibility" or "Setup" sections below.
|
||||
|
||||
I originally purchased PSO GC when I heard about PSUL, and wanted to play around with running homebrew on my GameCube. This pathway eventually led to [GCARS-CS](https://github.com/fuzziqersoftware/gcars-cs), but that's another story.
|
||||
|
||||
@@ -29,68 +50,147 @@ newserv is many things - a server, a proxy, an encryption and decryption tool, a
|
||||
With that said, I offer no guarantees on how or when this project will advance. Feel free to submit GitHub issues if you find bugs or have feature requests; I'd like to make the server as stable and complete as possible, but I can't promise that I'll respond to issues in a timely manner. If you feel like contributing to newserv yourself, pull requests are welcome as well.
|
||||
|
||||
Current known issues / missing features / things to do:
|
||||
- Episode 3 battles are implemented but are not well-tested.
|
||||
- Fix behavior when joining a spectator team after the beginning of a battle.
|
||||
- PSOBB is not well-tested and likely will disconnect or misbehave when clients try to use unimplemented features.
|
||||
- Enemy indexes also desync slightly in most games, often in later areas, leading to incorrect EXP values being given for killed enemies.
|
||||
- Fix some edge cases on the BB proxy server (e.g. make sure Change Ship does the right thing, which is not the same as what it should do on V2/V3).
|
||||
- Implement the rest of PSOBB. Major areas of work:
|
||||
- Find any remaining mismatches in enemy IDs / experience
|
||||
- Sale prices for non-rare weapons with specials are computed incorrectly when buying/selling at shops
|
||||
- Replace enemy list, game episode, etc. with quest data when loading a quest
|
||||
- Implement trade window
|
||||
- Fix some edge cases on the BB proxy server (e.g. make sure Change Ship does the right thing, which is not the same as what it should do on other versions).
|
||||
- There is a function that encodes QST files, but there's no corresponding CLI option.
|
||||
- Figure out what controls BML file data segment alignment.
|
||||
- Extension data in inventories is not handled properly.
|
||||
- PSOX is not tested at all.
|
||||
- Memory patches currently are platform-specific but not version-specific. This makes them quite a bit harder to write and use properly.
|
||||
- Find a way to silence audio in RunDOL.s. Some old DOLs don't reset audio systems at load time and it's annoying to hear the crash buzz when the GC hasn't actually crashed.
|
||||
- Implement private and overflow lobbies.
|
||||
- Enforce client-side size limits (e.g. for 60/62 commands) on the server side as well. (For 60/62 specifically, perhaps transform them to 6C/6D if needed.)
|
||||
- Encapsulate BB server-side random state and make replays deterministic.
|
||||
- VMS decoding doesn't work. Complete this reverse-engineering project.
|
||||
- Code style
|
||||
- The internal menu abstraction is ugly and hard to work with. Rewrite it.
|
||||
- Add default values for all commands (like we use for Episode 3 battle commands).
|
||||
- Clean up the way proxy session options are passed to the session from the client object (and add user-settable options for e.g. chat filter, which currently doesn't appear in the menu).
|
||||
- Implement character and inventory replacement for battle and challenge modes.
|
||||
- Implement the C5 (battle/challenge records) command.
|
||||
- Implement choice search.
|
||||
- Episode 3 bugs
|
||||
- Fix behavior when joining a spectator team after the beginning of a battle.
|
||||
- Disconnecting during a match turns you into a COM if there are other humans in the match, even if the match is part of a tournament. This may be incorrect behavior for tournaments.
|
||||
- Disconnecting during a tournament when there are no other humans in the match simply cancels the match (so it can be replayed) instead of forfeiting, which is almost certainly incorrect behavior. (Then again, no one likes losing tournaments to COMs...)
|
||||
- Tournament deck restrictions aren't enforced when populating COMs at tournament start time. This can cause weird behavior if, for example, a COM deck contains assist cards and the tournament rules forbid them.
|
||||
- There is a rare failure mode during battles that causes one of the clients to be disconnected.
|
||||
- Code style
|
||||
- Add default values in all command structures (like we use for Episode 3 battle commands).
|
||||
|
||||
## Compatibility
|
||||
|
||||
newserv supports several versions of PSO. Specifically:
|
||||
| Version | Basic commands | Lobbies | Games | Proxy |
|
||||
|----------------------|----------------|---------------|---------------|---------------|
|
||||
| Dreamcast Trial | Partial (6) | Not supported | Not supported | Not supported |
|
||||
| Dreamcast V1 | Supported (1) | Supported | Supported | Supported |
|
||||
| Dreamcast V2 | Supported (1) | Supported | Supported | Supported |
|
||||
| PC | Supported | Supported | Supported | Supported |
|
||||
| GameCube Ep1&2 Trial | Untested (2) | Untested (2) | Untested (2) | Untested (2) |
|
||||
| GameCube Ep1&2 | Supported | Supported | Supported | Supported |
|
||||
| GameCube Ep1&2 Plus | Supported | Supported | Supported | Supported |
|
||||
| GameCube Ep3 Trial | Supported | Supported | Supported (3) | Supported |
|
||||
| GameCube Ep3 | Supported | Supported | Supported (3) | Supported |
|
||||
| XBOX Ep1&2 | Untested (4) | Untested (4) | Untested (4) | Untested (4) |
|
||||
| Blue Burst | Supported | Supported | Partial (5) | Supported |
|
||||
| Version | Login | Lobbies | Games | Proxy |
|
||||
|----------------|--------------|--------------|--------------|--------------|
|
||||
| DC Trial | Yes (4) | Yes (4) | Yes (4) | No |
|
||||
| DC Prototype | Yes (4) | Yes (4) | Yes (4) | No |
|
||||
| DC V1 | Yes (1) | Yes | Yes | Yes |
|
||||
| DC V2 | Yes (1) | Yes | Yes | Yes |
|
||||
| PC | Yes | Yes | Yes | Yes |
|
||||
| GC Ep1&2 Trial | Untested (2) | Untested (2) | Untested (2) | Untested (2) |
|
||||
| GC Ep1&2 | Yes | Yes | Yes | Yes |
|
||||
| GC Ep1&2 Plus | Yes | Yes | Yes | Yes |
|
||||
| GC Ep3 Trial | Yes | Yes | Partial (5) | Yes |
|
||||
| GC Ep3 | Yes | Yes | Yes | Yes |
|
||||
| XBOX Ep1&2 | Untested (2) | Untested (2) | Untested (2) | Untested (2) |
|
||||
| BB (vanilla) | Yes | Yes | Yes (3) | Yes |
|
||||
| BB (Tethealla) | Yes | Yes | Yes (3) | Yes |
|
||||
|
||||
*Notes:*
|
||||
1. *DC support has only been tested with the US versions of PSO DC. Other versions probably don't work, but will be easy to add. Please submit a GitHub issue if you have a non-US DC version, and can provide a log from a connection attempt.*
|
||||
2. *This version only supports the modem adapter, which Dolphin does not currently emulate, so it's difficult to test.*
|
||||
3. *See the following section about Episode 3 functionality.*
|
||||
4. *newserv's implementation of PSOX is based on disassembly of the client executable; it has never been tested with a real client and most likely doesn't work.*
|
||||
5. *Some basic features are not implemented in Blue Burst games, so the games are not very playable. A lot of work has to be done to get BB games to a playable state.*
|
||||
6. *Support for PSO Dreamcast Trial Edition is very incomplete and probably never will be complete. This is really just exploring a curiosity that sheds some light on early network engineering done by Sega, not an actual attempt at supporting this version of the game.*
|
||||
1. *DC support has only been tested with the US versions of PSO DC. Other versions probably don't work, but will be easy to add support for. Please submit a GitHub issue if you have a non-US DC version, and can provide a log from a connection attempt.*
|
||||
2. *newserv's implementations of these versions are based on disassembly of the client executables and have never been tested.*
|
||||
3. *BB games are mostly playable, but there are still some unimplemented features (for example, some quests that use rare commands may not work). Please submit a GitHub issue if you find something that doesn't work.*
|
||||
4. *Support for PSO Dreamcast Trial Edition and the December 2000 prototype is somewhat incomplete and probably never will be complete. These versions are rather unstable and seem to crash often, but it's not obvious whether it's because they're prototypes or because newserv sends data they can't handle.*
|
||||
5. *Creating a game works and battle setup behaves mostly normally, but starting a battle doesn't work.*
|
||||
|
||||
### Episode 3
|
||||
## Setup
|
||||
|
||||
The following Episode 3 features are well-tested and work normally:
|
||||
### Configuration
|
||||
|
||||
Currently newserv works on macOS, Windows, and Ubuntu Linux. It will likely work on other Linux flavors too.
|
||||
|
||||
There is a fairly recent macOS ARM64 release on the newserv GitHub repository. You may need to install libevent manually even if you use this release (run `brew install libevent`).
|
||||
|
||||
There is a fairly recent Windows release on the newserv GitHub repository also. It's built with Cygwin, and all the necessary DLL files should be included. That said, I've only tested it on my own machine and there is no CI for Windows builds like there is for macOS and Linux, so if it doesn't work for you, please open a GitHub issue to let me know.
|
||||
|
||||
If you're not using a release from the GitHub repository, do this to build newserv:
|
||||
1. If you're on Windows, install Cygwin. While doing so, install the `cmake`, `gcc-core`, `gcc-g++`, `git`, `libevent2.1_7`, `make`, and `zlib` packages. Do the rest of these steps inside a Cygwin shell (not a Windows cmd shell or PowerShell).
|
||||
2. Make sure you have CMake and libevent installed. (On macOS, `brew install cmake libevent`; on most Linuxes, `sudo apt-get install cmake libevent-dev`; on Windows, you already did this in step 1.)
|
||||
3. Build and install phosg (https://github.com/fuzziqersoftware/phosg).
|
||||
4. Optionally, install resource_dasm (https://github.com/fuzziqersoftware/resource_dasm). This will enable newserv to send memory patches and load DOL files on PSO GC clients. PSO GC clients can play PSO normally on newserv without this.
|
||||
5. Run `cmake . && make` in the newserv directory.
|
||||
|
||||
After building newserv or downloading a release, do this to set it up and use it:
|
||||
1. In the system/ directory, make a copy of config.example.json named config.json, and edit it appropriately.
|
||||
2. If you plan to play PSO Blue Burst on newserv, set up the patch directory. See the "Client patch directories" section below.
|
||||
3. Run `./newserv` in the newserv directory. This will start the game server and run the interactive shell. You may need `sudo` if newserv's built-in DNS server is enabled.
|
||||
4. If you set AllowUnregisteredUsers to false in config.json, use the interactive shell to add your license. Run `help` in the shell to see how to do this.
|
||||
5. Set your client's network settings appropriately and start an online game. See the "Connecting local clients" or "Connecting remote clients" section to see how to get your game client to connect.
|
||||
|
||||
To use newserv in other ways (e.g. for translating data), see the end of this document.
|
||||
|
||||
### Installing quests
|
||||
|
||||
newserv automatically finds quests in the system/quests/ directory. To install your own quests, or to use quests you've saved using the proxy's "save files" option, just put them in that directory and name them appropriately.
|
||||
|
||||
Standard quest files should be named like `q###-CATEGORY-VERSION.EXT`, battle quests should be named like `b###-VERSION.EXT`, challenge quests should be named like `c###-VERSION.EXT` for Episode 1 or `d###-VERSION.EXT` for Episode 2, and Episode 3 download quests should be named like `e###-gc3.EXT`. The fields in each filename are:
|
||||
- `###`: quest number (this doesn't really matter; it should just be unique across the PSO version)
|
||||
- `CATEGORY`: ret = Retrieval, ext = Extermination, evt = Events, shp = Shops, vr = VR, twr = Tower, gv1/gv2/gv4 = Government (BB only), dl = Download (these don't appear during online play), 1p = Solo (BB only)
|
||||
- `VERSION`: dn = Dreamcast NTE, d1 = Dreamcast v1, dc = Dreamcast v2, pc = PC, gcn = GameCube Trial Edition, gc = GameCube Episodes 1 & 2, gc3 = Episode 3, xb = Xbox, bb = Blue Burst
|
||||
- `EXT`: file extension (see table below)
|
||||
|
||||
For example, the GameCube version of Lost HEAT SWORD is in two files named `q058-ret-gc.bin` and `q058-ret-gc.dat`. newserv knows these files are quests because they're in the system/quests/ directory, it knows they're for PSO GC because the filenames contain `-gc`, and it puts them in the Retrieval category because the filenames contain `-ret`.
|
||||
|
||||
The type identifiers (`b`, `c`, `d`, `e`, or `q`) and categories are configurable. See QuestCategories in config.example.json for more information on how to make new categories or edit the existing categories.
|
||||
|
||||
There are multiple PSO quest formats out there; newserv supports all of them. It can also decode any known format to standard .bin/.dat format. Specifically:
|
||||
|
||||
| Format | Extension | Supported | Decode action |
|
||||
|------------------|-----------------------|------------|------------------|
|
||||
| Compressed | .bin and .dat | Yes | None (1) |
|
||||
| Compressed Ep3 | .bin or .mnm | Yes (4) | None (1) |
|
||||
| Uncompressed | .bind and .datd | Yes | compress-prs (2) |
|
||||
| Uncompressed Ep3 | .bind or .mnmd | Yes (4) | compress-prs (2) |
|
||||
| VMS (DCv1) | .bin.vms and .dat.vms | Yes | decode-vms |
|
||||
| VMS (DCv2) | .bin.vms and .dat.vms | Decode (3) | decode-vms (3) |
|
||||
| GCI (decrypted) | .bin.gci and .dat.gci | Yes | decode-gci |
|
||||
| GCI (with key) | .bin.gci and .dat.gci | Yes | decode-gci |
|
||||
| GCI (no key) | .bin.gci and .dat.gci | Decode (3) | decode-gci (3) |
|
||||
| GCI (Ep3) | .bin.gci or .mnm.gci | Yes | decode-gci |
|
||||
| DLQ | .bin.dlq and .dat.dlq | Yes | decode-dlq |
|
||||
| DLQ (Ep3) | .bin.dlq or .mnm.dlq | Yes | decode-dlq |
|
||||
| QST (online) | .qst | Yes | decode-qst |
|
||||
| QST (download) | .qst | Yes | decode-qst |
|
||||
|
||||
*Notes:*
|
||||
1. *This is the default format. You can convert these to uncompressed format by running `newserv decompress-prs FILENAME.bin FILENAME.bind` (and similarly for .dat -> .datd)*
|
||||
2. *Similar to (1), to compress an uncompressed quest file: `newserv compress-prs FILENAME.bind FILENAME.bin` (and likewise for .datd -> .dat)*
|
||||
3. *Use the decode action to convert these quests to .bin/.dat format before putting them into the server's quests directory. If you know the encryption seed (serial number), pass it in as a hex string with the `--seed=` option. If you don't know the encryption seed, newserv will find it for you, which will likely take a long time.*
|
||||
4. *Episode 3 online quests don't go in the system/quests directory; they instead go in the system/ep3/maps-free or system/ep3/maps-quest directories. If you want an Episode 3 quest to be available for both online play and for downloading, the file must exist in both system/quests and in one of the map directories in system/ep3.*
|
||||
|
||||
Episode 3 download quests consist only of a .bin file - there is no corresponding .dat file. Episode 3 download quest files may be named with the .mnm extension instead of .bin, since the format is the same as the standard map files (in system/ep3/). These files can be encoded in any of the formats described above, except .qst. There are no encrypted Episode 3 GCI formats because the game doesn't encrypt quests saved to the memory card, unlike Episodes 1&2.
|
||||
|
||||
When newserv indexes the quests during startup, it will warn (but not fail) if any quests are corrupt or in unrecognized formats.
|
||||
|
||||
Quest contents are cached in memory, but if you've changed the contents of the quests directory, you can re-index the quests without restarting the server by running `reload quests` in the interactive shell. The new quests will be available immediately, but any games with quests already in progress will continue using the old versions of the quests until those quests end.
|
||||
|
||||
All quests, including those originally in GCI or DLQ format, are treated as online quests unless their filenames specify the dl category. newserv allows players to download all quests, even those in non-download categories.
|
||||
|
||||
### Episode 3 features
|
||||
|
||||
The following Episode 3 features work well:
|
||||
* CARD battles. Not every combination of abilities has been tested yet, so if you find a feature or card ability that doesn't work like it's supposed to, please make a GitHub issue and describe the situation (the attacking card(s), defending card(s), and ability or condition that didn't work).
|
||||
* Tournaments. (But they don't work like Sega's tournaments did - see below)
|
||||
* Downloading quests.
|
||||
* Creating and joining games.
|
||||
* Trading cards.
|
||||
* Participating in card auctions. (The auction contents must be configured in config.json.)
|
||||
* Tournaments. (See below)
|
||||
|
||||
The following Episode 3 features are implemented, but only partially tested:
|
||||
* CARD battles. If you find a feature or card ability that doesn't work, please make a GitHub issue and describe the situation (including the attacking card(s), defending card(s), and ability that didn't work).
|
||||
* Spectator teams are partially implemented, but are not well-tested. There is a known issue that prevents viewing battles unless you're in the spectator team when the battle begins.
|
||||
* Battle replays sometimes cause the client to crash during the replay. Using the $playrec command is therefore not recommended.
|
||||
The following Episode 3 features are implemented, but are only partially tested:
|
||||
* Spectator teams. There is a known issue that prevents viewing battles unless you're in the spectator team when the battle begins, and spectating clients sometimes crash for an unknown reason.
|
||||
* Battle replays also sometimes cause the client to crash during the replay. Using the $playrec command is therefore not recommended.
|
||||
|
||||
Tournaments work differently than they did on Sega's servers. Tournaments can be created with the `create-tournament` shell command, which enables players to register for them. (Use `help` to see all the arguments - there are many!) The `start-tournament` shell command starts the tournament, but this doesn't schedule any matches. Instead, players who are ready to play their next match can all stand at the rightmost 4-player battle table in the same CARD lobby, and the tournament match will start automatically. (This also means that, for example, not all matches in round 1 must be complete before round 2 can begin - only the matches preceding each individual match must be complete for that match to be playable.)
|
||||
Tournaments work differently than they did on Sega's servers. Tournaments can be created with the `create-tournament` shell command, which enables players to register for them. (Use `help` to see all the arguments - there are many!) The `start-tournament` shell command starts the tournament (and prevents further registrations), but this doesn't schedule any matches. Instead, players who are ready to play their next match can all stand at the rightmost 4-player battle table in the same CARD lobby, and the tournament match will start automatically.
|
||||
|
||||
These tournament semantics mean that there can be multiple matches in the same tournament in play simultaneously, and not all matches in a round must be complete before the next round can begin - only the matches preceding each individual match must be complete for that match to be playable.
|
||||
|
||||
Because newserv gives all players 1000000 meseta, there is no reward for winning a tournament. This may change in the future.
|
||||
|
||||
@@ -102,69 +202,9 @@ Episode 3 state and game data is stored in the system/ep3 directory. The files i
|
||||
* maps-free/ and maps-quest/: Online free battle and quest maps (.mnm/.bin/.mnmd/.bind files). Free battle and quest files have exactly the same format; the only difference between the files in these directories is which section of the menu they will appear in on the client.
|
||||
* 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).
|
||||
|
||||
## Usage
|
||||
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.
|
||||
|
||||
Currently newserv should build on macOS and Ubuntu. It will likely work on other Linux flavors too. It should work on Windows as well, but I haven't tested it recently - the build process could be very manual. Cygwin is likely the easiest Windows environment in which to build newserv.
|
||||
|
||||
There is a fairly recent macOS ARM64 release on the newserv GitHub repository. You may need to install libevent manually even if you use this release (run `brew install libevent`).
|
||||
|
||||
If you're using an older AMD64 Mac, you're running Linux, or you just want to build newserv yourself, here's what you do:
|
||||
1. Make sure you have CMake and libevent installed. (`brew install cmake libevent` on macOS, `sudo apt-get install cmake libevent-dev` on most Linuxes)
|
||||
2. Build and install phosg (https://github.com/fuzziqersoftware/phosg).
|
||||
3. Optionally, install resource_dasm (https://github.com/fuzziqersoftware/resource_dasm). This will enable newserv to send memory patches and load DOL files on PSO GC clients. PSO GC clients can play PSO normally on newserv without this.
|
||||
4. Run `cmake . && make` in the newserv directory.
|
||||
|
||||
After building newserv or downloading a release, do this to set it up and use it:
|
||||
1. In the system/ directory, make a copy of config.example.json named config.json, and edit it appropriately.
|
||||
2. If you plan to play PSO Blue Burst on newserv, set up the patch directory appropriately. See the "Client patch directories" section below.
|
||||
3. Run `./newserv` in the newserv directory. This will start the game server and run the interactive shell. You may need `sudo` if newserv's built-in DNS server is enabled.
|
||||
4. Use the interactive shell to add a license. Run `help` in the shell to see how to do this.
|
||||
5. Set your client's network settings appropriately and start an online game. See the "Connecting local clients" or "Connecting remote clients" section to see how to get your game client to connect.
|
||||
|
||||
To use newserv in other ways (e.g. for translating data), see the end of this document.
|
||||
|
||||
### Installing quests
|
||||
|
||||
newserv automatically finds quests in the system/quests/ directory. To install your own quests, or to use quests you've saved using the proxy's set-save-files option, just put them in that directory and name them appropriately.
|
||||
|
||||
Standard quest files should be named like `q###-CATEGORY-VERSION.EXT`, battle quests should be named like `b###-VERSION.EXT`, challenge quests should be named like `c###-VERSION.EXT`, and Episode 3 download quests should be named like `e###-gc3.EXT`. The fields in each filename are:
|
||||
- `###`: quest number (this doesn't really matter; it should just be unique for the PSO version)
|
||||
- `CATEGORY`: ret = Retrieval, ext = Extermination, evt = Events, shp = Shops, vr = VR, twr = Tower, gov = Government (BB only), dl = Download (these don't appear during online play), 1p = Solo (BB only)
|
||||
- `VERSION`: d1 = Dreamcast v1, dc = Dreamcast v2, pc = PC, gc = GameCube Episodes 1 & 2, gc3 = Episode 3, bb = Blue Burst
|
||||
- `EXT`: file extension (see table below)
|
||||
|
||||
For example, the GameCube version of Lost HEAT SWORD is in two files named `q058-ret-gc.bin` and `q058-ret-gc.dat`. newserv knows these files are quests because they're in the system/quests/ directory, it knows they're for PSO GC because the filenames contain `-gc`, and it puts them in the Retrieval category because the filenames contain `-ret`.
|
||||
|
||||
There are multiple PSO quest formats out there; newserv supports most of them. It can also decode any known format to standard .bin/.dat format. Specifically:
|
||||
|
||||
| Format | Extension | Supported | Decode action |
|
||||
|---------------------------|-----------------------|---------------|------------------|
|
||||
| Compressed | .bin and .dat | Yes | None (1) |
|
||||
| Compressed Ep3 | .bin or .mnm | Yes (4) | None (1) |
|
||||
| Uncompressed | .bind and .datd | Yes | compress-prs (2) |
|
||||
| Uncompressed Ep3 | .bind or .mnmd | Yes (4) | compress-prs (2) |
|
||||
| Unencrypted GCI | .bin.gci and .dat.gci | Yes | decode-gci |
|
||||
| Encrypted GCI with key | .bin.gci and .dat.gci | Yes | decode-gci |
|
||||
| Encrypted GCI without key | .bin.gci and .dat.gci | No | decode-gci (3) |
|
||||
| Ep3 GCI | .bin.gci or .mnm.gci | Download only | decode-gci |
|
||||
| Encrypted DLQ | .bin.dlq and .dat.dlq | Yes | decode-dlq |
|
||||
| Ep3 DLQ | .bin.dlq or .mnm.dlq | Download only | decode-dlq |
|
||||
| Online QST | .qst | Yes | decode-qst |
|
||||
| Download QST | .qst | Yes | decode-qst |
|
||||
|
||||
*Notes:*
|
||||
1. *This is the default format. You can convert these to uncompressed format by running `newserv decompress-prs FILENAME.bin FILENAME.bind` (and similarly for .dat -> .datd)*
|
||||
2. *Similar to (1), to compress an uncompressed quest file: `newserv compress-prs FILENAME.bind FILENAME.bin` (and likewise for .datd -> .dat)*
|
||||
3. *If you know the encryption seed (serial number), pass it in as a hex string with the `--seed=` option. If you don't know the encryption seed, newserv will find it for you, which will likely take a long time.*
|
||||
4. *Episode 3 online quests don't go in the system/quests directory; they instead go in the system/ep3/maps-free or system/ep3/maps-quest directory. If you want an Episode 3 quest to be available for both online play and for downloading, the file must exist in both system/quests and in one of the map directories in system/ep3.*
|
||||
|
||||
Episode 3 download quests consist only of a .bin file - there is no corresponding .dat file. Episode 3 download quest files may be named with the .mnm extension instead of .bin, since the format is the same as the standard map files (in system/ep3/). These files can be encoded in any of the formats described above, except .qst. There are no encrypted Episode 3 GCI formats because the game doesn't encrypt quests saved to the memory card, unlike Episodes 1&2.
|
||||
|
||||
When newserv indexes the quests during startup, it will warn (but not fail) if any quests are corrupt or in unrecognized formats.
|
||||
|
||||
If you've changed the contents of the quests directory, you can re-index the quests without restarting the server by running `reload quests` in the interactive shell. The new quests will be available immediately, but any games with quests already in progress will continue using the old versions of the quests until those quests end.
|
||||
|
||||
All quests, including those originally in GCI or DLQ format, are treated as online quests unless their filenames specify the dl category. newserv allows players to download all quests, even those in non-download categories.
|
||||
Like quests, Episode 3 card definitions, maps, and quests are cached in memory. If you've changed any of these files, you can run `reload ep3` in the interactive shell to make the changes take effect without restarting the server.
|
||||
|
||||
### Client patch directories
|
||||
|
||||
@@ -178,6 +218,8 @@ For BB clients, newserv reads some files out of the patch data to implement game
|
||||
|
||||
Specifically, the patch-bb directory should contain at least the data.gsl file and all map_*.dat files from the version of PSOBB that you want to play on newserv. You can copy these files out of the client's data directory from a clean installation, and put them in system/patch-bb/data.
|
||||
|
||||
Patch directory contents are cached in memory. If you've changed any of these files, you can run `reload patches` in the interactive shell to make the changes take effect without restarting the server.
|
||||
|
||||
### Memory patches and DOL files
|
||||
|
||||
Everything in this section requires resource_dasm to be installed, so newserv can use the PowerPC assembler and disassembler from its libresource_file library. If resource_dasm is not installed, newserv will still build and run, but these features will not be available.
|
||||
@@ -193,6 +235,8 @@ You can put memory patches in the system/ppc directory with filenames like Patch
|
||||
|
||||
You can also put DOL files in the system/dol directory, and they will appear in the Programs menu. Selecting a DOL file there will load the file into the GameCube's memory and run it, just like the old homebrew loaders (PSUL and PSOload) did. For this to work, ReadMemoryWord.s, WriteMemory.s, and RunDOL.s must be present in the system/ppc directory. This has been tested on Dolphin but not on a real GameCube, so results may vary.
|
||||
|
||||
Like other kinds of data, functions and DOL files are cached in memory. If you've changed any of these files, you can run `reload functions` or `reload dol-files` in the interactive shell to make the changes take effect without restarting the server.
|
||||
|
||||
I mainly built the DOL loading functionality for documentation purposes. By now, there are many better ways to load homebrew code on an unmodified GameCube, but to my knowledge there isn't another open-source implementation of this method in existence.
|
||||
|
||||
### Using newserv as a proxy
|
||||
@@ -205,9 +249,30 @@ To use the proxy for PSO BB, set the ProxyDestination-BB entry in config.json. I
|
||||
|
||||
When you're on PSO DC, PC, or GC and are connected to a remote server through newserv's proxy, choosing the Change Ship or Change Block action from the lobby counter will send you back to newserv's main menu instead of the remote server's ship or block select menu. You can go back to the server you were just on by choosing it from the proxy server menu again.
|
||||
|
||||
There are many options available when starting a proxy session. All options are off by default unless otherwise noted. The options are:
|
||||
* **Chat commands**: enables chat commands in the proxy session (on by default).
|
||||
* **Chat filter**: enables escape sequences in chat messages and info board (on by default).
|
||||
* **Player notifications**: shows a message when any player joins or leaves the game or lobby you're in.
|
||||
* **Block pings**: blocks automatic pings sent by the client, and responds to ping commands from the server automatically. This works around a bug in Sylverant's login server.
|
||||
* **Infinite HP**: automatically heals you whenever you get hit. An attack that kills you in one hit will still kill you, however.
|
||||
* **Infinite TP**: automatically restores your TP whenever you use any technique.
|
||||
* **Switch assist**: attempts to unlock doors that require two players in a one-player game.
|
||||
* **Infinite Meseta** (Episode 3 only): gives you 1,000,000 Meseta, regardless of the value sent by the remote server.
|
||||
* **Block events**: disables holiday events sent by the remote server.
|
||||
* **Block patches**: prevents any B2 (patch) commands from reaching the client.
|
||||
* **Save files**: saves copies of several kinds of files when they're sent by the remote server. The files are written to the current directory (which is usually the directory containing the system/ directory). These kinds of files can be saved:
|
||||
* Online quests and download quests (saved as .bin/.dat files)
|
||||
* GBA games (saved as .gba files)
|
||||
* Patches (saved as .bin files, and disassembled into PowerPC assembly if newserv is built with patch support)
|
||||
* Player data from BB sessions (saved as .bin files, which are not the same format as .nsc files)
|
||||
* Episode 3 online quests and maps (saved as .mnmd files)
|
||||
* Episode 3 download quests (saved as .mnm files)
|
||||
* Episode 3 card definitions (saved as .mnr files)
|
||||
* Episode 3 media updates (saved as .gvm, .bml, or .bin files)
|
||||
|
||||
The remote server will probably try to assign you a Guild Card number that doesn't match the one you have on newserv. On PSO DC, PC and GC, the proxy server rewrites the commands in transit to make it look like the remote server assigned you the same Guild Card number as you have on newserv, but if the remote server has some external integrations (e.g. forum or Discord bots), they will use the Guild Card number that the remote server believes it has assigned to you. The number assigned by the remote server is shown to you when you first connect to the remote server, and you can retrieve it in lobbies or during games with the $li command.
|
||||
|
||||
Some chat commands (see below) have the same basic function on the proxy server but have different effects or conditions. In addition, there are some server shell commands that affect clients on the proxy (run 'help' in the shell to see what they are). All proxy commands in the server shell only work when there's exactly one client connected through the proxy, since there isn't (yet) a way to say via the shell which session you want the command to apply to.
|
||||
Some chat commands (see below) have the same basic function on the proxy server but have different effects or conditions. In addition, there are some server shell commands that affect clients on the proxy (run `help` in the shell to see what they are). If there's only one proxy session open, the shell's proxy commands will affect that session. Otherwise, you'll have to specify which session to affect with the `on` prefix - to send a chat message in LinkedSession:17205AE4, for example, you would run `on 17205AE4 chat ...`.
|
||||
|
||||
### Chat commands
|
||||
|
||||
@@ -222,7 +287,7 @@ Some commands only work on the game server and not on the proxy server. The chat
|
||||
* `$what` (game server only): Shows the type, name, and stats of the nearest item on the ground.
|
||||
|
||||
* Debugging commands
|
||||
* `$dbgid` (game server only): Enable or disable high ID preference. When enabled, you'll be placed into the latest available slot in lobbies and games instead of the earliest. Can be useful for finding commands for which newserv doesn't handle client IDs properly.
|
||||
* `$debug` (game server only): Enable or disable debug. You need the DEBUG permission in your user license to use this command. When debug is enabled, you'll see in-game messages from the server when you take certain actions. You'll also be placed into the highest available slot in lobbies and games instead of the lowest, which is useful for finding commands for which newserv doesn't handle client IDs properly. This setting also disables certain safeguards and allows you to do some things that might crash your client.
|
||||
* `$gc` (game server only): Send your own Guild Card to yourself.
|
||||
* `$persist` (game server only): Enable or disable persistence for the current lobby or game. This determines whether the lobby/game is deleted when the last player leaves. You need the DEBUG permission in your user license to use this command because there are no game state checks when you do this. For example, if you make a game persistent, start a quest, then leave the game, the game can't be joined by anyone but also can't be deleted.
|
||||
* `$sc <data>`: Send a command to yourself.
|
||||
@@ -230,9 +295,9 @@ Some commands only work on the game server and not on the proxy server. The chat
|
||||
|
||||
* Personal state commands
|
||||
* `$arrow <color-id>`: Changes your lobby arrow color.
|
||||
* `$secid <section-id>`: Sets your override section ID. After running this command, any games you create will use your override section ID for rare drops instead of your character's actual section ID. To revert to your actual section id, run `$secid` with no name after it.
|
||||
* `$secid <section-id>`: Sets your override section ID. After running this command, any games you create will use your override section ID for rare drops instead of your character's actual section ID. To revert to your actual section id, run `$secid` with no name after it. On the proxy server, this will not work if the remote server controls item drops (e.g. on BB, or on Schtserv with server drops enabled).
|
||||
* `$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.
|
||||
* `$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 an Episode 3 game or spectator team, sends you to the lobby (but does not end your proxy session if you're in one).
|
||||
* `$exit`: If you're in a lobby, sends you to the main menu (which ends your proxy session, if you're in one). If you're in a game or spectator team, sends you to the lobby (but does not end your proxy session if you're in one). Does nothing if you're in a non-Episode 3 game and no quest is in progress.
|
||||
* `$patch <name>`: Run a patch on your client. `<name>` must exactly match the name of a patch on the server.
|
||||
|
||||
* Blue Burst player commands (game server only)
|
||||
@@ -240,7 +305,7 @@ Some commands only work on the game server and not on the proxy server. The chat
|
||||
* `$edit <stat> <value>`: Modifies your character data.
|
||||
|
||||
* Game state commands (game server only)
|
||||
* `$maxlevel <level>`: Sets the maximum level for players to join the current game.
|
||||
* `$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.)
|
||||
* `$minlevel <level>`: Sets the minimum level for players to join the current game.
|
||||
* `$password <password>`: Sets the game's join password. To unlock the game, run `$password` with nothing after it.
|
||||
* `$spec`: Toggles the allow spectators flag. If any players are spectating when this flag is disabled, they will be sent back to the lobby.
|
||||
@@ -248,12 +313,13 @@ Some commands only work on the game server and not on the proxy server. The chat
|
||||
* `$playrec <name>`: Play a battle recording. This command creates a spectator team and replays the specified battle log within it. There is a known issue which causes spectators to crash in some cases, so use of this command is currently not recommended.
|
||||
|
||||
* Cheat mode commands
|
||||
* `$cheat`: Enables or disables cheat mode for the current game. All other cheat mode commands do nothing if cheat mode is disabled. This command does nothing on the proxy server - cheat commands are always available there.
|
||||
* `$cheat`: Enables or disables cheat mode for the current game. All other cheat mode commands do nothing if cheat mode is disabled. By default, cheat mode is off in new games but can be enabled; there is an option in config.json that allows you to disable cheat mode entirely, or set it to on by default in new games.
|
||||
* `$infhp` / `$inftp`: Enables or disables infinite HP or TP mode. Applies to only you. In infinite HP mode, one-hit KO attacks will still kill you.
|
||||
* `$warp <area-id>`: Warps yourself to the given area.
|
||||
* `$warpme <area-id>`: Warps yourself to the given area.
|
||||
* `$warpall <area-id>`: Warps everyone in the game to the given area. You must be the leader to use this command, unless you're on the proxy server.
|
||||
* `$next`: Warps yourself to the next area.
|
||||
* `$swa`: Enables or disables switch assist. When enabled, the server will attempt to automatically unlock two-player doors in solo games if you step on both switches sequentially.
|
||||
* `$item <data>` (or `$i <data>`): Create an item. 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.
|
||||
|
||||
* Configuration commands
|
||||
* `$event <event>`: Sets the current holiday event in the current lobby. Holiday events are documented in the "Using $event" item in the information menu. If you're on the proxy server, this applies to all lobbies and games you join, but only you will see the new event - other players will not.
|
||||
@@ -285,7 +351,7 @@ To use the script, do this:
|
||||
|
||||
If you use this method, you'll have to run the script every time you start PSO in Flycast, but you won't have to run it again if you start another online game without restarting emulation.
|
||||
|
||||
Finally, the script takes an optional second argument that allows you to redirect the connection elsewhere (instead of the local machine). THis allows you to connect directly to remote servers if desired.
|
||||
Finally, the script takes an optional second argument that allows you to redirect the connection elsewhere (instead of the local machine). This allows you to connect directly to remote servers if desired.
|
||||
|
||||
#### PSO PC
|
||||
|
||||
@@ -299,9 +365,9 @@ If you have PSO Plus or Episode III, it won't want to connect to a server on the
|
||||
|
||||
#### PSO GC on Dolphin
|
||||
|
||||
If you have BBA support via a tap interface, you may be able to just set the DNS server address (as you would on a real GameCube, above) and it may work. This does not work on macOS, but you can use the tapserver interface instead (below).
|
||||
If you have BBA support via a tap interface or via the HLE/built-in interface, you may be able to just set the DNS server address (as you would on a real GameCube, above) and it may work.
|
||||
|
||||
If you're using a version of Dolphin with tapserver support (currently only the macOS version), 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, and this works for all PSO versions without any of the dual-interface trickery described above. To do this:
|
||||
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, and this works for all PSO versions without any of the dual-interface trickery described above. To do this:
|
||||
1. Set Dolphin's BBA type to tapserver (Config -> GameCube -> SP1).
|
||||
2. Enable newserv's IP stack simulator according to the comments in config.json and start newserv.
|
||||
3. In PSO, you have to configure the network settings manually (DHCP doesn't work), but the actual values don't matter as long as they're valid IP addresses. Example values:
|
||||
@@ -318,17 +384,25 @@ If you want to accept connections from outside your local network, you'll need t
|
||||
|
||||
For GC clients, you'll have to use newserv's built-in DNS server or set up your own DNS server as well. If you want external clients to be able to use your DNS server, you'll have to forward UDP port 53 to your newserv instance. Remote players can then connect to your server by entering your DNS server's IP address in their client's network configuration.
|
||||
|
||||
### Non-server usage
|
||||
### Non-server features
|
||||
|
||||
newserv has many CLI options, which can be used to access functionality other than the game/proxy server. Run `newserv help` to see these options and how to use them. The non-server things newserv can do are:
|
||||
newserv has many CLI options, which can be used to access functionality other than the game and proxy server. Run `newserv help` to see these options and how to use them. The non-server things newserv can do are:
|
||||
|
||||
* Compress or decompress data in the PRS and BC0 formats
|
||||
* Compute the decompressed size of compressed PRS data without decompressing it
|
||||
* Encrypt or decrypt data using any PSO version's network encryption scheme
|
||||
* Encrypt or decrypt data using Episode 3's trivial scheme
|
||||
* Run a brute-force search for a decryption seed
|
||||
* Decode Shift-JIS text to UTF-16
|
||||
* Convert quests in .gci, .dlq, or .qst format to .bin/.dat format
|
||||
* Extract the contents of a .gsl archive
|
||||
* Connect to another PSO server and pretend to be a client
|
||||
* Format Episode 3 game data in a human-readable manner
|
||||
* Compress or decompress data in PRS, PR2, or BC0 format (`compress-prs`, `compress-pr2`, `compress-bc0`, `decompress-prs`, `decompress-pr2`, `decompress-bc0`)
|
||||
* Compute the decompressed size of compressed PRS data without decompressing it (`prs-size`)
|
||||
* Encrypt or decrypt data using any PSO version's network encryption scheme (`encrypt-data`, `decrypt-data`)
|
||||
* Encrypt or decrypt data using Episode 3's trivial scheme (`encrypt-trivial-data`, `decrypt-trivial-data`)
|
||||
* Encrypt or decrypt data using the Challenge Mode text algorithm (`encrypt-challenge-data`, `decrypt-challenge-data`)
|
||||
* Encrypt or decrypt PSO GC save data (.gci files) (`encrypt-gci-save`, `decrypt-gci-save`)
|
||||
* Convert a PSO GC or Episode 3 snapshot file to a BMP image (`decode-gci-snapshot`)
|
||||
* Find the likely round1 or round2 seed for a corrupt save file (`salvage-gci`)
|
||||
* Run a brute-force search for a decryption seed (`find-decryption-seed`)
|
||||
* Decode Shift-JIS text to UTF-16 (`decode-sjis`)
|
||||
* Convert quests in .gci, .vms, .dlq, or .qst format to .bin/.dat format (`decode-gci`, `decode-vms`, `decode-dlq`, `decode-qst`)
|
||||
* Convert quests in .bin/.dat to .qst format (`encode-qst`)
|
||||
* Disassemble quest scripts (`disassemble-quest-script`)
|
||||
* Format Episode 3 game data in a human-readable manner (`show-ep3-maps`, `show-ep3-cards`)
|
||||
* Convert item data to a human-readable description, or vice versa (`describe-item`, `encode-item`)
|
||||
* Connect to another PSO server and pretend to be a client (`cat-client`)
|
||||
* Replay a session log for testing (`replay-log`)
|
||||
* Extract the contents of a .gsl or .bml archive (`extract-gsl`, `extract-bml`)
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
(Ep1&2 USA) Unlock all songs in BGM test
|
||||
(Note: sadly, there are no secret/unused ones)
|
||||
04368960 38600001
|
||||
04368964 4E800020
|
||||
|
||||
(Ep1&2 USA v1.01) Play lobby (and event) music on Pioneer 2 also
|
||||
0417E0F0 60000000
|
||||
|
||||
(Ep3 USA) Play lobby (and event) music in Morgue also
|
||||
040B7028 60000000
|
||||
|
||||
(Ep3 USA) Skip white logo screens during startup
|
||||
0409D774 38000007
|
||||
(Episodes 1&2 USA v1.01) Skip white logo screens during startup
|
||||
0413F190 38000007
|
||||
|
||||
(Ep3 USA) Skip agreement prompts before online game
|
||||
041B50C8 38000003
|
||||
(Episodes 1&2 USA v1.01) Skip agreement prompt before online game
|
||||
04327D80 38000003
|
||||
|
||||
(Ep3 USA) Disable rate limit for pressing A during loading screens
|
||||
042F9B30 38000000
|
||||
|
||||
(Ep3 USA) Auto-press A as fast as possible during loading screens
|
||||
042F9AC0 60000000
|
||||
|
||||
(Ep3 USA) Use 16:9 aspect ratio
|
||||
04383DC8 4BC87F99
|
||||
0400BD60 C042DED0
|
||||
0400BD64 EC5D00B2
|
||||
0400BD68 4E800020
|
||||
|
||||
(Ep3 USA) Disable darkening effect during battle details mode
|
||||
042F951C 4E800020
|
||||
|
||||
(Ep3 USA) Unlock all COM decks
|
||||
042CA908 38600001
|
||||
|
||||
(Ep3 USA) Enable all lobby counter options in non-CARD lobbies
|
||||
04096A8C 480000C0
|
||||
04096B4C 38800007
|
||||
04096BFC 4BFFFF2C
|
||||
|
||||
(Ep3 USA) Change HUD color mask
|
||||
0438CA8C 3C00RRGG
|
||||
0438CA90 6000BBAA
|
||||
|
||||
(Ep3 USA) Disable lobby event music (but keep the visuals)
|
||||
040B705C 38000000
|
||||
|
||||
(Ep3 USA) Enable unused fourth Pinz's Shop choice
|
||||
043101C0 38800004
|
||||
04310238 2C1D0004
|
||||
04487E8C 000000C8
|
||||
|
||||
(Ep3 USA) Change color of pulsing orange text (e.g. card ability names)
|
||||
0457EE18 RRRRRRRR // Phase 1 (long) red component as 32-bit float (0.0-255.0)
|
||||
0457EE20 GGGGGGGG // Phase 1 (long) green component as 32-bit float (0.0-255.0)
|
||||
0457EE10 BBBBBBBB // Phase 1 (long) blue component as 32-bit float (0.0-255.0)
|
||||
0457EE1C RRRRRRRR // Phase 2 (short) red component as 32-bit float (0.0-255.0)
|
||||
0457EE24 GGGGGGGG // Phase 2 (short) green component as 32-bit float (0.0-255.0)
|
||||
0457EE14 BBBBBBBB // Phase 2 (short) blue component as 32-bit float (0.0-255.0)
|
||||
|
||||
(Ep3 USA) Change color of pulsing orange text to be random every frame
|
||||
04155D78 7CA802A6
|
||||
04155D7C 7C661B78
|
||||
04155D80 481EF8B1
|
||||
04155D84 7C671B78
|
||||
04155D88 481EF8A9
|
||||
04155D8C 50677822
|
||||
04155D90 64E7FF00
|
||||
04155D94 90E60024
|
||||
04155D98 7CA803A6
|
||||
04155D9C 4E800020
|
||||
|
||||
(Ep3 USA) Enable color and symbol codes in info board text
|
||||
(Use codes like e.g. $CG to change text colors, as described in CommandFormats.hh)
|
||||
040F2E80 4BF0D41D
|
||||
040F0274 4BF10025
|
||||
040EFC58 4BF10641
|
||||
04000298 38810008
|
||||
0400029C 38C3FFFF
|
||||
040002A0 8CA60001
|
||||
040002A4 28050024
|
||||
040002A8 4082000C
|
||||
040002AC 38000009
|
||||
040002B0 98060000
|
||||
040002B4 28050000
|
||||
040002B8 4082FFE8
|
||||
040002BC 7C633050
|
||||
040002C0 4E800020
|
||||
|
||||
(Ep3 USA) Unlock all offline free battle maps
|
||||
042CAA00 38600001
|
||||
(This unlocks ALL maps, including a bunch of maps with garbage names that crash if you try to play them)
|
||||
|
||||
(Ep3 USA) Talk to auction counter offline to get all cards
|
||||
042F5D18 4BD160E8
|
||||
0400BE00 9421FFE0
|
||||
0400BE04 7C0802A6
|
||||
0400BE08 90010024
|
||||
0400BE0C 93E10010
|
||||
0400BE10 93C10014
|
||||
0400BE14 93A10018
|
||||
0400BE18 9381001C
|
||||
0400BE1C 3C60802A
|
||||
0400BE20 60631BAC
|
||||
0400BE24 7C6903A6
|
||||
0400BE28 38600000
|
||||
0400BE2C 4E800421
|
||||
0400BE30 7C7F1B78
|
||||
0400BE34 3C60802A
|
||||
0400BE38 606315BC
|
||||
0400BE3C 7C6903A6
|
||||
0400BE40 7FE3FB78
|
||||
0400BE44 4E800421
|
||||
0400BE48 3F80802A
|
||||
0400BE4C 639C17AC
|
||||
0400BE50 3BC00001
|
||||
0400BE54 3BA00063
|
||||
0400BE58 7FE3FB78
|
||||
0400BE5C 7FC4F378
|
||||
0400BE60 7F8903A6
|
||||
0400BE64 4E800421
|
||||
0400BE68 3BBDFFFF
|
||||
0400BE6C 281D0000
|
||||
0400BE70 4082FFE8
|
||||
0400BE74 3BDE0001
|
||||
0400BE78 281E02F0
|
||||
0400BE7C 4081FFD8
|
||||
0400BE80 3C60802A
|
||||
0400BE84 6063160C
|
||||
0400BE88 7C6903A6
|
||||
0400BE8C 7FE3FB78
|
||||
0400BE90 4E800421
|
||||
0400BE94 83E10010
|
||||
0400BE98 83C10014
|
||||
0400BE9C 83A10018
|
||||
0400BEA0 8381001C
|
||||
0400BEA4 80010024
|
||||
0400BEA8 38210020
|
||||
0400BEAC 7C0803A6
|
||||
0400BEB0 482E9FC0
|
||||
|
||||
(Episodes 1&2 USA v1.01) Press L for enemy debug; enable various other debug messages
|
||||
040FD9D8 38600001 # Various enemy debug messages
|
||||
00153E53 00000001 # Poison fog debug 1
|
||||
00153E4B 00000001 # Poison fog debug 2
|
||||
040FDA18 60000000 # TObjRoomId
|
||||
025CB6AA 00000000
|
||||
4A588EA0 00000040
|
||||
025CB6AA 00000001
|
||||
TODO: Figure out more debug message conditionals (vars/functions) and add them here
|
||||
|
||||
(Episode 3 USA) Able to find VIP cards offline (but they're still rare)
|
||||
042C0B20 4800000C
|
||||
|
||||
(Ep3 USA) Hold L when starting battle to enter debug menu
|
||||
042C5460 4BD3AF78
|
||||
040003D8 3C60804A
|
||||
040003DC 60630518
|
||||
040003E0 3C800002
|
||||
040003E4 480C9F35
|
||||
040003E8 2C030000
|
||||
040003EC 4082000C
|
||||
040003F0 8801001A
|
||||
040003F4 48000008
|
||||
040003F8 3800001A
|
||||
040003FC 482C5068
|
||||
|
||||
(Ep3 USA) Dressing room always accessible
|
||||
041A16FC 38600001
|
||||
|
||||
(Ep3 USA) Replace Options menu with debug menu
|
||||
04149E70 38600019
|
||||
@@ -0,0 +1,5 @@
|
||||
DC NTE: pso02.dricas.ne.jp
|
||||
Nov 2000 proto: test1.st-pso.games.sega.net
|
||||
Dec 2000 proto: sg107634.csrd.sega.co.jp
|
||||
Jan 2001 proto: master.pso.dream-key.com
|
||||
Aug 2001 proto (v2): ???
|
||||
@@ -0,0 +1,4 @@
|
||||
./newserv decrypt-gci-save --sys=8P-GPSE-PSO3_SYSTEM.gci 8P-GPSE-PSO3_CHARACTER.gci
|
||||
./newserv decrypt-gci-save --sys=8P-GPSE-PSO3_SYSTEM.gci 8P-GPSE-PSO3_GUILDCARD.gci
|
||||
./newserv decrypt-gci-save --sys=8P-GPOE-PSO_SYSTEM.gci 8P-GPOE-PSO_CHARACTER.gci
|
||||
./newserv decrypt-gci-save --sys=8P-GPOE-PSO_SYSTEM.gci 8P-GPOE-PSO_GUILDCARD.gci
|
||||
@@ -0,0 +1,45 @@
|
||||
Ep3 card text corrections (from THG Discord):
|
||||
- AP Absorption: Does not block Tech attacks, instead they deal 2 extra damage.
|
||||
- Assault: Adds 5 AP minus the number of FCs on your field, not in your deck.
|
||||
- Assist Return: If this replaces an Assist card that was not in its owner's own Assist slot, that card gets re-played in to that slot.
|
||||
- Barble: His "Unfilial" ability does 3 damage, not 1.
|
||||
- Berdysh: Equip requirements are Hunter and Humanoid, not either one.
|
||||
- Black King Bar: "Machine Influence" doesn't need the opponent to be an attacker.
|
||||
- Blade Dance: "Insanity" doesn't exist. Has "Steady Damage".
|
||||
- Combo/Explosion: Adds +(# of Combo cards played in phase squared) AP, but the effect only applies once per attacker.
|
||||
- EGM: "Timed EXP Sacrifice" gives 9 EXP, not 6.
|
||||
- Fix: Sets all FC attacks to 2 damage, not FC attackers to 2 AP.
|
||||
- Flatland: Allows summoning in any space on the board, not summoning for free.
|
||||
- Ghost Blast: Damage added is 1/3 death count, not 1x.
|
||||
- Gibbles +: Curse' sets MV to 1 for 6 turns, not permanently.
|
||||
- Govulmer: His "AP Silence" reduces AP by 3, not to 0.
|
||||
- Guil Shark: +2 damage per Guil for the "Group" ability, not +1.
|
||||
- Gulgus: His "Copy" ability gives full AP and TP, not 1/2.
|
||||
- Holy Ray: Doesn't have the "Enemy Bonus" ability.
|
||||
- Kaladbolg: "Attack AC Unable" was a lie.
|
||||
- Lock on 3: Also has the ability "DEF Cost 4 Disable".
|
||||
- Mighty Knuckle: Adds 1.5x points spent as damage, not those points +1.
|
||||
- Migium: Gains TP from it's "Combo" ability, not AP.
|
||||
- Orland: "Sword AP Count" looks at your team, not the whole field.
|
||||
- Pofuilly Slime: His "Copy" ability gives 1/2 AP and TP, not full.
|
||||
- Rainbow Baton: Correctly reads as Tech OK.
|
||||
- Red Slicer: "Native Influence" doesn't need the opponent to be an attacker.
|
||||
- Rufina: She doubles the AP of action cards used, not her own.
|
||||
- Unit Blow: Adds +3 AP per Unit Blow played in the entire Combat Phase, but the effect only applies once per attacker.
|
||||
|
||||
List of changes Sega made to Ep3 cards online (from THG Discord):
|
||||
- Rebalanced Vanilla Cards (E rank is gone, so some cards nerfed b/c they aren’t locked to 1x)
|
||||
- Meteor Cudgel: [Cost]5 ---> [Cost]4
|
||||
- Frozen Shooter: Frozen Target now only freezes self for 2 Turns, on a 20% chance.
|
||||
- Snow Queen: Frozen Target now only freezes self for 2 Turns, on a 25% chance.
|
||||
- Hand Break: Hand Disruptor added (old card description is now accurate)
|
||||
- Rush: [Cost]6 [AP]+0 ---> [Cost]4 [AP]+1
|
||||
- Explosion: [Cost]5 ---> [Cost]4
|
||||
- Resta: Range changed to Anti’s range (hits all ally SCs and FCs)
|
||||
- Dice Half: [Cost]5 ---> [Cost]4
|
||||
- Resistance: [Cost]5 ---> [Cost]4
|
||||
- Independant: [Cost]4 ---> [Cost]3
|
||||
- Dreamaga: [Cost]1 ---> [Cost]2
|
||||
- Dengeki: [Cost]1 ---> [Cost]2
|
||||
- EGM: [Cost]1 ---> [Cost]2
|
||||
- Beat: [AP]+5 ---> [AP]+4
|
||||
@@ -0,0 +1,127 @@
|
||||
|
||||
0457EE18 437F0000 CG_color_r_phase1
|
||||
0457EE20 00000000 CG_color_g_phase1
|
||||
0457EE10 00000000 CG_color_b_phase1
|
||||
0457EE1C 00000000 CG_color_r_phase2
|
||||
0457EE24 437F0000 CG_color_g_phase2
|
||||
0457EE14 00000000 CG_color_b_phase2
|
||||
|
||||
437F0000 == 255.0f
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(Ep3 USA) Change color of pulsing orange text (e.g. card ability names)
|
||||
0457EE18 RRRRRRRR // Phase 1 (long) red component as 32-bit float (0.0-255.0)
|
||||
0457EE20 GGGGGGGG // Phase 1 (long) green component as 32-bit float (0.0-255.0)
|
||||
0457EE10 BBBBBBBB // Phase 1 (long) blue component as 32-bit float (0.0-255.0)
|
||||
0457EE1C RRRRRRRR // Phase 2 (short) red component as 32-bit float (0.0-255.0)
|
||||
0457EE24 GGGGGGGG // Phase 2 (short) green component as 32-bit float (0.0-255.0)
|
||||
0457EE14 BBBBBBBB // Phase 2 (short) blue component as 32-bit float (0.0-255.0)
|
||||
|
||||
(Ep3 USA) Change color of pulsing orange text to be random every frame
|
||||
04155D78 7CA802A6
|
||||
04155D7C 7C661B78
|
||||
04155D80 481EF8B1
|
||||
04155D84 7C671B78
|
||||
04155D88 481EF8A9
|
||||
04155D8C 50677822
|
||||
04155D90 64E7FF00
|
||||
04155D94 90E60024
|
||||
04155D98 7CA803A6
|
||||
04155D9C 4E800020
|
||||
|
||||
|
||||
|
||||
color codes in info board
|
||||
|
||||
patch 800F2E80 48253CC9 bl strlen
|
||||
./m68kdasm --assemble-ppc32 --ppc32 --start-address=800F2E80
|
||||
bl [8000029C]
|
||||
040F2E80 4BF0D41D bl -0x000F2BE4 /* 8000029C */
|
||||
|
||||
patch/preserve 800f0274 38810008 addi param_2,r1,0x8
|
||||
./m68kdasm --assemble-ppc32 --ppc32 --start-address=800F0274
|
||||
bl [80000298]
|
||||
040F0274 4BF10025 bl -0x000EFFDC /* 80000298 */
|
||||
|
||||
patch/preserve 800efc58 38810008 addi r4,r1,0x8
|
||||
./m68kdasm --assemble-ppc32 --ppc32 --start-address=800EFC58
|
||||
bl [80000298]
|
||||
040EFC58 4BF10641 bl -0x000EF9C0 /* 80000298 */
|
||||
|
||||
./m68kdasm --assemble-ppc32 --ppc32 --start-address=80000298
|
||||
entry_from_send_61_and_send_98:
|
||||
addi r4, r1, 8
|
||||
entry_from_send_D8:
|
||||
subi r6, r3, 1
|
||||
again:
|
||||
lbzu r5, [r6 + 1]
|
||||
cmplwi r5, 0x24
|
||||
bne skip_char
|
||||
li r0, 0x09
|
||||
stb [r6], r0
|
||||
skip_char:
|
||||
cmplwi r5, 0
|
||||
bne again
|
||||
sub r3, r6, r3
|
||||
blr
|
||||
04000298 38810008 addi r4, r1, 0x0008
|
||||
0400029C 38C3FFFF subi r6, r3, 0x0001
|
||||
040002A0 8CA60001 lbzu r5, [r6 + 0x0001]
|
||||
040002A4 28050024 cmplwi r5, 36
|
||||
040002A8 4082000C bne +0x0000000C /* 800002B4 */
|
||||
040002AC 38000009 li r0, 0x0009
|
||||
040002B0 98060000 stb [r6], r0
|
||||
040002B4 28050000 cmplwi r5, 0
|
||||
040002B8 4082FFE8 bne -0x00000018 /* 800002A0 */
|
||||
040002BC 7C633050 subf r3, r3, r6
|
||||
040002C0 4E800020 blr
|
||||
|
||||
|
||||
|
||||
Ep1&2 v1.01 version of the above code
|
||||
|
||||
send_D9
|
||||
./m68kdasm --assemble-ppc32 --ppc32 --start-address=801DA398
|
||||
bl [800002D4]
|
||||
041DA398 4BE25F3D bl -0x001DA0C4 /* 800002D4 */
|
||||
|
||||
send_61
|
||||
./m68kdasm --assemble-ppc32 --ppc32 --start-address=801DC2AC
|
||||
bl [800002D0]
|
||||
041DC2AC 4BE24025 bl -0x001DBFDC /* 800002D0 */
|
||||
|
||||
send_98
|
||||
./m68kdasm --assemble-ppc32 --ppc32 --start-address=801DC144
|
||||
bl [800002D0]
|
||||
041DC144 4BE2418D bl -0x001DBE74 /* 800002D0 */
|
||||
|
||||
./m68kdasm --assemble-ppc32 --ppc32 --start-address=800002D0
|
||||
entry_from_send_61_and_send_98:
|
||||
addi r4, r1, 8
|
||||
entry_from_send_D8:
|
||||
subi r6, r3, 1
|
||||
again:
|
||||
lbzu r5, [r6 + 1]
|
||||
cmplwi r5, 0x24
|
||||
bne skip_char
|
||||
li r0, 0x09
|
||||
stb [r6], r0
|
||||
skip_char:
|
||||
cmplwi r5, 0
|
||||
bne again
|
||||
sub r3, r6, r3
|
||||
blr
|
||||
040002D0 38810008 addi r4, r1, 0x0008
|
||||
040002D4 38C3FFFF subi r6, r3, 0x0001
|
||||
040002D8 8CA60001 lbzu r5, [r6 + 0x0001]
|
||||
040002DC 28050024 cmplwi r5, 36
|
||||
040002E0 4082000C bne +0x0000000C /* 800002EC */
|
||||
040002E4 38000009 li r0, 0x0009
|
||||
040002E8 98060000 stb [r6], r0
|
||||
040002EC 28050000 cmplwi r5, 0
|
||||
040002F0 4082FFE8 bne -0x00000018 /* 800002D8 */
|
||||
040002F4 7C633050 subf r3, r3, r6
|
||||
040002F8 4E800020 blr
|
||||
@@ -0,0 +1,29 @@
|
||||
N1, N2, N3, N4 => use 8041F800 table
|
||||
R1, R2, R3, R4 => use 8041F8A0 table
|
||||
|
||||
|
||||
(Episode 3 USA) Able to find VIP cards offline (but still very rare)
|
||||
042C0B20 4800000C
|
||||
|
||||
|
||||
P(activate) is the probability that any transformation is attempted at all
|
||||
P(f/success) defines the probability range: so the actual probability is a
|
||||
uniform random number between P(activate) and P(activate) * P(f/success)
|
||||
count P(activate) P(f/success) P(vip)
|
||||
0-4 0.0 0.0 0.0
|
||||
5-10 0.01923077 0.55 0.005
|
||||
11-16 0.021276595 0.6 0.0045454544
|
||||
17-24 0.023809524 0.7 0.004347826
|
||||
25-32 0.027027028 0.7 0.004
|
||||
33-40 0.03125 0.8 0.0038461538
|
||||
41-52 0.037037037 0.8 0.0035714286
|
||||
53-99 0.05 0.9 0.0033333334
|
||||
|
||||
0-4 0.0 0.0 0.0
|
||||
5-10 0.020408163 0.55 0.005
|
||||
11-16 0.022727273 0.6 0.004761905
|
||||
17-24 0.025641026 0.7 0.0045454544
|
||||
25-32 0.029411765 0.7 0.005
|
||||
33-40 0.03448276 0.7 0.005
|
||||
41-52 0.041666668 0.8 0.0045454544
|
||||
53-99 0.05263158 0.9 0.004347826
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
star value tables
|
||||
|
||||
psobb [B1-437]
|
||||
00010203 04090909 01020304 05090909 01020304 05090909 01020304 05090909 01020304 05090909 00010203 04090909 01020304 05090909 01020304 05090909 01020304 05090909 00010203 09090901 02030409 09090102 03040909 09090A0A 090A0A09 0A0A090C 0B0A0A0A 0A0A0A0B 0A090A0A 0A0A0A09 0A0A0A0A 0A0A0A0A 0A0A0B0A 0C0C0B0A 0A090A09 090A0A0A 0A0C090C 0B0A090A 090C0A0B 0A0A0A0A 0A0A0A0B 0B0A0A0A 09090A09 0C0A0A0A 0B0A0B09 0A0A090A 0A0B090B 0A0B0B0A 090A090A 0B090A0A 0A0A0A0A 0A0A0A09 090C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0009 0A0A0A0B 090A0A09 0A0A0B0A 0A0A0A0A 0A0A0A0A 0A0A0A0A 0A0A0A0A 0A0A0A0A 0B0B0B0B 0B0B0B0B 0B0B0B0A 0C0A0C0B 0A0A0A0A 0A0B0A0B 0B0B0B0B 0A0A090A 0A0A090B 0B0B0B0C 0C0C0C0C 0A0A0C0A 090A0C09 0A0B0A0A 0A0A0C0A 0A0A0A09 0A0C0A09 0A0A0A0A 0A090C0B 09090909 09090909 09090909 09090909 0909090B 0A0C0A0B 0B0C0A0A 0A090A0A 0A0A0B0A 0A0A0A0A 0909090A 0A090C0A 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0102 03040102 03040203 04020304 01020304 01020304 01020304 01020304 01020304 01020304 03040000 00010102 02030304 04050506 06070707 07080808 08080809 09090A0A 0A0A0A0A 0B0C0A0A 0A0A0A0A 0B0B0B0A 0B0B0C0B 0B0B0B0B 0A0A0A0A 0A0A0C09 0909090A 0A0B0C09 0B0A0A0A 0A0A0A0A 0A0A0A0B 0A0A0A0A 0A0A0A00 00010203 03040405 05050606 07070808 08080808 0A0A0A0A 0A0A0909 090A0A0A 0A0A0A0A 0A0A0B0A 0A0B0A09 0909090A 0B0B0000 0B000000 00080808 08080808 09080808 09080808 09070707 07070909 090C0909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 0A0A0B0A 0B0A0909 0B0B0B0C 0A0A0A09 0A0A0A0A 090A0A0A 0A0A0A0A 0A0A0A0A 0203050B 0203050B 0203050B 0203050B 0204060B 0204060B 0203050B 080B080A 0B020305 02030502 03050304 06030405 07080B04 06090406 09040609 06090B06 090B0909 09090909 0A0B0B0B 0B0B0B0B 0B0B0B0B 0B0B0B0B 0B0B0B0B 0A0B0B0B 0B0B0B0B
|
||||
|
||||
psogc [94-2F7]
|
||||
00010203 04090909 01020304 05090909 01020304 05090909 01020304 05090909 01020304 05090909 00010203 04090909 01020304 05090909 01020304 05090909 01020304 05090909 00010203 09090901 02030409 09090102 03040909 09090A0A 090A0A09 0A0A090C 0B0A0A0A 0A0A0A0B 0A090A0A 0A0A0A09 0A0A0A0A 0A0A0A0A 0A0A0B0A 0C0C0B0A 0A090A09 090A0A0A 0A0C090C 0B0A090A 090C0A0B 0A0A0A0A 0A0A0A0B 0B0A0A0A 09090A09 0C0A0A0A 0B0A0B09 0A0A090A 0A0B090B 0A0B0B0A 090A090A 0B090A0A 0A0A0A0A 0A0A0A09 090C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0009 0A0A0A0B 090A0A09 0A0A0B0A 0A0A0A0A 0A0A0A0A 0A0A0A0A 0A0A0A0A 0A0A0A0A 0B0B0B0B 0B0B0B0B 0B0B0B0A 0C0A0C0B 0A0A0A0A 0A0B0A0B 0B0B0B0B 0A0A090A 0A0A090B 0B0B0B0C 0C0C0C0C 01020304 01020304 02030402 03040102 03040102 03040102 03040102 03040102 03040102 03040304 00000001 01020203 03040405 05060607 07070708 08080808 08090909 0A0A0A0A 0A0A0B0C 0A0A0A0A 0A0A0B0B 0B0A0B0B 0C0B0B0B 0B0B0000 01020303 04040505 05060607 07080808 0808080A 0A0A0A0A 0A090909 0A0A0A0A 0A0A0A0A 0A0B0A0A 0B0A0909 09090A0B 0B000000 00000000 08080808 08080809 08080809 08080809 07070707 07090909 0C090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090902 03050B02 03050B02 03050B02 03050B02 04060B02 04060B02 03050B08 0B080A0B 02030502 03050203 05030406 03040507 080B0406 09040609 04060906 090B0609 0B090909 090909
|
||||
|
||||
|
||||
|
||||
0203050B0203050B0203050B0203050B
|
||||
@@ -0,0 +1,106 @@
|
||||
#include "BMLArchive.hh"
|
||||
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "Text.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <bool IsBigEndian>
|
||||
struct BMLHeader {
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
|
||||
parray<uint8_t, 0x04> unknown_a1;
|
||||
U32T num_entries;
|
||||
parray<uint8_t, 0x38> unknown_a2;
|
||||
} __attribute__((packed));
|
||||
|
||||
template <bool IsBigEndian>
|
||||
struct BMLHeaderEntry {
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
|
||||
ptext<char, 0x20> filename;
|
||||
U32T compressed_size;
|
||||
parray<uint8_t, 0x04> unknown_a1;
|
||||
U32T decompressed_size;
|
||||
U32T compressed_gvm_size;
|
||||
U32T decompressed_gvm_size;
|
||||
parray<uint8_t, 0x0C> unknown_a2;
|
||||
} __attribute__((packed));
|
||||
|
||||
template <bool IsBigEndian>
|
||||
void BMLArchive::load_t() {
|
||||
StringReader r(*this->data);
|
||||
|
||||
const auto& header = r.get<BMLHeader<IsBigEndian>>();
|
||||
|
||||
size_t offset = 0x800;
|
||||
while (this->entries.size() < header.num_entries) {
|
||||
const auto& entry = r.get<BMLHeaderEntry<IsBigEndian>>();
|
||||
|
||||
if (offset + entry.compressed_size > this->data->size()) {
|
||||
throw runtime_error("BML data entry extends beyond end of data");
|
||||
}
|
||||
size_t data_offset = offset;
|
||||
offset = (offset + entry.compressed_size + 0x1F) & (~0x1F);
|
||||
|
||||
if (offset + entry.compressed_gvm_size > this->data->size()) {
|
||||
throw runtime_error("BML GVM entry extends beyond end of data");
|
||||
}
|
||||
size_t gvm_offset = offset;
|
||||
offset = (offset + entry.compressed_gvm_size + 0x1F) & (~0x1F);
|
||||
|
||||
this->entries.emplace(entry.filename, Entry{data_offset, entry.compressed_size, gvm_offset, entry.compressed_gvm_size});
|
||||
}
|
||||
}
|
||||
|
||||
BMLArchive::BMLArchive(shared_ptr<const string> data, bool big_endian)
|
||||
: data(data) {
|
||||
if (big_endian) {
|
||||
this->load_t<true>();
|
||||
} else {
|
||||
this->load_t<false>();
|
||||
}
|
||||
}
|
||||
|
||||
const unordered_map<string, BMLArchive::Entry> BMLArchive::all_entries() const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
pair<const void*, size_t> BMLArchive::get(const std::string& name) const {
|
||||
try {
|
||||
const auto& entry = this->entries.at(name);
|
||||
return make_pair(this->data->data() + entry.offset, entry.size);
|
||||
} catch (const out_of_range&) {
|
||||
throw out_of_range("BML does not contain file: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
pair<const void*, size_t> BMLArchive::get_gvm(const std::string& name) const {
|
||||
try {
|
||||
const auto& entry = this->entries.at(name);
|
||||
return make_pair(this->data->data() + entry.gvm_offset, entry.gvm_size);
|
||||
} catch (const out_of_range&) {
|
||||
throw out_of_range("BML does not contain file: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
string BMLArchive::get_copy(const string& name) const {
|
||||
try {
|
||||
const auto& entry = this->entries.at(name);
|
||||
return this->data->substr(entry.offset, entry.size);
|
||||
} catch (const out_of_range&) {
|
||||
throw out_of_range("BML does not contain file: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
StringReader BMLArchive::get_reader(const string& name) const {
|
||||
try {
|
||||
const auto& entry = this->entries.at(name);
|
||||
return StringReader(this->data->data() + entry.offset, entry.size);
|
||||
} catch (const out_of_range&) {
|
||||
throw out_of_range("BML does not contain file: " + name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
class BMLArchive {
|
||||
public:
|
||||
BMLArchive(std::shared_ptr<const std::string> data, bool big_endian);
|
||||
~BMLArchive() = default;
|
||||
|
||||
struct Entry {
|
||||
uint64_t offset;
|
||||
uint32_t size;
|
||||
uint64_t gvm_offset;
|
||||
uint32_t gvm_size;
|
||||
};
|
||||
const std::unordered_map<std::string, Entry> all_entries() const;
|
||||
|
||||
std::pair<const void*, size_t> get(const std::string& name) const;
|
||||
std::pair<const void*, size_t> get_gvm(const std::string& name) const;
|
||||
std::string get_copy(const std::string& name) const;
|
||||
StringReader get_reader(const std::string& name) const;
|
||||
|
||||
private:
|
||||
template <bool IsBigEndian>
|
||||
void load_t();
|
||||
|
||||
std::shared_ptr<const std::string> data;
|
||||
|
||||
std::unordered_map<std::string, Entry> entries;
|
||||
};
|
||||
@@ -0,0 +1,115 @@
|
||||
#include "BattleParamsIndex.hh"
|
||||
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
|
||||
#include "Loggers.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "StaticGameData.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
string BattleParamsIndex::Entry::str() const {
|
||||
string a1str = format_data_string(this->unknown_a1.data(), this->unknown_a1.bytes());
|
||||
return string_printf(
|
||||
"BattleParamsEntry[ATP=%hu PSV=%hu EVP=%hu HP=%hu DFP=%hu ATA=%hu LCK=%hu ESP=%hu a1=%s EXP=%" PRIu32 " diff=%" PRIu32 "]",
|
||||
this->atp.load(),
|
||||
this->psv.load(),
|
||||
this->evp.load(),
|
||||
this->hp.load(),
|
||||
this->dfp.load(),
|
||||
this->ata.load(),
|
||||
this->lck.load(),
|
||||
this->esp.load(),
|
||||
a1str.c_str(),
|
||||
this->experience.load(),
|
||||
this->difficulty.load());
|
||||
}
|
||||
|
||||
void BattleParamsIndex::Table::print(FILE* stream) const {
|
||||
auto print_entry = +[](FILE* stream, const Entry& e) {
|
||||
string a1str = format_data_string(e.unknown_a1.data(), e.unknown_a1.bytes());
|
||||
fprintf(stream,
|
||||
"%5hu %5hu %5hu %5hu %5hu %5hu %5hu %5hu %s %5" PRIu32 " %5" PRIu32,
|
||||
e.atp.load(),
|
||||
e.psv.load(),
|
||||
e.evp.load(),
|
||||
e.hp.load(),
|
||||
e.dfp.load(),
|
||||
e.ata.load(),
|
||||
e.lck.load(),
|
||||
e.esp.load(),
|
||||
a1str.c_str(),
|
||||
e.experience.load(),
|
||||
e.difficulty.load());
|
||||
};
|
||||
|
||||
for (size_t diff = 0; diff < 4; diff++) {
|
||||
fprintf(stream, "%c ZZ ATP PSV EVP HP DFP ATA LCK ESP A1 EXP DIFF\n",
|
||||
abbreviation_for_difficulty(diff));
|
||||
for (size_t z = 0; z < 0x60; z++) {
|
||||
fprintf(stream, " %02zX ", z);
|
||||
print_entry(stream, this->difficulty[diff][z]);
|
||||
fputc('\n', stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BattleParamsIndex::BattleParamsIndex(
|
||||
shared_ptr<const string> data_on_ep1,
|
||||
shared_ptr<const string> data_on_ep2,
|
||||
shared_ptr<const string> data_on_ep4,
|
||||
shared_ptr<const string> data_off_ep1,
|
||||
shared_ptr<const string> data_off_ep2,
|
||||
shared_ptr<const string> data_off_ep4) {
|
||||
this->files[0][0].data = data_on_ep1;
|
||||
this->files[0][1].data = data_on_ep2;
|
||||
this->files[0][2].data = data_on_ep4;
|
||||
this->files[1][0].data = data_off_ep1;
|
||||
this->files[1][1].data = data_off_ep2;
|
||||
this->files[1][2].data = data_off_ep4;
|
||||
|
||||
for (uint8_t is_solo = 0; is_solo < 2; is_solo++) {
|
||||
for (uint8_t episode = 0; episode < 3; episode++) {
|
||||
auto& file = this->files[is_solo][episode];
|
||||
if (file.data->size() < sizeof(Table)) {
|
||||
throw runtime_error(string_printf(
|
||||
"battle params table size is incorrect (expected %zX bytes, have %zX bytes; is_solo=%hhu, episode=%hhu)",
|
||||
sizeof(Table), file.data->size(), is_solo, episode));
|
||||
}
|
||||
file.table = reinterpret_cast<const Table*>(file.data->data());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const BattleParamsIndex::Entry& BattleParamsIndex::get(
|
||||
bool solo, Episode episode, uint8_t difficulty, EnemyType type) const {
|
||||
return this->get(solo, episode, difficulty, battle_param_index_for_enemy_type(episode, type));
|
||||
}
|
||||
|
||||
const BattleParamsIndex::Entry& BattleParamsIndex::get(
|
||||
bool solo, Episode episode, uint8_t difficulty, size_t index) const {
|
||||
if (difficulty > 4) {
|
||||
throw invalid_argument("incorrect difficulty");
|
||||
}
|
||||
if (index >= 0x60) {
|
||||
throw invalid_argument("incorrect monster type");
|
||||
}
|
||||
|
||||
uint8_t ep_index;
|
||||
switch (episode) {
|
||||
case Episode::EP1:
|
||||
ep_index = 0;
|
||||
break;
|
||||
case Episode::EP2:
|
||||
ep_index = 1;
|
||||
break;
|
||||
case Episode::EP4:
|
||||
ep_index = 2;
|
||||
break;
|
||||
default:
|
||||
throw invalid_argument("invalid episode");
|
||||
}
|
||||
|
||||
return this->files[!!solo][ep_index].table->difficulty[difficulty][index];
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <memory>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "EnemyType.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
class BattleParamsIndex {
|
||||
public:
|
||||
struct Entry {
|
||||
le_uint16_t atp; // attack power
|
||||
le_uint16_t psv; // perseverance (intelligence?)
|
||||
le_uint16_t evp; // evasion
|
||||
le_uint16_t hp; // hit points
|
||||
le_uint16_t dfp; // defense
|
||||
le_uint16_t ata; // accuracy
|
||||
le_uint16_t lck; // luck
|
||||
le_uint16_t esp; // ???
|
||||
parray<uint8_t, 0x0C> unknown_a1;
|
||||
le_uint32_t experience;
|
||||
le_uint32_t difficulty;
|
||||
|
||||
std::string str() const;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Table {
|
||||
parray<parray<Entry, 0x60>, 4> difficulty;
|
||||
|
||||
void print(FILE* stream) const;
|
||||
} __attribute__((packed));
|
||||
|
||||
BattleParamsIndex(
|
||||
std::shared_ptr<const std::string> data_on_ep1, // BattleParamEntry_on.dat
|
||||
std::shared_ptr<const std::string> data_on_ep2, // BattleParamEntry_lab_on.dat
|
||||
std::shared_ptr<const std::string> data_on_ep4, // BattleParamEntry_ep4_on.dat
|
||||
std::shared_ptr<const std::string> data_off_ep1, // BattleParamEntry.dat
|
||||
std::shared_ptr<const std::string> data_off_ep2, // BattleParamEntry_lab.dat
|
||||
std::shared_ptr<const std::string> data_off_ep4); // BattleParamEntry_ep4.dat
|
||||
|
||||
const Entry& get(
|
||||
bool solo, Episode episode, uint8_t difficulty, EnemyType type) const;
|
||||
const Entry& get(
|
||||
bool solo, Episode episode, uint8_t difficulty, size_t entry_index) const;
|
||||
|
||||
private:
|
||||
struct LoadedFile {
|
||||
std::shared_ptr<const std::string> data;
|
||||
const Table* table;
|
||||
};
|
||||
|
||||
// online/offline, episode
|
||||
LoadedFile files[2][3];
|
||||
};
|
||||
+16
-20
@@ -8,8 +8,8 @@
|
||||
#include <event2/event.h>
|
||||
#include <event2/listener.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -24,29 +24,27 @@
|
||||
|
||||
#include "Loggers.hh"
|
||||
#include "PSOProtocol.hh"
|
||||
#include "SendCommands.hh"
|
||||
#include "ProxyCommands.hh"
|
||||
#include "ReceiveCommands.hh"
|
||||
#include "ReceiveSubcommands.hh"
|
||||
#include "ProxyCommands.hh"
|
||||
#include "SendCommands.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
CatSession::CatSession(
|
||||
shared_ptr<struct event_base> base,
|
||||
const struct sockaddr_storage& remote,
|
||||
GameVersion version,
|
||||
shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file)
|
||||
: Shell(base),
|
||||
log("[CatSession] ", proxy_server_log.min_level),
|
||||
channel(
|
||||
version,
|
||||
CatSession::dispatch_on_channel_input,
|
||||
CatSession::dispatch_on_channel_error,
|
||||
this,
|
||||
"CatSession"),
|
||||
bb_key_file(bb_key_file) {
|
||||
: Shell(base),
|
||||
log("[CatSession] ", proxy_server_log.min_level),
|
||||
channel(
|
||||
version,
|
||||
CatSession::dispatch_on_channel_input,
|
||||
CatSession::dispatch_on_channel_error,
|
||||
this,
|
||||
"CatSession"),
|
||||
bb_key_file(bb_key_file) {
|
||||
if (remote.ss_family != AF_INET) {
|
||||
throw runtime_error("remote is not AF_INET");
|
||||
}
|
||||
@@ -62,7 +60,7 @@ CatSession::CatSession(
|
||||
this->channel.set_bufferevent(bev);
|
||||
|
||||
if (bufferevent_socket_connect(this->channel.bev.get(),
|
||||
reinterpret_cast<const sockaddr*>(&remote), sizeof(struct sockaddr_in)) != 0) {
|
||||
reinterpret_cast<const sockaddr*>(&remote), sizeof(struct sockaddr_in)) != 0) {
|
||||
throw runtime_error(string_printf("failed to connect (%d)", EVUTIL_SOCKET_ERROR()));
|
||||
}
|
||||
}
|
||||
@@ -77,8 +75,7 @@ void CatSession::on_channel_input(
|
||||
uint16_t command, uint32_t flag, std::string& data) {
|
||||
if (this->channel.version != GameVersion::BB) {
|
||||
if (command == 0x02 || command == 0x17 || command == 0x91 || command == 0x9B) {
|
||||
const auto& cmd = check_size_t<S_ServerInitDefault_DC_PC_V3_02_17_91_9B>(data,
|
||||
sizeof(S_ServerInitDefault_DC_PC_V3_02_17_91_9B), 0xFFFF);
|
||||
const auto& cmd = check_size_t<S_ServerInitDefault_DC_PC_V3_02_17_91_9B>(data, 0xFFFF);
|
||||
if ((this->channel.version == GameVersion::GC) ||
|
||||
(this->channel.version == GameVersion::XB)) {
|
||||
this->channel.crypt_in.reset(new PSOV3Encryption(cmd.server_key));
|
||||
@@ -97,8 +94,7 @@ void CatSession::on_channel_input(
|
||||
if (!this->bb_key_file) {
|
||||
throw runtime_error("BB encryption requires a key file");
|
||||
}
|
||||
const auto& cmd = check_size_t<S_ServerInitDefault_BB_03_9B>(data,
|
||||
sizeof(S_ServerInitDefault_BB_03_9B), 0xFFFF);
|
||||
const auto& cmd = check_size_t<S_ServerInitDefault_BB_03_9B>(data, 0xFFFF);
|
||||
this->channel.crypt_in.reset(new PSOBBEncryption(*this->bb_key_file, &cmd.server_key[0], sizeof(cmd.server_key)));
|
||||
this->channel.crypt_out.reset(new PSOBBEncryption(*this->bb_key_file, &cmd.client_key[0], sizeof(cmd.client_key)));
|
||||
this->log.info("Enabled BB encryption");
|
||||
@@ -133,7 +129,7 @@ void CatSession::on_channel_error(short events) {
|
||||
}
|
||||
}
|
||||
|
||||
void CatSession::print_prompt() { }
|
||||
void CatSession::print_prompt() {}
|
||||
|
||||
void CatSession::execute_command(const std::string& command) {
|
||||
string full_cmd = parse_data_string(command, nullptr, ParseDataFlags::ALLOW_FILES);
|
||||
|
||||
+5
-7
@@ -2,22 +2,20 @@
|
||||
|
||||
#include <event2/event.h>
|
||||
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#include "PSOEncryption.hh"
|
||||
#include "PSOProtocol.hh"
|
||||
#include "ServerState.hh"
|
||||
#include "Shell.hh"
|
||||
|
||||
|
||||
|
||||
class CatSession : public Shell {
|
||||
public:
|
||||
CatSession(
|
||||
|
||||
+48
-46
@@ -1,9 +1,9 @@
|
||||
#include "Channel.hh"
|
||||
|
||||
#include <errno.h>
|
||||
#include <event2/buffer.h>
|
||||
#include <event2/bufferevent.h>
|
||||
#include <event2/event.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -15,19 +15,13 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
extern bool use_terminal_colors;
|
||||
|
||||
|
||||
|
||||
static void flush_and_free_bufferevent(struct bufferevent* bev) {
|
||||
bufferevent_flush(bev, EV_READ | EV_WRITE, BEV_FINISHED);
|
||||
bufferevent_free(bev);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Channel::Channel(
|
||||
GameVersion version,
|
||||
on_command_received_t on_command_received,
|
||||
@@ -36,14 +30,14 @@ Channel::Channel(
|
||||
const string& name,
|
||||
TerminalFormat terminal_send_color,
|
||||
TerminalFormat terminal_recv_color)
|
||||
: bev(nullptr, flush_and_free_bufferevent),
|
||||
version(version),
|
||||
name(name),
|
||||
terminal_send_color(terminal_send_color),
|
||||
terminal_recv_color(terminal_recv_color),
|
||||
on_command_received(on_command_received),
|
||||
on_error(on_error),
|
||||
context_obj(context_obj) {
|
||||
: bev(nullptr, flush_and_free_bufferevent),
|
||||
version(version),
|
||||
name(name),
|
||||
terminal_send_color(terminal_send_color),
|
||||
terminal_recv_color(terminal_recv_color),
|
||||
on_command_received(on_command_received),
|
||||
on_error(on_error),
|
||||
context_obj(context_obj) {
|
||||
}
|
||||
|
||||
Channel::Channel(
|
||||
@@ -55,14 +49,14 @@ Channel::Channel(
|
||||
const string& name,
|
||||
TerminalFormat terminal_send_color,
|
||||
TerminalFormat terminal_recv_color)
|
||||
: bev(nullptr, flush_and_free_bufferevent),
|
||||
version(version),
|
||||
name(name),
|
||||
terminal_send_color(terminal_send_color),
|
||||
terminal_recv_color(terminal_recv_color),
|
||||
on_command_received(on_command_received),
|
||||
on_error(on_error),
|
||||
context_obj(context_obj) {
|
||||
: bev(nullptr, flush_and_free_bufferevent),
|
||||
version(version),
|
||||
name(name),
|
||||
terminal_send_color(terminal_send_color),
|
||||
terminal_recv_color(terminal_recv_color),
|
||||
on_command_received(on_command_received),
|
||||
on_error(on_error),
|
||||
context_obj(context_obj) {
|
||||
this->set_bufferevent(bev);
|
||||
}
|
||||
|
||||
@@ -114,8 +108,6 @@ void Channel::set_bufferevent(struct bufferevent* bev) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Channel::disconnect() {
|
||||
if (this->bev.get()) {
|
||||
// If the output buffer is not empty, move the bufferevent into the draining
|
||||
@@ -157,15 +149,12 @@ void Channel::disconnect() {
|
||||
this->crypt_out.reset();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Channel::Message Channel::recv(bool print_contents) {
|
||||
struct evbuffer* buf = bufferevent_get_input(this->bev.get());
|
||||
|
||||
size_t header_size = (this->version == GameVersion::BB) ? 8 : 4;
|
||||
PSOCommandHeader header;
|
||||
if (evbuffer_copyout(buf, &header, header_size)
|
||||
< static_cast<ssize_t>(header_size)) {
|
||||
if (evbuffer_copyout(buf, &header, header_size) < static_cast<ssize_t>(header_size)) {
|
||||
throw out_of_range("no command available");
|
||||
}
|
||||
|
||||
@@ -179,7 +168,8 @@ Channel::Message Channel::recv(bool print_contents) {
|
||||
// is not reflected in the size field. This logic does not occur if encryption
|
||||
// is not yet enabled.
|
||||
size_t command_physical_size = (this->crypt_in.get() && (version == GameVersion::BB))
|
||||
? ((command_logical_size + 7) & ~7) : command_logical_size;
|
||||
? ((command_logical_size + 7) & ~7)
|
||||
: command_logical_size;
|
||||
if (evbuffer_get_length(buf) < command_physical_size) {
|
||||
throw out_of_range("no command available");
|
||||
}
|
||||
@@ -190,8 +180,7 @@ Channel::Message Channel::recv(bool print_contents) {
|
||||
// consistent state.
|
||||
|
||||
string header_data(header_size, '\0');
|
||||
if (evbuffer_remove(buf, header_data.data(), header_data.size())
|
||||
< static_cast<ssize_t>(header_data.size())) {
|
||||
if (evbuffer_remove(buf, header_data.data(), header_data.size()) < static_cast<ssize_t>(header_data.size())) {
|
||||
throw logic_error("enough bytes available, but could not remove them");
|
||||
}
|
||||
if (this->crypt_in.get()) {
|
||||
@@ -199,8 +188,7 @@ Channel::Message Channel::recv(bool print_contents) {
|
||||
}
|
||||
|
||||
string command_data(command_physical_size - header_size, '\0');
|
||||
if (evbuffer_remove(buf, command_data.data(), command_data.size())
|
||||
< static_cast<ssize_t>(command_data.size())) {
|
||||
if (evbuffer_remove(buf, command_data.data(), command_data.size()) < static_cast<ssize_t>(command_data.size())) {
|
||||
throw logic_error("enough bytes available, but could not remove them");
|
||||
}
|
||||
|
||||
@@ -222,12 +210,14 @@ Channel::Message Channel::recv(bool print_contents) {
|
||||
}
|
||||
|
||||
if (version == GameVersion::BB) {
|
||||
command_data_log.info("Received from %s (version=BB command=%04hX flag=%08" PRIX32 ")",
|
||||
command_data_log.info(
|
||||
"Received from %s (version=BB command=%04hX flag=%08" PRIX32 ")",
|
||||
this->name.c_str(),
|
||||
header.command(this->version),
|
||||
header.flag(this->version));
|
||||
} else {
|
||||
command_data_log.info("Received from %s (version=%s command=%02hX flag=%02" PRIX32 ")",
|
||||
command_data_log.info(
|
||||
"Received from %s (version=%s command=%02hX flag=%02" PRIX32 ")",
|
||||
this->name.c_str(),
|
||||
name_for_version(this->version),
|
||||
header.command(this->version),
|
||||
@@ -245,19 +235,27 @@ Channel::Message Channel::recv(bool print_contents) {
|
||||
}
|
||||
|
||||
return {
|
||||
.command = header.command(this->version),
|
||||
.flag = header.flag(this->version),
|
||||
.data = move(command_data),
|
||||
.command = header.command(this->version),
|
||||
.flag = header.flag(this->version),
|
||||
.data = std::move(command_data),
|
||||
};
|
||||
}
|
||||
|
||||
void Channel::send(uint16_t cmd, uint32_t flag, const void* data, size_t size,
|
||||
bool print_contents) {
|
||||
void Channel::send(uint16_t cmd, uint32_t flag, bool print_contents) {
|
||||
this->send(cmd, flag, nullptr, 0, print_contents);
|
||||
}
|
||||
|
||||
void Channel::send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<const void*, size_t>> blocks, bool print_contents) {
|
||||
if (!this->connected()) {
|
||||
channel_exceptions_log.warning("Attempted to send command on closed channel; dropping data");
|
||||
return;
|
||||
}
|
||||
|
||||
size_t size = 0;
|
||||
for (const auto& b : blocks) {
|
||||
size += b.second;
|
||||
}
|
||||
|
||||
string send_data;
|
||||
size_t logical_size;
|
||||
size_t send_data_size = 0;
|
||||
@@ -327,10 +325,11 @@ void Channel::send(uint16_t cmd, uint32_t flag, const void* data, size_t size,
|
||||
throw runtime_error("outbound command too large");
|
||||
}
|
||||
|
||||
if (send_data.size() < send_data_size) {
|
||||
send_data.append(reinterpret_cast<const char*>(data), size);
|
||||
send_data.resize(send_data_size, '\0');
|
||||
send_data.reserve(send_data_size);
|
||||
for (const auto& b : blocks) {
|
||||
send_data.append(reinterpret_cast<const char*>(b.first), b.second);
|
||||
}
|
||||
send_data.resize(send_data_size, '\0');
|
||||
|
||||
if (print_contents && (this->terminal_send_color != TerminalFormat::END)) {
|
||||
if (use_terminal_colors && this->terminal_send_color != TerminalFormat::NORMAL) {
|
||||
@@ -357,6 +356,11 @@ void Channel::send(uint16_t cmd, uint32_t flag, const void* data, size_t size,
|
||||
evbuffer_add(buf, send_data.data(), send_data.size());
|
||||
}
|
||||
|
||||
void Channel::send(
|
||||
uint16_t cmd, uint32_t flag, const void* data, size_t size, bool print_contents) {
|
||||
this->send(cmd, flag, {make_pair(data, size)}, print_contents);
|
||||
}
|
||||
|
||||
void Channel::send(uint16_t cmd, uint32_t flag, const string& data, bool print_contents) {
|
||||
this->send(cmd, flag, data.data(), data.size(), print_contents);
|
||||
}
|
||||
@@ -376,8 +380,6 @@ void Channel::send(const string& data, bool print_contents) {
|
||||
return this->send(data.data(), data.size(), print_contents);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Channel::dispatch_on_input(struct bufferevent*, void* ctx) {
|
||||
Channel* ch = reinterpret_cast<Channel*>(ctx);
|
||||
// The client can be disconnected during on_command_received, so we have to
|
||||
|
||||
+3
-3
@@ -9,8 +9,6 @@
|
||||
#include "PSOProtocol.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
|
||||
|
||||
struct Channel {
|
||||
std::unique_ptr<struct bufferevent, void (*)(struct bufferevent*)> bev;
|
||||
struct sockaddr_storage local_addr;
|
||||
@@ -80,7 +78,9 @@ struct Channel {
|
||||
Message recv(bool print_contents = true);
|
||||
|
||||
// Sends a message with an automatically-constructed header.
|
||||
void send(uint16_t cmd, uint32_t flag = 0, const void* data = nullptr, size_t size = 0, bool print_contents = true);
|
||||
void send(uint16_t cmd, uint32_t flag = 0, bool print_contents = true);
|
||||
void send(uint16_t cmd, uint32_t flag, const void* data, size_t size, bool print_contents = true);
|
||||
void send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<const void*, size_t>> blocks, bool print_contents = true);
|
||||
void send(uint16_t cmd, uint32_t flag, const std::string& data, bool print_contents = true);
|
||||
template <typename CmdT>
|
||||
void send(uint16_t cmd, uint32_t flag, const CmdT& data) {
|
||||
|
||||
+302
-206
@@ -2,12 +2,12 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <phosg/Random.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <phosg/Time.hh>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "Client.hh"
|
||||
#include "Lobby.hh"
|
||||
@@ -21,16 +21,12 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Checks
|
||||
|
||||
|
||||
|
||||
class precondition_failed {
|
||||
public:
|
||||
precondition_failed(const std::u16string& user_msg) : user_msg(user_msg) { }
|
||||
precondition_failed(const std::u16string& user_msg) : user_msg(user_msg) {}
|
||||
~precondition_failed() = default;
|
||||
|
||||
const std::u16string& what() const {
|
||||
@@ -64,22 +60,21 @@ static void check_not_version(shared_ptr<Client> c, GameVersion version) {
|
||||
|
||||
static void check_is_game(shared_ptr<Lobby> l, bool is_game) {
|
||||
if (l->is_game() != is_game) {
|
||||
throw precondition_failed(is_game ?
|
||||
u"$C6This command cannot\nbe used in lobbies." :
|
||||
u"$C6This command cannot\nbe used in games.");
|
||||
throw precondition_failed(is_game ? u"$C6This command cannot\nbe used in lobbies." : u"$C6This command cannot\nbe used in games.");
|
||||
}
|
||||
}
|
||||
|
||||
static void check_is_ep3(shared_ptr<Client> c, bool is_ep3) {
|
||||
if (!!(c->flags & Client::Flag::IS_EPISODE_3) != is_ep3) {
|
||||
throw precondition_failed(is_ep3 ?
|
||||
u"$C6This command can only\nbe used in Episode 3." :
|
||||
u"$C6This command cannot\nbe used in Episode 3.");
|
||||
throw precondition_failed(is_ep3 ? u"$C6This command can only\nbe used in Episode 3." : u"$C6This command cannot\nbe used in Episode 3.");
|
||||
}
|
||||
}
|
||||
|
||||
static void check_cheats_enabled(shared_ptr<Lobby> l) {
|
||||
if (!(l->flags & Lobby::Flag::CHEATS_ENABLED)) {
|
||||
static void check_cheats_enabled(shared_ptr<ServerState> s, shared_ptr<Lobby> l = nullptr) {
|
||||
if (s->cheat_mode_behavior == ServerState::CheatModeBehavior::OFF) {
|
||||
throw precondition_failed(u"$C6Cheats are disabled.");
|
||||
}
|
||||
if (l && !(l->flags & Lobby::Flag::CHEATS_ENABLED)) {
|
||||
throw precondition_failed(u"$C6This command can\nonly be used in\ncheat mode.");
|
||||
}
|
||||
}
|
||||
@@ -90,8 +85,6 @@ static void check_is_leader(shared_ptr<Lobby> l, shared_ptr<Client> c) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Message commands
|
||||
|
||||
@@ -106,7 +99,7 @@ static void server_command_lobby_info(shared_ptr<ServerState>, shared_ptr<Lobby>
|
||||
if (l->is_game()) {
|
||||
lines.emplace_back(string_printf("Game ID: $C6%08X$C7", l->lobby_id));
|
||||
|
||||
if (!(l->flags & Lobby::Flag::EPISODE_3_ONLY)) {
|
||||
if (!l->is_ep3()) {
|
||||
if (l->max_level == 0xFFFFFFFF) {
|
||||
lines.emplace_back(string_printf("Levels: $C6%d+$C7", l->min_level + 1));
|
||||
} else {
|
||||
@@ -142,7 +135,7 @@ static void server_command_lobby_info(shared_ptr<ServerState>, shared_ptr<Lobby>
|
||||
}
|
||||
}
|
||||
}
|
||||
lines.emplace_back(move(slots_str));
|
||||
lines.emplace_back(std::move(slots_str));
|
||||
}
|
||||
|
||||
send_text_message(c, decode_sjis(join(lines, "\n")));
|
||||
@@ -150,8 +143,15 @@ static void server_command_lobby_info(shared_ptr<ServerState>, shared_ptr<Lobby>
|
||||
|
||||
static void proxy_command_lobby_info(shared_ptr<ServerState>,
|
||||
ProxyServer::LinkedSession& session, const std::u16string&) {
|
||||
string msg = string_printf("$C7GC: $C6%" PRId64 "$C7\nSlots: ",
|
||||
session.remote_guild_card_number);
|
||||
string msg;
|
||||
// On non-masked-GC sessions (BB), there is no remote Guild Card number, so we
|
||||
// don't show it. (The user can see it in the pause menu, unlike in masked-GC
|
||||
// sessions like GC.)
|
||||
if (session.remote_guild_card_number >= 0) {
|
||||
msg = string_printf("$C7GC: $C6%" PRId64 "$C7\n",
|
||||
session.remote_guild_card_number);
|
||||
}
|
||||
msg += "Slots: ";
|
||||
|
||||
for (size_t z = 0; z < session.lobby_players.size(); z++) {
|
||||
bool is_self = z == session.lobby_client_id;
|
||||
@@ -234,18 +234,20 @@ static void proxy_command_arrow(shared_ptr<ServerState>,
|
||||
session.server_channel.send(0x89, stoull(encode_sjis(args), nullptr, 0));
|
||||
}
|
||||
|
||||
static void server_command_dbgid(shared_ptr<ServerState>, shared_ptr<Lobby>,
|
||||
static void server_command_debug(shared_ptr<ServerState>, shared_ptr<Lobby>,
|
||||
shared_ptr<Client> c, const std::u16string&) {
|
||||
c->options.prefer_high_lobby_client_id = !c->options.prefer_high_lobby_client_id;
|
||||
send_text_message_printf(c, "ID preference set\nto $C6%s",
|
||||
c->options.prefer_high_lobby_client_id ? "high" : "low");
|
||||
check_privileges(c, Privilege::DEBUG);
|
||||
c->options.debug = !c->options.debug;
|
||||
send_text_message_printf(c, "Debug %s",
|
||||
c->options.debug ? "enabled" : "disabled");
|
||||
}
|
||||
|
||||
static void server_command_auction(shared_ptr<ServerState>, shared_ptr<Lobby> l,
|
||||
shared_ptr<Client> c, const std::u16string&) {
|
||||
check_privileges(c, Privilege::DEBUG);
|
||||
if (l->is_game() && (l->flags & Lobby::Flag::EPISODE_3_ONLY)) {
|
||||
if (l->is_game() && l->is_ep3()) {
|
||||
G_InitiateCardAuction_GC_Ep3_6xB5x42 cmd;
|
||||
cmd.header.sender_client_id = c->lobby_client_id;
|
||||
send_command_t(l, 0xC9, 0x00, cmd);
|
||||
}
|
||||
}
|
||||
@@ -253,32 +255,82 @@ static void server_command_auction(shared_ptr<ServerState>, shared_ptr<Lobby> l,
|
||||
static void proxy_command_auction(shared_ptr<ServerState>,
|
||||
ProxyServer::LinkedSession& session, const std::u16string&) {
|
||||
G_InitiateCardAuction_GC_Ep3_6xB5x42 cmd;
|
||||
cmd.header.sender_client_id = session.lobby_client_id;
|
||||
session.client_channel.send(0xC9, 0x00, &cmd, sizeof(cmd));
|
||||
session.server_channel.send(0xC9, 0x00, &cmd, sizeof(cmd));
|
||||
}
|
||||
|
||||
static void server_command_patch(shared_ptr<ServerState> s, shared_ptr<Lobby>,
|
||||
shared_ptr<Client> c, const std::u16string& args) {
|
||||
std::shared_ptr<CompiledFunctionCode> fn;
|
||||
string basename = encode_sjis(args);
|
||||
try {
|
||||
fn = s->function_code_index->name_to_function.at(encode_sjis(args));
|
||||
send_function_call(c, fn);
|
||||
prepare_client_for_patches(s, c, [s, wc = weak_ptr<Client>(c), basename]() {
|
||||
auto c = wc.lock();
|
||||
if (!c) {
|
||||
return;
|
||||
}
|
||||
// Note: We can't look this up outside of the closure because
|
||||
// c->specific_version can change during prepare_client_for_patches
|
||||
auto fn = s->function_code_index->name_and_specific_version_to_patch_function.at(
|
||||
string_printf("%s-%08" PRIX32, basename.c_str(), c->specific_version));
|
||||
send_function_call(c, fn);
|
||||
c->function_call_response_queue.emplace_back(empty_function_call_response_handler);
|
||||
});
|
||||
} catch (const out_of_range&) {
|
||||
send_text_message(c, u"Invalid patch name");
|
||||
}
|
||||
}
|
||||
|
||||
static void empty_patch_return_handler(uint32_t, uint32_t) {}
|
||||
|
||||
static void proxy_command_patch(shared_ptr<ServerState> s,
|
||||
ProxyServer::LinkedSession& session, const std::u16string& args) {
|
||||
std::shared_ptr<CompiledFunctionCode> fn;
|
||||
try {
|
||||
fn = s->function_code_index->name_to_function.at(encode_sjis(args));
|
||||
|
||||
string basename = encode_sjis(args);
|
||||
auto send_call = [s, basename, &session](uint32_t specific_version, uint32_t) {
|
||||
try {
|
||||
if (session.newserv_client_config.cfg.specific_version != specific_version) {
|
||||
session.newserv_client_config.cfg.specific_version = specific_version;
|
||||
session.log.info("Version detected as %08" PRIX32, session.newserv_client_config.cfg.specific_version);
|
||||
}
|
||||
auto fn = s->function_code_index->name_and_specific_version_to_patch_function.at(
|
||||
string_printf("%s-%08" PRIX32, basename.c_str(), session.newserv_client_config.cfg.specific_version));
|
||||
send_function_call(
|
||||
session.client_channel, session.newserv_client_config.cfg.flags, fn);
|
||||
// Don't forward the patch response to the server
|
||||
session.function_call_return_handler_queue.emplace_back(empty_patch_return_handler);
|
||||
} catch (const out_of_range&) {
|
||||
send_text_message(session.client_channel, u"Invalid patch name");
|
||||
}
|
||||
};
|
||||
|
||||
auto send_version_detect_or_send_call = [s, basename, &session, send_call]() {
|
||||
if (session.version == GameVersion::GC &&
|
||||
session.newserv_client_config.cfg.specific_version == default_specific_version_for_version(GameVersion::GC, -1)) {
|
||||
send_function_call(
|
||||
session.client_channel,
|
||||
session.newserv_client_config.cfg.flags,
|
||||
s->function_code_index->name_to_function.at("VersionDetect"));
|
||||
session.function_call_return_handler_queue.emplace_back(send_call);
|
||||
} else {
|
||||
send_call(session.newserv_client_config.cfg.specific_version, 0);
|
||||
}
|
||||
};
|
||||
|
||||
// This mirrors the implementation in prepare_client_for_patches
|
||||
if (!(session.newserv_client_config.cfg.flags & Client::Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH)) {
|
||||
send_function_call(
|
||||
session.client_channel, session.newserv_client_config.cfg.flags, fn);
|
||||
// Don't forward the patch response to the server
|
||||
session.should_forward_function_call_return_queue.emplace_back(false);
|
||||
} catch (const out_of_range&) {
|
||||
send_text_message(session.client_channel, u"Invalid patch name");
|
||||
session.client_channel, session.newserv_client_config.cfg.flags, s->function_code_index->name_to_function.at("CacheClearFix-Phase1"), {}, "", 0, 0, 0x7F2734EC);
|
||||
session.function_call_return_handler_queue.emplace_back([s, session_p = &session, send_version_detect_or_send_call](uint32_t, uint32_t) -> void {
|
||||
send_function_call(
|
||||
session_p->client_channel, session_p->newserv_client_config.cfg.flags, s->function_code_index->name_to_function.at("CacheClearFix-Phase2"));
|
||||
session_p->function_call_return_handler_queue.emplace_back([session_p, send_version_detect_or_send_call](uint32_t, uint32_t) -> void {
|
||||
session_p->newserv_client_config.cfg.flags |= Client::Flag::SEND_FUNCTION_CALL_NO_CACHE_PATCH;
|
||||
send_version_detect_or_send_call();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
send_version_detect_or_send_call();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,6 +351,10 @@ static void server_command_exit(shared_ptr<ServerState> s, shared_ptr<Lobby> l,
|
||||
if (l->is_game()) {
|
||||
if (c->flags & Client::Flag::IS_EPISODE_3) {
|
||||
c->channel.send(0xED, 0x00);
|
||||
} else if (l->flags & (Lobby::Flag::QUEST_IN_PROGRESS | Lobby::Flag::JOINABLE_QUEST_IN_PROGRESS)) {
|
||||
G_UnusedHeader cmd = {0x73, 0x01, 0x0000};
|
||||
c->channel.send(0x60, 0x00, cmd);
|
||||
c->area = 0;
|
||||
} else {
|
||||
send_text_message(c, u"$C6You must return to\nthe lobby first");
|
||||
}
|
||||
@@ -320,11 +376,14 @@ static void proxy_command_exit(shared_ptr<ServerState>,
|
||||
if (session.is_in_game) {
|
||||
if (session.newserv_client_config.cfg.flags & Client::Flag::IS_EPISODE_3) {
|
||||
session.client_channel.send(0xED, 0x00);
|
||||
} else if (session.is_in_quest) {
|
||||
G_UnusedHeader cmd = {0x73, 0x01, 0x0000};
|
||||
session.client_channel.send(0x60, 0x00, cmd);
|
||||
} else {
|
||||
send_text_message(session.client_channel, u"$C6You must return to\nthe lobby first");
|
||||
}
|
||||
} else {
|
||||
session.close_on_disconnect = true;
|
||||
session.disconnect_action = ProxyServer::LinkedSession::DisconnectAction::CLOSE_IMMEDIATELY;
|
||||
session.send_to_game_server();
|
||||
}
|
||||
}
|
||||
@@ -362,34 +421,42 @@ static void proxy_command_get_player_card(shared_ptr<ServerState>,
|
||||
static void server_command_send_client(shared_ptr<ServerState>, shared_ptr<Lobby>,
|
||||
shared_ptr<Client> c, const std::u16string& args) {
|
||||
string data = parse_data_string(encode_sjis(args));
|
||||
data.resize((data.size() + 3) & (~3));
|
||||
c->channel.send(data);
|
||||
}
|
||||
|
||||
static void proxy_command_send_client(shared_ptr<ServerState>,
|
||||
ProxyServer::LinkedSession& session, const std::u16string& args) {
|
||||
string data = parse_data_string(encode_sjis(args));
|
||||
data.resize((data.size() + 3) & (~3));
|
||||
session.client_channel.send(data);
|
||||
}
|
||||
|
||||
static void proxy_command_send_server(shared_ptr<ServerState>,
|
||||
ProxyServer::LinkedSession& session, const std::u16string& args) {
|
||||
string data = parse_data_string(encode_sjis(args));
|
||||
data.resize((data.size() + 3) & (~3));
|
||||
session.server_channel.send(data);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Lobby commands
|
||||
|
||||
static void server_command_cheat(shared_ptr<ServerState>, shared_ptr<Lobby> l,
|
||||
static void server_command_cheat(shared_ptr<ServerState> s, shared_ptr<Lobby> l,
|
||||
shared_ptr<Client> c, const std::u16string&) {
|
||||
check_is_game(l, true);
|
||||
check_is_leader(l, c);
|
||||
|
||||
if (s->cheat_mode_behavior == ServerState::CheatModeBehavior::OFF) {
|
||||
send_text_message(c, u"$C6Cheat mode cannot\nbe enabled on this\nserver");
|
||||
return;
|
||||
}
|
||||
|
||||
l->flags ^= Lobby::Flag::CHEATS_ENABLED;
|
||||
send_text_message_printf(l, "Cheat mode %s",
|
||||
(l->flags & Lobby::Flag::CHEATS_ENABLED) ? "enabled" : "disabled");
|
||||
|
||||
// if cheat mode was disabled, turn off all the cheat features that were on
|
||||
// If cheat mode was disabled, turn off all the cheat features that were on
|
||||
if (!(l->flags & Lobby::Flag::CHEATS_ENABLED)) {
|
||||
for (size_t x = 0; x < l->max_clients; x++) {
|
||||
auto c = l->clients[x];
|
||||
@@ -428,7 +495,8 @@ static void proxy_command_lobby_event(shared_ptr<ServerState>,
|
||||
send_text_message(session.client_channel, u"$C6No such lobby event.");
|
||||
} else {
|
||||
session.options.override_lobby_event = new_event;
|
||||
if ((session.version == GameVersion::GC && !(session.newserv_client_config.cfg.flags & Client::Flag::IS_TRIAL_EDITION)) ||
|
||||
// This command is supported on all V3 versions except Ep1&2 Trial
|
||||
if ((session.version == GameVersion::GC && !(session.newserv_client_config.cfg.flags & Client::Flag::IS_GC_TRIAL_EDITION)) ||
|
||||
(session.version == GameVersion::XB) ||
|
||||
(session.version == GameVersion::BB)) {
|
||||
session.client_channel.send(0xDA, session.options.override_lobby_event);
|
||||
@@ -469,7 +537,7 @@ static void server_command_lobby_type(shared_ptr<ServerState>, shared_ptr<Lobby>
|
||||
}
|
||||
|
||||
l->type = new_type;
|
||||
if (l->type < ((l->flags & Lobby::Flag::EPISODE_3_ONLY) ? 20 : 15)) {
|
||||
if (l->type < (l->is_ep3() ? 20 : 15)) {
|
||||
l->type = l->block - 1;
|
||||
}
|
||||
|
||||
@@ -511,7 +579,7 @@ static void server_command_playrec(shared_ptr<ServerState> s, shared_ptr<Lobby>
|
||||
if (l->battle_player) {
|
||||
l->battle_player->start();
|
||||
} else {
|
||||
uint32_t flags = Lobby::Flag::NON_V1_ONLY | Lobby::Flag::EPISODE_3_ONLY | Lobby::Flag::IS_SPECTATOR_TEAM;
|
||||
uint32_t flags = Lobby::Flag::NON_V1_ONLY | Lobby::Flag::IS_SPECTATOR_TEAM;
|
||||
string filename = encode_sjis(args);
|
||||
if (filename[0] == '!') {
|
||||
flags |= Lobby::Flag::START_BATTLE_PLAYER_IMMEDIATELY;
|
||||
@@ -521,7 +589,8 @@ static void server_command_playrec(shared_ptr<ServerState> s, shared_ptr<Lobby>
|
||||
shared_ptr<Episode3::BattleRecord> record(new Episode3::BattleRecord(data));
|
||||
shared_ptr<Episode3::BattleRecordPlayer> battle_player(
|
||||
new Episode3::BattleRecordPlayer(record, s->game_server->get_base()));
|
||||
create_game_generic(s, c, args.c_str(), u"", 0xFF, 0, flags, nullptr, battle_player);
|
||||
create_game_generic(s, c, args.c_str(), u"", Episode::EP3, GameMode::NORMAL,
|
||||
0, flags, nullptr, battle_player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -608,7 +677,7 @@ static void server_command_spec(shared_ptr<ServerState>, shared_ptr<Lobby> l,
|
||||
check_is_game(l, true);
|
||||
check_is_leader(l, c);
|
||||
check_is_ep3(c, true);
|
||||
if (!(l->flags & Lobby::Flag::EPISODE_3_ONLY)) {
|
||||
if (!l->is_ep3()) {
|
||||
throw logic_error("Episode 3 client in non-Episode 3 game");
|
||||
}
|
||||
|
||||
@@ -667,51 +736,51 @@ static void server_command_edit(shared_ptr<ServerState> s, shared_ptr<Lobby> l,
|
||||
|
||||
try {
|
||||
if (tokens.at(0) == "atp") {
|
||||
c->game_data.player()->disp.stats.atp = stoul(tokens.at(1));
|
||||
c->game_data.player()->disp.stats.char_stats.atp = stoul(tokens.at(1));
|
||||
} else if (tokens.at(0) == "mst") {
|
||||
c->game_data.player()->disp.stats.mst = stoul(tokens.at(1));
|
||||
c->game_data.player()->disp.stats.char_stats.mst = stoul(tokens.at(1));
|
||||
} else if (tokens.at(0) == "evp") {
|
||||
c->game_data.player()->disp.stats.evp = stoul(tokens.at(1));
|
||||
c->game_data.player()->disp.stats.char_stats.evp = stoul(tokens.at(1));
|
||||
} else if (tokens.at(0) == "hp") {
|
||||
c->game_data.player()->disp.stats.hp = stoul(tokens.at(1));
|
||||
c->game_data.player()->disp.stats.char_stats.hp = stoul(tokens.at(1));
|
||||
} else if (tokens.at(0) == "dfp") {
|
||||
c->game_data.player()->disp.stats.dfp = stoul(tokens.at(1));
|
||||
c->game_data.player()->disp.stats.char_stats.dfp = stoul(tokens.at(1));
|
||||
} else if (tokens.at(0) == "ata") {
|
||||
c->game_data.player()->disp.stats.ata = stoul(tokens.at(1));
|
||||
c->game_data.player()->disp.stats.char_stats.ata = stoul(tokens.at(1));
|
||||
} else if (tokens.at(0) == "lck") {
|
||||
c->game_data.player()->disp.stats.lck = stoul(tokens.at(1));
|
||||
c->game_data.player()->disp.stats.char_stats.lck = stoul(tokens.at(1));
|
||||
} else if (tokens.at(0) == "meseta") {
|
||||
c->game_data.player()->disp.meseta = stoul(tokens.at(1));
|
||||
c->game_data.player()->disp.stats.meseta = stoul(tokens.at(1));
|
||||
} else if (tokens.at(0) == "exp") {
|
||||
c->game_data.player()->disp.experience = stoul(tokens.at(1));
|
||||
c->game_data.player()->disp.stats.experience = stoul(tokens.at(1));
|
||||
} else if (tokens.at(0) == "level") {
|
||||
c->game_data.player()->disp.level = stoul(tokens.at(1)) - 1;
|
||||
c->game_data.player()->disp.stats.level = stoul(tokens.at(1)) - 1;
|
||||
} else if (tokens.at(0) == "namecolor") {
|
||||
uint32_t new_color;
|
||||
sscanf(tokens.at(1).c_str(), "%8X", &new_color);
|
||||
c->game_data.player()->disp.name_color = new_color;
|
||||
c->game_data.player()->disp.visual.name_color = new_color;
|
||||
} else if (tokens.at(0) == "secid") {
|
||||
uint8_t secid = section_id_for_name(decode_sjis(tokens.at(1)));
|
||||
if (secid == 0xFF) {
|
||||
send_text_message(c, u"$C6No such section ID");
|
||||
return;
|
||||
} else {
|
||||
c->game_data.player()->disp.section_id = secid;
|
||||
c->game_data.player()->disp.visual.section_id = secid;
|
||||
}
|
||||
} else if (tokens.at(0) == "name") {
|
||||
c->game_data.player()->disp.name = add_language_marker(tokens.at(1), 'J');
|
||||
} else if (tokens.at(0) == "npc") {
|
||||
if (tokens.at(1) == "none") {
|
||||
c->game_data.player()->disp.extra_model = 0;
|
||||
c->game_data.player()->disp.v2_flags &= 0xFD;
|
||||
c->game_data.player()->disp.visual.extra_model = 0;
|
||||
c->game_data.player()->disp.visual.v2_flags &= 0xFD;
|
||||
} else {
|
||||
uint8_t npc = npc_for_name(decode_sjis(tokens.at(1)));
|
||||
if (npc == 0xFF) {
|
||||
send_text_message(c, u"$C6No such NPC");
|
||||
return;
|
||||
}
|
||||
c->game_data.player()->disp.extra_model = npc;
|
||||
c->game_data.player()->disp.v2_flags |= 0x02;
|
||||
c->game_data.player()->disp.visual.extra_model = npc;
|
||||
c->game_data.player()->disp.visual.v2_flags |= 0x02;
|
||||
}
|
||||
} else if (tokens.at(0) == "tech") {
|
||||
uint8_t level = stoul(tokens.at(2)) - 1;
|
||||
@@ -747,13 +816,11 @@ static void server_command_edit(shared_ptr<ServerState> s, shared_ptr<Lobby> l,
|
||||
s->send_lobby_join_notifications(l, c);
|
||||
}
|
||||
|
||||
// TODO: implement this
|
||||
// TODO: make sure the bank name is filesystem-safe
|
||||
// TODO: implement this (and make sure the bank name is filesystem-safe)
|
||||
/* static void server_command_change_bank(shared_ptr<ServerState>, shared_ptr<Lobby>,
|
||||
shared_ptr<Client> c, const std::u16string&) {
|
||||
check_version(c, GameVersion::BB);
|
||||
|
||||
TODO
|
||||
...
|
||||
} */
|
||||
|
||||
// TODO: This can be implemented on the proxy server too.
|
||||
@@ -876,7 +943,8 @@ static void server_command_ban(shared_ptr<ServerState> s, shared_ptr<Lobby> l,
|
||||
uint64_t usecs = stoull(encode_sjis(args), nullptr, 0) * 1000000;
|
||||
|
||||
size_t unit_offset = 0;
|
||||
for (; isdigit(args[unit_offset]); unit_offset++);
|
||||
for (; isdigit(args[unit_offset]); unit_offset++)
|
||||
;
|
||||
if (args[unit_offset] == 'm') {
|
||||
usecs *= 60;
|
||||
} else if (args[unit_offset] == 'h') {
|
||||
@@ -891,8 +959,6 @@ static void server_command_ban(shared_ptr<ServerState> s, shared_ptr<Lobby> l,
|
||||
usecs *= 60 * 60 * 24 * 365;
|
||||
}
|
||||
|
||||
// TODO: put the length of time in this message. or don't; presumably the
|
||||
// person deserved it
|
||||
s->license_manager->ban_until(target->license->serial_number, now() + usecs);
|
||||
send_message_box(target, u"$C6You were banned by a moderator.");
|
||||
target->should_disconnect = true;
|
||||
@@ -903,80 +969,95 @@ static void server_command_ban(shared_ptr<ServerState> s, shared_ptr<Lobby> l,
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Cheat commands
|
||||
|
||||
static void server_command_warp(shared_ptr<ServerState>, shared_ptr<Lobby> l,
|
||||
shared_ptr<Client> c, const std::u16string& args) {
|
||||
static void server_command_warp(
|
||||
shared_ptr<ServerState> s, shared_ptr<Lobby> l, shared_ptr<Client> c, const std::u16string& args, bool is_warpall) {
|
||||
check_is_game(l, true);
|
||||
check_cheats_enabled(l);
|
||||
check_cheats_enabled(s, l);
|
||||
|
||||
uint32_t area = stoul(encode_sjis(args), nullptr, 0);
|
||||
if (!l->episode || (l->episode > 3)) {
|
||||
return;
|
||||
}
|
||||
if (c->area == area) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((l->episode == 1) && (area > 17)) {
|
||||
send_text_message(c, u"$C6Area numbers must be\n17 or less.");
|
||||
size_t limit = area_limit_for_episode(l->episode);
|
||||
if (limit == 0) {
|
||||
return;
|
||||
}
|
||||
if ((l->episode == 2) && (area > 17)) {
|
||||
send_text_message(c, u"$C6Area numbers must be\n17 or less.");
|
||||
return;
|
||||
}
|
||||
if ((l->episode == 3) && (area > 10)) {
|
||||
send_text_message(c, u"$C6Area numbers must be\n10 or less.");
|
||||
} else if (area > limit) {
|
||||
send_text_message_printf(c, "$C6Area numbers must\nbe %zu or less.", limit);
|
||||
return;
|
||||
}
|
||||
|
||||
send_warp(c, area);
|
||||
if (is_warpall) {
|
||||
send_warp(l, area, false);
|
||||
} else {
|
||||
send_warp(c, area, true);
|
||||
}
|
||||
}
|
||||
|
||||
static void proxy_command_warp(shared_ptr<ServerState>,
|
||||
ProxyServer::LinkedSession& session, const std::u16string& args) {
|
||||
static void server_command_warpme(
|
||||
shared_ptr<ServerState> s, shared_ptr<Lobby> l, shared_ptr<Client> c, const std::u16string& args) {
|
||||
server_command_warp(s, l, c, args, false);
|
||||
}
|
||||
|
||||
static void server_command_warpall(
|
||||
shared_ptr<ServerState> s, shared_ptr<Lobby> l, shared_ptr<Client> c, const std::u16string& args) {
|
||||
server_command_warp(s, l, c, args, true);
|
||||
}
|
||||
|
||||
static void proxy_command_warp(
|
||||
shared_ptr<ServerState> s, ProxyServer::LinkedSession& session, const std::u16string& args, bool is_warpall) {
|
||||
check_cheats_enabled(s);
|
||||
if (!session.is_in_game) {
|
||||
send_text_message(session.client_channel, u"$C6You must be in a\ngame to use this\ncommand");
|
||||
return;
|
||||
}
|
||||
uint32_t area = stoul(encode_sjis(args), nullptr, 0);
|
||||
send_warp(session.client_channel, session.lobby_client_id, area);
|
||||
send_warp(session.client_channel, session.lobby_client_id, area, !is_warpall);
|
||||
if (is_warpall) {
|
||||
send_warp(session.server_channel, session.lobby_client_id, area, false);
|
||||
}
|
||||
session.area = area;
|
||||
}
|
||||
|
||||
static void server_command_next(shared_ptr<ServerState>, shared_ptr<Lobby> l,
|
||||
shared_ptr<Client> c, const std::u16string&) {
|
||||
check_is_game(l, true);
|
||||
check_cheats_enabled(l);
|
||||
|
||||
if (!l->episode || (l->episode > 3)) {
|
||||
throw runtime_error("invalid episode number");
|
||||
}
|
||||
|
||||
uint8_t new_area = c->area + 1;
|
||||
if (((l->episode == 1) && (new_area > 17)) ||
|
||||
((l->episode == 2) && (new_area > 17)) ||
|
||||
((l->episode == 3) && (new_area > 10))) {
|
||||
new_area = 0;
|
||||
}
|
||||
|
||||
send_warp(c, new_area);
|
||||
static void proxy_command_warpme(
|
||||
shared_ptr<ServerState> s, ProxyServer::LinkedSession& session, const std::u16string& args) {
|
||||
proxy_command_warp(s, session, args, false);
|
||||
}
|
||||
|
||||
static void proxy_command_next(shared_ptr<ServerState>,
|
||||
ProxyServer::LinkedSession& session, const std::u16string&) {
|
||||
static void proxy_command_warpall(
|
||||
shared_ptr<ServerState> s, ProxyServer::LinkedSession& session, const std::u16string& args) {
|
||||
proxy_command_warp(s, session, args, true);
|
||||
}
|
||||
|
||||
static void server_command_next(shared_ptr<ServerState> s, shared_ptr<Lobby> l,
|
||||
shared_ptr<Client> c, const std::u16string&) {
|
||||
check_is_game(l, true);
|
||||
check_cheats_enabled(s, l);
|
||||
|
||||
size_t limit = area_limit_for_episode(l->episode);
|
||||
if (limit == 0) {
|
||||
return;
|
||||
}
|
||||
send_warp(c, (c->area + 1) % limit, true);
|
||||
}
|
||||
|
||||
static void proxy_command_next(
|
||||
shared_ptr<ServerState> s, ProxyServer::LinkedSession& session, const std::u16string&) {
|
||||
check_cheats_enabled(s);
|
||||
if (!session.is_in_game) {
|
||||
send_text_message(session.client_channel, u"$C6You must be in a\ngame to use this\ncommand");
|
||||
return;
|
||||
}
|
||||
|
||||
session.area++;
|
||||
send_warp(session.client_channel, session.lobby_client_id, session.area);
|
||||
send_warp(session.client_channel, session.lobby_client_id, session.area, true);
|
||||
}
|
||||
|
||||
static void server_command_what(shared_ptr<ServerState>, shared_ptr<Lobby> l,
|
||||
shared_ptr<Client> c, const std::u16string&) {
|
||||
check_is_game(l, true);
|
||||
if (!l->episode || (l->episode > 3)) {
|
||||
|
||||
if (!episode_has_arpg_semantics(l->episode)) {
|
||||
return;
|
||||
}
|
||||
if (!(l->flags & Lobby::Flag::ITEM_TRACKING_ENABLED)) {
|
||||
@@ -1001,7 +1082,7 @@ static void server_command_what(shared_ptr<ServerState>, shared_ptr<Lobby> l,
|
||||
send_text_message(c, u"$C4No items are near you");
|
||||
} else {
|
||||
const auto& item = l->item_id_to_floor_item.at(nearest_item_id);
|
||||
string name = name_for_item(item.inv_item.data, true);
|
||||
string name = item.inv_item.data.name(true);
|
||||
send_text_message(c, decode_sjis(name));
|
||||
}
|
||||
}
|
||||
@@ -1025,90 +1106,87 @@ static void proxy_command_song(shared_ptr<ServerState>,
|
||||
send_ep3_change_music(session.client_channel, song);
|
||||
}
|
||||
|
||||
static void server_command_infinite_hp(shared_ptr<ServerState>, shared_ptr<Lobby> l,
|
||||
shared_ptr<Client> c, const std::u16string&) {
|
||||
static void server_command_infinite_hp(
|
||||
shared_ptr<ServerState> s, shared_ptr<Lobby> l, shared_ptr<Client> c, const std::u16string&) {
|
||||
check_is_game(l, true);
|
||||
check_cheats_enabled(l);
|
||||
check_cheats_enabled(s, l);
|
||||
|
||||
c->options.infinite_hp = !c->options.infinite_hp;
|
||||
send_text_message_printf(c, "$C6Infinite HP %s",
|
||||
c->options.infinite_hp ? "enabled" : "disabled");
|
||||
}
|
||||
|
||||
static void proxy_command_infinite_hp(shared_ptr<ServerState>,
|
||||
ProxyServer::LinkedSession& session, const std::u16string&) {
|
||||
static void proxy_command_infinite_hp(
|
||||
shared_ptr<ServerState> s, ProxyServer::LinkedSession& session, const std::u16string&) {
|
||||
check_cheats_enabled(s);
|
||||
session.options.infinite_hp = !session.options.infinite_hp;
|
||||
send_text_message_printf(session.client_channel, "$C6Infinite HP %s",
|
||||
session.options.infinite_hp ? "enabled" : "disabled");
|
||||
}
|
||||
|
||||
static void server_command_infinite_tp(shared_ptr<ServerState>, shared_ptr<Lobby> l,
|
||||
shared_ptr<Client> c, const std::u16string&) {
|
||||
static void server_command_infinite_tp(
|
||||
shared_ptr<ServerState> s, shared_ptr<Lobby> l, shared_ptr<Client> c, const std::u16string&) {
|
||||
check_is_game(l, true);
|
||||
check_cheats_enabled(l);
|
||||
check_cheats_enabled(s, l);
|
||||
|
||||
c->options.infinite_tp = !c->options.infinite_tp;
|
||||
send_text_message_printf(c, "$C6Infinite TP %s",
|
||||
c->options.infinite_tp ? "enabled" : "disabled");
|
||||
}
|
||||
|
||||
static void proxy_command_infinite_tp(shared_ptr<ServerState>,
|
||||
ProxyServer::LinkedSession& session, const std::u16string&) {
|
||||
static void proxy_command_infinite_tp(
|
||||
shared_ptr<ServerState> s, ProxyServer::LinkedSession& session, const std::u16string&) {
|
||||
check_cheats_enabled(s);
|
||||
session.options.infinite_tp = !session.options.infinite_tp;
|
||||
send_text_message_printf(session.client_channel, "$C6Infinite TP %s",
|
||||
session.options.infinite_tp ? "enabled" : "disabled");
|
||||
}
|
||||
|
||||
static void server_command_switch_assist(shared_ptr<ServerState>, shared_ptr<Lobby> l,
|
||||
shared_ptr<Client> c, const std::u16string&) {
|
||||
static void server_command_switch_assist(
|
||||
shared_ptr<ServerState> s, shared_ptr<Lobby> l, shared_ptr<Client> c, const std::u16string&) {
|
||||
check_is_game(l, true);
|
||||
check_cheats_enabled(l);
|
||||
check_cheats_enabled(s, l);
|
||||
|
||||
c->options.switch_assist = !c->options.switch_assist;
|
||||
send_text_message_printf(c, "$C6Switch assist %s",
|
||||
c->options.switch_assist ? "enabled" : "disabled");
|
||||
}
|
||||
|
||||
static void proxy_command_switch_assist(shared_ptr<ServerState>,
|
||||
ProxyServer::LinkedSession& session, const std::u16string&) {
|
||||
static void proxy_command_switch_assist(
|
||||
shared_ptr<ServerState> s, ProxyServer::LinkedSession& session, const std::u16string&) {
|
||||
check_cheats_enabled(s);
|
||||
session.options.switch_assist = !session.options.switch_assist;
|
||||
send_text_message_printf(session.client_channel, "$C6Switch assist %s",
|
||||
session.options.switch_assist ? "enabled" : "disabled");
|
||||
}
|
||||
|
||||
static void server_command_item(shared_ptr<ServerState>, shared_ptr<Lobby> l,
|
||||
shared_ptr<Client> c, const std::u16string& args) {
|
||||
static void server_command_drop(shared_ptr<ServerState>, shared_ptr<Lobby> l,
|
||||
shared_ptr<Client> c, const std::u16string&) {
|
||||
check_is_game(l, true);
|
||||
check_cheats_enabled(l);
|
||||
check_is_leader(l, c);
|
||||
l->flags ^= Lobby::Flag::DROPS_ENABLED;
|
||||
send_text_message_printf(l, "Drops %s", (l->flags & Lobby::Flag::DROPS_ENABLED) ? "enabled" : "disabled");
|
||||
}
|
||||
|
||||
string data = parse_data_string(encode_sjis(args));
|
||||
if (data.size() < 2) {
|
||||
send_text_message(c, u"$C6Item codes must be\n2 bytes or more");
|
||||
return;
|
||||
}
|
||||
if (data.size() > 16) {
|
||||
send_text_message(c, u"$C6Item codes must be\n16 bytes or fewer");
|
||||
return;
|
||||
}
|
||||
static void server_command_item(
|
||||
shared_ptr<ServerState> s, shared_ptr<Lobby> l, shared_ptr<Client> c, const std::u16string& args) {
|
||||
check_is_game(l, true);
|
||||
check_cheats_enabled(s, l);
|
||||
|
||||
PlayerInventoryItem item;
|
||||
item.data = ItemData(encode_sjis(args));
|
||||
item.data.id = l->generate_item_id(c->lobby_client_id);
|
||||
if (data.size() <= 12) {
|
||||
memcpy(&item.data.data1, data.data(), data.size());
|
||||
} else {
|
||||
memcpy(&item.data.data1, data.data(), 12);
|
||||
memcpy(&item.data.data2, data.data() + 12, data.size() - 12);
|
||||
}
|
||||
|
||||
l->add_item(item, c->area, c->x, c->z);
|
||||
send_drop_stacked_item(l, item.data, c->area, c->x, c->z);
|
||||
|
||||
string name = name_for_item(item.data, true);
|
||||
string name = item.data.name(true);
|
||||
send_text_message(c, u"$C7Item created:\n" + decode_sjis(name));
|
||||
}
|
||||
|
||||
static void proxy_command_item(shared_ptr<ServerState>,
|
||||
ProxyServer::LinkedSession& session, const std::u16string& args) {
|
||||
static void proxy_command_item(
|
||||
shared_ptr<ServerState> s, ProxyServer::LinkedSession& session, const std::u16string& args) {
|
||||
check_cheats_enabled(s);
|
||||
if (session.version == GameVersion::BB) {
|
||||
send_text_message(session.client_channel,
|
||||
u"$C6This command cannot\nbe used on the proxy\nserver in BB games");
|
||||
@@ -1127,41 +1205,59 @@ static void proxy_command_item(shared_ptr<ServerState>,
|
||||
|
||||
bool set_drop = (!args.empty() && (args[0] == u'!'));
|
||||
|
||||
string data = parse_data_string(encode_sjis(args));
|
||||
if (data.size() < 2) {
|
||||
send_text_message(session.client_channel, u"$C6Item codes must be\n2 bytes or more");
|
||||
return;
|
||||
}
|
||||
if (data.size() > 16) {
|
||||
send_text_message(session.client_channel, u"$C6Item codes must be\n16 bytes or fewer");
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerInventoryItem item;
|
||||
item.data = ItemData(encode_sjis(set_drop ? args.substr(1) : args));
|
||||
item.data.id = random_object<uint32_t>();
|
||||
if (data.size() <= 12) {
|
||||
memcpy(&item.data.data1, data.data(), data.size());
|
||||
} else {
|
||||
memcpy(&item.data.data1, data.data(), 12);
|
||||
memcpy(&item.data.data2, data.data() + 12, data.size() - 12);
|
||||
}
|
||||
|
||||
if (set_drop) {
|
||||
session.next_drop_item = item;
|
||||
|
||||
string name = name_for_item(session.next_drop_item.data, true);
|
||||
string name = session.next_drop_item.data.name(true);
|
||||
send_text_message(session.client_channel, u"$C7Next drop:\n" + decode_sjis(name));
|
||||
|
||||
} else {
|
||||
send_drop_stacked_item(session.client_channel, item.data, session.area, session.x, session.z);
|
||||
send_drop_stacked_item(session.server_channel, item.data, session.area, session.x, session.z);
|
||||
|
||||
string name = name_for_item(item.data, true);
|
||||
string name = item.data.name(true);
|
||||
send_text_message(session.client_channel, u"$C7Item created:\n" + decode_sjis(name));
|
||||
}
|
||||
}
|
||||
|
||||
static void server_command_enable_ep3_battle_debug_menu(
|
||||
shared_ptr<ServerState>, shared_ptr<Lobby> l, shared_ptr<Client> c, const std::u16string& args) {
|
||||
if (!c->options.debug) {
|
||||
send_text_message(l, u"$C6This command can only\nbe run in debug mode\n(run %sdebug first)");
|
||||
return;
|
||||
}
|
||||
|
||||
check_is_game(l, true);
|
||||
check_is_ep3(c, true);
|
||||
if (l->episode != Episode::EP3) {
|
||||
throw logic_error("non-Ep3 client in Ep3 game");
|
||||
}
|
||||
auto base = l->ep3_server_base;
|
||||
if (!base) {
|
||||
send_text_message(l, u"$C6Episode 3 server\nis not initialized");
|
||||
return;
|
||||
}
|
||||
auto server = base->server;
|
||||
if (!server) {
|
||||
send_text_message(l, u"$C6Episode 3 server\nis not initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args.empty()) {
|
||||
server->override_environment_number = stoul(encode_sjis(args), nullptr, 16);
|
||||
send_text_message_printf(l, "$C6Override environment\nnumber set to %02hhX", server->override_environment_number);
|
||||
} else if (server->override_environment_number == 0xFF) {
|
||||
server->override_environment_number = 0x1A;
|
||||
send_text_message(l, u"$C6Battle setup debug\nmenu enabled");
|
||||
} else {
|
||||
server->override_environment_number = 0xFF;
|
||||
send_text_message(l, u"$C6Battle setup debug\nmenu disabled");
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1172,51 +1268,51 @@ typedef void (*proxy_handler_t)(shared_ptr<ServerState>,
|
||||
struct ChatCommandDefinition {
|
||||
server_handler_t server_handler;
|
||||
proxy_handler_t proxy_handler;
|
||||
u16string usage;
|
||||
};
|
||||
|
||||
static const unordered_map<u16string, ChatCommandDefinition> chat_commands({
|
||||
// TODO: implement command_help and actually use the usage strings here
|
||||
{u"$allevent", {server_command_lobby_event_all, nullptr, u"Usage:\nallevent <name/ID>"}},
|
||||
{u"$ann", {server_command_announce, nullptr, u"Usage:\nann <message>"}},
|
||||
{u"$arrow", {server_command_arrow, proxy_command_arrow, u"Usage:\narrow <color>"}},
|
||||
{u"$auction", {server_command_auction, proxy_command_auction, u"Usage:\nauction"}},
|
||||
{u"$ax", {server_command_ax, nullptr, u"Usage:\nax <message>"}},
|
||||
{u"$ban", {server_command_ban, nullptr, u"Usage:\nban <name-or-number>"}},
|
||||
// TODO: implement this on proxy server
|
||||
{u"$bbchar", {server_command_convert_char_to_bb, nullptr, u"Usage:\nbbchar <user> <pass> <1-4>"}},
|
||||
{u"$cheat", {server_command_cheat, nullptr, u"Usage:\ncheat"}},
|
||||
{u"$dbgid", {server_command_dbgid, nullptr, u"Usage:\ndbgid"}},
|
||||
{u"$edit", {server_command_edit, nullptr , u"Usage:\nedit <stat> <value>"}},
|
||||
{u"$event", {server_command_lobby_event, proxy_command_lobby_event, u"Usage:\nevent <name>"}},
|
||||
{u"$exit", {server_command_exit, proxy_command_exit, u"Usage:\nexit"}},
|
||||
{u"$gc", {server_command_get_self_card, proxy_command_get_player_card, u"Usage:\ngc"}},
|
||||
{u"$infhp", {server_command_infinite_hp, proxy_command_infinite_hp, u"Usage:\ninfhp"}},
|
||||
{u"$inftp", {server_command_infinite_tp, proxy_command_infinite_tp, u"Usage:\ninftp"}},
|
||||
{u"$item", {server_command_item, proxy_command_item, u"Usage:\nitem <item-code>"}},
|
||||
{u"$i", {server_command_item, proxy_command_item, u"Usage:\ni <item-code>"}},
|
||||
{u"$kick", {server_command_kick, nullptr, u"Usage:\nkick <name-or-number>"}},
|
||||
{u"$li", {server_command_lobby_info, proxy_command_lobby_info, u"Usage:\nli"}},
|
||||
{u"$maxlevel", {server_command_max_level, nullptr, u"Usage:\nmax_level <level>"}},
|
||||
{u"$minlevel", {server_command_min_level, nullptr, u"Usage:\nmin_level <level>"}},
|
||||
{u"$next", {server_command_next, proxy_command_next, u"Usage:\nnext"}},
|
||||
{u"$password", {server_command_password, nullptr, u"Usage:\nlock [password]\nomit password to\nunlock game"}},
|
||||
{u"$patch", {server_command_patch, proxy_command_patch, u"Usage:\npatch <name>"}},
|
||||
{u"$persist", {server_command_persist, nullptr, u"Usage:\npersist"}},
|
||||
{u"$playrec", {server_command_playrec, nullptr, u"Usage:\nplayrec <filename>"}},
|
||||
{u"$rand", {server_command_rand, proxy_command_rand, u"Usage:\nrand [hex seed]\nomit seed to revert\nto default"}},
|
||||
{u"$saverec", {server_command_saverec, nullptr, u"Usage:\nsaverec <filename>"}},
|
||||
{u"$sc", {server_command_send_client, proxy_command_send_client, u"Usage:\nsc <data>"}},
|
||||
{u"$secid", {server_command_secid, proxy_command_secid, u"Usage:\nsecid [section ID]\nomit section ID to\nrevert to normal"}},
|
||||
{u"$silence", {server_command_silence, nullptr, u"Usage:\nsilence <name-or-number>"}},
|
||||
// TODO: implement this on proxy server
|
||||
{u"$song", {server_command_song, proxy_command_song, u"Usage:\nsong <song-number>"}},
|
||||
{u"$spec", {server_command_spec, nullptr, u"Usage:\nspec"}},
|
||||
{u"$ss", {nullptr, proxy_command_send_server, u"Usage:\nss <data>"}},
|
||||
{u"$swa", {server_command_switch_assist, proxy_command_switch_assist, u"Usage:\nswa"}},
|
||||
{u"$type", {server_command_lobby_type, nullptr, u"Usage:\ntype <name>"}},
|
||||
{u"$warp", {server_command_warp, proxy_command_warp, u"Usage:\nwarp <area-number>"}},
|
||||
{u"$what", {server_command_what, nullptr, u"Usage:\nwhat"}},
|
||||
{u"$allevent", {server_command_lobby_event_all, nullptr}},
|
||||
{u"$ann", {server_command_announce, nullptr}},
|
||||
{u"$arrow", {server_command_arrow, proxy_command_arrow}},
|
||||
{u"$auction", {server_command_auction, proxy_command_auction}},
|
||||
{u"$ax", {server_command_ax, nullptr}},
|
||||
{u"$ban", {server_command_ban, nullptr}},
|
||||
{u"$bbchar", {server_command_convert_char_to_bb, nullptr}},
|
||||
{u"$cheat", {server_command_cheat, nullptr}},
|
||||
{u"$debug", {server_command_debug, nullptr}},
|
||||
{u"$drop", {server_command_drop, nullptr}},
|
||||
{u"$edit", {server_command_edit, nullptr}},
|
||||
{u"$event", {server_command_lobby_event, proxy_command_lobby_event}},
|
||||
{u"$exit", {server_command_exit, proxy_command_exit}},
|
||||
{u"$gc", {server_command_get_self_card, proxy_command_get_player_card}},
|
||||
{u"$infhp", {server_command_infinite_hp, proxy_command_infinite_hp}},
|
||||
{u"$inftp", {server_command_infinite_tp, proxy_command_infinite_tp}},
|
||||
{u"$item", {server_command_item, proxy_command_item}},
|
||||
{u"$i", {server_command_item, proxy_command_item}},
|
||||
{u"$kick", {server_command_kick, nullptr}},
|
||||
{u"$li", {server_command_lobby_info, proxy_command_lobby_info}},
|
||||
{u"$ep3battledebug", {server_command_enable_ep3_battle_debug_menu, nullptr}},
|
||||
{u"$maxlevel", {server_command_max_level, nullptr}},
|
||||
{u"$minlevel", {server_command_min_level, nullptr}},
|
||||
{u"$next", {server_command_next, proxy_command_next}},
|
||||
{u"$password", {server_command_password, nullptr}},
|
||||
{u"$patch", {server_command_patch, proxy_command_patch}},
|
||||
{u"$persist", {server_command_persist, nullptr}},
|
||||
{u"$playrec", {server_command_playrec, nullptr}},
|
||||
{u"$rand", {server_command_rand, proxy_command_rand}},
|
||||
{u"$saverec", {server_command_saverec, nullptr}},
|
||||
{u"$sc", {server_command_send_client, proxy_command_send_client}},
|
||||
{u"$secid", {server_command_secid, proxy_command_secid}},
|
||||
{u"$silence", {server_command_silence, nullptr}},
|
||||
{u"$song", {server_command_song, proxy_command_song}},
|
||||
{u"$spec", {server_command_spec, nullptr}},
|
||||
{u"$ss", {nullptr, proxy_command_send_server}},
|
||||
{u"$swa", {server_command_switch_assist, proxy_command_switch_assist}},
|
||||
{u"$type", {server_command_lobby_type, nullptr}},
|
||||
{u"$warp", {server_command_warpme, proxy_command_warpme}},
|
||||
{u"$warpme", {server_command_warpme, proxy_command_warpme}},
|
||||
{u"$warpall", {server_command_warpall, proxy_command_warpall}},
|
||||
{u"$what", {server_command_what, nullptr}},
|
||||
});
|
||||
|
||||
struct SplitCommand {
|
||||
|
||||
+2
-2
@@ -5,10 +5,10 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "ServerState.hh"
|
||||
#include "Lobby.hh"
|
||||
#include "Client.hh"
|
||||
#include "Lobby.hh"
|
||||
#include "ProxyServer.hh"
|
||||
#include "ServerState.hh"
|
||||
|
||||
void on_chat_command(std::shared_ptr<ServerState> s, std::shared_ptr<Lobby> l,
|
||||
std::shared_ptr<Client> c, const std::u16string& text);
|
||||
|
||||
+86
-57
@@ -1,9 +1,9 @@
|
||||
#include "Client.hh"
|
||||
|
||||
#include <errno.h>
|
||||
#include <event2/buffer.h>
|
||||
#include <event2/bufferevent.h>
|
||||
#include <event2/event.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -16,70 +16,66 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
const uint64_t CLIENT_CONFIG_MAGIC = 0x492A890E82AC9839;
|
||||
FileContentsCache client_options_cache(3600000000ULL);
|
||||
|
||||
static atomic<uint64_t> next_id(1);
|
||||
|
||||
|
||||
|
||||
ClientOptions::ClientOptions()
|
||||
: switch_assist(false),
|
||||
infinite_hp(false),
|
||||
infinite_tp(false),
|
||||
prefer_high_lobby_client_id(false),
|
||||
override_section_id(-1),
|
||||
override_lobby_event(-1),
|
||||
override_lobby_number(-1),
|
||||
override_random_seed(-1),
|
||||
save_files(false),
|
||||
enable_chat_commands(true),
|
||||
enable_chat_filter(true),
|
||||
suppress_remote_login(false),
|
||||
zero_remote_guild_card(false),
|
||||
ep3_infinite_meseta(false),
|
||||
red_name(false),
|
||||
blank_name(false),
|
||||
function_call_return_value(-1) { }
|
||||
|
||||
|
||||
: switch_assist(false),
|
||||
infinite_hp(false),
|
||||
infinite_tp(false),
|
||||
debug(false),
|
||||
override_section_id(-1),
|
||||
override_lobby_event(-1),
|
||||
override_lobby_number(-1),
|
||||
override_random_seed(-1),
|
||||
save_files(false),
|
||||
enable_chat_commands(true),
|
||||
enable_chat_filter(true),
|
||||
enable_player_notifications(false),
|
||||
suppress_client_pings(false),
|
||||
suppress_remote_login(false),
|
||||
zero_remote_guild_card(false),
|
||||
ep3_infinite_meseta(false),
|
||||
red_name(false),
|
||||
blank_name(false),
|
||||
function_call_return_value(-1) {}
|
||||
|
||||
Client::Client(
|
||||
struct bufferevent* bev,
|
||||
GameVersion version,
|
||||
ServerBehavior server_behavior)
|
||||
: id(next_id++),
|
||||
log("", client_log.min_level),
|
||||
bb_game_state(0),
|
||||
flags(flags_for_version(version, -1)),
|
||||
channel(bev, version, nullptr, nullptr, this, string_printf("C-%" PRIX64, this->id), TerminalFormat::FG_YELLOW, TerminalFormat::FG_GREEN),
|
||||
server_behavior(server_behavior),
|
||||
should_disconnect(false),
|
||||
should_send_to_lobby_server(false),
|
||||
should_send_to_proxy_server(false),
|
||||
proxy_destination_address(0),
|
||||
proxy_destination_port(0),
|
||||
x(0.0f),
|
||||
z(0.0f),
|
||||
area(0),
|
||||
lobby_id(0),
|
||||
lobby_client_id(0),
|
||||
lobby_arrow_color(0),
|
||||
preferred_lobby_id(-1),
|
||||
save_game_data_event(
|
||||
event_new(
|
||||
bufferevent_get_base(bev), -1, EV_TIMEOUT | EV_PERSIST,
|
||||
&Client::dispatch_save_game_data, this),
|
||||
event_free),
|
||||
card_battle_table_number(-1),
|
||||
card_battle_table_seat_number(0),
|
||||
card_battle_table_seat_state(0),
|
||||
next_exp_value(0),
|
||||
can_chat(true),
|
||||
pending_bb_save_player_index(0),
|
||||
dol_base_addr(0) {
|
||||
: id(next_id++),
|
||||
log(string_printf("[C-%" PRIX64 "] ", this->id), client_log.min_level),
|
||||
bb_game_state(0),
|
||||
flags(flags_for_version(version, -1)),
|
||||
specific_version(default_specific_version_for_version(version, -1)),
|
||||
channel(bev, version, nullptr, nullptr, this, string_printf("C-%" PRIX64, this->id), TerminalFormat::FG_YELLOW, TerminalFormat::FG_GREEN),
|
||||
server_behavior(server_behavior),
|
||||
should_disconnect(false),
|
||||
should_send_to_lobby_server(false),
|
||||
should_send_to_proxy_server(false),
|
||||
proxy_destination_address(0),
|
||||
proxy_destination_port(0),
|
||||
x(0.0f),
|
||||
z(0.0f),
|
||||
area(0),
|
||||
lobby_id(0),
|
||||
lobby_client_id(0),
|
||||
lobby_arrow_color(0),
|
||||
preferred_lobby_id(-1),
|
||||
save_game_data_event(
|
||||
event_new(
|
||||
bufferevent_get_base(bev), -1, EV_TIMEOUT | EV_PERSIST,
|
||||
&Client::dispatch_save_game_data, this),
|
||||
event_free),
|
||||
card_battle_table_number(-1),
|
||||
card_battle_table_seat_number(0),
|
||||
card_battle_table_seat_state(0),
|
||||
next_exp_value(0),
|
||||
can_chat(true),
|
||||
pending_bb_save_player_index(0),
|
||||
dol_base_addr(0) {
|
||||
this->last_switch_enabled_command.header.subcommand = 0;
|
||||
memset(&this->next_connection_addr, 0, sizeof(this->next_connection_addr));
|
||||
|
||||
@@ -87,6 +83,8 @@ Client::Client(
|
||||
struct timeval tv = usecs_to_timeval(60000000); // 1 minute
|
||||
event_add(this->save_game_data_event.get(), &tv);
|
||||
}
|
||||
|
||||
this->log.info("Created");
|
||||
}
|
||||
|
||||
Client::~Client() {
|
||||
@@ -96,6 +94,37 @@ Client::~Client() {
|
||||
this->log.warning(" %s", it.first.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
this->log.info("Deleted");
|
||||
}
|
||||
|
||||
QuestScriptVersion Client::quest_version() const {
|
||||
switch (this->version()) {
|
||||
case GameVersion::DC:
|
||||
if (this->flags & Flag::IS_DC_TRIAL_EDITION) {
|
||||
return QuestScriptVersion::DC_NTE;
|
||||
} else if (this->flags & Flag::IS_DC_V1) {
|
||||
return QuestScriptVersion::DC_V1;
|
||||
} else {
|
||||
return QuestScriptVersion::DC_V2;
|
||||
}
|
||||
case GameVersion::PC:
|
||||
return QuestScriptVersion::PC_V2;
|
||||
case GameVersion::GC:
|
||||
if (this->flags & Flag::IS_GC_TRIAL_EDITION) {
|
||||
return QuestScriptVersion::GC_NTE;
|
||||
} else if (this->flags & Flag::IS_EPISODE_3) {
|
||||
return QuestScriptVersion::GC_EP3;
|
||||
} else {
|
||||
return QuestScriptVersion::GC_V3;
|
||||
}
|
||||
case GameVersion::XB:
|
||||
return QuestScriptVersion::XB_V3;
|
||||
case GameVersion::BB:
|
||||
return QuestScriptVersion::BB_V4;
|
||||
default:
|
||||
throw logic_error("client\'s game version does not have a quest version");
|
||||
}
|
||||
}
|
||||
|
||||
void Client::set_license(shared_ptr<const License> l) {
|
||||
@@ -110,6 +139,7 @@ ClientConfig Client::export_config() const {
|
||||
ClientConfig cc;
|
||||
cc.magic = CLIENT_CONFIG_MAGIC;
|
||||
cc.flags = this->flags;
|
||||
cc.specific_version = this->specific_version;
|
||||
cc.proxy_destination_address = this->proxy_destination_address;
|
||||
cc.proxy_destination_port = this->proxy_destination_port;
|
||||
cc.unused.clear(0xFF);
|
||||
@@ -130,6 +160,7 @@ void Client::import_config(const ClientConfig& cc) {
|
||||
throw invalid_argument("invalid client config");
|
||||
}
|
||||
this->flags = cc.flags;
|
||||
this->specific_version = cc.specific_version;
|
||||
this->proxy_destination_address = cc.proxy_destination_address;
|
||||
this->proxy_destination_port = cc.proxy_destination_port;
|
||||
}
|
||||
@@ -140,8 +171,6 @@ void Client::import_config(const ClientConfigBB& cc) {
|
||||
this->game_data.bb_player_index = cc.bb_player_index;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Client::dispatch_save_game_data(evutil_socket_t, short, void* ctx) {
|
||||
reinterpret_cast<Client*>(ctx)->save_game_data();
|
||||
}
|
||||
|
||||
+51
-36
@@ -6,30 +6,26 @@
|
||||
|
||||
#include "Channel.hh"
|
||||
#include "CommandFormats.hh"
|
||||
#include "Episode3/BattleRecord.hh"
|
||||
#include "Episode3/Tournament.hh"
|
||||
#include "FileContentsCache.hh"
|
||||
#include "FunctionCompiler.hh"
|
||||
#include "License.hh"
|
||||
#include "PatchFileIndex.hh"
|
||||
#include "Player.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "PSOProtocol.hh"
|
||||
#include "PatchFileIndex.hh"
|
||||
#include "Player.hh"
|
||||
#include "QuestScript.hh"
|
||||
#include "Text.hh"
|
||||
#include "Episode3/BattleRecord.hh"
|
||||
#include "Episode3/Tournament.hh"
|
||||
|
||||
|
||||
|
||||
extern const uint64_t CLIENT_CONFIG_MAGIC;
|
||||
extern FileContentsCache client_options_cache;
|
||||
|
||||
|
||||
|
||||
struct ClientOptions {
|
||||
// Options used on both game and proxy server
|
||||
bool switch_assist;
|
||||
bool infinite_hp;
|
||||
bool infinite_tp;
|
||||
bool prefer_high_lobby_client_id;
|
||||
bool debug;
|
||||
int16_t override_section_id;
|
||||
int16_t override_lobby_event;
|
||||
int16_t override_lobby_number;
|
||||
@@ -39,6 +35,8 @@ struct ClientOptions {
|
||||
bool save_files;
|
||||
bool enable_chat_commands;
|
||||
bool enable_chat_filter;
|
||||
bool enable_player_notifications;
|
||||
bool suppress_client_pings;
|
||||
bool suppress_remote_login;
|
||||
bool zero_remote_guild_card;
|
||||
bool ep3_infinite_meseta;
|
||||
@@ -51,54 +49,67 @@ struct ClientOptions {
|
||||
|
||||
struct Client {
|
||||
enum Flag {
|
||||
// This flag has two meanings. If set on a client with GameVersion::DC, then
|
||||
// IS_DC_V1 is also set. In this case, the client is DC Network Trial
|
||||
// Edition, which uses several commands that no other version uses. If this
|
||||
// flag is set without IS_DC_V1, then the client is GC Episodes 1 & 2 Trial
|
||||
// Edition, and therefore uses V2 encryption instead of V3 encryption, and
|
||||
// doesn't support some commands.
|
||||
// Note that this flag is NOT set for Episode 3 Trial Edition clients, since
|
||||
// that version is similar enough to the release version of Episode 3 that
|
||||
// newserv does not have to change its behavior at all.
|
||||
IS_TRIAL_EDITION = 0x00002000,
|
||||
// Client is DC Network Trial Edition, which is missing a lot of features
|
||||
// and uses some different command numbers than any other version
|
||||
IS_DC_TRIAL_EDITION = 0x00002000,
|
||||
// A 90 01 command has been sent (which proto will send a 93 in response to,
|
||||
// and actual DCv1 will send a 92)
|
||||
CHECKED_FOR_DC_V1_PROTOTYPE = 0x00080000,
|
||||
// Client is DC v1 prototype
|
||||
IS_DC_V1_PROTOTYPE = 0x00040000,
|
||||
// Client is DC v1
|
||||
IS_DC_V1 = 0x00000010,
|
||||
IS_DC_V1 = 0x00000010,
|
||||
// Client is GC Episodes 1&2 Trial Edition, which is much more like PC than
|
||||
// actual GC Episodes 1&2 - it uses PC encryption and is missing most of the
|
||||
// features added in Episodes 1&2
|
||||
IS_GC_TRIAL_EDITION = 0x00200000,
|
||||
// Client is GC Episode 3 Trial Edition, which is fairly close to the final
|
||||
// Episode 3 build, but is missing a few commands that we'll have to avoid
|
||||
// sending
|
||||
IS_EP3_TRIAL_EDITION = 0x00400000,
|
||||
// For patch server clients, client is Blue Burst rather than PC
|
||||
IS_BB_PATCH = 0x00000001,
|
||||
IS_BB_PATCH = 0x00000001,
|
||||
// After joining a lobby, client will no longer send D6 commands when they
|
||||
// close message boxes
|
||||
NO_D6_AFTER_LOBBY = 0x00000002,
|
||||
NO_D6_AFTER_LOBBY = 0x00000002,
|
||||
// Client has the above flag and has already joined a lobby, or is not GC
|
||||
NO_D6 = 0x00000004,
|
||||
NO_D6 = 0x00000004,
|
||||
// Client is Episode 3, should be able to see CARD lobbies, and should only
|
||||
// be able to see/join games with the EPISODE_3_ONLY flag
|
||||
IS_EPISODE_3 = 0x00000008,
|
||||
IS_EPISODE_3 = 0x00000008,
|
||||
// Client disconnects if it receives B2 (send_function_call)
|
||||
NO_SEND_FUNCTION_CALL = 0x00000200,
|
||||
NO_SEND_FUNCTION_CALL = 0x00000200,
|
||||
// Client requires doubly-encrypted code section in send_function_call
|
||||
ENCRYPTED_SEND_FUNCTION_CALL = 0x00000800,
|
||||
ENCRYPTED_SEND_FUNCTION_CALL = 0x00000800,
|
||||
// Client supports send_function_call but does not actually run the code
|
||||
SEND_FUNCTION_CALL_CHECKSUM_ONLY = 0x00001000,
|
||||
SEND_FUNCTION_CALL_CHECKSUM_ONLY = 0x00001000,
|
||||
// Client supports send_function_call and clears its caches properly before
|
||||
// calling the function (so we don't need to patch it)
|
||||
SEND_FUNCTION_CALL_NO_CACHE_PATCH = 0x00020000,
|
||||
// Client is vulnerable to a buffer overflow that we can use to enable
|
||||
// send_function_call
|
||||
USE_OVERFLOW_FOR_SEND_FUNCTION_CALL = 0x00008000,
|
||||
|
||||
// Client is loading into a game
|
||||
LOADING = 0x00000020,
|
||||
LOADING = 0x00000020,
|
||||
// Client is loading a quest
|
||||
LOADING_QUEST = 0x00000040,
|
||||
LOADING_QUEST = 0x00000040,
|
||||
// Client is loading a joinable quest that has already started
|
||||
LOADING_RUNNING_QUEST = 0x00100000,
|
||||
// Client is waiting to join an Episode 3 card auction
|
||||
AWAITING_CARD_AUCTION = 0x00010000,
|
||||
AWAITING_CARD_AUCTION = 0x00010000,
|
||||
// Client is in the information menu (login server only)
|
||||
IN_INFORMATION_MENU = 0x00000080,
|
||||
IN_INFORMATION_MENU = 0x00000080,
|
||||
// Client is at the welcome message (login server only)
|
||||
AT_WELCOME_MESSAGE = 0x00000100,
|
||||
AT_WELCOME_MESSAGE = 0x00000100,
|
||||
// Client has already received a 97 (enable saves) command, so don't show
|
||||
// the programs menu anymore
|
||||
SAVE_ENABLED = 0x00000400,
|
||||
SAVE_ENABLED = 0x00000400,
|
||||
// Client has received newserv's Episode 3 card definitions, so don't send
|
||||
// them again
|
||||
HAS_EP3_CARD_DEFS = 0x00004000,
|
||||
HAS_EP3_CARD_DEFS = 0x00004000,
|
||||
|
||||
UNUSED_FLAG_BITS = 0xFF800000,
|
||||
};
|
||||
|
||||
uint64_t id;
|
||||
@@ -112,6 +123,7 @@ struct Client {
|
||||
// all of that space.
|
||||
uint8_t bb_game_state;
|
||||
uint32_t flags;
|
||||
uint32_t specific_version;
|
||||
|
||||
// Network
|
||||
Channel channel;
|
||||
@@ -137,11 +149,12 @@ struct Client {
|
||||
uint8_t lobby_arrow_color; // lobby arrow color ID
|
||||
int64_t preferred_lobby_id; // <0 = no preference
|
||||
ClientGameData game_data;
|
||||
std::unique_ptr<struct event, void(*)(struct event*)> save_game_data_event;
|
||||
std::unique_ptr<struct event, void (*)(struct event*)> save_game_data_event;
|
||||
int16_t card_battle_table_number;
|
||||
uint16_t card_battle_table_seat_number;
|
||||
uint16_t card_battle_table_seat_state;
|
||||
std::weak_ptr<Episode3::Tournament::Team> ep3_tournament_team;
|
||||
std::shared_ptr<const Menu> last_menu_sent;
|
||||
|
||||
// Miscellaneous (used by chat commands)
|
||||
uint32_t next_exp_value; // next EXP value to give
|
||||
@@ -149,6 +162,7 @@ struct Client {
|
||||
bool can_chat;
|
||||
std::string pending_bb_save_username;
|
||||
uint8_t pending_bb_save_player_index;
|
||||
std::deque<std::function<void(uint32_t, uint32_t)>> function_call_response_queue;
|
||||
|
||||
// File loading state
|
||||
uint32_t dol_base_addr;
|
||||
@@ -161,6 +175,7 @@ struct Client {
|
||||
inline GameVersion version() const {
|
||||
return this->channel.version;
|
||||
}
|
||||
QuestScriptVersion quest_version() const;
|
||||
|
||||
void set_license(std::shared_ptr<const License> l);
|
||||
|
||||
|
||||
+1254
-540
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,210 @@
|
||||
#include "CommonItemSet.hh"
|
||||
|
||||
#include "StaticGameData.hh"
|
||||
|
||||
CommonItemSet::CommonItemSet(shared_ptr<const string> data)
|
||||
: gsl(data, true) {}
|
||||
|
||||
const CommonItemSet::Table<true>& CommonItemSet::get_table(
|
||||
Episode episode, GameMode mode, uint8_t difficulty, uint8_t secid) const {
|
||||
// TODO: What should we do for Ep4?
|
||||
string filename = string_printf(
|
||||
"ItemPT%s%s%c%1d.rel",
|
||||
((mode == GameMode::CHALLENGE) ? "c" : ""),
|
||||
((episode == Episode::EP2) ? "l" : ""),
|
||||
tolower(abbreviation_for_difficulty(difficulty)),
|
||||
secid);
|
||||
auto data = this->gsl.get(filename);
|
||||
if (data.second < sizeof(Table<true>)) {
|
||||
throw runtime_error(string_printf(
|
||||
"ItemPT entry %s is too small (received %zX bytes, expected %zX bytes)",
|
||||
filename.c_str(), data.second, sizeof(Table<true>)));
|
||||
}
|
||||
return *reinterpret_cast<const Table<true>*>(data.first);
|
||||
}
|
||||
|
||||
RELFileSet::RELFileSet(std::shared_ptr<const std::string> data)
|
||||
: data(data),
|
||||
r(*this->data) {}
|
||||
|
||||
ArmorRandomSet::ArmorRandomSet(std::shared_ptr<const std::string> data)
|
||||
: RELFileSet(data) {
|
||||
// For some reason the footer tables are doubly indirect in this file
|
||||
uint32_t specs_offset_offset = this->r.pget_u32b(data->size() - 0x10);
|
||||
uint32_t specs_offset = this->r.pget_u32b(specs_offset_offset);
|
||||
this->tables = &this->r.pget<parray<TableSpec, 3>>(specs_offset);
|
||||
}
|
||||
|
||||
std::pair<const ArmorRandomSet::WeightTableEntry8*, size_t>
|
||||
ArmorRandomSet::get_armor_table(size_t index) const {
|
||||
return this->get_table<WeightTableEntry8>(this->tables->at(0), index);
|
||||
}
|
||||
|
||||
std::pair<const ArmorRandomSet::WeightTableEntry8*, size_t>
|
||||
ArmorRandomSet::get_shield_table(size_t index) const {
|
||||
return this->get_table<WeightTableEntry8>(this->tables->at(1), index);
|
||||
}
|
||||
|
||||
std::pair<const ArmorRandomSet::WeightTableEntry8*, size_t>
|
||||
ArmorRandomSet::get_unit_table(size_t index) const {
|
||||
return this->get_table<WeightTableEntry8>(this->tables->at(2), index);
|
||||
}
|
||||
|
||||
ToolRandomSet::ToolRandomSet(std::shared_ptr<const std::string> data)
|
||||
: RELFileSet(data) {
|
||||
uint32_t specs_offset = r.pget_u32b(data->size() - 0x10);
|
||||
this->common_recovery_table_spec = &r.pget<TableSpec>(r.pget_u32b(
|
||||
specs_offset));
|
||||
this->rare_recovery_table_spec = &r.pget<TableSpec>(
|
||||
r.pget_u32b(specs_offset + sizeof(uint32_t)),
|
||||
2 * sizeof(TableSpec));
|
||||
this->tech_disk_table_spec = this->rare_recovery_table_spec + 1;
|
||||
this->tech_disk_level_table_spec = &r.pget<TableSpec>(r.pget_u32b(
|
||||
specs_offset + 2 * sizeof(uint32_t)));
|
||||
}
|
||||
|
||||
pair<const uint8_t*, size_t> ToolRandomSet::get_common_recovery_table(
|
||||
size_t index) const {
|
||||
return this->get_table<uint8_t>(*this->common_recovery_table_spec, index);
|
||||
}
|
||||
|
||||
pair<const ToolRandomSet::WeightTableEntry8*, size_t>
|
||||
ToolRandomSet::get_rare_recovery_table(size_t index) const {
|
||||
return this->get_table<WeightTableEntry8>(*this->rare_recovery_table_spec, index);
|
||||
}
|
||||
|
||||
pair<const ToolRandomSet::WeightTableEntry8*, size_t>
|
||||
ToolRandomSet::get_tech_disk_table(size_t index) const {
|
||||
return this->get_table<WeightTableEntry8>(*this->tech_disk_table_spec, index);
|
||||
}
|
||||
|
||||
pair<const ToolRandomSet::TechDiskLevelEntry*, size_t>
|
||||
ToolRandomSet::get_tech_disk_level_table(size_t index) const {
|
||||
return this->get_table<TechDiskLevelEntry>(*this->tech_disk_level_table_spec, index);
|
||||
}
|
||||
|
||||
WeaponRandomSet::WeaponRandomSet(std::shared_ptr<const std::string> data)
|
||||
: RELFileSet(data) {
|
||||
uint32_t offsets_offset = this->r.pget_u32b(data->size() - 0x10);
|
||||
this->offsets = &this->r.pget<Offsets>(offsets_offset);
|
||||
}
|
||||
|
||||
std::pair<const WeaponRandomSet::WeightTableEntry8*, size_t>
|
||||
WeaponRandomSet::get_weapon_type_table(size_t index) const {
|
||||
const auto& spec = this->r.pget<TableSpec>(
|
||||
this->offsets->weapon_type_table + index * sizeof(TableSpec));
|
||||
const auto* data = &this->r.pget<WeightTableEntry8>(
|
||||
spec.offset, spec.entries_per_table * sizeof(WeightTableEntry8));
|
||||
return make_pair(data, spec.entries_per_table);
|
||||
}
|
||||
|
||||
const parray<WeaponRandomSet::WeightTableEntry32, 6>*
|
||||
WeaponRandomSet::get_bonus_type_table(size_t which, size_t index) const {
|
||||
uint32_t base_offset = which ? this->offsets->bonus_type_table2 : this->offsets->bonus_type_table1;
|
||||
return &this->r.pget<parray<WeightTableEntry32, 6>>(
|
||||
base_offset + sizeof(parray<WeightTableEntry32, 6>) * index);
|
||||
}
|
||||
|
||||
const WeaponRandomSet::RangeTableEntry*
|
||||
WeaponRandomSet::get_bonus_range(size_t which, size_t index) const {
|
||||
uint32_t base_offset = which ? this->offsets->bonus_range_table2 : this->offsets->bonus_range_table1;
|
||||
return &this->r.pget<RangeTableEntry>(
|
||||
base_offset + sizeof(RangeTableEntry) * index);
|
||||
}
|
||||
|
||||
const parray<WeaponRandomSet::WeightTableEntry32, 3>*
|
||||
WeaponRandomSet::get_special_mode_table(size_t index) const {
|
||||
return &this->r.pget<parray<WeightTableEntry32, 3>>(
|
||||
this->offsets->special_mode_table + sizeof(parray<WeightTableEntry32, 3>) * index);
|
||||
}
|
||||
|
||||
const WeaponRandomSet::RangeTableEntry*
|
||||
WeaponRandomSet::get_standard_grind_range(size_t index) const {
|
||||
return &this->r.pget<RangeTableEntry>(
|
||||
this->offsets->standard_grind_range_table + sizeof(RangeTableEntry) * index);
|
||||
}
|
||||
|
||||
const WeaponRandomSet::RangeTableEntry*
|
||||
WeaponRandomSet::get_favored_grind_range(size_t index) const {
|
||||
return &this->r.pget<RangeTableEntry>(
|
||||
this->offsets->favored_grind_range_table + sizeof(RangeTableEntry) * index);
|
||||
}
|
||||
|
||||
TekkerAdjustmentSet::TekkerAdjustmentSet(std::shared_ptr<const std::string> data)
|
||||
: data(data),
|
||||
r(*data) {
|
||||
this->offsets = &this->r.pget<Offsets>(this->r.pget_u32b(this->r.size() - 0x10));
|
||||
}
|
||||
|
||||
const ProbabilityTable<uint8_t, 100>& TekkerAdjustmentSet::get_table(
|
||||
std::array<ProbabilityTable<uint8_t, 100>, 10>& tables_default,
|
||||
std::array<ProbabilityTable<uint8_t, 100>, 10>& tables_favored,
|
||||
uint32_t offset_and_count_offset,
|
||||
bool favored,
|
||||
uint8_t section_id) const {
|
||||
if (section_id >= 10) {
|
||||
throw runtime_error("invalid section ID");
|
||||
}
|
||||
ProbabilityTable<uint8_t, 100>& table = favored ? tables_favored[section_id] : tables_default[section_id];
|
||||
if (table.count == 0) {
|
||||
uint32_t offset = r.pget_u32b(offset_and_count_offset);
|
||||
uint32_t count_per_section_id = r.pget_u32b(offset_and_count_offset + 4);
|
||||
auto* entries = &r.pget<DeltaProbabilityEntry>(offset, sizeof(DeltaProbabilityEntry) * count_per_section_id * 10);
|
||||
for (size_t z = count_per_section_id * section_id; z < count_per_section_id * (section_id + 1); z++) {
|
||||
size_t count = favored ? entries[z].count_favored : entries[z].count_default;
|
||||
for (size_t w = 0; w < count; w++) {
|
||||
table.push(entries[z].delta_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
const ProbabilityTable<uint8_t, 100>& TekkerAdjustmentSet::get_special_upgrade_prob_table(uint8_t section_id, bool favored) const {
|
||||
return this->get_table(
|
||||
this->special_upgrade_prob_tables_default,
|
||||
this->special_upgrade_prob_tables_favored,
|
||||
this->offsets->special_upgrade_prob_table_offset,
|
||||
favored, section_id);
|
||||
}
|
||||
|
||||
const ProbabilityTable<uint8_t, 100>& TekkerAdjustmentSet::get_grind_delta_prob_table(uint8_t section_id, bool favored) const {
|
||||
return this->get_table(
|
||||
this->grind_delta_prob_tables_default,
|
||||
this->grind_delta_prob_tables_favored,
|
||||
this->offsets->grind_delta_prob_table_offset,
|
||||
favored, section_id);
|
||||
}
|
||||
|
||||
const ProbabilityTable<uint8_t, 100>& TekkerAdjustmentSet::get_bonus_delta_prob_table(uint8_t section_id, bool favored) const {
|
||||
return this->get_table(
|
||||
this->bonus_delta_prob_tables_default,
|
||||
this->bonus_delta_prob_tables_favored,
|
||||
this->offsets->bonus_delta_prob_table_offset,
|
||||
favored, section_id);
|
||||
}
|
||||
|
||||
int8_t TekkerAdjustmentSet::get_luck(uint32_t start_offset, uint8_t delta_index) const {
|
||||
StringReader sub_r = r.sub(start_offset);
|
||||
while (!sub_r.eof()) {
|
||||
const auto& entry = sub_r.get<LuckTableEntry>();
|
||||
if (entry.delta_index == 0xFF) {
|
||||
return 0;
|
||||
} else if (entry.delta_index == delta_index) {
|
||||
return entry.luck;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int8_t TekkerAdjustmentSet::get_luck_for_special_upgrade(uint8_t delta_index) const {
|
||||
return this->get_luck(this->offsets->special_upgrade_luck_table_offset, delta_index);
|
||||
}
|
||||
|
||||
int8_t TekkerAdjustmentSet::get_luck_for_grind_delta(uint8_t delta_index) const {
|
||||
return this->get_luck(this->offsets->grind_delta_luck_table_offset, delta_index);
|
||||
}
|
||||
|
||||
int8_t TekkerAdjustmentSet::get_luck_for_bonus_delta(uint8_t delta_index) const {
|
||||
return this->get_luck(this->offsets->bonus_delta_luck_offset, delta_index);
|
||||
}
|
||||
+515
-172
@@ -2,204 +2,547 @@
|
||||
|
||||
#include <phosg/Encoding.hh>
|
||||
|
||||
#include "GSLArchive.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
// Note: There are clearly better ways of doing this, but this implementation
|
||||
// closely follows what the original code in the client does.
|
||||
template <typename ItemT, size_t MaxCount>
|
||||
struct ProbabilityTable {
|
||||
ItemT items[MaxCount];
|
||||
size_t count;
|
||||
|
||||
ProbabilityTable() : count(0) {}
|
||||
|
||||
// This file describes the structure of PSO GC ItemPT.gsl entries.
|
||||
// TODO: This is not (yet) used anywhere in newserv, but we can use it as a base
|
||||
// for PSOBB common item generation. Implement this.
|
||||
void push(ItemT item) {
|
||||
if (this->count == MaxCount) {
|
||||
throw runtime_error("push to full probability table");
|
||||
}
|
||||
this->items[this->count++] = item;
|
||||
}
|
||||
|
||||
// The ItemPT structure below describes the format of a single ItemPT entry
|
||||
// (which corresponds to a single difficulty, episode, section ID, and challenge
|
||||
// flag). ItemPT entries (within ItemPT.gsl) are named like this:
|
||||
// string_printf("ItemPT_%s%s%c%1d.rel",
|
||||
// (is_challenge ? "c" : ""),
|
||||
// (is_ep2 ? "l" : ""),
|
||||
// char_for_difficulty(difficulty), // One of "nhvu"
|
||||
// section_id);
|
||||
ItemT pop() {
|
||||
if (this->count == 0) {
|
||||
throw runtime_error("pop from empty probability table");
|
||||
}
|
||||
return this->items[--this->count];
|
||||
}
|
||||
|
||||
template <typename IntT>
|
||||
struct Range {
|
||||
IntT low;
|
||||
IntT high;
|
||||
} __attribute__((packed));
|
||||
void shuffle(PSOLFGEncryption& random_crypt) {
|
||||
for (size_t z = 1; z < this->count; z++) {
|
||||
size_t other_z = random_crypt.next() % (z + 1);
|
||||
ItemT t = this->items[z];
|
||||
this->items[z] = this->items[other_z];
|
||||
this->items[other_z] = t;
|
||||
}
|
||||
}
|
||||
|
||||
// For GC, use be_uint16_t/be_uint32_t; for other platforms use the le variants
|
||||
template <typename U16T, U32T>
|
||||
struct ItemPT {
|
||||
// This data structure uses index probability tables in multiple places. An
|
||||
// index probability table is a table where each entry holds the probability
|
||||
// that that entry's index is used. For example, if the armor slot count
|
||||
// probability table contains [77, 17, 5, 1, 0], this means there is a 77%
|
||||
// chance of no slots, 17% chance of 1 slot, 5% chance of 2 slots, 1% chance
|
||||
// of 3 slots, and no chance of 4 slots. The values in index probability
|
||||
// tables do not have to add up to 100; the game sums all of them and chooses
|
||||
// a random number less than that maximum.
|
||||
ItemT sample(PSOLFGEncryption& random_crypt) const {
|
||||
if (this->count == 0) {
|
||||
throw runtime_error("pop from empty probability table");
|
||||
} else if (this->count == 1) {
|
||||
return this->items[0];
|
||||
} else {
|
||||
return this->items[random_crypt.next() % this->count];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// The area (floor) number is used in many places as well. Unlike the normal
|
||||
// area numbers, which start with Pioneer 2, the area numbers in this
|
||||
// structure start with Forest 1, and boss areas are treated as the first area
|
||||
// of the next section (so De Rol Le has Mines 1 drops, for example). Final
|
||||
// boss areas are treated as the last non-boss area (so Dark Falz boxes are
|
||||
// like Ruins 3 boxes). We refer to these adjusted area numbers as (area - 1).
|
||||
class CommonItemSet {
|
||||
public:
|
||||
template <typename IntT>
|
||||
struct Range {
|
||||
IntT min;
|
||||
IntT max;
|
||||
} __attribute__((packed));
|
||||
|
||||
// This index probability table determines the types of non-rare weapons. The
|
||||
// indexes in this table correspond to the non-rare weapon types 01 through 0C
|
||||
// (Saber through Wand).
|
||||
/* 0000 */ parray<uint8_t, 0x0C> base_weapon_type_prob_table;
|
||||
// The Table structure below describes the format of a single ItemPT entry
|
||||
// (which corresponds to a single difficulty, episode, section ID, and
|
||||
// challenge flag). ItemPT entries (within ItemPT.gsl) are named like this:
|
||||
// string_printf("ItemPT%s%s%c%1d.rel",
|
||||
// (is_challenge ? "c" : ""),
|
||||
// (is_ep2 ? "l" : ""),
|
||||
// char_for_difficulty(difficulty), // One of "nhvu"
|
||||
// section_id);
|
||||
template <bool IsBigEndian>
|
||||
struct Table {
|
||||
using U16T = typename std::conditional<IsBigEndian, be_uint16_t, le_uint16_t>::type;
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
// This data structure uses index probability tables in multiple places. An
|
||||
// index probability table is a table where each entry holds the probability
|
||||
// that that entry's index is used. For example, if the armor slot count
|
||||
// probability table contains [77, 17, 5, 1, 0], this means there is a 77%
|
||||
// chance of no slots, 17% chance of 1 slot, 5% chance of 2 slots, 1% chance
|
||||
// of 3 slots, and no chance of 4 slots. The values in index probability
|
||||
// tables do not have to add up to 100; the game sums all of them and
|
||||
// chooses a random number less than that maximum.
|
||||
|
||||
// This table specifies the base subtype for each weapon type. Negative values
|
||||
// here mean that the weapon cannot be found in the first N areas (so -2, for
|
||||
// example, means that the weapon never appears in Forest 1 or 2 at all).
|
||||
// Nonnegative values here mean the subtype can be found in all areas, and
|
||||
// specify the base subtype (usually in the range [0, 4]). The subtype of
|
||||
// weapon that actually appears depends on this value and a value from the
|
||||
// following table.
|
||||
/* 000C */ parray<int8_t, 0x0C> subtype_base_table;
|
||||
// The area (floor) number is used in many places as well. Unlike the normal
|
||||
// area numbers, which start with Pioneer 2, the area numbers in this
|
||||
// structure start with Forest 1, and boss areas are treated as the first
|
||||
// area of the next section (so De Rol Le has Mines 1 drops, for example).
|
||||
// Final boss areas are treated as the last non-boss area (so Dark Falz
|
||||
// boxes are like Ruins 3 boxes). We refer to these adjusted area numbers as
|
||||
// (area - 1).
|
||||
|
||||
// This table specifies how many areas each weapon subtype appears in. For
|
||||
// example, if Sword (subtype 02, which is index 1 in this table and the table
|
||||
// above) has a subtype base of -2 and a subtype area lneght of 4, then Sword
|
||||
// items can be found when area - 1 is 2, 3, 4, or 5 (Cave 1 through Mine 1),
|
||||
// and Gigush (the next sword subtype) can be found in Mine 1 through Ruins 3.
|
||||
/* 0018 */ parray<uint8_t, 0x0C> subtype_area_length_table;
|
||||
// This index probability table determines the types of non-rare weapons.
|
||||
// The indexes in this table correspond to the non-rare weapon types 01
|
||||
// through 0C (Saber through Wand).
|
||||
/* 0000 */ parray<uint8_t, 0x0C> base_weapon_type_prob_table;
|
||||
|
||||
// This index probability table specifies how likely each possible grind value
|
||||
// is. The table is indexed as [grind][subtype_area_index], where the subtype
|
||||
// area index is how many areas the player is beyond the first area in which
|
||||
// the subtype can first be found (clamped to [0, 3]). To continue the example
|
||||
// above, in Cave 3, subtype_area_index would be 2, since Swords can first be
|
||||
// found two areas earlier in Cave 1.
|
||||
// For example, this table could look like this:
|
||||
// [64 1E 19 14] // Chance of getting a grind +0
|
||||
// [00 1E 17 0F] // Chance of getting a grind +1
|
||||
// [00 14 14 0E] // Chance of getting a grind +2
|
||||
// ...
|
||||
// C1 C2 C3 M1 // (Episode 1 area values from the example, for reference)
|
||||
/* 0024 */ parray<parray<uint8_t, 4>, 9> grind_prob_tables;
|
||||
// This table specifies the base subtype for each weapon type. Negative
|
||||
// values here mean that the weapon cannot be found in the first N areas (so
|
||||
// -2, for example, means that the weapon never appears in Forest 1 or 2 at
|
||||
// all). Nonnegative values here mean the subtype can be found in all areas,
|
||||
// and specify the base subtype (usually in the range [0, 4]). The subtype
|
||||
// of weapon that actually appears depends on this value and a value from
|
||||
// the following table.
|
||||
/* 000C */ parray<int8_t, 0x0C> subtype_base_table;
|
||||
|
||||
// This array specifies the chance that a rare weapon will have each possible
|
||||
// bonus value. The table is indexed as [(bonus_value - 10 / 5)][spec], so the
|
||||
// first row refers the probability of getting a -10% bonus, the next row is
|
||||
// the chance of getting -5%, etc., all the way up to +100%. For non-rare
|
||||
// items, spec is determined randomly based on the following field; for rare
|
||||
// items, spec is always 5.
|
||||
/* 0048 */ parray<parray<U16T, 6>, 0x17> bonus_value_prob_tables;
|
||||
// This table specifies how many areas each weapon subtype appears in. For
|
||||
// example, if Sword (subtype 02, which is index 1 in this table and the
|
||||
// table above) has a subtype base of -2 and a subtype area lneght of 4,
|
||||
// then Sword items can be found when area - 1 is 2, 3, 4, or 5 (Cave 1
|
||||
// through Mine 1), and Gigush (the next sword subtype) can be found in Mine
|
||||
// 1 through Ruins 3.
|
||||
/* 0018 */ parray<uint8_t, 0x0C> subtype_area_length_table;
|
||||
|
||||
// This array specifies the value of spec to be used in the above lookup for
|
||||
// non-rare items. This is NOT an index probability table; this is a direct
|
||||
// lookup with indexes [bonus_index][area - 1]. A value of 0xFF in any byte of
|
||||
// this array prevents any weapon from having a bonus in that slot.
|
||||
// For example, the array might look like this:
|
||||
// [00 00 00 01 01 01 01 02 02 02]
|
||||
// [FF FF FF 00 00 00 01 01 01 01]
|
||||
// [FF FF FF FF FF FF FF FF FF 00]
|
||||
// F1 F2 C1 C2 C3 M1 M2 R1 R2 R3 // (Episode 1 areas, for reference)
|
||||
// In this example, spec is 0, 1, or 2 in all cases where a weapon can have a
|
||||
// bonus. In Forest 1 and 2 and Cave 1, weapons may have at most one bonus; in
|
||||
// all other areas except Ruins 3, they can have at most two bonuses, and in
|
||||
// Ruins 3, they can have up to three bonuses.
|
||||
/* 015C */ parray<parray<uint8_t, 10>, 3> nonrare_bonus_prob_spec;
|
||||
// This index probability table specifies how likely each possible grind
|
||||
// value is. The table is indexed as [grind][subtype_area_index], where the
|
||||
// subtype area index is how many areas the player is beyond the first area
|
||||
// in which the subtype can first be found (clamped to [0, 3]). To continue
|
||||
// the example above, in Cave 3, subtype_area_index would be 2, since Swords
|
||||
// can first be found two areas earlier in Cave 1.
|
||||
// For example, this table could look like this:
|
||||
// [64 1E 19 14] // Chance of getting a grind +0
|
||||
// [00 1E 17 0F] // Chance of getting a grind +1
|
||||
// [00 14 14 0E] // Chance of getting a grind +2
|
||||
// ...
|
||||
// C1 C2 C3 M1 // (Episode 1 area values from the example for reference)
|
||||
/* 0024 */ parray<parray<uint8_t, 4>, 9> grind_prob_tables;
|
||||
|
||||
// This array specifies the chance that a weapon will have each bonus type.
|
||||
// The table is indexed as [bonus_type][area - 1] for non-rare items; for rare
|
||||
// items, a random value in the range [0, 9] is used instead of (area - 1).
|
||||
// For example, the table might look like this:
|
||||
// [46 46 3F 3E 3E 3D 3C 3C 3A 3A] // Chance of getting no bonus
|
||||
// [14 14 0A 0A 09 02 02 04 05 05] // Chance of getting Native bonus
|
||||
// [0A 0A 12 11 11 09 09 08 08 08] // Chance of getting A.Beast bonus
|
||||
// [00 00 09 0A 0B 13 12 08 09 09] // Chance of getting Machine bonus
|
||||
// [00 00 00 01 01 08 0A 13 13 13] // Chance of getting Dark bonus
|
||||
// [00 00 00 00 00 01 01 01 01 01] // Chance of getting Hit bonus
|
||||
// F1 F2 C1 C2 C3 M1 M2 R1 R2 R3 // (Episode 1 areas, for reference)
|
||||
/* 017A */ parray<parray<uint8_t, 10>, 6> bonus_type_prob_tables;
|
||||
// This array specifies the chance that a rare weapon will have each
|
||||
// possible bonus value. This is indexed as [(bonus_value - 10 / 5)][spec],
|
||||
// so the first row refers the probability of getting a -10% bonus, the next
|
||||
// row is the chance of getting -5%, etc., all the way up to +100%. For
|
||||
// non-rare items, spec is determined randomly based on the following field;
|
||||
// for rare items, spec is always 5.
|
||||
/* 0048 */ parray<parray<U16T, 6>, 0x17> bonus_value_prob_tables;
|
||||
|
||||
// This array (indexed by area - 1) specifies a multiplier of used in special
|
||||
// ability determination. It seems this uses the star values from ItemPMT, but
|
||||
// not yet clear exactly in what way.
|
||||
// TODO: Figure out exactly what this does. Anchor: 80106FEC
|
||||
/* 01B6 */ parray<uint8_t, 0x0A> special_mult;
|
||||
// This array specifies the value of spec to be used in the above lookup for
|
||||
// non-rare items. This is NOT an index probability table; this is a direct
|
||||
// lookup with indexes [bonus_index][area - 1]. A value of 0xFF in any byte
|
||||
// of this array prevents any weapon from having a bonus in that slot.
|
||||
// For example, the array might look like this:
|
||||
// [00 00 00 01 01 01 01 02 02 02]
|
||||
// [FF FF FF 00 00 00 01 01 01 01]
|
||||
// [FF FF FF FF FF FF FF FF FF 00]
|
||||
// F1 F2 C1 C2 C3 M1 M2 R1 R2 R3 // (Episode 1 areas, for reference)
|
||||
// In this example, spec is 0, 1, or 2 in all cases where a weapon can have
|
||||
// a bonus. In Forest 1 and 2 and Cave 1, weapons may have at most one
|
||||
// bonus; in all other areas except Ruins 3, they can have at most two
|
||||
// bonuses, and in Ruins 3, they can have up to three bonuses.
|
||||
/* 015C */ parray<parray<uint8_t, 10>, 3> nonrare_bonus_prob_spec;
|
||||
|
||||
// This array (indexed by area - 1) specifies the probability that any
|
||||
// non-rare weapon will have a special ability.
|
||||
/* 01C0 */ parray<uint8_t, 0x0A> special_percent;
|
||||
// This array specifies the chance that a weapon will have each bonus type.
|
||||
// The table is indexed as [bonus_type][area - 1] for non-rare items; for
|
||||
// rare items, a random value in the range [0, 9] is used instead of
|
||||
// (area - 1).
|
||||
// For example, the table might look like this:
|
||||
// [46 46 3F 3E 3E 3D 3C 3C 3A 3A] // Chance of getting no bonus
|
||||
// [14 14 0A 0A 09 02 02 04 05 05] // Chance of getting Native bonus
|
||||
// [0A 0A 12 11 11 09 09 08 08 08] // Chance of getting A.Beast bonus
|
||||
// [00 00 09 0A 0B 13 12 08 09 09] // Chance of getting Machine bonus
|
||||
// [00 00 00 01 01 08 0A 13 13 13] // Chance of getting Dark bonus
|
||||
// [00 00 00 00 00 01 01 01 01 01] // Chance of getting Hit bonus
|
||||
// F1 F2 C1 C2 C3 M1 M2 R1 R2 R3 // (Episode 1 areas, for reference)
|
||||
/* 017A */ parray<parray<uint8_t, 10>, 6> bonus_type_prob_tables;
|
||||
|
||||
// TODO: Figure out exactly how this table is used. Anchor: 80106D34
|
||||
/* 01CA */ parray<uint8_t, 0x05> armor_shield_type_index_prob_table;
|
||||
// This array (indexed by area - 1) specifies a multiplier of used in
|
||||
// special ability determination. It seems this uses the star values from
|
||||
// ItemPMT, but not yet clear exactly in what way.
|
||||
// TODO: Figure out exactly what this does. Anchor: 80106FEC
|
||||
/* 01B6 */ parray<uint8_t, 0x0A> special_mult;
|
||||
|
||||
// This index probability table specifies how common each possible slot count
|
||||
// is for armor drops.
|
||||
/* 01CF */ parray<uint8_t, 0x05> armor_slot_count_prob_table;
|
||||
// This array (indexed by area - 1) specifies the probability that any
|
||||
// non-rare weapon will have a special ability.
|
||||
/* 01C0 */ parray<uint8_t, 0x0A> special_percent;
|
||||
|
||||
// These values specify maximum indexes into another array which is generated
|
||||
// at runtime. The values here are multiplied by a random float in the range
|
||||
// [0, n] to look up the value in the secondary array, which is what ends up
|
||||
// determining the unit type.
|
||||
// TODO: Figure out and document the exact logic here. Anchor: 80106364
|
||||
/* 01D4 */ parray<uint8_t, 0x0A> unit_maxes;
|
||||
// TODO: Figure out exactly how this table is used. Anchor: 80106D34
|
||||
/* 01CA */ parray<uint8_t, 0x05> armor_shield_type_index_prob_table;
|
||||
|
||||
// This index probability table is indexed by [tool_class][area - 1]. The tool
|
||||
// class refers to an entry in ItemPMT, which links it to the actual item
|
||||
// code.
|
||||
/* 01DE */ parray<parray<U16T, 0x0A>, 0x1C> tool_class_prob_table;
|
||||
// This index probability table specifies how common each possible slot
|
||||
// count is for armor drops.
|
||||
/* 01CF */ parray<uint8_t, 0x05> armor_slot_count_prob_table;
|
||||
|
||||
// This index probability table determines how likely each technique is to
|
||||
// appear. The table is indexed as [technique_num][area - 1].
|
||||
/* 040E */ parray<parray<uint8_t, 0x0A> 0x13> technique_index_prob_table;
|
||||
// These values specify maximum indexes into another array which is
|
||||
// generated at runtime. The values here are multiplied by a random float in
|
||||
// the range [0, n] to look up the value in the secondary array, which is
|
||||
// what ends up determining the unit type.
|
||||
// TODO: Figure out and document the exact logic here. Anchor: 80106364
|
||||
/* 01D4 */ parray<uint8_t, 0x0A> unit_maxes;
|
||||
|
||||
// This table specifies the ranges for technique disk levels. The table is
|
||||
// indexed as [technique_num][area - 1]. If either min or max in the range is
|
||||
// 0xFF, or if max < min, technique disks are not dropped for that technique
|
||||
// and area pair.
|
||||
/* 04CC */ parray<parray<Range<uint8_t>, 0x0A>, 0x13> technique_level_ranges;
|
||||
// This index probability table is indexed by [tool_class][area - 1]. The
|
||||
// tool class refers to an entry in ItemPMT, which links it to the actual
|
||||
// item code.
|
||||
/* 01DE */ parray<parray<U16T, 0x0A>, 0x1C> tool_class_prob_table;
|
||||
|
||||
// Each byte in this table (indexed by enemy_type) represents the percent
|
||||
// chance that the enemy drops anything at all. (This check is done after the
|
||||
// rare drop check, so it only applies to non-rare items.)
|
||||
/* 0648 */ parray<uint8_t, 0x64> enemy_type_drop_probs;
|
||||
// This index probability table determines how likely each technique is to
|
||||
// appear. The table is indexed as [technique_num][area - 1].
|
||||
/* 040E */ parray<parray<uint8_t, 0x0A>, 0x13> technique_index_prob_table;
|
||||
|
||||
// This array (indexed by enemy_id) specifies the range of meseta values that
|
||||
// each enemy can drop.
|
||||
/* 06AC */ parray<Range<U16T>, 0x64> enemy_meseta_ranges;
|
||||
// This table specifies the ranges for technique disk levels. The table is
|
||||
// indexed as [technique_num][area - 1]. If either min or max in the range
|
||||
// is 0xFF, or if max < min, technique disks are not dropped for that
|
||||
// technique and area pair.
|
||||
/* 04CC */ parray<parray<Range<uint8_t>, 0x0A>, 0x13> technique_level_ranges;
|
||||
|
||||
// Each byte in this table (indexed by enemy_type) represents the class of
|
||||
// item that the enemy can drop. The values are:
|
||||
// 00 = weapon
|
||||
// 01 = armor
|
||||
// 02 = shield
|
||||
// 03 = unit
|
||||
// 04 = tool
|
||||
// 05 = meseta
|
||||
// Anything else = no item
|
||||
/* 083C */ parray<uint8_t, 0x64> enemy_item_classes;
|
||||
// Each byte in this table (indexed by enemy_type) represents the percent
|
||||
// chance that the enemy drops anything at all. (This check is done after
|
||||
// the rare drop check, so it only applies to non-rare items.)
|
||||
/* 0648 */ parray<uint8_t, 0x64> enemy_type_drop_probs;
|
||||
|
||||
// This table (indexed by area - 1) specifies the ranges of meseta values that
|
||||
// can drop from boxes.
|
||||
/* 08A0 */ parray<Range<U16T>, 0x0A> box_meseta_ranges;
|
||||
// This array (indexed by enemy_id) specifies the range of meseta values
|
||||
// that each enemy can drop.
|
||||
/* 06AC */ parray<Range<U16T>, 0x64> enemy_meseta_ranges;
|
||||
|
||||
// This index probability table determines which type of items drop from
|
||||
// boxes. The table is indexed as [item_class][area - 1], with item_class as
|
||||
// the result value (that is, in the example below, the game looks at a single
|
||||
// column and sums the values going down, then the chosen item class is one of
|
||||
// the row indexes based on the weight values in the column.) The resulting
|
||||
// item_class value has the same meaning as in enemy_item_classes above.
|
||||
// For example, this array might look like the following:
|
||||
// [07 07 08 08 06 07 08 09 09 0A] // Chances per area of a weapon drop
|
||||
// [02 02 02 02 03 02 02 02 03 03] // Chances per area of an armor drop
|
||||
// [02 02 02 02 03 02 02 02 03 03] // Chances per area of a shield drop
|
||||
// [00 00 03 03 03 04 03 04 05 05] // Chances per area of a unit drop
|
||||
// [11 11 12 12 12 12 12 12 12 12] // Chances per area of a tool drop
|
||||
// [32 32 32 32 32 32 32 32 32 32] // Chances per area of a meseta drop
|
||||
// [16 16 11 11 11 11 11 0F 0C 0B] // Chances per area of an empty box
|
||||
// F1 F2 C1 C2 C3 M1 M2 R1 R2 R3 // (Episode 1 areas, for reference)
|
||||
/* 08C8 */ parray<parray<uint8_t, 10>, 7> box_item_class_prob_tables;
|
||||
// Each byte in this table (indexed by enemy_type) represents the class of
|
||||
// item that the enemy can drop. The values are:
|
||||
// 00 = weapon
|
||||
// 01 = armor
|
||||
// 02 = shield
|
||||
// 03 = unit
|
||||
// 04 = tool
|
||||
// 05 = meseta
|
||||
// Anything else = no item
|
||||
/* 083C */ parray<uint8_t, 0x64> enemy_item_classes;
|
||||
|
||||
/* 0910 */ U32T offset_table[0x1C];
|
||||
/* 0980 */ U16T unknown_f1[0x20];
|
||||
/* 09C0 */ U32T unknown_f1_offset;
|
||||
/* 09C4 */ U32T unknown_f2[3];
|
||||
/* 09D0 */ U32T offset_table_offset;
|
||||
/* 09D4 */ U32T unknown_f3[3];
|
||||
/* 09E0 (end of structure) */
|
||||
} __attribute__((packed));
|
||||
// This table (indexed by area - 1) specifies the ranges of meseta values
|
||||
// that can drop from boxes.
|
||||
/* 08A0 */ parray<Range<U16T>, 0x0A> box_meseta_ranges;
|
||||
|
||||
// This index probability table determines which type of items drop from
|
||||
// boxes. The table is indexed as [item_class][area - 1], with item_class as
|
||||
// the result value (that is, in the example below, the game looks at a
|
||||
// single column and sums the values going down, then the chosen item class
|
||||
// is one of the row indexes based on the weight values in the column.) The
|
||||
// resulting item_class value has the same meaning as in enemy_item_classes
|
||||
// above.
|
||||
// For example, this array might look like the following:
|
||||
// [07 07 08 08 06 07 08 09 09 0A] // Chances per area of a weapon drop
|
||||
// [02 02 02 02 03 02 02 02 03 03] // Chances per area of an armor drop
|
||||
// [02 02 02 02 03 02 02 02 03 03] // Chances per area of a shield drop
|
||||
// [00 00 03 03 03 04 03 04 05 05] // Chances per area of a unit drop
|
||||
// [11 11 12 12 12 12 12 12 12 12] // Chances per area of a tool drop
|
||||
// [32 32 32 32 32 32 32 32 32 32] // Chances per area of a meseta drop
|
||||
// [16 16 11 11 11 11 11 0F 0C 0B] // Chances per area of an empty box
|
||||
// F1 F2 C1 C2 C3 M1 M2 R1 R2 R3 // (Episode 1 areas, for reference)
|
||||
/* 08C8 */ parray<parray<uint8_t, 10>, 7> box_item_class_prob_tables;
|
||||
|
||||
/* 090E */ parray<uint8_t, 2> unused1;
|
||||
|
||||
/* 0910 */ U32T base_weapon_type_prob_table_offset;
|
||||
/* 0914 */ U32T subtype_base_table_offset;
|
||||
/* 0918 */ U32T subtype_area_length_table_offset;
|
||||
/* 091C */ U32T grind_prob_tables_offset;
|
||||
/* 0920 */ U32T armor_shield_type_index_prob_table_offset;
|
||||
/* 0924 */ U32T armor_slot_count_prob_table_offset;
|
||||
/* 0928 */ U32T enemy_meseta_ranges_offset;
|
||||
/* 092C */ U32T enemy_type_drop_probs_offset;
|
||||
/* 0930 */ U32T enemy_item_classes_offset;
|
||||
/* 0934 */ U32T box_meseta_ranges_offset;
|
||||
/* 0938 */ U32T bonus_value_prob_tables_offset;
|
||||
/* 093C */ U32T nonrare_bonus_prob_spec_offset;
|
||||
/* 0940 */ U32T bonus_type_prob_tables_offset;
|
||||
/* 0944 */ U32T special_mult_offset;
|
||||
/* 0948 */ U32T special_percent_offset;
|
||||
/* 094C */ U32T tool_class_prob_table_offset;
|
||||
/* 0950 */ U32T technique_index_prob_table_offset;
|
||||
/* 0954 */ U32T technique_level_ranges_offset;
|
||||
/* 0958 */ uint8_t armor_or_shield_type_bias;
|
||||
/* 0959 */ parray<uint8_t, 3> unused2;
|
||||
/* 095C */ U32T unit_maxes_offset;
|
||||
/* 0960 */ U32T box_item_class_prob_tables_offset;
|
||||
/* 0964 */ U32T unused_offset2;
|
||||
/* 0968 */ U32T unused_offset3;
|
||||
/* 096C */ U32T unused_offset4;
|
||||
/* 0970 */ U32T unused_offset5;
|
||||
/* 0974 */ U32T unused_offset6;
|
||||
/* 0978 */ U32T unused_offset7;
|
||||
/* 097C */ U32T unused_offset8;
|
||||
/* 0980 */ U16T unknown_f1[0x20];
|
||||
/* 09C0 */ U32T unknown_f1_offset;
|
||||
/* 09C4 */ U32T unknown_f2[3];
|
||||
/* 09D0 */ U32T offset_table_offset;
|
||||
/* 09D4 */ U32T unknown_f3[3];
|
||||
/* 09E0 (end of structure) */
|
||||
|
||||
void print(FILE* stream) const;
|
||||
} __attribute__((packed));
|
||||
|
||||
CommonItemSet(std::shared_ptr<const std::string> data);
|
||||
|
||||
const Table<true>& get_table(
|
||||
Episode episode, GameMode mode, uint8_t difficulty, uint8_t secid) const;
|
||||
|
||||
private:
|
||||
GSLArchive gsl;
|
||||
};
|
||||
|
||||
class RELFileSet {
|
||||
public:
|
||||
template <typename ValueT, typename WeightT = ValueT>
|
||||
struct WeightTableEntry {
|
||||
ValueT value;
|
||||
WeightT weight;
|
||||
} __attribute__((packed));
|
||||
|
||||
using WeightTableEntry8 = WeightTableEntry<uint8_t>;
|
||||
using WeightTableEntry32 = WeightTableEntry<be_uint32_t>;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<const string> data;
|
||||
StringReader r;
|
||||
|
||||
struct TableSpec {
|
||||
be_uint32_t offset;
|
||||
uint8_t entries_per_table;
|
||||
parray<uint8_t, 3> unused;
|
||||
} __attribute__((packed));
|
||||
|
||||
RELFileSet(std::shared_ptr<const std::string> data);
|
||||
|
||||
template <typename T>
|
||||
std::pair<const T*, size_t> get_table(
|
||||
const TableSpec& spec, size_t index) const {
|
||||
const T* entries = &r.pget<T>(
|
||||
spec.offset + index * spec.entries_per_table * sizeof(T),
|
||||
spec.entries_per_table * sizeof(T));
|
||||
return make_pair(entries, spec.entries_per_table);
|
||||
}
|
||||
};
|
||||
|
||||
class ArmorRandomSet : public RELFileSet {
|
||||
public:
|
||||
// This class parses and accesses data from ArmorRandom.rel
|
||||
ArmorRandomSet(std::shared_ptr<const std::string> data);
|
||||
|
||||
std::pair<const WeightTableEntry8*, size_t> get_armor_table(size_t index) const;
|
||||
std::pair<const WeightTableEntry8*, size_t> get_shield_table(size_t index) const;
|
||||
std::pair<const WeightTableEntry8*, size_t> get_unit_table(size_t index) const;
|
||||
|
||||
private:
|
||||
const parray<TableSpec, 3>* tables;
|
||||
};
|
||||
|
||||
class ToolRandomSet : public RELFileSet {
|
||||
public:
|
||||
// This class parses and accesses data from ToolRandom.rel
|
||||
ToolRandomSet(std::shared_ptr<const std::string> data);
|
||||
|
||||
struct TechDiskLevelEntry {
|
||||
enum class Mode : uint8_t {
|
||||
LEVEL_1 = 0,
|
||||
PLAYER_LEVEL_DIVISOR = 1,
|
||||
RANDOM_IN_RANGE = 2,
|
||||
};
|
||||
Mode mode;
|
||||
uint8_t player_level_divisor_or_min_level;
|
||||
uint8_t max_level;
|
||||
} __attribute__((packed));
|
||||
|
||||
std::pair<const uint8_t*, size_t> get_common_recovery_table(size_t index) const;
|
||||
std::pair<const WeightTableEntry8*, size_t> get_rare_recovery_table(size_t index) const;
|
||||
std::pair<const WeightTableEntry8*, size_t> get_tech_disk_table(size_t index) const;
|
||||
std::pair<const TechDiskLevelEntry*, size_t> get_tech_disk_level_table(size_t index) const;
|
||||
|
||||
private:
|
||||
const TableSpec* common_recovery_table_spec;
|
||||
const TableSpec* rare_recovery_table_spec;
|
||||
const TableSpec* tech_disk_table_spec;
|
||||
const TableSpec* tech_disk_level_table_spec;
|
||||
};
|
||||
|
||||
class WeaponRandomSet : public RELFileSet {
|
||||
public:
|
||||
// This class parses and accesses data from WeaponRandom*.rel
|
||||
WeaponRandomSet(std::shared_ptr<const std::string> data);
|
||||
|
||||
struct RangeTableEntry {
|
||||
be_uint32_t min;
|
||||
be_uint32_t max;
|
||||
} __attribute__((packed));
|
||||
|
||||
std::pair<const WeightTableEntry8*, size_t> get_weapon_type_table(size_t index) const;
|
||||
const parray<WeightTableEntry32, 6>* get_bonus_type_table(size_t which, size_t index) const;
|
||||
const RangeTableEntry* get_bonus_range(size_t which, size_t index) const;
|
||||
const parray<WeightTableEntry32, 3>* get_special_mode_table(size_t index) const;
|
||||
const RangeTableEntry* get_standard_grind_range(size_t index) const;
|
||||
const RangeTableEntry* get_favored_grind_range(size_t index) const;
|
||||
|
||||
private:
|
||||
struct Offsets {
|
||||
be_uint32_t weapon_type_table; // [{c, o -> (table)}](10)
|
||||
be_uint32_t bonus_type_table1; // [[{u32 value, u32 weight}](6)](9)
|
||||
be_uint32_t bonus_type_table2; // [[{u32 value, u32 weight}](6)](9)
|
||||
be_uint32_t bonus_range_table1; // [{u32 min_index, u32 max_index}](9)
|
||||
be_uint32_t bonus_range_table2; // [{u32 min_index, u32 max_index}](9)
|
||||
be_uint32_t special_mode_table; // [[{u32 value, u32 weight}](3)](8)
|
||||
be_uint32_t standard_grind_range_table; // [{u32 min, u32 max}](6)
|
||||
be_uint32_t favored_grind_range_table; // [{u32 min, u32 max}](6)
|
||||
} __attribute__((packed));
|
||||
|
||||
const Offsets* offsets;
|
||||
};
|
||||
|
||||
class TekkerAdjustmentSet {
|
||||
public:
|
||||
// This class parses and accesses data from JudgeItem.rel
|
||||
TekkerAdjustmentSet(std::shared_ptr<const std::string> data);
|
||||
|
||||
const ProbabilityTable<uint8_t, 100>& get_special_upgrade_prob_table(uint8_t section_id, bool favored) const;
|
||||
const ProbabilityTable<uint8_t, 100>& get_grind_delta_prob_table(uint8_t section_id, bool favored) const;
|
||||
const ProbabilityTable<uint8_t, 100>& get_bonus_delta_prob_table(uint8_t section_id, bool favored) const;
|
||||
int8_t get_luck_for_special_upgrade(uint8_t delta_index) const;
|
||||
int8_t get_luck_for_grind_delta(uint8_t delta_index) const;
|
||||
int8_t get_luck_for_bonus_delta(uint8_t delta_index) const;
|
||||
|
||||
private:
|
||||
const ProbabilityTable<uint8_t, 100>& get_table(
|
||||
std::array<ProbabilityTable<uint8_t, 100>, 10>& tables_default,
|
||||
std::array<ProbabilityTable<uint8_t, 100>, 10>& tables_favored,
|
||||
uint32_t offset_and_count_offset,
|
||||
bool favored,
|
||||
uint8_t section_id) const;
|
||||
int8_t get_luck(uint32_t start_offset, uint8_t delta_index) const;
|
||||
|
||||
std::shared_ptr<const string> data;
|
||||
StringReader r;
|
||||
|
||||
struct DeltaProbabilityEntry {
|
||||
uint8_t delta_index;
|
||||
uint8_t count_default;
|
||||
uint8_t count_favored;
|
||||
} __attribute__((packed));
|
||||
struct LuckTableEntry {
|
||||
uint8_t delta_index;
|
||||
int8_t luck;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Offsets {
|
||||
// Each section ID's favored weapon class has different probabilities than
|
||||
// those used for all other weapons. The tables are labeled with (D) for the
|
||||
// default values and (F) for the favored-class values.
|
||||
|
||||
// Note that the favored bonuses for Redria are all zero; these values are
|
||||
// unused because Redria does not have a favored weapon type. Curiously,
|
||||
// Yellowboze also does not have a favored weapon type, but the values for
|
||||
// Yellowboze are not all zero.
|
||||
|
||||
// This table specifies how likely a special is to be upgraded or
|
||||
// downgraded by one level.
|
||||
// In PSO GC, the special upgrade table is:
|
||||
// Viridia => (D) +1=10%, 0=60%, -1=30%
|
||||
// Viridia => (F) +1=25%, 0=50%, -1=25%
|
||||
// Greennill => (D) +1=25%, 0=65%, -1=10%
|
||||
// Greennill => (F) +1=40%, 0=55%, -1=5%
|
||||
// Skyly => (D) +1=15%, 0=70%, -1=15%
|
||||
// Skyly => (F) +1=30%, 0=60%, -1=10%
|
||||
// Bluefull => (D) +1=10%, 0=60%, -1=30%
|
||||
// Bluefull => (F) +1=25%, 0=50%, -1=25%
|
||||
// Purplenum => (D) +1=25%, 0=65%, -1=10%
|
||||
// Purplenum => (F) +1=40%, 0=55%, -1=5%
|
||||
// Pinkal => (D) +1=15%, 0=70%, -1=15%
|
||||
// Pinkal => (F) +1=30%, 0=60%, -1=10%
|
||||
// Redria => (D) +1=20%, 0=60%, -1=20%
|
||||
// Redria => (F) +1=0%, 0=0%, -1=0%
|
||||
// Oran => (D) +1=15%, 0=70%, -1=15%
|
||||
// Oran => (F) +1=30%, 0=60%, -1=10%
|
||||
// Yellowboze => (D) +1=25%, 0=65%, -1=10%
|
||||
// Yellowboze => (F) +1=40%, 0=55%, -1=5%
|
||||
// Whitill => (D) +1=10%, 0=60%, -1=30%
|
||||
// Whitill => (F) +1=25%, 0=50%, -1=25%
|
||||
be_uint32_t special_upgrade_prob_table_offset; // [{c, o -> (DeltaProbabilityEntry)[10][c]})
|
||||
|
||||
// This table specifies how likely a weapon's grind is to be upgraded or
|
||||
// downgraded, and by how much. The final grind value is clamped to the
|
||||
// range between 0 and the weapon's maximum grind from ItemPMT, inclusive.
|
||||
// In PSO GC, the grind delta table is:
|
||||
// Viridia => (D) +3=3%, +2=7%, +1=13%, 0=60%, -1=10%, -2=7%, -3=0%
|
||||
// Viridia => (F) +3=5%, +2=13%, +1=25%, 0=50%, -1=7%, -2=0%, -3=0%
|
||||
// Greennill => (D) +3=0%, +2=5%, +1=10%, 0=70%, -1=10%, -2=5%, -3=0%
|
||||
// Greennill => (F) +3=3%, +2=7%, +1=20%, 0=60%, -1=10%, -2=0%, -3=0%
|
||||
// Skyly => (D) +3=0%, +2=7%, +1=10%, 0=60%, -1=13%, -2=7%, -3=3%
|
||||
// Skyly => (F) +3=3%, +2=12%, +1=20%, 0=50%, -1=10%, -2=5%, -3=0%
|
||||
// Bluefull => (D) +3=3%, +2=7%, +1=13%, 0=60%, -1=10%, -2=7%, -3=0%
|
||||
// Bluefull => (F) +3=5%, +2=13%, +1=25%, 0=50%, -1=7%, -2=0%, -3=0%
|
||||
// Purplenum => (D) +3=0%, +2=5%, +1=10%, 0=70%, -1=10%, -2=5%, -3=0%
|
||||
// Purplenum => (F) +3=3%, +2=7%, +1=20%, 0=60%, -1=10%, -2=0%, -3=0%
|
||||
// Pinkal => (D) +3=0%, +2=7%, +1=10%, 0=60%, -1=13%, -2=7%, -3=3%
|
||||
// Pinkal => (F) +3=3%, +2=12%, +1=20%, 0=50%, -1=10%, -2=5%, -3=0%
|
||||
// Redria => (D) +3=0%, +2=7%, +1=10%, 0=60%, -1=13%, -2=7%, -3=3%
|
||||
// Redria => (F) +3=0%, +2=0%, +1=0%, 0=0%, -1=0%, -2=0%, -3=0%
|
||||
// Oran => (D) +3=0%, +2=7%, +1=10%, 0=60%, -1=13%, -2=7%, -3=3%
|
||||
// Oran => (F) +3=3%, +2=12%, +1=20%, 0=50%, -1=10%, -2=5%, -3=0%
|
||||
// Yellowboze => (D) +3=0%, +2=5%, +1=10%, 0=70%, -1=10%, -2=5%, -3=0%
|
||||
// Yellowboze => (F) +3=3%, +2=7%, +1=20%, 0=60%, -1=10%, -2=0%, -3=0%
|
||||
// Whitill => (D) +3=3%, +2=7%, +1=13%, 0=60%, -1=10%, -2=7%, -3=0%
|
||||
// Whitill => (F) +3=5%, +2=13%, +1=25%, 0=50%, -1=7%, -2=0%, -3=0%
|
||||
be_uint32_t grind_delta_prob_table_offset; // [{c, o -> (DeltaProbabilityEntry)[10][c]})
|
||||
|
||||
// This table specifies how likely a weapon's bonuses are to be upgraded
|
||||
// or downgraded, and by how much. The final bonuses are capped above at
|
||||
// 100, but there is no lower limit (so negative results are possible).
|
||||
// In PSO GC, the bonus delta table is:
|
||||
// Viridia => (D) +10=5%, +5=15%, 0=60%, -5=15%, -10=5%
|
||||
// Viridia => (F) +10=8%, +5=20%, 0=60%, -5=10%, -10=2%
|
||||
// Greennill => (D) +10=5%, +5=10%, 0=50%, -5=25%, -10=10%
|
||||
// Greennill => (F) +10=8%, +5=15%, 0=50%, -5=20%, -10=7%
|
||||
// Skyly => (D) +10=10%, +5=25%, 0=50%, -5=10%, -10=5%
|
||||
// Skyly => (F) +10=13%, +5=30%, 0=50%, -5=5%, -10=2%
|
||||
// Bluefull => (D) +10=5%, +5=15%, 0=60%, -5=15%, -10=5%
|
||||
// Bluefull => (F) +10=8%, +5=20%, 0=60%, -5=10%, -10=2%
|
||||
// Purplenum => (D) +10=5%, +5=10%, 0=50%, -5=25%, -10=10%
|
||||
// Purplenum => (F) +10=8%, +5=15%, 0=50%, -5=20%, -10=7%
|
||||
// Pinkal => (D) +10=10%, +5=25%, 0=50%, -5=10%, -10=5%
|
||||
// Pinkal => (F) +10=13%, +5=30%, 0=50%, -5=5%, -10=2%
|
||||
// Redria => (D) +10=10%, +5=25%, 0=50%, -5=10%, -10=5%
|
||||
// Redria => (F) +10=0%, +5=0%, 0=0%, -5=0%, -10=0%
|
||||
// Oran => (D) +10=10%, +5=25%, 0=50%, -5=10%, -10=5%
|
||||
// Oran => (F) +10=13%, +5=30%, 0=50%, -5=5%, -10=2%
|
||||
// Yellowboze => (D) +10=5%, +5=10%, 0=50%, -5=25%, -10=10%
|
||||
// Yellowboze => (F) +10=8%, +5=15%, 0=50%, -5=20%, -10=7%
|
||||
// Whitill => (D) +10=5%, +5=15%, 0=60%, -5=15%, -10=5%
|
||||
// Whitill => (F) +10=8%, +5=20%, 0=60%, -5=10%, -10=2%
|
||||
be_uint32_t bonus_delta_prob_table_offset; // [{c, o -> (DeltaProbabilityEntry)[10][c]})
|
||||
|
||||
// There is a secondary computation done during weapon adjustment that
|
||||
// appears to determine how "good" the resulting weapon is compared to its
|
||||
// original state. If the result of this computation is positive, the game
|
||||
// plays a jingle when the tekker result is accepted. These tables describe
|
||||
// how much each delta affects this value, which we call luck.
|
||||
|
||||
// In PSO GC, the special upgrade luck table is:
|
||||
// +1 => +20, 0 => 0, -1 => -20
|
||||
be_uint32_t special_upgrade_luck_table_offset; // LuckTableEntry[...]; ending with FF FF
|
||||
|
||||
// In PSO GC, the grind delta luck table is:
|
||||
// +3 => +10, +2 => +5, +1 => +3, 0 => 0, -1 => -3, -2 => -5, -3 => -10
|
||||
be_uint32_t grind_delta_luck_table_offset; // LuckTableEntry[...]; ending with FF FF
|
||||
|
||||
// In PSO GC, the bonus delta luck table is:
|
||||
// +10 => +15, +5 => +8, 0 => 0, -5 => -8, -10 => -15
|
||||
be_uint32_t bonus_delta_luck_offset; // LuckTableEntry[...]; ending with FF FF
|
||||
} __attribute__((packed));
|
||||
|
||||
const Offsets* offsets;
|
||||
|
||||
mutable std::array<ProbabilityTable<uint8_t, 100>, 10> special_upgrade_prob_tables_default;
|
||||
mutable std::array<ProbabilityTable<uint8_t, 100>, 10> special_upgrade_prob_tables_favored;
|
||||
mutable std::array<ProbabilityTable<uint8_t, 100>, 10> grind_delta_prob_tables_default;
|
||||
mutable std::array<ProbabilityTable<uint8_t, 100>, 10> grind_delta_prob_tables_favored;
|
||||
mutable std::array<ProbabilityTable<uint8_t, 100>, 10> bonus_delta_prob_tables_default;
|
||||
mutable std::array<ProbabilityTable<uint8_t, 100>, 10> bonus_delta_prob_tables_favored;
|
||||
};
|
||||
|
||||
+898
-254
File diff suppressed because it is too large
Load Diff
+162
-18
@@ -2,22 +2,49 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <array>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <phosg/Tools.hh>
|
||||
#include <string>
|
||||
|
||||
#include "Text.hh"
|
||||
|
||||
enum class CompressPhase {
|
||||
INDEX = 0,
|
||||
CONSTRUCT_PATHS,
|
||||
BACKTRACE_OPTIMAL_PATH,
|
||||
GENERATE_RESULT,
|
||||
};
|
||||
|
||||
template <>
|
||||
const char* name_for_enum<CompressPhase>(CompressPhase v);
|
||||
|
||||
typedef std::function<void(CompressPhase phase, size_t input_progress, size_t input_size, size_t output_size)> ProgressCallback;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// PRS compression
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Use this class if you need to compress from multiple input buffers, or need
|
||||
// to compress multiple chunks and don't want to copy their contents
|
||||
// unnecessarily. (For most common use cases, use prs_compress (below) instead.)
|
||||
// unnecessarily. (For most common use cases, use prs_compress, below, instead.)
|
||||
// To use this class, instantiate it, then call .add() one or more times, then
|
||||
// call .close() and use the returned string as the compressed result.
|
||||
class PRSCompressor {
|
||||
public:
|
||||
// To use this class, instantiate it, then call .add() one or more times, then
|
||||
// call .close() and use the returned string as the compressed result.
|
||||
PRSCompressor(std::function<void(size_t, size_t)> progress_fn = nullptr);
|
||||
// compression_level specifies how aggressively to search for alternate paths:
|
||||
// -1: Don't perform any compression at all, but produce output that can be
|
||||
// understood by prs_decompress. The output will be about 9/8 the size
|
||||
// of the input.
|
||||
// 0: Greedily search for the longest backreference at every point. Don't
|
||||
// consider any alternate paths. Generally offers a good balance between
|
||||
// speed and output size.
|
||||
// 1: Consider two paths at each point when a backreference is found: using
|
||||
// the backreference or ignoring it.
|
||||
// 2+: Consider further chains of paths at each point. Using values 2 or
|
||||
// greater for compression_level generally yields diminishing returns.
|
||||
explicit PRSCompressor(ssize_t compression_level = 0, ProgressCallback progress_fn = nullptr);
|
||||
~PRSCompressor() = default;
|
||||
|
||||
// Adds more input data to be compressed, which logically comes after all
|
||||
@@ -36,33 +63,129 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
template <size_t Size>
|
||||
struct WrappedLog {
|
||||
parray<uint8_t, Size> data;
|
||||
|
||||
WrappedLog() : data(0) {}
|
||||
~WrappedLog() = default;
|
||||
|
||||
inline uint8_t at(size_t offset) const {
|
||||
return this->data[offset % this->data.size()];
|
||||
}
|
||||
inline uint8_t& at(size_t offset) {
|
||||
return this->data[offset % this->data.size()];
|
||||
}
|
||||
};
|
||||
|
||||
template <size_t Size>
|
||||
struct IndexedLog : WrappedLog<Size> {
|
||||
size_t offset;
|
||||
size_t size;
|
||||
std::array<std::deque<size_t>, 0x100> index;
|
||||
|
||||
IndexedLog()
|
||||
: WrappedLog<Size>(),
|
||||
offset(0),
|
||||
size(0) {}
|
||||
~IndexedLog() = default;
|
||||
|
||||
inline size_t end_offset() const {
|
||||
return this->offset + this->size;
|
||||
}
|
||||
|
||||
void push_back(uint8_t v) {
|
||||
if (this->size == Size) {
|
||||
this->pop_front();
|
||||
}
|
||||
size_t write_offset = this->offset + this->size;
|
||||
this->at(write_offset) = v;
|
||||
this->index[v].push_back(write_offset);
|
||||
this->size++;
|
||||
}
|
||||
uint8_t pop_back() {
|
||||
if (!this->size) {
|
||||
throw std::logic_error("pop_back called on empty IndexedLog");
|
||||
}
|
||||
this->size--;
|
||||
size_t offset = this->offset + this->size;
|
||||
uint8_t v = this->at(offset);
|
||||
this->index[v].pop_back();
|
||||
return v;
|
||||
}
|
||||
uint8_t pop_front() {
|
||||
uint8_t v = this->at(this->offset);
|
||||
this->index[v].pop_front();
|
||||
this->offset++;
|
||||
this->size--;
|
||||
return v;
|
||||
}
|
||||
const std::deque<size_t>& find(uint8_t v) {
|
||||
return this->index[v];
|
||||
}
|
||||
};
|
||||
|
||||
void add_byte(uint8_t v);
|
||||
void advance();
|
||||
void move_forward_data_to_reverse_log(size_t size);
|
||||
void advance_literal();
|
||||
void advance_short_copy(ssize_t offset, size_t size);
|
||||
void advance_long_copy(ssize_t offset, size_t size);
|
||||
void advance_extended_copy(ssize_t offset, size_t size);
|
||||
void write_control(bool z);
|
||||
void flush_control();
|
||||
|
||||
std::function<void(size_t, size_t)> progress_fn;
|
||||
ssize_t compression_level;
|
||||
ProgressCallback progress_fn;
|
||||
bool closed;
|
||||
|
||||
size_t control_byte_offset;
|
||||
uint16_t pending_control_bits;
|
||||
|
||||
size_t input_bytes;
|
||||
parray<uint8_t, 0x100> forward_log;
|
||||
size_t compression_offset;
|
||||
parray<uint8_t, 0x2000> reverse_log;
|
||||
std::vector<std::deque<size_t>> reverse_log_index;
|
||||
WrappedLog<0x101> forward_log;
|
||||
IndexedLog<0x2000> reverse_log;
|
||||
|
||||
StringWriter output;
|
||||
};
|
||||
|
||||
// Compresses data from a single input buffer using PRS and returns the
|
||||
// compressed result. This is a shortcut for constructing a PRSCompressor,
|
||||
// calling .add() once, and calling .close().
|
||||
std::string prs_compress(const void* vdata, size_t size, std::function<void(size_t, size_t)> progress_fn = nullptr);
|
||||
std::string prs_compress(const std::string& data, std::function<void(size_t, size_t)> progress_fn = nullptr);
|
||||
// These functions use PRSCompressor to compress a buffer of data. This is
|
||||
// essentially a shortcut for constructing a PRSCompressor, calling .add() on
|
||||
// it once, then calling .close().
|
||||
std::string prs_compress(
|
||||
const void* vdata,
|
||||
size_t size,
|
||||
ssize_t compression_level = 0,
|
||||
ProgressCallback progress_fn = nullptr);
|
||||
std::string prs_compress(
|
||||
const std::string& data,
|
||||
ssize_t compression_level = 0,
|
||||
ProgressCallback progress_fn = nullptr);
|
||||
|
||||
// A faster form of prs_compress that doesn't have a tunable compression level.
|
||||
std::string prs_compress_indexed(
|
||||
const void* vdata,
|
||||
size_t size,
|
||||
ProgressCallback progress_fn = nullptr);
|
||||
std::string prs_compress_indexed(
|
||||
const std::string& data,
|
||||
ProgressCallback progress_fn = nullptr);
|
||||
|
||||
// Compresses data using PRS to the smallest possible output size. This function
|
||||
// is slow, but produces results significantly smaller than even Sega's original
|
||||
// compressor.
|
||||
std::string prs_compress_optimal(
|
||||
const void* vdata,
|
||||
size_t size,
|
||||
ProgressCallback progress_fn = nullptr);
|
||||
|
||||
// Decompresses PRS-compressed data.
|
||||
struct PRSDecompressResult {
|
||||
std::string data;
|
||||
size_t input_bytes_used;
|
||||
};
|
||||
PRSDecompressResult prs_decompress_with_meta(const void* data, size_t size, size_t max_output_size = 0);
|
||||
PRSDecompressResult prs_decompress_with_meta(const std::string& data, size_t max_output_size = 0);
|
||||
std::string prs_decompress(const void* data, size_t size, size_t max_output_size = 0);
|
||||
std::string prs_decompress(const std::string& data, size_t max_output_size = 0);
|
||||
|
||||
@@ -75,6 +198,27 @@ size_t prs_decompress_size(const std::string& data, size_t max_output_size = 0);
|
||||
void prs_disassemble(FILE* stream, const void* data, size_t size);
|
||||
void prs_disassemble(FILE* stream, const std::string& data);
|
||||
|
||||
// Compresses and decompresses data using the BC0 algorithm.
|
||||
std::string bc0_compress(const std::string& data, std::function<void(size_t, size_t)> progress_fn = nullptr);
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// BC0 compression
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Compresses data using the BC0 algorithm. Like with PRS, the optimal variant
|
||||
// is slow, but produces the smallest possible output.
|
||||
std::string bc0_compress_optimal(
|
||||
const void* in_data_v,
|
||||
size_t in_size,
|
||||
ProgressCallback progress_fn = nullptr);
|
||||
std::string bc0_compress(const std::string& data, ProgressCallback progress_fn = nullptr);
|
||||
std::string bc0_compress(const void* in_data_v, size_t in_size, ProgressCallback progress_fn = nullptr);
|
||||
|
||||
// Encodes data in a BC0-compatible format without compression (similar to using
|
||||
// compression_level=-1 with prs_compress).
|
||||
std::string bc0_encode(const void* in_data_v, size_t in_size);
|
||||
|
||||
// Decompresses BC0-compressed data.
|
||||
std::string bc0_decompress(const std::string& data);
|
||||
std::string bc0_decompress(const void* data, size_t size);
|
||||
|
||||
// Prints the command stream from a BC0-compressed buffer.
|
||||
void bc0_disassemble(FILE* stream, const std::string& data);
|
||||
void bc0_disassemble(FILE* stream, const void* data, size_t size);
|
||||
|
||||
+13
-13
@@ -1,28 +1,28 @@
|
||||
#include "DNSServer.hh"
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <poll.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <poll.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Network.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Loggers.hh"
|
||||
#include "NetworkAddresses.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
DNSServer::DNSServer(shared_ptr<struct event_base> base,
|
||||
uint32_t local_connect_address, uint32_t external_connect_address) :
|
||||
base(base), local_connect_address(local_connect_address),
|
||||
external_connect_address(external_connect_address) { }
|
||||
DNSServer::DNSServer(
|
||||
shared_ptr<struct event_base> base,
|
||||
uint32_t local_connect_address, uint32_t external_connect_address)
|
||||
: base(base),
|
||||
local_connect_address(local_connect_address),
|
||||
external_connect_address(external_connect_address) {}
|
||||
|
||||
DNSServer::~DNSServer() {
|
||||
for (const auto& it : this->fd_to_receive_event) {
|
||||
@@ -43,11 +43,11 @@ void DNSServer::listen(int port) {
|
||||
}
|
||||
|
||||
void DNSServer::add_socket(int fd) {
|
||||
unique_ptr<struct event, void(*)(struct event*)> e(event_new(this->base.get(),
|
||||
fd, EV_READ | EV_PERSIST, &DNSServer::dispatch_on_receive_message,
|
||||
this), event_free);
|
||||
unique_ptr<struct event, void (*)(struct event*)> e(
|
||||
event_new(this->base.get(), fd, EV_READ | EV_PERSIST, &DNSServer::dispatch_on_receive_message, this),
|
||||
event_free);
|
||||
event_add(e.get(), nullptr);
|
||||
this->fd_to_receive_event.emplace(fd, move(e));
|
||||
this->fd_to_receive_event.emplace(fd, std::move(e));
|
||||
}
|
||||
|
||||
void DNSServer::dispatch_on_receive_message(evutil_socket_t fd,
|
||||
|
||||
+3
-4
@@ -3,10 +3,9 @@
|
||||
#include <event2/event.h>
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <set>
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
class DNSServer {
|
||||
public:
|
||||
@@ -28,7 +27,7 @@ public:
|
||||
|
||||
private:
|
||||
std::shared_ptr<struct event_base> base;
|
||||
std::unordered_map<int, std::unique_ptr<struct event, void(*)(struct event*)>> fd_to_receive_event;
|
||||
std::unordered_map<int, std::unique_ptr<struct event, void (*)(struct event*)>> fd_to_receive_event;
|
||||
uint32_t local_connect_address;
|
||||
uint32_t external_connect_address;
|
||||
|
||||
|
||||
+1050
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,145 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <phosg/Tools.hh>
|
||||
|
||||
#include "StaticGameData.hh"
|
||||
|
||||
enum class EnemyType {
|
||||
UNKNOWN = -1,
|
||||
NONE = 0,
|
||||
AL_RAPPY,
|
||||
ASTARK,
|
||||
BA_BOOTA,
|
||||
BARBA_RAY,
|
||||
BARBAROUS_WOLF,
|
||||
BEE_L,
|
||||
BEE_R,
|
||||
BOOMA,
|
||||
BOOTA,
|
||||
BULCLAW,
|
||||
CANADINE,
|
||||
CANADINE_GROUP,
|
||||
CANANE,
|
||||
CHAOS_BRINGER,
|
||||
CHAOS_SORCERER,
|
||||
CLAW,
|
||||
DARK_BELRA,
|
||||
DARK_FALZ_1,
|
||||
DARK_FALZ_2,
|
||||
DARK_FALZ_3,
|
||||
DARK_GUNNER,
|
||||
DARVANT,
|
||||
DARVANT_ULTIMATE,
|
||||
DE_ROL_LE,
|
||||
DE_ROL_LE_BODY,
|
||||
DE_ROL_LE_MINE,
|
||||
DEATH_GUNNER,
|
||||
DEL_LILY,
|
||||
DEL_RAPPY,
|
||||
DEL_RAPPY_ALT,
|
||||
DELBITER,
|
||||
DELDEPTH,
|
||||
DELSABER,
|
||||
DIMENIAN,
|
||||
DOLMDARL,
|
||||
DOLMOLM,
|
||||
DORPHON,
|
||||
DORPHON_ECLAIR,
|
||||
DRAGON,
|
||||
DUBCHIC,
|
||||
DUBWITCH, // Has no entry in battle params
|
||||
EGG_RAPPY,
|
||||
EPSIGUARD,
|
||||
EPSILON,
|
||||
EVIL_SHARK,
|
||||
GAEL,
|
||||
GAL_GRYPHON,
|
||||
GARANZ,
|
||||
GEE,
|
||||
GI_GUE,
|
||||
GIBBLES,
|
||||
GIGOBOOMA,
|
||||
GILLCHIC,
|
||||
GIRTABLULU,
|
||||
GOBOOMA,
|
||||
GOL_DRAGON,
|
||||
GORAN,
|
||||
GORAN_DETONATOR,
|
||||
GRASS_ASSASSIN,
|
||||
GUIL_SHARK,
|
||||
HALLO_RAPPY,
|
||||
HIDOOM,
|
||||
HILDEBEAR,
|
||||
HILDEBLUE,
|
||||
ILL_GILL,
|
||||
KONDRIEU,
|
||||
LA_DIMENIAN,
|
||||
LOVE_RAPPY,
|
||||
MERICAROL,
|
||||
MERICUS,
|
||||
MERIKLE,
|
||||
MERILLIA,
|
||||
MERILTAS,
|
||||
MERISSA_A,
|
||||
MERISSA_AA,
|
||||
MIGIUM,
|
||||
MONEST,
|
||||
MORFOS,
|
||||
MOTHMANT,
|
||||
NANO_DRAGON,
|
||||
NAR_LILY,
|
||||
OLGA_FLOW_1,
|
||||
OLGA_FLOW_2,
|
||||
PAL_SHARK,
|
||||
PAN_ARMS,
|
||||
PAZUZU,
|
||||
PAZUZU_ALT,
|
||||
PIG_RAY,
|
||||
POFUILLY_SLIME,
|
||||
POUILLY_SLIME,
|
||||
POISON_LILY,
|
||||
PYRO_GORAN,
|
||||
RAG_RAPPY,
|
||||
RECOBOX,
|
||||
RECON,
|
||||
SAINT_MILLION,
|
||||
SAINT_RAPPY,
|
||||
SAND_RAPPY,
|
||||
SAND_RAPPY_ALT,
|
||||
SATELLITE_LIZARD,
|
||||
SATELLITE_LIZARD_ALT,
|
||||
SAVAGE_WOLF,
|
||||
SHAMBERTIN,
|
||||
SINOW_BEAT,
|
||||
SINOW_BERILL,
|
||||
SINOW_GOLD,
|
||||
SINOW_SPIGELL,
|
||||
SINOW_ZELE,
|
||||
SINOW_ZOA,
|
||||
SO_DIMENIAN,
|
||||
UL_GIBBON,
|
||||
VOL_OPT_1,
|
||||
VOL_OPT_2,
|
||||
VOL_OPT_AMP,
|
||||
VOL_OPT_CORE,
|
||||
VOL_OPT_MONITOR,
|
||||
VOL_OPT_PILLAR,
|
||||
YOWIE,
|
||||
YOWIE_ALT,
|
||||
ZE_BOOTA,
|
||||
ZOL_GIBBON,
|
||||
ZU,
|
||||
ZU_ALT,
|
||||
MAX_ENEMY_TYPE,
|
||||
};
|
||||
|
||||
template <>
|
||||
const char* name_for_enum<EnemyType>(EnemyType type);
|
||||
template <>
|
||||
EnemyType enum_for_name<EnemyType>(const char* name);
|
||||
|
||||
bool enemy_type_valid_for_episode(Episode episode, EnemyType enemy_type);
|
||||
uint8_t battle_param_index_for_enemy_type(Episode episode, EnemyType enemy_type);
|
||||
uint8_t rare_table_index_for_enemy_type(EnemyType enemy_type);
|
||||
@@ -6,8 +6,6 @@ using namespace std;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
// Note: This order matches the order that the cards are defined in the original
|
||||
// code. This is relevant for consistency of results when choosing a random card
|
||||
// (for God Whim).
|
||||
@@ -24,81 +22,81 @@ const vector<uint16_t> ALL_ASSIST_CARD_IDS = {
|
||||
|
||||
AssistEffect assist_effect_number_for_card_id(uint16_t card_id) {
|
||||
static const unordered_map<uint16_t, AssistEffect> card_id_to_effect({
|
||||
{0x00F5, /* 0x0001 */ AssistEffect::DICE_HALF},
|
||||
{0x00F6, /* 0x0002 */ AssistEffect::DICE_PLUS_1},
|
||||
{0x00F7, /* 0x0003 */ AssistEffect::DICE_FEVER},
|
||||
{0x00F8, /* 0x0004 */ AssistEffect::CARD_RETURN},
|
||||
{0x00F9, /* 0x0005 */ AssistEffect::LAND_PRICE},
|
||||
{0x00FA, /* 0x0006 */ AssistEffect::POWERLESS_RAIN},
|
||||
{0x00FB, /* 0x0007 */ AssistEffect::BRAVE_WIND},
|
||||
{0x00FC, /* 0x0008 */ AssistEffect::SILENT_COLOSSEUM},
|
||||
{0x00FD, /* 0x0009 */ AssistEffect::RESISTANCE},
|
||||
{0x00FE, /* 0x000A */ AssistEffect::INDEPENDENT},
|
||||
{0x00FF, /* 0x000B */ AssistEffect::ASSISTLESS},
|
||||
{0x0100, /* 0x000C */ AssistEffect::ATK_DICE_2},
|
||||
{0x0101, /* 0x000D */ AssistEffect::DEFLATION},
|
||||
{0x0102, /* 0x000E */ AssistEffect::INFLATION},
|
||||
{0x0103, /* 0x000F */ AssistEffect::EXCHANGE},
|
||||
{0x0104, /* 0x0010 */ AssistEffect::INFLUENCE},
|
||||
{0x0105, /* 0x0011 */ AssistEffect::SKIP_SET},
|
||||
{0x0106, /* 0x0012 */ AssistEffect::SKIP_MOVE},
|
||||
{0x0121, /* 0x0013 */ AssistEffect::SKIP_ACT},
|
||||
{0x0137, /* 0x0014 */ AssistEffect::SKIP_DRAW},
|
||||
{0x0107, /* 0x0015 */ AssistEffect::FLY},
|
||||
{0x0108, /* 0x0016 */ AssistEffect::NECROMANCER},
|
||||
{0x0109, /* 0x0017 */ AssistEffect::PERMISSION},
|
||||
{0x010A, /* 0x0018 */ AssistEffect::SHUFFLE_ALL},
|
||||
{0x010B, /* 0x0019 */ AssistEffect::LEGACY},
|
||||
{0x010C, /* 0x001A */ AssistEffect::ASSIST_REVERSE},
|
||||
{0x010D, /* 0x001B */ AssistEffect::STAMINA},
|
||||
{0x010E, /* 0x001C */ AssistEffect::AP_ABSORPTION},
|
||||
{0x010F, /* 0x001D */ AssistEffect::HEAVY_FOG},
|
||||
{0x0125, /* 0x001E */ AssistEffect::TRASH_1},
|
||||
{0x0126, /* 0x001F */ AssistEffect::EMPTY_HAND},
|
||||
{0x0127, /* 0x0020 */ AssistEffect::HITMAN},
|
||||
{0x0128, /* 0x0021 */ AssistEffect::ASSIST_TRASH},
|
||||
{0x0129, /* 0x0022 */ AssistEffect::SHUFFLE_GROUP},
|
||||
{0x012A, /* 0x0023 */ AssistEffect::ASSIST_VANISH},
|
||||
{0x012B, /* 0x0024 */ AssistEffect::CHARITY},
|
||||
{0x012C, /* 0x0025 */ AssistEffect::INHERITANCE},
|
||||
{0x012D, /* 0x0026 */ AssistEffect::FIX},
|
||||
{0x012E, /* 0x0027 */ AssistEffect::MUSCULAR},
|
||||
{0x012F, /* 0x0028 */ AssistEffect::CHANGE_BODY},
|
||||
{0x0130, /* 0x0029 */ AssistEffect::GOD_WHIM},
|
||||
{0x0131, /* 0x002A */ AssistEffect::GOLD_RUSH},
|
||||
{0x0132, /* 0x002B */ AssistEffect::ASSIST_RETURN},
|
||||
{0x0133, /* 0x002C */ AssistEffect::REQUIEM},
|
||||
{0x0134, /* 0x002D */ AssistEffect::RANSOM},
|
||||
{0x0135, /* 0x002E */ AssistEffect::SIMPLE},
|
||||
{0x0136, /* 0x002F */ AssistEffect::SLOW_TIME},
|
||||
{0x023F, /* 0x0030 */ AssistEffect::QUICK_TIME},
|
||||
{0x0138, /* 0x0031 */ AssistEffect::TERRITORY},
|
||||
{0x0139, /* 0x0032 */ AssistEffect::OLD_TYPE},
|
||||
{0x013A, /* 0x0033 */ AssistEffect::FLATLAND},
|
||||
{0x013B, /* 0x0034 */ AssistEffect::IMMORTALITY},
|
||||
{0x013C, /* 0x0035 */ AssistEffect::SNAIL_PACE},
|
||||
{0x013D, /* 0x0036 */ AssistEffect::TECH_FIELD},
|
||||
{0x013E, /* 0x0037 */ AssistEffect::FOREST_RAIN},
|
||||
{0x013F, /* 0x0038 */ AssistEffect::CAVE_WIND},
|
||||
{0x0140, /* 0x0039 */ AssistEffect::MINE_BRIGHTNESS},
|
||||
{0x0141, /* 0x003A */ AssistEffect::RUIN_DARKNESS},
|
||||
{0x0142, /* 0x003B */ AssistEffect::SABER_DANCE},
|
||||
{0x0143, /* 0x003C */ AssistEffect::BULLET_STORM},
|
||||
{0x0144, /* 0x003D */ AssistEffect::CANE_PALACE},
|
||||
{0x0145, /* 0x003E */ AssistEffect::GIANT_GARDEN},
|
||||
{0x0146, /* 0x003F */ AssistEffect::MARCH_OF_THE_MEEK},
|
||||
{0x0148, /* 0x0040 */ AssistEffect::SUPPORT},
|
||||
{0x014A, /* 0x0041 */ AssistEffect::RICH},
|
||||
{0x014B, /* 0x0042 */ AssistEffect::REVERSE_CARD},
|
||||
{0x014C, /* 0x0043 */ AssistEffect::VENGEANCE},
|
||||
{0x014D, /* 0x0044 */ AssistEffect::SQUEEZE},
|
||||
{0x014E, /* 0x0045 */ AssistEffect::HOMESICK},
|
||||
{0x0240, /* 0x0046 */ AssistEffect::BOMB},
|
||||
{0x0241, /* 0x0047 */ AssistEffect::SKIP_TURN},
|
||||
{0x0242, /* 0x0048 */ AssistEffect::BATTLE_ROYALE},
|
||||
{0x0018, /* 0x0049 */ AssistEffect::DICE_FEVER_PLUS},
|
||||
{0x0019, /* 0x004A */ AssistEffect::RICH_PLUS},
|
||||
{0x001A, /* 0x004B */ AssistEffect::CHARITY_PLUS},
|
||||
{0x00F5, /* 0x0001 */ AssistEffect::DICE_HALF},
|
||||
{0x00F6, /* 0x0002 */ AssistEffect::DICE_PLUS_1},
|
||||
{0x00F7, /* 0x0003 */ AssistEffect::DICE_FEVER},
|
||||
{0x00F8, /* 0x0004 */ AssistEffect::CARD_RETURN},
|
||||
{0x00F9, /* 0x0005 */ AssistEffect::LAND_PRICE},
|
||||
{0x00FA, /* 0x0006 */ AssistEffect::POWERLESS_RAIN},
|
||||
{0x00FB, /* 0x0007 */ AssistEffect::BRAVE_WIND},
|
||||
{0x00FC, /* 0x0008 */ AssistEffect::SILENT_COLOSSEUM},
|
||||
{0x00FD, /* 0x0009 */ AssistEffect::RESISTANCE},
|
||||
{0x00FE, /* 0x000A */ AssistEffect::INDEPENDENT},
|
||||
{0x00FF, /* 0x000B */ AssistEffect::ASSISTLESS},
|
||||
{0x0100, /* 0x000C */ AssistEffect::ATK_DICE_2},
|
||||
{0x0101, /* 0x000D */ AssistEffect::DEFLATION},
|
||||
{0x0102, /* 0x000E */ AssistEffect::INFLATION},
|
||||
{0x0103, /* 0x000F */ AssistEffect::EXCHANGE},
|
||||
{0x0104, /* 0x0010 */ AssistEffect::INFLUENCE},
|
||||
{0x0105, /* 0x0011 */ AssistEffect::SKIP_SET},
|
||||
{0x0106, /* 0x0012 */ AssistEffect::SKIP_MOVE},
|
||||
{0x0121, /* 0x0013 */ AssistEffect::SKIP_ACT},
|
||||
{0x0137, /* 0x0014 */ AssistEffect::SKIP_DRAW},
|
||||
{0x0107, /* 0x0015 */ AssistEffect::FLY},
|
||||
{0x0108, /* 0x0016 */ AssistEffect::NECROMANCER},
|
||||
{0x0109, /* 0x0017 */ AssistEffect::PERMISSION},
|
||||
{0x010A, /* 0x0018 */ AssistEffect::SHUFFLE_ALL},
|
||||
{0x010B, /* 0x0019 */ AssistEffect::LEGACY},
|
||||
{0x010C, /* 0x001A */ AssistEffect::ASSIST_REVERSE},
|
||||
{0x010D, /* 0x001B */ AssistEffect::STAMINA},
|
||||
{0x010E, /* 0x001C */ AssistEffect::AP_ABSORPTION},
|
||||
{0x010F, /* 0x001D */ AssistEffect::HEAVY_FOG},
|
||||
{0x0125, /* 0x001E */ AssistEffect::TRASH_1},
|
||||
{0x0126, /* 0x001F */ AssistEffect::EMPTY_HAND},
|
||||
{0x0127, /* 0x0020 */ AssistEffect::HITMAN},
|
||||
{0x0128, /* 0x0021 */ AssistEffect::ASSIST_TRASH},
|
||||
{0x0129, /* 0x0022 */ AssistEffect::SHUFFLE_GROUP},
|
||||
{0x012A, /* 0x0023 */ AssistEffect::ASSIST_VANISH},
|
||||
{0x012B, /* 0x0024 */ AssistEffect::CHARITY},
|
||||
{0x012C, /* 0x0025 */ AssistEffect::INHERITANCE},
|
||||
{0x012D, /* 0x0026 */ AssistEffect::FIX},
|
||||
{0x012E, /* 0x0027 */ AssistEffect::MUSCULAR},
|
||||
{0x012F, /* 0x0028 */ AssistEffect::CHANGE_BODY},
|
||||
{0x0130, /* 0x0029 */ AssistEffect::GOD_WHIM},
|
||||
{0x0131, /* 0x002A */ AssistEffect::GOLD_RUSH},
|
||||
{0x0132, /* 0x002B */ AssistEffect::ASSIST_RETURN},
|
||||
{0x0133, /* 0x002C */ AssistEffect::REQUIEM},
|
||||
{0x0134, /* 0x002D */ AssistEffect::RANSOM},
|
||||
{0x0135, /* 0x002E */ AssistEffect::SIMPLE},
|
||||
{0x0136, /* 0x002F */ AssistEffect::SLOW_TIME},
|
||||
{0x023F, /* 0x0030 */ AssistEffect::QUICK_TIME},
|
||||
{0x0138, /* 0x0031 */ AssistEffect::TERRITORY},
|
||||
{0x0139, /* 0x0032 */ AssistEffect::OLD_TYPE},
|
||||
{0x013A, /* 0x0033 */ AssistEffect::FLATLAND},
|
||||
{0x013B, /* 0x0034 */ AssistEffect::IMMORTALITY},
|
||||
{0x013C, /* 0x0035 */ AssistEffect::SNAIL_PACE},
|
||||
{0x013D, /* 0x0036 */ AssistEffect::TECH_FIELD},
|
||||
{0x013E, /* 0x0037 */ AssistEffect::FOREST_RAIN},
|
||||
{0x013F, /* 0x0038 */ AssistEffect::CAVE_WIND},
|
||||
{0x0140, /* 0x0039 */ AssistEffect::MINE_BRIGHTNESS},
|
||||
{0x0141, /* 0x003A */ AssistEffect::RUIN_DARKNESS},
|
||||
{0x0142, /* 0x003B */ AssistEffect::SABER_DANCE},
|
||||
{0x0143, /* 0x003C */ AssistEffect::BULLET_STORM},
|
||||
{0x0144, /* 0x003D */ AssistEffect::CANE_PALACE},
|
||||
{0x0145, /* 0x003E */ AssistEffect::GIANT_GARDEN},
|
||||
{0x0146, /* 0x003F */ AssistEffect::MARCH_OF_THE_MEEK},
|
||||
{0x0148, /* 0x0040 */ AssistEffect::SUPPORT},
|
||||
{0x014A, /* 0x0041 */ AssistEffect::RICH},
|
||||
{0x014B, /* 0x0042 */ AssistEffect::REVERSE_CARD},
|
||||
{0x014C, /* 0x0043 */ AssistEffect::VENGEANCE},
|
||||
{0x014D, /* 0x0044 */ AssistEffect::SQUEEZE},
|
||||
{0x014E, /* 0x0045 */ AssistEffect::HOMESICK},
|
||||
{0x0240, /* 0x0046 */ AssistEffect::BOMB},
|
||||
{0x0241, /* 0x0047 */ AssistEffect::SKIP_TURN},
|
||||
{0x0242, /* 0x0048 */ AssistEffect::BATTLE_ROYALE},
|
||||
{0x0018, /* 0x0049 */ AssistEffect::DICE_FEVER_PLUS},
|
||||
{0x0019, /* 0x004A */ AssistEffect::RICH_PLUS},
|
||||
{0x001A, /* 0x004B */ AssistEffect::CHARITY_PLUS},
|
||||
});
|
||||
try {
|
||||
return card_id_to_effect.at(card_id);
|
||||
@@ -107,15 +105,13 @@ AssistEffect assist_effect_number_for_card_id(uint16_t card_id) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
AssistServer::AssistServer(shared_ptr<Server> server)
|
||||
: w_server(server),
|
||||
assist_effects(AssistEffect::NONE),
|
||||
num_assist_cards_set(0),
|
||||
client_ids_with_assists(0xFF),
|
||||
active_assist_effects(AssistEffect::NONE),
|
||||
num_active_assists(0) { }
|
||||
: w_server(server),
|
||||
assist_effects(AssistEffect::NONE),
|
||||
num_assist_cards_set(0),
|
||||
client_ids_with_assists(0xFF),
|
||||
active_assist_effects(AssistEffect::NONE),
|
||||
num_active_assists(0) {}
|
||||
|
||||
shared_ptr<Server> AssistServer::server() {
|
||||
auto s = this->w_server.lock();
|
||||
@@ -137,7 +133,7 @@ uint16_t AssistServer::card_id_for_card_ref(uint16_t card_ref) const {
|
||||
return this->server()->card_id_for_card_ref(card_ref);
|
||||
}
|
||||
|
||||
shared_ptr<const DataIndex::CardEntry> AssistServer::definition_for_card_id(
|
||||
shared_ptr<const CardIndex::CardEntry> AssistServer::definition_for_card_id(
|
||||
uint16_t card_id) const {
|
||||
return this->server()->definition_for_card_id(card_id);
|
||||
}
|
||||
@@ -281,6 +277,4 @@ void AssistServer::recompute_effects() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
@@ -5,14 +5,12 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "DataIndex.hh"
|
||||
#include "PlayerState.hh"
|
||||
#include "DataIndexes.hh"
|
||||
#include "DeckState.hh"
|
||||
#include "PlayerState.hh"
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
class Server;
|
||||
|
||||
extern const std::vector<uint16_t> ALL_ASSIST_CARD_IDS;
|
||||
@@ -26,7 +24,7 @@ public:
|
||||
std::shared_ptr<const Server> server() const;
|
||||
|
||||
uint16_t card_id_for_card_ref(uint16_t card_ref) const;
|
||||
std::shared_ptr<const DataIndex::CardEntry> definition_for_card_id(uint16_t card_id) const;
|
||||
std::shared_ptr<const CardIndex::CardEntry> definition_for_card_id(uint16_t card_id) const;
|
||||
|
||||
uint32_t compute_num_assist_effects_for_client(uint16_t client_id);
|
||||
uint32_t compute_num_assist_effects_for_team(uint32_t team_id);
|
||||
@@ -42,11 +40,11 @@ private:
|
||||
|
||||
public:
|
||||
parray<AssistEffect, 4> assist_effects;
|
||||
std::shared_ptr<const DataIndex::CardEntry> assist_card_defs[4];
|
||||
std::shared_ptr<const CardIndex::CardEntry> assist_card_defs[4];
|
||||
uint32_t num_assist_cards_set;
|
||||
parray<uint8_t, 4> client_ids_with_assists;
|
||||
parray<AssistEffect, 4> active_assist_effects;
|
||||
std::shared_ptr<const DataIndex::CardEntry> active_assist_card_defs[4];
|
||||
std::shared_ptr<const CardIndex::CardEntry> active_assist_card_defs[4];
|
||||
uint32_t num_active_assists;
|
||||
std::shared_ptr<HandAndEquipState> hand_and_equip_states[4];
|
||||
std::shared_ptr<parray<CardShortStatus, 0x10>> card_short_statuses[4];
|
||||
@@ -55,6 +53,4 @@ public:
|
||||
std::shared_ptr<parray<ActionMetadata, 9>> set_card_action_metadatas[4];
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
@@ -9,8 +9,6 @@ using namespace std;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
BattleRecord::Event::Event(StringReader& r) {
|
||||
this->type = r.get<Event::Type>();
|
||||
this->timestamp = r.get_u64l();
|
||||
@@ -74,19 +72,17 @@ void BattleRecord::Event::serialize(StringWriter& w) const {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
BattleRecord::BattleRecord(uint32_t behavior_flags)
|
||||
: is_writable(true),
|
||||
behavior_flags(behavior_flags),
|
||||
battle_start_timestamp(0),
|
||||
battle_end_timestamp(0) { }
|
||||
: is_writable(true),
|
||||
behavior_flags(behavior_flags),
|
||||
battle_start_timestamp(0),
|
||||
battle_end_timestamp(0) {}
|
||||
|
||||
BattleRecord::BattleRecord(const string& data)
|
||||
: is_writable(false),
|
||||
behavior_flags(0),
|
||||
battle_start_timestamp(0),
|
||||
battle_end_timestamp(0) {
|
||||
: is_writable(false),
|
||||
behavior_flags(0),
|
||||
battle_start_timestamp(0),
|
||||
battle_end_timestamp(0) {
|
||||
StringReader r(data);
|
||||
uint64_t signature = r.get_u64l();
|
||||
if (signature != this->SIGNATURE) {
|
||||
@@ -110,7 +106,7 @@ string BattleRecord::serialize() const {
|
||||
for (const auto& ev : this->events) {
|
||||
ev.serialize(w);
|
||||
}
|
||||
return move(w.str());
|
||||
return std::move(w.str());
|
||||
}
|
||||
|
||||
bool BattleRecord::writable() const {
|
||||
@@ -128,7 +124,6 @@ const BattleRecord::Event* BattleRecord::get_first_event() const {
|
||||
return &this->events.front();
|
||||
}
|
||||
|
||||
|
||||
void BattleRecord::add_player(
|
||||
const PlayerLobbyDataDCGC& lobby_data,
|
||||
const PlayerInventory& inventory,
|
||||
@@ -175,7 +170,7 @@ void BattleRecord::add_command(Event::Type type, string&& data) {
|
||||
Event& ev = this->events.emplace_back();
|
||||
ev.type = type;
|
||||
ev.timestamp = now();
|
||||
ev.data = move(data);
|
||||
ev.data = std::move(data);
|
||||
}
|
||||
|
||||
void BattleRecord::add_chat_message(
|
||||
@@ -187,16 +182,14 @@ void BattleRecord::add_chat_message(
|
||||
ev.type = Event::Type::CHAT_MESSAGE;
|
||||
ev.timestamp = now();
|
||||
ev.guild_card_number = guild_card_number;
|
||||
ev.data = move(data);
|
||||
ev.data = std::move(data);
|
||||
}
|
||||
|
||||
bool BattleRecord::is_map_definition_event(const Event& ev) {
|
||||
if (ev.type == Event::Type::BATTLE_COMMAND) {
|
||||
auto& header = check_size_t<G_CardBattleCommandHeader>(
|
||||
ev.data, sizeof(G_CardBattleCommandHeader), 0xFFFF);
|
||||
auto& header = check_size_t<G_CardBattleCommandHeader>(ev.data, 0xFFFF);
|
||||
if (header.subcommand == 0xB6) {
|
||||
auto& header = check_size_t<G_MapSubsubcommand_GC_Ep3_6xB6>(
|
||||
ev.data, sizeof(G_MapSubsubcommand_GC_Ep3_6xB6), 0xFFFF);
|
||||
auto& header = check_size_t<G_MapSubsubcommand_GC_Ep3_6xB6>(ev.data, 0xFFFF);
|
||||
if (header.subsubcommand == 0x41) {
|
||||
return true;
|
||||
}
|
||||
@@ -253,7 +246,7 @@ void BattleRecord::set_battle_start_timestamp() {
|
||||
initial_ev.players.emplace_back(players[z]);
|
||||
}
|
||||
}
|
||||
new_events.emplace_back(move(initial_ev));
|
||||
new_events.emplace_back(std::move(initial_ev));
|
||||
|
||||
// Skip all events before the last map definition event, and only retain
|
||||
// battle commands between then and now (since these battle commands will all
|
||||
@@ -269,26 +262,24 @@ void BattleRecord::set_battle_start_timestamp() {
|
||||
}
|
||||
for (; it != this->events.end(); it++) {
|
||||
if (it->type == Event::Type::BATTLE_COMMAND) {
|
||||
new_events.emplace_back(move(*it));
|
||||
new_events.emplace_back(std::move(*it));
|
||||
}
|
||||
}
|
||||
this->events = move(new_events);
|
||||
this->events = std::move(new_events);
|
||||
}
|
||||
|
||||
void BattleRecord::set_battle_end_timestamp() {
|
||||
this->battle_end_timestamp = now();
|
||||
}
|
||||
|
||||
|
||||
|
||||
BattleRecordPlayer::BattleRecordPlayer(
|
||||
shared_ptr<const BattleRecord> rec,
|
||||
shared_ptr<struct event_base> base)
|
||||
: record(rec),
|
||||
event_it(this->record->events.begin()),
|
||||
play_start_timestamp(0),
|
||||
base(base),
|
||||
next_command_ev(event_new(this->base.get(), -1, EV_TIMEOUT, &BattleRecordPlayer::dispatch_schedule_events, this), event_free) { }
|
||||
: record(rec),
|
||||
event_it(this->record->events.begin()),
|
||||
play_start_timestamp(0),
|
||||
base(base),
|
||||
next_command_ev(event_new(this->base.get(), -1, EV_TIMEOUT, &BattleRecordPlayer::dispatch_schedule_events, this), event_free) {}
|
||||
|
||||
shared_ptr<const BattleRecord> BattleRecordPlayer::get_record() const {
|
||||
return this->record;
|
||||
@@ -323,7 +314,7 @@ void BattleRecordPlayer::schedule_events() {
|
||||
|
||||
if (this->event_it == this->record->events.end()) {
|
||||
if (relative_ts >= this->record->battle_end_timestamp) {
|
||||
// If the record is complete and the end timestamp has been reached, so
|
||||
// If the record is complete and the end timestamp has been reached,
|
||||
// send exit commands to all players in the lobby, and don't reschedule
|
||||
// the event (it will be deleted along with the Player when the lobby is
|
||||
// destroyed, when the last client leaves)
|
||||
@@ -377,6 +368,4 @@ void BattleRecordPlayer::schedule_events() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <event2/event.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
#include <phosg/Strings.hh>
|
||||
|
||||
#include "../Player.hh"
|
||||
|
||||
@@ -17,8 +17,6 @@ namespace Episode3 {
|
||||
|
||||
// The comment in Server.hh does not apply to this file (and BattleRecord.cc).
|
||||
|
||||
|
||||
|
||||
class BattleRecord {
|
||||
public:
|
||||
struct PlayerEntry {
|
||||
@@ -118,7 +116,4 @@ private:
|
||||
std::shared_ptr<struct event> next_command_ev;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
+29
-33
@@ -1,36 +1,34 @@
|
||||
#include "Card.hh"
|
||||
|
||||
#include "Server.hh"
|
||||
#include "../CommandFormats.hh"
|
||||
#include "Server.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
Card::Card(
|
||||
uint16_t card_id,
|
||||
uint16_t card_ref,
|
||||
uint16_t client_id,
|
||||
shared_ptr<Server> server)
|
||||
: w_server(server),
|
||||
w_player_state(server->get_player_state(client_id)),
|
||||
client_id(client_id),
|
||||
card_id(card_id),
|
||||
card_ref(card_ref),
|
||||
card_flags(0),
|
||||
loc(0, 0, Direction::RIGHT),
|
||||
facing_direction(Direction::INVALID_FF),
|
||||
action_chain(),
|
||||
action_metadata(),
|
||||
num_ally_fcs_destroyed_at_set_time(0),
|
||||
num_cards_destroyed_by_team_at_set_time(0),
|
||||
unknown_a9(1),
|
||||
last_attack_preliminary_damage(0),
|
||||
last_attack_final_damage(0),
|
||||
num_destroyed_ally_fcs(0),
|
||||
current_defense_power(0) { }
|
||||
: w_server(server),
|
||||
w_player_state(server->get_player_state(client_id)),
|
||||
client_id(client_id),
|
||||
card_id(card_id),
|
||||
card_ref(card_ref),
|
||||
card_flags(0),
|
||||
loc(0, 0, Direction::RIGHT),
|
||||
facing_direction(Direction::INVALID_FF),
|
||||
action_chain(),
|
||||
action_metadata(),
|
||||
num_ally_fcs_destroyed_at_set_time(0),
|
||||
num_cards_destroyed_by_team_at_set_time(0),
|
||||
unknown_a9(1),
|
||||
last_attack_preliminary_damage(0),
|
||||
last_attack_final_damage(0),
|
||||
num_destroyed_ally_fcs(0),
|
||||
current_defense_power(0) {}
|
||||
|
||||
void Card::init() {
|
||||
this->clear_action_chain_and_metadata_and_most_flags();
|
||||
@@ -117,7 +115,7 @@ ssize_t Card::apply_abnormal_condition(
|
||||
existing_cond_index = z;
|
||||
if (eff.type == ConditionType::MV_BONUS ||
|
||||
((cond.card_definition_effect_index == def_effect_index) &&
|
||||
(cond.card_ref == target_card_ref))) {
|
||||
(cond.card_ref == target_card_ref))) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@@ -215,8 +213,8 @@ void Card::apply_ap_adjust_assists_to_attack(
|
||||
|
||||
bool Card::card_type_is_sc_or_creature() const {
|
||||
return (this->def_entry->def.type == CardType::HUNTERS_SC) ||
|
||||
(this->def_entry->def.type == CardType::ARKZ_SC) ||
|
||||
(this->def_entry->def.type == CardType::CREATURE);
|
||||
(this->def_entry->def.type == CardType::ARKZ_SC) ||
|
||||
(this->def_entry->def.type == CardType::CREATURE);
|
||||
}
|
||||
|
||||
bool Card::check_card_flag(uint32_t flags) const {
|
||||
@@ -254,7 +252,6 @@ void Card::commit_attack(
|
||||
effective_damage = 0;
|
||||
}
|
||||
|
||||
|
||||
auto attacker_ps = attacker_card->player_state();
|
||||
attacker_ps->stats.damage_given += effective_damage;
|
||||
this->player_state()->stats.damage_taken += effective_damage;
|
||||
@@ -406,13 +403,13 @@ int32_t Card::error_code_for_move_to_location(const Location& loc) const {
|
||||
return -0x60;
|
||||
}
|
||||
if (!this->server()->ruler_server->card_ref_can_move(
|
||||
this->client_id, this->card_ref, 1)) {
|
||||
this->client_id, this->card_ref, 1)) {
|
||||
return -0x7B;
|
||||
}
|
||||
// Note: The original code passes non-null pointers here but ignores the
|
||||
// values written to them; we use nulls since the behavior should be the same.
|
||||
if (!this->server()->ruler_server->get_move_path_length_and_cost(
|
||||
this->client_id, this->card_ref, loc, nullptr, nullptr)) {
|
||||
this->client_id, this->card_ref, loc, nullptr, nullptr)) {
|
||||
return -0x79;
|
||||
}
|
||||
return 0;
|
||||
@@ -510,7 +507,7 @@ bool Card::get_attack_condition_value(
|
||||
cond_type, card_ref, def_effect_index, value, out_value);
|
||||
}
|
||||
|
||||
shared_ptr<const DataIndex::CardEntry> Card::get_definition() const {
|
||||
shared_ptr<const CardIndex::CardEntry> Card::get_definition() const {
|
||||
return this->def_entry;
|
||||
}
|
||||
|
||||
@@ -556,7 +553,7 @@ int32_t Card::move_to_location(const Location& loc) {
|
||||
uint32_t path_cost;
|
||||
uint32_t path_length;
|
||||
if (!this->server()->ruler_server->get_move_path_length_and_cost(
|
||||
this->client_id, this->card_ref, loc, &path_length, &path_cost)) {
|
||||
this->client_id, this->card_ref, loc, &path_length, &path_cost)) {
|
||||
return -0x79;
|
||||
}
|
||||
|
||||
@@ -575,7 +572,9 @@ int32_t Card::move_to_location(const Location& loc) {
|
||||
this->loc.x = this->server()->warp_positions[warp_type][warp_end ^ 1][0];
|
||||
this->loc.y = this->server()->warp_positions[warp_type][warp_end ^ 1][1];
|
||||
cmd.change_type = 0;
|
||||
cmd.card_refs.clear(0xFFFF);
|
||||
cmd.card_refs[0] = this->card_ref;
|
||||
cmd.unknown_a2.clear(0xFFFFFFFF);
|
||||
this->server()->send(cmd);
|
||||
return 0;
|
||||
}
|
||||
@@ -598,7 +597,6 @@ void Card::propagate_shared_hp_if_needed() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Card::send_6xB4x4E_4C_4D_if_needed(bool always_send) {
|
||||
ssize_t index = -1;
|
||||
if (this->card_ref == this->player_state()->get_sc_card_ref()) {
|
||||
@@ -940,11 +938,11 @@ void Card::unknown_80237F98(bool require_condition_20_or_21) {
|
||||
if (this->action_chain.conditions[z].type != ConditionType::NONE) {
|
||||
if (!require_condition_20_or_21 ||
|
||||
this->server()->card_special->condition_has_when_20_or_21(
|
||||
this->action_chain.conditions[z])) {
|
||||
this->action_chain.conditions[z])) {
|
||||
ActionState as;
|
||||
auto& cond = this->action_chain.conditions[z];
|
||||
if (!this->server()->card_special->is_card_targeted_by_condition(
|
||||
cond, as, this->shared_from_this())) {
|
||||
cond, as, this->shared_from_this())) {
|
||||
this->server()->card_special->apply_stat_deltas_to_card_from_condition_and_clear_cond(
|
||||
cond, this->shared_from_this());
|
||||
should_send_updates = true;
|
||||
@@ -1237,6 +1235,4 @@ void Card::unknown_80237734() {
|
||||
this->send_6xB4x4E_4C_4D_if_needed();
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
@@ -4,14 +4,12 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "../Text.hh"
|
||||
#include "../CommandFormats.hh"
|
||||
#include "DataIndex.hh"
|
||||
#include "../Text.hh"
|
||||
#include "DataIndexes.hh"
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
class ServerBase;
|
||||
class Server;
|
||||
class PlayerState;
|
||||
@@ -60,7 +58,7 @@ public:
|
||||
uint8_t def_effect_index,
|
||||
uint16_t value,
|
||||
uint16_t* out_value) const;
|
||||
std::shared_ptr<const DataIndex::CardEntry> get_definition() const;
|
||||
std::shared_ptr<const CardIndex::CardEntry> get_definition() const;
|
||||
uint16_t get_card_ref() const;
|
||||
uint8_t get_client_id() const;
|
||||
uint8_t get_current_hp() const;
|
||||
@@ -101,12 +99,12 @@ private:
|
||||
public:
|
||||
int16_t max_hp;
|
||||
int16_t current_hp;
|
||||
std::shared_ptr<const DataIndex::CardEntry> def_entry;
|
||||
std::shared_ptr<const CardIndex::CardEntry> def_entry;
|
||||
uint8_t client_id;
|
||||
uint16_t card_id;
|
||||
uint16_t card_ref;
|
||||
uint16_t sc_card_ref;
|
||||
std::shared_ptr<const DataIndex::CardEntry> sc_def_entry;
|
||||
std::shared_ptr<const CardIndex::CardEntry> sc_def_entry;
|
||||
CardType sc_card_type;
|
||||
uint8_t team_id;
|
||||
uint32_t card_flags;
|
||||
@@ -126,6 +124,4 @@ public:
|
||||
int16_t current_defense_power;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
+255
-252
@@ -6,8 +6,6 @@ using namespace std;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
CardSpecial::DiceRoll::DiceRoll() {
|
||||
this->clear();
|
||||
}
|
||||
@@ -20,8 +18,6 @@ void CardSpecial::DiceRoll::clear() {
|
||||
this->unknown_a5 = 0xFFFF;
|
||||
}
|
||||
|
||||
|
||||
|
||||
CardSpecial::AttackEnvStats::AttackEnvStats() {
|
||||
this->clear();
|
||||
}
|
||||
@@ -73,10 +69,9 @@ uint32_t CardSpecial::AttackEnvStats::at(size_t offset) const {
|
||||
return reinterpret_cast<const parray<uint32_t, count>*>(this)->at(offset);
|
||||
}
|
||||
|
||||
|
||||
|
||||
CardSpecial::CardSpecial(shared_ptr<Server> server)
|
||||
: w_server(server), unknown_a2(0) { }
|
||||
: w_server(server),
|
||||
unknown_a2(0) {}
|
||||
|
||||
shared_ptr<Server> CardSpecial::server() {
|
||||
auto s = this->w_server.lock();
|
||||
@@ -109,11 +104,11 @@ void CardSpecial::adjust_attack_damage_due_to_conditions(
|
||||
}
|
||||
|
||||
if (!this->server()->ruler_server->check_usability_or_apply_condition_for_card_refs(
|
||||
cond.card_ref,
|
||||
target_card->get_card_ref(),
|
||||
attacker_card_ref,
|
||||
cond.card_definition_effect_index,
|
||||
attack_medium)) {
|
||||
cond.card_ref,
|
||||
target_card->get_card_ref(),
|
||||
attacker_card_ref,
|
||||
cond.card_definition_effect_index,
|
||||
attack_medium)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -411,7 +406,7 @@ bool CardSpecial::apply_stat_deltas_to_card_from_condition_and_clear_cond(
|
||||
if (hp != ap) {
|
||||
this->send_6xB4x06_for_stat_delta(card, cond_card_ref, 0xA0, hp - ap, 0, 0);
|
||||
this->send_6xB4x06_for_stat_delta(card, cond_card_ref, 0x20, ap - hp, 0, 0);
|
||||
card->set_current_hp(ap,1,1);
|
||||
card->set_current_hp(ap, 1, 1);
|
||||
card->ap = hp;
|
||||
this->destroy_card_if_hp_zero(card, cond_card_ref);
|
||||
}
|
||||
@@ -501,7 +496,7 @@ bool CardSpecial::card_has_condition_with_ref(
|
||||
uint16_t match_card_ref) const {
|
||||
size_t z = 0;
|
||||
while ((z < 9) &&
|
||||
((card->action_chain.conditions[z].type != cond_type) ||
|
||||
((card->action_chain.conditions[z].type != cond_type) ||
|
||||
(card->action_chain.conditions[z].card_ref == card_ref))) {
|
||||
z++;
|
||||
}
|
||||
@@ -532,7 +527,7 @@ void CardSpecial::compute_attack_ap(
|
||||
: AttackMedium::UNKNOWN;
|
||||
uint16_t target_card_ref = target_card->get_card_ref();
|
||||
|
||||
auto check_card = [&](shared_ptr<Card> card) -> void{
|
||||
auto check_card = [&](shared_ptr<Card> card) -> void {
|
||||
if (!card || (card->card_flags & 3)) {
|
||||
return;
|
||||
}
|
||||
@@ -541,19 +536,19 @@ void CardSpecial::compute_attack_ap(
|
||||
if (cond.type == ConditionType::NONE ||
|
||||
this->card_ref_has_ability_trap(cond) ||
|
||||
!this->server()->ruler_server->check_usability_or_apply_condition_for_card_refs(
|
||||
card->action_chain.conditions[cond_index].card_ref,
|
||||
target_card->get_card_ref(),
|
||||
attacker_card_ref,
|
||||
card->action_chain.conditions[cond_index].card_definition_effect_index,
|
||||
attacker_sc_attack_medium)) {
|
||||
card->action_chain.conditions[cond_index].card_ref,
|
||||
target_card->get_card_ref(),
|
||||
attacker_card_ref,
|
||||
card->action_chain.conditions[cond_index].card_definition_effect_index,
|
||||
attacker_sc_attack_medium)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto cond_type = card->action_chain.conditions[cond_index].type;
|
||||
if (((cond_type == ConditionType::UNKNOWN_5F) &&
|
||||
(target_card_ref == card->action_chain.conditions[cond_index].condition_giver_card_ref)) ||
|
||||
(target_card_ref == card->action_chain.conditions[cond_index].condition_giver_card_ref)) ||
|
||||
((cond_type == ConditionType::UNKNOWN_60) &&
|
||||
(target_card_ref == card->action_chain.conditions[cond_index].card_ref))) {
|
||||
(target_card_ref == card->action_chain.conditions[cond_index].card_ref))) {
|
||||
*out_value = card->action_chain.conditions[cond_index].value8;
|
||||
}
|
||||
}
|
||||
@@ -570,7 +565,7 @@ void CardSpecial::compute_attack_ap(
|
||||
}
|
||||
|
||||
if (attacker_card &&
|
||||
attacker_card->get_attack_condition_value(ConditionType::UNKNOWN_7D, 0xFFFF,0xFF,0xFFFF, nullptr)) {
|
||||
attacker_card->get_attack_condition_value(ConditionType::UNKNOWN_7D, 0xFFFF, 0xFF, 0xFFFF, nullptr)) {
|
||||
*out_value = *out_value * 1.5f;
|
||||
}
|
||||
if (target_card &&
|
||||
@@ -611,7 +606,8 @@ CardSpecial::AttackEnvStats CardSpecial::compute_attack_env_stats(
|
||||
ast.total_num_set_cards = ps_num_set_cards;
|
||||
|
||||
uint8_t target_card_team_id = target_card
|
||||
? target_card->player_state()->get_team_id() : 0xFF;
|
||||
? target_card->player_state()->get_team_id()
|
||||
: 0xFF;
|
||||
|
||||
size_t target_team_num_set_cards = 0;
|
||||
size_t condition_giver_team_num_set_cards = 0;
|
||||
@@ -629,19 +625,26 @@ CardSpecial::AttackEnvStats CardSpecial::compute_attack_env_stats(
|
||||
ast.condition_giver_team_num_set_cards = condition_giver_team_num_set_cards;
|
||||
|
||||
ast.num_native_creatures = this->get_all_set_cards_by_team_and_class(
|
||||
CardClass::NATIVE_CREATURE, 0xFF, true).size();
|
||||
CardClass::NATIVE_CREATURE, 0xFF, true)
|
||||
.size();
|
||||
ast.num_a_beast_creatures = this->get_all_set_cards_by_team_and_class(
|
||||
CardClass::A_BEAST_CREATURE, 0xFF, true).size();
|
||||
CardClass::A_BEAST_CREATURE, 0xFF, true)
|
||||
.size();
|
||||
ast.num_machine_creatures = this->get_all_set_cards_by_team_and_class(
|
||||
CardClass::MACHINE_CREATURE, 0xFF, true).size();
|
||||
CardClass::MACHINE_CREATURE, 0xFF, true)
|
||||
.size();
|
||||
ast.num_dark_creatures = this->get_all_set_cards_by_team_and_class(
|
||||
CardClass::DARK_CREATURE, 0xFF, true).size();
|
||||
CardClass::DARK_CREATURE, 0xFF, true)
|
||||
.size();
|
||||
ast.num_sword_type_items = this->get_all_set_cards_by_team_and_class(
|
||||
CardClass::SWORD_ITEM, 0xFF, true).size();
|
||||
CardClass::SWORD_ITEM, 0xFF, true)
|
||||
.size();
|
||||
ast.num_gun_type_items = this->get_all_set_cards_by_team_and_class(
|
||||
CardClass::GUN_ITEM, 0xFF, true).size();
|
||||
CardClass::GUN_ITEM, 0xFF, true)
|
||||
.size();
|
||||
ast.num_cane_type_items = this->get_all_set_cards_by_team_and_class(
|
||||
CardClass::CANE_ITEM, 0xFF, true).size();
|
||||
CardClass::CANE_ITEM, 0xFF, true)
|
||||
.size();
|
||||
ast.num_sword_type_items_on_team = card
|
||||
? this->get_all_set_cards_by_team_and_class(CardClass::SWORD_ITEM, card->get_team_id(), true).size()
|
||||
: 0;
|
||||
@@ -672,11 +675,14 @@ CardSpecial::AttackEnvStats CardSpecial::compute_attack_env_stats(
|
||||
ast.team_dice_boost = card ? this->server()->team_dice_boost[card->get_team_id()] : 0;
|
||||
|
||||
ast.effective_ap_if_not_tech = (!attacker_card || (attacker_card->action_chain.chain.attack_medium == AttackMedium::TECH))
|
||||
? 0 : attacker_card->action_chain.chain.damage;
|
||||
? 0
|
||||
: attacker_card->action_chain.chain.damage;
|
||||
ast.effective_ap_if_not_tech2 = (!attacker_card || (attacker_card->action_chain.chain.attack_medium == AttackMedium::TECH))
|
||||
? 0 : attacker_card->action_chain.chain.damage;
|
||||
? 0
|
||||
: attacker_card->action_chain.chain.damage;
|
||||
ast.effective_ap_if_not_physical = (!attacker_card || (attacker_card->action_chain.chain.attack_medium == AttackMedium::PHYSICAL))
|
||||
? 0 : attacker_card->action_chain.chain.damage;
|
||||
? 0
|
||||
: attacker_card->action_chain.chain.damage;
|
||||
ast.sc_effective_ap = attacker_card ? attacker_card->action_chain.chain.damage : 0;
|
||||
ast.attack_bonus = card->action_metadata.attack_bonus;
|
||||
ast.last_attack_preliminary_damage = card->last_attack_preliminary_damage;
|
||||
@@ -707,7 +713,8 @@ CardSpecial::AttackEnvStats CardSpecial::compute_attack_env_stats(
|
||||
// original code.
|
||||
for (z = 0;
|
||||
((target_card_ref != pa.attacker_card_ref) && (z < 9) && (pa.action_card_refs[z] != 0xFFFF));
|
||||
z++) { }
|
||||
z++) {
|
||||
}
|
||||
ast.action_cards_ap = 0;
|
||||
ast.action_cards_tp = 0;
|
||||
for (; (z < 9) && (pa.action_card_refs[z] != 0xFFFF); z++) {
|
||||
@@ -789,11 +796,11 @@ shared_ptr<Card> CardSpecial::compute_replaced_target_based_on_conditions(
|
||||
continue;
|
||||
}
|
||||
if (!this->server()->ruler_server->check_usability_or_apply_condition_for_card_refs(
|
||||
target_card->action_chain.conditions[x].card_ref,
|
||||
target_card->get_card_ref(),
|
||||
attacker_card_ref,
|
||||
target_card->action_chain.conditions[x].card_definition_effect_index,
|
||||
attack_medium)) {
|
||||
target_card->action_chain.conditions[x].card_ref,
|
||||
target_card->get_card_ref(),
|
||||
attacker_card_ref,
|
||||
target_card->action_chain.conditions[x].card_definition_effect_index,
|
||||
attack_medium)) {
|
||||
continue;
|
||||
}
|
||||
if (target_card->action_chain.conditions[x].type != ConditionType::PARRY) {
|
||||
@@ -809,7 +816,7 @@ shared_ptr<Card> CardSpecial::compute_replaced_target_based_on_conditions(
|
||||
// the Gifoie card's ID (00D9) for compute_effective_range.
|
||||
// TODO: We should fix this so it doesn't rely on a fixed card definition.
|
||||
parray<uint8_t, 9 * 9> range;
|
||||
compute_effective_range(range, this->server()->base()->data_index, 0x00D9, target_card_loc, this->server()->base()->map_and_rules1);
|
||||
compute_effective_range(range, this->server()->base()->card_index, 0x00D9, target_card_loc, this->server()->base()->map_and_rules1);
|
||||
auto card_refs_in_parry_range = target_ps->get_all_cards_within_range(
|
||||
range, target_card_loc, 0xFF);
|
||||
|
||||
@@ -871,11 +878,11 @@ shared_ptr<Card> CardSpecial::compute_replaced_target_based_on_conditions(
|
||||
continue;
|
||||
}
|
||||
if (!this->server()->ruler_server->check_usability_or_apply_condition_for_card_refs(
|
||||
other_set_card->action_chain.conditions[z].card_ref,
|
||||
other_set_card->get_card_ref(),
|
||||
attacker_card_ref,
|
||||
other_set_card->action_chain.conditions[z].card_definition_effect_index,
|
||||
attack_medium)) {
|
||||
other_set_card->action_chain.conditions[z].card_ref,
|
||||
other_set_card->get_card_ref(),
|
||||
attacker_card_ref,
|
||||
other_set_card->action_chain.conditions[z].card_definition_effect_index,
|
||||
attack_medium)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -896,9 +903,9 @@ shared_ptr<Card> CardSpecial::compute_replaced_target_based_on_conditions(
|
||||
(unknown_p4 != 0) &&
|
||||
(target_card_ref == other_set_card->action_chain.conditions[z].condition_giver_card_ref)) {
|
||||
candidate_cards.emplace_back(other_set_card);
|
||||
if (unknown_p11 &&(def_effect_index != 0xFF) && (set_card_ref != 0xFFFF) &&
|
||||
if (unknown_p11 && (def_effect_index != 0xFF) && (set_card_ref != 0xFFFF) &&
|
||||
!this->server()->ruler_server->check_usability_or_apply_condition_for_card_refs(
|
||||
set_card_ref, sc_card_ref, other_set_card->get_card_ref(), def_effect_index, attack_medium)) {
|
||||
set_card_ref, sc_card_ref, other_set_card->get_card_ref(), def_effect_index, attack_medium)) {
|
||||
*unknown_p11 = 1;
|
||||
}
|
||||
}
|
||||
@@ -950,11 +957,11 @@ shared_ptr<Card> CardSpecial::compute_replaced_target_based_on_conditions(
|
||||
continue;
|
||||
}
|
||||
if (!this->server()->ruler_server->check_usability_or_apply_condition_for_card_refs(
|
||||
cond.card_ref,
|
||||
other_sc->get_card_ref(),
|
||||
attacker_card_ref,
|
||||
cond.card_definition_effect_index,
|
||||
attack_medium)) {
|
||||
cond.card_ref,
|
||||
other_sc->get_card_ref(),
|
||||
attacker_card_ref,
|
||||
cond.card_definition_effect_index,
|
||||
attack_medium)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -977,7 +984,7 @@ shared_ptr<Card> CardSpecial::compute_replaced_target_based_on_conditions(
|
||||
candidate_cards.emplace_back(other_sc);
|
||||
if (unknown_p11 && (def_effect_index != 0xFF) && (set_card_ref != 0xFFFF) &&
|
||||
!this->server()->ruler_server->check_usability_or_apply_condition_for_card_refs(
|
||||
set_card_ref, sc_card_ref, other_sc->get_card_ref(), def_effect_index, attack_medium)) {
|
||||
set_card_ref, sc_card_ref, other_sc->get_card_ref(), def_effect_index, attack_medium)) {
|
||||
*unknown_p11 = 1;
|
||||
}
|
||||
}
|
||||
@@ -1262,7 +1269,7 @@ bool CardSpecial::evaluate_effect_arg2_condition(
|
||||
|
||||
auto set_card = this->server()->card_for_set_card_ref(set_card_ref);
|
||||
bool set_card_has_ability_trap = (set_card &&
|
||||
(this->card_has_condition_with_ref(set_card, ConditionType::ABILITY_TRAP, 0xFFFF, 0xFFFF)));
|
||||
(this->card_has_condition_with_ref(set_card, ConditionType::ABILITY_TRAP, 0xFFFF, 0xFFFF)));
|
||||
|
||||
switch (arg2_text[0]) {
|
||||
case 'C':
|
||||
@@ -1392,15 +1399,15 @@ bool CardSpecial::evaluate_effect_arg2_condition(
|
||||
case 13: {
|
||||
auto ce = card->get_definition();
|
||||
return ((ce->def.card_class() == CardClass::GUARD_ITEM) ||
|
||||
(ce->def.card_class() == CardClass::MAG_ITEM) ||
|
||||
this->server()->ruler_server->find_condition_on_card_ref(
|
||||
card->get_card_ref(), ConditionType::GUARD_CREATURE, 0, 0, 0));
|
||||
(ce->def.card_class() == CardClass::MAG_ITEM) ||
|
||||
this->server()->ruler_server->find_condition_on_card_ref(
|
||||
card->get_card_ref(), ConditionType::GUARD_CREATURE, 0, 0, 0));
|
||||
}
|
||||
case 14:
|
||||
return card->get_definition()->def.is_sc();
|
||||
case 15:
|
||||
return ((card->action_chain.chain.attack_action_card_ref_count == 0) &&
|
||||
(card->action_metadata.defense_card_ref_count == 0));
|
||||
(card->action_metadata.defense_card_ref_count == 0));
|
||||
case 16:
|
||||
return this->server()->ruler_server->card_ref_is_aerial(card->get_card_ref());
|
||||
case 17: {
|
||||
@@ -1462,14 +1469,14 @@ bool CardSpecial::evaluate_effect_arg2_condition(
|
||||
}
|
||||
}
|
||||
return (this->find_condition_with_parameters(
|
||||
card, ConditionType::ANY, set_card_ref, ((v % 10) == 0) ? 0xFF : (v % 10)) != nullptr);
|
||||
card, ConditionType::ANY, set_card_ref, ((v % 10) == 0) ? 0xFF : (v % 10)) != nullptr);
|
||||
}
|
||||
case 'r':
|
||||
return !set_card_has_ability_trap && (random_percent < atoi(arg2_text + 1));
|
||||
case 's': {
|
||||
auto ce = card->get_definition();
|
||||
return ((ce->def.self_cost >= arg2_text[1] - '0') &&
|
||||
(ce->def.self_cost <= arg2_text[2] - '0'));
|
||||
(ce->def.self_cost <= arg2_text[2] - '0'));
|
||||
}
|
||||
case 't': {
|
||||
auto set_card = this->server()->card_for_set_card_ref(set_card_ref);
|
||||
@@ -1597,8 +1604,8 @@ bool CardSpecial::execute_effect(
|
||||
|
||||
if ((card->card_flags & 3) ||
|
||||
(card->action_metadata.check_flag(0x10) &&
|
||||
(cond.card_ref != card->get_card_ref()) &&
|
||||
(cond.condition_giver_card_ref != card->get_card_ref()))) {
|
||||
(cond.card_ref != card->get_card_ref()) &&
|
||||
(cond.condition_giver_card_ref != card->get_card_ref()))) {
|
||||
unknown_p7 = unknown_p7 & 0xFFFFFFFB;
|
||||
}
|
||||
if (unknown_p7 == 0) {
|
||||
@@ -1887,8 +1894,7 @@ bool CardSpecial::execute_effect(
|
||||
|
||||
case ConditionType::BONUS_FROM_LEADER:
|
||||
if (unknown_p7 & 1) {
|
||||
clamped_unknown_p5 = this->count_cards_with_card_id_set_by_player_except_card_ref(expr_value, 0xFFFF)
|
||||
+ (card->action_chain).chain.ap_effect_bonus;
|
||||
clamped_unknown_p5 = this->count_cards_with_card_id_set_by_player_except_card_ref(expr_value, 0xFFFF) + (card->action_chain).chain.ap_effect_bonus;
|
||||
(card->action_chain).chain.ap_effect_bonus = clamp<int16_t>(clamped_unknown_p5, -99, 99);
|
||||
}
|
||||
return true;
|
||||
@@ -2069,9 +2075,9 @@ bool CardSpecial::execute_effect(
|
||||
auto sc_card = this->server()->card_for_set_card_ref(card_ref);
|
||||
if (sc_card && (sc_card->get_current_hp() > 0)) {
|
||||
if (this->server()->ruler_server->check_usability_or_apply_condition_for_card_refs(
|
||||
cond.card_ref, cond.condition_giver_card_ref,
|
||||
sc_card->get_card_ref(), cond.card_definition_effect_index,
|
||||
attack_medium)) {
|
||||
cond.card_ref, cond.condition_giver_card_ref,
|
||||
sc_card->get_card_ref(), cond.card_definition_effect_index,
|
||||
attack_medium)) {
|
||||
this->send_6xB4x06_for_stat_delta(sc_card, attacker_card_ref, 0x20, -sc_card->get_current_hp(), 0, 1);
|
||||
sc_card->set_current_hp(0);
|
||||
this->destroy_card_if_hp_zero(sc_card, attacker_card_ref);
|
||||
@@ -2288,11 +2294,11 @@ bool CardSpecial::execute_effect(
|
||||
auto set_card = this->server()->card_for_set_card_ref(card_ref);
|
||||
if (set_card && (set_card->get_current_hp() > 0)) {
|
||||
if (this->server()->ruler_server->check_usability_or_apply_condition_for_card_refs(
|
||||
cond.card_ref,
|
||||
cond.condition_giver_card_ref,
|
||||
set_card->get_card_ref(),
|
||||
cond.card_definition_effect_index,
|
||||
attack_medium)) {
|
||||
cond.card_ref,
|
||||
cond.condition_giver_card_ref,
|
||||
set_card->get_card_ref(),
|
||||
cond.card_definition_effect_index,
|
||||
attack_medium)) {
|
||||
this->send_6xB4x06_for_stat_delta(
|
||||
set_card, attacker_card_ref, 0x20, -set_card->get_current_hp(), 0, 1);
|
||||
set_card->set_current_hp(0);
|
||||
@@ -2391,7 +2397,7 @@ void CardSpecial::get_effective_ap_tp(
|
||||
}
|
||||
|
||||
const char* CardSpecial::get_next_expr_token(
|
||||
const char *expr, ExpressionTokenType* out_type, int32_t* out_value) const {
|
||||
const char* expr, ExpressionTokenType* out_type, int32_t* out_value) const {
|
||||
switch (*expr) {
|
||||
case '\0':
|
||||
*out_type = ExpressionTokenType::SPACE;
|
||||
@@ -2427,11 +2433,11 @@ const char* CardSpecial::get_next_expr_token(
|
||||
*out_type = ExpressionTokenType::SPACE;
|
||||
*out_value = 0x27;
|
||||
|
||||
static const vector<const char*> tokens({
|
||||
static const vector<const char*> tokens = {
|
||||
"f", "d", "ap", "tp", "hp", "mhp", "dm", "tdm", "tf", "ac", "php",
|
||||
"dc", "cs", "a", "kap", "ktp", "dn", "hf", "df", "ff", "ef", "bi",
|
||||
"ab", "mc", "dk", "sa", "gn", "wd", "tt", "lv", "adm", "ddm", "sat",
|
||||
"edm", "ldm", "rdm", "fdm", "ndm", "ehp"});
|
||||
"edm", "ldm", "rdm", "fdm", "ndm", "ehp"};
|
||||
for (size_t z = 0; z < tokens.size(); z++) {
|
||||
if (token_buf == tokens[z]) {
|
||||
*out_type = ExpressionTokenType::REFERENCE;
|
||||
@@ -2467,7 +2473,8 @@ vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
}
|
||||
|
||||
auto card2 = this->server()->card_for_set_card_ref((as.attacker_card_ref == 0xFFFF)
|
||||
? as.original_attacker_card_ref : as.attacker_card_ref);
|
||||
? as.original_attacker_card_ref
|
||||
: as.attacker_card_ref);
|
||||
|
||||
Location card1_loc;
|
||||
if (!card1) {
|
||||
@@ -2519,14 +2526,15 @@ vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
if (ce && ps) {
|
||||
uint16_t range_card_id = this->get_card_id_with_effective_range(card1, ce->def.card_id, card2);
|
||||
parray<uint8_t, 9 * 9> range;
|
||||
compute_effective_range(range, this->server()->base()->data_index, range_card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
compute_effective_range(range, this->server()->base()->card_index, range_card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
add_card_refs(ps->get_card_refs_within_range_from_all_players(range, card1_loc, CardType::ITEM));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
size_t z;
|
||||
for (z = 0; (z < 9) && (as.action_card_refs[z] != 0xFFFF) && (as.action_card_refs[z] != card_ref); z++) { }
|
||||
for (z = 0; (z < 9) && (as.action_card_refs[z] != 0xFFFF) && (as.action_card_refs[z] != card_ref); z++) {
|
||||
}
|
||||
for (; (z < 9) && (as.action_card_refs[z] != 0xFFFF); z++) {
|
||||
auto result_card = this->server()->card_for_set_card_ref(as.action_card_refs[z]);
|
||||
if (result_card) {
|
||||
@@ -2558,7 +2566,7 @@ vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
if (ce && ps) {
|
||||
uint16_t range_card_id = this->get_card_id_with_effective_range(card1, ce->def.card_id, card2);
|
||||
parray<uint8_t, 9 * 9> range;
|
||||
compute_effective_range(range, this->server()->base()->data_index, range_card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
compute_effective_range(range, this->server()->base()->card_index, range_card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
add_card_refs(ps->get_all_cards_within_range(range, card1_loc, card1->get_team_id()));
|
||||
}
|
||||
}
|
||||
@@ -2623,7 +2631,7 @@ vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
// should fix this eventually.
|
||||
uint16_t range_card_id = this->get_card_id_with_effective_range(card1, 0x00D9, card2);
|
||||
parray<uint8_t, 9 * 9> range;
|
||||
compute_effective_range(range, this->server()->base()->data_index, range_card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
compute_effective_range(range, this->server()->base()->card_index, range_card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
auto result_card_refs = ps->get_all_cards_within_range(range, card1_loc, card1->get_team_id());
|
||||
for (uint16_t result_card_ref : result_card_refs) {
|
||||
auto result_card = this->server()->card_for_set_card_ref(result_card_ref);
|
||||
@@ -2647,7 +2655,7 @@ vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
// TODO: Again with the Gifoie hardcoding...
|
||||
uint16_t range_card_id = this->get_card_id_with_effective_range(card1, 0x00D9, card2);
|
||||
parray<uint8_t, 9 * 9> range;
|
||||
compute_effective_range(range, this->server()->base()->data_index, range_card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
compute_effective_range(range, this->server()->base()->card_index, range_card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
auto result_card_refs = ps->get_all_cards_within_range(range, card1_loc, 0xFF);
|
||||
for (uint16_t result_card_ref : result_card_refs) {
|
||||
auto result_card = this->server()->card_for_set_card_ref(result_card_ref);
|
||||
@@ -2713,7 +2721,7 @@ vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
// TODO: Again with the Gifoie hardcoding...
|
||||
uint16_t range_card_id = this->get_card_id_with_effective_range(card1, 0x00D9, card2);
|
||||
parray<uint8_t, 9 * 9> range;
|
||||
compute_effective_range(range, this->server()->base()->data_index, range_card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
compute_effective_range(range, this->server()->base()->card_index, range_card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
auto result_card_refs = ps->get_all_cards_within_range(range, card1_loc, 0xFF);
|
||||
for (uint16_t result_card_ref : result_card_refs) {
|
||||
auto result_card = this->server()->card_for_set_card_ref(result_card_ref);
|
||||
@@ -2767,7 +2775,7 @@ vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
// TODO: Yet another Gifoie hardcode location :(
|
||||
uint16_t range_card_id = this->get_card_id_with_effective_range(card1, 0x00D9, card2);
|
||||
parray<uint8_t, 9 * 9> range;
|
||||
compute_effective_range(range, this->server()->base()->data_index, range_card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
compute_effective_range(range, this->server()->base()->card_index, range_card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
auto result_card_refs = ps->get_all_cards_within_range(range, card1_loc, card1->get_team_id());
|
||||
for (uint16_t result_card_ref : result_card_refs) {
|
||||
auto result_card = this->server()->card_for_set_card_ref(result_card_ref);
|
||||
@@ -2794,7 +2802,7 @@ vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
// TODO: Sigh. Gifoie again.
|
||||
uint16_t range_card_id = this->get_card_id_with_effective_range(card1, 0x00D9, card2);
|
||||
parray<uint8_t, 9 * 9> range;
|
||||
compute_effective_range(range, this->server()->base()->data_index, range_card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
compute_effective_range(range, this->server()->base()->card_index, range_card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
auto result_card_refs = ps->get_all_cards_within_range(range, card1_loc, 0xFF);
|
||||
for (uint16_t result_card_ref : result_card_refs) {
|
||||
auto result_card = this->server()->card_for_set_card_ref(result_card_ref);
|
||||
@@ -2890,7 +2898,7 @@ vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
// Slay instead of Gifoie
|
||||
uint16_t range_card_id = this->get_card_id_with_effective_range(card1, 0x009C, card2);
|
||||
parray<uint8_t, 9 * 9> range;
|
||||
compute_effective_range(range, this->server()->base()->data_index, range_card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
compute_effective_range(range, this->server()->base()->card_index, range_card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
auto result_card_refs = ps->get_all_cards_within_range(range, card1_loc, 0xFF);
|
||||
for (uint16_t result_card_ref : result_card_refs) {
|
||||
auto result_card = this->server()->card_for_set_card_ref(result_card_ref);
|
||||
@@ -2919,7 +2927,7 @@ vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
// TODO: Sigh. Gifoie. Sigh.
|
||||
uint16_t range_card_id = this->get_card_id_with_effective_range(card1, 0x00D9, card2);
|
||||
parray<uint8_t, 9 * 9> range;
|
||||
compute_effective_range(range, this->server()->base()->data_index, range_card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
compute_effective_range(range, this->server()->base()->card_index, range_card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
auto result_card_refs = ps->get_all_cards_within_range(range, card1_loc, 0xFF);
|
||||
for (uint16_t result_card_ref : result_card_refs) {
|
||||
auto result_card = this->server()->card_for_set_card_ref(result_card_ref);
|
||||
@@ -2957,7 +2965,7 @@ vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
// TODO: One more Gifoie here.
|
||||
uint16_t range_card_id = this->get_card_id_with_effective_range(card1, 0x00D9, card2);
|
||||
parray<uint8_t, 9 * 9> range;
|
||||
compute_effective_range(range, this->server()->base()->data_index, range_card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
compute_effective_range(range, this->server()->base()->card_index, range_card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
auto result_card_refs = ps->get_all_cards_within_range(range, card1_loc, card1->get_team_id());
|
||||
for (uint16_t result_card_ref : result_card_refs) {
|
||||
auto result_card = this->server()->card_for_set_card_ref(result_card_ref);
|
||||
@@ -2971,7 +2979,7 @@ vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
for (size_t set_index = 0; set_index < 8; set_index++) {
|
||||
auto result_card = ps->get_set_card(set_index);
|
||||
if (result_card && (card1 != result_card) &&
|
||||
(result_card->get_definition()->def.type == CardType::ITEM)) {
|
||||
(result_card->get_definition()->def.type == CardType::ITEM)) {
|
||||
bool should_add = true;
|
||||
for (auto c : ret) {
|
||||
if (c == result_card) {
|
||||
@@ -2992,7 +3000,7 @@ vector<shared_ptr<const Card>> CardSpecial::get_targeted_cards_for_condition(
|
||||
vector<shared_ptr<const Card>> filtered_ret;
|
||||
for (auto c : ret) {
|
||||
if (this->server()->ruler_server->check_usability_or_apply_condition_for_card_refs(
|
||||
card_ref, setter_card_ref, c->get_card_ref(), def_effect_index, attack_medium)) {
|
||||
card_ref, setter_card_ref, c->get_card_ref(), def_effect_index, attack_medium)) {
|
||||
filtered_ret.emplace_back(c);
|
||||
}
|
||||
}
|
||||
@@ -3176,8 +3184,8 @@ bool CardSpecial::should_cancel_condition_due_to_anti_abnormality(
|
||||
}
|
||||
if ((card->card_flags & 3) ||
|
||||
(card->action_metadata.check_flag(0x10) &&
|
||||
(card->get_card_ref() != target_card_ref) &&
|
||||
(card->get_card_ref() != sc_card_ref))) {
|
||||
(card->get_card_ref() != target_card_ref) &&
|
||||
(card->get_card_ref() != sc_card_ref))) {
|
||||
return true;
|
||||
}
|
||||
auto ce = card->get_definition();
|
||||
@@ -3375,7 +3383,7 @@ void CardSpecial::check_for_defense_interference(
|
||||
shared_ptr<Card> target_card,
|
||||
int16_t* inout_unknown_p4) {
|
||||
// Note: This check is not part of the original implementation.
|
||||
if (this->server()->base()->data_index->behavior_flags & BehaviorFlag::DISABLE_INTERFERENCE) {
|
||||
if (this->server()->base()->behavior_flags & BehaviorFlag::DISABLE_INTERFERENCE) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3519,15 +3527,15 @@ void CardSpecial::unknown_8024C2B0(
|
||||
bool all_targets_matched = false;
|
||||
if (!targeted_cards.empty() &&
|
||||
((card_effect.type == ConditionType::UNKNOWN_64) ||
|
||||
(card_effect.type == ConditionType::MISC_DEFENSE_BONUSES) ||
|
||||
(card_effect.type == ConditionType::MOSTLY_HALFGUARDS))) {
|
||||
(card_effect.type == ConditionType::MISC_DEFENSE_BONUSES) ||
|
||||
(card_effect.type == ConditionType::MOSTLY_HALFGUARDS))) {
|
||||
size_t count = 0;
|
||||
for (size_t z = 0; z < targeted_cards.size(); z++) {
|
||||
dice_roll.value_used_in_expr = false;
|
||||
string arg2_text = card_effect.arg2;
|
||||
if (this->evaluate_effect_arg2_condition(
|
||||
as, targeted_cards[z], arg2_text.c_str(), dice_roll,
|
||||
set_card_ref, sc_card_ref, random_percent, when)) {
|
||||
as, targeted_cards[z], arg2_text.c_str(), dice_roll,
|
||||
set_card_ref, sc_card_ref, random_percent, when)) {
|
||||
count++;
|
||||
}
|
||||
if (dice_roll.value_used_in_expr) {
|
||||
@@ -3554,7 +3562,7 @@ void CardSpecial::unknown_8024C2B0(
|
||||
string arg2_str = card_effect.arg2;
|
||||
if (all_targets_matched ||
|
||||
this->evaluate_effect_arg2_condition(
|
||||
as, targeted_cards[z], arg2_str.c_str(), dice_roll, set_card_ref, sc_card_ref, random_percent, when)) {
|
||||
as, targeted_cards[z], arg2_str.c_str(), dice_roll, set_card_ref, sc_card_ref, random_percent, when)) {
|
||||
auto env_stats = this->compute_attack_env_stats(
|
||||
as, targeted_cards[z], dice_roll, set_card_ref, sc_card_ref);
|
||||
string expr_str = card_effect.expr;
|
||||
@@ -3577,8 +3585,7 @@ void CardSpecial::unknown_8024C2B0(
|
||||
}
|
||||
|
||||
ssize_t applied_cond_index = -1;
|
||||
if ((unknown_v1 == 0) && !this->should_cancel_condition_due_to_anti_abnormality(
|
||||
card_effect, target_card, dice_cmd.effect.target_card_ref, sc_card_ref)) {
|
||||
if ((unknown_v1 == 0) && !this->should_cancel_condition_due_to_anti_abnormality(card_effect, target_card, dice_cmd.effect.target_card_ref, sc_card_ref)) {
|
||||
applied_cond_index = target_card->apply_abnormal_condition(
|
||||
card_effect, def_effect_index, dice_cmd.effect.target_card_ref, sc_card_ref, value, dice_roll.value, random_percent);
|
||||
// This debug_print call is in the original code.
|
||||
@@ -3713,158 +3720,157 @@ const InterferenceProbabilityEntry* get_interference_probability_entry(
|
||||
uint16_t column_card_id,
|
||||
bool is_attack) {
|
||||
static const InterferenceProbabilityEntry entries[] = {
|
||||
{0x0004, 0xFF, 0xFF},
|
||||
{0x0002, 0x04, 0x00},
|
||||
{0x0002, 0x00, 0x0F},
|
||||
{0x0003, 0x03, 0x00},
|
||||
{0x0003, 0x00, 0x0A},
|
||||
{0x0006, 0x01, 0x00},
|
||||
{0x0006, 0x00, 0x05},
|
||||
{0x0111, 0x01, 0x00},
|
||||
{0x0111, 0x00, 0x05},
|
||||
{0x0001, 0x03, 0x00},
|
||||
{0x0001, 0x00, 0x0A},
|
||||
{0x0002, 0xFF, 0xFF},
|
||||
{0x0004, 0x04, 0x00},
|
||||
{0x0004, 0x00, 0x0F},
|
||||
{0x0003, 0x06, 0x00},
|
||||
{0x0003, 0x00, 0x14},
|
||||
{0x0006, 0x04, 0x00},
|
||||
{0x0006, 0x00, 0x0F},
|
||||
{0x0003, 0xFF, 0xFF},
|
||||
{0x0004, 0x04, 0x00},
|
||||
{0x0004, 0x00, 0x0F},
|
||||
{0x0002, 0x04, 0x00},
|
||||
{0x0002, 0x00, 0x0F},
|
||||
{0x0006, 0xFF, 0xFF},
|
||||
{0x0002, 0x06, 0x00},
|
||||
{0x0002, 0x00, 0x14},
|
||||
{0x0111, 0xFF, 0xFF},
|
||||
{0x0004, 0x01, 0x00},
|
||||
{0x0004, 0x00, 0x05},
|
||||
{0x0001, 0x06, 0x00},
|
||||
{0x0001, 0x00, 0x14},
|
||||
{0x0001, 0xFF, 0xFF},
|
||||
{0x0111, 0x04, 0x00},
|
||||
{0x0111, 0x00, 0x0F},
|
||||
{0x0112, 0xFF, 0xFF},
|
||||
{0x0113, 0x06, 0x00},
|
||||
{0x0113, 0x00, 0x14},
|
||||
{0x0110, 0x06, 0x00},
|
||||
{0x0110, 0x00, 0x14},
|
||||
{0x0114, 0x01, 0x00},
|
||||
{0x0114, 0x00, 0x05},
|
||||
{0x011D, 0x02, 0x00},
|
||||
{0x011D, 0x00, 0x07},
|
||||
{0x0113, 0xFF, 0xFF},
|
||||
{0x0003, 0x03, 0x00},
|
||||
{0x0003, 0x00, 0x0A},
|
||||
{0x0112, 0x03, 0x00},
|
||||
{0x0112, 0x00, 0x0A},
|
||||
{0x0110, 0xFF, 0xFF},
|
||||
{0x0005, 0x03, 0x00},
|
||||
{0x0005, 0x00, 0x0A},
|
||||
{0x0112, 0x04, 0x00},
|
||||
{0x0112, 0x00, 0x0F},
|
||||
{0x0005, 0xFF, 0xFF},
|
||||
{0x0110, 0x03, 0x00},
|
||||
{0x0110, 0x00, 0x0A},
|
||||
{0x0114, 0xFF, 0xFF},
|
||||
{0x0005, 0x03, 0x00},
|
||||
{0x0005, 0x00, 0x0A},
|
||||
{0x0110, 0x01, 0x00},
|
||||
{0x0110, 0x00, 0x05},
|
||||
{0x0115, 0x06, 0x00},
|
||||
{0x0115, 0x00, 0x14},
|
||||
{0x0115, 0xFF, 0xFF},
|
||||
{0x0004, 0x01, 0x00},
|
||||
{0x0004, 0x00, 0x05},
|
||||
{0x0003, 0x01, 0x00},
|
||||
{0x0003, 0x00, 0x05},
|
||||
{0x0006, 0x01, 0x00},
|
||||
{0x0006, 0x00, 0x05},
|
||||
{0x0112, 0x01, 0x00},
|
||||
{0x0112, 0x00, 0x05},
|
||||
{0x0110, 0x01, 0x00},
|
||||
{0x0110, 0x00, 0x05},
|
||||
{0x0114, 0x04, 0x00},
|
||||
{0x0114, 0x00, 0x0F},
|
||||
{0x0008, 0xFF, 0xFF},
|
||||
{0x0007, 0x06, 0x00},
|
||||
{0x0007, 0x00, 0x14},
|
||||
{0x0116, 0x01, 0x00},
|
||||
{0x0116, 0x00, 0x05},
|
||||
{0x011E, 0x03, 0x00},
|
||||
{0x011E, 0x00, 0x0A},
|
||||
{0x0118, 0x06, 0x00},
|
||||
{0x0118, 0x00, 0x14},
|
||||
{0x0007, 0xFF, 0xFF},
|
||||
{0x0008, 0x06, 0x00},
|
||||
{0x0008, 0x00, 0x14},
|
||||
{0x0118, 0x01, 0x00},
|
||||
{0x0118, 0x00, 0x05},
|
||||
{0x011B, 0x03, 0x00},
|
||||
{0x011B, 0x00, 0x0A},
|
||||
{0x0116, 0xFF, 0xFF},
|
||||
{0x0008, 0x01, 0x00},
|
||||
{0x0008, 0x00, 0x05},
|
||||
{0x011C, 0x03, 0x00},
|
||||
{0x011C, 0x00, 0x0A},
|
||||
{0x011A, 0xFF, 0xFF},
|
||||
{0x0119, 0x04, 0x00},
|
||||
{0x0119, 0x00, 0x0F},
|
||||
{0x011D, 0x04, 0x00},
|
||||
{0x011D, 0x00, 0x0F},
|
||||
{0x0119, 0xFF, 0xFF},
|
||||
{0x011A, 0x04, 0x00},
|
||||
{0x011A, 0x00, 0x0F},
|
||||
{0x011D, 0x04, 0x00},
|
||||
{0x011D, 0x00, 0x0F},
|
||||
{0x011D, 0xFF, 0xFF},
|
||||
{0x0119, 0x04, 0x00},
|
||||
{0x0119, 0x00, 0x0F},
|
||||
{0x011A, 0x04, 0x00},
|
||||
{0x011A, 0x00, 0x0F},
|
||||
{0x0112, 0x01, 0x00},
|
||||
{0x0112, 0x00, 0x07},
|
||||
{0x011E, 0xFF, 0xFF},
|
||||
{0x0008, 0x03, 0x00},
|
||||
{0x0008, 0x00, 0x0A},
|
||||
{0x0118, 0x06, 0x00},
|
||||
{0x0118, 0x00, 0x14},
|
||||
{0x011C, 0xFF, 0xFF},
|
||||
{0x0116, 0x04, 0x00},
|
||||
{0x0116, 0x00, 0x0F},
|
||||
{0x011E, 0x01, 0x00},
|
||||
{0x011E, 0x00, 0x05},
|
||||
{0x0118, 0xFF, 0xFF},
|
||||
{0x011E, 0x06, 0x00},
|
||||
{0x011E, 0x00, 0x14},
|
||||
{0x011B, 0xFF, 0xFF},
|
||||
{0x0007, 0x03, 0x00},
|
||||
{0x0007, 0x00, 0x0A},
|
||||
{0x0117, 0x03, 0x00},
|
||||
{0x0117, 0x00, 0x0A},
|
||||
{0x011F, 0x06, 0x00},
|
||||
{0x011F, 0x00, 0x14},
|
||||
{0x0117, 0xFF, 0xFF},
|
||||
{0x011F, 0x03, 0x00},
|
||||
{0x011F, 0x00, 0x0A},
|
||||
{0x011B, 0x04, 0x00},
|
||||
{0x011B, 0x00, 0x0F},
|
||||
{0x011F, 0xFF, 0xFF},
|
||||
{0x0007, 0x01, 0x00},
|
||||
{0x0007, 0x00, 0x05},
|
||||
{0x011B, 0x06, 0x00},
|
||||
{0x011B, 0x00, 0x14},
|
||||
{0x0117, 0x04, 0x00},
|
||||
{0x0117, 0x00, 0x0F},
|
||||
{0x0004, 0xFF, 0xFF},
|
||||
{0x0002, 0x04, 0x00},
|
||||
{0x0002, 0x00, 0x0F},
|
||||
{0x0003, 0x03, 0x00},
|
||||
{0x0003, 0x00, 0x0A},
|
||||
{0x0006, 0x01, 0x00},
|
||||
{0x0006, 0x00, 0x05},
|
||||
{0x0111, 0x01, 0x00},
|
||||
{0x0111, 0x00, 0x05},
|
||||
{0x0001, 0x03, 0x00},
|
||||
{0x0001, 0x00, 0x0A},
|
||||
{0x0002, 0xFF, 0xFF},
|
||||
{0x0004, 0x04, 0x00},
|
||||
{0x0004, 0x00, 0x0F},
|
||||
{0x0003, 0x06, 0x00},
|
||||
{0x0003, 0x00, 0x14},
|
||||
{0x0006, 0x04, 0x00},
|
||||
{0x0006, 0x00, 0x0F},
|
||||
{0x0003, 0xFF, 0xFF},
|
||||
{0x0004, 0x04, 0x00},
|
||||
{0x0004, 0x00, 0x0F},
|
||||
{0x0002, 0x04, 0x00},
|
||||
{0x0002, 0x00, 0x0F},
|
||||
{0x0006, 0xFF, 0xFF},
|
||||
{0x0002, 0x06, 0x00},
|
||||
{0x0002, 0x00, 0x14},
|
||||
{0x0111, 0xFF, 0xFF},
|
||||
{0x0004, 0x01, 0x00},
|
||||
{0x0004, 0x00, 0x05},
|
||||
{0x0001, 0x06, 0x00},
|
||||
{0x0001, 0x00, 0x14},
|
||||
{0x0001, 0xFF, 0xFF},
|
||||
{0x0111, 0x04, 0x00},
|
||||
{0x0111, 0x00, 0x0F},
|
||||
{0x0112, 0xFF, 0xFF},
|
||||
{0x0113, 0x06, 0x00},
|
||||
{0x0113, 0x00, 0x14},
|
||||
{0x0110, 0x06, 0x00},
|
||||
{0x0110, 0x00, 0x14},
|
||||
{0x0114, 0x01, 0x00},
|
||||
{0x0114, 0x00, 0x05},
|
||||
{0x011D, 0x02, 0x00},
|
||||
{0x011D, 0x00, 0x07},
|
||||
{0x0113, 0xFF, 0xFF},
|
||||
{0x0003, 0x03, 0x00},
|
||||
{0x0003, 0x00, 0x0A},
|
||||
{0x0112, 0x03, 0x00},
|
||||
{0x0112, 0x00, 0x0A},
|
||||
{0x0110, 0xFF, 0xFF},
|
||||
{0x0005, 0x03, 0x00},
|
||||
{0x0005, 0x00, 0x0A},
|
||||
{0x0112, 0x04, 0x00},
|
||||
{0x0112, 0x00, 0x0F},
|
||||
{0x0005, 0xFF, 0xFF},
|
||||
{0x0110, 0x03, 0x00},
|
||||
{0x0110, 0x00, 0x0A},
|
||||
{0x0114, 0xFF, 0xFF},
|
||||
{0x0005, 0x03, 0x00},
|
||||
{0x0005, 0x00, 0x0A},
|
||||
{0x0110, 0x01, 0x00},
|
||||
{0x0110, 0x00, 0x05},
|
||||
{0x0115, 0x06, 0x00},
|
||||
{0x0115, 0x00, 0x14},
|
||||
{0x0115, 0xFF, 0xFF},
|
||||
{0x0004, 0x01, 0x00},
|
||||
{0x0004, 0x00, 0x05},
|
||||
{0x0003, 0x01, 0x00},
|
||||
{0x0003, 0x00, 0x05},
|
||||
{0x0006, 0x01, 0x00},
|
||||
{0x0006, 0x00, 0x05},
|
||||
{0x0112, 0x01, 0x00},
|
||||
{0x0112, 0x00, 0x05},
|
||||
{0x0110, 0x01, 0x00},
|
||||
{0x0110, 0x00, 0x05},
|
||||
{0x0114, 0x04, 0x00},
|
||||
{0x0114, 0x00, 0x0F},
|
||||
{0x0008, 0xFF, 0xFF},
|
||||
{0x0007, 0x06, 0x00},
|
||||
{0x0007, 0x00, 0x14},
|
||||
{0x0116, 0x01, 0x00},
|
||||
{0x0116, 0x00, 0x05},
|
||||
{0x011E, 0x03, 0x00},
|
||||
{0x011E, 0x00, 0x0A},
|
||||
{0x0118, 0x06, 0x00},
|
||||
{0x0118, 0x00, 0x14},
|
||||
{0x0007, 0xFF, 0xFF},
|
||||
{0x0008, 0x06, 0x00},
|
||||
{0x0008, 0x00, 0x14},
|
||||
{0x0118, 0x01, 0x00},
|
||||
{0x0118, 0x00, 0x05},
|
||||
{0x011B, 0x03, 0x00},
|
||||
{0x011B, 0x00, 0x0A},
|
||||
{0x0116, 0xFF, 0xFF},
|
||||
{0x0008, 0x01, 0x00},
|
||||
{0x0008, 0x00, 0x05},
|
||||
{0x011C, 0x03, 0x00},
|
||||
{0x011C, 0x00, 0x0A},
|
||||
{0x011A, 0xFF, 0xFF},
|
||||
{0x0119, 0x04, 0x00},
|
||||
{0x0119, 0x00, 0x0F},
|
||||
{0x011D, 0x04, 0x00},
|
||||
{0x011D, 0x00, 0x0F},
|
||||
{0x0119, 0xFF, 0xFF},
|
||||
{0x011A, 0x04, 0x00},
|
||||
{0x011A, 0x00, 0x0F},
|
||||
{0x011D, 0x04, 0x00},
|
||||
{0x011D, 0x00, 0x0F},
|
||||
{0x011D, 0xFF, 0xFF},
|
||||
{0x0119, 0x04, 0x00},
|
||||
{0x0119, 0x00, 0x0F},
|
||||
{0x011A, 0x04, 0x00},
|
||||
{0x011A, 0x00, 0x0F},
|
||||
{0x0112, 0x01, 0x00},
|
||||
{0x0112, 0x00, 0x07},
|
||||
{0x011E, 0xFF, 0xFF},
|
||||
{0x0008, 0x03, 0x00},
|
||||
{0x0008, 0x00, 0x0A},
|
||||
{0x0118, 0x06, 0x00},
|
||||
{0x0118, 0x00, 0x14},
|
||||
{0x011C, 0xFF, 0xFF},
|
||||
{0x0116, 0x04, 0x00},
|
||||
{0x0116, 0x00, 0x0F},
|
||||
{0x011E, 0x01, 0x00},
|
||||
{0x011E, 0x00, 0x05},
|
||||
{0x0118, 0xFF, 0xFF},
|
||||
{0x011E, 0x06, 0x00},
|
||||
{0x011E, 0x00, 0x14},
|
||||
{0x011B, 0xFF, 0xFF},
|
||||
{0x0007, 0x03, 0x00},
|
||||
{0x0007, 0x00, 0x0A},
|
||||
{0x0117, 0x03, 0x00},
|
||||
{0x0117, 0x00, 0x0A},
|
||||
{0x011F, 0x06, 0x00},
|
||||
{0x011F, 0x00, 0x14},
|
||||
{0x0117, 0xFF, 0xFF},
|
||||
{0x011F, 0x03, 0x00},
|
||||
{0x011F, 0x00, 0x0A},
|
||||
{0x011B, 0x04, 0x00},
|
||||
{0x011B, 0x00, 0x0F},
|
||||
{0x011F, 0xFF, 0xFF},
|
||||
{0x0007, 0x01, 0x00},
|
||||
{0x0007, 0x00, 0x05},
|
||||
{0x011B, 0x06, 0x00},
|
||||
{0x011B, 0x00, 0x14},
|
||||
{0x0117, 0x04, 0x00},
|
||||
{0x0117, 0x00, 0x0F},
|
||||
};
|
||||
constexpr size_t num_entries = sizeof(entries) / sizeof(entries[0]);
|
||||
|
||||
const InterferenceProbabilityEntry* ret_entry = nullptr;
|
||||
int16_t current_max = -1;
|
||||
size_t logical_index = 0;
|
||||
uint16_t current_row_card_id = 0xFFFF;
|
||||
for (size_t z = 0; z < num_entries; z++) {
|
||||
const auto& entry = entries[z];
|
||||
@@ -3878,7 +3884,6 @@ const InterferenceProbabilityEntry* get_interference_probability_entry(
|
||||
current_max = v;
|
||||
}
|
||||
}
|
||||
logical_index++;
|
||||
} else {
|
||||
current_row_card_id = current_column_card_id;
|
||||
}
|
||||
@@ -4121,7 +4126,7 @@ vector<shared_ptr<const Card>> CardSpecial::filter_cards_by_range(
|
||||
// TODO: Remove hardcoded card ID here (Earthquake)
|
||||
uint16_t card_id = this->get_card_id_with_effective_range(card1, 0x00ED, card2);
|
||||
parray<uint8_t, 9 * 9> range;
|
||||
compute_effective_range(range, this->server()->base()->data_index, card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
compute_effective_range(range, this->server()->base()->card_index, card_id, card1_loc, this->server()->base()->map_and_rules1);
|
||||
auto card_refs_in_range = ps->get_card_refs_within_range_from_all_players(range, card1_loc, CardType::ITEM);
|
||||
|
||||
for (auto card : cards) {
|
||||
@@ -4337,7 +4342,7 @@ void CardSpecial::unknown_8024A9D8(const ActionState& pa, uint16_t action_card_r
|
||||
|
||||
void CardSpecial::check_for_attack_interference(shared_ptr<Card> unknown_p2) {
|
||||
// Note: This check is not part of the original implementation.
|
||||
if (this->server()->base()->data_index->behavior_flags & BehaviorFlag::DISABLE_INTERFERENCE) {
|
||||
if (this->server()->base()->behavior_flags & BehaviorFlag::DISABLE_INTERFERENCE) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4526,6 +4531,4 @@ vector<shared_ptr<const Card>> CardSpecial::find_all_sc_cards_of_class(
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
@@ -5,12 +5,10 @@
|
||||
#include <memory>
|
||||
|
||||
#include "../Text.hh"
|
||||
#include "DataIndex.hh"
|
||||
#include "DataIndexes.hh"
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
struct InterferenceProbabilityEntry {
|
||||
uint16_t card_id;
|
||||
uint8_t attack_probability;
|
||||
@@ -22,8 +20,6 @@ const InterferenceProbabilityEntry* get_interference_probability_entry(
|
||||
uint16_t column_card_id,
|
||||
bool is_attack);
|
||||
|
||||
|
||||
|
||||
class CardSpecial {
|
||||
public:
|
||||
enum class ExpressionTokenType {
|
||||
@@ -224,7 +220,7 @@ public:
|
||||
int16_t ap,
|
||||
int16_t tp);
|
||||
const char* get_next_expr_token(
|
||||
const char *expr, ExpressionTokenType* out_type, int32_t* out_value) const;
|
||||
const char* expr, ExpressionTokenType* out_type, int32_t* out_value) const;
|
||||
std::vector<std::shared_ptr<const Card>> get_targeted_cards_for_condition(
|
||||
uint16_t card_ref,
|
||||
uint8_t def_effect_index,
|
||||
@@ -341,6 +337,4 @@ private:
|
||||
uint16_t unknown_a2;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,964 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/JSON.hh>
|
||||
|
||||
#include "../Text.hh"
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
// The comment in Server.hh does not apply to this file (and DataIndex.cc).
|
||||
// Except for the Location structure, these structures and functions are not
|
||||
// based on Sega's original implementation.
|
||||
|
||||
class DataIndex;
|
||||
|
||||
|
||||
|
||||
enum BehaviorFlag {
|
||||
SKIP_DECK_VERIFY = 0x00000001,
|
||||
IGNORE_CARD_COUNTS = 0x00000002,
|
||||
SKIP_D1_D2_REPLACE = 0x00000004,
|
||||
DISABLE_TIME_LIMITS = 0x00000008,
|
||||
ENABLE_STATUS_MESSAGES = 0x00000010,
|
||||
LOAD_CARD_TEXT = 0x00000020,
|
||||
ENABLE_RECORDING = 0x00000040,
|
||||
DISABLE_MASKING = 0x00000080,
|
||||
DISABLE_INTERFERENCE = 0x00000100,
|
||||
};
|
||||
|
||||
|
||||
|
||||
enum class StatSwapType : uint8_t {
|
||||
NONE = 0,
|
||||
A_T_SWAP = 1,
|
||||
A_H_SWAP = 2,
|
||||
};
|
||||
|
||||
enum class ActionType : uint8_t {
|
||||
INVALID_00 = 0,
|
||||
DEFENSE = 1,
|
||||
ATTACK = 2,
|
||||
};
|
||||
|
||||
enum class AttackMedium : uint8_t {
|
||||
UNKNOWN = 0,
|
||||
PHYSICAL = 1,
|
||||
TECH = 2,
|
||||
UNKNOWN_03 = 3, // Probably Resta
|
||||
INVALID_FF = 0xFF,
|
||||
};
|
||||
|
||||
const char* name_for_attack_medium(AttackMedium medium);
|
||||
|
||||
enum class CriterionCode : uint8_t {
|
||||
NONE = 0x00,
|
||||
HU_CLASS_SC = 0x01,
|
||||
RA_CLASS_SC = 0x02,
|
||||
FO_CLASS_SC = 0x03,
|
||||
SAME_TEAM = 0x04,
|
||||
SAME_PLAYER = 0x05,
|
||||
SAME_TEAM_NOT_SAME_PLAYER = 0x06, // Allies only
|
||||
UNKNOWN_07 = 0x07,
|
||||
NOT_SC = 0x08,
|
||||
SC = 0x09,
|
||||
HU_OR_RA_CLASS_SC = 0x0A,
|
||||
HUNTER_HUMAN_SC = 0x0B,
|
||||
HUNTER_HU_CLASS_MALE_SC = 0x0C,
|
||||
HUNTER_FEMALE_SC = 0x0D,
|
||||
HUNTER_HU_OR_FO_CLASS_HUMAN_SC = 0x0E,
|
||||
HUNTER_HU_CLASS_ANDROID_SC = 0x0F,
|
||||
UNKNOWN_10 = 0x10,
|
||||
UNKNOWN_11 = 0x11,
|
||||
HUNTER_HUNEWEARL_CLASS_SC = 0x12,
|
||||
HUNTER_RA_CLASS_MALE_SC = 0x13,
|
||||
HUNTER_RA_CLASS_FEMALE_SC = 0x14,
|
||||
HUNTER_RA_OR_FO_CLASS_FEMALE_SC = 0x15,
|
||||
HUNTER_HU_OR_RA_CLASS_HUMAN_SC = 0x16,
|
||||
HUNTER_RA_CLASS_ANDROID_SC = 0x17,
|
||||
HUNTER_FO_CLASS_FEMALE_SC = 0x18,
|
||||
HUNTER_FEMALE_HUMAN_SC = 0x19,
|
||||
HUNTER_ANDROID_SC = 0x1A,
|
||||
HU_OR_FO_CLASS_SC = 0x1B,
|
||||
RA_OR_FO_CLASS_SC = 0x1C,
|
||||
PHYSICAL_OR_UNKNOWN_ATTACK_MEDIUM = 0x1D,
|
||||
TECH_OR_UNKNOWN_ATTACK_MEDIUM = 0x1E,
|
||||
PHYSICAL_OR_TECH_OR_UNKNOWN_ATTACK_MEDIUM = 0x1F,
|
||||
UNKNOWN_20 = 0x20,
|
||||
UNKNOWN_21 = 0x21,
|
||||
UNKNOWN_22 = 0x22,
|
||||
};
|
||||
|
||||
enum class CardRarity : uint8_t {
|
||||
N1 = 0x01,
|
||||
R1 = 0x02,
|
||||
S = 0x03,
|
||||
E = 0x04,
|
||||
N2 = 0x05,
|
||||
N3 = 0x06,
|
||||
N4 = 0x07,
|
||||
R2 = 0x08,
|
||||
R3 = 0x09,
|
||||
R4 = 0x0A,
|
||||
SS = 0x0B,
|
||||
D1 = 0x0C,
|
||||
D2 = 0x0D,
|
||||
INVIS = 0x0E,
|
||||
};
|
||||
|
||||
enum class CardType : uint8_t {
|
||||
HUNTERS_SC = 0x00,
|
||||
ARKZ_SC = 0x01,
|
||||
ITEM = 0x02,
|
||||
CREATURE = 0x03,
|
||||
ACTION = 0x04,
|
||||
ASSIST = 0x05,
|
||||
INVALID_FF = 0xFF,
|
||||
END_CARD_LIST = 0xFF,
|
||||
};
|
||||
|
||||
enum class CardClass : uint16_t {
|
||||
HU_SC = 0x0000,
|
||||
RA_SC = 0x0001,
|
||||
FO_SC = 0x0002,
|
||||
NATIVE_CREATURE = 0x000A,
|
||||
A_BEAST_CREATURE = 0x000B,
|
||||
MACHINE_CREATURE = 0x000C,
|
||||
DARK_CREATURE = 0x000D,
|
||||
GUARD_ITEM = 0x0015,
|
||||
MAG_ITEM = 0x0017,
|
||||
SWORD_ITEM = 0x0018,
|
||||
GUN_ITEM = 0x0019,
|
||||
CANE_ITEM = 0x001A,
|
||||
ATTACK_ACTION = 0x001E,
|
||||
DEFENSE_ACTION = 0x001F,
|
||||
TECH = 0x0020,
|
||||
PHOTON_BLAST = 0x0021,
|
||||
CONNECT_ONLY_ATTACK_ACTION = 0x0022,
|
||||
BOSS_ATTACK_ACTION = 0x0023,
|
||||
BOSS_TECH = 0x0024,
|
||||
ASSIST = 0x0028,
|
||||
};
|
||||
|
||||
bool card_class_is_tech_like(CardClass cc);
|
||||
|
||||
enum class TargetMode : uint8_t {
|
||||
NONE = 0x00, // Used for defense cards, mags, shields, etc.
|
||||
SINGLE_RANGE = 0x01,
|
||||
MULTI_RANGE = 0x02,
|
||||
SELF = 0x03,
|
||||
TEAM = 0x04,
|
||||
EVERYONE = 0x05,
|
||||
MULTI_RANGE_ALLIES = 0x06, // e.g. Shifta
|
||||
ALL_ALLIES = 0x07, // e.g. Anti, Resta, Leilla
|
||||
ALL = 0x08, // e.g. Last Judgment, Earthquake
|
||||
OWN_FCS = 0x09, // e.g. Traitor
|
||||
};
|
||||
|
||||
enum class ConditionType : uint8_t {
|
||||
NONE = 0x00,
|
||||
AP_BOOST = 0x01, // Temporarily increase AP by N
|
||||
RAMPAGE = 0x02,
|
||||
MULTI_STRIKE = 0x03, // Duplicate attack N times
|
||||
DAMAGE_MOD_1 = 0x04, // Set attack damage / AP to N after action cards applied (step 1)
|
||||
IMMOBILE = 0x05, // Give Immobile condition
|
||||
HOLD = 0x06, // Give Hold condition
|
||||
UNKNOWN_07 = 0x07,
|
||||
TP_BOOST = 0x08, // Add N TP temporarily during attack
|
||||
GIVE_DAMAGE = 0x09, // Cause direct N HP loss
|
||||
GUOM = 0x0A, // Give Guom condition
|
||||
PARALYZE = 0x0B, // Give Paralysis condition
|
||||
UNKNOWN_0C = 0x0C, // Swap AP and TP temporarily (presumably)
|
||||
A_H_SWAP = 0x0D, // Swap AP and HP temporarily
|
||||
PIERCE = 0x0E, // Attack SC directly even if they have items equipped
|
||||
UNKNOWN_0F = 0x0F,
|
||||
HEAL = 0x10, // Increase HP by N
|
||||
RETURN_TO_HAND = 0x11, // Return card to hand
|
||||
UNKNOWN_12 = 0x12,
|
||||
UNKNOWN_13 = 0x13,
|
||||
ACID = 0x14, // Give Acid condition
|
||||
UNKNOWN_15 = 0x15,
|
||||
MIGHTY_KNUCKLE = 0x16, // Temporarily increase AP by N, and set ATK dice to zero
|
||||
UNIT_BLOW = 0x17, // Temporarily increase AP by N * number of this card set within phase
|
||||
CURSE = 0x18, // Give Curse condition
|
||||
COMBO_AP = 0x19, // Temporarily increase AP by number of this card set within phase
|
||||
PIERCE_RAMPAGE_BLOCK = 0x1A, // Block attack if Pierce/Rampage
|
||||
ABILITY_TRAP = 0x1B, // Temporarily disable opponent abilities
|
||||
FREEZE = 0x1C, // Give Freeze condition
|
||||
ANTI_ABNORMALITY_1 = 0x1D, // Cure all abnormal conditions
|
||||
UNKNOWN_1E = 0x1E,
|
||||
EXPLOSION = 0x1F, // Damage all SCs and FCs by number of this same card set * 2
|
||||
UNKNOWN_20 = 0x20,
|
||||
UNKNOWN_21 = 0x21,
|
||||
UNKNOWN_22 = 0x22,
|
||||
RETURN_TO_DECK = 0x23, // Cancel discard and move to bottom of deck instead
|
||||
AERIAL = 0x24, // Give Aerial status
|
||||
AP_LOSS = 0x25, // Make attacker temporarily lose N AP during defense
|
||||
BONUS_FROM_LEADER = 0x26, // Gain AP equal to the number of cards of type N on the field
|
||||
FREE_MANEUVER = 0x27, // Enable movement over occupied tiles
|
||||
HASTE = 0x28, // Multiply all move action costs by expr (which may be zero)
|
||||
CLONE = 0x29, // Make setting this card free if at least one card of type N is already on the field
|
||||
DEF_DISABLE_BY_COST = 0x2A, // Disable use of any defense cards costing between (N / 10) and (N % 10) points, inclusive
|
||||
FILIAL = 0x2B, // Increase controlling SC's HP by N when this card is destroyed
|
||||
SNATCH = 0x2C, // Steal N EXP during attack
|
||||
HAND_DISRUPTER = 0x2D, // Discard N cards from hand immediately
|
||||
DROP = 0x2E, // Give Drop condition
|
||||
ACTION_DISRUPTER = 0x2F, // Destroy all action cards used by attacker
|
||||
SET_HP = 0x30, // Set HP to N
|
||||
NATIVE_SHIELD = 0x31, // Block attacks from Native creatures
|
||||
A_BEAST_SHIELD = 0x32, // Block attacks from A.Beast creatures
|
||||
MACHINE_SHIELD = 0x33, // Block attacks from Machine creatures
|
||||
DARK_SHIELD = 0x34, // Block attacks from Dark creatures
|
||||
SWORD_SHIELD = 0x35, // Block attacks from Sword items
|
||||
GUN_SHIELD = 0x36, // Block attacks from Gun items
|
||||
CANE_SHIELD = 0x37, // Block attacks from Cane items
|
||||
UNKNOWN_38 = 0x38,
|
||||
UNKNOWN_39 = 0x39,
|
||||
DEFENDER = 0x3A, // Make attacks go to setter of this card instead of original target
|
||||
SURVIVAL_DECOYS = 0x3B, // Redirect damage for multi-sided attack
|
||||
GIVE_OR_TAKE_EXP = 0x3C, // Give N EXP, or take if N is negative
|
||||
UNKNOWN_3D = 0x3D,
|
||||
DEATH_COMPANION = 0x3E, // If this card has 1 or 2 HP, set its HP to N
|
||||
EXP_DECOY = 0x3F, // If defender has EXP, lose EXP instead of getting damage when attacked
|
||||
SET_MV = 0x40, // Set MV to N
|
||||
GROUP = 0x41, // Temporarily increase AP by N * number of this card on field, excluding itself
|
||||
BERSERK = 0x42, // User of this card receives the same damage as target, and isn't helped by target's defense cards
|
||||
GUARD_CREATURE = 0x43, // Attacks on controlling SC damage this card instead
|
||||
TECH = 0x44, // Technique cards cost 1 fewer ATK point
|
||||
BIG_SWING = 0x45, // Increase all attacking ATK costs by 1
|
||||
UNKNOWN_46 = 0x46,
|
||||
SHIELD_WEAPON = 0x47, // Limit attacker's choice of target to guard items
|
||||
ATK_DICE_BOOST = 0x48, // Increase ATK dice roll by 1
|
||||
UNKNOWN_49 = 0x49,
|
||||
MAJOR_PIERCE = 0x4A, // If SC has over half of max HP, attacks target SC instead of equipped items
|
||||
HEAVY_PIERCE = 0x4B, // If SC has 3 or more items equipped, attacks target SC instead of equipped items
|
||||
MAJOR_RAMPAGE = 0x4C, // If SC has over half of max HP, attacks target SC and all equipped items
|
||||
HEAVY_RAMPAGE = 0x4D, // If SC has 3 or more items equipped, attacks target SC and all equipped items
|
||||
AP_GROWTH = 0x4E, // Permanently increase AP by N
|
||||
TP_GROWTH = 0x4F, // Permanently increase TP by N
|
||||
REBORN = 0x50, // If any card of type N is on the field, this card goes to the hand when destroyed instead of being discarded
|
||||
COPY = 0x51, // Temporarily set AP/TP to N percent (or 100% if N is 0) of opponent's values
|
||||
UNKNOWN_52 = 0x52,
|
||||
MISC_GUARDS = 0x53, // Add N to card's defense value
|
||||
AP_OVERRIDE = 0x54, // Set AP to N temporarily
|
||||
TP_OVERRIDE = 0x55, // Set TP to N temporarily
|
||||
RETURN = 0x56, // Return card to hand on destruction instead of discarding
|
||||
A_T_SWAP_PERM = 0x57, // Permanently swap AP and TP
|
||||
A_H_SWAP_PERM = 0x58, // Permanently swap AP and HP
|
||||
SLAYERS_ASSASSINS = 0x59, // Temporarily increase AP during attack
|
||||
ANTI_ABNORMALITY_2 = 0x5A, // Remove all conditions
|
||||
FIXED_RANGE = 0x5B, // Use SC's range instead of weapon or attack card ranges
|
||||
ELUDE = 0x5C, // SC does not lose HP when equipped items are destroyed
|
||||
PARRY = 0x5D, // Forward attack to a random FC within one tile of original target, excluding attacker and original target
|
||||
BLOCK_ATTACK = 0x5E, // Completely block attack
|
||||
UNKNOWN_5F = 0x5F,
|
||||
UNKNOWN_60 = 0x60,
|
||||
COMBO_TP = 0x61, // Gain TP equal to the number of cards of type N on the field
|
||||
MISC_AP_BONUSES = 0x62, // Temporarily increase AP by N
|
||||
MISC_TP_BONUSES = 0x63, // Temporarily increase TP by N
|
||||
UNKNOWN_64 = 0x64,
|
||||
MISC_DEFENSE_BONUSES = 0x65, // Decrease damage by N
|
||||
MOSTLY_HALFGUARDS = 0x66, // Reduce damage from incoming attack by N
|
||||
PERIODIC_FIELD = 0x67, // Swap immunity to tech or physical attacks
|
||||
FC_LIMIT_BY_COUNT = 0x68, // Change FC limit from 8 ATK points total to 4 FCs total
|
||||
UNKNOWN_69 = 0x69,
|
||||
MV_BONUS = 0x6A, // Increase MV by N
|
||||
FORWARD_DAMAGE = 0x6B,
|
||||
WEAK_SPOT_INFLUENCE = 0x6C, // Temporarily decrease AP by N
|
||||
DAMAGE_MODIFIER_2 = 0x6D, // Set attack damage / AP after action cards applied (step 2)
|
||||
WEAK_HIT_BLOCK = 0x6E, // Block all attacks of N damage or less
|
||||
AP_SILENCE = 0x6F, // Temporarily decrease AP of opponent by N
|
||||
TP_SILENCE = 0x70, // Temporarily decrease TP of opponent by N
|
||||
A_T_SWAP = 0x71, // Temporarily swap AP and TP
|
||||
HALFGUARD = 0x72, // Halve damage from attacks that would inflict N or more damage
|
||||
UNKNOWN_73 = 0x73,
|
||||
RAMPAGE_AP_LOSS = 0x74, // Temporarily reduce AP by N
|
||||
UNKNOWN_75 = 0x75,
|
||||
REFLECT = 0x76, // Generate reverse attack
|
||||
UNKNOWN_77 = 0x77,
|
||||
ANY = 0x78, // Not a real condition; used as a wildcard in search functions
|
||||
UNKNOWN_79 = 0x79,
|
||||
UNKNOWN_7A = 0x7A,
|
||||
UNKNOWN_7B = 0x7B,
|
||||
UNKNOWN_7C = 0x7C,
|
||||
UNKNOWN_7D = 0x7D,
|
||||
INVALID_FF = 0xFF,
|
||||
ANY_FF = 0xFF, // Used as a wildcard in some search functions
|
||||
};
|
||||
|
||||
const char* name_for_condition_type(ConditionType cond_type);
|
||||
|
||||
enum class AssistEffect : uint16_t {
|
||||
NONE = 0x0000,
|
||||
DICE_HALF = 0x0001,
|
||||
DICE_PLUS_1 = 0x0002,
|
||||
DICE_FEVER = 0x0003,
|
||||
CARD_RETURN = 0x0004,
|
||||
LAND_PRICE = 0x0005,
|
||||
POWERLESS_RAIN = 0x0006,
|
||||
BRAVE_WIND = 0x0007,
|
||||
SILENT_COLOSSEUM = 0x0008,
|
||||
RESISTANCE = 0x0009,
|
||||
INDEPENDENT = 0x000A,
|
||||
ASSISTLESS = 0x000B,
|
||||
ATK_DICE_2 = 0x000C,
|
||||
DEFLATION = 0x000D,
|
||||
INFLATION = 0x000E,
|
||||
EXCHANGE = 0x000F,
|
||||
INFLUENCE = 0x0010,
|
||||
SKIP_SET = 0x0011,
|
||||
SKIP_MOVE = 0x0012,
|
||||
SKIP_ACT = 0x0013,
|
||||
SKIP_DRAW = 0x0014,
|
||||
FLY = 0x0015,
|
||||
NECROMANCER = 0x0016,
|
||||
PERMISSION = 0x0017,
|
||||
SHUFFLE_ALL = 0x0018,
|
||||
LEGACY = 0x0019,
|
||||
ASSIST_REVERSE = 0x001A,
|
||||
STAMINA = 0x001B,
|
||||
AP_ABSORPTION = 0x001C,
|
||||
HEAVY_FOG = 0x001D,
|
||||
TRASH_1 = 0x001E,
|
||||
EMPTY_HAND = 0x001F,
|
||||
HITMAN = 0x0020,
|
||||
ASSIST_TRASH = 0x0021,
|
||||
SHUFFLE_GROUP = 0x0022,
|
||||
ASSIST_VANISH = 0x0023,
|
||||
CHARITY = 0x0024,
|
||||
INHERITANCE = 0x0025,
|
||||
FIX = 0x0026,
|
||||
MUSCULAR = 0x0027,
|
||||
CHANGE_BODY = 0x0028,
|
||||
GOD_WHIM = 0x0029,
|
||||
GOLD_RUSH = 0x002A,
|
||||
ASSIST_RETURN = 0x002B,
|
||||
REQUIEM = 0x002C,
|
||||
RANSOM = 0x002D,
|
||||
SIMPLE = 0x002E,
|
||||
SLOW_TIME = 0x002F,
|
||||
QUICK_TIME = 0x0030,
|
||||
TERRITORY = 0x0031,
|
||||
OLD_TYPE = 0x0032,
|
||||
FLATLAND = 0x0033,
|
||||
IMMORTALITY = 0x0034,
|
||||
SNAIL_PACE = 0x0035,
|
||||
TECH_FIELD = 0x0036,
|
||||
FOREST_RAIN = 0x0037,
|
||||
CAVE_WIND = 0x0038,
|
||||
MINE_BRIGHTNESS = 0x0039,
|
||||
RUIN_DARKNESS = 0x003A,
|
||||
SABER_DANCE = 0x003B,
|
||||
BULLET_STORM = 0x003C,
|
||||
CANE_PALACE = 0x003D,
|
||||
GIANT_GARDEN = 0x003E,
|
||||
MARCH_OF_THE_MEEK = 0x003F,
|
||||
SUPPORT = 0x0040,
|
||||
RICH = 0x0041,
|
||||
REVERSE_CARD = 0x0042,
|
||||
VENGEANCE = 0x0043,
|
||||
SQUEEZE = 0x0044,
|
||||
HOMESICK = 0x0045,
|
||||
BOMB = 0x0046,
|
||||
SKIP_TURN = 0x0047,
|
||||
BATTLE_ROYALE = 0x0048,
|
||||
DICE_FEVER_PLUS = 0x0049,
|
||||
RICH_PLUS = 0x004A,
|
||||
CHARITY_PLUS = 0x004B,
|
||||
ANY = 0x004C, // Unused on cards; used in some search functions
|
||||
};
|
||||
|
||||
enum class BattlePhase : uint8_t {
|
||||
INVALID_00 = 0,
|
||||
DICE = 1,
|
||||
SET = 2,
|
||||
MOVE = 3,
|
||||
ACTION = 4,
|
||||
DRAW = 5,
|
||||
INVALID_FF = 0xFF,
|
||||
};
|
||||
|
||||
enum class ActionSubphase : uint8_t {
|
||||
ATTACK = 0,
|
||||
DEFENSE = 2,
|
||||
INVALID_FF = 0xFF,
|
||||
};
|
||||
|
||||
const char* name_for_action_subphase(ActionSubphase subphase);
|
||||
|
||||
enum class SetupPhase : uint8_t {
|
||||
REGISTRATION = 0,
|
||||
STARTER_ROLLS = 1,
|
||||
HAND_REDRAW_OPTION = 2,
|
||||
MAIN_BATTLE = 3,
|
||||
BATTLE_ENDED = 4,
|
||||
INVALID_FF = 0xFF,
|
||||
};
|
||||
|
||||
enum class RegistrationPhase : uint8_t {
|
||||
AWAITING_NUM_PLAYERS = 0, // num_players not set yet
|
||||
AWAITING_PLAYERS = 1, // num_players set, but some players not registered
|
||||
AWAITING_DECKS = 2, // all players registered, but some decks missing
|
||||
REGISTERED = 3, // All players/decks present, but battle not started yet
|
||||
BATTLE_STARTED = 4,
|
||||
INVALID_FF = 0xFF,
|
||||
};
|
||||
|
||||
|
||||
|
||||
enum class Direction : uint8_t {
|
||||
RIGHT = 0,
|
||||
UP = 1,
|
||||
LEFT = 2,
|
||||
DOWN = 3,
|
||||
INVALID_FF = 0xFF,
|
||||
};
|
||||
|
||||
Direction turn_left(Direction d);
|
||||
Direction turn_right(Direction d);
|
||||
Direction turn_around(Direction d);
|
||||
const char* name_for_direction(Direction d);
|
||||
|
||||
struct Location {
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
Direction direction;
|
||||
uint8_t unused;
|
||||
|
||||
Location();
|
||||
Location(uint8_t x, uint8_t y);
|
||||
Location(uint8_t x, uint8_t y, Direction direction);
|
||||
bool operator==(const Location& other) const;
|
||||
bool operator!=(const Location& other) const;
|
||||
|
||||
std::string str() const;
|
||||
|
||||
void clear();
|
||||
void clear_FF();
|
||||
} __attribute__((packed));
|
||||
|
||||
struct CardDefinition {
|
||||
struct Stat {
|
||||
enum Type : uint8_t {
|
||||
BLANK = 0,
|
||||
STAT = 1,
|
||||
PLUS_STAT = 2,
|
||||
MINUS_STAT = 3,
|
||||
EQUALS_STAT = 4,
|
||||
UNKNOWN = 5,
|
||||
PLUS_UNKNOWN = 6,
|
||||
MINUS_UNKNOWN = 7,
|
||||
EQUALS_UNKNOWN = 8,
|
||||
};
|
||||
be_uint16_t code;
|
||||
Type type;
|
||||
int8_t stat;
|
||||
|
||||
void decode_code();
|
||||
std::string str() const;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Effect {
|
||||
uint8_t effect_num;
|
||||
ConditionType type;
|
||||
ptext<char, 0x0F> expr; // May be blank if the condition type doesn't use it
|
||||
uint8_t when;
|
||||
ptext<char, 4> arg1;
|
||||
ptext<char, 4> arg2;
|
||||
ptext<char, 4> arg3;
|
||||
CriterionCode apply_criterion;
|
||||
uint8_t unknown_a2;
|
||||
|
||||
bool is_empty() const;
|
||||
static std::string str_for_arg(const std::string& arg);
|
||||
std::string str() const;
|
||||
} __attribute__((packed));
|
||||
|
||||
be_uint32_t card_id;
|
||||
parray<uint8_t, 0x40> jp_name;
|
||||
CardType type; // If <0 (signed), then this is the end of the card list
|
||||
uint8_t self_cost; // ATK dice points required
|
||||
uint8_t ally_cost; // ATK points from allies required; PBs use this
|
||||
uint8_t unused1;
|
||||
Stat hp;
|
||||
Stat ap;
|
||||
Stat tp;
|
||||
Stat mv;
|
||||
parray<uint8_t, 8> left_colors;
|
||||
parray<uint8_t, 8> right_colors;
|
||||
parray<uint8_t, 8> top_colors;
|
||||
parray<be_uint32_t, 6> range;
|
||||
be_uint32_t unused2;
|
||||
TargetMode target_mode;
|
||||
uint8_t assist_turns; // 90 (dec) = once, 99 (dec) = forever
|
||||
uint8_t cannot_move; // 0 for SC and creature cards; 1 for everything else
|
||||
uint8_t cannot_attack; // 1 for shields, mags, defense actions, and assist cards
|
||||
uint8_t unused3;
|
||||
uint8_t hide_in_deck_edit; // 0 = player can use this card (appears in deck edit)
|
||||
CriterionCode usable_criterion;
|
||||
CardRarity rarity;
|
||||
be_uint16_t unknown_a2;
|
||||
be_uint16_t be_card_class; // Used for checking attributes (e.g. item types)
|
||||
// These two fields seem to always contain the same value, and are always 0
|
||||
// for non-assist cards and nonzero for assists. Each assist card has a unique
|
||||
// value here and no effects, which makes it look like this is how assist
|
||||
// effects are implemented. There seems to be some 1k-modulation going on here
|
||||
// too; most cards are in the range 101-174 but a few have e.g. 1150, 2141. A
|
||||
// few pairs of cards have the same effect, which makes it look like some
|
||||
// other fields are also involved in determining their effects (see e.g. Skip
|
||||
// Draw / Skip Move, Dice Fever / Dice Fever +, Reverse Card / Rich +).
|
||||
parray<be_uint16_t, 2> assist_effect;
|
||||
// Drop rates are decimal-encoded with the following fields:
|
||||
// - rate % 10 (that is, the lowest decimal place) specifies the required game
|
||||
// mode. 0 means any mode, 1 means offline only, 2 means 1P free-battle, 3
|
||||
// means 2P+ free battle, 4 means story mode.
|
||||
// - (rate / 10) % 100 (that is, the tens and hundreds decimal places) specify
|
||||
// something else, but it's not clear what exactly.
|
||||
// - rate / 1000 (the thousands decimal place) specifies the level class
|
||||
// required to get this drop.
|
||||
// - rate / 10000 (the ten-thousands decimal place) must be either 0, 1, or 2,
|
||||
// but it's not clear yet what each value means.
|
||||
// The drop rates are completely ignored if any of the following are true
|
||||
// (which means the card can never be found in a normal post-battle draw):
|
||||
// - type is SC_HUNTERS or SC_ARKZ
|
||||
// - unknown_a3 is 0x23 or 0x24
|
||||
// - rarity is E, D1, D2, or INVIS
|
||||
// - hide_in_deck_edit is 1 (specifically 1; other nonzero values here don't
|
||||
// prevent the card from appearing in post-battle draws)
|
||||
parray<be_uint16_t, 2> drop_rates;
|
||||
ptext<char, 0x14> en_name;
|
||||
ptext<char, 0x0B> jp_short_name;
|
||||
ptext<char, 0x08> en_short_name;
|
||||
Effect effects[3];
|
||||
uint8_t unused4;
|
||||
|
||||
bool is_sc() const;
|
||||
bool is_fc() const;
|
||||
bool is_named_android_sc() const;
|
||||
bool any_top_color_matches(const CardDefinition& other) const;
|
||||
CardClass card_class() const;
|
||||
|
||||
void decode_range();
|
||||
std::string str() const;
|
||||
} __attribute__((packed)); // 0x128 bytes in total
|
||||
|
||||
struct CardDefinitionsFooter {
|
||||
be_uint32_t num_cards1;
|
||||
be_uint32_t unknown_a1;
|
||||
be_uint32_t num_cards2;
|
||||
be_uint32_t unknown_a2[11];
|
||||
be_uint32_t unknown_offset_a3;
|
||||
be_uint32_t unknown_a4[3];
|
||||
be_uint32_t footer_offset;
|
||||
be_uint32_t unknown_a5[3];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct DeckDefinition {
|
||||
ptext<char, 0x10> name;
|
||||
be_uint32_t client_id; // 0-3
|
||||
// List of card IDs. The card count is the number of nonzero entries here
|
||||
// before a zero entry (or 50 if no entries are nonzero). The first card ID is
|
||||
// the SC card, which the game implicitly subtracts from the limit - so a
|
||||
// valid deck should actually have 31 cards in it.
|
||||
parray<le_uint16_t, 50> card_ids;
|
||||
be_uint32_t unknown_a1;
|
||||
// Last modification time
|
||||
le_uint16_t year;
|
||||
uint8_t month;
|
||||
uint8_t day;
|
||||
uint8_t hour;
|
||||
uint8_t minute;
|
||||
uint8_t second;
|
||||
uint8_t unknown_a2;
|
||||
} __attribute__((packed)); // 0x84 bytes in total
|
||||
|
||||
struct PlayerConfig {
|
||||
// The first offsets in the comments in this struct are relative to start of
|
||||
// 61/98 command; the second are relative to the start of the
|
||||
// Ep3PlayerDataSegment structure in the reverse-engineering project.
|
||||
// TODO: Fill in the unknown fields here by looking around callsites of
|
||||
// get_player_data_segment
|
||||
/* 0728:---- */ parray<uint8_t, 0x154> unknown_a1;
|
||||
/* 087C:0000 */ uint8_t is_encrypted;
|
||||
/* 087D:0001 */ uint8_t basis;
|
||||
/* 087E:0002 */ parray<uint8_t, 2> unused;
|
||||
// The following fields (here through the beginning of decks) are encrypted
|
||||
// using the trivial algorithm, with the basis specified above, if
|
||||
// is_encrypted is equal to 1.
|
||||
// It appears the card counts field in this structure is actually 1000 (0x3E8)
|
||||
// bytes long, even though in every other place the counts array appears it's
|
||||
// 0x2F0 bytes long. They presumably did this because of the checksum logic.
|
||||
/* 0880:0004 */ parray<uint8_t, 1000> card_counts;
|
||||
// These appear to be an attempt at checksumming the card counts array, but
|
||||
// the algorithm don't cover the entire array and instead reads from later
|
||||
// parts of this structure. This appears to be due to a copy/paste error in
|
||||
// the original code. The algorithm sums card_counts [0] through [19] and puts
|
||||
// the result in card_count_checksums[0], then sums card counts [50] through
|
||||
// [69] and puts the result in card_count_checksums[1], etc. Presumably they
|
||||
// intended to use 20 as the stride instead of 50, which would have exactly
|
||||
// covered the entire card_counts array.
|
||||
/* 0C68:03EC */ parray<be_uint16_t, 50> card_count_checksums;
|
||||
// Yes, these are actually 64-bit integers. They include card IDs and some
|
||||
// other data, encoded in a way I don't fully understand yet.
|
||||
/* 0CCC:0450 */ parray<be_uint64_t, 0x1C2> unknown_a4;
|
||||
/* 1ADC:1260 */ parray<uint8_t, 0x80> unknown_a7;
|
||||
/* 1B5C:12E0 */ parray<DeckDefinition, 25> decks;
|
||||
/* 2840:1FC4 */ parray<uint8_t, 0x08> unknown_a8;
|
||||
/* 2848:1FCC */ be_uint32_t offline_clv_exp; // CLvOff = this / 100
|
||||
/* 284C:1FD0 */ be_uint32_t online_clv_exp; // CLvOn = this / 100
|
||||
struct PlayerReference {
|
||||
/* 00 */ be_uint32_t guild_card_number;
|
||||
/* 04 */ ptext<char, 0x18> player_name;
|
||||
} __attribute__((packed));
|
||||
// TODO: What do these player references mean? When are entries added to or
|
||||
// removed from this list?
|
||||
/* 2850:1FD4 */ parray<PlayerReference, 9> unknown_a9;
|
||||
/* 294C:20D0 */ parray<uint8_t, 0x50> unknown_a10;
|
||||
/* 299C:2120 */ ptext<char, 0x10> name;
|
||||
/* 29AC:2130 */ parray<uint8_t, 0xCC> unknown_a11;
|
||||
/* 2A78:21FC */
|
||||
} __attribute__((packed));
|
||||
|
||||
enum class HPType : uint8_t {
|
||||
DEFEAT_PLAYER = 0,
|
||||
DEFEAT_TEAM = 1,
|
||||
COMMON_HP = 2,
|
||||
};
|
||||
|
||||
enum class DiceExchangeMode : uint8_t {
|
||||
HIGH_ATK = 0,
|
||||
HIGH_DEF = 1,
|
||||
NONE = 2,
|
||||
};
|
||||
|
||||
enum class AllowedCards : uint8_t {
|
||||
ALL = 0,
|
||||
N_ONLY = 1,
|
||||
N_R_ONLY = 2,
|
||||
N_R_S_ONLY = 3,
|
||||
};
|
||||
|
||||
struct Rules {
|
||||
// When this structure is used in a map/quest definition, FF in any of these
|
||||
// fields means the user is allowed to override it. Any non-FF fields are
|
||||
// fixed for the map/quest and cannot be overridden.
|
||||
uint8_t overall_time_limit; // In increments of 5 minutes; 0 = unlimited
|
||||
uint8_t phase_time_limit; // In seconds; 0 = unlimited
|
||||
AllowedCards allowed_cards;
|
||||
uint8_t min_dice; // 0 = default (1)
|
||||
// 4
|
||||
uint8_t max_dice; // 0 = default (6)
|
||||
uint8_t disable_deck_shuffle; // 0 = shuffle on, 1 = off
|
||||
uint8_t disable_deck_loop; // 0 = loop on, 1 = off
|
||||
uint8_t char_hp;
|
||||
// 8
|
||||
HPType hp_type;
|
||||
uint8_t no_assist_cards; // 1 = assist cards disallowed
|
||||
uint8_t disable_dialogue; // 0 = dialogue on, 1 = dialogue off
|
||||
DiceExchangeMode dice_exchange_mode;
|
||||
// C
|
||||
uint8_t disable_dice_boost; // 0 = dice boost on, 1 = off
|
||||
parray<uint8_t, 3> unused;
|
||||
|
||||
Rules();
|
||||
explicit Rules(std::shared_ptr<const JSONObject> json);
|
||||
std::shared_ptr<JSONObject> json() const;
|
||||
bool operator==(const Rules& other) const;
|
||||
bool operator!=(const Rules& other) const;
|
||||
void clear();
|
||||
void set_defaults();
|
||||
|
||||
bool check_invalid_fields() const;
|
||||
bool check_and_reset_invalid_fields();
|
||||
|
||||
std::string str() const;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct StateFlags {
|
||||
le_uint16_t turn_num;
|
||||
BattlePhase battle_phase;
|
||||
uint8_t current_team_turn1;
|
||||
uint8_t current_team_turn2;
|
||||
ActionSubphase action_subphase;
|
||||
SetupPhase setup_phase;
|
||||
RegistrationPhase registration_phase;
|
||||
parray<le_uint32_t, 2> team_exp;
|
||||
parray<uint8_t, 2> team_dice_boost;
|
||||
uint8_t first_team_turn;
|
||||
uint8_t tournament_flag;
|
||||
parray<CardType, 4> client_sc_card_types;
|
||||
|
||||
StateFlags();
|
||||
bool operator==(const StateFlags& other) const;
|
||||
bool operator!=(const StateFlags& other) const;
|
||||
void clear();
|
||||
void clear_FF();
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
|
||||
struct MapList {
|
||||
be_uint32_t num_maps;
|
||||
be_uint32_t unknown_a1; // Always 0?
|
||||
be_uint32_t strings_offset; // From after total_size field (add 0x10 to this value)
|
||||
be_uint32_t total_size; // Including header, entries, and strings
|
||||
|
||||
struct Entry { // Should be 0x220 bytes in total
|
||||
be_uint16_t map_x;
|
||||
be_uint16_t map_y;
|
||||
be_uint16_t environment_number;
|
||||
be_uint16_t map_number;
|
||||
// Text offsets are from the beginning of the strings block after all map
|
||||
// entries (that is, add strings_offset to them to get the string offset)
|
||||
be_uint32_t name_offset;
|
||||
be_uint32_t location_name_offset;
|
||||
be_uint32_t quest_name_offset;
|
||||
be_uint32_t description_offset;
|
||||
be_uint16_t width;
|
||||
be_uint16_t height;
|
||||
parray<parray<uint8_t, 0x10>, 0x10> map_tiles;
|
||||
parray<parray<uint8_t, 0x10>, 0x10> modification_tiles;
|
||||
// This appears to be 0xFF for free battle maps, and 0 for quests.
|
||||
// TODO: Figure out what this field's meaning actually is
|
||||
uint8_t unknown_a1;
|
||||
parray<uint8_t, 3> unused;
|
||||
} __attribute__((packed));
|
||||
|
||||
// Variable-length fields:
|
||||
// Entry entries[num_maps];
|
||||
// char strings[...EOF]; // Null-terminated strings, pointed to by offsets in Entry structs
|
||||
} __attribute__((packed));
|
||||
|
||||
struct CompressedMapHeader { // .mnm file format
|
||||
le_uint32_t map_number;
|
||||
le_uint32_t compressed_data_size;
|
||||
// Compressed data immediately follows (which decompresses to a MapDefinition)
|
||||
} __attribute__((packed));
|
||||
|
||||
struct MapDefinition { // .mnmd format; also the format of (decompressed) quests
|
||||
/* 0000 */ be_uint32_t unknown_a1;
|
||||
/* 0004 */ be_uint32_t map_number;
|
||||
/* 0008 */ uint8_t width;
|
||||
/* 0009 */ uint8_t height;
|
||||
// The environment number specifies several things:
|
||||
// - The model to load for the main battle stage
|
||||
// - The music to play during the main battle
|
||||
// - The color of the battle tile outlines (probably)
|
||||
// - The preview image to show in the upper-left corner in the map select menu
|
||||
// The environment numbers are:
|
||||
// 00 - Unguis Lapis
|
||||
// 01 - Nebula Montana (1)
|
||||
// 02 - Lupus Silva (1)
|
||||
// 03 - Lupus Silva (2)
|
||||
// 04 - Molae Venti
|
||||
// 05 - Nebula Montana (2)
|
||||
// 06 - Tener Sinus
|
||||
// 07 - Mortis Fons
|
||||
// 08 - Morgue (destroyed)
|
||||
// 09 - Tower of Caelum
|
||||
// 0A = ??? (referred to as "^mapname"; crashes)
|
||||
// 0B = Cyber
|
||||
// 0C = Morgue (not destroyed)
|
||||
// 0D = (Castor/Pollux map)
|
||||
// 0E - Dolor Odor
|
||||
// 0F = Ravum Aedes Sacra
|
||||
// 10 - (Amplum Umbla map)
|
||||
// 11 - Via Tubus
|
||||
// 12 = Morgue (same as 08?)
|
||||
// 13 = ??? (crashes)
|
||||
// Environment numbers beyond 13 are not used in any known quests or maps.
|
||||
/* 000A */ uint8_t environment_number;
|
||||
// All alt_maps fields (including the floats) past num_alt_maps are filled in
|
||||
// with FF. For example, if num_alt_maps == 8, the last two fields in each
|
||||
// alt_maps array are filled with FF.
|
||||
/* 000B */ uint8_t num_alt_maps; // TODO: What are the alt maps for?
|
||||
// In the map_tiles array, the values are usually:
|
||||
// 00 = not a valid tile (blocked)
|
||||
// 01 = valid tile unless modified out (via modification_tiles)
|
||||
// 02 = team A start (1v1)
|
||||
// 03, 04 = team A start (2v2)
|
||||
// 06, 07 = team B start (2v2)
|
||||
// 08 = team B start (1v1)
|
||||
// These values can be redefined by start_tile_definitions below, however.
|
||||
// Note that the game displays the map reversed vertically in the preview
|
||||
// window. For example, player 1 is on team A, which usually starts at the top
|
||||
// of the map as defined in this struct, or at the bottom as shown in the
|
||||
// preview window.
|
||||
/* 000C */ parray<parray<uint8_t, 0x10>, 0x10> map_tiles;
|
||||
// The start_tile_definitions field is a list of 6 bytes for each team. The
|
||||
// low 6 bits of each byte match the starting location for the relevant player
|
||||
// in map_tiles; the high 2 bits are the player's initial facing direction.
|
||||
// - If the team has 1 player, only byte [0] is used.
|
||||
// - If the team has 2 players, bytes [1] and [2] are used.
|
||||
// - If the team has 3 players, bytes [3] through [5] are used.
|
||||
/* 010C */ parray<parray<uint8_t, 6>, 2> start_tile_definitions;
|
||||
/* 0118 */ parray<parray<uint8_t, 0x10>, 0x10> alt_maps1[2][0x0A];
|
||||
/* 1518 */ parray<be_float, 0x12> alt_maps_unknown_a3[2][0x0A];
|
||||
/* 1AB8 */ parray<be_float, 0x24> unknown_a5[3];
|
||||
// In the modification_tiles array, the values are:
|
||||
// 10 = blocked by rock (as if the corresponding map_tiles value was 00)
|
||||
// 20 = blocked by fence (as if the corresponding map_tiles value was 00)
|
||||
// 30-34 = teleporters (2 of each value may be present)
|
||||
// 40-44 = traps (one of each type is chosen at random to be a real trap at
|
||||
// battle start time)
|
||||
// 50 = blocked by metal box (appears as improperly-z-buffered teal cube in
|
||||
// preview; behaves like 10 and 20 in game)
|
||||
/* 1C68 */ parray<parray<uint8_t, 0x10>, 0x10> modification_tiles;
|
||||
/* 1D68 */ parray<uint8_t, 0x74> unknown_a6;
|
||||
/* 1DDC */ Rules default_rules;
|
||||
/* 1DEC */ parray<uint8_t, 4> unknown_a7;
|
||||
/* 1DF0 */ ptext<char, 0x14> name;
|
||||
/* 1E04 */ ptext<char, 0x14> location_name;
|
||||
/* 1E18 */ ptext<char, 0x3C> quest_name; // == location_name if not a quest
|
||||
/* 1E54 */ ptext<char, 0x190> description;
|
||||
/* 1FE4 */ be_uint16_t map_x;
|
||||
/* 1FE6 */ be_uint16_t map_y;
|
||||
struct NPCDeck {
|
||||
ptext<char, 0x18> name;
|
||||
parray<be_uint16_t, 0x20> card_ids; // Last one appears to always be FFFF
|
||||
} __attribute__((packed));
|
||||
/* 1FE8 */ NPCDeck npc_decks[3]; // Unused if name[0] == 0
|
||||
struct NPCCharacter {
|
||||
parray<be_uint16_t, 2> unknown_a1;
|
||||
parray<uint8_t, 4> unknown_a2;
|
||||
ptext<char, 0x10> name;
|
||||
parray<be_uint16_t, 0x7E> unknown_a3;
|
||||
} __attribute__((packed));
|
||||
/* 20F0 */ NPCCharacter npc_chars[3]; // Unused if name[0] == 0
|
||||
/* 242C */ parray<uint8_t, 0x14> unknown_a8; // Always FF?
|
||||
/* 2440 */ ptext<char, 0x190> before_message;
|
||||
/* 25D0 */ ptext<char, 0x190> after_message;
|
||||
/* 2760 */ ptext<char, 0x190> dispatch_message; // Usually "You can only dispatch <character>" or blank
|
||||
struct DialogueSet {
|
||||
be_uint16_t unknown_a1;
|
||||
be_uint16_t unknown_a2; // Always 0x0064 if valid, 0xFFFF if unused?
|
||||
ptext<char, 0x40> strings[4];
|
||||
} __attribute__((packed)); // Total size: 0x104 bytes
|
||||
/* 28F0 */ DialogueSet dialogue_sets[3][0x10]; // Up to 0x10 per valid NPC
|
||||
/* 59B0 */ parray<be_uint16_t, 0x10> reward_card_ids;
|
||||
/* 59D0 */ parray<uint8_t, 0x0C> unknown_a9;
|
||||
/* 59DC */ uint8_t unknown_a10;
|
||||
/* 59DD */ parray<uint8_t, 3> unknown_a11;
|
||||
// This array specifies which SC characters can't participate in the quest
|
||||
// (that is, the player is not allowed to choose decks with these SC cards).
|
||||
// The values in this array don't match the SC card IDs, however:
|
||||
// 0000 => Guykild (0005) 000C => Hyze (0117)
|
||||
// 0001 => Kylria (0006) 000D => Rufina (0118)
|
||||
// 0002 => Saligun (0110) 000E => Peko (0119)
|
||||
// 0003 => Relmitos (0111) 000F => Creinu (011A)
|
||||
// 0004 => Kranz (0002) 0010 => Reiz (011B)
|
||||
// 0005 => Sil'fer (0004) 0011 => Lura (0007)
|
||||
// 0006 => Ino'lis (0003) 0012 => Break (0008)
|
||||
// 0007 => Viviana (0112) 0013 => Rio (011C)
|
||||
// 0008 => Teifu (0113) 0014 => Endu (0116)
|
||||
// 0009 => Orland (0001) 0015 => Memoru (011D)
|
||||
// 000A => Stella (0114) 0016 => K.C. (011E)
|
||||
// 000B => Glustar (0115) 0017 => Ohgun (011F)
|
||||
// Unused entries in this array should be set to FFFF.
|
||||
/* 59E0 */ parray<be_uint16_t, 0x18> unavailable_sc_cards;
|
||||
struct EntryState {
|
||||
// Values for player_type:
|
||||
// 00 = Player (selectable by player, COM decks not allowed)
|
||||
// 01 = Player/COM (selectable by player)
|
||||
// 02 = COM (selectable by player, player decks not allowed)
|
||||
// 03 = COM (not selectable by player; uses NPC deck)
|
||||
// 04 = NONE (not selectable by player)
|
||||
// FF = FREE (same as Player/COM, used in free battle mode)
|
||||
uint8_t player_type;
|
||||
// Values for deck_type:
|
||||
// 00 = HERO ONLY
|
||||
// 01 = DARK ONLY
|
||||
// FF = any deck allowed
|
||||
uint8_t deck_type;
|
||||
} __attribute__((packed));
|
||||
/* 5A10 */ parray<EntryState, 4> entry_states;
|
||||
/* 5A18 */
|
||||
|
||||
std::string str(const DataIndex* data_index = nullptr) const;
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
|
||||
struct COMDeckDefinition {
|
||||
size_t index;
|
||||
std::string player_name;
|
||||
std::string deck_name;
|
||||
parray<le_uint16_t, 0x1F> card_ids;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class DataIndex {
|
||||
public:
|
||||
DataIndex(const std::string& directory, uint32_t behavior_flags);
|
||||
|
||||
struct CardEntry {
|
||||
CardDefinition def;
|
||||
std::string text;
|
||||
std::vector<std::string> debug_tags; // Empty unless debug == true
|
||||
};
|
||||
|
||||
class MapEntry {
|
||||
public:
|
||||
MapDefinition map;
|
||||
bool is_quest;
|
||||
|
||||
MapEntry(const MapDefinition& map, bool is_quest);
|
||||
MapEntry(const std::string& compressed_data, bool is_quest);
|
||||
|
||||
std::string compressed() const;
|
||||
|
||||
private:
|
||||
mutable std::string compressed_data;
|
||||
};
|
||||
|
||||
const std::string& get_compressed_card_definitions() const;
|
||||
std::shared_ptr<const CardEntry> definition_for_card_id(uint32_t id) const;
|
||||
std::shared_ptr<const CardEntry> definition_for_card_name(
|
||||
const std::string& name) const;
|
||||
std::set<uint32_t> all_card_ids() const;
|
||||
uint64_t card_definitions_mtime() const;
|
||||
|
||||
const std::string& get_compressed_map_list() const;
|
||||
std::shared_ptr<const MapEntry> definition_for_map_number(uint32_t id) const;
|
||||
std::shared_ptr<const MapEntry> definition_for_map_name(
|
||||
const std::string& name) const;
|
||||
std::set<uint32_t> all_map_ids() const;
|
||||
|
||||
size_t num_com_decks() const;
|
||||
std::shared_ptr<const COMDeckDefinition> com_deck(size_t which) const;
|
||||
std::shared_ptr<const COMDeckDefinition> com_deck(const std::string& name) const;
|
||||
std::shared_ptr<const COMDeckDefinition> random_com_deck() const;
|
||||
|
||||
const uint32_t behavior_flags;
|
||||
|
||||
private:
|
||||
std::string compressed_card_definitions;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<CardEntry>> card_definitions;
|
||||
std::unordered_map<std::string, std::shared_ptr<CardEntry>> card_definitions_by_name;
|
||||
uint64_t mtime_for_card_definitions;
|
||||
|
||||
// The compressed map list is generated on demand from the maps map below.
|
||||
// It's marked mutable because the logical consistency of the DataIndex object
|
||||
// is not violated from the caller's perspective even if we don't generate the
|
||||
// compressed map list at load time.
|
||||
mutable std::string compressed_map_list;
|
||||
std::map<uint32_t, std::shared_ptr<MapEntry>> maps;
|
||||
std::unordered_map<std::string, std::shared_ptr<MapEntry>> maps_by_name;
|
||||
|
||||
std::vector<std::shared_ptr<COMDeckDefinition>> com_decks;
|
||||
std::unordered_map<std::string, std::shared_ptr<COMDeckDefinition>> com_decks_by_name;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -4,8 +4,6 @@ using namespace std;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
NameEntry::NameEntry() {
|
||||
this->clear();
|
||||
}
|
||||
@@ -17,8 +15,6 @@ void NameEntry::clear() {
|
||||
this->unused = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
DeckEntry::DeckEntry() {
|
||||
this->clear();
|
||||
}
|
||||
@@ -32,8 +28,6 @@ void DeckEntry::clear() {
|
||||
this->card_ids.clear(0xFFFF);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t index_for_card_ref(uint16_t card_ref) {
|
||||
return card_ref & 0xFF;
|
||||
}
|
||||
@@ -42,8 +36,6 @@ uint8_t client_id_for_card_ref(uint16_t card_ref) {
|
||||
return (card_ref >> 8) & 0xFF;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t DeckState::num_drawable_cards() const {
|
||||
return this->card_refs.size() - this->draw_index;
|
||||
}
|
||||
@@ -102,8 +94,8 @@ bool DeckState::draw_card_by_ref(uint16_t card_ref) {
|
||||
this->entries[index].state = CardState::IN_HAND;
|
||||
return true;
|
||||
|
||||
// If the card is still drawable, we need to move it so it's just in front of
|
||||
// the draw index, then immediately draw it
|
||||
// If the card is still drawable, we need to move it so it's just in front of
|
||||
// the draw index, then immediately draw it
|
||||
} else if (this->entries[index].state == CardState::DRAWABLE) {
|
||||
ssize_t ref_index;
|
||||
for (ref_index = this->card_refs.size(); ref_index >= 0; ref_index--) {
|
||||
@@ -281,6 +273,4 @@ void DeckState::shuffle() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
@@ -4,13 +4,11 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "../Text.hh"
|
||||
#include "../PSOEncryption.hh"
|
||||
#include "../Text.hh"
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
struct NameEntry {
|
||||
parray<char, 0x10> name;
|
||||
uint8_t client_id;
|
||||
@@ -56,13 +54,13 @@ public:
|
||||
DeckState(
|
||||
uint8_t client_id,
|
||||
const parray<CardIDT, 0x1F>& card_ids,
|
||||
std::shared_ptr<PSOV2Encryption> random_crypt)
|
||||
: client_id(client_id),
|
||||
draw_index(1),
|
||||
card_ref_base(this->client_id << 8),
|
||||
shuffle_enabled(true),
|
||||
loop_enabled(true),
|
||||
random_crypt(random_crypt) {
|
||||
std::shared_ptr<PSOLFGEncryption> random_crypt)
|
||||
: client_id(client_id),
|
||||
draw_index(1),
|
||||
card_ref_base(this->client_id << 8),
|
||||
shuffle_enabled(true),
|
||||
loop_enabled(true),
|
||||
random_crypt(random_crypt) {
|
||||
for (size_t z = 0; z < card_ids.size(); z++) {
|
||||
auto& e = this->entries[z];
|
||||
e.card_id = card_ids[z];
|
||||
@@ -109,9 +107,7 @@ private:
|
||||
parray<CardEntry, 31> entries;
|
||||
parray<uint16_t, 31> card_refs;
|
||||
|
||||
std::shared_ptr<PSOV2Encryption> random_crypt;
|
||||
std::shared_ptr<PSOLFGEncryption> random_crypt;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
@@ -4,8 +4,6 @@ using namespace std;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
MapState::MapState() {
|
||||
this->clear();
|
||||
}
|
||||
@@ -32,8 +30,6 @@ void MapState::print(FILE* stream) const {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
MapAndRulesState::MapAndRulesState() {
|
||||
this->clear();
|
||||
}
|
||||
@@ -42,7 +38,7 @@ void MapAndRulesState::clear() {
|
||||
this->map.clear();
|
||||
this->num_players = 0;
|
||||
this->unused1 = 0;
|
||||
this->unused_by_server = 0;
|
||||
this->environment_number = 0;
|
||||
this->num_players_per_team = 0;
|
||||
this->num_team0_players = 0;
|
||||
this->unused2 = 0;
|
||||
@@ -54,8 +50,6 @@ void MapAndRulesState::clear() {
|
||||
this->unused5 = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool MapAndRulesState::loc_is_within_bounds(uint8_t x, uint8_t y) const {
|
||||
return (x < this->map.width) && (y < this->map.height);
|
||||
}
|
||||
@@ -75,8 +69,6 @@ void MapAndRulesState::clear_occupied_bit_for_tile(uint8_t x, uint8_t y) {
|
||||
this->map.tiles[y][x] &= 0xEF;
|
||||
}
|
||||
|
||||
|
||||
|
||||
OverlayState::OverlayState() {
|
||||
this->clear();
|
||||
}
|
||||
@@ -90,6 +82,4 @@ void OverlayState::clear() {
|
||||
this->unused3.clear(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
@@ -5,12 +5,10 @@
|
||||
#include <memory>
|
||||
|
||||
#include "../Text.hh"
|
||||
#include "DataIndex.hh"
|
||||
#include "DataIndexes.hh"
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
struct MapState {
|
||||
le_uint16_t width;
|
||||
le_uint16_t height;
|
||||
@@ -27,7 +25,7 @@ struct MapAndRulesState {
|
||||
MapState map;
|
||||
uint8_t num_players;
|
||||
uint8_t unused1;
|
||||
uint8_t unused_by_server;
|
||||
uint8_t environment_number;
|
||||
uint8_t num_players_per_team;
|
||||
uint8_t num_team0_players;
|
||||
uint8_t unused2;
|
||||
@@ -58,6 +56,4 @@ struct OverlayState {
|
||||
void clear();
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
+41
-37
@@ -6,40 +6,38 @@ using namespace std;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
PlayerState::PlayerState(uint8_t client_id, shared_ptr<Server> server)
|
||||
: w_server(server),
|
||||
client_id(client_id),
|
||||
num_mulligans_allowed(1),
|
||||
sc_card_type(CardType::HUNTERS_SC),
|
||||
team_id(0xFF),
|
||||
atk_points(0),
|
||||
def_points(0),
|
||||
atk_points2(0),
|
||||
atk_points2_max(6),
|
||||
atk_bonuses(0),
|
||||
def_bonuses(0),
|
||||
dice_results(0),
|
||||
unknown_a4(2),
|
||||
dice_max(6),
|
||||
total_set_cards_cost(0),
|
||||
sc_card_id(0xFFFF),
|
||||
sc_card_ref(0xFFFF),
|
||||
card_refs(0xFFFF),
|
||||
discard_log_card_refs(0xFFFF),
|
||||
discard_log_reasons(0),
|
||||
assist_remaining_turns(0),
|
||||
assist_card_set_number(0),
|
||||
set_assist_card_id(0xFFFF),
|
||||
god_whim_can_use_hidden_cards(false),
|
||||
unknown_a14(0),
|
||||
assist_flags(0),
|
||||
assist_delay_turns(0),
|
||||
start_facing_direction(Direction::RIGHT),
|
||||
num_destroyed_fcs(0),
|
||||
unknown_a16(0),
|
||||
unknown_a17(0) { }
|
||||
: w_server(server),
|
||||
client_id(client_id),
|
||||
num_mulligans_allowed(1),
|
||||
sc_card_type(CardType::HUNTERS_SC),
|
||||
team_id(0xFF),
|
||||
atk_points(0),
|
||||
def_points(0),
|
||||
atk_points2(0),
|
||||
atk_points2_max(6),
|
||||
atk_bonuses(0),
|
||||
def_bonuses(0),
|
||||
dice_results(0),
|
||||
unknown_a4(2),
|
||||
dice_max(6),
|
||||
total_set_cards_cost(0),
|
||||
sc_card_id(0xFFFF),
|
||||
sc_card_ref(0xFFFF),
|
||||
card_refs(0xFFFF),
|
||||
discard_log_card_refs(0xFFFF),
|
||||
discard_log_reasons(0),
|
||||
assist_remaining_turns(0),
|
||||
assist_card_set_number(0),
|
||||
set_assist_card_id(0xFFFF),
|
||||
god_whim_can_use_hidden_cards(false),
|
||||
unknown_a14(0),
|
||||
assist_flags(0),
|
||||
assist_delay_turns(0),
|
||||
start_facing_direction(Direction::RIGHT),
|
||||
num_destroyed_fcs(0),
|
||||
unknown_a16(0),
|
||||
unknown_a17(0) {}
|
||||
|
||||
void PlayerState::init() {
|
||||
if (this->server()->player_states[this->client_id].get() != this) {
|
||||
@@ -555,6 +553,8 @@ void PlayerState::discard_and_redraw_hand() {
|
||||
G_Unknown_GC_Ep3_6xB4x2C cmd;
|
||||
cmd.change_type = 3;
|
||||
cmd.client_id = this->client_id;
|
||||
cmd.card_refs.clear(0xFFFF);
|
||||
cmd.unknown_a2.clear(0xFFFFFFFF);
|
||||
this->server()->send(cmd);
|
||||
|
||||
this->deck_state->restart();
|
||||
@@ -643,6 +643,8 @@ bool PlayerState::do_mulligan() {
|
||||
G_Unknown_GC_Ep3_6xB4x2C cmd;
|
||||
cmd.change_type = 3;
|
||||
cmd.client_id = this->client_id;
|
||||
cmd.card_refs.clear(0xFFFF);
|
||||
cmd.unknown_a2.clear(0xFFFFFFFF);
|
||||
this->server()->send(cmd);
|
||||
|
||||
this->deck_state->do_mulligan();
|
||||
@@ -992,7 +994,7 @@ void PlayerState::replace_all_set_assists_with_random_assists() {
|
||||
card_id = ALL_ASSIST_CARD_IDS[index];
|
||||
if (!this->god_whim_can_use_hidden_cards) {
|
||||
auto ce = this->server()->definition_for_card_id(card_id);
|
||||
if (!ce || ce->def.hide_in_deck_edit) {
|
||||
if (!ce || ce->def.cannot_drop) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -1265,6 +1267,7 @@ bool PlayerState::set_card_from_hand(
|
||||
this->server()->send_6xB4x05();
|
||||
|
||||
G_Unknown_GC_Ep3_6xB4x4A cmd;
|
||||
cmd.card_refs.clear(0xFFFF);
|
||||
cmd.card_refs[0] = card_ref;
|
||||
cmd.client_id = this->client_id;
|
||||
cmd.entry_count = 1;
|
||||
@@ -1411,7 +1414,8 @@ void PlayerState::update_hand_and_equip_state_and_send_6xB4x02_if_needed(
|
||||
cmd.state.sc_card_ref = this->sc_card_ref;
|
||||
cmd.state.assist_card_ref2 = this->card_refs[6];
|
||||
cmd.state.assist_card_set_number = (this->card_refs[6] == 0xFFFF)
|
||||
? 0 : this->assist_card_set_number;
|
||||
? 0
|
||||
: this->assist_card_set_number;
|
||||
cmd.state.assist_card_id = this->set_assist_card_id;
|
||||
cmd.state.assist_remaining_turns = this->assist_remaining_turns;
|
||||
cmd.state.assist_delay_turns = this->assist_delay_turns;
|
||||
@@ -1581,6 +1585,7 @@ bool PlayerState::set_action_cards_for_action_state(const ActionState& pa) {
|
||||
|
||||
if (action_type == ActionType::ATTACK) {
|
||||
G_Unknown_GC_Ep3_6xB4x4A cmd;
|
||||
cmd.card_refs.clear(0xFFFF);
|
||||
cmd.client_id = this->client_id;
|
||||
cmd.round_num = this->server()->get_round_num();
|
||||
cmd.entry_count = 0;
|
||||
@@ -1619,6 +1624,7 @@ bool PlayerState::set_action_cards_for_action_state(const ActionState& pa) {
|
||||
|
||||
} else if (action_type == ActionType::DEFENSE) {
|
||||
G_Unknown_GC_Ep3_6xB4x4A cmd;
|
||||
cmd.card_refs.clear(0xFFFF);
|
||||
cmd.client_id = this->client_id;
|
||||
cmd.round_num = this->server()->get_round_num();
|
||||
for (size_t z = 0; (z < 4 * 9) && (pa.target_card_refs[z] != 0xFFFF); z++) {
|
||||
@@ -1830,6 +1836,4 @@ void PlayerState::compute_team_dice_boost_after_draw_phase() {
|
||||
this->update_hand_and_equip_state_and_send_6xB4x02_if_needed();
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
@@ -5,15 +5,13 @@
|
||||
#include <memory>
|
||||
|
||||
#include "../Text.hh"
|
||||
#include "DataIndex.hh"
|
||||
#include "Card.hh"
|
||||
#include "DataIndexes.hh"
|
||||
#include "DeckState.hh"
|
||||
#include "PlayerStateSubordinates.hh"
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
class ServerBase;
|
||||
class Server;
|
||||
|
||||
@@ -25,8 +23,7 @@ public:
|
||||
std::shared_ptr<const Server> server() const;
|
||||
|
||||
bool draw_cards_allowed() const;
|
||||
void apply_assist_card_effect_on_set(
|
||||
std::shared_ptr<PlayerState> setter_ps);
|
||||
void apply_assist_card_effect_on_set(std::shared_ptr<PlayerState> setter_ps);
|
||||
void apply_dice_effects();
|
||||
uint16_t card_ref_for_hand_index(size_t hand_index) const;
|
||||
int16_t compute_attack_or_defense_atk_costs(const ActionState& pa) const;
|
||||
@@ -185,9 +182,7 @@ public:
|
||||
uint32_t num_destroyed_fcs;
|
||||
uint8_t unknown_a16;
|
||||
uint8_t unknown_a17;
|
||||
PlayerStats stats;
|
||||
PlayerBattleStats stats;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
@@ -6,8 +6,6 @@ using namespace std;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
template <size_t Count>
|
||||
std::string string_for_refs(const parray<le_uint16_t, Count>& card_refs) {
|
||||
string ret = "[";
|
||||
@@ -24,26 +22,24 @@ std::string string_for_refs(const parray<le_uint16_t, Count>& card_refs) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Condition::Condition() {
|
||||
this->clear();
|
||||
}
|
||||
|
||||
bool Condition::operator==(const Condition& other) const {
|
||||
return (this->type == other.type) &&
|
||||
(this->remaining_turns == other.remaining_turns) &&
|
||||
(this->a_arg_value == other.a_arg_value) &&
|
||||
(this->dice_roll_value == other.dice_roll_value) &&
|
||||
(this->flags == other.flags) &&
|
||||
(this->card_definition_effect_index == other.card_definition_effect_index) &&
|
||||
(this->card_ref == other.card_ref) &&
|
||||
(this->value == other.value) &&
|
||||
(this->condition_giver_card_ref == other.condition_giver_card_ref) &&
|
||||
(this->random_percent == other.random_percent) &&
|
||||
(this->value8 == other.value8) &&
|
||||
(this->order == other.order) &&
|
||||
(this->unknown_a8 == other.unknown_a8);
|
||||
(this->remaining_turns == other.remaining_turns) &&
|
||||
(this->a_arg_value == other.a_arg_value) &&
|
||||
(this->dice_roll_value == other.dice_roll_value) &&
|
||||
(this->flags == other.flags) &&
|
||||
(this->card_definition_effect_index == other.card_definition_effect_index) &&
|
||||
(this->card_ref == other.card_ref) &&
|
||||
(this->value == other.value) &&
|
||||
(this->condition_giver_card_ref == other.condition_giver_card_ref) &&
|
||||
(this->random_percent == other.random_percent) &&
|
||||
(this->value8 == other.value8) &&
|
||||
(this->order == other.order) &&
|
||||
(this->unknown_a8 == other.unknown_a8);
|
||||
}
|
||||
bool Condition::operator!=(const Condition& other) const {
|
||||
return !this->operator==(other);
|
||||
@@ -84,8 +80,8 @@ void Condition::clear_FF() {
|
||||
std::string Condition::str() const {
|
||||
return string_printf(
|
||||
"Condition[type=%s, turns=%hhu, a_arg=%hhd, dice=%hhu, flags=%02hhX, "
|
||||
"def_eff_index=%hhu, ref=@%04hX, value=%hd, giver_ref=@%04hX "
|
||||
"percent=%hhu value8=%hd order=%hu a8=%hu]",
|
||||
"def_eff_index=%hhu, ref=@%04hX, value=%hd, giver_ref=@%04hX "
|
||||
"percent=%hhu value8=%hd order=%hu a8=%hu]",
|
||||
name_for_condition_type(this->type),
|
||||
this->remaining_turns,
|
||||
this->a_arg_value,
|
||||
@@ -101,8 +97,6 @@ std::string Condition::str() const {
|
||||
this->unknown_a8);
|
||||
}
|
||||
|
||||
|
||||
|
||||
EffectResult::EffectResult() {
|
||||
this->clear();
|
||||
}
|
||||
@@ -123,8 +117,8 @@ void EffectResult::clear() {
|
||||
std::string EffectResult::str() const {
|
||||
return string_printf(
|
||||
"EffectResult[att_ref=@%04hX, target_ref=@%04hX, value=%hhd, "
|
||||
"cur_hp=%hhd, ap=%hhd, tp=%hhd, flags=%02hhX, op=%hhd, "
|
||||
"cond_index=%hhu, dice=%hhu]",
|
||||
"cur_hp=%hhd, ap=%hhd, tp=%hhd, flags=%02hhX, op=%hhd, "
|
||||
"cond_index=%hhu, dice=%hhu]",
|
||||
this->attacker_card_ref.load(),
|
||||
this->target_card_ref.load(),
|
||||
this->value,
|
||||
@@ -137,20 +131,18 @@ std::string EffectResult::str() const {
|
||||
this->dice_roll_value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
CardShortStatus::CardShortStatus() {
|
||||
this->clear();
|
||||
}
|
||||
|
||||
bool CardShortStatus::operator==(const CardShortStatus& other) const {
|
||||
return (this->card_ref == other.card_ref) &&
|
||||
(this->current_hp == other.current_hp) &&
|
||||
(this->card_flags == other.card_flags) &&
|
||||
(this->loc == other.loc) &&
|
||||
(this->unused1 == other.unused1) &&
|
||||
(this->max_hp == other.max_hp) &&
|
||||
(this->unused2 == other.unused2);
|
||||
(this->current_hp == other.current_hp) &&
|
||||
(this->card_flags == other.card_flags) &&
|
||||
(this->loc == other.loc) &&
|
||||
(this->unused1 == other.unused1) &&
|
||||
(this->max_hp == other.max_hp) &&
|
||||
(this->unused2 == other.unused2);
|
||||
}
|
||||
bool CardShortStatus::operator!=(const CardShortStatus& other) const {
|
||||
return !this->operator==(other);
|
||||
@@ -160,7 +152,7 @@ std::string CardShortStatus::str() const {
|
||||
string loc_s = this->loc.str();
|
||||
return string_printf(
|
||||
"CardShortStatus[ref=@%04hX, cur_hp=%hd, flags=%08" PRIX32 ", loc=%s, "
|
||||
"u1=%04hX, max_hp=%hhd, u2=%hhu]",
|
||||
"u1=%04hX, max_hp=%hhd, u2=%hhu]",
|
||||
this->card_ref.load(),
|
||||
this->current_hp.load(),
|
||||
this->card_flags.load(),
|
||||
@@ -190,8 +182,6 @@ void CardShortStatus::clear_FF() {
|
||||
this->unused2 = 0xFF;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ActionState::ActionState() {
|
||||
this->clear();
|
||||
}
|
||||
@@ -212,8 +202,8 @@ std::string ActionState::str() const {
|
||||
string action_refs_s = string_for_refs(this->action_card_refs);
|
||||
return string_printf(
|
||||
"ActionState[client=%hu, u=%hhu, facing=%s, attacker_ref=@%04hX, "
|
||||
"def_ref=@%04hX, target_refs=%s, action_refs=%s, "
|
||||
"orig_attacker_ref=@%04hX]",
|
||||
"def_ref=@%04hX, target_refs=%s, action_refs=%s, "
|
||||
"orig_attacker_ref=@%04hX]",
|
||||
this->client_id.load(),
|
||||
this->unused,
|
||||
name_for_direction(this->facing_direction),
|
||||
@@ -224,34 +214,32 @@ std::string ActionState::str() const {
|
||||
this->original_attacker_card_ref.load());
|
||||
}
|
||||
|
||||
|
||||
|
||||
ActionChain::ActionChain() {
|
||||
this->clear();
|
||||
}
|
||||
|
||||
bool ActionChain::operator==(const ActionChain& other) const {
|
||||
return (this->effective_ap == other.effective_ap) &&
|
||||
(this->effective_tp == other.effective_tp) &&
|
||||
(this->ap_effect_bonus == other.ap_effect_bonus) &&
|
||||
(this->damage == other.damage) &&
|
||||
(this->acting_card_ref == other.acting_card_ref) &&
|
||||
(this->unknown_card_ref_a3 == other.unknown_card_ref_a3) &&
|
||||
(this->attack_action_card_refs == other.attack_action_card_refs) &&
|
||||
(this->attack_action_card_ref_count == other.attack_action_card_ref_count) &&
|
||||
(this->attack_medium == other.attack_medium) &&
|
||||
(this->target_card_ref_count == other.target_card_ref_count) &&
|
||||
(this->action_subphase == other.action_subphase) &&
|
||||
(this->strike_count == other.strike_count) &&
|
||||
(this->damage_multiplier == other.damage_multiplier) &&
|
||||
(this->attack_number == other.attack_number) &&
|
||||
(this->tp_effect_bonus == other.tp_effect_bonus) &&
|
||||
(this->unused1 == other.unused1) &&
|
||||
(this->unused2 == other.unused2) &&
|
||||
(this->card_ap == other.card_ap) &&
|
||||
(this->card_tp == other.card_tp) &&
|
||||
(this->flags == other.flags) &&
|
||||
(this->target_card_refs == other.target_card_refs);
|
||||
(this->effective_tp == other.effective_tp) &&
|
||||
(this->ap_effect_bonus == other.ap_effect_bonus) &&
|
||||
(this->damage == other.damage) &&
|
||||
(this->acting_card_ref == other.acting_card_ref) &&
|
||||
(this->unknown_card_ref_a3 == other.unknown_card_ref_a3) &&
|
||||
(this->attack_action_card_refs == other.attack_action_card_refs) &&
|
||||
(this->attack_action_card_ref_count == other.attack_action_card_ref_count) &&
|
||||
(this->attack_medium == other.attack_medium) &&
|
||||
(this->target_card_ref_count == other.target_card_ref_count) &&
|
||||
(this->action_subphase == other.action_subphase) &&
|
||||
(this->strike_count == other.strike_count) &&
|
||||
(this->damage_multiplier == other.damage_multiplier) &&
|
||||
(this->attack_number == other.attack_number) &&
|
||||
(this->tp_effect_bonus == other.tp_effect_bonus) &&
|
||||
(this->unused1 == other.unused1) &&
|
||||
(this->unused2 == other.unused2) &&
|
||||
(this->card_ap == other.card_ap) &&
|
||||
(this->card_tp == other.card_tp) &&
|
||||
(this->flags == other.flags) &&
|
||||
(this->target_card_refs == other.target_card_refs);
|
||||
}
|
||||
bool ActionChain::operator!=(const ActionChain& other) const {
|
||||
return !this->operator==(other);
|
||||
@@ -262,12 +250,12 @@ std::string ActionChain::str() const {
|
||||
string target_card_refs_s = string_for_refs(this->target_card_refs);
|
||||
return string_printf(
|
||||
"ActionChain[eff_ap=%hhd, eff_tp=%hhd, ap_bonus=%hhd, damage=%hhd, "
|
||||
"acting_ref=@%04hX, unknown_ref_a3=@%04hX, "
|
||||
"attack_action_refs=%s, attack_action_ref_count=%hhu, "
|
||||
"medium=%s, target_ref_count=%hhu, subphase=%s, "
|
||||
"strikes=%hhu, damage_mult=%hhd, attack_num=%hhu, "
|
||||
"tp_bonus=%hhd, u1=%hhu, u2=%hhu, card_ap=%hhd, "
|
||||
"card_tp=%hhd, flags=%08" PRIX32 ", target_refs=%s]",
|
||||
"acting_ref=@%04hX, unknown_ref_a3=@%04hX, "
|
||||
"attack_action_refs=%s, attack_action_ref_count=%hhu, "
|
||||
"medium=%s, target_ref_count=%hhu, subphase=%s, "
|
||||
"strikes=%hhu, damage_mult=%hhd, attack_num=%hhu, "
|
||||
"tp_bonus=%hhd, u1=%hhu, u2=%hhu, card_ap=%hhd, "
|
||||
"card_tp=%hhd, flags=%08" PRIX32 ", target_refs=%s]",
|
||||
this->effective_ap,
|
||||
this->effective_tp,
|
||||
this->ap_effect_bonus,
|
||||
@@ -339,8 +327,6 @@ void ActionChain::clear_FF() {
|
||||
this->target_card_refs.clear(0xFFFF);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ActionChainWithConds::ActionChainWithConds() {
|
||||
this->clear();
|
||||
}
|
||||
@@ -495,24 +481,22 @@ bool ActionChainWithConds::unknown_8024DEC4() const {
|
||||
return this->check_flag(4) ? false : (this->chain.target_card_ref_count != 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ActionMetadata::ActionMetadata() {
|
||||
this->clear();
|
||||
}
|
||||
|
||||
bool ActionMetadata::operator==(const ActionMetadata& other) const {
|
||||
return (this->card_ref == other.card_ref) &&
|
||||
(this->target_card_ref_count == other.target_card_ref_count) &&
|
||||
(this->defense_card_ref_count == other.defense_card_ref_count) &&
|
||||
(this->action_subphase == other.action_subphase) &&
|
||||
(this->defense_power == other.defense_power) &&
|
||||
(this->defense_bonus == other.defense_bonus) &&
|
||||
(this->attack_bonus == other.attack_bonus) &&
|
||||
(this->flags == other.flags) &&
|
||||
(this->target_card_refs == other.target_card_refs) &&
|
||||
(this->defense_card_refs == other.defense_card_refs) &&
|
||||
(this->original_attacker_card_refs == other.original_attacker_card_refs);
|
||||
(this->target_card_ref_count == other.target_card_ref_count) &&
|
||||
(this->defense_card_ref_count == other.defense_card_ref_count) &&
|
||||
(this->action_subphase == other.action_subphase) &&
|
||||
(this->defense_power == other.defense_power) &&
|
||||
(this->defense_bonus == other.defense_bonus) &&
|
||||
(this->attack_bonus == other.attack_bonus) &&
|
||||
(this->flags == other.flags) &&
|
||||
(this->target_card_refs == other.target_card_refs) &&
|
||||
(this->defense_card_refs == other.defense_card_refs) &&
|
||||
(this->original_attacker_card_refs == other.original_attacker_card_refs);
|
||||
}
|
||||
bool ActionMetadata::operator!=(const ActionMetadata& other) const {
|
||||
return !this->operator==(other);
|
||||
@@ -524,9 +508,9 @@ std::string ActionMetadata::str() const {
|
||||
string original_attacker_card_refs_s = string_for_refs(this->original_attacker_card_refs);
|
||||
return string_printf(
|
||||
"ActionMetadata[ref=@%04hX, target_ref_count=%hhu, def_ref_count=%hhu, "
|
||||
"subphase=%s, def_power=%hhd, def_bonus=%hhd, "
|
||||
"att_bonus=%hhd, flags=%08" PRIX32 ", target_refs=%s, "
|
||||
"defense_refs=%s, original_attacker_refs=%s]",
|
||||
"subphase=%s, def_power=%hhd, def_bonus=%hhd, "
|
||||
"att_bonus=%hhd, flags=%08" PRIX32 ", target_refs=%s, "
|
||||
"defense_refs=%s, original_attacker_refs=%s]",
|
||||
this->card_ref.load(),
|
||||
this->target_card_ref_count,
|
||||
this->defense_card_ref_count,
|
||||
@@ -610,8 +594,6 @@ void ActionMetadata::add_defense_card_ref(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
HandAndEquipState::HandAndEquipState() {
|
||||
this->clear();
|
||||
}
|
||||
@@ -623,13 +605,13 @@ std::string HandAndEquipState::str() const {
|
||||
string set_card_refs2_s = string_for_refs(this->set_card_refs2);
|
||||
return string_printf(
|
||||
"HandAndEquipState[dice=[%hhu, %hhu], atk=%hhu, def=%hhu, atk2=%hhu, "
|
||||
"a1=%hhu, total_set_cost=%hhu, is_cpu=%hhu, "
|
||||
"assist_flags=%08" PRIX32 ", hand_refs=%s, "
|
||||
"assist_ref=@%04hX, set_refs=%s, sc_ref=@%04hX, "
|
||||
"hand_refs2=%s, set_refs2=%s, assist_ref2=@%04hX, "
|
||||
"assist_set_num=%hu, assist_card_id=%04hX, "
|
||||
"assist_turns=%hhu, assit_dely=%hhu, atk_bonus=%hhu, "
|
||||
"def_bonus=%hhu, u2=[%hhu, %hhu]]",
|
||||
"a1=%hhu, total_set_cost=%hhu, is_cpu=%hhu, "
|
||||
"assist_flags=%08" PRIX32 ", hand_refs=%s, "
|
||||
"assist_ref=@%04hX, set_refs=%s, sc_ref=@%04hX, "
|
||||
"hand_refs2=%s, set_refs2=%s, assist_ref2=@%04hX, "
|
||||
"assist_set_num=%hu, assist_card_id=%04hX, "
|
||||
"assist_turns=%hhu, assit_dely=%hhu, atk_bonus=%hhu, "
|
||||
"def_bonus=%hhu, u2=[%hhu, %hhu]]",
|
||||
this->dice_results[0],
|
||||
this->dice_results[1],
|
||||
this->atk_points,
|
||||
@@ -706,13 +688,11 @@ void HandAndEquipState::clear_FF() {
|
||||
this->unused2.clear(0xFF);
|
||||
}
|
||||
|
||||
|
||||
|
||||
PlayerStats::PlayerStats() {
|
||||
PlayerBattleStats::PlayerBattleStats() {
|
||||
this->clear();
|
||||
}
|
||||
|
||||
void PlayerStats::clear() {
|
||||
void PlayerBattleStats::clear() {
|
||||
this->damage_given = 0;
|
||||
this->damage_taken = 0;
|
||||
this->num_opponent_cards_destroyed = 0;
|
||||
@@ -735,7 +715,7 @@ void PlayerStats::clear() {
|
||||
this->unused = 0;
|
||||
}
|
||||
|
||||
float PlayerStats::score(size_t num_rounds) const {
|
||||
float PlayerBattleStats::score(size_t num_rounds) const {
|
||||
// Note: This formula doesn't match the formula on PSO-World, which is:
|
||||
// 35
|
||||
// + (Attack Damage - Damage Taken)
|
||||
@@ -747,19 +727,14 @@ float PlayerStats::score(size_t num_rounds) const {
|
||||
// Ep3 PsoV3.dol, so it's presumably correct. Is the PSO-World formula simply
|
||||
// incorrect, or is it from e.g. the Japanese version, which may have a
|
||||
// different rank calculation function?
|
||||
return 38.0f
|
||||
+ 0.8f * this->action_card_negated_damage
|
||||
- 2.3f * num_rounds
|
||||
- 1.8f * this->sc_damage_taken
|
||||
+ 3.0f * this->max_attack_combo_size
|
||||
+ (this->damage_given - this->damage_taken);
|
||||
return 38.0f + 0.8f * this->action_card_negated_damage - 2.3f * num_rounds - 1.8f * this->sc_damage_taken + 3.0f * this->max_attack_combo_size + (this->damage_given - this->damage_taken);
|
||||
}
|
||||
|
||||
uint8_t PlayerStats::rank(size_t num_rounds) const {
|
||||
uint8_t PlayerBattleStats::rank(size_t num_rounds) const {
|
||||
return this->rank_for_score(this->score(num_rounds));
|
||||
}
|
||||
|
||||
const char* PlayerStats::rank_name(size_t num_rounds) const {
|
||||
const char* PlayerBattleStats::rank_name(size_t num_rounds) const {
|
||||
return this->name_for_rank(this->rank_for_score(this->score(num_rounds)));
|
||||
}
|
||||
|
||||
@@ -767,9 +742,9 @@ constexpr size_t RANK_THRESHOLD_COUNT = 9;
|
||||
static const float RANK_THRESHOLDS[RANK_THRESHOLD_COUNT] = {
|
||||
15.0f, 25.0f, 30.0f, 40.0f, 50.0f, 60.0f, 65.0f, 75.0f, 85.0f};
|
||||
static const char* RANK_NAMES[RANK_THRESHOLD_COUNT + 1] = {
|
||||
"E", "D", "D+", "C", "C+", "B", "B+", "A", "A+", "S"};
|
||||
"E", "D", "D+", "C", "C+", "B", "B+", "A", "A+", "S"};
|
||||
|
||||
uint8_t PlayerStats::rank_for_score(float score) {
|
||||
uint8_t PlayerBattleStats::rank_for_score(float score) {
|
||||
size_t rank = 0;
|
||||
while (rank < RANK_THRESHOLD_COUNT && RANK_THRESHOLDS[rank] <= score) {
|
||||
rank++;
|
||||
@@ -777,16 +752,13 @@ uint8_t PlayerStats::rank_for_score(float score) {
|
||||
return rank;
|
||||
}
|
||||
|
||||
const char* PlayerStats::name_for_rank(uint8_t rank) {
|
||||
const char* PlayerBattleStats::name_for_rank(uint8_t rank) {
|
||||
if (rank >= RANK_THRESHOLD_COUNT + 1) {
|
||||
throw invalid_argument("invalid rank");
|
||||
}
|
||||
return RANK_NAMES[rank];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool is_card_within_range(
|
||||
const parray<uint8_t, 9 * 9>& range,
|
||||
const Location& anchor_loc,
|
||||
@@ -824,6 +796,4 @@ vector<uint16_t> get_card_refs_within_range(
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
@@ -5,12 +5,10 @@
|
||||
#include <memory>
|
||||
|
||||
#include "../Text.hh"
|
||||
#include "DataIndex.hh"
|
||||
#include "DataIndexes.hh"
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
class ServerBase;
|
||||
class Server;
|
||||
class Card;
|
||||
@@ -236,7 +234,7 @@ struct HandAndEquipState {
|
||||
std::string str() const;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct PlayerStats {
|
||||
struct PlayerBattleStats {
|
||||
le_uint16_t damage_given;
|
||||
le_uint16_t damage_taken;
|
||||
le_uint16_t num_opponent_cards_destroyed;
|
||||
@@ -258,7 +256,7 @@ struct PlayerStats {
|
||||
le_uint16_t action_card_negated_damage;
|
||||
le_uint16_t unused;
|
||||
|
||||
PlayerStats();
|
||||
PlayerBattleStats();
|
||||
void clear();
|
||||
|
||||
float score(size_t num_rounds) const;
|
||||
@@ -269,13 +267,9 @@ struct PlayerStats {
|
||||
static const char* name_for_rank(uint8_t rank);
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
|
||||
std::vector<uint16_t> get_card_refs_within_range(
|
||||
const parray<uint8_t, 9 * 9>& range,
|
||||
const Location& loc,
|
||||
const parray<CardShortStatus, 0x10>& short_statuses);
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
+232
-238
@@ -6,11 +6,9 @@ using namespace std;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
void compute_effective_range(
|
||||
parray<uint8_t, 9 * 9>& ret,
|
||||
shared_ptr<const DataIndex> data_index,
|
||||
shared_ptr<const CardIndex> card_index,
|
||||
uint16_t card_id,
|
||||
const Location& loc,
|
||||
shared_ptr<const MapAndRulesState> map_and_rules) {
|
||||
@@ -21,9 +19,9 @@ void compute_effective_range(
|
||||
// Heavy Fog: one tile directly in front
|
||||
range_def[3] = 0x00000100;
|
||||
} else {
|
||||
shared_ptr<const DataIndex::CardEntry> ce;
|
||||
shared_ptr<const CardIndex::CardEntry> ce;
|
||||
try {
|
||||
ce = data_index->definition_for_card_id(card_id);
|
||||
ce = card_index->definition_for_id(card_id);
|
||||
} catch (const out_of_range&) {
|
||||
return;
|
||||
}
|
||||
@@ -128,9 +126,9 @@ void compute_effective_range(
|
||||
}
|
||||
|
||||
bool card_linkage_is_valid(
|
||||
shared_ptr<const DataIndex::CardEntry> right_ce,
|
||||
shared_ptr<const DataIndex::CardEntry> left_ce,
|
||||
shared_ptr<const DataIndex::CardEntry> sc_ce,
|
||||
shared_ptr<const CardIndex::CardEntry> right_ce,
|
||||
shared_ptr<const CardIndex::CardEntry> left_ce,
|
||||
shared_ptr<const CardIndex::CardEntry> sc_ce,
|
||||
bool has_permission_effect) {
|
||||
if (!right_ce) {
|
||||
return false;
|
||||
@@ -189,14 +187,12 @@ bool card_linkage_is_valid(
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RulerServer::RulerServer(shared_ptr<Server> server)
|
||||
: w_server(server),
|
||||
team_id_for_client_id(0xFF),
|
||||
error_code1(0),
|
||||
error_code2(0),
|
||||
error_code3(0) { }
|
||||
: w_server(server),
|
||||
team_id_for_client_id(0xFF),
|
||||
error_code1(0),
|
||||
error_code2(0),
|
||||
error_code3(0) {}
|
||||
|
||||
shared_ptr<Server> RulerServer::server() {
|
||||
auto s = this->w_server.lock();
|
||||
@@ -318,11 +314,11 @@ bool RulerServer::attack_action_has_rampage_and_not_pierce(
|
||||
auto attack_medium = this->get_attack_medium(pa);
|
||||
|
||||
if (!this->compute_effective_range_and_target_mode_for_attack(
|
||||
pa, &effective_range_card_id, &effective_target_mode, &orig_card_ref)) {
|
||||
pa, &effective_range_card_id, &effective_target_mode, &orig_card_ref)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((orig_card_ref != 0xFFFF) && (orig_card_ref != pa.attacker_card_ref) &&
|
||||
if ((orig_card_ref != 0xFFFF) && (orig_card_ref != pa.attacker_card_ref) &&
|
||||
!this->check_usability_or_apply_condition_for_card_refs(
|
||||
orig_card_ref, pa.attacker_card_ref, card_ref, 0xFF, AttackMedium::INVALID_FF)) {
|
||||
return false;
|
||||
@@ -341,7 +337,7 @@ bool RulerServer::attack_action_has_rampage_and_not_pierce(
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (; cond_index >= 0; cond_index--) {
|
||||
for (cond_index--; cond_index >= 0; cond_index--) {
|
||||
bool has_rampage = this->check_pierce_and_rampage(
|
||||
card_ref,
|
||||
ce->def.effects[cond_index].type,
|
||||
@@ -426,9 +422,9 @@ bool RulerServer::attack_action_has_pierce_and_not_rampage(
|
||||
for (; last_cond_index >= 0; last_cond_index--) {
|
||||
bool has_rampage = false;
|
||||
if (this->card_has_pierce_or_rampage(
|
||||
client_id, ce->def.effects[last_cond_index].type, &has_rampage,
|
||||
pa.attacker_card_ref, pa.action_card_refs[last_action_card_index],
|
||||
last_cond_index, attack_medium)) {
|
||||
client_id, ce->def.effects[last_cond_index].type, &has_rampage,
|
||||
pa.attacker_card_ref, pa.action_card_refs[last_action_card_index],
|
||||
last_cond_index, attack_medium)) {
|
||||
return true;
|
||||
}
|
||||
if (has_rampage) {
|
||||
@@ -442,10 +438,10 @@ bool RulerServer::attack_action_has_pierce_and_not_rampage(
|
||||
for (ssize_t cond_index = 8; cond_index >= 0; cond_index--) {
|
||||
bool has_rampage = false;
|
||||
if (this->card_has_pierce_or_rampage(
|
||||
client_id, chain->conditions[cond_index].type, &has_rampage,
|
||||
pa.attacker_card_ref, chain->conditions[cond_index].card_ref,
|
||||
chain->conditions[cond_index].card_definition_effect_index,
|
||||
attack_medium)) {
|
||||
client_id, chain->conditions[cond_index].type, &has_rampage,
|
||||
pa.attacker_card_ref, chain->conditions[cond_index].card_ref,
|
||||
chain->conditions[cond_index].card_definition_effect_index,
|
||||
attack_medium)) {
|
||||
return true;
|
||||
}
|
||||
if (has_rampage) {
|
||||
@@ -457,7 +453,6 @@ bool RulerServer::attack_action_has_pierce_and_not_rampage(
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool RulerServer::card_exists_by_status(const CardShortStatus& stat) const {
|
||||
if ((stat.card_flags & 3) || (stat.card_ref == 0xFFFF)) {
|
||||
return false;
|
||||
@@ -494,10 +489,10 @@ bool RulerServer::card_id_is_boss_sc(uint16_t card_id) {
|
||||
|
||||
bool RulerServer::card_id_is_support_tech_or_support_pb(uint16_t card_id) {
|
||||
return (card_id == 0x00E1) ||
|
||||
(card_id == 0x00E2) ||
|
||||
(card_id == 0x00E6) ||
|
||||
(card_id == 0x00EB) ||
|
||||
(card_id == 0x00EC);
|
||||
(card_id == 0x00E2) ||
|
||||
(card_id == 0x00E6) ||
|
||||
(card_id == 0x00EB) ||
|
||||
(card_id == 0x00EC);
|
||||
}
|
||||
|
||||
bool RulerServer::card_ref_can_attack(uint16_t card_ref) {
|
||||
@@ -537,11 +532,11 @@ bool RulerServer::card_ref_can_attack(uint16_t card_ref) {
|
||||
// then the item also cannot attack
|
||||
if ((ce->def.type == CardType::ITEM) &&
|
||||
(!this->short_statuses[client_id] ||
|
||||
(this->short_statuses[client_id]->at(0).card_ref == 0xFFFF) ||
|
||||
this->find_condition_on_card_ref(this->short_statuses[client_id]->at(0).card_ref, ConditionType::HOLD) ||
|
||||
this->find_condition_on_card_ref(this->short_statuses[client_id]->at(0).card_ref, ConditionType::GUOM) ||
|
||||
this->find_condition_on_card_ref(this->short_statuses[client_id]->at(0).card_ref, ConditionType::PARALYZE) ||
|
||||
this->find_condition_on_card_ref(this->short_statuses[client_id]->at(0).card_ref, ConditionType::FREEZE))) {
|
||||
(this->short_statuses[client_id]->at(0).card_ref == 0xFFFF) ||
|
||||
this->find_condition_on_card_ref(this->short_statuses[client_id]->at(0).card_ref, ConditionType::HOLD) ||
|
||||
this->find_condition_on_card_ref(this->short_statuses[client_id]->at(0).card_ref, ConditionType::GUOM) ||
|
||||
this->find_condition_on_card_ref(this->short_statuses[client_id]->at(0).card_ref, ConditionType::PARALYZE) ||
|
||||
this->find_condition_on_card_ref(this->short_statuses[client_id]->at(0).card_ref, ConditionType::FREEZE))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -589,7 +584,7 @@ bool RulerServer::card_ref_can_move(
|
||||
const auto& item_stat = short_statuses->at(z);
|
||||
if ((item_stat.card_ref != 0xFFFF) && this->card_exists_by_status(item_stat) &&
|
||||
(this->find_condition_on_card_ref(item_stat.card_ref, ConditionType::GUOM) ||
|
||||
this->find_condition_on_card_ref(item_stat.card_ref, ConditionType::IMMOBILE))) {
|
||||
this->find_condition_on_card_ref(item_stat.card_ref, ConditionType::IMMOBILE))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -951,11 +946,11 @@ bool RulerServer::check_usability_or_condition_apply(
|
||||
// positioning/team setup
|
||||
if (is_item_usability_check &&
|
||||
((criterion_code == CriterionCode::SAME_TEAM) ||
|
||||
(criterion_code == CriterionCode::SAME_PLAYER) ||
|
||||
(criterion_code == CriterionCode::SAME_TEAM_NOT_SAME_PLAYER) ||
|
||||
(criterion_code == CriterionCode::UNKNOWN_07) ||
|
||||
(criterion_code == CriterionCode::NOT_SC) ||
|
||||
(criterion_code == CriterionCode::SC))) {
|
||||
(criterion_code == CriterionCode::SAME_PLAYER) ||
|
||||
(criterion_code == CriterionCode::SAME_TEAM_NOT_SAME_PLAYER) ||
|
||||
(criterion_code == CriterionCode::UNKNOWN_07) ||
|
||||
(criterion_code == CriterionCode::NOT_SC) ||
|
||||
(criterion_code == CriterionCode::SC))) {
|
||||
criterion_code = CriterionCode::NONE;
|
||||
}
|
||||
|
||||
@@ -988,7 +983,7 @@ bool RulerServer::check_usability_or_condition_apply(
|
||||
case CriterionCode::SAME_TEAM:
|
||||
if ((client_id1 == client_id2) ||
|
||||
((client_id1 != 0xFF) && (client_id2 != 0xFF) &&
|
||||
(this->team_id_for_client_id[client_id1] == this->team_id_for_client_id[client_id2]))) {
|
||||
(this->team_id_for_client_id[client_id1] == this->team_id_for_client_id[client_id2]))) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -1026,255 +1021,255 @@ bool RulerServer::check_usability_or_condition_apply(
|
||||
break;
|
||||
case CriterionCode::HUNTER_HUMAN_SC: {
|
||||
static const unordered_set<uint16_t> card_ids = {
|
||||
0x0001, // Orland
|
||||
0x0002, // Kranz
|
||||
0x0003, // Ino'lis
|
||||
0x0004, // Sil'fer
|
||||
0x0006, // Kylria
|
||||
0x0111, // Relmitos
|
||||
0x0112, // Viviana
|
||||
0x0115, // Glustar
|
||||
0x02AA, // H-HUmar
|
||||
0x02AB, // H-HUnewearl
|
||||
0x02AE, // H-RAmar
|
||||
0x02AF, // H-RAmarl
|
||||
0x02B2, // H-FOmar
|
||||
0x02B3, // H-FOmarl
|
||||
0x02B4, // H-FOnewm
|
||||
0x02B5, // H-FOnewearl
|
||||
0x02CC, // H-HUmar
|
||||
0x02CD, // H-RAmarl
|
||||
0x02CE, // H-FOmarl
|
||||
0x02CF, // H-HUnewearl
|
||||
0x02D1, // H-RAmarl
|
||||
0x02D5, // H-FOmar
|
||||
0x02D6, // H-FOnewearl
|
||||
0x02D9, // H-FOnewm
|
||||
0x0001, // Orland
|
||||
0x0002, // Kranz
|
||||
0x0003, // Ino'lis
|
||||
0x0004, // Sil'fer
|
||||
0x0006, // Kylria
|
||||
0x0111, // Relmitos
|
||||
0x0112, // Viviana
|
||||
0x0115, // Glustar
|
||||
0x02AA, // H-HUmar
|
||||
0x02AB, // H-HUnewearl
|
||||
0x02AE, // H-RAmar
|
||||
0x02AF, // H-RAmarl
|
||||
0x02B2, // H-FOmar
|
||||
0x02B3, // H-FOmarl
|
||||
0x02B4, // H-FOnewm
|
||||
0x02B5, // H-FOnewearl
|
||||
0x02CC, // H-HUmar
|
||||
0x02CD, // H-RAmarl
|
||||
0x02CE, // H-FOmarl
|
||||
0x02CF, // H-HUnewearl
|
||||
0x02D1, // H-RAmarl
|
||||
0x02D5, // H-FOmar
|
||||
0x02D6, // H-FOnewearl
|
||||
0x02D9, // H-FOnewm
|
||||
};
|
||||
return ret && card_ids.count(card_id2);
|
||||
}
|
||||
case CriterionCode::HUNTER_HU_CLASS_MALE_SC: {
|
||||
static const unordered_set<uint16_t> card_ids = {
|
||||
0x0001, // Orland
|
||||
0x0113, // Teifu
|
||||
0x02AA, // H-HUmar
|
||||
0x02AC, // H-HUcast
|
||||
0x02CC, // H-HUmar
|
||||
0x02D7, // H-HUcast
|
||||
0x0001, // Orland
|
||||
0x0113, // Teifu
|
||||
0x02AA, // H-HUmar
|
||||
0x02AC, // H-HUcast
|
||||
0x02CC, // H-HUmar
|
||||
0x02D7, // H-HUcast
|
||||
};
|
||||
return ret && card_ids.count(card_id2);
|
||||
}
|
||||
case CriterionCode::HUNTER_FEMALE_SC: {
|
||||
static const unordered_set<uint16_t> card_ids = {
|
||||
0x0003, // Ino'lis
|
||||
0x0004, // Sil'fer
|
||||
0x0006, // Kylria
|
||||
0x0110, // Saligun
|
||||
0x0112, // Viviana
|
||||
0x0114, // Stella
|
||||
0x02AB, // H-HUnewearl
|
||||
0x02AD, // H-HUcaseal
|
||||
0x02AF, // H-RAmarl
|
||||
0x02B1, // H-RAcaseal
|
||||
0x02B3, // H-FOmarl
|
||||
0x02B5, // H-FOnewearl
|
||||
0x02CE, // H-FOmarl
|
||||
0x02CF, // H-HUnewearl
|
||||
0x02D1, // H-RAmarl
|
||||
0x02D4, // H-HUcaseal
|
||||
0x02D6, // H-FOnewearl
|
||||
0x02D8, // H-RAcaseal
|
||||
0x0003, // Ino'lis
|
||||
0x0004, // Sil'fer
|
||||
0x0006, // Kylria
|
||||
0x0110, // Saligun
|
||||
0x0112, // Viviana
|
||||
0x0114, // Stella
|
||||
0x02AB, // H-HUnewearl
|
||||
0x02AD, // H-HUcaseal
|
||||
0x02AF, // H-RAmarl
|
||||
0x02B1, // H-RAcaseal
|
||||
0x02B3, // H-FOmarl
|
||||
0x02B5, // H-FOnewearl
|
||||
0x02CE, // H-FOmarl
|
||||
0x02CF, // H-HUnewearl
|
||||
0x02D1, // H-RAmarl
|
||||
0x02D4, // H-HUcaseal
|
||||
0x02D6, // H-FOnewearl
|
||||
0x02D8, // H-RAcaseal
|
||||
};
|
||||
return ret && card_ids.count(card_id2);
|
||||
}
|
||||
case CriterionCode::HUNTER_HU_OR_FO_CLASS_HUMAN_SC: {
|
||||
static const unordered_set<uint16_t> card_ids = {
|
||||
0x0001, // Orland
|
||||
0x0003, // Ino'lis
|
||||
0x0004, // Sil'fer
|
||||
0x0111, // Relmitos
|
||||
0x0115, // Glustar
|
||||
0x0112, // Viviana
|
||||
0x02AA, // H-HUmar
|
||||
0x02AB, // H-HUnewearl
|
||||
0x02B2, // H-FOmar
|
||||
0x02B3, // H-FOmarl
|
||||
0x02B4, // H-FOnewm
|
||||
0x02B5, // H-FOnewearl
|
||||
0x02CC, // H-HUmar
|
||||
0x02CE, // H-FOmarl
|
||||
0x02CF, // H-HUnewearl
|
||||
0x02D5, // H-FOmar
|
||||
0x02D6, // H-FOnewearl
|
||||
0x02D9, // H-FOnewm
|
||||
0x0001, // Orland
|
||||
0x0003, // Ino'lis
|
||||
0x0004, // Sil'fer
|
||||
0x0111, // Relmitos
|
||||
0x0115, // Glustar
|
||||
0x0112, // Viviana
|
||||
0x02AA, // H-HUmar
|
||||
0x02AB, // H-HUnewearl
|
||||
0x02B2, // H-FOmar
|
||||
0x02B3, // H-FOmarl
|
||||
0x02B4, // H-FOnewm
|
||||
0x02B5, // H-FOnewearl
|
||||
0x02CC, // H-HUmar
|
||||
0x02CE, // H-FOmarl
|
||||
0x02CF, // H-HUnewearl
|
||||
0x02D5, // H-FOmar
|
||||
0x02D6, // H-FOnewearl
|
||||
0x02D9, // H-FOnewm
|
||||
};
|
||||
return ret && card_ids.count(card_id2);
|
||||
}
|
||||
case CriterionCode::HUNTER_HU_CLASS_ANDROID_SC: {
|
||||
static const unordered_set<uint16_t> card_ids = {
|
||||
0x0110, // Saligun
|
||||
0x0113, // Teifu
|
||||
0x02AC, // H-HUcast
|
||||
0x02AD, // H-HUcaseal
|
||||
0x02D4, // H-HUcaseal
|
||||
0x02D7, // H-HUcast
|
||||
0x0110, // Saligun
|
||||
0x0113, // Teifu
|
||||
0x02AC, // H-HUcast
|
||||
0x02AD, // H-HUcaseal
|
||||
0x02D4, // H-HUcaseal
|
||||
0x02D7, // H-HUcast
|
||||
};
|
||||
return ret && card_ids.count(card_id2);
|
||||
}
|
||||
case CriterionCode::UNKNOWN_10: {
|
||||
static const unordered_set<uint16_t> card_ids = {
|
||||
0x0001, // Orland
|
||||
0x0003, // Ino'lis
|
||||
0x0110, // Saligun
|
||||
0x0111, // Relmitos
|
||||
0x0113, // Teifu
|
||||
0x02AA, // H-HUmar
|
||||
0x02AC, // H-HUcast
|
||||
0x02AD, // H-HUcaseal
|
||||
0x02B2, // H-FOmar
|
||||
0x02B3, // H-FOmarl
|
||||
0x02CC, // H-HUmar
|
||||
0x02CE, // H-FOmarl
|
||||
0x02D4, // H-HUcaseal
|
||||
0x02D5, // H-FOmar
|
||||
0x02D7, // H-HUcast
|
||||
0x0001, // Orland
|
||||
0x0003, // Ino'lis
|
||||
0x0110, // Saligun
|
||||
0x0111, // Relmitos
|
||||
0x0113, // Teifu
|
||||
0x02AA, // H-HUmar
|
||||
0x02AC, // H-HUcast
|
||||
0x02AD, // H-HUcaseal
|
||||
0x02B2, // H-FOmar
|
||||
0x02B3, // H-FOmarl
|
||||
0x02CC, // H-HUmar
|
||||
0x02CE, // H-FOmarl
|
||||
0x02D4, // H-HUcaseal
|
||||
0x02D5, // H-FOmar
|
||||
0x02D7, // H-HUcast
|
||||
};
|
||||
return ret && card_ids.count(card_id2);
|
||||
}
|
||||
case CriterionCode::UNKNOWN_11: {
|
||||
static const unordered_set<uint16_t> card_ids = {
|
||||
0x0001, // Orland
|
||||
0x0002, // Kranz
|
||||
0x0005, // Guykild
|
||||
0x0113, // Teifu
|
||||
0x02AA, // H-HUmar
|
||||
0x02AC, // H-HUcast
|
||||
0x02AE, // H-RAmar
|
||||
0x02B0, // H-RAcast
|
||||
0x02CC, // H-HUmar
|
||||
0x02CD, // H-RAmarl
|
||||
0x02D0, // H-RAcast
|
||||
0x02D7, // H-HUcast
|
||||
0x0001, // Orland
|
||||
0x0002, // Kranz
|
||||
0x0005, // Guykild
|
||||
0x0113, // Teifu
|
||||
0x02AA, // H-HUmar
|
||||
0x02AC, // H-HUcast
|
||||
0x02AE, // H-RAmar
|
||||
0x02B0, // H-RAcast
|
||||
0x02CC, // H-HUmar
|
||||
0x02CD, // H-RAmarl
|
||||
0x02D0, // H-RAcast
|
||||
0x02D7, // H-HUcast
|
||||
};
|
||||
return ret && card_ids.count(card_id2);
|
||||
}
|
||||
case CriterionCode::HUNTER_HUNEWEARL_CLASS_SC: {
|
||||
static const unordered_set<uint16_t> card_ids = {
|
||||
0x0004, // Sil'fer
|
||||
0x02AB, // H-HUnewearl
|
||||
0x02CF, // H-HUnewearl
|
||||
0x0004, // Sil'fer
|
||||
0x02AB, // H-HUnewearl
|
||||
0x02CF, // H-HUnewearl
|
||||
};
|
||||
return ret && card_ids.count(card_id2);
|
||||
}
|
||||
case CriterionCode::HUNTER_RA_CLASS_MALE_SC: {
|
||||
static const unordered_set<uint16_t> card_ids = {
|
||||
0x0002, // Kranz
|
||||
0x0005, // Guykild
|
||||
0x02AE, // H-RAmar
|
||||
0x02B0, // H-RAcast
|
||||
0x02CD, // H-RAmarl
|
||||
0x02D0, // H-RAcast
|
||||
0x0002, // Kranz
|
||||
0x0005, // Guykild
|
||||
0x02AE, // H-RAmar
|
||||
0x02B0, // H-RAcast
|
||||
0x02CD, // H-RAmarl
|
||||
0x02D0, // H-RAcast
|
||||
};
|
||||
return ret && card_ids.count(card_id2);
|
||||
}
|
||||
case CriterionCode::HUNTER_RA_CLASS_FEMALE_SC: {
|
||||
static const unordered_set<uint16_t> card_ids = {
|
||||
0x0006, // Kylria
|
||||
0x0114, // Stella
|
||||
0x02AF, // H-RAmarl
|
||||
0x02B1, // H-RAcaseal
|
||||
0x02D1, // H-RAmarl
|
||||
0x02D2, // D-RAcaseal
|
||||
0x0006, // Kylria
|
||||
0x0114, // Stella
|
||||
0x02AF, // H-RAmarl
|
||||
0x02B1, // H-RAcaseal
|
||||
0x02D1, // H-RAmarl
|
||||
0x02D2, // D-RAcaseal
|
||||
};
|
||||
return ret && card_ids.count(card_id2);
|
||||
}
|
||||
case CriterionCode::HUNTER_RA_OR_FO_CLASS_FEMALE_SC: {
|
||||
static const unordered_set<uint16_t> card_ids = {
|
||||
0x0003, // Ino'lis
|
||||
0x0006, // Kylria
|
||||
0x0112, // Viviana
|
||||
0x0114, // Stella
|
||||
0x02AF, // H-RAmarl
|
||||
0x02B1, // H-RAcaseal
|
||||
0x02B3, // H-FOmarl
|
||||
0x02B5, // H-FOnewearl
|
||||
0x02CE, // H-FOmarl
|
||||
0x02D1, // H-RAmarl
|
||||
0x02D6, // H-FOnewearl
|
||||
0x02D8, // H-RAcaseal
|
||||
0x0003, // Ino'lis
|
||||
0x0006, // Kylria
|
||||
0x0112, // Viviana
|
||||
0x0114, // Stella
|
||||
0x02AF, // H-RAmarl
|
||||
0x02B1, // H-RAcaseal
|
||||
0x02B3, // H-FOmarl
|
||||
0x02B5, // H-FOnewearl
|
||||
0x02CE, // H-FOmarl
|
||||
0x02D1, // H-RAmarl
|
||||
0x02D6, // H-FOnewearl
|
||||
0x02D8, // H-RAcaseal
|
||||
};
|
||||
return ret && card_ids.count(card_id2);
|
||||
}
|
||||
case CriterionCode::HUNTER_HU_OR_RA_CLASS_HUMAN_SC: {
|
||||
static const unordered_set<uint16_t> card_ids = {
|
||||
0x0001, // Orland
|
||||
0x0002, // Kranz
|
||||
0x0004, // Sil'fer
|
||||
0x0006, // Kylria
|
||||
0x02AA, // H-HUmar
|
||||
0x02AB, // H-HUnewearl
|
||||
0x02AE, // H-RAmar
|
||||
0x02AF, // H-RAmarl
|
||||
0x02CC, // H-HUmar
|
||||
0x02CD, // H-RAmarl
|
||||
0x02CF, // H-HUnewearl
|
||||
0x02D1, // H-RAmarl
|
||||
0x0001, // Orland
|
||||
0x0002, // Kranz
|
||||
0x0004, // Sil'fer
|
||||
0x0006, // Kylria
|
||||
0x02AA, // H-HUmar
|
||||
0x02AB, // H-HUnewearl
|
||||
0x02AE, // H-RAmar
|
||||
0x02AF, // H-RAmarl
|
||||
0x02CC, // H-HUmar
|
||||
0x02CD, // H-RAmarl
|
||||
0x02CF, // H-HUnewearl
|
||||
0x02D1, // H-RAmarl
|
||||
};
|
||||
return ret && card_ids.count(card_id2);
|
||||
}
|
||||
case CriterionCode::HUNTER_RA_CLASS_ANDROID_SC: {
|
||||
static const unordered_set<uint16_t> card_ids = {
|
||||
0x0005, // Guykild
|
||||
0x0114, // Stella
|
||||
0x02B0, // H-RAcast
|
||||
0x02B1, // H-RAcaseal
|
||||
0x02D0, // H-RAcast
|
||||
0x02D8, // H-RAcaseal
|
||||
0x0005, // Guykild
|
||||
0x0114, // Stella
|
||||
0x02B0, // H-RAcast
|
||||
0x02B1, // H-RAcaseal
|
||||
0x02D0, // H-RAcast
|
||||
0x02D8, // H-RAcaseal
|
||||
};
|
||||
return ret && card_ids.count(card_id2);
|
||||
}
|
||||
case CriterionCode::HUNTER_FO_CLASS_FEMALE_SC: {
|
||||
static const unordered_set<uint16_t> card_ids = {
|
||||
0x0003, // Ino'lis
|
||||
0x0112, // Viviana
|
||||
0x02B3, // H-FOmarl
|
||||
0x02B5, // H-FOnewearl
|
||||
0x02CE, // H-FOmarl
|
||||
0x02D6, // H-FOnewearl
|
||||
0x0003, // Ino'lis
|
||||
0x0112, // Viviana
|
||||
0x02B3, // H-FOmarl
|
||||
0x02B5, // H-FOnewearl
|
||||
0x02CE, // H-FOmarl
|
||||
0x02D6, // H-FOnewearl
|
||||
};
|
||||
return ret && card_ids.count(card_id2);
|
||||
}
|
||||
case CriterionCode::HUNTER_FEMALE_HUMAN_SC: {
|
||||
static const unordered_set<uint16_t> card_ids = {
|
||||
0x0003, // Ino'lis
|
||||
0x0004, // Sil'fer
|
||||
0x0006, // Kylria
|
||||
0x0112, // Viviana
|
||||
0x02AB, // H-HUnewearl
|
||||
0x02AF, // H-RAmarl
|
||||
0x02B3, // H-FOmarl
|
||||
0x02B5, // H-FOnewearl
|
||||
0x02CE, // H-FOmarl
|
||||
0x02CF, // H-HUnewearl
|
||||
0x02D1, // H-RAmarl
|
||||
0x02D6, // H-FOnewearl
|
||||
0x0003, // Ino'lis
|
||||
0x0004, // Sil'fer
|
||||
0x0006, // Kylria
|
||||
0x0112, // Viviana
|
||||
0x02AB, // H-HUnewearl
|
||||
0x02AF, // H-RAmarl
|
||||
0x02B3, // H-FOmarl
|
||||
0x02B5, // H-FOnewearl
|
||||
0x02CE, // H-FOmarl
|
||||
0x02CF, // H-HUnewearl
|
||||
0x02D1, // H-RAmarl
|
||||
0x02D6, // H-FOnewearl
|
||||
};
|
||||
return ret && card_ids.count(card_id2);
|
||||
}
|
||||
case CriterionCode::HUNTER_ANDROID_SC: {
|
||||
static const unordered_set<uint16_t> card_ids = {
|
||||
0x0005, // Guykild
|
||||
0x0110, // Saligun
|
||||
0x0113, // Teifu
|
||||
0x0114, // Stella
|
||||
0x02AC, // H-HUcast
|
||||
0x02AD, // H-HUcaseal
|
||||
0x02B0, // H-RAcast
|
||||
0x02B1, // H-RAcaseal
|
||||
0x02D0, // H-RAcast
|
||||
0x02D4, // H-HUcaseal
|
||||
0x02D7, // H-HUcast
|
||||
0x02D8, // H-RAcaseal
|
||||
0x0005, // Guykild
|
||||
0x0110, // Saligun
|
||||
0x0113, // Teifu
|
||||
0x0114, // Stella
|
||||
0x02AC, // H-HUcast
|
||||
0x02AD, // H-HUcaseal
|
||||
0x02B0, // H-RAcast
|
||||
0x02B1, // H-RAcaseal
|
||||
0x02D0, // H-RAcast
|
||||
0x02D4, // H-HUcaseal
|
||||
0x02D7, // H-HUcast
|
||||
0x02D8, // H-RAcaseal
|
||||
};
|
||||
return ret && card_ids.count(card_id2);
|
||||
}
|
||||
@@ -1368,7 +1363,7 @@ uint16_t RulerServer::compute_attack_or_defense_costs(
|
||||
|
||||
if (((action_type == ActionType::ATTACK) || (action_type == ActionType::INVALID_00)) &&
|
||||
(this->find_condition_on_card_ref(pa.attacker_card_ref, ConditionType::BIG_SWING) ||
|
||||
this->find_condition_on_card_ref(sc_card_ref_if_item, ConditionType::BIG_SWING))) {
|
||||
this->find_condition_on_card_ref(sc_card_ref_if_item, ConditionType::BIG_SWING))) {
|
||||
cost_bias++;
|
||||
}
|
||||
|
||||
@@ -1435,7 +1430,8 @@ bool RulerServer::compute_effective_range_and_target_mode_for_attack(
|
||||
TargetMode* out_effective_target_mode,
|
||||
uint16_t* out_orig_card_ref) const {
|
||||
size_t z;
|
||||
for (z = 0; (z < 9) && (pa.action_card_refs[z] != 0xFFFF); z++) { }
|
||||
for (z = 0; (z < 9) && (pa.action_card_refs[z] != 0xFFFF); z++) {
|
||||
}
|
||||
if (z >= 9) {
|
||||
return false;
|
||||
}
|
||||
@@ -1617,7 +1613,7 @@ bool RulerServer::defense_card_matches_any_attack_card_top_color(
|
||||
return false;
|
||||
}
|
||||
|
||||
shared_ptr<const DataIndex::CardEntry> RulerServer::definition_for_card_ref(uint16_t card_ref) const {
|
||||
shared_ptr<const CardIndex::CardEntry> RulerServer::definition_for_card_ref(uint16_t card_ref) const {
|
||||
uint16_t card_id = this->card_id_for_card_ref(card_ref);
|
||||
if (card_id == 0xFFFF) {
|
||||
return nullptr;
|
||||
@@ -1705,7 +1701,7 @@ int32_t RulerServer::error_code_for_client_setting_card(
|
||||
if ((short_statuses->at(0).card_ref == 0xFFFF) ||
|
||||
!this->card_exists_by_status(short_statuses->at(0)) ||
|
||||
!this->check_usability_or_apply_condition_for_card_refs(
|
||||
card_ref, short_statuses->at(0).card_ref, 0xFFFF, 0xFF, AttackMedium::INVALID_FF)) {
|
||||
card_ref, short_statuses->at(0).card_ref, 0xFFFF, 0xFF, AttackMedium::INVALID_FF)) {
|
||||
return -0x75;
|
||||
}
|
||||
|
||||
@@ -1764,7 +1760,7 @@ int32_t RulerServer::error_code_for_client_setting_card(
|
||||
Location summon_area_loc;
|
||||
uint8_t summon_area_size;
|
||||
if (!this->get_creature_summon_area(
|
||||
client_id, &summon_area_loc, &summon_area_size)) {
|
||||
client_id, &summon_area_loc, &summon_area_size)) {
|
||||
if (team_id != 1) {
|
||||
if ((loc->x > 0) && (loc->x < this->map_and_rules->map.width - 1)) {
|
||||
if ((loc->y < this->map_and_rules->map.height - summon_cost - 1) &&
|
||||
@@ -1976,15 +1972,15 @@ uint16_t RulerServer::get_ally_sc_card_ref(uint16_t card_ref) const {
|
||||
return 0xFFFF;
|
||||
}
|
||||
|
||||
shared_ptr<const DataIndex::CardEntry> RulerServer::definition_for_card_id(
|
||||
uint32_t card_id) const {
|
||||
shared_ptr<const CardIndex::CardEntry> RulerServer::definition_for_card_id(uint32_t card_id) const {
|
||||
return this->server()->definition_for_card_id(card_id);
|
||||
}
|
||||
|
||||
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_id = (card_id_override == 0xFFFF)
|
||||
? this->card_id_for_card_ref(card_ref) : card_id_override;
|
||||
? this->card_id_for_card_ref(card_ref)
|
||||
: card_id_override;
|
||||
|
||||
if (card_id != 0xFFFF) {
|
||||
auto ce = this->definition_for_card_id(card_id);
|
||||
@@ -2102,7 +2098,7 @@ bool RulerServer::get_move_path_length_and_cost(
|
||||
parray<uint8_t, 0x100> visited_map;
|
||||
path.end_loc = loc;
|
||||
if (!this->check_move_path_and_get_cost(
|
||||
client_id, card_ref, &visited_map, &path, out_cost)) {
|
||||
client_id, card_ref, &visited_map, &path, out_cost)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2189,9 +2185,9 @@ bool RulerServer::is_attack_valid(const ActionState& pa) {
|
||||
(attacker_chain->chain.acting_card_ref != attacker_card_ref) ||
|
||||
!attacker_ce ||
|
||||
((attacker_ce->def.type != CardType::HUNTERS_SC &&
|
||||
(attacker_ce->def.type != CardType::ARKZ_SC) &&
|
||||
(attacker_ce->def.type != CardType::CREATURE) &&
|
||||
(attacker_ce->def.type != CardType::ITEM)))) {
|
||||
(attacker_ce->def.type != CardType::ARKZ_SC) &&
|
||||
(attacker_ce->def.type != CardType::CREATURE) &&
|
||||
(attacker_ce->def.type != CardType::ITEM)))) {
|
||||
this->error_code3 = -0x6F;
|
||||
return false;
|
||||
}
|
||||
@@ -2247,7 +2243,7 @@ bool RulerServer::is_attack_valid(const ActionState& pa) {
|
||||
}
|
||||
|
||||
if (!this->check_usability_or_apply_condition_for_card_refs(
|
||||
right_card_ref, attacker_card_ref, 0xFFFF, 0xFF, AttackMedium::INVALID_FF)) {
|
||||
right_card_ref, attacker_card_ref, 0xFFFF, 0xFF, AttackMedium::INVALID_FF)) {
|
||||
this->error_code3 = -0x6A;
|
||||
return false;
|
||||
}
|
||||
@@ -2377,7 +2373,7 @@ bool RulerServer::is_defense_valid(const ActionState& pa) {
|
||||
}
|
||||
|
||||
if (!this->defense_card_can_apply_to_attack(
|
||||
pa.action_card_refs[0], pa.target_card_refs[0], pa.original_attacker_card_ref)) {
|
||||
pa.action_card_refs[0], pa.target_card_refs[0], pa.original_attacker_card_ref)) {
|
||||
this->error_code3 = -0x61;
|
||||
return false;
|
||||
}
|
||||
@@ -2447,10 +2443,10 @@ size_t RulerServer::max_move_distance_for_card_ref(uint32_t card_ref) const {
|
||||
}
|
||||
|
||||
RulerServer::MovePath::MovePath()
|
||||
: length(-1),
|
||||
remaining_distance(0),
|
||||
num_occupied_tiles(0),
|
||||
cost(0) { }
|
||||
: length(-1),
|
||||
remaining_distance(0),
|
||||
num_occupied_tiles(0),
|
||||
cost(0) {}
|
||||
|
||||
void RulerServer::MovePath::add_step(const Location& loc) {
|
||||
this->step_locs[++this->length] = loc;
|
||||
@@ -2617,8 +2613,8 @@ const CardShortStatus* RulerServer::short_status_for_card_ref(uint16_t card_ref)
|
||||
|
||||
bool RulerServer::should_allow_attacks_on_current_turn() const {
|
||||
return (this->state_flags &&
|
||||
((this->state_flags->turn_num > 1) ||
|
||||
(this->state_flags->current_team_turn1 != this->state_flags->first_team_turn)));
|
||||
((this->state_flags->turn_num > 1) ||
|
||||
(this->state_flags->current_team_turn1 != this->state_flags->first_team_turn)));
|
||||
}
|
||||
|
||||
int32_t RulerServer::verify_deck(
|
||||
@@ -2676,6 +2672,4 @@ int32_t RulerServer::verify_deck(
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
@@ -4,28 +4,26 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "DataIndex.hh"
|
||||
#include "PlayerState.hh"
|
||||
#include "DeckState.hh"
|
||||
#include "AssistServer.hh"
|
||||
#include "DataIndexes.hh"
|
||||
#include "DeckState.hh"
|
||||
#include "PlayerState.hh"
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
class Server;
|
||||
|
||||
void compute_effective_range(
|
||||
parray<uint8_t, 9 * 9>& ret,
|
||||
std::shared_ptr<const DataIndex> data_index,
|
||||
std::shared_ptr<const CardIndex> card_index,
|
||||
uint16_t card_id,
|
||||
const Location& loc,
|
||||
std::shared_ptr<const MapAndRulesState> map_and_rules);
|
||||
|
||||
bool card_linkage_is_valid(
|
||||
std::shared_ptr<const DataIndex::CardEntry> right_def,
|
||||
std::shared_ptr<const DataIndex::CardEntry> left_def,
|
||||
std::shared_ptr<const DataIndex::CardEntry> sc_def,
|
||||
std::shared_ptr<const CardIndex::CardEntry> right_def,
|
||||
std::shared_ptr<const CardIndex::CardEntry> left_def,
|
||||
std::shared_ptr<const CardIndex::CardEntry> sc_def,
|
||||
bool has_permission_effect);
|
||||
|
||||
class RulerServer {
|
||||
@@ -132,7 +130,7 @@ public:
|
||||
uint16_t attacker_sc_card_ref) const;
|
||||
bool defense_card_matches_any_attack_card_top_color(
|
||||
const ActionState& pa) const;
|
||||
std::shared_ptr<const DataIndex::CardEntry> definition_for_card_ref(uint16_t card_ref) const;
|
||||
std::shared_ptr<const CardIndex::CardEntry> definition_for_card_ref(uint16_t card_ref) const;
|
||||
int32_t error_code_for_client_setting_card(
|
||||
uint8_t client_id,
|
||||
uint16_t card_ref,
|
||||
@@ -158,7 +156,7 @@ public:
|
||||
size_t num_occupied_tiles,
|
||||
size_t num_vacant_tiles) const;
|
||||
uint16_t get_ally_sc_card_ref(uint16_t card_ref) const;
|
||||
std::shared_ptr<const DataIndex::CardEntry> definition_for_card_id(
|
||||
std::shared_ptr<const CardIndex::CardEntry> definition_for_card_id(
|
||||
uint32_t card_id) const;
|
||||
uint32_t get_card_id_with_effective_range(
|
||||
uint16_t card_ref, uint16_t card_id_override, TargetMode* out_target_mode) const;
|
||||
@@ -227,6 +225,4 @@ public:
|
||||
int32_t error_code3;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
+132
-131
@@ -1,7 +1,7 @@
|
||||
#include "Server.hh"
|
||||
|
||||
#include <phosg/Time.hh>
|
||||
#include <phosg/Random.hh>
|
||||
#include <phosg/Time.hh>
|
||||
|
||||
#include "../SendCommands.hh"
|
||||
|
||||
@@ -9,15 +9,11 @@ using namespace std;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
// These strings in the original implementation did not contain the semicolons
|
||||
// (or anything after them).
|
||||
// This is (obviously) not the original string. The original string is:
|
||||
// "[V1][FINAL2.0] 03/09/13 15:30 by K.Toya"
|
||||
static const char* VERSION_SIGNATURE =
|
||||
"newserv Ep3 based on [V1][FINAL2.0] 03/09/13 15:30 by K.Toya";
|
||||
|
||||
|
||||
|
||||
ServerBase::PresenceEntry::PresenceEntry() {
|
||||
this->clear();
|
||||
}
|
||||
@@ -28,19 +24,21 @@ void ServerBase::PresenceEntry::clear() {
|
||||
this->is_cpu_player = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ServerBase::ServerBase(
|
||||
shared_ptr<Lobby> lobby,
|
||||
shared_ptr<const DataIndex> data_index,
|
||||
uint32_t random_seed,
|
||||
shared_ptr<const DataIndex::MapEntry> map_if_tournament)
|
||||
: lobby(lobby),
|
||||
data_index(data_index),
|
||||
log(lobby->log.prefix + "[Ep3::Server] "),
|
||||
random_seed(random_seed),
|
||||
is_tournament(!!map_if_tournament),
|
||||
last_chosen_map(map_if_tournament) { }
|
||||
shared_ptr<const CardIndex> card_index,
|
||||
shared_ptr<const MapIndex> map_index,
|
||||
uint32_t behavior_flags,
|
||||
shared_ptr<PSOLFGEncryption> random_crypt,
|
||||
shared_ptr<const MapIndex::MapEntry> map_if_tournament)
|
||||
: lobby(lobby),
|
||||
card_index(card_index),
|
||||
map_index(map_index),
|
||||
behavior_flags(behavior_flags),
|
||||
log(lobby->log.prefix + "[Ep3::Server] "),
|
||||
random_crypt(random_crypt),
|
||||
is_tournament(!!map_if_tournament),
|
||||
last_chosen_map(map_if_tournament) {}
|
||||
|
||||
void ServerBase::init() {
|
||||
this->reset();
|
||||
@@ -65,53 +63,57 @@ void ServerBase::recreate_server() {
|
||||
this->server->init();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Server::Server(shared_ptr<ServerBase> base)
|
||||
: w_base(base),
|
||||
battle_finished(false),
|
||||
battle_in_progress(false),
|
||||
round_num(1),
|
||||
battle_phase(BattlePhase::INVALID_00),
|
||||
first_team_turn(0xFF),
|
||||
current_team_turn1(0xFF),
|
||||
setup_phase(SetupPhase::REGISTRATION),
|
||||
registration_phase(RegistrationPhase::AWAITING_NUM_PLAYERS),
|
||||
action_subphase(ActionSubphase::ATTACK),
|
||||
current_team_turn2(0xFF),
|
||||
num_pending_attacks(0),
|
||||
client_done_enqueuing_attacks(false),
|
||||
player_ready_to_end_phase(false),
|
||||
unknown_a10(0),
|
||||
overall_time_expired(false),
|
||||
battle_start_usecs(0),
|
||||
should_copy_prev_states_to_current_states(0),
|
||||
card_special(nullptr),
|
||||
clients_done_in_mulligan_phase(false),
|
||||
num_pending_attacks_with_cards(0),
|
||||
unknown_a14(0),
|
||||
unknown_a15(0),
|
||||
defense_list_ended_for_client(false),
|
||||
next_assist_card_set_number(1),
|
||||
team_exp(0),
|
||||
team_dice_boost(0),
|
||||
team_client_count(0),
|
||||
team_num_ally_fcs_destroyed(0),
|
||||
team_num_cards_destroyed(0),
|
||||
hard_reset_flag(false),
|
||||
tournament_flag(base->is_tournament ? 1 : 0),
|
||||
num_trap_tiles_of_type(0),
|
||||
chosen_trap_tile_index_of_type(0),
|
||||
has_done_pb(0),
|
||||
num_6xB4x06_commands_sent(0),
|
||||
prev_num_6xB4x06_commands_sent(0) { }
|
||||
: w_base(base),
|
||||
tournament_match_result_sent(false),
|
||||
override_environment_number(0xFF),
|
||||
battle_finished(false),
|
||||
battle_in_progress(false),
|
||||
round_num(1),
|
||||
battle_phase(BattlePhase::INVALID_00),
|
||||
first_team_turn(0xFF),
|
||||
current_team_turn1(0xFF),
|
||||
setup_phase(SetupPhase::REGISTRATION),
|
||||
registration_phase(RegistrationPhase::AWAITING_NUM_PLAYERS),
|
||||
action_subphase(ActionSubphase::ATTACK),
|
||||
current_team_turn2(0xFF),
|
||||
num_pending_attacks(0),
|
||||
client_done_enqueuing_attacks(false),
|
||||
player_ready_to_end_phase(false),
|
||||
random_crypt(base->random_crypt),
|
||||
unknown_a10(0),
|
||||
overall_time_expired(false),
|
||||
battle_start_usecs(0),
|
||||
should_copy_prev_states_to_current_states(0),
|
||||
card_special(nullptr),
|
||||
clients_done_in_mulligan_phase(false),
|
||||
num_pending_attacks_with_cards(0),
|
||||
unknown_a14(0),
|
||||
unknown_a15(0),
|
||||
defense_list_ended_for_client(false),
|
||||
next_assist_card_set_number(1),
|
||||
team_exp(0),
|
||||
team_dice_boost(0),
|
||||
team_client_count(0),
|
||||
team_num_ally_fcs_destroyed(0),
|
||||
team_num_cards_destroyed(0),
|
||||
hard_reset_flag(false),
|
||||
tournament_flag(base->is_tournament ? 1 : 0),
|
||||
num_trap_tiles_of_type(0),
|
||||
chosen_trap_tile_index_of_type(0),
|
||||
has_done_pb(0),
|
||||
num_6xB4x06_commands_sent(0),
|
||||
prev_num_6xB4x06_commands_sent(0) {}
|
||||
|
||||
void Server::init() {
|
||||
this->card_special.reset(new CardSpecial(this->shared_from_this()));
|
||||
|
||||
// The default PSOV2Encryption constructor in the original implementation just
|
||||
// uses 0 as the seed. We'll replace this object later when the battle starts.
|
||||
this->random_crypt.reset(new PSOV2Encryption(0));
|
||||
// Note: The original implementation calls the default PSOV2Encryption
|
||||
// constructor for random_crypt, which just uses 0 as the seed. It then
|
||||
// re-seeds the generator later. We instead expect the caller to provide a
|
||||
// seeded generator, and we don't re-seed it at all.
|
||||
// this->random_crypt.reset(new PSOV2Encryption(0));
|
||||
|
||||
this->state_flags.reset(new StateFlags());
|
||||
|
||||
this->clear_player_flags_after_dice_phase();
|
||||
@@ -185,7 +187,7 @@ void Server::send(const void* data, size_t size) const {
|
||||
}
|
||||
|
||||
string masked_data;
|
||||
if (!(this->base()->data_index->behavior_flags & BehaviorFlag::DISABLE_MASKING)) {
|
||||
if (!(this->base()->behavior_flags & BehaviorFlag::DISABLE_MASKING)) {
|
||||
if (size >= 8) {
|
||||
masked_data.assign(reinterpret_cast<const char*>(data), size);
|
||||
uint8_t mask_key = (random_object<uint32_t>() % 0xFF) + 1;
|
||||
@@ -219,24 +221,23 @@ void Server::send_6xB4x46() const {
|
||||
|
||||
G_ServerVersionStrings_GC_Ep3_6xB4x46 cmd46;
|
||||
cmd46.version_signature = VERSION_SIGNATURE;
|
||||
cmd46.date_str1 = format_time(this->base()->data_index->card_definitions_mtime() * 1000000);
|
||||
cmd46.date_str2 = string_printf("Lobby/%08" PRIX32 " random %08" PRIX32,
|
||||
l->lobby_id, l->random_seed);
|
||||
cmd46.date_str1 = format_time(this->base()->card_index->definitions_mtime() * 1000000);
|
||||
cmd46.date_str2 = string_printf("Lobby/%08" PRIX32, l->lobby_id);
|
||||
this->send(cmd46);
|
||||
}
|
||||
|
||||
string Server::prepare_6xB6x41_map_definition(
|
||||
shared_ptr<const DataIndex::MapEntry> map) {
|
||||
const auto& compressed = map->compressed();
|
||||
shared_ptr<const MapIndex::MapEntry> map, bool is_trial) {
|
||||
const auto& compressed = map->compressed(is_trial);
|
||||
|
||||
StringWriter w;
|
||||
uint32_t subcommand_size = (compressed.size() + sizeof(G_MapData_GC_Ep3_6xB6x41) + 3) & (~3);
|
||||
w.put<G_MapData_GC_Ep3_6xB6x41>({{{{0xB6, 0, 0}, subcommand_size}, 0x41, {}}, map->map.map_number.load(), compressed.size(), 0});
|
||||
w.write(compressed);
|
||||
return move(w.str());
|
||||
return std::move(w.str());
|
||||
}
|
||||
|
||||
void Server::send_commands_for_joining_spectator(Channel& c) const {
|
||||
void Server::send_commands_for_joining_spectator(Channel& c, bool is_trial) const {
|
||||
bool should_send_state = true;
|
||||
if (this->setup_phase == SetupPhase::REGISTRATION) {
|
||||
// If registration is still in progress, we only need to send the map data
|
||||
@@ -249,7 +250,7 @@ void Server::send_commands_for_joining_spectator(Channel& c) const {
|
||||
|
||||
auto map = this->base()->last_chosen_map;
|
||||
if (map) {
|
||||
string data = this->prepare_6xB6x41_map_definition(map);
|
||||
string data = this->prepare_6xB6x41_map_definition(map, is_trial);
|
||||
c.send(0x6C, 0x00, data);
|
||||
}
|
||||
|
||||
@@ -262,10 +263,9 @@ void Server::send_commands_for_joining_spectator(Channel& c) const {
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((format(printf, 2, 3)))
|
||||
void Server::log_debug(const char* fmt, ...) const {
|
||||
__attribute__((format(printf, 2, 3))) void Server::log_debug(const char* fmt, ...) const {
|
||||
auto l = this->base()->lobby.lock();
|
||||
if (l && (this->base()->data_index->behavior_flags & Episode3::BehaviorFlag::ENABLE_STATUS_MESSAGES)) {
|
||||
if (l && (this->base()->behavior_flags & Episode3::BehaviorFlag::ENABLE_STATUS_MESSAGES)) {
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
this->base()->log.info_v(fmt, va);
|
||||
@@ -273,10 +273,9 @@ void Server::log_debug(const char* fmt, ...) const {
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((format(printf, 2, 3)))
|
||||
void Server::send_debug_message_printf(const char* fmt, ...) const {
|
||||
__attribute__((format(printf, 2, 3))) void Server::send_debug_message_printf(const char* fmt, ...) const {
|
||||
auto l = this->base()->lobby.lock();
|
||||
if (l && (this->base()->data_index->behavior_flags & Episode3::BehaviorFlag::ENABLE_STATUS_MESSAGES)) {
|
||||
if (l && (this->base()->behavior_flags & Episode3::BehaviorFlag::ENABLE_STATUS_MESSAGES)) {
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
std::string buf = string_vprintf(fmt, va);
|
||||
@@ -286,8 +285,7 @@ void Server::send_debug_message_printf(const char* fmt, ...) const {
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((format(printf, 2, 3)))
|
||||
void Server::send_info_message_printf(const char* fmt, ...) const {
|
||||
__attribute__((format(printf, 2, 3))) void Server::send_info_message_printf(const char* fmt, ...) const {
|
||||
auto l = this->base()->lobby.lock();
|
||||
if (l) {
|
||||
va_list va;
|
||||
@@ -374,10 +372,9 @@ void Server::draw_phase_before() {
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr<const DataIndex::CardEntry> Server::definition_for_card_ref(uint16_t card_ref) const {
|
||||
shared_ptr<const CardIndex::CardEntry> Server::definition_for_card_ref(uint16_t card_ref) const {
|
||||
try {
|
||||
return this->base()->data_index->definition_for_card_id(
|
||||
this->card_id_for_card_ref(card_ref));
|
||||
return this->base()->card_index->definition_for_id(this->card_id_for_card_ref(card_ref));
|
||||
} catch (const out_of_range&) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -539,7 +536,8 @@ void Server::check_for_destroyed_cards_and_send_6xB4x05_6xB4x02() {
|
||||
|
||||
bool Server::check_presence_entry(uint8_t client_id) const {
|
||||
return (client_id < 4)
|
||||
? this->base()->presence_entries[client_id].player_present : false;
|
||||
? this->base()->presence_entries[client_id].player_present
|
||||
: false;
|
||||
}
|
||||
|
||||
void Server::clear_player_flags_after_dice_phase() {
|
||||
@@ -587,9 +585,9 @@ void Server::copy_player_states_to_prev_states() {
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr<const DataIndex::CardEntry> Server::definition_for_card_id(uint16_t card_id) const {
|
||||
shared_ptr<const CardIndex::CardEntry> Server::definition_for_card_id(uint16_t card_id) const {
|
||||
try {
|
||||
return this->base()->data_index->definition_for_card_id(card_id);
|
||||
return this->base()->card_index->definition_for_id(card_id);
|
||||
} catch (const out_of_range&) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -972,12 +970,14 @@ void Server::move_phase_after() {
|
||||
(abs(sc_card->loc.y - trap_y) < 2) &&
|
||||
ps->replace_assist_card_by_id(trap_card_id)) {
|
||||
G_Unknown_GC_Ep3_6xB4x2C cmd;
|
||||
cmd.client_id = client_id;
|
||||
cmd.change_type = 0x01;
|
||||
cmd.loc.direction = static_cast<Direction>(trap_type);
|
||||
cmd.client_id = client_id;
|
||||
cmd.card_refs.clear(0xFFFF);
|
||||
cmd.loc.x = trap_x;
|
||||
cmd.loc.y = trap_y;
|
||||
cmd.loc.direction = static_cast<Direction>(trap_type);
|
||||
cmd.unknown_a2[0] = trap_card_id;
|
||||
cmd.unknown_a2[1] = 0xFFFFFFFF;
|
||||
this->send(cmd);
|
||||
}
|
||||
}
|
||||
@@ -1180,8 +1180,8 @@ void Server::set_client_id_ready_to_advance_phase(uint8_t client_id) {
|
||||
// TODO: It'd be nice to do this in a constant-randomness way, but I'm
|
||||
// lazy, and this matches Sega's original implementation. The less-lazy
|
||||
// way to do it would be to roll three dice: one in the range [1, N],
|
||||
// one in the range [3, N], and on in the range [1, 2] to decide whether
|
||||
// to swap the first two results.
|
||||
// one in the range [3, N], and one in the range [1, 2] to decide
|
||||
// whether to swap the first two results.
|
||||
for (size_t z = 0; z < 200; z++) {
|
||||
ps->roll_main_dice();
|
||||
if ((ps->get_atk_points() >= 3) || (ps->get_def_points() >= 3)) {
|
||||
@@ -1220,7 +1220,6 @@ void Server::set_client_id_ready_to_advance_phase(uint8_t client_id) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Server::set_phase_after() {
|
||||
for (size_t client_id = 0; client_id < 4; client_id++) {
|
||||
auto ps = this->player_states[client_id];
|
||||
@@ -1312,9 +1311,9 @@ void Server::set_player_deck_valid(uint8_t client_id) {
|
||||
|
||||
void Server::setup_and_start_battle() {
|
||||
this->setup_phase = SetupPhase::STARTER_ROLLS;
|
||||
// Note: The original implementation uses time() as the random seed; we use a
|
||||
// user-settable value in order to support replays and deterministic testing
|
||||
this->random_crypt.reset(new PSOV2Encryption(this->base()->random_seed));
|
||||
|
||||
// Note: This is where original implementation re-seeds random_crypt (it uses
|
||||
// time() as the seed value).
|
||||
|
||||
for (size_t z = 0; z < 4; z++) {
|
||||
if (!this->check_presence_entry(z)) {
|
||||
@@ -1513,34 +1512,33 @@ bool Server::update_registration_phase() {
|
||||
}
|
||||
|
||||
const unordered_map<uint8_t, Server::handler_t> Server::subcommand_handlers({
|
||||
{0x0B, &Server::handle_6xB3x0B_mulligan_hand},
|
||||
{0x0C, &Server::handle_6xB3x0C_end_mulligan_phase},
|
||||
{0x0D, &Server::handle_6xB3x0D_end_non_action_phase},
|
||||
{0x0E, &Server::handle_6xB3x0E_discard_card_from_hand},
|
||||
{0x0F, &Server::handle_6xB3x0F_set_card_from_hand},
|
||||
{0x10, &Server::handle_6xB3x10_move_fc_to_location},
|
||||
{0x11, &Server::handle_6xB3x11_enqueue_attack_or_defense},
|
||||
{0x12, &Server::handle_6xB3x12_end_attack_list},
|
||||
{0x13, &Server::handle_6xB3x13_update_map_during_setup},
|
||||
{0x14, &Server::handle_6xB3x14_update_deck_during_setup},
|
||||
{0x15, &Server::handle_6xB3x15_unused_hard_reset_server_state},
|
||||
{0x1B, &Server::handle_6xB3x1B_update_player_name},
|
||||
{0x1D, &Server::handle_6xB3x1D_start_battle},
|
||||
{0x21, &Server::handle_6xB3x21_end_battle},
|
||||
{0x28, &Server::handle_6xB3x28_end_defense_list},
|
||||
{0x2B, &Server::handle_6xB3x2B_ignored},
|
||||
{0x34, &Server::handle_6xB3x34_subtract_ally_atk_points},
|
||||
{0x37, &Server::handle_6xB3x37_client_ready_to_advance_from_starter_roll_phase},
|
||||
{0x3A, &Server::handle_6xB3x3A_ignored},
|
||||
{0x40, &Server::handle_6xB3x40_map_list_request},
|
||||
{0x41, &Server::handle_6xB3x41_map_request},
|
||||
{0x48, &Server::handle_6xB3x48_end_turn},
|
||||
{0x49, &Server::handle_6xB3x49_card_counts},
|
||||
{0x0B, &Server::handle_6xB3x0B_mulligan_hand},
|
||||
{0x0C, &Server::handle_6xB3x0C_end_mulligan_phase},
|
||||
{0x0D, &Server::handle_6xB3x0D_end_non_action_phase},
|
||||
{0x0E, &Server::handle_6xB3x0E_discard_card_from_hand},
|
||||
{0x0F, &Server::handle_6xB3x0F_set_card_from_hand},
|
||||
{0x10, &Server::handle_6xB3x10_move_fc_to_location},
|
||||
{0x11, &Server::handle_6xB3x11_enqueue_attack_or_defense},
|
||||
{0x12, &Server::handle_6xB3x12_end_attack_list},
|
||||
{0x13, &Server::handle_6xB3x13_update_map_during_setup},
|
||||
{0x14, &Server::handle_6xB3x14_update_deck_during_setup},
|
||||
{0x15, &Server::handle_6xB3x15_unused_hard_reset_server_state},
|
||||
{0x1B, &Server::handle_6xB3x1B_update_player_name},
|
||||
{0x1D, &Server::handle_6xB3x1D_start_battle},
|
||||
{0x21, &Server::handle_6xB3x21_end_battle},
|
||||
{0x28, &Server::handle_6xB3x28_end_defense_list},
|
||||
{0x2B, &Server::handle_6xB3x2B_ignored},
|
||||
{0x34, &Server::handle_6xB3x34_subtract_ally_atk_points},
|
||||
{0x37, &Server::handle_6xB3x37_client_ready_to_advance_from_starter_roll_phase},
|
||||
{0x3A, &Server::handle_6xB3x3A_ignored},
|
||||
{0x40, &Server::handle_6xB3x40_map_list_request},
|
||||
{0x41, &Server::handle_6xB3x41_map_request},
|
||||
{0x48, &Server::handle_6xB3x48_end_turn},
|
||||
{0x49, &Server::handle_6xB3x49_card_counts},
|
||||
});
|
||||
|
||||
void Server::on_server_data_input(const string& data) {
|
||||
auto header = check_size_t<G_CardBattleCommandHeader>(
|
||||
data, sizeof(G_CardBattleCommandHeader), 0xFFFF);
|
||||
auto header = check_size_t<G_CardBattleCommandHeader>(data, 0xFFFF);
|
||||
if (header.size * 4 < data.size()) {
|
||||
throw runtime_error("command is incomplete");
|
||||
}
|
||||
@@ -1846,8 +1844,13 @@ void Server::handle_6xB3x13_update_map_during_setup(const string& data) {
|
||||
(this->registration_phase != RegistrationPhase::BATTLE_STARTED)) {
|
||||
*b->map_and_rules1 = in_cmd.map_and_rules_state;
|
||||
*b->map_and_rules2 = in_cmd.map_and_rules_state;
|
||||
if (this->override_environment_number != 0xFF) {
|
||||
b->map_and_rules1->environment_number = this->override_environment_number;
|
||||
b->map_and_rules2->environment_number = this->override_environment_number;
|
||||
this->override_environment_number = 0xFF;
|
||||
}
|
||||
b->overlay_state = in_cmd.overlay_state;
|
||||
if (b->data_index->behavior_flags & BehaviorFlag::DISABLE_TIME_LIMITS) {
|
||||
if (b->behavior_flags & BehaviorFlag::DISABLE_TIME_LIMITS) {
|
||||
b->map_and_rules1->rules.overall_time_limit = 0;
|
||||
b->map_and_rules1->rules.phase_time_limit = 0;
|
||||
b->map_and_rules2->rules.overall_time_limit = 0;
|
||||
@@ -1877,9 +1880,9 @@ void Server::handle_6xB3x14_update_deck_during_setup(const string& data) {
|
||||
}
|
||||
DeckEntry entry = in_cmd.entry;
|
||||
int32_t verify_error = 0;
|
||||
if (!(this->base()->data_index->behavior_flags & BehaviorFlag::SKIP_DECK_VERIFY)) {
|
||||
if (!(this->base()->behavior_flags & BehaviorFlag::SKIP_DECK_VERIFY)) {
|
||||
// Note: Sega's original implementation doesn't use the card counts here
|
||||
if (this->base()->data_index->behavior_flags & BehaviorFlag::IGNORE_CARD_COUNTS) {
|
||||
if (this->base()->behavior_flags & BehaviorFlag::IGNORE_CARD_COUNTS) {
|
||||
verify_error = this->ruler_server->verify_deck(entry.card_ids);
|
||||
} else {
|
||||
verify_error = this->ruler_server->verify_deck(entry.card_ids,
|
||||
@@ -1889,7 +1892,7 @@ void Server::handle_6xB3x14_update_deck_during_setup(const string& data) {
|
||||
if (verify_error) {
|
||||
throw runtime_error(string_printf("invalid deck: -0x%" PRIX32, verify_error));
|
||||
}
|
||||
if (!(this->base()->data_index->behavior_flags & BehaviorFlag::SKIP_D1_D2_REPLACE)) {
|
||||
if (!(this->base()->behavior_flags & BehaviorFlag::SKIP_D1_D2_REPLACE)) {
|
||||
this->ruler_server->replace_D1_D2_rarity_cards_with_Attack(entry.card_ids);
|
||||
}
|
||||
*this->base()->deck_entries[in_cmd.client_id] = in_cmd.entry;
|
||||
@@ -2025,7 +2028,7 @@ void Server::handle_6xB3x28_end_defense_list(const string& data) {
|
||||
this->send(out_cmd_fin);
|
||||
}
|
||||
|
||||
void Server::handle_6xB3x2B_ignored(const string&) { }
|
||||
void Server::handle_6xB3x2B_ignored(const string&) {}
|
||||
|
||||
void Server::handle_6xB3x34_subtract_ally_atk_points(const string& data) {
|
||||
const auto& in_cmd = check_size_t<G_PhotonBlastRequest_GC_Ep3_6xB3x34_CAx34>(data);
|
||||
@@ -2131,7 +2134,7 @@ void Server::handle_6xB3x37_client_ready_to_advance_from_starter_roll_phase(cons
|
||||
}
|
||||
}
|
||||
|
||||
void Server::handle_6xB3x3A_ignored(const string&) { }
|
||||
void Server::handle_6xB3x3A_ignored(const string&) {}
|
||||
|
||||
void Server::handle_6xB3x40_map_list_request(const string& data) {
|
||||
const auto& in_cmd = check_size_t<G_MapListRequest_GC_Ep3_6xB3x40_CAx40>(data);
|
||||
@@ -2143,7 +2146,7 @@ void Server::handle_6xB3x40_map_list_request(const string& data) {
|
||||
throw runtime_error("lobby is deleted");
|
||||
}
|
||||
|
||||
const auto& list_data = this->base()->data_index->get_compressed_map_list();
|
||||
const auto& list_data = this->base()->map_index->get_compressed_list();
|
||||
|
||||
StringWriter w;
|
||||
uint32_t subcommand_size = (list_data.size() + sizeof(G_MapList_GC_Ep3_6xB6x40) + 3) & (~3);
|
||||
@@ -2157,7 +2160,7 @@ void Server::handle_6xB3x40_map_list_request(const string& data) {
|
||||
|
||||
if (l->battle_record && l->battle_record->writable()) {
|
||||
l->battle_record->add_command(
|
||||
BattleRecord::Event::Type::BATTLE_COMMAND, move(w.str()));
|
||||
BattleRecord::Event::Type::BATTLE_COMMAND, std::move(w.str()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2172,8 +2175,9 @@ void Server::handle_6xB3x41_map_request(const string& data) {
|
||||
throw runtime_error("lobby is deleted");
|
||||
}
|
||||
|
||||
base->last_chosen_map = base->data_index->definition_for_map_number(cmd.map_number);
|
||||
auto out_cmd = this->prepare_6xB6x41_map_definition(base->last_chosen_map);
|
||||
base->last_chosen_map = base->map_index->definition_for_number(cmd.map_number);
|
||||
auto out_cmd = this->prepare_6xB6x41_map_definition(
|
||||
base->last_chosen_map, l->flags & Lobby::Flag::IS_EP3_TRIAL);
|
||||
send_command(l, 0x6C, 0x00, out_cmd);
|
||||
for (auto watcher_l : l->watcher_lobbies) {
|
||||
send_command_if_not_loading(watcher_l, 0x6C, 0x00, out_cmd);
|
||||
@@ -2181,7 +2185,7 @@ void Server::handle_6xB3x41_map_request(const string& data) {
|
||||
|
||||
if (l->battle_record && l->battle_record->writable()) {
|
||||
l->battle_record->add_command(
|
||||
BattleRecord::Event::Type::BATTLE_COMMAND, move(out_cmd));
|
||||
BattleRecord::Event::Type::BATTLE_COMMAND, std::move(out_cmd));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2379,7 +2383,7 @@ void Server::unknown_8023EEF4() {
|
||||
if (!this->attack_cards[this->unknown_a14]->action_chain.check_flag(0x40)) {
|
||||
this->card_special->unknown_8024945C(this->attack_cards[this->unknown_a14], as);
|
||||
}
|
||||
this->attack_cards[this->unknown_a14]->compute_action_chain_results(1,0);
|
||||
this->attack_cards[this->unknown_a14]->compute_action_chain_results(1, 0);
|
||||
this->attack_cards[this->unknown_a14]->unknown_80236374(this->attack_cards[this->unknown_a14], &as);
|
||||
if (!this->attack_cards[this->unknown_a14]->action_chain.check_flag(0x40)) {
|
||||
this->card_special->unknown_8024966C(this->attack_cards[this->unknown_a14], &as);
|
||||
@@ -2653,7 +2657,6 @@ void Server::send_6xB4x05() {
|
||||
this->send(cmd);
|
||||
}
|
||||
|
||||
|
||||
void Server::send_6xB4x02_for_all_players_if_needed(bool always_send) {
|
||||
for (size_t z = 0; z < 4; z++) {
|
||||
auto ps = this->player_states[z];
|
||||
@@ -2680,6 +2683,4 @@ void Server::send_6xB4x50_trap_tile_locations() const {
|
||||
this->send(this->prepare_6xB4x50_trap_tile_locations());
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
+27
-28
@@ -4,9 +4,9 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "../Text.hh"
|
||||
#include "../CommandFormats.hh"
|
||||
#include "../Channel.hh"
|
||||
#include "../CommandFormats.hh"
|
||||
#include "../Text.hh"
|
||||
#include "AssistServer.hh"
|
||||
#include "CardSpecial.hh"
|
||||
#include "MapState.hh"
|
||||
@@ -17,17 +17,15 @@ struct Lobby;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This implementation of Episode 3 battles (contained in all files in the
|
||||
* src/Episode3 directory, except for DataIndex.hh/cc) is derived from Sega's
|
||||
* src/Episode3 directory, except for DataIndexes.hh/cc) is derived from Sega's
|
||||
* original server implementation, reverse-engineered from the Episode 3 client
|
||||
* executable. The control flow, function breakdown, and structure definitions
|
||||
* in these files map very closely to how their server implementation was
|
||||
* written; notable differences (due to necessary environment differences or bug
|
||||
* fixes) are described in the comments therein.
|
||||
*
|
||||
*
|
||||
* Some debugging functions have been added which are not part of the original
|
||||
* implementation. Notably, this applies to functions like debug message senders
|
||||
* and loggers and all str() functions.
|
||||
@@ -51,19 +49,19 @@ namespace Episode3 {
|
||||
// - - - - - - - DeckState
|
||||
// - - - - - - - HandAndEquipState
|
||||
// - - - - - - - MapAndRulesState / OverlayState
|
||||
// - - - - - - - - Everything within DataIndex
|
||||
// - - - - - - - - Everything within DataIndexes
|
||||
|
||||
class Server;
|
||||
|
||||
|
||||
|
||||
class ServerBase : public std::enable_shared_from_this<ServerBase> {
|
||||
public:
|
||||
ServerBase(
|
||||
std::shared_ptr<Lobby> lobby,
|
||||
std::shared_ptr<const DataIndex> data_index,
|
||||
uint32_t random_seed,
|
||||
std::shared_ptr<const DataIndex::MapEntry> map_if_tournament);
|
||||
std::shared_ptr<const CardIndex> card_index,
|
||||
std::shared_ptr<const MapIndex> map_index,
|
||||
uint32_t behavior_flags,
|
||||
std::shared_ptr<PSOLFGEncryption> random_crypt,
|
||||
std::shared_ptr<const MapIndex::MapEntry> map_if_tournament);
|
||||
void init();
|
||||
void reset();
|
||||
void recreate_server();
|
||||
@@ -77,11 +75,13 @@ public:
|
||||
} __attribute__((packed));
|
||||
|
||||
std::weak_ptr<Lobby> lobby;
|
||||
std::shared_ptr<const DataIndex> data_index;
|
||||
std::shared_ptr<const CardIndex> card_index;
|
||||
std::shared_ptr<const MapIndex> map_index;
|
||||
uint32_t behavior_flags;
|
||||
PrefixedLogger log;
|
||||
uint32_t random_seed;
|
||||
std::shared_ptr<PSOLFGEncryption> random_crypt;
|
||||
bool is_tournament;
|
||||
std::shared_ptr<const DataIndex::MapEntry> last_chosen_map;
|
||||
std::shared_ptr<const MapIndex::MapEntry> last_chosen_map;
|
||||
|
||||
std::shared_ptr<MapAndRulesState> map_and_rules1;
|
||||
std::shared_ptr<MapAndRulesState> map_and_rules2;
|
||||
@@ -120,15 +120,12 @@ public:
|
||||
}
|
||||
void send(const void* data, size_t size) const;
|
||||
|
||||
void send_commands_for_joining_spectator(Channel& ch) const;
|
||||
void send_commands_for_joining_spectator(Channel& ch, bool is_trial) const;
|
||||
|
||||
__attribute__((format(printf, 2, 3)))
|
||||
void log_debug(const char* fmt, ...) const;
|
||||
__attribute__((format(printf, 2, 3))) void log_debug(const char* fmt, ...) const;
|
||||
|
||||
__attribute__((format(printf, 2, 3)))
|
||||
void send_debug_message_printf(const char* fmt, ...) const;
|
||||
__attribute__((format(printf, 2, 3)))
|
||||
void send_info_message_printf(const char* fmt, ...) const;
|
||||
__attribute__((format(printf, 2, 3))) void send_debug_message_printf(const char* fmt, ...) const;
|
||||
__attribute__((format(printf, 2, 3))) void send_info_message_printf(const char* fmt, ...) const;
|
||||
void send_debug_command_received_message(
|
||||
uint8_t client_id, uint8_t subsubcommand, const char* description) const;
|
||||
void send_debug_command_received_message(
|
||||
@@ -142,7 +139,7 @@ public:
|
||||
bool advance_battle_phase();
|
||||
void action_phase_after();
|
||||
void draw_phase_before();
|
||||
std::shared_ptr<const DataIndex::CardEntry> definition_for_card_ref(uint16_t card_ref) const;
|
||||
std::shared_ptr<const CardIndex::CardEntry> definition_for_card_ref(uint16_t card_ref) const;
|
||||
std::shared_ptr<Card> card_for_set_card_ref(uint16_t card_ref);
|
||||
std::shared_ptr<const Card> card_for_set_card_ref(uint16_t card_ref) const;
|
||||
uint16_t card_id_for_card_ref(uint16_t card_ref) const;
|
||||
@@ -154,7 +151,7 @@ public:
|
||||
void compute_all_map_occupied_bits();
|
||||
void compute_team_dice_boost(uint8_t team_id);
|
||||
void copy_player_states_to_prev_states();
|
||||
std::shared_ptr<const DataIndex::CardEntry> definition_for_card_id(uint16_t card_id) const;
|
||||
std::shared_ptr<const CardIndex::CardEntry> definition_for_card_id(uint16_t card_id) const;
|
||||
void destroy_cards_with_zero_hp();
|
||||
void determine_first_team_turn();
|
||||
void dice_phase_after();
|
||||
@@ -236,11 +233,12 @@ public:
|
||||
G_UpdateDecks_GC_Ep3_6xB4x07 prepare_6xB4x07_decks_update() const;
|
||||
G_SetPlayerNames_GC_Ep3_6xB4x1C prepare_6xB4x1C_names_update() const;
|
||||
static std::string prepare_6xB6x41_map_definition(
|
||||
std::shared_ptr<const DataIndex::MapEntry> map);
|
||||
std::shared_ptr<const MapIndex::MapEntry> map, bool is_trial);
|
||||
G_SetTrapTileLocations_GC_Ep3_6xB4x50 prepare_6xB4x50_trap_tile_locations() const;
|
||||
|
||||
std::vector<std::shared_ptr<Card>> const_cast_set_cards_v(
|
||||
const std::vector<std::shared_ptr<const Card>>& cards);
|
||||
|
||||
private:
|
||||
typedef void (Server::*handler_t)(const std::string&);
|
||||
static const std::unordered_map<uint8_t, handler_t> subcommand_handlers;
|
||||
@@ -248,6 +246,9 @@ private:
|
||||
std::weak_ptr<ServerBase> w_base;
|
||||
|
||||
public:
|
||||
bool tournament_match_result_sent; // Not part of original implementation
|
||||
uint8_t override_environment_number; // Not part of original implementation
|
||||
|
||||
uint32_t battle_finished;
|
||||
uint32_t battle_in_progress;
|
||||
uint32_t round_num;
|
||||
@@ -262,7 +263,7 @@ public:
|
||||
uint32_t num_pending_attacks;
|
||||
parray<uint8_t, 4> client_done_enqueuing_attacks;
|
||||
parray<uint8_t, 4> player_ready_to_end_phase;
|
||||
std::shared_ptr<PSOV2Encryption> random_crypt;
|
||||
std::shared_ptr<PSOLFGEncryption> random_crypt;
|
||||
uint32_t unknown_a10;
|
||||
uint32_t overall_time_expired;
|
||||
// Note: In the original implementation, this is a uint32_t and is measured in
|
||||
@@ -301,6 +302,4 @@ public:
|
||||
mutable uint32_t prev_num_6xB4x06_commands_sent;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
+104
-121
@@ -9,14 +9,14 @@ using namespace std;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
|
||||
|
||||
Tournament::PlayerEntry::PlayerEntry(uint32_t serial_number)
|
||||
: serial_number(serial_number), com_deck() { }
|
||||
: serial_number(serial_number),
|
||||
com_deck() {}
|
||||
|
||||
Tournament::PlayerEntry::PlayerEntry(
|
||||
shared_ptr<const COMDeckDefinition> com_deck)
|
||||
: serial_number(0), com_deck(com_deck) { }
|
||||
: serial_number(0),
|
||||
com_deck(com_deck) {}
|
||||
|
||||
bool Tournament::PlayerEntry::is_com() const {
|
||||
return (this->com_deck != nullptr);
|
||||
@@ -26,17 +26,15 @@ bool Tournament::PlayerEntry::is_human() const {
|
||||
return (this->serial_number != 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Tournament::Team::Team(
|
||||
shared_ptr<Tournament> tournament, size_t index, size_t max_players)
|
||||
: tournament(tournament),
|
||||
index(index),
|
||||
max_players(max_players),
|
||||
name(""),
|
||||
password(""),
|
||||
num_rounds_cleared(0),
|
||||
is_active(true) { }
|
||||
: tournament(tournament),
|
||||
index(index),
|
||||
max_players(max_players),
|
||||
name(""),
|
||||
password(""),
|
||||
num_rounds_cleared(0),
|
||||
is_active(true) {}
|
||||
|
||||
string Tournament::Team::str() const {
|
||||
size_t num_human_players = 0;
|
||||
@@ -133,8 +131,8 @@ bool Tournament::Team::unregister_player(uint32_t serial_number) {
|
||||
}
|
||||
}
|
||||
|
||||
// If the tournament has not started yet, just remove the player from the
|
||||
// team
|
||||
// If the tournament has not started yet, just remove the player from the
|
||||
// team
|
||||
} else {
|
||||
if (!tournament->all_player_serial_numbers.erase(serial_number)) {
|
||||
throw logic_error("player removed from team but not from tournament");
|
||||
@@ -173,17 +171,15 @@ size_t Tournament::Team::num_com_players() const {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Tournament::Match::Match(
|
||||
shared_ptr<Tournament> tournament,
|
||||
shared_ptr<Match> preceding_a,
|
||||
shared_ptr<Match> preceding_b)
|
||||
: tournament(tournament),
|
||||
preceding_a(preceding_a),
|
||||
preceding_b(preceding_b),
|
||||
winner_team(nullptr),
|
||||
round_num(0) {
|
||||
: tournament(tournament),
|
||||
preceding_a(preceding_a),
|
||||
preceding_b(preceding_b),
|
||||
winner_team(nullptr),
|
||||
round_num(0) {
|
||||
if (this->preceding_a->round_num != this->preceding_b->round_num) {
|
||||
throw logic_error("preceding matches have different round numbers");
|
||||
}
|
||||
@@ -193,11 +189,11 @@ Tournament::Match::Match(
|
||||
Tournament::Match::Match(
|
||||
shared_ptr<Tournament> tournament,
|
||||
shared_ptr<Team> winner_team)
|
||||
: tournament(tournament),
|
||||
preceding_a(nullptr),
|
||||
preceding_b(nullptr),
|
||||
winner_team(winner_team),
|
||||
round_num(0) { }
|
||||
: tournament(tournament),
|
||||
preceding_a(nullptr),
|
||||
preceding_b(nullptr),
|
||||
winner_team(winner_team),
|
||||
round_num(0) {}
|
||||
|
||||
string Tournament::Match::str() const {
|
||||
string winner_str = this->winner_team ? this->winner_team->str() : "(none)";
|
||||
@@ -216,7 +212,8 @@ bool Tournament::Match::resolve_if_no_human_players() {
|
||||
!this->preceding_a->winner_team->has_any_human_players() &&
|
||||
!this->preceding_b->winner_team->has_any_human_players()) {
|
||||
this->set_winner_team((random_object<uint8_t>() & 1)
|
||||
? this->preceding_b->winner_team : this->preceding_a->winner_team);
|
||||
? this->preceding_b->winner_team
|
||||
: this->preceding_a->winner_team);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -282,25 +279,25 @@ shared_ptr<Tournament::Team> Tournament::Match::opponent_team_for_team(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Tournament::Tournament(
|
||||
shared_ptr<const DataIndex> data_index,
|
||||
shared_ptr<const MapIndex> map_index,
|
||||
shared_ptr<const COMDeckIndex> com_deck_index,
|
||||
uint8_t number,
|
||||
const string& name,
|
||||
shared_ptr<const DataIndex::MapEntry> map,
|
||||
shared_ptr<const MapIndex::MapEntry> map,
|
||||
const Rules& rules,
|
||||
size_t num_teams,
|
||||
bool is_2v2)
|
||||
: log(string_printf("[Tournament/%02hhX] ", number)),
|
||||
data_index(data_index),
|
||||
number(number),
|
||||
name(name),
|
||||
map(map),
|
||||
rules(rules),
|
||||
num_teams(num_teams),
|
||||
is_2v2(is_2v2),
|
||||
current_state(State::REGISTRATION) {
|
||||
: log(string_printf("[Tournament/%02hhX] ", number)),
|
||||
map_index(map_index),
|
||||
com_deck_index(com_deck_index),
|
||||
number(number),
|
||||
name(name),
|
||||
map(map),
|
||||
rules(rules),
|
||||
num_teams(num_teams),
|
||||
is_2v2(is_2v2),
|
||||
current_state(State::REGISTRATION) {
|
||||
if (this->num_teams < 4) {
|
||||
throw invalid_argument("team count must be 4 or more");
|
||||
}
|
||||
@@ -313,50 +310,48 @@ Tournament::Tournament(
|
||||
}
|
||||
|
||||
Tournament::Tournament(
|
||||
std::shared_ptr<const DataIndex> data_index,
|
||||
shared_ptr<const MapIndex> map_index,
|
||||
shared_ptr<const COMDeckIndex> com_deck_index,
|
||||
uint8_t number,
|
||||
std::shared_ptr<const JSONObject> json)
|
||||
: log(string_printf("[Tournament/%02hhX] ", number)),
|
||||
data_index(data_index),
|
||||
source_json(json),
|
||||
number(number),
|
||||
current_state(State::REGISTRATION) { }
|
||||
const JSON& json)
|
||||
: log(string_printf("[Tournament/%02hhX] ", number)),
|
||||
map_index(map_index),
|
||||
com_deck_index(com_deck_index),
|
||||
source_json(json),
|
||||
number(number),
|
||||
current_state(State::REGISTRATION) {}
|
||||
|
||||
void Tournament::init() {
|
||||
vector<size_t> team_index_to_rounds_cleared;
|
||||
|
||||
bool is_registration_complete;
|
||||
if (this->source_json) {
|
||||
auto& dict = this->source_json->as_dict();
|
||||
this->name = dict.at("name")->as_string();
|
||||
this->map = this->data_index->definition_for_map_number(dict.at("map_number")->as_int());
|
||||
this->rules = Rules(dict.at("rules"));
|
||||
this->is_2v2 = dict.at("is_2v2")->as_bool();
|
||||
is_registration_complete = dict.at("is_registration_complete")->as_bool();
|
||||
if (!this->source_json.is_null()) {
|
||||
this->name = this->source_json.get_string("name");
|
||||
this->map = this->map_index->definition_for_number(this->source_json.get_int("map_number"));
|
||||
this->rules = Rules(this->source_json.at("rules"));
|
||||
this->is_2v2 = this->source_json.get_bool("is_2v2");
|
||||
is_registration_complete = this->source_json.get_bool("is_registration_complete");
|
||||
|
||||
for (const auto& team_json : dict.at("teams")->as_list()) {
|
||||
auto& team_dict = team_json->as_dict();
|
||||
for (const auto& team_json : this->source_json.get_list("teams")) {
|
||||
auto& team = this->teams.emplace_back(new Team(
|
||||
this->shared_from_this(),
|
||||
this->teams.size(),
|
||||
team_dict.at("max_players")->as_int()));
|
||||
team->name = team_dict.at("name")->as_string();
|
||||
team->password = team_dict.at("password")->as_string();
|
||||
team_index_to_rounds_cleared.emplace_back(team_dict.at("num_rounds_cleared")->as_int());
|
||||
for (const auto& player_json : team_dict.at("player_specs")->as_list()) {
|
||||
team_json->get_int("max_players")));
|
||||
team->name = team_json->get_string("name");
|
||||
team->password = team_json->get_string("password");
|
||||
team_index_to_rounds_cleared.emplace_back(team_json->get_int("num_rounds_cleared"));
|
||||
for (const auto& player_json : team_json->get_list("player_specs")) {
|
||||
if (player_json->is_int()) {
|
||||
uint32_t serial_number = player_json->as_int();
|
||||
team->players.emplace_back(serial_number);
|
||||
this->all_player_serial_numbers.emplace(serial_number);
|
||||
team->players.emplace_back(player_json->as_int());
|
||||
this->all_player_serial_numbers.emplace(player_json->as_int());
|
||||
} else {
|
||||
team->players.emplace_back(this->data_index->com_deck(
|
||||
player_json->as_string()));
|
||||
team->players.emplace_back(this->com_deck_index->deck_for_name(player_json->as_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
this->num_teams = this->teams.size();
|
||||
|
||||
this->source_json.reset();
|
||||
this->source_json = nullptr;
|
||||
|
||||
} else {
|
||||
// Create empty teams
|
||||
@@ -385,9 +380,9 @@ void Tournament::init() {
|
||||
current_round_matches[z + 1]);
|
||||
current_round_matches[z]->following = m;
|
||||
current_round_matches[z + 1]->following = m;
|
||||
next_round_matches.emplace_back(move(m));
|
||||
next_round_matches.emplace_back(std::move(m));
|
||||
}
|
||||
current_round_matches = move(next_round_matches);
|
||||
current_round_matches = std::move(next_round_matches);
|
||||
}
|
||||
this->final_match = current_round_matches.at(0);
|
||||
|
||||
@@ -414,10 +409,8 @@ void Tournament::init() {
|
||||
if (!match->preceding_a->winner_team || !match->preceding_b->winner_team) {
|
||||
throw logic_error("preceding matches are not resolved");
|
||||
}
|
||||
size_t& a_rounds_cleared = team_index_to_rounds_cleared[
|
||||
match->preceding_a->winner_team->index];
|
||||
size_t& b_rounds_cleared = team_index_to_rounds_cleared[
|
||||
match->preceding_b->winner_team->index];
|
||||
size_t& a_rounds_cleared = team_index_to_rounds_cleared[match->preceding_a->winner_team->index];
|
||||
size_t& b_rounds_cleared = team_index_to_rounds_cleared[match->preceding_b->winner_team->index];
|
||||
if (a_rounds_cleared && b_rounds_cleared) {
|
||||
throw runtime_error("both teams won the same match");
|
||||
}
|
||||
@@ -463,39 +456,33 @@ void Tournament::init() {
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<JSONObject> Tournament::json() const {
|
||||
unordered_map<string, shared_ptr<JSONObject>> dict;
|
||||
dict.emplace("name", make_json_str(this->name));
|
||||
dict.emplace("map_number", make_json_int(this->map->map.map_number));
|
||||
dict.emplace("rules", this->rules.json());
|
||||
dict.emplace("is_2v2", make_json_bool(this->is_2v2));
|
||||
dict.emplace("is_registration_complete", make_json_bool(
|
||||
this->current_state != State::REGISTRATION));
|
||||
|
||||
vector<shared_ptr<JSONObject>> teams_list;
|
||||
JSON Tournament::json() const {
|
||||
auto teams_list = JSON::list();
|
||||
for (auto team : this->teams) {
|
||||
unordered_map<string, shared_ptr<JSONObject>> team_dict;
|
||||
team_dict.emplace("max_players", make_json_int(team->max_players));
|
||||
vector<shared_ptr<JSONObject>> player_jsons_list;
|
||||
auto players_list = JSON::list();
|
||||
for (const auto& player : team->players) {
|
||||
if (player.is_human()) {
|
||||
player_jsons_list.emplace_back(make_json_int(player.serial_number));
|
||||
players_list.emplace_back(player.serial_number);
|
||||
} else {
|
||||
player_jsons_list.emplace_back(make_json_str(player.com_deck->deck_name));
|
||||
players_list.emplace_back(player.com_deck->deck_name);
|
||||
}
|
||||
}
|
||||
team_dict.emplace("player_specs", make_json_list(move(player_jsons_list)));
|
||||
team_dict.emplace("name", make_json_str(team->name));
|
||||
team_dict.emplace("password", make_json_str(team->password));
|
||||
team_dict.emplace("num_rounds_cleared", make_json_int(team->num_rounds_cleared));
|
||||
teams_list.emplace_back(new JSONObject(move(team_dict)));
|
||||
teams_list.emplace_back(JSON::dict({
|
||||
{"max_players", team->max_players},
|
||||
{"player_specs", std::move(players_list)},
|
||||
{"name", team->name},
|
||||
{"password", team->password},
|
||||
{"num_rounds_cleared", team->num_rounds_cleared},
|
||||
}));
|
||||
}
|
||||
dict.emplace("teams", make_json_list(move(teams_list)));
|
||||
return shared_ptr<JSONObject>(new JSONObject(move(dict)));
|
||||
}
|
||||
|
||||
std::shared_ptr<const DataIndex> Tournament::get_data_index() const {
|
||||
return this->data_index;
|
||||
return JSON::dict({
|
||||
{"name", this->name},
|
||||
{"map_number", this->map->map.map_number.load()},
|
||||
{"rules", this->rules.json()},
|
||||
{"is_2v2", this->is_2v2},
|
||||
{"is_registration_complete", (this->current_state != State::REGISTRATION)},
|
||||
{"teams", std::move(teams_list)},
|
||||
});
|
||||
}
|
||||
|
||||
uint8_t Tournament::get_number() const {
|
||||
@@ -506,7 +493,7 @@ const string& Tournament::get_name() const {
|
||||
return this->name;
|
||||
}
|
||||
|
||||
shared_ptr<const DataIndex::MapEntry> Tournament::get_map() const {
|
||||
shared_ptr<const MapIndex::MapEntry> Tournament::get_map() const {
|
||||
return this->map;
|
||||
}
|
||||
|
||||
@@ -601,13 +588,13 @@ void Tournament::start() {
|
||||
throw logic_error("non-human player on team before tournament start");
|
||||
}
|
||||
}
|
||||
if (this->data_index->num_com_decks() < t->max_players - t->players.size()) {
|
||||
if (this->com_deck_index->num_decks() < t->max_players - t->players.size()) {
|
||||
throw runtime_error("not enough COM decks to complete team");
|
||||
}
|
||||
// TODO: Don't allow duplicate COM decks, nor duplicate COM SCs on the same
|
||||
// team
|
||||
while (t->players.size() < t->max_players) {
|
||||
t->players.emplace_back(this->data_index->random_com_deck());
|
||||
t->players.emplace_back(this->com_deck_index->random_deck());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -661,26 +648,25 @@ void Tournament::print_bracket(FILE* stream) const {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
TournamentIndex::TournamentIndex(
|
||||
shared_ptr<const DataIndex> data_index,
|
||||
shared_ptr<const MapIndex> map_index,
|
||||
shared_ptr<const COMDeckIndex> com_deck_index,
|
||||
const string& state_filename,
|
||||
bool skip_load_state)
|
||||
: data_index(data_index), state_filename(state_filename) {
|
||||
: map_index(map_index),
|
||||
com_deck_index(com_deck_index),
|
||||
state_filename(state_filename) {
|
||||
if (this->state_filename.empty() || skip_load_state) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto json = JSONObject::parse(load_file(this->state_filename));
|
||||
|
||||
auto& list = json->as_list();
|
||||
if (list.size() != 0x20) {
|
||||
auto json = JSON::parse(load_file(this->state_filename));
|
||||
if (json.size() != 0x20) {
|
||||
throw runtime_error("tournament JSON list length is incorrect");
|
||||
}
|
||||
for (size_t z = 0; z < 0x20; z++) {
|
||||
if (!list.at(z)->is_null()) {
|
||||
this->tournaments[z].reset(new Tournament(this->data_index, z, list[z]));
|
||||
if (!json.at(z).is_null()) {
|
||||
this->tournaments[z].reset(new Tournament(this->map_index, this->com_deck_index, z, json.at(z)));
|
||||
this->tournaments[z]->init();
|
||||
}
|
||||
}
|
||||
@@ -691,16 +677,15 @@ void TournamentIndex::save() const {
|
||||
return;
|
||||
}
|
||||
|
||||
vector<shared_ptr<JSONObject>> list;
|
||||
auto list = JSON::list();
|
||||
for (size_t z = 0; z < 0x20; z++) {
|
||||
if (this->tournaments[z]) {
|
||||
list.emplace_back(this->tournaments[z]->json());
|
||||
} else {
|
||||
list.emplace_back(make_json_null());
|
||||
list.emplace_back(nullptr);
|
||||
}
|
||||
}
|
||||
auto json = make_json_list(move(list));
|
||||
save_file(this->state_filename, json->format());
|
||||
save_file(this->state_filename, list.serialize(JSON::SerializeOption::FORMAT));
|
||||
}
|
||||
|
||||
vector<shared_ptr<Tournament>> TournamentIndex::all_tournaments() const {
|
||||
@@ -715,7 +700,7 @@ vector<shared_ptr<Tournament>> TournamentIndex::all_tournaments() const {
|
||||
|
||||
shared_ptr<Tournament> TournamentIndex::create_tournament(
|
||||
const string& name,
|
||||
shared_ptr<const DataIndex::MapEntry> map,
|
||||
shared_ptr<const MapIndex::MapEntry> map,
|
||||
const Rules& rules,
|
||||
size_t num_teams,
|
||||
bool is_2v2) {
|
||||
@@ -731,7 +716,7 @@ shared_ptr<Tournament> TournamentIndex::create_tournament(
|
||||
}
|
||||
|
||||
auto t = make_shared<Tournament>(
|
||||
this->data_index, number, name, map, rules, num_teams, is_2v2);
|
||||
this->map_index, this->com_deck_index, number, name, map, rules, num_teams, is_2v2);
|
||||
t->init();
|
||||
this->tournaments[number] = t;
|
||||
return t;
|
||||
@@ -768,6 +753,4 @@ shared_ptr<Tournament::Team> TournamentIndex::team_for_serial_number(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
+25
-25
@@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <event2/event.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <unordered_set>
|
||||
#include <string>
|
||||
#include <phosg/JSON.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#include "../Player.hh"
|
||||
|
||||
@@ -18,8 +18,6 @@ namespace Episode3 {
|
||||
|
||||
// The comment in Server.hh does not apply to this file (and Tournament.cc).
|
||||
|
||||
|
||||
|
||||
class Tournament : public std::enable_shared_from_this<Tournament> {
|
||||
public:
|
||||
enum class State {
|
||||
@@ -94,26 +92,27 @@ public:
|
||||
};
|
||||
|
||||
Tournament(
|
||||
std::shared_ptr<const DataIndex> data_index,
|
||||
std::shared_ptr<const MapIndex> map_index,
|
||||
std::shared_ptr<const COMDeckIndex> com_deck_index,
|
||||
uint8_t number,
|
||||
const std::string& name,
|
||||
std::shared_ptr<const DataIndex::MapEntry> map,
|
||||
std::shared_ptr<const MapIndex::MapEntry> map,
|
||||
const Rules& rules,
|
||||
size_t num_teams,
|
||||
bool is_2v2);
|
||||
Tournament(
|
||||
std::shared_ptr<const DataIndex> data_index,
|
||||
std::shared_ptr<const MapIndex> map_index,
|
||||
std::shared_ptr<const COMDeckIndex> com_deck_index,
|
||||
uint8_t number,
|
||||
std::shared_ptr<const JSONObject> json);
|
||||
const JSON& json);
|
||||
~Tournament() = default;
|
||||
void init();
|
||||
|
||||
std::shared_ptr<JSONObject> json() const;
|
||||
JSON json() const;
|
||||
|
||||
std::shared_ptr<const DataIndex> get_data_index() const;
|
||||
uint8_t get_number() const;
|
||||
const std::string& get_name() const;
|
||||
std::shared_ptr<const DataIndex::MapEntry> get_map() const;
|
||||
std::shared_ptr<const MapIndex::MapEntry> get_map() const;
|
||||
const Rules& get_rules() const;
|
||||
bool get_is_2v2() const;
|
||||
State get_state() const;
|
||||
@@ -133,11 +132,12 @@ public:
|
||||
private:
|
||||
PrefixedLogger log;
|
||||
|
||||
std::shared_ptr<const DataIndex> data_index;
|
||||
std::shared_ptr<const JSONObject> source_json;
|
||||
std::shared_ptr<const MapIndex> map_index;
|
||||
std::shared_ptr<const COMDeckIndex> com_deck_index;
|
||||
JSON source_json;
|
||||
uint8_t number;
|
||||
std::string name;
|
||||
std::shared_ptr<const DataIndex::MapEntry> map;
|
||||
std::shared_ptr<const MapIndex::MapEntry> map;
|
||||
Rules rules;
|
||||
size_t num_teams;
|
||||
bool is_2v2;
|
||||
@@ -162,7 +162,8 @@ private:
|
||||
class TournamentIndex {
|
||||
public:
|
||||
explicit TournamentIndex(
|
||||
std::shared_ptr<const DataIndex> data_index,
|
||||
std::shared_ptr<const MapIndex> map_index,
|
||||
std::shared_ptr<const COMDeckIndex> com_deck_index,
|
||||
const std::string& state_filename,
|
||||
bool skip_load_state = false);
|
||||
~TournamentIndex() = default;
|
||||
@@ -172,11 +173,11 @@ public:
|
||||
std::vector<std::shared_ptr<Tournament>> all_tournaments() const;
|
||||
|
||||
std::shared_ptr<Tournament> create_tournament(
|
||||
const std::string& name,
|
||||
std::shared_ptr<const DataIndex::MapEntry> map,
|
||||
const Rules& rules,
|
||||
size_t num_teams,
|
||||
bool is_2v2);
|
||||
const std::string& name,
|
||||
std::shared_ptr<const MapIndex::MapEntry> map,
|
||||
const Rules& rules,
|
||||
size_t num_teams,
|
||||
bool is_2v2);
|
||||
void delete_tournament(uint8_t number);
|
||||
std::shared_ptr<Tournament> get_tournament(uint8_t number) const;
|
||||
std::shared_ptr<Tournament> get_tournament(const std::string& name) const;
|
||||
@@ -185,11 +186,10 @@ public:
|
||||
uint32_t serial_number) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<const DataIndex> data_index;
|
||||
std::shared_ptr<const MapIndex> map_index;
|
||||
std::shared_ptr<const COMDeckIndex> com_deck_index;
|
||||
std::string state_filename;
|
||||
std::shared_ptr<Tournament> tournaments[0x20];
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Episode3
|
||||
|
||||
@@ -7,22 +7,22 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
FileContentsCache::FileContentsCache(uint64_t ttl_usecs) : ttl_usecs(ttl_usecs) { }
|
||||
FileContentsCache::FileContentsCache(uint64_t ttl_usecs) : ttl_usecs(ttl_usecs) {}
|
||||
|
||||
FileContentsCache::File::File(
|
||||
const string& name,
|
||||
string&& data,
|
||||
uint64_t load_time)
|
||||
: name(name), data(new string(move(data))), load_time(load_time) { }
|
||||
: name(name),
|
||||
data(new string(std::move(data))),
|
||||
load_time(load_time) {}
|
||||
|
||||
shared_ptr<const FileContentsCache::File> FileContentsCache::replace(
|
||||
const string& name, string&& data, uint64_t t) {
|
||||
if (t == 0) {
|
||||
t = now();
|
||||
}
|
||||
shared_ptr<File> new_file(new File(name, move(data), t));
|
||||
shared_ptr<File> new_file(new File(name, std::move(data), t));
|
||||
auto emplace_ret = this->name_to_file.emplace(name, new_file);
|
||||
if (!emplace_ret.second) {
|
||||
emplace_ret.first->second = new_file;
|
||||
@@ -33,7 +33,7 @@ shared_ptr<const FileContentsCache::File> FileContentsCache::replace(
|
||||
shared_ptr<const FileContentsCache::File> FileContentsCache::replace(
|
||||
const string& name, const void* data, size_t size, uint64_t t) {
|
||||
string s(reinterpret_cast<const char*>(data), size);
|
||||
return this->replace(name, move(s), t);
|
||||
return this->replace(name, std::move(s), t);
|
||||
}
|
||||
|
||||
FileContentsCache::GetResult FileContentsCache::get_or_load(const std::string& name) {
|
||||
@@ -65,7 +65,8 @@ FileContentsCache::GetResult FileContentsCache::get(const std::string& name,
|
||||
if (this->ttl_usecs && (t - entry->load_time < this->ttl_usecs)) {
|
||||
return {entry, false};
|
||||
}
|
||||
} catch (const out_of_range& e) { }
|
||||
} catch (const out_of_range& e) {
|
||||
}
|
||||
return {this->replace(name, generate(name)), true};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <functional>
|
||||
|
||||
#include <phosg/Time.hh>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
class FileContentsCache {
|
||||
public:
|
||||
struct File {
|
||||
@@ -92,7 +91,8 @@ public:
|
||||
if (this->ttl_usecs && (t - f->load_time < this->ttl_usecs)) {
|
||||
return {*reinterpret_cast<const T*>(f->data->data()), f, false};
|
||||
}
|
||||
} catch (const out_of_range& e) { }
|
||||
} catch (const out_of_range& e) {
|
||||
}
|
||||
T value = generate(name);
|
||||
auto ret = this->replace_obj(name, value);
|
||||
ret.generate_called = true;
|
||||
|
||||
+163
-49
@@ -3,29 +3,34 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Hash.hh>
|
||||
#include <phosg/Time.hh>
|
||||
#include <stdexcept>
|
||||
|
||||
#ifdef HAVE_RESOURCE_FILE
|
||||
#include <resource_file/Emulators/PPC32Emulator.hh>
|
||||
#endif
|
||||
|
||||
#include "Loggers.hh"
|
||||
#include "CommandFormats.hh"
|
||||
#include "Compression.hh"
|
||||
#include "Loggers.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
static bool is_function_compiler_available = true;
|
||||
|
||||
bool function_compiler_available() {
|
||||
#ifndef HAVE_RESOURCE_FILE
|
||||
return false;
|
||||
#else
|
||||
return true;
|
||||
return is_function_compiler_available;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void set_function_compiler_available(bool is_available) {
|
||||
is_function_compiler_available = is_available;
|
||||
}
|
||||
|
||||
const char* name_for_architecture(CompiledFunctionCode::Architecture arch) {
|
||||
switch (arch) {
|
||||
@@ -38,12 +43,11 @@ const char* name_for_architecture(CompiledFunctionCode::Architecture arch) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename FooterT, typename U16T>
|
||||
template <typename FooterT>
|
||||
string CompiledFunctionCode::generate_client_command_t(
|
||||
const unordered_map<string, uint32_t>& label_writes,
|
||||
const string& suffix) const {
|
||||
const unordered_map<string, uint32_t>& label_writes,
|
||||
const string& suffix,
|
||||
uint32_t override_relocations_offset) const {
|
||||
FooterT footer;
|
||||
footer.num_relocations = this->relocation_deltas.size();
|
||||
footer.unused1.clear(0);
|
||||
@@ -70,26 +74,37 @@ string CompiledFunctionCode::generate_client_command_t(
|
||||
}
|
||||
|
||||
footer.relocations_offset = w.size();
|
||||
for (uint16_t delta : this->relocation_deltas) {
|
||||
w.put<U16T>(delta);
|
||||
|
||||
// Always write at least 4 bytes even if there are no relocations
|
||||
if (this->relocation_deltas.empty()) {
|
||||
w.put_u32(0);
|
||||
}
|
||||
if (this->relocation_deltas.size() & 1) {
|
||||
w.put_u16(0);
|
||||
|
||||
if (override_relocations_offset) {
|
||||
footer.relocations_offset = override_relocations_offset;
|
||||
} else {
|
||||
for (uint16_t delta : this->relocation_deltas) {
|
||||
w.put<typename FooterT::U16T>(delta);
|
||||
}
|
||||
if (this->relocation_deltas.size() & 1) {
|
||||
w.put_u16(0);
|
||||
}
|
||||
}
|
||||
|
||||
w.put(footer);
|
||||
return move(w.str());
|
||||
return std::move(w.str());
|
||||
}
|
||||
|
||||
string CompiledFunctionCode::generate_client_command(
|
||||
const unordered_map<string, uint32_t>& label_writes,
|
||||
const string& suffix) const {
|
||||
const unordered_map<string, uint32_t>& label_writes,
|
||||
const string& suffix,
|
||||
uint32_t override_relocations_offset) const {
|
||||
if (this->arch == Architecture::POWERPC) {
|
||||
return this->generate_client_command_t<S_ExecuteCode_Footer_GC_B2, be_uint16_t>(
|
||||
label_writes, suffix);
|
||||
return this->generate_client_command_t<S_ExecuteCode_Footer_GC_B2>(
|
||||
label_writes, suffix, override_relocations_offset);
|
||||
} else if ((this->arch == Architecture::X86) || (this->arch == Architecture::SH4)) {
|
||||
return this->generate_client_command_t<S_ExecuteCode_Footer_DC_PC_XB_BB_B2, le_uint16_t>(
|
||||
label_writes, suffix);
|
||||
return this->generate_client_command_t<S_ExecuteCode_Footer_DC_PC_XB_BB_B2>(
|
||||
label_writes, suffix, override_relocations_offset);
|
||||
} else {
|
||||
throw logic_error("invalid architecture");
|
||||
}
|
||||
@@ -99,8 +114,6 @@ bool CompiledFunctionCode::is_big_endian() const {
|
||||
return this->arch == Architecture::POWERPC;
|
||||
}
|
||||
|
||||
|
||||
|
||||
shared_ptr<CompiledFunctionCode> compile_function_code(
|
||||
CompiledFunctionCode::Architecture arch,
|
||||
const string& directory,
|
||||
@@ -122,8 +135,8 @@ shared_ptr<CompiledFunctionCode> compile_function_code(
|
||||
|
||||
if (arch == CompiledFunctionCode::Architecture::POWERPC) {
|
||||
auto assembled = PPC32Emulator::assemble(text, {directory});
|
||||
ret->code = move(assembled.code);
|
||||
ret->label_offsets = move(assembled.label_offsets);
|
||||
ret->code = std::move(assembled.code);
|
||||
ret->label_offsets = std::move(assembled.label_offsets);
|
||||
} else if (arch == CompiledFunctionCode::Architecture::X86) {
|
||||
throw runtime_error("x86 assembler is not implemented");
|
||||
}
|
||||
@@ -159,8 +172,6 @@ shared_ptr<CompiledFunctionCode> compile_function_code(
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
FunctionCodeIndex::FunctionCodeIndex(const string& directory) {
|
||||
if (!function_compiler_available()) {
|
||||
function_compiler_log.info("Function compiler is not available");
|
||||
@@ -175,6 +186,20 @@ FunctionCodeIndex::FunctionCodeIndex(const string& directory) {
|
||||
bool is_patch = ends_with(filename, ".patch.s");
|
||||
string name = filename.substr(0, filename.size() - (is_patch ? 8 : 2));
|
||||
|
||||
// Check for specific_version token
|
||||
uint32_t specific_version = 0;
|
||||
string patch_name = name;
|
||||
if (is_patch &&
|
||||
(filename.size() >= 13) &&
|
||||
(filename[filename.size() - 13] == '.') &&
|
||||
isdigit(filename[filename.size() - 12]) &&
|
||||
(filename[filename.size() - 11] == 'O' || filename[filename.size() - 11] == 'S') &&
|
||||
(filename[filename.size() - 10] == 'E' || filename[filename.size() - 10] == 'J' || filename[filename.size() - 10] == 'P') &&
|
||||
(isdigit(filename[filename.size() - 9]) || filename[filename.size() - 9] == 'T')) {
|
||||
specific_version = 0x33000000 | (filename[filename.size() - 11] << 16) | (filename[filename.size() - 10] << 8) | filename[filename.size() - 9];
|
||||
patch_name = filename.substr(0, filename.size() - 13);
|
||||
}
|
||||
|
||||
try {
|
||||
string path = directory + "/" + filename;
|
||||
string text = load_file(path);
|
||||
@@ -186,15 +211,19 @@ FunctionCodeIndex::FunctionCodeIndex(const string& directory) {
|
||||
"duplicate function index: %08" PRIX32, code->index));
|
||||
}
|
||||
}
|
||||
code->specific_version = specific_version;
|
||||
code->patch_name = patch_name;
|
||||
this->name_to_function.emplace(name, code);
|
||||
if (is_patch) {
|
||||
code->menu_item_id = next_menu_item_id++;
|
||||
this->menu_item_id_to_patch_function.emplace(code->menu_item_id, code);
|
||||
this->name_to_patch_function.emplace(name, code);
|
||||
this->menu_item_id_and_specific_version_to_patch_function.emplace(
|
||||
static_cast<uint64_t>(code->menu_item_id) << 32 | specific_version, code);
|
||||
this->name_and_specific_version_to_patch_function.emplace(
|
||||
string_printf("%s-%08" PRIX32, patch_name.c_str(), specific_version), code);
|
||||
}
|
||||
|
||||
string index_prefix = code->index ? string_printf("%02X => ", code->index) : "";
|
||||
string patch_prefix = is_patch ? string_printf("[%08" PRIX32 "] ", code->menu_item_id) : "";
|
||||
string patch_prefix = is_patch ? string_printf("[%08" PRIX32 "/%08" PRIX32 "] ", code->menu_item_id, code->specific_version) : "";
|
||||
function_compiler_log.info("Compiled function %s%s%s (%s)",
|
||||
index_prefix.c_str(), patch_prefix.c_str(), name.c_str(), name_for_architecture(code->arch));
|
||||
|
||||
@@ -204,20 +233,29 @@ FunctionCodeIndex::FunctionCodeIndex(const string& directory) {
|
||||
}
|
||||
}
|
||||
|
||||
vector<MenuItem> FunctionCodeIndex::patch_menu() const {
|
||||
vector<MenuItem> ret;
|
||||
ret.emplace_back(PatchesMenuItemID::GO_BACK, u"Go back", u"", 0);
|
||||
for (const auto& it : this->name_to_patch_function) {
|
||||
shared_ptr<const Menu> FunctionCodeIndex::patch_menu(uint32_t specific_version) const {
|
||||
auto suffix = string_printf("-%08" PRIX32, specific_version);
|
||||
|
||||
shared_ptr<Menu> ret(new Menu(MenuID::PATCHES, u"Patches"));
|
||||
ret->items.emplace_back(PatchesMenuItemID::GO_BACK, u"Go back", u"Return to the\nmain menu", 0);
|
||||
for (const auto& it : this->name_and_specific_version_to_patch_function) {
|
||||
const auto& fn = it.second;
|
||||
if (!fn->hide_from_patches_menu) {
|
||||
ret.emplace_back(fn->menu_item_id, decode_sjis(fn->name), u"",
|
||||
if (!fn->hide_from_patches_menu && ends_with(it.first, suffix)) {
|
||||
ret->items.emplace_back(fn->menu_item_id, decode_sjis(fn->patch_name), u"",
|
||||
MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool FunctionCodeIndex::patch_menu_empty(uint32_t specific_version) const {
|
||||
for (const auto& it : this->menu_item_id_and_specific_version_to_patch_function) {
|
||||
if ((it.first & 0xFF000000) == (specific_version & 0xFF000000)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
DOLFileIndex::DOLFileIndex(const string& directory) {
|
||||
if (!function_compiler_available()) {
|
||||
@@ -229,12 +267,18 @@ DOLFileIndex::DOLFileIndex(const string& directory) {
|
||||
return;
|
||||
}
|
||||
|
||||
shared_ptr<Menu> menu(new Menu(MenuID::PROGRAMS, u"Programs"));
|
||||
this->menu = menu;
|
||||
menu->items.emplace_back(ProgramsMenuItemID::GO_BACK, u"Go back", u"Return to the\nmain menu", 0);
|
||||
|
||||
uint32_t next_menu_item_id = 0;
|
||||
for (const auto& filename : list_directory(directory)) {
|
||||
if (!ends_with(filename, ".dol")) {
|
||||
for (const auto& filename : list_directory_sorted(directory)) {
|
||||
bool is_dol = ends_with(filename, ".dol");
|
||||
bool is_compressed_dol = ends_with(filename, ".dol.prs");
|
||||
if (!is_dol && !is_compressed_dol) {
|
||||
continue;
|
||||
}
|
||||
string name = filename.substr(0, filename.size() - 4);
|
||||
string name = filename.substr(0, filename.size() - (is_compressed_dol ? 8 : 4));
|
||||
|
||||
try {
|
||||
shared_ptr<DOLFile> dol(new DOLFile());
|
||||
@@ -242,11 +286,48 @@ DOLFileIndex::DOLFileIndex(const string& directory) {
|
||||
dol->name = name;
|
||||
|
||||
string path = directory + "/" + filename;
|
||||
dol->data = load_file(path);
|
||||
string file_data = load_file(path);
|
||||
|
||||
string description;
|
||||
if (is_compressed_dol) {
|
||||
size_t decompressed_size = prs_decompress_size(file_data);
|
||||
|
||||
StringWriter w;
|
||||
w.put_u32b(file_data.size());
|
||||
w.put_u32b(decompressed_size);
|
||||
w.write(file_data);
|
||||
while (w.size() & 3) {
|
||||
w.put_u8(0);
|
||||
}
|
||||
dol->data = std::move(w.str());
|
||||
|
||||
string compressed_size_str = format_size(file_data.size());
|
||||
string decompressed_size_str = format_size(decompressed_size);
|
||||
function_compiler_log.info("Loaded compressed DOL file %s (%s -> %s)",
|
||||
dol->name.c_str(), compressed_size_str.c_str(), decompressed_size_str.c_str());
|
||||
description = string_printf("$C6%s$C7\n%s\n%s (orig)",
|
||||
dol->name.c_str(), compressed_size_str.c_str(), decompressed_size_str.c_str());
|
||||
|
||||
} else {
|
||||
StringWriter w;
|
||||
w.put_u32b(0);
|
||||
w.put_u32b(file_data.size());
|
||||
w.write(file_data);
|
||||
while (w.size() & 3) {
|
||||
w.put_u8(0);
|
||||
}
|
||||
dol->data = std::move(w.str());
|
||||
|
||||
string size_str = format_size(dol->data.size());
|
||||
function_compiler_log.info("Loaded DOL file %s (%s)", filename.c_str(), size_str.c_str());
|
||||
description = string_printf("$C6%s$C7\n%s", dol->name.c_str(), size_str.c_str());
|
||||
}
|
||||
|
||||
this->name_to_file.emplace(dol->name, dol);
|
||||
this->item_id_to_file.emplace_back(dol);
|
||||
function_compiler_log.info("Loaded DOL file %s", filename.c_str());
|
||||
|
||||
menu->items.emplace_back(dol->menu_item_id, decode_sjis(dol->name),
|
||||
decode_sjis(description), MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL);
|
||||
|
||||
} catch (const exception& e) {
|
||||
function_compiler_log.warning("Failed to load DOL file %s: %s", filename.c_str(), e.what());
|
||||
@@ -254,12 +335,45 @@ DOLFileIndex::DOLFileIndex(const string& directory) {
|
||||
}
|
||||
}
|
||||
|
||||
vector<MenuItem> DOLFileIndex::menu() const {
|
||||
vector<MenuItem> ret;
|
||||
ret.emplace_back(ProgramsMenuItemID::GO_BACK, u"Go back", u"", 0);
|
||||
for (const auto& dol : this->item_id_to_file) {
|
||||
ret.emplace_back(dol->menu_item_id, decode_sjis(dol->name), u"",
|
||||
MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL);
|
||||
uint32_t specific_version_for_gc_header_checksum(uint32_t header_checksum) {
|
||||
static unordered_map<uint32_t, uint32_t> checksum_to_specific_version;
|
||||
if (checksum_to_specific_version.empty()) {
|
||||
struct {
|
||||
char system_code = 'G';
|
||||
char game_code1 = 'P';
|
||||
char game_code2;
|
||||
char region_code;
|
||||
char developer_code1 = '8';
|
||||
char developer_code2 = 'P';
|
||||
uint8_t disc_number = 0;
|
||||
uint8_t version_code;
|
||||
} __attribute__((packed)) data;
|
||||
for (const char* game_code2 = "OS"; *game_code2; game_code2++) {
|
||||
data.game_code2 = *game_code2;
|
||||
for (const char* region_code = "JEP"; *region_code; region_code++) {
|
||||
data.region_code = *region_code;
|
||||
for (uint8_t version_code = 0; version_code < 8; version_code++) {
|
||||
data.version_code = version_code;
|
||||
uint32_t checksum = crc32(&data, sizeof(data));
|
||||
uint32_t specific_version = 0x33000030 | (*game_code2 << 16) | (*region_code << 8) | version_code;
|
||||
if (!checksum_to_specific_version.emplace(checksum, specific_version).second) {
|
||||
throw logic_error("multiple specific_versions have same header checksum");
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
// Generate entries for Trial Editions
|
||||
data.region_code = 'J';
|
||||
data.system_code = 'D';
|
||||
data.version_code = 0;
|
||||
uint32_t checksum = crc32(&data, sizeof(data));
|
||||
uint32_t specific_version = 0x33004A54 | (*game_code2 << 16);
|
||||
if (!checksum_to_specific_version.emplace(checksum, specific_version).second) {
|
||||
throw logic_error("multiple specific_versions have same header checksum");
|
||||
}
|
||||
data.system_code = 'G';
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
return checksum_to_specific_version.at(header_checksum);
|
||||
}
|
||||
|
||||
+21
-23
@@ -2,19 +2,16 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "Menu.hh"
|
||||
|
||||
|
||||
|
||||
bool function_compiler_available();
|
||||
|
||||
|
||||
void set_function_compiler_available(bool is_available);
|
||||
|
||||
// TODO: Support x86 and SH4 function calls in the future. Currently we only
|
||||
// support PPC32 because I haven't written an appropriate x86 assembler yet.
|
||||
@@ -31,19 +28,23 @@ struct CompiledFunctionCode {
|
||||
std::unordered_map<std::string, uint32_t> label_offsets;
|
||||
uint32_t entrypoint_offset_offset;
|
||||
std::string name;
|
||||
std::string patch_name; // Blank if not a patch
|
||||
uint32_t index; // 0 = unused (not registered in index_to_function)
|
||||
uint32_t menu_item_id;
|
||||
bool hide_from_patches_menu;
|
||||
uint32_t specific_version;
|
||||
|
||||
bool is_big_endian() const;
|
||||
|
||||
template <typename FooterT, typename U16T>
|
||||
template <typename FooterT>
|
||||
std::string generate_client_command_t(
|
||||
const std::unordered_map<std::string, uint32_t>& label_writes,
|
||||
const std::string& suffix) const;
|
||||
const std::unordered_map<std::string, uint32_t>& label_writes,
|
||||
const std::string& suffix,
|
||||
uint32_t override_relocations_offset = 0) const;
|
||||
std::string generate_client_command(
|
||||
const std::unordered_map<std::string, uint32_t>& label_writes = {},
|
||||
const std::string& suffix = "") const;
|
||||
const std::string& suffix = "",
|
||||
uint32_t override_relocations_offset = 0) const;
|
||||
};
|
||||
|
||||
const char* name_for_architecture(CompiledFunctionCode::Architecture arch);
|
||||
@@ -54,41 +55,38 @@ std::shared_ptr<CompiledFunctionCode> compile_function_code(
|
||||
const std::string& name,
|
||||
const std::string& text);
|
||||
|
||||
|
||||
|
||||
struct FunctionCodeIndex {
|
||||
FunctionCodeIndex() = default;
|
||||
explicit FunctionCodeIndex(const std::string& directory);
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<CompiledFunctionCode>> name_to_function;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<CompiledFunctionCode>> index_to_function;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<CompiledFunctionCode>> menu_item_id_to_patch_function;
|
||||
std::unordered_map<uint64_t, std::shared_ptr<CompiledFunctionCode>> menu_item_id_and_specific_version_to_patch_function;
|
||||
// Key here is e.g. "PATCHNAME-SPECIFICVERSION", with the latter in hex
|
||||
std::map<std::string, std::shared_ptr<CompiledFunctionCode>> name_and_specific_version_to_patch_function;
|
||||
|
||||
std::map<std::string, std::shared_ptr<CompiledFunctionCode>> name_to_patch_function;
|
||||
|
||||
std::vector<MenuItem> patch_menu() const;
|
||||
inline bool patch_menu_empty() const {
|
||||
return this->name_to_patch_function.empty();
|
||||
}
|
||||
std::shared_ptr<const Menu> patch_menu(uint32_t specific_version) const;
|
||||
bool patch_menu_empty(uint32_t specific_version) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct DOLFileIndex {
|
||||
struct DOLFile {
|
||||
uint32_t menu_item_id;
|
||||
std::string name;
|
||||
std::string data;
|
||||
bool is_compressed;
|
||||
};
|
||||
|
||||
std::vector<std::shared_ptr<DOLFile>> item_id_to_file;
|
||||
std::map<std::string, std::shared_ptr<DOLFile>> name_to_file;
|
||||
std::unordered_map<std::string, std::shared_ptr<DOLFile>> name_to_file;
|
||||
std::shared_ptr<const Menu> menu;
|
||||
|
||||
DOLFileIndex() = default;
|
||||
explicit DOLFileIndex(const std::string& directory);
|
||||
|
||||
std::vector<MenuItem> menu() const;
|
||||
inline bool empty() const {
|
||||
return this->name_to_file.empty() && this->item_id_to_file.empty();
|
||||
}
|
||||
};
|
||||
|
||||
uint32_t specific_version_for_gc_header_checksum(uint32_t header_checksum);
|
||||
|
||||
+10
-10
@@ -8,22 +8,22 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
template <typename LongT>
|
||||
template <bool IsBigEndian>
|
||||
struct GSLHeaderEntry {
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
|
||||
ptext<char, 0x20> filename;
|
||||
LongT offset; // In pages, so actual offset is this * 0x800
|
||||
LongT size;
|
||||
U32T offset; // In pages, so actual offset is this * 0x800
|
||||
U32T size;
|
||||
uint64_t unused;
|
||||
} __attribute__((packed));
|
||||
|
||||
template <typename LongT>
|
||||
template <bool IsBigEndian>
|
||||
void GSLArchive::load_t() {
|
||||
StringReader r(*this->data);
|
||||
uint64_t min_data_offset = 0xFFFFFFFFFFFFFFFF;
|
||||
while (r.where() < min_data_offset) {
|
||||
const auto& entry = r.get<GSLHeaderEntry<LongT>>();
|
||||
const auto& entry = r.get<GSLHeaderEntry<IsBigEndian>>();
|
||||
if (entry.filename.len() == 0) {
|
||||
break;
|
||||
}
|
||||
@@ -36,11 +36,11 @@ void GSLArchive::load_t() {
|
||||
}
|
||||
|
||||
GSLArchive::GSLArchive(shared_ptr<const string> data, bool big_endian)
|
||||
: data(data) {
|
||||
: data(data) {
|
||||
if (big_endian) {
|
||||
this->load_t<be_uint32_t>();
|
||||
this->load_t<true>();
|
||||
} else {
|
||||
this->load_t<le_uint32_t>();
|
||||
this->load_t<false>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-3
@@ -8,8 +8,6 @@
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
|
||||
class GSLArchive {
|
||||
public:
|
||||
GSLArchive(std::shared_ptr<const std::string> data, bool big_endian);
|
||||
@@ -26,7 +24,7 @@ public:
|
||||
StringReader get_reader(const std::string& name) const;
|
||||
|
||||
private:
|
||||
template <typename LongT>
|
||||
template <bool IsBigEndian>
|
||||
void load_t();
|
||||
|
||||
std::shared_ptr<const std::string> data;
|
||||
|
||||
+33
-32
@@ -6,8 +6,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
static inline uint16_t collapse_checksum(uint32_t sum) {
|
||||
// It's impossible for this to be necessary more than twice: the first
|
||||
// addition can carry out at most a single bit.
|
||||
@@ -15,35 +13,33 @@ static inline uint16_t collapse_checksum(uint32_t sum) {
|
||||
return (sum & 0xFFFF) + (sum >> 16);
|
||||
}
|
||||
|
||||
|
||||
|
||||
FrameInfo::FrameInfo()
|
||||
: ether(nullptr),
|
||||
ether_protocol(0),
|
||||
ipv4(nullptr),
|
||||
arp(nullptr),
|
||||
udp(nullptr),
|
||||
tcp(nullptr),
|
||||
header_start(nullptr),
|
||||
payload(nullptr),
|
||||
total_size(0),
|
||||
tcp_options_size(0),
|
||||
payload_size(0) { }
|
||||
: ether(nullptr),
|
||||
ether_protocol(0),
|
||||
ipv4(nullptr),
|
||||
arp(nullptr),
|
||||
udp(nullptr),
|
||||
tcp(nullptr),
|
||||
header_start(nullptr),
|
||||
payload(nullptr),
|
||||
total_size(0),
|
||||
tcp_options_size(0),
|
||||
payload_size(0) {}
|
||||
|
||||
FrameInfo::FrameInfo(const string& data) : FrameInfo(data.data(), data.size()) { }
|
||||
FrameInfo::FrameInfo(const string& data) : FrameInfo(data.data(), data.size()) {}
|
||||
|
||||
FrameInfo::FrameInfo(const void* header_start, size_t size)
|
||||
: ether(nullptr),
|
||||
ether_protocol(0),
|
||||
ipv4(nullptr),
|
||||
arp(nullptr),
|
||||
udp(nullptr),
|
||||
tcp(nullptr),
|
||||
header_start(header_start),
|
||||
payload(nullptr),
|
||||
total_size(size),
|
||||
tcp_options_size(0),
|
||||
payload_size(size) {
|
||||
: ether(nullptr),
|
||||
ether_protocol(0),
|
||||
ipv4(nullptr),
|
||||
arp(nullptr),
|
||||
udp(nullptr),
|
||||
tcp(nullptr),
|
||||
header_start(header_start),
|
||||
payload(nullptr),
|
||||
total_size(size),
|
||||
tcp_options_size(0),
|
||||
payload_size(size) {
|
||||
|
||||
// Parse ethernet header
|
||||
if (this->payload_size < sizeof(EthernetHeader)) {
|
||||
@@ -125,26 +121,31 @@ string FrameInfo::header_str() const {
|
||||
return "<invalid-frame-info>";
|
||||
}
|
||||
|
||||
string ret = string_printf("%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX->%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX",
|
||||
string ret = string_printf(
|
||||
"%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX->%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX",
|
||||
this->ether->src_mac[0], this->ether->src_mac[1], this->ether->src_mac[2],
|
||||
this->ether->src_mac[3], this->ether->src_mac[4], this->ether->src_mac[5],
|
||||
this->ether->dest_mac[0], this->ether->dest_mac[1], this->ether->dest_mac[2],
|
||||
this->ether->dest_mac[3], this->ether->dest_mac[4], this->ether->dest_mac[5]);
|
||||
|
||||
if (this->arp) {
|
||||
ret += string_printf(",ARP,hw_type=%04hX,proto_type=%04hX,hw_addr_len=%02hhX,proto_addr_len=%02hhX,op=%04hX",
|
||||
ret += string_printf(
|
||||
",ARP,hw_type=%04hX,proto_type=%04hX,hw_addr_len=%02hhX,proto_addr_len=%02hhX,op=%04hX",
|
||||
this->arp->hardware_type.load(), this->arp->protocol_type.load(), this->arp->hwaddr_len, this->arp->paddr_len, this->arp->operation.load());
|
||||
|
||||
} else if (this->ipv4) {
|
||||
ret += string_printf(",IPv4,size=%04hX,src=%08" PRIX32 ",dest=%08" PRIX32,
|
||||
ret += string_printf(
|
||||
",IPv4,size=%04hX,src=%08" PRIX32 ",dest=%08" PRIX32,
|
||||
this->ipv4->size.load(), this->ipv4->src_addr.load(), this->ipv4->dest_addr.load());
|
||||
|
||||
if (this->udp) {
|
||||
ret += string_printf(",UDP,src_port=%04hX,dest_port=%04hX,size=%04hX",
|
||||
ret += string_printf(
|
||||
",UDP,src_port=%04hX,dest_port=%04hX,size=%04hX",
|
||||
this->udp->src_port.load(), this->udp->dest_port.load(), this->udp->size.load());
|
||||
|
||||
} else if (this->tcp) {
|
||||
ret += string_printf(",TCP,src_port=%04hX,dest_port=%04hX,seq=%08" PRIX32 ",ack=%08" PRIX32 ",flags=%04hX(",
|
||||
ret += string_printf(
|
||||
",TCP,src_port=%04hX,dest_port=%04hX,seq=%08" PRIX32 ",ack=%08" PRIX32 ",flags=%04hX(",
|
||||
this->tcp->src_port.load(), this->tcp->dest_port.load(), this->tcp->seq_num.load(), this->tcp->ack_num.load(), this->tcp->flags.load());
|
||||
if (this->tcp->flags & TCPHeader::Flag::FIN) {
|
||||
ret += "FIN,";
|
||||
|
||||
+1
-5
@@ -4,8 +4,6 @@
|
||||
|
||||
#include <phosg/Encoding.hh>
|
||||
|
||||
|
||||
|
||||
struct EthernetHeader {
|
||||
uint8_t dest_mac[6];
|
||||
uint8_t src_mac[6];
|
||||
@@ -42,7 +40,7 @@ struct UDPHeader {
|
||||
|
||||
struct TCPHeader {
|
||||
enum Flag {
|
||||
NS = 0x0100,
|
||||
NS = 0x0100,
|
||||
CWR = 0x0080, // congestion window reduced
|
||||
ECE = 0x0040, // ECN capable / congestion experienced
|
||||
URG = 0x0020, // urgent pointer used
|
||||
@@ -63,8 +61,6 @@ struct TCPHeader {
|
||||
be_uint16_t urgent_ptr;
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
|
||||
struct FrameInfo {
|
||||
// This is always valid
|
||||
const EthernetHeader* ether;
|
||||
|
||||
+49
-86
@@ -1,36 +1,26 @@
|
||||
#include "IPStackSimulator.hh"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <event2/buffer.h>
|
||||
#include <event2/bufferevent.h>
|
||||
#include <event2/listener.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef PHOSG_WINDOWS
|
||||
#include <arpa/inet.h>
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <phosg/Network.hh>
|
||||
#include <phosg/Random.hh>
|
||||
#include <phosg/Time.hh>
|
||||
#include <string>
|
||||
|
||||
#include "Loggers.hh"
|
||||
#include "IPFrameInfo.hh"
|
||||
#include "DNSServer.hh"
|
||||
#include "IPFrameInfo.hh"
|
||||
#include "Loggers.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
static const size_t DEFAULT_RESEND_PUSH_USECS = 200000; // 200ms
|
||||
|
||||
|
||||
|
||||
// Note: these functions exist because seq nums are allowed to wrap around the
|
||||
// 32-bit integer space by design. We have to do the subtraction before the
|
||||
// comparison to allow integer overflow to occur if needed.
|
||||
@@ -51,8 +41,6 @@ static __attribute__((unused)) inline bool seq_num_greater_or_equal(uint32_t a,
|
||||
return (a == b) || seq_num_greater(a, b);
|
||||
}
|
||||
|
||||
|
||||
|
||||
string IPStackSimulator::str_for_ipv4_netloc(uint32_t addr, uint16_t port) {
|
||||
be_uint32_t be_addr = addr;
|
||||
char addr_str[INET_ADDRSTRLEN];
|
||||
@@ -73,14 +61,12 @@ string IPStackSimulator::str_for_tcp_connection(shared_ptr<const IPClient> c,
|
||||
fd, key, client_netloc_str.c_str(), server_netloc_str.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
IPStackSimulator::IPStackSimulator(
|
||||
std::shared_ptr<struct event_base> base,
|
||||
std::shared_ptr<ServerState> state)
|
||||
: base(base),
|
||||
state(state),
|
||||
pcap_text_log_file(state->ip_stack_debug ? fopen("IPStackSimulator-Log.txt", "wt") : nullptr) {
|
||||
: base(base),
|
||||
state(state),
|
||||
pcap_text_log_file(state->ip_stack_debug ? fopen("IPStackSimulator-Log.txt", "wt") : nullptr) {
|
||||
memset(this->host_mac_address_bytes, 0x90, 6);
|
||||
memset(this->broadcast_mac_address_bytes, 0xFF, 6);
|
||||
}
|
||||
@@ -91,8 +77,6 @@ IPStackSimulator::~IPStackSimulator() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void IPStackSimulator::listen(const std::string& socket_path) {
|
||||
this->add_socket(::listen(socket_path, 0, SOMAXCONN));
|
||||
}
|
||||
@@ -108,17 +92,15 @@ void IPStackSimulator::listen(int port) {
|
||||
void IPStackSimulator::add_socket(int fd) {
|
||||
this->listeners.emplace(
|
||||
evconnlistener_new(
|
||||
this->base.get(),
|
||||
IPStackSimulator::dispatch_on_listen_accept,
|
||||
this,
|
||||
LEV_OPT_REUSEABLE,
|
||||
0,
|
||||
fd),
|
||||
this->base.get(),
|
||||
IPStackSimulator::dispatch_on_listen_accept,
|
||||
this,
|
||||
LEV_OPT_REUSEABLE,
|
||||
0,
|
||||
fd),
|
||||
evconnlistener_free);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t IPStackSimulator::connect_address_for_remote_address(uint32_t remote_addr) {
|
||||
// Use an address not on the same subnet as the client, so that PSO Plus and
|
||||
// Episode III will think they're talking to a remote network and won't reject
|
||||
@@ -130,41 +112,36 @@ uint32_t IPStackSimulator::connect_address_for_remote_address(uint32_t remote_ad
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
IPStackSimulator::IPClient::IPClient(struct bufferevent* bev)
|
||||
: bev(bev, bufferevent_free), ipv4_addr(0) {
|
||||
: bev(bev, bufferevent_free),
|
||||
ipv4_addr(0) {
|
||||
memset(this->mac_addr, 0, 6);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void flush_and_free_bufferevent(struct bufferevent* bev) {
|
||||
bufferevent_flush(bev, EV_READ | EV_WRITE, BEV_FINISHED);
|
||||
bufferevent_free(bev);
|
||||
}
|
||||
|
||||
IPStackSimulator::IPClient::TCPConnection::TCPConnection()
|
||||
: server_bev(nullptr, flush_and_free_bufferevent),
|
||||
pending_data(evbuffer_new(), evbuffer_free),
|
||||
resend_push_event(nullptr, event_free),
|
||||
awaiting_first_ack(true),
|
||||
server_addr(0),
|
||||
server_port(0),
|
||||
client_port(0),
|
||||
next_client_seq(0),
|
||||
acked_server_seq(0),
|
||||
resend_push_usecs(DEFAULT_RESEND_PUSH_USECS),
|
||||
next_push_max_frame_size(1024),
|
||||
max_frame_size(1024),
|
||||
bytes_received(0),
|
||||
bytes_sent(0) { }
|
||||
|
||||
|
||||
: server_bev(nullptr, flush_and_free_bufferevent),
|
||||
pending_data(evbuffer_new(), evbuffer_free),
|
||||
resend_push_event(nullptr, event_free),
|
||||
awaiting_first_ack(true),
|
||||
server_addr(0),
|
||||
server_port(0),
|
||||
client_port(0),
|
||||
next_client_seq(0),
|
||||
acked_server_seq(0),
|
||||
resend_push_usecs(DEFAULT_RESEND_PUSH_USECS),
|
||||
next_push_max_frame_size(1024),
|
||||
max_frame_size(1024),
|
||||
bytes_received(0),
|
||||
bytes_sent(0) {}
|
||||
|
||||
void IPStackSimulator::dispatch_on_listen_accept(
|
||||
struct evconnlistener* listener, evutil_socket_t fd,
|
||||
struct sockaddr *address, int socklen, void* ctx) {
|
||||
struct sockaddr* address, int socklen, void* ctx) {
|
||||
reinterpret_cast<IPStackSimulator*>(ctx)->on_listen_accept(
|
||||
listener, fd, address, socklen);
|
||||
}
|
||||
@@ -174,7 +151,7 @@ void IPStackSimulator::on_listen_accept(struct evconnlistener* listener,
|
||||
int listen_fd = evconnlistener_get_fd(listener);
|
||||
ip_stack_simulator_log.info("Virtual network fd %d connected via fd %d", fd, listen_fd);
|
||||
|
||||
struct bufferevent *bev = bufferevent_socket_new(this->base.get(), fd,
|
||||
struct bufferevent* bev = bufferevent_socket_new(this->base.get(), fd,
|
||||
BEV_OPT_CLOSE_ON_FREE | BEV_OPT_DEFER_CALLBACKS);
|
||||
shared_ptr<IPClient> c(new IPClient(bev));
|
||||
c->sim = this;
|
||||
@@ -197,8 +174,6 @@ void IPStackSimulator::on_listen_error(struct evconnlistener* listener) {
|
||||
event_base_loopexit(this->base.get(), nullptr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void IPStackSimulator::dispatch_on_client_input(
|
||||
struct bufferevent* bev, void* ctx) {
|
||||
reinterpret_cast<IPStackSimulator*>(ctx)->on_client_input(bev);
|
||||
@@ -256,8 +231,6 @@ void IPStackSimulator::on_client_error(struct bufferevent* bev,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void IPStackSimulator::on_client_frame(
|
||||
shared_ptr<IPClient> c, const string& frame) {
|
||||
if (ip_stack_simulator_log.info("Virtual network sent frame")) {
|
||||
@@ -316,8 +289,6 @@ void IPStackSimulator::on_client_frame(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void IPStackSimulator::on_client_arp_frame(
|
||||
shared_ptr<IPClient> c, const FrameInfo& fi) {
|
||||
if (fi.arp->hwaddr_len != 6 ||
|
||||
@@ -336,7 +307,7 @@ void IPStackSimulator::on_client_arp_frame(
|
||||
}
|
||||
if (c->ipv4_addr == 0) {
|
||||
c->ipv4_addr = *reinterpret_cast<const be_uint32_t*>(
|
||||
reinterpret_cast<const uint8_t*>(fi.payload) + 6);
|
||||
reinterpret_cast<const uint8_t*>(fi.payload) + 6);
|
||||
}
|
||||
|
||||
EthernetHeader r_ether;
|
||||
@@ -388,8 +359,6 @@ void IPStackSimulator::on_client_arp_frame(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void IPStackSimulator::on_client_udp_frame(
|
||||
shared_ptr<IPClient> c, const FrameInfo& fi) {
|
||||
// We only implement the DNS server here
|
||||
@@ -459,20 +428,18 @@ void IPStackSimulator::on_client_udp_frame(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint64_t IPStackSimulator::tcp_conn_key_for_connection(
|
||||
const IPClient::TCPConnection& conn) {
|
||||
return (static_cast<uint64_t>(conn.server_addr) << 32) |
|
||||
(static_cast<uint64_t>(conn.server_port) << 16) |
|
||||
static_cast<uint64_t>(conn.client_port);
|
||||
(static_cast<uint64_t>(conn.server_port) << 16) |
|
||||
static_cast<uint64_t>(conn.client_port);
|
||||
}
|
||||
|
||||
uint64_t IPStackSimulator::tcp_conn_key_for_client_frame(
|
||||
const IPv4Header& ipv4, const TCPHeader& tcp) {
|
||||
return (static_cast<uint64_t>(ipv4.dest_addr) << 32) |
|
||||
(static_cast<uint64_t>(tcp.dest_port) << 16) |
|
||||
static_cast<uint64_t>(tcp.src_port);
|
||||
(static_cast<uint64_t>(tcp.dest_port) << 16) |
|
||||
static_cast<uint64_t>(tcp.src_port);
|
||||
}
|
||||
|
||||
uint64_t IPStackSimulator::tcp_conn_key_for_client_frame(const FrameInfo& fi) {
|
||||
@@ -482,14 +449,12 @@ uint64_t IPStackSimulator::tcp_conn_key_for_client_frame(const FrameInfo& fi) {
|
||||
return IPStackSimulator::tcp_conn_key_for_client_frame(*fi.ipv4, *fi.tcp);
|
||||
}
|
||||
|
||||
|
||||
void IPStackSimulator::on_client_tcp_frame(
|
||||
shared_ptr<IPClient> c, const FrameInfo& fi) {
|
||||
ip_stack_simulator_log.info("Virtual network sent TCP frame (seq=%08" PRIX32 ", ack=%08" PRIX32 ")",
|
||||
fi.tcp->seq_num.load(), fi.tcp->ack_num.load());
|
||||
|
||||
if (fi.tcp->flags & (TCPHeader::Flag::NS | TCPHeader::Flag::CWR |
|
||||
TCPHeader::Flag::ECE | TCPHeader::Flag::URG)) {
|
||||
if (fi.tcp->flags & (TCPHeader::Flag::NS | TCPHeader::Flag::CWR | TCPHeader::Flag::ECE | TCPHeader::Flag::URG)) {
|
||||
throw runtime_error("unsupported flag in TCP packet");
|
||||
}
|
||||
|
||||
@@ -542,7 +507,6 @@ void IPStackSimulator::on_client_tcp_frame(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint64_t key = this->tcp_conn_key_for_client_frame(fi);
|
||||
auto emplace_ret = c->tcp_connections.emplace(key, IPClient::TCPConnection());
|
||||
auto& conn = emplace_ret.first->second;
|
||||
@@ -651,17 +615,18 @@ void IPStackSimulator::on_client_tcp_frame(
|
||||
c->tcp_connections.erase(key);
|
||||
conn_valid = false;
|
||||
|
||||
// Note: The PSH flag isn't required to be set on all packets that contain
|
||||
// data. The PSH flag just means "tell the application that data is
|
||||
// available", so some senders only set the PSH flag on the last frame of a
|
||||
// large segment of data, since the application wouldn't be able to process
|
||||
// the segment until all of it is available. newserv can handle incomplete
|
||||
// commands, so we just ignore the PSH flag and forward any data to the
|
||||
// server immediately.
|
||||
// Note: The PSH flag isn't required to be set on all packets that contain
|
||||
// data. The PSH flag just means "tell the application that data is
|
||||
// available", so some senders only set the PSH flag on the last frame of a
|
||||
// large segment of data, since the application wouldn't be able to process
|
||||
// the segment until all of it is available. newserv can handle incomplete
|
||||
// commands, so we just ignore the PSH flag and forward any data to the
|
||||
// server immediately.
|
||||
} else if (fi.payload_size != 0) {
|
||||
|
||||
string conn_str = ip_stack_simulator_log.should_log(LogLevel::WARNING)
|
||||
? this->str_for_tcp_connection(c, *conn) : "";
|
||||
? this->str_for_tcp_connection(c, *conn)
|
||||
: "";
|
||||
|
||||
size_t payload_skip_bytes;
|
||||
if (fi.tcp->seq_num == conn->next_client_seq) {
|
||||
@@ -945,8 +910,6 @@ void IPStackSimulator::on_server_error(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void IPStackSimulator::log_frame(const string& data) const {
|
||||
if (this->pcap_text_log_file) {
|
||||
print_data(this->pcap_text_log_file, data, 0, nullptr,
|
||||
|
||||
+14
-16
@@ -1,18 +1,16 @@
|
||||
#include <stdint.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <deque>
|
||||
#include <string>
|
||||
#include <phosg/Process.hh>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Process.hh>
|
||||
#include <string>
|
||||
|
||||
#include "IPFrameInfo.hh"
|
||||
#include "Server.hh"
|
||||
#include "ProxyServer.hh"
|
||||
#include "Server.hh"
|
||||
#include "ServerState.hh"
|
||||
|
||||
|
||||
|
||||
class IPStackSimulator {
|
||||
public:
|
||||
IPStackSimulator(
|
||||
@@ -31,10 +29,10 @@ private:
|
||||
std::shared_ptr<struct event_base> base;
|
||||
std::shared_ptr<ServerState> state;
|
||||
|
||||
using unique_listener = std::unique_ptr<struct evconnlistener, void(*)(struct evconnlistener*)>;
|
||||
using unique_bufferevent = std::unique_ptr<struct bufferevent, void(*)(struct bufferevent*)>;
|
||||
using unique_evbuffer = std::unique_ptr<struct evbuffer, void(*)(struct evbuffer*)>;
|
||||
using unique_event = std::unique_ptr<struct event, void(*)(struct event*)>;
|
||||
using unique_listener = std::unique_ptr<struct evconnlistener, void (*)(struct evconnlistener*)>;
|
||||
using unique_bufferevent = std::unique_ptr<struct bufferevent, void (*)(struct bufferevent*)>;
|
||||
using unique_evbuffer = std::unique_ptr<struct evbuffer, void (*)(struct evbuffer*)>;
|
||||
using unique_event = std::unique_ptr<struct event, void (*)(struct event*)>;
|
||||
|
||||
struct IPClient {
|
||||
IPStackSimulator* sim;
|
||||
@@ -93,19 +91,19 @@ private:
|
||||
|
||||
static std::string str_for_ipv4_netloc(uint32_t addr, uint16_t port);
|
||||
static std::string str_for_tcp_connection(std::shared_ptr<const IPClient> c,
|
||||
const IPClient::TCPConnection& conn);
|
||||
const IPClient::TCPConnection& conn);
|
||||
|
||||
static void dispatch_on_listen_accept(struct evconnlistener* listener,
|
||||
evutil_socket_t fd, struct sockaddr *address, int socklen, void* ctx);
|
||||
evutil_socket_t fd, struct sockaddr* address, int socklen, void* ctx);
|
||||
void on_listen_accept(struct evconnlistener* listener, evutil_socket_t fd,
|
||||
struct sockaddr *address, int socklen);
|
||||
struct sockaddr* address, int socklen);
|
||||
static void dispatch_on_listen_error(struct evconnlistener* listener, void* ctx);
|
||||
void on_listen_error(struct evconnlistener* listener);
|
||||
|
||||
static void dispatch_on_client_input(struct bufferevent* bev, void* ctx);
|
||||
void on_client_input(struct bufferevent* bev);
|
||||
static void dispatch_on_client_error(struct bufferevent* bev, short events,
|
||||
void* ctx);
|
||||
void* ctx);
|
||||
void on_client_error(struct bufferevent* bev, short events);
|
||||
|
||||
void on_client_frame(std::shared_ptr<IPClient> c, const std::string& frame);
|
||||
@@ -114,13 +112,13 @@ private:
|
||||
void on_client_tcp_frame(std::shared_ptr<IPClient> c, const FrameInfo& fi);
|
||||
|
||||
static void dispatch_on_resend_push(evutil_socket_t fd, short events,
|
||||
void* ctx);
|
||||
void* ctx);
|
||||
void on_resend_push(std::shared_ptr<IPClient> c, IPClient::TCPConnection& conn);
|
||||
|
||||
static void dispatch_on_server_input(struct bufferevent* bev, void* ctx);
|
||||
void on_server_input(std::shared_ptr<IPClient> c, IPClient::TCPConnection& conn);
|
||||
static void dispatch_on_server_error(struct bufferevent* bev, short events,
|
||||
void* ctx);
|
||||
void* ctx);
|
||||
void on_server_error(std::shared_ptr<IPClient> c, IPClient::TCPConnection& conn, short events);
|
||||
|
||||
void send_pending_push_frame(
|
||||
|
||||
+1746
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,191 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "CommonItemSet.hh"
|
||||
#include "ItemParameterTable.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "RareItemSet.hh"
|
||||
#include "StaticGameData.hh"
|
||||
|
||||
struct ItemDropSub {
|
||||
uint8_t override_area;
|
||||
};
|
||||
|
||||
class ItemCreator {
|
||||
public:
|
||||
struct Restrictions {
|
||||
// Note: In the original code, this is actually the battle rules structure.
|
||||
// We omit some fields here because the item creator doesn't need them.
|
||||
enum class TechDiskMode {
|
||||
ON = 0,
|
||||
OFF = 1,
|
||||
LIMIT_LEVEL = 2,
|
||||
};
|
||||
enum class WeaponAndArmorMode {
|
||||
// Note: These names match the value names in TPlyPKEditor
|
||||
ALL_ON = 0,
|
||||
ONLY_PICKING = 1,
|
||||
ALL_OFF = 2,
|
||||
NO_RARE = 3,
|
||||
};
|
||||
enum class ToolMode {
|
||||
// Note: These names match the value names in TPlyPKEditor
|
||||
ALL_ON = 0,
|
||||
ONLY_PICKING = 1,
|
||||
ALL_OFF = 2,
|
||||
};
|
||||
enum class MesetaDropMode {
|
||||
// Note: These names match the value names in TPlyPKEditor
|
||||
ON = 0,
|
||||
OFF = 1,
|
||||
ONLY_PICKING = 2,
|
||||
};
|
||||
TechDiskMode tech_disk_mode;
|
||||
WeaponAndArmorMode weapon_and_armor_mode;
|
||||
bool forbid_mags;
|
||||
ToolMode tool_mode;
|
||||
MesetaDropMode meseta_drop_mode;
|
||||
bool forbid_scape_dolls;
|
||||
uint8_t max_tech_disk_level; // 0xFF = no maximum
|
||||
};
|
||||
|
||||
ItemCreator(
|
||||
std::shared_ptr<const CommonItemSet> common_item_set,
|
||||
std::shared_ptr<const RareItemSet> rare_item_set,
|
||||
std::shared_ptr<const ArmorRandomSet> armor_random_set,
|
||||
std::shared_ptr<const ToolRandomSet> tool_random_set,
|
||||
std::shared_ptr<const WeaponRandomSet> weapon_random_set,
|
||||
std::shared_ptr<const TekkerAdjustmentSet> tekker_adjustment_set,
|
||||
std::shared_ptr<const ItemParameterTable> item_parameter_table,
|
||||
Episode episode,
|
||||
GameMode mode,
|
||||
uint8_t difficulty,
|
||||
uint8_t section_id,
|
||||
uint32_t random_seed,
|
||||
std::shared_ptr<const Restrictions> restrictions = nullptr);
|
||||
~ItemCreator() = default;
|
||||
|
||||
ItemData on_monster_item_drop(uint32_t enemy_type, uint8_t area);
|
||||
ItemData on_box_item_drop(uint8_t area);
|
||||
ItemData on_specialized_box_item_drop(uint32_t def0, uint32_t def1, uint32_t def2);
|
||||
|
||||
std::vector<ItemData> generate_armor_shop_contents(size_t player_level);
|
||||
std::vector<ItemData> generate_tool_shop_contents(size_t player_level);
|
||||
std::vector<ItemData> generate_weapon_shop_contents(size_t player_level);
|
||||
|
||||
// This function adjusts the item in-place, and returns the luck value.
|
||||
// See the comments in TekkerAdjustmentSet for what this value means.
|
||||
ssize_t apply_tekker_deltas(ItemData& item, uint8_t section_id);
|
||||
|
||||
private:
|
||||
PrefixedLogger log;
|
||||
Episode episode;
|
||||
GameMode mode;
|
||||
uint8_t difficulty;
|
||||
uint8_t section_id;
|
||||
std::shared_ptr<const CommonItemSet> common_item_set;
|
||||
std::shared_ptr<const RareItemSet> rare_item_set;
|
||||
std::shared_ptr<const ArmorRandomSet> armor_random_set;
|
||||
std::shared_ptr<const ToolRandomSet> tool_random_set;
|
||||
std::shared_ptr<const WeaponRandomSet> weapon_random_set;
|
||||
std::shared_ptr<const TekkerAdjustmentSet> tekker_adjustment_set;
|
||||
std::shared_ptr<const ItemParameterTable> item_parameter_table;
|
||||
const CommonItemSet::Table<true>* pt;
|
||||
std::shared_ptr<const Restrictions> restrictions;
|
||||
|
||||
std::shared_ptr<ItemDropSub> item_drop_sub;
|
||||
parray<uint8_t, 0x88> unit_weights_table1;
|
||||
parray<int8_t, 0x0D> unit_weights_table2;
|
||||
|
||||
// Note: The original implementation uses 17 different random states for some
|
||||
// reason. We forego that and use only one for simplicity.
|
||||
PSOV2Encryption random_crypt;
|
||||
|
||||
bool are_rare_drops_allowed() const;
|
||||
uint8_t normalize_area_number(uint8_t area) const;
|
||||
|
||||
ItemData on_monster_item_drop_with_norm_area(
|
||||
uint32_t enemy_type, uint8_t norm_area);
|
||||
ItemData on_box_item_drop_with_norm_area(uint8_t area_norm);
|
||||
|
||||
uint32_t rand_int(uint64_t max);
|
||||
float rand_float_0_1_from_crypt();
|
||||
|
||||
template <size_t NumRanges>
|
||||
uint32_t choose_meseta_amount(
|
||||
const parray<CommonItemSet::Range<be_uint16_t>, NumRanges> ranges,
|
||||
size_t table_index);
|
||||
|
||||
bool should_allow_meseta_drops() const;
|
||||
|
||||
ItemData check_rare_spec_and_create_rare_enemy_item(uint32_t enemy_type);
|
||||
ItemData check_rare_specs_and_create_rare_box_item(uint8_t area_norm);
|
||||
ItemData check_rate_and_create_rare_item(const RareItemSet::ExpandedDrop& drop);
|
||||
|
||||
void generate_rare_weapon_bonuses(ItemData& item, uint32_t random_sample);
|
||||
void deduplicate_weapon_bonuses(ItemData& item) const;
|
||||
void set_item_kill_count_if_unsealable(ItemData& item) const;
|
||||
void set_item_unidentified_flag_if_challenge(ItemData& item) const;
|
||||
void set_tool_item_amount_to_1(ItemData& item) const;
|
||||
|
||||
void generate_common_item_variances(uint32_t norm_area, ItemData& item);
|
||||
void generate_common_armor_slots_and_bonuses(ItemData& item);
|
||||
void generate_common_armor_slot_count(ItemData& item);
|
||||
void generate_common_armor_or_shield_type_and_variances(
|
||||
char area_norm, ItemData& item);
|
||||
void generate_common_tool_variances(uint32_t area_norm, ItemData& item);
|
||||
uint8_t generate_tech_disk_level(uint32_t tech_num, uint32_t area_norm);
|
||||
void generate_common_tool_type(uint8_t tool_class, ItemData& item) const;
|
||||
void generate_common_mag_variances(ItemData& item) const;
|
||||
void generate_common_weapon_variances(uint8_t area_norm, ItemData& item);
|
||||
void generate_common_weapon_grind(ItemData& item,
|
||||
uint8_t offset_within_subtype_range);
|
||||
void generate_common_weapon_bonuses(ItemData& item, uint8_t area_norm);
|
||||
void generate_common_weapon_special(ItemData& item, uint8_t area_norm);
|
||||
uint8_t choose_weapon_special(uint8_t det);
|
||||
void generate_unit_weights_tables();
|
||||
void generate_common_unit_variances(uint8_t det, ItemData& item);
|
||||
void choose_tech_disk_level_for_tool_shop(
|
||||
ItemData& item, size_t player_level, uint8_t tech_num_index);
|
||||
static void clear_tool_item_if_invalid(ItemData& item);
|
||||
void clear_item_if_restricted(ItemData& item) const;
|
||||
|
||||
static size_t get_table_index_for_armor_shop(size_t player_level);
|
||||
static bool shop_does_not_contain_duplicate_armor(
|
||||
const std::vector<ItemData>& shop, const ItemData& item);
|
||||
static bool shop_does_not_contain_duplicate_tech_disk(
|
||||
const std::vector<ItemData>& shop, const ItemData& item);
|
||||
static bool shop_does_not_contain_duplicate_or_too_many_similar_weapons(
|
||||
const std::vector<ItemData>& shop, const ItemData& item);
|
||||
static bool shop_does_not_contain_duplicate_item_by_primary_identifier(
|
||||
const std::vector<ItemData>& shop, const ItemData& item);
|
||||
void generate_armor_shop_armors(
|
||||
std::vector<ItemData>& shop, size_t player_level);
|
||||
void generate_armor_shop_shields(
|
||||
std::vector<ItemData>& shop, size_t player_level);
|
||||
void generate_armor_shop_units(
|
||||
std::vector<ItemData>& shop, size_t player_level);
|
||||
|
||||
static size_t get_table_index_for_tool_shop(size_t player_level);
|
||||
void generate_common_tool_shop_recovery_items(
|
||||
std::vector<ItemData>& shop, size_t player_level);
|
||||
void generate_rare_tool_shop_recovery_items(
|
||||
std::vector<ItemData>& shop, size_t player_level);
|
||||
void generate_tool_shop_tech_disks(
|
||||
std::vector<ItemData>& shop, size_t player_level);
|
||||
|
||||
void generate_weapon_shop_item_grind(ItemData& item, size_t player_level);
|
||||
void generate_weapon_shop_item_special(ItemData& item, size_t player_level);
|
||||
void generate_weapon_shop_item_bonus1(ItemData& item, size_t player_level);
|
||||
void generate_weapon_shop_item_bonus2(ItemData& item, size_t player_level);
|
||||
|
||||
template <typename IntT>
|
||||
IntT get_rand_from_weighted_tables(
|
||||
const IntT* tables, size_t offset, size_t num_values, size_t stride);
|
||||
template <typename IntT, size_t X>
|
||||
IntT get_rand_from_weighted_tables_1d(const parray<IntT, X>& tables);
|
||||
template <typename IntT, size_t X, size_t Y>
|
||||
IntT get_rand_from_weighted_tables_2d_vertical(
|
||||
const parray<parray<IntT, X>, Y>& tables, size_t offset);
|
||||
};
|
||||
+1939
File diff suppressed because it is too large
Load Diff
+151
@@ -0,0 +1,151 @@
|
||||
#pragma once
|
||||
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <string>
|
||||
|
||||
#include "Text.hh"
|
||||
|
||||
constexpr uint32_t MESETA_IDENTIFIER = 0x00040000;
|
||||
|
||||
struct ItemMagStats {
|
||||
uint16_t iq;
|
||||
uint16_t synchro;
|
||||
uint16_t def;
|
||||
uint16_t pow;
|
||||
uint16_t dex;
|
||||
uint16_t mind;
|
||||
uint8_t flags;
|
||||
uint8_t photon_blasts;
|
||||
uint8_t color;
|
||||
|
||||
ItemMagStats()
|
||||
: iq(0),
|
||||
synchro(40),
|
||||
def(500),
|
||||
pow(0),
|
||||
dex(0),
|
||||
mind(0),
|
||||
flags(0),
|
||||
photon_blasts(0),
|
||||
color(14) {}
|
||||
|
||||
inline uint16_t def_level() const {
|
||||
return this->def / 100;
|
||||
}
|
||||
inline uint16_t pow_level() const {
|
||||
return this->pow / 100;
|
||||
}
|
||||
inline uint16_t dex_level() const {
|
||||
return this->dex / 100;
|
||||
}
|
||||
inline uint16_t mind_level() const {
|
||||
return this->mind / 100;
|
||||
}
|
||||
inline uint16_t level() const {
|
||||
return this->def_level() + this->pow_level() + this->dex_level() + this->mind_level();
|
||||
}
|
||||
};
|
||||
|
||||
struct ItemData { // 0x14 bytes
|
||||
// QUICK ITEM FORMAT REFERENCE
|
||||
// data1/0 data1/4 data1/8 data2
|
||||
// Weapon: 00ZZZZGG SS00AABB AABBAABB 00000000
|
||||
// Armor: 0101ZZ00 FFTTDDDD EEEE0000 00000000
|
||||
// Shield: 0102ZZ00 FFTTDDDD EEEE0000 00000000
|
||||
// Unit: 0103ZZ00 FF0000RR RR000000 00000000
|
||||
// Mag: 02ZZLLWW HHHHIIII JJJJKKKK YYQQPPVV
|
||||
// Tool: 03ZZZZFF 00CC0000 00000000 00000000
|
||||
// Meseta: 04000000 00000000 00000000 MMMMMMMM
|
||||
// A = attribute type (for S-ranks, custom name)
|
||||
// B = attribute amount (for S-ranks, custom name)
|
||||
// C = stack size (for tools)
|
||||
// D = DEF bonus
|
||||
// E = EVP bonus
|
||||
// F = flags (40=present; for tools, unused if item is stackable)
|
||||
// G = weapon grind
|
||||
// H = mag DEF
|
||||
// I = mag POW
|
||||
// J = mag DEX
|
||||
// K = mag MIND
|
||||
// L = mag level
|
||||
// M = meseta amount
|
||||
// P = mag flags (40=present, 04=has left pb, 02=has right pb, 01=has center pb)
|
||||
// Q = mag IQ
|
||||
// R = unit modifier (little-endian)
|
||||
// S = weapon flags (80=unidentified, 40=present) and special (low 6 bits)
|
||||
// T = slot count
|
||||
// V = mag color
|
||||
// W = photon blasts
|
||||
// Y = mag synchro
|
||||
// Z = item ID
|
||||
// Note: PSO GC erroneously byteswaps data2 even when the item is a mag. This
|
||||
// makes it incompatible with little-endian versions of PSO (i.e. all other
|
||||
// versions). We manually byteswap data2 upon receipt and immediately before
|
||||
// sending where needed.
|
||||
|
||||
union {
|
||||
parray<uint8_t, 12> data1;
|
||||
parray<le_uint16_t, 6> data1w;
|
||||
parray<le_uint32_t, 3> data1d;
|
||||
} __attribute__((packed));
|
||||
le_uint32_t id;
|
||||
union {
|
||||
parray<uint8_t, 4> data2;
|
||||
parray<le_uint16_t, 2> data2w;
|
||||
le_uint32_t data2d;
|
||||
} __attribute__((packed));
|
||||
|
||||
ItemData();
|
||||
explicit ItemData(const std::string& orig_description, bool allow_raw_data = true);
|
||||
ItemData(const ItemData& other);
|
||||
ItemData& operator=(const ItemData& other);
|
||||
|
||||
void parse(const std::string& desc, bool skip_specials);
|
||||
|
||||
bool operator==(const ItemData& other) const;
|
||||
bool operator!=(const ItemData& other) const;
|
||||
|
||||
void clear();
|
||||
|
||||
void bswap_data2_if_mag();
|
||||
|
||||
std::string hex() const;
|
||||
std::string name(bool include_color_codes) const;
|
||||
uint32_t primary_identifier() const;
|
||||
|
||||
bool is_wrapped() const;
|
||||
void unwrap();
|
||||
|
||||
bool is_stackable() const;
|
||||
size_t stack_size() const;
|
||||
size_t max_stack_size() const;
|
||||
|
||||
static bool is_common_consumable(uint32_t primary_identifier);
|
||||
bool is_common_consumable() const;
|
||||
|
||||
void assign_mag_stats(const ItemMagStats& mag);
|
||||
void clear_mag_stats();
|
||||
uint16_t compute_mag_level() const;
|
||||
uint16_t compute_mag_strength_flags() const;
|
||||
uint8_t mag_photon_blast_for_slot(uint8_t slot) const;
|
||||
bool mag_has_photon_blast_in_any_slot(uint8_t pb_num) const;
|
||||
void add_mag_photon_blast(uint8_t pb_num);
|
||||
|
||||
uint16_t get_sealed_item_kill_count() const;
|
||||
void set_sealed_item_kill_count(uint16_t v);
|
||||
uint8_t get_tool_item_amount() const;
|
||||
void set_tool_item_amount(uint8_t amount);
|
||||
int16_t get_armor_or_shield_defense_bonus() const;
|
||||
void set_armor_or_shield_defense_bonus(int16_t bonus);
|
||||
int16_t get_common_armor_evasion_bonus() const;
|
||||
void set_common_armor_evasion_bonus(int16_t bonus);
|
||||
int16_t get_unit_bonus() const;
|
||||
void set_unit_bonus(int16_t bonus);
|
||||
|
||||
bool has_bonuses() const;
|
||||
bool is_s_rank_weapon() const;
|
||||
|
||||
bool empty() const;
|
||||
|
||||
static bool compare_for_sort(const ItemData& a, const ItemData& b);
|
||||
} __attribute__((packed));
|
||||
@@ -0,0 +1,383 @@
|
||||
#include "ItemParameterTable.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
ItemParameterTable::ItemParameterTable(shared_ptr<const string> data)
|
||||
: data(data),
|
||||
r(*data) {
|
||||
size_t offset_table_offset = this->r.pget_u32l(this->data->size() - 0x10);
|
||||
this->offsets = &r.pget<TableOffsets>(offset_table_offset);
|
||||
}
|
||||
|
||||
const ItemParameterTable::Weapon& ItemParameterTable::get_weapon(
|
||||
uint8_t data1_1, uint8_t data1_2) const {
|
||||
if (data1_1 >= 0xED) {
|
||||
throw runtime_error("weapon ID out of range");
|
||||
}
|
||||
const auto& co = this->r.pget<CountAndOffset>(
|
||||
this->offsets->weapon_table + sizeof(CountAndOffset) * data1_1);
|
||||
if (data1_2 >= co.count) {
|
||||
throw runtime_error("weapon ID out of range");
|
||||
}
|
||||
return this->r.pget<Weapon>(co.offset + sizeof(Weapon) * data1_2);
|
||||
}
|
||||
|
||||
const ItemParameterTable::ArmorOrShield& ItemParameterTable::get_armor_or_shield(
|
||||
uint8_t data1_1, uint8_t data1_2) const {
|
||||
if ((data1_1 < 1) || (data1_1 > 2)) {
|
||||
throw runtime_error("armor/shield ID out of range");
|
||||
}
|
||||
const auto& co = this->r.pget<CountAndOffset>(
|
||||
this->offsets->armor_table + sizeof(CountAndOffset) * (data1_1 - 1));
|
||||
if (data1_2 >= co.count) {
|
||||
throw runtime_error("armor/shield ID out of range");
|
||||
}
|
||||
return this->r.pget<ArmorOrShield>(co.offset + sizeof(ArmorOrShield) * data1_2);
|
||||
}
|
||||
|
||||
const ItemParameterTable::Unit& ItemParameterTable::get_unit(
|
||||
uint8_t data1_2) const {
|
||||
const auto& co = this->r.pget<CountAndOffset>(this->offsets->unit_table);
|
||||
if (data1_2 >= co.count) {
|
||||
throw runtime_error("unit ID out of range");
|
||||
}
|
||||
return this->r.pget<Unit>(co.offset + sizeof(Unit) * data1_2);
|
||||
}
|
||||
|
||||
const ItemParameterTable::Tool& ItemParameterTable::get_tool(
|
||||
uint8_t data1_1, uint8_t data1_2) const {
|
||||
if (data1_1 > 0x1A) {
|
||||
throw runtime_error("tool ID out of range");
|
||||
}
|
||||
const auto& co = this->r.pget<CountAndOffset>(
|
||||
this->offsets->tool_table + sizeof(CountAndOffset) * data1_1);
|
||||
if (data1_2 >= co.count) {
|
||||
throw runtime_error("tool ID out of range");
|
||||
}
|
||||
return this->r.pget<Tool>(co.offset + sizeof(Tool) * data1_2);
|
||||
}
|
||||
|
||||
pair<uint8_t, uint8_t> ItemParameterTable::find_tool_by_class(
|
||||
uint8_t tool_class) const {
|
||||
const auto& cos = this->r.pget<parray<CountAndOffset, 0x18>>(
|
||||
this->offsets->tool_table);
|
||||
for (size_t z = 0; z < cos.size(); z++) {
|
||||
const auto& co = cos[z];
|
||||
const auto* defs = &this->r.pget<Tool>(co.offset, sizeof(Tool) * co.count);
|
||||
for (size_t y = 0; y < co.count; y++) {
|
||||
if (defs[y].base.id == tool_class) {
|
||||
return make_pair(z, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw runtime_error("invalid tool class");
|
||||
}
|
||||
|
||||
const ItemParameterTable::Mag& ItemParameterTable::get_mag(
|
||||
uint8_t data1_1) const {
|
||||
const auto& co = this->r.pget<CountAndOffset>(this->offsets->mag_table);
|
||||
if (data1_1 >= co.count) {
|
||||
throw runtime_error("unit ID out of range");
|
||||
}
|
||||
return this->r.pget<Mag>(co.offset + sizeof(Mag) * data1_1);
|
||||
}
|
||||
|
||||
float ItemParameterTable::get_sale_divisor(uint8_t data1_0, uint8_t data1_1) const {
|
||||
if (data1_0 == 0) { // Weapon
|
||||
if (data1_1 < 0xED) {
|
||||
return this->r.pget_f32l(
|
||||
this->offsets->weapon_sale_divisor_table + data1_1 * sizeof(float));
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
const auto& divisors = this->r.pget<NonWeaponSaleDivisors>(
|
||||
this->offsets->sale_divisor_table);
|
||||
if (data1_0 == 1) {
|
||||
switch (data1_1) {
|
||||
case 1:
|
||||
return divisors.armor_divisor;
|
||||
case 2:
|
||||
return divisors.shield_divisor;
|
||||
case 3:
|
||||
return divisors.unit_divisor;
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
if (data1_0 == 2) {
|
||||
return divisors.mag_divisor;
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
const ItemParameterTable::MagFeedResult& ItemParameterTable::get_mag_feed_result(
|
||||
uint8_t table_index, uint8_t item_index) const {
|
||||
if (table_index >= 8) {
|
||||
throw runtime_error("invalid mag feed table index");
|
||||
}
|
||||
if (item_index >= 11) {
|
||||
throw runtime_error("invalid mag feed item index");
|
||||
}
|
||||
const auto& table_offsets = this->r.pget<MagFeedResultsListOffsets>(this->offsets->mag_feed_table);
|
||||
const auto& results = this->r.pget<MagFeedResultsList>(table_offsets.offsets[table_index]);
|
||||
return results.results[item_index];
|
||||
}
|
||||
|
||||
uint8_t ItemParameterTable::get_item_stars(uint16_t slot) const {
|
||||
if ((slot >= 0xB1) && (slot < 0x437)) {
|
||||
return this->r.pget_u8(this->offsets->star_value_table + slot - 0xB1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t ItemParameterTable::get_special_stars(uint8_t det) const {
|
||||
if (!(det & 0x3F) || (det & 0x80)) {
|
||||
return 0;
|
||||
}
|
||||
// Note: PSO GC uses 0x1CB here. 0x256 was chosen to point to the same data in
|
||||
// PSO BB's ItemPMT file.
|
||||
return this->get_item_stars(det + 0x0256);
|
||||
}
|
||||
|
||||
const ItemParameterTable::Special& ItemParameterTable::get_special(uint8_t special) const {
|
||||
special &= 0x3F;
|
||||
if (special >= 0x29) {
|
||||
throw runtime_error("invalid special index");
|
||||
}
|
||||
return this->r.pget<Special>(this->offsets->special_data_table + sizeof(Special) * special);
|
||||
}
|
||||
|
||||
uint8_t ItemParameterTable::get_max_tech_level(uint8_t char_class, uint8_t tech_num) const {
|
||||
if (char_class >= 12) {
|
||||
throw runtime_error("invalid character class");
|
||||
}
|
||||
if (tech_num >= 19) {
|
||||
throw runtime_error("invalid technique number");
|
||||
}
|
||||
return r.pget_u8(this->offsets->max_tech_level_table + tech_num * 12 + char_class);
|
||||
}
|
||||
|
||||
const ItemParameterTable::ItemBase& ItemParameterTable::get_item_definition(
|
||||
const ItemData& item) const {
|
||||
switch (item.data1[0]) {
|
||||
case 0:
|
||||
return this->get_weapon(item.data1[1], item.data1[2]).base;
|
||||
case 1:
|
||||
if (item.data1[1] == 3) {
|
||||
return this->get_unit(item.data1[2]).base;
|
||||
} else if ((item.data1[1] == 1) || (item.data1[1] == 2)) {
|
||||
return this->get_armor_or_shield(item.data1[1], item.data1[2]).base;
|
||||
}
|
||||
throw runtime_error("invalid item");
|
||||
case 2:
|
||||
return this->get_mag(item.data1[1]).base;
|
||||
case 3:
|
||||
if (item.data1[1] == 2) {
|
||||
return this->get_tool(2, item.data1[4]).base;
|
||||
} else {
|
||||
return this->get_tool(item.data1[1], item.data1[2]).base;
|
||||
}
|
||||
throw logic_error("this should be impossible");
|
||||
case 4:
|
||||
throw runtime_error("item is meseta and therefore has no definition");
|
||||
default:
|
||||
throw runtime_error("invalid item");
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ItemParameterTable::get_item_base_stars(const ItemData& item) const {
|
||||
if (item.data1[0] == 2) {
|
||||
return (item.data1[1] > 0x27) ? 12 : 0;
|
||||
} else if (item.data1[0] < 2) {
|
||||
return this->get_item_stars(this->get_item_definition(item).id);
|
||||
} else if (item.data1[0] == 3) {
|
||||
const auto& def = (item.data1[1] == 2)
|
||||
? this->get_tool(2, item.data1[4])
|
||||
: this->get_tool(item.data1[1], item.data1[2]);
|
||||
return (def.item_flag & 0x80) ? 12 : 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ItemParameterTable::get_item_adjusted_stars(const ItemData& item) const {
|
||||
uint8_t ret = this->get_item_base_stars(item);
|
||||
if (item.data1[0] == 0) {
|
||||
if (ret < 9) {
|
||||
if (!(item.data1[4] & 0x80)) {
|
||||
ret += this->get_special_stars(item.data1[4]);
|
||||
}
|
||||
} else if (item.data1[4] & 0x80) {
|
||||
ret = 0;
|
||||
}
|
||||
} else if (item.data1[0] == 1) {
|
||||
if (item.data1[1] == 3) {
|
||||
int16_t unit_bonus = item.get_unit_bonus();
|
||||
if (unit_bonus < 0) {
|
||||
ret--;
|
||||
} else if (unit_bonus > 0) {
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return min<uint8_t>(ret, 12);
|
||||
}
|
||||
|
||||
bool ItemParameterTable::is_item_rare(const ItemData& item) const {
|
||||
return (this->get_item_base_stars(item) >= 9);
|
||||
}
|
||||
|
||||
bool ItemParameterTable::is_unsealable_item(const ItemData& item) const {
|
||||
const auto& co = this->r.pget<CountAndOffset>(this->offsets->unsealable_table);
|
||||
const auto* defs = &this->r.pget<UnsealableItem>(
|
||||
co.offset, co.count * sizeof(UnsealableItem));
|
||||
for (size_t z = 0; z < co.count; z++) {
|
||||
if ((defs[z].item[0] == item.data1[0]) &&
|
||||
(defs[z].item[1] == item.data1[1]) &&
|
||||
(defs[z].item[2] == item.data1[2])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ItemParameterTable::populate_item_combination_index() const {
|
||||
if (!this->item_combination_index.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& co = this->r.pget<CountAndOffset>(this->offsets->combination_table);
|
||||
const auto* defs = &this->r.pget<ItemCombination>(
|
||||
co.offset, co.count * sizeof(ItemCombination));
|
||||
for (size_t z = 0; z < co.count; z++) {
|
||||
const auto& def = defs[z];
|
||||
uint32_t key = (def.used_item[0] << 16) | (def.used_item[1] << 8) | def.used_item[2];
|
||||
this->item_combination_index[key].emplace_back(def);
|
||||
}
|
||||
}
|
||||
|
||||
const ItemParameterTable::ItemCombination& ItemParameterTable::get_item_combination(
|
||||
const ItemData& used_item, const ItemData& equipped_item) const {
|
||||
for (const auto& def : this->get_all_combinations_for_used_item(used_item)) {
|
||||
if ((def.equipped_item[0] == 0xFF || def.equipped_item[0] == equipped_item.data1[0]) &&
|
||||
(def.equipped_item[1] == 0xFF || def.equipped_item[1] == equipped_item.data1[1]) &&
|
||||
(def.equipped_item[2] == 0xFF || def.equipped_item[2] == equipped_item.data1[2])) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
throw out_of_range("no item combination applies");
|
||||
}
|
||||
|
||||
const std::vector<ItemParameterTable::ItemCombination>& ItemParameterTable::get_all_combinations_for_used_item(
|
||||
const ItemData& used_item) const {
|
||||
try {
|
||||
uint32_t key = (used_item.data1[0] << 16) | (used_item.data1[1] << 8) | used_item.data1[2];
|
||||
return this->get_all_item_combinations().at(key);
|
||||
} catch (const out_of_range&) {
|
||||
static const vector<ItemCombination> ret;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
const std::map<uint32_t, std::vector<ItemParameterTable::ItemCombination>>& ItemParameterTable::get_all_item_combinations() const {
|
||||
this->populate_item_combination_index();
|
||||
return this->item_combination_index;
|
||||
}
|
||||
|
||||
std::pair<const ItemParameterTable::EventItem*, size_t> ItemParameterTable::get_event_items(uint8_t event_number) const {
|
||||
const auto& co = this->r.pget<CountAndOffset>(this->offsets->unwrap_table);
|
||||
if (event_number >= co.count) {
|
||||
throw runtime_error("invalid event number");
|
||||
}
|
||||
const auto& event_co = this->r.pget<CountAndOffset>(co.offset + sizeof(CountAndOffset) * event_number);
|
||||
const auto* defs = &this->r.pget<EventItem>(event_co.offset, event_co.count * sizeof(ItemCombination));
|
||||
return make_pair(defs, event_co.count);
|
||||
}
|
||||
|
||||
size_t ItemParameterTable::price_for_item(const ItemData& item) const {
|
||||
switch (item.data1[0]) {
|
||||
case 0: {
|
||||
if (item.data1[4] & 0x80) {
|
||||
return 8;
|
||||
}
|
||||
if (this->is_item_rare(item)) {
|
||||
return 80;
|
||||
}
|
||||
|
||||
float sale_divisor = this->get_sale_divisor(item.data1[0], item.data1[1]);
|
||||
if (sale_divisor == 0.0) {
|
||||
throw runtime_error("item sale divisor is zero");
|
||||
}
|
||||
|
||||
const auto& def = this->get_weapon(item.data1[1], item.data1[2]);
|
||||
double atp_max = def.atp_max + item.data1[3];
|
||||
double atp_factor = ((atp_max * atp_max) / sale_divisor);
|
||||
|
||||
double bonus_factor = 0.0;
|
||||
for (size_t bonus_index = 0; bonus_index < 3; bonus_index++) {
|
||||
uint8_t bonus_type = item.data1[(2 * bonus_index) + 6];
|
||||
if ((bonus_type > 0) && (bonus_type < 6)) {
|
||||
bonus_factor += item.data1[(2 * bonus_index) + 7];
|
||||
}
|
||||
bonus_factor += 100.0;
|
||||
}
|
||||
|
||||
size_t special_stars = this->get_special_stars(item.data1[4]);
|
||||
double special_stars_factor = 1000.0 * special_stars * special_stars;
|
||||
|
||||
return special_stars_factor + ((atp_factor * bonus_factor) / 100.0);
|
||||
}
|
||||
|
||||
case 1: {
|
||||
if (this->is_item_rare(item)) {
|
||||
return 80;
|
||||
}
|
||||
|
||||
if (item.data1[1] == 3) { // Unit
|
||||
return this->get_item_adjusted_stars(item) * this->get_sale_divisor(item.data1[0], 3);
|
||||
}
|
||||
|
||||
double sale_divisor = (double)this->get_sale_divisor(item.data1[0], item.data1[1]);
|
||||
if (sale_divisor == 0.0) {
|
||||
throw runtime_error("item sale divisor is zero");
|
||||
}
|
||||
|
||||
int16_t def_bonus = item.get_armor_or_shield_defense_bonus();
|
||||
int16_t evp_bonus = item.get_common_armor_evasion_bonus();
|
||||
|
||||
const auto& def = this->get_armor_or_shield(item.data1[1], item.data1[2]);
|
||||
double power_factor = def.dfp + def.evp + def_bonus + evp_bonus;
|
||||
double power_factor_floor = static_cast<int32_t>((power_factor * power_factor) / sale_divisor);
|
||||
return power_factor_floor + (70.0 * static_cast<double>(item.data1[5] + 1) * static_cast<double>(def.required_level + 1));
|
||||
}
|
||||
|
||||
case 2:
|
||||
return (item.data1[2] + 1) * this->get_sale_divisor(2, item.data1[1]);
|
||||
|
||||
case 3: {
|
||||
const auto& def = this->get_tool(item.data1[1], item.data1[2]);
|
||||
return def.cost * ((item.data1[1] == 2) ? (item.data1[2] + 1) : 1);
|
||||
}
|
||||
|
||||
case 4:
|
||||
return item.data2d;
|
||||
|
||||
default:
|
||||
throw runtime_error("invalid item");
|
||||
}
|
||||
throw logic_error("this should be impossible");
|
||||
}
|
||||
|
||||
MagEvolutionTable::MagEvolutionTable(shared_ptr<const string> data)
|
||||
: data(data),
|
||||
r(*data) {
|
||||
size_t offset_table_offset = this->r.pget_u32l(this->data->size() - 0x10);
|
||||
this->offsets = &r.pget<TableOffsets>(offset_table_offset);
|
||||
}
|
||||
|
||||
uint8_t MagEvolutionTable::get_evolution_number(uint8_t data1_1) const {
|
||||
const auto& table = this->r.pget<EvolutionNumberTable>(this->offsets->evolution_number);
|
||||
return table.values[data1_1];
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ItemData.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
class ItemParameterTable {
|
||||
public:
|
||||
struct CountAndOffset {
|
||||
le_uint32_t count;
|
||||
le_uint32_t offset;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct ItemBase {
|
||||
le_uint32_t id;
|
||||
le_uint16_t type;
|
||||
le_uint16_t skin;
|
||||
le_uint32_t team_points;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct ArmorOrShield {
|
||||
ItemBase base;
|
||||
le_uint16_t dfp;
|
||||
le_uint16_t evp;
|
||||
uint8_t block_particle;
|
||||
uint8_t block_effect;
|
||||
uint8_t item_class;
|
||||
uint8_t unknown_a1;
|
||||
uint8_t required_level;
|
||||
uint8_t efr;
|
||||
uint8_t eth;
|
||||
uint8_t eic;
|
||||
uint8_t edk;
|
||||
uint8_t elt;
|
||||
uint8_t dfp_range;
|
||||
uint8_t evp_range;
|
||||
uint8_t stat_boost;
|
||||
uint8_t tech_boost;
|
||||
le_uint16_t unknown_a2;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Unit {
|
||||
ItemBase base;
|
||||
le_uint16_t stat;
|
||||
le_uint16_t stat_amount;
|
||||
le_int16_t modifier_amount;
|
||||
parray<uint8_t, 2> unused;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Mag {
|
||||
ItemBase base;
|
||||
le_uint16_t feed_table;
|
||||
uint8_t photon_blast;
|
||||
uint8_t activation;
|
||||
uint8_t on_pb_full;
|
||||
uint8_t on_low_hp;
|
||||
uint8_t on_death;
|
||||
uint8_t on_boss;
|
||||
uint8_t on_pb_full_flag;
|
||||
uint8_t on_low_hp_flag;
|
||||
uint8_t on_death_flag;
|
||||
uint8_t on_boss_flag;
|
||||
uint8_t item_class;
|
||||
parray<uint8_t, 3> unused;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Tool {
|
||||
ItemBase base;
|
||||
le_uint16_t amount;
|
||||
le_uint16_t tech;
|
||||
le_int32_t cost;
|
||||
uint8_t item_flag;
|
||||
parray<uint8_t, 3> unused;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Weapon {
|
||||
ItemBase base;
|
||||
uint8_t item_class;
|
||||
uint8_t unknown_a0;
|
||||
le_uint16_t atp_min;
|
||||
le_uint16_t atp_max;
|
||||
le_uint16_t atp_required;
|
||||
le_uint16_t mst_required;
|
||||
le_uint16_t ata_required;
|
||||
le_uint16_t mst;
|
||||
uint8_t max_grind;
|
||||
uint8_t photon;
|
||||
uint8_t special;
|
||||
uint8_t ata;
|
||||
uint8_t stat_boost;
|
||||
uint8_t projectile;
|
||||
int8_t trail1_x;
|
||||
int8_t trail1_y;
|
||||
int8_t trail2_x;
|
||||
int8_t trail2_y;
|
||||
int8_t color;
|
||||
uint8_t unknown_a1;
|
||||
uint8_t unknown_a2;
|
||||
uint8_t unknown_a3;
|
||||
uint8_t unknown_a4;
|
||||
uint8_t unknown_a5;
|
||||
uint8_t tech_boost;
|
||||
uint8_t combo_type;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct MagFeedResult {
|
||||
int8_t def;
|
||||
int8_t pow;
|
||||
int8_t dex;
|
||||
int8_t mind;
|
||||
int8_t iq;
|
||||
int8_t synchro;
|
||||
parray<uint8_t, 2> unused;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct MagFeedResultsList {
|
||||
parray<MagFeedResult, 11> results;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct MagFeedResultsListOffsets {
|
||||
parray<le_uint32_t, 8> offsets; // Offsets of MagFeedResultsList structs
|
||||
} __attribute__((packed));
|
||||
|
||||
struct ItemStarValue {
|
||||
uint8_t num_stars;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Special {
|
||||
le_uint16_t type;
|
||||
le_uint16_t amount;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct StatBoost {
|
||||
uint8_t stat1;
|
||||
uint8_t stat2;
|
||||
le_uint16_t amount1;
|
||||
le_uint16_t amount2;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct MaxTechniqueLevels {
|
||||
// Indexed as [tech_num][char_class]
|
||||
parray<parray<uint8_t, 12>, 19> max_level;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct ItemCombination {
|
||||
parray<uint8_t, 3> used_item;
|
||||
parray<uint8_t, 3> equipped_item;
|
||||
parray<uint8_t, 3> result_item;
|
||||
uint8_t mag_level;
|
||||
uint8_t grind;
|
||||
uint8_t level;
|
||||
uint8_t char_class;
|
||||
parray<uint8_t, 3> unused;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct TechniqueBoost {
|
||||
le_uint32_t tech1;
|
||||
le_float boost1;
|
||||
le_uint32_t tech2;
|
||||
le_float boost2;
|
||||
le_uint32_t tech3;
|
||||
le_float boost3;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct EventItem {
|
||||
parray<uint8_t, 3> item;
|
||||
uint8_t probability;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct UnsealableItem {
|
||||
parray<uint8_t, 3> item;
|
||||
uint8_t unused;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct NonWeaponSaleDivisors {
|
||||
le_float armor_divisor;
|
||||
le_float shield_divisor;
|
||||
le_float unit_divisor;
|
||||
le_float mag_divisor;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct TableOffsets {
|
||||
/* 00 / 14884 */ le_uint32_t weapon_table; // -> [{count, offset -> [Weapon]}](0xED)
|
||||
/* 04 / 1478C */ le_uint32_t armor_table; // -> [{count, offset -> [ArmorOrShield]}](2; armors and shields)
|
||||
/* 08 / 1479C */ le_uint32_t unit_table; // -> {count, offset -> [Unit]} (last if out of range)
|
||||
/* 0C / 147AC */ le_uint32_t tool_table; // -> [{count, offset -> [Tool]}](0x1A) (last if out of range)
|
||||
/* 10 / 147A4 */ le_uint32_t mag_table; // -> {count, offset -> [Mag]}
|
||||
/* 14 / 0F4B8 */ le_uint32_t attack_animation_table; // -> [uint8_t](0xED)
|
||||
/* 18 / 0DE7C */ le_uint32_t photon_color_table; // -> [0x24-byte structs](0x20)
|
||||
/* 1C / 0E194 */ le_uint32_t weapon_range_table; // -> ???
|
||||
/* 20 / 0F5A8 */ le_uint32_t weapon_sale_divisor_table; // -> [float](0xED)
|
||||
/* 24 / 0F83C */ le_uint32_t sale_divisor_table; // -> NonWeaponSaleDivisors
|
||||
/* 28 / 1502C */ le_uint32_t mag_feed_table; // -> MagFeedResultsTable
|
||||
/* 2C / 0FB0C */ le_uint32_t star_value_table; // -> [uint8_t] (indexed by .id from weapon, armor, etc.)
|
||||
/* 30 / 0FE3C */ le_uint32_t special_data_table; // -> [Special]
|
||||
/* 34 / 0FEE0 */ le_uint32_t weapon_effect_table; // -> [16-byte structs]
|
||||
/* 38 / 1275C */ le_uint32_t stat_boost_table; // -> [StatBoost]
|
||||
/* 3C / 11C80 */ le_uint32_t shield_effect_table; // -> [8-byte structs]
|
||||
/* 40 / 12894 */ le_uint32_t max_tech_level_table; // -> MaxTechniqueLevels
|
||||
/* 44 / 14FF4 */ le_uint32_t combination_table; // -> {count, offset -> [ItemCombination]}
|
||||
/* 48 / 12754 */ le_uint32_t unknown_a1;
|
||||
/* 4C / 14278 */ le_uint32_t tech_boost_table; // -> [TechniqueBoost] (always 0x2C of them? from counts struct?)
|
||||
/* 50 / 15014 */ le_uint32_t unwrap_table; // -> {count, offset -> [{count, offset -> [EventItem]}]}
|
||||
/* 54 / 1501C */ le_uint32_t unsealable_table; // -> {count, offset -> [UnsealableItem]}
|
||||
/* 58 / 15024 */ le_uint32_t ranged_special_table; // -> {count, offset -> [4-byte structs]}
|
||||
} __attribute__((packed));
|
||||
|
||||
ItemParameterTable(std::shared_ptr<const std::string> data);
|
||||
~ItemParameterTable() = default;
|
||||
|
||||
const Weapon& get_weapon(uint8_t data1_1, uint8_t data1_2) const;
|
||||
const ArmorOrShield& get_armor_or_shield(uint8_t data1_1, uint8_t data1_2) const;
|
||||
const Unit& get_unit(uint8_t data1_2) const;
|
||||
const Tool& get_tool(uint8_t data1_1, uint8_t data1_2) const;
|
||||
std::pair<uint8_t, uint8_t> find_tool_by_class(uint8_t tool_class) const;
|
||||
const Mag& get_mag(uint8_t data1_1) const;
|
||||
float get_sale_divisor(uint8_t data1_0, uint8_t data1_1) const;
|
||||
const MagFeedResult& get_mag_feed_result(uint8_t table_index, uint8_t which) const;
|
||||
uint8_t get_item_stars(uint16_t slot) const;
|
||||
uint8_t get_special_stars(uint8_t det) const;
|
||||
const Special& get_special(uint8_t special) const;
|
||||
uint8_t get_max_tech_level(uint8_t char_class, uint8_t tech_num) const;
|
||||
|
||||
const ItemBase& get_item_definition(const ItemData& item) const;
|
||||
uint8_t get_item_base_stars(const ItemData& item) const;
|
||||
uint8_t get_item_adjusted_stars(const ItemData& item) const;
|
||||
bool is_item_rare(const ItemData& item) const;
|
||||
bool is_unsealable_item(const ItemData& param_1) const;
|
||||
const ItemCombination& get_item_combination(const ItemData& used_item, const ItemData& equipped_item) const;
|
||||
const std::vector<ItemCombination>& get_all_combinations_for_used_item(const ItemData& used_item) const;
|
||||
const std::map<uint32_t, std::vector<ItemCombination>>& get_all_item_combinations() const;
|
||||
std::pair<const EventItem*, size_t> get_event_items(uint8_t event_number) const;
|
||||
|
||||
size_t price_for_item(const ItemData& item) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<const std::string> data;
|
||||
StringReader r;
|
||||
const TableOffsets* offsets;
|
||||
|
||||
// Key is used_item. We can't index on (used_item, equipped_item) because
|
||||
// equipped_item may contain wildcards, and the matching order matters.
|
||||
void populate_item_combination_index() const;
|
||||
mutable std::map<uint32_t, std::vector<ItemCombination>> item_combination_index;
|
||||
};
|
||||
|
||||
class MagEvolutionTable {
|
||||
public:
|
||||
struct TableOffsets {
|
||||
/* 00 / 0400 */ le_uint32_t unknown_a1; // -> [offset -> (0xC-byte struct)[0x53], offset -> (same as first offset)]
|
||||
/* 04 / 0408 */ le_uint32_t unknown_a2; // -> (2-byte struct, or single word)[0x53]
|
||||
/* 08 / 04AE */ le_uint32_t unknown_a3; // -> (0xA8 bytes; possibly (8-byte struct)[0x15])
|
||||
/* 0C / 0556 */ le_uint32_t unknown_a4; // -> (uint8_t)[0x53]
|
||||
/* 10 / 05AC */ le_uint32_t unknown_a5; // -> (float)[0x48]
|
||||
/* 14 / 06CC */ le_uint32_t evolution_number; // -> (uint8_t)[0x53]
|
||||
} __attribute__((packed));
|
||||
|
||||
struct EvolutionNumberTable {
|
||||
parray<uint8_t, 0x53> values;
|
||||
} __attribute__((packed));
|
||||
|
||||
MagEvolutionTable(std::shared_ptr<const std::string> data);
|
||||
~MagEvolutionTable() = default;
|
||||
|
||||
uint8_t get_evolution_number(uint8_t data1_1) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<const std::string> data;
|
||||
StringReader r;
|
||||
const TableOffsets* offsets;
|
||||
};
|
||||
+384
-536
@@ -4,204 +4,52 @@
|
||||
|
||||
#include <phosg/Random.hh>
|
||||
|
||||
#include "SendCommands.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
uint32_t random_int(shared_ptr<mt19937> rand, uint32_t min, uint32_t max) {
|
||||
uint32_t range = max - min + 1;
|
||||
return min + ((*rand)() % range);
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* these items all need some kind of special handling that hasn't been implemented yet.
|
||||
|
||||
030B04 = TP Material (?)
|
||||
030C00 = Cell Of MAG 502
|
||||
030C01 = Cell Of MAG 213
|
||||
030C02 = Parts Of RoboChao
|
||||
030C03 = Heart Of Opa Opa
|
||||
030C04 = Heart Of Pian
|
||||
030C05 = Heart Of Chao
|
||||
|
||||
030D00 = Sorcerer's Right Arm
|
||||
030D01 = S-beat's Arms
|
||||
030D02 = P-arm's Arms
|
||||
030D03 = Delsaber's Right Arm
|
||||
030D04 = C-bringer's Right Arm
|
||||
030D05 = Delsaber's Left Arm
|
||||
030D06 = S-red's Arms
|
||||
030D07 = Dragon's Claw
|
||||
030D08 = Hildebear's Head
|
||||
030D09 = Hildeblue's Head
|
||||
030D0A = Parts of Baranz
|
||||
030D0B = Belra's Right Arms
|
||||
030D0C = GIGUE'S ARMS
|
||||
030D0D = S-BERILL'S ARMS
|
||||
030D0E = G-ASSASIN'S ARMS
|
||||
030D0F = BOOMA'S RIGHT ARMS
|
||||
030D10 = GOBOOMA'S RIGHT ARMS
|
||||
030D11 = GIGOBOOMA'S RIGHT ARMS
|
||||
030D12 = GAL WIND
|
||||
030D13 = RAPPY'S WING
|
||||
|
||||
030E00 = BERILL PHOTON
|
||||
030E01 = PARASITIC GENE FLOW
|
||||
030E02 = MAGICSTONE IRITISTA
|
||||
030E03 = BLUE BLACK STONE
|
||||
030E04 = SYNCESTA
|
||||
030E05 = MAGIC WATER
|
||||
030E06 = PARASITIC CELL TYPE D
|
||||
030E07 = MAGIC ROCK HEART KEY
|
||||
030E08 = MAGIC ROCK MOOLA
|
||||
030E09 = STAR AMPLIFIER
|
||||
030E0A = BOOK OF HITOGATA
|
||||
030E0B = HEART OF CHU CHU
|
||||
030E0C = PART OF EGG BLASTER
|
||||
030E0D = HEART OF ANGLE
|
||||
030E0E = HEART OF DEVIL
|
||||
030E0F = KIT OF HAMBERGER
|
||||
030E10 = PANTHER'S SPIRIT
|
||||
030E11 = KIT OF MARK3
|
||||
030E12 = KIT OF MASTER SYSTEM
|
||||
030E13 = KIT OF GENESIS
|
||||
030E14 = KIT OF SEGA SATURN
|
||||
030E15 = KIT OF DREAMCAST
|
||||
030E16 = AMP. RESTA
|
||||
030E17 = AMP. ANTI
|
||||
030E18 = AMP. SHIFTA
|
||||
030E19 = AMP. DEBAND
|
||||
030E1A = AMP.
|
||||
030E1B = AMP.
|
||||
030E1C = AMP.
|
||||
030E1D = AMP.
|
||||
030E1E = AMP.
|
||||
030E1F = AMP.
|
||||
030E20 = AMP.
|
||||
030E21 = AMP.
|
||||
030E22 = AMP.
|
||||
030E23 = AMP.
|
||||
030E24 = AMP.
|
||||
030E25 = AMP.
|
||||
030E26 = HEART OF KAPUKAPU
|
||||
030E27 = PROTON BOOSTER
|
||||
030F00 = ADD SLOT
|
||||
031000 = PHOTON DROP
|
||||
031001 = PHOTON SPHERE
|
||||
031002 = PHOTON CRYSTAL
|
||||
031100 = BOOK OF KATANA 1
|
||||
031101 = BOOK OF KATANA 2
|
||||
031102 = BOOK OF KATANA 3
|
||||
031200 = WEAPONS BRONZE BADGE
|
||||
031201 = WEAPONS SILVER BADGE
|
||||
031202 = WEAPONS GOLD BADGE
|
||||
031203 = WEAPONS CRYSTAL BADGE
|
||||
031204 = WEAPONS STEEL BADGE
|
||||
031205 = WEAPONS ALUMINUM BADGE
|
||||
031206 = WEAPONS LEATHER BADGE
|
||||
031207 = WEAPONS BONE BADGE
|
||||
031208 = LETTER OF APPRECATION
|
||||
031209 = AUTOGRAPH ALBUM
|
||||
03120A = VALENTINE'S CHOCOLATE
|
||||
03120B = NEWYEAR'S CARD
|
||||
03120C = CRISMAS CARD
|
||||
03120D = BIRTHDAY CARD
|
||||
03120E = PROOF OF SONIC TEAM
|
||||
03120F = SPECIAL EVENT TICKET
|
||||
031300 = PRESENT
|
||||
031400 = CHOCOLATE
|
||||
031401 = CANDY
|
||||
031402 = CAKE
|
||||
031403 = SILVER BADGE
|
||||
031404 = GOLD BADGE
|
||||
031405 = CRYSTAL BADGE
|
||||
031406 = IRON BADGE
|
||||
031407 = ALUMINUM BADGE
|
||||
031408 = LEATHER BADGE
|
||||
031409 = BONE BADGE
|
||||
03140A = BONQUET
|
||||
03140B = DECOCTION
|
||||
031500 = CRISMAS PRESENT
|
||||
031501 = EASTER EGG
|
||||
031502 = JACK-O'S-LANTERN
|
||||
031700 = HUNTERS REPORT
|
||||
031701 = HUNTERS REPORT RANK A
|
||||
031702 = HUNTERS REPORT RANK B
|
||||
031703 = HUNTERS REPORT RANK C
|
||||
031704 = HUNTERS REPORT RANK F
|
||||
031705 = HUNTERS REPORT
|
||||
031705 = HUNTERS REPORT
|
||||
031705 = HUNTERS REPORT
|
||||
031705 = HUNTERS REPORT
|
||||
031705 = HUNTERS REPORT
|
||||
031705 = HUNTERS REPORT
|
||||
031705 = HUNTERS REPORT
|
||||
031705 = HUNTERS REPORT
|
||||
031705 = HUNTERS REPORT
|
||||
031802 = Dragon Scale
|
||||
031803 = Heaven Striker Coat
|
||||
031807 = Rappys Beak
|
||||
031802 = Dragon Scale */
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void player_use_item(shared_ptr<Client> c, size_t item_index) {
|
||||
auto player = c->game_data.player();
|
||||
|
||||
ssize_t equipped_weapon = -1;
|
||||
// ssize_t equipped_armor = -1;
|
||||
// ssize_t equipped_shield = -1;
|
||||
// ssize_t equipped_mag = -1;
|
||||
for (size_t y = 0; y < c->game_data.player()->inventory.num_items; y++) {
|
||||
if (c->game_data.player()->inventory.items[y].flags & 0x00000008) {
|
||||
if (c->game_data.player()->inventory.items[y].data.data1[0] == 0) {
|
||||
equipped_weapon = y;
|
||||
}
|
||||
// else if ((c->game_data.player()->inventory.items[y].data.data1[0] == 1) &&
|
||||
// (c->game_data.player()->inventory.items[y].data.data1[1] == 1)) {
|
||||
// equipped_armor = y;
|
||||
// } else if ((c->game_data.player()->inventory.items[y].data.data1[0] == 1) &&
|
||||
// (c->game_data.player()->inventory.items[y].data.data1[1] == 2)) {
|
||||
// equipped_shield = y;
|
||||
// } else if (c->game_data.player()->inventory.items[y].data.data1[0] == 2) {
|
||||
// equipped_mag = y;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
void player_use_item(shared_ptr<ServerState> s, shared_ptr<Client> c, size_t item_index) {
|
||||
// On PC (and presumably DC), the client sends a 6x29 after this to delete the
|
||||
// used item. On GC and later versions, this does not happen, so we should
|
||||
// delete the item here.
|
||||
bool should_delete_item = (c->version() != GameVersion::DC) &&
|
||||
(c->version() != GameVersion::PC);
|
||||
bool should_delete_item = (c->version() != GameVersion::DC) && (c->version() != GameVersion::PC);
|
||||
|
||||
auto& item = c->game_data.player()->inventory.items[item_index];
|
||||
if (item.data.data1w[0] == 0x0203) { // technique disk
|
||||
c->game_data.player()->disp.technique_levels.data()[item.data.data1[4]] = item.data.data1[2];
|
||||
auto player = c->game_data.player();
|
||||
auto& item = player->inventory.items[item_index];
|
||||
uint32_t item_identifier = item.data.primary_identifier();
|
||||
|
||||
} else if (item.data.data1w[0] == 0x0A03) { // grinder
|
||||
if (equipped_weapon < 0) {
|
||||
throw invalid_argument("grinder used with no weapon equipped");
|
||||
if (item.data.is_common_consumable()) { // Monomate, etc.
|
||||
// Nothing to do (it should be deleted)
|
||||
|
||||
} else if (item_identifier == 0x030200) { // Technique disk
|
||||
uint8_t max_level = s->item_parameter_table->get_max_tech_level(player->disp.visual.char_class, item.data.data1[4]);
|
||||
if (item.data.data1[2] > max_level) {
|
||||
throw runtime_error("technique level too high");
|
||||
}
|
||||
player->disp.technique_levels.data()[item.data.data1[4]] = item.data.data1[2];
|
||||
|
||||
} else if ((item_identifier & 0xFFFF00) == 0x030A00) { // Grinder
|
||||
if (item.data.data1[2] > 2) {
|
||||
throw invalid_argument("incorrect grinder value");
|
||||
}
|
||||
c->game_data.player()->inventory.items[equipped_weapon].data.data1[3] += (item.data.data1[2] + 1);
|
||||
// TODO: we should check for max grind here
|
||||
auto& weapon = player->inventory.items[player->inventory.find_equipped_weapon()];
|
||||
auto weapon_def = s->item_parameter_table->get_weapon(
|
||||
weapon.data.data1[1], weapon.data.data1[2]);
|
||||
if (weapon.data.data1[3] >= weapon_def.max_grind) {
|
||||
throw runtime_error("weapon already at maximum grind");
|
||||
}
|
||||
weapon.data.data1[3] += (item.data.data1[2] + 1);
|
||||
|
||||
} else if (item.data.data1w[0] == 0x0B03) { // material
|
||||
} else if ((item_identifier & 0xFFFF00) == 0x030B00) { // Material
|
||||
switch (item.data.data1[2]) {
|
||||
case 0: // Power Material
|
||||
c->game_data.player()->disp.stats.atp += 2;
|
||||
c->game_data.player()->disp.stats.char_stats.atp += 2;
|
||||
break;
|
||||
case 1: // Mind Material
|
||||
c->game_data.player()->disp.stats.mst += 2;
|
||||
c->game_data.player()->disp.stats.char_stats.mst += 2;
|
||||
break;
|
||||
case 2: // Evade Material
|
||||
c->game_data.player()->disp.stats.evp += 2;
|
||||
c->game_data.player()->disp.stats.char_stats.evp += 2;
|
||||
break;
|
||||
case 3: // HP Material
|
||||
c->game_data.player()->inventory.hp_materials_used += 2;
|
||||
@@ -210,395 +58,395 @@ void player_use_item(shared_ptr<Client> c, size_t item_index) {
|
||||
c->game_data.player()->inventory.tp_materials_used += 2;
|
||||
break;
|
||||
case 5: // Def Material
|
||||
c->game_data.player()->disp.stats.dfp += 2;
|
||||
c->game_data.player()->disp.stats.char_stats.dfp += 2;
|
||||
break;
|
||||
case 6: // Luck Material
|
||||
c->game_data.player()->disp.stats.lck += 2;
|
||||
c->game_data.player()->disp.stats.char_stats.lck += 2;
|
||||
break;
|
||||
default:
|
||||
throw invalid_argument("unknown material used");
|
||||
}
|
||||
|
||||
} else if ((item_identifier & 0xFFFF00) == 0x030F00) { // AddSlot
|
||||
auto& armor = player->inventory.items[player->inventory.find_equipped_armor()];
|
||||
if (armor.data.data1[5] >= 4) {
|
||||
throw runtime_error("armor already at maximum slot count");
|
||||
}
|
||||
armor.data.data1[5]++;
|
||||
|
||||
} else if (item.data.is_wrapped()) {
|
||||
// Unwrap present
|
||||
item.data.unwrap();
|
||||
should_delete_item = false;
|
||||
|
||||
} else if (item_identifier == 0x003300) {
|
||||
// Unseal Sealed J-Sword => Tsumikiri J-Sword
|
||||
item.data.data1[1] = 0x32;
|
||||
should_delete_item = false;
|
||||
|
||||
} else if (item_identifier == 0x00AB00) {
|
||||
// Unseal Lame d'Argent => Excalibur
|
||||
item.data.data1[1] = 0xAC;
|
||||
should_delete_item = false;
|
||||
|
||||
} else if (item_identifier == 0x01034D) {
|
||||
// Unseal Limiter => Adept
|
||||
item.data.data1[2] = 0x4E;
|
||||
should_delete_item = false;
|
||||
|
||||
} else if (item_identifier == 0x01034F) {
|
||||
// Unseal Swordsman Lore => Proof of Sword-Saint
|
||||
item.data.data1[2] = 0x50;
|
||||
should_delete_item = false;
|
||||
|
||||
} else if (item_identifier == 0x030C00) {
|
||||
// Cell of MAG 502
|
||||
auto& mag = player->inventory.items[player->inventory.find_equipped_mag()];
|
||||
mag.data.data1[1] = (player->disp.visual.section_id & 1) ? 0x1D : 0x21;
|
||||
|
||||
} else if (item_identifier == 0x030C01) {
|
||||
// Cell of MAG 213
|
||||
auto& mag = player->inventory.items[player->inventory.find_equipped_mag()];
|
||||
mag.data.data1[1] = (player->disp.visual.section_id & 1) ? 0x27 : 0x22;
|
||||
|
||||
} else if (item_identifier == 0x030C02) {
|
||||
// Parts of RoboChao
|
||||
auto& mag = player->inventory.items[player->inventory.find_equipped_mag()];
|
||||
mag.data.data1[1] = 0x28;
|
||||
|
||||
} else if (item_identifier == 0x030C03) {
|
||||
// Heart of Opa Opa
|
||||
auto& mag = player->inventory.items[player->inventory.find_equipped_mag()];
|
||||
mag.data.data1[1] = 0x29;
|
||||
|
||||
} else if (item_identifier == 0x030C04) {
|
||||
// Heart of Pian
|
||||
auto& mag = player->inventory.items[player->inventory.find_equipped_mag()];
|
||||
mag.data.data1[1] = 0x2A;
|
||||
|
||||
} else if (item_identifier == 0x030C05) {
|
||||
// Heart of Chao
|
||||
auto& mag = player->inventory.items[player->inventory.find_equipped_mag()];
|
||||
mag.data.data1[1] = 0x2B;
|
||||
|
||||
} else if ((item_identifier & 0xFFFF00) == 0x031500) {
|
||||
// Christmas Present, etc. - use unwrap_table + probabilities therein
|
||||
auto table = s->item_parameter_table->get_event_items(item.data.data1[2]);
|
||||
size_t sum = 0;
|
||||
for (size_t z = 0; z < table.second; z++) {
|
||||
sum += table.first[z].probability;
|
||||
}
|
||||
if (sum == 0) {
|
||||
throw runtime_error("no unwrap results available for event");
|
||||
}
|
||||
size_t det = random_object<size_t>() % sum;
|
||||
for (size_t z = 0; z < table.second; z++) {
|
||||
const auto& entry = table.first[z];
|
||||
if (det > entry.probability) {
|
||||
det -= entry.probability;
|
||||
} else {
|
||||
item.data.data2d = 0;
|
||||
item.data.data1[0] = entry.item[0];
|
||||
item.data.data1[1] = entry.item[1];
|
||||
item.data.data1[2] = entry.item[2];
|
||||
item.data.data1.clear_after(3);
|
||||
should_delete_item = false;
|
||||
|
||||
auto l = s->find_lobby(c->lobby_id);
|
||||
send_create_inventory_item(l, c, item.data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// default item action is to unwrap the item if it's a present
|
||||
if ((item.data.data1[0] == 2) && (item.data.data2[2] & 0x40)) {
|
||||
item.data.data2[2] &= 0xBF;
|
||||
should_delete_item = false;
|
||||
} else if ((item.data.data1[0] != 2) && (item.data.data1[4] & 0x40)) {
|
||||
item.data.data1[4] &= 0xBF;
|
||||
should_delete_item = false;
|
||||
// Use item combinations table from ItemPMT
|
||||
bool combo_applied = false;
|
||||
for (size_t z = 0; z < player->inventory.num_items; z++) {
|
||||
auto& inv_item = player->inventory.items[z];
|
||||
if (!(inv_item.flags & 0x00000008)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
const auto& combo = s->item_parameter_table->get_item_combination(
|
||||
item.data, inv_item.data);
|
||||
if (combo.char_class != 0xFF && combo.char_class != player->disp.visual.char_class) {
|
||||
throw runtime_error("item combination requires specific char_class");
|
||||
}
|
||||
if (combo.mag_level != 0xFF) {
|
||||
if (inv_item.data.data1[0] != 2) {
|
||||
throw runtime_error("item combination applies with mag level requirement, but equipped item is not a mag");
|
||||
}
|
||||
if (inv_item.data.compute_mag_level() < combo.mag_level) {
|
||||
throw runtime_error("item combination applies with mag level requirement, but equipped mag level is too low");
|
||||
}
|
||||
}
|
||||
if (combo.grind != 0xFF) {
|
||||
if (inv_item.data.data1[0] != 0) {
|
||||
throw runtime_error("item combination applies with grind requirement, but equipped item is not a weapon");
|
||||
}
|
||||
if (inv_item.data.data1[3] < combo.grind) {
|
||||
throw runtime_error("item combination applies with grind requirement, but equipped weapon grind is too low");
|
||||
}
|
||||
}
|
||||
if (combo.level != 0xFF && player->disp.stats.level + 1 < combo.level) {
|
||||
throw runtime_error("item combination applies with level requirement, but player level is too low");
|
||||
}
|
||||
// If we get here, then the combo applies
|
||||
if (combo_applied) {
|
||||
throw runtime_error("multiple combinations apply");
|
||||
}
|
||||
combo_applied = true;
|
||||
|
||||
inv_item.data.data1[0] = combo.result_item[0];
|
||||
inv_item.data.data1[1] = combo.result_item[1];
|
||||
inv_item.data.data1[2] = combo.result_item[2];
|
||||
inv_item.data.data1[3] = 0; // Grind
|
||||
inv_item.data.data1[4] = 0; // Flags + special
|
||||
} catch (const out_of_range&) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!combo_applied) {
|
||||
throw runtime_error("no combinations apply");
|
||||
}
|
||||
}
|
||||
|
||||
if (should_delete_item) {
|
||||
// Allow overdrafting meseta if the client is not BB, since the server isn't
|
||||
// informed when meseta is added or removed from the bank.
|
||||
c->game_data.player()->remove_item(item.data.id, 1, c->version() != GameVersion::BB);
|
||||
player->remove_item(item.data.id, 1, c->version() != GameVersion::BB);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void player_feed_mag(std::shared_ptr<ServerState> s, std::shared_ptr<Client> c, size_t mag_item_index, size_t fed_item_index) {
|
||||
static const unordered_map<uint32_t, size_t> result_index_for_fed_item({
|
||||
{0x030000, 0}, // Monomate
|
||||
{0x030001, 1}, // Dimate
|
||||
{0x030002, 2}, // Trimate
|
||||
{0x030100, 3}, // Monofluid
|
||||
{0x030101, 4}, // Difluid
|
||||
{0x030102, 5}, // Trifluid
|
||||
{0x030600, 6}, // Antidote
|
||||
{0x030601, 7}, // Antiparalysis
|
||||
{0x030300, 8}, // Sol Atomizer
|
||||
{0x030400, 9}, // Moon Atomizer
|
||||
{0x030500, 10}, // Star Atomizer
|
||||
});
|
||||
|
||||
CommonItemData::CommonItemData(
|
||||
vector<uint32_t>&& enemy_item_categories,
|
||||
vector<uint32_t>&& box_item_categories,
|
||||
vector<vector<uint8_t>>&& unit_types) :
|
||||
enemy_item_categories(move(enemy_item_categories)),
|
||||
box_item_categories(move(box_item_categories)),
|
||||
unit_types(move(unit_types)) {
|
||||
auto player = c->game_data.player();
|
||||
auto& fed_item = player->inventory.items[fed_item_index];
|
||||
auto& mag_item = player->inventory.items[mag_item_index];
|
||||
|
||||
// sanity check the values
|
||||
if (this->enemy_item_categories.size() != 8) {
|
||||
throw invalid_argument("enemy item categories is incorrect length");
|
||||
}
|
||||
if (this->box_item_categories.size() != 8) {
|
||||
throw invalid_argument("box item categories is incorrect length");
|
||||
}
|
||||
if (this->unit_types.size() != 4) {
|
||||
throw invalid_argument("unit types is incorrect length");
|
||||
}
|
||||
size_t result_index = result_index_for_fed_item.at(fed_item.data.primary_identifier());
|
||||
const auto& mag_def = s->item_parameter_table->get_mag(mag_item.data.data1[1]);
|
||||
const auto& feed_result = s->item_parameter_table->get_mag_feed_result(mag_def.feed_table, result_index);
|
||||
|
||||
{
|
||||
uint64_t sum = 0;
|
||||
for (uint32_t v : this->enemy_item_categories) {
|
||||
sum += v;
|
||||
}
|
||||
if (sum > 0xFFFFFFFF) {
|
||||
throw invalid_argument("enemy item category sum is too large");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
uint64_t sum = 0;
|
||||
for (uint32_t v : this->box_item_categories) {
|
||||
sum += v;
|
||||
}
|
||||
if (sum > 0xFFFFFFFF) {
|
||||
throw invalid_argument("box item category sum is too large");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CommonItemCreator::CommonItemCreator(
|
||||
std::shared_ptr<const CommonItemData> data,
|
||||
std::shared_ptr<std::mt19937> random)
|
||||
: data(data), random(random) { }
|
||||
|
||||
int32_t CommonItemCreator::decide_item_type(bool is_box) const {
|
||||
uint32_t det = (*this->random)();
|
||||
|
||||
const auto& v = is_box ? this->data->box_item_categories : this->data->enemy_item_categories;
|
||||
for (size_t x = 0; x < v.size(); x++) {
|
||||
uint32_t probability = v.at(x);
|
||||
if (probability > det) {
|
||||
return x;
|
||||
}
|
||||
det -= probability;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
ItemData CommonItemCreator::create_drop_item(bool is_box, uint8_t episode,
|
||||
uint8_t difficulty, uint8_t area, uint8_t) const {
|
||||
// TODO: use the section ID (last argument) to vary drop frequencies appropriately
|
||||
// change the area if it's invalid (data for the bosses are actually in other areas)
|
||||
if (area > 10) {
|
||||
if (episode == 1) {
|
||||
if (area == 11) {
|
||||
area = 3; // dragon
|
||||
} else if (area == 12) {
|
||||
area = 6; // de rol le
|
||||
} else if (area == 13) {
|
||||
area = 8; // vol opt
|
||||
} else if (area == 14) {
|
||||
area = 10; // dark falz
|
||||
} else {
|
||||
area = 1; // unknown area -> forest 1
|
||||
auto update_stat = +[](ItemData& data, size_t which, int8_t delta) -> void {
|
||||
uint16_t existing_stat = data.data1w[which] % 100;
|
||||
if ((delta > 0) || ((delta < 0) && (-delta < existing_stat))) {
|
||||
uint16_t level = data.compute_mag_level();
|
||||
if (level > 200) {
|
||||
throw runtime_error("mag level is too high");
|
||||
}
|
||||
} else if (episode == 2) {
|
||||
if (area == 12) {
|
||||
area = 9; // gal gryphon
|
||||
} else if (area == 13) {
|
||||
area = 10; // olga flow
|
||||
} else if (area == 14) {
|
||||
area = 3; // barba ray
|
||||
} else if (area == 15) {
|
||||
area = 6; // gol dragon
|
||||
} else {
|
||||
area = 10; // tower
|
||||
if ((level == 200) && ((99 - existing_stat) < delta)) {
|
||||
delta = 99 - existing_stat;
|
||||
}
|
||||
} else if (episode == 3) {
|
||||
area = 1;
|
||||
data.data1w[which] += delta;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ItemData item;
|
||||
update_stat(mag_item.data, 2, feed_result.def);
|
||||
update_stat(mag_item.data, 3, feed_result.pow);
|
||||
update_stat(mag_item.data, 4, feed_result.dex);
|
||||
update_stat(mag_item.data, 5, feed_result.mind);
|
||||
mag_item.data.data2[0] = clamp<ssize_t>(static_cast<ssize_t>(mag_item.data.data2[0]) + feed_result.synchro, 0, 120);
|
||||
mag_item.data.data2[1] = clamp<ssize_t>(static_cast<ssize_t>(mag_item.data.data2[1]) + feed_result.iq, 0, 200);
|
||||
|
||||
// picks a random non-rare item type, then gives it appropriate random stats
|
||||
// modify some of the constants in this section to change the system's
|
||||
// parameters
|
||||
int32_t type = this->decide_item_type(is_box);
|
||||
switch (type) {
|
||||
case 0x00: // material
|
||||
item.data1[0] = 0x03;
|
||||
item.data1[1] = 0x0B;
|
||||
item.data1[2] = random_int(this->random, 0, 6);
|
||||
break;
|
||||
uint8_t mag_level = mag_item.data.compute_mag_level();
|
||||
mag_item.data.data1[2] = mag_level;
|
||||
uint8_t evolution_number = s->mag_evolution_table->get_evolution_number(mag_item.data.data1[1]);
|
||||
uint8_t mag_number = mag_item.data.data1[1];
|
||||
|
||||
case 0x01: // equipment
|
||||
switch (random_int(this->random, 0, 3)) {
|
||||
case 0x00: // weapon
|
||||
item.data1[1] = random_int(this->random, 1, 12); // random normal class
|
||||
item.data1[2] = difficulty + random_int(this->random, 0, 2); // special type
|
||||
if ((item.data1[1] > 0x09) && (item.data1[2] > 0x04)) {
|
||||
item.data1[2] = 0x04; // no special classes above 4
|
||||
// Note: Sega really did just hardcode all these rules into the client. There
|
||||
// is no data file describing these evolutions, unfortunately.
|
||||
|
||||
if (mag_level < 10) {
|
||||
// Nothing to do
|
||||
|
||||
} else if (mag_level < 35) { // Level 10 evolution
|
||||
if (evolution_number < 1) {
|
||||
switch (player->disp.visual.char_class) {
|
||||
case 0: // HUmar
|
||||
case 1: // HUnewearl
|
||||
case 2: // HUcast
|
||||
case 9: // HUcaseal
|
||||
mag_item.data.data1[1] = 0x01; // Varuna
|
||||
break;
|
||||
case 3: // RAmar
|
||||
case 11: // RAmarl
|
||||
case 4: // RAcast
|
||||
case 5: // RAcaseal
|
||||
mag_item.data.data1[1] = 0x0D; // Kalki
|
||||
break;
|
||||
case 10: // FOmar
|
||||
case 6: // FOmarl
|
||||
case 7: // FOnewm
|
||||
case 8: // FOnewearl
|
||||
mag_item.data.data1[1] = 0x19; // Vritra
|
||||
break;
|
||||
default:
|
||||
throw runtime_error("invalid character class");
|
||||
}
|
||||
}
|
||||
|
||||
} else if (mag_level < 50) { // Level 35 evolution
|
||||
if (evolution_number < 2) {
|
||||
uint16_t flags = mag_item.data.compute_mag_strength_flags();
|
||||
if (mag_number == 0x0D) {
|
||||
if ((flags & 0x110) == 0) {
|
||||
mag_item.data.data1[1] = 0x02;
|
||||
} else if (flags & 8) {
|
||||
mag_item.data.data1[1] = 0x03;
|
||||
} else if (flags & 0x20) {
|
||||
mag_item.data.data1[1] = 0x0B;
|
||||
}
|
||||
} else if (mag_number == 1) {
|
||||
if (flags & 0x108) {
|
||||
mag_item.data.data1[1] = 0x0E;
|
||||
} else if (flags & 0x10) {
|
||||
mag_item.data.data1[1] = 0x0F;
|
||||
} else if (flags & 0x20) {
|
||||
mag_item.data.data1[1] = 0x04;
|
||||
}
|
||||
} else if (mag_number == 0x19) {
|
||||
if (flags & 0x120) {
|
||||
mag_item.data.data1[1] = 0x1A;
|
||||
} else if (flags & 8) {
|
||||
mag_item.data.data1[1] = 0x1B;
|
||||
} else if (flags & 0x10) {
|
||||
mag_item.data.data1[1] = 0x14;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if ((mag_level % 5) == 0) { // Level 50 (and beyond) evolutions
|
||||
if (evolution_number < 4) {
|
||||
|
||||
if (mag_level >= 100) {
|
||||
uint8_t section_id_group = player->disp.visual.section_id % 3;
|
||||
uint16_t def = mag_item.data.data1w[2] / 100;
|
||||
uint16_t pow = mag_item.data.data1w[3] / 100;
|
||||
uint16_t dex = mag_item.data.data1w[4] / 100;
|
||||
uint16_t mind = mag_item.data.data1w[5] / 100;
|
||||
bool is_male = char_class_is_male(player->disp.visual.char_class);
|
||||
size_t table_index = (is_male ? 0 : 1) + section_id_group * 2;
|
||||
|
||||
bool is_hunter = char_class_is_hunter(player->disp.visual.char_class);
|
||||
bool is_ranger = char_class_is_ranger(player->disp.visual.char_class);
|
||||
bool is_force = char_class_is_force(player->disp.visual.char_class);
|
||||
if (is_force) {
|
||||
table_index += 12;
|
||||
} else if (is_ranger) {
|
||||
table_index += 6;
|
||||
} else if (!is_hunter) {
|
||||
throw logic_error("char class is not any of the top-level classes");
|
||||
}
|
||||
|
||||
// Note: The original code checks the class (hunter/ranger/force) again
|
||||
// here, and goes into 3 branches that each do these same checks.
|
||||
// However, the result of all 3 branches is exactly the same!
|
||||
if (((section_id_group == 0) && (pow + mind == def + dex)) ||
|
||||
((section_id_group == 1) && (pow + dex == mind + def)) ||
|
||||
((section_id_group == 2) && (pow + def == mind + dex))) {
|
||||
// clang-format off
|
||||
static const uint8_t result_table[] = {
|
||||
// M0 F0 M1 F1 M2 F2
|
||||
0x39, 0x3B, 0x3A, 0x3B, 0x3A, 0x3B, // Hunter
|
||||
0x3D, 0x3C, 0x3D, 0x3C, 0x3D, 0x3E, // Ranger
|
||||
0x41, 0x3F, 0x41, 0x40, 0x41, 0x40, // Force
|
||||
};
|
||||
// clang-format on
|
||||
mag_item.data.data1[1] = result_table[table_index];
|
||||
}
|
||||
}
|
||||
|
||||
// If a special evolution did not occur, do a normal level 50 evolution
|
||||
if (mag_number == mag_item.data.data1[1]) {
|
||||
uint16_t flags = mag_item.data.compute_mag_strength_flags();
|
||||
uint16_t def = mag_item.data.data1w[2] / 100;
|
||||
uint16_t pow = mag_item.data.data1w[3] / 100;
|
||||
uint16_t dex = mag_item.data.data1w[4] / 100;
|
||||
uint16_t mind = mag_item.data.data1w[5] / 100;
|
||||
|
||||
bool is_hunter = char_class_is_hunter(player->disp.visual.char_class);
|
||||
bool is_ranger = char_class_is_ranger(player->disp.visual.char_class);
|
||||
bool is_force = char_class_is_force(player->disp.visual.char_class);
|
||||
if (is_hunter + is_ranger + is_force != 1) {
|
||||
throw logic_error("char class is not exactly one of the top-level classes");
|
||||
}
|
||||
|
||||
if (is_hunter) {
|
||||
if (flags & 0x108) {
|
||||
mag_item.data.data1[1] = (player->disp.visual.section_id & 1)
|
||||
? ((dex < mind) ? 0x08 : 0x06)
|
||||
: ((dex < mind) ? 0x0C : 0x05);
|
||||
} else if (flags & 0x010) {
|
||||
mag_item.data.data1[1] = (player->disp.visual.section_id & 1)
|
||||
? ((mind < pow) ? 0x12 : 0x10)
|
||||
: ((mind < pow) ? 0x17 : 0x13);
|
||||
} else if (flags & 0x020) {
|
||||
mag_item.data.data1[1] = (player->disp.visual.section_id & 1)
|
||||
? ((pow < dex) ? 0x16 : 0x24)
|
||||
: ((pow < dex) ? 0x07 : 0x1E);
|
||||
}
|
||||
item.data1[4] = 0x80; // untekked
|
||||
if (item.data1[2] < 0x04) {
|
||||
item.data1[4] |= random_int(this->random, 0, 40); // give a special
|
||||
} else if (is_ranger) {
|
||||
if (flags & 0x110) {
|
||||
mag_item.data.data1[1] = (player->disp.visual.section_id & 1)
|
||||
? ((mind < pow) ? 0x0A : 0x05)
|
||||
: ((mind < pow) ? 0x0C : 0x06);
|
||||
} else if (flags & 0x008) {
|
||||
mag_item.data.data1[1] = (player->disp.visual.section_id & 1)
|
||||
? ((dex < mind) ? 0x0A : 0x26)
|
||||
: ((dex < mind) ? 0x0C : 0x06);
|
||||
} else if (flags & 0x020) {
|
||||
mag_item.data.data1[1] = (player->disp.visual.section_id & 1)
|
||||
? ((pow < dex) ? 0x18 : 0x1E)
|
||||
: ((pow < dex) ? 0x08 : 0x05);
|
||||
}
|
||||
for (size_t x = 0, y = 0; (x < 5) && (y < 3); x++) { // percentages
|
||||
if (random_int(this->random, 0, 10) == 1) { // 1/11 chance of getting each type of percentage
|
||||
item.data1[6 + (y * 2)] = x + 1;
|
||||
item.data1[7 + (y * 2)] = random_int(this->random, 0, 10) * 5;
|
||||
y++;
|
||||
} else if (is_force) {
|
||||
if (flags & 0x120) {
|
||||
if (def < 45) {
|
||||
mag_item.data.data1[1] = (player->disp.visual.section_id & 1)
|
||||
? ((pow < dex) ? 0x17 : 0x09)
|
||||
: ((pow < dex) ? 0x1E : 0x1C);
|
||||
} else {
|
||||
mag_item.data.data1[1] = 0x24;
|
||||
}
|
||||
} else if (flags & 0x008) {
|
||||
if (def < 45) {
|
||||
mag_item.data.data1[1] = (player->disp.visual.section_id & 1)
|
||||
? ((dex < mind) ? 0x1C : 0x20)
|
||||
: ((dex < mind) ? 0x1F : 0x25);
|
||||
} else {
|
||||
mag_item.data.data1[1] = 0x23;
|
||||
}
|
||||
} else if (flags & 0x010) {
|
||||
if (def < 45) {
|
||||
mag_item.data.data1[1] = (player->disp.visual.section_id & 1)
|
||||
? ((mind < pow) ? 0x12 : 0x0C)
|
||||
: ((mind < pow) ? 0x15 : 0x11);
|
||||
} else {
|
||||
mag_item.data.data1[1] = 0x24;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01: // armor
|
||||
item.data1[0] = 0x01;
|
||||
item.data1[1] = 0x01;
|
||||
item.data1[2] = (6 * difficulty) + random_int(this->random, 0, ((area / 2) + 2) - 1); // standard type based on difficulty and area
|
||||
if (item.data1[2] > 0x17) {
|
||||
item.data1[2] = 0x17; // no standard types above 0x17
|
||||
}
|
||||
if (random_int(this->random, 0, 10) == 0) { // +/-
|
||||
item.data1[4] = random_int(this->random, 0, 5);
|
||||
item.data1[6] = random_int(this->random, 0, 2);
|
||||
}
|
||||
item.data1[5] = random_int(this->random, 0, 4); // slots
|
||||
break;
|
||||
|
||||
case 0x02: // shield
|
||||
item.data1[0] = 0x01;
|
||||
item.data1[1] = 0x02;
|
||||
item.data1[2] = (5 * difficulty) + random_int(this->random, 0, ((area / 2) + 2) - 1); // standard type based on difficulty and area
|
||||
if (item.data1[2] > 0x14) {
|
||||
item.data1[2] = 0x14; // no standard types above 0x14
|
||||
}
|
||||
if (random_int(this->random, 0, 10) == 0) { // +/-
|
||||
item.data1[4] = random_int(this->random, 0, 5);
|
||||
item.data1[6] = random_int(this->random, 0, 5);
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x03: { // unit
|
||||
const auto& type_table = this->data->unit_types.at(difficulty);
|
||||
uint8_t type = type_table[random_int(this->random, 0, type_table.size() - 1)];
|
||||
if (type == 0xFF) {
|
||||
throw out_of_range("no item dropped"); // 0xFF -> no item drops
|
||||
}
|
||||
item.data1[0] = 0x01;
|
||||
item.data1[1] = 0x03;
|
||||
item.data1[2] = type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02: // technique
|
||||
item.data1[0] = 0x03;
|
||||
item.data1[1] = 0x02;
|
||||
item.data1[4] = random_int(this->random, 0, 18); // tech type
|
||||
if ((item.data1[4] != 14) && (item.data1[4] != 17)) { // if not ryuker or reverser, give it a level
|
||||
if (item.data1[4] == 16) { // if not anti, give it a level between 1 and 30
|
||||
if (area > 3) {
|
||||
item.data1[2] = difficulty + random_int(this->random, 0, ((area - 1) / 2) - 1);
|
||||
} else {
|
||||
item.data1[2] = difficulty;
|
||||
}
|
||||
if (item.data1[2] > 6) {
|
||||
item.data1[2] = 6;
|
||||
}
|
||||
} else {
|
||||
item.data1[2] = (5 * difficulty) + random_int(this->random, 0, ((area * 3) / 2) - 1); // else between 1 and 7
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x03: // scape doll
|
||||
item.data1[0] = 0x03;
|
||||
item.data1[1] = 0x09;
|
||||
item.data1[2] = 0x00;
|
||||
break;
|
||||
|
||||
case 0x04: // grinder
|
||||
item.data1[0] = 0x03;
|
||||
item.data1[1] = 0x0A;
|
||||
item.data1[2] = random_int(this->random, 0, 2); // mono, di, tri
|
||||
break;
|
||||
|
||||
case 0x05: // consumable
|
||||
item.data1[0] = 0x03;
|
||||
item.data1[5] = 0x01;
|
||||
switch (random_int(this->random, 0, 2)) {
|
||||
case 0: // antidote / antiparalysis
|
||||
item.data1[1] = 6;
|
||||
item.data1[2] = random_int(this->random, 0, 1);
|
||||
break;
|
||||
|
||||
case 1: // telepipe / trap vision
|
||||
item.data1[1] = 7 + random_int(this->random, 0, 1);
|
||||
break;
|
||||
|
||||
case 2: // sol / moon / star atomizer
|
||||
item.data1[1] = 3 + random_int(this->random, 0, 2);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x06: // consumable
|
||||
item.data1[0] = 0x03;
|
||||
item.data1[5] = 0x01;
|
||||
item.data1[1] = random_int(this->random, 0, 1); // mate or fluid
|
||||
if (difficulty == 0) {
|
||||
item.data1[2] = random_int(this->random, 0, 1); // only mono and di on normal
|
||||
} else if (difficulty == 3) {
|
||||
item.data1[2] = random_int(this->random, 1, 2); // only di and tri on ultimate
|
||||
} else {
|
||||
item.data1[2] = random_int(this->random, 0, 2); // else, any of the three
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x07: // meseta
|
||||
item.data1[0] = 0x04;
|
||||
item.data2d = (90 * difficulty) + (random_int(this->random, 1, 20) * (area * 2)); // meseta amount
|
||||
break;
|
||||
|
||||
default:
|
||||
throw out_of_range("no item created");
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
ItemData CommonItemCreator::create_shop_item(uint8_t difficulty,
|
||||
uint8_t item_type) const {
|
||||
static const uint8_t max_percentages[4] = {20, 35, 45, 50};
|
||||
static const uint8_t max_quantity[4] = { 1, 1, 2, 2};
|
||||
static const uint8_t max_tech_level[4] = { 8, 15, 23, 30};
|
||||
static const uint8_t max_anti_level[4] = { 2, 4, 6, 7};
|
||||
|
||||
ItemData item;
|
||||
|
||||
item.data1[0] = item_type;
|
||||
while (item.data1[0] == 2) {
|
||||
item.data1[0] = rand() % 3;
|
||||
}
|
||||
switch (item.data1[0]) {
|
||||
case 0: { // weapon
|
||||
item.data1[1] = (rand() % 12) + 1;
|
||||
if (item.data1[1] > 9) {
|
||||
item.data1[2] = difficulty;
|
||||
} else {
|
||||
item.data1[2] = (rand() & 1) + difficulty;
|
||||
}
|
||||
|
||||
item.data1[3] = rand() % 11;
|
||||
item.data1[4] = rand() % 11;
|
||||
|
||||
size_t num_percentages = 0;
|
||||
for (size_t x = 0; (x < 5) && (num_percentages < 3); x++) {
|
||||
if ((rand() % 4) == 1) {
|
||||
item.data1[(num_percentages * 2) + 6] = x;
|
||||
item.data1[(num_percentages * 2) + 7] = rand() % (max_percentages[difficulty] + 1);
|
||||
num_percentages++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 1: // armor
|
||||
item.data1[1] = 0;
|
||||
while (item.data1[1] == 0) {
|
||||
item.data1[1] = rand() & 3;
|
||||
}
|
||||
switch (item.data1[1]) {
|
||||
case 1:
|
||||
item.data1[2] = (rand() % 6) + (difficulty * 6);
|
||||
item.data1[5] = rand() % 5;
|
||||
break;
|
||||
case 2:
|
||||
item.data2[2] = (rand() % 6) + (difficulty * 5);
|
||||
*reinterpret_cast<short*>(&item.data1[6]) = (rand() % 9) - 4;
|
||||
*reinterpret_cast<short*>(&item.data1[9]) = (rand() % 9) - 4;
|
||||
break;
|
||||
case 3:
|
||||
item.data2[2] = rand() % 0x3B;
|
||||
*reinterpret_cast<short*>(&item.data1[7]) = (rand() % 5) - 4;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 3: // tool
|
||||
item.data1[1] = rand() % 12;
|
||||
switch (item.data1[1]) {
|
||||
case 0:
|
||||
case 1:
|
||||
if (difficulty == 0) {
|
||||
item.data1[2] = 0;
|
||||
} else if (difficulty == 1) {
|
||||
item.data1[2] = rand() % 2;
|
||||
} else if (difficulty == 2) {
|
||||
item.data1[2] = (rand() % 2) + 1;
|
||||
} else if (difficulty == 3) {
|
||||
item.data1[2] = 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case 6:
|
||||
item.data1[2] = rand() % 2;
|
||||
break;
|
||||
|
||||
case 10:
|
||||
item.data1[2] = rand() % 3;
|
||||
break;
|
||||
|
||||
case 11:
|
||||
item.data1[2] = rand() % 7;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (item.data1[1]) {
|
||||
case 2:
|
||||
item.data1[4] = rand() % 19;
|
||||
switch (item.data1[4]) {
|
||||
case 14:
|
||||
case 17:
|
||||
item.data1[2] = 0; // reverser & ryuker always level 1
|
||||
break;
|
||||
case 16:
|
||||
item.data1[2] = rand() % max_anti_level[difficulty];
|
||||
break;
|
||||
default:
|
||||
item.data1[2] = rand() % max_tech_level[difficulty];
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 16:
|
||||
item.data1[5] = rand() % (max_quantity[difficulty] + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
// If the mag has evolved, add its new photon blast
|
||||
if (mag_number != mag_item.data.data1[1]) {
|
||||
const auto& new_mag_def = s->item_parameter_table->get_mag(mag_item.data.data1[1]);
|
||||
mag_item.data.add_mag_photon_blast(new_mag_def.photon_blast);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-28
@@ -6,32 +6,8 @@
|
||||
#include <random>
|
||||
|
||||
#include "Client.hh"
|
||||
#include "ServerState.hh"
|
||||
#include "StaticGameData.hh"
|
||||
|
||||
|
||||
|
||||
void player_use_item(std::shared_ptr<Client> c, size_t item_index);
|
||||
|
||||
struct CommonItemData {
|
||||
std::vector<uint32_t> enemy_item_categories;
|
||||
std::vector<uint32_t> box_item_categories;
|
||||
std::vector<std::vector<uint8_t>> unit_types;
|
||||
|
||||
CommonItemData(
|
||||
std::vector<uint32_t>&& enemy_item_categories,
|
||||
std::vector<uint32_t>&& box_item_categories,
|
||||
std::vector<std::vector<uint8_t>>&& unit_types);
|
||||
};
|
||||
|
||||
struct CommonItemCreator {
|
||||
std::shared_ptr<const CommonItemData> data;
|
||||
std::shared_ptr<std::mt19937> random;
|
||||
|
||||
CommonItemCreator(
|
||||
std::shared_ptr<const CommonItemData> data,
|
||||
std::shared_ptr<std::mt19937> random);
|
||||
|
||||
int32_t decide_item_type(bool is_box) const;
|
||||
ItemData create_drop_item(bool is_box, uint8_t episode, uint8_t difficulty,
|
||||
uint8_t area, uint8_t section_id) const;
|
||||
ItemData create_shop_item(uint8_t difficulty, uint8_t shop_type) const;
|
||||
};
|
||||
void player_use_item(std::shared_ptr<ServerState> s, std::shared_ptr<Client> c, size_t item_index);
|
||||
void player_feed_mag(std::shared_ptr<ServerState> s, std::shared_ptr<Client> c, size_t mag_item_index, size_t fed_item_index);
|
||||
|
||||
+4
-6
@@ -8,8 +8,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
LevelTable::LevelTable(shared_ptr<const string> data, bool compressed) {
|
||||
if (compressed) {
|
||||
this->data.reset(new string(prs_decompress(*data)));
|
||||
@@ -23,15 +21,15 @@ LevelTable::LevelTable(shared_ptr<const string> data, bool compressed) {
|
||||
this->table = reinterpret_cast<const Table*>(this->data->data());
|
||||
}
|
||||
|
||||
const PlayerStats& LevelTable::base_stats_for_class(uint8_t char_class) const {
|
||||
const CharacterStats& LevelTable::base_stats_for_class(uint8_t char_class) const {
|
||||
if (char_class >= 12) {
|
||||
throw out_of_range("invalid character class");
|
||||
}
|
||||
return this->table->base_stats[char_class];
|
||||
}
|
||||
|
||||
const LevelTable::LevelStats& LevelTable::stats_for_level(uint8_t char_class,
|
||||
uint8_t level) const {
|
||||
const LevelTable::LevelStats& LevelTable::stats_for_level(
|
||||
uint8_t char_class, uint8_t level) const {
|
||||
if (char_class >= 12) {
|
||||
throw invalid_argument("invalid character class");
|
||||
}
|
||||
@@ -41,7 +39,7 @@ const LevelTable::LevelStats& LevelTable::stats_for_level(uint8_t char_class,
|
||||
return this->table->levels[char_class][level];
|
||||
}
|
||||
|
||||
void LevelTable::LevelStats::apply(PlayerStats& ps) const {
|
||||
void LevelTable::LevelStats::apply(CharacterStats& ps) const {
|
||||
ps.ata += this->ata;
|
||||
ps.atp += this->atp;
|
||||
ps.dfp += this->dfp;
|
||||
|
||||
+12
-16
@@ -3,21 +3,17 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
struct PlayerStats {
|
||||
le_uint16_t atp;
|
||||
le_uint16_t mst;
|
||||
le_uint16_t evp;
|
||||
le_uint16_t hp;
|
||||
le_uint16_t dfp;
|
||||
le_uint16_t ata;
|
||||
le_uint16_t lck;
|
||||
|
||||
PlayerStats() noexcept;
|
||||
struct CharacterStats {
|
||||
le_uint16_t atp = 0;
|
||||
le_uint16_t mst = 0;
|
||||
le_uint16_t evp = 0;
|
||||
le_uint16_t hp = 0;
|
||||
le_uint16_t dfp = 0;
|
||||
le_uint16_t ata = 0;
|
||||
le_uint16_t lck = 0;
|
||||
} __attribute__((packed));
|
||||
|
||||
class LevelTable { // from PlyLevelTbl.prs
|
||||
@@ -33,18 +29,18 @@ public:
|
||||
uint8_t tp;
|
||||
le_uint32_t experience;
|
||||
|
||||
void apply(PlayerStats& ps) const;
|
||||
void apply(CharacterStats& ps) const;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Table {
|
||||
PlayerStats base_stats[12];
|
||||
CharacterStats base_stats[12];
|
||||
le_uint32_t unknown[12];
|
||||
LevelStats levels[12][200];
|
||||
} __attribute__((packed));
|
||||
|
||||
LevelTable(std::shared_ptr<const std::string> data, bool compressed);
|
||||
|
||||
const PlayerStats& base_stats_for_class(uint8_t char_class) const;
|
||||
const CharacterStats& base_stats_for_class(uint8_t char_class) const;
|
||||
const LevelStats& stats_for_level(uint8_t char_class, uint8_t level) const;
|
||||
|
||||
private:
|
||||
|
||||
+10
-10
@@ -5,14 +5,15 @@
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Time.hh>
|
||||
|
||||
#include "Loggers.hh"
|
||||
#include "License.hh"
|
||||
#include "Loggers.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
License::License() : serial_number(0), privileges(0), ban_end_time(0) { }
|
||||
License::License()
|
||||
: serial_number(0),
|
||||
privileges(0),
|
||||
ban_end_time(0) {}
|
||||
|
||||
string License::str() const {
|
||||
string ret = string_printf("License(serial_number=%" PRIu32, this->serial_number);
|
||||
@@ -39,12 +40,13 @@ string License::str() const {
|
||||
return ret + ")";
|
||||
}
|
||||
|
||||
|
||||
|
||||
LicenseManager::LicenseManager() : filename(""), autosave(false) { }
|
||||
LicenseManager::LicenseManager()
|
||||
: filename(""),
|
||||
autosave(false) {}
|
||||
|
||||
LicenseManager::LicenseManager(const string& filename)
|
||||
: filename(filename), autosave(true) {
|
||||
: filename(filename),
|
||||
autosave(true) {
|
||||
try {
|
||||
auto licenses = load_vector_file<License>(this->filename);
|
||||
for (const auto& read_license : licenses) {
|
||||
@@ -200,8 +202,6 @@ vector<License> LicenseManager::snapshot() const {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
shared_ptr<License> LicenseManager::create_license_pc(
|
||||
uint32_t serial_number, const string& access_key, bool temporary) {
|
||||
shared_ptr<License> l(new License());
|
||||
|
||||
+18
-18
@@ -1,29 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "Text.hh"
|
||||
|
||||
enum Privilege {
|
||||
KICK_USER = 0x00000001,
|
||||
BAN_USER = 0x00000002,
|
||||
SILENCE_USER = 0x00000004,
|
||||
KICK_USER = 0x00000001,
|
||||
BAN_USER = 0x00000002,
|
||||
SILENCE_USER = 0x00000004,
|
||||
CHANGE_LOBBY_INFO = 0x00000008,
|
||||
CHANGE_EVENT = 0x00000010,
|
||||
ANNOUNCE = 0x00000020,
|
||||
FREE_JOIN_GAMES = 0x00000040,
|
||||
UNLOCK_GAMES = 0x00000080,
|
||||
CHANGE_EVENT = 0x00000010,
|
||||
ANNOUNCE = 0x00000020,
|
||||
FREE_JOIN_GAMES = 0x00000040,
|
||||
UNLOCK_GAMES = 0x00000080,
|
||||
|
||||
DEBUG = 0x01000000,
|
||||
DEBUG = 0x01000000,
|
||||
|
||||
MODERATOR = 0x00000007,
|
||||
ADMINISTRATOR = 0x0000003F,
|
||||
ROOT = 0x7FFFFFFF,
|
||||
MODERATOR = 0x00000007,
|
||||
ADMINISTRATOR = 0x0000003F,
|
||||
ROOT = 0x7FFFFFFF,
|
||||
|
||||
TEMPORARY = 0x80000000,
|
||||
TEMPORARY = 0x80000000,
|
||||
};
|
||||
|
||||
enum LicenseVerifyAction {
|
||||
@@ -48,17 +48,17 @@ struct License {
|
||||
|
||||
class incorrect_password : public std::invalid_argument {
|
||||
public:
|
||||
incorrect_password() : invalid_argument("incorrect password") { }
|
||||
incorrect_password() : invalid_argument("incorrect password") {}
|
||||
};
|
||||
|
||||
class incorrect_access_key : public std::invalid_argument {
|
||||
public:
|
||||
incorrect_access_key() : invalid_argument("incorrect access key") { }
|
||||
incorrect_access_key() : invalid_argument("incorrect access key") {}
|
||||
};
|
||||
|
||||
class missing_license : public std::invalid_argument {
|
||||
public:
|
||||
missing_license() : invalid_argument("missing license") { }
|
||||
missing_license() : invalid_argument("missing license") {}
|
||||
};
|
||||
|
||||
class LicenseManager {
|
||||
|
||||
+27
-33
@@ -10,26 +10,25 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
Lobby::Lobby(uint32_t id)
|
||||
: log(string_printf("[Lobby/%" PRIX32 "] ", id), lobby_log.min_level),
|
||||
lobby_id(id),
|
||||
min_level(0),
|
||||
max_level(0xFFFFFFFF),
|
||||
next_game_item_id(0x00810000),
|
||||
version(GameVersion::GC),
|
||||
section_id(0),
|
||||
episode(1),
|
||||
difficulty(0),
|
||||
random_seed(random_object<uint32_t>()),
|
||||
random(new mt19937(this->random_seed)),
|
||||
event(0),
|
||||
block(0),
|
||||
type(0),
|
||||
leader_id(0),
|
||||
max_clients(12),
|
||||
flags(0) {
|
||||
: log(string_printf("[Lobby/%" PRIX32 "] ", id), lobby_log.min_level),
|
||||
lobby_id(id),
|
||||
min_level(0),
|
||||
max_level(0xFFFFFFFF),
|
||||
next_game_item_id(0x00810000),
|
||||
version(GameVersion::GC),
|
||||
section_id(0),
|
||||
episode(Episode::NONE),
|
||||
mode(GameMode::NORMAL),
|
||||
difficulty(0),
|
||||
exp_multiplier(1),
|
||||
random_seed(random_object<uint32_t>()),
|
||||
event(0),
|
||||
block(0),
|
||||
type(0),
|
||||
leader_id(0),
|
||||
max_clients(12),
|
||||
flags(0) {
|
||||
for (size_t x = 0; x < 12; x++) {
|
||||
this->next_item_id[x] = 0x00010000 + 0x00200000 * x;
|
||||
}
|
||||
@@ -53,7 +52,7 @@ bool Lobby::any_client_loading() const {
|
||||
if (!this->clients[x].get()) {
|
||||
continue;
|
||||
}
|
||||
if (this->clients[x]->flags & (Client::Flag::LOADING | Client::Flag::LOADING_QUEST)) {
|
||||
if (this->clients[x]->flags & (Client::Flag::LOADING | Client::Flag::LOADING_QUEST | Client::Flag::LOADING_RUNNING_QUEST)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -81,7 +80,7 @@ void Lobby::add_client(shared_ptr<Client> c, ssize_t required_client_id) {
|
||||
this->clients[required_client_id] = c;
|
||||
index = required_client_id;
|
||||
|
||||
} else if (c->options.prefer_high_lobby_client_id) {
|
||||
} else if (c->options.debug) {
|
||||
for (index = max_clients - 1; index >= min_client_id; index--) {
|
||||
if (!this->clients[index].get()) {
|
||||
this->clients[index] = c;
|
||||
@@ -134,13 +133,14 @@ void Lobby::add_client(shared_ptr<Client> c, ssize_t required_client_id) {
|
||||
lobby_data.player_tag = 0x00010000;
|
||||
lobby_data.guild_card = c->license->serial_number;
|
||||
lobby_data.name = encode_sjis(c->game_data.player()->disp.name);
|
||||
this->battle_record->add_player(lobby_data,
|
||||
this->battle_record->add_player(
|
||||
lobby_data,
|
||||
c->game_data.player()->inventory,
|
||||
c->game_data.player()->disp.to_dcpcv3());
|
||||
}
|
||||
|
||||
// Send spectator count notifications if needed
|
||||
if (this->is_game() && (this->flags & Lobby::Flag::EPISODE_3_ONLY)) {
|
||||
if (this->is_game() && this->is_ep3()) {
|
||||
if (this->flags & Lobby::Flag::IS_SPECTATOR_TEAM) {
|
||||
auto watched_l = this->watched_lobby.lock();
|
||||
if (watched_l) {
|
||||
@@ -178,7 +178,7 @@ void Lobby::remove_client(shared_ptr<Client> c) {
|
||||
}
|
||||
|
||||
// If the lobby is Episode 3, update the appropriate spectator counts
|
||||
if (this->is_game() && (this->flags & Lobby::Flag::EPISODE_3_ONLY)) {
|
||||
if (this->is_game() && this->is_ep3()) {
|
||||
if (this->flags & Lobby::Flag::IS_SPECTATOR_TEAM) {
|
||||
auto watched_l = this->watched_lobby.lock();
|
||||
if (watched_l) {
|
||||
@@ -214,10 +214,8 @@ void Lobby::move_client_to_lobby(
|
||||
dest_lobby->add_client(c, required_client_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
shared_ptr<Client> Lobby::find_client(const u16string* identifier,
|
||||
uint64_t serial_number) {
|
||||
shared_ptr<Client> Lobby::find_client(
|
||||
const u16string* identifier, uint64_t serial_number) {
|
||||
for (size_t x = 0; x < this->max_clients; x++) {
|
||||
if (!this->clients[x]) {
|
||||
continue;
|
||||
@@ -234,8 +232,6 @@ shared_ptr<Client> Lobby::find_client(const u16string* identifier,
|
||||
throw out_of_range("client not found");
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t Lobby::game_event_for_lobby_event(uint8_t lobby_event) {
|
||||
if (lobby_event > 7) {
|
||||
return 0;
|
||||
@@ -249,8 +245,6 @@ uint8_t Lobby::game_event_for_lobby_event(uint8_t lobby_event) {
|
||||
return lobby_event;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Lobby::add_item(const PlayerInventoryItem& item, uint8_t area, float x, float z) {
|
||||
auto& fi = this->item_id_to_floor_item[item.data.id];
|
||||
fi.inv_item = item;
|
||||
@@ -264,7 +258,7 @@ PlayerInventoryItem Lobby::remove_item(uint32_t item_id) {
|
||||
if (item_it == this->item_id_to_floor_item.end()) {
|
||||
throw out_of_range("item not present");
|
||||
}
|
||||
PlayerInventoryItem ret = move(item_it->second.inv_item);
|
||||
PlayerInventoryItem ret = std::move(item_it->second.inv_item);
|
||||
this->item_id_to_floor_item.erase(item_it);
|
||||
return ret;
|
||||
}
|
||||
|
||||
+37
-33
@@ -2,47 +2,46 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <random>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "Client.hh"
|
||||
#include "Player.hh"
|
||||
#include "Map.hh"
|
||||
#include "RareItemSet.hh"
|
||||
#include "Text.hh"
|
||||
#include "Quest.hh"
|
||||
#include "Items.hh"
|
||||
#include "Episode3/BattleRecord.hh"
|
||||
#include "Episode3/Server.hh"
|
||||
#include "ItemCreator.hh"
|
||||
#include "Map.hh"
|
||||
#include "Player.hh"
|
||||
#include "Quest.hh"
|
||||
#include "RareItemSet.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
struct Lobby : public std::enable_shared_from_this<Lobby> {
|
||||
enum Flag {
|
||||
GAME = 0x00000001,
|
||||
EPISODE_3_ONLY = 0x00000002,
|
||||
NON_V1_ONLY = 0x00000004, // DC NTE and DCv1 not allowed
|
||||
PERSISTENT = 0x00000008,
|
||||
GAME = 0x00000001,
|
||||
NON_V1_ONLY = 0x00000002, // DC NTE and DCv1 not allowed
|
||||
PERSISTENT = 0x00000004,
|
||||
|
||||
// Flags used only for games
|
||||
CHEATS_ENABLED = 0x00000100,
|
||||
QUEST_IN_PROGRESS = 0x00000200,
|
||||
BATTLE_IN_PROGRESS = 0x00000400,
|
||||
JOINABLE_QUEST_IN_PROGRESS = 0x00000800,
|
||||
ITEM_TRACKING_ENABLED = 0x00001000,
|
||||
IS_SPECTATOR_TEAM = 0x00002000, // EPISODE_3_ONLY must also be set
|
||||
SPECTATORS_FORBIDDEN = 0x00004000,
|
||||
BATTLE_MODE = 0x00008000,
|
||||
CHALLENGE_MODE = 0x00010000,
|
||||
SOLO_MODE = 0x00020000,
|
||||
START_BATTLE_PLAYER_IMMEDIATELY = 0x00040000,
|
||||
CHEATS_ENABLED = 0x00000100,
|
||||
QUEST_IN_PROGRESS = 0x00000200,
|
||||
BATTLE_IN_PROGRESS = 0x00000400,
|
||||
JOINABLE_QUEST_IN_PROGRESS = 0x00000800,
|
||||
ITEM_TRACKING_ENABLED = 0x00001000,
|
||||
IS_SPECTATOR_TEAM = 0x00002000, // episode must be EP3 also
|
||||
SPECTATORS_FORBIDDEN = 0x00004000,
|
||||
START_BATTLE_PLAYER_IMMEDIATELY = 0x00008000,
|
||||
DROPS_ENABLED = 0x00010000, // Does not affect BB
|
||||
IS_EP3_TRIAL = 0x00020000,
|
||||
|
||||
// Flags used only for lobbies
|
||||
PUBLIC = 0x01000000,
|
||||
DEFAULT = 0x02000000,
|
||||
PUBLIC = 0x01000000,
|
||||
DEFAULT = 0x02000000,
|
||||
};
|
||||
|
||||
PrefixedLogger log;
|
||||
@@ -59,7 +58,7 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
|
||||
float z;
|
||||
uint8_t area;
|
||||
};
|
||||
std::vector<PSOEnemy> enemies;
|
||||
std::shared_ptr<Map> map;
|
||||
std::array<uint32_t, 12> next_item_id;
|
||||
uint32_t next_game_item_id;
|
||||
std::unordered_map<uint32_t, FloorItem> item_id_to_floor_item;
|
||||
@@ -68,14 +67,16 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
|
||||
// Game config
|
||||
GameVersion version;
|
||||
uint8_t section_id;
|
||||
uint8_t episode; // 1 = Ep1, 2 = Ep2, 3 = Ep4, 0xFF = Ep3
|
||||
uint8_t difficulty;
|
||||
Episode episode;
|
||||
GameMode mode;
|
||||
uint8_t difficulty; // 0-3
|
||||
uint16_t exp_multiplier;
|
||||
std::u16string password;
|
||||
std::u16string name;
|
||||
// This seed is also sent to the client for rare enemy generation
|
||||
uint32_t random_seed;
|
||||
std::shared_ptr<std::mt19937> random;
|
||||
std::shared_ptr<const CommonItemCreator> common_item_creator;
|
||||
std::shared_ptr<PSOLFGEncryption> random_crypt;
|
||||
std::shared_ptr<ItemCreator> item_creator;
|
||||
|
||||
// Ep3 stuff
|
||||
// There are three kinds of Episode 3 games. All of these types have the flag
|
||||
@@ -103,7 +104,7 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
|
||||
uint8_t leader_id;
|
||||
uint8_t max_clients;
|
||||
uint32_t flags;
|
||||
std::shared_ptr<const Quest> loading_quest;
|
||||
std::shared_ptr<const Quest> quest;
|
||||
std::array<std::shared_ptr<Client>, 12> clients;
|
||||
// Keys in this map are client_id
|
||||
std::unordered_map<size_t, std::weak_ptr<Client>> clients_to_add;
|
||||
@@ -113,6 +114,9 @@ struct Lobby : public std::enable_shared_from_this<Lobby> {
|
||||
inline bool is_game() const {
|
||||
return this->flags & Flag::GAME;
|
||||
}
|
||||
inline bool is_ep3() const {
|
||||
return this->episode == Episode::EP3;
|
||||
}
|
||||
|
||||
void reassign_leader_on_client_departure(size_t leaving_client_id);
|
||||
size_t count_clients() const;
|
||||
|
||||
+35
-46
@@ -4,58 +4,47 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
PrefixedLogger ax_messages_log ("[$ax message] " , LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger channel_exceptions_log("[Channel] " , LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger client_log ("" , LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger command_data_log ("[Commands] " , LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger config_log ("[Config] " , LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger dns_server_log ("[DNSServer] " , LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger function_compiler_log ("[FunctionCompiler] ", LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger ax_messages_log("[$ax message] ", LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger channel_exceptions_log("[Channel] ", LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger client_log("", LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger command_data_log("[Commands] ", LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger config_log("[Config] ", LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger dns_server_log("[DNSServer] ", LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger function_compiler_log("[FunctionCompiler] ", LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger ip_stack_simulator_log("[IPStackSimulator] ", LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger license_log ("[LicenseManager] " , LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger lobby_log ("" , LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger patch_index_log ("[PatchFileIndex] " , LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger player_data_log ("" , LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger proxy_server_log ("[ProxyServer] " , LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger replay_log ("[ReplaySession] " , LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger server_log ("[Server] " , LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger static_game_data_log ("[StaticGameData] " , LogLevel::USE_DEFAULT);
|
||||
|
||||
static LogLevel log_level_for_name(const string& name) {
|
||||
static const unordered_map<string, LogLevel> levels({
|
||||
{"debug", LogLevel::DEBUG},
|
||||
{"info", LogLevel::INFO},
|
||||
{"warning", LogLevel::WARNING},
|
||||
{"error", LogLevel::ERROR},
|
||||
{"disabled", LogLevel::DISABLED},
|
||||
});
|
||||
return levels.at(tolower(name));
|
||||
}
|
||||
PrefixedLogger license_log("[LicenseManager] ", LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger lobby_log("", LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger patch_index_log("[PatchFileIndex] ", LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger player_data_log("", LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger proxy_server_log("[ProxyServer] ", LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger replay_log("[ReplaySession] ", LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger server_log("[Server] ", LogLevel::USE_DEFAULT);
|
||||
PrefixedLogger static_game_data_log("[StaticGameData] ", LogLevel::USE_DEFAULT);
|
||||
|
||||
static void set_log_level_from_json(
|
||||
PrefixedLogger& log, shared_ptr<JSONObject> d, const char* json_key) {
|
||||
PrefixedLogger& log, const JSON& d, const char* json_key) {
|
||||
try {
|
||||
log.min_level = log_level_for_name(d->at(json_key)->as_string());
|
||||
} catch (const JSONObject::key_error&) { }
|
||||
string name = toupper(d.at(json_key).as_string());
|
||||
log.min_level = enum_for_name<LogLevel>(name.c_str());
|
||||
} catch (const out_of_range&) {
|
||||
}
|
||||
}
|
||||
|
||||
void set_log_levels_from_json(shared_ptr<JSONObject> json) {
|
||||
set_log_level_from_json(ax_messages_log , json, "AXMessages");
|
||||
void set_log_levels_from_json(const JSON& json) {
|
||||
set_log_level_from_json(ax_messages_log, json, "AXMessages");
|
||||
set_log_level_from_json(channel_exceptions_log, json, "ChannelExceptions");
|
||||
set_log_level_from_json(client_log , json, "Clients");
|
||||
set_log_level_from_json(command_data_log , json, "CommandData");
|
||||
set_log_level_from_json(config_log , json, "Config");
|
||||
set_log_level_from_json(dns_server_log , json, "DNSServer");
|
||||
set_log_level_from_json(function_compiler_log , json, "FunctionCompiler");
|
||||
set_log_level_from_json(client_log, json, "Clients");
|
||||
set_log_level_from_json(command_data_log, json, "CommandData");
|
||||
set_log_level_from_json(config_log, json, "Config");
|
||||
set_log_level_from_json(dns_server_log, json, "DNSServer");
|
||||
set_log_level_from_json(function_compiler_log, json, "FunctionCompiler");
|
||||
set_log_level_from_json(ip_stack_simulator_log, json, "IPStackSimulator");
|
||||
set_log_level_from_json(license_log , json, "LicenseManager");
|
||||
set_log_level_from_json(lobby_log , json, "Lobbies");
|
||||
set_log_level_from_json(patch_index_log , json, "PatchFileIndex");
|
||||
set_log_level_from_json(player_data_log , json, "PlayerData");
|
||||
set_log_level_from_json(proxy_server_log , json, "ProxyServer");
|
||||
set_log_level_from_json(replay_log , json, "Replay");
|
||||
set_log_level_from_json(server_log , json, "GameServer");
|
||||
set_log_level_from_json(static_game_data_log , json, "StaticGameData");
|
||||
set_log_level_from_json(license_log, json, "LicenseManager");
|
||||
set_log_level_from_json(lobby_log, json, "Lobbies");
|
||||
set_log_level_from_json(patch_index_log, json, "PatchFileIndex");
|
||||
set_log_level_from_json(player_data_log, json, "PlayerData");
|
||||
set_log_level_from_json(proxy_server_log, json, "ProxyServer");
|
||||
set_log_level_from_json(replay_log, json, "Replay");
|
||||
set_log_level_from_json(server_log, json, "GameServer");
|
||||
set_log_level_from_json(static_game_data_log, json, "StaticGameData");
|
||||
}
|
||||
|
||||
+2
-4
@@ -1,9 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <phosg/Strings.hh>
|
||||
#include <phosg/JSON.hh>
|
||||
|
||||
|
||||
#include <phosg/Strings.hh>
|
||||
|
||||
extern PrefixedLogger ax_messages_log;
|
||||
extern PrefixedLogger channel_exceptions_log;
|
||||
@@ -22,4 +20,4 @@ extern PrefixedLogger replay_log;
|
||||
extern PrefixedLogger server_log;
|
||||
extern PrefixedLogger static_game_data_log;
|
||||
|
||||
void set_log_levels_from_json(std::shared_ptr<JSONObject> json);
|
||||
void set_log_levels_from_json(const JSON& json);
|
||||
|
||||
+1042
-429
File diff suppressed because it is too large
Load Diff
+549
-452
File diff suppressed because it is too large
Load Diff
+52
-77
@@ -8,83 +8,60 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "BattleParamsIndex.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
|
||||
|
||||
class BattleParamsIndex {
|
||||
public:
|
||||
struct Entry {
|
||||
le_uint16_t atp; // attack power
|
||||
le_uint16_t psv; // perseverance (intelligence?)
|
||||
le_uint16_t evp; // evasion
|
||||
le_uint16_t hp; // hit points
|
||||
le_uint16_t dfp; // defense
|
||||
le_uint16_t ata; // accuracy
|
||||
le_uint16_t lck; // luck
|
||||
le_uint16_t esp; // ???
|
||||
uint8_t unknown_a1[0x0C];
|
||||
le_uint32_t experience;
|
||||
le_uint32_t difficulty;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Table {
|
||||
parray<parray<Entry, 0x60>, 4> difficulty;
|
||||
} __attribute__((packed));
|
||||
|
||||
BattleParamsIndex(
|
||||
std::shared_ptr<const std::string> data_on_ep1, // BattleParamEntry_on.dat
|
||||
std::shared_ptr<const std::string> data_on_ep2, // BattleParamEntry_lab_on.dat
|
||||
std::shared_ptr<const std::string> data_on_ep4, // BattleParamEntry_ep4_on.dat
|
||||
std::shared_ptr<const std::string> data_off_ep1, // BattleParamEntry.dat
|
||||
std::shared_ptr<const std::string> data_off_ep2, // BattleParamEntry_lab.dat
|
||||
std::shared_ptr<const std::string> data_off_ep4); // BattleParamEntry_ep4.dat
|
||||
|
||||
const Entry& get(bool solo, uint8_t episode, uint8_t difficulty,
|
||||
uint8_t monster_type) const;
|
||||
|
||||
private:
|
||||
struct LoadedFile {
|
||||
std::shared_ptr<const std::string> data;
|
||||
const Table* table;
|
||||
struct Map {
|
||||
struct RareEnemyRates {
|
||||
uint32_t hildeblue; // HILDEBEAR -> HILDEBLUE
|
||||
uint32_t rappy; // RAG_RAPPY -> {AL_RAPPY or seasonal rappies}; SAND_RAPPY -> DEL_RAPPY
|
||||
uint32_t nar_lily; // POISON_LILY -> NAR_LILY
|
||||
uint32_t pouilly_slime; // POFUILLY_SLIME -> POUILLY_SLIME
|
||||
uint32_t merissa_aa; // MERISSA_A -> MERISSA_AA
|
||||
uint32_t pazuzu; // ZU -> PAZUZU (and _ALT variants)
|
||||
uint32_t dorphon_eclair; // DORPHON -> DORPHON_ECLAIR
|
||||
uint32_t kondrieu; // {SAINT_MILLION, SHAMBERTIN} -> KONDRIEU
|
||||
};
|
||||
|
||||
// online/offline, episode
|
||||
LoadedFile files[2][3];
|
||||
struct Enemy {
|
||||
enum Flag {
|
||||
HIT_BY_PLAYER0 = 0x01,
|
||||
HIT_BY_PLAYER1 = 0x02,
|
||||
HIT_BY_PLAYER2 = 0x04,
|
||||
HIT_BY_PLAYER3 = 0x08,
|
||||
DEFEATED = 0x10,
|
||||
ITEM_DROPPED = 0x20,
|
||||
};
|
||||
EnemyType type;
|
||||
uint8_t flags;
|
||||
uint8_t last_hit_by_client_id;
|
||||
|
||||
explicit Enemy(EnemyType type);
|
||||
|
||||
std::string str() const;
|
||||
} __attribute__((packed));
|
||||
|
||||
std::vector<Enemy> enemies;
|
||||
std::vector<size_t> rare_enemy_indexes;
|
||||
|
||||
void clear();
|
||||
void add_enemies_from_map_data(
|
||||
Episode episode,
|
||||
uint8_t difficulty,
|
||||
uint8_t event,
|
||||
const void* data,
|
||||
size_t size,
|
||||
const RareEnemyRates* rare_rates = nullptr);
|
||||
void add_enemies_from_quest_data(
|
||||
Episode episode,
|
||||
uint8_t difficulty,
|
||||
uint8_t event,
|
||||
const void* data,
|
||||
size_t size);
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct PSOEnemy {
|
||||
uint64_t id;
|
||||
uint16_t source_type;
|
||||
uint8_t hit_flags;
|
||||
uint8_t last_hit;
|
||||
uint32_t experience;
|
||||
uint32_t rt_index;
|
||||
const char* type_name;
|
||||
|
||||
explicit PSOEnemy(uint64_t id);
|
||||
PSOEnemy(
|
||||
uint64_t id,
|
||||
uint16_t source_type,
|
||||
uint32_t experience,
|
||||
uint32_t rt_index,
|
||||
const char* type_name);
|
||||
|
||||
std::string str() const;
|
||||
} __attribute__((packed));
|
||||
|
||||
std::vector<PSOEnemy> parse_map(
|
||||
std::shared_ptr<const BattleParamsIndex> battle_params,
|
||||
bool is_solo,
|
||||
uint8_t episode,
|
||||
uint8_t difficulty,
|
||||
std::shared_ptr<const std::string> data,
|
||||
bool alt_enemies);
|
||||
|
||||
|
||||
|
||||
// TODO: This class is currently unused. It would be nice if we could use this
|
||||
// to generate variations and link to the corresponding map filenames, but it
|
||||
// seems that SetDataTable.rel files link to map filenames that don't actually
|
||||
@@ -106,7 +83,7 @@ public:
|
||||
void print(FILE* stream) const;
|
||||
|
||||
private:
|
||||
template <typename U32T>
|
||||
template <bool IsBigEndian>
|
||||
void load_table_t(std::shared_ptr<const std::string> data);
|
||||
|
||||
// Indexes are [area_id][variation1][variation2]
|
||||
@@ -114,13 +91,11 @@ private:
|
||||
std::vector<std::vector<std::vector<SetEntry>>> entries;
|
||||
};
|
||||
|
||||
|
||||
|
||||
void generate_variations(
|
||||
parray<le_uint32_t, 0x20>& variations,
|
||||
std::shared_ptr<std::mt19937> random,
|
||||
uint8_t episode,
|
||||
std::shared_ptr<PSOLFGEncryption> random,
|
||||
Episode episode,
|
||||
bool is_solo);
|
||||
std::vector<std::string> map_filenames_for_variation(
|
||||
uint8_t episode, bool is_solo, uint8_t area, uint32_t var1, uint32_t var2);
|
||||
Episode episode, bool is_solo, uint8_t area, uint32_t var1, uint32_t var2);
|
||||
void load_map_files();
|
||||
|
||||
+19
-3
@@ -2,8 +2,24 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
MenuItem::MenuItem(
|
||||
uint32_t item_id, const u16string& name,
|
||||
const u16string& description, uint32_t flags)
|
||||
: item_id(item_id),
|
||||
name(name),
|
||||
description(description),
|
||||
get_description(nullptr),
|
||||
flags(flags) {}
|
||||
|
||||
MenuItem::MenuItem(
|
||||
uint32_t item_id, const u16string& name,
|
||||
std::function<std::u16string()> get_description, uint32_t flags)
|
||||
: item_id(item_id),
|
||||
name(name),
|
||||
description(),
|
||||
get_description(std::move(get_description)),
|
||||
flags(flags) {}
|
||||
|
||||
MenuItem::MenuItem(uint32_t item_id, const u16string& name,
|
||||
const u16string& description, uint32_t flags) : item_id(item_id), name(name),
|
||||
description(description), flags(flags) { }
|
||||
Menu::Menu(uint32_t menu_id, const std::u16string& name)
|
||||
: menu_id(menu_id),
|
||||
name(name) {}
|
||||
|
||||
+61
-48
@@ -2,9 +2,9 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
||||
// Note: These aren't enums because neither enum nor enum class does what we
|
||||
// want. Specifically, we need GO_BACK to be valid in multiple enums (and enums
|
||||
@@ -13,67 +13,67 @@
|
||||
// casting values all over the place, so we can't use enum classes either.
|
||||
|
||||
namespace MenuID {
|
||||
constexpr uint32_t MAIN = 0x11000011;
|
||||
constexpr uint32_t INFORMATION = 0x22000022;
|
||||
constexpr uint32_t LOBBY = 0x33000033;
|
||||
constexpr uint32_t GAME = 0x44000044;
|
||||
constexpr uint32_t QUEST = 0x55000055;
|
||||
constexpr uint32_t QUEST_FILTER = 0x66000066;
|
||||
constexpr uint32_t PROXY_DESTINATIONS = 0x77000077;
|
||||
constexpr uint32_t PROGRAMS = 0x88000088;
|
||||
constexpr uint32_t PATCHES = 0x99000099;
|
||||
constexpr uint32_t PROXY_OPTIONS = 0xAA0000AA;
|
||||
constexpr uint32_t TOURNAMENTS = 0xBB0000BB;
|
||||
constexpr uint32_t TOURNAMENTS_FOR_SPEC = 0xBB1111BB;
|
||||
constexpr uint32_t TOURNAMENT_ENTRIES = 0xCC0000CC;
|
||||
}
|
||||
constexpr uint32_t MAIN = 0x11000011;
|
||||
constexpr uint32_t INFORMATION = 0x22000022;
|
||||
constexpr uint32_t LOBBY = 0x33000033;
|
||||
constexpr uint32_t GAME = 0x44000044;
|
||||
constexpr uint32_t QUEST = 0x55000055;
|
||||
constexpr uint32_t QUEST_FILTER = 0x66000066;
|
||||
constexpr uint32_t PROXY_DESTINATIONS = 0x77000077;
|
||||
constexpr uint32_t PROGRAMS = 0x88000088;
|
||||
constexpr uint32_t PATCHES = 0x99000099;
|
||||
constexpr uint32_t PROXY_OPTIONS = 0xAA0000AA;
|
||||
constexpr uint32_t TOURNAMENTS = 0xBB0000BB;
|
||||
constexpr uint32_t TOURNAMENTS_FOR_SPEC = 0xBB1111BB;
|
||||
constexpr uint32_t TOURNAMENT_ENTRIES = 0xCC0000CC;
|
||||
} // namespace MenuID
|
||||
|
||||
namespace MainMenuItemID {
|
||||
constexpr uint32_t GO_TO_LOBBY = 0x11222211;
|
||||
constexpr uint32_t INFORMATION = 0x11333311;
|
||||
constexpr uint32_t DOWNLOAD_QUESTS = 0x11444411;
|
||||
constexpr uint32_t PROXY_DESTINATIONS = 0x11555511;
|
||||
constexpr uint32_t PATCHES = 0x11666611;
|
||||
constexpr uint32_t PROGRAMS = 0x11777711;
|
||||
constexpr uint32_t DISCONNECT = 0x11888811;
|
||||
constexpr uint32_t CLEAR_LICENSE = 0x11999911;
|
||||
}
|
||||
constexpr uint32_t GO_TO_LOBBY = 0x11222211;
|
||||
constexpr uint32_t INFORMATION = 0x11333311;
|
||||
constexpr uint32_t DOWNLOAD_QUESTS = 0x11444411;
|
||||
constexpr uint32_t PROXY_DESTINATIONS = 0x11555511;
|
||||
constexpr uint32_t PATCHES = 0x11666611;
|
||||
constexpr uint32_t PROGRAMS = 0x11777711;
|
||||
constexpr uint32_t DISCONNECT = 0x11888811;
|
||||
constexpr uint32_t CLEAR_LICENSE = 0x11999911;
|
||||
} // namespace MainMenuItemID
|
||||
|
||||
namespace InformationMenuItemID {
|
||||
constexpr uint32_t GO_BACK = 0x22FFFF22;
|
||||
constexpr uint32_t GO_BACK = 0x22FFFF22;
|
||||
}
|
||||
|
||||
namespace ProxyDestinationsMenuItemID {
|
||||
constexpr uint32_t GO_BACK = 0x77FFFF77;
|
||||
constexpr uint32_t OPTIONS = 0x77EEEE77;
|
||||
}
|
||||
constexpr uint32_t GO_BACK = 0x77FFFF77;
|
||||
constexpr uint32_t OPTIONS = 0x77EEEE77;
|
||||
} // namespace ProxyDestinationsMenuItemID
|
||||
|
||||
namespace ProgramsMenuItemID {
|
||||
constexpr uint32_t GO_BACK = 0x88FFFF88;
|
||||
constexpr uint32_t GO_BACK = 0x88FFFF88;
|
||||
}
|
||||
|
||||
namespace PatchesMenuItemID {
|
||||
constexpr uint32_t GO_BACK = 0x99FFFF99;
|
||||
constexpr uint32_t GO_BACK = 0x99FFFF99;
|
||||
}
|
||||
|
||||
namespace ProxyOptionsMenuItemID {
|
||||
constexpr uint32_t GO_BACK = 0xAAFFFFAA;
|
||||
constexpr uint32_t CHAT_COMMANDS = 0xAA0000AA;
|
||||
constexpr uint32_t CHAT_FILTER = 0xAA1111AA;
|
||||
constexpr uint32_t INFINITE_HP = 0xAA2222AA;
|
||||
constexpr uint32_t INFINITE_TP = 0xAA3333AA;
|
||||
constexpr uint32_t SWITCH_ASSIST = 0xAA4444AA;
|
||||
constexpr uint32_t BLOCK_EVENTS = 0xAA5555AA;
|
||||
constexpr uint32_t BLOCK_PATCHES = 0xAA6666AA;
|
||||
constexpr uint32_t SAVE_FILES = 0xAA7777AA;
|
||||
constexpr uint32_t RED_NAME = 0xAA8888AA;
|
||||
constexpr uint32_t BLANK_NAME = 0xAA9999AA;
|
||||
constexpr uint32_t SUPPRESS_LOGIN = 0xAAAAAAAA;
|
||||
constexpr uint32_t SKIP_CARD = 0xAABBBBAA;
|
||||
constexpr uint32_t EP3_INFINITE_MESETA = 0xAACCCCAA;
|
||||
}
|
||||
|
||||
|
||||
constexpr uint32_t GO_BACK = 0xAAFFFFAA;
|
||||
constexpr uint32_t CHAT_COMMANDS = 0xAA0000AA;
|
||||
constexpr uint32_t CHAT_FILTER = 0xAA1111AA;
|
||||
constexpr uint32_t PLAYER_NOTIFICATIONS = 0xAA2222AA;
|
||||
constexpr uint32_t BLOCK_PINGS = 0xAA3333AA;
|
||||
constexpr uint32_t INFINITE_HP = 0xAA4444AA;
|
||||
constexpr uint32_t INFINITE_TP = 0xAA5555AA;
|
||||
constexpr uint32_t SWITCH_ASSIST = 0xAA6666AA;
|
||||
constexpr uint32_t BLOCK_EVENTS = 0xAA7777AA;
|
||||
constexpr uint32_t BLOCK_PATCHES = 0xAA8888AA;
|
||||
constexpr uint32_t SAVE_FILES = 0xAA9999AA;
|
||||
constexpr uint32_t RED_NAME = 0xAAAAAAAA;
|
||||
constexpr uint32_t BLANK_NAME = 0xAABBBBAA;
|
||||
constexpr uint32_t SUPPRESS_LOGIN = 0xAACCCCAA;
|
||||
constexpr uint32_t SKIP_CARD = 0xAADDDDAA;
|
||||
constexpr uint32_t EP3_INFINITE_MESETA = 0xAAEEEEAA;
|
||||
} // namespace ProxyOptionsMenuItemID
|
||||
|
||||
struct MenuItem {
|
||||
enum Flag {
|
||||
@@ -94,13 +94,26 @@ struct MenuItem {
|
||||
REQUIRES_MESSAGE_BOXES = 0x080,
|
||||
REQUIRES_SEND_FUNCTION_CALL = 0x100,
|
||||
REQUIRES_SAVE_DISABLED = 0x200,
|
||||
INVISIBLE_IN_INFO_MENU = 0x400,
|
||||
};
|
||||
|
||||
uint32_t item_id;
|
||||
std::u16string name;
|
||||
std::u16string description;
|
||||
std::function<std::u16string()> get_description;
|
||||
uint32_t flags;
|
||||
|
||||
MenuItem(uint32_t item_id, const std::u16string& name,
|
||||
const std::u16string& description, uint32_t flags);
|
||||
MenuItem(uint32_t item_id, const std::u16string& name,
|
||||
std::function<std::u16string()> get_description, uint32_t flags);
|
||||
};
|
||||
|
||||
struct Menu {
|
||||
uint32_t menu_id;
|
||||
std::u16string name;
|
||||
std::vector<MenuItem> items;
|
||||
|
||||
Menu() = delete;
|
||||
Menu(uint32_t menu_id, const std::u16string& name);
|
||||
};
|
||||
|
||||
+11
-15
@@ -1,14 +1,12 @@
|
||||
#include "NetworkAddresses.hh"
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#include <errno.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <errno.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <memory>
|
||||
#include <phosg/Encoding.hh>
|
||||
@@ -17,19 +15,17 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
uint32_t resolve_address(const char* address) {
|
||||
struct addrinfo *res0;
|
||||
struct addrinfo* res0;
|
||||
if (getaddrinfo(address, nullptr, nullptr, &res0)) {
|
||||
auto e = string_for_error(errno);
|
||||
throw runtime_error(string_printf("can\'t resolve hostname %s: %s", address,
|
||||
e.c_str()));
|
||||
throw runtime_error(string_printf(
|
||||
"can\'t resolve hostname %s: %s", address, e.c_str()));
|
||||
}
|
||||
|
||||
std::unique_ptr<struct addrinfo, void(*)(struct addrinfo*)> res0_unique(
|
||||
std::unique_ptr<struct addrinfo, void (*)(struct addrinfo*)> res0_unique(
|
||||
res0, freeaddrinfo);
|
||||
struct addrinfo *res4 = nullptr;
|
||||
struct addrinfo* res4 = nullptr;
|
||||
for (struct addrinfo* res = res0; res; res = res->ai_next) {
|
||||
if (res->ai_family == AF_INET) {
|
||||
res4 = res;
|
||||
@@ -51,7 +47,7 @@ map<string, uint32_t> get_local_addresses() {
|
||||
throw runtime_error(string_printf("failed to get interface addresses: %s", s.c_str()));
|
||||
}
|
||||
|
||||
unique_ptr<struct ifaddrs, void(*)(struct ifaddrs*)> ifa(ifa_raw, freeifaddrs);
|
||||
unique_ptr<struct ifaddrs, void (*)(struct ifaddrs*)> ifa(ifa_raw, freeifaddrs);
|
||||
|
||||
map<string, uint32_t> ret;
|
||||
for (struct ifaddrs* i = ifa.get(); i; i = i->ifa_next) {
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
// PSO is IPv4-only, so we just treat addresses as uint32_t everywhere because
|
||||
// it's easier
|
||||
|
||||
|
||||
+188
-87
@@ -3,29 +3,27 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Random.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
// TODO: fix style in this file, especially in psobb functions
|
||||
|
||||
|
||||
|
||||
// Most ciphers used by PSO are symmetric; alias decrypt to encrypt by default
|
||||
void PSOEncryption::decrypt(void* data, size_t size, bool advance) {
|
||||
this->encrypt(data, size, advance);
|
||||
}
|
||||
|
||||
|
||||
|
||||
PSOLFGEncryption::PSOLFGEncryption(
|
||||
uint32_t seed, size_t stream_length, size_t end_offset)
|
||||
: stream(stream_length, 0), offset(0), end_offset(end_offset), seed(seed) { }
|
||||
: stream(stream_length, 0),
|
||||
offset(0),
|
||||
end_offset(end_offset),
|
||||
seed(seed) {}
|
||||
|
||||
uint32_t PSOLFGEncryption::next(bool advance) {
|
||||
if (this->offset == this->end_offset) {
|
||||
@@ -38,8 +36,10 @@ uint32_t PSOLFGEncryption::next(bool advance) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename LongT>
|
||||
template <bool IsBigEndian>
|
||||
void PSOLFGEncryption::encrypt_t(void* vdata, size_t size, bool advance) {
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
|
||||
if (size & 3) {
|
||||
throw invalid_argument("size must be a multiple of 4");
|
||||
}
|
||||
@@ -48,18 +48,44 @@ void PSOLFGEncryption::encrypt_t(void* vdata, size_t size, bool advance) {
|
||||
}
|
||||
size >>= 2;
|
||||
|
||||
LongT* data = reinterpret_cast<LongT*>(vdata);
|
||||
U32T* data = reinterpret_cast<U32T*>(vdata);
|
||||
for (size_t x = 0; x < size; x++) {
|
||||
data[x] ^= this->next(advance);
|
||||
}
|
||||
}
|
||||
|
||||
template <bool IsBigEndian>
|
||||
void PSOLFGEncryption::encrypt_minus_t(void* vdata, size_t size, bool advance) {
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
|
||||
if (size & 3) {
|
||||
throw invalid_argument("size must be a multiple of 4");
|
||||
}
|
||||
if (!advance && (size != 4)) {
|
||||
throw logic_error("cannot peek-encrypt/decrypt with size > 4");
|
||||
}
|
||||
size >>= 2;
|
||||
|
||||
U32T* data = reinterpret_cast<U32T*>(vdata);
|
||||
for (size_t x = 0; x < size; x++) {
|
||||
data[x] = this->next(advance) - data[x];
|
||||
}
|
||||
}
|
||||
|
||||
void PSOLFGEncryption::encrypt(void* vdata, size_t size, bool advance) {
|
||||
this->encrypt_t<le_uint32_t>(vdata, size, advance);
|
||||
this->encrypt_t<false>(vdata, size, advance);
|
||||
}
|
||||
|
||||
void PSOLFGEncryption::encrypt_big_endian(void* vdata, size_t size, bool advance) {
|
||||
this->encrypt_t<be_uint32_t>(vdata, size, advance);
|
||||
this->encrypt_t<true>(vdata, size, advance);
|
||||
}
|
||||
|
||||
void PSOLFGEncryption::encrypt_minus(void* vdata, size_t size, bool advance) {
|
||||
this->encrypt_minus_t<false>(vdata, size, advance);
|
||||
}
|
||||
|
||||
void PSOLFGEncryption::encrypt_big_endian_minus(void* vdata, size_t size, bool advance) {
|
||||
this->encrypt_minus_t<true>(vdata, size, advance);
|
||||
}
|
||||
|
||||
void PSOLFGEncryption::encrypt_both_endian(
|
||||
@@ -81,10 +107,8 @@ void PSOLFGEncryption::encrypt_both_endian(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
PSOV2Encryption::PSOV2Encryption(uint32_t seed)
|
||||
: PSOLFGEncryption(seed, this->STREAM_LENGTH + 1, this->STREAM_LENGTH) {
|
||||
: PSOLFGEncryption(seed, this->STREAM_LENGTH + 1, this->STREAM_LENGTH) {
|
||||
uint32_t esi, ebx, edi, eax, edx, var1;
|
||||
esi = 1;
|
||||
ebx = this->seed;
|
||||
@@ -135,10 +159,8 @@ PSOEncryption::Type PSOV2Encryption::type() const {
|
||||
return Type::V2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PSOV3Encryption::PSOV3Encryption(uint32_t seed)
|
||||
: PSOLFGEncryption(seed, this->STREAM_LENGTH, this->STREAM_LENGTH) {
|
||||
: PSOLFGEncryption(seed, this->STREAM_LENGTH, this->STREAM_LENGTH) {
|
||||
uint32_t x, y, basekey, source1, source2, source3;
|
||||
basekey = 0;
|
||||
|
||||
@@ -191,11 +213,9 @@ PSOEncryption::Type PSOV3Encryption::type() const {
|
||||
return Type::V3;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PSOBBEncryption::PSOBBEncryption(
|
||||
const KeyFile& key, const void* original_seed, size_t seed_size)
|
||||
: state(key) {
|
||||
: state(key) {
|
||||
this->apply_seed(original_seed, seed_size);
|
||||
}
|
||||
|
||||
@@ -210,14 +230,14 @@ void PSOBBEncryption::encrypt(void* vdata, size_t size, bool advance) {
|
||||
for (size_t y = 0; y < 4; y += 2) {
|
||||
dwords[x] ^= this->state.initial_keys.as32[y];
|
||||
dwords[x + 1] ^= ((this->state.private_keys.as32[dwords[x] >> 24] +
|
||||
this->state.private_keys.as32[((dwords[x] >> 16) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((dwords[x] >> 8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(dwords[x] & 0xFF) + 0x300];
|
||||
this->state.private_keys.as32[((dwords[x] >> 16) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((dwords[x] >> 8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(dwords[x] & 0xFF) + 0x300];
|
||||
dwords[x + 1] ^= this->state.initial_keys.as32[y + 1];
|
||||
dwords[x] ^= ((this->state.private_keys.as32[dwords[x + 1] >> 24] +
|
||||
this->state.private_keys.as32[(dwords[x + 1] >> 16 & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[(dwords[x + 1] >> 8 & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(dwords[x + 1] & 0xFF) + 0x300];
|
||||
this->state.private_keys.as32[(dwords[x + 1] >> 16 & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[(dwords[x + 1] >> 8 & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(dwords[x + 1] & 0xFF) + 0x300];
|
||||
}
|
||||
dwords[x] ^= this->state.initial_keys.as32[4];
|
||||
dwords[x + 1] ^= this->state.initial_keys.as32[5];
|
||||
@@ -266,26 +286,26 @@ void PSOBBEncryption::encrypt(void* vdata, size_t size, bool advance) {
|
||||
while (edx < num_dwords) {
|
||||
ebx = data[edx] ^ this->state.initial_keys.as32[0];
|
||||
ebp = ((this->state.private_keys.as32[(ebx >> 0x18)] +
|
||||
this->state.private_keys.as32[((ebx >> 0x10) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((ebx >> 0x8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(ebx & 0xFF) + 0x300];
|
||||
this->state.private_keys.as32[((ebx >> 0x10) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((ebx >> 0x8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(ebx & 0xFF) + 0x300];
|
||||
ebp = ebp ^ this->state.initial_keys.as32[1];
|
||||
ebp ^= data[edx + 1];
|
||||
edi = ((this->state.private_keys.as32[(ebp >> 0x18)] +
|
||||
this->state.private_keys.as32[((ebp >> 0x10) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((ebp >> 0x8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(ebp & 0xFF) + 0x300];
|
||||
this->state.private_keys.as32[((ebp >> 0x10) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((ebp >> 0x8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(ebp & 0xFF) + 0x300];
|
||||
edi = edi ^ this->state.initial_keys.as32[2];
|
||||
ebx = ebx ^ edi;
|
||||
esi = ((this->state.private_keys.as32[(ebx >> 0x18)] +
|
||||
this->state.private_keys.as32[((ebx >> 0x10) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((ebx >> 0x8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(ebx & 0xFF) + 0x300];
|
||||
this->state.private_keys.as32[((ebx >> 0x10) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((ebx >> 0x8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(ebx & 0xFF) + 0x300];
|
||||
ebp = ebp ^ esi ^ this->state.initial_keys.as32[3];
|
||||
edi = ((this->state.private_keys.as32[(ebp >> 0x18)] +
|
||||
this->state.private_keys.as32[((ebp >> 0x10) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((ebp >> 0x8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(ebp & 0xFF) + 0x300];
|
||||
this->state.private_keys.as32[((ebp >> 0x10) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((ebp >> 0x8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(ebp & 0xFF) + 0x300];
|
||||
edi = edi ^ this->state.initial_keys.as32[4];
|
||||
ebp = ebp ^ this->state.initial_keys.as32[5];
|
||||
ebx = ebx ^ edi;
|
||||
@@ -307,14 +327,14 @@ void PSOBBEncryption::decrypt(void* vdata, size_t size, bool advance) {
|
||||
for (size_t y = 4; y > 0; y -= 2) {
|
||||
dwords[x] = dwords[x] ^ this->state.initial_keys.as32[y + 1];
|
||||
dwords[x + 1] ^= ((this->state.private_keys.as32[dwords[x] >> 24] +
|
||||
this->state.private_keys.as32[((dwords[x] >> 16) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((dwords[x] >> 8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(dwords[x] & 0xFF) + 0x300];
|
||||
this->state.private_keys.as32[((dwords[x] >> 16) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((dwords[x] >> 8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(dwords[x] & 0xFF) + 0x300];
|
||||
dwords[x + 1] ^= this->state.initial_keys.as32[y];
|
||||
dwords[x] ^= ((this->state.private_keys.as32[dwords[x + 1] >> 24] +
|
||||
this->state.private_keys.as32[((dwords[x + 1] >> 16) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((dwords[x + 1] >> 8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(dwords[x + 1] & 0xFF) + 0x300];
|
||||
this->state.private_keys.as32[((dwords[x + 1] >> 16) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((dwords[x + 1] >> 8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(dwords[x + 1] & 0xFF) + 0x300];
|
||||
}
|
||||
dwords[x] ^= this->state.initial_keys.as32[1];
|
||||
dwords[x + 1] ^= this->state.initial_keys.as32[0];
|
||||
@@ -362,26 +382,26 @@ void PSOBBEncryption::decrypt(void* vdata, size_t size, bool advance) {
|
||||
ebx = dwords[edx];
|
||||
ebx = ebx ^ this->state.initial_keys.as32[5];
|
||||
ebp = ((this->state.private_keys.as32[(ebx >> 0x18)] +
|
||||
this->state.private_keys.as32[((ebx >> 0x10) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((ebx >> 0x8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(ebx & 0xFF) + 0x300];
|
||||
this->state.private_keys.as32[((ebx >> 0x10) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((ebx >> 0x8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(ebx & 0xFF) + 0x300];
|
||||
ebp = ebp ^ this->state.initial_keys.as32[4];
|
||||
ebp ^= dwords[edx + 1];
|
||||
edi = ((this->state.private_keys.as32[(ebp >> 0x18)] +
|
||||
this->state.private_keys.as32[((ebp >> 0x10) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((ebp >> 0x8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(ebp & 0xFF) + 0x300];
|
||||
this->state.private_keys.as32[((ebp >> 0x10) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((ebp >> 0x8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(ebp & 0xFF) + 0x300];
|
||||
edi = edi ^ this->state.initial_keys.as32[3];
|
||||
ebx = ebx ^ edi;
|
||||
esi = ((this->state.private_keys.as32[(ebx >> 0x18)] +
|
||||
this->state.private_keys.as32[((ebx >> 0x10) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((ebx >> 0x8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(ebx & 0xFF) + 0x300];
|
||||
this->state.private_keys.as32[((ebx >> 0x10) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((ebx >> 0x8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(ebx & 0xFF) + 0x300];
|
||||
ebp = ebp ^ esi ^ this->state.initial_keys.as32[2];
|
||||
edi = ((this->state.private_keys.as32[(ebp >> 0x18)] +
|
||||
this->state.private_keys.as32[((ebp >> 0x10) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((ebp >> 0x8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(ebp & 0xFF) + 0x300];
|
||||
this->state.private_keys.as32[((ebp >> 0x10) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((ebp >> 0x8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(ebp & 0xFF) + 0x300];
|
||||
edi = edi ^ this->state.initial_keys.as32[1];
|
||||
ebp = ebp ^ this->state.initial_keys.as32[0];
|
||||
ebx = ebx ^ edi;
|
||||
@@ -402,13 +422,14 @@ void PSOBBEncryption::tfs1_scramble(uint32_t* out1, uint32_t* out2) const {
|
||||
for (size_t x = 0; x < 0x10; x += 2) {
|
||||
a ^= this->state.initial_keys.as32[x];
|
||||
b ^= (((this->state.private_keys.as32[a >> 24] +
|
||||
this->state.private_keys.as32[((a >> 16) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((a >> 8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(a & 0xFF) + 0x300]) ^ this->state.initial_keys.as32[x + 1];
|
||||
this->state.private_keys.as32[((a >> 16) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((a >> 8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(a & 0xFF) + 0x300]) ^
|
||||
this->state.initial_keys.as32[x + 1];
|
||||
a ^= ((this->state.private_keys.as32[b >> 24] +
|
||||
this->state.private_keys.as32[((b >> 16) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((b >> 8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(b & 0xFF) + 0x300];
|
||||
this->state.private_keys.as32[((b >> 16) & 0xFF) + 0x100]) ^
|
||||
this->state.private_keys.as32[((b >> 8) & 0xFF) + 0x200]) +
|
||||
this->state.private_keys.as32[(b & 0xFF) + 0x300];
|
||||
}
|
||||
*out1 = this->state.initial_keys.as32[0x11] ^ b;
|
||||
*out2 = this->state.initial_keys.as32[0x10] ^ a;
|
||||
@@ -580,7 +601,7 @@ void PSOBBEncryption::apply_seed(const void* original_seed, size_t seed_size) {
|
||||
esi = this->state.initial_keys.as32[17];
|
||||
esi = esi ^ eax;
|
||||
this->state.initial_keys.as32[(edi / 4)] = esi;
|
||||
this->state.initial_keys.as32[(edi / 4)+1] = ecx;
|
||||
this->state.initial_keys.as32[(edi / 4) + 1] = ecx;
|
||||
edi = edi + 8;
|
||||
}
|
||||
|
||||
@@ -667,13 +688,13 @@ void PSOBBEncryption::apply_seed(const void* original_seed, size_t seed_size) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
PSOV2OrV3DetectorEncryption::PSOV2OrV3DetectorEncryption(
|
||||
uint32_t key,
|
||||
const std::unordered_set<uint32_t>& v2_matches,
|
||||
const std::unordered_set<uint32_t>& v3_matches)
|
||||
: key(key), v2_matches(v2_matches), v3_matches(v3_matches) { }
|
||||
: key(key),
|
||||
v2_matches(v2_matches),
|
||||
v3_matches(v3_matches) {}
|
||||
|
||||
void PSOV2OrV3DetectorEncryption::encrypt(void* data, size_t size, bool advance) {
|
||||
if (!this->active_crypt) {
|
||||
@@ -702,9 +723,9 @@ void PSOV2OrV3DetectorEncryption::encrypt(void* data, size_t size, bool advance)
|
||||
"ambiguous crypt version (v2=%08" PRIX32 ", v3=%08" PRIX32 ")",
|
||||
decrypted_v2.load(), decrypted_v3.load()));
|
||||
} else if (v2_match) {
|
||||
this->active_crypt = move(v2_crypt);
|
||||
this->active_crypt = std::move(v2_crypt);
|
||||
} else {
|
||||
this->active_crypt = move(v3_crypt);
|
||||
this->active_crypt = std::move(v3_crypt);
|
||||
}
|
||||
}
|
||||
this->active_crypt->encrypt(data, size, advance);
|
||||
@@ -717,11 +738,10 @@ PSOEncryption::Type PSOV2OrV3DetectorEncryption::type() const {
|
||||
return this->active_crypt->type();
|
||||
}
|
||||
|
||||
|
||||
|
||||
PSOV2OrV3ImitatorEncryption::PSOV2OrV3ImitatorEncryption(
|
||||
uint32_t key, std::shared_ptr<PSOV2OrV3DetectorEncryption> detector_crypt)
|
||||
: key(key), detector_crypt(detector_crypt) { }
|
||||
: key(key),
|
||||
detector_crypt(detector_crypt) {}
|
||||
|
||||
void PSOV2OrV3ImitatorEncryption::encrypt(void* data, size_t size, bool advance) {
|
||||
if (!this->active_crypt) {
|
||||
@@ -744,16 +764,14 @@ PSOEncryption::Type PSOV2OrV3ImitatorEncryption::type() const {
|
||||
return this->active_crypt->type();
|
||||
}
|
||||
|
||||
|
||||
|
||||
PSOBBMultiKeyDetectorEncryption::PSOBBMultiKeyDetectorEncryption(
|
||||
const vector<shared_ptr<const PSOBBEncryption::KeyFile>>& possible_keys,
|
||||
const unordered_set<string>& expected_first_data,
|
||||
const void* seed,
|
||||
size_t seed_size)
|
||||
: possible_keys(possible_keys),
|
||||
expected_first_data(expected_first_data),
|
||||
seed(reinterpret_cast<const char*>(seed), seed_size) { }
|
||||
: possible_keys(possible_keys),
|
||||
expected_first_data(expected_first_data),
|
||||
seed(reinterpret_cast<const char*>(seed), seed_size) {}
|
||||
|
||||
void PSOBBMultiKeyDetectorEncryption::encrypt(void* data, size_t size, bool advance) {
|
||||
if (!this->active_crypt.get()) {
|
||||
@@ -791,16 +809,14 @@ PSOEncryption::Type PSOBBMultiKeyDetectorEncryption::type() const {
|
||||
return Type::BB;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PSOBBMultiKeyImitatorEncryption::PSOBBMultiKeyImitatorEncryption(
|
||||
shared_ptr<const PSOBBMultiKeyDetectorEncryption> detector_crypt,
|
||||
const void* seed,
|
||||
size_t seed_size,
|
||||
bool jsd1_use_detector_seed)
|
||||
: detector_crypt(detector_crypt),
|
||||
seed(reinterpret_cast<const char*>(seed), seed_size),
|
||||
jsd1_use_detector_seed(jsd1_use_detector_seed) { }
|
||||
: detector_crypt(detector_crypt),
|
||||
seed(reinterpret_cast<const char*>(seed), seed_size),
|
||||
jsd1_use_detector_seed(jsd1_use_detector_seed) {}
|
||||
|
||||
void PSOBBMultiKeyImitatorEncryption::encrypt(void* data, size_t size, bool advance) {
|
||||
this->ensure_crypt()->encrypt(data, size, advance);
|
||||
@@ -835,8 +851,6 @@ shared_ptr<PSOBBEncryption> PSOBBMultiKeyImitatorEncryption::ensure_crypt() {
|
||||
return this->active_crypt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
JSD0Encryption::JSD0Encryption(const void* seed, size_t seed_size) : key(0) {
|
||||
const uint8_t* bytes = reinterpret_cast<const uint8_t*>(seed);
|
||||
for (size_t z = 0; z < seed_size; z++) {
|
||||
@@ -864,8 +878,6 @@ PSOEncryption::Type JSD0Encryption::type() const {
|
||||
return Type::JSD0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void decrypt_trivial_gci_data(void* data, size_t size, uint8_t basis) {
|
||||
uint8_t* bytes = reinterpret_cast<uint8_t*>(data);
|
||||
uint8_t key = basis + 0x80;
|
||||
@@ -874,3 +886,92 @@ void decrypt_trivial_gci_data(void* data, size_t size, uint8_t basis) {
|
||||
bytes[z] ^= key;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t count_one_bits(uint16_t v) {
|
||||
uint8_t ret = 0;
|
||||
while (v) {
|
||||
v &= (v - 1);
|
||||
ret++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint32_t encrypt_challenge_time(uint16_t value) {
|
||||
vector<uint8_t> available_bits({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15});
|
||||
|
||||
uint16_t mask = 0;
|
||||
uint8_t num_one_bits = (random_object<uint8_t>() % 9) + 4; // Range [4, 12]
|
||||
for (; num_one_bits; num_one_bits--) {
|
||||
uint8_t index = random_object<uint8_t>() % available_bits.size();
|
||||
auto it = available_bits.begin() + index;
|
||||
mask |= (1 << *it);
|
||||
available_bits.erase(it);
|
||||
}
|
||||
|
||||
return (mask << 16) | (value ^ mask);
|
||||
}
|
||||
|
||||
uint16_t decrypt_challenge_time(uint32_t value) {
|
||||
uint16_t mask = (value >> 0x10);
|
||||
uint8_t mask_one_bits = count_one_bits(mask);
|
||||
return ((mask_one_bits < 4) || (mask_one_bits > 12))
|
||||
? 0xFFFF
|
||||
: ((mask ^ value) & 0xFFFF);
|
||||
}
|
||||
|
||||
template <typename StringT, bool IsEncrypt>
|
||||
StringT crypt_challenge_rank_text(const void* src, size_t count) {
|
||||
if (count == 0) {
|
||||
return StringT();
|
||||
}
|
||||
|
||||
StringT ret;
|
||||
StringReader r(src, count * sizeof(typename StringT::value_type));
|
||||
typename StringT::value_type prev = 0;
|
||||
while (!r.eof()) {
|
||||
typename StringT::value_type ch = r.get<typename StringT::value_type>();
|
||||
if (ch == 0) {
|
||||
break;
|
||||
}
|
||||
if (ret.empty()) {
|
||||
ret.push_back(ch ^ 0x7F);
|
||||
} else {
|
||||
ret.push_back((IsEncrypt ? ((ch - prev) ^ 0x7F) : ((ch ^ 0x7F) + ret.back())) & 0xFF);
|
||||
}
|
||||
prev = ch;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
string encrypt_challenge_rank_text(const char* src, size_t count) {
|
||||
return crypt_challenge_rank_text<string, true>(src, count);
|
||||
}
|
||||
|
||||
string decrypt_challenge_rank_text(const char* src, size_t count) {
|
||||
return crypt_challenge_rank_text<string, false>(src, count);
|
||||
}
|
||||
|
||||
u16string encrypt_challenge_rank_text(const char16_t* src, size_t count) {
|
||||
return crypt_challenge_rank_text<u16string, true>(src, count);
|
||||
}
|
||||
|
||||
u16string decrypt_challenge_rank_text(const char16_t* src, size_t count) {
|
||||
return crypt_challenge_rank_text<u16string, false>(src, count);
|
||||
}
|
||||
|
||||
std::string decrypt_challenge_rank_text(const std::string& data) {
|
||||
return decrypt_challenge_rank_text(data.data(), data.size());
|
||||
}
|
||||
|
||||
std::string encrypt_challenge_rank_text(const std::string& data) {
|
||||
return encrypt_challenge_rank_text(data.data(), data.size());
|
||||
}
|
||||
|
||||
std::u16string decrypt_challenge_rank_text(const std::u16string& data) {
|
||||
return decrypt_challenge_rank_text(data.data(), data.size());
|
||||
}
|
||||
|
||||
std::u16string encrypt_challenge_rank_text(const std::u16string& data) {
|
||||
return encrypt_challenge_rank_text(data.data(), data.size());
|
||||
}
|
||||
|
||||
+50
-24
@@ -4,14 +4,12 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#include <memory>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <phosg/Encoding.hh>
|
||||
|
||||
#include "Text.hh" // for parray
|
||||
|
||||
|
||||
|
||||
class PSOEncryption {
|
||||
public:
|
||||
enum class Type {
|
||||
@@ -39,22 +37,24 @@ protected:
|
||||
PSOEncryption() = default;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class PSOLFGEncryption : public PSOEncryption {
|
||||
public:
|
||||
virtual void encrypt(void* data, size_t size, bool advance = true);
|
||||
void encrypt_big_endian(void* data, size_t size, bool advance = true);
|
||||
void encrypt_minus(void* data, size_t size, bool advance = true);
|
||||
void encrypt_big_endian_minus(void* data, size_t size, bool advance = true);
|
||||
void encrypt_both_endian(void* le_data, void* be_data, size_t size, bool advance = true);
|
||||
|
||||
template <bool IsBigEndian>
|
||||
void encrypt_t(void* data, size_t size, bool advance = true);
|
||||
template <bool IsBigEndian>
|
||||
void encrypt_minus_t(void* data, size_t size, bool advance = true);
|
||||
|
||||
uint32_t next(bool advance = true);
|
||||
|
||||
protected:
|
||||
explicit PSOLFGEncryption(uint32_t seed, size_t stream_length, size_t end_offset);
|
||||
|
||||
template <typename LongT>
|
||||
void encrypt_t(void* data, size_t size, bool advance);
|
||||
|
||||
virtual void update_stream() = 0;
|
||||
|
||||
std::vector<uint32_t> stream;
|
||||
@@ -87,8 +87,6 @@ protected:
|
||||
static constexpr size_t STREAM_LENGTH = 521;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class PSOBBEncryption : public PSOEncryption {
|
||||
public:
|
||||
enum Subtype : uint8_t {
|
||||
@@ -105,18 +103,23 @@ public:
|
||||
uint8_t jsd1_stream_offset;
|
||||
parray<uint8_t, 0x48> as8;
|
||||
parray<le_uint32_t, 0x12> as32;
|
||||
InitialKeys() : as32() { }
|
||||
InitialKeys(const InitialKeys& other) : as32(other.as32) { }
|
||||
InitialKeys() : as32() {}
|
||||
InitialKeys(const InitialKeys& other) : as32(other.as32) {}
|
||||
} __attribute__((packed));
|
||||
union PrivateKeys {
|
||||
parray<uint8_t, 0x1000> as8;
|
||||
parray<le_uint32_t, 0x400> as32;
|
||||
PrivateKeys() : as32() { }
|
||||
PrivateKeys(const PrivateKeys& other) : as32(other.as32) { }
|
||||
PrivateKeys() : as32() {}
|
||||
PrivateKeys(const PrivateKeys& other) : as32(other.as32) {}
|
||||
} __attribute__((packed));
|
||||
InitialKeys initial_keys;
|
||||
PrivateKeys private_keys;
|
||||
Subtype subtype;
|
||||
// This field only really needs to be one byte, but annoyingly, some
|
||||
// compilers pad this structure to a longer alignment, presumably because
|
||||
// the unions above contain structures with 32-bit alignment. To prevent
|
||||
// this structure's size from not matching the .nsk files' sizes, we use
|
||||
// an unnecessarily large size for this field.
|
||||
le_uint64_t subtype;
|
||||
} __attribute__((packed));
|
||||
|
||||
PSOBBEncryption(const KeyFile& key, const void* seed, size_t seed_size);
|
||||
@@ -133,9 +136,6 @@ protected:
|
||||
void apply_seed(const void* original_seed, size_t seed_size);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// The following classes provide support for automatically detecting which type
|
||||
// of encryption a client is using based on their initial response to the server
|
||||
|
||||
@@ -172,8 +172,6 @@ protected:
|
||||
std::shared_ptr<PSOEncryption> active_crypt;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// The following classes provide support for multiple PSOBB private keys, and
|
||||
// the ability to automatically detect which key the client is using based on
|
||||
// the first 8 bytes they send
|
||||
@@ -228,8 +226,6 @@ protected:
|
||||
bool jsd1_use_detector_seed;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class JSD0Encryption : public PSOEncryption {
|
||||
public:
|
||||
JSD0Encryption(const void* seed, size_t seed_size);
|
||||
@@ -243,6 +239,36 @@ private:
|
||||
uint8_t key;
|
||||
};
|
||||
|
||||
|
||||
|
||||
void decrypt_trivial_gci_data(void* data, size_t size, uint8_t basis);
|
||||
|
||||
uint32_t encrypt_challenge_time(uint16_t value);
|
||||
uint16_t decrypt_challenge_time(uint32_t value);
|
||||
|
||||
std::string decrypt_challenge_rank_text(const char* data, size_t count);
|
||||
std::string decrypt_challenge_rank_text(const std::string& data);
|
||||
std::string encrypt_challenge_rank_text(const char* data, size_t count);
|
||||
std::string encrypt_challenge_rank_text(const std::string& data);
|
||||
std::u16string decrypt_challenge_rank_text(const char16_t* data, size_t count);
|
||||
std::u16string decrypt_challenge_rank_text(const std::u16string& data);
|
||||
std::u16string encrypt_challenge_rank_text(const char16_t* data, size_t count);
|
||||
std::u16string encrypt_challenge_rank_text(const std::u16string& data);
|
||||
|
||||
template <size_t Size>
|
||||
std::string decrypt_challenge_rank_text(const ptext<char, Size>& data) {
|
||||
return decrypt_challenge_rank_text(data.data(), data.size());
|
||||
}
|
||||
|
||||
template <size_t Size>
|
||||
std::u16string decrypt_challenge_rank_text(const ptext<char16_t, Size>& data) {
|
||||
return decrypt_challenge_rank_text(data.data(), data.size());
|
||||
}
|
||||
|
||||
template <size_t Size>
|
||||
std::string encrypt_challenge_rank_text(const ptext<char, Size>& data) {
|
||||
return encrypt_challenge_rank_text(data.data(), data.size());
|
||||
}
|
||||
|
||||
template <size_t Size>
|
||||
std::u16string encrypt_challenge_rank_text(const ptext<char16_t, Size>& data) {
|
||||
return encrypt_challenge_rank_text(data.data(), data.size());
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
struct TObjectVTable {
|
||||
be_uint32_t unused_a1;
|
||||
be_uint32_t unused_a2;
|
||||
@@ -36,7 +34,8 @@ shared_ptr<PSOGCObjectGraph::VTable> PSOGCObjectGraph::parse_vtable_memo(
|
||||
StringReader& r, uint32_t addr) {
|
||||
try {
|
||||
return this->all_vtables.at(addr);
|
||||
} catch (const out_of_range&) { }
|
||||
} catch (const out_of_range&) {
|
||||
}
|
||||
|
||||
const auto& vt = r.pget<TObjectVTable>(addr & 0x01FFFFFF);
|
||||
auto ret = this->all_vtables.emplace(addr, new VTable()).first->second;
|
||||
@@ -52,7 +51,8 @@ shared_ptr<PSOGCObjectGraph::Object> PSOGCObjectGraph::parse_object_memo(
|
||||
StringReader& r, uint32_t addr) {
|
||||
try {
|
||||
return this->all_objects.at(addr);
|
||||
} catch (const out_of_range&) { }
|
||||
} catch (const out_of_range&) {
|
||||
}
|
||||
|
||||
const auto& obj = r.pget<TObject>(addr & 0x01FFFFFF);
|
||||
string type_name = r.pget_cstr(obj.type_name_addr & 0x01FFFFFF);
|
||||
@@ -60,7 +60,7 @@ shared_ptr<PSOGCObjectGraph::Object> PSOGCObjectGraph::parse_object_memo(
|
||||
auto ret = this->all_objects.emplace(addr, new Object()).first->second;
|
||||
ret->address = addr;
|
||||
ret->flags = obj.flags;
|
||||
ret->type_name = move(type_name);
|
||||
ret->type_name = std::move(type_name);
|
||||
ret->vtable = this->parse_vtable_memo(r, obj.vtable_addr);
|
||||
if (obj.parent_addr) {
|
||||
ret->parent = this->parse_object_memo(r, obj.parent_addr);
|
||||
@@ -79,8 +79,6 @@ void PSOGCObjectGraph::print(FILE* stream) const {
|
||||
this->root->print(stream);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PSOGCObjectGraph::Object::print(FILE* stream, size_t indent_level) const {
|
||||
for (size_t z = 0; z < indent_level; z++) {
|
||||
fputc(' ', stream);
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
|
||||
|
||||
struct PSOGCObjectGraph {
|
||||
PSOGCObjectGraph(const std::string& memory_data, uint32_t root_address);
|
||||
|
||||
|
||||
+2
-10
@@ -2,19 +2,15 @@
|
||||
|
||||
#include <event2/buffer.h>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "Text.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
extern bool use_terminal_colors;
|
||||
|
||||
|
||||
|
||||
PSOCommandHeader::PSOCommandHeader() {
|
||||
this->bb.size = 0;
|
||||
this->bb.command = 0;
|
||||
@@ -144,8 +140,6 @@ void PSOCommandHeader::set_flag(GameVersion version, uint32_t flag) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void check_size_v(size_t size, size_t min_size, size_t max_size) {
|
||||
if (size < min_size) {
|
||||
throw std::runtime_error(string_printf(
|
||||
@@ -162,8 +156,6 @@ void check_size_v(size_t size, size_t min_size, size_t max_size) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string prepend_command_header(
|
||||
GameVersion version,
|
||||
bool encryption_enabled,
|
||||
@@ -215,5 +207,5 @@ std::string prepend_command_header(
|
||||
throw logic_error("unimplemented game version in prepend_command_header");
|
||||
}
|
||||
ret.write(data);
|
||||
return move(ret.str());
|
||||
return std::move(ret.str());
|
||||
}
|
||||
|
||||
+54
-34
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <event2/bufferevent.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <functional>
|
||||
#include <phosg/Strings.hh>
|
||||
|
||||
#include "Version.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
struct PSOCommandHeaderPC {
|
||||
le_uint16_t size;
|
||||
@@ -49,12 +49,12 @@ union PSOCommandHeader {
|
||||
|
||||
// This function is used in a lot of places to check received command sizes and
|
||||
// cast them to the appropriate type
|
||||
template <typename T>
|
||||
const T& check_size_t(
|
||||
const void* data,
|
||||
template <typename RetT, typename PtrT>
|
||||
RetT& check_size_generic(
|
||||
PtrT data,
|
||||
size_t size,
|
||||
size_t min_size = sizeof(T),
|
||||
size_t max_size = sizeof(T)) {
|
||||
size_t min_size,
|
||||
size_t max_size) {
|
||||
if (size < min_size) {
|
||||
throw std::runtime_error(string_printf(
|
||||
"command too small (expected at least 0x%zX bytes, received 0x%zX bytes)",
|
||||
@@ -65,39 +65,59 @@ const T& check_size_t(
|
||||
"command too large (expected at most 0x%zX bytes, received 0x%zX bytes)",
|
||||
max_size, size));
|
||||
}
|
||||
return *reinterpret_cast<const T*>(data);
|
||||
return *reinterpret_cast<RetT*>(data);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T& check_size_t(const std::string& data, size_t min_size, size_t max_size) {
|
||||
return check_size_generic<const T, const void*>(data.data(), data.size(), min_size, max_size);
|
||||
}
|
||||
template <typename T>
|
||||
const T& check_size_t(
|
||||
const std::string& data,
|
||||
size_t min_size = sizeof(T),
|
||||
size_t max_size = sizeof(T)) {
|
||||
return check_size_t<T>(data.data(), data.size(), min_size, max_size);
|
||||
const T& check_size_t(const std::string& data, size_t max_size) {
|
||||
return check_size_generic<const T, const void*>(data.data(), data.size(), sizeof(T), max_size);
|
||||
}
|
||||
template <typename T>
|
||||
T& check_size_t(
|
||||
void* data,
|
||||
size_t size,
|
||||
size_t min_size = sizeof(T),
|
||||
size_t max_size = sizeof(T)) {
|
||||
if (size < min_size) {
|
||||
throw std::runtime_error(string_printf(
|
||||
"command too small (expected at least 0x%zX bytes, received 0x%zX bytes)",
|
||||
min_size, size));
|
||||
}
|
||||
if (size > max_size) {
|
||||
throw std::runtime_error(string_printf(
|
||||
"command too large (expected at most 0x%zX bytes, received 0x%zX bytes)",
|
||||
max_size, size));
|
||||
}
|
||||
return *reinterpret_cast<T*>(data);
|
||||
const T& check_size_t(const std::string& data) {
|
||||
return check_size_generic<const T, const void*>(data.data(), data.size(), sizeof(T), sizeof(T));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T& check_size_t(std::string& data, size_t min_size, size_t max_size) {
|
||||
return check_size_generic<T, void*>(data.data(), data.size(), min_size, max_size);
|
||||
}
|
||||
template <typename T>
|
||||
T& check_size_t(
|
||||
std::string& data,
|
||||
size_t min_size = sizeof(T),
|
||||
size_t max_size = sizeof(T)) {
|
||||
return check_size_t<T>(data.data(), data.size(), min_size, max_size);
|
||||
T& check_size_t(std::string& data, size_t max_size) {
|
||||
return check_size_generic<T, void*>(data.data(), data.size(), sizeof(T), max_size);
|
||||
}
|
||||
template <typename T>
|
||||
T& check_size_t(std::string& data) {
|
||||
return check_size_generic<T, void*>(data.data(), data.size(), sizeof(T), sizeof(T));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T& check_size_t(const void* data, size_t size, size_t min_size, size_t max_size) {
|
||||
return check_size_generic<const T, const void*>(data, size, min_size, max_size);
|
||||
}
|
||||
template <typename T>
|
||||
const T& check_size_t(const void* data, size_t size, size_t max_size) {
|
||||
return check_size_generic<const T, const void*>(data, size, sizeof(T), max_size);
|
||||
}
|
||||
template <typename T>
|
||||
const T& check_size_t(const void* data, size_t size) {
|
||||
return check_size_generic<const T, const void*>(data, size, sizeof(T), sizeof(T));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T& check_size_t(void* data, size_t size, size_t min_size, size_t max_size) {
|
||||
return check_size_generic<T, void*>(data, size, min_size, max_size);
|
||||
}
|
||||
template <typename T>
|
||||
T& check_size_t(void* data, size_t size, size_t max_size) {
|
||||
return check_size_generic<T, void*>(data, size, sizeof(T), max_size);
|
||||
}
|
||||
template <typename T>
|
||||
T& check_size_t(void* data, size_t size) {
|
||||
return check_size_generic<T, void*>(data, size, sizeof(T), sizeof(T));
|
||||
}
|
||||
|
||||
void check_size_v(size_t size, size_t min_size, size_t max_size = 0);
|
||||
|
||||
+27
-33
@@ -4,19 +4,19 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <functional>
|
||||
#include <stdexcept>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Hash.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "Loggers.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
PatchFileIndex::File::File(PatchFileIndex* index)
|
||||
: index(index), crc32(0), size(0) { }
|
||||
: index(index),
|
||||
crc32(0),
|
||||
size(0) {}
|
||||
|
||||
std::shared_ptr<const std::string> PatchFileIndex::File::load_data() {
|
||||
if (!this->loaded_data) {
|
||||
@@ -29,26 +29,24 @@ std::shared_ptr<const std::string> PatchFileIndex::File::load_data() {
|
||||
return this->loaded_data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PatchFileIndex::PatchFileIndex(const string& root_dir)
|
||||
: root_dir(root_dir) {
|
||||
: root_dir(root_dir) {
|
||||
|
||||
string metadata_cache_filename = root_dir + "/.metadata-cache.json";
|
||||
shared_ptr<JSONObject> metadata_cache_json;
|
||||
JSON metadata_cache_json;
|
||||
try {
|
||||
string metadata_text = load_file(metadata_cache_filename);
|
||||
metadata_cache_json = JSONObject::parse(metadata_text);
|
||||
metadata_cache_json = JSON::parse(metadata_text);
|
||||
patch_index_log.info("Loaded patch metadata cache from %s", metadata_cache_filename.c_str());
|
||||
} catch (const exception& e) {
|
||||
metadata_cache_json = make_json_dict({});
|
||||
metadata_cache_json = JSON::dict();
|
||||
patch_index_log.warning("Cannot load patch metadata cache from %s: %s", metadata_cache_filename.c_str(), e.what());
|
||||
}
|
||||
|
||||
// Assuming it's rare for patch files to change, we skip writing the metadata
|
||||
// cache if no files were changed at all (which should usually be the case)
|
||||
bool should_write_metadata_cache = false;
|
||||
shared_ptr<JSONObject> new_metadata_cache_json = make_json_dict({});
|
||||
JSON new_metadata_cache_json = JSON::dict();
|
||||
|
||||
vector<string> path_directories;
|
||||
function<void(const string&)> collect_dir = [&](const string& dir) -> void {
|
||||
@@ -77,12 +75,11 @@ PatchFileIndex::PatchFileIndex(const string& root_dir)
|
||||
f->name = item;
|
||||
|
||||
string compute_crc32s_message; // If not empty, should compute crc32s
|
||||
shared_ptr<JSONObject> cache_item_json;
|
||||
JSON cache_item_json;
|
||||
try {
|
||||
cache_item_json = metadata_cache_json->at(relative_item_path);
|
||||
auto cache_item = metadata_cache_json->at(relative_item_path)->as_list();
|
||||
uint64_t cached_size = cache_item.at(0)->as_int();
|
||||
uint64_t cached_mtime = cache_item.at(1)->as_int();
|
||||
cache_item_json = metadata_cache_json.at(relative_item_path);
|
||||
uint64_t cached_size = cache_item_json.get_int(0);
|
||||
uint64_t cached_mtime = cache_item_json.get_int(1);
|
||||
if (static_cast<uint64_t>(st.st_mtime) != cached_mtime) {
|
||||
throw runtime_error("file has been modified");
|
||||
}
|
||||
@@ -90,8 +87,8 @@ PatchFileIndex::PatchFileIndex(const string& root_dir)
|
||||
throw runtime_error("file size has changed");
|
||||
}
|
||||
f->size = cached_size;
|
||||
f->crc32 = cache_item.at(2)->as_int();
|
||||
for (const auto& chunk_crc32_json : cache_item.at(3)->as_list()) {
|
||||
f->crc32 = cache_item_json.get_int(2);
|
||||
for (const auto& chunk_crc32_json : cache_item_json.get_list(3)) {
|
||||
f->chunk_crcs.emplace_back(chunk_crc32_json->as_int());
|
||||
}
|
||||
|
||||
@@ -108,33 +105,30 @@ PatchFileIndex::PatchFileIndex(const string& root_dir)
|
||||
}
|
||||
|
||||
// File was modified or cache item was missing; make a new cache item
|
||||
vector<shared_ptr<JSONObject>> chunk_crcs_item;
|
||||
auto chunk_crcs_item = JSON::list();
|
||||
for (uint32_t chunk_crc : f->chunk_crcs) {
|
||||
chunk_crcs_item.emplace_back(make_json_int(chunk_crc));
|
||||
chunk_crcs_item.emplace_back(chunk_crc);
|
||||
}
|
||||
vector<shared_ptr<JSONObject>> new_cache_item({
|
||||
make_json_int(f->size),
|
||||
make_json_int(st.st_mtime),
|
||||
make_json_int(f->crc32),
|
||||
make_json_list(move(chunk_crcs_item)),
|
||||
});
|
||||
new_metadata_cache_json->as_dict().emplace(
|
||||
relative_item_path, make_json_list(move(new_cache_item)));
|
||||
new_metadata_cache_json.emplace(
|
||||
relative_item_path, JSON::list({f->size, st.st_mtime, f->crc32, std::move(chunk_crcs_item)}));
|
||||
should_write_metadata_cache = true;
|
||||
|
||||
} else {
|
||||
// File was not modified and cache item was valid; just use the
|
||||
// existing cache item
|
||||
new_metadata_cache_json->as_dict().emplace(
|
||||
relative_item_path, cache_item_json);
|
||||
new_metadata_cache_json.emplace(
|
||||
relative_item_path, std::move(cache_item_json));
|
||||
}
|
||||
|
||||
this->files_by_patch_order.emplace_back(f);
|
||||
this->files_by_name.emplace(relative_item_path, f);
|
||||
if (compute_crc32s_message.empty()) {
|
||||
patch_index_log.info("Added file %s (%" PRIu32 " bytes; %zu chunks; %08" PRIX32 " from cache)",
|
||||
patch_index_log.info(
|
||||
"Added file %s (%" PRIu32 " bytes; %zu chunks; %08" PRIX32 " from cache)",
|
||||
full_item_path.c_str(), f->size, f->chunk_crcs.size(), f->crc32);
|
||||
} else {
|
||||
patch_index_log.info("Added file %s (%" PRIu32 " bytes; %zu chunks; %08" PRIX32 " [%s])",
|
||||
patch_index_log.info(
|
||||
"Added file %s (%" PRIu32 " bytes; %zu chunks; %08" PRIX32 " [%s])",
|
||||
full_item_path.c_str(), f->size, f->chunk_crcs.size(), f->crc32, compute_crc32s_message.c_str());
|
||||
}
|
||||
}
|
||||
@@ -147,7 +141,7 @@ PatchFileIndex::PatchFileIndex(const string& root_dir)
|
||||
|
||||
if (should_write_metadata_cache) {
|
||||
try {
|
||||
save_file(metadata_cache_filename, new_metadata_cache_json->serialize());
|
||||
save_file(metadata_cache_filename, new_metadata_cache_json.serialize());
|
||||
patch_index_log.info("Saved patch metadata cache to %s", metadata_cache_filename.c_str());
|
||||
} catch (const exception& e) {
|
||||
patch_index_log.warning("Cannot save patch metadata cache to %s: %s", metadata_cache_filename.c_str(), e.what());
|
||||
|
||||
@@ -2,13 +2,11 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
|
||||
|
||||
struct PatchFileIndex {
|
||||
explicit PatchFileIndex(const std::string& root_dir);
|
||||
@@ -42,10 +40,13 @@ struct PatchFileChecksumRequest {
|
||||
bool response_received;
|
||||
|
||||
explicit PatchFileChecksumRequest(std::shared_ptr<PatchFileIndex::File> file)
|
||||
: file(file), crc32(0), size(0), response_received(false) { }
|
||||
: file(file),
|
||||
crc32(0),
|
||||
size(0),
|
||||
response_received(false) {}
|
||||
inline bool needs_update() const {
|
||||
return !this->response_received ||
|
||||
(this->crc32 != this->file->crc32) ||
|
||||
(this->size != this->file->size);
|
||||
(this->crc32 != this->file->crc32) ||
|
||||
(this->size != this->file->size);
|
||||
}
|
||||
};
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user