Compare commits
141 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5b72e59ebe | |||
| d2c16b5363 | |||
| 977ed05526 | |||
| e2c34dfb70 | |||
| 4416579210 | |||
| 5f591ac189 | |||
| aa9d2beffe | |||
| 24656d587b | |||
| fbaf7d722d | |||
| bda5c40cc2 | |||
| eeac5ccf4d | |||
| bbff30071e | |||
| a7a512682c | |||
| f3f933aaca | |||
| 5433663866 | |||
| 598120c661 | |||
| d4f885fad1 | |||
| 8ab1eabda7 | |||
| d23775f069 | |||
| de45f49b78 | |||
| 2608d5d601 | |||
| 92df4ff1e2 | |||
| 27ecab2993 | |||
| 3dc106b42e | |||
| 768e8bbfe2 | |||
| 324f681c46 | |||
| d178d062a8 | |||
| 3ac421cf55 | |||
| 0e9bd019af | |||
| 5ce4eb8cfc | |||
| 64082fa872 | |||
| 063f67d3f6 | |||
| 5df98fb691 | |||
| a686d81d4c | |||
| bc9fc25799 | |||
| 07d8e1df7b | |||
| 7427fbd252 | |||
| 679f58937f | |||
| af5770058b | |||
| d2cb7a4cb8 | |||
| 62c778d877 | |||
| 9dd6339fe8 | |||
| 7b6b8151a7 | |||
| e77ee397cd | |||
| 8775367043 | |||
| ba752eb7dc | |||
| 8421ab16d5 | |||
| 340a36878b | |||
| 836704e987 | |||
| d0ff9bd048 | |||
| 001c2c905f | |||
| 443a0a3037 | |||
| d294dbcc55 | |||
| 0c63d6a07f | |||
| 3f6157c03f | |||
| c8eab046c0 | |||
| d8230eb37a | |||
| f71980382a | |||
| 0a8678fda7 | |||
| adb5d51510 | |||
| 45679a7f98 | |||
| f6f5ca47e9 | |||
| a4ade28755 | |||
| c957ea6c10 | |||
| 6bfb84d999 | |||
| 49fbacf0fa | |||
| 79efce5252 | |||
| cb9a0ed1c4 | |||
| fc5788364b | |||
| df2b64a601 | |||
| 2ff75fe132 | |||
| 625e8e0624 | |||
| de8ed72233 | |||
| ce2607253c | |||
| b6fb9051b6 | |||
| f069622b94 | |||
| 0b7e532b32 | |||
| f4e6a40097 | |||
| 2ed97974e0 | |||
| 251a9ecd0a | |||
| 777ffc1108 | |||
| 3951a46386 | |||
| bfbf1ba87e | |||
| dc7c3eb58c | |||
| a0126bd6b5 | |||
| c86ecbe9ef | |||
| 99a606be18 | |||
| 7ebae9ed9d | |||
| e803ca54c6 | |||
| d619bff349 | |||
| c7cb81e0fc | |||
| f7c847bcf0 | |||
| b81d119906 | |||
| 5535d749b9 | |||
| 992d204a83 | |||
| b478c035bb | |||
| 0f81d98c6e | |||
| edc659a241 | |||
| ef08805f93 | |||
| 70413668d8 | |||
| 27bbb2c7e4 | |||
| 43ad1597a4 | |||
| ce0badde87 | |||
| 9d46d1042b | |||
| 2e7c792b97 | |||
| c411cec06c | |||
| 451c8d5e09 | |||
| a35753fdf1 | |||
| ca6605877a | |||
| 59db3c82f9 | |||
| e42cfb649f | |||
| cf88455975 | |||
| b272f2326e | |||
| a29494b120 | |||
| 4d172fff64 | |||
| 57ea246dd7 | |||
| 636309952e | |||
| dfeeed2b1a | |||
| f83822bba0 | |||
| 60f67fa791 | |||
| 9b6a6e4412 | |||
| 83b8c199b9 | |||
| 3f1939e674 | |||
| 31616954cc | |||
| ee21885f13 | |||
| 2cc6a85d4b | |||
| 29320f0858 | |||
| 29f200b83e | |||
| 09bf81f77f | |||
| ddbb922b95 | |||
| c7dd98ccc0 | |||
| f5c2c930d8 | |||
| 79fee4cec4 | |||
| 0bec4d0f49 | |||
| a4fc133d75 | |||
| 45c9dc9a23 | |||
| 594ffbe7e6 | |||
| 7decab75c2 | |||
| 9815126ced | |||
| 4b5eba3727 | |||
| 49010b02f1 |
+4
-4
@@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(newserv)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
if (MSVC)
|
||||
add_compile_options(/W4 /WX)
|
||||
@@ -90,6 +90,7 @@ set(SOURCES
|
||||
src/GSLArchive.cc
|
||||
src/GVMEncoder.cc
|
||||
src/HTTPServer.cc
|
||||
src/IntegralExpression.cc
|
||||
src/IPFrameInfo.cc
|
||||
src/IPStackSimulator.cc
|
||||
src/IPV4RangeSet.cc
|
||||
@@ -105,8 +106,8 @@ set(SOURCES
|
||||
src/Map.cc
|
||||
src/Menu.cc
|
||||
src/NetworkAddresses.cc
|
||||
src/PatchServer.cc
|
||||
src/PatchFileIndex.cc
|
||||
src/PatchServer.cc
|
||||
src/PlayerFilesManager.cc
|
||||
src/PlayerSubordinates.cc
|
||||
src/ProxyCommands.cc
|
||||
@@ -115,7 +116,6 @@ set(SOURCES
|
||||
src/PSOGCObjectGraph.cc
|
||||
src/PSOProtocol.cc
|
||||
src/Quest.cc
|
||||
src/IntegralExpression.cc
|
||||
src/QuestScript.cc
|
||||
src/RareItemSet.cc
|
||||
src/ReceiveCommands.cc
|
||||
@@ -136,7 +136,7 @@ set(SOURCES
|
||||
)
|
||||
|
||||
if(resource_file_FOUND)
|
||||
set(SOURCES ${SOURCES} src/ARCodeTranslator.cc)
|
||||
set(SOURCES ${SOURCES} src/AddressTranslator.cc)
|
||||
endif()
|
||||
|
||||
add_executable(newserv ${SOURCES})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2023 Martin Michelsen
|
||||
Copyright (c) 2024 Martin Michelsen
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
@@ -18,4 +18,3 @@ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ See TODO.md for a list of known issues and future work I've curated, or go to th
|
||||
* Background
|
||||
* [History](#history)
|
||||
* [Other server projects](#other-server-projects)
|
||||
* [Using newserv in other projects](#using-newserv-in-other-projects)
|
||||
* [Compatibility](#compatibility)
|
||||
* Setup
|
||||
* [Server setup](#server-setup)
|
||||
@@ -62,7 +63,14 @@ Independently of this project, there are many other PSO servers out there. Those
|
||||
* (2019) **[Mechonis](https://gitlab.com/sora3087/mechonis)**: A PSOBB server with a microservice architecture written in TypeScript by TrueVision.
|
||||
* (2021) **[Phantasmal World](https://github.com/DaanVandenBosch/phantasmal-world)**: A set of PSO tools, including a web-based model viewer and quest builder, and a PSO server, written by Daan Vanden Bosch.
|
||||
* (2021) **[Elseware](http://git.sharnoth.com/jake/elseware)**: A PSOBB server written in Rust by Jake.
|
||||
* (2022) **[PSOSERVER](https://github.com/Sancaros/PSOSERVER)**: A server for all versions, written in C by Sancaros and based on Sylverant and newserv.
|
||||
|
||||
## Using newserv in other projects
|
||||
|
||||
There is a fair amount of code in this project that could potentially be useful to other projects. You are free to use code from newserv in your own open-source projects; the only condition is that the contents of the LICENSE file must be included in your project if you use code from newserv. Your project does not also have to use the MIT license; you can use any license you want.
|
||||
|
||||
If you want to use parts of newserv in your project, there are two easy ways to do so with proper licensing:
|
||||
* If you're using a lot of code from newserv, you can put a copy of newserv's LICENSE file in your repository alongside your own license file, or include the contents of newserv's license in your own license file.
|
||||
* If you're only using a few files from newserv, you can copy and paste the contents of the LICENSE file into a comment at the beginning of each copied file.
|
||||
|
||||
# Compatibility
|
||||
|
||||
@@ -183,9 +191,13 @@ The version of PSO PC I have has the server addresses starting at offset 0x29CB3
|
||||
|
||||
### PSO GC on a real GameCube
|
||||
|
||||
You can make PSO connect to newserv by setting its default gateway and DNS server addresses in network settings to newserv's address. newserv's DNS server must be running on port 53 and must be accessible to the GameCube.
|
||||
You can make PSO connect to newserv by setting the default gateway and DNS server addresses in the game's network settings to newserv's address. newserv's DNS server must be running on port 53 and must be accessible to the GameCube. If you're not playing PSO Plus or Episode III, this should be all you need to do, assuming you already set LocalAddress in config.json to your PC's private IP address.
|
||||
|
||||
If you have PSO Plus or Episode III, it won't want to connect to a server on the same local network as the GameCube itself, as determined by the GameCube's IP address and subnet mask. In the old days, one way to get around this was to create a fake network adapter on the server (or use an existing real one) that has an IP address on a different subnet, tell the GameCube that the server is the default gateway (as above), and have the server reply to the DNS request with its non-local IP address. To do this with newserv, just set LocalAddress in the config file to a different interface. For example, if the GameCube is on the 192.168.0.x network and your other adapter has address 10.0.1.6, set newserv's LocalAddress to 10.0.1.6 and set PSO's DNS server and default gateway addresses to the server's 192.168.0.x address. This may not work on modern systems or on non-Windows machines - I haven't tested it in many years.
|
||||
If you have PSO Plus or Episode III, it won't want to connect to a server on the same local network as the GameCube itself, as determined by the GameCube's IP address and subnet mask. There are a couple of ways to get around this.
|
||||
|
||||
Sodaboy described a fairly easy method, which is to forward the PSO and DNS ports in your router's configuration to your PC's private IP address (the PSO ports are in config.json, and are all TCP; the DNS port is 53 and is UDP). Then, set LocalAddress and ExternalAddress in config.json to your external IP address (from e.g. whatismyip.com). Most routers will let you connect to your public IP address even from within the local network, but the GameCube will think it's connecting to a different network, so it won't reject the connection. If you're concerned about security and don't want your server to be publicly accessible, you can use Windows Firewall or UFW on Linux block incoming connections on the ports you opened, except for connections from the IP addresses you specify.
|
||||
|
||||
Another method is to use two network interfaces on the same PC, and tell the GameCube to connect to the one that appears to be on a different network. For example, if your GameCube is on the 10.0.0.x subnet and your PC's address is 10.0.0.5, you can create a fake network adapter on your PC (or use an existing real one) that has an IP address on a different subnet than the GameCube, such as 192.168.0.8. Then, in PSO's network config, set the default gateway and DNS server addresses to 192.168.0.8, and set LocalAddress in config.json to 192.168.0.8, and PSO should connect. This is what I did back in the old days when I primarily developed software on Windows, but I haven't tried it in many years.
|
||||
|
||||
### PSO GC on a Wii or Wii U
|
||||
|
||||
@@ -193,7 +205,7 @@ Using a Wii or Wii U to connect to newserv requires the Wii or vWii to be softmo
|
||||
|
||||
Nintendont includes BBA emulation and is compatible with all PSO GameCube versions except Episodes I&II Trial Edition. To use Nintendont, enable BBA emulation in Nintendont's settings and follow the instructions in the above section (PSO GC on a real GameCube).
|
||||
|
||||
Devolution includes modem emulation and is compatible with all PSO GameCube versions including Episodes I&II Trial Edition. newserv can act as a PPP server, which Devolution can directly cnnect to. To do this:
|
||||
Devolution includes modem emulation and is compatible with all PSO GameCube versions including Episodes I&II Trial Edition. newserv can act as a PPP server, which Devolution can directly connect to. To do this:
|
||||
1. Enable the PPPRawListen option according to the comments in config.json.
|
||||
2. Start newserv.
|
||||
3. In the game's network settings, set the username and password to anything (they cannot be blank), and set the phone number to the number that newserv outputs to the console during startup. (It will be near the end of all the startup log messages.) If your Wii is on the same network as newserv, use the local number; otherwise, use the external number.
|
||||
@@ -204,9 +216,9 @@ If you're using the HLE BBA type, set the BBA's DNS server address to newserv's
|
||||
|
||||
If you're using the TAP BBA type, you'll have to set PSO's network settings appropriately for your tap interface. Set the DNS server address in PSO's network settings to newserv's IP address.
|
||||
|
||||
If you're using a version of Dolphin with tapserver support, you can make it connect to a newserv instance running on the same machine via the tapserver interface. You do not need to install or run tapserver. To do this:
|
||||
1. Set Dolphin's BBA type to tapserver (Config -> GameCube -> SP1).
|
||||
2. Enable newserv's IP stack simulator according to the comments in config.json and start newserv.
|
||||
If you're using the tapserver BBA or modem type, you can make it connect to a newserv instance running on the same machine via the tapserver interface. To do this:
|
||||
1. In the GameCube pane of the Config window, set the SP1 device to Broadband Adapter (tapserver) or Modem Adapter (tapserver).
|
||||
2. Set IPStackListen (for BBA) or PPPStackListen (for modem) according to the comments in config.json and start newserv.
|
||||
3. In PSO's network settings, enable DHCP ("Automatically obtain an IP address"), set DNS server address to "Automatic", and leave DHCP Hostname as "Not set". Leave the proxy server settings blank.
|
||||
4. Start an online game.
|
||||
|
||||
@@ -214,9 +226,12 @@ If you're using a version of Dolphin with tapserver support, you can make it con
|
||||
|
||||
The PSO BB client has been modified and distributed in many different forms. newserv supports most, but not all, of the common distributions. Unlike other versions, it's important that the client and server have the same map files, so make sure to set up the patch directory based on the client you'll be using with newserv. (See the "Client patch directories" section for instructions on setting this up.)
|
||||
|
||||
The original Japanese and US versions of PSO BB should work (the last Japanese release can be found [here](https://archive.org/details/psobb_jp_setup_12511_20240109/)), but you'll have to modify your hosts file or edit psobb.exe to point to your newserv instance. The original versions are packed with various versions of ASProtect, so this is a more involved process than simply opening the executable in a hex editor and finding/replacing some strings.
|
||||
The original Japanese and US versions of PSO BB work with newserv (the last Japanese release can be found [here](https://archive.org/details/psobb_jp_setup_12511_20240109/)). To get them to connect to your server, do one of the following:
|
||||
* Use a drop-in patcher like [AzureFlare](https://github.com/Repflez/AzureFlare).
|
||||
* Modify your hosts file to redirect the client's destination address to localhost or your server's address.
|
||||
* Edit psobb.exe to point to your newserv instance. The original clients are packed with various versions of ASProtect, so this is a more involved process than simply opening the executable in a hex editor and finding/replacing some strings.
|
||||
|
||||
Alternatively, you can use the Tethealla client ([English](https://web.archive.org/web/20240402011115/https://ragol.org/files/bb/TethVer12513_English.zip) / [Japanese](https://web.archive.org/web/20240402013127/https://ragol.org/files/bb/TethVer12513_Japanese.zip)); you can find the connection addresses starting at 0x56D724 in psobb.exe. Overwrite these addresses with your server's hostname or IP address, and you should be able to connect. If the server is on the same PC as the client and you don't plan to have any external players, these Tethealla clients will automatically connect to the server without any modifications.
|
||||
Alternatively, you can use the Tethealla client ([English](https://web.archive.org/web/20240402011115/https://ragol.org/files/bb/TethVer12513_English.zip) or [Japanese](https://web.archive.org/web/20240402013127/https://ragol.org/files/bb/TethVer12513_Japanese.zip)). If the server is on the same PC as the client and you don't plan to have any external players, these Tethealla clients will automatically connect to the server without any modifications. This version of the client is not packed, and you can find the connection addresses starting at 0x56D724 in psobb.exe. Overwrite these addresses with your server's hostname or IP address, and you should be able to connect.
|
||||
|
||||
### Connecting external clients
|
||||
|
||||
@@ -324,6 +339,28 @@ All versions of PSO can see and interact with each other in the lobby. newserv a
|
||||
|
||||
In V1/V2 cross-version play, when any of the server drop modes are used, the server uses the drop table corresponding to the version the game was created with. (For example, if a DC V1 player created the game, rare-table-v1.json will be used, even after V2 players join.)
|
||||
|
||||
## Server-side saves
|
||||
|
||||
newserv has the ability to save character data on the server side. For PSO BB, this is required of course, but this feature can also be used on other PSO versions.
|
||||
|
||||
Each account has 4 BB character slots and 16 non-BB character file slots. The non-BB slots are independent of the BB slots, and can be accessed with the `$savechar <slot>` and `$loadchar <slot>` commands (slots are numbered 1 through 16). `$savechar` copies the character you're currently playing as and saves the data on the server, and `$loadchar` does the reverse, overwriting your current character with the data saved on the server. Note that you can load a character that was saved from a different version of PSO, which allows you to easily transfer characters between games. On v1 and v2, changes done by `$loadchar` will be undone if you join a game; to permanently save your changes, disconnect from the lobby after using the command.
|
||||
|
||||
There is a third command, `$bbchar <username> <password> <slot>`, which behaves similarly to `$savechar` but writes the character data to a BB character slot in a different account instead (slots are numbered 1 through 4). This can be used to "upgrade" a character to BB from an earlier version.
|
||||
|
||||
Exactly which data is saved and loaded depends on the game version:
|
||||
|
||||
| Game | Inventory | Character | Options/chats | Quest flags | Bank | Battle/challenge |
|
||||
|----------------------|-----------|-----------|---------------|-------------|------|------------------|
|
||||
| PSO DC v1 prototypes | Yes | Yes | No | No | No | N/A |
|
||||
| PSO DC v1 | Yes | Yes | No | No | No | N/A |
|
||||
| PSO DC v2 | Yes | Yes | Yes | Yes | Yes | Yes |
|
||||
| PSO PC (v2) | Yes | Yes | No | No | No | Save only |
|
||||
| PSO GC NTE | Yes | Yes | Yes | Yes | Yes | Yes |
|
||||
| PSO GC (not Plus) | Yes | Yes | Yes | Yes | Yes | Yes |
|
||||
| PSO GC Plus | Save only | Save only | No | No | No | Save only |
|
||||
| PSO Xbox | Yes | Yes | Yes | Yes | Yes | Yes |
|
||||
| PSO BB | Yes | Yes | Yes | Yes | Yes | Yes |
|
||||
|
||||
## Episode 3 features
|
||||
|
||||
newserv supports many features unique to Episode 3:
|
||||
@@ -355,13 +392,14 @@ Episode 3 state and game data is stored in the system/ep3 directory. The files i
|
||||
* card-text.mnr: Compressed card text archive. Generally only used for debugging.
|
||||
* card-text.mnrd: Decompressed card text archive; same format as TextCardE.bin. Generally only used for debugging.
|
||||
* com-decks.json: COM decks used in tournaments. The default decks in this file come from logs from Sega's servers, so the file doesn't include every COM deck Sega ever made - the rest are probably lost to time.
|
||||
* maps/: Online free battle and quest maps (.mnm/.bin/.mnmd/.bind files). newserv comes with all the original online and offline maps, including Story Mode quests. If you don't want the offline maps and quests to be playable online, delete the .bind files system/ep3/maps.
|
||||
* maps/: Online free battle and quest maps (.mnm/.bin/.mnmd/.bind files). newserv comes with the default online maps, as well as some fan-made variations and quests to help new players get up to speed.
|
||||
* maps-download/: Download maps and quests (.mnm/.bin/.mnmd/.bind files). There are two subcategories by default (download maps and Trial Edition download maps), but you can add more by editing QuestCategories in config.json. Categories that have flag 0x40 (Ep3 download) set are indexed from this directory; all others are indexed from system/quests/. Files in maps-download/ subdirectories have the same format as those in the maps/ directory, but should be named like `e###-gc3-LANGUAGE.EXT` (similar to how non-Episode 3 quests are named in the system/quests/ directory). If you want a map to be available for online play and for downloading, the file must exist in both maps/ and in a maps-download/ subdirectory (a symbolic link is acceptable).
|
||||
* maps-offline/: Offline map files. These are all the offline quests and free battle maps from the client, including some debugging/test maps that were inaccessible during normal play. To make them playable online, put the files in the maps/ directory.
|
||||
* tournament-state.json: State of all active tournaments. This file is automatically written when any tournament changes state for any reason (e.g. a tournament is created/started/deleted or a match is resolved).
|
||||
|
||||
There is no public editor for Episode 3 maps and quests, but the format is described fairly thoroughly in src/Episode3/DataIndexes.hh (see the MapDefinition structure). You'll need to use `newserv decompress-prs ...` to decompress .bin or .mnm files before editing them, but you don't need to compress the files again to use them - just put the .bind or .mnmd file in the maps directory and newserv will make it available.
|
||||
There is no public editor for Episode 3 maps and quests, but the format is described fairly thoroughly in src/Episode3/DataIndexes.hh (see the MapDefinition structure). You'll need to use `newserv decompress-prs ...` to decompress a .bin or .mnm file before editing it, but you don't need to compress it again to use it - just put the .bind or .mnmd file in the maps directory and newserv will make it available.
|
||||
|
||||
Like quests, Episode 3 card definitions, maps, and quests are cached in memory. If you've changed any of these files, you can run `reload ep3-data` in the interactive shell to make the changes take effect without restarting the server.
|
||||
Like quests, Episode 3 card definitions, maps, and quests are cached in memory. If you've changed any of these files, you can run `reload ep3-cards` or `reload ep3-maps` in the interactive shell to make the changes take effect without restarting the server.
|
||||
|
||||
## Memory patches, client functions, and DOL files
|
||||
|
||||
@@ -371,48 +409,48 @@ You can put assembly files in the system/client-functions directory with filenam
|
||||
|
||||
The VERS token in client function filenames refers to the specific version of the game that the client function applies to. Some versions do not support receiving client functions at all. The specific versions are:
|
||||
|
||||
| Game | VERS | Supported |
|
||||
|-------------------|------|-----------|
|
||||
| PSO DC NTE | 1OJ1 | No |
|
||||
| PSO DC 11/2000 | 1OJ2 | No |
|
||||
| PSO DC 12/2000 | 1OJ3 | No |
|
||||
| PSO DC 01/2001 | 1OJ4 | No |
|
||||
| PSO DC v1 JP | 1OJF | No |
|
||||
| PSO DC v1 US | 1OEF | No |
|
||||
| PSO DC v1 EU | 1OPF | No |
|
||||
| PSO DC 08/2001 | 2OJ5 | Yes |
|
||||
| PSO DC v2 JP | 2OJF | Yes |
|
||||
| PSO DC v2 US | 2OEF | Yes |
|
||||
| PSO DC v2 EU | 2OPF | Yes |
|
||||
| PSO PC (v2) | 2OJW | No |
|
||||
| PSO GC NTE | 3OJT | Yes |
|
||||
| PSO GC v1.2 JP | 3OJ2 | Yes |
|
||||
| PSO GC v1.3 JP | 3OJ3 | Yes |
|
||||
| PSO GC v1.4 JP | 3OJ4 | Yes |
|
||||
| PSO GC v1.5 JP | 3OJ5 | No |
|
||||
| PSO GC v1.0 US | 3OE0 | Yes |
|
||||
| PSO GC v1.1 US | 3OE1 | Yes |
|
||||
| PSO GC v1.2 US | 3OE2 | No |
|
||||
| PSO GC v1.0 EU | 3OP0 | Yes |
|
||||
| PSO GC Ep3 NTE | 3SJT | Yes |
|
||||
| PSO GC Ep3 JP | 3SJ0 | Yes |
|
||||
| PSO GC Ep3 US | 3SE0 | No |
|
||||
| PSO GC Ep3 EU | 3SP0 | No |
|
||||
| PSO Xbox Beta | 4OJB | Yes |
|
||||
| PSO Xbox JP Disc | 4OJD | Yes |
|
||||
| PSO Xbox JP TU | 4OJU | Yes |
|
||||
| PSO Xbox US Disc | 4OED | Yes |
|
||||
| PSO Xbox US TU | 4OEU | Yes |
|
||||
| PSO Xbox EU Disc | 4OPD | Yes |
|
||||
| PSO Xbox EU TU | 4OPU | Yes |
|
||||
| PSO BB JP 1.25.13 | 51OC | Yes |
|
||||
| PSO BB Tethealla | 51OC | Yes |
|
||||
| Game | VERS | Architecture |
|
||||
|-------------------|------|---------------|
|
||||
| PSO DC NTE | 1OJ1 | Not supported |
|
||||
| PSO DC 11/2000 | 1OJ2 | Not supported |
|
||||
| PSO DC 12/2000 | 1OJ3 | Not supported |
|
||||
| PSO DC 01/2001 | 1OJ4 | Not supported |
|
||||
| PSO DC v1 JP | 1OJF | Not supported |
|
||||
| PSO DC v1 US | 1OEF | Not supported |
|
||||
| PSO DC v1 EU | 1OPF | Not supported |
|
||||
| PSO DC 08/2001 | 2OJ5 | SH-4 |
|
||||
| PSO DC v2 JP | 2OJF | SH-4 |
|
||||
| PSO DC v2 US | 2OEF | SH-4 |
|
||||
| PSO DC v2 EU | 2OPF | SH-4 |
|
||||
| PSO PC (v2) | 2OJW | Not supported |
|
||||
| PSO GC NTE | 3OJT | PowerPC |
|
||||
| PSO GC v1.2 JP | 3OJ2 | PowerPC |
|
||||
| PSO GC v1.3 JP | 3OJ3 | PowerPC |
|
||||
| PSO GC v1.4 JP | 3OJ4 | PowerPC |
|
||||
| PSO GC v1.5 JP | 3OJ5 | Not supported |
|
||||
| PSO GC v1.0 US | 3OE0 | PowerPC |
|
||||
| PSO GC v1.1 US | 3OE1 | PowerPC |
|
||||
| PSO GC v1.2 US | 3OE2 | Not supported |
|
||||
| PSO GC v1.0 EU | 3OP0 | PowerPC |
|
||||
| PSO GC Ep3 NTE | 3SJT | PowerPC |
|
||||
| PSO GC Ep3 JP | 3SJ0 | PowerPC |
|
||||
| PSO GC Ep3 US | 3SE0 | Not supported |
|
||||
| PSO GC Ep3 EU | 3SP0 | Not supported |
|
||||
| PSO Xbox Beta | 4OJB | x86 |
|
||||
| PSO Xbox JP Disc | 4OJD | x86 |
|
||||
| PSO Xbox JP TU | 4OJU | x86 |
|
||||
| PSO Xbox US Disc | 4OED | x86 |
|
||||
| PSO Xbox US TU | 4OEU | x86 |
|
||||
| PSO Xbox EU Disc | 4OPD | x86 |
|
||||
| PSO Xbox EU TU | 4OPU | x86 |
|
||||
| PSO BB JP 1.25.13 | 51OC | x86 |
|
||||
| PSO BB Tethealla | 51OC | x86 |
|
||||
|
||||
*Note: newserv uses the shorter GameCube versioning convention, where discs labeled DOL-XXXX-0-0Y are version 1.Y. The PSO community seems to use the convention 1.0Y in some places instead, but these are the same version. For example, the version that newserv calls v1.4 is the same as v1.04, and is labeled DOL-GPOJ-0-04 on the underside of the disc.*
|
||||
|
||||
newserv comes with a set of patches for some of the above versions, based on AR codes originally made by Ralf at GC-Forever and Aleron Ives. Many of them were originally posted in [this thread](https://www.gc-forever.com/forums/viewtopic.php?f=38&t=2050).
|
||||
|
||||
You can also put DOL files in the system/dol directory, and they will appear in the Programs menu for GC clients. Selecting a DOL file there will load the file into the GameCube's memory and run it, just like the old homebrew loaders (PSUL and PSOload) did. For this to work, ReadMemoryWord.ppc.s, WriteMemory.ppc.s, and RunDOL.ppc.s must be present in the system/client-functions directory. This has been tested on Dolphin but not on a real GameCube, so results may vary.
|
||||
You can also put DOL files in the system/dol directory, and they will appear in the Programs menu for GC clients. Selecting a DOL file there will load the file into the GameCube's memory and run it, just like the old homebrew loaders (PSUL and PSOload) did. For this to work, ReadMemoryWord.ppc.s, WriteMemory.ppc.s, and RunDOL.ppc.s must be present in the system/client-functions/System directory. This has been tested on Dolphin but not on a real GameCube, so results may vary.
|
||||
|
||||
Like other kinds of data, functions and DOL files are cached in memory. If you've changed any of these files, you can run `reload functions` or `reload dol-files` in the interactive shell to make the changes take effect without restarting the server.
|
||||
|
||||
@@ -460,35 +498,36 @@ newserv supports a variety of commands players can use by chatting in-game. Any
|
||||
Some commands only work on the game server and not on the proxy server. The chat commands are:
|
||||
|
||||
* Information commands
|
||||
* `$li`: Shows basic information about the lobby or game you're in. If you're on the proxy server, shows information about your connection instead (remote Guild Card number, client ID, etc.).
|
||||
* `$si` (game server only): Shows basic information about the server.
|
||||
* `$ping`: Shows round-trip ping time from the server to you. On the proxy server, shows the ping time from you to the proxy and from the proxy to the server.
|
||||
* `$matcount` (game server only): Shows how many of each type of material you've used.
|
||||
* `$itemnotifs <mode>`: Enables item drop notification messages. If the game has private drops enabled, you will only see a notification if the dropped item is visible to you; you won't be notified of other players' drops. The modes are:
|
||||
* `$li`: Show basic information about the lobby or game you're in. If you're on the proxy server, show information about your connection instead (remote Guild Card number, client ID, etc.).
|
||||
* `$si` (game server only): Show basic information about the server.
|
||||
* `$ping`: Show round-trip ping time from the server to you. On the proxy server, show the ping time from you to the proxy and from the proxy to the server.
|
||||
* `$matcount` (game server only): Show how many of each type of material you've used.
|
||||
* `$itemnotifs <mode>`: Enable item drop notification messages. If the game has private drops enabled, you will only see a notification if the dropped item is visible to you; you won't be notified of other players' drops. The modes are:
|
||||
* `off`: No notifications are shown.
|
||||
* `rare`: You are notified when a rare item drops.
|
||||
* `on`: You are notified when any item drops, except Meseta.
|
||||
* `every`: You are notified when any item drops, including Meseta.
|
||||
* `$what` (game server only): Shows the type, name, and stats of the nearest item on the ground.
|
||||
* `$where` (game server only): Shows your current floor number and coordinates. Mainly useful for debugging.
|
||||
* `$what` (game server only): Show the type, name, and stats of the nearest item on the ground.
|
||||
* `$where` (game server only): Show your current floor number and coordinates. Mainly useful for debugging.
|
||||
* `$qfread <field-name>` (game server only): Show the value of a quest counter in your player data. The field names are defined in config.json.
|
||||
|
||||
* Debugging commands
|
||||
* `$debug` (game server only): Enable or disable debug. You need the DEBUG flag in your user account to use this command. Enabling debug does a few things:
|
||||
* `$debug` (game server only): Enable or disable debug. You need the DEBUG flag in your user account to use this command. Enabling debug does several things:
|
||||
* You'll see in-game messages from the server when you take certain actions, like killing an enemy in BB.
|
||||
* You'll see the rare seed value and floor variations when you join a game.
|
||||
* You'll be placed into the highest available slot in lobbies and games instead of the lowest, unless you're joining a BB solo-mode game.
|
||||
* You'll be able to join games with any PSO version, not only those for which crossplay is normally supported. Be prepared for client crashes and other client-side brokenness if you do this. Please do not submit any issues for broken behaviors in crossplay, unless the situation is explicitly supported (see the "Cross-version play" section above).
|
||||
* You'll be placed into the last available slot in lobbies and games instead of the first, unless you're joining a BB solo-mode game.
|
||||
* You'll be able to join games with any PSO version, not only those for which crossplay is normally supported. Be prepared for client crashes and other client-side brokenness if you do this. Do not submit any issues for broken behaviors in crossplay, unless the situation is explicitly supported (see the "Cross-version play" section above).
|
||||
* The rest of the commands in this section are enabled on the game server. (They are always enabled on the proxy server.)
|
||||
* `$quest <number>` (game server only): Load a quest by quest number. Can be used to load battle or challenge quests with only one player present.
|
||||
* `$quest <number>` (game server only): Load a quest by quest number. Can be used to load battle or challenge quests with only one player present. Debug is not required to be enabled if the specified quest has the AllowStartFromChatCommand field set in its metadata file.
|
||||
* `$qcall <function-id>`: Call a quest function on your client.
|
||||
* `$qcheck <flag-num>` (game server only): Show the value of a quest flag. This command can be used without debug mode enabled. If you're in a game, show the value of the flag in that game; if you're in the lobby, show the saved value of that quest flag for your character (BB only).
|
||||
* `$qset <flag-num>` or `$qclear <flag-num>`: Set or clear a quest flag for everyone in the game. If you're in the lobby and on BB, set or clear the saved value of a quest flag in your character file.
|
||||
* `$qgread <flag-num>` (game server only): Get the value of a quest counter ("global flag"). This command can be used without debug mode enabled.
|
||||
* `$qgread <flag-num>` (game server only): Show the value of a quest counter ("global flag"). This command can be used without debug mode enabled.
|
||||
* `$qgwrite <flag-num> <value>` (game server only): Set the value of a quest counter ("global flag") for yourself.
|
||||
* `$qsync <reg-num> <value>`: Set a quest register's value for yourself only. `<reg-num>` should be either rXX (e.g. r60) or fXX (e.g. f60); if the latter, `<value>` is parsed as a floating-point value instead of as an integer.
|
||||
* `$qsyncall <reg-num> <value>`: Set a quest register's value for everyone in the game. `<reg-num>` should be either rXX (e.g. r60) or fXX (e.g. f60); if the latter, `<value>` is parsed as a floating-point value instead of as an integer.
|
||||
* `$swset [floor] <flag-num>` and `$swclear [floor] <flag-num>`: Set or clear a switch flag. If floor is not given, sets or clears the flag on your current floor.
|
||||
* `$swsetall`: Sets all switch flags on your current floor. This unlocks all doors, disables all laser fences, triggers all light/poison switches, etc.
|
||||
* `$swsetall`: Set all switch flags on your current floor. This unlocks all doors, disables all laser fences, triggers all light/poison switches, etc.
|
||||
* `$gc` (game server only): Send your own Guild Card to yourself.
|
||||
* `$sc <data>`: Send a command to yourself.
|
||||
* `$ss <data>`: Send a command to the remote server (if in a proxy session) or to the game server.
|
||||
@@ -498,62 +537,63 @@ Some commands only work on the game server and not on the proxy server. The chat
|
||||
* `$ep3battledebug` (game server only; Episode 3 only): Enable or disable TCard00_Select. If enabled, the game will enter the debug menu when you start a battle.
|
||||
|
||||
* 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. If you're in a game and you are the leader of the game, this also immediately changes the item tables used by the server when creating items. To revert to your actual section id, run `$secid` with no name after it. On the proxy server, this will not work if the remote server controls item drops (e.g. on BB, or on Schtserv with server drops enabled). If the server does not allow cheat mode anywhere (that is, "CheatModeBehavior" is "Off" in config.json), this command does nothing.
|
||||
* `$rand <seed>`: Sets your override random seed (specified as a 32-bit hex value). This will make any games you create use the given seed for rare enemies. This also makes item drops deterministic in Blue Burst games hosted by newserv. On the proxy server, this command can cause desyncs with other players in the same game, since they will not see the overridden random seed. To remove the override, run `$rand` with no arguments. If the server does not allow cheat mode anywhere (that is, "CheatModeBehavior" is "Off" in config.json), this command does nothing.
|
||||
* `$ln [name-or-type]`: Sets the lobby number. Visible only to you. This command exists because some non-lobby maps can be loaded as lobbies with invalid lobby numbers. See the "GC lobby types" and "Ep3 lobby types" entries in the information menu for acceptable values here. Note that non-lobby maps do not have a lobby counter, so there's no way to exit the lobby without using either `$ln` again or `$exit`. On the game server, `$ln` reloads the lobby immediately; on the proxy server, it doesn't take effect until you load another lobby yourself (which means you'll like have to use `$exit` to escape). Run this command with no argument to return to the default lobby.
|
||||
* `$swa`: Enables or disables switch assist. When enabled, the server will attempt to automatically unlock two-player and four-player doors in non-quest games if you step on all the required switches sequentially.
|
||||
* `$exit`: If you're in a lobby, sends you to the main menu (which ends your proxy session, if you're in one). If you're in a game or spectator team, sends you to the lobby (but does not end your proxy session if you're in one). Does nothing if you're in a non-Episode 3 game and no quest is in progress.
|
||||
* `$arrow <color-id>`: Change your lobby arrow color.
|
||||
* `$secid <section-id>`: Set your override section ID. After running this command, any games you create will use your override section ID for rare drops instead of your character's actual section ID. If you're in a game and you are the leader of the game, this also immediately changes the item tables used by the server when creating items. To revert to your actual section id, run `$secid` with no name after it. On the proxy server, this will not work if the remote server controls item drops (e.g. on BB, or on Schtserv with server drops enabled). If the server does not allow cheat mode anywhere (that is, "CheatModeBehavior" is "Off" in config.json), this command does nothing.
|
||||
* `$rand <seed>`: Set your override random seed (specified as a 32-bit hex value). This will make any games you create use the given seed for rare enemies. This also makes item drops deterministic in Blue Burst games hosted by newserv. On the proxy server, this command can cause desyncs with other players in the same game, since they will not see the overridden random seed. To remove the override, run `$rand` with no arguments. If the server does not allow cheat mode anywhere (that is, "CheatModeBehavior" is "Off" in config.json), this command does nothing.
|
||||
* `$ln [name-or-type]`: Set the lobby number. Visible only to you. This command exists because some non-lobby maps can be loaded as lobbies with invalid lobby numbers. See the "GC lobby types" and "Ep3 lobby types" entries in the information menu for acceptable values here. Note that non-lobby maps do not have a lobby counter, so there's no way to exit the lobby without using either `$ln` again or `$exit`. On the game server, `$ln` reloads the lobby immediately; on the proxy server, it doesn't take effect until you load another lobby yourself (which means you'll like have to use `$exit` to escape). Run this command with no argument to return to the default lobby.
|
||||
* `$swa`: Enable or disable switch assist. When enabled, the server will attempt to automatically unlock two-player and four-player doors in non-quest games if you step on all the required switches sequentially.
|
||||
* `$exit`: If you're in a lobby, send you to the main menu (which ends your proxy session, if you're in one). If you're in a game or spectator team, send you to the lobby (but does not end your proxy session if you're in one). Does nothing if you're in a non-Episode 3 game and no quest is in progress.
|
||||
* `$patch <name>`: Run a patch on your client. `<name>` must exactly match the name of a patch on the server.
|
||||
|
||||
* Character data commands (game server only)
|
||||
* `$savechar <slot>`: Saves your current character data on the server in the specified slot (each serial number has 4 slots, numbered 1-4). These slots are separate from BB character slots; using this command does not affect BB characters.
|
||||
* `$loadchar <slot>` (v1 and v2 only): Loads your character data from the specified slot. The changes will be undone if you join a game - to save your changes, disconnect from the lobby.
|
||||
* `$bbchar <username> <password> <slot>`: Use this command when playing on a non-BB version of PSO. If the username and password are correct, this command converts your current character to BB format and saves it on the server in the given slot (1-4). Any character already in that slot is overwritten. (This command is similar to `$savechar`, except it overwrites a BB character slot, and can transfer characters across accounts.) Note that the character's chat data, quick menu config, and bank contents are not copied, since there is no way for the server to request those types of data.
|
||||
* `$edit <stat> <value>`: Modifies your character data. If you are on V3 (GameCube/Xbox), this command does nothing. If you are on V1 or V2 (DC or PC, not BB), your changes will be undone if you join a game - to save your changes, disconnect from the lobby. If cheats are allowed on the server, `<stat>` can be any of `atp`, `mst`, `evp`, `hp`, `dfp`, `ata`, `lck`, `meseta`, `exp`, `level`, `namecolor`, `secid`, `name`, `language`, `npc`, or `tech`. If cheats are not allowed, only `namecolor`, `name`, `language`, and `npc` can be used. Changing your character's language is only useful on BB; to do so, use a single-character language code (e.g. to switch your character to English, use `$edit language E`; for Japanese, use `$edit language J`).
|
||||
* `$savechar <slot>`: Save your current character data on the server in the specified slot. See the "Server-side saves" section for more details.
|
||||
* `$loadchar <slot>`: Save your current character data on the server in the specified slot. See the "Server-side saves" section for more details.
|
||||
* `$bbchar <username> <password> <slot>`: Save your current character data on the server in a different account's BB character slots. See the "Server-side saves" section for more details.
|
||||
* `$edit <stat> <value>`: Modify your character data. If you are on V3 (GameCube/Xbox), this command does nothing. If you are on V1 or V2 (DC or PC, not BB), your changes will be undone if you join a game - to save your changes, disconnect from the lobby. If cheats are allowed on the server, `<stat>` can be any of `atp`, `mst`, `evp`, `hp`, `dfp`, `ata`, `lck`, `meseta`, `exp`, `level`, `namecolor`, `secid`, `name`, `language`, `npc`, or `tech`. If cheats are not allowed, only `namecolor`, `name`, `language`, and `npc` can be used. Changing your character's language is only useful on BB; to do so, use a single-character language code (e.g. to switch your character to English, use `$edit language E`; for Japanese, use `$edit language J`).
|
||||
|
||||
* Blue Burst player commands (game server only)
|
||||
* `$bank [number]`: Switches your current bank, so you can access your other character's banks (if `number` is 1-4) or your shared account bank (if `number` is 0). If `number` is not given, switches back to your current character's bank.
|
||||
* `$save`: Saves your character, system, and Guild Card data immediately. (By default, your character is saved every 60 seconds while online, and your account and Guild Card data are saved whenever they change.)
|
||||
* `$bank [number]`: Switch your current bank, so you can access your other character's banks (if `number` is 1-4) or your shared account bank (if `number` is 0). If `number` is not given, switch back to your current character's bank.
|
||||
* `$save`: Save your character, system, and Guild Card data immediately. (By default, your character is saved every 60 seconds while online, and your account and Guild Card data are saved whenever they change.)
|
||||
|
||||
* Game state commands (game server only)
|
||||
* `$maxlevel <level>`: 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.
|
||||
* `$dropmode [mode]`: Changes the way item drops behave in the current game. `mode` can be `none`, `client`, `shared`, `private`, or `duplicate`. If `mode` is not given, tells you the current drop mode without changing it. See the "Item tables and drop modes" section for more information.
|
||||
* `$persist`: Enable or disable persistence for the current game. When persistence is on, the game will not be deleted when the last player leaves. The states of enemies, objects, and switches will be saved, and items left on the floor will not be deleted (except items only visible to the leaving player). If the game is empty for too long (15 minutes by default), it is then deleted. There is an edge case with persistence: if the player defeats a boss, leaves the room, joins again, and returns to the boss arena, neither the boss nor the exit warp will spawn, so they will be stuck there and have to use $warp or Quit Game to get out. For this reason, `$warp 0` is allowed in boss arenas once the boss is defeated, even if cheat mode is disabled.
|
||||
* `$maxlevel <level>`: Set the maximum level for players to join the current game. (This only applies when joining; if a player joins and then levels up past this level during the game, they are not kicked out, but won't be able to rejoin if they leave.)
|
||||
* `$minlevel <level>`: Set the minimum level for players to join the current game.
|
||||
* `$password <password>`: Set the game's join password. To unlock the game, run `$password` with nothing after it.
|
||||
* `$dropmode [mode]`: Change the way item drops behave in the current game. `mode` can be `none`, `client`, `shared`, `private`, or `duplicate`. If `mode` is not given, tells you the current drop mode without changing it. See the "Item tables and drop modes" section for more information.
|
||||
* `$persist`: Enable or disable persistence for the current game. When persistence is on, the game will not be deleted when the last player leaves. The states of enemies, objects, and switches will be saved, and items left on the floor will not be deleted (except items that were only visible to the leaving player, which are deleted). If the game is empty for too long (15 minutes by default), it is then deleted. There is an edge case with persistence: if the player defeats a boss, leaves the room, joins again, and returns to the boss arena, neither the boss nor the exit warp will appear, so they will be stuck there and have to use $warp or Quit Game to get out. For this reason, `$warp 0` is allowed in boss arenas once the boss is defeated, even if cheat mode is disabled.
|
||||
|
||||
* Episode 3 commands (game server only)
|
||||
* `$spec`: Toggles the allow spectators flag for Episode 3 games. If any players are spectating when this flag is disabled, they will be sent back to the lobby.
|
||||
* `$inftime`: Toggles infinite-time mode. Must be used before starting a battle. If infinite-time mode is enabled, the overall and per-phase time limits will be disabled regardless of the values chosen during battle setup. After completing a battle, infinite-time mode is reset to the server's default value (which can be set in Episode3BehaviorFlags in config.json).
|
||||
* `$dicerange [d:L-H] [1:L-H] [a1:L-H] [d1:L-H]`: Sets override dice ranges for the next battle. The min and max dice values from the rules setup menu always apply to the ATK dice, but you can specify a different range for the DEF dice with `d:2-4` (for example). The `1:` override applies to the 1-player team in a 2v1 game (so you would set the 2-player team's desired dice range in the rules menu). You can also specify the 1-player team's ATK and DEF ranges separately with the `a1:` and `d1:` overrides. Note that these ranges will only be used if the chosen map or quest does not override them.
|
||||
* `$stat <what>`: Shows a statistic about your player or team in the current battle. `<what>` can be `duration`, `fcs-destroyed`, `cards-destroyed`, `damage-given`, `damage-taken`, `opp-cards-destroyed`, `own-cards-destroyed`, `move-distance`, `cards-set`, `fcs-set`, `attack-actions-set`, `techs-set`, `assists-set`, `defenses-self`, `defenses-ally`, `cards-drawn`, `max-attack-damage`, `max-combo`, `attacks-given`, `attacks-taken`, `sc-damage`, `damage-defended`, or `rank`.
|
||||
* `$surrender`: Causes your team to immediately lose the current battle.
|
||||
* `$saverec <name>`: Saves the recording of the last battle.
|
||||
* `$playrec <name>`: Plays a battle recording. This command creates a spectator team and replays the specified battle log within it. There is a bug in Dolphin that makes use of this command unstable in emulation (see the "Battle records" section above).
|
||||
* `$spec`: Toggle the allow spectators flag for Episode 3 games. If any players are spectating when this flag is disabled, they are sent back to the lobby.
|
||||
* `$inftime`: Toggle infinite-time mode. Must be used before starting a battle. If infinite-time mode is on, the overall and per-phase time limits will be disabled regardless of the values chosen during battle rules setup. After completing a battle, infinite-time mode is reset to the server's default value (which can be set in Episode3BehaviorFlags in config.json).
|
||||
* `$dicerange [d:L-H] [1:L-H] [a1:L-H] [d1:L-H]`: Set override dice ranges for the next battle. The min and max dice values from the rules setup menu always apply to the ATK dice, but you can specify a different range for the DEF dice with `d:2-4` (for example). The `1:` override applies to the 1-player team in a 2v1 game (so you would set the 2-player team's desired dice range in the rules menu). You can also specify the 1-player team's ATK and DEF ranges separately with the `a1:` and `d1:` overrides. Note that these ranges will only be used if the chosen map or quest does not override them.
|
||||
* `$stat <what>`: Show a statistic about your player or team in the current battle. `<what>` can be `duration`, `fcs-destroyed`, `cards-destroyed`, `damage-given`, `damage-taken`, `opp-cards-destroyed`, `own-cards-destroyed`, `move-distance`, `cards-set`, `fcs-set`, `attack-actions-set`, `techs-set`, `assists-set`, `defenses-self`, `defenses-ally`, `cards-drawn`, `max-attack-damage`, `max-combo`, `attacks-given`, `attacks-taken`, `sc-damage`, `damage-defended`, or `rank`.
|
||||
* `$surrender`: Cause your team to immediately lose the current battle.
|
||||
* `$saverec <name>`: Save the recording of the last battle.
|
||||
* `$playrec <name>`: Play a battle recording. This command creates a spectator team immediately but the replay does not start automatically, to give other players a chance to join. To start the battle replay within the spectator team, run `$playrec` again (with no name). There is a bug in Dolphin that makes this command unstable in emulation (see the "Battle records" section above).
|
||||
|
||||
* Cheat mode commands
|
||||
* `$cheat` (game server only): Enables or disables cheat mode for the current game. All other cheat mode commands do nothing if cheat mode is disabled. By default, cheat mode is off in new games but can be enabled; there is an option in config.json that allows you to disable cheat mode entirely, or set it to on by default in new games. Cheat mode is always enabled on the proxy server, unless cheat mode is disabled on the entire server.
|
||||
* `$infhp` / `$inftp`: Enables or disables infinite HP or TP mode. Applies to only you. In infinite HP mode, one-hit KO attacks will still kill you. On V1 and V2, infinite HP also automatically cures status ailments.
|
||||
* `$warpme <floor-id>` (or `$warp <floor-id>`): Warps yourself to the given floor.
|
||||
* `$warpall <floor-id>`: Warps everyone in the game to the given floor. You must be the leader to use this command, unless you're on the proxy server.
|
||||
* `$next`: Warps yourself to the next floor.
|
||||
* `$cheat` (game server only): Enable or disable cheat mode for the current game. All other cheat mode commands do nothing if cheat mode is disabled. By default, cheat mode is off in new games but can be enabled; there is an option in config.json that allows you to disable cheat mode entirely, or set it to on by default in new games. Cheat mode is always enabled on the proxy server, unless cheat mode is disabled on the entire server.
|
||||
* `$infhp`: Enable or disable infinite HP mode. Applies to only you; does not affect other players. When enabled, one-hit KO attacks will still kill you, but on most versions of the game (not DCv1, GC US 1.2, or GC JP 1.5), the server will automatically revive you if you die. On all versions except GC US 1.2 and GC JP 1.5, infinite HP also automatically cures status ailments.
|
||||
* `$inftp`: Enable or disable infinite TP mode. Applies to only you; does not affect other players.
|
||||
* `$warpme <floor-id>` (or `$warp <floor-id>`): Warp yourself to the given floor.
|
||||
* `$warpall <floor-id>`: Warp everyone in the game to the given floor. You must be the leader to use this command, unless you're on the proxy server.
|
||||
* `$next`: Warp yourself to the next floor.
|
||||
* `$item <desc>` (or `$i <desc>`): Create an item. `desc` may be a description of the item (e.g. "Hell Saber +5 0/10/25/0/10") or a string of hex data specifying the item code. Item codes are 16 hex bytes; at least 2 bytes must be specified, and all unspecified bytes are zeroes. If you are on the proxy server, you must not be using Blue Burst for this command to work. On the game server, this command works for all versions.
|
||||
* `$unset <index>` (game server only): In an Episode 3 battle, removes one of your set cards from the field. `<index>` is the index of the set card as it appears on your screen - 1 is the card next to your SC's icon, 2 is the card to the right of 1, etc. This does not cause a Hunters-side SC to lose HP, as they normally do when their items are destroyed.
|
||||
* `$dropmode [mode]` (proxy server): Changes the way item drops behave in the current game, if you are not on BB. Unlike the game server version of this command, using this on the proxy server requires cheats to be enabled. This works by intercepting the drop requests sent to and from the leader. (So, if you are the leader and not using server drop mode on the remote server, it affects the entire game; otherwise, it affects only items generated by your actions.) `mode` can be `none` (no drops), `default` (normal drops), or `proxy` (use newserv's drop tables instead of the remote server's). If `mode` is not given, tells you the current drop mode without changing it.
|
||||
* `$dropmode [mode]` (proxy server): Change the way item drops behave in the current game, if you are not on BB. Unlike the game server version of this command, using this on the proxy server requires cheats to be enabled. This works by intercepting the drop requests sent to and from the leader. (So, if you are the leader and not using server drop mode on the remote server, it affects the entire game; otherwise, it affects only items generated by your actions.) `mode` can be `none` (no drops), `default` (normal drops), or `proxy` (use newserv's drop tables instead of the remote server's). If `mode` is not given, tells you the current drop mode without changing it.
|
||||
|
||||
* Configuration commands
|
||||
* `$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.
|
||||
* `$allevent <event>` (game server only): Sets the current holiday event in all lobbies.
|
||||
* `$song <song-id>` (Episode 3 only): Plays a specific song in the current lobby.
|
||||
* Aesthetic commands
|
||||
* `$event <event>`: Set the current holiday event in the current lobby. Holiday events are documented in the "Using $event" item in the information menu. If you're on the proxy server, this applies to all lobbies and games you join, but only you will see the new event - other players will not.
|
||||
* `$allevent <event>` (game server only): Set the current holiday event in all lobbies.
|
||||
* `$song <song-id>` (Episode 3 only): Play a specific song in the current lobby.
|
||||
|
||||
* Administration commands (game server only)
|
||||
* `$ann <message>`: Sends an announcement message. The message is sent as temporary on-screen text to all players in all games and lobbies.
|
||||
* `$ann! <message>`: Sends an announcement message. The message is sent as a Simple Mail message to all players in all games and lobbies.
|
||||
* `$ax <message>`: Sends a message to the server's terminal. This cannot be used to run server shell commands; it only prints text to stderr.
|
||||
* `$silence <identifier>`: Silences a player (remove their ability to chat) or unsilences a player. The identifier may be the player's name or Guild Card number.
|
||||
* `$kick <identifier>`: Disconnects a player. The identifier may be the player's name or Guild Card number.
|
||||
* `$ban <identifier>`: Bans a player. The identifier may be the player's name or Guild Card number.
|
||||
* `$ann <message>`: Send an announcement message. The message is sent as temporary on-screen text to all players in all games and lobbies.
|
||||
* `$ann! <message>`: Send an announcement message. The message is sent as a Simple Mail message to all players in all games and lobbies.
|
||||
* `$ax <message>`: Send a message to the server's terminal. This cannot be used to run server shell commands; it only prints text to stderr.
|
||||
* `$silence <identifier>`: Silence a player (remove their ability to chat) or unsilence a player. The identifier may be the player's name or Guild Card number.
|
||||
* `$kick <identifier>`: Disconnect a player. The identifier may be the player's name or Guild Card number.
|
||||
* `$ban <duration> <identifier>`: Ban a player. The duration should be of the form `10m` (minutes), `10h` (hours), `10d` (days), `10w` (weeks), `10M` (months), or `10y` (years). (Numbers other than 10 may be used, of course.) As with `$kick`, the identifier may be the player's name or Guild Card number.
|
||||
|
||||
# Non-server features
|
||||
|
||||
|
||||
+68
-68
@@ -35,7 +35,7 @@ EB => 0047E958 0047ECCC
|
||||
EF => 007C2290 007C94FC
|
||||
|
||||
Game command handler table
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 DCv2 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 DCv2USA PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
01 => 8C0245E4 8C025298 8C0285A8 8C028C18 8C028C24 8C02DAC4 8C02DAC4 004DCD70 0058C830 802330EC 801DA750 801DD934 801DDD70 801DE450 801DDEC4 002D8D50 002DACC0 002DB1C0 800FB508 800F7BD8 800F801C 007F5CD4 007FCF54
|
||||
02 => 8C025BD4 8C026910 8C02A07C 8C02A6D4 8C02A6E0 8C030110 8C030110 004DEA90 0058E540 8022D870 801D5960 801DA438 801DA870 801DAF2C 801DAA70 002DADE0 002DCD20 002DD240 800F6918 800F3594 800F39D8 -------- --------
|
||||
03 => 8C02465C 8C025310 8C02861C 8C028C8C 8C028C98 8C02DB60 8C02DB60 004DCDB0 0058C870 8023302C 801DA690 801DD874 801DDCB0 801DE390 801DDE04 002D8DD0 002DAD40 002DB240 800FB448 800F7B18 800F7F5C 007E4B50 007EBDBC
|
||||
@@ -45,7 +45,7 @@ Game command handler table
|
||||
07 => 8C02486C 8C025520 8C028820 8C028E90 8C028E9C 8C02DDC8 8C02DDC8 004DCED0 0058C990 80232C5C 801DA3F0 801DD6A0 801DDADC 801DE1BC 801DDC30 002D8F30 002DAEA0 002DB3A0 800FB1A8 800F7878 800F7CBC 007E4B50 007C8380
|
||||
08 => 8C02490C 8C0255C0 8C0288B8 8C028F28 8C028F34 8C02DE60 8C02DE60 004DCF40 0058CA00 80232A5C 801DA358 801DD608 801DDA44 801DE124 801DDB98 002D8FC0 002DAF30 002DB430 800FB110 800F77E0 800F7C24 007E4B50 007C848C
|
||||
0E => 8C0249AC 8C025660 8C0289E8 8C029058 8C029064 8C02DF90 8C02DF90 004DD020 0058CAE0 80232590 801D9F20 801DD450 801DD88C 801DDF6C 801DD9E0 002D90E0 002DB050 002DB550 800FAEC0 800F7590 800F79D4 -------- --------
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 DCv2 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 DCv2USA PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
11 => 8C024BF4 8C0258F0 8C028CC8 8C029338 8C029344 8C02E270 8C02E270 004DD1E0 0058CCA0 80231D24 801D9844 801DCFE4 801DD41C 801DDAFC 801DD570 002D9420 002DB390 002DB890 800FA6C0 800F6D90 800F71D4 007C1534 007C87A0
|
||||
12 => 8C024B88 8C02583C 8C028BAC 8C02921C 8C029228 8C02E154 8C02E154 004DD150 0058CC10 80232108 801D9C08 801DD340 801DD77C 801DDE5C 801DD8D0 002D95C0 002F7370 00243DA0 800FAA88 800F7158 800F759C 005A9104 00779DF0
|
||||
13 => 8C024BB0 8C0258A0 8C028C7C 8C0292EC 8C0292F8 8C02E224 8C02E224 004DD1C0 0058CC80 80231DD4 801D989C 801DD03C 801DD478 801DDB58 801DD5CC 002D93A0 002DB310 002DB810 800FA71C 800F6DEC 800F7230 007C1494 007C8700
|
||||
@@ -59,15 +59,15 @@ Game command handler table
|
||||
1C => 8C024D24 8C025A20 8C028E40 8C0294B0 8C0294BC 8C02E3E8 8C02E3E8 004DD150 0058CC10 80231AE8 801D96D4 801DCE74 801DD2AC 801DD98C 801DD400 002D95C0 002F7370 00243DA0 800FA550 800F6C20 800F7064 -------- --------
|
||||
1D => 8C024EF8 8C025BF4 8C028FAC 8C02961C 8C029628 8C02E578 8C02E578 004DD420 0058CEE0 8023162C 801D9184 801DCB64 801DCF9C 801DD67C 801DD0F0 002D9850 002DB7B0 002DBCB0 800FA000 800F66D0 800F6B14 007C1990 007C8BFC
|
||||
1F => -------- -------- 8C028950 8C028FC0 8C028FCC 8C02DEF8 8C02DEF8 004DCFB0 0058CA70 8023285C 801DA114 801DD51C 801DD958 801DE038 801DDAAC 002D9050 002DAFC0 002DB4C0 800FB078 800F7748 800F7B8C 007C2078 007C92E4
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 DCv2 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 DCv2USA PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
22 => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 0047E92C 007F2E5C
|
||||
23 => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 007EBC6C 007F2EEC
|
||||
24 => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 007EBC88 007F2F08
|
||||
25 => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 007EBCC8 007F2F48
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 DCv2 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 DCv2USA PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
41 => 8C024EBC 8C025BB8 8C028F74 8C0295E4 8C0295F0 8C02E540 8C02E540 004DD400 0058CEC0 80231694 801D91E8 801DCBC8 801DD000 801DD6E0 801DD154 002D9810 002DB770 002DBC70 800FA064 800F6734 800F6B78 007C193C 007C8BA8
|
||||
44 => -------- 8C025864 8C028BD4 8C029244 8C029250 8C02E17C 8C02E17C 004DD160 0058CC20 80232034 801D9B40 801DD278 801DD6B4 801DDD94 801DD808 002D9240 002DB1B0 002DB6B0 800FA9C0 800F7090 800F74D4 007C1C28 007C8E94
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 DCv2 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 DCv2USA PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
60 => 8C024D38 8C025A34 8C028E54 8C0294C4 8C0294D0 8C02E3FC 8C02E3FC 004DD310 0058CDD0 80231A88 801D9674 801DCE14 801DD24C 801DD92C 801DD3A0 002D95D0 002DB530 002DBA30 800FA4F0 800F6BC0 800F7004 007C162C 007C8898
|
||||
62 => 8C024D38 8C025A34 8C028E54 8C0294C4 8C0294D0 8C02E3FC 8C02E3FC 004DD310 0058CDD0 80231A88 801D9674 801DCE14 801DD24C 801DD92C 801DD3A0 002D95D0 002DB530 002DBA30 800FA4F0 800F6BC0 800F7004 007C162C 007C8898
|
||||
64 => 8C024ABC 8C025770 8C028AF0 8C029160 8C02916C 8C02E098 8C02E098 004DD0C0 0058CB80 80232410 801D9EB0 801DD3E0 801DD81C 801DDEFC 801DD970 002D9190 002DB100 002DB600 800FAD90 800F7460 800F78A4 007C135C 007C85C8
|
||||
@@ -78,7 +78,7 @@ Game command handler table
|
||||
69 => 8C0259BC 8C0266F8 8C029E68 8C02A4C0 8C02A4CC 8C02F4F8 8C02F4F8 004DE190 0058DC50 8022EF54 801D7308 801DB634 801DBA6C 801DC14C 801DBBC0 002DA4E0 002DC440 002DC940 800F82B8 800F4D4C 800F5190 007F5C7C 007FCEFC
|
||||
6C => 8C024D9C 8C025A98 8C028E8C 8C0294FC 8C029508 8C02E414 8C02E414 004DD310 0058CDD0 80231A48 801D9634 801DCDD4 801DD20C 801DD8EC 801DD360 002D9610 002DB570 002DBA70 800FA4B0 800F6B80 800F6FC4 007C1B3C 007C8DA8
|
||||
6D => 8C024D9C 8C025A98 8C028E8C 8C0294FC 8C029508 8C02E414 8C02E414 004DD310 0058CDD0 80231A48 801D9634 801DCDD4 801DD20C 801DD8EC 801DD360 002D9610 002DB570 002DBA70 800FA4B0 800F6B80 800F6FC4 007C1B3C 007C8DA8
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 DCv2 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 DCv2USA PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
80 => 8C024E00 8C025AFC 8C028EC4 8C029534 8C029540 8C02E44C 8C02E44C 004DD330 0058CDF0 80231990 801D9550 801DCCF0 801DD128 801DD808 801DD27C 002D9630 002DB590 002DBA90 800FA3CC 800F6A9C 800F6EE0 -------- --------
|
||||
81 => 8C024F38 8C025C34 8C028FEC 8C02965C 8C029668 8C02E5B8 8C02E5B8 004DD450 0058CF10 80231550 801D90A0 801DCA80 801DCEB8 801DD598 801DD00C 002D9880 002DB7E0 002DBCE0 800F9F1C 800F65EC 800F6A30 007C1B58 007C8DC4
|
||||
83 => 8C024E4C 8C025B48 8C028F0C 8C02957C 8C029588 8C02E494 8C02E494 004DD370 0058CE30 80231844 801D9360 801DCC1C 801DD054 801DD734 801DD1A8 002D9670 002DB5D0 002DBAD0 800FA1DC 800F68AC 800F6CF0 007C1780 007C89EC
|
||||
@@ -88,7 +88,7 @@ Game command handler table
|
||||
8D => 8C0260C8 -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
|
||||
8E => 8C02486C -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
|
||||
8F => 8C02486C -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 DCv2 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 DCv2USA PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
90 => -------- 8C026B28 8C02A298 8C02A8F0 8C02A8FC 8C02F63C 8C02F63C 004DE2A0 0058E510 8022EDD8 801D7180 801DB4CC 801DB904 801DBFE4 801DBA58 002DA610 002DCD00 002DCA70 800F8130 800F4BC4 800F5008 -------- --------
|
||||
91 => -------- 8C026800 8C029F74 8C02A5CC 8C02A5D8 8C02F534 8C02F534 004DE1B0 0058DC70 8022EE34 801D71DC 801DB528 801DB960 801DC040 801DBAB4 002DA510 002DC470 002DC970 800F818C 800F4C20 800F5064 -------- --------
|
||||
92 => -------- 8C026C28 8C02A3A4 8C02A9FC 8C02AA08 8C02F74C 8C02F74C 004DE380 0058E740 8022EC9C 801D6FF4 801DB3B0 801DB7E8 801DBEC8 801DB93C 002DA6E0 002DCFE0 002DCB40 800F7FA4 800F4A38 800F4E7C -------- --------
|
||||
@@ -98,7 +98,7 @@ Game command handler table
|
||||
9B => -------- -------- -------- -------- -------- 8C02FF24 8C02FF24 004DE900 0058E380 8022DC28 801D5C64 801DA700 801DAB38 801DB1F4 801DAD38 002DAC30 002DCB50 002DD090 800F6C1C 800F3898 800F3CDC 007D3E88 007DB0F4
|
||||
9C => -------- -------- -------- -------- -------- 8C030358 8C030358 004DE380 0058E740 8022D814 801D5904 801DA3DC 801DA814 801DAED0 801DAA14 002DA6E0 002DCFE0 002DCB40 800F68BC 800F3538 800F397C 007DA6F8 007E1964
|
||||
9F => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 801D4BC0 801D9A1C 801D9E54 801DA510 801DA054 002DB610 002DD570 002DDA70 800F5A08 800F2868 800F2CAC 007E488C 007EBAF8
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 DCv2 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 DCv2USA PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
A0 => -------- 8C025520 8C028820 8C028E90 8C028E9C 8C02DDC8 8C02DDC8 004DCED0 0058C990 80232C5C 801DA3F0 801DD6A0 801DDADC 801DE1BC 801DDC30 002D8F30 002DAEA0 002DB3A0 800FB1A8 800F7878 800F7CBC 007C1114 007C8380
|
||||
A1 => -------- 8C025520 8C028820 8C028E90 8C028E9C 8C02DDC8 8C02DDC8 004DCED0 0058C990 80232C5C 801DA3F0 801DD6A0 801DDADC 801DE1BC 801DDC30 002D8F30 002DAEA0 002DB3A0 800FB1A8 800F7878 800F7CBC 007C1114 007C8380
|
||||
A2 => -------- 8C025C70 8C029024 8C029694 8C0296A0 8C02E5F0 8C02E5F0 004DD4B0 0058CF70 80231444 801D904C 801DCA2C 801DCE64 801DD544 801DCFB8 002D98D0 002DB830 002DBD30 800F9EC8 800F6598 800F69DC 007C1B94 007C8E00
|
||||
@@ -109,7 +109,7 @@ A6 => -------- -------- 8C028C0C 8C02927C 8C029288 8C02E1B4 8C02E1B4 004DD180 00
|
||||
A7 => -------- -------- 8C028C44 8C0292B4 8C0292C0 8C02E1EC 8C02E1EC 004DD1A0 0058CC60 80231E9C 801D998C 801DD0F8 801DD534 801DDC14 801DD688 002D9320 002DB290 002DB790 800FA80C 800F6EDC 800F7320 007C1F38 007C91A4
|
||||
AB => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 801D4A18 801D9918 801D9D50 801DA40C 801D9F50 002DB6F0 002DD650 002DDB50 800F5860 800F26C0 800F2B04 007E4A98 007EBD04
|
||||
AC => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 801D4958 801D987C 801D9CB4 801DA370 801D9EB4 002DB710 002DD670 002DDB70 800F57C4 800F2624 800F2A68 007E4AE0 007EBD4C
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 DCv2 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 DCv2USA PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
B0 => -------- -------- 8C0290FC 8C02976C 8C029778 8C02E6C8 8C02E6C8 004DD580 0058D040 8023110C 801D8C44 801DC78C 801DCBC4 801DD2A4 801DCD18 002D9A20 002DB980 002DBE80 800F9ACC 800F618C 800F65D0 007C1FF0 007C925C
|
||||
B1 => -------- -------- 8C02A8E4 8C02AF60 8C02AF6C 8C02FAFC 8C02FAFC 004DE5E0 0058E040 8022E6F8 801D69BC 801DAE40 801DB278 801DB958 801DB3CC 002DA890 002DC7B0 002DCCF0 800F7934 800F43C8 800F480C 007C2178 007C93E4
|
||||
B2 => -------- -------- -------- -------- -------- 8C02FCF4 8C02FCF4 004DE730 0058E190 8022E108 801D6238 801DAB28 801DAF60 801DB61C -------- 002DAA60 002DC980 002DCEC0 800F718C -------- -------- 007C22B8 007C9524
|
||||
@@ -118,14 +118,14 @@ B8 => -------- -------- -------- -------- -------- -------- -------- -------- --
|
||||
B9 => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 800F0590 800F09D4 -------- --------
|
||||
BA => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 800EFA0C 800EFE50 -------- --------
|
||||
BB => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 800F0454 800F0898 -------- --------
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 DCv2 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 DCv2USA PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
C0 => -------- -------- -------- -------- -------- 8C02FB94 8C02FB94 004DE630 0058E090 8022E5CC 801D6854 801DAD48 801DB180 801DB860 801DB2D4 002DA920 002DC840 002DCD80 800F77CC 800F4250 800F4694 007C21FC 007C9468
|
||||
C4 => -------- -------- -------- -------- -------- 8C02FCBC 8C02FCBC 004DE710 0058E170 8022E1E8 801D6364 801DABD4 801DB00C 801DB6EC 801DB160 002DAA20 002DC940 002DCE80 800F72DC 800F3E08 800F424C 007C2240 007C94AC
|
||||
C5 => -------- -------- -------- -------- -------- 8C030530 8C030530 004DEDF0 0058E8D0 8022D4A8 801D5538 801DA210 801DA648 801DAD04 801DA848 002DB280 002DD1E0 002DD6E0 800F6380 800F31F0 800F3634 007DD9A0 007E4C0C
|
||||
C9 => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 800FA4F0 800F6BC0 800F7004 -------- --------
|
||||
CB => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 800F0324 800F0768 -------- --------
|
||||
CC => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 800F1EE4 800F2328 -------- --------
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 DCv2 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 DCv2USA PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
D1 => -------- -------- -------- -------- -------- -------- -------- -------- -------- 8022D1D4 801D508C 801D9E14 801DA24C 801DA908 801DA44C 002DB490 002DD3F0 002DD8F0 800F5ED4 800F2D34 800F3178 007C55E8 007CC854
|
||||
D3 => -------- -------- -------- -------- -------- -------- -------- -------- -------- 8022D0A8 801D4F3C 801D9D24 801DA15C 801DA818 801DA35C 002DB4B0 002DD410 002DD910 800F5D84 800F2BE4 800F3028 007C8884 007CFAF0
|
||||
D4 => -------- -------- -------- -------- -------- -------- -------- -------- -------- 8022D054 801D4EE8 801D9CD0 801DA108 801DA7C4 801DA308 002DB520 002DD480 002DD980 800F5D30 800F2B90 800F2FD4 007F29E0 007F9C60
|
||||
@@ -136,7 +136,7 @@ DA => -------- -------- -------- -------- -------- -------- -------- -------- --
|
||||
DC => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 800F39E0 800F07EC 800F0C30 -------- --------
|
||||
DD => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 007EBBD8 007F2E44
|
||||
DE => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 007EF6F0 007F6970
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 DCv2 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 DCv2USA PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
E0 => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 800F554C 800F23F0 800F2834 -------- --------
|
||||
E1 => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 800F54BC 800F2360 800F27A4 -------- --------
|
||||
E2 => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 800F5218 800F20BC 800F2500 -------- --------
|
||||
@@ -152,7 +152,7 @@ EB => -------- -------- -------- -------- -------- -------- -------- -------- --
|
||||
ED => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 800F3FC8 800F0DE4 800F1228 -------- --------
|
||||
EE => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 800F3C7C 800F0A88 800F0ECC 007C2034 007C92A0
|
||||
EF => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 800F3824 800F064C 800F0A90 007C2290 007C94FC
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 DCv2 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 DCv2USA PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US GCEp3EU BB1243U BB12513J
|
||||
F0 => -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- 007EBB4C 007F2DB8
|
||||
|
||||
|
||||
@@ -162,9 +162,9 @@ Subcommands flags:
|
||||
4 = allowed in game on non-Pioneer 2
|
||||
|
||||
Subcommand handler table
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB12513J
|
||||
DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB12513J
|
||||
60 => 8C024D38 8C025A34 8C028E54 8C0294C4 8C0294D0 8C02E3FC 004DD310 0058CDD0 80231A88 801D9674 801DCE14 801DD24C 801DD92C 801DD3A0 002DBBA0 002DB530 002DE000 800FA4F0 800F6BC0 007C8898
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB12513J
|
||||
6x02 8C02BBDC-- 8C02C754-- 8C03079C-- 8C030FBC-- 8C03125C-- 8C0370F8-7 004DF710-7 0058F210-7 80236F20-7 801DE060-7 801E3A7C-7 801E3EE0-7 801E45DC-7 801E3FA0-7 002C9010-7 002F76A0-7 002F7820-7 800FFBDC-7 800FC50C-7 0061CDB0-7
|
||||
6x03 8C02BC48-- 8C02C7C0-- 8C030808-- 8C031028-- 8C0312C8-- 8C037164-7 004DF710-7 0058F210-7 80236F1C-7 801DE05C-7 801E3A78-7 801E3EDC-7 801E45D8-7 801E3F9C-7 002C9010-7 002F76A0-7 002F7820-7 800FFBD8-7 800FC508-7 0061CDB0-7
|
||||
6x04 8C02BCB4-- 8C02C82C-- 8C030874-- 8C031094-- 8C031334-- 8C0371D0-7 004DF780-7 0058F280-7 80236ED0-7 801DDFE8-7 801E3A40-7 801E3EA4-7 801E45A0-7 801E3F64-7 002DBC90-7 002DDBF0-7 002DE0F0-7 800FFB64-7 800FC494-7 0080090C-7
|
||||
@@ -178,7 +178,7 @@ cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE
|
||||
6x0D ---------- ---------- 8C026610-- 8C026C48-- 8C026C54-- 8C029CA4-7 004CE1B0-7 0057B330-7 802086F4-7 801AF074-7 801B2690-7 801B2A6C-7 801B30C0-7 801B2C04-7 001FFD10-7 001FFF10-7 001FFF10-7 800D2CEC-7 800CED48-7 0069006C-7
|
||||
6x0E 8C0553DC-- 8C056588-- 8C0265CC-- 8C026C04-- 8C026C10-- 8C029C60-6 004CE180-6 0057B300-6 8020878C-6 801AF248-6 801B2770-6 801B2B4C-6 801B31A0-6 801B2CE4-6 001FFC20-6 001FFE20-6 001FFE20-6 800D2EB0-6 800CEF0C-6 006902C0-6
|
||||
6x0F 8C05543C-- 8C0565E8-- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB12513J
|
||||
6x10 8C0554AC-- 8C056658-- 8C05CAD4-- 8C05D500-- 8C05D784-- 8C067588-4 0041DBF0-4 00421D10-4 80077074-4 800288B8-4 80028560-4 80028780-4 800287C0-4 80028748-4 000412F0-4 00041230-4 00041250-4 ---------- ---------- 00423A58-4
|
||||
6x11 8C1180D8-- 8C11B8B8-- 8C05CB34-- 8C05D560-- 8C05D7E4-- 8C0675E8-4 0041DC30-4 00421D50-4 80076FF0-4 80028828-4 800284D0-4 800286F0-4 80028730-4 800286B8-4 00041390-4 000412D0-4 000412F0-4 ---------- ---------- 00423AA8-4
|
||||
6x12 8C118100-- 8C11B8E0-- 8C05CBA4-- 8C05D5D0-- 8C05D854-- 8C067658-4 0041DC80-4 00421DA0-4 80076F40-4 8002878C-4 80028434-4 80028654-4 80028694-4 8002861C-4 00041440-4 00041380-4 000413A0-4 ---------- ---------- 00423B00-4
|
||||
@@ -195,7 +195,7 @@ cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE
|
||||
6x1D 8C01D148-- 8C01D758-- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
|
||||
6x1E 8C023310-- 8C01D7CC-- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
|
||||
6x1F 8C0233F0-- 8C01D5EC-- 8C01FBE4-- 8C01FF7C-- 8C01FF88-- 8C021DCC-7 004C72C0-7 00573E70-7 80212050-7 801B8A80-7 801BA324-7 801BA710-7 801BAD90-7 801BA8D4-7 001F9300-7 001F9510-7 001F9510-7 800DB8A4-7 800D7810-7 0068D488-7
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB12513J
|
||||
6x20 8C0230E0-- 8C023B24-- 8C01FC68-- 8C020000-- 8C02000C-- 8C021E84-7 004C7360-7 00573F10-7 80211F4C-7 801B88F4-7 801BA288-7 801BA674-7 801BACF4-7 801BA838-7 001F9470-7 001F9680-7 001F9680-7 800DB718-7 800D7684-7 0068D5C8-7
|
||||
6x21 8C01D7F0-- 8C023C04-- 8C01FB70-- 8C01FF08-- 8C01FF14-- 8C021D08-7 004C7210-7 00573DC0-7 802121EC-7 801B8D4C-7 801BA4B8-7 801BA8A4-7 801BAF28-7 801BAA6C-7 001F91E0-7 001F93F0-7 001F93F0-7 800DBB4C-7 800D7AB8-7 0068D3F8-7
|
||||
6x22 8C01D944-- 8C023898-- 8C02700C-- 8C027644-- 8C027650-- 8C02A80C-7 004CEBF0-7 0057BD70-7 802076A8-7 801ADD58-7 801B168C-7 801B1A68-7 801B20BC-7 801B1C00-7 00200820-7 00200A20-7 00200A20-7 800D1A00-7 800CDA5C-7 0069278C-7
|
||||
@@ -212,7 +212,7 @@ cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE
|
||||
6x2D 8C021248-- 8C023958-- 8C023B7C-- 8C023F00-- 8C023F0C-- 8C0268D0-7 004CB7B0-7 00578460-7 8020B454-7 801B1DF8-7 801B4BE0-7 801B4FCC-7 801B5620-7 801B5164-7 001FDFE0-7 001FE1F0-7 001FE1F0-7 800D5A50-7 800D1AAC-7 0068D830-7
|
||||
6x2E 8C19A7D8-- 8C01F970-- 8C022A50-- 8C022DD4-- 8C022DE0-- 8C025788-7 004CA990-7 00577620-7 8020C280-7 801B3344-7 801B5B8C-7 801B5F78-7 801B65CC-7 801B6110-7 001FD650-7 001FD860-7 001FD860-7 800D6EB4-7 800D2F10-7 0068FFBC-7
|
||||
6x2F 8C022544-- 8C02174C-- 8C026E64-- 8C02749C-- 8C0274A8-- 8C02A624-7 004CEA10-7 0057BB90-7 802078BC-7 801ADFA4-7 801B1818-7 801B1BF4-7 801B2248-7 801B1D8C-7 002006A0-7 002008A0-7 002008A0-7 800D1C30-7 800CDC8C-7 006933C0-7
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB12513J
|
||||
6x30 8C020EE0-- 8C1A6CE0-- 8C022518-- 8C022958-- 8C022964-- 8C024E5C-6 004C9F80-6 00576BC0-6 8020CE40-6 801B3EF4-6 801B64D8-6 801B68C4-6 801B6F18-6 801B6A5C-6 001FCA70-6 001FCC80-6 001FCC80-6 800D7A30-6 800D3A8C-6 006928E4-6
|
||||
6x31 8C020F80-- 8C022CAC-- 8C0247F4-- 8C024BF0-- 8C024BFC-- 8C0278D4-7 004CC2D0-7 00578FD0-7 8020A7F8-7 801B0C94-7 801B4014-7 801B4400-7 801B4A54-7 801B4598-7 001FEA00-7 001FEC10-7 001FEC10-7 800D49A8-7 800D0A04-7 00690360-7
|
||||
6x32 8C19B1C0-- 8C021480-- 8C0248B8-- 8C024CB4-- 8C024CC0-- 8C027998-7 004CC460-7 00579160-7 8020A698-7 801B0B38-7 801B3F00-7 801B42EC-7 801B4940-7 801B4484-7 001FEB20-7 001FED30-7 001FED30-7 800D485C-7 800D08B8-7 006903A0-7
|
||||
@@ -228,7 +228,7 @@ cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE
|
||||
6x3D 8C19A134-- 8C1A4138-- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
|
||||
6x3E 8C19AB7C-- 8C1A46E8-- 8C1BE79C-- 8C1C11F8-- 8C1C17F8-- 8C1E978C-7 004D22D0-7 00581720-7 80224318-7 801CD4D0-7 801D00E0-7 801D0524-7 801D0BE0-7 801D0724-7 00204B70-7 00204DA0-7 00204DA0-7 800EC9D0-7 800E8C34-7 00698B74-7
|
||||
6x3F 8C19B41C-- 8C1A4D3C-- 8C1BE8B8-- 8C1C1314-- 8C1C1914-- 8C1E98E4-7 004D23D0-7 00581820-7 802241CC-7 801CD374-7 801CFFF0-7 801D0434-7 801D0AF0-7 801D0634-7 00204CA0-7 00204ED0-7 00204ED0-7 800EC874-7 800E8AD8-7 00698CD0-7
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB12513J
|
||||
6x40 8C19BB6C-- 8C1A5E10-- 8C1BED80-- 8C1C17DC-- 8C1C1DDC-- 8C1E9E1C-7 004D27A0-7 00581BF0-7 80223B90-7 801CCCD8-7 801CF9BC-7 801CFE00-7 801D04BC-7 801D0000-7 00205200-7 00205430-7 00205430-7 800EC1E4-7 800E8448-7 00698DDC-7
|
||||
6x41 8C19BF64-- 8C1A6230-- 8C1BF470-- 8C1C1ECC-- 8C1C24CC-- 8C1EA368-7 004159E0-7 00415E40-7 80223994-7 801CC814-7 801CF508-7 801CF94C-7 801D0008-7 801CFB4C-7 002C9010-7 002F76A0-7 002F7820-7 800EBD28-7 800E7F8C-7 0061CDB0-7
|
||||
6x42 8C19C404-- 8C1A552C-- 8C1BFA50-- 8C1C24AC-- 8C1C2AAC-- 8C1EA67C-7 004D2CB0-7 00582140-7 80223470-7 801CC3F4-7 801CF13C-7 801CF580-7 801CFC3C-7 801CF780-7 00205890-7 00205AC0-7 00205AC0-7 800EB920-7 800E7B84-7 00698E84-7
|
||||
@@ -245,7 +245,7 @@ cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE
|
||||
6x4D 8C05DCCC-- 8C1A94D4-- 8C1C422C-- 8C1C6CB4-- 8C1C72B4-- 8C1EF454-6 004D6520-6 005859C0-6 8021E4A0-6 801C618C-6 801CA108-6 801CA524-6 801CABE0-6 801CA724-6 0020A0A0-6 0020A2D0-6 0020A2A0-6 800E5DE8-6 800E1B84-6 0069ABBC-6
|
||||
6x4E 8C155400-- 8C024170-- 8C1C4608-- 8C1C7090-- 8C1C7690-- 8C1EF8B4-6 004D6840-6 00585CE0-6 8021E14C-6 801C5B98-6 801C9BA8-6 801C9FC4-6 801CA680-6 801CA1C4-6 0020A620-6 0020A850-6 0020A820-6 800E590C-6 800E16A8-6 0069AD04-6
|
||||
6x4F 8C05DE64-- 8C1A97C8-- 8C1C4CC4-- 8C1C774C-- 8C1C7D4C-- 8C1EFF6C-6 004D6EE0-6 00586390-6 8021DA60-6 801C5570-6 801C9670-6 801C9A8C-6 801CA148-6 801C9C8C-6 0020AB20-6 0020AD50-6 0020AD20-6 800E52FC-6 800E1098-6 0069AEA8-6
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB12513J
|
||||
6x50 8C05DF60-- 8C1A9C10-- 8C1C3340-- 8C1C5DC8-- 8C1C63C8-- 8C1EE52C-6 004D5A80-6 00584F10-6 8021F3A4-6 801C7538-6 801CB08C-6 801CB4A8-6 801CBB64-6 801CB6A8-6 00209250-6 002094A0-6 00209480-6 800E7110-6 800E2EAC-6 0069AEF4-6
|
||||
6x51 8C155060-- 8C1A9FD0-- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
|
||||
6x52 8C1550F4-- 8C05EEE8-- 8C1C509C-- 8C1C7B24-- 8C1C8124-- 8C1F02CC-7 004D70E0-7 00586590-7 8021D6FC-7 801C505C-7 801C924C-7 801C9668-7 801C9CF4-7 801C9838-7 0020AE60-7 0020B090-7 0020B060-7 800E4DC8-7 800E0B64-7 0069AF68-7
|
||||
@@ -262,7 +262,7 @@ cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE
|
||||
6x5D 8C018124-- 8C0241EC-- 8C065A38-- 8C066528-- 8C0667AC-- 8C073F88-6 0046DE70-6 004DC160-6 80158BCC-6 800FE108-6 80101DCC-6 80102070-6 80102128-6 80101F38-6 001728C0-6 001729F0-6 00172A00-6 8005DD7C-6 8005D7B0-6 005C4D58-6
|
||||
6x5E 8C0181AC-- 8C0241F0-- 8C065B24-- 8C066614-- 8C066898-- 8C0740BC-6 0046DF90-6 004DC280-6 80158A28-6 800FDED4-6 80101CC0-6 80101F64-6 8010201C-6 80101E2C-6 00172A10-6 00172B40-6 00172B50-6 8005DB48-6 8005D57C-6 005C4EDC-6
|
||||
6x5F 8C018250-- 8C151304-- 8C16FA6C-- 8C171CB4-- 8C172244-- 8C1953B0-6 0047CCF0-6 004EDDE0-6 80172208-6 80116A74-6 8011AC30-6 8011AED4-6 8011AFCC-6 8011ADF4-6 001882F0-6 001884A0-6 001884E0-6 80076638-6 80075FB8-6 005E3BD0-6
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB12513J
|
||||
6x60 8C018438-- 8C09904C-- 8C16FB04-- 8C171D4C-- 8C1722DC-- 8C19547C-6 0047CDC0-6 004EDEB0-6 80172104-6 8011699C-6 8011AB58-6 8011ADFC-6 8011AEF4-6 8011AD1C-6 001883A0-6 00188550-6 00188590-6 80076560-6 80075EE0-6 ----------
|
||||
6x61 8C0179EC-- 8C0EB354-- 8C066E94-- 8C067984-- 8C067C08-- 8C074D88-6 0046E780-6 004DCA60-6 80158034-6 800FD3E4-6 801011D8-6 8010147C-6 80101540-6 80101350-6 00173140-6 00173270-6 00173280-6 8005D07C-6 8005CAB0-6 005C51D0-6
|
||||
6x62 8C1B5474-- 8C1A313C-- 8C16F9D0-- 8C171C18-- 8C1721A8-- 8C195314-6 004159E0-6 00415E40-6 8017249C-6 80116BD4-6 8011AD90-6 8011B034-6 8011B12C-6 8011AF54-6 002C9010-6 002F76A0-6 002F7820-6 80076798-6 80076118-6 0061CDB0-6
|
||||
@@ -279,7 +279,7 @@ cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE
|
||||
6x6D ---------- ---------- 8C019DC4-- 8C01A00C-- 8C01A004-- 8C01AFA8-7 0048B300-7 0050AD30-7 8018C7F0-7 80131468-7 80135430-7 801356D4-7 801359CC-7 8013574C-7 002C02A0-7 002C1EE0-7 002C20D0-7 80093BA4-7 80093200-7 0079FCB4-7
|
||||
6x6E ---------- ---------- 8C019E78-- 8C01A0CC-- 8C01A0C4-- 8C01B070-7 0048B3A0-7 0050ADD0-7 8018C6F8-7 80131344-7 80135350-7 801355F4-7 801358EC-7 8013566C-7 002C0320-7 002C1F60-7 002C2150-7 80093A80-7 800930DC-7 0079FD30-7
|
||||
6x6F ---------- ---------- 8C019F60-- 8C01A1C0-- 8C01A1B8-- 8C01B16C-7 0048B480-7 0050AEB0-7 8018C6A8-7 801312F4-7 80135300-7 801355A4-7 8013589C-7 8013561C-7 002C03E0-7 002C2020-7 002C2210-7 80093A30-7 8009308C-7 0079FEB4-7
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB12513J
|
||||
6x70 ---------- ---------- 8C01A014-- 8C01A280-- 8C01A278-- 8C01B230-7 0048B4C0-7 0050AEE0-7 8018C2B4-7 80130DE0-7 80135190-7 80135434-7 8013572C-7 801354AC-7 002C04B0-7 002C20F0-7 002C22E0-7 80093358-7 800929B4-7 0079FDDC-7
|
||||
6x71 ---------- ---------- 8C01A0EC-- 8C01A364-- 8C01A35C-- 8C01B318-7 0048B5F0-7 0050B020-7 8018C0B0-7 80130BFC-7 80134FAC-7 80135250-7 80135540-7 801352C0-7 002C05B0-7 002C21F0-7 002C23E0-7 80092EE8-7 80092544-7 0079FF1C-7
|
||||
6x72 ---------- ---------- 8C019380-- 8C0195A4-- 8C01959C-- 8C01A4DC-7 0048AAE0-7 0050A510-7 8018D528-7 80132368-7 80135FF0-7 80136294-7 8013658C-7 8013630C-7 002BF690-7 002C12C0-7 002C14B0-7 800947A8-7 80093E04-7 0079D1CC-7
|
||||
@@ -296,7 +296,7 @@ cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE
|
||||
6x7D ---------- ---------- ---------- ---------- ---------- 8C24F0D0-7 ---------- 0057F1B0-7 802180EC-7 801BE850-7 801C315C-7 801C357C-7 801C3C08-7 801C374C-7 00214B20-7 00214DF0-7 00214E50-7 ---------- ---------- 006AF9B4-7
|
||||
6x7E ---------- ---------- ---------- ---------- ---------- 8C24F1DC-7 ---------- 00415E40-7 802180E8-7 801BE84C-7 801C3158-7 801C3578-7 801C3C04-7 801C3748-7 002C9010-7 002F76A0-7 002F7820-7 ---------- ---------- 0061CDB0-7
|
||||
6x7F ---------- ---------- ---------- ---------- ---------- 8C24F1E0-7 ---------- 0057F2C0-7 8021809C-7 801BE804-7 801C3110-7 801C3530-7 801C3BBC-7 801C3700-7 00214C20-7 00214EF0-7 00214F50-7 ---------- ---------- 006AFA9C-7
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB12513J
|
||||
6x80 ---------- ---------- ---------- ---------- ---------- 8C0FEF14-4 0049E850-4 005329E0-4 801C6E70-4 8016A5A8-4 8016EF3C-4 8016F2F8-4 8016F8DC-4 8016F418-4 001BB740-4 001BB9C0-4 001BB9D0-4 ---------- ---------- 0062F2D4-4
|
||||
6x81 ---------- ---------- ---------- ---------- ---------- 8C02BA5C-7 004CF9F0-7 0057CC50-7 80205F84-7 801AC468-7 801B0314-7 801B06F0-7 801B0D44-7 801B0888-7 002018F0-7 00201AF0-7 00201AF0-7 800D0434-7 800CC490-7 00691A58-7
|
||||
6x82 ---------- ---------- ---------- ---------- ---------- 8C02BB28-7 004CFA80-7 0057CCE0-7 80205E78-7 801AC310-7 801B0204-7 801B05E0-7 801B0C34-7 801B0778-7 002019C0-7 00201BC0-7 00201BC0-7 800D02EC-7 800CC348-7 00691ADC-7
|
||||
@@ -313,7 +313,7 @@ cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE
|
||||
6x8D ---------- ---------- ---------- ---------- ---------- 8C1EC8FC-6 004D43F0-6 00583880-6 802212B4-6 801C9D98-6 801CD0A0-6 801CD4BC-6 801CDB78-6 801CD6BC-6 00207780-6 002079B0-6 002079B0-6 800E92F0-6 800E5554-6 0069A030-6
|
||||
6x8E ---------- ---------- ---------- ---------- ---------- 8C02BF50-7 004159E0-7 00415E40-7 80205A8C-7 801ABDE8-7 801AFD88-7 801B0164-7 801B07B8-7 801B02FC-7 002C9010-7 002F76A0-7 002F7820-7 ---------- ---------- 0061CDB0-7
|
||||
6x8F ---------- ---------- ---------- ---------- ---------- 8C02BFD8-7 004CFE20-7 0057D080-7 8020596C-7 801ABBF0-7 801AFC38-7 801B0014-7 801B0668-7 801B01AC-7 00201DE0-7 00201FE0-7 00201FE0-7 ---------- ---------- 006918FC-7
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB12513J
|
||||
6x90 ---------- ---------- ---------- ---------- ---------- 8C02BBBC-7 004CFAE0-7 0057CD30-7 80205DEC-7 801AC1B8-7 801B011C-7 801B04F8-7 801B0B4C-7 801B0690-7 00201A30-7 00201C30-7 00201C30-7 ---------- ---------- 006919B0-7
|
||||
6x91 ---------- ---------- ---------- ---------- ---------- 8C2630F4-6 00499430-6 0051E940-6 801AE4F8-6 80152634-6 80156F78-6 80157334-6 80157918-6 80157454-6 001A4460-6 001A4690-6 001A4780-6 ---------- ---------- 00612BFC-6
|
||||
6x92 ---------- ---------- ---------- ---------- ---------- 8C2625B4-4 ---------- 00449E70-4 803385F8-4 802DCD2C-4 802E3598-4 802E3F40-4 802E4D08-4 802E5930-4 001EDE70-4 001EE080-4 001EE080-4 ---------- ---------- 0067B85C-4
|
||||
@@ -330,7 +330,7 @@ cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE
|
||||
6x9D ---------- ---------- ---------- ---------- ---------- 8C253F38-6 0042FE10-6 0045F530-6 800C4000-6 8006FB14-6 80071EDC-6 800721FC-6 8007226C-6 80072230-6 000C01F0-6 000C0350-6 000C03A0-6 ---------- ---------- 004DBC1C-6
|
||||
6x9E ---------- ---------- ---------- ---------- ---------- ---------- 00443240-7 004737E0-7 80236ECC-7 801DDFB0-7 801E3A3C-7 801E3EA0-7 801E459C-7 801E3F60-7 002C9010-7 002F76A0-7 002F7820-7 ---------- ---------- 0061CDB0-7
|
||||
6x9F ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 800B6830-4 80062720-4 80064970-4 80064C88-4 80064CC8-4 80064C50-4 000790D0-4 000791B0-4 000790F0-4 ---------- ---------- 004A6FE8-4
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB12513J
|
||||
6xA0 ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 800B670C-4 80062674-4 800648E4-4 80064BFC-4 80064C3C-4 80064BC4-4 00079160-4 00079240-4 00079180-4 ---------- ---------- 004A7034-4
|
||||
6xA1 ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 8020A524-7 801B0A04-7 801B3E14-7 801B4200-7 801B4854-7 801B4398-7 001FEBE0-7 001FEDF0-7 001FEDF0-7 800D4738-7 800D0794-7 0069042C-7
|
||||
6xA2 ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 80172018-6 801168FC-6 8011AAB8-6 8011AD5C-6 8011AE54-6 8011AC7C-6 00188420-6 001885D0-6 00188610-6 800764C0-6 80075E40-6 ----------
|
||||
@@ -347,7 +347,7 @@ cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE
|
||||
6xAD ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 8034C970-4 80354604-4 803554FC-4 803564D8-4 803570E4-4 0008B5F0-4 0008B6D0-4 0008B610-4 ---------- ---------- 0048CB10-4
|
||||
6xAE ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 801B8790-7 801BA1F0-7 801BA5DC-7 801BAC48-7 801BA78C-7 001F9550-7 001F9760-7 001F9760-7 800DB5A0-7 800D750C-7 0068D690-7
|
||||
6xAF ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 801C2348-7 801C6ED0-7 801C72EC-7 801C7978-7 801C74BC-7 0020C8F0-7 0020CB20-7 0020CB20-7 800E213C-7 800DDED8-7 0069B418-7
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB12513J
|
||||
6xB0 ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 801C2204-7 801C6E44-7 801C7260-7 801C78EC-7 801C7430-7 0020C970-7 0020CBA0-7 0020CBA0-7 800E1FF8-7 800DDD94-7 0069B478-7
|
||||
6xB1 ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 801C37FC-7 801C7E2C-7 801C8248-7 801C88D4-7 801C8418-7 002C9010-7 002F76A0-7 002F7820-7 800E35B0-7 800DF34C-7 0061CDB0-7
|
||||
6xB2 ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 80220558-7 80226200-7 80226ABC-7 80227408-7 80227B70-7 002C9010-7 002F76A0-7 002F7820-7 80140BA8-7 80131480-7 0061CDB0-7
|
||||
@@ -364,7 +364,7 @@ cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE
|
||||
6xBD ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 801C9B00-7 ----------
|
||||
6xBE ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 8030B4E4-7 0068F74C-6
|
||||
6xBF ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 8030D01C-1 006928C0-6
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB12513J
|
||||
6xC0 ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 0068F2CC-6
|
||||
6xC1 ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 0078BC44-7
|
||||
6xC2 ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 0078BE84-7
|
||||
@@ -372,13 +372,13 @@ cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE
|
||||
6xCC ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 0068EE0C-6
|
||||
6xCD ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 0078C0D8-1
|
||||
6xCE ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 0078BFF4-1
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB12513J
|
||||
6xD2 ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 00800924-6
|
||||
6xD4 ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 006746BC-4
|
||||
6xDB ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 0068EEEC-6
|
||||
6xDC ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 0076B034-4
|
||||
6xDD ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 00787998-3
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1 DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB
|
||||
cmd DC-NTE DC112000 DC122000 DC012001 DCv1USA DC082001 PC-NTE PC GC1&2NTE GC-GJAM GC12JP12 GC12US11 GC12EU GC12US12 XBOXBETA XBOX-US0 XBOX-US1 GCEp3NTE GCEp3US BB12513J
|
||||
6xE3 ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 00800950-6
|
||||
|
||||
Episode 3 CA send wrapper functions
|
||||
@@ -489,7 +489,7 @@ SUBCMD GCEp3NTE GCEp3USA
|
||||
6xB5x47 80234FBC 8022A314
|
||||
|
||||
Quest opcode handlers (format: GET_ARGS EXEC_FUN)
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
00 8C13C19C-() 8C13C830 8C13F83C-??? 8C13FF80 8C151764-() 8C151EA8 8C16C6F0-() 8C16CE34 004E12C0-() 004E1A50 00590DD0-() 00595030 80242F44-() 80242304 801F2A10-() 801F2520 80109CA8-() 801097B8 00218DF0-??? 002C9010 002190C0-??? 002F76A0 006B101C-() 0061CDB0
|
||||
01 8C13C19C-() 8C13C834 8C13F83C-??? 8C13FF84 8C151764-() 8C151EAC 8C16C6F0-() 8C16CE38 004E12C0-() 004E1A60 00590DD0-() 00591560 80242F44-() 802422C0 801F2A10-() 801F24D0 80109CA8-() 80109768 00218DF0-??? 00219170 002190C0-??? 00219440 006B101C-() 006B16A0
|
||||
02 8C13C19C-() 8C13C870 8C13F83C-??? 8C13FFC0 8C151764-() 8C151EE8 8C16C6F0-() 8C16CE74 004E12C0-() 004E1AA0 00590DD0-() 005915A0 80242F44-() 802422A8 801F2A10-() 801F24B8 80109CA8-() 80109750 00218DF0-??? 002191B0 002190C0-??? 00219480 006B101C-() 006B16E0
|
||||
@@ -504,7 +504,7 @@ Quest opcode handlers (format: GET_ARGS EXEC_FUN)
|
||||
0B ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F27F0-BW 801F2420 80109A88-BW 801096B8 00218F00-??? 00219270 002191D0-??? 00219540 006B1120-BW 006B174C
|
||||
0C ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2930-BB 801F2408 80109BC8-BB 801096A0 00218E50-??? 00219290 00219120-??? 00219560 006B1058-BB 006B1760
|
||||
0D ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F27F0-BW 801F23EC 80109A88-BW 80109684 00218F00-??? 002192B0 002191D0-??? 00219580 006B1120-BW 006B177C
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
10 8C13C1B0-B 8C13C8D4 8C13F850-??? 8C140024 8C151778-B 8C151F4C 8C16C704-B 8C16CED8 004E12D0-B 004E1B50 00590DE0-B 00591650 80242EF8-B 8024220C 801F2988-B 801F23D8 80109C20-B 80109670 00218E20-??? 002192D0 002190F0-??? 002195A0 006B1040-B 006B179C
|
||||
11 8C13C1B0-B 8C13C8E8 8C13F850-??? 8C140038 8C151778-B 8C151F60 8C16C704-B 8C16CEEC 004E12D0-B 004E1B70 00590DE0-B 00591670 80242EF8-B 802421F8 801F2988-B 801F23C4 80109C20-B 8010965C 00218E20-??? 002192F0 002190F0-??? 002195C0 006B1040-B 006B17B0
|
||||
12 8C13C1B0-B 8C13C8FC 8C13F850-??? 8C14004C 8C151778-B 8C151F74 8C16C704-B 8C16CF00 004E12D0-B 004E1B90 00590DE0-B 00591690 80242EF8-B 802421DC 801F2988-B 801F23A8 80109C20-B 80109640 00218E20-??? 00219310 002190F0-??? 002195E0 006B1040-B 006B17C4
|
||||
@@ -521,7 +521,7 @@ Quest opcode handlers (format: GET_ARGS EXEC_FUN)
|
||||
1D 8C13C21C-BL 8C13CA5C 8C13F8BC-??? 8C1401AC 8C1517E4-BL 8C1520D4 8C16C770-BL 8C16D060 004E1350-BL 004E1D80 00590E60-BL 00591880 80242E1C-BL 80242000 801F28D8-BL 801F21CC 80109B70-BL 80109464 00218E90-??? 002194B0 00219160-??? 00219780 006B107C-BL 006B1908
|
||||
1E 8C13C1DC-BB 8C13CA74 8C13F87C-??? 8C1401C4 8C1517A4-BB 8C1520EC 8C16C730-BB 8C16D078 004E1300-BB 004E1DA0 00590E10-BB 005918A0 80242EA0-BB 80241FE0 801F2930-BB 801F21AC 80109BC8-BB 80109444 00218E50-??? 002194D0 00219120-??? 002197A0 006B1058-BB 006B1920
|
||||
1F 8C13C21C-BL 8C13CAA0 8C13F8BC-??? 8C1401F0 8C1517E4-BL 8C152118 8C16C770-BL 8C16D0A4 004E1350-BL 004E1DD0 00590E60-BL 005918D0 80242E1C-BL 80241FC8 801F28D8-BL 801F2194 80109B70-BL 8010942C 00218E90-??? 002194F0 00219160-??? 002197C0 006B107C-BL 006B1944
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
20 8C13C1DC-BB 8C13CAC4 8C13F87C-??? 8C140214 8C1517A4-BB 8C15213C 8C16C730-BB 8C16D0C8 004E1300-BB 004E1DF0 00590E10-BB 005918F0 80242EA0-BB 80241FA8 801F2930-BB 801F2174 80109BC8-BB 8010940C 00218E50-??? 00219510 00219120-??? 002197E0 006B1058-BB 006B1964
|
||||
21 8C13C21C-BL 8C13CAE4 8C13F8BC-??? 8C140234 8C1517E4-BL 8C15215C 8C16C770-BL 8C16D0E8 004E1350-BL 004E1E20 00590E60-BL 00591920 80242E1C-BL 80241F90 801F28D8-BL 801F215C 80109B70-BL 801093F4 00218E90-??? 00219530 00219160-??? 00219800 006B107C-BL 006B197C
|
||||
22 8C13C1DC-BB 8C13CAFC 8C13F87C-??? 8C14024C 8C1517A4-BB 8C152174 8C16C730-BB 8C16D100 004E1300-BB 004E1E40 00590E10-BB 00591940 80242EA0-BB 80241F70 801F2930-BB 801F213C 80109BC8-BB 801093D4 00218E50-??? 00219550 00219120-??? 00219820 006B1058-BB 006B1990
|
||||
@@ -538,7 +538,7 @@ Quest opcode handlers (format: GET_ARGS EXEC_FUN)
|
||||
2D 8C13C48C-BLW 8C13CC5C 8C13FBDC-??? 8C1403C8 8C151B04-BLW 8C152340 8C16CA90-BLW 8C16D2CC 004E15F0-BLW 004E2090 00591100-BLW 00591B90 802428C8-BLW 80241D94 801F2728-BLW 801F1F68 801099C0-BLW 80109200 00218F90-??? 00219730 00219260-??? 00219A00 006B1174-BLW 006B1B50
|
||||
2E 8C13C420-BBW 8C13CC88 8C13FB70-??? 8C1403F4 8C151A98-BBW 8C15236C 8C16CA24-BBW 8C16D2F8 004E15A0-BBW 004E20D0 005910B0-BBW 00591BD0 80242980-BBW 80241D64 801F278C-BBW 801F1F38 80109A24-BBW 801091D0 00218F40-??? 00219760 00219210-??? 00219A30 006B1144-BBW 006B1B78
|
||||
2F 8C13C48C-BLW 8C13CCBC 8C13FBDC-??? 8C140428 8C151B04-BLW 8C1523A0 8C16CA90-BLW 8C16D32C 004E15F0-BLW 004E2110 00591100-BLW 00591C10 802428C8-BLW 80241D3C 801F2728-BLW 801F1F10 801099C0-BLW 801091A8 00218F90-??? 00219790 00219260-??? 00219A60 006B1174-BLW 006B1BA4
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
30 8C13C420-BBW 8C13CCE8 8C13FB70-??? 8C140454 8C151A98-BBW 8C1523CC 8C16CA24-BBW 8C16D358 004E15A0-BBW 004E2150 005910B0-BBW 00591C50 80242980-BBW 80241D0C 801F278C-BBW 801F1EE0 80109A24-BBW 80109178 00218F40-??? 002197C0 00219210-??? 00219A90 006B1144-BBW 006B1BCC
|
||||
31 8C13C48C-BLW 8C13CD1C 8C13FBDC-??? 8C140488 8C151B04-BLW 8C152400 8C16CA90-BLW 8C16D38C 004E15F0-BLW 004E2190 00591100-BLW 00591C90 802428C8-BLW 80241CE4 801F2728-BLW 801F1EB8 801099C0-BLW 80109150 00218F90-??? 002197F0 00219260-??? 00219AC0 006B1174-BLW 006B1BF8
|
||||
32 8C13C420-BBW 8C13CD48 8C13FB70-??? 8C1404B4 8C151A98-BBW 8C15242C 8C16CA24-BBW 8C16D3B8 004E15A0-BBW 004E21D0 005910B0-BBW 00591CD0 80242980-BBW 80241CB4 801F278C-BBW 801F1E88 80109A24-BBW 80109120 00218F40-??? 00219820 00219210-??? 00219AF0 006B1144-BBW 006B1C20
|
||||
@@ -555,7 +555,7 @@ Quest opcode handlers (format: GET_ARGS EXEC_FUN)
|
||||
3D 8C13C48C-BLW 8C13CF5C 8C13FBDC-??? 8C1406C8 8C151B04-BLW 8C152640 8C16CA90-BLW 8C16D5CC 004E15F0-BLW 004E2490 00591100-BLW 00591F90 802428C8-BLW 80241AD4 801F2728-BLW 801F1CA8 801099C0-BLW 80108F40 00218F90-??? 00219A30 00219260-??? 00219D00 006B1174-BLW 006B1DF0
|
||||
3E 8C13C420-BBW 8C13CF88 8C13FB70-??? 8C1406F4 8C151A98-BBW 8C15266C 8C16CA24-BBW 8C16D5F8 004E15A0-BBW 004E24D0 005910B0-BBW 00591FD0 80242980-BBW 80241AA4 801F278C-BBW 801F1C78 80109A24-BBW 80108F10 00218F40-??? 00219A60 00219210-??? 00219D30 006B1144-BBW 006B1E18
|
||||
3F 8C13C48C-BLW 8C13CFBC 8C13FBDC-??? 8C140728 8C151B04-BLW 8C1526A0 8C16CA90-BLW 8C16D62C 004E15F0-BLW 004E2510 00591100-BLW 00592010 802428C8-BLW 80241A7C 801F2728-BLW 801F1C50 801099C0-BLW 80108EE8 00218F90-??? 00219A90 00219260-??? 00219D60 006B1174-BLW 006B1E44
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
40 8C13C588-BW* 8C13CFE8 8C13FCD8-??? 8C140754 8C151C00-BW* 8C1526CC 8C16CB8C-BW* 8C16D658 004E16C0-BW* 004E2550 005911D0-BW* 00592050 80242748-BW* 80241A40 801F261C-BW* 801F1C08 801098B4-BW* 80108EA0 00219040-??? 00219AC0 00219310-??? 00219D90 006B1274-BW* 006B1E6C
|
||||
41 8C13C588-BW* 8C13D020 8C13FCD8-??? 8C14078C 8C151C00-BW* 8C152704 8C16CB8C-BW* 8C16D690 004E16C0-BW* 004E2590 005911D0-BW* 00592090 80242748-BW* 802419E4 801F261C-BW* 801F1BC0 801098B4-BW* 80108E58 00219040-??? 00219B00 00219310-??? 00219DD0 006B1274-BW* 006B1EB0
|
||||
42 8C13C274-L 8C13D074 8C13F914-??? 8C1407E0 8C15183C-L 8C152758 8C16C7C8-L 8C16D6E4 004E1390-L 004E1A50 00590EA0-L 00595030 80242DA8-L 802419E0 801F2988-B 801F1B94 80109C20-B 80108E2C 00218E20-??? 00219B50 002190F0-??? 00219E20 006B1040-B 006B1F1C
|
||||
@@ -569,7 +569,7 @@ Quest opcode handlers (format: GET_ARGS EXEC_FUN)
|
||||
4C ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2988-B 801E6F04 80109C20-B 800FF4D0 00218E20-??? 002223D0 002190F0-??? 002226C0 006B1040-B 006B8B48
|
||||
4D ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2848-W 801E6ED8 80109AE0-W 800FF4A4 00219100-??? 00222400 002193D0-??? 002226F0 006B10E0-W 006B8B70
|
||||
4E ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F25C4-S 801E6EB8 8010985C-S 800FF484 002190B0-??? 00222430 00219380-??? 00222660 006B12E4-S 006B8AF4
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
50 8C13C684-LS 8C13D078 8C13FDD4-??? 8C1407E4 8C151CFC-LS 8C15275C 8C16CC88-LS 8C16D6E8 004E1810-LS 004E25F0 00591320-LS 005920F0 80242514-LS 802418E0 801F29D0-... 801F19C0 80109C68-... 80108C58 00218E00-??? 00219C40 002190D0-??? 00219F10 006B1028-... 006B23F8
|
||||
51 8C13C714-BS 8C13D11C 8C13FE64-??? 8C140888 8C151D8C-BS 8C152868 8C16CD18-BS 8C16D7F4 004E18F0-BS 004E26B0 00591400-BS 005921B0 80242404-BS 80241798 801F29D0-... 801F1888 80109C68-... 80108B20 00218E00-??? 00219D30 002190D0-??? 0021A000 006B1028-... 006B206C
|
||||
52 8C13C19C-() 8C13D258 8C13F83C-??? 8C1409C4 8C151764-() 8C1529B8 8C16C6F0-() 8C16D948 004E12C0-() 004E27E0 00590DD0-() 005922E0 80242F44-() 8024176C 801F2A10-() 801F185C 80109CA8-() 80108AF4 00218DF0-??? 00219FB0 002190C0-??? 0021A280 006B101C-() 006B2250
|
||||
@@ -585,7 +585,7 @@ Quest opcode handlers (format: GET_ARGS EXEC_FUN)
|
||||
5C 8C13C19C-() 8C13D328 8C13F83C-??? 8C140ADC 8C151764-() 8C152BF8 8C16C6F0-() 8C16DB88 004E12C0-() 004E29D0 00590DD0-() 005924D0 80242F44-() 80241460 801F2A10-() 801F1550 80109CA8-() 801087E8 00218DF0-??? 0021A260 002190C0-??? 0021A530 006B101C-() 006B24F0
|
||||
5D 8C13C1B0-B 8C13DCA0 8C13F850-??? 8C1416D8 8C151778-B 8C153AB0 8C16C704-B 8C16EA50 004E12D0-B 004E35F0 00590DE0-B 00593100 80242EF8-B 8023FE3C 801F2988-B 801EFD64 80109C20-B 80106ED8 00218E20-??? 0021B260 002190F0-??? 0021B530 006B1040-B 006B3390
|
||||
5E 8C13C19C-() 8C13D3BC 8C13F83C-??? 8C140B70 8C151764-() 8C152CD8 8C16C6F0-() 8C16DC68 004E12C0-() 004E2A70 00590DD0-() 00592570 80242F44-() 80241404 801F2A10-() 801F1508 80109CA8-() 801087A0 00218DF0-??? 0021A310 002190C0-??? 0021A5E0 006B101C-() 006B25B0
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
60 8C13C2BC-LL 8C13D3E0 8C13F95C-??? 8C140BB0 8C151884-LL 8C152D64 8C16C810-LL 8C16DCF4 004E13C0-LL 004E2AC0 00590ED0-LL 005925C0 80242D00-LL 802413B0 801F29D0-... 801F14D0 80109C68-... 80108768 00218E00-??? 0021A370 002190D0-??? 0021A640 006B1028-... 006B25F8
|
||||
61 8C13C274-L 8C13D7B0 8C13F914-??? 8C1410F4 8C15183C-L 8C153424 8C16C7C8-L 8C16E3B4 004E1390-L 004E2FB0 00590EA0-L 00592AC0 80242DA8-L 80240A70 801F29D0-... 801F0BFC 80109C68-... 80107E34 00218E00-??? 0021A900 002190D0-??? 0021ABD0 006B1028-... 006B9964
|
||||
62 8C13C274-L 8C13D7BC 8C13F914-??? 8C141100 8C15183C-L 8C153430 8C16C7C8-L 8C16E3C0 004E1390-L 004E2FC0 00590EA0-L 00592AD0 80242DA8-L 80240A4C 801F29D0-... 801F0BD0 80109C68-... 80107E08 00218E00-??? 0021A910 002190D0-??? 0021ABE0 006B1028-... 006B2CEC
|
||||
@@ -600,7 +600,7 @@ Quest opcode handlers (format: GET_ARGS EXEC_FUN)
|
||||
6C 8C13C19C-() 8C13DAC4 8C13F83C-??? 8C1414F4 8C151764-() 8C15386C 8C16C6F0-() 8C16E80C 004E12C0-() 004E33B0 00590DD0-() 00592EC0 80242F44-() 80240218 801F2A10-() 801F0168 80109CA8-() 801072DC 00218DF0-??? 0021AF80 002190C0-??? 0021B250 006B101C-() 006B31B0
|
||||
6D 8C13C2BC-LL 8C13D97C 8C13F95C-??? 8C1413A4 8C151884-LL 8C1536D4 8C16C810-LL 8C16E674 004E13C0-LL 004E3240 00590ED0-LL 00592D50 80242D00-LL 80240434 801F2988-B 801F0398 80109C20-B 8010754C 00218E20-??? 0021ADE0 002190F0-??? 0021B0B0 006B1040-B 006B3030
|
||||
6E 8C13C274-L 8C13D8C8 8C13F914-??? 8C14120C 8C15183C-L 8C15353C 8C16C7C8-L 8C16E4CC 004E1390-L 004E30E0 00590EA0-L 00592BF0 80242DA8-L 802407FC 801F29D0-... 801F0958 80109C68-... 80107B90 00218E00-??? 0021AB10 002190D0-??? 0021ADE0 006B1028-... 006B2DA8
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
70 8C13C19C-() 8C13DBC4 8C13F83C-??? 8C1415FC 8C151764-() 8C153984 8C16C6F0-() 8C16E924 004E12C0-() 004E34B0 00590DD0-() 00592FC0 80242F44-() 8024000C 801F2A10-() 801EFF34 80109CA8-() 801070A8 00218DF0-??? 0021B0C0 002190C0-??? 0021B390 006B101C-() 006B993C
|
||||
71 8C13C19C-() 8C13DBD0 8C13F83C-??? 8C141608 8C151764-() 8C1539B8 8C16C6F0-() 8C16E958 004E12C0-() 004E34D0 00590DD0-() 00592FE0 80242F44-() 8023FFCC 801F2A10-() 801EFEF4 80109CA8-() 80107068 00218DF0-??? 0021B120 002190C0-??? 0021B3F0 006B101C-() 006B32A4
|
||||
72 8C13C274-L 8C13D898 8C13F914-??? 8C1411DC 8C15183C-L 8C15350C 8C16C7C8-L 8C16E49C 004E1390-L 004E30A0 00590EA0-L 00592BB0 80242DA8-L 80240884 801F29D0-... 801F09F0 80109C68-... 80107C28 00218E00-??? 0021AA70 002190D0-??? 0021AD40 006B1028-... 006B2D78
|
||||
@@ -617,7 +617,7 @@ Quest opcode handlers (format: GET_ARGS EXEC_FUN)
|
||||
7D 8C13C2BC-LL 8C13D4F4 8C13F95C-??? 8C140CD8 8C151884-LL 8C153008 8C16C810-LL 8C16DF98 004E13C0-LL 004E2CC0 00590ED0-LL 005927C0 80242D00-LL 80240E8C 801F2988-B 801F0FE0 80109C20-B 80108248 00218E20-??? 0021A5C0 002190F0-??? 0021A890 006B1040-B 006B2868
|
||||
7E 8C13C2BC-LL 8C13D970 8C13F95C-??? 8C141398 8C151884-LL 8C1536C8 8C16C810-LL 8C16E668 004E13C0-LL 004E3230 00590ED0-LL 00592D40 80242D00-LL 80240510 801F29D0-... 801F047C 80109C68-... 80107630 00218E00-??? 0021ADC0 002190D0-??? 0021B090 006B1028-... 006B3014
|
||||
7F 8C13C2BC-LL 8C13D6F4 8C13F95C-??? 8C141038 8C151884-LL 8C153368 8C16C810-LL 8C16E2F8 004E13C0-LL 004E2F30 00590ED0-LL 00592A40 80242D00-LL 80240A94 801F2988-B 801F0C28 80109C20-B 80107E60 00218E20-??? 0021A880 002190F0-??? 0021AB50 006B1040-B 006B2C38
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
80 8C13C19C-() 8C13D7C8 8C13F83C-??? 8C14110C 8C151764-() 8C15343C 8C16C6F0-() 8C16E3CC 004E12C0-() 004E2FD0 00590DD0-() 00592AE0 80242F44-() 80240A28 801F2A10-() 801F0BAC 80109CA8-() 80107DE4 00218DF0-??? 0021A920 002190C0-??? 0021ABF0 006B101C-() 006B2CFC
|
||||
81 8C13C19C-() 8C13D868 8C13F83C-??? 8C1411AC 8C151764-() 8C1534DC 8C16C6F0-() 8C16E46C 004E12C0-() 004E3060 00590DD0-() 00592B70 80242F44-() 8024090C 801F2A10-() 801F0A88 80109CA8-() 80107CC0 00218DF0-??? 0021A9F0 002190C0-??? 0021ACC0 006B101C-() 006B2D50
|
||||
82 8C13C19C-() 8C13D7D4 8C13F83C-??? 8C141118 8C151764-() 8C153448 8C16C6F0-() 8C16E3D8 004E12C0-() 004E2FE0 00590DD0-() 00592AF0 80242F44-() 80240A08 801F2A10-() 801F0B8C 80109CA8-() 80107DC4 00218DF0-??? 0021A950 002190C0-??? 0021AC20 006B101C-() 006B2D08
|
||||
@@ -634,7 +634,7 @@ Quest opcode handlers (format: GET_ARGS EXEC_FUN)
|
||||
8D 8C13C1B0-B 8C13DD9C 8C13F850-??? 8C1417D4 8C151778-B 8C153BAC 8C16C704-B 8C16EB4C 004E12D0-B 004E36F0 00590DE0-B 00593210 80242EF8-B 8023FC1C 801F2988-B 801EFB94 80109C20-B 80106D08 00218E20-??? 0021B330 002190F0-??? 0021B600 006B1040-B 006B34BC
|
||||
8E 8C13C1B0-B 8C13DE5C 8C13F850-??? 8C141894 8C151778-B 8C153C6C 8C16C704-B 8C16EC0C 004E12D0-B 004E37B0 00590DE0-B 005932E0 80242EF8-B 8023FB0C 801F2988-B 801EFAAC 80109C20-B 80106C20 00218E20-??? 0021B3C0 002190F0-??? 0021B690 006B1040-B 006B3528
|
||||
8F 8C13C1B0-B 8C13DF1C 8C13F850-??? 8C141954 8C151778-B 8C153D2C 8C16C704-B 8C16ECCC 004E12D0-B 004E3870 00590DE0-B 005933B0 80242EF8-B 8023F9D8 801F2988-B 801EF99C 80109C20-B 80106B10 00218E20-??? 0021B450 002190F0-??? 0021B720 006B1040-B 006B3594
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
90 8C13C274-L 8C13E2F0 8C13F914-??? 8C141E8C 8C15183C-L 8C1542F4 8C16C7C8-L 8C16F280 004E1390-L 004E3DD0 00590EA0-L 00593940 80242DA8-L 8023F288 801F29D0-... 801EF29C 80109C68-... 80106410 00218E00-??? 0021BA50 002190D0-??? 0021BD20 006B1028-... 006B39F0
|
||||
91 8C13C274-L 8C13E2FC 8C13F914-??? 8C141E98 8C15183C-L 8C154300 8C16C7C8-L 8C16F28C 004E1390-L 004E3DE0 00590EA0-L 00593950 80242DA8-L 8023F264 801F29D0-... 801EF270 80109C68-... 801063E4 00218E00-??? 0021BA60 002190D0-??? 0021BD30 006B1028-... 006B3A00
|
||||
92 8C13C274-L 8C13E308 8C13F914-??? 8C141EA4 8C15183C-L 8C15430C 8C16C7C8-L 8C16F298 004E1390-L 004E3DF0 00590EA0-L 00593960 80242DA8-L 8023F244 801F29D0-... 801EF244 80109C68-... 801063B8 00218E00-??? 0021BA70 002190D0-??? 0021BD40 006B1028-... 006B3A10
|
||||
@@ -647,7 +647,7 @@ Quest opcode handlers (format: GET_ARGS EXEC_FUN)
|
||||
99 8C13C19C-() 8C13E0FC 8C13F83C-??? 8C141C80 8C151764-() 8C154070 8C16C6F0-() 8C16F010 004E12C0-() 004E3BD0 00590DD0-() 00593730 80242F44-() 8023F630 801F2A10-() 801EF638 80109CA8-() 801067AC 00218DF0-??? 0021B730 002190C0-??? 0021BA00 006B101C-() 006B3770
|
||||
9A 8C13C19C-() 8C13E130 8C13F83C-??? 8C141CB4 8C151764-() 8C1540B4 8C16C6F0-() 8C16F054 004E12C0-() 004E3C00 00590DD0-() 00593760 80242F44-() 8023F60C 801F2A10-() 801EF614 80109CA8-() 80106788 00218DF0-??? 0021B780 002190C0-??? 0021BA50 006B101C-() 006B3784
|
||||
9B 8C13C19C-() 8C13E13C 8C13F83C-??? 8C141CC0 8C151764-() 8C1540C0 8C16C6F0-() 8C16F060 004E12C0-() 004E3C10 00590DD0-() 00593770 80242F44-() 8023F5E8 801F2A10-() 801EF5F0 80109CA8-() 80106764 00218DF0-??? 0021B7B0 002190C0-??? 0021BA80 006B101C-() 006B3790
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
A0 8C13C684-LS 8C13E148 8C13FDD4-??? 8C141CCC 8C151CFC-LS 8C1540CC 8C16CC88-LS 8C16F06C 004E1810-LS 004E3C20 00591320-LS 00593780 80242514-LS 8023F544 801F29D0-... 801EF540 80109C68-... 801066B4 00218E00-??? 0021B7E0 002190D0-??? 0021BAB0 006B1028-... 006B379C
|
||||
A1 8C13C274-L 8C13E338 8C13F914-??? 8C141ED4 8C15183C-L 8C1543E0 8C16C7C8-L 8C16F38C 004E1390-L 004E3EB0 00590EA0-L 00593A40 80242DA8-L 8023F058 801F2848-W 801EEFF0 80109AE0-W 8010615C 00219100-??? 0021BC20 002193D0-??? 0021BEF0 006B10E0-W 006B9930
|
||||
A2 8C13C274-L 8C13E344 8C13F914-??? 8C141EE0 8C15183C-L 8C1543EC 8C16C7C8-L 8C16F398 004E1390-L 004E3EC0 00590EA0-L 00593A50 80242DA8-L 8023F048 801F2848-W 801EEFCC 80109AE0-W 80106138 00219100-??? 0021BC30 002193D0-??? 0021BF00 006B10E0-W 006B3ADC
|
||||
@@ -656,7 +656,7 @@ Quest opcode handlers (format: GET_ARGS EXEC_FUN)
|
||||
A5 8C13C274-L 8C13E350 8C13F914-??? 8C141EEC 8C15183C-L 8C1543F8 8C16C7C8-L 8C16F3A4 004E1390-L 004E3ED0 00590EA0-L 00593A60 80242DA8-L 8023F038 801F2848-W 801EEFA8 80109AE0-W 80106114 00219100-??? 0021BC40 002193D0-??? 0021BF10 006B10E0-W 006B3AE8
|
||||
A6 8C13C19C-() 8C13E36C 8C13F83C-??? 8C141F08 8C151764-() 8C15441C 8C16C6F0-() 8C16F3C8 004E12C0-() 004E3F00 00590DD0-() 00593A90 80242F44-() 8023F000 801F2A10-() 801EEF3C 80109CA8-() 8010607C 00218DF0-??? 0021BC70 002190C0-??? 0021BF40 006B101C-() 006B3B00
|
||||
A8 8C13C2BC-LL 8C13D8D4 8C13F95C-??? 8C141218 8C151884-LL 8C153548 8C16C810-LL 8C16E4D8 004E13C0-LL 004E30F0 00590ED0-LL 00592C00 80242D00-LL 802406B8 801F2988-B 801F0868 80109C20-B 80107AA0 00218E20-??? 0021AB20 002190F0-??? 0021ADF0 006B1040-B 006B2DB8
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
B0 8C13C2BC-LL 8C13E370 8C13F95C-??? 8C141F0C 8C151884-LL 8C154428 8C16C810-LL 8C16F3D4 004E13C0-LL 004E3F10 00590ED0-LL 00593AA0 80242D00-LL 8023EFC4 801F29D0-... 801EEEF4 80109C68-... 80106034 00218E00-??? 0021BC80 002190D0-??? 0021BF50 006B1028-... 006B3B0C
|
||||
B1 8C13C378-W 8C13C888 8C13FAC8-??? 8C13FFD8 8C1519F0-W 8C151F00 8C16C97C-W 8C16CE8C 004E1530-W 004E1AD0 00591040-W 005915D0 80242A98-W 80242260 801F2848-W 801F2470 80109AE0-W 80109708 00219100-??? 00219200 002193D0-??? 002194D0 006B10E0-W 006B16FC
|
||||
B2 8C13C1B0-B 8C13E398 8C13F850-??? 8C141F34 8C151778-B 8C154480 8C16C704-B 8C16F42C 004E12D0-B 004E3F50 00590DE0-B 00593AE0 80242EF8-B 8023EF58 801F2988-B 801EEE84 80109C20-B 80105FC4 00218E20-??? 0021BD20 002190F0-??? 0021BFF0 006B1040-B 006B3BA4
|
||||
@@ -670,7 +670,7 @@ Quest opcode handlers (format: GET_ARGS EXEC_FUN)
|
||||
BA ------------ -------- 8C13F914-??? 8C14268C 8C15183C-L 8C154CA4 8C16C7C8-L 8C16FCC0 004E1390-L 004E4B40 00590EA0-L 005946D0 80242DA8-L 8023E518 801F2848-W 801EE43C 80109AE0-W 80105564 00219100-??? 0021C730 002193D0-??? 0021CA00 006B10E0-W 006B9918
|
||||
BB ------------ -------- 8C13F83C-??? 8C142698 8C151764-() 8C154CB0 8C16C6F0-() 8C16FCCC 004E12C0-() 004E4B50 00590DD0-() 005946E0 80242F44-() 8023E504 801F2A10-() 801EE418 80109CA8-() 80105530 00218DF0-??? 0021C740 002190C0-??? 0021CA10 006B101C-() 006B990C
|
||||
BC ------------ -------- 8C13FD6C-??? 8C1426A4 8C151C94-S 8C154CBC 8C16CC20-S 8C16FCD8 004E1740-S 004E1A50 00591250-S 00595030 80242648-S 8023E500 801F25C4-S 801EE414 8010985C-S 8010552C 002190B0-??? 002C9010 00219380-??? 002F76A0 006B12E4-S 0061CDB0
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
C0 ------------ -------- 8C13F95C-??? 8C1412B4 8C151884-LL 8C1535E4 8C16C810-LL 8C16E584 004E13C0-LL 004E3170 00590ED0-LL 00592C80 80242D00-LL 80240600 801F2988-B 801F0728 80109C20-B 80107960 00218E20-??? 0021AC10 002190F0-??? 0021AEE0 006B1040-B 006B2EA8
|
||||
C1 ------------ -------- 8C13FDD4-??? 8C141D5C 8C151CFC-LS 8C15415C 8C16CC88-LS 8C16F108 004E1810-LS 004E3CA0 00591320-LS 00593810 80242514-LS 8023F524 801F29D0-... 801EF510 80109C68-... 80106684 00218E00-??? 0021B8A0 002190D0-??? 0021BB70 006B1028-... 006B3898
|
||||
C2 ------------ -------- 8C13F83C-??? 8C141C34 8C151764-() 8C15400C 8C16C6F0-() 8C16EFAC 004E12C0-() 004E3B70 00590DD0-() 005936D0 80242F44-() 8023F6C0 801F2A10-() 801EF6C8 80109CA8-() 8010683C 00218DF0-??? 0021B6A0 002190C0-??? 0021B970 006B101C-() 006B3744
|
||||
@@ -687,7 +687,7 @@ Quest opcode handlers (format: GET_ARGS EXEC_FUN)
|
||||
CD ------------ -------- 8C13F95C-??? 8C14131C 8C151884-LL 8C15364C 8C16C810-LL 8C16E5EC 004E13C0-LL 004E31C0 00590ED0-LL 00592CD0 80242D00-LL 80240538 801F2988-B 801F058C 80109C20-B 801077C4 00218E20-??? 0021ACD0 002190F0-??? 0021AFA0 006B1040-B 006B2F38
|
||||
CE ------------ -------- 8C13F95C-??? 8C140E2C 8C151884-LL 8C15315C 8C16C810-LL 8C16E0EC 004E13C0-LL 004E2DB0 00590ED0-LL 005928C0 80242D00-LL 80240CD4 801F2988-B 801F0E48 80109C20-B 80108080 00218E20-??? 0021A6D0 002190F0-??? 0021A9A0 006B1040-B 006B29F4
|
||||
CF ------------ -------- 8C13F83C-??? 8C141D68 8C151764-() 8C1541D0 8C16C6F0-() 8C16F17C 004E12C0-() 004E3CF0 00590DD0-() 00593860 80242F44-() 8023F464 801F2A10-() 801EF4A0 80109CA8-() 80106614 00218DF0-??? 0021B900 002190C0-??? 0021BBD0 006B101C-() 006B3918
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
D0 ------------ -------- ------------ -------- 8C151764-() 8C154024 8C16C6F0-() 8C16EFC4 004E12C0-() 004E3B90 00590DD0-() 005936F0 80242F44-() 8023F680 801F2A10-() 801EF688 80109CA8-() 801067FC 00218DF0-??? 0021B6D0 002190C0-??? 0021B9A0 006B101C-() 006B3754
|
||||
D1 ------------ -------- ------------ -------- 8C1517A4-BB 8C154A38 8C16C730-BB 8C16FA44 004E1300-BB 004E4840 00590E10-BB 005943D0 80242EA0-BB 8023E778 801F2930-BB 801EE6BC 80109BC8-BB 801057FC 00218E50-??? 0021C3F0 00219120-??? 0021C6C0 006B1058-BB 006B41EC
|
||||
D2 ------------ -------- ------------ -------- 8C151764-() 8C154CC0 8C16C6F0-() 8C16FCDC 004E12C0-() 004E4B60 00590DD0-() 005946F0 80242F44-() 8023E4DC 801F2A10-() 801EE3F0 80109CA8-() 80105508 00218DF0-??? 0021C750 002190C0-??? 0021CA20 006B101C-() 006B4448
|
||||
@@ -704,7 +704,7 @@ Quest opcode handlers (format: GET_ARGS EXEC_FUN)
|
||||
DD ------------ -------- ------------ -------- 8C151764-() 8C15419C 8C16C6F0-() 8C16F148 004E12C0-() 004E3CD0 00590DD0-() 00593840 80242F44-() 8023F484 801F2A10-() 801EF4C0 80109CA8-() 80106634 00218DF0-??? 0021B8E0 002190C0-??? 0021BBB0 006B101C-() 006B38E4
|
||||
DE ------------ -------- ------------ -------- 8C151778-B 8C154E70 8C16C704-B 8C16FF24 004E12D0-B 004E4D70 00590DE0-B 00594900 80242EF8-B 8023E06C 801F2988-B 801EDFFC 80109C20-B 80105088 00218E20-??? 0021CA30 002190F0-??? 0021CD00 006B1040-B 006B45C8
|
||||
DF ------------ -------- ------------ -------- 8C151884-LL 8C152D98 8C16C810-LL 8C16DD28 004E13C0-LL 004E2AF0 00590ED0-LL 005925F0 80242D00-LL 802411BC 801F29D0-... 801F12CC 80109C68-... 80108564 00218E00-??? 0021A3A0 002190D0-??? 0021A670 006B1028-... 006B2640
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
E0 ------------ -------- ------------ -------- 8C151764-() 8C154F04 8C16C6F0-() 8C16FFB8 004E12C0-() 004E4E50 00590DD0-() 005949E0 80242F44-() 8023E04C 801F2A10-() 801EDFDC 80109CA8-() 80105084 00218DF0-??? 0021CAD0 002190C0-??? 0021CDA0 006B101C-() 006B4660
|
||||
E1 ------------ -------- ------------ -------- 8C15183C-L 8C154330 8C16C7C8-L 8C16F2D0 004E1390-L 004E3E10 00590EA0-L 005939A0 80242DA8-L 8023F1D4 801F29D0-... 801EF1AC 80109C68-... 80106318 00218E00-??? 0021BB00 002190D0-??? 0021BDD0 006B1028-... 006B3A48
|
||||
E2 ------------ -------- ------------ -------- 8C15183C-L 8C15433C 8C16C7C8-L 8C16F2E8 004E1390-L 004E3E30 00590EA0-L 005939C0 80242DA8-L 8023F0A4 801F2988-B 801EF074 80109C20-B 801061E0 00218E20-??? 0021BB40 002190F0-??? 0021BE10 006B1040-B 006B3A60
|
||||
@@ -721,11 +721,11 @@ Quest opcode handlers (format: GET_ARGS EXEC_FUN)
|
||||
ED ------------ -------- ------------ -------- 8C151764-() 8C154FDC 8C16C6F0-() 8C170094 004E12C0-() 004E4F70 00590DD0-() 00594B00 80242F44-() 8023DEA8 801F2A10-() 801EDE70 80109CA8-() 80104F0C 00218DF0-??? 0021CC40 002190C0-??? 0021CF10 006B101C-() 006B473C
|
||||
EE ------------ -------- ------------ -------- 8C15183C-L 8C154450 8C16C7C8-L 8C16F3FC 004E1390-L 004E3F30 00590EA0-L 00593AC0 80242DA8-L 8023EF84 801F29D0-... 801EEEB0 80109C68-... 80105FF0 00218E00-??? 0021BCD0 002190D0-??? 0021BFA0 006B1028-... 006B3B64
|
||||
EF ------------ -------- ------------ -------- 8C151884-LL 8C154DF0 8C16C810-LL 8C16FE0C 004E13C0-LL 004E4C60 00590ED0-LL 005947F0 80242D00-LL 8023E308 801F29D0-... 801EE270 80109C68-... 801052FC 00218E00-??? 0021C880 002190D0-??? 0021CB50 006B1028-... 006B44E0
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F0 ------------ -------- ------------ -------- 8C151884-LL 8C154E24 8C16C810-LL 8C16FE40 004E13C0-LL 004E4CA0 00590ED0-LL 00594830 80242D00-LL 8023E2C0 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ --------
|
||||
F1 ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C16FE74 004E1390-L 004E4CE0 00590EA0-L 00594870 80242DA8-L 8023E1B8 801F2988-B 801EE160 80109C20-B 801051EC 00218E20-??? 0021C8F0 002190F0-??? 0021CBC0 006B1040-B 006B450C
|
||||
F2 ------------ -------- ------------ -------- ------------ -------- 8C16C6F0-() 8C16FF00 004E12C0-() 004E4D40 00590DD0-() 005948D0 80242F44-() 8023E198 801F2A10-() 801EE128 80109CA8-() 801051B4 00218DF0-??? 0021C990 002190C0-??? 0021CC60 006B101C-() 006B4574
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F800 ------------ -------- ------------ -------- ------------ -------- 8C16C6F0-() 8C1700C4 004E12C0-() 004E4F90 00590DD0-() 00594B20 80242F44-() 8023DE60 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ --------
|
||||
F801 ------------ -------- ------------ -------- ------------ -------- 8C16CD18-BS 8C171E3C 004E18F0-BS 004E1A50 00591400-BS 00596AE0 80242404-BS 8023B008 801F29D0-... 801EAC18 80109C68-... 80102D20 00218E00-??? 0021F130 002190D0-??? 0021F400 006B1028-... 006B6448
|
||||
F808 ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C1700F4 004E12D0-B 004E4FB0 00590DE0-B 00594B40 80242EF8-B 8023DE34 801F2988-B 801EDE44 80109C20-B 80104EE0 00218E20-??? 0021CCA0 002190F0-??? 0021CF70 006B1040-B 006B47AC
|
||||
@@ -736,7 +736,7 @@ F80C ------------ -------- ------------ -------- ------------ -------- 8C16C
|
||||
F80D ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C1701C4 004E12D0-B 004E50C0 00590DE0-B 00594C50 80242EF8-B 8023DCE0 801F2988-B 801EDCBC 80109C20-B 80104D50 00218E20-??? 0021CD90 002190F0-??? 0021D060 006B1040-B 006B48C0
|
||||
F80E ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C17020C 004E1390-L 004E5130 00590EA0-L 00594CC0 80242DA8-L 8023DCB4 801F29D0-... 801EDC84 80109C68-... 80104D18 00218E00-??? 0021CDE0 002190D0-??? 0021D0B0 006B1028-... 006B4964
|
||||
F80F ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C170230 004E1390-L 004E5150 00590EA0-L 00594CE0 80242DA8-L 8023DC88 801F29D0-... 801EDC4C 80109C68-... 80104CE0 00218E00-??? 0021CE10 002190D0-??? 0021D0E0 006B1028-... 006B497C
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F810 ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C170254 004E1390-L 004E5170 00590EA0-L 00594D00 80242DA8-L 8023DC08 801F29D0-... 801EDBD8 80109C68-... 80104C6C 00218E00-??? 0021CE40 002190D0-??? 0021D110 006B1028-... 006B4994 ba_initial_floor
|
||||
F811 ------------ -------- ------------ -------- ------------ -------- 8C16C6F0-() 8C17029C 004E12C0-() 004E5250 00590DD0-() 00594DE0 80242F44-() 8023DBD8 801F2A10-() 801EDBA8 80109CA8-() 80104C3C 00218DF0-??? 0021CF20 002190C0-??? 0021D1F0 006B101C-() 006B98E4 set_ba_rules
|
||||
F812 ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C1702B0 004E1390-L 004E5270 00590EA0-L 00594E00 80242DA8-L 8023DB9C 801F29D0-... 801EDB64 80109C68-... 80104BF8 00218E00-??? 0021CF40 002190D0-??? 0021D210 006B1028-... 006B4A70 ba_set_tech_disk_mode
|
||||
@@ -752,7 +752,7 @@ F81B ------------ -------- ------------ -------- ------------ -------- 8C16C
|
||||
F81C ------------ -------- ------------ -------- ------------ -------- 8C16CC20-S 8C170418 004E1740-S 004E1A50 00591250-S 00594F40 80242648-S 8023D92C 801F29D0-... 801ED878 80109C68-... 80104964 00218E00-??? 0021D080 002190D0-??? 0021D350 006B1028-... 006B4BB4 ba_start
|
||||
F81D ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C170C48 004E1390-L 004E5CB0 00590EA0-L 00595870 80242DA8-L 8023C994 801F29D0-... 801EC87C 80109C68-... 80104218 00218E00-??? 0021DA30 002190D0-??? 0021DD00 006B1028-... 006B52EC death_lvl_up
|
||||
F81E ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C170C54 004E1390-L 004E5CC0 00590EA0-L 00595880 80242DA8-L 8023C96C 801F29D0-... 801EC84C 80109C68-... 801041E8 00218E00-??? 0021DA40 002190D0-??? 0021DD10 006B1028-... 006B52F8 ba_set_meseta_drop_mode
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F820 ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C17042C 004E1390-L 004E53B0 00590EA0-L 00594F60 80242DA8-L 8023D8C4 801F29D0-... 801ED7F8 80109C68-... 80104960 00218E00-??? 0021D0C0 002190D0-??? 0021D390 006B1028-... 006B4BC8 cmode_stage
|
||||
F821 ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C170450 004E12D0-B 004E53D0 00590DE0-B 00594F80 80242EF8-B 8023D824 801F2988-B 801ED6FC 80109C20-B 8010495C 00218E20-??? 0021D120 002190F0-??? 0021D3F0 006B1040-B 006B4BF4 nop_F821
|
||||
F822 ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C1704C8 004E12D0-B 004E1A50 00590DE0-B 00595030 80242EF8-B 8023D820 801F2988-B 801ED6A4 80109C20-B 80104958 00218E20-??? 002C9010 002190F0-??? 002F76A0 006B1040-B 0061CDB0 nop_F822
|
||||
@@ -768,7 +768,7 @@ F82B ------------ -------- ------------ -------- ------------ -------- 8C16C
|
||||
F82C ------------ -------- ------------ -------- ------------ -------- 8C16C810-LL 8C1706E0 004E13C0-LL 004E56C0 00590ED0-LL 00595280 80242D00-LL 8023D38C 801F29D0-... 801ED240 80109C68-... 80104728 00218E00-??? 0021D480 002190D0-??? 0021D750 006B1028-... 006B4E30 lock_door2
|
||||
F82D ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C170724 004E12D0-B 004E5710 00590DE0-B 005952D0 80242EF8-B 8023D33C 801F2988-B 801ED1F0 80109C20-B 801046D8 00218E20-??? 0021D500 002190F0-??? 0021D7D0 006B1040-B 006B4E7C if_switch_not_pressed
|
||||
F82E ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C170758 004E12D0-B 004E5740 00590DE0-B 00595300 80242EF8-B 8023D2E8 801F2988-B 801ED19C 80109C20-B 80104684 00218E20-??? 0021D530 002190F0-??? 0021D800 006B1040-B 006B4EA4 if_switch_pressed
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F830 ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C17056C 004E12D0-B 004E5530 00590DE0-B 005950F0 80242EF8-B 8023D5F8 801F2988-B 801ED46C 80109C20-B 80104940 00218E20-??? 0021D2B0 002190F0-??? 0021D580 006B1040-B 006B4CE8 control_dragon
|
||||
F831 ------------ -------- ------------ -------- ------------ -------- 8C16C6F0-() 8C170584 004E12C0-() 004E5550 00590DD0-() 00595110 80242F44-() 8023D5D8 801F2A10-() 801ED44C 80109CA8-() 8010493C 00218DF0-??? 0021D2E0 002190C0-??? 0021D5B0 006B101C-() 006B4D00 release_dragon
|
||||
F838 ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C17078C 004E12D0-B 004E5780 00590DE0-B 00595340 80242EF8-B 8023D2A0 801F2988-B 801ED14C 80109C20-B 80104634 00218E20-??? 0021D560 002190F0-??? 0021D830 006B1040-B 006B4ED4 shrink
|
||||
@@ -778,7 +778,7 @@ F83B ------------ -------- ------------ -------- ------------ -------- 8C16C
|
||||
F83C ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C170990 004E12D0-B 004E5980 00590DE0-B 00595540 80242EF8-B 8023CF34 801F2988-B 801ECE6C 80109C20-B 80104388 00218E20-??? 0021D750 002190F0-??? 0021DA20 006B1040-B 006B50D8 display_clock2
|
||||
F83D ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C170C70 004E1390-L 004E5CE0 00590EA0-L 005958A0 80242DA8-L 8023C964 801F29D0-... 801EC820 80109C68-... 801041B4 00218E00-??? 0021DA60 002190D0-??? 0021DD30 006B1028-... 006B5314 set_area_total
|
||||
F83E ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C170C7C 004E1390-L 004E5CF0 00590EA0-L 005958B0 80242DA8-L 8023C95C 801F29D0-... 801EC7F4 80109C68-... 80104180 00218E00-??? 0021DA70 002190D0-??? 0021DD40 006B1028-... 006B5320 delete_area_title
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F840 ------------ -------- ------------ -------- ------------ -------- 8C16C6F0-() 8C17094C 004E12C0-() 004E5940 00590DD0-() 00595500 80242F44-() 8023D088 801F2A10-() 801ECEFC 80109CA8-() 801043C4 00218DF0-??? 0021D710 002190C0-??? 0021D9E0 006B101C-() 006B98B8 load_npc_data
|
||||
F841 ------------ -------- ------------ -------- ------------ -------- 8C16C97C-W 8C170958 004E1530-W 004E5950 00591040-W 00595510 80242A98-W 8023CF8C 801F2848-W 801ECEC4 80109AE0-W 8010438C 00219100-??? 0021D720 002193D0-??? 0021D9F0 006B10E0-W 006B5014 get_npc_data
|
||||
F848 ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C1709A8 004E12D0-B 004E59A0 00590DE0-B 00595560 80242EF8-B 8023CEB4 801F2988-B 801ECDE8 80109C20-B 80104384 00218E20-??? 0021D7C0 002190F0-??? 0021DA90 006B1040-B 006B50EC give_damage_score
|
||||
@@ -789,7 +789,7 @@ F84C ------------ -------- ------------ -------- ------------ -------- 8C16C
|
||||
F84D ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C170AC0 004E12D0-B 004E5AE0 00590DE0-B 005956A0 80242EF8-B 8023CC34 801F2988-B 801ECB54 80109C20-B 80104370 00218E20-??? 0021D8B0 002190F0-??? 0021DB80 006B1040-B 006B51C8 death_score
|
||||
F84E ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C170AF8 004E12D0-B 004E5B20 00590DE0-B 005956E0 80242EF8-B 8023CBB4 801F2988-B 801ECAD0 80109C20-B 8010436C 00218E20-??? 0021D8E0 002190F0-??? 0021DBB0 006B1040-B 006B51F4 enemy_kill_score
|
||||
F84F ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C170B30 004E12D0-B 004E5B60 00590DE0-B 00595720 80242EF8-B 8023CB34 801F2988-B 801ECA4C 80109C20-B 80104368 00218E20-??? 0021D910 002190F0-??? 0021DBE0 006B1040-B 006B5220 enemy_death_score
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F850 ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C170B68 004E12D0-B 004E5BA0 00590DE0-B 00595760 80242EF8-B 8023CAB4 801F2988-B 801EC9C8 80109C20-B 80104364 00218E20-??? 0021D940 002190F0-??? 0021DC10 006B1040-B 006B524C meseta_score
|
||||
F851 ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C170BA0 004E12D0-B 004E5BE0 00590DE0-B 005957A0 80242EF8-B 8023CA68 801F2988-B 801EC97C 80109C20-B 80104318 00218E20-??? 0021D970 002190F0-??? 0021DC40 006B1040-B 006B9888 ba_set_trap_count
|
||||
F852 ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C170BD8 004E1390-L 004E5C20 00590EA0-L 005957E0 80242DA8-L 8023CA50 801F29D0-... 801EC95C 80109C68-... 801042F8 00218E00-??? 0021D9A0 002190D0-??? 0021DC70 006B1028-... 006B5278 ba_set_target
|
||||
@@ -806,7 +806,7 @@ F85C ------------ -------- ------------ -------- ------------ -------- 8C16C
|
||||
F85D ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C170D80 004E1390-L 004E5E00 00590EA0-L 005959C0 80242DA8-L 8023C7D4 801F29D0-... 801EC5D4 80109C68-... 80103F90 00218E00-??? 0021DBC0 002190D0-??? 0021DE90 006B1028-... 006B53F8 set_allow_item_flags
|
||||
F85E ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C170D8C 004E1390-L 004E5E10 00590EA0-L 005959D0 80242DA8-L 8023C7B0 801F29D0-... 801EC5A4 80109C68-... 80103F60 00218E00-??? 0021DBD0 002190D0-??? 0021DEA0 006B1028-... 006B5408 ba_enable_sonar
|
||||
F85F ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C170DAC 004E1390-L 004E5E30 00590EA0-L 005959F0 80242DA8-L 8023C7A0 801F29D0-... 801EC58C 80109C68-... 80103F48 00218E00-??? 0021DBF0 002190D0-??? 0021DEC0 006B1028-... 006B5424 ba_use_sonar
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F860 ------------ -------- ------------ -------- ------------ -------- 8C16C6F0-() 8C170DB8 004E12C0-() 004E5E40 00590DD0-() 00595A00 80242F44-() 8023C778 801F2A10-() 801EC564 80109CA8-() 80103F44 00218DF0-??? 0021DC00 002190C0-??? 0021DED0 006B101C-() 006B5430 clear_score_announce
|
||||
F861 ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C170DD8 004E1390-L 004E5E60 00590EA0-L 00595A20 80242DA8-L 8023C744 801F29D0-... 801EC524 80109C68-... 80103F40 00218E00-??? 0021DC20 002190D0-??? 0021DEF0 006B1028-... 006B5464 set_score_announce
|
||||
F862 ------------ -------- ------------ -------- ------------ -------- 8C16C878-LLS 8C170E00 004E1400-LLS 004E5E90 00590F10-LLS 00595A50 80242B98-LLS 8023C6A4 801F29D0-... 801EC480 80109C68-... 80103E9C 00218E00-??? 0021DC50 002190D0-??? 0021DF20 006B1028-... 006B54F4 give_s_rank_weapon
|
||||
@@ -823,7 +823,7 @@ F86C ------------ -------- ------------ -------- ------------ -------- 8C16C
|
||||
F86D ------------ -------- ------------ -------- ------------ -------- 8C16C6F0-() 8C1712C4 004E12C0-() 004E6410 00590DD0-() 00595FD0 80242F44-() 8023BFFC 801F2A10-() 801EBDD0 80109CA8-() 80103BF0 00218DF0-??? 0021E4D0 002190C0-??? 0021E7A0 006B101C-() 006B5988 ba_set_trapself
|
||||
F86E ------------ -------- ------------ -------- ------------ -------- 8C16C6F0-() 8C1712D0 004E12C0-() 004E6420 00590DD0-() 00595FE0 80242F44-() 8023BFF0 801F2A10-() 801EBDAC 80109CA8-() 80103BCC 00218DF0-??? 0021E4E0 002190C0-??? 0021E7B0 006B101C-() 006B5994 ba_clear_trapself
|
||||
F86F ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C170BEC 004E1390-L 004E5C30 00590EA0-L 005957F0 80242DA8-L 8023CA34 801F29D0-... 801EC938 80109C68-... 801042D4 00218E00-??? 0021D9B0 002190D0-??? 0021DC80 006B1028-... 006B528C ba_set_lives
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F870 ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C170C00 004E1390-L 004E5C50 00590EA0-L 00595810 80242DA8-L 8023CA0C 801F29D0-... 801EC90C 80109C68-... 801042A8 00218E00-??? 0021D9D0 002190D0-??? 0021DCA0 006B1028-... 006B52A0 ba_set_max_tech_level
|
||||
F871 ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C170C18 004E1390-L 004E5C70 00590EA0-L 00595830 80242DA8-L 8023C9C8 801F29D0-... 801EC8C4 80109C68-... 80104260 00218E00-??? 0021D9F0 002190D0-??? 0021DCC0 006B1028-... 006B52BC ba_set_char_level
|
||||
F872 ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C170C30 004E1390-L 004E5C90 00590EA0-L 00595850 80242DA8-L 8023C9A4 801F29D0-... 801EC894 80109C68-... 80104230 00218E00-??? 0021DA10 002190D0-??? 0021DCE0 006B1028-... 006B52D8 ba_set_time_limit
|
||||
@@ -840,7 +840,7 @@ F87C ------------ -------- ------------ -------- ------------ -------- 8C16C
|
||||
F87D ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C1716CC 004E12D0-B 004E6830 00590DE0-B 00596410 80242EF8-B 8023BAB0 801F2988-B 801EB854 80109C20-B 80103770 00218E20-??? 0021E910 002190F0-??? 0021EBE0 006B1040-B 006B5D88 kill_player
|
||||
F87E ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C1716FC 004E12D0-B 004E6860 00590DE0-B 00596440 80242EF8-B 8023BA5C 801F2988-B 801EB800 80109C20-B 8010371C 00218E20-??? 0021E970 002190F0-??? 0021EC40 006B1040-B 006B5DA8 get_serial_number
|
||||
F87F ------------ -------- ------------ -------- ------------ -------- 8C16C730-BB 8C171740 004E1300-BB 004E68A0 00590E10-BB 00596480 80242EA0-BB 8023BA20 801F2930-BB 801EB79C 80109BC8-BB 801036B8 00218E50-??? 0021E9F0 00219120-??? 0021ECC0 006B1058-BB 006B5DD0 get_eventflag
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F880 ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C171780 004E12D0-B 004E68E0 00590DE0-B 005964C0 80242EF8-B 8023B9A0 801F2988-B 801EB708 80109C20-B 80103624 00218E20-??? 0021EA30 002190F0-??? 0021ED00 006B1040-B 006B5E04 set_trap_damage
|
||||
F881 ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C1717BC 004E12D0-B 004E6920 00590DE0-B 00596500 80242EF8-B 8023B914 801F2988-B 801EB67C 80109C20-B 80103598 00218E20-??? 0021EA60 002190F0-??? 0021ED30 006B1040-B 006B5E30 get_pl_name
|
||||
F882 ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C17181C 004E12D0-B 004E6980 00590DE0-B 00596560 80242EF8-B 8023B890 801F2988-B 801EB5F8 80109C20-B 80103514 00218E20-??? 0021EAD0 002190F0-??? 0021EDA0 006B1040-B 006B5E84 get_pl_job
|
||||
@@ -857,7 +857,7 @@ F88C ------------ -------- ------------ -------- ------------ -------- 8C16C
|
||||
F88D ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C171CD4 004E12D0-B 004E6DC0 00590DE0-B 005969A0 80242EF8-B 8023B3C8 801F2988-B 801EAFE0 80109C20-B 80102E28 00218E20-??? 0021EF90 002190F0-??? 0021F260 006B1058-BB 006B6370 chl_set_timerecord
|
||||
F88E ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C171CEC 004E12D0-B 004E6DE0 00590DE0-B 005969C0 80242EF8-B 8023B364 801F2988-B 801EAF88 80109C20-B 80102E24 00218E20-??? 0021F000 002190F0-??? 0021F2D0 006B1040-B 006B6390 chl_get_timerecord
|
||||
F88F ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C171D14 004E12D0-B 004E6E00 00590DE0-B 005969E0 80242EF8-B 8023B0FC 801F2988-B 801EAD18 80109C20-B 80102E20 00218E20-??? 0021F040 002190F0-??? 0021F310 006B1040-B 006B63A4 set_cmode_grave_rates
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F890 ------------ -------- ------------ -------- ------------ -------- 8C16C6F0-() 8C16F2DC 004E12C0-() 004E3E20 00590DD0-() 005939B0 80242F44-() 8023F1B4 801F2A10-() 801EF18C 80109CA8-() 801062F8 00218DF0-??? 0021BB30 002190C0-??? 0021BE00 006B101C-() 006B3A58 clear_mainwarp_all
|
||||
F891 ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C171ED0 004E1390-L 004E6F00 00590EA0-L 00596B80 80242DA8-L 8023AFE8 801F29D0-... 801EABEC 80109C68-... 80102CF4 00218E00-??? 0021F1D0 002190D0-??? 0021F4A0 006B1028-... 006B64C8 load_enemy_data
|
||||
F892 ------------ -------- ------------ -------- ------------ -------- 8C16C97C-W 8C171EDC 004E1530-W 004E6F10 00591040-W 00596B90 80242A98-W 8023AF18 801F2848-W 801EAB88 80109AE0-W 80102C90 00219100-??? 0021F1E0 002193D0-??? 0021F4B0 006B10E0-W 006B64D8 get_physical_data
|
||||
@@ -874,7 +874,7 @@ F89C ------------ -------- ------------ -------- ------------ -------- 8C16C
|
||||
F89D ------------ -------- ------------ -------- ------------ -------- 8C16C6F0-() 8C1721CC 004E12C0-() 004E71D0 00590DD0-() 00596E50 80242F44-() 8023A9B4 801F2A10-() 801EA758 80109CA8-() 801028EC 00218DF0-??? 0021F520 002190C0-??? 0021F7F0 006B101C-() 006B6924 chl_reverser
|
||||
F89E ------------ -------- ------------ -------- ------------ -------- 8C16C7C8-L 8C1721D8 004E1390-L 004E71E0 00590EA0-L 00596E60 80242DA8-L 8023A990 801F29D0-... 801EA728 80109C68-... 801028BC 00218E00-??? 0021F590 002190D0-??? 0021F860 006B1028-... 006B692C ba_forbid_scape_dolls
|
||||
F89F ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C1721F8 004E12D0-B 004E7200 00590DE0-B 00596E80 80242EF8-B 8023A948 801F2988-B 801EA6E0 80109C20-B 80102874 00218E20-??? 0021F5B0 002190F0-??? 0021F880 006B1040-B 006B6948 player_recovery
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F8A0 ------------ -------- ------------ -------- ------------ -------- 8C16C6F0-() 8C172234 004E12C0-() 004E7240 00590DD0-() 00596EC0 80242F44-() 8023A900 801F2A10-() 801EA6A4 80109CA8-() 80102870 00218DF0-??? 0021F5F0 002190C0-??? 0021F8C0 006B101C-() 006B6974
|
||||
F8A1 ------------ -------- ------------ -------- ------------ -------- 8C16C6F0-() 8C172240 004E12C0-() 004E7250 00590DD0-() 00596ED0 80242F44-() 8023A8B8 801F2A10-() 801EA668 80109CA8-() 8010286C 00218DF0-??? 0021F640 002190C0-??? 0021F910 006B101C-() 006B6980
|
||||
F8A2 ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C17224C 004E12D0-B 004E7260 00590DE0-B 00596EE0 80242EF8-B 8023A814 801F2988-B 801EA5D0 80109C20-B 80102868 00218E20-??? 0021F680 002190F0-??? 0021F950 006B1040-B 006B698C
|
||||
@@ -891,7 +891,7 @@ F8AC ------------ -------- ------------ -------- ------------ -------- 8C16C
|
||||
F8AD ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C1726B8 004E12D0-B 004E76B0 00590DE0-B 005973F0 80242EF8-B 8023A1FC 801F2988-B 801E9F9C 80109C20-B 801023E0 00218E20-??? 0021FBC0 002190F0-??? 0021FE90 006B1040-B 006B6D18
|
||||
F8AE ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C1726D0 004E12D0-B 004E76D0 00590DE0-B 00597410 80242EF8-B 8023A198 801F2988-B 801E9F3C 80109C20-B 801023DC 00218E20-??? 0021FBE0 002190F0-??? 0021FEB0 006B1040-B 006B6D2C
|
||||
F8AF ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C172724 004E12D0-B 004E7720 00590DE0-B 00597460 80242EF8-B 8023A138 801F2988-B 801E9EDC 80109C20-B 8010237C 00218E20-??? 0021FC20 002190F0-??? 0021FEF0 006B1040-B 006B6D64
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F8B0 ------------ -------- ------------ -------- ------------ -------- 8C16C730-BB 8C17277C 004E1300-BB 004E7770 00590E10-BB 005974B0 80242EA0-BB 8023A118 801F29D0-... 801E9EB4 80109C68-... 80102354 00218E00-??? 0021FC60 002190D0-??? 0021FF30 006B1028-... 006B6D9C
|
||||
F8B1 ------------ -------- ------------ -------- ------------ -------- 8C16C730-BB 8C172798 004E1300-BB 004E77A0 00590E10-BB 005974E0 80242EA0-BB 8023A0FC 801F29D0-... 801E9E90 80109C68-... 80102330 00218E00-??? 0021FC80 002190D0-??? 0021FF50 006B1028-... 006B6DB8
|
||||
F8B2 ------------ -------- ------------ -------- ------------ -------- 8C16C730-BB 8C1727B4 004E1300-BB 004E77D0 00590E10-BB 00597510 80242EA0-BB 8023A0E0 801F29D0-... 801E9E6C 80109C68-... 8010230C 00218E00-??? 0021FCA0 002190D0-??? 0021FF70 006B1028-... 006B6DD4
|
||||
@@ -905,7 +905,7 @@ F8B9 ------------ -------- ------------ -------- ------------ -------- 8C16C
|
||||
F8BA ------------ -------- ------------ -------- ------------ -------- 8C16C6F0-() 8C1728FC 004E12C0-() 004E7920 00590DD0-() 00597660 80242F44-() 80239EB4 801F2A10-() 801E9C30 80109CA8-() 80102184 00218DF0-??? 0021FE30 002190C0-??? 00220100 006B101C-() 006B6EE0
|
||||
F8BB ------------ -------- ------------ -------- ------------ -------- 8C16C704-B 8C172924 004E12D0-B 004E7930 00590DE0-B 00597670 80242EF8-B 80239E5C 801F2988-B 801E9C10 80109C20-B 80102164 00218E20-??? 0021F7A0 002190F0-??? 0021FA70 006B1040-B 006B6F00
|
||||
F8BC ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2890-L 801E9BBC 80109B28-L 80102110 00218ED0-??? 0021FE50 002191A0-??? 00220120 006B10C8-L 006B6F44
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F8C0 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F29D0-... 801E9B80 80109C68-... 801020C8 00218E00-??? 0021FE80 002190D0-??? 00220150 006B1028-... 0061CDB0
|
||||
F8C1 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2988-B 801E9B08 80109C20-B 80102040 00218E20-??? 0021FEB0 002190F0-??? 00220180 006B1040-B 0061CDB0
|
||||
F8C2 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2A10-() 801E9AD8 80109CA8-() 80102010 00218DF0-??? 002C9010 002190C0-??? 002F76A0 006B101C-() 0061CDB0
|
||||
@@ -922,7 +922,7 @@ F8CC ------------ -------- ------------ -------- ------------ -------- -----
|
||||
F8CD ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2988-B 801E9714 80109C20-B 80101CE4 00218E20-??? 00220230 002190F0-??? 00220500 006B1040-B 006B7064
|
||||
F8CE ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2988-B 801E96E4 80109C20-B 80101CB4 00218E20-??? 00220260 002190F0-??? 00220530 006B1040-B 006B707C
|
||||
F8CF ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2988-B 801E96B4 80109C20-B 80101C84 00218E20-??? 00220290 002190F0-??? 00220560 006B1040-B 006B7094
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F8D0 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2988-B 801E9684 80109C20-B 80101C54 00218E20-??? 002202C0 002190F0-??? 00220590 006B1040-B 006B70AC
|
||||
F8D1 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2988-B 801E9654 80109C20-B 80101C24 00218E20-??? 002202F0 002190F0-??? 002205C0 006B1040-B 006B70C4
|
||||
F8D2 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2988-B 801E9624 80109C20-B 80101BF4 00218E20-??? 00220320 002190F0-??? 002205F0 006B1040-B 006B70DC
|
||||
@@ -939,7 +939,7 @@ F8DC ------------ -------- ------------ -------- ------------ -------- -----
|
||||
F8DD ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2930-BB 801E92F4 80109BC8-BB 801018B4 00218E50-??? 002206A0 00219120-??? 00220970 006B1058-BB 006B7298
|
||||
F8DE ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2930-BB 801E92C8 80109BC8-BB 80101888 00218E50-??? 00220700 00219120-??? 002209D0 006B1058-BB 006B73B0
|
||||
F8DF ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2A10-() 801E9018 80109CA8-() 80101594 00218DF0-??? 002208A0 002190C0-??? 00220B70 006B101C-() 006B76CC
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F8E0 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2A10-() 801E8FEC 80109CA8-() 80101568 00218DF0-??? 002208B0 002190C0-??? 00220B80 006B101C-() 006B76E4
|
||||
F8E1 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2A10-() 801E8FC4 80109CA8-() 80101540 00218DF0-??? 002208C0 002190C0-??? 00220B90 006B101C-() 006B76FC
|
||||
F8E2 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2A10-() 801E8F9C 80109CA8-() 80101518 00218DF0-??? 002208D0 002190C0-??? 00220BA0 006B101C-() 006B7708
|
||||
@@ -956,12 +956,12 @@ F8EC ------------ -------- ------------ -------- ------------ -------- -----
|
||||
F8ED ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2930-BB 801EB544 80109BC8-BB 80103460 00218E50-??? 0021EBA0 00219120-??? 0021EE70 006B1058-BB 006B5F10
|
||||
F8EE ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F29D0-... 801EB4EC 80109C68-... 80103408 00218E00-??? 0021EBE0 002190D0-??? 0021EEB0 006B1028-... 006B5F40
|
||||
F8EF ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2A10-() 801EB4E8 80109CA8-() 80103404 00218DF0-??? 002C9010 002190C0-??? 002F76A0 006B101C-() 0061CDB0
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F8F0 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2A10-() 801EB4C8 80109CA8-() 801033E4 00218DF0-??? 0021EC20 002190C0-??? 0021EEF0 006B101C-() 006B5F7C
|
||||
F8F1 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2A10-() 801EB4A8 80109CA8-() 801033C4 00218DF0-??? 0021EC50 002190C0-??? 0021EF20 006B101C-() 006B5F84
|
||||
F8F2 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F29D0-... 801E909C 80109C68-... 80101618 00218E00-??? 002207E0 002190D0-??? 00220AB0 006B1028-... 006B75A8
|
||||
F8F3 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F29D0-... 801F07EC 80109C68-... 80107A24 00218E00-??? 0021ABB0 002190D0-??? 0021AE80 006B1028-... 006B2E34
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F901 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2930-BB 801E8828 80109BC8-BB 80100D80 00218E50-??? 00220D40 00219120-??? 00221010 006B1058-BB 006B7A88
|
||||
F902 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2930-BB 801E87FC 80109BC8-BB 80100D54 00218E50-??? 00220D60 00219120-??? 00221030 006B1058-BB 006B7AA8
|
||||
F903 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2930-BB 801F2458 80109BC8-BB 801096F0 00218E50-??? 00219210 00219120-??? 002194E0 006B1058-BB 006B170C
|
||||
@@ -974,7 +974,7 @@ F90C ------------ -------- ------------ -------- ------------ -------- -----
|
||||
F90D ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F28D8-BL 801E86C4 80109B70-BL 80100C1C 00218E90-??? 00220E20 00219160-??? 002210F0 006B107C-BL 006B7B9C
|
||||
F90E ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2930-BB 801E8690 80109BC8-BB 80100BE8 00218E50-??? 00220E40 00219120-??? 00221110 006B1058-BB 006B7BC0
|
||||
F90F ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F28D8-BL 801E865C 80109B70-BL 80100BB4 00218E90-??? 00220E60 00219160-??? 00221130 006B107C-BL 006B7BE8
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F910 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F29D0-... 801E84A0 80109C68-... 801009F8 00218E00-??? 00220F50 002190D0-??? 00221220 006B1028-... 006B7CEC
|
||||
F911 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2930-BB 801E8410 80109BC8-BB 80100968 00218E50-??? 00220FB0 00219120-??? 00221280 006B1058-BB 006B7D18
|
||||
F912 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2A10-() 801E83E4 80109CA8-() 8010092C 00218DF0-??? 00221030 002190C0-??? 00221300 006B101C-() 006B97D8
|
||||
@@ -991,7 +991,7 @@ F91C ------------ -------- ------------ -------- ------------ -------- -----
|
||||
F91D ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2988-B 801E7D90 80109C20-B 801002D8 00218E20-??? 00221580 002190F0-??? 00221850 006B1040-B 006B80C4
|
||||
F91E ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2988-B 801E7D58 80109C20-B 801002A0 00218E20-??? 002215C0 002190F0-??? 00221890 006B1040-B 006B80F8
|
||||
F91F ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2988-B 801E7CBC 80109C20-B 80100204 00218E20-??? 002215E0 002190F0-??? 002218B0 006B1040-B 006B810C
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F920 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F29D0-... 801E7C3C 80109C68-... 80100184 00218E00-??? 002216B0 002190D0-??? 00221980 006B1028-... 006B8180
|
||||
F921 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F29D0-... 801E7B9C 80109C68-... 801000D4 00218E00-??? 00221730 002190D0-??? 00221A00 006B1028-... 006B81BC
|
||||
F922 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F29D0-... 801E7AA4 80109C68-... 800FFFDC 00218E00-??? 00221780 002190D0-??? 00221A50 006B1028-... 006B81F0
|
||||
@@ -1008,7 +1008,7 @@ F92C ------------ -------- ------------ -------- ------------ -------- -----
|
||||
F92D ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F29D0-... 801E7530 80109C68-... 800FFA10 00218E00-??? 00221E00 002190D0-??? 002220D0 006B1028-... 006B8574
|
||||
F92E ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F29D0-... 801E6E80 80109C68-... 800FF44C 00218E00-??? 00222450 002190D0-??? 00222720 006B1028-... 006B8B98
|
||||
F92F ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F29D0-... 801E7C0C 80109C68-... 80100144 00218E00-??? 00221710 002190D0-??? 002219E0 006B1028-... 0061CDB0
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F930 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F29D0-... 801E7410 80109C68-... 800FF8F0 00218E00-??? 00221E60 002190D0-??? 00222130 006B1028-... 006B863C
|
||||
F931 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F29D0-... 801E7348 80109C68-... 800FF818 00218E00-??? 00221F90 002190D0-??? 00222260 006B1028-... 006B8740
|
||||
F932 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F2988-B 801E72F4 80109C20-B 800FF7C4 00218E20-??? 00222040 002190F0-??? 00222310 006B1040-B 006B87FC
|
||||
@@ -1025,7 +1025,7 @@ F93C ------------ -------- ------------ -------- ------------ -------- -----
|
||||
F93D ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F29D0-... 801E7DF0 80109C68-... 80100338 00218E00-??? 00221560 002190D0-??? 00221830 006B1028-... 006B80AC
|
||||
F93E ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F29D0-... 801E6E5C 80109C68-... 800FF428 00218E00-??? 00222480 002190D0-??? 00222750 006B1028-... 006B96F8
|
||||
F93F ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F29D0-... 801E6E38 80109C68-... 800FF404 00218E00-??? 002224B0 002190D0-??? 00222780 006B1028-... 006B8BC4
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F940 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F29D0-... 801E6DC8 80109C68-... 800FF394 00218E00-??? 002224E0 002190D0-??? 002227B0 006B1028-... 006B8BD4
|
||||
F941 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F29D0-... 801E6D60 80109C68-... 800FF32C 00218E00-??? 00222530 002190D0-??? 00222800 006B1028-... 006B8C10
|
||||
F942 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 801F29D0-... 801E6D04 80109C68-... 800FF2D0 00218E00-??? 00222580 002190D0-??? 00222850 006B1028-... 006B8C44
|
||||
@@ -1042,7 +1042,7 @@ F94C ------------ -------- ------------ -------- ------------ -------- -----
|
||||
F94D ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 80109C20-B 80107668 00218E00-??? 00221660 002190D0-??? 00221930 006B1028-... 0061CDB0
|
||||
F94E ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 006B1028-... 0061CDB0
|
||||
F94F ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 006B1028-... 0061CDB0
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F950 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 006B1028-... 006B8EA0
|
||||
F951 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 006B101C-!!! 006B4908
|
||||
F952 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 006B1040-B 006B8EB0
|
||||
@@ -1059,7 +1059,7 @@ F95C ------------ -------- ------------ -------- ------------ -------- -----
|
||||
F95D ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 006B1028-... 006B93FC
|
||||
F95E ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 006B1028-... 006B941C
|
||||
F95F ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 006B1028-... 006B9104
|
||||
DC-NTE--------------- DC112000------------- DCv1----------------- DCv2----------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
DC-NTE--------------- DC112000------------- DCv1USA-------------- DCv2USA-------------- PC-NTE------ -------- PC------------------- GC1&2NTE------------- GC1&2v11------------- GCEp3USA------------- XBOXBETA------------- XBOX-US0------------- BB-------------------
|
||||
F960 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 006B1028-... 006B915C
|
||||
F961 ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- ------------ -------- 006B1040-B 006B91F8
|
||||
|
||||
|
||||
@@ -1,96 +1,94 @@
|
||||
###########################################################
|
||||
|
||||
NPC: Coren Tsu - The Wanderer
|
||||
AREAS: Pioneer 2
|
||||
|
||||
Translations by: apexseals (discord: apexseals)
|
||||
Proofing & Debugging by: nolrinale (github.com/nolrinale)
|
||||
|
||||
###########################################################
|
||||
|
||||
presentation:
|
||||
|
||||
I am Coren Tsu, a wandering merchant,
|
||||
you could say.
|
||||
|
||||
Please take some time to look at
|
||||
the rare and wonderous goods
|
||||
I have been collecting.
|
||||
|
||||
If you spend a little meseta,
|
||||
you could win a wonderful prize.
|
||||
|
||||
Well? Wanna try?
|
||||
|
||||
|
||||
You may win,
|
||||
you may lose.
|
||||
|
||||
But if you don't win,
|
||||
don't take it out on me.
|
||||
|
||||
That's just the way
|
||||
gambling is, yes?
|
||||
|
||||
Well then, how much
|
||||
meseta do you want to pay?
|
||||
|
||||
As long as you pay me,
|
||||
I'll give you a great service.
|
||||
|
||||
|
||||
Huh?
|
||||
|
||||
That's too bad...
|
||||
|
||||
Well, these kind of things usually
|
||||
have a chance to lose money.
|
||||
|
||||
Let's keep this discreet.
|
||||
If you feel up to it, talk to me again.
|
||||
|
||||
|
||||
It seems you have
|
||||
too many items.
|
||||
|
||||
First, go and
|
||||
organize your items,
|
||||
|
||||
Then speak to me again.
|
||||
|
||||
What?
|
||||
|
||||
You said you'd try,
|
||||
then you said no.
|
||||
|
||||
People like that
|
||||
fail at everything.
|
||||
|
||||
|
||||
What the...?
|
||||
|
||||
You don't have the
|
||||
meseta to pay me?
|
||||
|
||||
I won't work with such
|
||||
cold hearted people.
|
||||
|
||||
|
||||
Alright, let's do it.
|
||||
|
||||
You better pray
|
||||
for something good...
|
||||
|
||||
|
||||
Look here!
|
||||
Take it!
|
||||
|
||||
Even if you had bad luck,
|
||||
something good will come out of it.
|
||||
|
||||
You'll win someday!
|
||||
|
||||
In case you want to try again,
|
||||
come back to me once more.
|
||||
|
||||
|
||||
###########################################################
|
||||
|
||||
NPC: Coren Tsu - The Wanderer
|
||||
AREAS: Pioneer 2
|
||||
|
||||
Translations by: apexseals (discord: apexseals)
|
||||
Proofing & Debugging by: nolrinale (github.com/nolrinale)
|
||||
|
||||
###########################################################
|
||||
|
||||
presentation:
|
||||
|
||||
I am Coren Tsu, a wandering merchant,
|
||||
you could say.
|
||||
|
||||
Please take some time to look at
|
||||
the rare and wonderous goods
|
||||
I have been collecting.
|
||||
|
||||
If you spend a little meseta,
|
||||
you could win a wonderful prize.
|
||||
|
||||
Well? Wanna try?
|
||||
|
||||
|
||||
You may win,
|
||||
you may lose.
|
||||
|
||||
But if you don't win,
|
||||
don't take it out on me.
|
||||
|
||||
That's just the way
|
||||
gambling is, yes?
|
||||
|
||||
Well then, how much
|
||||
meseta do you want to pay?
|
||||
|
||||
As long as you pay me,
|
||||
I'll give you a great service.
|
||||
|
||||
|
||||
Huh?
|
||||
|
||||
That's too bad...
|
||||
|
||||
Well, these kind of things usually
|
||||
have a chance to lose money.
|
||||
|
||||
Let's keep this discreet.
|
||||
If you feel up to it, talk to me again.
|
||||
|
||||
|
||||
It seems you have
|
||||
too many items.
|
||||
|
||||
First, go and
|
||||
organize your items,
|
||||
|
||||
Then speak to me again.
|
||||
|
||||
What?
|
||||
|
||||
You said you'd try,
|
||||
then you said no.
|
||||
|
||||
People like that
|
||||
fail at everything.
|
||||
|
||||
|
||||
What the...?
|
||||
|
||||
You don't have the
|
||||
meseta to pay me?
|
||||
|
||||
I won't work with such
|
||||
cold hearted people.
|
||||
|
||||
|
||||
Alright, let's do it.
|
||||
|
||||
You better pray
|
||||
for something good...
|
||||
|
||||
|
||||
Look here!
|
||||
Take it!
|
||||
|
||||
Even if you had bad luck,
|
||||
something good will come out of it.
|
||||
|
||||
You'll win someday!
|
||||
|
||||
In case you want to try again,
|
||||
come back to me once more.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
inline void run_ar_code_translator(const std::string&, const std::string&, const std::string&) {
|
||||
throw std::runtime_error("resource_file is not available; install it and rebuild newserv");
|
||||
}
|
||||
|
||||
inline void run_xbe_patch_translator(const std::string&, const std::string&, const std::string&) {
|
||||
throw std::runtime_error("resource_file is not available; install it and rebuild newserv");
|
||||
}
|
||||
|
||||
inline std::vector<std::pair<uint32_t, std::string>> diff_dol_files(const std::string&, const std::string&) {
|
||||
throw std::runtime_error("resource_file is not available; install it and rebuild newserv");
|
||||
}
|
||||
@@ -1,640 +0,0 @@
|
||||
#include "ARCodeTranslator.hh"
|
||||
|
||||
#include <array>
|
||||
#include <future>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <resource_file/ExecutableFormats/DOLFile.hh>
|
||||
#include <resource_file/ExecutableFormats/XBEFile.hh>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class ARCodeTranslator {
|
||||
public:
|
||||
enum class ExpandMethod {
|
||||
FORWARD = 0,
|
||||
FORWARD_WITH_BARRIER,
|
||||
BACKWARD,
|
||||
BACKWARD_WITH_BARRIER,
|
||||
BOTH,
|
||||
BOTH_WITH_BARRIER,
|
||||
BOTH_IGNORE_ORIGIN,
|
||||
};
|
||||
|
||||
static const char* name_for_expand_method(ExpandMethod method) {
|
||||
switch (method) {
|
||||
case ExpandMethod::FORWARD:
|
||||
return "FORWARD";
|
||||
case ExpandMethod::FORWARD_WITH_BARRIER:
|
||||
return "FORWARD_WITH_BARRIER";
|
||||
case ExpandMethod::BACKWARD:
|
||||
return "BACKWARD";
|
||||
case ExpandMethod::BACKWARD_WITH_BARRIER:
|
||||
return "BACKWARD_WITH_BARRIER";
|
||||
case ExpandMethod::BOTH:
|
||||
return "BOTH";
|
||||
case ExpandMethod::BOTH_WITH_BARRIER:
|
||||
return "BOTH_WITH_BARRIER";
|
||||
case ExpandMethod::BOTH_IGNORE_ORIGIN:
|
||||
return "BOTH_IGNORE_ORIGIN";
|
||||
default:
|
||||
throw logic_error("invalid expand method");
|
||||
}
|
||||
}
|
||||
|
||||
ARCodeTranslator(const string& directory)
|
||||
: log("[ar-trans] "),
|
||||
directory(directory) {
|
||||
while (ends_with(this->directory, "/")) {
|
||||
this->directory.pop_back();
|
||||
}
|
||||
for (const auto& filename : list_directory(this->directory)) {
|
||||
if (ends_with(filename, ".dol")) {
|
||||
string name = filename.substr(0, filename.size() - 4);
|
||||
string path = directory + "/" + filename;
|
||||
this->files.emplace(name, make_shared<DOLFile>(path.c_str()));
|
||||
this->log.info("Loaded %s", name.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
~ARCodeTranslator() = default;
|
||||
|
||||
const string& get_source_filename() const {
|
||||
return this->src_filename;
|
||||
}
|
||||
void set_source_file(const string& filename) {
|
||||
this->src_filename = filename;
|
||||
this->src_file = this->files.at(this->src_filename);
|
||||
}
|
||||
|
||||
void find_rtoc_global_regs() const {
|
||||
for (const auto& it : this->files) {
|
||||
bool r2_high_found = false;
|
||||
bool r2_low_found = false;
|
||||
bool r13_high_found = false;
|
||||
bool r13_low_found = false;
|
||||
uint32_t r2 = 0;
|
||||
uint32_t r13 = 0;
|
||||
for (const auto& section : it.second->sections) {
|
||||
if (!section.is_text) {
|
||||
continue;
|
||||
}
|
||||
StringReader r(section.data);
|
||||
while (!r.eof() && r.where()) {
|
||||
uint32_t opcode = r.get_u32b();
|
||||
if ((opcode & 0xFFFF0000) == 0x3DA00000) {
|
||||
if (r13_high_found) {
|
||||
throw runtime_error("multiple values for r13_high");
|
||||
}
|
||||
r13_high_found = true;
|
||||
r13 |= (opcode << 16);
|
||||
} else if ((opcode & 0xFFFF0000) == 0x3C400000) {
|
||||
if (r2_high_found) {
|
||||
throw runtime_error("multiple values for r2_high");
|
||||
}
|
||||
r2_high_found = true;
|
||||
r2 |= (opcode << 16);
|
||||
} else if ((opcode & 0xFFFF0000) == 0x61AD0000) {
|
||||
if (r13_low_found) {
|
||||
throw runtime_error("multiple values for r13_low");
|
||||
}
|
||||
r13_low_found = true;
|
||||
r13 |= (opcode & 0xFFFF);
|
||||
} else if ((opcode & 0xFFFF0000) == 0x60420000) {
|
||||
if (r2_low_found) {
|
||||
throw runtime_error("multiple values for r2_low");
|
||||
}
|
||||
r2_low_found = true;
|
||||
r2 |= (opcode & 0xFFFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (r2_low_found && r2_high_found) {
|
||||
fprintf(stderr, "(%s) r2 = %08" PRIX32 "\n", it.first.c_str(), r2);
|
||||
} else {
|
||||
fprintf(stderr, "(%s) r2 = __MISSING__\n", it.first.c_str());
|
||||
}
|
||||
if (r13_low_found && r13_high_found) {
|
||||
fprintf(stderr, "(%s) r13 = %08" PRIX32 "\n", it.first.c_str(), r13);
|
||||
} else {
|
||||
fprintf(stderr, "(%s) r13 = __MISSING__\n", it.first.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t find_match(shared_ptr<const DOLFile> dest_file, uint32_t src_address, ExpandMethod expand_method) const {
|
||||
if (!this->src_file) {
|
||||
throw runtime_error("no source file selected");
|
||||
}
|
||||
|
||||
const DOLFile::Section* src_section = nullptr;
|
||||
for (const auto& sec : this->src_file->sections) {
|
||||
if (src_address >= sec.address && src_address < sec.address + sec.data.size()) {
|
||||
src_section = &sec;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!src_section) {
|
||||
throw runtime_error("source address not within any section");
|
||||
}
|
||||
|
||||
const char* method_token = this->name_for_expand_method(expand_method);
|
||||
|
||||
size_t src_offset = src_address - src_section->address;
|
||||
size_t src_bytes_available_before = src_offset;
|
||||
size_t src_bytes_available_after = src_section->data.size() - src_offset - 4;
|
||||
this->log.info("(find_match/%s) Source offset = %08zX with %zX/%zX bytes available before/after",
|
||||
method_token, src_offset, src_bytes_available_before, src_bytes_available_after);
|
||||
|
||||
size_t match_bytes_before = 0;
|
||||
size_t match_bytes_after = 0;
|
||||
while (match_bytes_before + match_bytes_after + 4 < 0x100) {
|
||||
size_t num_matches = 0;
|
||||
size_t last_match_address = 0;
|
||||
size_t match_length = match_bytes_before + match_bytes_after + 4;
|
||||
StringReader src_r(src_section->data.data() + src_offset - match_bytes_before, match_length);
|
||||
for (const auto& dest_section : dest_file->sections) {
|
||||
for (size_t dest_match_offset = 0;
|
||||
dest_match_offset < dest_section.data.size();
|
||||
dest_match_offset += 4) {
|
||||
src_r.go(0);
|
||||
StringReader dest_r(dest_section.data.data() + dest_match_offset, match_length);
|
||||
size_t z;
|
||||
for (z = 0; z < match_length; z += 4) {
|
||||
if (expand_method == ExpandMethod::BOTH_IGNORE_ORIGIN && z == match_bytes_before) {
|
||||
src_r.skip(4);
|
||||
dest_r.skip(4);
|
||||
} else if (src_section->is_text) {
|
||||
uint32_t src_opcode = src_r.get_u32b();
|
||||
uint32_t dest_opcode = dest_r.get_u32b();
|
||||
uint32_t src_class = src_opcode & 0xFC000000;
|
||||
if (src_class != (dest_opcode & 0xFC000000)) {
|
||||
break;
|
||||
}
|
||||
if (src_class == 0x48000000) {
|
||||
// b +-offset
|
||||
src_opcode &= 0xFC000003;
|
||||
dest_opcode &= 0xFC000003;
|
||||
} else if (((src_opcode & 0xAC1F0000) == 0x800D0000) || ((src_opcode & 0xAC1F0000) == 0x80020000)) {
|
||||
// lwz/lfs rXX/fXX, [r2/r13 +- offset] OR stw/stfs [r2/r13 +- offset], rXX/fXX
|
||||
src_opcode &= 0xFFFF0000;
|
||||
dest_opcode &= 0xFFFF0000;
|
||||
}
|
||||
if (src_opcode != dest_opcode) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
uint32_t src_data = src_r.get_u32b();
|
||||
uint32_t dest_data = dest_r.get_u32b();
|
||||
if ((src_data & 0xFE000000) == 0x80000000) {
|
||||
src_data &= 0xFE000003;
|
||||
}
|
||||
if ((dest_data & 0xFE000000) == 0x80000000) {
|
||||
dest_data &= 0xFE000003;
|
||||
}
|
||||
if (src_data != dest_data) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (z == match_length) {
|
||||
num_matches++;
|
||||
last_match_address = dest_section.address + dest_match_offset + match_bytes_before;
|
||||
}
|
||||
}
|
||||
}
|
||||
this->log.info("(find_match/%s) For match length %zX, %zu matches found", method_token, match_length, num_matches);
|
||||
if (num_matches == 1) {
|
||||
return last_match_address;
|
||||
} else if (num_matches == 0) {
|
||||
throw runtime_error("did not find exactly one match");
|
||||
}
|
||||
bool can_expand_backward = false;
|
||||
bool can_expand_forward = false;
|
||||
switch (expand_method) {
|
||||
case ExpandMethod::BACKWARD_WITH_BARRIER:
|
||||
can_expand_backward = (src_r.pget_u32b(0) != 0x4E800020) &&
|
||||
(src_bytes_available_before >= match_bytes_before + 4);
|
||||
break;
|
||||
case ExpandMethod::BACKWARD:
|
||||
can_expand_backward = (src_bytes_available_before >= match_bytes_before + 4);
|
||||
break;
|
||||
case ExpandMethod::FORWARD_WITH_BARRIER:
|
||||
can_expand_forward = (src_r.pget_u32b(src_r.size() - 4) != 0x4E800020) &&
|
||||
(src_bytes_available_after >= match_bytes_after + 4);
|
||||
break;
|
||||
case ExpandMethod::FORWARD:
|
||||
can_expand_forward = (src_bytes_available_after >= match_bytes_after + 4);
|
||||
break;
|
||||
case ExpandMethod::BOTH_WITH_BARRIER:
|
||||
case ExpandMethod::BOTH_IGNORE_ORIGIN:
|
||||
can_expand_backward = (src_r.pget_u32b(0) != 0x4E800020) &&
|
||||
(src_bytes_available_before >= match_bytes_before + 4);
|
||||
can_expand_forward = (src_r.pget_u32b(src_r.size() - 4) != 0x4E800020) &&
|
||||
(src_bytes_available_after >= match_bytes_after + 4);
|
||||
break;
|
||||
case ExpandMethod::BOTH:
|
||||
can_expand_backward = (src_bytes_available_before >= match_bytes_before + 4);
|
||||
can_expand_forward = (src_bytes_available_after >= match_bytes_after + 4);
|
||||
break;
|
||||
default:
|
||||
throw logic_error("invalid expand method");
|
||||
}
|
||||
if (!can_expand_backward && !can_expand_forward) {
|
||||
throw runtime_error("no further expansion is allowed");
|
||||
}
|
||||
if (can_expand_backward) {
|
||||
match_bytes_before += 4;
|
||||
}
|
||||
if (can_expand_forward) {
|
||||
match_bytes_after += 4;
|
||||
}
|
||||
}
|
||||
throw runtime_error("scan field too long; too many matches");
|
||||
}
|
||||
|
||||
void find_all_matches(uint32_t src_addr) const {
|
||||
if (!this->src_file) {
|
||||
throw runtime_error("no source file selected");
|
||||
}
|
||||
|
||||
unordered_map<string, uint32_t> results;
|
||||
for (const auto& it : this->files) {
|
||||
if (it.second == this->src_file) {
|
||||
log.info("(%s) %08" PRIX32 " (from source)", it.first.c_str(), src_addr);
|
||||
results.emplace(it.first, src_addr);
|
||||
} else {
|
||||
|
||||
array<future<uint32_t>, 7> futures;
|
||||
static const array<ExpandMethod, 7> methods = {
|
||||
ExpandMethod::FORWARD,
|
||||
ExpandMethod::FORWARD_WITH_BARRIER,
|
||||
ExpandMethod::BACKWARD,
|
||||
ExpandMethod::BACKWARD_WITH_BARRIER,
|
||||
ExpandMethod::BOTH,
|
||||
ExpandMethod::BOTH_WITH_BARRIER,
|
||||
ExpandMethod::BOTH_IGNORE_ORIGIN,
|
||||
};
|
||||
for (size_t z = 0; z < methods.size(); z++) {
|
||||
futures[z] = async(&ARCodeTranslator::find_match, this, it.second, src_addr, methods[z]);
|
||||
}
|
||||
|
||||
unordered_set<uint32_t> match_addrs;
|
||||
for (size_t z = 0; z < futures.size(); z++) {
|
||||
const char* method_name = this->name_for_expand_method(methods[z]);
|
||||
try {
|
||||
uint32_t ret = futures[z].get();
|
||||
log.info("(%s) (%s) %08" PRIX32, it.first.c_str(), method_name, ret);
|
||||
match_addrs.emplace(ret);
|
||||
} catch (const exception& e) {
|
||||
log.error("(%s) (%s) failed: %s", it.first.c_str(), method_name, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
if (match_addrs.empty()) {
|
||||
log.error("(%s) no match found", it.first.c_str());
|
||||
} else if (match_addrs.size() > 1) {
|
||||
log.error("(%s) different matches found by different methods", it.first.c_str());
|
||||
} else {
|
||||
results.emplace(it.first, *match_addrs.begin());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto& it : results) {
|
||||
fprintf(stdout, "%s => %08" PRIX32 "\n", it.first.c_str(), it.second);
|
||||
}
|
||||
}
|
||||
|
||||
void handle_command(const string& command) {
|
||||
auto tokens = split(command, ' ');
|
||||
if (tokens.empty()) {
|
||||
throw runtime_error("no command given");
|
||||
}
|
||||
strip_trailing_whitespace(tokens[tokens.size() - 1]);
|
||||
|
||||
if (tokens[0] == "use") {
|
||||
this->set_source_file(tokens.at(1));
|
||||
} else if (tokens[0] == "match") {
|
||||
this->find_all_matches(stoul(tokens.at(1), nullptr, 16));
|
||||
} else if (tokens[0] == "find-globals") {
|
||||
this->find_rtoc_global_regs();
|
||||
} else if (!tokens[0].empty()) {
|
||||
throw runtime_error("unknown command");
|
||||
}
|
||||
}
|
||||
|
||||
void run_shell() {
|
||||
while (!feof(stdin)) {
|
||||
if (!this->src_filename.empty()) {
|
||||
fprintf(stdout, "ar-trans:%s/%s> ", this->directory.c_str(), this->src_filename.c_str());
|
||||
} else {
|
||||
fprintf(stdout, "ar-trans:%s> ", this->directory.c_str());
|
||||
}
|
||||
fflush(stdout);
|
||||
|
||||
string command = fgets(stdin);
|
||||
try {
|
||||
this->handle_command(command);
|
||||
} catch (const exception& e) {
|
||||
this->log.error("Failed: %s", e.what());
|
||||
}
|
||||
}
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
|
||||
private:
|
||||
PrefixedLogger log;
|
||||
string directory;
|
||||
unordered_map<string, shared_ptr<const DOLFile>> files;
|
||||
string src_filename;
|
||||
shared_ptr<const DOLFile> src_file;
|
||||
};
|
||||
|
||||
class XBEPatchTranslator {
|
||||
public:
|
||||
enum class ExpandMethod {
|
||||
FORWARD = 0,
|
||||
BACKWARD,
|
||||
BOTH,
|
||||
};
|
||||
|
||||
static const char* name_for_expand_method(ExpandMethod method) {
|
||||
switch (method) {
|
||||
case ExpandMethod::FORWARD:
|
||||
return "FORWARD";
|
||||
case ExpandMethod::BACKWARD:
|
||||
return "BACKWARD";
|
||||
case ExpandMethod::BOTH:
|
||||
return "BOTH";
|
||||
default:
|
||||
throw logic_error("invalid expand method");
|
||||
}
|
||||
}
|
||||
|
||||
XBEPatchTranslator(const string& directory)
|
||||
: log("[xbe-trans] "),
|
||||
directory(directory) {
|
||||
while (ends_with(this->directory, "/")) {
|
||||
this->directory.pop_back();
|
||||
}
|
||||
for (const auto& filename : list_directory(this->directory)) {
|
||||
if (ends_with(filename, ".xbe")) {
|
||||
string name = filename.substr(0, filename.size() - 4);
|
||||
string path = directory + "/" + filename;
|
||||
this->files.emplace(name, make_shared<XBEFile>(path.c_str()));
|
||||
this->log.info("Loaded %s", name.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
~XBEPatchTranslator() = default;
|
||||
|
||||
const string& get_source_filename() const {
|
||||
return this->src_filename;
|
||||
}
|
||||
void set_source_file(const string& filename) {
|
||||
this->src_filename = filename;
|
||||
this->src_file = this->files.at(this->src_filename);
|
||||
}
|
||||
|
||||
uint32_t find_match(
|
||||
shared_ptr<const XBEFile> dest_file,
|
||||
uint32_t src_address,
|
||||
uint32_t src_size,
|
||||
ExpandMethod expand_method) const {
|
||||
if (!this->src_file) {
|
||||
throw runtime_error("no source file selected");
|
||||
}
|
||||
|
||||
const XBEFile::Section* src_section = nullptr;
|
||||
for (const auto& sec : this->src_file->sections) {
|
||||
if (src_address >= sec.addr && src_address < sec.addr + sec.file_size) {
|
||||
src_section = &sec;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!src_section) {
|
||||
throw runtime_error("source address not within any section");
|
||||
}
|
||||
|
||||
const char* method_token = this->name_for_expand_method(expand_method);
|
||||
|
||||
size_t src_offset = src_address - src_section->addr;
|
||||
size_t src_bytes_available_before = src_offset;
|
||||
size_t src_bytes_available_after = src_section->file_size - src_offset - src_size;
|
||||
this->log.info("(find_match/%s) Source offset = %08zX with %zX/%zX bytes available before/after",
|
||||
method_token, src_offset, src_bytes_available_before, src_bytes_available_after);
|
||||
|
||||
size_t match_bytes_before = 0;
|
||||
size_t match_bytes_after = 0;
|
||||
while (match_bytes_before + match_bytes_after + src_size < 0x100) {
|
||||
size_t num_matches = 0;
|
||||
size_t last_match_address = 0;
|
||||
size_t match_length = match_bytes_before + match_bytes_after + src_size;
|
||||
auto src_r = this->src_file->read_from_addr(src_section->addr + src_offset - match_bytes_before, match_length);
|
||||
for (const auto& dest_section : dest_file->sections) {
|
||||
for (size_t dest_match_offset = 0; dest_match_offset + match_length <= dest_section.file_size; dest_match_offset++) {
|
||||
src_r.go(0);
|
||||
StringReader dest_r = dest_file->read_from_addr(dest_section.addr + dest_match_offset, match_length);
|
||||
size_t z;
|
||||
for (z = 0; z < match_length; z++) {
|
||||
uint8_t src_data = src_r.get_u8();
|
||||
uint8_t dest_data = dest_r.get_u8();
|
||||
if (src_data != dest_data) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (z == match_length) {
|
||||
num_matches++;
|
||||
last_match_address = dest_section.addr + dest_match_offset + match_bytes_before;
|
||||
}
|
||||
}
|
||||
}
|
||||
this->log.info("(find_match/%s) For match length %zX, %zu matches found", method_token, match_length, num_matches);
|
||||
if (num_matches == 1) {
|
||||
return last_match_address;
|
||||
} else if (num_matches == 0) {
|
||||
throw runtime_error("did not find exactly one match");
|
||||
}
|
||||
bool can_expand_backward = false;
|
||||
bool can_expand_forward = false;
|
||||
switch (expand_method) {
|
||||
case ExpandMethod::BACKWARD:
|
||||
can_expand_backward = (src_bytes_available_before > match_bytes_before);
|
||||
break;
|
||||
case ExpandMethod::FORWARD:
|
||||
can_expand_forward = (src_bytes_available_after > match_bytes_after);
|
||||
break;
|
||||
case ExpandMethod::BOTH:
|
||||
can_expand_backward = (src_bytes_available_before > match_bytes_before);
|
||||
can_expand_forward = (src_bytes_available_after > match_bytes_after);
|
||||
break;
|
||||
default:
|
||||
throw logic_error("invalid expand method");
|
||||
}
|
||||
if (!can_expand_backward && !can_expand_forward) {
|
||||
throw runtime_error("no further expansion is allowed");
|
||||
}
|
||||
if (can_expand_backward) {
|
||||
match_bytes_before++;
|
||||
}
|
||||
if (can_expand_forward) {
|
||||
match_bytes_after++;
|
||||
}
|
||||
}
|
||||
throw runtime_error("scan field too long; too many matches");
|
||||
}
|
||||
|
||||
void find_all_matches(uint32_t src_addr, uint32_t src_size) const {
|
||||
if (!this->src_file) {
|
||||
throw runtime_error("no source file selected");
|
||||
}
|
||||
|
||||
unordered_map<string, uint32_t> results;
|
||||
for (const auto& it : files) {
|
||||
if (it.second == this->src_file) {
|
||||
log.info("(%s) %08" PRIX32 " (from source)", it.first.c_str(), src_addr);
|
||||
results.emplace(it.first, src_addr);
|
||||
} else {
|
||||
|
||||
array<future<uint32_t>, 3> futures;
|
||||
static const array<ExpandMethod, 3> methods = {
|
||||
ExpandMethod::FORWARD,
|
||||
ExpandMethod::BACKWARD,
|
||||
ExpandMethod::BOTH,
|
||||
};
|
||||
for (size_t z = 0; z < methods.size(); z++) {
|
||||
futures[z] = async(&XBEPatchTranslator::find_match, this, it.second, src_addr, src_size, methods[z]);
|
||||
}
|
||||
|
||||
unordered_set<uint32_t> match_addrs;
|
||||
for (size_t z = 0; z < futures.size(); z++) {
|
||||
const char* method_name = this->name_for_expand_method(methods[z]);
|
||||
try {
|
||||
uint32_t ret = futures[z].get();
|
||||
log.info("(%s) (%s) %08" PRIX32, it.first.c_str(), method_name, ret);
|
||||
match_addrs.emplace(ret);
|
||||
} catch (const exception& e) {
|
||||
log.error("(%s) (%s) failed: %s", it.first.c_str(), method_name, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
if (match_addrs.empty()) {
|
||||
log.error("(%s) no match found", it.first.c_str());
|
||||
} else if (match_addrs.size() > 1) {
|
||||
log.error("(%s) different matches found by different methods", it.first.c_str());
|
||||
} else {
|
||||
results.emplace(it.first, *match_addrs.begin());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto& it : results) {
|
||||
fprintf(stdout, "%s => %08" PRIX32 "\n", it.first.c_str(), it.second);
|
||||
}
|
||||
}
|
||||
|
||||
void handle_command(const string& command) {
|
||||
auto tokens = split(command, ' ');
|
||||
if (tokens.empty()) {
|
||||
throw runtime_error("no command given");
|
||||
}
|
||||
strip_trailing_whitespace(tokens[tokens.size() - 1]);
|
||||
|
||||
if (tokens[0] == "use") {
|
||||
this->set_source_file(tokens.at(1));
|
||||
} else if (tokens[0] == "match") {
|
||||
this->find_all_matches(stoul(tokens.at(1), nullptr, 16), stoul(tokens.at(2), nullptr, 16));
|
||||
} else if (!tokens[0].empty()) {
|
||||
throw runtime_error("unknown command");
|
||||
}
|
||||
}
|
||||
|
||||
void run_shell() {
|
||||
while (!feof(stdin)) {
|
||||
if (!this->src_filename.empty()) {
|
||||
fprintf(stdout, "ar-trans:%s/%s> ", this->directory.c_str(), this->src_filename.c_str());
|
||||
} else {
|
||||
fprintf(stdout, "ar-trans:%s> ", this->directory.c_str());
|
||||
}
|
||||
fflush(stdout);
|
||||
|
||||
string command = fgets(stdin);
|
||||
try {
|
||||
this->handle_command(command);
|
||||
} catch (const exception& e) {
|
||||
this->log.error("Failed: %s", e.what());
|
||||
}
|
||||
}
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
|
||||
private:
|
||||
PrefixedLogger log;
|
||||
string directory;
|
||||
unordered_map<string, shared_ptr<const XBEFile>> files;
|
||||
string src_filename;
|
||||
shared_ptr<const XBEFile> src_file;
|
||||
};
|
||||
|
||||
void run_ar_code_translator(const std::string& directory, const std::string& use_filename, const std::string& command) {
|
||||
ARCodeTranslator trans(directory);
|
||||
if (!use_filename.empty()) {
|
||||
trans.set_source_file(use_filename);
|
||||
}
|
||||
|
||||
if (!command.empty()) {
|
||||
trans.handle_command(command);
|
||||
} else {
|
||||
trans.run_shell();
|
||||
}
|
||||
}
|
||||
|
||||
void run_xbe_patch_translator(const std::string& directory, const std::string& use_filename, const std::string& command) {
|
||||
XBEPatchTranslator trans(directory);
|
||||
if (!use_filename.empty()) {
|
||||
trans.set_source_file(use_filename);
|
||||
}
|
||||
|
||||
if (!command.empty()) {
|
||||
trans.handle_command(command);
|
||||
} else {
|
||||
trans.run_shell();
|
||||
}
|
||||
}
|
||||
|
||||
vector<pair<uint32_t, string>> diff_dol_files(const string& a_filename, const string& b_filename) {
|
||||
DOLFile a(a_filename.c_str());
|
||||
DOLFile b(b_filename.c_str());
|
||||
auto a_mem = make_shared<MemoryContext>();
|
||||
auto b_mem = make_shared<MemoryContext>();
|
||||
a.load_into(a_mem);
|
||||
b.load_into(b_mem);
|
||||
|
||||
uint32_t min_addr = 0xFFFFFFFF;
|
||||
uint32_t max_addr = 0x00000000;
|
||||
for (const auto& sec : a.sections) {
|
||||
min_addr = min<uint32_t>(min_addr, sec.address);
|
||||
max_addr = max<uint32_t>(max_addr, sec.address + sec.data.size());
|
||||
}
|
||||
for (const auto& sec : b.sections) {
|
||||
min_addr = min<uint32_t>(min_addr, sec.address);
|
||||
max_addr = max<uint32_t>(max_addr, sec.address + sec.data.size());
|
||||
}
|
||||
|
||||
vector<pair<uint32_t, string>> ret;
|
||||
for (uint32_t addr = min_addr; addr < max_addr; addr += 4) {
|
||||
bool a_exists = a_mem->exists(addr, 4);
|
||||
bool b_exists = b_mem->exists(addr, 4);
|
||||
if (a_exists && b_exists) {
|
||||
string a_value = a_mem->read(addr, 4);
|
||||
string b_value = b_mem->read(addr, 4);
|
||||
if (a_value != b_value) {
|
||||
if (!ret.empty() && (ret.back().first + ret.back().second.size() == addr)) {
|
||||
ret.back().second += b_value;
|
||||
} else {
|
||||
ret.emplace_back(make_pair(addr, b_value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
void run_ar_code_translator(const std::string& directory, const std::string& use_filename, const std::string& command);
|
||||
void run_xbe_patch_translator(const std::string& directory, const std::string& use_filename, const std::string& command);
|
||||
std::vector<std::pair<uint32_t, std::string>> diff_dol_files(const std::string& a_filename, const std::string& b_filename);
|
||||
+1003
-1003
File diff suppressed because it is too large
Load Diff
+263
-263
@@ -1,263 +1,263 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <phosg/JSON.hh>
|
||||
#include <shared_mutex>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "Text.hh"
|
||||
|
||||
class LicenseIndex;
|
||||
|
||||
struct DCNTELicense {
|
||||
std::string serial_number;
|
||||
std::string access_key;
|
||||
|
||||
static std::shared_ptr<DCNTELicense> from_json(const JSON& json);
|
||||
JSON json() const;
|
||||
};
|
||||
|
||||
struct V1V2License {
|
||||
uint32_t serial_number = 0;
|
||||
std::string access_key;
|
||||
|
||||
static std::shared_ptr<V1V2License> from_json(const JSON& json);
|
||||
JSON json() const;
|
||||
};
|
||||
|
||||
struct GCLicense {
|
||||
uint32_t serial_number = 0;
|
||||
std::string access_key;
|
||||
std::string password;
|
||||
|
||||
static std::shared_ptr<GCLicense> from_json(const JSON& json);
|
||||
JSON json() const;
|
||||
};
|
||||
|
||||
struct XBLicense {
|
||||
std::string gamertag;
|
||||
uint64_t user_id = 0;
|
||||
uint64_t account_id = 0;
|
||||
|
||||
static std::shared_ptr<XBLicense> from_json(const JSON& json);
|
||||
JSON json() const;
|
||||
};
|
||||
|
||||
struct BBLicense {
|
||||
std::string username;
|
||||
std::string password;
|
||||
|
||||
static std::shared_ptr<BBLicense> from_json(const JSON& json);
|
||||
JSON json() const;
|
||||
};
|
||||
|
||||
struct Account {
|
||||
enum class Flag : uint32_t {
|
||||
// clang-format off
|
||||
KICK_USER = 0x00000001,
|
||||
BAN_USER = 0x00000002,
|
||||
SILENCE_USER = 0x00000004,
|
||||
CHANGE_EVENT = 0x00000010,
|
||||
ANNOUNCE = 0x00000020,
|
||||
FREE_JOIN_GAMES = 0x00000040,
|
||||
DEBUG = 0x01000000,
|
||||
CHEAT_ANYWHERE = 0x02000000,
|
||||
DISABLE_QUEST_REQUIREMENTS = 0x04000000,
|
||||
ALWAYS_ENABLE_CHAT_COMMANDS = 0x08000000,
|
||||
MODERATOR = 0x00000007,
|
||||
ADMINISTRATOR = 0x000000FF,
|
||||
ROOT = 0x7FFFFFFF,
|
||||
IS_SHARED_ACCOUNT = 0x80000000,
|
||||
// NOTE: When adding or changing license flags, don't forget to change the
|
||||
// documentation in the shell's help text.
|
||||
UNUSED_BITS = 0x70FFFF00,
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
// account_id is also the account's guild card number
|
||||
uint32_t account_id = 0;
|
||||
|
||||
uint32_t flags = 0;
|
||||
uint64_t ban_end_time = 0; // 0 = not banned
|
||||
std::string last_player_name;
|
||||
std::string auto_reply_message;
|
||||
|
||||
uint32_t ep3_current_meseta = 0;
|
||||
uint32_t ep3_total_meseta_earned = 0;
|
||||
|
||||
uint32_t bb_team_id = 0;
|
||||
bool is_temporary = false; // If true, isn't saved to disk
|
||||
|
||||
std::unordered_set<std::string> auto_patches_enabled;
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<DCNTELicense>> dc_nte_licenses;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<V1V2License>> dc_licenses;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<V1V2License>> pc_licenses;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<GCLicense>> gc_licenses;
|
||||
std::unordered_map<std::string, std::shared_ptr<XBLicense>> xb_licenses;
|
||||
std::unordered_map<std::string, std::shared_ptr<BBLicense>> bb_licenses;
|
||||
|
||||
Account() = default;
|
||||
explicit Account(const JSON& json);
|
||||
virtual ~Account() = default;
|
||||
|
||||
JSON json() const;
|
||||
virtual void save() const;
|
||||
virtual void delete_file() const;
|
||||
|
||||
[[nodiscard]] inline bool check_flag(Flag flag) const {
|
||||
return !!(this->flags & static_cast<uint32_t>(flag));
|
||||
}
|
||||
inline void set_flag(Flag flag) {
|
||||
this->flags |= static_cast<uint32_t>(flag);
|
||||
}
|
||||
inline void clear_flag(Flag flag) {
|
||||
this->flags &= (~static_cast<uint32_t>(flag));
|
||||
}
|
||||
inline void toggle_flag(Flag flag) {
|
||||
this->flags ^= static_cast<uint32_t>(flag);
|
||||
}
|
||||
inline void replace_all_flags(Flag mask) {
|
||||
this->flags = static_cast<uint32_t>(mask);
|
||||
}
|
||||
|
||||
void print(FILE* stream) const;
|
||||
};
|
||||
|
||||
struct Login {
|
||||
bool account_was_created = false;
|
||||
// This field will never be null
|
||||
std::shared_ptr<Account> account;
|
||||
// Exactly one of the following will be non-null, representing the license
|
||||
// that the client logged in with
|
||||
std::shared_ptr<DCNTELicense> dc_nte_license;
|
||||
std::shared_ptr<V1V2License> dc_license;
|
||||
std::shared_ptr<V1V2License> pc_license;
|
||||
std::shared_ptr<GCLicense> gc_license;
|
||||
std::shared_ptr<XBLicense> xb_license;
|
||||
std::shared_ptr<BBLicense> bb_license;
|
||||
};
|
||||
|
||||
class AccountIndex {
|
||||
public:
|
||||
class no_username : public std::invalid_argument {
|
||||
public:
|
||||
no_username() : invalid_argument("serial number is zero or username is missing") {}
|
||||
};
|
||||
class incorrect_password : public std::invalid_argument {
|
||||
public:
|
||||
incorrect_password() : invalid_argument("incorrect password") {}
|
||||
};
|
||||
class incorrect_access_key : public std::invalid_argument {
|
||||
public:
|
||||
incorrect_access_key() : invalid_argument("incorrect access key") {}
|
||||
};
|
||||
class missing_account : public std::invalid_argument {
|
||||
public:
|
||||
missing_account() : invalid_argument("missing account") {}
|
||||
};
|
||||
|
||||
explicit AccountIndex(bool force_all_temporary);
|
||||
virtual ~AccountIndex() = default;
|
||||
|
||||
std::shared_ptr<Account> create_account(bool is_temporary) const;
|
||||
|
||||
size_t count() const;
|
||||
std::vector<std::shared_ptr<Account>> all() const;
|
||||
|
||||
void add(std::shared_ptr<Account> a);
|
||||
void remove(uint32_t serial_number);
|
||||
|
||||
void add_dc_nte_license(std::shared_ptr<Account> account, std::shared_ptr<DCNTELicense> license);
|
||||
void add_dc_license(std::shared_ptr<Account> account, std::shared_ptr<V1V2License> license);
|
||||
void add_pc_license(std::shared_ptr<Account> account, std::shared_ptr<V1V2License> license);
|
||||
void add_gc_license(std::shared_ptr<Account> account, std::shared_ptr<GCLicense> license);
|
||||
void add_xb_license(std::shared_ptr<Account> account, std::shared_ptr<XBLicense> license);
|
||||
void add_bb_license(std::shared_ptr<Account> account, std::shared_ptr<BBLicense> license);
|
||||
void remove_dc_nte_license(std::shared_ptr<Account> account, const std::string& serial_number);
|
||||
void remove_dc_license(std::shared_ptr<Account> account, uint32_t serial_number);
|
||||
void remove_pc_license(std::shared_ptr<Account> account, uint32_t serial_number);
|
||||
void remove_gc_license(std::shared_ptr<Account> account, uint32_t serial_number);
|
||||
void remove_xb_license(std::shared_ptr<Account> account, const std::string& gamertag);
|
||||
void remove_bb_license(std::shared_ptr<Account> account, const std::string& username);
|
||||
|
||||
std::shared_ptr<Account> from_account_id(uint32_t account_id) const;
|
||||
std::shared_ptr<Login> from_dc_nte_credentials(
|
||||
const std::string& serial_number,
|
||||
const std::string& access_key,
|
||||
bool allow_create);
|
||||
std::shared_ptr<Login> from_dc_credentials(
|
||||
uint32_t serial_number,
|
||||
const std::string& access_key,
|
||||
const std::string& character_name,
|
||||
bool allow_create);
|
||||
std::shared_ptr<Login> from_pc_nte_credentials(
|
||||
uint32_t guild_card_number,
|
||||
bool allow_create);
|
||||
std::shared_ptr<Login> from_pc_credentials(
|
||||
uint32_t serial_number,
|
||||
const std::string& access_key,
|
||||
const std::string& character_name,
|
||||
bool allow_create);
|
||||
std::shared_ptr<Login> from_gc_credentials(
|
||||
uint32_t serial_number,
|
||||
const std::string& access_key,
|
||||
const std::string* password,
|
||||
const std::string& character_name,
|
||||
bool allow_create);
|
||||
std::shared_ptr<Login> from_xb_credentials(
|
||||
const std::string& gamertag,
|
||||
uint64_t user_id,
|
||||
uint64_t account_id,
|
||||
bool allow_create);
|
||||
std::shared_ptr<Login> from_bb_credentials(
|
||||
const std::string& username,
|
||||
const std::string* password,
|
||||
bool allow_create);
|
||||
|
||||
std::shared_ptr<Account> create_temporary_account_for_shared_account(
|
||||
std::shared_ptr<const Account> src_a, const std::string& variation_data) const;
|
||||
|
||||
protected:
|
||||
bool force_all_temporary;
|
||||
|
||||
// This class must be thread-safe because it's used by both the patch server
|
||||
// and game server threads
|
||||
mutable std::shared_mutex lock;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<Account>> by_account_id;
|
||||
std::unordered_map<std::string, std::shared_ptr<Account>> by_dc_nte_serial_number;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<Account>> by_dc_serial_number;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<Account>> by_pc_serial_number;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<Account>> by_gc_serial_number;
|
||||
std::unordered_map<std::string, std::shared_ptr<Account>> by_xb_gamertag;
|
||||
std::unordered_map<std::string, std::shared_ptr<Account>> by_bb_username;
|
||||
|
||||
void add_locked(std::shared_ptr<Account> a);
|
||||
|
||||
std::shared_ptr<Login> from_dc_nte_credentials_locked(
|
||||
const std::string& serial_number,
|
||||
const std::string& access_key);
|
||||
std::shared_ptr<Login> from_dc_credentials_locked(
|
||||
uint32_t serial_number,
|
||||
const std::string& access_key,
|
||||
const std::string& character_name);
|
||||
std::shared_ptr<Login> from_pc_credentials_locked(
|
||||
uint32_t serial_number,
|
||||
const std::string& access_key,
|
||||
const std::string& character_name);
|
||||
std::shared_ptr<Login> from_gc_credentials_locked(
|
||||
uint32_t serial_number,
|
||||
const std::string& access_key,
|
||||
const std::string* password,
|
||||
const std::string& character_name);
|
||||
std::shared_ptr<Login> from_xb_credentials_locked(
|
||||
const std::string& gamertag,
|
||||
uint64_t user_id,
|
||||
uint64_t account_id);
|
||||
std::shared_ptr<Login> from_bb_credentials_locked(
|
||||
const std::string& username,
|
||||
const std::string* password);
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <phosg/JSON.hh>
|
||||
#include <shared_mutex>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "Text.hh"
|
||||
|
||||
class LicenseIndex;
|
||||
|
||||
struct DCNTELicense {
|
||||
std::string serial_number;
|
||||
std::string access_key;
|
||||
|
||||
static std::shared_ptr<DCNTELicense> from_json(const JSON& json);
|
||||
JSON json() const;
|
||||
};
|
||||
|
||||
struct V1V2License {
|
||||
uint32_t serial_number = 0;
|
||||
std::string access_key;
|
||||
|
||||
static std::shared_ptr<V1V2License> from_json(const JSON& json);
|
||||
JSON json() const;
|
||||
};
|
||||
|
||||
struct GCLicense {
|
||||
uint32_t serial_number = 0;
|
||||
std::string access_key;
|
||||
std::string password;
|
||||
|
||||
static std::shared_ptr<GCLicense> from_json(const JSON& json);
|
||||
JSON json() const;
|
||||
};
|
||||
|
||||
struct XBLicense {
|
||||
std::string gamertag;
|
||||
uint64_t user_id = 0;
|
||||
uint64_t account_id = 0;
|
||||
|
||||
static std::shared_ptr<XBLicense> from_json(const JSON& json);
|
||||
JSON json() const;
|
||||
};
|
||||
|
||||
struct BBLicense {
|
||||
std::string username;
|
||||
std::string password;
|
||||
|
||||
static std::shared_ptr<BBLicense> from_json(const JSON& json);
|
||||
JSON json() const;
|
||||
};
|
||||
|
||||
struct Account {
|
||||
enum class Flag : uint32_t {
|
||||
// clang-format off
|
||||
KICK_USER = 0x00000001,
|
||||
BAN_USER = 0x00000002,
|
||||
SILENCE_USER = 0x00000004,
|
||||
CHANGE_EVENT = 0x00000010,
|
||||
ANNOUNCE = 0x00000020,
|
||||
FREE_JOIN_GAMES = 0x00000040,
|
||||
DEBUG = 0x01000000,
|
||||
CHEAT_ANYWHERE = 0x02000000,
|
||||
DISABLE_QUEST_REQUIREMENTS = 0x04000000,
|
||||
ALWAYS_ENABLE_CHAT_COMMANDS = 0x08000000,
|
||||
MODERATOR = 0x00000007,
|
||||
ADMINISTRATOR = 0x000000FF,
|
||||
ROOT = 0x7FFFFFFF,
|
||||
IS_SHARED_ACCOUNT = 0x80000000,
|
||||
// NOTE: When adding or changing license flags, don't forget to change the
|
||||
// documentation in the shell's help text.
|
||||
UNUSED_BITS = 0x70FFFF00,
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
// account_id is also the account's guild card number
|
||||
uint32_t account_id = 0;
|
||||
|
||||
uint32_t flags = 0;
|
||||
uint64_t ban_end_time = 0; // 0 = not banned
|
||||
std::string last_player_name;
|
||||
std::string auto_reply_message;
|
||||
|
||||
uint32_t ep3_current_meseta = 0;
|
||||
uint32_t ep3_total_meseta_earned = 0;
|
||||
|
||||
uint32_t bb_team_id = 0;
|
||||
bool is_temporary = false; // If true, isn't saved to disk
|
||||
|
||||
std::unordered_set<std::string> auto_patches_enabled;
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<DCNTELicense>> dc_nte_licenses;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<V1V2License>> dc_licenses;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<V1V2License>> pc_licenses;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<GCLicense>> gc_licenses;
|
||||
std::unordered_map<std::string, std::shared_ptr<XBLicense>> xb_licenses;
|
||||
std::unordered_map<std::string, std::shared_ptr<BBLicense>> bb_licenses;
|
||||
|
||||
Account() = default;
|
||||
explicit Account(const JSON& json);
|
||||
virtual ~Account() = default;
|
||||
|
||||
JSON json() const;
|
||||
virtual void save() const;
|
||||
virtual void delete_file() const;
|
||||
|
||||
[[nodiscard]] inline bool check_flag(Flag flag) const {
|
||||
return !!(this->flags & static_cast<uint32_t>(flag));
|
||||
}
|
||||
inline void set_flag(Flag flag) {
|
||||
this->flags |= static_cast<uint32_t>(flag);
|
||||
}
|
||||
inline void clear_flag(Flag flag) {
|
||||
this->flags &= (~static_cast<uint32_t>(flag));
|
||||
}
|
||||
inline void toggle_flag(Flag flag) {
|
||||
this->flags ^= static_cast<uint32_t>(flag);
|
||||
}
|
||||
inline void replace_all_flags(Flag mask) {
|
||||
this->flags = static_cast<uint32_t>(mask);
|
||||
}
|
||||
|
||||
void print(FILE* stream) const;
|
||||
};
|
||||
|
||||
struct Login {
|
||||
bool account_was_created = false;
|
||||
// This field will never be null
|
||||
std::shared_ptr<Account> account;
|
||||
// Exactly one of the following will be non-null, representing the license
|
||||
// that the client logged in with
|
||||
std::shared_ptr<DCNTELicense> dc_nte_license;
|
||||
std::shared_ptr<V1V2License> dc_license;
|
||||
std::shared_ptr<V1V2License> pc_license;
|
||||
std::shared_ptr<GCLicense> gc_license;
|
||||
std::shared_ptr<XBLicense> xb_license;
|
||||
std::shared_ptr<BBLicense> bb_license;
|
||||
};
|
||||
|
||||
class AccountIndex {
|
||||
public:
|
||||
class no_username : public std::invalid_argument {
|
||||
public:
|
||||
no_username() : invalid_argument("serial number is zero or username is missing") {}
|
||||
};
|
||||
class incorrect_password : public std::invalid_argument {
|
||||
public:
|
||||
incorrect_password() : invalid_argument("incorrect password") {}
|
||||
};
|
||||
class incorrect_access_key : public std::invalid_argument {
|
||||
public:
|
||||
incorrect_access_key() : invalid_argument("incorrect access key") {}
|
||||
};
|
||||
class missing_account : public std::invalid_argument {
|
||||
public:
|
||||
missing_account() : invalid_argument("missing account") {}
|
||||
};
|
||||
|
||||
explicit AccountIndex(bool force_all_temporary);
|
||||
virtual ~AccountIndex() = default;
|
||||
|
||||
std::shared_ptr<Account> create_account(bool is_temporary) const;
|
||||
|
||||
size_t count() const;
|
||||
std::vector<std::shared_ptr<Account>> all() const;
|
||||
|
||||
void add(std::shared_ptr<Account> a);
|
||||
void remove(uint32_t serial_number);
|
||||
|
||||
void add_dc_nte_license(std::shared_ptr<Account> account, std::shared_ptr<DCNTELicense> license);
|
||||
void add_dc_license(std::shared_ptr<Account> account, std::shared_ptr<V1V2License> license);
|
||||
void add_pc_license(std::shared_ptr<Account> account, std::shared_ptr<V1V2License> license);
|
||||
void add_gc_license(std::shared_ptr<Account> account, std::shared_ptr<GCLicense> license);
|
||||
void add_xb_license(std::shared_ptr<Account> account, std::shared_ptr<XBLicense> license);
|
||||
void add_bb_license(std::shared_ptr<Account> account, std::shared_ptr<BBLicense> license);
|
||||
void remove_dc_nte_license(std::shared_ptr<Account> account, const std::string& serial_number);
|
||||
void remove_dc_license(std::shared_ptr<Account> account, uint32_t serial_number);
|
||||
void remove_pc_license(std::shared_ptr<Account> account, uint32_t serial_number);
|
||||
void remove_gc_license(std::shared_ptr<Account> account, uint32_t serial_number);
|
||||
void remove_xb_license(std::shared_ptr<Account> account, const std::string& gamertag);
|
||||
void remove_bb_license(std::shared_ptr<Account> account, const std::string& username);
|
||||
|
||||
std::shared_ptr<Account> from_account_id(uint32_t account_id) const;
|
||||
std::shared_ptr<Login> from_dc_nte_credentials(
|
||||
const std::string& serial_number,
|
||||
const std::string& access_key,
|
||||
bool allow_create);
|
||||
std::shared_ptr<Login> from_dc_credentials(
|
||||
uint32_t serial_number,
|
||||
const std::string& access_key,
|
||||
const std::string& character_name,
|
||||
bool allow_create);
|
||||
std::shared_ptr<Login> from_pc_nte_credentials(
|
||||
uint32_t guild_card_number,
|
||||
bool allow_create);
|
||||
std::shared_ptr<Login> from_pc_credentials(
|
||||
uint32_t serial_number,
|
||||
const std::string& access_key,
|
||||
const std::string& character_name,
|
||||
bool allow_create);
|
||||
std::shared_ptr<Login> from_gc_credentials(
|
||||
uint32_t serial_number,
|
||||
const std::string& access_key,
|
||||
const std::string* password,
|
||||
const std::string& character_name,
|
||||
bool allow_create);
|
||||
std::shared_ptr<Login> from_xb_credentials(
|
||||
const std::string& gamertag,
|
||||
uint64_t user_id,
|
||||
uint64_t account_id,
|
||||
bool allow_create);
|
||||
std::shared_ptr<Login> from_bb_credentials(
|
||||
const std::string& username,
|
||||
const std::string* password,
|
||||
bool allow_create);
|
||||
|
||||
std::shared_ptr<Account> create_temporary_account_for_shared_account(
|
||||
std::shared_ptr<const Account> src_a, const std::string& variation_data) const;
|
||||
|
||||
protected:
|
||||
bool force_all_temporary;
|
||||
|
||||
// This class must be thread-safe because it's used by both the patch server
|
||||
// and game server threads
|
||||
mutable std::shared_mutex lock;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<Account>> by_account_id;
|
||||
std::unordered_map<std::string, std::shared_ptr<Account>> by_dc_nte_serial_number;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<Account>> by_dc_serial_number;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<Account>> by_pc_serial_number;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<Account>> by_gc_serial_number;
|
||||
std::unordered_map<std::string, std::shared_ptr<Account>> by_xb_gamertag;
|
||||
std::unordered_map<std::string, std::shared_ptr<Account>> by_bb_username;
|
||||
|
||||
void add_locked(std::shared_ptr<Account> a);
|
||||
|
||||
std::shared_ptr<Login> from_dc_nte_credentials_locked(
|
||||
const std::string& serial_number,
|
||||
const std::string& access_key);
|
||||
std::shared_ptr<Login> from_dc_credentials_locked(
|
||||
uint32_t serial_number,
|
||||
const std::string& access_key,
|
||||
const std::string& character_name);
|
||||
std::shared_ptr<Login> from_pc_credentials_locked(
|
||||
uint32_t serial_number,
|
||||
const std::string& access_key,
|
||||
const std::string& character_name);
|
||||
std::shared_ptr<Login> from_gc_credentials_locked(
|
||||
uint32_t serial_number,
|
||||
const std::string& access_key,
|
||||
const std::string* password,
|
||||
const std::string& character_name);
|
||||
std::shared_ptr<Login> from_xb_credentials_locked(
|
||||
const std::string& gamertag,
|
||||
uint64_t user_id,
|
||||
uint64_t account_id);
|
||||
std::shared_ptr<Login> from_bb_credentials_locked(
|
||||
const std::string& username,
|
||||
const std::string* password);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
inline void run_address_translator(const std::string&, const std::string&, const std::string&) {
|
||||
throw std::runtime_error("resource_file is not available; install it and rebuild newserv");
|
||||
}
|
||||
|
||||
inline std::vector<std::pair<uint32_t, std::string>> diff_dol_files(const std::string&, const std::string&) {
|
||||
throw std::runtime_error("resource_file is not available; install it and rebuild newserv");
|
||||
}
|
||||
@@ -0,0 +1,528 @@
|
||||
#include "AddressTranslator.hh"
|
||||
|
||||
#include <array>
|
||||
#include <future>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <resource_file/ExecutableFormats/DOLFile.hh>
|
||||
#include <resource_file/ExecutableFormats/XBEFile.hh>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class AddressTranslator {
|
||||
public:
|
||||
enum class ExpandMethod {
|
||||
PPC_TEXT_FORWARD = 0,
|
||||
PPC_TEXT_FORWARD_WITH_BARRIER,
|
||||
PPC_TEXT_BACKWARD,
|
||||
PPC_TEXT_BACKWARD_WITH_BARRIER,
|
||||
PPC_TEXT_BOTH,
|
||||
PPC_TEXT_BOTH_WITH_BARRIER,
|
||||
PPC_TEXT_BOTH_IGNORE_ORIGIN,
|
||||
PPC_DATA_FORWARD,
|
||||
PPC_DATA_BACKWARD,
|
||||
PPC_DATA_BOTH,
|
||||
RAW_FORWARD,
|
||||
RAW_BACKWARD,
|
||||
RAW_BOTH,
|
||||
};
|
||||
|
||||
static const char* name_for_expand_method(ExpandMethod method) {
|
||||
switch (method) {
|
||||
case ExpandMethod::PPC_TEXT_FORWARD:
|
||||
return "PPC_TEXT_FORWARD";
|
||||
case ExpandMethod::PPC_TEXT_FORWARD_WITH_BARRIER:
|
||||
return "PPC_TEXT_FORWARD_WITH_BARRIER";
|
||||
case ExpandMethod::PPC_TEXT_BACKWARD:
|
||||
return "PPC_TEXT_BACKWARD";
|
||||
case ExpandMethod::PPC_TEXT_BACKWARD_WITH_BARRIER:
|
||||
return "PPC_TEXT_BACKWARD_WITH_BARRIER";
|
||||
case ExpandMethod::PPC_TEXT_BOTH:
|
||||
return "PPC_TEXT_BOTH";
|
||||
case ExpandMethod::PPC_TEXT_BOTH_WITH_BARRIER:
|
||||
return "PPC_TEXT_BOTH_WITH_BARRIER";
|
||||
case ExpandMethod::PPC_TEXT_BOTH_IGNORE_ORIGIN:
|
||||
return "PPC_TEXT_BOTH_IGNORE_ORIGIN";
|
||||
case ExpandMethod::PPC_DATA_FORWARD:
|
||||
return "PPC_DATA_FORWARD";
|
||||
case ExpandMethod::PPC_DATA_BACKWARD:
|
||||
return "PPC_DATA_BACKWARD";
|
||||
case ExpandMethod::PPC_DATA_BOTH:
|
||||
return "PPC_DATA_BOTH";
|
||||
case ExpandMethod::RAW_FORWARD:
|
||||
return "RAW_FORWARD";
|
||||
case ExpandMethod::RAW_BACKWARD:
|
||||
return "RAW_BACKWARD";
|
||||
case ExpandMethod::RAW_BOTH:
|
||||
return "RAW_BOTH";
|
||||
default:
|
||||
throw logic_error("invalid expand method");
|
||||
}
|
||||
}
|
||||
|
||||
static bool is_ppc_expand_method(ExpandMethod method) {
|
||||
switch (method) {
|
||||
case ExpandMethod::PPC_TEXT_FORWARD:
|
||||
case ExpandMethod::PPC_TEXT_FORWARD_WITH_BARRIER:
|
||||
case ExpandMethod::PPC_TEXT_BACKWARD:
|
||||
case ExpandMethod::PPC_TEXT_BACKWARD_WITH_BARRIER:
|
||||
case ExpandMethod::PPC_TEXT_BOTH:
|
||||
case ExpandMethod::PPC_TEXT_BOTH_WITH_BARRIER:
|
||||
case ExpandMethod::PPC_TEXT_BOTH_IGNORE_ORIGIN:
|
||||
case ExpandMethod::PPC_DATA_FORWARD:
|
||||
case ExpandMethod::PPC_DATA_BACKWARD:
|
||||
case ExpandMethod::PPC_DATA_BOTH:
|
||||
return true;
|
||||
case ExpandMethod::RAW_FORWARD:
|
||||
case ExpandMethod::RAW_BACKWARD:
|
||||
case ExpandMethod::RAW_BOTH:
|
||||
return false;
|
||||
default:
|
||||
throw logic_error("invalid expand method");
|
||||
}
|
||||
}
|
||||
|
||||
static bool is_ppc_data_expand_method(ExpandMethod method) {
|
||||
switch (method) {
|
||||
case ExpandMethod::PPC_DATA_FORWARD:
|
||||
case ExpandMethod::PPC_DATA_BACKWARD:
|
||||
case ExpandMethod::PPC_DATA_BOTH:
|
||||
return true;
|
||||
case ExpandMethod::PPC_TEXT_FORWARD:
|
||||
case ExpandMethod::PPC_TEXT_FORWARD_WITH_BARRIER:
|
||||
case ExpandMethod::PPC_TEXT_BACKWARD:
|
||||
case ExpandMethod::PPC_TEXT_BACKWARD_WITH_BARRIER:
|
||||
case ExpandMethod::PPC_TEXT_BOTH:
|
||||
case ExpandMethod::PPC_TEXT_BOTH_WITH_BARRIER:
|
||||
case ExpandMethod::PPC_TEXT_BOTH_IGNORE_ORIGIN:
|
||||
case ExpandMethod::RAW_FORWARD:
|
||||
case ExpandMethod::RAW_BACKWARD:
|
||||
case ExpandMethod::RAW_BOTH:
|
||||
return false;
|
||||
default:
|
||||
throw logic_error("invalid expand method");
|
||||
}
|
||||
}
|
||||
|
||||
AddressTranslator(const string& directory)
|
||||
: log("[addr-trans] "),
|
||||
directory(directory),
|
||||
enable_ppc(false) {
|
||||
while (ends_with(this->directory, "/")) {
|
||||
this->directory.pop_back();
|
||||
}
|
||||
for (const auto& filename : list_directory(this->directory)) {
|
||||
if (ends_with(filename, ".dol")) {
|
||||
string name = filename.substr(0, filename.size() - 4);
|
||||
string path = directory + "/" + filename;
|
||||
DOLFile dol(path.c_str());
|
||||
auto mem = make_shared<MemoryContext>();
|
||||
dol.load_into(mem);
|
||||
this->mems.emplace(name, mem);
|
||||
this->enable_ppc = true;
|
||||
this->log.info("Loaded %s", name.c_str());
|
||||
} else if (ends_with(filename, ".xbe")) {
|
||||
string name = filename.substr(0, filename.size() - 4);
|
||||
string path = directory + "/" + filename;
|
||||
XBEFile xbe(path.c_str());
|
||||
auto mem = make_shared<MemoryContext>();
|
||||
xbe.load_into(mem);
|
||||
this->mems.emplace(name, mem);
|
||||
this->log.info("Loaded %s", name.c_str());
|
||||
} else if (ends_with(filename, ".bin")) {
|
||||
string name = filename.substr(0, filename.size() - 4);
|
||||
string path = directory + "/" + filename;
|
||||
string data = load_file(path);
|
||||
auto mem = make_shared<MemoryContext>();
|
||||
mem->allocate_at(0x8C010000, data.size());
|
||||
mem->memcpy(0x8C010000, data.data(), data.size());
|
||||
this->mems.emplace(name, mem);
|
||||
this->log.info("Loaded %s", name.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
~AddressTranslator() = default;
|
||||
|
||||
const string& get_source_filename() const {
|
||||
return this->src_filename;
|
||||
}
|
||||
void set_source_file(const string& filename) {
|
||||
this->src_filename = filename;
|
||||
this->src_mem = this->mems.at(this->src_filename);
|
||||
}
|
||||
|
||||
void find_ppc_rtoc_global_regs() const {
|
||||
for (const auto& it : this->mems) {
|
||||
bool r2_high_found = false;
|
||||
bool r2_low_found = false;
|
||||
bool r13_high_found = false;
|
||||
bool r13_low_found = false;
|
||||
uint32_t r2 = 0;
|
||||
uint32_t r13 = 0;
|
||||
for (const auto& block : it.second->allocated_blocks()) {
|
||||
StringReader r = it.second->reader(block.first, block.second);
|
||||
while (!r.eof() && r.where()) {
|
||||
uint32_t opcode = r.get_u32b();
|
||||
if ((opcode & 0xFFFF0000) == 0x3DA00000) {
|
||||
if (r13_high_found) {
|
||||
throw runtime_error("multiple values for r13_high");
|
||||
}
|
||||
r13_high_found = true;
|
||||
r13 |= (opcode << 16);
|
||||
} else if ((opcode & 0xFFFF0000) == 0x3C400000) {
|
||||
if (r2_high_found) {
|
||||
throw runtime_error("multiple values for r2_high");
|
||||
}
|
||||
r2_high_found = true;
|
||||
r2 |= (opcode << 16);
|
||||
} else if ((opcode & 0xFFFF0000) == 0x61AD0000) {
|
||||
if (r13_low_found) {
|
||||
throw runtime_error("multiple values for r13_low");
|
||||
}
|
||||
r13_low_found = true;
|
||||
r13 |= (opcode & 0xFFFF);
|
||||
} else if ((opcode & 0xFFFF0000) == 0x60420000) {
|
||||
if (r2_low_found) {
|
||||
throw runtime_error("multiple values for r2_low");
|
||||
}
|
||||
r2_low_found = true;
|
||||
r2 |= (opcode & 0xFFFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (r2_low_found && r2_high_found) {
|
||||
fprintf(stderr, "(%s) r2 = %08" PRIX32 "\n", it.first.c_str(), r2);
|
||||
} else {
|
||||
fprintf(stderr, "(%s) r2 = __MISSING__\n", it.first.c_str());
|
||||
}
|
||||
if (r13_low_found && r13_high_found) {
|
||||
fprintf(stderr, "(%s) r13 = %08" PRIX32 "\n", it.first.c_str(), r13);
|
||||
} else {
|
||||
fprintf(stderr, "(%s) r13 = __MISSING__\n", it.first.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t find_match(
|
||||
shared_ptr<const MemoryContext> dest_mem,
|
||||
uint32_t src_addr,
|
||||
uint32_t src_size,
|
||||
ExpandMethod expand_method) const {
|
||||
bool is_ppc = this->is_ppc_expand_method(expand_method);
|
||||
bool is_ppc_data = this->is_ppc_data_expand_method(expand_method);
|
||||
if (!this->src_mem) {
|
||||
throw runtime_error("no source file selected");
|
||||
}
|
||||
|
||||
if (src_size == 0) {
|
||||
src_size = is_ppc ? 4 : 1;
|
||||
}
|
||||
|
||||
pair<uint32_t, uint32_t> src_section = make_pair(0, 0);
|
||||
for (const auto& sec : this->src_mem->allocated_blocks()) {
|
||||
if (src_addr >= sec.first && src_addr + src_size <= sec.first + sec.second) {
|
||||
src_section = sec;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!src_section.second) {
|
||||
throw runtime_error("source address not within any section");
|
||||
}
|
||||
|
||||
const char* method_token = this->name_for_expand_method(expand_method);
|
||||
|
||||
size_t src_offset = src_addr - src_section.first;
|
||||
size_t src_bytes_available_before = src_offset;
|
||||
size_t src_bytes_available_after = src_section.second - src_offset - 4;
|
||||
this->log.info("(find_match/%s) Source offset = %08zX with %zX/%zX bytes available before/after",
|
||||
method_token, src_offset, src_bytes_available_before, src_bytes_available_after);
|
||||
|
||||
size_t match_bytes_before = 0;
|
||||
size_t match_bytes_after = 0;
|
||||
while (match_bytes_before + match_bytes_after + 4 < 0x100) {
|
||||
size_t num_matches = 0;
|
||||
size_t last_match_address = 0;
|
||||
size_t match_length = match_bytes_before + match_bytes_after + 4;
|
||||
StringReader src_r = this->src_mem->reader(src_section.first + src_offset - match_bytes_before, match_length);
|
||||
for (const auto& dest_section : dest_mem->allocated_blocks()) {
|
||||
for (size_t dest_match_offset = 0;
|
||||
dest_match_offset + match_length < dest_section.second;
|
||||
dest_match_offset += (is_ppc ? 4 : 1)) {
|
||||
src_r.go(0);
|
||||
StringReader dest_r = dest_mem->reader(dest_section.first + dest_match_offset, match_length);
|
||||
size_t z;
|
||||
if (is_ppc) {
|
||||
for (z = 0; z < match_length; z += 4) {
|
||||
if ((expand_method == ExpandMethod::PPC_TEXT_BOTH_IGNORE_ORIGIN) && (z == match_bytes_before)) {
|
||||
src_r.skip(4);
|
||||
dest_r.skip(4);
|
||||
} else if (!is_ppc_data) {
|
||||
uint32_t src_opcode = src_r.get_u32b();
|
||||
uint32_t dest_opcode = dest_r.get_u32b();
|
||||
uint32_t src_class = src_opcode & 0xFC000000;
|
||||
if (src_class != (dest_opcode & 0xFC000000)) {
|
||||
break;
|
||||
}
|
||||
if (src_class == 0x48000000) {
|
||||
// b +-offset
|
||||
src_opcode &= 0xFC000003;
|
||||
dest_opcode &= 0xFC000003;
|
||||
} else if (((src_opcode & 0xAC1F0000) == 0x800D0000) || ((src_opcode & 0xAC1F0000) == 0x80020000)) {
|
||||
// lwz/lfs rXX/fXX, [r2/r13 +- offset] OR stw/stfs [r2/r13 +- offset], rXX/fXX
|
||||
src_opcode &= 0xFFFF0000;
|
||||
dest_opcode &= 0xFFFF0000;
|
||||
}
|
||||
if (src_opcode != dest_opcode) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
uint32_t src_data = src_r.get_u32b();
|
||||
uint32_t dest_data = dest_r.get_u32b();
|
||||
if ((src_data & 0xFE000000) == 0x80000000) {
|
||||
src_data &= 0xFE000003;
|
||||
}
|
||||
if ((dest_data & 0xFE000000) == 0x80000000) {
|
||||
dest_data &= 0xFE000003;
|
||||
}
|
||||
if (src_data != dest_data) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (z = 0; z < match_length; z++) {
|
||||
uint8_t src_data = src_r.get_u8();
|
||||
uint8_t dest_data = dest_r.get_u8();
|
||||
if (src_data != dest_data) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (z == match_length) {
|
||||
num_matches++;
|
||||
last_match_address = dest_section.first + dest_match_offset + match_bytes_before;
|
||||
}
|
||||
}
|
||||
}
|
||||
this->log.info("(find_match/%s) For match length %zX, %zu matches found", method_token, match_length, num_matches);
|
||||
if (num_matches == 1) {
|
||||
return last_match_address;
|
||||
} else if (num_matches == 0) {
|
||||
throw runtime_error("did not find exactly one match");
|
||||
}
|
||||
bool can_expand_backward = false;
|
||||
bool can_expand_forward = false;
|
||||
switch (expand_method) {
|
||||
case ExpandMethod::PPC_TEXT_BACKWARD_WITH_BARRIER:
|
||||
can_expand_backward = (src_r.pget_u32b(0) != 0x4E800020) &&
|
||||
(src_bytes_available_before >= match_bytes_before + 4);
|
||||
break;
|
||||
case ExpandMethod::PPC_TEXT_BACKWARD:
|
||||
case ExpandMethod::PPC_DATA_BACKWARD:
|
||||
can_expand_backward = (src_bytes_available_before >= match_bytes_before + 4);
|
||||
break;
|
||||
case ExpandMethod::PPC_TEXT_FORWARD_WITH_BARRIER:
|
||||
can_expand_forward = (src_r.pget_u32b(src_r.size() - 4) != 0x4E800020) &&
|
||||
(src_bytes_available_after >= match_bytes_after + 4);
|
||||
break;
|
||||
case ExpandMethod::PPC_TEXT_FORWARD:
|
||||
case ExpandMethod::PPC_DATA_FORWARD:
|
||||
can_expand_forward = (src_bytes_available_after >= match_bytes_after + 4);
|
||||
break;
|
||||
case ExpandMethod::PPC_TEXT_BOTH_WITH_BARRIER:
|
||||
case ExpandMethod::PPC_TEXT_BOTH_IGNORE_ORIGIN:
|
||||
can_expand_backward = (src_r.pget_u32b(0) != 0x4E800020) &&
|
||||
(src_bytes_available_before >= match_bytes_before + 4);
|
||||
can_expand_forward = (src_r.pget_u32b(src_r.size() - 4) != 0x4E800020) &&
|
||||
(src_bytes_available_after >= match_bytes_after + 4);
|
||||
break;
|
||||
case ExpandMethod::PPC_TEXT_BOTH:
|
||||
case ExpandMethod::PPC_DATA_BOTH:
|
||||
can_expand_backward = (src_bytes_available_before >= match_bytes_before + 4);
|
||||
can_expand_forward = (src_bytes_available_after >= match_bytes_after + 4);
|
||||
break;
|
||||
case ExpandMethod::RAW_BACKWARD:
|
||||
can_expand_backward = (src_bytes_available_before > match_bytes_before);
|
||||
break;
|
||||
case ExpandMethod::RAW_FORWARD:
|
||||
can_expand_forward = (src_bytes_available_after > match_bytes_after);
|
||||
break;
|
||||
case ExpandMethod::RAW_BOTH:
|
||||
can_expand_backward = (src_bytes_available_before > match_bytes_before);
|
||||
can_expand_forward = (src_bytes_available_after > match_bytes_after);
|
||||
break;
|
||||
default:
|
||||
throw logic_error("invalid expand method");
|
||||
}
|
||||
if (!can_expand_backward && !can_expand_forward) {
|
||||
throw runtime_error("no further expansion is allowed");
|
||||
}
|
||||
if (can_expand_backward) {
|
||||
match_bytes_before += (is_ppc ? 4 : 1);
|
||||
}
|
||||
if (can_expand_forward) {
|
||||
match_bytes_after += (is_ppc ? 4 : 1);
|
||||
}
|
||||
}
|
||||
throw runtime_error("scan field too long; too many matches");
|
||||
}
|
||||
|
||||
void find_all_matches(uint32_t src_addr, uint32_t src_size) const {
|
||||
if (!this->src_mem) {
|
||||
throw runtime_error("no source file selected");
|
||||
}
|
||||
|
||||
map<string, uint32_t> results;
|
||||
for (const auto& it : this->mems) {
|
||||
if (it.second == this->src_mem) {
|
||||
log.info("(%s) %08" PRIX32 " (from source)", it.first.c_str(), src_addr);
|
||||
results.emplace(it.first, src_addr);
|
||||
|
||||
} else {
|
||||
vector<future<uint32_t>> futures;
|
||||
static const vector<ExpandMethod> ppc_methods = {
|
||||
ExpandMethod::PPC_TEXT_FORWARD,
|
||||
ExpandMethod::PPC_TEXT_FORWARD_WITH_BARRIER,
|
||||
ExpandMethod::PPC_TEXT_BACKWARD,
|
||||
ExpandMethod::PPC_TEXT_BACKWARD_WITH_BARRIER,
|
||||
ExpandMethod::PPC_TEXT_BOTH,
|
||||
ExpandMethod::PPC_TEXT_BOTH_WITH_BARRIER,
|
||||
ExpandMethod::PPC_TEXT_BOTH_IGNORE_ORIGIN,
|
||||
ExpandMethod::PPC_DATA_FORWARD,
|
||||
ExpandMethod::PPC_DATA_BACKWARD,
|
||||
ExpandMethod::PPC_DATA_BOTH,
|
||||
};
|
||||
static const vector<ExpandMethod> raw_methods = {
|
||||
ExpandMethod::RAW_FORWARD,
|
||||
ExpandMethod::RAW_BACKWARD,
|
||||
ExpandMethod::RAW_BOTH,
|
||||
};
|
||||
const auto& methods = this->enable_ppc ? ppc_methods : raw_methods;
|
||||
for (size_t z = 0; z < methods.size(); z++) {
|
||||
futures.emplace_back(async(&AddressTranslator::find_match, this, it.second, src_addr, src_size, methods[z]));
|
||||
}
|
||||
|
||||
unordered_set<uint32_t> match_addrs;
|
||||
for (size_t z = 0; z < futures.size(); z++) {
|
||||
const char* method_name = this->name_for_expand_method(methods[z]);
|
||||
try {
|
||||
uint32_t ret = futures[z].get();
|
||||
log.info("(%s) (%s) %08" PRIX32, it.first.c_str(), method_name, ret);
|
||||
match_addrs.emplace(ret);
|
||||
} catch (const exception& e) {
|
||||
log.error("(%s) (%s) failed: %s", it.first.c_str(), method_name, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
if (match_addrs.empty()) {
|
||||
log.error("(%s) no match found", it.first.c_str());
|
||||
} else if (match_addrs.size() > 1) {
|
||||
log.error("(%s) different matches found by different methods", it.first.c_str());
|
||||
} else {
|
||||
results.emplace(it.first, *match_addrs.begin());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto& it : results) {
|
||||
fprintf(stdout, "%s => %08" PRIX32 "\n", it.first.c_str(), it.second);
|
||||
}
|
||||
}
|
||||
|
||||
void handle_command(const string& command) {
|
||||
auto tokens = split(command, ' ');
|
||||
if (tokens.empty()) {
|
||||
throw runtime_error("no command given");
|
||||
}
|
||||
strip_trailing_whitespace(tokens[tokens.size() - 1]);
|
||||
|
||||
if (tokens[0] == "use") {
|
||||
this->set_source_file(tokens.at(1));
|
||||
} else if (tokens[0] == "match") {
|
||||
this->find_all_matches(
|
||||
stoul(tokens.at(1), nullptr, 16),
|
||||
tokens.size() >= 3 ? stoul(tokens[2], nullptr, 16) : 0);
|
||||
} else if (tokens[0] == "find-ppc-globals") {
|
||||
this->find_ppc_rtoc_global_regs();
|
||||
} else if (!tokens[0].empty()) {
|
||||
throw runtime_error("unknown command");
|
||||
}
|
||||
}
|
||||
|
||||
void run_shell() {
|
||||
while (!feof(stdin)) {
|
||||
if (!this->src_filename.empty()) {
|
||||
fprintf(stdout, "addr-trans:%s/%s> ", this->directory.c_str(), this->src_filename.c_str());
|
||||
} else {
|
||||
fprintf(stdout, "addr-trans:%s> ", this->directory.c_str());
|
||||
}
|
||||
fflush(stdout);
|
||||
|
||||
string command = fgets(stdin);
|
||||
try {
|
||||
this->handle_command(command);
|
||||
} catch (const exception& e) {
|
||||
this->log.error("Failed: %s", e.what());
|
||||
}
|
||||
}
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
|
||||
private:
|
||||
PrefixedLogger log;
|
||||
string directory;
|
||||
unordered_map<string, shared_ptr<const MemoryContext>> mems;
|
||||
string src_filename;
|
||||
shared_ptr<const MemoryContext> src_mem;
|
||||
bool enable_ppc;
|
||||
};
|
||||
|
||||
void run_address_translator(const std::string& directory, const std::string& use_filename, const std::string& command) {
|
||||
AddressTranslator trans(directory);
|
||||
if (!use_filename.empty()) {
|
||||
trans.set_source_file(use_filename);
|
||||
}
|
||||
|
||||
if (!command.empty()) {
|
||||
trans.handle_command(command);
|
||||
} else {
|
||||
trans.run_shell();
|
||||
}
|
||||
}
|
||||
|
||||
vector<pair<uint32_t, string>> diff_dol_files(const string& a_filename, const string& b_filename) {
|
||||
DOLFile a(a_filename.c_str());
|
||||
DOLFile b(b_filename.c_str());
|
||||
auto a_mem = make_shared<MemoryContext>();
|
||||
auto b_mem = make_shared<MemoryContext>();
|
||||
a.load_into(a_mem);
|
||||
b.load_into(b_mem);
|
||||
|
||||
uint32_t min_addr = 0xFFFFFFFF;
|
||||
uint32_t max_addr = 0x00000000;
|
||||
for (const auto& sec : a.sections) {
|
||||
min_addr = min<uint32_t>(min_addr, sec.address);
|
||||
max_addr = max<uint32_t>(max_addr, sec.address + sec.data.size());
|
||||
}
|
||||
for (const auto& sec : b.sections) {
|
||||
min_addr = min<uint32_t>(min_addr, sec.address);
|
||||
max_addr = max<uint32_t>(max_addr, sec.address + sec.data.size());
|
||||
}
|
||||
|
||||
vector<pair<uint32_t, string>> ret;
|
||||
for (uint32_t addr = min_addr; addr < max_addr; addr += 4) {
|
||||
bool a_exists = a_mem->exists(addr, 4);
|
||||
bool b_exists = b_mem->exists(addr, 4);
|
||||
if (a_exists && b_exists) {
|
||||
string a_value = a_mem->read(addr, 4);
|
||||
string b_value = b_mem->read(addr, 4);
|
||||
if (a_value != b_value) {
|
||||
if (!ret.empty() && (ret.back().first + ret.back().second.size() == addr)) {
|
||||
ret.back().second += b_value;
|
||||
} else {
|
||||
ret.emplace_back(make_pair(addr, b_value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
void run_address_translator(const std::string& directory, const std::string& use_filename, const std::string& command);
|
||||
std::vector<std::pair<uint32_t, std::string>> diff_dol_files(const std::string& a_filename, const std::string& b_filename);
|
||||
+83
-83
@@ -1,83 +1,83 @@
|
||||
#include "BattleParamsIndex.hh"
|
||||
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
|
||||
#include "Loggers.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "StaticGameData.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void BattleParamsIndex::Table::print(FILE* stream) const {
|
||||
auto print_entry = +[](FILE* stream, const PlayerStats& e) {
|
||||
fprintf(stream,
|
||||
"%5hu %5hu %5hu %5hu %5hu %5hu %5hu %5hu %5" PRIu32 " %5" PRIu32,
|
||||
e.char_stats.atp.load(),
|
||||
e.char_stats.mst.load(),
|
||||
e.char_stats.evp.load(),
|
||||
e.char_stats.hp.load(),
|
||||
e.char_stats.dfp.load(),
|
||||
e.char_stats.ata.load(),
|
||||
e.char_stats.lck.load(),
|
||||
e.esp.load(),
|
||||
e.experience.load(),
|
||||
e.meseta.load());
|
||||
};
|
||||
|
||||
for (size_t diff = 0; diff < 4; diff++) {
|
||||
fprintf(stream, "%c ZZ ATP PSV EVP HP DFP ATA LCK ESP EXP DIFF\n",
|
||||
abbreviation_for_difficulty(diff));
|
||||
for (size_t z = 0; z < 0x60; z++) {
|
||||
fprintf(stream, " %02zX ", z);
|
||||
print_entry(stream, this->stats[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::Table& BattleParamsIndex::get_table(bool solo, Episode episode) const {
|
||||
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;
|
||||
}
|
||||
#include "BattleParamsIndex.hh"
|
||||
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
|
||||
#include "Loggers.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "StaticGameData.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void BattleParamsIndex::Table::print(FILE* stream) const {
|
||||
auto print_entry = +[](FILE* stream, const PlayerStats& e) {
|
||||
fprintf(stream,
|
||||
"%5hu %5hu %5hu %5hu %5hu %5hu %5hu %5hu %5" PRIu32 " %5" PRIu32,
|
||||
e.char_stats.atp.load(),
|
||||
e.char_stats.mst.load(),
|
||||
e.char_stats.evp.load(),
|
||||
e.char_stats.hp.load(),
|
||||
e.char_stats.dfp.load(),
|
||||
e.char_stats.ata.load(),
|
||||
e.char_stats.lck.load(),
|
||||
e.esp.load(),
|
||||
e.experience.load(),
|
||||
e.meseta.load());
|
||||
};
|
||||
|
||||
for (size_t diff = 0; diff < 4; diff++) {
|
||||
fprintf(stream, "%c ZZ ATP PSV EVP HP DFP ATA LCK ESP EXP DIFF\n",
|
||||
abbreviation_for_difficulty(diff));
|
||||
for (size_t z = 0; z < 0x60; z++) {
|
||||
fprintf(stream, " %02zX ", z);
|
||||
print_entry(stream, this->stats[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::Table& BattleParamsIndex::get_table(bool solo, Episode episode) const {
|
||||
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;
|
||||
}
|
||||
|
||||
+100
-100
@@ -1,100 +1,100 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "EnemyType.hh"
|
||||
#include "LevelTable.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
class BattleParamsIndex {
|
||||
public:
|
||||
// These files are little-endian, even on PSO GC.
|
||||
|
||||
struct AttackData {
|
||||
/* 00 */ le_int16_t unknown_a1;
|
||||
/* 02 */ le_int16_t atp;
|
||||
/* 04 */ le_int16_t ata_bonus;
|
||||
/* 06 */ le_uint16_t unknown_a4;
|
||||
/* 08 */ le_float distance_x;
|
||||
/* 0C */ le_uint32_t angle_x; // Out of 0x10000 (high 16 bits are unused)
|
||||
/* 10 */ le_float distance_y;
|
||||
/* 14 */ le_uint16_t unknown_a8;
|
||||
/* 16 */ le_uint16_t unknown_a9;
|
||||
/* 18 */ le_uint16_t unknown_a10;
|
||||
/* 1A */ le_uint16_t unknown_a11;
|
||||
/* 1C */ le_uint32_t unknown_a12;
|
||||
/* 20 */ le_uint32_t unknown_a13;
|
||||
/* 24 */ le_uint32_t unknown_a14;
|
||||
/* 28 */ le_uint32_t unknown_a15;
|
||||
/* 2C */ le_uint32_t unknown_a16;
|
||||
/* 30 */
|
||||
} __packed_ws__(AttackData, 0x30);
|
||||
|
||||
struct ResistData {
|
||||
/* 00 */ le_int16_t evp_bonus;
|
||||
/* 02 */ le_uint16_t efr;
|
||||
/* 04 */ le_uint16_t eic;
|
||||
/* 06 */ le_uint16_t eth;
|
||||
/* 08 */ le_uint16_t elt;
|
||||
/* 0A */ le_uint16_t edk;
|
||||
/* 0C */ le_uint32_t unknown_a6;
|
||||
/* 10 */ le_uint32_t unknown_a7;
|
||||
/* 14 */ le_uint32_t unknown_a8;
|
||||
/* 18 */ le_uint32_t unknown_a9;
|
||||
/* 1C */ le_int32_t dfp_bonus;
|
||||
/* 20 */
|
||||
} __packed_ws__(ResistData, 0x20);
|
||||
|
||||
struct MovementData {
|
||||
/* 00 */ le_float idle_move_speed;
|
||||
/* 04 */ le_float idle_animation_speed;
|
||||
/* 08 */ le_float move_speed;
|
||||
/* 0C */ le_float animation_speed;
|
||||
/* 10 */ le_float unknown_a1;
|
||||
/* 14 */ le_float unknown_a2;
|
||||
/* 18 */ le_uint32_t unknown_a3;
|
||||
/* 1C */ le_uint32_t unknown_a4;
|
||||
/* 20 */ le_uint32_t unknown_a5;
|
||||
/* 24 */ le_uint32_t unknown_a6;
|
||||
/* 28 */ le_uint32_t unknown_a7;
|
||||
/* 2C */ le_uint32_t unknown_a8;
|
||||
/* 30 */
|
||||
} __packed_ws__(MovementData, 0x30);
|
||||
|
||||
struct Table {
|
||||
/* 0000 */ parray<parray<PlayerStats, 0x60>, 4> stats;
|
||||
/* 3600 */ parray<parray<AttackData, 0x60>, 4> attack_data;
|
||||
/* 7E00 */ parray<parray<ResistData, 0x60>, 4> resist_data;
|
||||
/* AE00 */ parray<parray<MovementData, 0x60>, 4> movement_data;
|
||||
/* F600 */
|
||||
|
||||
void print(FILE* stream) const;
|
||||
} __packed_ws__(Table, 0xF600);
|
||||
|
||||
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 Table& get_table(bool solo, Episode episode) const;
|
||||
|
||||
private:
|
||||
struct File {
|
||||
std::shared_ptr<const std::string> data;
|
||||
const Table* table;
|
||||
};
|
||||
|
||||
// Indexed as [online/offline][episode]
|
||||
std::array<std::array<File, 3>, 2> files;
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "EnemyType.hh"
|
||||
#include "LevelTable.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
class BattleParamsIndex {
|
||||
public:
|
||||
// These files are little-endian, even on PSO GC.
|
||||
|
||||
struct AttackData {
|
||||
/* 00 */ le_int16_t unknown_a1;
|
||||
/* 02 */ le_int16_t atp;
|
||||
/* 04 */ le_int16_t ata_bonus;
|
||||
/* 06 */ le_uint16_t unknown_a4;
|
||||
/* 08 */ le_float distance_x;
|
||||
/* 0C */ le_uint32_t angle_x; // Out of 0x10000 (high 16 bits are unused)
|
||||
/* 10 */ le_float distance_y;
|
||||
/* 14 */ le_uint16_t unknown_a8;
|
||||
/* 16 */ le_uint16_t unknown_a9;
|
||||
/* 18 */ le_uint16_t unknown_a10;
|
||||
/* 1A */ le_uint16_t unknown_a11;
|
||||
/* 1C */ le_uint32_t unknown_a12;
|
||||
/* 20 */ le_uint32_t unknown_a13;
|
||||
/* 24 */ le_uint32_t unknown_a14;
|
||||
/* 28 */ le_uint32_t unknown_a15;
|
||||
/* 2C */ le_uint32_t unknown_a16;
|
||||
/* 30 */
|
||||
} __packed_ws__(AttackData, 0x30);
|
||||
|
||||
struct ResistData {
|
||||
/* 00 */ le_int16_t evp_bonus;
|
||||
/* 02 */ le_uint16_t efr;
|
||||
/* 04 */ le_uint16_t eic;
|
||||
/* 06 */ le_uint16_t eth;
|
||||
/* 08 */ le_uint16_t elt;
|
||||
/* 0A */ le_uint16_t edk;
|
||||
/* 0C */ le_uint32_t unknown_a6;
|
||||
/* 10 */ le_uint32_t unknown_a7;
|
||||
/* 14 */ le_uint32_t unknown_a8;
|
||||
/* 18 */ le_uint32_t unknown_a9;
|
||||
/* 1C */ le_int32_t dfp_bonus;
|
||||
/* 20 */
|
||||
} __packed_ws__(ResistData, 0x20);
|
||||
|
||||
struct MovementData {
|
||||
/* 00 */ le_float idle_move_speed;
|
||||
/* 04 */ le_float idle_animation_speed;
|
||||
/* 08 */ le_float move_speed;
|
||||
/* 0C */ le_float animation_speed;
|
||||
/* 10 */ le_float unknown_a1;
|
||||
/* 14 */ le_float unknown_a2;
|
||||
/* 18 */ le_uint32_t unknown_a3;
|
||||
/* 1C */ le_uint32_t unknown_a4;
|
||||
/* 20 */ le_uint32_t unknown_a5;
|
||||
/* 24 */ le_uint32_t unknown_a6;
|
||||
/* 28 */ le_uint32_t unknown_a7;
|
||||
/* 2C */ le_uint32_t unknown_a8;
|
||||
/* 30 */
|
||||
} __packed_ws__(MovementData, 0x30);
|
||||
|
||||
struct Table {
|
||||
/* 0000 */ parray<parray<PlayerStats, 0x60>, 4> stats;
|
||||
/* 3600 */ parray<parray<AttackData, 0x60>, 4> attack_data;
|
||||
/* 7E00 */ parray<parray<ResistData, 0x60>, 4> resist_data;
|
||||
/* AE00 */ parray<parray<MovementData, 0x60>, 4> movement_data;
|
||||
/* F600 */
|
||||
|
||||
void print(FILE* stream) const;
|
||||
} __packed_ws__(Table, 0xF600);
|
||||
|
||||
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 Table& get_table(bool solo, Episode episode) const;
|
||||
|
||||
private:
|
||||
struct File {
|
||||
std::shared_ptr<const std::string> data;
|
||||
const Table* table;
|
||||
};
|
||||
|
||||
// Indexed as [online/offline][episode]
|
||||
std::array<std::array<File, 3>, 2> files;
|
||||
};
|
||||
|
||||
+188
-188
@@ -1,188 +1,188 @@
|
||||
#include "CatSession.hh"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <event2/buffer.h>
|
||||
#include <event2/bufferevent.h>
|
||||
#include <event2/event.h>
|
||||
#include <event2/listener.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Network.hh>
|
||||
#include <phosg/Random.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <phosg/Time.hh>
|
||||
|
||||
#include "Loggers.hh"
|
||||
#include "PSOProtocol.hh"
|
||||
#include "ProxyCommands.hh"
|
||||
#include "ReceiveCommands.hh"
|
||||
#include "ReceiveSubcommands.hh"
|
||||
#include "SendCommands.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
CatSession::exit_shell::exit_shell() : runtime_error("shell exited") {}
|
||||
|
||||
CatSession::CatSession(
|
||||
shared_ptr<struct event_base> base,
|
||||
const struct sockaddr_storage& remote,
|
||||
Version version,
|
||||
shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file)
|
||||
: log(string_printf("[CatSession:%s] ", name_for_enum(version)), proxy_server_log.min_level),
|
||||
base(base),
|
||||
read_event(event_new(this->base.get(), 0, EV_READ | EV_PERSIST, CatSession::dispatch_read_stdin, this), event_free),
|
||||
channel(version, 1, CatSession::dispatch_on_channel_input, CatSession::dispatch_on_channel_error, this, "CatSession"),
|
||||
bb_key_file(bb_key_file) {
|
||||
|
||||
if (remote.ss_family != AF_INET) {
|
||||
throw runtime_error("remote is not AF_INET");
|
||||
}
|
||||
|
||||
string netloc_str = render_sockaddr_storage(remote);
|
||||
this->log.info("Connecting to %s", netloc_str.c_str());
|
||||
|
||||
struct bufferevent* bev = bufferevent_socket_new(
|
||||
this->base.get(), -1, BEV_OPT_CLOSE_ON_FREE | BEV_OPT_DEFER_CALLBACKS);
|
||||
if (!bev) {
|
||||
throw runtime_error(string_printf("failed to open socket (%d)", EVUTIL_SOCKET_ERROR()));
|
||||
}
|
||||
this->channel.set_bufferevent(bev, 0);
|
||||
|
||||
if (bufferevent_socket_connect(this->channel.bev.get(),
|
||||
reinterpret_cast<const sockaddr*>(&remote), sizeof(struct sockaddr_in)) != 0) {
|
||||
throw runtime_error(string_printf("failed to connect (%d)", EVUTIL_SOCKET_ERROR()));
|
||||
}
|
||||
|
||||
event_add(this->read_event.get(), nullptr);
|
||||
this->poll.add(0, POLLIN);
|
||||
}
|
||||
|
||||
void CatSession::execute_command(const std::string& command) {
|
||||
string full_cmd = parse_data_string(command, nullptr, ParseDataFlags::ALLOW_FILES);
|
||||
send_command_with_header(this->channel, full_cmd.data(), full_cmd.size());
|
||||
}
|
||||
|
||||
void CatSession::dispatch_on_channel_input(
|
||||
Channel& ch, uint16_t command, uint32_t flag, std::string& data) {
|
||||
auto* session = reinterpret_cast<CatSession*>(ch.context_obj);
|
||||
session->on_channel_input(command, flag, data);
|
||||
}
|
||||
|
||||
void CatSession::on_channel_input(
|
||||
uint16_t command, uint32_t flag, std::string& data) {
|
||||
if (!uses_v4_encryption(this->channel.version)) {
|
||||
if (command == 0x02 || command == 0x17 || command == 0x91 || command == 0x9B) {
|
||||
const auto& cmd = check_size_t<S_ServerInitDefault_DC_PC_V3_02_17_91_9B>(data, 0xFFFF);
|
||||
if (uses_v3_encryption(this->channel.version)) {
|
||||
this->channel.crypt_in = make_shared<PSOV3Encryption>(cmd.server_key);
|
||||
this->channel.crypt_out = make_shared<PSOV3Encryption>(cmd.client_key);
|
||||
this->log.info("Enabled V3 encryption (server key %08" PRIX32 ", client key %08" PRIX32 ")",
|
||||
cmd.server_key.load(), cmd.client_key.load());
|
||||
} else { // PC, DC, or patch server
|
||||
this->channel.crypt_in = make_shared<PSOV2Encryption>(cmd.server_key);
|
||||
this->channel.crypt_out = make_shared<PSOV2Encryption>(cmd.client_key);
|
||||
this->log.info("Enabled V2 encryption (server key %08" PRIX32 ", client key %08" PRIX32 ")",
|
||||
cmd.server_key.load(), cmd.client_key.load());
|
||||
}
|
||||
}
|
||||
} else { // BB
|
||||
if (command == 0x03 || command == 0x9B) {
|
||||
if (!this->bb_key_file) {
|
||||
throw runtime_error("BB encryption requires a key file");
|
||||
}
|
||||
const auto& cmd = check_size_t<S_ServerInitDefault_BB_03_9B>(data, 0xFFFF);
|
||||
this->channel.crypt_in = make_shared<PSOBBEncryption>(*this->bb_key_file, &cmd.server_key[0], sizeof(cmd.server_key));
|
||||
this->channel.crypt_out = make_shared<PSOBBEncryption>(*this->bb_key_file, &cmd.client_key[0], sizeof(cmd.client_key));
|
||||
this->log.info("Enabled BB encryption");
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Use the iovec form of print_data here instead of
|
||||
// prepend_command_header (which copies the string)
|
||||
string full_cmd = prepend_command_header(
|
||||
this->channel.version, this->channel.crypt_in.get(), command, flag, data);
|
||||
print_data(stdout, full_cmd, 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::OFFSET_16_BITS);
|
||||
}
|
||||
|
||||
void CatSession::dispatch_on_channel_error(Channel& ch, short events) {
|
||||
auto* session = reinterpret_cast<CatSession*>(ch.context_obj);
|
||||
session->on_channel_error(events);
|
||||
}
|
||||
|
||||
void CatSession::on_channel_error(short events) {
|
||||
if (events & BEV_EVENT_CONNECTED) {
|
||||
this->log.info("Channel connected");
|
||||
}
|
||||
if (events & BEV_EVENT_ERROR) {
|
||||
int err = EVUTIL_SOCKET_ERROR();
|
||||
this->log.warning("Error %d (%s) in unlinked client stream", err,
|
||||
evutil_socket_error_to_string(err));
|
||||
}
|
||||
if (events & (BEV_EVENT_ERROR | BEV_EVENT_EOF)) {
|
||||
this->log.info("Session endpoint has disconnected");
|
||||
this->channel.disconnect();
|
||||
event_base_loopexit(this->base.get(), nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void CatSession::dispatch_read_stdin(evutil_socket_t, short, void* ctx) {
|
||||
reinterpret_cast<CatSession*>(ctx)->read_stdin();
|
||||
}
|
||||
|
||||
void CatSession::read_stdin() {
|
||||
bool any_command_read = false;
|
||||
for (;;) {
|
||||
auto poll_result = this->poll.poll();
|
||||
short fd_events = 0;
|
||||
try {
|
||||
fd_events = poll_result.at(0);
|
||||
} catch (const out_of_range&) {
|
||||
}
|
||||
|
||||
if (!(fd_events & POLLIN)) {
|
||||
break;
|
||||
}
|
||||
|
||||
string command(2048, '\0');
|
||||
if (!fgets(command.data(), command.size(), stdin)) {
|
||||
if (!any_command_read) {
|
||||
// ctrl+d probably; we should exit
|
||||
fputc('\n', stderr);
|
||||
event_base_loopexit(this->base.get(), nullptr);
|
||||
return;
|
||||
} else {
|
||||
break; // probably not EOF; just no more commands for now
|
||||
}
|
||||
}
|
||||
|
||||
// trim the extra data off the string
|
||||
size_t len = strlen(command.c_str());
|
||||
if (len == 0) {
|
||||
break;
|
||||
}
|
||||
if (command[len - 1] == '\n') {
|
||||
len--;
|
||||
}
|
||||
command.resize(len);
|
||||
any_command_read = true;
|
||||
|
||||
try {
|
||||
execute_command(command);
|
||||
} catch (const exit_shell&) {
|
||||
event_base_loopexit(this->base.get(), nullptr);
|
||||
return;
|
||||
} catch (const exception& e) {
|
||||
fprintf(stderr, "FAILED: %s\n", e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
#include "CatSession.hh"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <event2/buffer.h>
|
||||
#include <event2/bufferevent.h>
|
||||
#include <event2/event.h>
|
||||
#include <event2/listener.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Network.hh>
|
||||
#include <phosg/Random.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <phosg/Time.hh>
|
||||
|
||||
#include "Loggers.hh"
|
||||
#include "PSOProtocol.hh"
|
||||
#include "ProxyCommands.hh"
|
||||
#include "ReceiveCommands.hh"
|
||||
#include "ReceiveSubcommands.hh"
|
||||
#include "SendCommands.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
CatSession::exit_shell::exit_shell() : runtime_error("shell exited") {}
|
||||
|
||||
CatSession::CatSession(
|
||||
shared_ptr<struct event_base> base,
|
||||
const struct sockaddr_storage& remote,
|
||||
Version version,
|
||||
shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file)
|
||||
: log(string_printf("[CatSession:%s] ", name_for_enum(version)), proxy_server_log.min_level),
|
||||
base(base),
|
||||
read_event(event_new(this->base.get(), 0, EV_READ | EV_PERSIST, CatSession::dispatch_read_stdin, this), event_free),
|
||||
channel(version, 1, CatSession::dispatch_on_channel_input, CatSession::dispatch_on_channel_error, this, "CatSession"),
|
||||
bb_key_file(bb_key_file) {
|
||||
|
||||
if (remote.ss_family != AF_INET) {
|
||||
throw runtime_error("remote is not AF_INET");
|
||||
}
|
||||
|
||||
string netloc_str = render_sockaddr_storage(remote);
|
||||
this->log.info("Connecting to %s", netloc_str.c_str());
|
||||
|
||||
struct bufferevent* bev = bufferevent_socket_new(
|
||||
this->base.get(), -1, BEV_OPT_CLOSE_ON_FREE | BEV_OPT_DEFER_CALLBACKS);
|
||||
if (!bev) {
|
||||
throw runtime_error(string_printf("failed to open socket (%d)", EVUTIL_SOCKET_ERROR()));
|
||||
}
|
||||
this->channel.set_bufferevent(bev, 0);
|
||||
|
||||
if (bufferevent_socket_connect(this->channel.bev.get(),
|
||||
reinterpret_cast<const sockaddr*>(&remote), sizeof(struct sockaddr_in)) != 0) {
|
||||
throw runtime_error(string_printf("failed to connect (%d)", EVUTIL_SOCKET_ERROR()));
|
||||
}
|
||||
|
||||
event_add(this->read_event.get(), nullptr);
|
||||
this->poll.add(0, POLLIN);
|
||||
}
|
||||
|
||||
void CatSession::execute_command(const std::string& command) {
|
||||
string full_cmd = parse_data_string(command, nullptr, ParseDataFlags::ALLOW_FILES);
|
||||
send_command_with_header(this->channel, full_cmd.data(), full_cmd.size());
|
||||
}
|
||||
|
||||
void CatSession::dispatch_on_channel_input(
|
||||
Channel& ch, uint16_t command, uint32_t flag, std::string& data) {
|
||||
auto* session = reinterpret_cast<CatSession*>(ch.context_obj);
|
||||
session->on_channel_input(command, flag, data);
|
||||
}
|
||||
|
||||
void CatSession::on_channel_input(
|
||||
uint16_t command, uint32_t flag, std::string& data) {
|
||||
if (!uses_v4_encryption(this->channel.version)) {
|
||||
if (command == 0x02 || command == 0x17 || command == 0x91 || command == 0x9B) {
|
||||
const auto& cmd = check_size_t<S_ServerInitDefault_DC_PC_V3_02_17_91_9B>(data, 0xFFFF);
|
||||
if (uses_v3_encryption(this->channel.version)) {
|
||||
this->channel.crypt_in = make_shared<PSOV3Encryption>(cmd.server_key);
|
||||
this->channel.crypt_out = make_shared<PSOV3Encryption>(cmd.client_key);
|
||||
this->log.info("Enabled V3 encryption (server key %08" PRIX32 ", client key %08" PRIX32 ")",
|
||||
cmd.server_key.load(), cmd.client_key.load());
|
||||
} else { // PC, DC, or patch server
|
||||
this->channel.crypt_in = make_shared<PSOV2Encryption>(cmd.server_key);
|
||||
this->channel.crypt_out = make_shared<PSOV2Encryption>(cmd.client_key);
|
||||
this->log.info("Enabled V2 encryption (server key %08" PRIX32 ", client key %08" PRIX32 ")",
|
||||
cmd.server_key.load(), cmd.client_key.load());
|
||||
}
|
||||
}
|
||||
} else { // BB
|
||||
if (command == 0x03 || command == 0x9B) {
|
||||
if (!this->bb_key_file) {
|
||||
throw runtime_error("BB encryption requires a key file");
|
||||
}
|
||||
const auto& cmd = check_size_t<S_ServerInitDefault_BB_03_9B>(data, 0xFFFF);
|
||||
this->channel.crypt_in = make_shared<PSOBBEncryption>(*this->bb_key_file, &cmd.server_key[0], sizeof(cmd.server_key));
|
||||
this->channel.crypt_out = make_shared<PSOBBEncryption>(*this->bb_key_file, &cmd.client_key[0], sizeof(cmd.client_key));
|
||||
this->log.info("Enabled BB encryption");
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Use the iovec form of print_data here instead of
|
||||
// prepend_command_header (which copies the string)
|
||||
string full_cmd = prepend_command_header(
|
||||
this->channel.version, this->channel.crypt_in.get(), command, flag, data);
|
||||
print_data(stdout, full_cmd, 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::OFFSET_16_BITS);
|
||||
}
|
||||
|
||||
void CatSession::dispatch_on_channel_error(Channel& ch, short events) {
|
||||
auto* session = reinterpret_cast<CatSession*>(ch.context_obj);
|
||||
session->on_channel_error(events);
|
||||
}
|
||||
|
||||
void CatSession::on_channel_error(short events) {
|
||||
if (events & BEV_EVENT_CONNECTED) {
|
||||
this->log.info("Channel connected");
|
||||
}
|
||||
if (events & BEV_EVENT_ERROR) {
|
||||
int err = EVUTIL_SOCKET_ERROR();
|
||||
this->log.warning("Error %d (%s) in unlinked client stream", err,
|
||||
evutil_socket_error_to_string(err));
|
||||
}
|
||||
if (events & (BEV_EVENT_ERROR | BEV_EVENT_EOF)) {
|
||||
this->log.info("Session endpoint has disconnected");
|
||||
this->channel.disconnect();
|
||||
event_base_loopexit(this->base.get(), nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void CatSession::dispatch_read_stdin(evutil_socket_t, short, void* ctx) {
|
||||
reinterpret_cast<CatSession*>(ctx)->read_stdin();
|
||||
}
|
||||
|
||||
void CatSession::read_stdin() {
|
||||
bool any_command_read = false;
|
||||
for (;;) {
|
||||
auto poll_result = this->poll.poll();
|
||||
short fd_events = 0;
|
||||
try {
|
||||
fd_events = poll_result.at(0);
|
||||
} catch (const out_of_range&) {
|
||||
}
|
||||
|
||||
if (!(fd_events & POLLIN)) {
|
||||
break;
|
||||
}
|
||||
|
||||
string command(2048, '\0');
|
||||
if (!fgets(command.data(), command.size(), stdin)) {
|
||||
if (!any_command_read) {
|
||||
// ctrl+d probably; we should exit
|
||||
fputc('\n', stderr);
|
||||
event_base_loopexit(this->base.get(), nullptr);
|
||||
return;
|
||||
} else {
|
||||
break; // probably not EOF; just no more commands for now
|
||||
}
|
||||
}
|
||||
|
||||
// trim the extra data off the string
|
||||
size_t len = strlen(command.c_str());
|
||||
if (len == 0) {
|
||||
break;
|
||||
}
|
||||
if (command[len - 1] == '\n') {
|
||||
len--;
|
||||
}
|
||||
command.resize(len);
|
||||
any_command_read = true;
|
||||
|
||||
try {
|
||||
execute_command(command);
|
||||
} catch (const exit_shell&) {
|
||||
event_base_loopexit(this->base.get(), nullptr);
|
||||
return;
|
||||
} catch (const exception& e) {
|
||||
fprintf(stderr, "FAILED: %s\n", e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+54
-54
@@ -1,54 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include <event2/event.h>
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#include "PSOEncryption.hh"
|
||||
#include "PSOProtocol.hh"
|
||||
#include "ServerState.hh"
|
||||
|
||||
class CatSession {
|
||||
public:
|
||||
CatSession(
|
||||
std::shared_ptr<struct event_base> base,
|
||||
const struct sockaddr_storage& remote,
|
||||
Version version,
|
||||
std::shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file);
|
||||
CatSession(const CatSession&) = delete;
|
||||
CatSession(CatSession&&) = delete;
|
||||
CatSession& operator=(const CatSession&) = delete;
|
||||
CatSession& operator=(CatSession&&) = delete;
|
||||
virtual ~CatSession() = default;
|
||||
|
||||
protected:
|
||||
PrefixedLogger log;
|
||||
std::shared_ptr<struct event_base> base;
|
||||
std::unique_ptr<struct event, void (*)(struct event*)> read_event;
|
||||
Poll poll;
|
||||
|
||||
Channel channel;
|
||||
std::shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file;
|
||||
|
||||
class exit_shell : public std::runtime_error {
|
||||
public:
|
||||
exit_shell();
|
||||
~exit_shell() = default;
|
||||
};
|
||||
|
||||
virtual void execute_command(const std::string& command);
|
||||
|
||||
static void dispatch_read_stdin(evutil_socket_t fd, short events, void* ctx);
|
||||
static void dispatch_on_channel_input(Channel& ch, uint16_t command, uint32_t flag, std::string& msg);
|
||||
static void dispatch_on_channel_error(Channel& ch, short events);
|
||||
void on_channel_input(uint16_t command, uint32_t flag, std::string& msg);
|
||||
void on_channel_error(short events);
|
||||
void read_stdin();
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <event2/event.h>
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#include "PSOEncryption.hh"
|
||||
#include "PSOProtocol.hh"
|
||||
#include "ServerState.hh"
|
||||
|
||||
class CatSession {
|
||||
public:
|
||||
CatSession(
|
||||
std::shared_ptr<struct event_base> base,
|
||||
const struct sockaddr_storage& remote,
|
||||
Version version,
|
||||
std::shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file);
|
||||
CatSession(const CatSession&) = delete;
|
||||
CatSession(CatSession&&) = delete;
|
||||
CatSession& operator=(const CatSession&) = delete;
|
||||
CatSession& operator=(CatSession&&) = delete;
|
||||
virtual ~CatSession() = default;
|
||||
|
||||
protected:
|
||||
PrefixedLogger log;
|
||||
std::shared_ptr<struct event_base> base;
|
||||
std::unique_ptr<struct event, void (*)(struct event*)> read_event;
|
||||
Poll poll;
|
||||
|
||||
Channel channel;
|
||||
std::shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file;
|
||||
|
||||
class exit_shell : public std::runtime_error {
|
||||
public:
|
||||
exit_shell();
|
||||
~exit_shell() = default;
|
||||
};
|
||||
|
||||
virtual void execute_command(const std::string& command);
|
||||
|
||||
static void dispatch_read_stdin(evutil_socket_t fd, short events, void* ctx);
|
||||
static void dispatch_on_channel_input(Channel& ch, uint16_t command, uint32_t flag, std::string& msg);
|
||||
static void dispatch_on_channel_error(Channel& ch, short events);
|
||||
void on_channel_input(uint16_t command, uint32_t flag, std::string& msg);
|
||||
void on_channel_error(short events);
|
||||
void read_stdin();
|
||||
};
|
||||
|
||||
+421
-421
@@ -1,421 +1,421 @@
|
||||
#include "Channel.hh"
|
||||
|
||||
#include <errno.h>
|
||||
#include <event2/buffer.h>
|
||||
#include <event2/bufferevent.h>
|
||||
#include <event2/event.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <phosg/Network.hh>
|
||||
#include <phosg/Time.hh>
|
||||
|
||||
#include "Loggers.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
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(
|
||||
Version version,
|
||||
uint8_t language,
|
||||
on_command_received_t on_command_received,
|
||||
on_error_t on_error,
|
||||
void* context_obj,
|
||||
const string& name,
|
||||
TerminalFormat terminal_send_color,
|
||||
TerminalFormat terminal_recv_color)
|
||||
: bev(nullptr, flush_and_free_bufferevent),
|
||||
virtual_network_id(0),
|
||||
version(version),
|
||||
language(language),
|
||||
name(name),
|
||||
terminal_send_color(terminal_send_color),
|
||||
terminal_recv_color(terminal_recv_color),
|
||||
on_command_received(on_command_received),
|
||||
on_error(on_error),
|
||||
context_obj(context_obj) {
|
||||
}
|
||||
|
||||
Channel::Channel(
|
||||
struct bufferevent* bev,
|
||||
uint64_t virtual_network_id,
|
||||
Version version,
|
||||
uint8_t language,
|
||||
on_command_received_t on_command_received,
|
||||
on_error_t on_error,
|
||||
void* context_obj,
|
||||
const string& name,
|
||||
TerminalFormat terminal_send_color,
|
||||
TerminalFormat terminal_recv_color)
|
||||
: bev(nullptr, flush_and_free_bufferevent),
|
||||
version(version),
|
||||
language(language),
|
||||
name(name),
|
||||
terminal_send_color(terminal_send_color),
|
||||
terminal_recv_color(terminal_recv_color),
|
||||
on_command_received(on_command_received),
|
||||
on_error(on_error),
|
||||
context_obj(context_obj) {
|
||||
this->set_bufferevent(bev, virtual_network_id);
|
||||
}
|
||||
|
||||
void Channel::replace_with(
|
||||
Channel&& other,
|
||||
on_command_received_t on_command_received,
|
||||
on_error_t on_error,
|
||||
void* context_obj,
|
||||
const std::string& name) {
|
||||
this->set_bufferevent(other.bev.release(), other.virtual_network_id);
|
||||
this->local_addr = other.local_addr;
|
||||
this->remote_addr = other.remote_addr;
|
||||
this->version = other.version;
|
||||
this->language = other.language;
|
||||
this->crypt_in = other.crypt_in;
|
||||
this->crypt_out = other.crypt_out;
|
||||
this->name = name;
|
||||
this->terminal_send_color = other.terminal_send_color;
|
||||
this->terminal_recv_color = other.terminal_recv_color;
|
||||
this->on_command_received = on_command_received;
|
||||
this->on_error = on_error;
|
||||
this->context_obj = context_obj;
|
||||
other.disconnect(); // Clears crypts, addrs, etc.
|
||||
}
|
||||
|
||||
void Channel::set_bufferevent(struct bufferevent* bev, uint64_t virtual_network_id) {
|
||||
this->bev.reset(bev);
|
||||
this->virtual_network_id = virtual_network_id;
|
||||
|
||||
if (this->bev.get()) {
|
||||
int fd = bufferevent_getfd(this->bev.get());
|
||||
if (fd < 0) {
|
||||
memset(&this->local_addr, 0, sizeof(this->local_addr));
|
||||
memset(&this->remote_addr, 0, sizeof(this->remote_addr));
|
||||
} else {
|
||||
get_socket_addresses(fd, &this->local_addr, &this->remote_addr);
|
||||
}
|
||||
|
||||
bufferevent_setcb(this->bev.get(), &Channel::dispatch_on_input, nullptr, &Channel::dispatch_on_error, this);
|
||||
bufferevent_enable(this->bev.get(), EV_READ | EV_WRITE);
|
||||
|
||||
} else {
|
||||
memset(&this->local_addr, 0, sizeof(this->local_addr));
|
||||
memset(&this->remote_addr, 0, sizeof(this->remote_addr));
|
||||
}
|
||||
}
|
||||
|
||||
void Channel::disconnect() {
|
||||
if (this->bev.get()) {
|
||||
// If the output buffer is not empty, move the bufferevent into the draining
|
||||
// pool instead of disconnecting it, to make sure all the data gets sent.
|
||||
struct evbuffer* out_buffer = bufferevent_get_output(this->bev.get());
|
||||
if (evbuffer_get_length(out_buffer) == 0) {
|
||||
this->bev.reset(); // Destructor flushes and frees the bufferevent
|
||||
} else {
|
||||
// The callbacks will free it when all the data is sent or the client
|
||||
// disconnects
|
||||
|
||||
auto on_output = +[](struct bufferevent* bev, void*) -> void {
|
||||
flush_and_free_bufferevent(bev);
|
||||
};
|
||||
|
||||
auto on_error = +[](struct bufferevent* bev, short events, void*) -> void {
|
||||
if (events & BEV_EVENT_ERROR) {
|
||||
int err = EVUTIL_SOCKET_ERROR();
|
||||
channel_exceptions_log.warning(
|
||||
"Disconnecting channel caused error %d (%s)", err,
|
||||
evutil_socket_error_to_string(err));
|
||||
}
|
||||
if (events & (BEV_EVENT_EOF | BEV_EVENT_ERROR)) {
|
||||
bufferevent_flush(bev, EV_WRITE, BEV_FINISHED);
|
||||
bufferevent_free(bev);
|
||||
}
|
||||
};
|
||||
|
||||
struct bufferevent* bev = this->bev.release();
|
||||
bufferevent_setcb(bev, nullptr, on_output, on_error, bev);
|
||||
bufferevent_disable(bev, EV_READ);
|
||||
}
|
||||
}
|
||||
|
||||
memset(&this->local_addr, 0, sizeof(this->local_addr));
|
||||
memset(&this->remote_addr, 0, sizeof(this->remote_addr));
|
||||
this->virtual_network_id = false;
|
||||
this->crypt_in.reset();
|
||||
this->crypt_out.reset();
|
||||
}
|
||||
|
||||
Channel::Message Channel::recv() {
|
||||
struct evbuffer* buf = bufferevent_get_input(this->bev.get());
|
||||
|
||||
size_t header_size = (this->version == Version::BB_V4) ? 8 : 4;
|
||||
PSOCommandHeader header;
|
||||
if (evbuffer_copyout(buf, &header, header_size) < static_cast<ssize_t>(header_size)) {
|
||||
throw out_of_range("no command available");
|
||||
}
|
||||
|
||||
if (this->crypt_in.get()) {
|
||||
this->crypt_in->decrypt(&header, header_size, false);
|
||||
}
|
||||
|
||||
size_t command_logical_size = header.size(version);
|
||||
|
||||
// If encryption is enabled, BB pads commands to 8-byte boundaries, and this
|
||||
// is not reflected in the size field. This logic does not occur if encryption
|
||||
// is not yet enabled.
|
||||
size_t command_physical_size = (this->crypt_in.get() && (version == Version::BB_V4))
|
||||
? ((command_logical_size + 7) & ~7)
|
||||
: command_logical_size;
|
||||
if (evbuffer_get_length(buf) < command_physical_size) {
|
||||
throw out_of_range("no command available");
|
||||
}
|
||||
|
||||
// If we get here, then there is a full command in the buffer. Some encryption
|
||||
// algorithms' advancement depends on the decrypted data, so we have to
|
||||
// actually decrypt the header again (with advance=true) to keep them in a
|
||||
// consistent state.
|
||||
|
||||
string header_data(header_size, '\0');
|
||||
if (evbuffer_remove(buf, header_data.data(), header_data.size()) < static_cast<ssize_t>(header_data.size())) {
|
||||
throw logic_error("enough bytes available, but could not remove them");
|
||||
}
|
||||
if (this->crypt_in.get()) {
|
||||
this->crypt_in->decrypt(header_data.data(), header_data.size());
|
||||
}
|
||||
|
||||
string command_data(command_physical_size - header_size, '\0');
|
||||
if (evbuffer_remove(buf, command_data.data(), command_data.size()) < static_cast<ssize_t>(command_data.size())) {
|
||||
throw logic_error("enough bytes available, but could not remove them");
|
||||
}
|
||||
|
||||
if (this->crypt_in.get()) {
|
||||
// Some versions of PSO DC can send commands whose sizes are not a multiple
|
||||
// of 4, but the server is expected to always use a multiple of 4 bytes when
|
||||
// decrypting (the extra cipher bytes are lost). To emulate this behavior,
|
||||
// we have to round up the size for DC commands here.
|
||||
size_t orig_size = command_data.size();
|
||||
command_data.resize((orig_size + 3) & (~3), 0);
|
||||
this->crypt_in->decrypt(command_data.data(), command_data.size());
|
||||
command_data.resize(orig_size);
|
||||
}
|
||||
command_data.resize(command_logical_size - header_size);
|
||||
|
||||
if (command_data_log.should_log(LogLevel::INFO) && (this->terminal_recv_color != TerminalFormat::END)) {
|
||||
if (use_terminal_colors && this->terminal_recv_color != TerminalFormat::NORMAL) {
|
||||
print_color_escape(stderr, this->terminal_recv_color, TerminalFormat::BOLD, TerminalFormat::END);
|
||||
}
|
||||
|
||||
if (version == Version::BB_V4) {
|
||||
command_data_log.info(
|
||||
"Received from %s (version=BB command=%04hX flag=%08" PRIX32 ")",
|
||||
this->name.c_str(),
|
||||
header.command(this->version),
|
||||
header.flag(this->version));
|
||||
} else {
|
||||
command_data_log.info(
|
||||
"Received from %s (version=%s command=%02hX flag=%02" PRIX32 ")",
|
||||
this->name.c_str(),
|
||||
name_for_enum(this->version),
|
||||
header.command(this->version),
|
||||
header.flag(this->version));
|
||||
}
|
||||
|
||||
vector<struct iovec> iovs;
|
||||
iovs.emplace_back(iovec{.iov_base = header_data.data(), .iov_len = header_data.size()});
|
||||
iovs.emplace_back(iovec{.iov_base = command_data.data(), .iov_len = command_data.size()});
|
||||
print_data(stderr, iovs, 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::DISABLE_COLOR | PrintDataFlags::OFFSET_16_BITS);
|
||||
|
||||
if (use_terminal_colors && this->terminal_recv_color != TerminalFormat::NORMAL) {
|
||||
print_color_escape(stderr, TerminalFormat::NORMAL, TerminalFormat::END);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
.command = header.command(this->version),
|
||||
.flag = header.flag(this->version),
|
||||
.data = std::move(command_data),
|
||||
};
|
||||
}
|
||||
|
||||
void Channel::send(uint16_t cmd, uint32_t flag, bool silent) {
|
||||
this->send(cmd, flag, nullptr, 0, silent);
|
||||
}
|
||||
|
||||
void Channel::send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<const void*, size_t>> blocks, bool silent) {
|
||||
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;
|
||||
switch (this->version) {
|
||||
case Version::DC_NTE:
|
||||
case Version::DC_V1_11_2000_PROTOTYPE:
|
||||
case Version::DC_V1:
|
||||
case Version::DC_V2:
|
||||
case Version::GC_NTE:
|
||||
case Version::GC_V3:
|
||||
case Version::GC_EP3_NTE:
|
||||
case Version::GC_EP3:
|
||||
case Version::XB_V3: {
|
||||
PSOCommandHeaderDCV3 header;
|
||||
if (this->crypt_out.get() &&
|
||||
(this->version != Version::DC_NTE) &&
|
||||
(this->version != Version::DC_V1_11_2000_PROTOTYPE) &&
|
||||
(this->version != Version::DC_V1)) {
|
||||
send_data_size = (sizeof(header) + size + 3) & ~3;
|
||||
} else {
|
||||
send_data_size = (sizeof(header) + size);
|
||||
}
|
||||
logical_size = send_data_size;
|
||||
header.command = cmd;
|
||||
header.flag = flag;
|
||||
header.size = send_data_size;
|
||||
send_data.append(reinterpret_cast<const char*>(&header), sizeof(header));
|
||||
break;
|
||||
}
|
||||
case Version::PC_PATCH:
|
||||
case Version::BB_PATCH:
|
||||
case Version::PC_NTE:
|
||||
case Version::PC_V2: {
|
||||
PSOCommandHeaderPC header;
|
||||
if (this->crypt_out.get()) {
|
||||
send_data_size = (sizeof(header) + size + 3) & ~3;
|
||||
} else {
|
||||
send_data_size = (sizeof(header) + size);
|
||||
}
|
||||
logical_size = send_data_size;
|
||||
header.size = send_data_size;
|
||||
header.command = cmd;
|
||||
header.flag = flag;
|
||||
send_data.append(reinterpret_cast<const char*>(&header), sizeof(header));
|
||||
break;
|
||||
}
|
||||
case Version::BB_V4: {
|
||||
// BB has an annoying behavior here: command lengths must be multiples of
|
||||
// 4, but the actual data length must be a multiple of 8. If the size
|
||||
// field is not divisible by 8, 4 extra bytes are sent anyway. This
|
||||
// behavior only applies when encryption is enabled - any commands sent
|
||||
// before encryption is enabled have no size restrictions (except they
|
||||
// must include a full header and must fit in the client's receive
|
||||
// buffer), and no implicit extra bytes are sent.
|
||||
PSOCommandHeaderBB header;
|
||||
if (this->crypt_out.get()) {
|
||||
send_data_size = (sizeof(header) + size + 7) & ~7;
|
||||
} else {
|
||||
send_data_size = (sizeof(header) + size);
|
||||
}
|
||||
logical_size = (sizeof(header) + size + 3) & ~3;
|
||||
header.size = logical_size;
|
||||
header.command = cmd;
|
||||
header.flag = flag;
|
||||
send_data.append(reinterpret_cast<const char*>(&header), sizeof(header));
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
throw logic_error("unimplemented game version in send_command");
|
||||
}
|
||||
|
||||
// All versions of PSO I've seen (so far) have a receive buffer 0x7C00
|
||||
// bytes in size
|
||||
if (send_data_size > 0x7C00) {
|
||||
throw runtime_error("outbound command too large");
|
||||
}
|
||||
|
||||
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 (!silent && (command_data_log.should_log(LogLevel::INFO)) && (this->terminal_send_color != TerminalFormat::END)) {
|
||||
if (use_terminal_colors && this->terminal_send_color != TerminalFormat::NORMAL) {
|
||||
print_color_escape(stderr, TerminalFormat::FG_YELLOW, TerminalFormat::BOLD, TerminalFormat::END);
|
||||
}
|
||||
if (version == Version::BB_V4) {
|
||||
command_data_log.info("Sending to %s (version=BB command=%04hX flag=%08" PRIX32 ")",
|
||||
this->name.c_str(), cmd, flag);
|
||||
} else {
|
||||
command_data_log.info("Sending to %s (version=%s command=%02hX flag=%02" PRIX32 ")",
|
||||
this->name.c_str(), name_for_enum(version), cmd, flag);
|
||||
}
|
||||
print_data(stderr, send_data.data(), logical_size, 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::DISABLE_COLOR | PrintDataFlags::OFFSET_16_BITS);
|
||||
if (use_terminal_colors && this->terminal_send_color != TerminalFormat::NORMAL) {
|
||||
print_color_escape(stderr, TerminalFormat::NORMAL, TerminalFormat::END);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->crypt_out.get()) {
|
||||
this->crypt_out->encrypt(send_data.data(), send_data.size());
|
||||
}
|
||||
|
||||
struct evbuffer* buf = bufferevent_get_output(this->bev.get());
|
||||
evbuffer_add(buf, send_data.data(), send_data.size());
|
||||
}
|
||||
|
||||
void Channel::send(uint16_t cmd, uint32_t flag, const void* data, size_t size, bool silent) {
|
||||
this->send(cmd, flag, {make_pair(data, size)}, silent);
|
||||
}
|
||||
|
||||
void Channel::send(uint16_t cmd, uint32_t flag, const string& data, bool silent) {
|
||||
this->send(cmd, flag, data.data(), data.size(), silent);
|
||||
}
|
||||
|
||||
void Channel::send(const void* data, size_t size, bool silent) {
|
||||
size_t header_size = (this->version == Version::BB_V4) ? 8 : 4;
|
||||
const auto* header = reinterpret_cast<const PSOCommandHeader*>(data);
|
||||
this->send(
|
||||
header->command(this->version),
|
||||
header->flag(this->version),
|
||||
reinterpret_cast<const uint8_t*>(data) + header_size,
|
||||
size - header_size,
|
||||
silent);
|
||||
}
|
||||
|
||||
void Channel::send(const string& data, bool silent) {
|
||||
return this->send(data.data(), data.size(), silent);
|
||||
}
|
||||
|
||||
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
|
||||
// make sure ch->bev is valid every time before calling recv()
|
||||
while (ch->bev.get()) {
|
||||
Message msg;
|
||||
try {
|
||||
msg = ch->recv();
|
||||
} catch (const out_of_range&) {
|
||||
break;
|
||||
} catch (const exception& e) {
|
||||
channel_exceptions_log.warning("Error receiving on channel: %s", e.what());
|
||||
ch->on_error(*ch, BEV_EVENT_ERROR);
|
||||
break;
|
||||
}
|
||||
if (ch->on_command_received) {
|
||||
ch->on_command_received(*ch, msg.command, msg.flag, msg.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Channel::dispatch_on_error(struct bufferevent*, short events, void* ctx) {
|
||||
Channel* ch = reinterpret_cast<Channel*>(ctx);
|
||||
if (ch->on_error) {
|
||||
ch->on_error(*ch, events);
|
||||
} else {
|
||||
ch->disconnect();
|
||||
}
|
||||
}
|
||||
#include "Channel.hh"
|
||||
|
||||
#include <errno.h>
|
||||
#include <event2/buffer.h>
|
||||
#include <event2/bufferevent.h>
|
||||
#include <event2/event.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <phosg/Network.hh>
|
||||
#include <phosg/Time.hh>
|
||||
|
||||
#include "Loggers.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
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(
|
||||
Version version,
|
||||
uint8_t language,
|
||||
on_command_received_t on_command_received,
|
||||
on_error_t on_error,
|
||||
void* context_obj,
|
||||
const string& name,
|
||||
TerminalFormat terminal_send_color,
|
||||
TerminalFormat terminal_recv_color)
|
||||
: bev(nullptr, flush_and_free_bufferevent),
|
||||
virtual_network_id(0),
|
||||
version(version),
|
||||
language(language),
|
||||
name(name),
|
||||
terminal_send_color(terminal_send_color),
|
||||
terminal_recv_color(terminal_recv_color),
|
||||
on_command_received(on_command_received),
|
||||
on_error(on_error),
|
||||
context_obj(context_obj) {
|
||||
}
|
||||
|
||||
Channel::Channel(
|
||||
struct bufferevent* bev,
|
||||
uint64_t virtual_network_id,
|
||||
Version version,
|
||||
uint8_t language,
|
||||
on_command_received_t on_command_received,
|
||||
on_error_t on_error,
|
||||
void* context_obj,
|
||||
const string& name,
|
||||
TerminalFormat terminal_send_color,
|
||||
TerminalFormat terminal_recv_color)
|
||||
: bev(nullptr, flush_and_free_bufferevent),
|
||||
version(version),
|
||||
language(language),
|
||||
name(name),
|
||||
terminal_send_color(terminal_send_color),
|
||||
terminal_recv_color(terminal_recv_color),
|
||||
on_command_received(on_command_received),
|
||||
on_error(on_error),
|
||||
context_obj(context_obj) {
|
||||
this->set_bufferevent(bev, virtual_network_id);
|
||||
}
|
||||
|
||||
void Channel::replace_with(
|
||||
Channel&& other,
|
||||
on_command_received_t on_command_received,
|
||||
on_error_t on_error,
|
||||
void* context_obj,
|
||||
const std::string& name) {
|
||||
this->set_bufferevent(other.bev.release(), other.virtual_network_id);
|
||||
this->local_addr = other.local_addr;
|
||||
this->remote_addr = other.remote_addr;
|
||||
this->version = other.version;
|
||||
this->language = other.language;
|
||||
this->crypt_in = other.crypt_in;
|
||||
this->crypt_out = other.crypt_out;
|
||||
this->name = name;
|
||||
this->terminal_send_color = other.terminal_send_color;
|
||||
this->terminal_recv_color = other.terminal_recv_color;
|
||||
this->on_command_received = on_command_received;
|
||||
this->on_error = on_error;
|
||||
this->context_obj = context_obj;
|
||||
other.disconnect(); // Clears crypts, addrs, etc.
|
||||
}
|
||||
|
||||
void Channel::set_bufferevent(struct bufferevent* bev, uint64_t virtual_network_id) {
|
||||
this->bev.reset(bev);
|
||||
this->virtual_network_id = virtual_network_id;
|
||||
|
||||
if (this->bev.get()) {
|
||||
int fd = bufferevent_getfd(this->bev.get());
|
||||
if (fd < 0) {
|
||||
memset(&this->local_addr, 0, sizeof(this->local_addr));
|
||||
memset(&this->remote_addr, 0, sizeof(this->remote_addr));
|
||||
} else {
|
||||
get_socket_addresses(fd, &this->local_addr, &this->remote_addr);
|
||||
}
|
||||
|
||||
bufferevent_setcb(this->bev.get(), &Channel::dispatch_on_input, nullptr, &Channel::dispatch_on_error, this);
|
||||
bufferevent_enable(this->bev.get(), EV_READ | EV_WRITE);
|
||||
|
||||
} else {
|
||||
memset(&this->local_addr, 0, sizeof(this->local_addr));
|
||||
memset(&this->remote_addr, 0, sizeof(this->remote_addr));
|
||||
}
|
||||
}
|
||||
|
||||
void Channel::disconnect() {
|
||||
if (this->bev.get()) {
|
||||
// If the output buffer is not empty, move the bufferevent into the draining
|
||||
// pool instead of disconnecting it, to make sure all the data gets sent.
|
||||
struct evbuffer* out_buffer = bufferevent_get_output(this->bev.get());
|
||||
if (evbuffer_get_length(out_buffer) == 0) {
|
||||
this->bev.reset(); // Destructor flushes and frees the bufferevent
|
||||
} else {
|
||||
// The callbacks will free it when all the data is sent or the client
|
||||
// disconnects
|
||||
|
||||
auto on_output = +[](struct bufferevent* bev, void*) -> void {
|
||||
flush_and_free_bufferevent(bev);
|
||||
};
|
||||
|
||||
auto on_error = +[](struct bufferevent* bev, short events, void*) -> void {
|
||||
if (events & BEV_EVENT_ERROR) {
|
||||
int err = EVUTIL_SOCKET_ERROR();
|
||||
channel_exceptions_log.warning(
|
||||
"Disconnecting channel caused error %d (%s)", err,
|
||||
evutil_socket_error_to_string(err));
|
||||
}
|
||||
if (events & (BEV_EVENT_EOF | BEV_EVENT_ERROR)) {
|
||||
bufferevent_flush(bev, EV_WRITE, BEV_FINISHED);
|
||||
bufferevent_free(bev);
|
||||
}
|
||||
};
|
||||
|
||||
struct bufferevent* bev = this->bev.release();
|
||||
bufferevent_setcb(bev, nullptr, on_output, on_error, bev);
|
||||
bufferevent_disable(bev, EV_READ);
|
||||
}
|
||||
}
|
||||
|
||||
memset(&this->local_addr, 0, sizeof(this->local_addr));
|
||||
memset(&this->remote_addr, 0, sizeof(this->remote_addr));
|
||||
this->virtual_network_id = false;
|
||||
this->crypt_in.reset();
|
||||
this->crypt_out.reset();
|
||||
}
|
||||
|
||||
Channel::Message Channel::recv() {
|
||||
struct evbuffer* buf = bufferevent_get_input(this->bev.get());
|
||||
|
||||
size_t header_size = (this->version == Version::BB_V4) ? 8 : 4;
|
||||
PSOCommandHeader header;
|
||||
if (evbuffer_copyout(buf, &header, header_size) < static_cast<ssize_t>(header_size)) {
|
||||
throw out_of_range("no command available");
|
||||
}
|
||||
|
||||
if (this->crypt_in.get()) {
|
||||
this->crypt_in->decrypt(&header, header_size, false);
|
||||
}
|
||||
|
||||
size_t command_logical_size = header.size(version);
|
||||
|
||||
// If encryption is enabled, BB pads commands to 8-byte boundaries, and this
|
||||
// is not reflected in the size field. This logic does not occur if encryption
|
||||
// is not yet enabled.
|
||||
size_t command_physical_size = (this->crypt_in.get() && (version == Version::BB_V4))
|
||||
? ((command_logical_size + 7) & ~7)
|
||||
: command_logical_size;
|
||||
if (evbuffer_get_length(buf) < command_physical_size) {
|
||||
throw out_of_range("no command available");
|
||||
}
|
||||
|
||||
// If we get here, then there is a full command in the buffer. Some encryption
|
||||
// algorithms' advancement depends on the decrypted data, so we have to
|
||||
// actually decrypt the header again (with advance=true) to keep them in a
|
||||
// consistent state.
|
||||
|
||||
string header_data(header_size, '\0');
|
||||
if (evbuffer_remove(buf, header_data.data(), header_data.size()) < static_cast<ssize_t>(header_data.size())) {
|
||||
throw logic_error("enough bytes available, but could not remove them");
|
||||
}
|
||||
if (this->crypt_in.get()) {
|
||||
this->crypt_in->decrypt(header_data.data(), header_data.size());
|
||||
}
|
||||
|
||||
string command_data(command_physical_size - header_size, '\0');
|
||||
if (evbuffer_remove(buf, command_data.data(), command_data.size()) < static_cast<ssize_t>(command_data.size())) {
|
||||
throw logic_error("enough bytes available, but could not remove them");
|
||||
}
|
||||
|
||||
if (this->crypt_in.get()) {
|
||||
// Some versions of PSO DC can send commands whose sizes are not a multiple
|
||||
// of 4, but the server is expected to always use a multiple of 4 bytes when
|
||||
// decrypting (the extra cipher bytes are lost). To emulate this behavior,
|
||||
// we have to round up the size for DC commands here.
|
||||
size_t orig_size = command_data.size();
|
||||
command_data.resize((orig_size + 3) & (~3), 0);
|
||||
this->crypt_in->decrypt(command_data.data(), command_data.size());
|
||||
command_data.resize(orig_size);
|
||||
}
|
||||
command_data.resize(command_logical_size - header_size);
|
||||
|
||||
if (command_data_log.should_log(LogLevel::INFO) && (this->terminal_recv_color != TerminalFormat::END)) {
|
||||
if (use_terminal_colors && this->terminal_recv_color != TerminalFormat::NORMAL) {
|
||||
print_color_escape(stderr, this->terminal_recv_color, TerminalFormat::BOLD, TerminalFormat::END);
|
||||
}
|
||||
|
||||
if (version == Version::BB_V4) {
|
||||
command_data_log.info(
|
||||
"Received from %s (version=BB command=%04hX flag=%08" PRIX32 ")",
|
||||
this->name.c_str(),
|
||||
header.command(this->version),
|
||||
header.flag(this->version));
|
||||
} else {
|
||||
command_data_log.info(
|
||||
"Received from %s (version=%s command=%02hX flag=%02" PRIX32 ")",
|
||||
this->name.c_str(),
|
||||
name_for_enum(this->version),
|
||||
header.command(this->version),
|
||||
header.flag(this->version));
|
||||
}
|
||||
|
||||
vector<struct iovec> iovs;
|
||||
iovs.emplace_back(iovec{.iov_base = header_data.data(), .iov_len = header_data.size()});
|
||||
iovs.emplace_back(iovec{.iov_base = command_data.data(), .iov_len = command_data.size()});
|
||||
print_data(stderr, iovs, 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::DISABLE_COLOR | PrintDataFlags::OFFSET_16_BITS);
|
||||
|
||||
if (use_terminal_colors && this->terminal_recv_color != TerminalFormat::NORMAL) {
|
||||
print_color_escape(stderr, TerminalFormat::NORMAL, TerminalFormat::END);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
.command = header.command(this->version),
|
||||
.flag = header.flag(this->version),
|
||||
.data = std::move(command_data),
|
||||
};
|
||||
}
|
||||
|
||||
void Channel::send(uint16_t cmd, uint32_t flag, bool silent) {
|
||||
this->send(cmd, flag, nullptr, 0, silent);
|
||||
}
|
||||
|
||||
void Channel::send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<const void*, size_t>> blocks, bool silent) {
|
||||
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;
|
||||
switch (this->version) {
|
||||
case Version::DC_NTE:
|
||||
case Version::DC_V1_11_2000_PROTOTYPE:
|
||||
case Version::DC_V1:
|
||||
case Version::DC_V2:
|
||||
case Version::GC_NTE:
|
||||
case Version::GC_V3:
|
||||
case Version::GC_EP3_NTE:
|
||||
case Version::GC_EP3:
|
||||
case Version::XB_V3: {
|
||||
PSOCommandHeaderDCV3 header;
|
||||
if (this->crypt_out.get() &&
|
||||
(this->version != Version::DC_NTE) &&
|
||||
(this->version != Version::DC_V1_11_2000_PROTOTYPE) &&
|
||||
(this->version != Version::DC_V1)) {
|
||||
send_data_size = (sizeof(header) + size + 3) & ~3;
|
||||
} else {
|
||||
send_data_size = (sizeof(header) + size);
|
||||
}
|
||||
logical_size = send_data_size;
|
||||
header.command = cmd;
|
||||
header.flag = flag;
|
||||
header.size = send_data_size;
|
||||
send_data.append(reinterpret_cast<const char*>(&header), sizeof(header));
|
||||
break;
|
||||
}
|
||||
case Version::PC_PATCH:
|
||||
case Version::BB_PATCH:
|
||||
case Version::PC_NTE:
|
||||
case Version::PC_V2: {
|
||||
PSOCommandHeaderPC header;
|
||||
if (this->crypt_out.get()) {
|
||||
send_data_size = (sizeof(header) + size + 3) & ~3;
|
||||
} else {
|
||||
send_data_size = (sizeof(header) + size);
|
||||
}
|
||||
logical_size = send_data_size;
|
||||
header.size = send_data_size;
|
||||
header.command = cmd;
|
||||
header.flag = flag;
|
||||
send_data.append(reinterpret_cast<const char*>(&header), sizeof(header));
|
||||
break;
|
||||
}
|
||||
case Version::BB_V4: {
|
||||
// BB has an annoying behavior here: command lengths must be multiples of
|
||||
// 4, but the actual data length must be a multiple of 8. If the size
|
||||
// field is not divisible by 8, 4 extra bytes are sent anyway. This
|
||||
// behavior only applies when encryption is enabled - any commands sent
|
||||
// before encryption is enabled have no size restrictions (except they
|
||||
// must include a full header and must fit in the client's receive
|
||||
// buffer), and no implicit extra bytes are sent.
|
||||
PSOCommandHeaderBB header;
|
||||
if (this->crypt_out.get()) {
|
||||
send_data_size = (sizeof(header) + size + 7) & ~7;
|
||||
} else {
|
||||
send_data_size = (sizeof(header) + size);
|
||||
}
|
||||
logical_size = (sizeof(header) + size + 3) & ~3;
|
||||
header.size = logical_size;
|
||||
header.command = cmd;
|
||||
header.flag = flag;
|
||||
send_data.append(reinterpret_cast<const char*>(&header), sizeof(header));
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
throw logic_error("unimplemented game version in send_command");
|
||||
}
|
||||
|
||||
// All versions of PSO I've seen (so far) have a receive buffer 0x7C00
|
||||
// bytes in size
|
||||
if (send_data_size > 0x7C00) {
|
||||
throw runtime_error("outbound command too large");
|
||||
}
|
||||
|
||||
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 (!silent && (command_data_log.should_log(LogLevel::INFO)) && (this->terminal_send_color != TerminalFormat::END)) {
|
||||
if (use_terminal_colors && this->terminal_send_color != TerminalFormat::NORMAL) {
|
||||
print_color_escape(stderr, TerminalFormat::FG_YELLOW, TerminalFormat::BOLD, TerminalFormat::END);
|
||||
}
|
||||
if (version == Version::BB_V4) {
|
||||
command_data_log.info("Sending to %s (version=BB command=%04hX flag=%08" PRIX32 ")",
|
||||
this->name.c_str(), cmd, flag);
|
||||
} else {
|
||||
command_data_log.info("Sending to %s (version=%s command=%02hX flag=%02" PRIX32 ")",
|
||||
this->name.c_str(), name_for_enum(version), cmd, flag);
|
||||
}
|
||||
print_data(stderr, send_data.data(), logical_size, 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::DISABLE_COLOR | PrintDataFlags::OFFSET_16_BITS);
|
||||
if (use_terminal_colors && this->terminal_send_color != TerminalFormat::NORMAL) {
|
||||
print_color_escape(stderr, TerminalFormat::NORMAL, TerminalFormat::END);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->crypt_out.get()) {
|
||||
this->crypt_out->encrypt(send_data.data(), send_data.size());
|
||||
}
|
||||
|
||||
struct evbuffer* buf = bufferevent_get_output(this->bev.get());
|
||||
evbuffer_add(buf, send_data.data(), send_data.size());
|
||||
}
|
||||
|
||||
void Channel::send(uint16_t cmd, uint32_t flag, const void* data, size_t size, bool silent) {
|
||||
this->send(cmd, flag, {make_pair(data, size)}, silent);
|
||||
}
|
||||
|
||||
void Channel::send(uint16_t cmd, uint32_t flag, const string& data, bool silent) {
|
||||
this->send(cmd, flag, data.data(), data.size(), silent);
|
||||
}
|
||||
|
||||
void Channel::send(const void* data, size_t size, bool silent) {
|
||||
size_t header_size = (this->version == Version::BB_V4) ? 8 : 4;
|
||||
const auto* header = reinterpret_cast<const PSOCommandHeader*>(data);
|
||||
this->send(
|
||||
header->command(this->version),
|
||||
header->flag(this->version),
|
||||
reinterpret_cast<const uint8_t*>(data) + header_size,
|
||||
size - header_size,
|
||||
silent);
|
||||
}
|
||||
|
||||
void Channel::send(const string& data, bool silent) {
|
||||
return this->send(data.data(), data.size(), silent);
|
||||
}
|
||||
|
||||
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
|
||||
// make sure ch->bev is valid every time before calling recv()
|
||||
while (ch->bev.get()) {
|
||||
Message msg;
|
||||
try {
|
||||
msg = ch->recv();
|
||||
} catch (const out_of_range&) {
|
||||
break;
|
||||
} catch (const exception& e) {
|
||||
channel_exceptions_log.warning("Error receiving on channel: %s", e.what());
|
||||
ch->on_error(*ch, BEV_EVENT_ERROR);
|
||||
break;
|
||||
}
|
||||
if (ch->on_command_received) {
|
||||
ch->on_command_received(*ch, msg.command, msg.flag, msg.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Channel::dispatch_on_error(struct bufferevent*, short events, void* ctx) {
|
||||
Channel* ch = reinterpret_cast<Channel*>(ctx);
|
||||
if (ch->on_error) {
|
||||
ch->on_error(*ch, events);
|
||||
} else {
|
||||
ch->disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
+103
-103
@@ -1,103 +1,103 @@
|
||||
#pragma once
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "PSOEncryption.hh"
|
||||
#include "PSOProtocol.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
struct Channel {
|
||||
std::unique_ptr<struct bufferevent, void (*)(struct bufferevent*)> bev;
|
||||
struct sockaddr_storage local_addr;
|
||||
struct sockaddr_storage remote_addr;
|
||||
uint64_t virtual_network_id; // 0 = normal TCP connection
|
||||
|
||||
Version version;
|
||||
uint8_t language;
|
||||
std::shared_ptr<PSOEncryption> crypt_in;
|
||||
std::shared_ptr<PSOEncryption> crypt_out;
|
||||
|
||||
std::string name;
|
||||
TerminalFormat terminal_send_color;
|
||||
TerminalFormat terminal_recv_color;
|
||||
|
||||
struct Message {
|
||||
uint16_t command;
|
||||
uint32_t flag;
|
||||
std::string data;
|
||||
};
|
||||
|
||||
typedef void (*on_command_received_t)(Channel&, uint16_t, uint32_t, std::string&);
|
||||
typedef void (*on_error_t)(Channel&, short);
|
||||
|
||||
on_command_received_t on_command_received;
|
||||
on_error_t on_error;
|
||||
void* context_obj;
|
||||
|
||||
// Creates an unconnected channel
|
||||
Channel(
|
||||
Version version,
|
||||
uint8_t language,
|
||||
on_command_received_t on_command_received,
|
||||
on_error_t on_error,
|
||||
void* context_obj,
|
||||
const std::string& name,
|
||||
TerminalFormat terminal_send_color = TerminalFormat::END,
|
||||
TerminalFormat terminal_recv_color = TerminalFormat::END);
|
||||
// Creates a connected channel
|
||||
Channel(
|
||||
struct bufferevent* bev,
|
||||
uint64_t virtual_network_id,
|
||||
Version version,
|
||||
uint8_t language,
|
||||
on_command_received_t on_command_received,
|
||||
on_error_t on_error,
|
||||
void* context_obj,
|
||||
const std::string& name = "",
|
||||
TerminalFormat terminal_send_color = TerminalFormat::END,
|
||||
TerminalFormat terminal_recv_color = TerminalFormat::END);
|
||||
Channel(const Channel& other) = delete;
|
||||
Channel(Channel&& other) = delete;
|
||||
Channel& operator=(const Channel& other) = delete;
|
||||
Channel& operator=(Channel&& other) = delete;
|
||||
|
||||
void replace_with(
|
||||
Channel&& other,
|
||||
on_command_received_t on_command_received,
|
||||
on_error_t on_error,
|
||||
void* context_obj,
|
||||
const std::string& name = "");
|
||||
|
||||
void set_bufferevent(struct bufferevent* bev, uint64_t virtual_network_id);
|
||||
|
||||
inline bool connected() const {
|
||||
return this->bev.get() != nullptr;
|
||||
}
|
||||
void disconnect();
|
||||
|
||||
// Receives a message. Throws std::out_of_range if no messages are available.
|
||||
Message recv();
|
||||
|
||||
// Sends a message with an automatically-constructed header.
|
||||
void send(uint16_t cmd, uint32_t flag = 0, bool silent = false);
|
||||
void send(uint16_t cmd, uint32_t flag, const void* data, size_t size, bool silent = false);
|
||||
void send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<const void*, size_t>> blocks, bool silent = false);
|
||||
void send(uint16_t cmd, uint32_t flag, const std::string& data, bool silent = false);
|
||||
template <typename CmdT>
|
||||
requires(!std::is_pointer_v<CmdT>)
|
||||
void send(uint16_t cmd, uint32_t flag, const CmdT& data, bool silent = false) {
|
||||
this->send(cmd, flag, &data, sizeof(data), silent);
|
||||
}
|
||||
|
||||
// Sends a message with a pre-existing header (as the first few bytes in the
|
||||
// data)
|
||||
void send(const void* data, size_t size, bool silent = false);
|
||||
void send(const std::string& data, bool silent = false);
|
||||
|
||||
private:
|
||||
static void dispatch_on_input(struct bufferevent*, void* ctx);
|
||||
static void dispatch_on_error(struct bufferevent*, short events, void* ctx);
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "PSOEncryption.hh"
|
||||
#include "PSOProtocol.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
struct Channel {
|
||||
std::unique_ptr<struct bufferevent, void (*)(struct bufferevent*)> bev;
|
||||
struct sockaddr_storage local_addr;
|
||||
struct sockaddr_storage remote_addr;
|
||||
uint64_t virtual_network_id; // 0 = normal TCP connection
|
||||
|
||||
Version version;
|
||||
uint8_t language;
|
||||
std::shared_ptr<PSOEncryption> crypt_in;
|
||||
std::shared_ptr<PSOEncryption> crypt_out;
|
||||
|
||||
std::string name;
|
||||
TerminalFormat terminal_send_color;
|
||||
TerminalFormat terminal_recv_color;
|
||||
|
||||
struct Message {
|
||||
uint16_t command;
|
||||
uint32_t flag;
|
||||
std::string data;
|
||||
};
|
||||
|
||||
typedef void (*on_command_received_t)(Channel&, uint16_t, uint32_t, std::string&);
|
||||
typedef void (*on_error_t)(Channel&, short);
|
||||
|
||||
on_command_received_t on_command_received;
|
||||
on_error_t on_error;
|
||||
void* context_obj;
|
||||
|
||||
// Creates an unconnected channel
|
||||
Channel(
|
||||
Version version,
|
||||
uint8_t language,
|
||||
on_command_received_t on_command_received,
|
||||
on_error_t on_error,
|
||||
void* context_obj,
|
||||
const std::string& name,
|
||||
TerminalFormat terminal_send_color = TerminalFormat::END,
|
||||
TerminalFormat terminal_recv_color = TerminalFormat::END);
|
||||
// Creates a connected channel
|
||||
Channel(
|
||||
struct bufferevent* bev,
|
||||
uint64_t virtual_network_id,
|
||||
Version version,
|
||||
uint8_t language,
|
||||
on_command_received_t on_command_received,
|
||||
on_error_t on_error,
|
||||
void* context_obj,
|
||||
const std::string& name = "",
|
||||
TerminalFormat terminal_send_color = TerminalFormat::END,
|
||||
TerminalFormat terminal_recv_color = TerminalFormat::END);
|
||||
Channel(const Channel& other) = delete;
|
||||
Channel(Channel&& other) = delete;
|
||||
Channel& operator=(const Channel& other) = delete;
|
||||
Channel& operator=(Channel&& other) = delete;
|
||||
|
||||
void replace_with(
|
||||
Channel&& other,
|
||||
on_command_received_t on_command_received,
|
||||
on_error_t on_error,
|
||||
void* context_obj,
|
||||
const std::string& name = "");
|
||||
|
||||
void set_bufferevent(struct bufferevent* bev, uint64_t virtual_network_id);
|
||||
|
||||
inline bool connected() const {
|
||||
return this->bev.get() != nullptr;
|
||||
}
|
||||
void disconnect();
|
||||
|
||||
// Receives a message. Throws std::out_of_range if no messages are available.
|
||||
Message recv();
|
||||
|
||||
// Sends a message with an automatically-constructed header.
|
||||
void send(uint16_t cmd, uint32_t flag = 0, bool silent = false);
|
||||
void send(uint16_t cmd, uint32_t flag, const void* data, size_t size, bool silent = false);
|
||||
void send(uint16_t cmd, uint32_t flag, const std::vector<std::pair<const void*, size_t>> blocks, bool silent = false);
|
||||
void send(uint16_t cmd, uint32_t flag, const std::string& data, bool silent = false);
|
||||
template <typename CmdT>
|
||||
requires(!std::is_pointer_v<CmdT>)
|
||||
void send(uint16_t cmd, uint32_t flag, const CmdT& data, bool silent = false) {
|
||||
this->send(cmd, flag, &data, sizeof(data), silent);
|
||||
}
|
||||
|
||||
// Sends a message with a pre-existing header (as the first few bytes in the
|
||||
// data)
|
||||
void send(const void* data, size_t size, bool silent = false);
|
||||
void send(const std::string& data, bool silent = false);
|
||||
|
||||
private:
|
||||
static void dispatch_on_input(struct bufferevent*, void* ctx);
|
||||
static void dispatch_on_error(struct bufferevent*, short events, void* ctx);
|
||||
};
|
||||
|
||||
+2603
-2472
File diff suppressed because it is too large
Load Diff
+14
-14
@@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "Client.hh"
|
||||
#include "Lobby.hh"
|
||||
#include "ProxyServer.hh"
|
||||
#include "ServerState.hh"
|
||||
|
||||
void on_chat_command(std::shared_ptr<Client> c, const std::string& text);
|
||||
void on_chat_command(std::shared_ptr<ProxyServer::LinkedSession> ses, const std::string& text);
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "Client.hh"
|
||||
#include "Lobby.hh"
|
||||
#include "ProxyServer.hh"
|
||||
#include "ServerState.hh"
|
||||
|
||||
void on_chat_command(std::shared_ptr<Client> c, const std::string& text);
|
||||
void on_chat_command(std::shared_ptr<ProxyServer::LinkedSession> ses, const std::string& text);
|
||||
|
||||
+150
-150
@@ -1,150 +1,150 @@
|
||||
#include "ChoiceSearch.hh"
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "Client.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
const vector<ChoiceSearchCategory> CHOICE_SEARCH_CATEGORIES({
|
||||
ChoiceSearchCategory{
|
||||
.id = 0x0001,
|
||||
.name = "Level",
|
||||
.choices = {
|
||||
{0x0000, "Any"},
|
||||
{0x0001, "Own level +/- 5"},
|
||||
{0x0002, "Level 1-10"},
|
||||
{0x0003, "Level 11-20"},
|
||||
{0x0004, "Level 21-40"},
|
||||
{0x0005, "Level 41-60"},
|
||||
{0x0006, "Level 61-80"},
|
||||
{0x0007, "Level 81-100"},
|
||||
{0x0008, "Level 101-120"},
|
||||
{0x0009, "Level 121-160"},
|
||||
{0x000A, "Level 161-200"},
|
||||
},
|
||||
.client_matches = +[](shared_ptr<Client> searcher_c, shared_ptr<Client> target_c, uint16_t choice_id) -> bool {
|
||||
if (choice_id == 0x0000) {
|
||||
return true;
|
||||
}
|
||||
uint32_t target_level = target_c->character()->disp.stats.level + 1;
|
||||
switch (choice_id) {
|
||||
case 0x0001:
|
||||
return (labs(static_cast<int32_t>(target_level - searcher_c->character()->disp.stats.level)) <= 5);
|
||||
case 0x0002:
|
||||
return (target_level <= 10);
|
||||
case 0x0003:
|
||||
return (target_level > 10) && (target_level <= 20);
|
||||
case 0x0004:
|
||||
return (target_level > 20) && (target_level <= 40);
|
||||
case 0x0005:
|
||||
return (target_level > 40) && (target_level <= 60);
|
||||
case 0x0006:
|
||||
return (target_level > 60) && (target_level <= 80);
|
||||
case 0x0007:
|
||||
return (target_level > 80) && (target_level <= 100);
|
||||
case 0x0008:
|
||||
return (target_level > 100) && (target_level <= 120);
|
||||
case 0x0009:
|
||||
return (target_level > 120) && (target_level <= 160);
|
||||
case 0x000A:
|
||||
return (target_level > 160) && (target_level <= 200);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
},
|
||||
ChoiceSearchCategory{
|
||||
.id = 0x0002,
|
||||
.name = "Class",
|
||||
.choices = {
|
||||
{0x0000, "Any"},
|
||||
{0x0010, "Hunter"},
|
||||
{0x0001, "HUmar"},
|
||||
{0x0002, "HUnewearl"},
|
||||
{0x0003, "HUcast"},
|
||||
{0x000A, "HUcaseal"},
|
||||
{0x0011, "Ranger"},
|
||||
{0x0004, "RAmar"},
|
||||
{0x000C, "RAmarl"},
|
||||
{0x0005, "RAcast"},
|
||||
{0x0006, "RAcaseal"},
|
||||
{0x0012, "Force"},
|
||||
{0x000B, "FOmar"},
|
||||
{0x0007, "FOmarl"},
|
||||
{0x0008, "FOnewm"},
|
||||
{0x0009, "FOnewearl"},
|
||||
},
|
||||
.client_matches = +[](shared_ptr<Client>, shared_ptr<Client> target_c, uint16_t choice_id) -> bool {
|
||||
switch (choice_id) {
|
||||
case 0x0000:
|
||||
return true;
|
||||
case 0x0010:
|
||||
return target_c->character()->disp.visual.class_flags & 0x20;
|
||||
case 0x0011:
|
||||
return target_c->character()->disp.visual.class_flags & 0x40;
|
||||
case 0x0012:
|
||||
return target_c->character()->disp.visual.class_flags & 0x80;
|
||||
default:
|
||||
return ((choice_id - 1) == target_c->character()->disp.visual.char_class);
|
||||
}
|
||||
},
|
||||
},
|
||||
ChoiceSearchCategory{
|
||||
.id = 0x0003,
|
||||
.name = "Platform",
|
||||
.choices = {
|
||||
{0x0000, "Any"},
|
||||
{0x0001, "DC betas"},
|
||||
{0x0002, "DC V1"},
|
||||
{0x0003, "DC V2 / PC"},
|
||||
{0x0004, "GC / Xbox Episodes 1&2"},
|
||||
{0x0005, "GC Episode 3"},
|
||||
{0x0006, "BB"},
|
||||
},
|
||||
.client_matches = +[](shared_ptr<Client>, shared_ptr<Client> target_c, uint16_t choice_id) -> bool {
|
||||
if (choice_id == 0x0000) {
|
||||
return true;
|
||||
}
|
||||
switch (target_c->version()) {
|
||||
case Version::DC_NTE:
|
||||
case Version::DC_V1_11_2000_PROTOTYPE:
|
||||
return (choice_id == 0x0001);
|
||||
case Version::DC_V1:
|
||||
return (choice_id == 0x0002);
|
||||
case Version::DC_V2:
|
||||
case Version::PC_NTE:
|
||||
case Version::PC_V2:
|
||||
return (choice_id == 0x0003);
|
||||
case Version::GC_NTE:
|
||||
case Version::GC_V3:
|
||||
case Version::XB_V3:
|
||||
return (choice_id == 0x0004);
|
||||
case Version::GC_EP3_NTE:
|
||||
case Version::GC_EP3:
|
||||
return (choice_id == 0x0005);
|
||||
case Version::BB_V4:
|
||||
return (choice_id == 0x0006);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
},
|
||||
},
|
||||
ChoiceSearchCategory{
|
||||
.id = 0x0204,
|
||||
.name = "Game mode",
|
||||
.choices = {
|
||||
{0x0000, "Any"},
|
||||
{0x0001, "Normal"},
|
||||
{0x0002, "Hard"},
|
||||
{0x0003, "Very Hard"},
|
||||
{0x0004, "Ultimate"},
|
||||
{0x0005, "Battle"},
|
||||
{0x0006, "Challenge"},
|
||||
},
|
||||
.client_matches = +[](shared_ptr<Client>, shared_ptr<Client> target_c, uint16_t choice_id) -> bool {
|
||||
uint16_t target_choice_id = target_c->character()->choice_search_config.get_setting(0x0204);
|
||||
return (choice_id == 0) || (target_choice_id == 0) || (choice_id == target_choice_id);
|
||||
},
|
||||
},
|
||||
});
|
||||
#include "ChoiceSearch.hh"
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "Client.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
const vector<ChoiceSearchCategory> CHOICE_SEARCH_CATEGORIES({
|
||||
ChoiceSearchCategory{
|
||||
.id = 0x0001,
|
||||
.name = "Level",
|
||||
.choices = {
|
||||
{0x0000, "Any"},
|
||||
{0x0001, "Own level +/- 5"},
|
||||
{0x0002, "Level 1-10"},
|
||||
{0x0003, "Level 11-20"},
|
||||
{0x0004, "Level 21-40"},
|
||||
{0x0005, "Level 41-60"},
|
||||
{0x0006, "Level 61-80"},
|
||||
{0x0007, "Level 81-100"},
|
||||
{0x0008, "Level 101-120"},
|
||||
{0x0009, "Level 121-160"},
|
||||
{0x000A, "Level 161-200"},
|
||||
},
|
||||
.client_matches = +[](shared_ptr<Client> searcher_c, shared_ptr<Client> target_c, uint16_t choice_id) -> bool {
|
||||
if (choice_id == 0x0000) {
|
||||
return true;
|
||||
}
|
||||
uint32_t target_level = target_c->character()->disp.stats.level + 1;
|
||||
switch (choice_id) {
|
||||
case 0x0001:
|
||||
return (labs(static_cast<int32_t>(target_level - searcher_c->character()->disp.stats.level)) <= 5);
|
||||
case 0x0002:
|
||||
return (target_level <= 10);
|
||||
case 0x0003:
|
||||
return (target_level > 10) && (target_level <= 20);
|
||||
case 0x0004:
|
||||
return (target_level > 20) && (target_level <= 40);
|
||||
case 0x0005:
|
||||
return (target_level > 40) && (target_level <= 60);
|
||||
case 0x0006:
|
||||
return (target_level > 60) && (target_level <= 80);
|
||||
case 0x0007:
|
||||
return (target_level > 80) && (target_level <= 100);
|
||||
case 0x0008:
|
||||
return (target_level > 100) && (target_level <= 120);
|
||||
case 0x0009:
|
||||
return (target_level > 120) && (target_level <= 160);
|
||||
case 0x000A:
|
||||
return (target_level > 160) && (target_level <= 200);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
},
|
||||
ChoiceSearchCategory{
|
||||
.id = 0x0002,
|
||||
.name = "Class",
|
||||
.choices = {
|
||||
{0x0000, "Any"},
|
||||
{0x0010, "Hunter"},
|
||||
{0x0001, "HUmar"},
|
||||
{0x0002, "HUnewearl"},
|
||||
{0x0003, "HUcast"},
|
||||
{0x000A, "HUcaseal"},
|
||||
{0x0011, "Ranger"},
|
||||
{0x0004, "RAmar"},
|
||||
{0x000C, "RAmarl"},
|
||||
{0x0005, "RAcast"},
|
||||
{0x0006, "RAcaseal"},
|
||||
{0x0012, "Force"},
|
||||
{0x000B, "FOmar"},
|
||||
{0x0007, "FOmarl"},
|
||||
{0x0008, "FOnewm"},
|
||||
{0x0009, "FOnewearl"},
|
||||
},
|
||||
.client_matches = +[](shared_ptr<Client>, shared_ptr<Client> target_c, uint16_t choice_id) -> bool {
|
||||
switch (choice_id) {
|
||||
case 0x0000:
|
||||
return true;
|
||||
case 0x0010:
|
||||
return target_c->character()->disp.visual.class_flags & 0x20;
|
||||
case 0x0011:
|
||||
return target_c->character()->disp.visual.class_flags & 0x40;
|
||||
case 0x0012:
|
||||
return target_c->character()->disp.visual.class_flags & 0x80;
|
||||
default:
|
||||
return ((choice_id - 1) == target_c->character()->disp.visual.char_class);
|
||||
}
|
||||
},
|
||||
},
|
||||
ChoiceSearchCategory{
|
||||
.id = 0x0003,
|
||||
.name = "Platform",
|
||||
.choices = {
|
||||
{0x0000, "Any"},
|
||||
{0x0001, "DC betas"},
|
||||
{0x0002, "DC V1"},
|
||||
{0x0003, "DC V2 / PC"},
|
||||
{0x0004, "GC / Xbox Episodes 1&2"},
|
||||
{0x0005, "GC Episode 3"},
|
||||
{0x0006, "BB"},
|
||||
},
|
||||
.client_matches = +[](shared_ptr<Client>, shared_ptr<Client> target_c, uint16_t choice_id) -> bool {
|
||||
if (choice_id == 0x0000) {
|
||||
return true;
|
||||
}
|
||||
switch (target_c->version()) {
|
||||
case Version::DC_NTE:
|
||||
case Version::DC_V1_11_2000_PROTOTYPE:
|
||||
return (choice_id == 0x0001);
|
||||
case Version::DC_V1:
|
||||
return (choice_id == 0x0002);
|
||||
case Version::DC_V2:
|
||||
case Version::PC_NTE:
|
||||
case Version::PC_V2:
|
||||
return (choice_id == 0x0003);
|
||||
case Version::GC_NTE:
|
||||
case Version::GC_V3:
|
||||
case Version::XB_V3:
|
||||
return (choice_id == 0x0004);
|
||||
case Version::GC_EP3_NTE:
|
||||
case Version::GC_EP3:
|
||||
return (choice_id == 0x0005);
|
||||
case Version::BB_V4:
|
||||
return (choice_id == 0x0006);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
},
|
||||
},
|
||||
ChoiceSearchCategory{
|
||||
.id = 0x0204,
|
||||
.name = "Game mode",
|
||||
.choices = {
|
||||
{0x0000, "Any"},
|
||||
{0x0001, "Normal"},
|
||||
{0x0002, "Hard"},
|
||||
{0x0003, "Very Hard"},
|
||||
{0x0004, "Ultimate"},
|
||||
{0x0005, "Battle"},
|
||||
{0x0006, "Challenge"},
|
||||
},
|
||||
.client_matches = +[](shared_ptr<Client>, shared_ptr<Client> target_c, uint16_t choice_id) -> bool {
|
||||
uint16_t target_choice_id = target_c->character()->choice_search_config.get_setting(0x0204);
|
||||
return (choice_id == 0) || (target_choice_id == 0) || (choice_id == target_choice_id);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
+64
-64
@@ -1,64 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Text.hh"
|
||||
|
||||
class Client;
|
||||
|
||||
template <bool IsBigEndian>
|
||||
struct ChoiceSearchConfigT {
|
||||
using U16T = typename std::conditional<IsBigEndian, be_uint16_t, le_uint16_t>::type;
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
|
||||
U32T disabled = 1; // 0 = enabled, 1 = disabled. Unused in command C3
|
||||
struct Entry {
|
||||
U16T parent_choice_id = 0;
|
||||
U16T choice_id = 0;
|
||||
} __packed_ws__(Entry, 4);
|
||||
parray<Entry, 5> entries;
|
||||
|
||||
int32_t get_setting(uint16_t parent_choice_id) const {
|
||||
for (size_t z = 0; z < this->entries.size(); z++) {
|
||||
if (this->entries[z].parent_choice_id == parent_choice_id) {
|
||||
return this->entries[z].choice_id;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
operator ChoiceSearchConfigT<!IsBigEndian>() const {
|
||||
ChoiceSearchConfigT<!IsBigEndian> ret;
|
||||
ret.disabled = this->disabled.load();
|
||||
for (size_t z = 0; z < this->entries.size(); z++) {
|
||||
auto& ret_e = ret.entries[z];
|
||||
const auto& this_e = this->entries[z];
|
||||
ret_e.parent_choice_id = this_e.parent_choice_id.load();
|
||||
ret_e.choice_id = this_e.choice_id.load();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
} __packed__;
|
||||
|
||||
using ChoiceSearchConfig = ChoiceSearchConfigT<false>;
|
||||
using ChoiceSearchConfigBE = ChoiceSearchConfigT<true>;
|
||||
check_struct_size(ChoiceSearchConfig, 0x18);
|
||||
check_struct_size(ChoiceSearchConfigBE, 0x18);
|
||||
|
||||
struct ChoiceSearchCategory {
|
||||
struct Choice {
|
||||
uint16_t id;
|
||||
const char* name;
|
||||
};
|
||||
|
||||
uint16_t id;
|
||||
const char* name;
|
||||
std::vector<Choice> choices;
|
||||
std::function<bool(std::shared_ptr<Client> searcher_c, std::shared_ptr<Client> target_c, uint16_t choice_id)> client_matches;
|
||||
};
|
||||
|
||||
extern const std::vector<ChoiceSearchCategory> CHOICE_SEARCH_CATEGORIES;
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Text.hh"
|
||||
|
||||
class Client;
|
||||
|
||||
template <bool IsBigEndian>
|
||||
struct ChoiceSearchConfigT {
|
||||
using U16T = typename std::conditional<IsBigEndian, be_uint16_t, le_uint16_t>::type;
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
|
||||
U32T disabled = 1; // 0 = enabled, 1 = disabled. Unused in command C3
|
||||
struct Entry {
|
||||
U16T parent_choice_id = 0;
|
||||
U16T choice_id = 0;
|
||||
} __packed_ws__(Entry, 4);
|
||||
parray<Entry, 5> entries;
|
||||
|
||||
int32_t get_setting(uint16_t parent_choice_id) const {
|
||||
for (size_t z = 0; z < this->entries.size(); z++) {
|
||||
if (this->entries[z].parent_choice_id == parent_choice_id) {
|
||||
return this->entries[z].choice_id;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
operator ChoiceSearchConfigT<!IsBigEndian>() const {
|
||||
ChoiceSearchConfigT<!IsBigEndian> ret;
|
||||
ret.disabled = this->disabled.load();
|
||||
for (size_t z = 0; z < this->entries.size(); z++) {
|
||||
auto& ret_e = ret.entries[z];
|
||||
const auto& this_e = this->entries[z];
|
||||
ret_e.parent_choice_id = this_e.parent_choice_id.load();
|
||||
ret_e.choice_id = this_e.choice_id.load();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
} __packed__;
|
||||
|
||||
using ChoiceSearchConfig = ChoiceSearchConfigT<false>;
|
||||
using ChoiceSearchConfigBE = ChoiceSearchConfigT<true>;
|
||||
check_struct_size(ChoiceSearchConfig, 0x18);
|
||||
check_struct_size(ChoiceSearchConfigBE, 0x18);
|
||||
|
||||
struct ChoiceSearchCategory {
|
||||
struct Choice {
|
||||
uint16_t id;
|
||||
const char* name;
|
||||
};
|
||||
|
||||
uint16_t id;
|
||||
const char* name;
|
||||
std::vector<Choice> choices;
|
||||
std::function<bool(std::shared_ptr<Client> searcher_c, std::shared_ptr<Client> target_c, uint16_t choice_id)> client_matches;
|
||||
};
|
||||
|
||||
extern const std::vector<ChoiceSearchCategory> CHOICE_SEARCH_CATEGORIES;
|
||||
|
||||
+1120
-1100
File diff suppressed because it is too large
Load Diff
+412
-405
@@ -1,405 +1,412 @@
|
||||
#pragma once
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "Account.hh"
|
||||
#include "Channel.hh"
|
||||
#include "CommandFormats.hh"
|
||||
#include "Episode3/BattleRecord.hh"
|
||||
#include "Episode3/Tournament.hh"
|
||||
#include "FileContentsCache.hh"
|
||||
#include "FunctionCompiler.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "PSOProtocol.hh"
|
||||
#include "PatchFileIndex.hh"
|
||||
#include "Quest.hh"
|
||||
#include "QuestScript.hh"
|
||||
#include "TeamIndex.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
extern const uint64_t CLIENT_CONFIG_MAGIC;
|
||||
|
||||
class Server;
|
||||
struct Lobby;
|
||||
|
||||
class Client : public std::enable_shared_from_this<Client> {
|
||||
public:
|
||||
enum class Flag : uint64_t {
|
||||
// clang-format off
|
||||
|
||||
// This mask specifies which flags are sent to the client
|
||||
// TODO: It'd be nice to use a pattern here (e.g. all server-side flags are
|
||||
// in the high bits) but that would require re-recording or manually
|
||||
// rewriting all the tests
|
||||
CLIENT_SIDE_MASK = 0xFF3CFFFF7C0FFFFB,
|
||||
|
||||
// Version-related flags
|
||||
CHECKED_FOR_DC_V1_PROTOTYPE = 0x0000000000000002,
|
||||
NO_D6_AFTER_LOBBY = 0x0000000000000100,
|
||||
NO_D6 = 0x0000000000000200,
|
||||
FORCE_ENGLISH_LANGUAGE_BB = 0x0000000000000400,
|
||||
|
||||
// Flags describing the behavior for send_function_call
|
||||
NO_SEND_FUNCTION_CALL = 0x0000000000001000,
|
||||
ENCRYPTED_SEND_FUNCTION_CALL = 0x0000000000002000,
|
||||
SEND_FUNCTION_CALL_CHECKSUM_ONLY = 0x0000000000004000,
|
||||
SEND_FUNCTION_CALL_NO_CACHE_PATCH = 0x0000000000008000,
|
||||
USE_OVERFLOW_FOR_SEND_FUNCTION_CALL = 0x0000000000010000,
|
||||
|
||||
// State flags
|
||||
LOADING = 0x0000000000100000, // Server-side only
|
||||
LOADING_QUEST = 0x0000000000200000, // Server-side only
|
||||
LOADING_RUNNING_JOINABLE_QUEST = 0x0000000000400000, // Server-side only
|
||||
LOADING_TOURNAMENT = 0x0000000000800000, // Server-side only
|
||||
IN_INFORMATION_MENU = 0x0000000001000000, // Server-side only
|
||||
AT_WELCOME_MESSAGE = 0x0000000002000000, // Server-side only
|
||||
SAVE_ENABLED = 0x0000000004000000,
|
||||
HAS_EP3_CARD_DEFS = 0x0000000008000000,
|
||||
HAS_EP3_MEDIA_UPDATES = 0x0000000010000000,
|
||||
USE_OVERRIDE_RANDOM_SEED = 0x0000000020000000,
|
||||
HAS_GUILD_CARD_NUMBER = 0x0000000040000000,
|
||||
HAS_AUTO_PATCHES = 0x0000004000000000,
|
||||
AT_BANK_COUNTER = 0x0000000080000000, // Server-side only
|
||||
SHOULD_SEND_ARTIFICIAL_ITEM_STATE = 0x0001000000000000, // Server-side only
|
||||
SHOULD_SEND_ARTIFICIAL_ENEMY_AND_SET_STATE = 0x0040000000000000, // Server-side only
|
||||
SHOULD_SEND_ARTIFICIAL_OBJECT_STATE = 0x0080000000000000, // Server-side only
|
||||
SHOULD_SEND_ARTIFICIAL_FLAG_STATE = 0x0002000000000000, // Server-side only
|
||||
SHOULD_SEND_ENABLE_SAVE = 0x0004000000000000,
|
||||
SWITCH_ASSIST_ENABLED = 0x0000000100000000,
|
||||
|
||||
// Cheat mode and option flags
|
||||
INFINITE_HP_ENABLED = 0x0000000200000000,
|
||||
INFINITE_TP_ENABLED = 0x0000000400000000,
|
||||
DEBUG_ENABLED = 0x0000000800000000,
|
||||
ITEM_DROP_NOTIFICATIONS_1 = 0x0010000000000000,
|
||||
ITEM_DROP_NOTIFICATIONS_2 = 0x0020000000000000,
|
||||
|
||||
// Proxy option flags
|
||||
PROXY_SAVE_FILES = 0x0000001000000000,
|
||||
PROXY_CHAT_COMMANDS_ENABLED = 0x0000002000000000,
|
||||
PROXY_PLAYER_NOTIFICATIONS_ENABLED = 0x0000008000000000,
|
||||
PROXY_SUPPRESS_CLIENT_PINGS = 0x0000010000000000,
|
||||
PROXY_SUPPRESS_REMOTE_LOGIN = 0x0000020000000000,
|
||||
PROXY_ZERO_REMOTE_GUILD_CARD = 0x0000040000000000,
|
||||
PROXY_EP3_INFINITE_MESETA_ENABLED = 0x0000080000000000,
|
||||
PROXY_EP3_INFINITE_TIME_ENABLED = 0x0000100000000000,
|
||||
PROXY_RED_NAME_ENABLED = 0x0000200000000000,
|
||||
PROXY_BLANK_NAME_ENABLED = 0x0000400000000000,
|
||||
PROXY_BLOCK_FUNCTION_CALLS = 0x0000800000000000,
|
||||
PROXY_EP3_UNMASK_WHISPERS = 0x0008000000000000,
|
||||
// clang-format on
|
||||
};
|
||||
enum class ItemDropNotificationMode {
|
||||
NOTHING = 0,
|
||||
RARES_ONLY = 1,
|
||||
ALL_ITEMS = 2,
|
||||
ALL_ITEMS_INCLUDING_MESETA = 3,
|
||||
};
|
||||
|
||||
static constexpr uint64_t DEFAULT_FLAGS = static_cast<uint64_t>(Flag::PROXY_CHAT_COMMANDS_ENABLED);
|
||||
|
||||
struct Config {
|
||||
uint64_t enabled_flags = DEFAULT_FLAGS; // Client::Flag enum
|
||||
uint32_t specific_version = 0;
|
||||
int32_t override_random_seed = 0;
|
||||
uint8_t override_section_id = 0xFF; // FF = no override
|
||||
uint8_t override_lobby_event = 0xFF; // FF = no override
|
||||
uint8_t override_lobby_number = 0x80; // 80 = no override
|
||||
uint32_t proxy_destination_address = 0;
|
||||
uint16_t proxy_destination_port = 0;
|
||||
|
||||
Config() = default;
|
||||
|
||||
bool operator==(const Config& other) const = default;
|
||||
bool operator!=(const Config& other) const = default;
|
||||
|
||||
bool should_update_vs(const Config& other) const;
|
||||
|
||||
[[nodiscard]] static inline bool check_flag(uint64_t enabled_flags, Flag flag) {
|
||||
return !!(enabled_flags & static_cast<uint64_t>(flag));
|
||||
}
|
||||
|
||||
[[nodiscard]] inline bool check_flag(Flag flag) const {
|
||||
return this->check_flag(this->enabled_flags, flag);
|
||||
}
|
||||
inline void set_flag(Flag flag) {
|
||||
this->enabled_flags |= static_cast<uint64_t>(flag);
|
||||
}
|
||||
inline void clear_flag(Flag flag) {
|
||||
this->enabled_flags &= (~static_cast<uint64_t>(flag));
|
||||
}
|
||||
inline void toggle_flag(Flag flag) {
|
||||
this->enabled_flags ^= static_cast<uint64_t>(flag);
|
||||
}
|
||||
|
||||
void set_flags_for_version(Version version, int64_t sub_version);
|
||||
|
||||
ItemDropNotificationMode get_drop_notification_mode() const;
|
||||
void set_drop_notification_mode(ItemDropNotificationMode new_mode);
|
||||
|
||||
template <size_t Bytes>
|
||||
void parse_from(const parray<uint8_t, Bytes>& data) {
|
||||
StringReader r(data.data(), data.size());
|
||||
if (r.get_u32l() != CLIENT_CONFIG_MAGIC) {
|
||||
throw std::invalid_argument("config signature is incorrect");
|
||||
}
|
||||
this->specific_version = r.get_u32l();
|
||||
this->enabled_flags = r.get_u64l();
|
||||
this->override_random_seed = r.get_u32l();
|
||||
this->proxy_destination_address = r.get_u32b();
|
||||
this->proxy_destination_port = r.get_u16l();
|
||||
this->override_section_id = r.get_u8();
|
||||
this->override_lobby_event = r.get_u8();
|
||||
this->override_lobby_number = r.get_u8();
|
||||
}
|
||||
|
||||
template <size_t Bytes>
|
||||
void serialize_into(parray<uint8_t, Bytes>& data) const {
|
||||
StringWriter w;
|
||||
w.put_u32l(CLIENT_CONFIG_MAGIC);
|
||||
w.put_u32l(this->specific_version);
|
||||
w.put_u64l(this->enabled_flags & static_cast<uint64_t>(Flag::CLIENT_SIDE_MASK));
|
||||
w.put_u32l(this->override_random_seed);
|
||||
w.put_u32b(this->proxy_destination_address);
|
||||
w.put_u16l(this->proxy_destination_port);
|
||||
w.put_u8(this->override_section_id);
|
||||
w.put_u8(this->override_lobby_event);
|
||||
w.put_u8(this->override_lobby_number);
|
||||
|
||||
const auto& s = w.str();
|
||||
for (size_t z = 0; z < s.size(); z++) {
|
||||
data[z] = s[z];
|
||||
}
|
||||
data.clear_after(s.size(), 0xFF);
|
||||
}
|
||||
};
|
||||
|
||||
std::weak_ptr<Server> server;
|
||||
uint64_t id;
|
||||
PrefixedLogger log;
|
||||
|
||||
std::shared_ptr<Login> login;
|
||||
|
||||
// Network
|
||||
Channel channel;
|
||||
struct sockaddr_storage next_connection_addr;
|
||||
ServerBehavior server_behavior;
|
||||
bool should_disconnect;
|
||||
bool should_send_to_lobby_server;
|
||||
bool should_send_to_proxy_server;
|
||||
std::unordered_map<std::string, std::function<void()>> disconnect_hooks;
|
||||
std::shared_ptr<XBNetworkLocation> xb_netloc;
|
||||
parray<le_uint32_t, 3> xb_9E_unknown_a1a;
|
||||
uint8_t bb_connection_phase;
|
||||
uint64_t ping_start_time;
|
||||
|
||||
// Lobby/positioning
|
||||
Config config;
|
||||
Config synced_config;
|
||||
std::unique_ptr<parray<le_uint32_t, 0x20>> override_variations;
|
||||
int32_t sub_version;
|
||||
float x;
|
||||
float z;
|
||||
uint32_t floor;
|
||||
std::weak_ptr<Lobby> lobby;
|
||||
uint8_t lobby_client_id;
|
||||
uint8_t lobby_arrow_color;
|
||||
int64_t preferred_lobby_id; // <0 = no preference
|
||||
|
||||
std::unique_ptr<struct event, void (*)(struct event*)> save_game_data_event;
|
||||
std::unique_ptr<struct event, void (*)(struct event*)> send_ping_event;
|
||||
std::unique_ptr<struct event, void (*)(struct event*)> idle_timeout_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 Episode3::BattleRecord> ep3_prev_battle_record;
|
||||
std::shared_ptr<const Menu> last_menu_sent;
|
||||
uint32_t last_game_info_requested;
|
||||
struct JoinCommand {
|
||||
uint16_t command;
|
||||
uint32_t flag;
|
||||
std::string data;
|
||||
};
|
||||
std::unique_ptr<std::deque<JoinCommand>> game_join_command_queue;
|
||||
|
||||
// Character / game data
|
||||
struct PendingItemTrade {
|
||||
uint8_t other_client_id;
|
||||
bool confirmed; // true if client has sent a D2 command
|
||||
std::vector<ItemData> items;
|
||||
};
|
||||
struct PendingCardTrade {
|
||||
uint8_t other_client_id;
|
||||
bool confirmed; // true if client has sent an EE D2 command
|
||||
std::vector<std::pair<uint32_t, uint32_t>> card_to_count;
|
||||
};
|
||||
bool should_update_play_time;
|
||||
std::unordered_set<uint32_t> blocked_senders;
|
||||
std::unique_ptr<PlayerDispDataDCPCV3> v1_v2_last_reported_disp;
|
||||
// These are null unless the client is within the trade sequence (D0-D4 or EE commands)
|
||||
std::unique_ptr<PendingItemTrade> pending_item_trade;
|
||||
std::unique_ptr<PendingCardTrade> pending_card_trade;
|
||||
std::shared_ptr<Episode3::PlayerConfig> ep3_config; // Null for non-Ep3
|
||||
int8_t bb_character_index;
|
||||
ItemData bb_identify_result;
|
||||
std::array<std::vector<ItemData>, 3> bb_shop_contents;
|
||||
|
||||
// Miscellaneous (used by chat commands)
|
||||
uint32_t next_exp_value; // next EXP value to give
|
||||
RecentSwitchFlags recent_switch_flags; // used for switch assist
|
||||
bool can_chat;
|
||||
struct PendingCharacterExport {
|
||||
std::shared_ptr<const Account> dest_account;
|
||||
ssize_t character_index = -1;
|
||||
std::shared_ptr<const BBLicense> dest_bb_license; // Only used for $bbchar; null for $savechar
|
||||
};
|
||||
std::unique_ptr<PendingCharacterExport> pending_character_export;
|
||||
std::deque<std::function<void(uint32_t, uint32_t)>> function_call_response_queue;
|
||||
|
||||
// File loading state
|
||||
uint32_t dol_base_addr;
|
||||
std::shared_ptr<DOLFileIndex::File> loading_dol_file;
|
||||
std::unordered_map<std::string, std::shared_ptr<const std::string>> sending_files;
|
||||
|
||||
Client(
|
||||
std::shared_ptr<Server> server,
|
||||
struct bufferevent* bev,
|
||||
uint64_t virtual_network_id,
|
||||
Version version,
|
||||
ServerBehavior server_behavior);
|
||||
~Client();
|
||||
|
||||
void update_channel_name();
|
||||
|
||||
void reschedule_save_game_data_event();
|
||||
void reschedule_ping_and_timeout_events();
|
||||
|
||||
inline Version version() const {
|
||||
return this->channel.version;
|
||||
}
|
||||
inline uint8_t language() const {
|
||||
return this->channel.language;
|
||||
}
|
||||
|
||||
void convert_account_to_temporary_if_nte();
|
||||
|
||||
void sync_config();
|
||||
|
||||
std::shared_ptr<ServerState> require_server_state() const;
|
||||
std::shared_ptr<Lobby> require_lobby() const;
|
||||
|
||||
std::shared_ptr<const TeamIndex::Team> team() const;
|
||||
|
||||
bool evaluate_quest_availability_expression(
|
||||
std::shared_ptr<const IntegralExpression> expr,
|
||||
std::shared_ptr<const Lobby> game,
|
||||
uint8_t event,
|
||||
uint8_t difficulty,
|
||||
size_t num_players,
|
||||
bool v1_present) const;
|
||||
bool can_see_quest(
|
||||
std::shared_ptr<const Quest> q,
|
||||
std::shared_ptr<const Lobby> game,
|
||||
uint8_t event,
|
||||
uint8_t difficulty,
|
||||
size_t num_players,
|
||||
bool v1_present) const;
|
||||
bool can_play_quest(
|
||||
std::shared_ptr<const Quest> q,
|
||||
std::shared_ptr<const Lobby> game,
|
||||
uint8_t event,
|
||||
uint8_t difficulty,
|
||||
size_t num_players,
|
||||
bool v1_present) const;
|
||||
|
||||
bool can_use_chat_commands() const;
|
||||
|
||||
static void dispatch_save_game_data(evutil_socket_t, short, void* ctx);
|
||||
void save_game_data();
|
||||
static void dispatch_send_ping(evutil_socket_t, short, void* ctx);
|
||||
void send_ping();
|
||||
static void dispatch_idle_timeout(evutil_socket_t, short, void* ctx);
|
||||
void idle_timeout();
|
||||
|
||||
void suspend_timeouts();
|
||||
|
||||
const std::string& get_bb_username() const;
|
||||
void set_bb_username(const std::string& bb_username);
|
||||
|
||||
void create_battle_overlay(std::shared_ptr<const BattleRules> rules, std::shared_ptr<const LevelTable> level_table);
|
||||
void create_challenge_overlay(Version version, size_t template_index, std::shared_ptr<const LevelTable> level_table);
|
||||
inline void delete_overlay() {
|
||||
this->overlay_character_data.reset();
|
||||
}
|
||||
inline bool has_overlay() const {
|
||||
return this->overlay_character_data.get() != nullptr;
|
||||
}
|
||||
|
||||
void import_blocked_senders(const parray<le_uint32_t, 30>& blocked_senders);
|
||||
|
||||
std::shared_ptr<PSOBBBaseSystemFile> system_file(bool allow_load = true);
|
||||
std::shared_ptr<PSOBBCharacterFile> character(bool allow_load = true, bool allow_overlay = true);
|
||||
std::shared_ptr<PSOBBGuildCardFile> guild_card_file(bool allow_load = true);
|
||||
std::shared_ptr<const PSOBBBaseSystemFile> system_file(bool allow_load = true) const;
|
||||
std::shared_ptr<const PSOBBCharacterFile> character(bool allow_load = true, bool allow_overlay = true) const;
|
||||
std::shared_ptr<const PSOBBGuildCardFile> guild_card_file(bool allow_load = true) const;
|
||||
|
||||
void create_character_file(
|
||||
uint32_t guild_card_number,
|
||||
uint8_t language,
|
||||
const PlayerDispDataBBPreview& preview,
|
||||
std::shared_ptr<const LevelTable> level_table);
|
||||
|
||||
std::string system_filename() const;
|
||||
static std::string character_filename(const std::string& bb_username, int8_t index);
|
||||
static std::string backup_character_filename(uint32_t account_id, size_t index);
|
||||
std::string character_filename(int8_t index = -1) const;
|
||||
std::string guild_card_filename() const;
|
||||
std::string shared_bank_filename() const;
|
||||
|
||||
std::string legacy_player_filename() const;
|
||||
std::string legacy_account_filename() const;
|
||||
|
||||
void save_all();
|
||||
void save_system_file() const;
|
||||
static void save_character_file(
|
||||
const std::string& filename,
|
||||
std::shared_ptr<const PSOBBBaseSystemFile> sys,
|
||||
std::shared_ptr<const PSOBBCharacterFile> character);
|
||||
// Note: This function is not const because it updates the player's play time.
|
||||
void save_character_file();
|
||||
void save_guild_card_file() const;
|
||||
|
||||
void load_backup_character(uint32_t account_id, size_t index);
|
||||
void save_and_unload_character();
|
||||
|
||||
PlayerBank& current_bank();
|
||||
std::shared_ptr<PSOBBCharacterFile> current_bank_character();
|
||||
bool use_shared_bank(); // Returns true if the bank exists; false if it was created
|
||||
void use_character_bank(int8_t bb_character_index);
|
||||
void use_default_bank();
|
||||
|
||||
void print_inventory(FILE* stream) const;
|
||||
void print_bank(FILE* stream) const;
|
||||
|
||||
private:
|
||||
// The overlay character data is used in battle and challenge modes, when
|
||||
// character data is temporarily replaced in-game. In other play modes and in
|
||||
// lobbies, overlay_character_data is null.
|
||||
std::shared_ptr<PSOBBBaseSystemFile> system_data;
|
||||
std::shared_ptr<PSOBBCharacterFile> overlay_character_data;
|
||||
std::shared_ptr<PSOBBCharacterFile> character_data;
|
||||
std::shared_ptr<PSOBBGuildCardFile> guild_card_data;
|
||||
std::shared_ptr<PlayerBank> external_bank;
|
||||
std::shared_ptr<PSOBBCharacterFile> external_bank_character;
|
||||
int8_t external_bank_character_index;
|
||||
uint64_t last_play_time_update;
|
||||
|
||||
void save_and_clear_external_bank();
|
||||
|
||||
void load_all_files();
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "Account.hh"
|
||||
#include "Channel.hh"
|
||||
#include "CommandFormats.hh"
|
||||
#include "Episode3/BattleRecord.hh"
|
||||
#include "Episode3/Tournament.hh"
|
||||
#include "FileContentsCache.hh"
|
||||
#include "FunctionCompiler.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "PSOProtocol.hh"
|
||||
#include "PatchFileIndex.hh"
|
||||
#include "Quest.hh"
|
||||
#include "QuestScript.hh"
|
||||
#include "TeamIndex.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
extern const uint64_t CLIENT_CONFIG_MAGIC;
|
||||
|
||||
class Server;
|
||||
struct Lobby;
|
||||
class Parsed6x70Data;
|
||||
|
||||
class Client : public std::enable_shared_from_this<Client> {
|
||||
public:
|
||||
enum class Flag : uint64_t {
|
||||
// clang-format off
|
||||
|
||||
// This mask specifies which flags are sent to the client
|
||||
// TODO: It'd be nice to use a pattern here (e.g. all server-side flags are
|
||||
// in the high bits) but that would require re-recording or manually
|
||||
// rewriting all the tests
|
||||
CLIENT_SIDE_MASK = 0xFF3CFFFF7C0FFFFB,
|
||||
|
||||
// Version-related flags
|
||||
CHECKED_FOR_DC_V1_PROTOTYPE = 0x0000000000000002,
|
||||
NO_D6_AFTER_LOBBY = 0x0000000000000100,
|
||||
NO_D6 = 0x0000000000000200,
|
||||
FORCE_ENGLISH_LANGUAGE_BB = 0x0000000000000400,
|
||||
|
||||
// Flags describing the behavior for send_function_call
|
||||
NO_SEND_FUNCTION_CALL = 0x0000000000001000,
|
||||
ENCRYPTED_SEND_FUNCTION_CALL = 0x0000000000002000,
|
||||
SEND_FUNCTION_CALL_CHECKSUM_ONLY = 0x0000000000004000,
|
||||
SEND_FUNCTION_CALL_NO_CACHE_PATCH = 0x0000000000008000,
|
||||
USE_OVERFLOW_FOR_SEND_FUNCTION_CALL = 0x0000000000010000,
|
||||
|
||||
// State flags
|
||||
LOADING = 0x0000000000100000, // Server-side only
|
||||
LOADING_QUEST = 0x0000000000200000, // Server-side only
|
||||
LOADING_RUNNING_JOINABLE_QUEST = 0x0000000000400000, // Server-side only
|
||||
LOADING_TOURNAMENT = 0x0000000000800000, // Server-side only
|
||||
IN_INFORMATION_MENU = 0x0000000001000000, // Server-side only
|
||||
AT_WELCOME_MESSAGE = 0x0000000002000000, // Server-side only
|
||||
SAVE_ENABLED = 0x0000000004000000,
|
||||
HAS_EP3_CARD_DEFS = 0x0000000008000000,
|
||||
HAS_EP3_MEDIA_UPDATES = 0x0000000010000000,
|
||||
USE_OVERRIDE_RANDOM_SEED = 0x0000000020000000,
|
||||
HAS_GUILD_CARD_NUMBER = 0x0000000040000000,
|
||||
HAS_AUTO_PATCHES = 0x0000004000000000,
|
||||
AT_BANK_COUNTER = 0x0000000080000000, // Server-side only
|
||||
SHOULD_SEND_ARTIFICIAL_ITEM_STATE = 0x0001000000000000, // Server-side only
|
||||
SHOULD_SEND_ARTIFICIAL_ENEMY_AND_SET_STATE = 0x0040000000000000, // Server-side only
|
||||
SHOULD_SEND_ARTIFICIAL_OBJECT_STATE = 0x0080000000000000, // Server-side only
|
||||
SHOULD_SEND_ARTIFICIAL_FLAG_STATE = 0x0002000000000000, // Server-side only
|
||||
SHOULD_SEND_ARTIFICIAL_PLAYER_STATES = 0x0200000000000000, // Server-side only
|
||||
SHOULD_SEND_ENABLE_SAVE = 0x0004000000000000,
|
||||
SWITCH_ASSIST_ENABLED = 0x0000000100000000,
|
||||
IS_CLIENT_CUSTOMIZATION = 0x0100000000000000,
|
||||
|
||||
// Cheat mode and option flags
|
||||
INFINITE_HP_ENABLED = 0x0000000200000000,
|
||||
INFINITE_TP_ENABLED = 0x0000000400000000,
|
||||
DEBUG_ENABLED = 0x0000000800000000,
|
||||
ITEM_DROP_NOTIFICATIONS_1 = 0x0010000000000000,
|
||||
ITEM_DROP_NOTIFICATIONS_2 = 0x0020000000000000,
|
||||
|
||||
// Proxy option flags
|
||||
PROXY_SAVE_FILES = 0x0000001000000000,
|
||||
PROXY_CHAT_COMMANDS_ENABLED = 0x0000002000000000,
|
||||
PROXY_PLAYER_NOTIFICATIONS_ENABLED = 0x0000008000000000,
|
||||
PROXY_SUPPRESS_CLIENT_PINGS = 0x0000010000000000,
|
||||
PROXY_SUPPRESS_REMOTE_LOGIN = 0x0000020000000000,
|
||||
PROXY_ZERO_REMOTE_GUILD_CARD = 0x0000040000000000,
|
||||
PROXY_EP3_INFINITE_MESETA_ENABLED = 0x0000080000000000,
|
||||
PROXY_EP3_INFINITE_TIME_ENABLED = 0x0000100000000000,
|
||||
PROXY_RED_NAME_ENABLED = 0x0000200000000000,
|
||||
PROXY_BLANK_NAME_ENABLED = 0x0000400000000000,
|
||||
PROXY_BLOCK_FUNCTION_CALLS = 0x0000800000000000,
|
||||
PROXY_EP3_UNMASK_WHISPERS = 0x0008000000000000,
|
||||
// clang-format on
|
||||
};
|
||||
enum class ItemDropNotificationMode {
|
||||
NOTHING = 0,
|
||||
RARES_ONLY = 1,
|
||||
ALL_ITEMS = 2,
|
||||
ALL_ITEMS_INCLUDING_MESETA = 3,
|
||||
};
|
||||
|
||||
static constexpr uint64_t DEFAULT_FLAGS = static_cast<uint64_t>(Flag::PROXY_CHAT_COMMANDS_ENABLED);
|
||||
|
||||
struct Config {
|
||||
uint64_t enabled_flags = DEFAULT_FLAGS; // Client::Flag enum
|
||||
uint32_t specific_version = 0;
|
||||
int32_t override_random_seed = 0;
|
||||
uint8_t override_section_id = 0xFF; // FF = no override
|
||||
uint8_t override_lobby_event = 0xFF; // FF = no override
|
||||
uint8_t override_lobby_number = 0x80; // 80 = no override
|
||||
uint32_t proxy_destination_address = 0;
|
||||
uint16_t proxy_destination_port = 0;
|
||||
|
||||
Config() = default;
|
||||
|
||||
bool operator==(const Config& other) const = default;
|
||||
bool operator!=(const Config& other) const = default;
|
||||
|
||||
bool should_update_vs(const Config& other) const;
|
||||
|
||||
[[nodiscard]] static inline bool check_flag(uint64_t enabled_flags, Flag flag) {
|
||||
return !!(enabled_flags & static_cast<uint64_t>(flag));
|
||||
}
|
||||
|
||||
[[nodiscard]] inline bool check_flag(Flag flag) const {
|
||||
return this->check_flag(this->enabled_flags, flag);
|
||||
}
|
||||
inline void set_flag(Flag flag) {
|
||||
this->enabled_flags |= static_cast<uint64_t>(flag);
|
||||
}
|
||||
inline void clear_flag(Flag flag) {
|
||||
this->enabled_flags &= (~static_cast<uint64_t>(flag));
|
||||
}
|
||||
inline void toggle_flag(Flag flag) {
|
||||
this->enabled_flags ^= static_cast<uint64_t>(flag);
|
||||
}
|
||||
|
||||
void set_flags_for_version(Version version, int64_t sub_version);
|
||||
|
||||
ItemDropNotificationMode get_drop_notification_mode() const;
|
||||
void set_drop_notification_mode(ItemDropNotificationMode new_mode);
|
||||
|
||||
template <size_t Bytes>
|
||||
void parse_from(const parray<uint8_t, Bytes>& data) {
|
||||
StringReader r(data.data(), data.size());
|
||||
if (r.get_u32l() != CLIENT_CONFIG_MAGIC) {
|
||||
throw std::invalid_argument("config signature is incorrect");
|
||||
}
|
||||
this->specific_version = r.get_u32l();
|
||||
this->enabled_flags = r.get_u64l();
|
||||
this->override_random_seed = r.get_u32l();
|
||||
this->proxy_destination_address = r.get_u32b();
|
||||
this->proxy_destination_port = r.get_u16l();
|
||||
this->override_section_id = r.get_u8();
|
||||
this->override_lobby_event = r.get_u8();
|
||||
this->override_lobby_number = r.get_u8();
|
||||
}
|
||||
|
||||
template <size_t Bytes>
|
||||
void serialize_into(parray<uint8_t, Bytes>& data) const {
|
||||
StringWriter w;
|
||||
w.put_u32l(CLIENT_CONFIG_MAGIC);
|
||||
w.put_u32l(this->specific_version);
|
||||
w.put_u64l(this->enabled_flags & static_cast<uint64_t>(Flag::CLIENT_SIDE_MASK));
|
||||
w.put_u32l(this->override_random_seed);
|
||||
w.put_u32b(this->proxy_destination_address);
|
||||
w.put_u16l(this->proxy_destination_port);
|
||||
w.put_u8(this->override_section_id);
|
||||
w.put_u8(this->override_lobby_event);
|
||||
w.put_u8(this->override_lobby_number);
|
||||
|
||||
const auto& s = w.str();
|
||||
for (size_t z = 0; z < s.size(); z++) {
|
||||
data[z] = s[z];
|
||||
}
|
||||
data.clear_after(s.size(), 0xFF);
|
||||
}
|
||||
};
|
||||
|
||||
std::weak_ptr<Server> server;
|
||||
uint64_t id;
|
||||
PrefixedLogger log;
|
||||
|
||||
std::shared_ptr<Login> login;
|
||||
|
||||
// Network
|
||||
Channel channel;
|
||||
struct sockaddr_storage next_connection_addr;
|
||||
ServerBehavior server_behavior;
|
||||
bool should_disconnect;
|
||||
bool should_send_to_lobby_server;
|
||||
bool should_send_to_proxy_server;
|
||||
std::unordered_map<std::string, std::function<void()>> disconnect_hooks;
|
||||
std::shared_ptr<XBNetworkLocation> xb_netloc;
|
||||
parray<le_uint32_t, 3> xb_9E_unknown_a1a;
|
||||
uint8_t bb_connection_phase;
|
||||
uint64_t ping_start_time;
|
||||
|
||||
// Lobby/positioning
|
||||
Config config;
|
||||
Config synced_config;
|
||||
std::unique_ptr<parray<le_uint32_t, 0x20>> override_variations;
|
||||
int32_t sub_version;
|
||||
float x;
|
||||
float z;
|
||||
uint32_t floor;
|
||||
std::weak_ptr<Lobby> lobby;
|
||||
uint8_t lobby_client_id;
|
||||
uint8_t lobby_arrow_color;
|
||||
int64_t preferred_lobby_id; // <0 = no preference
|
||||
|
||||
std::unique_ptr<struct event, void (*)(struct event*)> save_game_data_event;
|
||||
std::unique_ptr<struct event, void (*)(struct event*)> send_ping_event;
|
||||
std::unique_ptr<struct event, void (*)(struct event*)> idle_timeout_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 Episode3::BattleRecord> ep3_prev_battle_record;
|
||||
std::shared_ptr<const Menu> last_menu_sent;
|
||||
uint32_t last_game_info_requested;
|
||||
struct JoinCommand {
|
||||
uint16_t command;
|
||||
uint32_t flag;
|
||||
std::string data;
|
||||
};
|
||||
std::unique_ptr<std::deque<JoinCommand>> game_join_command_queue;
|
||||
|
||||
// Character / game data
|
||||
struct PendingItemTrade {
|
||||
uint8_t other_client_id;
|
||||
bool confirmed; // true if client has sent a D2 command
|
||||
std::vector<ItemData> items;
|
||||
};
|
||||
struct PendingCardTrade {
|
||||
uint8_t other_client_id;
|
||||
bool confirmed; // true if client has sent an EE D2 command
|
||||
std::vector<std::pair<uint32_t, uint32_t>> card_to_count;
|
||||
};
|
||||
bool should_update_play_time;
|
||||
std::unordered_set<uint32_t> blocked_senders;
|
||||
std::unique_ptr<PlayerDispDataDCPCV3> v1_v2_last_reported_disp;
|
||||
std::shared_ptr<Parsed6x70Data> last_reported_6x70;
|
||||
// These are null unless the client is within the trade sequence (D0-D4 or EE commands)
|
||||
std::unique_ptr<PendingItemTrade> pending_item_trade;
|
||||
std::unique_ptr<PendingCardTrade> pending_card_trade;
|
||||
uint32_t telepipe_lobby_id;
|
||||
G_SetTelepipeState_6x68 telepipe_state;
|
||||
std::shared_ptr<Episode3::PlayerConfig> ep3_config; // Null for non-Ep3
|
||||
int8_t bb_character_index;
|
||||
ItemData bb_identify_result;
|
||||
std::array<std::vector<ItemData>, 3> bb_shop_contents;
|
||||
|
||||
// Miscellaneous (used by chat commands)
|
||||
uint32_t next_exp_value; // next EXP value to give
|
||||
RecentSwitchFlags recent_switch_flags; // used for switch assist
|
||||
bool can_chat;
|
||||
struct PendingCharacterExport {
|
||||
std::shared_ptr<const Account> dest_account;
|
||||
ssize_t character_index = -1;
|
||||
std::shared_ptr<const BBLicense> dest_bb_license; // Only used for $bbchar; null for $savechar
|
||||
};
|
||||
std::unique_ptr<PendingCharacterExport> pending_character_export;
|
||||
std::deque<std::function<void(uint32_t, uint32_t)>> function_call_response_queue;
|
||||
|
||||
// File loading state
|
||||
uint32_t dol_base_addr;
|
||||
std::shared_ptr<DOLFileIndex::File> loading_dol_file;
|
||||
std::unordered_map<std::string, std::shared_ptr<const std::string>> sending_files;
|
||||
|
||||
Client(
|
||||
std::shared_ptr<Server> server,
|
||||
struct bufferevent* bev,
|
||||
uint64_t virtual_network_id,
|
||||
Version version,
|
||||
ServerBehavior server_behavior);
|
||||
~Client();
|
||||
|
||||
void update_channel_name();
|
||||
|
||||
void reschedule_save_game_data_event();
|
||||
void reschedule_ping_and_timeout_events();
|
||||
|
||||
inline Version version() const {
|
||||
return this->channel.version;
|
||||
}
|
||||
inline uint8_t language() const {
|
||||
return this->channel.language;
|
||||
}
|
||||
|
||||
void convert_account_to_temporary_if_nte();
|
||||
|
||||
void sync_config();
|
||||
|
||||
std::shared_ptr<ServerState> require_server_state() const;
|
||||
std::shared_ptr<Lobby> require_lobby() const;
|
||||
|
||||
std::shared_ptr<const TeamIndex::Team> team() const;
|
||||
|
||||
bool evaluate_quest_availability_expression(
|
||||
std::shared_ptr<const IntegralExpression> expr,
|
||||
std::shared_ptr<const Lobby> game,
|
||||
uint8_t event,
|
||||
uint8_t difficulty,
|
||||
size_t num_players,
|
||||
bool v1_present) const;
|
||||
bool can_see_quest(
|
||||
std::shared_ptr<const Quest> q,
|
||||
std::shared_ptr<const Lobby> game,
|
||||
uint8_t event,
|
||||
uint8_t difficulty,
|
||||
size_t num_players,
|
||||
bool v1_present) const;
|
||||
bool can_play_quest(
|
||||
std::shared_ptr<const Quest> q,
|
||||
std::shared_ptr<const Lobby> game,
|
||||
uint8_t event,
|
||||
uint8_t difficulty,
|
||||
size_t num_players,
|
||||
bool v1_present) const;
|
||||
|
||||
bool can_use_chat_commands() const;
|
||||
|
||||
static void dispatch_save_game_data(evutil_socket_t, short, void* ctx);
|
||||
void save_game_data();
|
||||
static void dispatch_send_ping(evutil_socket_t, short, void* ctx);
|
||||
void send_ping();
|
||||
static void dispatch_idle_timeout(evutil_socket_t, short, void* ctx);
|
||||
void idle_timeout();
|
||||
|
||||
void suspend_timeouts();
|
||||
|
||||
const std::string& get_bb_username() const;
|
||||
void set_bb_username(const std::string& bb_username);
|
||||
|
||||
void create_battle_overlay(std::shared_ptr<const BattleRules> rules, std::shared_ptr<const LevelTable> level_table);
|
||||
void create_challenge_overlay(Version version, size_t template_index, std::shared_ptr<const LevelTable> level_table);
|
||||
inline void delete_overlay() {
|
||||
this->overlay_character_data.reset();
|
||||
}
|
||||
inline bool has_overlay() const {
|
||||
return this->overlay_character_data.get() != nullptr;
|
||||
}
|
||||
|
||||
void import_blocked_senders(const parray<le_uint32_t, 30>& blocked_senders);
|
||||
|
||||
std::shared_ptr<PSOBBBaseSystemFile> system_file(bool allow_load = true);
|
||||
std::shared_ptr<PSOBBCharacterFile> character(bool allow_load = true, bool allow_overlay = true);
|
||||
std::shared_ptr<PSOBBGuildCardFile> guild_card_file(bool allow_load = true);
|
||||
std::shared_ptr<const PSOBBBaseSystemFile> system_file(bool allow_load = true) const;
|
||||
std::shared_ptr<const PSOBBCharacterFile> character(bool allow_load = true, bool allow_overlay = true) const;
|
||||
std::shared_ptr<const PSOBBGuildCardFile> guild_card_file(bool allow_load = true) const;
|
||||
|
||||
void create_character_file(
|
||||
uint32_t guild_card_number,
|
||||
uint8_t language,
|
||||
const PlayerDispDataBBPreview& preview,
|
||||
std::shared_ptr<const LevelTable> level_table);
|
||||
|
||||
std::string system_filename() const;
|
||||
static std::string character_filename(const std::string& bb_username, int8_t index);
|
||||
static std::string backup_character_filename(uint32_t account_id, size_t index);
|
||||
std::string character_filename(int8_t index = -1) const;
|
||||
std::string guild_card_filename() const;
|
||||
std::string shared_bank_filename() const;
|
||||
|
||||
std::string legacy_player_filename() const;
|
||||
std::string legacy_account_filename() const;
|
||||
|
||||
void save_all();
|
||||
void save_system_file() const;
|
||||
static void save_character_file(
|
||||
const std::string& filename,
|
||||
std::shared_ptr<const PSOBBBaseSystemFile> sys,
|
||||
std::shared_ptr<const PSOBBCharacterFile> character);
|
||||
// Note: This function is not const because it updates the player's play time.
|
||||
void save_character_file();
|
||||
void save_guild_card_file() const;
|
||||
|
||||
void load_backup_character(uint32_t account_id, size_t index);
|
||||
void save_and_unload_character();
|
||||
|
||||
PlayerBank200& current_bank();
|
||||
std::shared_ptr<PSOBBCharacterFile> current_bank_character();
|
||||
bool use_shared_bank(); // Returns true if the bank exists; false if it was created
|
||||
void use_character_bank(int8_t bb_character_index);
|
||||
void use_default_bank();
|
||||
|
||||
void print_inventory(FILE* stream) const;
|
||||
void print_bank(FILE* stream) const;
|
||||
|
||||
private:
|
||||
// The overlay character data is used in battle and challenge modes, when
|
||||
// character data is temporarily replaced in-game. In other play modes and in
|
||||
// lobbies, overlay_character_data is null.
|
||||
std::shared_ptr<PSOBBBaseSystemFile> system_data;
|
||||
std::shared_ptr<PSOBBCharacterFile> overlay_character_data;
|
||||
std::shared_ptr<PSOBBCharacterFile> character_data;
|
||||
std::shared_ptr<PSOBBGuildCardFile> guild_card_data;
|
||||
std::shared_ptr<PlayerBank200> external_bank;
|
||||
std::shared_ptr<PSOBBCharacterFile> external_bank_character;
|
||||
int8_t external_bank_character_index;
|
||||
uint64_t last_play_time_update;
|
||||
|
||||
void save_and_clear_external_bank();
|
||||
|
||||
void load_all_files();
|
||||
void update_character_data_after_load(std::shared_ptr<PSOBBCharacterFile> character_data);
|
||||
};
|
||||
|
||||
+7233
-7195
File diff suppressed because it is too large
Load Diff
+345
-40
@@ -16,6 +16,16 @@ JSON to_json(const parray<IntT, Count>& v) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename IntT, size_t Count>
|
||||
void from_json_into(const JSON& json, parray<IntT, Count>& ret) {
|
||||
if (json.size() != Count) {
|
||||
throw runtime_error("incorrect array length");
|
||||
}
|
||||
for (size_t z = 0; z < Count; z++) {
|
||||
ret[z] = json.at(z).as_int();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename IntT, size_t Count>
|
||||
JSON to_json(const parray<CommonItemSet::Table::Range<IntT>, Count>& v) {
|
||||
auto ret = JSON::list();
|
||||
@@ -25,6 +35,16 @@ JSON to_json(const parray<CommonItemSet::Table::Range<IntT>, Count>& v) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename IntT, size_t Count>
|
||||
void from_json_into(const JSON& json, parray<CommonItemSet::Table::Range<IntT>, Count>& ret) {
|
||||
if (json.size() != Count) {
|
||||
throw runtime_error("incorrect array length");
|
||||
}
|
||||
for (size_t z = 0; z < Count; z++) {
|
||||
from_json_into(json.at(z), ret[z]);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename IntT>
|
||||
JSON to_json(const CommonItemSet::Table::Range<IntT>& v) {
|
||||
if (v.min == v.max) {
|
||||
@@ -34,6 +54,22 @@ JSON to_json(const CommonItemSet::Table::Range<IntT>& v) {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename IntT>
|
||||
void from_json_into(const JSON& json, CommonItemSet::Table::Range<IntT>& ret) {
|
||||
if (json.is_int()) {
|
||||
IntT v = json.as_int();
|
||||
ret.min = v;
|
||||
ret.max = v;
|
||||
} else {
|
||||
const auto& l = json.as_list();
|
||||
if (l.size() != 2) {
|
||||
throw runtime_error("incorrect range list length");
|
||||
}
|
||||
ret.min = l.at(0)->as_int();
|
||||
ret.max = l.at(1)->as_int();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename IntT, size_t Count1, size_t Count2>
|
||||
JSON to_json(const parray<parray<IntT, Count2>, Count1>& v) {
|
||||
auto ret = JSON::list();
|
||||
@@ -43,6 +79,262 @@ JSON to_json(const parray<parray<IntT, Count2>, Count1>& v) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename IntT, size_t Count1, size_t Count2>
|
||||
void from_json_into(const JSON& json, parray<parray<IntT, Count2>, Count1>& ret) {
|
||||
if (json.size() != Count1) {
|
||||
throw runtime_error("incorrect array length");
|
||||
}
|
||||
for (size_t z = 0; z < Count1; z++) {
|
||||
from_json_into(json.at(z), ret[z]);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename IntT, size_t Count1, size_t Count2>
|
||||
void from_json_into(const JSON& json, parray<parray<CommonItemSet::Table::Range<IntT>, Count2>, Count1>& ret) {
|
||||
if (json.size() != Count1) {
|
||||
throw runtime_error("incorrect array length");
|
||||
}
|
||||
for (size_t z = 0; z < Count1; z++) {
|
||||
from_json_into(json.at(z), ret[z]);
|
||||
}
|
||||
}
|
||||
|
||||
CommonItemSet::Table::Table(const JSON& json, Episode episode)
|
||||
: episode(episode) {
|
||||
from_json_into(json.at("BaseWeaponTypeProbTable"), this->base_weapon_type_prob_table);
|
||||
from_json_into(json.at("SubtypeBaseTable"), this->subtype_base_table);
|
||||
from_json_into(json.at("SubtypeAreaLengthTable"), this->subtype_area_length_table);
|
||||
from_json_into(json.at("GrindProbTable"), this->grind_prob_table);
|
||||
from_json_into(json.at("ArmorShieldTypeIndexProbTable"), this->armor_shield_type_index_prob_table);
|
||||
from_json_into(json.at("ArmorSlotCountProbTable"), this->armor_slot_count_prob_table);
|
||||
from_json_into(json.at("BoxMesetaRanges"), this->box_meseta_ranges);
|
||||
this->has_rare_bonus_value_prob_table = json.at("HasRareBonusValueProbTable").as_bool();
|
||||
from_json_into(json.at("BonusValueProbTable"), this->bonus_value_prob_table);
|
||||
from_json_into(json.at("NonRareBonusProbSpec"), this->nonrare_bonus_prob_spec);
|
||||
from_json_into(json.at("BonusTypeProbTable"), this->bonus_type_prob_table);
|
||||
from_json_into(json.at("SpecialMult"), this->special_mult);
|
||||
from_json_into(json.at("SpecialPercent"), this->special_percent);
|
||||
from_json_into(json.at("ToolClassProbTable"), this->tool_class_prob_table);
|
||||
from_json_into(json.at("TechniqueIndexProbTable"), this->technique_index_prob_table);
|
||||
from_json_into(json.at("TechniqueLevelRanges"), this->technique_level_ranges);
|
||||
this->armor_or_shield_type_bias = json.at("ArmorOrShieldTypeBias").as_int();
|
||||
from_json_into(json.at("UnitMaxStarsTable"), this->unit_max_stars_table);
|
||||
from_json_into(json.at("BoxItemClassProbTable"), this->box_item_class_prob_table);
|
||||
|
||||
const auto& enemy_meseta_ranges_json = json.at("EnemyMesetaRanges").as_dict();
|
||||
const auto& enemy_type_drop_probs_json = json.at("EnemyTypeDropProbs").as_dict();
|
||||
const auto& enemy_item_classes_json = json.at("EnemyItemClasses").as_dict();
|
||||
for (size_t z = 0; z < 0x64; z++) {
|
||||
static const array<Episode, 3> episodes = {Episode::EP1, Episode::EP2, Episode::EP4};
|
||||
for (Episode episode : episodes) {
|
||||
for (auto type : enemy_types_for_rare_table_index(episode, z)) {
|
||||
string name = string_printf("%s:%s", abbreviation_for_episode(episode), name_for_enum(type));
|
||||
from_json_into(*enemy_meseta_ranges_json.at(name), this->enemy_meseta_ranges[z]);
|
||||
this->enemy_type_drop_probs[z] = enemy_type_drop_probs_json.at(name)->as_int();
|
||||
this->enemy_item_classes[z] = enemy_item_classes_json.at(name)->as_int();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const char* name_for_common_item_class(uint8_t item_class) {
|
||||
switch (item_class) {
|
||||
case 0x00:
|
||||
return "WEAPON ";
|
||||
case 0x01:
|
||||
return "ARMOR ";
|
||||
case 0x02:
|
||||
return "SHIELD ";
|
||||
case 0x03:
|
||||
return "UNIT ";
|
||||
case 0x04:
|
||||
return "TOOL ";
|
||||
case 0x05:
|
||||
return "MESETA ";
|
||||
case 0x06:
|
||||
return "NOTHING";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
void CommonItemSet::Table::print(FILE* stream) const {
|
||||
const auto& meseta_ranges = this->enemy_meseta_ranges;
|
||||
const auto& drop_probs = this->enemy_type_drop_probs;
|
||||
const auto& item_classes = this->enemy_item_classes;
|
||||
fprintf(stream, "Enemy tables:\n");
|
||||
fprintf(stream, " ## $LOW $HIGH DAR%% ITEM ENEMIES\n");
|
||||
for (size_t z = 0; z < 0x64; z++) {
|
||||
string enemies_str;
|
||||
for (EnemyType enemy_type : enemy_types_for_rare_table_index(this->episode, z)) {
|
||||
if (!enemies_str.empty()) {
|
||||
enemies_str += ", ";
|
||||
}
|
||||
enemies_str += name_for_enum(enemy_type);
|
||||
}
|
||||
if (drop_probs[z]) {
|
||||
fprintf(stream, " %02zX %5hu %5hu %3hhu%% %02hX:%s %s\n",
|
||||
z, meseta_ranges[z].min, meseta_ranges[z].max, drop_probs[z], item_classes[z],
|
||||
name_for_common_item_class(item_classes[z]), enemies_str.c_str());
|
||||
} else {
|
||||
fprintf(stream, " %02zX ----- ----- 0%% -- %s\n", z, enemies_str.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
static const array<const char*, 12> base_weapon_type_names = {
|
||||
"SABER ",
|
||||
"SWORD ",
|
||||
"DAGGER ",
|
||||
"PARTISAN",
|
||||
"SLICER ",
|
||||
"HANDGUN ",
|
||||
"RIFLE ",
|
||||
"MECHGUN ",
|
||||
"SHOT ",
|
||||
"CANE ",
|
||||
"ROD ",
|
||||
"WAND ",
|
||||
};
|
||||
fprintf(stream, "Base weapon config:\n");
|
||||
fprintf(stream, " TYPE PROB [SB AL] FLOORS\n");
|
||||
for (size_t z = 0; z < 12; z++) {
|
||||
uint8_t floor_to_class[10];
|
||||
if (this->subtype_base_table[z] < 0) {
|
||||
size_t start_floor = std::min<size_t>(-this->subtype_area_length_table[z], 10);
|
||||
for (size_t x = 0; x < start_floor; x++) {
|
||||
floor_to_class[x] = 0xFF;
|
||||
}
|
||||
for (size_t x = start_floor; x < 10; x++) {
|
||||
floor_to_class[x] = (x - start_floor) / this->subtype_area_length_table[z];
|
||||
}
|
||||
} else {
|
||||
for (size_t x = 0; x < 10; x++) {
|
||||
floor_to_class[x] = this->subtype_base_table[z] + (x / this->subtype_area_length_table[z]);
|
||||
}
|
||||
}
|
||||
fprintf(stream, " %02zX:%s %3hhu%% [%02hhX %02hhX] %02hhX %02hhX %02hhX %02hhX %02hhX %02hhX %02hhX %02hhX %02hhX %02hhX\n",
|
||||
z, base_weapon_type_names[z], this->base_weapon_type_prob_table[z],
|
||||
this->subtype_base_table[z], this->subtype_area_length_table[z],
|
||||
floor_to_class[0], floor_to_class[1], floor_to_class[2], floor_to_class[3], floor_to_class[4],
|
||||
floor_to_class[5], floor_to_class[6], floor_to_class[7], floor_to_class[8], floor_to_class[9]);
|
||||
}
|
||||
|
||||
fprintf(stream, "Box configuration:\n");
|
||||
fprintf(stream, " AR $LOW $HIGH WEP%% ARM%% SHD%% UNI%% TL%% MST%% NO%%\n");
|
||||
for (size_t z = 0; z < 10; z++) {
|
||||
fprintf(stream, " %02zX %5hu %5hu %3hhu%% %3hhu%% %3hhu%% %3hhu%% %3hhu%% %3hhu%% %3hhu%%\n",
|
||||
z, this->box_meseta_ranges[z].min, this->box_meseta_ranges[z].max,
|
||||
this->box_item_class_prob_table[0][z],
|
||||
this->box_item_class_prob_table[1][z],
|
||||
this->box_item_class_prob_table[2][z],
|
||||
this->box_item_class_prob_table[3][z],
|
||||
this->box_item_class_prob_table[4][z],
|
||||
this->box_item_class_prob_table[5][z],
|
||||
this->box_item_class_prob_table[6][z]);
|
||||
}
|
||||
|
||||
fprintf(stream, "Weapon drops:\n");
|
||||
fprintf(stream, " Grinds:\n");
|
||||
fprintf(stream, " GD AR0%% AR1%% AR2%% AR3%%\n");
|
||||
for (size_t z = 0; z < 9; z++) {
|
||||
fprintf(stream, " +%zu %3hhd%% %3hhd%% %3hhd%% %3hhd%%\n", z,
|
||||
this->grind_prob_table[z][0], this->grind_prob_table[z][1],
|
||||
this->grind_prob_table[z][2], this->grind_prob_table[z][3]);
|
||||
}
|
||||
fprintf(stream, " Bonus value table:\n");
|
||||
fprintf(stream, " ID");
|
||||
for (int8_t v = -10; v <= 100; v += 5) {
|
||||
fprintf(stream, " %5hhd%%", v);
|
||||
}
|
||||
fputc('\n', stream);
|
||||
for (size_t z = 0; z < (this->has_rare_bonus_value_prob_table ? 6 : 5); z++) {
|
||||
fprintf(stream, " %02zX", z);
|
||||
for (size_t x = 0; x < 0x17; x++) {
|
||||
fprintf(stream, " %5hu#", this->bonus_value_prob_table[x][z]);
|
||||
}
|
||||
fputc('\n', stream);
|
||||
}
|
||||
fprintf(stream, " Area config tables:\n");
|
||||
fprintf(stream, " AR BONUS SP NO%% NTV%% AB%% MAC%% DRK%% HIT%% SM SPC%%\n");
|
||||
for (size_t z = 0; z < 10; z++) {
|
||||
fprintf(stream, " %02zX %02hhX %02hhX %02hhX %3hhu%% %3hhu%% %3hhu%% %3hhu%% %3hhu%% %3hhu%% %02hhX %3hhu%%\n",
|
||||
z, this->nonrare_bonus_prob_spec[0][z], this->nonrare_bonus_prob_spec[1][z], this->nonrare_bonus_prob_spec[2][z],
|
||||
this->bonus_type_prob_table[0][z], this->bonus_type_prob_table[1][z], this->bonus_type_prob_table[2][z],
|
||||
this->bonus_type_prob_table[3][z], this->bonus_type_prob_table[4][z], this->bonus_type_prob_table[5][z],
|
||||
this->special_mult[z], this->special_percent[z]);
|
||||
}
|
||||
|
||||
fprintf(stream, " Tool class table:\n");
|
||||
fprintf(stream, " CS A1 A2 A3 A4 A5 A6 A7 A8 A9 A10\n");
|
||||
for (size_t tool_class = 0; tool_class < this->tool_class_prob_table.size(); tool_class++) {
|
||||
fprintf(stream, " %02zX", tool_class);
|
||||
for (size_t area_norm = 0; area_norm < 10; area_norm++) {
|
||||
fprintf(stream, " %5hu", this->tool_class_prob_table[tool_class][area_norm]);
|
||||
}
|
||||
fputc('\n', stream);
|
||||
}
|
||||
|
||||
static const array<const char*, 19> technique_names = {
|
||||
"FOIE ",
|
||||
"GIFOIE ",
|
||||
"RAFOIE ",
|
||||
"BARTA ",
|
||||
"GIBARTA ",
|
||||
"RABARTA ",
|
||||
"ZONDE ",
|
||||
"GIZONDE ",
|
||||
"RAZONDE ",
|
||||
"GRANTS ",
|
||||
"DEBAND ",
|
||||
"JELLEN ",
|
||||
"ZALURE ",
|
||||
"SHIFTA ",
|
||||
"RYUKER ",
|
||||
"RESTA ",
|
||||
"ANTI ",
|
||||
"REVERSER",
|
||||
"MEGID ",
|
||||
};
|
||||
|
||||
fprintf(stream, " Technique table:\n");
|
||||
fprintf(stream, " TECH A1 A2 A3 A4 A5 A6 A7 A8 A9 A10\n");
|
||||
for (size_t tech_num = 0; tech_num < this->technique_index_prob_table.size(); tech_num++) {
|
||||
fprintf(stream, " %02zX:%s", tech_num, technique_names[tech_num]);
|
||||
for (size_t area_norm = 0; area_norm < 10; area_norm++) {
|
||||
uint16_t prob = this->technique_index_prob_table[tech_num][area_norm];
|
||||
if (prob) {
|
||||
const auto& level_range = this->technique_level_ranges[tech_num][area_norm];
|
||||
size_t min_level = level_range.min + 1;
|
||||
size_t max_level = level_range.max + 1;
|
||||
fprintf(stream, " %5hu[%2zu-%2zu]", prob, min_level, max_level);
|
||||
} else {
|
||||
fprintf(stream, " 0[-----]");
|
||||
}
|
||||
}
|
||||
fputc('\n', stream);
|
||||
}
|
||||
|
||||
fprintf(stream, " Armor/shield type bias: %hhu\n", this->armor_or_shield_type_bias);
|
||||
|
||||
fprintf(stream, " Armor/shield type index table:\n");
|
||||
fprintf(stream, " TY PROB\n");
|
||||
for (size_t z = 0; z < 5; z++) {
|
||||
fprintf(stream, " %02zX %3hhu%%\n", z, this->armor_shield_type_index_prob_table[z]);
|
||||
}
|
||||
|
||||
fprintf(stream, " Armor/shield slot count table:\n");
|
||||
fprintf(stream, " #S PROB\n");
|
||||
for (size_t z = 0; z < 5; z++) {
|
||||
fprintf(stream, " %02zX %3hhu%%\n", z, this->armor_slot_count_prob_table[z]);
|
||||
}
|
||||
|
||||
fprintf(stream, " Unit maximum stars table:\n");
|
||||
fprintf(stream, " AR #*\n");
|
||||
for (size_t z = 0; z < 10; z++) {
|
||||
fprintf(stream, " %02zX %3hhu\n", z, this->unit_max_stars_table[z]);
|
||||
}
|
||||
}
|
||||
|
||||
JSON CommonItemSet::Table::json() const {
|
||||
JSON enemy_meseta_ranges_json = JSON::dict();
|
||||
JSON enemy_type_drop_probs_json = JSON::dict();
|
||||
@@ -111,7 +403,28 @@ JSON CommonItemSet::json() const {
|
||||
return modes_dict;
|
||||
}
|
||||
|
||||
CommonItemSet::Table::Table(const StringReader& r, bool is_big_endian, bool is_v3) {
|
||||
void CommonItemSet::print(FILE* stream) const {
|
||||
static const array<GameMode, 4> modes = {GameMode::NORMAL, GameMode::BATTLE, GameMode::CHALLENGE, GameMode::SOLO};
|
||||
for (const auto& mode : modes) {
|
||||
static const array<Episode, 3> episodes = {Episode::EP1, Episode::EP2, Episode::EP4};
|
||||
for (const auto& episode : episodes) {
|
||||
for (uint8_t difficulty = 0; difficulty < 4; difficulty++) {
|
||||
for (uint8_t section_id = 0; section_id < 10; section_id++) {
|
||||
try {
|
||||
auto table = this->get_table(episode, mode, difficulty, section_id);
|
||||
fprintf(stream, "============ %s %s %s %s\n",
|
||||
name_for_mode(mode), name_for_episode(episode), name_for_difficulty(difficulty), name_for_section_id(section_id));
|
||||
table->print(stream);
|
||||
} catch (const runtime_error&) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CommonItemSet::Table::Table(const StringReader& r, bool is_big_endian, bool is_v3, Episode episode)
|
||||
: episode(episode) {
|
||||
if (is_big_endian) {
|
||||
this->parse_itempt_t<true>(r, is_v3);
|
||||
} else {
|
||||
@@ -179,41 +492,6 @@ void CommonItemSet::Table::parse_itempt_t(const StringReader& r, bool is_v3) {
|
||||
this->box_item_class_prob_table = r.pget<parray<parray<uint8_t, 10>, 7>>(offsets.box_item_class_prob_table_offset);
|
||||
}
|
||||
|
||||
void CommonItemSet::Table::print_enemy_table(FILE* stream) const {
|
||||
const auto& meseta_ranges = this->enemy_meseta_ranges;
|
||||
const auto& drop_probs = this->enemy_type_drop_probs;
|
||||
const auto& item_classes = this->enemy_item_classes;
|
||||
// const parray<Range<uint16_t>, 0x64>& enemy_meseta_ranges() const;
|
||||
// const parray<uint8_t, 0x64>& enemy_type_drop_probs() const;
|
||||
// const parray<uint8_t, 0x64>& enemy_item_classes() const;
|
||||
fprintf(stream, "## $_LOW $_HIGH DAR ITEM\n");
|
||||
for (size_t z = 0; z < 0x64; z++) {
|
||||
const char* item_class_name = "__UNKNOWN__";
|
||||
switch (item_classes[z]) {
|
||||
case 0x00:
|
||||
item_class_name = "WEAPON";
|
||||
break;
|
||||
case 0x01:
|
||||
item_class_name = "ARMOR";
|
||||
break;
|
||||
case 0x02:
|
||||
item_class_name = "SHIELD";
|
||||
break;
|
||||
case 0x03:
|
||||
item_class_name = "UNIT";
|
||||
break;
|
||||
case 0x04:
|
||||
item_class_name = "TOOL";
|
||||
break;
|
||||
case 0x05:
|
||||
item_class_name = "MESETA";
|
||||
break;
|
||||
}
|
||||
fprintf(stream, "%02zX %5hu %5hu %3hhu %02hX (%s)\n",
|
||||
z, meseta_ranges[z].min, meseta_ranges[z].max, drop_probs[z], item_classes[z], item_class_name);
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t CommonItemSet::key_for_table(Episode episode, GameMode mode, uint8_t difficulty, uint8_t secid) {
|
||||
// Bits: -----EEEMMDDSSSS
|
||||
return (((static_cast<uint16_t>(episode) << 8) & 0x0700) |
|
||||
@@ -241,7 +519,7 @@ AFSV2CommonItemSet::AFSV2CommonItemSet(
|
||||
for (size_t section_id = 0; section_id < 10; section_id++) {
|
||||
auto entry = pt_afs.get(difficulty * 10 + section_id);
|
||||
StringReader r(entry.first, entry.second);
|
||||
auto table = make_shared<Table>(r, false, false);
|
||||
auto table = make_shared<Table>(r, false, false, Episode::EP1);
|
||||
this->tables.emplace(this->key_for_table(Episode::EP1, GameMode::NORMAL, difficulty, section_id), table);
|
||||
this->tables.emplace(this->key_for_table(Episode::EP1, GameMode::BATTLE, difficulty, section_id), table);
|
||||
this->tables.emplace(this->key_for_table(Episode::EP1, GameMode::SOLO, difficulty, section_id), table);
|
||||
@@ -253,7 +531,7 @@ AFSV2CommonItemSet::AFSV2CommonItemSet(
|
||||
AFSArchive ct_afs(ct_afs_data);
|
||||
for (size_t difficulty = 0; difficulty < 4; difficulty++) {
|
||||
auto r = ct_afs.get_reader(difficulty * 10);
|
||||
auto table = make_shared<Table>(r, false, false);
|
||||
auto table = make_shared<Table>(r, false, false, Episode::EP1);
|
||||
for (size_t section_id = 0; section_id < 10; section_id++) {
|
||||
this->tables.emplace(this->key_for_table(Episode::EP1, GameMode::CHALLENGE, difficulty, section_id), table);
|
||||
}
|
||||
@@ -305,7 +583,7 @@ GSLV3V4CommonItemSet::GSLV3V4CommonItemSet(std::shared_ptr<const std::string> gs
|
||||
throw;
|
||||
}
|
||||
}
|
||||
auto table = make_shared<Table>(r, is_big_endian, true);
|
||||
auto table = make_shared<Table>(r, is_big_endian, true, episode);
|
||||
this->tables.emplace(this->key_for_table(episode, GameMode::NORMAL, difficulty, section_id), table);
|
||||
this->tables.emplace(this->key_for_table(episode, GameMode::BATTLE, difficulty, section_id), table);
|
||||
this->tables.emplace(this->key_for_table(episode, GameMode::SOLO, difficulty, section_id), table);
|
||||
@@ -315,7 +593,7 @@ GSLV3V4CommonItemSet::GSLV3V4CommonItemSet(std::shared_ptr<const std::string> gs
|
||||
if (episode != Episode::EP4) {
|
||||
for (size_t difficulty = 0; difficulty < 4; difficulty++) {
|
||||
auto r = gsl.get_reader(filename_for_table(episode, difficulty, 0, true));
|
||||
auto table = make_shared<Table>(r, is_big_endian, true);
|
||||
auto table = make_shared<Table>(r, is_big_endian, true, episode);
|
||||
for (size_t section_id = 0; section_id < 10; section_id++) {
|
||||
this->tables.emplace(this->key_for_table(episode, GameMode::CHALLENGE, difficulty, section_id), table);
|
||||
}
|
||||
@@ -324,6 +602,33 @@ GSLV3V4CommonItemSet::GSLV3V4CommonItemSet(std::shared_ptr<const std::string> gs
|
||||
}
|
||||
}
|
||||
|
||||
JSONCommonItemSet::JSONCommonItemSet(const JSON& json) {
|
||||
for (const auto& mode_it : json.as_dict()) {
|
||||
static const unordered_map<string, GameMode> mode_keys(
|
||||
{{"Normal", GameMode::NORMAL}, {"Battle", GameMode::BATTLE}, {"Challenge", GameMode::CHALLENGE}, {"Solo", GameMode::SOLO}});
|
||||
GameMode mode = mode_keys.at(mode_it.first);
|
||||
|
||||
for (const auto& episode_it : mode_it.second->as_dict()) {
|
||||
static const unordered_map<string, Episode> episode_keys(
|
||||
{{"Episode1", Episode::EP1}, {"Episode2", Episode::EP2}, {"Episode4", Episode::EP4}});
|
||||
Episode episode = episode_keys.at(episode_it.first);
|
||||
|
||||
for (const auto& difficulty_it : episode_it.second->as_dict()) {
|
||||
static const unordered_map<string, uint8_t> difficulty_keys(
|
||||
{{"Normal", 0}, {"Hard", 1}, {"VeryHard", 2}, {"Ultimate", 3}});
|
||||
uint8_t difficulty = difficulty_keys.at(difficulty_it.first);
|
||||
|
||||
for (const auto& section_id_it : difficulty_it.second->as_dict()) {
|
||||
uint8_t section_id = section_id_for_name(section_id_it.first);
|
||||
this->tables.emplace(
|
||||
this->key_for_table(episode, mode, difficulty, section_id),
|
||||
make_shared<Table>(*section_id_it.second, episode));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RELFileSet::RELFileSet(std::shared_ptr<const std::string> data)
|
||||
: data(data),
|
||||
r(*this->data) {}
|
||||
|
||||
+10
-2
@@ -14,7 +14,8 @@ public:
|
||||
class Table {
|
||||
public:
|
||||
Table() = delete;
|
||||
Table(const StringReader& r, bool big_endian, bool is_v3);
|
||||
Table(const JSON& json, Episode episode);
|
||||
Table(const StringReader& r, bool big_endian, bool is_v3, Episode episode);
|
||||
|
||||
template <typename IntT>
|
||||
struct Range {
|
||||
@@ -22,6 +23,7 @@ public:
|
||||
IntT max;
|
||||
} __packed__;
|
||||
|
||||
Episode episode;
|
||||
parray<uint8_t, 0x0C> base_weapon_type_prob_table;
|
||||
parray<int8_t, 0x0C> subtype_base_table;
|
||||
parray<uint8_t, 0x0C> subtype_area_length_table;
|
||||
@@ -45,8 +47,8 @@ public:
|
||||
parray<uint8_t, 0x0A> unit_max_stars_table;
|
||||
parray<parray<uint8_t, 10>, 7> box_item_class_prob_table;
|
||||
|
||||
void print_enemy_table(FILE* stream) const;
|
||||
JSON json() const;
|
||||
void print(FILE* stream) const;
|
||||
|
||||
private:
|
||||
template <bool IsBigEndian>
|
||||
@@ -263,6 +265,7 @@ public:
|
||||
|
||||
std::shared_ptr<const Table> get_table(Episode episode, GameMode mode, uint8_t difficulty, uint8_t secid) const;
|
||||
JSON json() const;
|
||||
void print(FILE* stream) const;
|
||||
|
||||
protected:
|
||||
CommonItemSet() = default;
|
||||
@@ -282,6 +285,11 @@ public:
|
||||
GSLV3V4CommonItemSet(std::shared_ptr<const std::string> gsl_data, bool is_big_endian);
|
||||
};
|
||||
|
||||
class JSONCommonItemSet : public CommonItemSet {
|
||||
public:
|
||||
explicit JSONCommonItemSet(const JSON& json);
|
||||
};
|
||||
|
||||
// Note: There are clearly better ways of doing this, but this implementation
|
||||
// closely follows what the original code in the client does.
|
||||
template <typename ItemT, size_t MaxCount>
|
||||
|
||||
+1357
-1357
File diff suppressed because it is too large
Load Diff
+226
-226
@@ -1,226 +1,226 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#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.)
|
||||
// To use this class, instantiate it, then call .add() one or more times, then
|
||||
// call .close() and use the returned string as the compressed result.
|
||||
class PRSCompressor {
|
||||
public:
|
||||
// compression_level specifies how aggressively to search for alternate paths:
|
||||
// -1: Don't perform any compression at all, but produce output that can be
|
||||
// understood by prs_decompress. The output will be about 9/8 the size
|
||||
// of the input.
|
||||
// 0: Greedily search for the longest backreference at every point. Don't
|
||||
// consider any alternate paths. Generally offers a good balance between
|
||||
// speed and output size.
|
||||
// 1: Consider two paths at each point when a backreference is found: using
|
||||
// the backreference or ignoring it.
|
||||
// 2+: Consider further chains of paths at each point. Using values 2 or
|
||||
// greater for compression_level generally yields diminishing returns.
|
||||
explicit PRSCompressor(ssize_t compression_level = 0, ProgressCallback progress_fn = nullptr);
|
||||
~PRSCompressor() = default;
|
||||
|
||||
// Adds more input data to be compressed, which logically comes after all
|
||||
// previous data provided via add() calls. Cannot be called after close() is
|
||||
// called.
|
||||
void add(const void* data, size_t size);
|
||||
void add(const std::string& data);
|
||||
|
||||
// Ends compression and returns the complete compressed result. It's OK to
|
||||
// std::move() from the returned string reference.
|
||||
std::string& close();
|
||||
|
||||
// Returns the total number of bytes passed to add() calls so far.
|
||||
inline size_t input_size() const {
|
||||
return this->input_bytes;
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
ssize_t compression_level;
|
||||
ProgressCallback progress_fn;
|
||||
bool closed;
|
||||
|
||||
size_t control_byte_offset;
|
||||
uint16_t pending_control_bits;
|
||||
|
||||
size_t input_bytes;
|
||||
WrappedLog<0x101> forward_log;
|
||||
IndexedLog<0x2000> reverse_log;
|
||||
|
||||
StringWriter output;
|
||||
};
|
||||
|
||||
// These functions use PRSCompressor to compress a buffer of data. This is
|
||||
// essentially a shortcut for constructing a PRSCompressor, calling .add() on
|
||||
// it once, then calling .close().
|
||||
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);
|
||||
std::string prs_compress_optimal(const std::string& data, ProgressCallback progress_fn = nullptr);
|
||||
|
||||
// Compresses data using PRS to the LARGEST possible output size. There is no
|
||||
// practical use for this function except for amusement.
|
||||
std::string prs_compress_pessimal(const void* vdata, size_t size);
|
||||
|
||||
// Decompresses PRS-compressed data.
|
||||
struct PRSDecompressResult {
|
||||
std::string data;
|
||||
size_t input_bytes_used;
|
||||
};
|
||||
PRSDecompressResult prs_decompress_with_meta(const void* data, size_t size, size_t max_output_size = 0, bool allow_unterminated = false);
|
||||
PRSDecompressResult prs_decompress_with_meta(const std::string& data, size_t max_output_size = 0, bool allow_unterminated = false);
|
||||
std::string prs_decompress(const void* data, size_t size, size_t max_output_size = 0, bool allow_unterminated = false);
|
||||
std::string prs_decompress(const std::string& data, size_t max_output_size = 0, bool allow_unterminated = false);
|
||||
|
||||
// Returns the decompressed size of PRS-compressed data, without actually
|
||||
// decompressing it.
|
||||
size_t prs_decompress_size(const void* data, size_t size, size_t max_output_size = 0, bool allow_unterminated = false);
|
||||
size_t prs_decompress_size(const std::string& data, size_t max_output_size = 0, bool allow_unterminated = false);
|
||||
|
||||
// Prints the command stream from a PRS-compressed buffer.
|
||||
void prs_disassemble(FILE* stream, const void* data, size_t size);
|
||||
void prs_disassemble(FILE* stream, const std::string& data);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// BC0 compression
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Compresses data using the BC0 algorithm. Like with PRS, the optimal variant
|
||||
// is slow, but produces the smallest possible output.
|
||||
std::string bc0_compress_optimal(
|
||||
const void* in_data_v,
|
||||
size_t in_size,
|
||||
ProgressCallback progress_fn = nullptr);
|
||||
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);
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#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.)
|
||||
// To use this class, instantiate it, then call .add() one or more times, then
|
||||
// call .close() and use the returned string as the compressed result.
|
||||
class PRSCompressor {
|
||||
public:
|
||||
// compression_level specifies how aggressively to search for alternate paths:
|
||||
// -1: Don't perform any compression at all, but produce output that can be
|
||||
// understood by prs_decompress. The output will be about 9/8 the size
|
||||
// of the input.
|
||||
// 0: Greedily search for the longest backreference at every point. Don't
|
||||
// consider any alternate paths. Generally offers a good balance between
|
||||
// speed and output size.
|
||||
// 1: Consider two paths at each point when a backreference is found: using
|
||||
// the backreference or ignoring it.
|
||||
// 2+: Consider further chains of paths at each point. Using values 2 or
|
||||
// greater for compression_level generally yields diminishing returns.
|
||||
explicit PRSCompressor(ssize_t compression_level = 0, ProgressCallback progress_fn = nullptr);
|
||||
~PRSCompressor() = default;
|
||||
|
||||
// Adds more input data to be compressed, which logically comes after all
|
||||
// previous data provided via add() calls. Cannot be called after close() is
|
||||
// called.
|
||||
void add(const void* data, size_t size);
|
||||
void add(const std::string& data);
|
||||
|
||||
// Ends compression and returns the complete compressed result. It's OK to
|
||||
// std::move() from the returned string reference.
|
||||
std::string& close();
|
||||
|
||||
// Returns the total number of bytes passed to add() calls so far.
|
||||
inline size_t input_size() const {
|
||||
return this->input_bytes;
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
ssize_t compression_level;
|
||||
ProgressCallback progress_fn;
|
||||
bool closed;
|
||||
|
||||
size_t control_byte_offset;
|
||||
uint16_t pending_control_bits;
|
||||
|
||||
size_t input_bytes;
|
||||
WrappedLog<0x101> forward_log;
|
||||
IndexedLog<0x2000> reverse_log;
|
||||
|
||||
StringWriter output;
|
||||
};
|
||||
|
||||
// These functions use PRSCompressor to compress a buffer of data. This is
|
||||
// essentially a shortcut for constructing a PRSCompressor, calling .add() on
|
||||
// it once, then calling .close().
|
||||
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);
|
||||
std::string prs_compress_optimal(const std::string& data, ProgressCallback progress_fn = nullptr);
|
||||
|
||||
// Compresses data using PRS to the LARGEST possible output size. There is no
|
||||
// practical use for this function except for amusement.
|
||||
std::string prs_compress_pessimal(const void* vdata, size_t size);
|
||||
|
||||
// Decompresses PRS-compressed data.
|
||||
struct PRSDecompressResult {
|
||||
std::string data;
|
||||
size_t input_bytes_used;
|
||||
};
|
||||
PRSDecompressResult prs_decompress_with_meta(const void* data, size_t size, size_t max_output_size = 0, bool allow_unterminated = false);
|
||||
PRSDecompressResult prs_decompress_with_meta(const std::string& data, size_t max_output_size = 0, bool allow_unterminated = false);
|
||||
std::string prs_decompress(const void* data, size_t size, size_t max_output_size = 0, bool allow_unterminated = false);
|
||||
std::string prs_decompress(const std::string& data, size_t max_output_size = 0, bool allow_unterminated = false);
|
||||
|
||||
// Returns the decompressed size of PRS-compressed data, without actually
|
||||
// decompressing it.
|
||||
size_t prs_decompress_size(const void* data, size_t size, size_t max_output_size = 0, bool allow_unterminated = false);
|
||||
size_t prs_decompress_size(const std::string& data, size_t max_output_size = 0, bool allow_unterminated = false);
|
||||
|
||||
// Prints the command stream from a PRS-compressed buffer.
|
||||
void prs_disassemble(FILE* stream, const void* data, size_t size);
|
||||
void prs_disassemble(FILE* stream, const std::string& data);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// BC0 compression
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Compresses data using the BC0 algorithm. Like with PRS, the optimal variant
|
||||
// is slow, but produces the smallest possible output.
|
||||
std::string bc0_compress_optimal(
|
||||
const void* in_data_v,
|
||||
size_t in_size,
|
||||
ProgressCallback progress_fn = nullptr);
|
||||
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);
|
||||
|
||||
+121
-121
@@ -1,121 +1,121 @@
|
||||
#include "DNSServer.hh"
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <poll.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Network.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#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,
|
||||
shared_ptr<const IPV4RangeSet> banned_ipv4_ranges)
|
||||
: base(base),
|
||||
local_connect_address(local_connect_address),
|
||||
external_connect_address(external_connect_address),
|
||||
banned_ipv4_ranges(banned_ipv4_ranges) {}
|
||||
|
||||
DNSServer::~DNSServer() {
|
||||
for (const auto& it : this->fd_to_receive_event) {
|
||||
close(it.first);
|
||||
}
|
||||
}
|
||||
|
||||
void DNSServer::listen(const std::string& socket_path) {
|
||||
this->add_socket(::listen(socket_path, 0, 0));
|
||||
}
|
||||
|
||||
void DNSServer::listen(const std::string& addr, int port) {
|
||||
this->add_socket(::listen(addr, port, 0));
|
||||
}
|
||||
|
||||
void DNSServer::listen(int port) {
|
||||
this->add_socket(::listen("", port, 0));
|
||||
}
|
||||
|
||||
void DNSServer::add_socket(int fd) {
|
||||
unique_ptr<struct event, void (*)(struct event*)> e(
|
||||
event_new(this->base.get(), fd, EV_READ | EV_PERSIST, &DNSServer::dispatch_on_receive_message, this),
|
||||
event_free);
|
||||
event_add(e.get(), nullptr);
|
||||
this->fd_to_receive_event.emplace(fd, std::move(e));
|
||||
}
|
||||
|
||||
void DNSServer::dispatch_on_receive_message(evutil_socket_t fd,
|
||||
short events, void* ctx) {
|
||||
reinterpret_cast<DNSServer*>(ctx)->on_receive_message(fd, events);
|
||||
}
|
||||
|
||||
string DNSServer::response_for_query(const void* vdata, size_t size, uint32_t resolved_address) {
|
||||
if (size < 0x0C) {
|
||||
throw invalid_argument("query too small");
|
||||
}
|
||||
|
||||
const char* data = reinterpret_cast<const char*>(vdata);
|
||||
size_t name_len = strlen(&data[12]) + 1;
|
||||
|
||||
be_uint32_t be_resolved_address = resolved_address;
|
||||
|
||||
string response;
|
||||
response.append(data, 2);
|
||||
response.append("\x81\x80\x00\x01\x00\x01\x00\x00\x00\x00", 10);
|
||||
response.append(&data[12], name_len);
|
||||
response.append("\x00\x01\x00\x01\xC0\x0C\x00\x01\x00\x01\x00\x00\x00\x3C\x00\x04", 16);
|
||||
response.append(reinterpret_cast<const char*>(&be_resolved_address), 4);
|
||||
return response;
|
||||
}
|
||||
|
||||
string DNSServer::response_for_query(
|
||||
const string& query, uint32_t resolved_address) {
|
||||
return DNSServer::response_for_query(query.data(), query.size(), resolved_address);
|
||||
}
|
||||
|
||||
void DNSServer::on_receive_message(int fd, short) {
|
||||
for (;;) {
|
||||
struct sockaddr_storage remote;
|
||||
socklen_t remote_size = sizeof(sockaddr_in);
|
||||
memset(&remote, 0, remote_size);
|
||||
|
||||
string input(2048, 0);
|
||||
ssize_t bytes = recvfrom(fd, const_cast<char*>(input.data()), input.size(),
|
||||
0, reinterpret_cast<sockaddr*>(&remote), &remote_size);
|
||||
|
||||
if (bytes < 0) {
|
||||
if (errno != EAGAIN) {
|
||||
dns_server_log.error("input error %d", errno);
|
||||
throw runtime_error("cannot read from udp socket");
|
||||
}
|
||||
break;
|
||||
|
||||
} else if (bytes == 0) {
|
||||
break;
|
||||
|
||||
} else if (bytes < 0x0C) {
|
||||
dns_server_log.warning("input query too small");
|
||||
print_data(stderr, input.data(), bytes);
|
||||
|
||||
} else if (!this->banned_ipv4_ranges->check(remote)) {
|
||||
input.resize(bytes);
|
||||
const sockaddr_in* remote_sin = reinterpret_cast<const sockaddr_in*>(&remote);
|
||||
uint32_t remote_address = ntohl(remote_sin->sin_addr.s_addr);
|
||||
uint32_t connect_address = is_local_address(remote_address)
|
||||
? this->local_connect_address
|
||||
: this->external_connect_address;
|
||||
string response = this->response_for_query(input, connect_address);
|
||||
sendto(fd, response.data(), response.size(), 0,
|
||||
reinterpret_cast<const sockaddr*>(&remote), remote_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
#include "DNSServer.hh"
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <poll.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Network.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#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,
|
||||
shared_ptr<const IPV4RangeSet> banned_ipv4_ranges)
|
||||
: base(base),
|
||||
local_connect_address(local_connect_address),
|
||||
external_connect_address(external_connect_address),
|
||||
banned_ipv4_ranges(banned_ipv4_ranges) {}
|
||||
|
||||
DNSServer::~DNSServer() {
|
||||
for (const auto& it : this->fd_to_receive_event) {
|
||||
close(it.first);
|
||||
}
|
||||
}
|
||||
|
||||
void DNSServer::listen(const std::string& socket_path) {
|
||||
this->add_socket(::listen(socket_path, 0, 0));
|
||||
}
|
||||
|
||||
void DNSServer::listen(const std::string& addr, int port) {
|
||||
this->add_socket(::listen(addr, port, 0));
|
||||
}
|
||||
|
||||
void DNSServer::listen(int port) {
|
||||
this->add_socket(::listen("", port, 0));
|
||||
}
|
||||
|
||||
void DNSServer::add_socket(int fd) {
|
||||
unique_ptr<struct event, void (*)(struct event*)> e(
|
||||
event_new(this->base.get(), fd, EV_READ | EV_PERSIST, &DNSServer::dispatch_on_receive_message, this),
|
||||
event_free);
|
||||
event_add(e.get(), nullptr);
|
||||
this->fd_to_receive_event.emplace(fd, std::move(e));
|
||||
}
|
||||
|
||||
void DNSServer::dispatch_on_receive_message(evutil_socket_t fd,
|
||||
short events, void* ctx) {
|
||||
reinterpret_cast<DNSServer*>(ctx)->on_receive_message(fd, events);
|
||||
}
|
||||
|
||||
string DNSServer::response_for_query(const void* vdata, size_t size, uint32_t resolved_address) {
|
||||
if (size < 0x0C) {
|
||||
throw invalid_argument("query too small");
|
||||
}
|
||||
|
||||
const char* data = reinterpret_cast<const char*>(vdata);
|
||||
size_t name_len = strlen(&data[12]) + 1;
|
||||
|
||||
be_uint32_t be_resolved_address = resolved_address;
|
||||
|
||||
string response;
|
||||
response.append(data, 2);
|
||||
response.append("\x81\x80\x00\x01\x00\x01\x00\x00\x00\x00", 10);
|
||||
response.append(&data[12], name_len);
|
||||
response.append("\x00\x01\x00\x01\xC0\x0C\x00\x01\x00\x01\x00\x00\x00\x3C\x00\x04", 16);
|
||||
response.append(reinterpret_cast<const char*>(&be_resolved_address), 4);
|
||||
return response;
|
||||
}
|
||||
|
||||
string DNSServer::response_for_query(
|
||||
const string& query, uint32_t resolved_address) {
|
||||
return DNSServer::response_for_query(query.data(), query.size(), resolved_address);
|
||||
}
|
||||
|
||||
void DNSServer::on_receive_message(int fd, short) {
|
||||
for (;;) {
|
||||
struct sockaddr_storage remote;
|
||||
socklen_t remote_size = sizeof(sockaddr_in);
|
||||
memset(&remote, 0, remote_size);
|
||||
|
||||
string input(2048, 0);
|
||||
ssize_t bytes = recvfrom(fd, const_cast<char*>(input.data()), input.size(),
|
||||
0, reinterpret_cast<sockaddr*>(&remote), &remote_size);
|
||||
|
||||
if (bytes < 0) {
|
||||
if (errno != EAGAIN) {
|
||||
dns_server_log.error("input error %d", errno);
|
||||
throw runtime_error("cannot read from udp socket");
|
||||
}
|
||||
break;
|
||||
|
||||
} else if (bytes == 0) {
|
||||
break;
|
||||
|
||||
} else if (bytes < 0x0C) {
|
||||
dns_server_log.warning("input query too small");
|
||||
print_data(stderr, input.data(), bytes);
|
||||
|
||||
} else if (!this->banned_ipv4_ranges->check(remote)) {
|
||||
input.resize(bytes);
|
||||
const sockaddr_in* remote_sin = reinterpret_cast<const sockaddr_in*>(&remote);
|
||||
uint32_t remote_address = ntohl(remote_sin->sin_addr.s_addr);
|
||||
uint32_t connect_address = is_local_address(remote_address)
|
||||
? this->local_connect_address
|
||||
: this->external_connect_address;
|
||||
string response = this->response_for_query(input, connect_address);
|
||||
sendto(fd, response.data(), response.size(), 0,
|
||||
reinterpret_cast<const sockaddr*>(&remote), remote_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+44
-44
@@ -1,44 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <event2/event.h>
|
||||
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "IPV4RangeSet.hh"
|
||||
|
||||
class DNSServer {
|
||||
public:
|
||||
DNSServer(
|
||||
std::shared_ptr<struct event_base> base,
|
||||
uint32_t local_connect_address,
|
||||
uint32_t external_connect_address,
|
||||
std::shared_ptr<const IPV4RangeSet> banned_ipv4_ranges);
|
||||
DNSServer(const DNSServer&) = delete;
|
||||
DNSServer(DNSServer&&) = delete;
|
||||
virtual ~DNSServer();
|
||||
|
||||
inline void set_banned_ipv4_ranges(std::shared_ptr<const IPV4RangeSet> banned_ipv4_ranges) {
|
||||
this->banned_ipv4_ranges = banned_ipv4_ranges;
|
||||
}
|
||||
|
||||
void listen(const std::string& socket_path);
|
||||
void listen(const std::string& addr, int port);
|
||||
void listen(int port);
|
||||
void add_socket(int fd);
|
||||
|
||||
static std::string response_for_query(const void* vdata, size_t size, uint32_t resolved_address);
|
||||
static std::string response_for_query(const std::string& query, uint32_t resolved_address);
|
||||
|
||||
private:
|
||||
std::shared_ptr<struct event_base> base;
|
||||
std::unordered_map<int, std::unique_ptr<struct event, void (*)(struct event*)>> fd_to_receive_event;
|
||||
uint32_t local_connect_address;
|
||||
uint32_t external_connect_address;
|
||||
std::shared_ptr<const IPV4RangeSet> banned_ipv4_ranges;
|
||||
|
||||
static void dispatch_on_receive_message(evutil_socket_t fd, short events, void* ctx);
|
||||
void on_receive_message(int fd, short event);
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <event2/event.h>
|
||||
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "IPV4RangeSet.hh"
|
||||
|
||||
class DNSServer {
|
||||
public:
|
||||
DNSServer(
|
||||
std::shared_ptr<struct event_base> base,
|
||||
uint32_t local_connect_address,
|
||||
uint32_t external_connect_address,
|
||||
std::shared_ptr<const IPV4RangeSet> banned_ipv4_ranges);
|
||||
DNSServer(const DNSServer&) = delete;
|
||||
DNSServer(DNSServer&&) = delete;
|
||||
virtual ~DNSServer();
|
||||
|
||||
inline void set_banned_ipv4_ranges(std::shared_ptr<const IPV4RangeSet> banned_ipv4_ranges) {
|
||||
this->banned_ipv4_ranges = banned_ipv4_ranges;
|
||||
}
|
||||
|
||||
void listen(const std::string& socket_path);
|
||||
void listen(const std::string& addr, int port);
|
||||
void listen(int port);
|
||||
void add_socket(int fd);
|
||||
|
||||
static std::string response_for_query(const void* vdata, size_t size, uint32_t resolved_address);
|
||||
static std::string response_for_query(const std::string& query, uint32_t resolved_address);
|
||||
|
||||
private:
|
||||
std::shared_ptr<struct event_base> base;
|
||||
std::unordered_map<int, std::unique_ptr<struct event, void (*)(struct event*)>> fd_to_receive_event;
|
||||
uint32_t local_connect_address;
|
||||
uint32_t external_connect_address;
|
||||
std::shared_ptr<const IPV4RangeSet> banned_ipv4_ranges;
|
||||
|
||||
static void dispatch_on_receive_message(evutil_socket_t fd, short events, void* ctx);
|
||||
void on_receive_message(int fd, short event);
|
||||
};
|
||||
|
||||
+1120
-1120
File diff suppressed because it is too large
Load Diff
+149
-149
@@ -1,149 +1,149 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <phosg/Tools.hh>
|
||||
|
||||
#include "StaticGameData.hh"
|
||||
|
||||
enum class EnemyType {
|
||||
UNKNOWN = -1,
|
||||
NONE = 0,
|
||||
NON_ENEMY_NPC,
|
||||
AL_RAPPY,
|
||||
ASTARK,
|
||||
BA_BOOTA,
|
||||
BARBA_RAY,
|
||||
BARBAROUS_WOLF,
|
||||
BEE_L,
|
||||
BEE_R,
|
||||
BOOMA,
|
||||
BOOTA,
|
||||
BULCLAW,
|
||||
BULK,
|
||||
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);
|
||||
const std::vector<EnemyType>& enemy_types_for_rare_table_index(Episode episode, uint8_t rt_index);
|
||||
bool enemy_type_is_rare(EnemyType type);
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <phosg/Tools.hh>
|
||||
|
||||
#include "StaticGameData.hh"
|
||||
|
||||
enum class EnemyType {
|
||||
UNKNOWN = -1,
|
||||
NONE = 0,
|
||||
NON_ENEMY_NPC,
|
||||
AL_RAPPY,
|
||||
ASTARK,
|
||||
BA_BOOTA,
|
||||
BARBA_RAY,
|
||||
BARBAROUS_WOLF,
|
||||
BEE_L,
|
||||
BEE_R,
|
||||
BOOMA,
|
||||
BOOTA,
|
||||
BULCLAW,
|
||||
BULK,
|
||||
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);
|
||||
const std::vector<EnemyType>& enemy_types_for_rare_table_index(Episode episode, uint8_t rt_index);
|
||||
bool enemy_type_is_rare(EnemyType type);
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Episode3 {
|
||||
void BattleRecord::PlayerEntry::print(FILE* stream) const {
|
||||
// TODO: Format this nicely somehow. Maybe factor out the functions in
|
||||
// QuestScript that format some of these structures
|
||||
print_data(stream, this, sizeof(this));
|
||||
print_data(stream, this, sizeof(*this), 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::DISABLE_COLOR | PrintDataFlags::OFFSET_16_BITS);
|
||||
}
|
||||
|
||||
BattleRecord::Event::Event(StringReader& r) {
|
||||
@@ -96,29 +96,30 @@ void BattleRecord::Event::print(FILE* stream) const {
|
||||
for (const auto& player : this->players) {
|
||||
fprintf(stream, " %02" PRIX32, player.lobby_data.client_id.load());
|
||||
}
|
||||
fputc('\n', stream);
|
||||
for (const auto& player : this->players) {
|
||||
player.print(stream);
|
||||
}
|
||||
break;
|
||||
case Type::BATTLE_COMMAND:
|
||||
fprintf(stream, "BATTLE_COMMAND\n");
|
||||
print_data(stream, this->data);
|
||||
print_data(stream, this->data, 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::DISABLE_COLOR | PrintDataFlags::OFFSET_16_BITS);
|
||||
break;
|
||||
case Type::GAME_COMMAND:
|
||||
fprintf(stream, "GAME_COMMAND\n");
|
||||
print_data(stream, this->data);
|
||||
print_data(stream, this->data, 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::DISABLE_COLOR | PrintDataFlags::OFFSET_16_BITS);
|
||||
break;
|
||||
case Type::EP3_GAME_COMMAND:
|
||||
fprintf(stream, "EP3_GAME_COMMAND\n");
|
||||
print_data(stream, this->data);
|
||||
print_data(stream, this->data, 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::DISABLE_COLOR | PrintDataFlags::OFFSET_16_BITS);
|
||||
break;
|
||||
case Type::CHAT_MESSAGE:
|
||||
fprintf(stream, "CHAT_MESSAGE %08" PRIX32 "\n", this->guild_card_number);
|
||||
print_data(stream, this->data);
|
||||
print_data(stream, this->data, 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::DISABLE_COLOR | PrintDataFlags::OFFSET_16_BITS);
|
||||
break;
|
||||
case Type::SERVER_DATA_COMMAND:
|
||||
fprintf(stream, "SERVER_DATA_COMMAND\n");
|
||||
print_data(stream, this->data);
|
||||
print_data(stream, this->data, 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::DISABLE_COLOR | PrintDataFlags::OFFSET_16_BITS);
|
||||
break;
|
||||
default:
|
||||
throw runtime_error("unknown event type in battle record");
|
||||
@@ -255,6 +256,20 @@ void BattleRecord::add_random_data(const void* data, size_t size) {
|
||||
this->random_stream.append(reinterpret_cast<const char*>(data), size);
|
||||
}
|
||||
|
||||
vector<string> BattleRecord::get_all_server_data_commands() const {
|
||||
vector<string> ret;
|
||||
for (const auto& event : this->events) {
|
||||
if (event.type == Event::Type::SERVER_DATA_COMMAND) {
|
||||
ret.emplace_back(event.data);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
const string& BattleRecord::get_random_stream() const {
|
||||
return this->random_stream;
|
||||
}
|
||||
|
||||
bool BattleRecord::is_map_definition_event(const Event& ev) {
|
||||
if (ev.type == Event::Type::BATTLE_COMMAND) {
|
||||
auto& header = check_size_t<G_CardBattleCommandHeader>(ev.data, 0xFFFF);
|
||||
@@ -331,7 +346,7 @@ void BattleRecord::set_battle_start_timestamp() {
|
||||
}
|
||||
}
|
||||
for (; it != this->events.end(); it++) {
|
||||
if (it->type == Event::Type::BATTLE_COMMAND) {
|
||||
if ((it->type == Event::Type::BATTLE_COMMAND) || (it->type == Event::Type::SERVER_DATA_COMMAND)) {
|
||||
new_events.emplace_back(std::move(*it));
|
||||
}
|
||||
}
|
||||
@@ -373,7 +388,7 @@ shared_ptr<const BattleRecord> BattleRecordPlayer::get_record() const {
|
||||
return this->record;
|
||||
}
|
||||
|
||||
void BattleRecordPlayer::set_lobby(std::shared_ptr<Lobby> l) {
|
||||
void BattleRecordPlayer::set_lobby(shared_ptr<Lobby> l) {
|
||||
this->lobby = l;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +86,9 @@ public:
|
||||
|
||||
void print(FILE* stream) const;
|
||||
|
||||
std::vector<std::string> get_all_server_data_commands() const;
|
||||
const std::string& get_random_stream() const;
|
||||
|
||||
private:
|
||||
static constexpr uint64_t SIGNATURE_V1 = 0x14C946D56D1DAC50;
|
||||
static constexpr uint64_t SIGNATURE_V2 = 0xD01E5EC12853C377;
|
||||
|
||||
+26
-28
@@ -396,8 +396,8 @@ int16_t Card::compute_defense_power_for_attacker_card(shared_ptr<const Card> att
|
||||
}
|
||||
}
|
||||
|
||||
s->card_special->apply_action_conditions(3, attacker_card, this->shared_from_this(), 0x08, nullptr);
|
||||
s->card_special->apply_action_conditions(3, attacker_card, this->shared_from_this(), 0x10, nullptr);
|
||||
s->card_special->apply_action_conditions(EffectWhen::BEFORE_ANY_CARD_ATTACK, attacker_card, this->shared_from_this(), 0x08, nullptr);
|
||||
s->card_special->apply_action_conditions(EffectWhen::BEFORE_ANY_CARD_ATTACK, attacker_card, this->shared_from_this(), 0x10, nullptr);
|
||||
return this->action_metadata.defense_power + this->action_metadata.defense_bonus;
|
||||
}
|
||||
|
||||
@@ -982,7 +982,7 @@ void Card::compute_action_chain_results(bool apply_action_conditions, bool ignor
|
||||
|
||||
if (apply_action_conditions) {
|
||||
auto this_sh = this->shared_from_this();
|
||||
s->card_special->apply_action_conditions(3, this_sh, this_sh, 1, nullptr);
|
||||
s->card_special->apply_action_conditions(EffectWhen::BEFORE_ANY_CARD_ATTACK, this_sh, this_sh, 1, nullptr);
|
||||
log.debug("applied action conditions (1)");
|
||||
} else {
|
||||
log.debug("skipped applying action conditions (1)");
|
||||
@@ -1120,7 +1120,7 @@ void Card::compute_action_chain_results(bool apply_action_conditions, bool ignor
|
||||
|
||||
if (apply_action_conditions) {
|
||||
auto this_sh = this->shared_from_this();
|
||||
s->card_special->apply_action_conditions(0x03, this_sh, this_sh, 2, nullptr);
|
||||
s->card_special->apply_action_conditions(EffectWhen::BEFORE_ANY_CARD_ATTACK, this_sh, this_sh, 2, nullptr);
|
||||
log.debug("applied action conditions (2)");
|
||||
if (!is_nte && this->action_chain.check_flag(0x100)) {
|
||||
this->action_chain.chain.damage = min<int16_t>(this->action_chain.chain.damage + 5, 99);
|
||||
@@ -1171,7 +1171,7 @@ void Card::unknown_80237F98(bool require_condition_20_or_21) {
|
||||
for (ssize_t z = 8; z >= 0; z--) {
|
||||
if (this->action_chain.conditions[z].type != ConditionType::NONE) {
|
||||
if (!require_condition_20_or_21 ||
|
||||
s->card_special->condition_has_when_20_or_21(this->action_chain.conditions[z])) {
|
||||
s->card_special->condition_applies_on_sc_or_item_attack(this->action_chain.conditions[z])) {
|
||||
ActionState as;
|
||||
auto& cond = this->action_chain.conditions[z];
|
||||
if (!s->card_special->is_card_targeted_by_condition(cond, as, this->shared_from_this())) {
|
||||
@@ -1219,7 +1219,9 @@ void Card::move_phase_before() {
|
||||
}
|
||||
|
||||
void Card::unknown_80236374(shared_ptr<Card> other_card, const ActionState* as) {
|
||||
auto log = this->server()->log_stack(string_printf("unknown_80236374(@%04hX #%04hX, @%04hX #%04hX): ", this->get_card_ref(), this->get_card_id(), other_card->get_card_ref(), other_card->get_card_id()));
|
||||
auto s = this->server();
|
||||
auto log = s->log_stack(string_printf("unknown_80236374(@%04hX #%04hX, @%04hX #%04hX): ", this->get_card_ref(), this->get_card_id(), other_card->get_card_ref(), other_card->get_card_id()));
|
||||
|
||||
auto check_card = [&](shared_ptr<Card> card) -> void {
|
||||
if (card) {
|
||||
if (!card->unknown_80236554(other_card, as)) {
|
||||
@@ -1231,25 +1233,21 @@ void Card::unknown_80236374(shared_ptr<Card> other_card, const ActionState* as)
|
||||
};
|
||||
|
||||
for (size_t client_id = 0; client_id < 4; client_id++) {
|
||||
auto ps = this->server()->player_states[client_id];
|
||||
if (ps) {
|
||||
if (this->server()->get_current_team_turn2() != ps->get_team_id()) {
|
||||
check_card(ps->get_sc_card());
|
||||
for (size_t set_index = 0; set_index < 8; set_index++) {
|
||||
check_card(ps->get_set_card(set_index));
|
||||
}
|
||||
auto ps = s->player_states[client_id];
|
||||
if (ps && (s->get_current_team_turn2() != ps->get_team_id())) {
|
||||
check_card(ps->get_sc_card());
|
||||
for (size_t set_index = 0; set_index < 8; set_index++) {
|
||||
check_card(ps->get_set_card(set_index));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t client_id = 0; client_id < 4; client_id++) {
|
||||
auto ps = this->server()->player_states[client_id];
|
||||
if (ps) {
|
||||
if (this->server()->get_current_team_turn2() == ps->get_team_id()) {
|
||||
check_card(ps->get_sc_card());
|
||||
for (size_t set_index = 0; set_index < 8; set_index++) {
|
||||
check_card(ps->get_set_card(set_index));
|
||||
}
|
||||
auto ps = s->player_states[client_id];
|
||||
if (ps && (s->get_current_team_turn2() == ps->get_team_id())) {
|
||||
check_card(ps->get_sc_card());
|
||||
for (size_t set_index = 0; set_index < 8; set_index++) {
|
||||
check_card(ps->get_set_card(set_index));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1404,8 +1402,8 @@ bool Card::unknown_80236554(shared_ptr<Card> other_card, const ActionState* as)
|
||||
log.debug("last attack damage stats cleared");
|
||||
|
||||
if (other_card) {
|
||||
s->card_special->apply_action_conditions(0x03, other_card, this->shared_from_this(), 0x20, as);
|
||||
s->card_special->apply_action_conditions(0x17, other_card, this->shared_from_this(), 0x40, as);
|
||||
s->card_special->apply_action_conditions(EffectWhen::BEFORE_ANY_CARD_ATTACK, other_card, this->shared_from_this(), 0x20, as);
|
||||
s->card_special->apply_action_conditions(EffectWhen::BEFORE_THIS_CARD_ATTACKED, other_card, this->shared_from_this(), 0x40, as);
|
||||
if (other_card->action_chain.check_flag(0x20000)) {
|
||||
this->action_metadata.attack_bonus = 0;
|
||||
return ret;
|
||||
@@ -1520,7 +1518,7 @@ void Card::apply_attack_result() {
|
||||
|
||||
this->compute_action_chain_results(true, false);
|
||||
if (!this->action_chain.check_flag(0x40)) {
|
||||
s->card_special->unknown_8024997C(this->shared_from_this());
|
||||
s->card_special->apply_effects_before_attack(this->shared_from_this());
|
||||
}
|
||||
|
||||
this->compute_action_chain_results(true, false);
|
||||
@@ -1560,21 +1558,21 @@ void Card::apply_attack_result() {
|
||||
}
|
||||
}
|
||||
|
||||
this->compute_action_chain_results(1, 0);
|
||||
this->compute_action_chain_results(true, false);
|
||||
if (!this->action_chain.check_flag(0x40)) {
|
||||
s->card_special->unknown_8024997C(this->shared_from_this());
|
||||
s->card_special->apply_effects_before_attack(this->shared_from_this());
|
||||
}
|
||||
if (!(this->card_flags & 2)) {
|
||||
this->compute_action_chain_results(1, 0);
|
||||
this->compute_action_chain_results(true, false);
|
||||
s->card_special->check_for_attack_interference(this->shared_from_this());
|
||||
}
|
||||
this->compute_action_chain_results(1, 0);
|
||||
this->compute_action_chain_results(true, false);
|
||||
this->unknown_80236374(this->shared_from_this(), nullptr);
|
||||
this->unknown_802362D8(this->shared_from_this());
|
||||
}
|
||||
|
||||
if (!this->action_chain.check_flag(0x40)) {
|
||||
s->card_special->unknown_8024A394(this->shared_from_this());
|
||||
s->card_special->apply_effects_after_attack(this->shared_from_this());
|
||||
}
|
||||
ps->stats.num_attacks_given++;
|
||||
|
||||
|
||||
+115
-97
@@ -79,7 +79,7 @@ void CardSpecial::AttackEnvStats::clear() {
|
||||
this->target_attack_bonus = 0;
|
||||
this->last_attack_preliminary_damage = 0;
|
||||
this->last_attack_damage = 0;
|
||||
this->total_last_attack_damage = 0;
|
||||
this->final_last_attack_damage = 0;
|
||||
this->last_attack_damage_count = 0;
|
||||
this->target_current_hp = 0;
|
||||
}
|
||||
@@ -107,7 +107,7 @@ void CardSpecial::AttackEnvStats::print(FILE* stream) const {
|
||||
fprintf(stream, "(ef) non_target_team_num_set_cards = %" PRIu32 "\n", this->non_target_team_num_set_cards);
|
||||
fprintf(stream, "(ehp) target_current_hp = %" PRIu32 "\n", this->target_current_hp);
|
||||
fprintf(stream, "(f) num_set_cards = %" PRIu32 "\n", this->num_set_cards);
|
||||
fprintf(stream, "(fdm) total_last_attack_damage = %" PRIu32 "\n", this->total_last_attack_damage);
|
||||
fprintf(stream, "(fdm) final_last_attack_damage = %" PRIu32 "\n", this->final_last_attack_damage);
|
||||
fprintf(stream, "(ff) target_team_num_set_cards = %" PRIu32 "\n", this->target_team_num_set_cards);
|
||||
fprintf(stream, "(gn) num_gun_type_items = %" PRIu32 "\n", this->num_gun_type_items);
|
||||
fprintf(stream, "(hf) num_item_or_creature_cards_in_hand = %" PRIu32 "\n", this->num_item_or_creature_cards_in_hand);
|
||||
@@ -239,7 +239,7 @@ void CardSpecial::adjust_dice_boost_if_team_has_condition_52(
|
||||
}
|
||||
|
||||
void CardSpecial::apply_action_conditions(
|
||||
uint8_t when,
|
||||
EffectWhen when,
|
||||
shared_ptr<const Card> attacker_card,
|
||||
shared_ptr<Card> defender_card,
|
||||
uint32_t flags,
|
||||
@@ -252,8 +252,7 @@ void CardSpecial::apply_action_conditions(
|
||||
temp_as = *as;
|
||||
}
|
||||
} else {
|
||||
temp_as = this->create_defense_state_for_card_pair_action_chains(
|
||||
attacker_card, defender_card);
|
||||
temp_as = this->create_defense_state_for_card_pair_action_chains(attacker_card, defender_card);
|
||||
}
|
||||
|
||||
this->apply_defense_conditions(temp_as, when, defender_card, flags);
|
||||
@@ -291,7 +290,7 @@ bool CardSpecial::apply_attribute_guard_if_possible(
|
||||
}
|
||||
|
||||
bool CardSpecial::apply_defense_condition(
|
||||
uint8_t when,
|
||||
EffectWhen when,
|
||||
Condition* defender_cond,
|
||||
uint8_t cond_index,
|
||||
const ActionState& defense_state,
|
||||
@@ -328,7 +327,7 @@ bool CardSpecial::apply_defense_condition(
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((when == 0x02) && (defender_cond->type == ConditionType::GUOM) && (flags & 4)) {
|
||||
if ((when == EffectWhen::AFTER_ANY_CARD_ATTACK) && (defender_cond->type == ConditionType::GUOM) && (flags & 4)) {
|
||||
CardShortStatus stat = defender_card->get_short_status();
|
||||
if (stat.card_flags & 4) {
|
||||
G_ApplyConditionEffect_Ep3_6xB4x06 cmd;
|
||||
@@ -347,7 +346,7 @@ bool CardSpecial::apply_defense_condition(
|
||||
|
||||
if (s->options.is_nte()) {
|
||||
auto defender_ps = defender_card->player_state();
|
||||
if ((when == 0x0F) && (flags & 4) && (defender_cond->type == ConditionType::DROP) && defender_ps) {
|
||||
if ((when == EffectWhen::BEFORE_DRAW_PHASE) && (flags & 4) && (defender_cond->type == ConditionType::DROP) && defender_ps) {
|
||||
auto defender_sc_card = defender_ps->get_sc_card();
|
||||
uint8_t defender_team_id = defender_ps->get_team_id();
|
||||
if (defender_sc_card && s->team_exp[defender_team_id]) {
|
||||
@@ -364,7 +363,7 @@ bool CardSpecial::apply_defense_condition(
|
||||
}
|
||||
}
|
||||
|
||||
if ((when == 0x04) && (flags & 4) && !defender_has_ability_trap && (defender_cond->type == ConditionType::ACID)) {
|
||||
if ((when == EffectWhen::BEFORE_DICE_PHASE_THIS_TEAM_TURN) && (flags & 4) && !defender_has_ability_trap && (defender_cond->type == ConditionType::ACID)) {
|
||||
int16_t hp = defender_card->get_current_hp();
|
||||
if (hp > 0) {
|
||||
this->send_6xB4x06_for_stat_delta(defender_card, defender_cond->card_ref, 0x20, -1, 0, 1);
|
||||
@@ -418,12 +417,11 @@ bool CardSpecial::apply_defense_condition(
|
||||
|
||||
bool CardSpecial::apply_defense_conditions(
|
||||
const ActionState& as,
|
||||
uint8_t when,
|
||||
EffectWhen when,
|
||||
shared_ptr<Card> defender_card,
|
||||
uint32_t flags) {
|
||||
for (size_t z = 0; z < 9; z++) {
|
||||
this->apply_defense_condition(
|
||||
when, &defender_card->action_chain.conditions[z], z, as, defender_card, flags, 0);
|
||||
this->apply_defense_condition(when, &defender_card->action_chain.conditions[z], z, as, defender_card, flags, 0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -812,7 +810,7 @@ CardSpecial::AttackEnvStats CardSpecial::compute_attack_env_stats(
|
||||
int32_t total_last_attack_damage = 0;
|
||||
size_t last_attack_damage_count = 0;
|
||||
this->sum_last_attack_damage(nullptr, &total_last_attack_damage, &last_attack_damage_count);
|
||||
ast.total_last_attack_damage = total_last_attack_damage;
|
||||
ast.final_last_attack_damage = total_last_attack_damage;
|
||||
ast.last_attack_damage_count = last_attack_damage_count;
|
||||
|
||||
if (!target_card) {
|
||||
@@ -1238,13 +1236,14 @@ void CardSpecial::compute_team_dice_bonus(uint8_t team_id) {
|
||||
s->team_dice_bonus[team_id] = min<uint8_t>(value, 8);
|
||||
}
|
||||
|
||||
bool CardSpecial::condition_has_when_20_or_21(const Condition& cond) const {
|
||||
bool CardSpecial::condition_applies_on_sc_or_item_attack(const Condition& cond) const {
|
||||
auto ce = this->server()->definition_for_card_ref(cond.card_ref);
|
||||
if (!ce) {
|
||||
return false;
|
||||
}
|
||||
uint8_t when = ce->def.effects[cond.card_definition_effect_index].when;
|
||||
return ((when == 0x20) || (when == 0x21));
|
||||
EffectWhen when = ce->def.effects[cond.card_definition_effect_index].when;
|
||||
return ((when == EffectWhen::AFTER_CREATURE_OR_HUNTER_SC_ATTACK) ||
|
||||
(when == EffectWhen::BEFORE_CREATURE_OR_HUNTER_SC_ATTACK));
|
||||
}
|
||||
|
||||
size_t CardSpecial::count_action_cards_with_condition_for_all_current_attacks(
|
||||
@@ -1410,7 +1409,7 @@ bool CardSpecial::evaluate_effect_arg2_condition(
|
||||
uint16_t set_card_ref,
|
||||
uint16_t sc_card_ref,
|
||||
uint8_t random_percent,
|
||||
uint8_t when) const {
|
||||
EffectWhen when) const {
|
||||
// Note: In the original code, as and dice_roll were optional pointers, but
|
||||
// they are non-null at all callsites, so we've replaced them with references
|
||||
// (and eliminated the null checks within this function).
|
||||
@@ -1650,7 +1649,7 @@ bool CardSpecial::evaluate_effect_arg2_condition(
|
||||
// or comment it appropriately.
|
||||
if (is_nte) {
|
||||
return (v < set_card->unknown_a9);
|
||||
} else if (when == 4) {
|
||||
} else if (when == EffectWhen::BEFORE_DICE_PHASE_THIS_TEAM_TURN) {
|
||||
uint32_t y = set_card->unknown_a9 & 0xFFFFFFFE;
|
||||
if ((set_card->unknown_a9 > 0) &&
|
||||
(y == (y / (v & 0xFFFFFFFE)) * (v & 0xFFFFFFFE))) {
|
||||
@@ -3519,7 +3518,7 @@ void CardSpecial::on_card_set(shared_ptr<PlayerState> ps, uint16_t card_ref) {
|
||||
uint16_t sc_card_ref = sc_card ? sc_card->get_card_ref() : 0xFFFF;
|
||||
|
||||
ActionState as;
|
||||
this->evaluate_and_apply_effects(0x01, card_ref, as, sc_card_ref);
|
||||
this->evaluate_and_apply_effects(EffectWhen::CARD_SET, card_ref, as, sc_card_ref);
|
||||
}
|
||||
|
||||
const CardDefinition::Effect* CardSpecial::original_definition_for_condition(const Condition& cond) const {
|
||||
@@ -3827,7 +3826,7 @@ int16_t CardSpecial::max_all_attack_bonuses(size_t* out_count) const {
|
||||
return max_attack_bonus;
|
||||
}
|
||||
|
||||
void CardSpecial::unknown_80244AA8(shared_ptr<Card> card) {
|
||||
void CardSpecial::apply_effects_after_card_move(shared_ptr<Card> card) {
|
||||
ActionState as = this->create_attack_state_from_card_action_chain(card);
|
||||
|
||||
bool is_nte = this->server()->options.is_nte();
|
||||
@@ -3847,12 +3846,12 @@ void CardSpecial::unknown_80244AA8(shared_ptr<Card> card) {
|
||||
}
|
||||
}
|
||||
}
|
||||
this->apply_defense_conditions(as, 0x27, card, 0x04);
|
||||
this->evaluate_and_apply_effects(0x27, card->get_card_ref(), as, 0xFFFF);
|
||||
this->apply_defense_conditions(as, EffectWhen::BEFORE_MOVE_PHASE_AND_AFTER_CARD_MOVE_FINAL, card, 0x04);
|
||||
this->evaluate_and_apply_effects(EffectWhen::BEFORE_MOVE_PHASE_AND_AFTER_CARD_MOVE_FINAL, card->get_card_ref(), as, 0xFFFF);
|
||||
}
|
||||
|
||||
this->apply_defense_conditions(as, 0x13, card, is_nte ? 0x1F : 0x04);
|
||||
this->evaluate_and_apply_effects(0x13, card->get_card_ref(), as, 0xFFFF);
|
||||
this->apply_defense_conditions(as, EffectWhen::AFTER_CARD_MOVE, card, is_nte ? 0x1F : 0x04);
|
||||
this->evaluate_and_apply_effects(EffectWhen::AFTER_CARD_MOVE, card->get_card_ref(), as, 0xFFFF);
|
||||
}
|
||||
|
||||
void CardSpecial::check_for_defense_interference(
|
||||
@@ -3938,20 +3937,20 @@ void CardSpecial::check_for_defense_interference(
|
||||
}
|
||||
|
||||
void CardSpecial::evaluate_and_apply_effects(
|
||||
uint8_t when,
|
||||
EffectWhen when,
|
||||
uint16_t set_card_ref,
|
||||
const ActionState& as,
|
||||
uint16_t sc_card_ref,
|
||||
bool apply_defense_condition_to_all_cards,
|
||||
uint16_t apply_defense_condition_to_card_ref) {
|
||||
auto s = this->server();
|
||||
auto log = s->log_stack(string_printf("evaluate_and_apply_effects(%02hhX, @%04hX, @%04hX): ", when, set_card_ref, sc_card_ref));
|
||||
auto log = s->log_stack(string_printf("evaluate_and_apply_effects(%s, @%04hX, @%04hX): ", name_for_enum(when), set_card_ref, sc_card_ref));
|
||||
bool is_nte = s->options.is_nte();
|
||||
|
||||
{
|
||||
string as_str = as.str(s);
|
||||
log.debug("when=%02hhX, set_card_ref=@%04hX, as=%s, sc_card_ref=@%04hX, apply_defense_condition_to_all_cards=%s, apply_defense_condition_to_card_ref=@%04hX",
|
||||
when, set_card_ref, as_str.c_str(), sc_card_ref, apply_defense_condition_to_all_cards ? "true" : "false", apply_defense_condition_to_card_ref);
|
||||
log.debug("when=%s, set_card_ref=@%04hX, as=%s, sc_card_ref=@%04hX, apply_defense_condition_to_all_cards=%s, apply_defense_condition_to_card_ref=@%04hX",
|
||||
name_for_enum(when), set_card_ref, as_str.c_str(), sc_card_ref, apply_defense_condition_to_all_cards ? "true" : "false", apply_defense_condition_to_card_ref);
|
||||
}
|
||||
|
||||
if (!is_nte) {
|
||||
@@ -4016,7 +4015,7 @@ void CardSpecial::evaluate_and_apply_effects(
|
||||
string card_effect_str = card_effect.str();
|
||||
effect_log.debug("effect: %s", card_effect_str.c_str());
|
||||
if (card_effect.when != when) {
|
||||
effect_log.debug("does not apply (effect.when=%02hhX, when=%02" PRIX32 ")", card_effect.when, when);
|
||||
effect_log.debug("does not apply (effect.when=%s, when=%s)", name_for_enum(card_effect.when), name_for_enum(when));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -4428,10 +4427,10 @@ void CardSpecial::on_card_destroyed(
|
||||
attacker_card, destroyed_card);
|
||||
|
||||
uint16_t destroyed_card_ref = destroyed_card->get_card_ref();
|
||||
this->evaluate_and_apply_effects(0x05, destroyed_card_ref, defense_as, 0xFFFF);
|
||||
this->evaluate_and_apply_effects(EffectWhen::CARD_DESTROYED, destroyed_card_ref, defense_as, 0xFFFF);
|
||||
for (size_t z = 0; (z < 8) && (defense_as.action_card_refs[z] != 0xFFFF); z++) {
|
||||
this->evaluate_and_apply_effects(
|
||||
0x05, defense_as.action_card_refs[z], defense_as, destroyed_card->get_card_ref());
|
||||
EffectWhen::CARD_DESTROYED, defense_as.action_card_refs[z], defense_as, destroyed_card->get_card_ref());
|
||||
}
|
||||
|
||||
if (attacker_card) {
|
||||
@@ -4673,9 +4672,9 @@ vector<shared_ptr<const Card>> CardSpecial::filter_cards_by_range(
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CardSpecial::unknown_8024AAB8(const ActionState& as) {
|
||||
void CardSpecial::apply_effects_after_attack_target_resolution(const ActionState& as) {
|
||||
auto s = this->server();
|
||||
auto log = s->log_stack("unknown_8024AAB8: ");
|
||||
auto log = s->log_stack("apply_effects_after_attack_target_resolution: ");
|
||||
string as_str = as.str(s);
|
||||
log.debug("as=%s", as_str.c_str());
|
||||
|
||||
@@ -4687,31 +4686,37 @@ void CardSpecial::unknown_8024AAB8(const ActionState& as) {
|
||||
|
||||
if (this->send_6xB4x06_if_card_ref_invalid(as.original_attacker_card_ref, 0x1F) == 0xFFFF) {
|
||||
this->evaluate_and_apply_effects(
|
||||
0x01, as.action_card_refs[z], as, this->send_6xB4x06_if_card_ref_invalid(as.attacker_card_ref, 0x21));
|
||||
EffectWhen::CARD_SET,
|
||||
as.action_card_refs[z],
|
||||
as,
|
||||
this->send_6xB4x06_if_card_ref_invalid(as.attacker_card_ref, 0x21));
|
||||
this->evaluate_and_apply_effects(
|
||||
0x0B, as.action_card_refs[z], as, this->send_6xB4x06_if_card_ref_invalid(as.attacker_card_ref, 0x22));
|
||||
EffectWhen::AFTER_ATTACK_TARGET_RESOLUTION,
|
||||
as.action_card_refs[z],
|
||||
as,
|
||||
this->send_6xB4x06_if_card_ref_invalid(as.attacker_card_ref, 0x22));
|
||||
} else {
|
||||
uint16_t card_ref = this->send_6xB4x06_if_card_ref_invalid(as.target_card_refs[0], 0x20);
|
||||
if (card_ref != 0xFFFF) {
|
||||
this->evaluate_and_apply_effects(0x01, as.action_card_refs[z], as, card_ref);
|
||||
this->evaluate_and_apply_effects(0x15, as.action_card_refs[z], as, card_ref);
|
||||
this->evaluate_and_apply_effects(EffectWhen::CARD_SET, as.action_card_refs[z], as, card_ref);
|
||||
this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_15, as.action_card_refs[z], as, card_ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (as.original_attacker_card_ref == 0xffff) {
|
||||
if (as.original_attacker_card_ref == 0xFFFF) {
|
||||
uint16_t card_ref1 = this->send_6xB4x06_if_card_ref_invalid(as.attacker_card_ref, 0x23);
|
||||
uint16_t card_ref2 = this->send_6xB4x06_if_card_ref_invalid(as.attacker_card_ref, 0x25);
|
||||
this->evaluate_and_apply_effects(0x33, card_ref2, as, card_ref1);
|
||||
this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_33, card_ref2, as, card_ref1);
|
||||
card_ref1 = this->send_6xB4x06_if_card_ref_invalid(as.attacker_card_ref, 0x24);
|
||||
card_ref2 = this->send_6xB4x06_if_card_ref_invalid(as.attacker_card_ref, 0x26);
|
||||
this->evaluate_and_apply_effects(0x34, card_ref2, as, card_ref1);
|
||||
this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_34, card_ref2, as, card_ref1);
|
||||
for (size_t z = 0; (z < 4 * 9) && (as.target_card_refs[z] != 0xFFFF); z++) {
|
||||
uint16_t card_ref = this->send_6xB4x06_if_card_ref_invalid(as.action_card_refs[z], 0x27);
|
||||
if (card_ref == 0xFFFF) {
|
||||
break;
|
||||
}
|
||||
this->evaluate_and_apply_effects(0x35, as.target_card_refs[z], as, as.attacker_card_ref);
|
||||
this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_35, as.target_card_refs[z], as, as.attacker_card_ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4719,11 +4724,11 @@ void CardSpecial::unknown_8024AAB8(const ActionState& as) {
|
||||
void CardSpecial::move_phase_before_for_card(shared_ptr<Card> card) {
|
||||
bool is_nte = this->server()->options.is_nte();
|
||||
ActionState as = this->create_attack_state_from_card_action_chain(card);
|
||||
this->apply_defense_conditions(as, 0x09, card, is_nte ? 0x1F : 0x04);
|
||||
this->evaluate_and_apply_effects(0x09, card->get_card_ref(), as, 0xFFFF);
|
||||
this->apply_defense_conditions(as, EffectWhen::BEFORE_MOVE_PHASE, card, is_nte ? 0x1F : 0x04);
|
||||
this->evaluate_and_apply_effects(EffectWhen::BEFORE_MOVE_PHASE, card->get_card_ref(), as, 0xFFFF);
|
||||
if (!is_nte) {
|
||||
this->apply_defense_conditions(as, 0x27, card, 0x04);
|
||||
this->evaluate_and_apply_effects(0x27, card->get_card_ref(), as, 0xFFFF);
|
||||
this->apply_defense_conditions(as, EffectWhen::BEFORE_MOVE_PHASE_AND_AFTER_CARD_MOVE_FINAL, card, 0x04);
|
||||
this->evaluate_and_apply_effects(EffectWhen::BEFORE_MOVE_PHASE_AND_AFTER_CARD_MOVE_FINAL, card->get_card_ref(), as, 0xFFFF);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4750,19 +4755,19 @@ void CardSpecial::dice_phase_before_for_card(shared_ptr<Card> card) {
|
||||
}
|
||||
|
||||
if (!is_nte) {
|
||||
this->apply_defense_conditions(as, 0x46, card, 0x04);
|
||||
this->evaluate_and_apply_effects(0x46, card->get_card_ref(), as, sc_card_ref);
|
||||
this->apply_defense_conditions(as, EffectWhen::BEFORE_DICE_PHASE_ALL_TURNS_FINAL, card, 0x04);
|
||||
this->evaluate_and_apply_effects(EffectWhen::BEFORE_DICE_PHASE_ALL_TURNS_FINAL, card->get_card_ref(), as, sc_card_ref);
|
||||
}
|
||||
if (ps->is_team_turn()) {
|
||||
this->apply_defense_conditions(as, 0x04, card, 0x04);
|
||||
this->evaluate_and_apply_effects(0x04, card->get_card_ref(), as, sc_card_ref);
|
||||
this->apply_defense_conditions(as, EffectWhen::BEFORE_DICE_PHASE_THIS_TEAM_TURN, card, 0x04);
|
||||
this->evaluate_and_apply_effects(EffectWhen::BEFORE_DICE_PHASE_THIS_TEAM_TURN, card->get_card_ref(), as, sc_card_ref);
|
||||
}
|
||||
}
|
||||
|
||||
template <uint8_t When1, uint8_t When2>
|
||||
template <EffectWhen When1, EffectWhen When2>
|
||||
void CardSpecial::apply_effects_on_phase_change_t(shared_ptr<Card> unknown_p2, const ActionState* existing_as) {
|
||||
auto s = this->server();
|
||||
auto log = s->log_stack(string_printf("apply_effects_on_phase_change_t<%02hhX, %02hhX>(@%04hX #%04hX): ", When1, When2, unknown_p2->get_card_ref(), unknown_p2->get_card_id()));
|
||||
auto log = s->log_stack(string_printf("apply_effects_on_phase_change_t<%s, %s>(@%04hX #%04hX): ", name_for_enum(When1), name_for_enum(When2), unknown_p2->get_card_ref(), unknown_p2->get_card_id()));
|
||||
bool is_nte = s->options.is_nte();
|
||||
|
||||
ActionState as;
|
||||
@@ -4799,17 +4804,17 @@ void CardSpecial::apply_effects_on_phase_change_t(shared_ptr<Card> unknown_p2, c
|
||||
}
|
||||
|
||||
void CardSpecial::draw_phase_before_for_card(shared_ptr<Card> unknown_p2) {
|
||||
this->apply_effects_on_phase_change_t<0x0F, 0x0A>(unknown_p2);
|
||||
this->apply_effects_on_phase_change_t<EffectWhen::BEFORE_DRAW_PHASE, EffectWhen::UNKNOWN_0A>(unknown_p2);
|
||||
}
|
||||
|
||||
void CardSpecial::action_phase_before_for_card(shared_ptr<Card> unknown_p2) {
|
||||
if (unknown_p2->player_state()->is_team_turn()) {
|
||||
this->apply_effects_on_phase_change_t<0x0E, 0x0A>(unknown_p2);
|
||||
this->apply_effects_on_phase_change_t<EffectWhen::BEFORE_ACT_PHASE, EffectWhen::UNKNOWN_0A>(unknown_p2);
|
||||
}
|
||||
}
|
||||
|
||||
void CardSpecial::unknown_8024945C(shared_ptr<Card> unknown_p2, const ActionState* existing_as) {
|
||||
this->apply_effects_on_phase_change_t<0x0A, 0x0A>(unknown_p2, this->server()->options.is_nte() ? nullptr : existing_as);
|
||||
this->apply_effects_on_phase_change_t<EffectWhen::UNKNOWN_0A, EffectWhen::UNKNOWN_0A>(unknown_p2, this->server()->options.is_nte() ? nullptr : existing_as);
|
||||
}
|
||||
|
||||
void CardSpecial::unknown_8024966C(shared_ptr<Card> unknown_p2, const ActionState* existing_as) {
|
||||
@@ -4828,38 +4833,38 @@ void CardSpecial::unknown_8024966C(shared_ptr<Card> unknown_p2, const ActionStat
|
||||
auto ce = unknown_p2->get_definition();
|
||||
auto defender_card = (ce && (ce->def.type == CardType::ITEM) && card) ? card : unknown_p2;
|
||||
|
||||
this->apply_defense_conditions(as, 0x3D, unknown_p2, 4);
|
||||
this->apply_defense_conditions(as, 0x3E, unknown_p2, 4);
|
||||
this->apply_defense_conditions(as, EffectWhen::ATTACK_STAT_OVERRIDES, unknown_p2, 4);
|
||||
this->apply_defense_conditions(as, EffectWhen::ATTACK_DAMAGE_ADJUSTMENT, unknown_p2, 4);
|
||||
if (defender_card) {
|
||||
this->apply_defense_conditions(as, 0x22, defender_card, 4);
|
||||
this->apply_defense_conditions(as, EffectWhen::UNKNOWN_22, defender_card, 4);
|
||||
}
|
||||
|
||||
for (size_t z = 0; (z < 4 * 9) && (as.target_card_refs[z] != 0xFFFF); z++) {
|
||||
auto card = this->server()->card_for_set_card_ref(as.target_card_refs[z]);
|
||||
if (card) {
|
||||
ActionState defense_as = this->create_defense_state_for_card_pair_action_chains(unknown_p2, card);
|
||||
this->apply_defense_conditions(defense_as, 0x3D, card, 4);
|
||||
this->apply_defense_conditions(defense_as, 0x3F, card, 4);
|
||||
this->apply_defense_conditions(defense_as, EffectWhen::ATTACK_STAT_OVERRIDES, card, 4);
|
||||
this->apply_defense_conditions(defense_as, EffectWhen::DEFENSE_DAMAGE_ADJUSTMENT, card, 4);
|
||||
}
|
||||
}
|
||||
|
||||
this->evaluate_and_apply_effects(0x3D, unknown_p2->get_card_ref(), as, card_ref);
|
||||
this->evaluate_and_apply_effects(0x3E, unknown_p2->get_card_ref(), as, card_ref);
|
||||
this->evaluate_and_apply_effects(EffectWhen::ATTACK_STAT_OVERRIDES, unknown_p2->get_card_ref(), as, card_ref);
|
||||
this->evaluate_and_apply_effects(EffectWhen::ATTACK_DAMAGE_ADJUSTMENT, unknown_p2->get_card_ref(), as, card_ref);
|
||||
if (defender_card) {
|
||||
this->evaluate_and_apply_effects(0x22, defender_card->get_card_ref(), as, card_ref);
|
||||
this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_22, defender_card->get_card_ref(), as, card_ref);
|
||||
}
|
||||
|
||||
for (size_t z = 0; (z < 8) && (as.action_card_refs[z] != 0xFFFF); z++) {
|
||||
this->evaluate_and_apply_effects(0x3D, as.action_card_refs[z], as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(0x3E, as.action_card_refs[z], as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(EffectWhen::ATTACK_STAT_OVERRIDES, as.action_card_refs[z], as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(EffectWhen::ATTACK_DAMAGE_ADJUSTMENT, as.action_card_refs[z], as, unknown_p2->get_card_ref());
|
||||
}
|
||||
|
||||
for (size_t z = 0; (z < 4 * 9) && (as.target_card_refs[z] != 0xFFFF); z++) {
|
||||
card = this->server()->card_for_set_card_ref(as.target_card_refs[z]);
|
||||
if (card) {
|
||||
ActionState defense_as = this->create_defense_state_for_card_pair_action_chains(unknown_p2, card);
|
||||
this->evaluate_and_apply_effects(0x3D, card->get_card_ref(), defense_as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(0x3F, card->get_card_ref(), defense_as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(EffectWhen::ATTACK_STAT_OVERRIDES, card->get_card_ref(), defense_as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(EffectWhen::DEFENSE_DAMAGE_ADJUSTMENT, card->get_card_ref(), defense_as, unknown_p2->get_card_ref());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4873,11 +4878,11 @@ void CardSpecial::unknown_8024A9D8(const ActionState& pa, uint16_t action_card_r
|
||||
for (size_t z = 0; (z < 8) && (pa.action_card_refs[z] != 0xFFFF); z++) {
|
||||
if (this->server()->options.is_nte() || (action_card_ref == 0xFFFF) || (action_card_ref == pa.action_card_refs[z])) {
|
||||
if (pa.original_attacker_card_ref == 0xFFFF) {
|
||||
this->evaluate_and_apply_effects(0x29, pa.action_card_refs[z], pa, pa.attacker_card_ref);
|
||||
this->evaluate_and_apply_effects(0x2A, pa.action_card_refs[z], pa, pa.attacker_card_ref);
|
||||
this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_29, pa.action_card_refs[z], pa, pa.attacker_card_ref);
|
||||
this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_2A, pa.action_card_refs[z], pa, pa.attacker_card_ref);
|
||||
} else {
|
||||
this->evaluate_and_apply_effects(0x29, pa.action_card_refs[z], pa, pa.target_card_refs[0]);
|
||||
this->evaluate_and_apply_effects(0x2B, pa.action_card_refs[z], pa, pa.target_card_refs[0]);
|
||||
this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_29, pa.action_card_refs[z], pa, pa.target_card_refs[0]);
|
||||
this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_2B, pa.action_card_refs[z], pa, pa.target_card_refs[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4957,10 +4962,15 @@ void CardSpecial::check_for_attack_interference(shared_ptr<Card> unknown_p2) {
|
||||
this->server()->send(cmd);
|
||||
}
|
||||
|
||||
template <uint8_t When1, uint8_t When2, uint8_t When3, uint8_t When4>
|
||||
void CardSpecial::unknown_t2(shared_ptr<Card> unknown_p2) {
|
||||
template <
|
||||
EffectWhen WhenAllCards,
|
||||
EffectWhen WhenAttackerAndActionCards,
|
||||
EffectWhen WhenAttackerOrHunterSCCard,
|
||||
EffectWhen WhenTargetsAndActionCards>
|
||||
void CardSpecial::apply_effects_before_or_after_attack(shared_ptr<Card> unknown_p2) {
|
||||
auto s = this->server();
|
||||
auto log = s->log_stack(string_printf("unknown_t2<%02hhX, %02hhX, %02hhX, %02hhX>(@%04hX #%04hX): ", When1, When2, When3, When4, unknown_p2->get_card_ref(), unknown_p2->get_card_id()));
|
||||
auto log = s->log_stack(string_printf("apply_effects_before_or_after_attack<%s, %s, %s, %s>(@%04hX #%04hX): ",
|
||||
name_for_enum(WhenAllCards), name_for_enum(WhenAttackerAndActionCards), name_for_enum(WhenAttackerOrHunterSCCard), name_for_enum(WhenTargetsAndActionCards), unknown_p2->get_card_ref(), unknown_p2->get_card_id()));
|
||||
|
||||
ActionState as = this->create_attack_state_from_card_action_chain(unknown_p2);
|
||||
|
||||
@@ -4970,56 +4980,64 @@ void CardSpecial::unknown_t2(shared_ptr<Card> unknown_p2) {
|
||||
sc_card_ref = sc_card->get_card_ref();
|
||||
}
|
||||
|
||||
auto defender_card = unknown_p2;
|
||||
auto attacker_card = unknown_p2;
|
||||
if (unknown_p2->get_definition() && (unknown_p2->get_definition()->def.type == CardType::ITEM) && sc_card) {
|
||||
defender_card = sc_card;
|
||||
attacker_card = sc_card;
|
||||
}
|
||||
|
||||
uint8_t apply_defense_conditions_flags = s->options.is_nte() ? 0x1F : 0x04;
|
||||
this->apply_defense_conditions(as, When1, unknown_p2, apply_defense_conditions_flags);
|
||||
this->apply_defense_conditions(as, When2, unknown_p2, apply_defense_conditions_flags);
|
||||
if (defender_card) {
|
||||
this->apply_defense_conditions(as, When3, defender_card, apply_defense_conditions_flags);
|
||||
this->apply_defense_conditions(as, WhenAllCards, unknown_p2, apply_defense_conditions_flags);
|
||||
this->apply_defense_conditions(as, WhenAttackerAndActionCards, unknown_p2, apply_defense_conditions_flags);
|
||||
if (attacker_card) {
|
||||
this->apply_defense_conditions(as, WhenAttackerOrHunterSCCard, attacker_card, apply_defense_conditions_flags);
|
||||
}
|
||||
|
||||
for (size_t z = 0; (z < 4 * 9) && (as.target_card_refs[z] != 0xFFFF); z++) {
|
||||
auto set_card = s->card_for_set_card_ref(as.target_card_refs[z]);
|
||||
if (set_card) {
|
||||
ActionState target_as = this->create_defense_state_for_card_pair_action_chains(unknown_p2, set_card);
|
||||
this->apply_defense_conditions(target_as, When1, set_card, apply_defense_conditions_flags);
|
||||
this->apply_defense_conditions(target_as, When4, set_card, apply_defense_conditions_flags);
|
||||
this->apply_defense_conditions(target_as, WhenAllCards, set_card, apply_defense_conditions_flags);
|
||||
this->apply_defense_conditions(target_as, WhenTargetsAndActionCards, set_card, apply_defense_conditions_flags);
|
||||
}
|
||||
}
|
||||
|
||||
this->evaluate_and_apply_effects(When1, unknown_p2->get_card_ref(), as, sc_card_ref);
|
||||
this->evaluate_and_apply_effects(When2, unknown_p2->get_card_ref(), as, sc_card_ref);
|
||||
if (defender_card) {
|
||||
this->evaluate_and_apply_effects(When3, defender_card->get_card_ref(), as, sc_card_ref);
|
||||
this->evaluate_and_apply_effects(WhenAllCards, unknown_p2->get_card_ref(), as, sc_card_ref);
|
||||
this->evaluate_and_apply_effects(WhenAttackerAndActionCards, unknown_p2->get_card_ref(), as, sc_card_ref);
|
||||
if (attacker_card) {
|
||||
this->evaluate_and_apply_effects(WhenAttackerOrHunterSCCard, attacker_card->get_card_ref(), as, sc_card_ref);
|
||||
}
|
||||
for (size_t z = 0; (z < 8) && (as.action_card_refs[z] != 0xFFFF); z++) {
|
||||
this->evaluate_and_apply_effects(When1, as.action_card_refs[z], as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(When2, as.action_card_refs[z], as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(WhenAllCards, as.action_card_refs[z], as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(WhenAttackerAndActionCards, as.action_card_refs[z], as, unknown_p2->get_card_ref());
|
||||
}
|
||||
for (size_t z = 0; (z < 4 * 9) && (as.target_card_refs[z] != 0xFFFF); z++) {
|
||||
auto set_card = s->card_for_set_card_ref(as.target_card_refs[z]);
|
||||
if (set_card) {
|
||||
ActionState target_as = this->create_defense_state_for_card_pair_action_chains(unknown_p2, set_card);
|
||||
this->evaluate_and_apply_effects(When1, set_card->get_card_ref(), target_as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(When4, set_card->get_card_ref(), target_as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(WhenAllCards, set_card->get_card_ref(), target_as, unknown_p2->get_card_ref());
|
||||
this->evaluate_and_apply_effects(WhenTargetsAndActionCards, set_card->get_card_ref(), target_as, unknown_p2->get_card_ref());
|
||||
for (size_t z = 0; (z < 8) && (target_as.action_card_refs[z] != 0xFFFF); z++) {
|
||||
this->evaluate_and_apply_effects(When1, target_as.action_card_refs[z], target_as, set_card->get_card_ref());
|
||||
this->evaluate_and_apply_effects(When4, target_as.action_card_refs[z], target_as, set_card->get_card_ref());
|
||||
this->evaluate_and_apply_effects(WhenAllCards, target_as.action_card_refs[z], target_as, set_card->get_card_ref());
|
||||
this->evaluate_and_apply_effects(WhenTargetsAndActionCards, target_as.action_card_refs[z], target_as, set_card->get_card_ref());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CardSpecial::unknown_8024997C(shared_ptr<Card> card) {
|
||||
return this->unknown_t2<0x03, 0x0D, 0x21, 0x17>(card);
|
||||
void CardSpecial::apply_effects_after_attack(shared_ptr<Card> card) {
|
||||
return this->apply_effects_before_or_after_attack<
|
||||
EffectWhen::AFTER_ANY_CARD_ATTACK,
|
||||
EffectWhen::AFTER_THIS_CARD_ATTACK,
|
||||
EffectWhen::AFTER_CREATURE_OR_HUNTER_SC_ATTACK,
|
||||
EffectWhen::AFTER_THIS_CARD_ATTACKED>(card);
|
||||
}
|
||||
|
||||
void CardSpecial::unknown_8024A394(shared_ptr<Card> card) {
|
||||
return this->unknown_t2<0x02, 0x0C, 0x20, 0x16>(card);
|
||||
void CardSpecial::apply_effects_before_attack(shared_ptr<Card> card) {
|
||||
return this->apply_effects_before_or_after_attack<
|
||||
EffectWhen::BEFORE_ANY_CARD_ATTACK,
|
||||
EffectWhen::BEFORE_THIS_CARD_ATTACK,
|
||||
EffectWhen::BEFORE_CREATURE_OR_HUNTER_SC_ATTACK,
|
||||
EffectWhen::BEFORE_THIS_CARD_ATTACKED>(card);
|
||||
}
|
||||
|
||||
bool CardSpecial::client_has_atk_dice_boost_condition(uint8_t client_id) {
|
||||
@@ -5056,8 +5074,8 @@ void CardSpecial::unknown_8024A6DC(shared_ptr<Card> unknown_p2, shared_ptr<Card>
|
||||
ActionState as = this->create_defense_state_for_card_pair_action_chains(
|
||||
unknown_p2, unknown_p3);
|
||||
for (size_t z = 0; (z < 8) && (as.action_card_refs[z] != 0xFFFF); z++) {
|
||||
this->evaluate_and_apply_effects(0x01, as.action_card_refs[z], as, unknown_p3->get_card_ref());
|
||||
this->evaluate_and_apply_effects(0x15, as.action_card_refs[z], as, unknown_p3->get_card_ref());
|
||||
this->evaluate_and_apply_effects(EffectWhen::CARD_SET, as.action_card_refs[z], as, unknown_p3->get_card_ref());
|
||||
this->evaluate_and_apply_effects(EffectWhen::UNKNOWN_15, as.action_card_refs[z], as, unknown_p3->get_card_ref());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+18
-14
@@ -85,7 +85,7 @@ public:
|
||||
/* 84 */ uint32_t target_attack_bonus; // "edm" in expr
|
||||
/* 88 */ uint32_t last_attack_preliminary_damage; // "ldm" in expr
|
||||
/* 8C */ uint32_t last_attack_damage; // "rdm" in expr
|
||||
/* 90 */ uint32_t total_last_attack_damage; // "fdm" in expr
|
||||
/* 90 */ uint32_t final_last_attack_damage; // "fdm" in expr
|
||||
/* 94 */ uint32_t last_attack_damage_count; // "ndm" in expr
|
||||
/* 98 */ uint32_t target_current_hp; // "ehp" in expr
|
||||
/* 9C */
|
||||
@@ -106,7 +106,7 @@ public:
|
||||
void adjust_dice_boost_if_team_has_condition_52(
|
||||
uint8_t team_id, uint8_t* inout_dice_boost, std::shared_ptr<const Card> card);
|
||||
void apply_action_conditions(
|
||||
uint8_t when,
|
||||
EffectWhen when,
|
||||
std::shared_ptr<const Card> attacker_card,
|
||||
std::shared_ptr<Card> defender_card,
|
||||
uint32_t flags,
|
||||
@@ -118,7 +118,7 @@ public:
|
||||
uint16_t condition_giver_card_ref,
|
||||
uint16_t attacker_card_ref);
|
||||
bool apply_defense_condition(
|
||||
uint8_t when,
|
||||
EffectWhen when,
|
||||
Condition* defender_cond,
|
||||
uint8_t cond_index,
|
||||
const ActionState& defense_state,
|
||||
@@ -127,7 +127,7 @@ public:
|
||||
bool unknown_p8);
|
||||
bool apply_defense_conditions(
|
||||
const ActionState& as,
|
||||
uint8_t when,
|
||||
EffectWhen when,
|
||||
std::shared_ptr<Card> defender_card,
|
||||
uint32_t flags);
|
||||
bool apply_stat_deltas_to_all_cards_from_all_conditions_with_card_ref(
|
||||
@@ -165,7 +165,7 @@ public:
|
||||
uint16_t sc_card_ref);
|
||||
StatSwapType compute_stat_swap_type(std::shared_ptr<const Card> card) const;
|
||||
void compute_team_dice_bonus(uint8_t team_id);
|
||||
bool condition_has_when_20_or_21(const Condition& cond) const;
|
||||
bool condition_applies_on_sc_or_item_attack(const Condition& cond) const;
|
||||
size_t count_action_cards_with_condition_for_all_current_attacks(
|
||||
ConditionType cond_type, uint16_t card_ref) const;
|
||||
size_t count_action_cards_with_condition_for_current_attack(
|
||||
@@ -189,7 +189,7 @@ public:
|
||||
uint16_t set_card_ref,
|
||||
uint16_t sc_card_ref,
|
||||
uint8_t random_percent,
|
||||
uint8_t when) const;
|
||||
EffectWhen when) const;
|
||||
int32_t evaluate_effect_expr(
|
||||
const AttackEnvStats& ast,
|
||||
const char* expr,
|
||||
@@ -276,13 +276,13 @@ public:
|
||||
size_t* out_damage_count) const;
|
||||
void update_condition_orders(std::shared_ptr<Card> card);
|
||||
int16_t max_all_attack_bonuses(size_t* out_count) const;
|
||||
void unknown_80244AA8(std::shared_ptr<Card> card);
|
||||
void apply_effects_after_card_move(std::shared_ptr<Card> card);
|
||||
void check_for_defense_interference(
|
||||
std::shared_ptr<const Card> attacker_card,
|
||||
std::shared_ptr<Card> target_card,
|
||||
int16_t* inout_unknown_p4);
|
||||
void evaluate_and_apply_effects(
|
||||
uint8_t when,
|
||||
EffectWhen when,
|
||||
uint16_t set_card_ref,
|
||||
const ActionState& as,
|
||||
uint16_t sc_card_ref,
|
||||
@@ -313,10 +313,10 @@ public:
|
||||
std::shared_ptr<const Card> card1,
|
||||
const Location& card1_loc,
|
||||
std::shared_ptr<const Card> card2) const;
|
||||
void unknown_8024AAB8(const ActionState& as);
|
||||
void apply_effects_after_attack_target_resolution(const ActionState& as);
|
||||
void move_phase_before_for_card(std::shared_ptr<Card> unknown_p2);
|
||||
void dice_phase_before_for_card(std::shared_ptr<Card> card);
|
||||
template <uint8_t When1, uint8_t When2>
|
||||
template <EffectWhen When1, EffectWhen When2>
|
||||
void apply_effects_on_phase_change_t(std::shared_ptr<Card> unknown_p2, const ActionState* existing_as = nullptr);
|
||||
void draw_phase_before_for_card(std::shared_ptr<Card> unknown_p2);
|
||||
void action_phase_before_for_card(std::shared_ptr<Card> unknown_p2);
|
||||
@@ -325,10 +325,14 @@ public:
|
||||
static std::shared_ptr<Card> sc_card_for_card(std::shared_ptr<Card> unknown_p2);
|
||||
void unknown_8024A9D8(const ActionState& pa, uint16_t action_card_ref);
|
||||
void check_for_attack_interference(std::shared_ptr<Card> unknown_p2);
|
||||
template <uint8_t When1, uint8_t When2, uint8_t When3, uint8_t When4>
|
||||
void unknown_t2(std::shared_ptr<Card> unknown_p2);
|
||||
void unknown_8024997C(std::shared_ptr<Card> card);
|
||||
void unknown_8024A394(std::shared_ptr<Card> card);
|
||||
template <
|
||||
EffectWhen WhenAllCards,
|
||||
EffectWhen WhenAttackerAndActionCards,
|
||||
EffectWhen WhenAttackerOrHunterSCCard,
|
||||
EffectWhen WhenTargetsAndActionCards>
|
||||
void apply_effects_before_or_after_attack(std::shared_ptr<Card> unknown_p2);
|
||||
void apply_effects_before_attack(std::shared_ptr<Card> card);
|
||||
void apply_effects_after_attack(std::shared_ptr<Card> card);
|
||||
bool client_has_atk_dice_boost_condition(uint8_t client_id);
|
||||
void unknown_8024A6DC(
|
||||
std::shared_ptr<Card> unknown_p2, std::shared_ptr<Card> unknown_p3);
|
||||
|
||||
+88
-16
@@ -109,8 +109,8 @@ bool Location::operator!=(const Location& other) const {
|
||||
}
|
||||
|
||||
std::string Location::str() const {
|
||||
return string_printf("Location[x=%hhu, y=%hhu, dir=%s, u=%hhu]",
|
||||
this->x, this->y, name_for_enum(this->direction), this->unused);
|
||||
return string_printf("Location[x=%hhu, y=%hhu, dir=%hhu:%s, u=%hhu]",
|
||||
this->x, this->y, static_cast<uint8_t>(this->direction), name_for_enum(this->direction), this->unused);
|
||||
}
|
||||
|
||||
void Location::clear() {
|
||||
@@ -517,7 +517,7 @@ bool CardDefinition::Effect::is_empty() const {
|
||||
return (this->effect_num == 0 &&
|
||||
this->type == ConditionType::NONE &&
|
||||
this->expr.empty() &&
|
||||
this->when == 0 &&
|
||||
this->when == EffectWhen::NONE &&
|
||||
this->arg1.empty() &&
|
||||
this->arg2.empty() &&
|
||||
this->arg3.empty() &&
|
||||
@@ -603,7 +603,7 @@ string CardDefinition::Effect::str(const char* separator, const TextSet* text_ar
|
||||
if (!this->expr.empty()) {
|
||||
tokens.emplace_back("expr=" + this->expr.decode());
|
||||
}
|
||||
tokens.emplace_back(string_printf("when=%02hhX", this->when));
|
||||
tokens.emplace_back(string_printf("when=%02hhX:%s", static_cast<uint8_t>(this->when), name_for_enum(this->when)));
|
||||
tokens.emplace_back("arg1=" + this->str_for_arg(this->arg1.decode()));
|
||||
tokens.emplace_back("arg2=" + this->str_for_arg(this->arg2.decode()));
|
||||
tokens.emplace_back("arg3=" + this->str_for_arg(this->arg3.decode()));
|
||||
@@ -736,23 +736,23 @@ string name_for_rank(CardRank rank) {
|
||||
}
|
||||
}
|
||||
|
||||
string name_for_target_mode(TargetMode target_mode) {
|
||||
const char* name_for_target_mode(TargetMode target_mode) {
|
||||
static const vector<const char*> names({
|
||||
"NONE",
|
||||
"SINGLE",
|
||||
"MULTI",
|
||||
"SINGLE_RANGE",
|
||||
"MULTI_RANGE",
|
||||
"SELF",
|
||||
"TEAM",
|
||||
"EVERYONE",
|
||||
"MULTI_RANGE_ALLIES",
|
||||
"ALL_ALLIES",
|
||||
"ALL",
|
||||
"MULTI-ALLY",
|
||||
"ALL-ALLY",
|
||||
"ALL-ATTACK",
|
||||
"OWN-FCS",
|
||||
"OWN_FCS",
|
||||
});
|
||||
try {
|
||||
return names.at(static_cast<uint8_t>(target_mode));
|
||||
} catch (const out_of_range&) {
|
||||
return string_printf("(%02hhX)", static_cast<uint8_t>(target_mode));
|
||||
return "__UNKNOWN__";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -886,7 +886,7 @@ string CardDefinition::str(bool single_line, const TextSet* text_archive) const
|
||||
string criterion_str = name_for_enum(this->usable_criterion);
|
||||
string card_class_str = name_for_enum(this->card_class());
|
||||
string rank_str = name_for_rank(this->rank);
|
||||
string target_mode_str = name_for_target_mode(this->target_mode);
|
||||
const char* target_mode_str = name_for_target_mode(this->target_mode);
|
||||
string assist_turns_str = string_for_assist_turns(this->assist_turns);
|
||||
string hp_str = this->hp.str();
|
||||
string ap_str = this->ap.str();
|
||||
@@ -937,7 +937,7 @@ string CardDefinition::str(bool single_line, const TextSet* text_archive) const
|
||||
criterion_str.c_str(),
|
||||
rank_str.c_str(),
|
||||
cost_str.c_str(),
|
||||
target_mode_str.c_str(),
|
||||
target_mode_str,
|
||||
range_str.c_str(),
|
||||
assist_turns_str.c_str(),
|
||||
this->cannot_move ? "true" : "false",
|
||||
@@ -1004,7 +1004,7 @@ Card: %04" PRIX32 " \"%s\"\n\
|
||||
criterion_str.c_str(),
|
||||
rank_str.c_str(),
|
||||
cost_str.c_str(),
|
||||
target_mode_str.c_str(),
|
||||
target_mode_str,
|
||||
range_str.c_str(),
|
||||
assist_turns_str.c_str(),
|
||||
this->cannot_move ? "cannot" : "can",
|
||||
@@ -1068,7 +1068,7 @@ JSON CardDefinition::Effect::json() const {
|
||||
{"EffectNum", this->effect_num},
|
||||
{"ConditionType", name_for_enum(this->type)},
|
||||
{"Expression", this->expr.decode()},
|
||||
{"When", this->when},
|
||||
{"When", name_for_enum(this->when)},
|
||||
{"Arg1", this->arg1.decode()},
|
||||
{"Arg2", this->arg2.decode()},
|
||||
{"Arg3", this->arg3.decode()},
|
||||
@@ -3117,6 +3117,78 @@ const char* name_for_enum<Episode3::ConditionType>(Episode3::ConditionType cond_
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
const char* name_for_enum<Episode3::EffectWhen>(Episode3::EffectWhen when) {
|
||||
switch (when) {
|
||||
case Episode3::EffectWhen::NONE:
|
||||
return "NONE";
|
||||
case Episode3::EffectWhen::CARD_SET:
|
||||
return "CARD_SET";
|
||||
case Episode3::EffectWhen::AFTER_ANY_CARD_ATTACK:
|
||||
return "AFTER_ANY_CARD_ATTACK";
|
||||
case Episode3::EffectWhen::BEFORE_ANY_CARD_ATTACK:
|
||||
return "BEFORE_ANY_CARD_ATTACK";
|
||||
case Episode3::EffectWhen::BEFORE_DICE_PHASE_THIS_TEAM_TURN:
|
||||
return "BEFORE_DICE_PHASE_THIS_TEAM_TURN";
|
||||
case Episode3::EffectWhen::CARD_DESTROYED:
|
||||
return "CARD_DESTROYED";
|
||||
case Episode3::EffectWhen::AFTER_SET_PHASE:
|
||||
return "AFTER_SET_PHASE";
|
||||
case Episode3::EffectWhen::BEFORE_MOVE_PHASE:
|
||||
return "BEFORE_MOVE_PHASE";
|
||||
case Episode3::EffectWhen::UNKNOWN_0A:
|
||||
return "UNKNOWN_0A";
|
||||
case Episode3::EffectWhen::AFTER_ATTACK_TARGET_RESOLUTION:
|
||||
return "AFTER_ATTACK_TARGET_RESOLUTION";
|
||||
case Episode3::EffectWhen::AFTER_THIS_CARD_ATTACK:
|
||||
return "AFTER_THIS_CARD_ATTACK";
|
||||
case Episode3::EffectWhen::BEFORE_THIS_CARD_ATTACK:
|
||||
return "BEFORE_THIS_CARD_ATTACK";
|
||||
case Episode3::EffectWhen::BEFORE_ACT_PHASE:
|
||||
return "BEFORE_ACT_PHASE";
|
||||
case Episode3::EffectWhen::BEFORE_DRAW_PHASE:
|
||||
return "BEFORE_DRAW_PHASE";
|
||||
case Episode3::EffectWhen::AFTER_CARD_MOVE:
|
||||
return "AFTER_CARD_MOVE";
|
||||
case Episode3::EffectWhen::UNKNOWN_15:
|
||||
return "UNKNOWN_15";
|
||||
case Episode3::EffectWhen::AFTER_THIS_CARD_ATTACKED:
|
||||
return "AFTER_THIS_CARD_ATTACKED";
|
||||
case Episode3::EffectWhen::BEFORE_THIS_CARD_ATTACKED:
|
||||
return "BEFORE_THIS_CARD_ATTACKED";
|
||||
case Episode3::EffectWhen::AFTER_CREATURE_OR_HUNTER_SC_ATTACK:
|
||||
return "AFTER_CREATURE_OR_HUNTER_SC_ATTACK";
|
||||
case Episode3::EffectWhen::BEFORE_CREATURE_OR_HUNTER_SC_ATTACK:
|
||||
return "BEFORE_CREATURE_OR_HUNTER_SC_ATTACK";
|
||||
case Episode3::EffectWhen::UNKNOWN_22:
|
||||
return "UNKNOWN_22";
|
||||
case Episode3::EffectWhen::BEFORE_MOVE_PHASE_AND_AFTER_CARD_MOVE_FINAL:
|
||||
return "BEFORE_MOVE_PHASE_AND_AFTER_CARD_MOVE_FINAL";
|
||||
case Episode3::EffectWhen::UNKNOWN_29:
|
||||
return "UNKNOWN_29";
|
||||
case Episode3::EffectWhen::UNKNOWN_2A:
|
||||
return "UNKNOWN_2A";
|
||||
case Episode3::EffectWhen::UNKNOWN_2B:
|
||||
return "UNKNOWN_2B";
|
||||
case Episode3::EffectWhen::UNKNOWN_33:
|
||||
return "UNKNOWN_33";
|
||||
case Episode3::EffectWhen::UNKNOWN_34:
|
||||
return "UNKNOWN_34";
|
||||
case Episode3::EffectWhen::UNKNOWN_35:
|
||||
return "UNKNOWN_35";
|
||||
case Episode3::EffectWhen::ATTACK_STAT_OVERRIDES:
|
||||
return "ATTACK_STAT_OVERRIDES";
|
||||
case Episode3::EffectWhen::ATTACK_DAMAGE_ADJUSTMENT:
|
||||
return "ATTACK_DAMAGE_ADJUSTMENT";
|
||||
case Episode3::EffectWhen::DEFENSE_DAMAGE_ADJUSTMENT:
|
||||
return "DEFENSE_DAMAGE_ADJUSTMENT";
|
||||
case Episode3::EffectWhen::BEFORE_DICE_PHASE_ALL_TURNS_FINAL:
|
||||
return "BEFORE_DICE_PHASE_ALL_TURNS_FINAL";
|
||||
default:
|
||||
return "__INVALID__";
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
const char* name_for_enum<Episode3::Direction>(Episode3::Direction d) {
|
||||
switch (d) {
|
||||
|
||||
@@ -173,6 +173,8 @@ enum class TargetMode : uint8_t {
|
||||
OWN_FCS = 0x09, // e.g. Traitor
|
||||
};
|
||||
|
||||
const char* name_for_target_mode(TargetMode target_mode);
|
||||
|
||||
enum class ConditionType : uint8_t {
|
||||
NONE = 0x00,
|
||||
AP_BOOST = 0x01, // Temporarily increase AP by N
|
||||
@@ -304,6 +306,41 @@ enum class ConditionType : uint8_t {
|
||||
ANY_FF = 0xFF, // Used as a wildcard in some search functions
|
||||
};
|
||||
|
||||
enum class EffectWhen : uint8_t {
|
||||
NONE = 0x00,
|
||||
CARD_SET = 0x01, // Permanent effects like RAMPAGE/PIERCE on SCs, BIG_SWING, AERIAL, etc.; many AC effects also
|
||||
AFTER_ANY_CARD_ATTACK = 0x02, // GIVE_DAMAGE, HEAL, A_H_SWAP_PERM
|
||||
BEFORE_ANY_CARD_ATTACK = 0x03, // AP_LOSS, COMBO_TP
|
||||
BEFORE_DICE_PHASE_THIS_TEAM_TURN = 0x04, // Many different effects
|
||||
CARD_DESTROYED = 0x05, // RETURN_TO_HAND, RETURN, FILIAL, GIVE_OR_TAKE_EXP
|
||||
AFTER_SET_PHASE = 0x06, // Unused
|
||||
BEFORE_MOVE_PHASE = 0x09, // Unused
|
||||
UNKNOWN_0A = 0x0A, // ANTI_ABNORMALITY_2 on Tollaw (non-SC version of another when?)
|
||||
AFTER_ATTACK_TARGET_RESOLUTION = 0x0B, // ABILITY_TRAP via First Attack action card only
|
||||
AFTER_THIS_CARD_ATTACK = 0x0C, // Many effects
|
||||
BEFORE_THIS_CARD_ATTACK = 0x0D, // Conditions, AP_BOOST/TP_BOOST, AP_SILENCE, MULTI_STRIKE
|
||||
BEFORE_ACT_PHASE = 0x0E, // Before act phase (ANTI_ABNORMALITY_2, FIXED_RANGE)
|
||||
BEFORE_DRAW_PHASE = 0x0F, // Unused
|
||||
AFTER_CARD_MOVE = 0x13, // Unused
|
||||
UNKNOWN_15 = 0x15, // Unused
|
||||
AFTER_THIS_CARD_ATTACKED = 0x16, // Conditions, DEATH_COMPANION, GIVE_DAMAGE, AP_GROWTH (Nidra)
|
||||
BEFORE_THIS_CARD_ATTACKED = 0x17, // Defense damage adjustments
|
||||
AFTER_CREATURE_OR_HUNTER_SC_ATTACK = 0x20, // RETURN_TO_HAND, A_T_SWAP_PERM, GIVE_OR_TAKE_EXP
|
||||
BEFORE_CREATURE_OR_HUNTER_SC_ATTACK = 0x21, // Unused
|
||||
UNKNOWN_22 = 0x22, // MISC_AP_BONUSES (SCs only?)
|
||||
BEFORE_MOVE_PHASE_AND_AFTER_CARD_MOVE_FINAL = 0x27, // SET_MV
|
||||
UNKNOWN_29 = 0x29, // MIGHTY_KNUCKLE
|
||||
UNKNOWN_2A = 0x2A, // Unused
|
||||
UNKNOWN_2B = 0x2B, // Unused
|
||||
UNKNOWN_33 = 0x33, // DEF_DISABLE_BY_COST
|
||||
UNKNOWN_34 = 0x34, // Unused
|
||||
UNKNOWN_35 = 0x35, // Unused
|
||||
ATTACK_STAT_OVERRIDES = 0x3D, // BONUS_FROM_LEADER, COPY, ABILITY_TRAP
|
||||
ATTACK_DAMAGE_ADJUSTMENT = 0x3E, // AP_BOOST, SLAYERS_ASSASSINS, WEAK_SPOT_INFLUENCE, GROUP
|
||||
DEFENSE_DAMAGE_ADJUSTMENT = 0x3F, // MOSTLY_HALFGUARDS, ACTION_DISRUPTER
|
||||
BEFORE_DICE_PHASE_ALL_TURNS_FINAL = 0x46, // Pollux Timed Pierce
|
||||
};
|
||||
|
||||
enum class AssistEffect : uint16_t {
|
||||
NONE = 0x0000,
|
||||
DICE_HALF = 0x0001,
|
||||
@@ -486,7 +523,7 @@ struct CardDefinition {
|
||||
/* 02 */ pstring<TextEncoding::ASCII, 0x0F> expr;
|
||||
// when specifies in which phase the effect should activate.
|
||||
// TODO: There are many values that can be used here; document them.
|
||||
/* 11 */ uint8_t when;
|
||||
/* 11 */ EffectWhen when;
|
||||
// arg1 generally specifies how long the effect activates for.
|
||||
/* 12 */ pstring<TextEncoding::ASCII, 4> arg1;
|
||||
// arg2 generally specifies a condition for when the effect activates.
|
||||
@@ -1575,4 +1612,6 @@ const char* name_for_enum<Episode3::CardClass>(Episode3::CardClass cc);
|
||||
template <>
|
||||
const char* name_for_enum<Episode3::ConditionType>(Episode3::ConditionType cond_type);
|
||||
template <>
|
||||
const char* name_for_enum<Episode3::EffectWhen>(Episode3::EffectWhen when);
|
||||
template <>
|
||||
const char* name_for_enum<Episode3::Direction>(Episode3::Direction d);
|
||||
|
||||
@@ -1003,7 +1003,7 @@ bool PlayerState::move_card_to_location_by_card_index(size_t card_index, const L
|
||||
this->send_6xB4x04_if_needed();
|
||||
s->send_6xB4x05();
|
||||
s->send_6xB4x39();
|
||||
s->card_special->unknown_80244AA8(card);
|
||||
s->card_special->apply_effects_after_card_move(card);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "DataIndexes.hh"
|
||||
#include "Server.hh"
|
||||
|
||||
using namespace std;
|
||||
@@ -1469,36 +1470,52 @@ bool RulerServer::compute_effective_range_and_target_mode_for_attack(
|
||||
uint16_t* out_effective_card_id,
|
||||
TargetMode* out_effective_target_mode,
|
||||
uint16_t* out_orig_card_ref) const {
|
||||
auto s = this->server();
|
||||
bool is_nte = s->options.is_nte();
|
||||
auto log = s->log_stack("compute_effective_range_and_target_mode_for_attack: ");
|
||||
|
||||
size_t z;
|
||||
for (z = 0; (z < 8) && (pa.action_card_refs[z] != 0xFFFF); z++) {
|
||||
}
|
||||
if (z >= 8) {
|
||||
log.debug("too many action card refs");
|
||||
return false;
|
||||
}
|
||||
log.debug("%zu action card refs", z);
|
||||
uint16_t card_ref = (z == 0) ? pa.attacker_card_ref : pa.action_card_refs[z - 1];
|
||||
log.debug("base card ref = @%04hX", card_ref);
|
||||
|
||||
uint16_t card_id = this->card_id_for_card_ref(card_ref);
|
||||
if (card_id == 0xFFFF) {
|
||||
log.debug("card ref is broken");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto ce = this->definition_for_card_id(card_id);
|
||||
uint8_t client_id = client_id_for_card_ref(pa.attacker_card_ref);
|
||||
if ((client_id == 0xFF) || !ce) {
|
||||
log.debug("card ref is broken or definition is missing");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (out_orig_card_ref) {
|
||||
log.debug("orig_card_ref = @%04hX", card_ref);
|
||||
*out_orig_card_ref = card_ref;
|
||||
}
|
||||
|
||||
auto target_mode = ce->def.target_mode;
|
||||
if (this->card_ref_or_sc_has_fixed_range(pa.attacker_card_ref)) {
|
||||
const char* target_mode_name = name_for_target_mode(target_mode);
|
||||
log.debug("attacker card ref @%04hX has fixed range; target mode is %s (%hhu)",
|
||||
pa.attacker_card_ref.load(), target_mode_name, static_cast<uint8_t>(target_mode));
|
||||
card_id = this->card_id_for_card_ref(pa.attacker_card_ref);
|
||||
if (!this->server()->options.is_nte()) {
|
||||
if (!is_nte) {
|
||||
auto sc_ce = this->definition_for_card_id(card_id);
|
||||
if (sc_ce && (static_cast<uint8_t>(target_mode) < 6)) {
|
||||
target_mode = sc_ce->def.target_mode;
|
||||
const char* target_mode_name = name_for_target_mode(target_mode);
|
||||
log.debug("sc_ce overrides target mode with %s (%hhu)",
|
||||
target_mode_name, static_cast<uint8_t>(target_mode));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1508,8 +1525,10 @@ bool RulerServer::compute_effective_range_and_target_mode_for_attack(
|
||||
auto assist_effect = this->assist_server->get_active_assist_by_index(z);
|
||||
if (assist_effect == AssistEffect::SIMPLE) {
|
||||
card_id = this->card_id_for_card_ref(pa.attacker_card_ref);
|
||||
log.debug("SIMPLE assist overrides card id with #%04hX", card_id);
|
||||
} else if (assist_effect == AssistEffect::HEAVY_FOG) {
|
||||
card_id = 0xFFFE;
|
||||
log.debug("HEAVY_FOG assist overrides card id with #%04hX", card_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2040,21 +2059,27 @@ shared_ptr<const CardIndex::CardEntry> RulerServer::definition_for_card_id(uint3
|
||||
|
||||
uint32_t RulerServer::get_card_id_with_effective_range(
|
||||
uint16_t card_ref, uint16_t card_id_override, TargetMode* out_target_mode) const {
|
||||
auto log = this->server()->log_stack(string_printf("get_card_id_with_effective_range(@%04hX, #%04hX): ", card_ref, card_id_override));
|
||||
|
||||
uint16_t card_id = (card_id_override == 0xFFFF)
|
||||
? this->card_id_for_card_ref(card_ref)
|
||||
: card_id_override;
|
||||
log.debug("card_id=#%04hX", card_id);
|
||||
|
||||
if (card_id != 0xFFFF) {
|
||||
auto ce = this->definition_for_card_id(card_id);
|
||||
uint8_t client_id = client_id_for_card_ref(card_ref);
|
||||
if ((client_id != 0xFF) && ce) {
|
||||
TargetMode effective_target_mode = ce->def.target_mode;
|
||||
log.debug("ce valid for #%04hX with effective target mode %s", card_id, name_for_target_mode(effective_target_mode));
|
||||
|
||||
if (this->card_ref_or_sc_has_fixed_range(card_ref)) {
|
||||
// Undo the override that may have been passed in
|
||||
auto ce = this->definition_for_card_id(this->card_id_for_card_ref(card_ref));
|
||||
if (ce && (static_cast<uint8_t>(effective_target_mode) < 6)) {
|
||||
effective_target_mode = ce->def.target_mode;
|
||||
log.debug("@%04hX has FIXED_RANGE", card_ref);
|
||||
auto orig_ce = this->definition_for_card_id(this->card_id_for_card_ref(card_ref));
|
||||
if (orig_ce && (static_cast<uint8_t>(effective_target_mode) < 6)) {
|
||||
log.debug("ce valid for #%04hX with effective target mode %s; overriding to %s", card_id, name_for_target_mode(effective_target_mode), name_for_target_mode(orig_ce->def.target_mode));
|
||||
effective_target_mode = orig_ce->def.target_mode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2063,14 +2088,17 @@ uint32_t RulerServer::get_card_id_with_effective_range(
|
||||
auto eff = this->assist_server->get_active_assist_by_index(z);
|
||||
if (eff == AssistEffect::SIMPLE) {
|
||||
card_id = this->card_id_for_card_ref(card_ref);
|
||||
log.debug("SIMPLE assist effect is active; using #%04hX for range", card_id);
|
||||
} else if (eff == AssistEffect::HEAVY_FOG) {
|
||||
card_id = 0xFFFE;
|
||||
log.debug("HEAVY_FOG assist effect is active; limiting range to one tile in front");
|
||||
}
|
||||
}
|
||||
|
||||
if (out_target_mode) {
|
||||
*out_target_mode = effective_target_mode;
|
||||
}
|
||||
log.debug("results: card_id=#%04hX, target_mode=%s", card_id, name_for_target_mode(effective_target_mode));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-6
@@ -30,7 +30,7 @@ void Server::PresenceEntry::clear() {
|
||||
|
||||
Server::Server(shared_ptr<Lobby> lobby, Options&& options)
|
||||
: lobby(lobby),
|
||||
battle_record(lobby->battle_record),
|
||||
battle_record(lobby ? lobby->battle_record : nullptr),
|
||||
has_lobby(lobby != nullptr),
|
||||
options(std::move(options)),
|
||||
last_chosen_map(this->options.tournament ? this->options.tournament->get_map() : nullptr),
|
||||
@@ -260,7 +260,7 @@ void Server::send(const void* data, size_t size, uint8_t command, bool enable_ma
|
||||
|
||||
} else if ((this->options.behavior_flags & BehaviorFlag::LOG_COMMANDS_IF_LOBBY_MISSING) &&
|
||||
this->log().info("Generated command")) {
|
||||
print_data(stderr, data, size);
|
||||
print_data(stderr, data, size, 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::DISABLE_COLOR | PrintDataFlags::OFFSET_16_BITS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1075,7 +1075,13 @@ shared_ptr<const PlayerState> Server::get_player_state(uint8_t client_id) const
|
||||
}
|
||||
|
||||
uint32_t Server::get_random_raw() {
|
||||
le_uint32_t ret = random_from_optional_crypt(this->options.opt_rand_crypt);
|
||||
le_uint32_t ret;
|
||||
if (this->options.opt_rand_stream) {
|
||||
this->options.opt_rand_stream->readx(&ret, sizeof(ret));
|
||||
} else {
|
||||
ret = random_from_optional_crypt(this->options.opt_rand_crypt);
|
||||
}
|
||||
|
||||
if (this->battle_record && this->battle_record->writable()) {
|
||||
this->battle_record->add_random_data(&ret, sizeof(ret));
|
||||
}
|
||||
@@ -1456,12 +1462,12 @@ void Server::set_phase_after() {
|
||||
if (ps) {
|
||||
auto card = ps->get_sc_card();
|
||||
if (card) {
|
||||
this->card_special->apply_action_conditions(0x06, nullptr, card, is_nte ? 0x1F : 0x04, nullptr);
|
||||
this->card_special->apply_action_conditions(EffectWhen::AFTER_SET_PHASE, nullptr, card, is_nte ? 0x1F : 0x04, nullptr);
|
||||
}
|
||||
for (size_t set_index = 0; set_index < 8; set_index++) {
|
||||
auto card = ps->get_set_card(set_index);
|
||||
if (card) {
|
||||
this->card_special->apply_action_conditions(0x06, nullptr, card, is_nte ? 0x1F : 0x04, nullptr);
|
||||
this->card_special->apply_action_conditions(EffectWhen::AFTER_SET_PHASE, nullptr, card, is_nte ? 0x1F : 0x04, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2863,7 +2869,7 @@ void Server::unknown_8023EEF4() {
|
||||
ActionState as = cmd.state;
|
||||
this->send(cmd);
|
||||
|
||||
this->card_special->unknown_8024AAB8(as);
|
||||
this->card_special->apply_effects_after_attack_target_resolution(as);
|
||||
|
||||
if (!is_nte) {
|
||||
this->attack_cards[this->unknown_a14]->compute_action_chain_results(1, 0);
|
||||
|
||||
@@ -72,6 +72,7 @@ public:
|
||||
std::shared_ptr<const CardIndex> card_index;
|
||||
std::shared_ptr<const MapIndex> map_index;
|
||||
uint32_t behavior_flags;
|
||||
std::shared_ptr<StringReader> opt_rand_stream;
|
||||
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt;
|
||||
std::shared_ptr<const Tournament> tournament;
|
||||
std::array<std::vector<uint16_t>, 5> trap_card_ids;
|
||||
|
||||
@@ -9,8 +9,12 @@
|
||||
#include <optional>
|
||||
#include <stdexcept>
|
||||
|
||||
// Calls a function on the given base's event thread. This function returns
|
||||
// when the call has been enqueued, not necessarily after it returns.
|
||||
void forward_to_event_thread(std::shared_ptr<struct event_base> base, std::function<void()>&& fn);
|
||||
|
||||
// Calls a function on the given base's event thread and waits for it to
|
||||
// return. Returns the value returned on that thread.
|
||||
template <typename T>
|
||||
T call_on_event_thread(std::shared_ptr<struct event_base> base, std::function<T()>&& compute) {
|
||||
std::optional<T> ret;
|
||||
|
||||
+528
-523
File diff suppressed because it is too large
Load Diff
+101
-99
@@ -1,99 +1,101 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#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.
|
||||
|
||||
struct CompiledFunctionCode {
|
||||
enum class Architecture {
|
||||
UNKNOWN = 0,
|
||||
POWERPC, // GC
|
||||
X86, // PC, XB, BB
|
||||
SH4, // Dreamcast
|
||||
};
|
||||
Architecture arch;
|
||||
std::string code;
|
||||
std::vector<uint16_t> relocation_deltas;
|
||||
std::unordered_map<std::string, uint32_t> label_offsets;
|
||||
uint32_t entrypoint_offset_offset;
|
||||
std::string source_path; // Path to source file from newserv root
|
||||
std::string short_name; // Based on filename
|
||||
std::string long_name; // From .meta name directive
|
||||
std::string description; // From .meta description directive
|
||||
uint8_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>
|
||||
std::string generate_client_command_t(
|
||||
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 = "",
|
||||
uint32_t override_relocations_offset = 0) const;
|
||||
};
|
||||
|
||||
const char* name_for_architecture(CompiledFunctionCode::Architecture arch);
|
||||
|
||||
std::shared_ptr<CompiledFunctionCode> compile_function_code(
|
||||
CompiledFunctionCode::Architecture arch,
|
||||
const std::string& directory,
|
||||
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<uint8_t, std::shared_ptr<CompiledFunctionCode>> index_to_function;
|
||||
std::unordered_map<uint64_t, std::shared_ptr<CompiledFunctionCode>> menu_item_id_and_specific_version_to_patch_function;
|
||||
// Key here is e.g. "PATCHNAME-SPECIFICVERSION", with the latter in hex
|
||||
std::map<std::string, std::shared_ptr<CompiledFunctionCode>> name_and_specific_version_to_patch_function;
|
||||
|
||||
std::shared_ptr<const Menu> patch_menu(uint32_t specific_version) const;
|
||||
std::shared_ptr<const Menu> patch_switches_menu(uint32_t specific_version, const std::unordered_set<std::string>& auto_patches_enabled) const;
|
||||
bool patch_menu_empty(uint32_t specific_version) const;
|
||||
|
||||
std::shared_ptr<const CompiledFunctionCode> get_patch(const std::string& name, uint32_t specific_version) const;
|
||||
};
|
||||
|
||||
struct DOLFileIndex {
|
||||
struct File {
|
||||
uint32_t menu_item_id;
|
||||
std::string name;
|
||||
std::string data;
|
||||
bool is_compressed;
|
||||
};
|
||||
|
||||
std::vector<std::shared_ptr<File>> item_id_to_file;
|
||||
std::unordered_map<std::string, std::shared_ptr<File>> name_to_file;
|
||||
std::shared_ptr<const Menu> menu;
|
||||
|
||||
DOLFileIndex() = default;
|
||||
explicit DOLFileIndex(const std::string& directory);
|
||||
|
||||
inline bool empty() const {
|
||||
return this->name_to_file.empty() && this->item_id_to_file.empty();
|
||||
}
|
||||
};
|
||||
|
||||
uint32_t specific_version_for_gc_header_checksum(uint32_t header_checksum);
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#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.
|
||||
|
||||
struct CompiledFunctionCode {
|
||||
enum class Architecture {
|
||||
UNKNOWN = 0,
|
||||
POWERPC, // GC
|
||||
X86, // PC, XB, BB
|
||||
SH4, // Dreamcast
|
||||
};
|
||||
Architecture arch;
|
||||
std::string code;
|
||||
std::vector<uint16_t> relocation_deltas;
|
||||
std::unordered_map<std::string, uint32_t> label_offsets;
|
||||
uint32_t entrypoint_offset_offset;
|
||||
std::string source_path; // Path to source file from newserv root
|
||||
std::string short_name; // Based on filename
|
||||
std::string long_name; // From .meta name directive
|
||||
std::string description; // From .meta description directive
|
||||
uint8_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>
|
||||
std::string generate_client_command_t(
|
||||
const std::unordered_map<std::string, uint32_t>& label_writes,
|
||||
const void* suffix_data = nullptr,
|
||||
size_t suffix_size = 0,
|
||||
uint32_t override_relocations_offset = 0) const;
|
||||
std::string generate_client_command(
|
||||
const std::unordered_map<std::string, uint32_t>& label_writes = {},
|
||||
const void* suffix_data = nullptr,
|
||||
size_t suffix_size = 0,
|
||||
uint32_t override_relocations_offset = 0) const;
|
||||
};
|
||||
|
||||
const char* name_for_architecture(CompiledFunctionCode::Architecture arch);
|
||||
|
||||
std::shared_ptr<CompiledFunctionCode> compile_function_code(
|
||||
CompiledFunctionCode::Architecture arch,
|
||||
const std::string& directory,
|
||||
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<uint8_t, std::shared_ptr<CompiledFunctionCode>> index_to_function;
|
||||
std::unordered_map<uint64_t, std::shared_ptr<CompiledFunctionCode>> menu_item_id_and_specific_version_to_patch_function;
|
||||
// Key here is e.g. "PATCHNAME-SPECIFICVERSION", with the latter in hex
|
||||
std::map<std::string, std::shared_ptr<CompiledFunctionCode>> name_and_specific_version_to_patch_function;
|
||||
|
||||
std::shared_ptr<const Menu> patch_menu(uint32_t specific_version) const;
|
||||
std::shared_ptr<const Menu> patch_switches_menu(uint32_t specific_version, const std::unordered_set<std::string>& auto_patches_enabled) const;
|
||||
bool patch_menu_empty(uint32_t specific_version) const;
|
||||
|
||||
std::shared_ptr<const CompiledFunctionCode> get_patch(const std::string& name, uint32_t specific_version) const;
|
||||
};
|
||||
|
||||
struct DOLFileIndex {
|
||||
struct File {
|
||||
uint32_t menu_item_id;
|
||||
std::string name;
|
||||
std::string data;
|
||||
bool is_compressed;
|
||||
};
|
||||
|
||||
std::vector<std::shared_ptr<File>> item_id_to_file;
|
||||
std::unordered_map<std::string, std::shared_ptr<File>> name_to_file;
|
||||
std::shared_ptr<const Menu> menu;
|
||||
|
||||
DOLFileIndex() = default;
|
||||
explicit DOLFileIndex(const std::string& directory);
|
||||
|
||||
inline bool empty() const {
|
||||
return this->name_to_file.empty() && this->item_id_to_file.empty();
|
||||
}
|
||||
};
|
||||
|
||||
uint32_t specific_version_for_gc_header_checksum(uint32_t header_checksum);
|
||||
|
||||
+1031
-1023
File diff suppressed because it is too large
Load Diff
+76
-76
@@ -1,76 +1,76 @@
|
||||
#pragma once
|
||||
|
||||
#include <event2/buffer.h>
|
||||
#include <event2/event.h>
|
||||
#include <event2/http.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "ProxyServer.hh"
|
||||
#include "ServerState.hh"
|
||||
|
||||
class HTTPServer {
|
||||
public:
|
||||
HTTPServer(std::shared_ptr<ServerState> state);
|
||||
HTTPServer(const HTTPServer&) = delete;
|
||||
HTTPServer(HTTPServer&&) = delete;
|
||||
HTTPServer& operator=(const HTTPServer&) = delete;
|
||||
HTTPServer& operator=(HTTPServer&&) = delete;
|
||||
virtual ~HTTPServer() = default;
|
||||
|
||||
void listen(const std::string& socket_path);
|
||||
void listen(const std::string& addr, int port);
|
||||
void listen(int port);
|
||||
void add_socket(int fd);
|
||||
|
||||
void schedule_stop();
|
||||
void wait_for_stop();
|
||||
|
||||
protected:
|
||||
class http_error : public std::runtime_error {
|
||||
public:
|
||||
http_error(int code, const std::string& what);
|
||||
int code;
|
||||
};
|
||||
|
||||
std::shared_ptr<ServerState> state;
|
||||
std::shared_ptr<struct event_base> base;
|
||||
std::shared_ptr<struct evhttp> http;
|
||||
std::thread th;
|
||||
|
||||
void thread_fn();
|
||||
|
||||
static void dispatch_handle_request(struct evhttp_request* req, void* ctx);
|
||||
void handle_request(struct evhttp_request* req);
|
||||
|
||||
static const std::unordered_map<int, const char*> explanation_for_response_code;
|
||||
static void send_response(struct evhttp_request* req, int code, const char* content_type, struct evbuffer* b);
|
||||
static void send_response(struct evhttp_request* req, int code, const char* content_type, const char* fmt, ...);
|
||||
|
||||
static std::unordered_multimap<std::string, std::string> parse_url_params(const std::string& query);
|
||||
static std::unordered_map<std::string, std::string> parse_url_params_unique(const std::string& query);
|
||||
static const std::string& get_url_param(
|
||||
const std::unordered_multimap<std::string, std::string>& params,
|
||||
const std::string& key,
|
||||
const std::string* _default = nullptr);
|
||||
|
||||
static JSON generate_quest_json_st(std::shared_ptr<const Quest> q);
|
||||
static JSON generate_client_config_json_st(const Client::Config& config);
|
||||
static JSON generate_account_json_st(std::shared_ptr<const Account> a);
|
||||
static JSON generate_game_client_json_st(std::shared_ptr<const Client> c, std::shared_ptr<const ItemNameIndex> item_name_index);
|
||||
static JSON generate_proxy_client_json_st(std::shared_ptr<const ProxyServer::LinkedSession> ses);
|
||||
static JSON generate_lobby_json_st(std::shared_ptr<const Lobby> l, std::shared_ptr<const ItemNameIndex> item_name_index);
|
||||
JSON generate_game_server_clients_json() const;
|
||||
JSON generate_proxy_server_clients_json() const;
|
||||
JSON generate_server_info_json() const;
|
||||
JSON generate_lobbies_json() const;
|
||||
JSON generate_summary_json() const;
|
||||
JSON generate_all_json() const;
|
||||
|
||||
JSON generate_ep3_cards_json(bool trial) const;
|
||||
JSON generate_common_tables_json() const;
|
||||
JSON generate_rare_tables_json() const;
|
||||
JSON generate_rare_table_json(const std::string& table_name) const;
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <event2/buffer.h>
|
||||
#include <event2/event.h>
|
||||
#include <event2/http.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "ProxyServer.hh"
|
||||
#include "ServerState.hh"
|
||||
|
||||
class HTTPServer {
|
||||
public:
|
||||
HTTPServer(std::shared_ptr<ServerState> state);
|
||||
HTTPServer(const HTTPServer&) = delete;
|
||||
HTTPServer(HTTPServer&&) = delete;
|
||||
HTTPServer& operator=(const HTTPServer&) = delete;
|
||||
HTTPServer& operator=(HTTPServer&&) = delete;
|
||||
virtual ~HTTPServer() = default;
|
||||
|
||||
void listen(const std::string& socket_path);
|
||||
void listen(const std::string& addr, int port);
|
||||
void listen(int port);
|
||||
void add_socket(int fd);
|
||||
|
||||
void schedule_stop();
|
||||
void wait_for_stop();
|
||||
|
||||
protected:
|
||||
class http_error : public std::runtime_error {
|
||||
public:
|
||||
http_error(int code, const std::string& what);
|
||||
int code;
|
||||
};
|
||||
|
||||
std::shared_ptr<ServerState> state;
|
||||
std::shared_ptr<struct event_base> base;
|
||||
std::shared_ptr<struct evhttp> http;
|
||||
std::thread th;
|
||||
|
||||
void thread_fn();
|
||||
|
||||
static void dispatch_handle_request(struct evhttp_request* req, void* ctx);
|
||||
void handle_request(struct evhttp_request* req);
|
||||
|
||||
static const std::unordered_map<int, const char*> explanation_for_response_code;
|
||||
static void send_response(struct evhttp_request* req, int code, const char* content_type, struct evbuffer* b);
|
||||
static void send_response(struct evhttp_request* req, int code, const char* content_type, const char* fmt, ...);
|
||||
|
||||
static std::unordered_multimap<std::string, std::string> parse_url_params(const std::string& query);
|
||||
static std::unordered_map<std::string, std::string> parse_url_params_unique(const std::string& query);
|
||||
static const std::string& get_url_param(
|
||||
const std::unordered_multimap<std::string, std::string>& params,
|
||||
const std::string& key,
|
||||
const std::string* _default = nullptr);
|
||||
|
||||
static JSON generate_quest_json_st(std::shared_ptr<const Quest> q);
|
||||
static JSON generate_client_config_json_st(const Client::Config& config);
|
||||
static JSON generate_account_json_st(std::shared_ptr<const Account> a);
|
||||
static JSON generate_game_client_json_st(std::shared_ptr<const Client> c, std::shared_ptr<const ItemNameIndex> item_name_index);
|
||||
static JSON generate_proxy_client_json_st(std::shared_ptr<const ProxyServer::LinkedSession> ses);
|
||||
static JSON generate_lobby_json_st(std::shared_ptr<const Lobby> l, std::shared_ptr<const ItemNameIndex> item_name_index);
|
||||
JSON generate_game_server_clients_json() const;
|
||||
JSON generate_proxy_server_clients_json() const;
|
||||
JSON generate_server_info_json() const;
|
||||
JSON generate_lobbies_json() const;
|
||||
JSON generate_summary_json() const;
|
||||
JSON generate_all_json() const;
|
||||
|
||||
JSON generate_ep3_cards_json(bool trial) const;
|
||||
JSON generate_common_tables_json() const;
|
||||
JSON generate_rare_tables_json() const;
|
||||
JSON generate_rare_table_json(const std::string& table_name) const;
|
||||
};
|
||||
|
||||
+73
-73
@@ -1,73 +1,73 @@
|
||||
#include "IPV4RangeSet.hh"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
IPV4RangeSet::IPV4RangeSet(const JSON& json) {
|
||||
for (const auto& it : json.as_list()) {
|
||||
// String should be of the form a.b.c.d or a.b.c.d/e
|
||||
auto tokens = split(it->as_string(), '/');
|
||||
|
||||
size_t mask_bits;
|
||||
if (tokens.size() == 1) {
|
||||
mask_bits = 32;
|
||||
} else if (tokens.size() == 2) {
|
||||
mask_bits = stoul(tokens[1], nullptr, 10);
|
||||
if (mask_bits > 32) {
|
||||
throw runtime_error("invalid IPv4 address range");
|
||||
}
|
||||
} else {
|
||||
throw runtime_error("invalid IPv4 address range");
|
||||
}
|
||||
|
||||
auto addr_tokens = split(tokens[0], '.');
|
||||
if (addr_tokens.size() != 4) {
|
||||
throw runtime_error("invalid IPv4 address");
|
||||
}
|
||||
uint32_t addr = 0;
|
||||
for (size_t z = 0; z < 4; z++) {
|
||||
size_t end_pos = 0;
|
||||
size_t new_byte = stoul(addr_tokens[z], &end_pos, 10);
|
||||
if (end_pos != addr_tokens[z].size() || new_byte > 0xFF) {
|
||||
throw runtime_error("invalid IPv4 address");
|
||||
}
|
||||
addr = (addr << 8) | new_byte;
|
||||
}
|
||||
addr &= (0xFFFFFFFF << (32 - mask_bits));
|
||||
|
||||
this->ranges.emplace(addr, mask_bits);
|
||||
}
|
||||
}
|
||||
|
||||
JSON IPV4RangeSet::json() const {
|
||||
auto ret = JSON::list();
|
||||
for (const auto& it : this->ranges) {
|
||||
uint32_t addr = it.first;
|
||||
uint8_t mask_bits = it.second;
|
||||
ret.emplace_back(string_printf("%hhu.%hhu.%hhu.%hhu/%hhu",
|
||||
static_cast<uint8_t>((addr >> 24) & 0xFF),
|
||||
static_cast<uint8_t>((addr >> 16) & 0xFF),
|
||||
static_cast<uint8_t>((addr >> 8) & 0xFF),
|
||||
static_cast<uint8_t>(addr & 0xFF),
|
||||
mask_bits));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool IPV4RangeSet::check(uint32_t addr) const {
|
||||
auto it = this->ranges.upper_bound(addr);
|
||||
if (it == this->ranges.begin()) {
|
||||
return false; // addr is before any range
|
||||
}
|
||||
const auto& range = *(--it);
|
||||
return (((range.first ^ addr) & (0xFFFFFFFF << (32 - range.second))) == 0);
|
||||
}
|
||||
|
||||
bool IPV4RangeSet::check(const struct sockaddr_storage& ss) const {
|
||||
if (ss.ss_family != AF_INET) {
|
||||
return false;
|
||||
}
|
||||
const sockaddr_in* sin = reinterpret_cast<const sockaddr_in*>(&ss);
|
||||
return this->check(ntohl(sin->sin_addr.s_addr));
|
||||
}
|
||||
#include "IPV4RangeSet.hh"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
IPV4RangeSet::IPV4RangeSet(const JSON& json) {
|
||||
for (const auto& it : json.as_list()) {
|
||||
// String should be of the form a.b.c.d or a.b.c.d/e
|
||||
auto tokens = split(it->as_string(), '/');
|
||||
|
||||
size_t mask_bits;
|
||||
if (tokens.size() == 1) {
|
||||
mask_bits = 32;
|
||||
} else if (tokens.size() == 2) {
|
||||
mask_bits = stoul(tokens[1], nullptr, 10);
|
||||
if (mask_bits > 32) {
|
||||
throw runtime_error("invalid IPv4 address range");
|
||||
}
|
||||
} else {
|
||||
throw runtime_error("invalid IPv4 address range");
|
||||
}
|
||||
|
||||
auto addr_tokens = split(tokens[0], '.');
|
||||
if (addr_tokens.size() != 4) {
|
||||
throw runtime_error("invalid IPv4 address");
|
||||
}
|
||||
uint32_t addr = 0;
|
||||
for (size_t z = 0; z < 4; z++) {
|
||||
size_t end_pos = 0;
|
||||
size_t new_byte = stoul(addr_tokens[z], &end_pos, 10);
|
||||
if (end_pos != addr_tokens[z].size() || new_byte > 0xFF) {
|
||||
throw runtime_error("invalid IPv4 address");
|
||||
}
|
||||
addr = (addr << 8) | new_byte;
|
||||
}
|
||||
addr &= (0xFFFFFFFF << (32 - mask_bits));
|
||||
|
||||
this->ranges.emplace(addr, mask_bits);
|
||||
}
|
||||
}
|
||||
|
||||
JSON IPV4RangeSet::json() const {
|
||||
auto ret = JSON::list();
|
||||
for (const auto& it : this->ranges) {
|
||||
uint32_t addr = it.first;
|
||||
uint8_t mask_bits = it.second;
|
||||
ret.emplace_back(string_printf("%hhu.%hhu.%hhu.%hhu/%hhu",
|
||||
static_cast<uint8_t>((addr >> 24) & 0xFF),
|
||||
static_cast<uint8_t>((addr >> 16) & 0xFF),
|
||||
static_cast<uint8_t>((addr >> 8) & 0xFF),
|
||||
static_cast<uint8_t>(addr & 0xFF),
|
||||
mask_bits));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool IPV4RangeSet::check(uint32_t addr) const {
|
||||
auto it = this->ranges.upper_bound(addr);
|
||||
if (it == this->ranges.begin()) {
|
||||
return false; // addr is before any range
|
||||
}
|
||||
const auto& range = *(--it);
|
||||
return (((range.first ^ addr) & (0xFFFFFFFF << (32 - range.second))) == 0);
|
||||
}
|
||||
|
||||
bool IPV4RangeSet::check(const struct sockaddr_storage& ss) const {
|
||||
if (ss.ss_family != AF_INET) {
|
||||
return false;
|
||||
}
|
||||
const sockaddr_in* sin = reinterpret_cast<const sockaddr_in*>(&ss);
|
||||
return this->check(ntohl(sin->sin_addr.s_addr));
|
||||
}
|
||||
|
||||
+18
-18
@@ -1,18 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <phosg/JSON.hh>
|
||||
#include <set>
|
||||
|
||||
class IPV4RangeSet {
|
||||
public:
|
||||
IPV4RangeSet() = default;
|
||||
explicit IPV4RangeSet(const JSON& json);
|
||||
|
||||
JSON json() const;
|
||||
|
||||
bool check(uint32_t addr) const;
|
||||
bool check(const struct sockaddr_storage& ss) const;
|
||||
|
||||
protected:
|
||||
std::map<uint32_t, uint8_t> ranges; // {addr: mask_bits}
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <phosg/JSON.hh>
|
||||
#include <set>
|
||||
|
||||
class IPV4RangeSet {
|
||||
public:
|
||||
IPV4RangeSet() = default;
|
||||
explicit IPV4RangeSet(const JSON& json);
|
||||
|
||||
JSON json() const;
|
||||
|
||||
bool check(uint32_t addr) const;
|
||||
bool check(const struct sockaddr_storage& ss) const;
|
||||
|
||||
protected:
|
||||
std::map<uint32_t, uint8_t> ranges; // {addr: mask_bits}
|
||||
};
|
||||
|
||||
+455
-455
@@ -1,455 +1,455 @@
|
||||
#include "IntegralExpression.hh"
|
||||
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Hash.hh>
|
||||
#include <phosg/Random.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <phosg/Tools.hh>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "CommandFormats.hh"
|
||||
#include "Compression.hh"
|
||||
#include "Loggers.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "QuestScript.hh"
|
||||
#include "SaveFileFormats.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
IntegralExpression::IntegralExpression(const string& text)
|
||||
: root(this->parse_expr(text)) {}
|
||||
|
||||
IntegralExpression::BinaryOperatorNode::BinaryOperatorNode(
|
||||
Type type, unique_ptr<const Node>&& left, unique_ptr<const Node>&& right)
|
||||
: type(type),
|
||||
left(std::move(left)),
|
||||
right(std::move(right)) {}
|
||||
|
||||
bool IntegralExpression::BinaryOperatorNode::operator==(const Node& other) const {
|
||||
try {
|
||||
const BinaryOperatorNode& other_bin = dynamic_cast<const BinaryOperatorNode&>(other);
|
||||
return other_bin.type == this->type && *other_bin.left == *this->left && *other_bin.right == *this->right;
|
||||
} catch (const bad_cast&) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t IntegralExpression::BinaryOperatorNode::evaluate(const Env& env) const {
|
||||
switch (this->type) {
|
||||
case Type::LOGICAL_OR:
|
||||
return this->left->evaluate(env) || this->right->evaluate(env);
|
||||
case Type::LOGICAL_AND:
|
||||
return this->left->evaluate(env) && this->right->evaluate(env);
|
||||
case Type::BITWISE_OR:
|
||||
return this->left->evaluate(env) | this->right->evaluate(env);
|
||||
case Type::BITWISE_AND:
|
||||
return this->left->evaluate(env) & this->right->evaluate(env);
|
||||
case Type::BITWISE_XOR:
|
||||
return this->left->evaluate(env) ^ this->right->evaluate(env);
|
||||
case Type::LEFT_SHIFT:
|
||||
return this->left->evaluate(env) << this->right->evaluate(env);
|
||||
case Type::RIGHT_SHIFT:
|
||||
return this->left->evaluate(env) >> this->right->evaluate(env);
|
||||
case Type::LESS_THAN:
|
||||
return this->left->evaluate(env) < this->right->evaluate(env);
|
||||
case Type::GREATER_THAN:
|
||||
return this->left->evaluate(env) > this->right->evaluate(env);
|
||||
case Type::LESS_OR_EQUAL:
|
||||
return this->left->evaluate(env) <= this->right->evaluate(env);
|
||||
case Type::GREATER_OR_EQUAL:
|
||||
return this->left->evaluate(env) >= this->right->evaluate(env);
|
||||
case Type::EQUAL:
|
||||
return this->left->evaluate(env) == this->right->evaluate(env);
|
||||
case Type::NOT_EQUAL:
|
||||
return this->left->evaluate(env) != this->right->evaluate(env);
|
||||
case Type::ADD:
|
||||
return this->left->evaluate(env) + this->right->evaluate(env);
|
||||
case Type::SUBTRACT:
|
||||
return this->left->evaluate(env) - this->right->evaluate(env);
|
||||
case Type::MULTIPLY:
|
||||
return this->left->evaluate(env) * this->right->evaluate(env);
|
||||
case Type::DIVIDE:
|
||||
return this->left->evaluate(env) / this->right->evaluate(env);
|
||||
case Type::MODULUS:
|
||||
return this->left->evaluate(env) % this->right->evaluate(env);
|
||||
default:
|
||||
throw logic_error("invalid binary operator type");
|
||||
}
|
||||
}
|
||||
|
||||
string IntegralExpression::BinaryOperatorNode::str() const {
|
||||
switch (this->type) {
|
||||
case Type::LOGICAL_OR:
|
||||
return "(" + this->left->str() + ") || (" + this->right->str() + ")";
|
||||
case Type::LOGICAL_AND:
|
||||
return "(" + this->left->str() + ") && (" + this->right->str() + ")";
|
||||
case Type::BITWISE_OR:
|
||||
return "(" + this->left->str() + ") | (" + this->right->str() + ")";
|
||||
case Type::BITWISE_AND:
|
||||
return "(" + this->left->str() + ") & (" + this->right->str() + ")";
|
||||
case Type::BITWISE_XOR:
|
||||
return "(" + this->left->str() + ") ^ (" + this->right->str() + ")";
|
||||
case Type::LEFT_SHIFT:
|
||||
return "(" + this->left->str() + ") << (" + this->right->str() + ")";
|
||||
case Type::RIGHT_SHIFT:
|
||||
return "(" + this->left->str() + ") >> (" + this->right->str() + ")";
|
||||
case Type::LESS_THAN:
|
||||
return "(" + this->left->str() + ") < (" + this->right->str() + ")";
|
||||
case Type::GREATER_THAN:
|
||||
return "(" + this->left->str() + ") > (" + this->right->str() + ")";
|
||||
case Type::LESS_OR_EQUAL:
|
||||
return "(" + this->left->str() + ") <= (" + this->right->str() + ")";
|
||||
case Type::GREATER_OR_EQUAL:
|
||||
return "(" + this->left->str() + ") >= (" + this->right->str() + ")";
|
||||
case Type::EQUAL:
|
||||
return "(" + this->left->str() + ") == (" + this->right->str() + ")";
|
||||
case Type::NOT_EQUAL:
|
||||
return "(" + this->left->str() + ") != (" + this->right->str() + ")";
|
||||
case Type::ADD:
|
||||
return "(" + this->left->str() + ") + (" + this->right->str() + ")";
|
||||
case Type::SUBTRACT:
|
||||
return "(" + this->left->str() + ") - (" + this->right->str() + ")";
|
||||
case Type::MULTIPLY:
|
||||
return "(" + this->left->str() + ") * (" + this->right->str() + ")";
|
||||
case Type::DIVIDE:
|
||||
return "(" + this->left->str() + ") / (" + this->right->str() + ")";
|
||||
case Type::MODULUS:
|
||||
return "(" + this->left->str() + ") % (" + this->right->str() + ")";
|
||||
default:
|
||||
throw logic_error("invalid binary operator type");
|
||||
}
|
||||
}
|
||||
|
||||
IntegralExpression::UnaryOperatorNode::UnaryOperatorNode(Type type, unique_ptr<const Node>&& sub)
|
||||
: type(type),
|
||||
sub(std::move(sub)) {}
|
||||
|
||||
bool IntegralExpression::UnaryOperatorNode::operator==(const Node& other) const {
|
||||
try {
|
||||
const UnaryOperatorNode& other_un = dynamic_cast<const UnaryOperatorNode&>(other);
|
||||
return other_un.type == this->type && *other_un.sub == *this->sub;
|
||||
} catch (const bad_cast&) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t IntegralExpression::UnaryOperatorNode::evaluate(const Env& env) const {
|
||||
switch (this->type) {
|
||||
case Type::LOGICAL_NOT:
|
||||
return !this->sub->evaluate(env);
|
||||
case Type::BITWISE_NOT:
|
||||
return ~this->sub->evaluate(env);
|
||||
case Type::NEGATIVE:
|
||||
return -this->sub->evaluate(env);
|
||||
default:
|
||||
throw logic_error("invalid unary operator type");
|
||||
}
|
||||
}
|
||||
|
||||
string IntegralExpression::UnaryOperatorNode::str() const {
|
||||
switch (this->type) {
|
||||
case Type::LOGICAL_NOT:
|
||||
return "!(" + this->sub->str() + ")";
|
||||
case Type::BITWISE_NOT:
|
||||
return "~(" + this->sub->str() + ")";
|
||||
case Type::NEGATIVE:
|
||||
return "-(" + this->sub->str() + ")";
|
||||
default:
|
||||
throw logic_error("invalid unary operator type");
|
||||
}
|
||||
}
|
||||
|
||||
IntegralExpression::FlagLookupNode::FlagLookupNode(uint16_t flag_index)
|
||||
: flag_index(flag_index) {}
|
||||
|
||||
bool IntegralExpression::FlagLookupNode::operator==(const Node& other) const {
|
||||
try {
|
||||
const FlagLookupNode& other_flag = dynamic_cast<const FlagLookupNode&>(other);
|
||||
return other_flag.flag_index == this->flag_index;
|
||||
} catch (const bad_cast&) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t IntegralExpression::FlagLookupNode::evaluate(const Env& env) const {
|
||||
if (!env.flags) {
|
||||
throw runtime_error("quest flags not available");
|
||||
}
|
||||
return env.flags->get(this->flag_index) ? 1 : 0;
|
||||
}
|
||||
|
||||
string IntegralExpression::FlagLookupNode::str() const {
|
||||
return string_printf("F_%04hX", this->flag_index);
|
||||
}
|
||||
|
||||
IntegralExpression::ChallengeCompletionLookupNode::ChallengeCompletionLookupNode(
|
||||
Episode episode, uint8_t stage_index)
|
||||
: episode(episode),
|
||||
stage_index(stage_index) {}
|
||||
|
||||
bool IntegralExpression::ChallengeCompletionLookupNode::operator==(const Node& other) const {
|
||||
try {
|
||||
const ChallengeCompletionLookupNode& other_cc = dynamic_cast<const ChallengeCompletionLookupNode&>(other);
|
||||
return other_cc.episode == this->episode && other_cc.stage_index == this->stage_index;
|
||||
} catch (const bad_cast&) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t IntegralExpression::ChallengeCompletionLookupNode::evaluate(const Env& env) const {
|
||||
if (!env.challenge_records) {
|
||||
throw runtime_error("challenge records not available");
|
||||
}
|
||||
if (this->episode == Episode::EP1) {
|
||||
return env.challenge_records->times_ep1_online.at(this->stage_index).has_value();
|
||||
} else if (this->episode == Episode::EP2) {
|
||||
return env.challenge_records->times_ep2_online.at(this->stage_index).has_value();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
string IntegralExpression::ChallengeCompletionLookupNode::str() const {
|
||||
return string_printf("CC_%s_%hhu", abbreviation_for_episode(this->episode), static_cast<uint8_t>(this->stage_index + 1));
|
||||
}
|
||||
|
||||
IntegralExpression::TeamRewardLookupNode::TeamRewardLookupNode(const string& reward_name)
|
||||
: reward_name(reward_name) {}
|
||||
|
||||
bool IntegralExpression::TeamRewardLookupNode::operator==(const Node& other) const {
|
||||
try {
|
||||
const TeamRewardLookupNode& other_team_reward = dynamic_cast<const TeamRewardLookupNode&>(other);
|
||||
return other_team_reward.reward_name == this->reward_name;
|
||||
} catch (const bad_cast&) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t IntegralExpression::TeamRewardLookupNode::evaluate(const Env& env) const {
|
||||
return (env.team && env.team->has_reward(this->reward_name)) ? 1 : 0;
|
||||
}
|
||||
|
||||
string IntegralExpression::TeamRewardLookupNode::str() const {
|
||||
return "T_" + this->reward_name;
|
||||
}
|
||||
|
||||
IntegralExpression::NumPlayersLookupNode::NumPlayersLookupNode() {}
|
||||
|
||||
bool IntegralExpression::NumPlayersLookupNode::operator==(const Node& other) const {
|
||||
return dynamic_cast<const NumPlayersLookupNode*>(&other) != nullptr;
|
||||
}
|
||||
|
||||
int64_t IntegralExpression::NumPlayersLookupNode::evaluate(const Env& env) const {
|
||||
return env.num_players;
|
||||
}
|
||||
|
||||
string IntegralExpression::NumPlayersLookupNode::str() const {
|
||||
return "V_NumPlayers";
|
||||
}
|
||||
|
||||
IntegralExpression::EventLookupNode::EventLookupNode() {}
|
||||
|
||||
bool IntegralExpression::EventLookupNode::operator==(const Node& other) const {
|
||||
return dynamic_cast<const EventLookupNode*>(&other) != nullptr;
|
||||
}
|
||||
|
||||
int64_t IntegralExpression::EventLookupNode::evaluate(const Env& env) const {
|
||||
return env.event;
|
||||
}
|
||||
|
||||
string IntegralExpression::EventLookupNode::str() const {
|
||||
return "V_Event";
|
||||
}
|
||||
|
||||
IntegralExpression::V1PresenceLookupNode::V1PresenceLookupNode() {}
|
||||
|
||||
bool IntegralExpression::V1PresenceLookupNode::operator==(const Node& other) const {
|
||||
return dynamic_cast<const V1PresenceLookupNode*>(&other) != nullptr;
|
||||
}
|
||||
|
||||
int64_t IntegralExpression::V1PresenceLookupNode::evaluate(const Env& env) const {
|
||||
return env.v1_present ? 1 : 0;
|
||||
}
|
||||
|
||||
string IntegralExpression::V1PresenceLookupNode::str() const {
|
||||
return "V_V1Present";
|
||||
}
|
||||
|
||||
IntegralExpression::ConstantNode::ConstantNode(int64_t value)
|
||||
: value(value) {}
|
||||
|
||||
bool IntegralExpression::ConstantNode::operator==(const Node& other) const {
|
||||
try {
|
||||
const ConstantNode& other_const = dynamic_cast<const ConstantNode&>(other);
|
||||
return other_const.value == this->value;
|
||||
} catch (const bad_cast&) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t IntegralExpression::ConstantNode::evaluate(const Env&) const {
|
||||
return this->value;
|
||||
}
|
||||
|
||||
string IntegralExpression::ConstantNode::str() const {
|
||||
return string_printf("%" PRId64, this->value);
|
||||
}
|
||||
|
||||
unique_ptr<const IntegralExpression::Node> IntegralExpression::parse_expr(string_view text) {
|
||||
// Strip off spaces and fully-enclosing parentheses
|
||||
for (;;) {
|
||||
size_t starting_size = text.size();
|
||||
while (text.at(0) == ' ') {
|
||||
text = text.substr(1);
|
||||
}
|
||||
while (text.at(text.size() - 1) == ' ') {
|
||||
text = text.substr(0, text.size() - 1);
|
||||
}
|
||||
if (text.at(0) == '(' && text.at(text.size() - 1) == ')') {
|
||||
// It doesn't suffice to just check the first ant last characters, since
|
||||
// text could be like "(a) && (b)". Instead, we ignore the first and last
|
||||
// characters, and don't strip anything if the internal parentheses are
|
||||
// unbalanced.
|
||||
size_t paren_level = 1;
|
||||
for (size_t z = 1; z < text.size() - 1; z++) {
|
||||
if (text[z] == '(') {
|
||||
paren_level++;
|
||||
} else if (text[z] == ')') {
|
||||
paren_level--;
|
||||
if (paren_level == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (paren_level > 0) {
|
||||
text = text.substr(1, text.size() - 2);
|
||||
}
|
||||
}
|
||||
if (text.size() == starting_size) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (text.empty()) {
|
||||
throw runtime_error("invalid expression");
|
||||
}
|
||||
|
||||
// Check for unary operators
|
||||
if (text[0] == '!') {
|
||||
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::LOGICAL_NOT,
|
||||
IntegralExpression::parse_expr(text.substr(1)));
|
||||
} else if (text[0] == '~') {
|
||||
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::BITWISE_NOT,
|
||||
IntegralExpression::parse_expr(text.substr(1)));
|
||||
} else if (text[0] == '-') {
|
||||
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::NEGATIVE,
|
||||
IntegralExpression::parse_expr(text.substr(1)));
|
||||
}
|
||||
|
||||
// Check for binary operators at the root level
|
||||
using BinType = BinaryOperatorNode::Type;
|
||||
static const vector<vector<pair<std::string, BinaryOperatorNode::Type>>> binary_operator_levels = {
|
||||
{{make_pair("*", BinType::MULTIPLY)}, {make_pair("/", BinType::DIVIDE)}, {make_pair("%", BinType::MODULUS)}},
|
||||
{{make_pair("+", BinType::ADD)}, {make_pair("-", BinType::SUBTRACT)}},
|
||||
{{make_pair("<<", BinType::LEFT_SHIFT)}, {make_pair(">>", BinType::RIGHT_SHIFT)}},
|
||||
{{make_pair("<=", BinType::LESS_OR_EQUAL)}, {make_pair(">=", BinType::GREATER_OR_EQUAL)}, {make_pair("<", BinType::LESS_THAN)}, {make_pair(">", BinType::GREATER_THAN)}},
|
||||
{{make_pair("==", BinType::EQUAL)}, {make_pair("!=", BinType::NOT_EQUAL)}},
|
||||
{{make_pair("&", BinType::BITWISE_AND)}},
|
||||
{{make_pair("^", BinType::BITWISE_XOR)}},
|
||||
{{make_pair("|", BinType::BITWISE_OR)}},
|
||||
{{make_pair("&&", BinType::LOGICAL_AND)}},
|
||||
{{make_pair("||", BinType::LOGICAL_OR)}},
|
||||
};
|
||||
for (const auto& operators : binary_operator_levels) {
|
||||
size_t paren_level = 0;
|
||||
for (size_t z = 0; z < text.size() - 1; z++) {
|
||||
if (text[z] == '(') {
|
||||
paren_level++;
|
||||
continue;
|
||||
} else if (text[z] == ')') {
|
||||
paren_level--;
|
||||
continue;
|
||||
}
|
||||
if (!paren_level) {
|
||||
for (const auto& oper : operators) {
|
||||
// Awful hack (because I'm too lazy to add a tokenization step): if
|
||||
// the operator is followed or preceded by another copy of itself,
|
||||
// don't match it (this prevents us from matching & when the token is
|
||||
// actually &&)
|
||||
if ((text.size() > z + oper.first.size()) &&
|
||||
((z < oper.first.size()) || (text.compare(z - oper.first.size(), oper.first.size(), oper.first) != 0)) &&
|
||||
(text.compare(z, oper.first.size(), oper.first) == 0) &&
|
||||
(text.compare(z + oper.first.size(), oper.first.size(), oper.first) != 0)) {
|
||||
auto left = IntegralExpression::parse_expr(text.substr(0, z));
|
||||
auto right = IntegralExpression::parse_expr(text.substr(z + oper.first.size()));
|
||||
return make_unique<BinaryOperatorNode>(oper.second, std::move(left), std::move(right));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check for env lookups
|
||||
if (text.starts_with("F_")) {
|
||||
char* endptr = nullptr;
|
||||
uint64_t flag = strtoul(text.data() + 2, &endptr, 16);
|
||||
if (endptr != text.data() + text.size()) {
|
||||
throw runtime_error("invalid flag lookup token");
|
||||
}
|
||||
if (flag >= 0x400) {
|
||||
throw runtime_error("invalid flag index");
|
||||
}
|
||||
return make_unique<FlagLookupNode>(flag);
|
||||
}
|
||||
if (text.starts_with("CC_")) {
|
||||
Episode episode;
|
||||
if (text.starts_with("CC_Ep1_")) {
|
||||
episode = Episode::EP1;
|
||||
} else if (text.starts_with("CC_Ep2_")) {
|
||||
episode = Episode::EP2;
|
||||
} else {
|
||||
throw runtime_error("invalid challenge episode");
|
||||
}
|
||||
char* endptr = nullptr;
|
||||
uint64_t stage_index = strtoul(text.data() + 7, &endptr, 0) - 1;
|
||||
if (endptr != text.data() + text.size()) {
|
||||
throw runtime_error("invalid challenge completion lookup token");
|
||||
}
|
||||
if ((episode == Episode::EP1 && stage_index > 8) || (episode == Episode::EP2 && stage_index > 4)) {
|
||||
throw runtime_error("invalid challenge stage index");
|
||||
}
|
||||
return make_unique<ChallengeCompletionLookupNode>(episode, stage_index);
|
||||
}
|
||||
if (text.starts_with("T_")) {
|
||||
return make_unique<TeamRewardLookupNode>(string(text.substr(2)));
|
||||
}
|
||||
if (text == "V_NumPlayers") {
|
||||
return make_unique<NumPlayersLookupNode>();
|
||||
}
|
||||
if (text == "V_Event") {
|
||||
return make_unique<EventLookupNode>();
|
||||
}
|
||||
if (text == "V_V1Present") {
|
||||
return make_unique<V1PresenceLookupNode>();
|
||||
}
|
||||
|
||||
// Check for constants
|
||||
if (text == "true") {
|
||||
return make_unique<ConstantNode>(1);
|
||||
}
|
||||
if (text == "false") {
|
||||
return make_unique<ConstantNode>(0);
|
||||
}
|
||||
try {
|
||||
size_t endpos;
|
||||
int64_t v = stoll(string(text), &endpos, 0);
|
||||
if (endpos == text.size()) {
|
||||
return make_unique<ConstantNode>(v);
|
||||
}
|
||||
} catch (const exception&) {
|
||||
}
|
||||
throw runtime_error("unparseable expression");
|
||||
}
|
||||
#include "IntegralExpression.hh"
|
||||
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Hash.hh>
|
||||
#include <phosg/Random.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <phosg/Tools.hh>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "CommandFormats.hh"
|
||||
#include "Compression.hh"
|
||||
#include "Loggers.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "QuestScript.hh"
|
||||
#include "SaveFileFormats.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
IntegralExpression::IntegralExpression(const string& text)
|
||||
: root(this->parse_expr(text)) {}
|
||||
|
||||
IntegralExpression::BinaryOperatorNode::BinaryOperatorNode(
|
||||
Type type, unique_ptr<const Node>&& left, unique_ptr<const Node>&& right)
|
||||
: type(type),
|
||||
left(std::move(left)),
|
||||
right(std::move(right)) {}
|
||||
|
||||
bool IntegralExpression::BinaryOperatorNode::operator==(const Node& other) const {
|
||||
try {
|
||||
const BinaryOperatorNode& other_bin = dynamic_cast<const BinaryOperatorNode&>(other);
|
||||
return other_bin.type == this->type && *other_bin.left == *this->left && *other_bin.right == *this->right;
|
||||
} catch (const bad_cast&) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t IntegralExpression::BinaryOperatorNode::evaluate(const Env& env) const {
|
||||
switch (this->type) {
|
||||
case Type::LOGICAL_OR:
|
||||
return this->left->evaluate(env) || this->right->evaluate(env);
|
||||
case Type::LOGICAL_AND:
|
||||
return this->left->evaluate(env) && this->right->evaluate(env);
|
||||
case Type::BITWISE_OR:
|
||||
return this->left->evaluate(env) | this->right->evaluate(env);
|
||||
case Type::BITWISE_AND:
|
||||
return this->left->evaluate(env) & this->right->evaluate(env);
|
||||
case Type::BITWISE_XOR:
|
||||
return this->left->evaluate(env) ^ this->right->evaluate(env);
|
||||
case Type::LEFT_SHIFT:
|
||||
return this->left->evaluate(env) << this->right->evaluate(env);
|
||||
case Type::RIGHT_SHIFT:
|
||||
return this->left->evaluate(env) >> this->right->evaluate(env);
|
||||
case Type::LESS_THAN:
|
||||
return this->left->evaluate(env) < this->right->evaluate(env);
|
||||
case Type::GREATER_THAN:
|
||||
return this->left->evaluate(env) > this->right->evaluate(env);
|
||||
case Type::LESS_OR_EQUAL:
|
||||
return this->left->evaluate(env) <= this->right->evaluate(env);
|
||||
case Type::GREATER_OR_EQUAL:
|
||||
return this->left->evaluate(env) >= this->right->evaluate(env);
|
||||
case Type::EQUAL:
|
||||
return this->left->evaluate(env) == this->right->evaluate(env);
|
||||
case Type::NOT_EQUAL:
|
||||
return this->left->evaluate(env) != this->right->evaluate(env);
|
||||
case Type::ADD:
|
||||
return this->left->evaluate(env) + this->right->evaluate(env);
|
||||
case Type::SUBTRACT:
|
||||
return this->left->evaluate(env) - this->right->evaluate(env);
|
||||
case Type::MULTIPLY:
|
||||
return this->left->evaluate(env) * this->right->evaluate(env);
|
||||
case Type::DIVIDE:
|
||||
return this->left->evaluate(env) / this->right->evaluate(env);
|
||||
case Type::MODULUS:
|
||||
return this->left->evaluate(env) % this->right->evaluate(env);
|
||||
default:
|
||||
throw logic_error("invalid binary operator type");
|
||||
}
|
||||
}
|
||||
|
||||
string IntegralExpression::BinaryOperatorNode::str() const {
|
||||
switch (this->type) {
|
||||
case Type::LOGICAL_OR:
|
||||
return "(" + this->left->str() + ") || (" + this->right->str() + ")";
|
||||
case Type::LOGICAL_AND:
|
||||
return "(" + this->left->str() + ") && (" + this->right->str() + ")";
|
||||
case Type::BITWISE_OR:
|
||||
return "(" + this->left->str() + ") | (" + this->right->str() + ")";
|
||||
case Type::BITWISE_AND:
|
||||
return "(" + this->left->str() + ") & (" + this->right->str() + ")";
|
||||
case Type::BITWISE_XOR:
|
||||
return "(" + this->left->str() + ") ^ (" + this->right->str() + ")";
|
||||
case Type::LEFT_SHIFT:
|
||||
return "(" + this->left->str() + ") << (" + this->right->str() + ")";
|
||||
case Type::RIGHT_SHIFT:
|
||||
return "(" + this->left->str() + ") >> (" + this->right->str() + ")";
|
||||
case Type::LESS_THAN:
|
||||
return "(" + this->left->str() + ") < (" + this->right->str() + ")";
|
||||
case Type::GREATER_THAN:
|
||||
return "(" + this->left->str() + ") > (" + this->right->str() + ")";
|
||||
case Type::LESS_OR_EQUAL:
|
||||
return "(" + this->left->str() + ") <= (" + this->right->str() + ")";
|
||||
case Type::GREATER_OR_EQUAL:
|
||||
return "(" + this->left->str() + ") >= (" + this->right->str() + ")";
|
||||
case Type::EQUAL:
|
||||
return "(" + this->left->str() + ") == (" + this->right->str() + ")";
|
||||
case Type::NOT_EQUAL:
|
||||
return "(" + this->left->str() + ") != (" + this->right->str() + ")";
|
||||
case Type::ADD:
|
||||
return "(" + this->left->str() + ") + (" + this->right->str() + ")";
|
||||
case Type::SUBTRACT:
|
||||
return "(" + this->left->str() + ") - (" + this->right->str() + ")";
|
||||
case Type::MULTIPLY:
|
||||
return "(" + this->left->str() + ") * (" + this->right->str() + ")";
|
||||
case Type::DIVIDE:
|
||||
return "(" + this->left->str() + ") / (" + this->right->str() + ")";
|
||||
case Type::MODULUS:
|
||||
return "(" + this->left->str() + ") % (" + this->right->str() + ")";
|
||||
default:
|
||||
throw logic_error("invalid binary operator type");
|
||||
}
|
||||
}
|
||||
|
||||
IntegralExpression::UnaryOperatorNode::UnaryOperatorNode(Type type, unique_ptr<const Node>&& sub)
|
||||
: type(type),
|
||||
sub(std::move(sub)) {}
|
||||
|
||||
bool IntegralExpression::UnaryOperatorNode::operator==(const Node& other) const {
|
||||
try {
|
||||
const UnaryOperatorNode& other_un = dynamic_cast<const UnaryOperatorNode&>(other);
|
||||
return other_un.type == this->type && *other_un.sub == *this->sub;
|
||||
} catch (const bad_cast&) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t IntegralExpression::UnaryOperatorNode::evaluate(const Env& env) const {
|
||||
switch (this->type) {
|
||||
case Type::LOGICAL_NOT:
|
||||
return !this->sub->evaluate(env);
|
||||
case Type::BITWISE_NOT:
|
||||
return ~this->sub->evaluate(env);
|
||||
case Type::NEGATIVE:
|
||||
return -this->sub->evaluate(env);
|
||||
default:
|
||||
throw logic_error("invalid unary operator type");
|
||||
}
|
||||
}
|
||||
|
||||
string IntegralExpression::UnaryOperatorNode::str() const {
|
||||
switch (this->type) {
|
||||
case Type::LOGICAL_NOT:
|
||||
return "!(" + this->sub->str() + ")";
|
||||
case Type::BITWISE_NOT:
|
||||
return "~(" + this->sub->str() + ")";
|
||||
case Type::NEGATIVE:
|
||||
return "-(" + this->sub->str() + ")";
|
||||
default:
|
||||
throw logic_error("invalid unary operator type");
|
||||
}
|
||||
}
|
||||
|
||||
IntegralExpression::FlagLookupNode::FlagLookupNode(uint16_t flag_index)
|
||||
: flag_index(flag_index) {}
|
||||
|
||||
bool IntegralExpression::FlagLookupNode::operator==(const Node& other) const {
|
||||
try {
|
||||
const FlagLookupNode& other_flag = dynamic_cast<const FlagLookupNode&>(other);
|
||||
return other_flag.flag_index == this->flag_index;
|
||||
} catch (const bad_cast&) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t IntegralExpression::FlagLookupNode::evaluate(const Env& env) const {
|
||||
if (!env.flags) {
|
||||
throw runtime_error("quest flags not available");
|
||||
}
|
||||
return env.flags->get(this->flag_index) ? 1 : 0;
|
||||
}
|
||||
|
||||
string IntegralExpression::FlagLookupNode::str() const {
|
||||
return string_printf("F_%04hX", this->flag_index);
|
||||
}
|
||||
|
||||
IntegralExpression::ChallengeCompletionLookupNode::ChallengeCompletionLookupNode(
|
||||
Episode episode, uint8_t stage_index)
|
||||
: episode(episode),
|
||||
stage_index(stage_index) {}
|
||||
|
||||
bool IntegralExpression::ChallengeCompletionLookupNode::operator==(const Node& other) const {
|
||||
try {
|
||||
const ChallengeCompletionLookupNode& other_cc = dynamic_cast<const ChallengeCompletionLookupNode&>(other);
|
||||
return other_cc.episode == this->episode && other_cc.stage_index == this->stage_index;
|
||||
} catch (const bad_cast&) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t IntegralExpression::ChallengeCompletionLookupNode::evaluate(const Env& env) const {
|
||||
if (!env.challenge_records) {
|
||||
throw runtime_error("challenge records not available");
|
||||
}
|
||||
if (this->episode == Episode::EP1) {
|
||||
return env.challenge_records->times_ep1_online.at(this->stage_index).has_value();
|
||||
} else if (this->episode == Episode::EP2) {
|
||||
return env.challenge_records->times_ep2_online.at(this->stage_index).has_value();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
string IntegralExpression::ChallengeCompletionLookupNode::str() const {
|
||||
return string_printf("CC_%s_%hhu", abbreviation_for_episode(this->episode), static_cast<uint8_t>(this->stage_index + 1));
|
||||
}
|
||||
|
||||
IntegralExpression::TeamRewardLookupNode::TeamRewardLookupNode(const string& reward_name)
|
||||
: reward_name(reward_name) {}
|
||||
|
||||
bool IntegralExpression::TeamRewardLookupNode::operator==(const Node& other) const {
|
||||
try {
|
||||
const TeamRewardLookupNode& other_team_reward = dynamic_cast<const TeamRewardLookupNode&>(other);
|
||||
return other_team_reward.reward_name == this->reward_name;
|
||||
} catch (const bad_cast&) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t IntegralExpression::TeamRewardLookupNode::evaluate(const Env& env) const {
|
||||
return (env.team && env.team->has_reward(this->reward_name)) ? 1 : 0;
|
||||
}
|
||||
|
||||
string IntegralExpression::TeamRewardLookupNode::str() const {
|
||||
return "T_" + this->reward_name;
|
||||
}
|
||||
|
||||
IntegralExpression::NumPlayersLookupNode::NumPlayersLookupNode() {}
|
||||
|
||||
bool IntegralExpression::NumPlayersLookupNode::operator==(const Node& other) const {
|
||||
return dynamic_cast<const NumPlayersLookupNode*>(&other) != nullptr;
|
||||
}
|
||||
|
||||
int64_t IntegralExpression::NumPlayersLookupNode::evaluate(const Env& env) const {
|
||||
return env.num_players;
|
||||
}
|
||||
|
||||
string IntegralExpression::NumPlayersLookupNode::str() const {
|
||||
return "V_NumPlayers";
|
||||
}
|
||||
|
||||
IntegralExpression::EventLookupNode::EventLookupNode() {}
|
||||
|
||||
bool IntegralExpression::EventLookupNode::operator==(const Node& other) const {
|
||||
return dynamic_cast<const EventLookupNode*>(&other) != nullptr;
|
||||
}
|
||||
|
||||
int64_t IntegralExpression::EventLookupNode::evaluate(const Env& env) const {
|
||||
return env.event;
|
||||
}
|
||||
|
||||
string IntegralExpression::EventLookupNode::str() const {
|
||||
return "V_Event";
|
||||
}
|
||||
|
||||
IntegralExpression::V1PresenceLookupNode::V1PresenceLookupNode() {}
|
||||
|
||||
bool IntegralExpression::V1PresenceLookupNode::operator==(const Node& other) const {
|
||||
return dynamic_cast<const V1PresenceLookupNode*>(&other) != nullptr;
|
||||
}
|
||||
|
||||
int64_t IntegralExpression::V1PresenceLookupNode::evaluate(const Env& env) const {
|
||||
return env.v1_present ? 1 : 0;
|
||||
}
|
||||
|
||||
string IntegralExpression::V1PresenceLookupNode::str() const {
|
||||
return "V_V1Present";
|
||||
}
|
||||
|
||||
IntegralExpression::ConstantNode::ConstantNode(int64_t value)
|
||||
: value(value) {}
|
||||
|
||||
bool IntegralExpression::ConstantNode::operator==(const Node& other) const {
|
||||
try {
|
||||
const ConstantNode& other_const = dynamic_cast<const ConstantNode&>(other);
|
||||
return other_const.value == this->value;
|
||||
} catch (const bad_cast&) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t IntegralExpression::ConstantNode::evaluate(const Env&) const {
|
||||
return this->value;
|
||||
}
|
||||
|
||||
string IntegralExpression::ConstantNode::str() const {
|
||||
return string_printf("%" PRId64, this->value);
|
||||
}
|
||||
|
||||
unique_ptr<const IntegralExpression::Node> IntegralExpression::parse_expr(string_view text) {
|
||||
// Strip off spaces and fully-enclosing parentheses
|
||||
for (;;) {
|
||||
size_t starting_size = text.size();
|
||||
while (text.at(0) == ' ') {
|
||||
text = text.substr(1);
|
||||
}
|
||||
while (text.at(text.size() - 1) == ' ') {
|
||||
text = text.substr(0, text.size() - 1);
|
||||
}
|
||||
if (text.at(0) == '(' && text.at(text.size() - 1) == ')') {
|
||||
// It doesn't suffice to just check the first ant last characters, since
|
||||
// text could be like "(a) && (b)". Instead, we ignore the first and last
|
||||
// characters, and don't strip anything if the internal parentheses are
|
||||
// unbalanced.
|
||||
size_t paren_level = 1;
|
||||
for (size_t z = 1; z < text.size() - 1; z++) {
|
||||
if (text[z] == '(') {
|
||||
paren_level++;
|
||||
} else if (text[z] == ')') {
|
||||
paren_level--;
|
||||
if (paren_level == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (paren_level > 0) {
|
||||
text = text.substr(1, text.size() - 2);
|
||||
}
|
||||
}
|
||||
if (text.size() == starting_size) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (text.empty()) {
|
||||
throw runtime_error("invalid expression");
|
||||
}
|
||||
|
||||
// Check for binary operators at the root level
|
||||
using BinType = BinaryOperatorNode::Type;
|
||||
static const vector<vector<pair<std::string, BinaryOperatorNode::Type>>> binary_operator_levels = {
|
||||
{{make_pair("*", BinType::MULTIPLY)}, {make_pair("/", BinType::DIVIDE)}, {make_pair("%", BinType::MODULUS)}},
|
||||
{{make_pair("+", BinType::ADD)}, {make_pair("-", BinType::SUBTRACT)}},
|
||||
{{make_pair("<<", BinType::LEFT_SHIFT)}, {make_pair(">>", BinType::RIGHT_SHIFT)}},
|
||||
{{make_pair("<=", BinType::LESS_OR_EQUAL)}, {make_pair(">=", BinType::GREATER_OR_EQUAL)}, {make_pair("<", BinType::LESS_THAN)}, {make_pair(">", BinType::GREATER_THAN)}},
|
||||
{{make_pair("==", BinType::EQUAL)}, {make_pair("!=", BinType::NOT_EQUAL)}},
|
||||
{{make_pair("&", BinType::BITWISE_AND)}},
|
||||
{{make_pair("^", BinType::BITWISE_XOR)}},
|
||||
{{make_pair("|", BinType::BITWISE_OR)}},
|
||||
{{make_pair("&&", BinType::LOGICAL_AND)}},
|
||||
{{make_pair("||", BinType::LOGICAL_OR)}},
|
||||
};
|
||||
for (const auto& operators : binary_operator_levels) {
|
||||
size_t paren_level = 0;
|
||||
for (size_t z = 0; z < text.size() - 1; z++) {
|
||||
if (text[z] == '(') {
|
||||
paren_level++;
|
||||
continue;
|
||||
} else if (text[z] == ')') {
|
||||
paren_level--;
|
||||
continue;
|
||||
}
|
||||
if (!paren_level) {
|
||||
for (const auto& oper : operators) {
|
||||
// Awful hack (because I'm too lazy to add a tokenization step): if
|
||||
// the operator is followed or preceded by another copy of itself,
|
||||
// don't match it (this prevents us from matching & when the token is
|
||||
// actually &&)
|
||||
if ((text.size() > z + oper.first.size()) &&
|
||||
((z < oper.first.size()) || (text.compare(z - oper.first.size(), oper.first.size(), oper.first) != 0)) &&
|
||||
(text.compare(z, oper.first.size(), oper.first) == 0) &&
|
||||
(text.compare(z + oper.first.size(), oper.first.size(), oper.first) != 0)) {
|
||||
auto left = IntegralExpression::parse_expr(text.substr(0, z));
|
||||
auto right = IntegralExpression::parse_expr(text.substr(z + oper.first.size()));
|
||||
return make_unique<BinaryOperatorNode>(oper.second, std::move(left), std::move(right));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check for unary operators
|
||||
if (text[0] == '!') {
|
||||
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::LOGICAL_NOT,
|
||||
IntegralExpression::parse_expr(text.substr(1)));
|
||||
} else if (text[0] == '~') {
|
||||
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::BITWISE_NOT,
|
||||
IntegralExpression::parse_expr(text.substr(1)));
|
||||
} else if (text[0] == '-') {
|
||||
return make_unique<UnaryOperatorNode>(UnaryOperatorNode::Type::NEGATIVE,
|
||||
IntegralExpression::parse_expr(text.substr(1)));
|
||||
}
|
||||
|
||||
// Check for env lookups
|
||||
if (text.starts_with("F_")) {
|
||||
char* endptr = nullptr;
|
||||
uint64_t flag = strtoul(text.data() + 2, &endptr, 16);
|
||||
if (endptr != text.data() + text.size()) {
|
||||
throw runtime_error("invalid flag lookup token");
|
||||
}
|
||||
if (flag >= 0x400) {
|
||||
throw runtime_error("invalid flag index");
|
||||
}
|
||||
return make_unique<FlagLookupNode>(flag);
|
||||
}
|
||||
if (text.starts_with("CC_")) {
|
||||
Episode episode;
|
||||
if (text.starts_with("CC_Ep1_")) {
|
||||
episode = Episode::EP1;
|
||||
} else if (text.starts_with("CC_Ep2_")) {
|
||||
episode = Episode::EP2;
|
||||
} else {
|
||||
throw runtime_error("invalid challenge episode");
|
||||
}
|
||||
char* endptr = nullptr;
|
||||
uint64_t stage_index = strtoul(text.data() + 7, &endptr, 0) - 1;
|
||||
if (endptr != text.data() + text.size()) {
|
||||
throw runtime_error("invalid challenge completion lookup token");
|
||||
}
|
||||
if ((episode == Episode::EP1 && stage_index > 8) || (episode == Episode::EP2 && stage_index > 4)) {
|
||||
throw runtime_error("invalid challenge stage index");
|
||||
}
|
||||
return make_unique<ChallengeCompletionLookupNode>(episode, stage_index);
|
||||
}
|
||||
if (text.starts_with("T_")) {
|
||||
return make_unique<TeamRewardLookupNode>(string(text.substr(2)));
|
||||
}
|
||||
if (text == "V_NumPlayers") {
|
||||
return make_unique<NumPlayersLookupNode>();
|
||||
}
|
||||
if (text == "V_Event") {
|
||||
return make_unique<EventLookupNode>();
|
||||
}
|
||||
if (text == "V_V1Present") {
|
||||
return make_unique<V1PresenceLookupNode>();
|
||||
}
|
||||
|
||||
// Check for constants
|
||||
if (text == "true") {
|
||||
return make_unique<ConstantNode>(1);
|
||||
}
|
||||
if (text == "false") {
|
||||
return make_unique<ConstantNode>(0);
|
||||
}
|
||||
try {
|
||||
size_t endpos;
|
||||
int64_t v = stoll(string(text), &endpos, 0);
|
||||
if (endpos == text.size()) {
|
||||
return make_unique<ConstantNode>(v);
|
||||
}
|
||||
} catch (const exception&) {
|
||||
}
|
||||
throw runtime_error("unparseable expression");
|
||||
}
|
||||
|
||||
+188
-188
@@ -1,188 +1,188 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "PlayerSubordinates.hh"
|
||||
#include "QuestScript.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "TeamIndex.hh"
|
||||
|
||||
class IntegralExpression {
|
||||
public:
|
||||
struct Env {
|
||||
const QuestFlagsForDifficulty* flags;
|
||||
const PlayerRecordsChallengeBB* challenge_records;
|
||||
std::shared_ptr<const TeamIndex::Team> team;
|
||||
size_t num_players;
|
||||
uint8_t event;
|
||||
bool v1_present;
|
||||
};
|
||||
|
||||
IntegralExpression(const std::string& text);
|
||||
~IntegralExpression() = default;
|
||||
inline bool operator==(const IntegralExpression& other) const {
|
||||
return this->root->operator==(*other.root);
|
||||
}
|
||||
inline bool operator!=(const IntegralExpression& other) const {
|
||||
return !this->operator==(other);
|
||||
}
|
||||
inline int64_t evaluate(const Env& env) const {
|
||||
return this->root->evaluate(env);
|
||||
}
|
||||
inline std::string str() const {
|
||||
return this->root->str();
|
||||
}
|
||||
|
||||
protected:
|
||||
class Node {
|
||||
public:
|
||||
virtual ~Node() = default;
|
||||
virtual bool operator==(const Node& other) const = 0;
|
||||
inline bool operator!=(const Node& other) const {
|
||||
return !this->operator==(other);
|
||||
}
|
||||
virtual int64_t evaluate(const Env& env) const = 0;
|
||||
virtual std::string str() const = 0;
|
||||
|
||||
protected:
|
||||
Node() = default;
|
||||
};
|
||||
|
||||
class BinaryOperatorNode : public Node {
|
||||
public:
|
||||
enum class Type {
|
||||
LOGICAL_OR = 0,
|
||||
LOGICAL_AND,
|
||||
BITWISE_OR,
|
||||
BITWISE_AND,
|
||||
BITWISE_XOR,
|
||||
LEFT_SHIFT,
|
||||
RIGHT_SHIFT,
|
||||
LESS_THAN,
|
||||
GREATER_THAN,
|
||||
LESS_OR_EQUAL,
|
||||
GREATER_OR_EQUAL,
|
||||
EQUAL,
|
||||
NOT_EQUAL,
|
||||
ADD,
|
||||
SUBTRACT,
|
||||
MULTIPLY,
|
||||
DIVIDE,
|
||||
MODULUS,
|
||||
};
|
||||
BinaryOperatorNode(Type type, std::unique_ptr<const Node>&& left, std::unique_ptr<const Node>&& right);
|
||||
virtual ~BinaryOperatorNode() = default;
|
||||
virtual bool operator==(const Node& other) const;
|
||||
virtual int64_t evaluate(const Env& env) const;
|
||||
virtual std::string str() const;
|
||||
|
||||
protected:
|
||||
Type type;
|
||||
std::unique_ptr<const Node> left;
|
||||
std::unique_ptr<const Node> right;
|
||||
};
|
||||
|
||||
class UnaryOperatorNode : public Node {
|
||||
public:
|
||||
enum class Type {
|
||||
LOGICAL_NOT = 0,
|
||||
BITWISE_NOT,
|
||||
NEGATIVE,
|
||||
};
|
||||
UnaryOperatorNode(Type type, std::unique_ptr<const Node>&& sub);
|
||||
virtual ~UnaryOperatorNode() = default;
|
||||
virtual bool operator==(const Node& other) const;
|
||||
virtual int64_t evaluate(const Env& env) const;
|
||||
virtual std::string str() const;
|
||||
|
||||
protected:
|
||||
Type type;
|
||||
std::unique_ptr<const Node> sub;
|
||||
};
|
||||
|
||||
class FlagLookupNode : public Node {
|
||||
public:
|
||||
FlagLookupNode(uint16_t flag_index);
|
||||
virtual ~FlagLookupNode() = default;
|
||||
virtual bool operator==(const Node& other) const;
|
||||
virtual int64_t evaluate(const Env& env) const;
|
||||
virtual std::string str() const;
|
||||
|
||||
protected:
|
||||
uint16_t flag_index;
|
||||
};
|
||||
|
||||
class ChallengeCompletionLookupNode : public Node {
|
||||
public:
|
||||
ChallengeCompletionLookupNode(Episode episode, uint8_t stage_index);
|
||||
virtual ~ChallengeCompletionLookupNode() = default;
|
||||
virtual bool operator==(const Node& other) const;
|
||||
virtual int64_t evaluate(const Env& env) const;
|
||||
virtual std::string str() const;
|
||||
|
||||
protected:
|
||||
Episode episode;
|
||||
uint8_t stage_index;
|
||||
};
|
||||
|
||||
class TeamRewardLookupNode : public Node {
|
||||
public:
|
||||
TeamRewardLookupNode(const std::string& reward_name);
|
||||
virtual ~TeamRewardLookupNode() = default;
|
||||
virtual bool operator==(const Node& other) const;
|
||||
virtual int64_t evaluate(const Env& env) const;
|
||||
virtual std::string str() const;
|
||||
|
||||
protected:
|
||||
std::string reward_name;
|
||||
};
|
||||
|
||||
class NumPlayersLookupNode : public Node {
|
||||
public:
|
||||
NumPlayersLookupNode();
|
||||
virtual ~NumPlayersLookupNode() = default;
|
||||
virtual bool operator==(const Node& other) const;
|
||||
virtual int64_t evaluate(const Env& env) const;
|
||||
virtual std::string str() const;
|
||||
};
|
||||
|
||||
class EventLookupNode : public Node {
|
||||
public:
|
||||
EventLookupNode();
|
||||
virtual ~EventLookupNode() = default;
|
||||
virtual bool operator==(const Node& other) const;
|
||||
virtual int64_t evaluate(const Env& env) const;
|
||||
virtual std::string str() const;
|
||||
};
|
||||
|
||||
class V1PresenceLookupNode : public Node {
|
||||
public:
|
||||
V1PresenceLookupNode();
|
||||
virtual ~V1PresenceLookupNode() = default;
|
||||
virtual bool operator==(const Node& other) const;
|
||||
virtual int64_t evaluate(const Env& env) const;
|
||||
virtual std::string str() const;
|
||||
};
|
||||
|
||||
class ConstantNode : public Node {
|
||||
public:
|
||||
ConstantNode(int64_t value);
|
||||
virtual ~ConstantNode() = default;
|
||||
virtual bool operator==(const Node& other) const;
|
||||
virtual int64_t evaluate(const Env& env) const;
|
||||
virtual std::string str() const;
|
||||
|
||||
protected:
|
||||
int64_t value;
|
||||
};
|
||||
|
||||
std::unique_ptr<const Node> parse_expr(std::string_view text);
|
||||
|
||||
std::unique_ptr<const Node> root;
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "PlayerSubordinates.hh"
|
||||
#include "QuestScript.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "TeamIndex.hh"
|
||||
|
||||
class IntegralExpression {
|
||||
public:
|
||||
struct Env {
|
||||
const QuestFlagsForDifficulty* flags;
|
||||
const PlayerRecordsChallengeBB* challenge_records;
|
||||
std::shared_ptr<const TeamIndex::Team> team;
|
||||
size_t num_players;
|
||||
uint8_t event;
|
||||
bool v1_present;
|
||||
};
|
||||
|
||||
IntegralExpression(const std::string& text);
|
||||
~IntegralExpression() = default;
|
||||
inline bool operator==(const IntegralExpression& other) const {
|
||||
return this->root->operator==(*other.root);
|
||||
}
|
||||
inline bool operator!=(const IntegralExpression& other) const {
|
||||
return !this->operator==(other);
|
||||
}
|
||||
inline int64_t evaluate(const Env& env) const {
|
||||
return this->root->evaluate(env);
|
||||
}
|
||||
inline std::string str() const {
|
||||
return this->root->str();
|
||||
}
|
||||
|
||||
protected:
|
||||
class Node {
|
||||
public:
|
||||
virtual ~Node() = default;
|
||||
virtual bool operator==(const Node& other) const = 0;
|
||||
inline bool operator!=(const Node& other) const {
|
||||
return !this->operator==(other);
|
||||
}
|
||||
virtual int64_t evaluate(const Env& env) const = 0;
|
||||
virtual std::string str() const = 0;
|
||||
|
||||
protected:
|
||||
Node() = default;
|
||||
};
|
||||
|
||||
class BinaryOperatorNode : public Node {
|
||||
public:
|
||||
enum class Type {
|
||||
LOGICAL_OR = 0,
|
||||
LOGICAL_AND,
|
||||
BITWISE_OR,
|
||||
BITWISE_AND,
|
||||
BITWISE_XOR,
|
||||
LEFT_SHIFT,
|
||||
RIGHT_SHIFT,
|
||||
LESS_THAN,
|
||||
GREATER_THAN,
|
||||
LESS_OR_EQUAL,
|
||||
GREATER_OR_EQUAL,
|
||||
EQUAL,
|
||||
NOT_EQUAL,
|
||||
ADD,
|
||||
SUBTRACT,
|
||||
MULTIPLY,
|
||||
DIVIDE,
|
||||
MODULUS,
|
||||
};
|
||||
BinaryOperatorNode(Type type, std::unique_ptr<const Node>&& left, std::unique_ptr<const Node>&& right);
|
||||
virtual ~BinaryOperatorNode() = default;
|
||||
virtual bool operator==(const Node& other) const;
|
||||
virtual int64_t evaluate(const Env& env) const;
|
||||
virtual std::string str() const;
|
||||
|
||||
protected:
|
||||
Type type;
|
||||
std::unique_ptr<const Node> left;
|
||||
std::unique_ptr<const Node> right;
|
||||
};
|
||||
|
||||
class UnaryOperatorNode : public Node {
|
||||
public:
|
||||
enum class Type {
|
||||
LOGICAL_NOT = 0,
|
||||
BITWISE_NOT,
|
||||
NEGATIVE,
|
||||
};
|
||||
UnaryOperatorNode(Type type, std::unique_ptr<const Node>&& sub);
|
||||
virtual ~UnaryOperatorNode() = default;
|
||||
virtual bool operator==(const Node& other) const;
|
||||
virtual int64_t evaluate(const Env& env) const;
|
||||
virtual std::string str() const;
|
||||
|
||||
protected:
|
||||
Type type;
|
||||
std::unique_ptr<const Node> sub;
|
||||
};
|
||||
|
||||
class FlagLookupNode : public Node {
|
||||
public:
|
||||
FlagLookupNode(uint16_t flag_index);
|
||||
virtual ~FlagLookupNode() = default;
|
||||
virtual bool operator==(const Node& other) const;
|
||||
virtual int64_t evaluate(const Env& env) const;
|
||||
virtual std::string str() const;
|
||||
|
||||
protected:
|
||||
uint16_t flag_index;
|
||||
};
|
||||
|
||||
class ChallengeCompletionLookupNode : public Node {
|
||||
public:
|
||||
ChallengeCompletionLookupNode(Episode episode, uint8_t stage_index);
|
||||
virtual ~ChallengeCompletionLookupNode() = default;
|
||||
virtual bool operator==(const Node& other) const;
|
||||
virtual int64_t evaluate(const Env& env) const;
|
||||
virtual std::string str() const;
|
||||
|
||||
protected:
|
||||
Episode episode;
|
||||
uint8_t stage_index;
|
||||
};
|
||||
|
||||
class TeamRewardLookupNode : public Node {
|
||||
public:
|
||||
TeamRewardLookupNode(const std::string& reward_name);
|
||||
virtual ~TeamRewardLookupNode() = default;
|
||||
virtual bool operator==(const Node& other) const;
|
||||
virtual int64_t evaluate(const Env& env) const;
|
||||
virtual std::string str() const;
|
||||
|
||||
protected:
|
||||
std::string reward_name;
|
||||
};
|
||||
|
||||
class NumPlayersLookupNode : public Node {
|
||||
public:
|
||||
NumPlayersLookupNode();
|
||||
virtual ~NumPlayersLookupNode() = default;
|
||||
virtual bool operator==(const Node& other) const;
|
||||
virtual int64_t evaluate(const Env& env) const;
|
||||
virtual std::string str() const;
|
||||
};
|
||||
|
||||
class EventLookupNode : public Node {
|
||||
public:
|
||||
EventLookupNode();
|
||||
virtual ~EventLookupNode() = default;
|
||||
virtual bool operator==(const Node& other) const;
|
||||
virtual int64_t evaluate(const Env& env) const;
|
||||
virtual std::string str() const;
|
||||
};
|
||||
|
||||
class V1PresenceLookupNode : public Node {
|
||||
public:
|
||||
V1PresenceLookupNode();
|
||||
virtual ~V1PresenceLookupNode() = default;
|
||||
virtual bool operator==(const Node& other) const;
|
||||
virtual int64_t evaluate(const Env& env) const;
|
||||
virtual std::string str() const;
|
||||
};
|
||||
|
||||
class ConstantNode : public Node {
|
||||
public:
|
||||
ConstantNode(int64_t value);
|
||||
virtual ~ConstantNode() = default;
|
||||
virtual bool operator==(const Node& other) const;
|
||||
virtual int64_t evaluate(const Env& env) const;
|
||||
virtual std::string str() const;
|
||||
|
||||
protected:
|
||||
int64_t value;
|
||||
};
|
||||
|
||||
std::unique_ptr<const Node> parse_expr(std::string_view text);
|
||||
|
||||
std::unique_ptr<const Node> root;
|
||||
};
|
||||
|
||||
+86
-77
@@ -7,6 +7,17 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
// The favored weapon type table is hardcoded in the game client. The table is:
|
||||
// Viridia shots
|
||||
// Greennill rifles
|
||||
// Skyly swords
|
||||
// Bluefull partisans
|
||||
// Purplenum mechguns
|
||||
// Pinkal canes
|
||||
// Redria (none)
|
||||
// Oran daggers
|
||||
// Yellowboze (none)
|
||||
// Whitill slicers
|
||||
static const array<uint8_t, 10> favored_weapon_by_section_id = {
|
||||
0x09, 0x07, 0x02, 0x04, 0x08, 0x0A, 0xFF, 0x03, 0xFF, 0x05};
|
||||
|
||||
@@ -472,7 +483,7 @@ void ItemCreator::deduplicate_weapon_bonuses(ItemData& item) const {
|
||||
void ItemCreator::set_item_kill_count_if_unsealable(ItemData& item) const {
|
||||
if (this->item_parameter_table->is_unsealable_item(item)) {
|
||||
this->log.info("Item is unsealable; setting kill count to zero");
|
||||
item.set_sealed_item_kill_count(0);
|
||||
item.set_kill_count(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1439,78 +1450,78 @@ vector<ItemData> ItemCreator::generate_weapon_shop_contents(size_t player_level)
|
||||
|
||||
} else {
|
||||
static const vector<pair<uint8_t, uint8_t>> defs({
|
||||
{0x01, 0x00},
|
||||
{0x01, 0x01},
|
||||
{0x01, 0x02},
|
||||
{0x01, 0x03},
|
||||
{0x01, 0x04},
|
||||
{0x03, 0x00},
|
||||
{0x03, 0x01},
|
||||
{0x03, 0x02},
|
||||
{0x03, 0x03},
|
||||
{0x03, 0x04},
|
||||
{0x02, 0x00},
|
||||
{0x02, 0x01},
|
||||
{0x02, 0x02},
|
||||
{0x02, 0x03},
|
||||
{0x02, 0x04},
|
||||
{0x05, 0x00},
|
||||
{0x05, 0x01},
|
||||
{0x05, 0x02},
|
||||
{0x05, 0x03},
|
||||
{0x05, 0x04},
|
||||
{0x04, 0x00},
|
||||
{0x04, 0x01},
|
||||
{0x04, 0x02},
|
||||
{0x04, 0x03},
|
||||
{0x04, 0x04},
|
||||
{0x06, 0x00},
|
||||
{0x06, 0x01},
|
||||
{0x06, 0x02},
|
||||
{0x06, 0x03},
|
||||
{0x06, 0x04},
|
||||
{0x07, 0x00},
|
||||
{0x07, 0x01},
|
||||
{0x07, 0x02},
|
||||
{0x07, 0x03},
|
||||
{0x07, 0x04},
|
||||
{0x08, 0x00},
|
||||
{0x08, 0x01},
|
||||
{0x08, 0x02},
|
||||
{0x08, 0x03},
|
||||
{0x08, 0x04},
|
||||
{0x09, 0x00},
|
||||
{0x09, 0x01},
|
||||
{0x09, 0x02},
|
||||
{0x09, 0x03},
|
||||
{0x09, 0x04},
|
||||
{0x0A, 0x00},
|
||||
{0x0A, 0x01},
|
||||
{0x0A, 0x02},
|
||||
{0x0A, 0x03},
|
||||
{0x0B, 0x00},
|
||||
{0x0B, 0x01},
|
||||
{0x0B, 0x02},
|
||||
{0x0B, 0x03},
|
||||
{0x0C, 0x00},
|
||||
{0x0C, 0x01},
|
||||
{0x0C, 0x02},
|
||||
{0x0C, 0x03},
|
||||
{0xFF, 0xFF},
|
||||
{0xFF, 0xFF},
|
||||
{0x01, 0x05},
|
||||
{0x02, 0x05},
|
||||
{0x06, 0x05},
|
||||
{0x08, 0x05},
|
||||
{0x0A, 0x04},
|
||||
{0x0C, 0x04},
|
||||
{0x0B, 0x04},
|
||||
{0x01, 0x06},
|
||||
{0x03, 0x05},
|
||||
{0x07, 0x05},
|
||||
{0x0A, 0x05},
|
||||
{0x0C, 0x05},
|
||||
{0x0B, 0x05},
|
||||
/* 00 */ {0x01, 0x00},
|
||||
/* 01 */ {0x01, 0x01},
|
||||
/* 02 */ {0x01, 0x02},
|
||||
/* 03 */ {0x01, 0x03},
|
||||
/* 04 */ {0x01, 0x04},
|
||||
/* 05 */ {0x03, 0x00},
|
||||
/* 06 */ {0x03, 0x01},
|
||||
/* 07 */ {0x03, 0x02},
|
||||
/* 08 */ {0x03, 0x03},
|
||||
/* 09 */ {0x03, 0x04},
|
||||
/* 0A */ {0x02, 0x00},
|
||||
/* 0B */ {0x02, 0x01},
|
||||
/* 0C */ {0x02, 0x02},
|
||||
/* 0D */ {0x02, 0x03},
|
||||
/* 0E */ {0x02, 0x04},
|
||||
/* 0F */ {0x05, 0x00},
|
||||
/* 10 */ {0x05, 0x01},
|
||||
/* 11 */ {0x05, 0x02},
|
||||
/* 12 */ {0x05, 0x03},
|
||||
/* 13 */ {0x05, 0x04},
|
||||
/* 14 */ {0x04, 0x00},
|
||||
/* 15 */ {0x04, 0x01},
|
||||
/* 16 */ {0x04, 0x02},
|
||||
/* 17 */ {0x04, 0x03},
|
||||
/* 18 */ {0x04, 0x04},
|
||||
/* 19 */ {0x06, 0x00},
|
||||
/* 1A */ {0x06, 0x01},
|
||||
/* 1B */ {0x06, 0x02},
|
||||
/* 1C */ {0x06, 0x03},
|
||||
/* 1D */ {0x06, 0x04},
|
||||
/* 1E */ {0x07, 0x00},
|
||||
/* 1F */ {0x07, 0x01},
|
||||
/* 20 */ {0x07, 0x02},
|
||||
/* 21 */ {0x07, 0x03},
|
||||
/* 22 */ {0x07, 0x04},
|
||||
/* 23 */ {0x08, 0x00},
|
||||
/* 24 */ {0x08, 0x01},
|
||||
/* 25 */ {0x08, 0x02},
|
||||
/* 26 */ {0x08, 0x03},
|
||||
/* 27 */ {0x08, 0x04},
|
||||
/* 28 */ {0x09, 0x00},
|
||||
/* 29 */ {0x09, 0x01},
|
||||
/* 2A */ {0x09, 0x02},
|
||||
/* 2B */ {0x09, 0x03},
|
||||
/* 2C */ {0x09, 0x04},
|
||||
/* 2D */ {0x0A, 0x00},
|
||||
/* 2E */ {0x0A, 0x01},
|
||||
/* 2F */ {0x0A, 0x02},
|
||||
/* 30 */ {0x0A, 0x03},
|
||||
/* 31 */ {0x0B, 0x00},
|
||||
/* 32 */ {0x0B, 0x01},
|
||||
/* 33 */ {0x0B, 0x02},
|
||||
/* 34 */ {0x0B, 0x03},
|
||||
/* 35 */ {0x0C, 0x00},
|
||||
/* 36 */ {0x0C, 0x01},
|
||||
/* 37 */ {0x0C, 0x02},
|
||||
/* 38 */ {0x0C, 0x03},
|
||||
/* 39 */ {0xFF, 0xFF}, // Special-cased above
|
||||
/* 3A */ {0xFF, 0xFF}, // Special-cased above
|
||||
/* 3B */ {0x01, 0x05},
|
||||
/* 3C */ {0x02, 0x05},
|
||||
/* 3D */ {0x06, 0x05},
|
||||
/* 3E */ {0x08, 0x05},
|
||||
/* 3F */ {0x0A, 0x04},
|
||||
/* 40 */ {0x0C, 0x04},
|
||||
/* 41 */ {0x0B, 0x04},
|
||||
/* 42 */ {0x01, 0x06},
|
||||
/* 43 */ {0x03, 0x05},
|
||||
/* 44 */ {0x07, 0x05},
|
||||
/* 45 */ {0x0A, 0x05},
|
||||
/* 46 */ {0x0C, 0x05},
|
||||
/* 47 */ {0x0B, 0x05},
|
||||
});
|
||||
const auto& def = defs.at(which);
|
||||
item.data1[0] = 0;
|
||||
@@ -1556,10 +1567,8 @@ void ItemCreator::generate_weapon_shop_item_grind(ItemData& item, size_t player_
|
||||
? this->weapon_random_set->get_favored_grind_range(table_index)
|
||||
: this->weapon_random_set->get_standard_grind_range(table_index);
|
||||
|
||||
const auto& weapon_def = this->item_parameter_table->get_weapon(
|
||||
item.data1[1], item.data1[2]);
|
||||
item.data1[3] = clamp<uint8_t>(
|
||||
this->rand_int(range->max + 1), range->min, weapon_def.max_grind);
|
||||
const auto& weapon_def = this->item_parameter_table->get_weapon(item.data1[1], item.data1[2]);
|
||||
item.data1[3] = clamp<uint8_t>(this->rand_int(range->max + 1), range->min, weapon_def.max_grind);
|
||||
}
|
||||
|
||||
void ItemCreator::generate_weapon_shop_item_special(ItemData& item, size_t player_level) {
|
||||
|
||||
@@ -83,6 +83,24 @@ private:
|
||||
|
||||
// Note: The original implementation uses 17 different random states for some
|
||||
// reason. We forego that and use only one for simplicity.
|
||||
// Originally, the 17 random states were used for:
|
||||
// [0x00] - drop-anything rate check
|
||||
// [0x01] - common item class check
|
||||
// [0x02] - get_rand_from_weighted_tables16 determinants
|
||||
// [0x03] - get_rand_from_weighted_tables8 determinants
|
||||
// [0x04] - tech disk levels
|
||||
// [0x05] - meseta amounts
|
||||
// [0x06] - rare drop rate check
|
||||
// [0x07] - rare weapon special table index
|
||||
// [0x08] - apparently unused
|
||||
// [0x09] - whether to generate a common weapon special
|
||||
// [0x0A] - number of stars for common weapon special
|
||||
// [0x0B] - unit modifiers
|
||||
// [0x0C] - common armor DFP bonuses
|
||||
// [0x0D] - common armor EVP bonuses
|
||||
// [0x0E] - apparently unused
|
||||
// [0x0F] - which common weapon special to generate
|
||||
// [0x10] - apparently unused
|
||||
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt;
|
||||
|
||||
bool are_rare_drops_allowed() const;
|
||||
|
||||
+18
-9
@@ -431,7 +431,10 @@ void ItemData::decode_for_version(Version from_version) {
|
||||
}
|
||||
|
||||
void ItemData::encode_for_version(Version to_version, shared_ptr<const ItemParameterTable> item_parameter_table) {
|
||||
bool should_encode_v2_data = (is_v1(to_version) || is_v2(to_version)) && (to_version != Version::GC_NTE) && !this->has_encoded_v2_data();
|
||||
bool should_encode_v2_data = item_parameter_table &&
|
||||
(is_v1(to_version) || is_v2(to_version)) &&
|
||||
(to_version != Version::GC_NTE) &&
|
||||
!this->has_encoded_v2_data();
|
||||
|
||||
switch (this->data1[0]) {
|
||||
case 0x00:
|
||||
@@ -534,16 +537,22 @@ bool ItemData::has_encoded_v2_data() const {
|
||||
: (this->get_encoded_v2_data() != 0);
|
||||
}
|
||||
|
||||
uint16_t ItemData::get_sealed_item_kill_count() const {
|
||||
return ((this->data1[10] << 8) | this->data1[11]) & 0x7FFF;
|
||||
bool ItemData::has_kill_count() const {
|
||||
return !this->is_s_rank_weapon() && (this->data1[10] & 0x80);
|
||||
}
|
||||
|
||||
void ItemData::set_sealed_item_kill_count(uint16_t v) {
|
||||
if (v > 0x7FFF) {
|
||||
this->data1w[5] = 0xFFFF;
|
||||
} else {
|
||||
this->data1[10] = (v >> 8) | 0x80;
|
||||
this->data1[11] = v;
|
||||
uint16_t ItemData::get_kill_count() const {
|
||||
return this->has_kill_count() ? (((this->data1[10] << 8) | this->data1[11]) & 0x7FFF) : 0;
|
||||
}
|
||||
|
||||
void ItemData::set_kill_count(uint16_t v) {
|
||||
if (!this->is_s_rank_weapon()) {
|
||||
if (v > 0x7FFF) {
|
||||
this->data1w[5] = 0xFFFF;
|
||||
} else {
|
||||
this->data1[10] = (v >> 8) | 0x80;
|
||||
this->data1[11] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -84,6 +84,7 @@ struct ItemData {
|
||||
// Mag: 02ZZLLWW HHHHIIII JJJJKKKK YYQQPPVV
|
||||
// Tool: 03ZZZZFF 00CC0000 00000000 00000000
|
||||
// Meseta: 04000000 00000000 00000000 MMMMMMMM
|
||||
// 01034D00 00000000 204E0000
|
||||
// A = attribute type (for S-ranks, custom name)
|
||||
// B = attribute amount (for S-ranks, custom name)
|
||||
// C = stack size (for tools)
|
||||
@@ -173,8 +174,9 @@ struct ItemData {
|
||||
uint8_t get_encoded_v2_data() const;
|
||||
bool has_encoded_v2_data() const;
|
||||
|
||||
uint16_t get_sealed_item_kill_count() const;
|
||||
void set_sealed_item_kill_count(uint16_t v);
|
||||
bool has_kill_count() const;
|
||||
uint16_t get_kill_count() const;
|
||||
void set_kill_count(uint16_t v);
|
||||
uint8_t get_tool_item_amount(const StackLimits& limits) const;
|
||||
void set_tool_item_amount(const StackLimits& limits, uint8_t amount);
|
||||
int16_t get_armor_or_shield_defense_bonus() const;
|
||||
|
||||
+11
-7
@@ -208,7 +208,10 @@ std::string ItemNameIndex::describe_item(const ItemData& item, bool include_colo
|
||||
if (which == 0) {
|
||||
continue;
|
||||
}
|
||||
if (which > 5) {
|
||||
if (which & 0x80) {
|
||||
uint16_t kill_count = ((which << 8) & 0x7F00) | (value & 0xFF);
|
||||
ret_tokens.emplace_back(string_printf("K:%hu", kill_count));
|
||||
} else if (which > 5) {
|
||||
ret_tokens.emplace_back(string_printf("!PC:%02hhX%02hhX", which, value));
|
||||
} else {
|
||||
bonuses[which - 1] = value;
|
||||
@@ -217,13 +220,14 @@ std::string ItemNameIndex::describe_item(const ItemData& item, bool include_colo
|
||||
if (!bonuses.is_filled_with(0)) {
|
||||
bool should_include_hit = (bonuses[4] != 0);
|
||||
bool should_highlight_hit = include_color_escapes && (bonuses[4] > 0);
|
||||
const char* color_prefix = include_color_escapes ? "$C7" : "";
|
||||
if (should_include_hit) {
|
||||
ret_tokens.emplace_back(string_printf("%hhd/%hhd/%hhd/%hhd/%s%hhd",
|
||||
bonuses[0], bonuses[1], bonuses[2], bonuses[3],
|
||||
(should_highlight_hit ? "$CG" : ""), bonuses[4]));
|
||||
ret_tokens.emplace_back(string_printf("%s%hhd/%hhd/%hhd/%hhd/%s%hhd",
|
||||
color_prefix, bonuses[0], bonuses[1], bonuses[2], bonuses[3],
|
||||
(should_highlight_hit ? "$C6" : ""), bonuses[4]));
|
||||
} else {
|
||||
ret_tokens.emplace_back(string_printf("%hhd/%hhd/%hhd/%hhd",
|
||||
bonuses[0], bonuses[1], bonuses[2], bonuses[3]));
|
||||
ret_tokens.emplace_back(string_printf("%s%hhd/%hhd/%hhd/%hhd",
|
||||
color_prefix, bonuses[0], bonuses[1], bonuses[2], bonuses[3]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -848,7 +852,7 @@ void ItemNameIndex::print_table(FILE* stream) const {
|
||||
t.amount.load(),
|
||||
t.tech.load(),
|
||||
t.cost.load(),
|
||||
t.item_flag.load(),
|
||||
t.item_flags.load(),
|
||||
stars,
|
||||
divisor_str.c_str(),
|
||||
name.c_str());
|
||||
|
||||
@@ -397,7 +397,7 @@ ItemParameterTable::ToolV4 ItemParameterTable::ToolV1V2::to_v4() const {
|
||||
ret.amount = this->amount;
|
||||
ret.tech = this->tech;
|
||||
ret.cost = this->cost;
|
||||
ret.item_flag = this->item_flag;
|
||||
ret.item_flags = this->item_flags;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -410,7 +410,7 @@ ItemParameterTable::ToolV4 ItemParameterTable::ToolV3T<IsBigEndian>::to_v4() con
|
||||
ret.amount = this->amount.load();
|
||||
ret.tech = this->tech.load();
|
||||
ret.cost = this->cost.load();
|
||||
ret.item_flag = this->item_flag.load();
|
||||
ret.item_flags = this->item_flags.load();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1008,7 +1008,7 @@ uint8_t ItemParameterTable::get_item_base_stars(const ItemData& item) const {
|
||||
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;
|
||||
return (def.item_flags & 0x80) ? 12 : 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -341,7 +341,16 @@ public:
|
||||
/* 04 */ U16T amount = 0;
|
||||
/* 06 */ U16T tech = 0;
|
||||
/* 08 */ S32T cost = 0;
|
||||
/* 0C */ U32T item_flag = 0;
|
||||
// Bits in item_flags:
|
||||
// 00000001 - ever usable by player ("Use" appears in inventory menu)
|
||||
// 00000002 - unknown
|
||||
// 00000004 - unknown
|
||||
// 00000008 - usable by android characters
|
||||
// 00000010 - usable in Pioneer 2 / Lab
|
||||
// 00000020 - usable in boss arenas
|
||||
// 00000040 - usable in Challenge mode
|
||||
// 00000080 - is rare (renders as red box; V3+)
|
||||
/* 0C */ U32T item_flags = 0;
|
||||
/* 10 */
|
||||
} __packed__;
|
||||
|
||||
|
||||
+513
-505
File diff suppressed because it is too large
Load Diff
+25
-25
@@ -1,25 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <random>
|
||||
|
||||
#include "Client.hh"
|
||||
#include "ItemData.hh"
|
||||
#include "ItemParameterTable.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "ServerState.hh"
|
||||
#include "StaticGameData.hh"
|
||||
|
||||
void player_use_item(std::shared_ptr<Client> c, size_t item_index, std::shared_ptr<PSOLFGEncryption> opt_rand_crypt);
|
||||
void player_feed_mag(std::shared_ptr<Client> c, size_t mag_item_index, size_t fed_item_index);
|
||||
|
||||
void apply_mag_feed_result(
|
||||
ItemData& mag_item,
|
||||
const ItemData& fed_item,
|
||||
std::shared_ptr<const ItemParameterTable> item_parameter_table,
|
||||
std::shared_ptr<const MagEvolutionTable> mag_evolution_table,
|
||||
uint8_t char_class,
|
||||
uint8_t section_id,
|
||||
bool version_has_rare_mags);
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <random>
|
||||
|
||||
#include "Client.hh"
|
||||
#include "ItemData.hh"
|
||||
#include "ItemParameterTable.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "ServerState.hh"
|
||||
#include "StaticGameData.hh"
|
||||
|
||||
void player_use_item(std::shared_ptr<Client> c, size_t item_index, std::shared_ptr<PSOLFGEncryption> opt_rand_crypt);
|
||||
void player_feed_mag(std::shared_ptr<Client> c, size_t mag_item_index, size_t fed_item_index);
|
||||
|
||||
void apply_mag_feed_result(
|
||||
ItemData& mag_item,
|
||||
const ItemData& fed_item,
|
||||
std::shared_ptr<const ItemParameterTable> item_parameter_table,
|
||||
std::shared_ptr<const MagEvolutionTable> mag_evolution_table,
|
||||
uint8_t char_class,
|
||||
uint8_t section_id,
|
||||
bool version_has_rare_mags);
|
||||
|
||||
+190
-190
@@ -1,190 +1,190 @@
|
||||
#include "LevelTable.hh"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <phosg/Filesystem.hh>
|
||||
|
||||
#include "Compression.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void LevelTable::reset_to_base(PlayerStats& stats, uint8_t char_class) const {
|
||||
stats.level = 0;
|
||||
stats.experience = 0;
|
||||
stats.char_stats = this->base_stats_for_class(char_class);
|
||||
}
|
||||
|
||||
void LevelTable::advance_to_level(PlayerStats& stats, uint32_t level, uint8_t char_class) const {
|
||||
for (; stats.level < level; stats.level++) {
|
||||
const auto& level_stats = this->stats_delta_for_level(char_class, stats.level + 1);
|
||||
// The original code clamps the resulting stat values to [0, max_stat]; we
|
||||
// don't have max_stat handy so we just allow them to be unbounded
|
||||
stats.char_stats.atp += level_stats.atp;
|
||||
stats.char_stats.mst += level_stats.mst;
|
||||
stats.char_stats.evp += level_stats.evp;
|
||||
stats.char_stats.hp += level_stats.hp;
|
||||
stats.char_stats.dfp += level_stats.dfp;
|
||||
stats.char_stats.ata += level_stats.ata;
|
||||
// Note: It is not a bug that lck is ignored here; the original code
|
||||
// ignores it too.
|
||||
stats.experience = level_stats.experience;
|
||||
}
|
||||
}
|
||||
|
||||
LevelTableV2::LevelTableV2(const string& data, bool compressed) {
|
||||
struct Offsets {
|
||||
// TODO: The overall format of this file on V2 has much more data than we
|
||||
// actually use. What's known of the structure so far:
|
||||
le_uint32_t level_deltas; // -> u32[9] -> LevelStatsDelta[200]
|
||||
le_uint32_t unknown_a1; // -> float[6]
|
||||
le_uint32_t max_stats; // -> PlayerStats[9]
|
||||
le_uint32_t level_100_stats; // -> Level100Entry[9]
|
||||
le_uint32_t base_stats; // -> u32[9] -> CharacterStats
|
||||
le_uint32_t unknown_a2; // -> (0x120 zero bytes)
|
||||
le_uint32_t attack_data; // -> AttackData[9]
|
||||
le_uint32_t unknown_a4; // -> (0x14-byte struct)[9]
|
||||
le_uint32_t unknown_a5; // -> float[9]
|
||||
le_uint32_t unknown_a6; // -> (0x30 bytes)
|
||||
le_uint32_t unknown_a7; // -> (0x2D bytes)
|
||||
le_uint32_t unknown_a8; // -> u32[3] -> float[0x2D]
|
||||
le_uint32_t unknown_a9; // -> (0x90 bytes)
|
||||
le_uint32_t unknown_a10; // -> u32[3] -> (0x10-byte struct)[0x0C]
|
||||
le_uint32_t unknown_a11; // -> u32[3] -> (0x30-bytes)
|
||||
le_uint32_t unknown_a12; // -> u32[3] -> (0x14-byte struct)[0x0F]
|
||||
} __packed_ws__(Offsets, 0x40);
|
||||
|
||||
StringReader r;
|
||||
string decompressed_data;
|
||||
if (compressed) {
|
||||
decompressed_data = prs_decompress(data);
|
||||
r = StringReader(decompressed_data);
|
||||
} else {
|
||||
r = StringReader(data);
|
||||
}
|
||||
|
||||
const auto& offsets = r.pget<Offsets>(r.pget_u32l(r.size() - 0x10));
|
||||
const auto& level_deltas_offsets = r.pget<parray<le_uint32_t, 9>>(offsets.level_deltas);
|
||||
const auto& base_stats_offsets = r.pget<parray<le_uint32_t, 9>>(offsets.base_stats);
|
||||
for (size_t char_class = 0; char_class < 9; char_class++) {
|
||||
const auto& src_level_deltas = r.pget<parray<LevelStatsDelta, 200>>(level_deltas_offsets[char_class]);
|
||||
for (size_t level = 0; level < 200; level++) {
|
||||
this->level_deltas[char_class][level] = src_level_deltas[level];
|
||||
}
|
||||
this->max_stats[char_class] = r.pget<PlayerStats>(offsets.max_stats + char_class * sizeof(PlayerStats));
|
||||
this->level_100_stats[char_class] = r.pget<Level100Entry>(offsets.level_100_stats + char_class * sizeof(Level100Entry));
|
||||
this->base_stats[char_class] = r.pget<CharacterStats>(base_stats_offsets[char_class]);
|
||||
}
|
||||
}
|
||||
|
||||
const CharacterStats& LevelTableV2::base_stats_for_class(uint8_t char_class) const {
|
||||
return this->base_stats.at(char_class);
|
||||
}
|
||||
|
||||
const LevelTableV2::Level100Entry& LevelTableV2::level_100_stats_for_class(uint8_t char_class) const {
|
||||
return this->level_100_stats.at(char_class);
|
||||
}
|
||||
|
||||
const PlayerStats& LevelTableV2::max_stats_for_class(uint8_t char_class) const {
|
||||
return this->max_stats.at(char_class);
|
||||
}
|
||||
|
||||
const LevelStatsDelta& LevelTableV2::stats_delta_for_level(uint8_t char_class, uint8_t level) const {
|
||||
return this->level_deltas.at(char_class).at(level);
|
||||
}
|
||||
|
||||
LevelTableV3BE::LevelTableV3BE(const string& data, bool encrypted) {
|
||||
StringReader r;
|
||||
string decompressed_data;
|
||||
if (encrypted) {
|
||||
auto decrypted = decrypt_pr2_data<true>(data);
|
||||
decompressed_data = prs_decompress(decrypted.compressed_data);
|
||||
if (decompressed_data.size() != decrypted.decompressed_size) {
|
||||
throw runtime_error("decompressed data size does not match expected size");
|
||||
}
|
||||
r = StringReader(decompressed_data);
|
||||
} else {
|
||||
r = StringReader(data);
|
||||
}
|
||||
|
||||
// The GC format is very simple (but everything is big-endian):
|
||||
// root:
|
||||
// u32 offset:
|
||||
// u32[12] offsets:
|
||||
// LevelStatsDeltaBE[200] level_deltas
|
||||
const auto& offsets = r.pget<parray<be_uint32_t, 12>>(r.pget_u32b(r.pget_u32b(r.size() - 0x10)));
|
||||
for (size_t char_class = 0; char_class < 12; char_class++) {
|
||||
const auto& src_deltas = r.pget<parray<LevelStatsDeltaBE, 200>>(offsets[char_class]);
|
||||
for (size_t level = 0; level < 200; level++) {
|
||||
const auto& src_delta = src_deltas[level];
|
||||
auto& dest_delta = this->level_deltas[char_class][level];
|
||||
dest_delta.atp = src_delta.atp;
|
||||
dest_delta.mst = src_delta.mst;
|
||||
dest_delta.evp = src_delta.evp;
|
||||
dest_delta.hp = src_delta.hp;
|
||||
dest_delta.dfp = src_delta.dfp;
|
||||
dest_delta.ata = src_delta.ata;
|
||||
dest_delta.lck = src_delta.lck;
|
||||
dest_delta.tp = src_delta.tp;
|
||||
dest_delta.experience = src_delta.experience.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const CharacterStats& LevelTableV3BE::base_stats_for_class(uint8_t char_class) const {
|
||||
static const array<CharacterStats, 12> data = {
|
||||
// ATP MST EVP HP DFP ATA LCK
|
||||
CharacterStats{0x0023, 0x001D, 0x002D, 0x0014, 0x0011, 0x001E, 0x000A},
|
||||
CharacterStats{0x001E, 0x0028, 0x003C, 0x0013, 0x0016, 0x0019, 0x000A},
|
||||
CharacterStats{0x0023, 0x0000, 0x0023, 0x0016, 0x0012, 0x0023, 0x000A},
|
||||
CharacterStats{0x0012, 0x0014, 0x0024, 0x0010, 0x000D, 0x0028, 0x000A},
|
||||
CharacterStats{0x0019, 0x0000, 0x001F, 0x0012, 0x0012, 0x002D, 0x000A},
|
||||
CharacterStats{0x0014, 0x0000, 0x001F, 0x0011, 0x0017, 0x002D, 0x000A},
|
||||
CharacterStats{0x000D, 0x0035, 0x0023, 0x0014, 0x000A, 0x000F, 0x000A},
|
||||
CharacterStats{0x000D, 0x003C, 0x0032, 0x0013, 0x0007, 0x000C, 0x000A},
|
||||
CharacterStats{0x000A, 0x003A, 0x0035, 0x0013, 0x000D, 0x000A, 0x000A},
|
||||
CharacterStats{0x0023, 0x0000, 0x0023, 0x0016, 0x0012, 0x0023, 0x000A},
|
||||
CharacterStats{0x000D, 0x0035, 0x0023, 0x0014, 0x000A, 0x000F, 0x000A},
|
||||
CharacterStats{0x0012, 0x0014, 0x0024, 0x0010, 0x000D, 0x0028, 0x000A},
|
||||
};
|
||||
return data.at(char_class);
|
||||
}
|
||||
|
||||
const LevelStatsDelta& LevelTableV3BE::stats_delta_for_level(uint8_t char_class, uint8_t level) const {
|
||||
return this->level_deltas.at(char_class).at(level);
|
||||
}
|
||||
|
||||
LevelTableV4::LevelTableV4(const string& data, bool compressed) {
|
||||
struct Offsets {
|
||||
le_uint32_t base_stats; // -> u32[12] -> CharacterStats
|
||||
le_uint32_t level_deltas; // -> u32[12] -> LevelStatsDelta[200]
|
||||
} __packed_ws__(Offsets, 8);
|
||||
|
||||
StringReader r;
|
||||
string decompressed_data;
|
||||
if (compressed) {
|
||||
decompressed_data = prs_decompress(data);
|
||||
r = StringReader(decompressed_data);
|
||||
} else {
|
||||
r = StringReader(data);
|
||||
}
|
||||
|
||||
const auto& offsets = r.pget<Offsets>(r.pget_u32l(r.size() - 0x10));
|
||||
const auto& level_deltas_offsets = r.pget<parray<le_uint32_t, 12>>(offsets.level_deltas);
|
||||
const auto& base_stats_offsets = r.pget<parray<le_uint32_t, 12>>(offsets.base_stats);
|
||||
for (size_t char_class = 0; char_class < 12; char_class++) {
|
||||
const auto& src_level_deltas = r.pget<parray<LevelStatsDelta, 200>>(level_deltas_offsets[char_class]);
|
||||
for (size_t level = 0; level < 200; level++) {
|
||||
this->level_deltas[char_class][level] = src_level_deltas[level];
|
||||
}
|
||||
this->base_stats[char_class] = r.pget<CharacterStats>(base_stats_offsets[char_class]);
|
||||
}
|
||||
}
|
||||
|
||||
const CharacterStats& LevelTableV4::base_stats_for_class(uint8_t char_class) const {
|
||||
return this->base_stats.at(char_class);
|
||||
}
|
||||
|
||||
const LevelStatsDelta& LevelTableV4::stats_delta_for_level(uint8_t char_class, uint8_t level) const {
|
||||
return this->level_deltas.at(char_class).at(level);
|
||||
}
|
||||
#include "LevelTable.hh"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <phosg/Filesystem.hh>
|
||||
|
||||
#include "Compression.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void LevelTable::reset_to_base(PlayerStats& stats, uint8_t char_class) const {
|
||||
stats.level = 0;
|
||||
stats.experience = 0;
|
||||
stats.char_stats = this->base_stats_for_class(char_class);
|
||||
}
|
||||
|
||||
void LevelTable::advance_to_level(PlayerStats& stats, uint32_t level, uint8_t char_class) const {
|
||||
for (; stats.level < level; stats.level++) {
|
||||
const auto& level_stats = this->stats_delta_for_level(char_class, stats.level + 1);
|
||||
// The original code clamps the resulting stat values to [0, max_stat]; we
|
||||
// don't have max_stat handy so we just allow them to be unbounded
|
||||
stats.char_stats.atp += level_stats.atp;
|
||||
stats.char_stats.mst += level_stats.mst;
|
||||
stats.char_stats.evp += level_stats.evp;
|
||||
stats.char_stats.hp += level_stats.hp;
|
||||
stats.char_stats.dfp += level_stats.dfp;
|
||||
stats.char_stats.ata += level_stats.ata;
|
||||
// Note: It is not a bug that lck is ignored here; the original code
|
||||
// ignores it too.
|
||||
stats.experience = level_stats.experience;
|
||||
}
|
||||
}
|
||||
|
||||
LevelTableV2::LevelTableV2(const string& data, bool compressed) {
|
||||
struct Offsets {
|
||||
// TODO: The overall format of this file on V2 has much more data than we
|
||||
// actually use. What's known of the structure so far:
|
||||
le_uint32_t level_deltas; // -> u32[9] -> LevelStatsDelta[200]
|
||||
le_uint32_t unknown_a1; // -> float[6]
|
||||
le_uint32_t max_stats; // -> PlayerStats[9]
|
||||
le_uint32_t level_100_stats; // -> Level100Entry[9]
|
||||
le_uint32_t base_stats; // -> u32[9] -> CharacterStats
|
||||
le_uint32_t unknown_a2; // -> (0x120 zero bytes)
|
||||
le_uint32_t attack_data; // -> AttackData[9]
|
||||
le_uint32_t unknown_a4; // -> (0x14-byte struct)[9]
|
||||
le_uint32_t unknown_a5; // -> float[9]
|
||||
le_uint32_t unknown_a6; // -> (0x30 bytes)
|
||||
le_uint32_t unknown_a7; // -> (0x2D bytes)
|
||||
le_uint32_t unknown_a8; // -> u32[3] -> float[0x2D]
|
||||
le_uint32_t unknown_a9; // -> (0x90 bytes)
|
||||
le_uint32_t unknown_a10; // -> u32[3] -> (0x10-byte struct)[0x0C]
|
||||
le_uint32_t unknown_a11; // -> u32[3] -> (0x30-bytes)
|
||||
le_uint32_t unknown_a12; // -> u32[3] -> (0x14-byte struct)[0x0F]
|
||||
} __packed_ws__(Offsets, 0x40);
|
||||
|
||||
StringReader r;
|
||||
string decompressed_data;
|
||||
if (compressed) {
|
||||
decompressed_data = prs_decompress(data);
|
||||
r = StringReader(decompressed_data);
|
||||
} else {
|
||||
r = StringReader(data);
|
||||
}
|
||||
|
||||
const auto& offsets = r.pget<Offsets>(r.pget_u32l(r.size() - 0x10));
|
||||
const auto& level_deltas_offsets = r.pget<parray<le_uint32_t, 9>>(offsets.level_deltas);
|
||||
const auto& base_stats_offsets = r.pget<parray<le_uint32_t, 9>>(offsets.base_stats);
|
||||
for (size_t char_class = 0; char_class < 9; char_class++) {
|
||||
const auto& src_level_deltas = r.pget<parray<LevelStatsDelta, 200>>(level_deltas_offsets[char_class]);
|
||||
for (size_t level = 0; level < 200; level++) {
|
||||
this->level_deltas[char_class][level] = src_level_deltas[level];
|
||||
}
|
||||
this->max_stats[char_class] = r.pget<PlayerStats>(offsets.max_stats + char_class * sizeof(PlayerStats));
|
||||
this->level_100_stats[char_class] = r.pget<Level100Entry>(offsets.level_100_stats + char_class * sizeof(Level100Entry));
|
||||
this->base_stats[char_class] = r.pget<CharacterStats>(base_stats_offsets[char_class]);
|
||||
}
|
||||
}
|
||||
|
||||
const CharacterStats& LevelTableV2::base_stats_for_class(uint8_t char_class) const {
|
||||
return this->base_stats.at(char_class);
|
||||
}
|
||||
|
||||
const LevelTableV2::Level100Entry& LevelTableV2::level_100_stats_for_class(uint8_t char_class) const {
|
||||
return this->level_100_stats.at(char_class);
|
||||
}
|
||||
|
||||
const PlayerStats& LevelTableV2::max_stats_for_class(uint8_t char_class) const {
|
||||
return this->max_stats.at(char_class);
|
||||
}
|
||||
|
||||
const LevelStatsDelta& LevelTableV2::stats_delta_for_level(uint8_t char_class, uint8_t level) const {
|
||||
return this->level_deltas.at(char_class).at(level);
|
||||
}
|
||||
|
||||
LevelTableV3BE::LevelTableV3BE(const string& data, bool encrypted) {
|
||||
StringReader r;
|
||||
string decompressed_data;
|
||||
if (encrypted) {
|
||||
auto decrypted = decrypt_pr2_data<true>(data);
|
||||
decompressed_data = prs_decompress(decrypted.compressed_data);
|
||||
if (decompressed_data.size() != decrypted.decompressed_size) {
|
||||
throw runtime_error("decompressed data size does not match expected size");
|
||||
}
|
||||
r = StringReader(decompressed_data);
|
||||
} else {
|
||||
r = StringReader(data);
|
||||
}
|
||||
|
||||
// The GC format is very simple (but everything is big-endian):
|
||||
// root:
|
||||
// u32 offset:
|
||||
// u32[12] offsets:
|
||||
// LevelStatsDeltaBE[200] level_deltas
|
||||
const auto& offsets = r.pget<parray<be_uint32_t, 12>>(r.pget_u32b(r.pget_u32b(r.size() - 0x10)));
|
||||
for (size_t char_class = 0; char_class < 12; char_class++) {
|
||||
const auto& src_deltas = r.pget<parray<LevelStatsDeltaBE, 200>>(offsets[char_class]);
|
||||
for (size_t level = 0; level < 200; level++) {
|
||||
const auto& src_delta = src_deltas[level];
|
||||
auto& dest_delta = this->level_deltas[char_class][level];
|
||||
dest_delta.atp = src_delta.atp;
|
||||
dest_delta.mst = src_delta.mst;
|
||||
dest_delta.evp = src_delta.evp;
|
||||
dest_delta.hp = src_delta.hp;
|
||||
dest_delta.dfp = src_delta.dfp;
|
||||
dest_delta.ata = src_delta.ata;
|
||||
dest_delta.lck = src_delta.lck;
|
||||
dest_delta.tp = src_delta.tp;
|
||||
dest_delta.experience = src_delta.experience.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const CharacterStats& LevelTableV3BE::base_stats_for_class(uint8_t char_class) const {
|
||||
static const array<CharacterStats, 12> data = {
|
||||
// ATP MST EVP HP DFP ATA LCK
|
||||
CharacterStats{0x0023, 0x001D, 0x002D, 0x0014, 0x0011, 0x001E, 0x000A},
|
||||
CharacterStats{0x001E, 0x0028, 0x003C, 0x0013, 0x0016, 0x0019, 0x000A},
|
||||
CharacterStats{0x0023, 0x0000, 0x0023, 0x0016, 0x0012, 0x0023, 0x000A},
|
||||
CharacterStats{0x0012, 0x0014, 0x0024, 0x0010, 0x000D, 0x0028, 0x000A},
|
||||
CharacterStats{0x0019, 0x0000, 0x001F, 0x0012, 0x0012, 0x002D, 0x000A},
|
||||
CharacterStats{0x0014, 0x0000, 0x001F, 0x0011, 0x0017, 0x002D, 0x000A},
|
||||
CharacterStats{0x000D, 0x0035, 0x0023, 0x0014, 0x000A, 0x000F, 0x000A},
|
||||
CharacterStats{0x000D, 0x003C, 0x0032, 0x0013, 0x0007, 0x000C, 0x000A},
|
||||
CharacterStats{0x000A, 0x003A, 0x0035, 0x0013, 0x000D, 0x000A, 0x000A},
|
||||
CharacterStats{0x0023, 0x0000, 0x0023, 0x0016, 0x0012, 0x0023, 0x000A},
|
||||
CharacterStats{0x000D, 0x0035, 0x0023, 0x0014, 0x000A, 0x000F, 0x000A},
|
||||
CharacterStats{0x0012, 0x0014, 0x0024, 0x0010, 0x000D, 0x0028, 0x000A},
|
||||
};
|
||||
return data.at(char_class);
|
||||
}
|
||||
|
||||
const LevelStatsDelta& LevelTableV3BE::stats_delta_for_level(uint8_t char_class, uint8_t level) const {
|
||||
return this->level_deltas.at(char_class).at(level);
|
||||
}
|
||||
|
||||
LevelTableV4::LevelTableV4(const string& data, bool compressed) {
|
||||
struct Offsets {
|
||||
le_uint32_t base_stats; // -> u32[12] -> CharacterStats
|
||||
le_uint32_t level_deltas; // -> u32[12] -> LevelStatsDelta[200]
|
||||
} __packed_ws__(Offsets, 8);
|
||||
|
||||
StringReader r;
|
||||
string decompressed_data;
|
||||
if (compressed) {
|
||||
decompressed_data = prs_decompress(data);
|
||||
r = StringReader(decompressed_data);
|
||||
} else {
|
||||
r = StringReader(data);
|
||||
}
|
||||
|
||||
const auto& offsets = r.pget<Offsets>(r.pget_u32l(r.size() - 0x10));
|
||||
const auto& level_deltas_offsets = r.pget<parray<le_uint32_t, 12>>(offsets.level_deltas);
|
||||
const auto& base_stats_offsets = r.pget<parray<le_uint32_t, 12>>(offsets.base_stats);
|
||||
for (size_t char_class = 0; char_class < 12; char_class++) {
|
||||
const auto& src_level_deltas = r.pget<parray<LevelStatsDelta, 200>>(level_deltas_offsets[char_class]);
|
||||
for (size_t level = 0; level < 200; level++) {
|
||||
this->level_deltas[char_class][level] = src_level_deltas[level];
|
||||
}
|
||||
this->base_stats[char_class] = r.pget<CharacterStats>(base_stats_offsets[char_class]);
|
||||
}
|
||||
}
|
||||
|
||||
const CharacterStats& LevelTableV4::base_stats_for_class(uint8_t char_class) const {
|
||||
return this->base_stats.at(char_class);
|
||||
}
|
||||
|
||||
const LevelStatsDelta& LevelTableV4::stats_delta_for_level(uint8_t char_class, uint8_t level) const {
|
||||
return this->level_deltas.at(char_class).at(level);
|
||||
}
|
||||
|
||||
+173
-173
@@ -1,173 +1,173 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <string>
|
||||
|
||||
#include "Text.hh"
|
||||
|
||||
class LevelTable;
|
||||
|
||||
template <bool IsBigEndian>
|
||||
struct CharacterStatsT {
|
||||
using U16T = typename std::conditional<IsBigEndian, be_uint16_t, le_uint16_t>::type;
|
||||
|
||||
/* 00 */ U16T atp = 0;
|
||||
/* 02 */ U16T mst = 0;
|
||||
/* 04 */ U16T evp = 0;
|
||||
/* 06 */ U16T hp = 0;
|
||||
/* 08 */ U16T dfp = 0;
|
||||
/* 0A */ U16T ata = 0;
|
||||
/* 0C */ U16T lck = 0;
|
||||
/* 0E */
|
||||
|
||||
operator CharacterStatsT<!IsBigEndian>() const {
|
||||
CharacterStatsT<!IsBigEndian> ret;
|
||||
ret.atp = this->atp.load();
|
||||
ret.mst = this->mst.load();
|
||||
ret.evp = this->evp.load();
|
||||
ret.hp = this->hp.load();
|
||||
ret.dfp = this->dfp.load();
|
||||
ret.ata = this->ata.load();
|
||||
ret.lck = this->lck.load();
|
||||
return ret;
|
||||
}
|
||||
} __packed__;
|
||||
using CharacterStats = CharacterStatsT<false>;
|
||||
using CharacterStatsBE = CharacterStatsT<true>;
|
||||
check_struct_size(CharacterStats, 0x0E);
|
||||
check_struct_size(CharacterStatsBE, 0x0E);
|
||||
|
||||
template <bool IsBigEndian>
|
||||
struct PlayerStatsT {
|
||||
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;
|
||||
using F32T = typename std::conditional<IsBigEndian, be_float, le_float>::type;
|
||||
|
||||
/* 00 */ CharacterStatsT<IsBigEndian> char_stats;
|
||||
/* 0E */ U16T esp = 0;
|
||||
/* 10 */ F32T height = 0.0;
|
||||
/* 14 */ F32T unknown_a3 = 0.0;
|
||||
/* 18 */ U32T level = 0;
|
||||
/* 1C */ U32T experience = 0;
|
||||
/* 20 */ U32T meseta = 0;
|
||||
/* 24 */
|
||||
|
||||
operator PlayerStatsT<!IsBigEndian>() const {
|
||||
PlayerStatsT<!IsBigEndian> ret;
|
||||
ret.char_stats = this->char_stats;
|
||||
ret.esp = this->esp.load();
|
||||
ret.height = this->height.load();
|
||||
ret.unknown_a3 = this->unknown_a3.load();
|
||||
ret.level = this->level.load();
|
||||
ret.experience = this->experience.load();
|
||||
ret.meseta = this->meseta.load();
|
||||
return ret;
|
||||
}
|
||||
} __packed__;
|
||||
using PlayerStats = PlayerStatsT<false>;
|
||||
using PlayerStatsBE = PlayerStatsT<true>;
|
||||
check_struct_size(PlayerStats, 0x24);
|
||||
check_struct_size(PlayerStatsBE, 0x24);
|
||||
|
||||
template <bool IsBigEndian>
|
||||
struct LevelStatsDeltaT {
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
|
||||
/* 00 */ uint8_t atp;
|
||||
/* 01 */ uint8_t mst;
|
||||
/* 02 */ uint8_t evp;
|
||||
/* 03 */ uint8_t hp;
|
||||
/* 04 */ uint8_t dfp;
|
||||
/* 05 */ uint8_t ata;
|
||||
/* 06 */ uint8_t lck;
|
||||
/* 07 */ uint8_t tp;
|
||||
/* 08 */ U32T experience;
|
||||
/* 0C */
|
||||
|
||||
void apply(CharacterStats& ps) const {
|
||||
ps.ata += this->ata;
|
||||
ps.atp += this->atp;
|
||||
ps.dfp += this->dfp;
|
||||
ps.evp += this->evp;
|
||||
ps.hp += this->hp;
|
||||
ps.mst += this->mst;
|
||||
ps.lck += this->lck;
|
||||
}
|
||||
} __packed__;
|
||||
using LevelStatsDelta = LevelStatsDeltaT<false>;
|
||||
using LevelStatsDeltaBE = LevelStatsDeltaT<true>;
|
||||
check_struct_size(LevelStatsDelta, 0x0C);
|
||||
check_struct_size(LevelStatsDeltaBE, 0x0C);
|
||||
|
||||
class LevelTable {
|
||||
// This is the base class for all the LevelTable implementations. The public
|
||||
// interface here only defines functions that the server needs to handle
|
||||
// requests, but some subclasses implement more functionality. See the
|
||||
// comments and Offsets structures inside the subclasses' constructor
|
||||
// implementations for more details on the file formats.
|
||||
public:
|
||||
virtual ~LevelTable() = default;
|
||||
virtual const CharacterStats& base_stats_for_class(uint8_t char_class) const = 0;
|
||||
virtual const LevelStatsDelta& stats_delta_for_level(uint8_t char_class, uint8_t level) const = 0;
|
||||
|
||||
void reset_to_base(PlayerStats& stats, uint8_t char_class) const;
|
||||
void advance_to_level(PlayerStats& stats, uint32_t level, uint8_t char_class) const;
|
||||
|
||||
protected:
|
||||
LevelTable() = default;
|
||||
};
|
||||
|
||||
class LevelTableV2 : public LevelTable { // from PlayerTable.prs (PC)
|
||||
public:
|
||||
struct Level100Entry {
|
||||
/* 00 */ CharacterStats char_stats;
|
||||
/* 0E */ le_uint16_t unknown_a1 = 0;
|
||||
/* 10 */ le_float height = 0.0;
|
||||
/* 14 */ le_float unknown_a3 = 0.0;
|
||||
/* 18 */ le_uint32_t level = 0;
|
||||
/* 1C */
|
||||
} __packed_ws__(Level100Entry, 0x1C);
|
||||
|
||||
LevelTableV2(const std::string& data, bool compressed);
|
||||
virtual ~LevelTableV2() = default;
|
||||
|
||||
virtual const CharacterStats& base_stats_for_class(uint8_t char_class) const;
|
||||
const Level100Entry& level_100_stats_for_class(uint8_t char_class) const;
|
||||
const PlayerStats& max_stats_for_class(uint8_t char_class) const;
|
||||
virtual const LevelStatsDelta& stats_delta_for_level(uint8_t char_class, uint8_t level) const;
|
||||
|
||||
private:
|
||||
std::array<CharacterStats, 9> base_stats;
|
||||
std::array<Level100Entry, 9> level_100_stats;
|
||||
std::array<PlayerStats, 9> max_stats;
|
||||
std::array<std::array<LevelStatsDelta, 200>, 9> level_deltas;
|
||||
};
|
||||
|
||||
class LevelTableV3BE : public LevelTable { // from PlyLevelTbl.cpt (GC)
|
||||
public:
|
||||
LevelTableV3BE(const std::string& data, bool encrypted);
|
||||
virtual ~LevelTableV3BE() = default;
|
||||
|
||||
virtual const CharacterStats& base_stats_for_class(uint8_t char_class) const;
|
||||
virtual const LevelStatsDelta& stats_delta_for_level(uint8_t char_class, uint8_t level) const;
|
||||
|
||||
private:
|
||||
std::array<std::array<LevelStatsDelta, 200>, 12> level_deltas;
|
||||
};
|
||||
|
||||
class LevelTableV4 : public LevelTable { // from PlyLevelTbl.prs (BB)
|
||||
public:
|
||||
LevelTableV4(const std::string& data, bool compressed);
|
||||
virtual ~LevelTableV4() = default;
|
||||
|
||||
virtual const CharacterStats& base_stats_for_class(uint8_t char_class) const;
|
||||
virtual const LevelStatsDelta& stats_delta_for_level(uint8_t char_class, uint8_t level) const;
|
||||
|
||||
private:
|
||||
std::array<CharacterStats, 12> base_stats;
|
||||
std::array<std::array<LevelStatsDelta, 200>, 12> level_deltas;
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <string>
|
||||
|
||||
#include "Text.hh"
|
||||
|
||||
class LevelTable;
|
||||
|
||||
template <bool IsBigEndian>
|
||||
struct CharacterStatsT {
|
||||
using U16T = typename std::conditional<IsBigEndian, be_uint16_t, le_uint16_t>::type;
|
||||
|
||||
/* 00 */ U16T atp = 0;
|
||||
/* 02 */ U16T mst = 0;
|
||||
/* 04 */ U16T evp = 0;
|
||||
/* 06 */ U16T hp = 0;
|
||||
/* 08 */ U16T dfp = 0;
|
||||
/* 0A */ U16T ata = 0;
|
||||
/* 0C */ U16T lck = 0;
|
||||
/* 0E */
|
||||
|
||||
operator CharacterStatsT<!IsBigEndian>() const {
|
||||
CharacterStatsT<!IsBigEndian> ret;
|
||||
ret.atp = this->atp.load();
|
||||
ret.mst = this->mst.load();
|
||||
ret.evp = this->evp.load();
|
||||
ret.hp = this->hp.load();
|
||||
ret.dfp = this->dfp.load();
|
||||
ret.ata = this->ata.load();
|
||||
ret.lck = this->lck.load();
|
||||
return ret;
|
||||
}
|
||||
} __packed__;
|
||||
using CharacterStats = CharacterStatsT<false>;
|
||||
using CharacterStatsBE = CharacterStatsT<true>;
|
||||
check_struct_size(CharacterStats, 0x0E);
|
||||
check_struct_size(CharacterStatsBE, 0x0E);
|
||||
|
||||
template <bool IsBigEndian>
|
||||
struct PlayerStatsT {
|
||||
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;
|
||||
using F32T = typename std::conditional<IsBigEndian, be_float, le_float>::type;
|
||||
|
||||
/* 00 */ CharacterStatsT<IsBigEndian> char_stats;
|
||||
/* 0E */ U16T esp = 0;
|
||||
/* 10 */ F32T height = 0.0;
|
||||
/* 14 */ F32T unknown_a3 = 0.0;
|
||||
/* 18 */ U32T level = 0;
|
||||
/* 1C */ U32T experience = 0;
|
||||
/* 20 */ U32T meseta = 0;
|
||||
/* 24 */
|
||||
|
||||
operator PlayerStatsT<!IsBigEndian>() const {
|
||||
PlayerStatsT<!IsBigEndian> ret;
|
||||
ret.char_stats = this->char_stats;
|
||||
ret.esp = this->esp.load();
|
||||
ret.height = this->height.load();
|
||||
ret.unknown_a3 = this->unknown_a3.load();
|
||||
ret.level = this->level.load();
|
||||
ret.experience = this->experience.load();
|
||||
ret.meseta = this->meseta.load();
|
||||
return ret;
|
||||
}
|
||||
} __packed__;
|
||||
using PlayerStats = PlayerStatsT<false>;
|
||||
using PlayerStatsBE = PlayerStatsT<true>;
|
||||
check_struct_size(PlayerStats, 0x24);
|
||||
check_struct_size(PlayerStatsBE, 0x24);
|
||||
|
||||
template <bool IsBigEndian>
|
||||
struct LevelStatsDeltaT {
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
|
||||
/* 00 */ uint8_t atp;
|
||||
/* 01 */ uint8_t mst;
|
||||
/* 02 */ uint8_t evp;
|
||||
/* 03 */ uint8_t hp;
|
||||
/* 04 */ uint8_t dfp;
|
||||
/* 05 */ uint8_t ata;
|
||||
/* 06 */ uint8_t lck;
|
||||
/* 07 */ uint8_t tp;
|
||||
/* 08 */ U32T experience;
|
||||
/* 0C */
|
||||
|
||||
void apply(CharacterStats& ps) const {
|
||||
ps.ata += this->ata;
|
||||
ps.atp += this->atp;
|
||||
ps.dfp += this->dfp;
|
||||
ps.evp += this->evp;
|
||||
ps.hp += this->hp;
|
||||
ps.mst += this->mst;
|
||||
ps.lck += this->lck;
|
||||
}
|
||||
} __packed__;
|
||||
using LevelStatsDelta = LevelStatsDeltaT<false>;
|
||||
using LevelStatsDeltaBE = LevelStatsDeltaT<true>;
|
||||
check_struct_size(LevelStatsDelta, 0x0C);
|
||||
check_struct_size(LevelStatsDeltaBE, 0x0C);
|
||||
|
||||
class LevelTable {
|
||||
// This is the base class for all the LevelTable implementations. The public
|
||||
// interface here only defines functions that the server needs to handle
|
||||
// requests, but some subclasses implement more functionality. See the
|
||||
// comments and Offsets structures inside the subclasses' constructor
|
||||
// implementations for more details on the file formats.
|
||||
public:
|
||||
virtual ~LevelTable() = default;
|
||||
virtual const CharacterStats& base_stats_for_class(uint8_t char_class) const = 0;
|
||||
virtual const LevelStatsDelta& stats_delta_for_level(uint8_t char_class, uint8_t level) const = 0;
|
||||
|
||||
void reset_to_base(PlayerStats& stats, uint8_t char_class) const;
|
||||
void advance_to_level(PlayerStats& stats, uint32_t level, uint8_t char_class) const;
|
||||
|
||||
protected:
|
||||
LevelTable() = default;
|
||||
};
|
||||
|
||||
class LevelTableV2 : public LevelTable { // from PlayerTable.prs (PC)
|
||||
public:
|
||||
struct Level100Entry {
|
||||
/* 00 */ CharacterStats char_stats;
|
||||
/* 0E */ le_uint16_t unknown_a1 = 0;
|
||||
/* 10 */ le_float height = 0.0;
|
||||
/* 14 */ le_float unknown_a3 = 0.0;
|
||||
/* 18 */ le_uint32_t level = 0;
|
||||
/* 1C */
|
||||
} __packed_ws__(Level100Entry, 0x1C);
|
||||
|
||||
LevelTableV2(const std::string& data, bool compressed);
|
||||
virtual ~LevelTableV2() = default;
|
||||
|
||||
virtual const CharacterStats& base_stats_for_class(uint8_t char_class) const;
|
||||
const Level100Entry& level_100_stats_for_class(uint8_t char_class) const;
|
||||
const PlayerStats& max_stats_for_class(uint8_t char_class) const;
|
||||
virtual const LevelStatsDelta& stats_delta_for_level(uint8_t char_class, uint8_t level) const;
|
||||
|
||||
private:
|
||||
std::array<CharacterStats, 9> base_stats;
|
||||
std::array<Level100Entry, 9> level_100_stats;
|
||||
std::array<PlayerStats, 9> max_stats;
|
||||
std::array<std::array<LevelStatsDelta, 200>, 9> level_deltas;
|
||||
};
|
||||
|
||||
class LevelTableV3BE : public LevelTable { // from PlyLevelTbl.cpt (GC)
|
||||
public:
|
||||
LevelTableV3BE(const std::string& data, bool encrypted);
|
||||
virtual ~LevelTableV3BE() = default;
|
||||
|
||||
virtual const CharacterStats& base_stats_for_class(uint8_t char_class) const;
|
||||
virtual const LevelStatsDelta& stats_delta_for_level(uint8_t char_class, uint8_t level) const;
|
||||
|
||||
private:
|
||||
std::array<std::array<LevelStatsDelta, 200>, 12> level_deltas;
|
||||
};
|
||||
|
||||
class LevelTableV4 : public LevelTable { // from PlyLevelTbl.prs (BB)
|
||||
public:
|
||||
LevelTableV4(const std::string& data, bool compressed);
|
||||
virtual ~LevelTableV4() = default;
|
||||
|
||||
virtual const CharacterStats& base_stats_for_class(uint8_t char_class) const;
|
||||
virtual const LevelStatsDelta& stats_delta_for_level(uint8_t char_class, uint8_t level) const;
|
||||
|
||||
private:
|
||||
std::array<CharacterStats, 12> base_stats;
|
||||
std::array<std::array<LevelStatsDelta, 200>, 12> level_deltas;
|
||||
};
|
||||
|
||||
+1066
-1054
File diff suppressed because it is too large
Load Diff
+322
-318
@@ -1,318 +1,322 @@
|
||||
#pragma once
|
||||
|
||||
#include <event2/event.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "Client.hh"
|
||||
#include "CommandFormats.hh"
|
||||
#include "Episode3/BattleRecord.hh"
|
||||
#include "Episode3/Server.hh"
|
||||
#include "ItemCreator.hh"
|
||||
#include "Map.hh"
|
||||
#include "Quest.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
struct ServerState;
|
||||
|
||||
struct Lobby : public std::enable_shared_from_this<Lobby> {
|
||||
struct FloorItem {
|
||||
ItemData data;
|
||||
float x;
|
||||
float z;
|
||||
uint64_t drop_number;
|
||||
// The low 12 bits of flags are visibility flags, specifying which clients
|
||||
// can see the item. (In practice, only the lowest 4 of these bits are used,
|
||||
// but the game has fields for 12 players so we do too.)
|
||||
// The 13th bit (0x1000) specifies whether a rare item notification should
|
||||
// be sent to all players when the item is picked up. This has no effect for
|
||||
// non-rare items.
|
||||
uint16_t flags;
|
||||
|
||||
bool visible_to_client(uint8_t client_id) const;
|
||||
};
|
||||
struct FloorItemManager {
|
||||
PrefixedLogger log;
|
||||
uint64_t next_drop_number;
|
||||
// It's important that this is a map and not an unordered_map. See the
|
||||
// comment in send_game_item_state for more details.
|
||||
std::map<uint32_t, std::shared_ptr<FloorItem>> items; // Keyed on item_id
|
||||
std::array<std::map<uint64_t, std::shared_ptr<FloorItem>>, 12> queue_for_client;
|
||||
|
||||
FloorItemManager(uint32_t lobby_id, uint8_t floor);
|
||||
~FloorItemManager() = default;
|
||||
|
||||
bool exists(uint32_t item_id) const;
|
||||
std::shared_ptr<FloorItem> find(uint32_t item_id) const;
|
||||
void add(const ItemData& item, float x, float z, uint16_t flags);
|
||||
void add(std::shared_ptr<FloorItem> fi);
|
||||
std::shared_ptr<FloorItem> remove(uint32_t item_id, uint8_t client_id);
|
||||
std::unordered_set<std::shared_ptr<FloorItem>> evict();
|
||||
void clear_inaccessible(uint16_t remaining_clients_mask);
|
||||
void clear_private();
|
||||
void clear();
|
||||
uint32_t reassign_all_item_ids(uint32_t next_item_id);
|
||||
};
|
||||
enum class Flag {
|
||||
// clang-format off
|
||||
GAME = 0x00000001,
|
||||
PERSISTENT = 0x00000002,
|
||||
// Flags used only for games
|
||||
CHEATS_ENABLED = 0x00000100,
|
||||
QUEST_IN_PROGRESS = 0x00000200,
|
||||
BATTLE_IN_PROGRESS = 0x00000400,
|
||||
JOINABLE_QUEST_IN_PROGRESS = 0x00000800,
|
||||
IS_SPECTATOR_TEAM = 0x00002000, // episode must be EP3 also
|
||||
SPECTATORS_FORBIDDEN = 0x00004000,
|
||||
START_BATTLE_PLAYER_IMMEDIATELY = 0x00008000,
|
||||
CANNOT_CHANGE_CHEAT_MODE = 0x00010000,
|
||||
USE_CREATOR_SECTION_ID = 0x00020000,
|
||||
// Flags used only for lobbies
|
||||
PUBLIC = 0x01000000,
|
||||
DEFAULT = 0x02000000,
|
||||
IS_OVERFLOW = 0x08000000,
|
||||
// clang-format on
|
||||
};
|
||||
enum class DropMode {
|
||||
DISABLED = 0,
|
||||
CLIENT = 1, // Not allowed for BB games
|
||||
SERVER_SHARED = 2,
|
||||
SERVER_PRIVATE = 3,
|
||||
SERVER_DUPLICATE = 4,
|
||||
};
|
||||
|
||||
std::weak_ptr<ServerState>
|
||||
server_state;
|
||||
PrefixedLogger log;
|
||||
|
||||
uint32_t lobby_id;
|
||||
|
||||
uint32_t min_level;
|
||||
uint32_t max_level;
|
||||
|
||||
// Game state
|
||||
std::array<uint32_t, 12> next_item_id_for_client;
|
||||
uint32_t next_game_item_id;
|
||||
std::vector<FloorItemManager> floor_item_managers;
|
||||
std::shared_ptr<const Map::RareEnemyRates> rare_enemy_rates;
|
||||
std::shared_ptr<Map> map;
|
||||
parray<le_uint32_t, 0x20> variations;
|
||||
std::unique_ptr<QuestFlags> quest_flags_known; // If null, ALL quest flags are known
|
||||
std::unique_ptr<QuestFlags> quest_flag_values;
|
||||
std::unique_ptr<SwitchFlags> switch_flags;
|
||||
|
||||
// Game config
|
||||
Version base_version;
|
||||
// Bits in allowed_versions specify who is allowed to join this game. The
|
||||
// bits are indexed as (1 << version), where version is a value from the
|
||||
// Version enum.
|
||||
uint16_t allowed_versions;
|
||||
uint8_t creator_section_id;
|
||||
uint8_t override_section_id;
|
||||
Episode episode;
|
||||
GameMode mode;
|
||||
uint8_t difficulty; // 0-3
|
||||
uint16_t base_exp_multiplier;
|
||||
float challenge_exp_multiplier;
|
||||
std::string password;
|
||||
std::string name;
|
||||
// This seed is also sent to the client for rare enemy generation
|
||||
uint32_t random_seed;
|
||||
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt;
|
||||
uint8_t allowed_drop_modes;
|
||||
DropMode drop_mode;
|
||||
std::shared_ptr<ItemCreator> item_creator;
|
||||
|
||||
struct ChallengeParameters {
|
||||
uint8_t stage_number = 0;
|
||||
uint32_t rank_color = 0xFFFFFFFF;
|
||||
std::string rank_text;
|
||||
struct RankThreshold {
|
||||
uint32_t bitmask = 0;
|
||||
uint32_t seconds = 0;
|
||||
};
|
||||
std::array<RankThreshold, 3> rank_thresholds;
|
||||
};
|
||||
std::shared_ptr<ChallengeParameters> challenge_params;
|
||||
|
||||
// Ep3 stuff
|
||||
// There are three kinds of Episode 3 games. All of these types have episode
|
||||
// set to EP3; types 2 and 3 additionally have the IS_SPECTATOR_TEAM flag.
|
||||
// 1. Primary games. These are the lobbies where battles may take place.
|
||||
// 2. Watcher games. These lobbies receive all the battle and chat commands
|
||||
// from a primary game. (This the implementation of spectator teams.)
|
||||
// 3. Replay games. These lobbies replay a sequence of battle commands and
|
||||
// chat commands from a previous primary game.
|
||||
// Types 2 and 3 may be distinguished by the presence of the battle_record
|
||||
// field - in replay games, it will be present; in watcher games it will be
|
||||
// absent.
|
||||
std::shared_ptr<Episode3::Server> ep3_server; // Only used in primary games
|
||||
std::weak_ptr<Lobby> watched_lobby; // Only used in watcher games
|
||||
std::unordered_set<std::shared_ptr<Lobby>> watcher_lobbies; // Only used in primary games
|
||||
std::shared_ptr<Episode3::BattleRecord> battle_record; // Not used in watcher games
|
||||
std::shared_ptr<Episode3::BattleRecordPlayer> battle_player; // Only used in replay games
|
||||
std::shared_ptr<Episode3::Tournament::Match> tournament_match;
|
||||
std::shared_ptr<const G_SetEXResultValues_Ep3_6xB4x4B> ep3_ex_result_values;
|
||||
|
||||
// Lobby stuff
|
||||
uint8_t event;
|
||||
uint8_t block;
|
||||
uint8_t leader_id;
|
||||
uint8_t max_clients;
|
||||
uint32_t enabled_flags;
|
||||
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;
|
||||
|
||||
// This is only used when the PERSISTENT flag is set and idle_timeout_usecs
|
||||
// is not zero
|
||||
uint64_t idle_timeout_usecs;
|
||||
std::unique_ptr<struct event, void (*)(struct event*)> idle_timeout_event;
|
||||
|
||||
Lobby(std::shared_ptr<ServerState> s, uint32_t id, bool is_game);
|
||||
Lobby(const Lobby&) = delete;
|
||||
Lobby(Lobby&&) = delete;
|
||||
~Lobby();
|
||||
Lobby& operator=(const Lobby&) = delete;
|
||||
Lobby& operator=(Lobby&&) = delete;
|
||||
|
||||
void reset_next_item_ids();
|
||||
|
||||
[[nodiscard]] inline bool check_flag(Flag flag) const {
|
||||
return !!(this->enabled_flags & static_cast<uint32_t>(flag));
|
||||
}
|
||||
inline void set_flag(Flag flag) {
|
||||
this->enabled_flags |= static_cast<uint32_t>(flag);
|
||||
}
|
||||
inline void clear_flag(Flag flag) {
|
||||
this->enabled_flags &= (~static_cast<uint32_t>(flag));
|
||||
}
|
||||
inline void toggle_flag(Flag flag) {
|
||||
this->enabled_flags ^= static_cast<uint32_t>(flag);
|
||||
}
|
||||
|
||||
std::shared_ptr<ServerState> require_server_state() const;
|
||||
std::shared_ptr<ChallengeParameters> require_challenge_params() const;
|
||||
void set_drop_mode(DropMode new_mode);
|
||||
void create_item_creator();
|
||||
void change_section_id();
|
||||
uint8_t effective_section_id() const;
|
||||
static std::shared_ptr<Map> load_maps(
|
||||
Version version,
|
||||
Episode episode,
|
||||
uint8_t difficulty,
|
||||
uint8_t event,
|
||||
uint32_t lobby_id,
|
||||
std::shared_ptr<const Map::RareEnemyRates> rare_rates,
|
||||
uint32_t random_seed,
|
||||
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt,
|
||||
std::shared_ptr<const std::string> quest_dat_contents_decompressed);
|
||||
static std::shared_ptr<Map> load_maps(
|
||||
Version version,
|
||||
Episode episode,
|
||||
GameMode mode,
|
||||
uint8_t difficulty,
|
||||
uint8_t event,
|
||||
uint32_t lobby_id,
|
||||
std::shared_ptr<const SetDataTableBase> sdt,
|
||||
std::function<std::shared_ptr<const std::string>(Version, const std::string&)> get_file_data,
|
||||
std::shared_ptr<const Map::RareEnemyRates> rare_rates,
|
||||
uint32_t random_seed,
|
||||
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt,
|
||||
const parray<le_uint32_t, 0x20>& variations,
|
||||
const PrefixedLogger* log = nullptr);
|
||||
static std::shared_ptr<Map> load_maps(
|
||||
const std::vector<std::string>& enemy_filenames,
|
||||
const std::vector<std::string>& object_filenames,
|
||||
const std::vector<std::string>& event_filenames,
|
||||
Version version,
|
||||
Episode episode,
|
||||
GameMode mode,
|
||||
uint8_t difficulty,
|
||||
uint8_t event,
|
||||
uint32_t lobby_id,
|
||||
std::function<std::shared_ptr<const std::string>(Version, const std::string&)> get_file_data,
|
||||
std::shared_ptr<const Map::RareEnemyRates> rare_rates,
|
||||
uint32_t random_seed,
|
||||
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt,
|
||||
const PrefixedLogger* log = nullptr);
|
||||
void load_maps();
|
||||
void create_ep3_server();
|
||||
|
||||
[[nodiscard]] inline bool is_game() const {
|
||||
return this->check_flag(Flag::GAME);
|
||||
}
|
||||
[[nodiscard]] inline bool is_ep3() const {
|
||||
return this->episode == Episode::EP3;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline bool version_is_allowed(Version v) const {
|
||||
return this->allowed_versions & (1 << static_cast<size_t>(v));
|
||||
}
|
||||
inline void allow_version(Version v) {
|
||||
this->allowed_versions |= (1 << static_cast<size_t>(v));
|
||||
}
|
||||
|
||||
void reassign_leader_on_client_departure(size_t leaving_client_id);
|
||||
size_t count_clients() const;
|
||||
bool any_v1_clients_present() const;
|
||||
bool any_client_loading() const;
|
||||
|
||||
void add_client(std::shared_ptr<Client> c, ssize_t required_client_id = -1);
|
||||
void remove_client(std::shared_ptr<Client> c);
|
||||
|
||||
void move_client_to_lobby(
|
||||
std::shared_ptr<Lobby> dest_lobby,
|
||||
std::shared_ptr<Client> c,
|
||||
ssize_t required_client_id = -1);
|
||||
|
||||
std::shared_ptr<Client> find_client(const std::string* identifier = nullptr, uint64_t account_id = 0);
|
||||
|
||||
enum class JoinError {
|
||||
ALLOWED = 0,
|
||||
FULL,
|
||||
VERSION_CONFLICT,
|
||||
QUEST_IN_PROGRESS,
|
||||
BATTLE_IN_PROGRESS,
|
||||
LOADING,
|
||||
SOLO,
|
||||
INCORRECT_PASSWORD,
|
||||
LEVEL_TOO_LOW,
|
||||
LEVEL_TOO_HIGH,
|
||||
NO_ACCESS_TO_QUEST,
|
||||
};
|
||||
JoinError join_error_for_client(std::shared_ptr<Client> c, const std::string* password) const;
|
||||
|
||||
bool item_exists(uint8_t floor, uint32_t item_id) const;
|
||||
std::shared_ptr<FloorItem> find_item(uint8_t floor, uint32_t item_id) const;
|
||||
void add_item(uint8_t floor, const ItemData& item, float x, float z, uint16_t flags);
|
||||
void add_item(uint8_t floor, std::shared_ptr<FloorItem>);
|
||||
void evict_items_from_floor(uint8_t floor);
|
||||
std::shared_ptr<FloorItem> remove_item(uint8_t floor, uint32_t item_id, uint8_t requesting_client_id);
|
||||
|
||||
uint32_t generate_item_id(uint8_t client_id);
|
||||
void on_item_id_generated_externally(uint32_t item_id);
|
||||
void assign_inventory_and_bank_item_ids(std::shared_ptr<Client> c, bool consume_ids);
|
||||
|
||||
QuestIndex::IncludeCondition quest_include_condition() const;
|
||||
|
||||
std::unordered_map<uint32_t, std::shared_ptr<Client>> clients_by_account_id() const;
|
||||
|
||||
static void dispatch_on_idle_timeout(evutil_socket_t, short, void* ctx);
|
||||
|
||||
static bool compare_shared(const std::shared_ptr<const Lobby>& a, const std::shared_ptr<const Lobby>& b);
|
||||
};
|
||||
|
||||
template <>
|
||||
Lobby::DropMode enum_for_name<Lobby::DropMode>(const char* name);
|
||||
template <>
|
||||
const char* name_for_enum<Lobby::DropMode>(Lobby::DropMode value);
|
||||
#pragma once
|
||||
|
||||
#include <event2/event.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "Client.hh"
|
||||
#include "CommandFormats.hh"
|
||||
#include "Episode3/BattleRecord.hh"
|
||||
#include "Episode3/Server.hh"
|
||||
#include "ItemCreator.hh"
|
||||
#include "Map.hh"
|
||||
#include "Quest.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
struct ServerState;
|
||||
|
||||
struct Lobby : public std::enable_shared_from_this<Lobby> {
|
||||
struct FloorItem {
|
||||
ItemData data;
|
||||
float x;
|
||||
float z;
|
||||
uint64_t drop_number;
|
||||
// The low 12 bits of flags are visibility flags, specifying which clients
|
||||
// can see the item. (In practice, only the lowest 4 of these bits are used,
|
||||
// but the game has fields for 12 players so we do too.)
|
||||
// The 13th bit (0x1000) specifies whether a rare item notification should
|
||||
// be sent to all players when the item is picked up. This has no effect for
|
||||
// non-rare items.
|
||||
uint16_t flags;
|
||||
|
||||
bool visible_to_client(uint8_t client_id) const;
|
||||
};
|
||||
struct FloorItemManager {
|
||||
PrefixedLogger log;
|
||||
uint64_t next_drop_number;
|
||||
// It's important that this is a map and not an unordered_map. See the
|
||||
// comment in send_game_item_state for more details.
|
||||
std::map<uint32_t, std::shared_ptr<FloorItem>> items; // Keyed on item_id
|
||||
std::array<std::map<uint64_t, std::shared_ptr<FloorItem>>, 12> queue_for_client;
|
||||
|
||||
FloorItemManager(uint32_t lobby_id, uint8_t floor);
|
||||
~FloorItemManager() = default;
|
||||
|
||||
bool exists(uint32_t item_id) const;
|
||||
std::shared_ptr<FloorItem> find(uint32_t item_id) const;
|
||||
void add(const ItemData& item, float x, float z, uint16_t flags);
|
||||
void add(std::shared_ptr<FloorItem> fi);
|
||||
std::shared_ptr<FloorItem> remove(uint32_t item_id, uint8_t client_id);
|
||||
std::unordered_set<std::shared_ptr<FloorItem>> evict();
|
||||
void clear_inaccessible(uint16_t remaining_clients_mask);
|
||||
void clear_private();
|
||||
void clear();
|
||||
uint32_t reassign_all_item_ids(uint32_t next_item_id);
|
||||
};
|
||||
enum class Flag {
|
||||
// clang-format off
|
||||
GAME = 0x00000001,
|
||||
PERSISTENT = 0x00000002,
|
||||
// Flags used only for games
|
||||
CHEATS_ENABLED = 0x00000100,
|
||||
QUEST_SELECTION_IN_PROGRESS = 0x00000200,
|
||||
QUEST_IN_PROGRESS = 0x00000400,
|
||||
BATTLE_IN_PROGRESS = 0x00000800,
|
||||
JOINABLE_QUEST_IN_PROGRESS = 0x00001000,
|
||||
IS_CLIENT_CUSTOMIZATION = 0x00002000,
|
||||
IS_SPECTATOR_TEAM = 0x00004000, // .episode must be EP3 also
|
||||
SPECTATORS_FORBIDDEN = 0x00008000,
|
||||
START_BATTLE_PLAYER_IMMEDIATELY = 0x00010000,
|
||||
CANNOT_CHANGE_CHEAT_MODE = 0x00020000,
|
||||
USE_CREATOR_SECTION_ID = 0x00040000,
|
||||
// Flags used only for lobbies
|
||||
PUBLIC = 0x01000000,
|
||||
DEFAULT = 0x02000000,
|
||||
IS_OVERFLOW = 0x08000000,
|
||||
// clang-format on
|
||||
};
|
||||
enum class DropMode {
|
||||
DISABLED = 0,
|
||||
CLIENT = 1, // Not allowed for BB games
|
||||
SERVER_SHARED = 2,
|
||||
SERVER_PRIVATE = 3,
|
||||
SERVER_DUPLICATE = 4,
|
||||
};
|
||||
|
||||
std::weak_ptr<ServerState>
|
||||
server_state;
|
||||
PrefixedLogger log;
|
||||
|
||||
uint32_t lobby_id;
|
||||
|
||||
uint32_t min_level;
|
||||
uint32_t max_level;
|
||||
|
||||
// Game state
|
||||
std::array<uint32_t, 12> next_item_id_for_client;
|
||||
uint32_t next_game_item_id;
|
||||
std::vector<FloorItemManager> floor_item_managers;
|
||||
std::shared_ptr<const Map::RareEnemyRates> rare_enemy_rates;
|
||||
std::shared_ptr<Map> map;
|
||||
parray<le_uint32_t, 0x20> variations;
|
||||
std::unique_ptr<QuestFlags> quest_flags_known; // If null, ALL quest flags are known
|
||||
std::unique_ptr<QuestFlags> quest_flag_values;
|
||||
std::unique_ptr<SwitchFlags> switch_flags;
|
||||
|
||||
// Game config
|
||||
Version base_version;
|
||||
// Bits in allowed_versions specify who is allowed to join this game. The
|
||||
// bits are indexed as (1 << version), where version is a value from the
|
||||
// Version enum.
|
||||
uint16_t allowed_versions;
|
||||
uint8_t creator_section_id;
|
||||
uint8_t override_section_id;
|
||||
Episode episode;
|
||||
GameMode mode;
|
||||
uint8_t difficulty; // 0-3
|
||||
uint16_t base_exp_multiplier;
|
||||
float exp_share_multiplier;
|
||||
float challenge_exp_multiplier;
|
||||
std::string password;
|
||||
std::string name;
|
||||
// This seed is also sent to the client for rare enemy generation
|
||||
uint32_t random_seed;
|
||||
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt;
|
||||
uint8_t allowed_drop_modes;
|
||||
DropMode drop_mode;
|
||||
std::shared_ptr<ItemCreator> item_creator;
|
||||
|
||||
struct ChallengeParameters {
|
||||
uint8_t stage_number = 0;
|
||||
uint32_t rank_color = 0xFFFFFFFF;
|
||||
std::string rank_text;
|
||||
struct RankThreshold {
|
||||
uint32_t bitmask = 0;
|
||||
uint32_t seconds = 0;
|
||||
};
|
||||
std::array<RankThreshold, 3> rank_thresholds;
|
||||
};
|
||||
std::shared_ptr<ChallengeParameters> challenge_params;
|
||||
|
||||
// Ep3 stuff
|
||||
// There are three kinds of Episode 3 games. All of these types have episode
|
||||
// set to EP3; types 2 and 3 additionally have the IS_SPECTATOR_TEAM flag.
|
||||
// 1. Primary games. These are the lobbies where battles may take place.
|
||||
// 2. Watcher games. These lobbies receive all the battle and chat commands
|
||||
// from a primary game. (This the implementation of spectator teams.)
|
||||
// 3. Replay games. These lobbies replay a sequence of battle commands and
|
||||
// chat commands from a previous primary game.
|
||||
// Types 2 and 3 may be distinguished by the presence of the battle_record
|
||||
// field - in replay games, it will be present; in watcher games it will be
|
||||
// absent.
|
||||
std::shared_ptr<Episode3::Server> ep3_server; // Only used in primary games
|
||||
std::weak_ptr<Lobby> watched_lobby; // Only used in watcher games
|
||||
std::unordered_set<std::shared_ptr<Lobby>> watcher_lobbies; // Only used in primary games
|
||||
std::shared_ptr<Episode3::BattleRecord> battle_record; // Not used in watcher games
|
||||
std::shared_ptr<Episode3::BattleRecordPlayer> battle_player; // Only used in replay games
|
||||
std::shared_ptr<Episode3::Tournament::Match> tournament_match;
|
||||
std::shared_ptr<const G_SetEXResultValues_Ep3_6xB4x4B> ep3_ex_result_values;
|
||||
|
||||
// Lobby stuff
|
||||
uint8_t event;
|
||||
uint8_t block;
|
||||
uint8_t leader_id;
|
||||
uint8_t max_clients;
|
||||
uint32_t enabled_flags;
|
||||
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;
|
||||
|
||||
// This is only used when the PERSISTENT flag is set and idle_timeout_usecs
|
||||
// is not zero
|
||||
uint64_t idle_timeout_usecs;
|
||||
std::unique_ptr<struct event, void (*)(struct event*)> idle_timeout_event;
|
||||
|
||||
Lobby(std::shared_ptr<ServerState> s, uint32_t id, bool is_game);
|
||||
Lobby(const Lobby&) = delete;
|
||||
Lobby(Lobby&&) = delete;
|
||||
~Lobby();
|
||||
Lobby& operator=(const Lobby&) = delete;
|
||||
Lobby& operator=(Lobby&&) = delete;
|
||||
|
||||
void reset_next_item_ids();
|
||||
|
||||
[[nodiscard]] inline bool check_flag(Flag flag) const {
|
||||
return !!(this->enabled_flags & static_cast<uint32_t>(flag));
|
||||
}
|
||||
inline void set_flag(Flag flag) {
|
||||
this->enabled_flags |= static_cast<uint32_t>(flag);
|
||||
}
|
||||
inline void clear_flag(Flag flag) {
|
||||
this->enabled_flags &= (~static_cast<uint32_t>(flag));
|
||||
}
|
||||
inline void toggle_flag(Flag flag) {
|
||||
this->enabled_flags ^= static_cast<uint32_t>(flag);
|
||||
}
|
||||
|
||||
std::shared_ptr<ServerState> require_server_state() const;
|
||||
std::shared_ptr<ChallengeParameters> require_challenge_params() const;
|
||||
void set_drop_mode(DropMode new_mode);
|
||||
void create_item_creator();
|
||||
void change_section_id();
|
||||
uint8_t effective_section_id() const;
|
||||
static std::shared_ptr<Map> load_maps(
|
||||
Version version,
|
||||
Episode episode,
|
||||
uint8_t difficulty,
|
||||
uint8_t event,
|
||||
uint32_t lobby_id,
|
||||
std::shared_ptr<const Map::RareEnemyRates> rare_rates,
|
||||
uint32_t random_seed,
|
||||
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt,
|
||||
std::shared_ptr<const std::string> quest_dat_contents_decompressed);
|
||||
static std::shared_ptr<Map> load_maps(
|
||||
Version version,
|
||||
Episode episode,
|
||||
GameMode mode,
|
||||
uint8_t difficulty,
|
||||
uint8_t event,
|
||||
uint32_t lobby_id,
|
||||
std::shared_ptr<const SetDataTableBase> sdt,
|
||||
std::function<std::shared_ptr<const std::string>(Version, const std::string&)> get_file_data,
|
||||
std::shared_ptr<const Map::RareEnemyRates> rare_rates,
|
||||
uint32_t random_seed,
|
||||
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt,
|
||||
const parray<le_uint32_t, 0x20>& variations,
|
||||
const PrefixedLogger* log = nullptr);
|
||||
static std::shared_ptr<Map> load_maps(
|
||||
const std::vector<std::string>& enemy_filenames,
|
||||
const std::vector<std::string>& object_filenames,
|
||||
const std::vector<std::string>& event_filenames,
|
||||
Version version,
|
||||
Episode episode,
|
||||
GameMode mode,
|
||||
uint8_t difficulty,
|
||||
uint8_t event,
|
||||
uint32_t lobby_id,
|
||||
std::function<std::shared_ptr<const std::string>(Version, const std::string&)> get_file_data,
|
||||
std::shared_ptr<const Map::RareEnemyRates> rare_rates,
|
||||
uint32_t random_seed,
|
||||
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt,
|
||||
const PrefixedLogger* log = nullptr);
|
||||
void load_maps();
|
||||
void create_ep3_server();
|
||||
|
||||
[[nodiscard]] inline bool is_game() const {
|
||||
return this->check_flag(Flag::GAME);
|
||||
}
|
||||
[[nodiscard]] inline bool is_ep3() const {
|
||||
return this->episode == Episode::EP3;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline bool version_is_allowed(Version v) const {
|
||||
return this->allowed_versions & (1 << static_cast<size_t>(v));
|
||||
}
|
||||
inline void allow_version(Version v) {
|
||||
this->allowed_versions |= (1 << static_cast<size_t>(v));
|
||||
}
|
||||
|
||||
void reassign_leader_on_client_departure(size_t leaving_client_id);
|
||||
size_t count_clients() const;
|
||||
bool any_v1_clients_present() const;
|
||||
bool any_client_loading() const;
|
||||
|
||||
void add_client(std::shared_ptr<Client> c, ssize_t required_client_id = -1);
|
||||
void remove_client(std::shared_ptr<Client> c);
|
||||
|
||||
void move_client_to_lobby(
|
||||
std::shared_ptr<Lobby> dest_lobby,
|
||||
std::shared_ptr<Client> c,
|
||||
ssize_t required_client_id = -1);
|
||||
|
||||
std::shared_ptr<Client> find_client(const std::string* identifier = nullptr, uint64_t account_id = 0);
|
||||
|
||||
enum class JoinError {
|
||||
ALLOWED = 0,
|
||||
FULL,
|
||||
VERSION_CONFLICT,
|
||||
QUEST_SELECTION_IN_PROGRESS,
|
||||
QUEST_IN_PROGRESS,
|
||||
BATTLE_IN_PROGRESS,
|
||||
LOADING,
|
||||
SOLO,
|
||||
INCORRECT_PASSWORD,
|
||||
LEVEL_TOO_LOW,
|
||||
LEVEL_TOO_HIGH,
|
||||
NO_ACCESS_TO_QUEST,
|
||||
};
|
||||
JoinError join_error_for_client(std::shared_ptr<Client> c, const std::string* password) const;
|
||||
|
||||
bool item_exists(uint8_t floor, uint32_t item_id) const;
|
||||
std::shared_ptr<FloorItem> find_item(uint8_t floor, uint32_t item_id) const;
|
||||
void add_item(uint8_t floor, const ItemData& item, float x, float z, uint16_t flags);
|
||||
void add_item(uint8_t floor, std::shared_ptr<FloorItem>);
|
||||
void evict_items_from_floor(uint8_t floor);
|
||||
std::shared_ptr<FloorItem> remove_item(uint8_t floor, uint32_t item_id, uint8_t requesting_client_id);
|
||||
|
||||
uint32_t generate_item_id(uint8_t client_id);
|
||||
void on_item_id_generated_externally(uint32_t item_id);
|
||||
void assign_inventory_and_bank_item_ids(std::shared_ptr<Client> c, bool consume_ids);
|
||||
|
||||
QuestIndex::IncludeCondition quest_include_condition() const;
|
||||
|
||||
std::unordered_map<uint32_t, std::shared_ptr<Client>> clients_by_account_id() const;
|
||||
|
||||
static void dispatch_on_idle_timeout(evutil_socket_t, short, void* ctx);
|
||||
|
||||
static bool compare_shared(const std::shared_ptr<const Lobby>& a, const std::shared_ptr<const Lobby>& b);
|
||||
};
|
||||
|
||||
template <>
|
||||
Lobby::DropMode enum_for_name<Lobby::DropMode>(const char* name);
|
||||
template <>
|
||||
const char* name_for_enum<Lobby::DropMode>(Lobby::DropMode value);
|
||||
|
||||
+48
-48
@@ -1,48 +1,48 @@
|
||||
#include "Loggers.hh"
|
||||
|
||||
#include <phosg/Strings.hh>
|
||||
|
||||
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 ip_stack_simulator_log("[IPStackSimulator] ", 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, const JSON& d, const char* json_key) {
|
||||
try {
|
||||
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(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(ip_stack_simulator_log, json, "IPStackSimulator");
|
||||
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");
|
||||
}
|
||||
#include "Loggers.hh"
|
||||
|
||||
#include <phosg/Strings.hh>
|
||||
|
||||
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 ip_stack_simulator_log("[IPStackSimulator] ", 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, const JSON& d, const char* json_key) {
|
||||
try {
|
||||
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(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(ip_stack_simulator_log, json, "IPStackSimulator");
|
||||
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");
|
||||
}
|
||||
|
||||
+22
-22
@@ -1,22 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <phosg/JSON.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
|
||||
extern PrefixedLogger ax_messages_log;
|
||||
extern PrefixedLogger channel_exceptions_log;
|
||||
extern PrefixedLogger client_log;
|
||||
extern PrefixedLogger command_data_log;
|
||||
extern PrefixedLogger config_log;
|
||||
extern PrefixedLogger dns_server_log;
|
||||
extern PrefixedLogger function_compiler_log;
|
||||
extern PrefixedLogger ip_stack_simulator_log;
|
||||
extern PrefixedLogger lobby_log;
|
||||
extern PrefixedLogger patch_index_log;
|
||||
extern PrefixedLogger player_data_log;
|
||||
extern PrefixedLogger proxy_server_log;
|
||||
extern PrefixedLogger replay_log;
|
||||
extern PrefixedLogger server_log;
|
||||
extern PrefixedLogger static_game_data_log;
|
||||
|
||||
void set_log_levels_from_json(const JSON& json);
|
||||
#pragma once
|
||||
|
||||
#include <phosg/JSON.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
|
||||
extern PrefixedLogger ax_messages_log;
|
||||
extern PrefixedLogger channel_exceptions_log;
|
||||
extern PrefixedLogger client_log;
|
||||
extern PrefixedLogger command_data_log;
|
||||
extern PrefixedLogger config_log;
|
||||
extern PrefixedLogger dns_server_log;
|
||||
extern PrefixedLogger function_compiler_log;
|
||||
extern PrefixedLogger ip_stack_simulator_log;
|
||||
extern PrefixedLogger lobby_log;
|
||||
extern PrefixedLogger patch_index_log;
|
||||
extern PrefixedLogger player_data_log;
|
||||
extern PrefixedLogger proxy_server_log;
|
||||
extern PrefixedLogger replay_log;
|
||||
extern PrefixedLogger server_log;
|
||||
extern PrefixedLogger static_game_data_log;
|
||||
|
||||
void set_log_levels_from_json(const JSON& json);
|
||||
|
||||
+2820
-2750
File diff suppressed because it is too large
Load Diff
+2567
-2567
File diff suppressed because it is too large
Load Diff
+494
-484
@@ -1,484 +1,494 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <memory>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/JSON.hh>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "BattleParamsIndex.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
struct Map {
|
||||
static const char* name_for_object_type(uint16_t type);
|
||||
|
||||
struct SectionHeader {
|
||||
enum class Type {
|
||||
END = 0,
|
||||
OBJECTS = 1,
|
||||
ENEMIES = 2,
|
||||
WAVE_EVENTS = 3,
|
||||
RANDOM_ENEMY_LOCATIONS = 4,
|
||||
RANDOM_ENEMY_DEFINITIONS = 5,
|
||||
};
|
||||
le_uint32_t le_type;
|
||||
le_uint32_t section_size; // Includes this header
|
||||
le_uint32_t floor;
|
||||
le_uint32_t data_size;
|
||||
|
||||
inline Type type() const {
|
||||
return static_cast<Type>(this->le_type.load());
|
||||
}
|
||||
} __packed_ws__(SectionHeader, 0x10);
|
||||
|
||||
struct ObjectEntry { // Section type 1 (OBJECTS)
|
||||
/* 00 */ le_uint16_t base_type;
|
||||
/* 02 */ le_uint16_t flags;
|
||||
/* 04 */ le_uint16_t index;
|
||||
/* 06 */ le_uint16_t unknown_a2;
|
||||
/* 08 */ le_uint16_t entity_id; // == index + 0x4000
|
||||
/* 0A */ le_uint16_t group;
|
||||
/* 0C */ le_uint16_t section;
|
||||
/* 0E */ le_uint16_t unknown_a3;
|
||||
/* 10 */ le_float x;
|
||||
/* 14 */ le_float y;
|
||||
/* 18 */ le_float z;
|
||||
/* 1C */ le_uint32_t x_angle;
|
||||
/* 20 */ le_uint32_t y_angle;
|
||||
/* 24 */ le_uint32_t z_angle;
|
||||
/* 28 */ le_float param1; // If <= 0, this is a specialized box, and the specialization is in param4/5/6
|
||||
/* 2C */ le_float param2;
|
||||
/* 30 */ le_float param3;
|
||||
/* 34 */ le_uint32_t param4;
|
||||
/* 38 */ le_uint32_t param5;
|
||||
/* 3C */ le_uint32_t param6;
|
||||
/* 40 */ le_uint32_t unused; // Reserved for pointer in client's memory; unused by server
|
||||
/* 44 */
|
||||
|
||||
std::string str() const;
|
||||
} __packed_ws__(ObjectEntry, 0x44);
|
||||
|
||||
struct EnemyEntry { // Section type 2 (ENEMIES)
|
||||
/* 00 */ le_uint16_t base_type;
|
||||
/* 02 */ le_uint16_t flags;
|
||||
/* 04 */ le_uint16_t index;
|
||||
/* 06 */ le_uint16_t num_children;
|
||||
/* 08 */ le_uint16_t floor;
|
||||
/* 0A */ le_uint16_t entity_id; // == index + 0x1000
|
||||
/* 0C */ le_uint16_t section;
|
||||
/* 0E */ le_uint16_t wave_number;
|
||||
/* 10 */ le_uint16_t wave_number2;
|
||||
/* 12 */ le_uint16_t unknown_a1;
|
||||
/* 14 */ le_float x;
|
||||
/* 18 */ le_float y;
|
||||
/* 1C */ le_float z;
|
||||
/* 20 */ le_uint32_t x_angle;
|
||||
/* 24 */ le_uint32_t y_angle;
|
||||
/* 28 */ le_uint32_t z_angle;
|
||||
/* 2C */ le_float fparam1;
|
||||
/* 30 */ le_float fparam2;
|
||||
/* 34 */ le_float fparam3;
|
||||
/* 38 */ le_float fparam4;
|
||||
/* 3C */ le_float fparam5;
|
||||
/* 40 */ le_uint16_t uparam1;
|
||||
/* 42 */ le_uint16_t uparam2;
|
||||
/* 44 */ le_uint32_t unused; // Reserved for pointer in client's memory; unused by server
|
||||
/* 48 */
|
||||
|
||||
std::string str() const;
|
||||
} __packed_ws__(EnemyEntry, 0x48);
|
||||
|
||||
struct EventsSectionHeader { // Section type 3 (WAVE_EVENTS)
|
||||
/* 00 */ le_uint32_t action_stream_offset;
|
||||
/* 04 */ le_uint32_t entries_offset;
|
||||
/* 08 */ le_uint32_t entry_count;
|
||||
/* 0C */ be_uint32_t format; // 0 or 'evt2'
|
||||
/* 10 */
|
||||
} __packed_ws__(EventsSectionHeader, 0x10);
|
||||
|
||||
struct Event1Entry { // Section type 3 (WAVE_EVENTS) if format == 0
|
||||
/* 00 */ le_uint32_t event_id;
|
||||
// Bits in flags:
|
||||
// 0004 = is active
|
||||
// 0008 = post-wave actions have been run
|
||||
// 0010 = all enemies killed
|
||||
/* 04 */ le_uint16_t flags;
|
||||
/* 06 */ le_uint16_t event_type;
|
||||
/* 08 */ le_uint16_t section;
|
||||
/* 0A */ le_uint16_t wave_number;
|
||||
/* 0C */ le_uint32_t delay;
|
||||
/* 10 */ le_uint32_t action_stream_offset;
|
||||
/* 14 */
|
||||
} __packed_ws__(Event1Entry, 0x14);
|
||||
|
||||
struct Event2Entry { // Section type 3 (WAVE_EVENTS) if format == 'evt2'
|
||||
/* 00 */ le_uint32_t event_id;
|
||||
/* 04 */ le_uint16_t flags;
|
||||
/* 06 */ le_uint16_t event_type;
|
||||
/* 08 */ le_uint16_t section;
|
||||
/* 0A */ le_uint16_t wave_number;
|
||||
/* 0C */ le_uint16_t min_delay;
|
||||
/* 0E */ le_uint16_t max_delay;
|
||||
/* 10 */ uint8_t min_enemies;
|
||||
/* 11 */ uint8_t max_enemies;
|
||||
/* 12 */ le_uint16_t max_waves;
|
||||
/* 14 */ le_uint32_t action_stream_offset;
|
||||
/* 18 */
|
||||
} __packed_ws__(Event2Entry, 0x18);
|
||||
|
||||
struct RandomEnemyLocationsHeader { // Section type 4 (RANDOM_ENEMY_LOCATIONS)
|
||||
/* 00 */ le_uint32_t section_table_offset; // Offset to RandomEnemyLocationSegment structs, from start of this struct
|
||||
/* 04 */ le_uint32_t entries_offset; // Offset to RandomEnemyLocationEntry structs, from start of this struct
|
||||
/* 08 */ le_uint32_t num_sections;
|
||||
/* 0C */
|
||||
} __packed_ws__(RandomEnemyLocationsHeader, 0x0C);
|
||||
|
||||
struct RandomEnemyLocationSection { // Section type 4 (RANDOM_ENEMY_LOCATIONS)
|
||||
/* 00 */ le_uint16_t section;
|
||||
/* 02 */ le_uint16_t count;
|
||||
/* 04 */ le_uint32_t offset;
|
||||
/* 08 */
|
||||
} __packed_ws__(RandomEnemyLocationSection, 8);
|
||||
|
||||
struct RandomEnemyLocationEntry { // Section type 4 (RANDOM_ENEMY_LOCATIONS)
|
||||
/* 00 */ le_float x;
|
||||
/* 04 */ le_float y;
|
||||
/* 08 */ le_float z;
|
||||
/* 0C */ le_uint32_t x_angle;
|
||||
/* 10 */ le_uint32_t y_angle;
|
||||
/* 14 */ le_uint32_t z_angle;
|
||||
/* 18 */ uint16_t unknown_a9;
|
||||
/* 1A */ uint16_t unknown_a10;
|
||||
/* 1C */
|
||||
} __packed_ws__(RandomEnemyLocationEntry, 0x1C);
|
||||
|
||||
struct RandomEnemyDefinitionsHeader { // Section type 5 (RANDOM_ENEMY_DEFINITIONS)
|
||||
/* 00 */ le_uint32_t entries_offset; // Offset to RandomEnemyDefinition structs, from start of this struct
|
||||
/* 04 */ le_uint32_t weight_entries_offset; // Offset to RandomEnemyDefinitionWeights structs, from start of this struct
|
||||
/* 08 */ le_uint32_t entry_count;
|
||||
/* 0C */ le_uint32_t weight_entry_count;
|
||||
/* 10 */
|
||||
} __packed_ws__(RandomEnemyDefinitionsHeader, 0x10);
|
||||
|
||||
struct RandomEnemyDefinition { // Section type 5 (RANDOM_ENEMY_DEFINITIONS)
|
||||
// All fields through entry_num map to the corresponding fields in
|
||||
// EnemyEntry. Note that the order of the uparam fields is switched!
|
||||
/* 00 */ le_float fparam1;
|
||||
/* 04 */ le_float fparam2;
|
||||
/* 08 */ le_float fparam3;
|
||||
/* 0C */ le_float fparam4;
|
||||
/* 10 */ le_float fparam5;
|
||||
/* 14 */ le_uint16_t uparam2;
|
||||
/* 16 */ le_uint16_t uparam1;
|
||||
/* 18 */ le_uint32_t entry_num;
|
||||
/* 1C */ le_uint16_t min_children;
|
||||
/* 1E */ le_uint16_t max_children;
|
||||
/* 20 */
|
||||
} __packed_ws__(RandomEnemyDefinition, 0x20);
|
||||
|
||||
struct RandomEnemyWeight { // Section type 5 (RANDOM_ENEMY_DEFINITIONS)
|
||||
/* 00 */ uint8_t base_type_index;
|
||||
/* 01 */ uint8_t definition_entry_num;
|
||||
/* 02 */ uint8_t weight;
|
||||
/* 03 */ uint8_t unknown_a4;
|
||||
/* 04 */
|
||||
} __packed_ws__(RandomEnemyWeight, 4);
|
||||
|
||||
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
|
||||
|
||||
RareEnemyRates(uint32_t enemy_rate, uint32_t boss_rate);
|
||||
explicit RareEnemyRates(const JSON& json);
|
||||
|
||||
JSON json() const;
|
||||
};
|
||||
|
||||
static const std::shared_ptr<const RareEnemyRates> NO_RARE_ENEMIES;
|
||||
static const std::shared_ptr<const RareEnemyRates> DEFAULT_RARE_ENEMIES;
|
||||
|
||||
struct Object {
|
||||
// TODO: Add more fields in here if we ever care about them. Currently we
|
||||
// only care about boxes with fixed item drops.
|
||||
size_t source_index;
|
||||
uint8_t floor;
|
||||
uint16_t object_id;
|
||||
uint16_t base_type;
|
||||
uint16_t section;
|
||||
uint16_t group;
|
||||
float param1; // If <= 0, this is a specialized box, and the specialization is in param4/5/6
|
||||
float param3; // If == 0, the item should be varied by difficulty and area
|
||||
uint32_t param4;
|
||||
uint32_t param5;
|
||||
uint32_t param6;
|
||||
uint16_t game_flags;
|
||||
// Technically set_flags shouldn't be part of the Object struct, but all
|
||||
// object entries always generate exactly one object, so we store it here.
|
||||
uint16_t set_flags;
|
||||
bool item_drop_checked;
|
||||
|
||||
std::string str() const;
|
||||
};
|
||||
|
||||
struct Enemy {
|
||||
enum Flag {
|
||||
EXP_REQUESTED_BY_PLAYER0 = 0x01,
|
||||
EXP_REQUESTED_BY_PLAYER1 = 0x02,
|
||||
EXP_REQUESTED_BY_PLAYER2 = 0x04,
|
||||
EXP_REQUESTED_BY_PLAYER3 = 0x08,
|
||||
ITEM_DROPPED = 0x10,
|
||||
};
|
||||
size_t source_index;
|
||||
size_t set_index;
|
||||
uint16_t enemy_id;
|
||||
uint16_t total_damage;
|
||||
uint32_t game_flags; // From 6x0A
|
||||
uint16_t section;
|
||||
uint16_t wave_number;
|
||||
EnemyType type;
|
||||
uint8_t floor;
|
||||
uint8_t state_flags;
|
||||
|
||||
Enemy(
|
||||
uint16_t enemy_id,
|
||||
size_t source_index,
|
||||
size_t set_index,
|
||||
uint8_t floor,
|
||||
uint16_t section,
|
||||
uint16_t wave_number,
|
||||
EnemyType type);
|
||||
|
||||
std::string str() const;
|
||||
};
|
||||
|
||||
struct Event {
|
||||
uint32_t event_id;
|
||||
uint16_t flags;
|
||||
uint16_t section;
|
||||
uint16_t wave_number;
|
||||
uint8_t floor;
|
||||
uint32_t action_stream_offset;
|
||||
std::vector<size_t> enemy_indexes;
|
||||
|
||||
std::string str() const;
|
||||
};
|
||||
|
||||
struct DATParserRandomState {
|
||||
PSOV2Encryption random;
|
||||
PSOV2Encryption location_table_random;
|
||||
std::array<uint32_t, 0x20> location_index_table;
|
||||
uint32_t location_indexes_populated;
|
||||
uint32_t location_indexes_used;
|
||||
uint32_t location_entries_base_offset;
|
||||
|
||||
DATParserRandomState(uint32_t rare_seed);
|
||||
size_t rand_int_biased(size_t min_v, size_t max_v);
|
||||
uint32_t next_location_index();
|
||||
void generate_shuffled_location_table(const Map::RandomEnemyLocationsHeader& header, StringReader r, uint16_t section);
|
||||
};
|
||||
|
||||
Map(Version version, uint32_t lobby_id, uint32_t rare_seed, std::shared_ptr<PSOLFGEncryption> opt_rand_crypt);
|
||||
~Map() = default;
|
||||
|
||||
void clear();
|
||||
|
||||
void add_objects_from_map_data(uint8_t floor, const void* data, size_t size);
|
||||
|
||||
bool check_and_log_rare_enemy(bool default_is_rare, uint32_t rare_rate);
|
||||
void add_enemy(
|
||||
Episode episode,
|
||||
uint8_t difficulty,
|
||||
uint8_t event,
|
||||
uint8_t floor,
|
||||
size_t index,
|
||||
const EnemyEntry& e,
|
||||
std::shared_ptr<const RareEnemyRates> rare_rates = DEFAULT_RARE_ENEMIES);
|
||||
void add_enemies_from_map_data(
|
||||
Episode episode,
|
||||
uint8_t difficulty,
|
||||
uint8_t event,
|
||||
uint8_t floor,
|
||||
const void* data,
|
||||
size_t size,
|
||||
std::shared_ptr<const RareEnemyRates> rare_rates = DEFAULT_RARE_ENEMIES);
|
||||
void add_random_enemies_from_map_data(
|
||||
Episode episode,
|
||||
uint8_t difficulty,
|
||||
uint8_t event,
|
||||
uint8_t floor,
|
||||
StringReader wave_events_r,
|
||||
StringReader random_enemy_locations_r,
|
||||
StringReader random_enemy_definitions_r,
|
||||
std::shared_ptr<DATParserRandomState> random_state,
|
||||
std::shared_ptr<const RareEnemyRates> rare_rates = DEFAULT_RARE_ENEMIES);
|
||||
|
||||
void add_event(
|
||||
uint32_t event_id,
|
||||
uint16_t flags,
|
||||
uint8_t floor,
|
||||
uint16_t section,
|
||||
uint16_t wave_number,
|
||||
uint32_t action_stream_offset);
|
||||
std::vector<Event*> get_events(uint8_t floor, uint32_t event_id);
|
||||
std::vector<const Event*> get_events(uint8_t floor, uint32_t event_id) const;
|
||||
void add_events_from_map_data(uint8_t floor, const void* data, size_t size);
|
||||
|
||||
struct DATSectionsForFloor {
|
||||
uint32_t objects = 0xFFFFFFFF;
|
||||
uint32_t enemies = 0xFFFFFFFF;
|
||||
uint32_t wave_events = 0xFFFFFFFF;
|
||||
uint32_t random_enemy_locations = 0xFFFFFFFF;
|
||||
uint32_t random_enemy_definitions = 0xFFFFFFFF;
|
||||
};
|
||||
static std::vector<DATSectionsForFloor> collect_quest_map_data_sections(const void* data, size_t size);
|
||||
|
||||
void add_entities_from_quest_data(
|
||||
Episode episode,
|
||||
uint8_t difficulty,
|
||||
uint8_t event,
|
||||
const void* data,
|
||||
size_t size,
|
||||
std::shared_ptr<const RareEnemyRates> rare_rates = Map::DEFAULT_RARE_ENEMIES);
|
||||
|
||||
const Enemy& find_enemy(uint8_t floor, EnemyType type) const;
|
||||
Enemy& find_enemy(uint8_t floor, EnemyType type);
|
||||
std::vector<Object*> get_objects(uint8_t floor, uint16_t section, uint16_t wave_number);
|
||||
std::vector<Enemy*> get_enemies(uint8_t floor, uint16_t section, uint16_t wave_number);
|
||||
std::vector<Event*> get_events(uint8_t floor, uint16_t section, uint16_t wave_number);
|
||||
std::vector<Event*> get_events(uint8_t floor);
|
||||
|
||||
static std::string disassemble_objects_data(const void* data, size_t size, size_t* object_number = nullptr);
|
||||
static std::string disassemble_enemies_data(const void* data, size_t size, size_t* enemy_number = nullptr);
|
||||
static std::string disassemble_wave_events_data(const void* data, size_t size, uint8_t floor = 0xFF);
|
||||
static std::string disassemble_quest_data(const void* data, size_t size);
|
||||
|
||||
PrefixedLogger log;
|
||||
Version version;
|
||||
uint32_t rare_seed;
|
||||
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt;
|
||||
std::vector<Object> objects;
|
||||
std::vector<Enemy> enemies;
|
||||
std::vector<uint16_t> enemy_set_flags;
|
||||
std::vector<size_t> rare_enemy_indexes;
|
||||
std::vector<Event> events;
|
||||
std::string event_action_stream;
|
||||
std::multimap<uint64_t, size_t> floor_and_event_id_to_index;
|
||||
std::unordered_multimap<uint64_t, size_t> floor_section_and_group_to_object_index;
|
||||
std::unordered_multimap<uint64_t, size_t> floor_section_and_wave_number_to_enemy_index;
|
||||
std::unordered_multimap<uint64_t, size_t> floor_section_and_wave_number_to_event_index;
|
||||
};
|
||||
|
||||
class SetDataTableBase {
|
||||
public:
|
||||
virtual ~SetDataTableBase() = default;
|
||||
|
||||
parray<le_uint32_t, 0x20> generate_variations(
|
||||
Episode episode,
|
||||
bool is_solo,
|
||||
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt = nullptr) const;
|
||||
virtual std::pair<uint32_t, uint32_t> num_available_variations_for_floor(Episode episode, uint8_t floor) const = 0;
|
||||
virtual std::pair<uint32_t, uint32_t> num_free_roam_variations_for_floor(Episode episode, bool is_solo, uint8_t floor) const = 0;
|
||||
|
||||
enum class FilenameType {
|
||||
OBJECTS = 0,
|
||||
ENEMIES,
|
||||
EVENTS,
|
||||
};
|
||||
|
||||
virtual std::string map_filename_for_variation(
|
||||
uint8_t floor, uint32_t var1, uint32_t var2, Episode episode, GameMode mode, FilenameType type) const = 0;
|
||||
std::vector<std::string> map_filenames_for_variations(
|
||||
const parray<le_uint32_t, 0x20>& variations, Episode episode, GameMode mode, FilenameType type) const;
|
||||
|
||||
uint8_t default_area_for_floor(Episode episode, uint8_t floor) const;
|
||||
|
||||
protected:
|
||||
explicit SetDataTableBase(Version version);
|
||||
|
||||
Version version;
|
||||
};
|
||||
|
||||
class SetDataTable : public SetDataTableBase {
|
||||
public:
|
||||
struct SetEntry {
|
||||
std::string object_list_basename;
|
||||
std::string enemy_and_event_list_basename;
|
||||
std::string area_setup_filename;
|
||||
};
|
||||
|
||||
SetDataTable(Version version, const std::string& data);
|
||||
virtual ~SetDataTable() = default;
|
||||
|
||||
virtual std::pair<uint32_t, uint32_t> num_available_variations_for_floor(Episode episode, uint8_t floor) const;
|
||||
virtual std::pair<uint32_t, uint32_t> num_free_roam_variations_for_floor(Episode episode, bool is_solo, uint8_t floor) const;
|
||||
virtual std::string map_filename_for_variation(
|
||||
uint8_t floor, uint32_t var1, uint32_t var2, Episode episode, GameMode mode, FilenameType type) const;
|
||||
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
template <bool IsBigEndian>
|
||||
void load_table_t(const std::string& data);
|
||||
|
||||
// Indexes are [floor][variation1][variation2]
|
||||
// floor is cumulative per episode, so Ep2 starts at floor=18.
|
||||
std::vector<std::vector<std::vector<SetEntry>>> entries;
|
||||
};
|
||||
|
||||
class SetDataTableDCNTE : public SetDataTableBase {
|
||||
public:
|
||||
SetDataTableDCNTE();
|
||||
virtual ~SetDataTableDCNTE() = default;
|
||||
|
||||
virtual std::pair<uint32_t, uint32_t> num_available_variations_for_floor(Episode episode, uint8_t floor) const;
|
||||
virtual std::pair<uint32_t, uint32_t> num_free_roam_variations_for_floor(Episode episode, bool is_solo, uint8_t floor) const;
|
||||
virtual std::string map_filename_for_variation(
|
||||
uint8_t floor, uint32_t var1, uint32_t var2, Episode episode, GameMode mode, FilenameType type) const;
|
||||
|
||||
private:
|
||||
static const std::array<std::vector<std::vector<std::string>>, 0x12> NAMES;
|
||||
};
|
||||
|
||||
class SetDataTableDC112000 : public SetDataTableBase {
|
||||
public:
|
||||
SetDataTableDC112000();
|
||||
virtual ~SetDataTableDC112000() = default;
|
||||
|
||||
virtual std::pair<uint32_t, uint32_t> num_available_variations_for_floor(Episode episode, uint8_t floor) const;
|
||||
virtual std::pair<uint32_t, uint32_t> num_free_roam_variations_for_floor(Episode episode, bool is_solo, uint8_t floor) const;
|
||||
virtual std::string map_filename_for_variation(
|
||||
uint8_t floor, uint32_t var1, uint32_t var2, Episode episode, GameMode mode, FilenameType type) const;
|
||||
|
||||
private:
|
||||
static const std::array<std::vector<std::vector<std::string>>, 0x12> NAMES;
|
||||
};
|
||||
|
||||
void generate_variations_deprecated(
|
||||
parray<le_uint32_t, 0x20>& variations,
|
||||
std::shared_ptr<PSOLFGEncryption> random,
|
||||
Version version,
|
||||
Episode episode,
|
||||
bool is_solo);
|
||||
|
||||
parray<le_uint32_t, 0x20> variation_maxes_deprecated(Version version, Episode episode, bool is_solo);
|
||||
bool next_variation_deprecated(parray<le_uint32_t, 0x20>& variations, Version version, Episode episode, bool is_solo);
|
||||
|
||||
std::vector<std::string> map_filenames_for_variation_deprecated(
|
||||
uint8_t floor, uint32_t var1, uint32_t var2, Version version, Episode episode, GameMode mode, bool is_enemies);
|
||||
std::vector<std::vector<std::string>> map_filenames_for_variations_deprecated(
|
||||
const parray<le_uint32_t, 0x20>& variations,
|
||||
Version version,
|
||||
Episode episode,
|
||||
GameMode mode,
|
||||
bool is_enemies);
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <memory>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/JSON.hh>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "BattleParamsIndex.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
struct Map {
|
||||
static const char* name_for_object_type(uint16_t type);
|
||||
|
||||
struct SectionHeader {
|
||||
enum class Type {
|
||||
END = 0,
|
||||
OBJECTS = 1,
|
||||
ENEMIES = 2,
|
||||
WAVE_EVENTS = 3,
|
||||
RANDOM_ENEMY_LOCATIONS = 4,
|
||||
RANDOM_ENEMY_DEFINITIONS = 5,
|
||||
};
|
||||
le_uint32_t le_type;
|
||||
le_uint32_t section_size; // Includes this header
|
||||
le_uint32_t floor;
|
||||
le_uint32_t data_size;
|
||||
|
||||
inline Type type() const {
|
||||
return static_cast<Type>(this->le_type.load());
|
||||
}
|
||||
} __packed_ws__(SectionHeader, 0x10);
|
||||
|
||||
struct ObjectEntry { // Section type 1 (OBJECTS)
|
||||
/* 00 */ le_uint16_t base_type;
|
||||
/* 02 */ le_uint16_t flags;
|
||||
/* 04 */ le_uint16_t index;
|
||||
/* 06 */ le_uint16_t unknown_a2;
|
||||
/* 08 */ le_uint16_t entity_id; // == index + 0x4000
|
||||
/* 0A */ le_uint16_t group;
|
||||
/* 0C */ le_uint16_t section;
|
||||
/* 0E */ le_uint16_t unknown_a3;
|
||||
/* 10 */ le_float x;
|
||||
/* 14 */ le_float y;
|
||||
/* 18 */ le_float z;
|
||||
/* 1C */ le_uint32_t x_angle;
|
||||
/* 20 */ le_uint32_t y_angle;
|
||||
/* 24 */ le_uint32_t z_angle;
|
||||
/* 28 */ le_float param1; // If <= 0, this is a specialized box, and the specialization is in param4/5/6
|
||||
/* 2C */ le_float param2;
|
||||
/* 30 */ le_float param3;
|
||||
/* 34 */ le_uint32_t param4;
|
||||
/* 38 */ le_uint32_t param5;
|
||||
/* 3C */ le_uint32_t param6;
|
||||
/* 40 */ le_uint32_t unused; // Reserved for pointer in client's memory; unused by server
|
||||
/* 44 */
|
||||
|
||||
std::string str() const;
|
||||
} __packed_ws__(ObjectEntry, 0x44);
|
||||
|
||||
struct EnemyEntry { // Section type 2 (ENEMIES)
|
||||
/* 00 */ le_uint16_t base_type;
|
||||
/* 02 */ le_uint16_t flags;
|
||||
/* 04 */ le_uint16_t index;
|
||||
/* 06 */ le_uint16_t num_children;
|
||||
/* 08 */ le_uint16_t floor;
|
||||
/* 0A */ le_uint16_t entity_id; // == index + 0x1000
|
||||
/* 0C */ le_uint16_t section;
|
||||
/* 0E */ le_uint16_t wave_number;
|
||||
/* 10 */ le_uint16_t wave_number2;
|
||||
/* 12 */ le_uint16_t unknown_a1;
|
||||
/* 14 */ le_float x;
|
||||
/* 18 */ le_float y;
|
||||
/* 1C */ le_float z;
|
||||
/* 20 */ le_uint32_t x_angle;
|
||||
/* 24 */ le_uint32_t y_angle;
|
||||
/* 28 */ le_uint32_t z_angle;
|
||||
/* 2C */ le_float fparam1;
|
||||
/* 30 */ le_float fparam2;
|
||||
/* 34 */ le_float fparam3;
|
||||
/* 38 */ le_float fparam4;
|
||||
/* 3C */ le_float fparam5;
|
||||
/* 40 */ le_uint16_t uparam1;
|
||||
/* 42 */ le_uint16_t uparam2;
|
||||
/* 44 */ le_uint32_t unused; // Reserved for pointer in client's memory; unused by server
|
||||
/* 48 */
|
||||
|
||||
std::string str() const;
|
||||
} __packed_ws__(EnemyEntry, 0x48);
|
||||
|
||||
struct EventsSectionHeader { // Section type 3 (WAVE_EVENTS)
|
||||
/* 00 */ le_uint32_t action_stream_offset;
|
||||
/* 04 */ le_uint32_t entries_offset;
|
||||
/* 08 */ le_uint32_t entry_count;
|
||||
/* 0C */ be_uint32_t format; // 0 or 'evt2'
|
||||
/* 10 */
|
||||
} __packed_ws__(EventsSectionHeader, 0x10);
|
||||
|
||||
struct Event1Entry { // Section type 3 (WAVE_EVENTS) if format == 0
|
||||
/* 00 */ le_uint32_t event_id;
|
||||
// Bits in flags:
|
||||
// 0004 = is active
|
||||
// 0008 = post-wave actions have been run
|
||||
// 0010 = all enemies killed
|
||||
/* 04 */ le_uint16_t flags;
|
||||
/* 06 */ le_uint16_t event_type;
|
||||
/* 08 */ le_uint16_t section;
|
||||
/* 0A */ le_uint16_t wave_number;
|
||||
/* 0C */ le_uint32_t delay;
|
||||
/* 10 */ le_uint32_t action_stream_offset;
|
||||
/* 14 */
|
||||
} __packed_ws__(Event1Entry, 0x14);
|
||||
|
||||
struct Event2Entry { // Section type 3 (WAVE_EVENTS) if format == 'evt2'
|
||||
/* 00 */ le_uint32_t event_id;
|
||||
/* 04 */ le_uint16_t flags;
|
||||
/* 06 */ le_uint16_t event_type;
|
||||
/* 08 */ le_uint16_t section;
|
||||
/* 0A */ le_uint16_t wave_number;
|
||||
/* 0C */ le_uint16_t min_delay;
|
||||
/* 0E */ le_uint16_t max_delay;
|
||||
/* 10 */ uint8_t min_enemies;
|
||||
/* 11 */ uint8_t max_enemies;
|
||||
/* 12 */ le_uint16_t max_waves;
|
||||
/* 14 */ le_uint32_t action_stream_offset;
|
||||
/* 18 */
|
||||
} __packed_ws__(Event2Entry, 0x18);
|
||||
|
||||
struct RandomEnemyLocationsHeader { // Section type 4 (RANDOM_ENEMY_LOCATIONS)
|
||||
/* 00 */ le_uint32_t section_table_offset; // Offset to RandomEnemyLocationSegment structs, from start of this struct
|
||||
/* 04 */ le_uint32_t entries_offset; // Offset to RandomEnemyLocationEntry structs, from start of this struct
|
||||
/* 08 */ le_uint32_t num_sections;
|
||||
/* 0C */
|
||||
} __packed_ws__(RandomEnemyLocationsHeader, 0x0C);
|
||||
|
||||
struct RandomEnemyLocationSection { // Section type 4 (RANDOM_ENEMY_LOCATIONS)
|
||||
/* 00 */ le_uint16_t section;
|
||||
/* 02 */ le_uint16_t count;
|
||||
/* 04 */ le_uint32_t offset;
|
||||
/* 08 */
|
||||
} __packed_ws__(RandomEnemyLocationSection, 8);
|
||||
|
||||
struct RandomEnemyLocationEntry { // Section type 4 (RANDOM_ENEMY_LOCATIONS)
|
||||
/* 00 */ le_float x;
|
||||
/* 04 */ le_float y;
|
||||
/* 08 */ le_float z;
|
||||
/* 0C */ le_uint32_t x_angle;
|
||||
/* 10 */ le_uint32_t y_angle;
|
||||
/* 14 */ le_uint32_t z_angle;
|
||||
/* 18 */ uint16_t unknown_a9;
|
||||
/* 1A */ uint16_t unknown_a10;
|
||||
/* 1C */
|
||||
} __packed_ws__(RandomEnemyLocationEntry, 0x1C);
|
||||
|
||||
struct RandomEnemyDefinitionsHeader { // Section type 5 (RANDOM_ENEMY_DEFINITIONS)
|
||||
/* 00 */ le_uint32_t entries_offset; // Offset to RandomEnemyDefinition structs, from start of this struct
|
||||
/* 04 */ le_uint32_t weight_entries_offset; // Offset to RandomEnemyDefinitionWeights structs, from start of this struct
|
||||
/* 08 */ le_uint32_t entry_count;
|
||||
/* 0C */ le_uint32_t weight_entry_count;
|
||||
/* 10 */
|
||||
} __packed_ws__(RandomEnemyDefinitionsHeader, 0x10);
|
||||
|
||||
struct RandomEnemyDefinition { // Section type 5 (RANDOM_ENEMY_DEFINITIONS)
|
||||
// All fields through entry_num map to the corresponding fields in
|
||||
// EnemyEntry. Note that the order of the uparam fields is switched!
|
||||
/* 00 */ le_float fparam1;
|
||||
/* 04 */ le_float fparam2;
|
||||
/* 08 */ le_float fparam3;
|
||||
/* 0C */ le_float fparam4;
|
||||
/* 10 */ le_float fparam5;
|
||||
/* 14 */ le_uint16_t uparam2;
|
||||
/* 16 */ le_uint16_t uparam1;
|
||||
/* 18 */ le_uint32_t entry_num;
|
||||
/* 1C */ le_uint16_t min_children;
|
||||
/* 1E */ le_uint16_t max_children;
|
||||
/* 20 */
|
||||
} __packed_ws__(RandomEnemyDefinition, 0x20);
|
||||
|
||||
struct RandomEnemyWeight { // Section type 5 (RANDOM_ENEMY_DEFINITIONS)
|
||||
/* 00 */ uint8_t base_type_index;
|
||||
/* 01 */ uint8_t definition_entry_num;
|
||||
/* 02 */ uint8_t weight;
|
||||
/* 03 */ uint8_t unknown_a4;
|
||||
/* 04 */
|
||||
} __packed_ws__(RandomEnemyWeight, 4);
|
||||
|
||||
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
|
||||
|
||||
RareEnemyRates(uint32_t enemy_rate, uint32_t boss_rate);
|
||||
explicit RareEnemyRates(const JSON& json);
|
||||
|
||||
JSON json() const;
|
||||
};
|
||||
|
||||
static const std::shared_ptr<const RareEnemyRates> NO_RARE_ENEMIES;
|
||||
static const std::shared_ptr<const RareEnemyRates> DEFAULT_RARE_ENEMIES;
|
||||
|
||||
struct Object {
|
||||
// TODO: Add more fields in here if we ever care about them. Currently we
|
||||
// only care about boxes with fixed item drops.
|
||||
size_t source_index;
|
||||
uint8_t floor;
|
||||
uint16_t object_id;
|
||||
uint16_t base_type;
|
||||
uint16_t section;
|
||||
uint16_t group;
|
||||
float param1; // If <= 0, this is a specialized box, and the specialization is in param4/5/6
|
||||
float param3; // If == 0, the item should be varied by difficulty and area
|
||||
uint32_t param4;
|
||||
uint32_t param5;
|
||||
uint32_t param6;
|
||||
uint16_t game_flags;
|
||||
// Technically set_flags shouldn't be part of the Object struct, but all
|
||||
// object entries always generate exactly one object, so we store it here.
|
||||
uint16_t set_flags;
|
||||
bool item_drop_checked;
|
||||
|
||||
std::string str() const;
|
||||
};
|
||||
|
||||
struct Enemy {
|
||||
enum Flag {
|
||||
LAST_HIT_MASK = 0x03,
|
||||
EXP_GIVEN = 0x04,
|
||||
ITEM_DROPPED = 0x08,
|
||||
ALL_HITS_MASK_FIRST = 0x10,
|
||||
ALL_HITS_MASK = 0xF0,
|
||||
};
|
||||
size_t source_index;
|
||||
size_t set_index;
|
||||
uint16_t enemy_id;
|
||||
uint16_t total_damage;
|
||||
uint32_t game_flags; // From 6x0A
|
||||
uint16_t section;
|
||||
uint16_t wave_number;
|
||||
EnemyType type;
|
||||
uint8_t floor;
|
||||
uint8_t server_flags;
|
||||
|
||||
Enemy(
|
||||
uint16_t enemy_id,
|
||||
size_t source_index,
|
||||
size_t set_index,
|
||||
uint8_t floor,
|
||||
uint16_t section,
|
||||
uint16_t wave_number,
|
||||
EnemyType type);
|
||||
|
||||
std::string str() const;
|
||||
|
||||
inline bool ever_hit_by_client_id(uint8_t client_id) const {
|
||||
return this->server_flags & (Flag::ALL_HITS_MASK_FIRST << client_id);
|
||||
}
|
||||
inline bool last_hit_by_client_id(uint8_t client_id) const {
|
||||
return (this->server_flags & Flag::LAST_HIT_MASK) == client_id;
|
||||
}
|
||||
inline void set_last_hit_by_client_id(uint8_t client_id) {
|
||||
this->server_flags = (this->server_flags & (~Flag::LAST_HIT_MASK)) | (Flag::ALL_HITS_MASK_FIRST << client_id) | (client_id & 3);
|
||||
}
|
||||
};
|
||||
|
||||
struct Event {
|
||||
uint32_t event_id;
|
||||
uint16_t flags;
|
||||
uint16_t section;
|
||||
uint16_t wave_number;
|
||||
uint8_t floor;
|
||||
uint32_t action_stream_offset;
|
||||
std::vector<size_t> enemy_indexes;
|
||||
|
||||
std::string str() const;
|
||||
};
|
||||
|
||||
struct DATParserRandomState {
|
||||
PSOV2Encryption random;
|
||||
PSOV2Encryption location_table_random;
|
||||
std::array<uint32_t, 0x20> location_index_table;
|
||||
uint32_t location_indexes_populated;
|
||||
uint32_t location_indexes_used;
|
||||
uint32_t location_entries_base_offset;
|
||||
|
||||
DATParserRandomState(uint32_t rare_seed);
|
||||
size_t rand_int_biased(size_t min_v, size_t max_v);
|
||||
uint32_t next_location_index();
|
||||
void generate_shuffled_location_table(const Map::RandomEnemyLocationsHeader& header, StringReader r, uint16_t section);
|
||||
};
|
||||
|
||||
Map(Version version, uint32_t lobby_id, uint32_t rare_seed, std::shared_ptr<PSOLFGEncryption> opt_rand_crypt);
|
||||
~Map() = default;
|
||||
|
||||
void clear();
|
||||
|
||||
void add_objects_from_map_data(uint8_t floor, const void* data, size_t size);
|
||||
|
||||
bool check_and_log_rare_enemy(bool default_is_rare, uint32_t rare_rate);
|
||||
void add_enemy(
|
||||
Episode episode,
|
||||
uint8_t difficulty,
|
||||
uint8_t event,
|
||||
uint8_t floor,
|
||||
size_t index,
|
||||
const EnemyEntry& e,
|
||||
std::shared_ptr<const RareEnemyRates> rare_rates = DEFAULT_RARE_ENEMIES);
|
||||
void add_enemies_from_map_data(
|
||||
Episode episode,
|
||||
uint8_t difficulty,
|
||||
uint8_t event,
|
||||
uint8_t floor,
|
||||
const void* data,
|
||||
size_t size,
|
||||
std::shared_ptr<const RareEnemyRates> rare_rates = DEFAULT_RARE_ENEMIES);
|
||||
void add_random_enemies_from_map_data(
|
||||
Episode episode,
|
||||
uint8_t difficulty,
|
||||
uint8_t event,
|
||||
uint8_t floor,
|
||||
StringReader wave_events_r,
|
||||
StringReader random_enemy_locations_r,
|
||||
StringReader random_enemy_definitions_r,
|
||||
std::shared_ptr<DATParserRandomState> random_state,
|
||||
std::shared_ptr<const RareEnemyRates> rare_rates = DEFAULT_RARE_ENEMIES);
|
||||
|
||||
void add_event(
|
||||
uint32_t event_id,
|
||||
uint16_t flags,
|
||||
uint8_t floor,
|
||||
uint16_t section,
|
||||
uint16_t wave_number,
|
||||
uint32_t action_stream_offset);
|
||||
std::vector<Event*> get_events(uint8_t floor, uint32_t event_id);
|
||||
std::vector<const Event*> get_events(uint8_t floor, uint32_t event_id) const;
|
||||
void add_events_from_map_data(uint8_t floor, const void* data, size_t size);
|
||||
|
||||
struct DATSectionsForFloor {
|
||||
uint32_t objects = 0xFFFFFFFF;
|
||||
uint32_t enemies = 0xFFFFFFFF;
|
||||
uint32_t wave_events = 0xFFFFFFFF;
|
||||
uint32_t random_enemy_locations = 0xFFFFFFFF;
|
||||
uint32_t random_enemy_definitions = 0xFFFFFFFF;
|
||||
};
|
||||
static std::vector<DATSectionsForFloor> collect_quest_map_data_sections(const void* data, size_t size);
|
||||
|
||||
void add_entities_from_quest_data(
|
||||
Episode episode,
|
||||
uint8_t difficulty,
|
||||
uint8_t event,
|
||||
const void* data,
|
||||
size_t size,
|
||||
std::shared_ptr<const RareEnemyRates> rare_rates = Map::DEFAULT_RARE_ENEMIES);
|
||||
|
||||
const Enemy& find_enemy(uint8_t floor, EnemyType type) const;
|
||||
Enemy& find_enemy(uint8_t floor, EnemyType type);
|
||||
std::vector<Object*> get_objects(uint8_t floor, uint16_t section, uint16_t wave_number);
|
||||
std::vector<Enemy*> get_enemies(uint8_t floor, uint16_t section, uint16_t wave_number);
|
||||
std::vector<Event*> get_events(uint8_t floor, uint16_t section, uint16_t wave_number);
|
||||
std::vector<Event*> get_events(uint8_t floor);
|
||||
|
||||
static std::string disassemble_objects_data(const void* data, size_t size, size_t* object_number = nullptr);
|
||||
static std::string disassemble_enemies_data(const void* data, size_t size, size_t* enemy_number = nullptr);
|
||||
static std::string disassemble_wave_events_data(const void* data, size_t size, uint8_t floor = 0xFF);
|
||||
static std::string disassemble_quest_data(const void* data, size_t size);
|
||||
|
||||
PrefixedLogger log;
|
||||
Version version;
|
||||
uint32_t rare_seed;
|
||||
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt;
|
||||
std::vector<Object> objects;
|
||||
std::vector<Enemy> enemies;
|
||||
std::vector<uint16_t> enemy_set_flags;
|
||||
std::vector<size_t> rare_enemy_indexes;
|
||||
std::vector<Event> events;
|
||||
std::string event_action_stream;
|
||||
std::multimap<uint64_t, size_t> floor_and_event_id_to_index;
|
||||
std::unordered_multimap<uint64_t, size_t> floor_section_and_group_to_object_index;
|
||||
std::unordered_multimap<uint64_t, size_t> floor_section_and_wave_number_to_enemy_index;
|
||||
std::unordered_multimap<uint64_t, size_t> floor_section_and_wave_number_to_event_index;
|
||||
};
|
||||
|
||||
class SetDataTableBase {
|
||||
public:
|
||||
virtual ~SetDataTableBase() = default;
|
||||
|
||||
parray<le_uint32_t, 0x20> generate_variations(
|
||||
Episode episode,
|
||||
bool is_solo,
|
||||
std::shared_ptr<PSOLFGEncryption> opt_rand_crypt = nullptr) const;
|
||||
virtual std::pair<uint32_t, uint32_t> num_available_variations_for_floor(Episode episode, uint8_t floor) const = 0;
|
||||
virtual std::pair<uint32_t, uint32_t> num_free_roam_variations_for_floor(Episode episode, bool is_solo, uint8_t floor) const = 0;
|
||||
|
||||
enum class FilenameType {
|
||||
OBJECTS = 0,
|
||||
ENEMIES,
|
||||
EVENTS,
|
||||
};
|
||||
|
||||
virtual std::string map_filename_for_variation(
|
||||
uint8_t floor, uint32_t var1, uint32_t var2, Episode episode, GameMode mode, FilenameType type) const = 0;
|
||||
std::vector<std::string> map_filenames_for_variations(
|
||||
const parray<le_uint32_t, 0x20>& variations, Episode episode, GameMode mode, FilenameType type) const;
|
||||
|
||||
uint8_t default_area_for_floor(Episode episode, uint8_t floor) const;
|
||||
|
||||
protected:
|
||||
explicit SetDataTableBase(Version version);
|
||||
|
||||
Version version;
|
||||
};
|
||||
|
||||
class SetDataTable : public SetDataTableBase {
|
||||
public:
|
||||
struct SetEntry {
|
||||
std::string object_list_basename;
|
||||
std::string enemy_and_event_list_basename;
|
||||
std::string area_setup_filename;
|
||||
};
|
||||
|
||||
SetDataTable(Version version, const std::string& data);
|
||||
virtual ~SetDataTable() = default;
|
||||
|
||||
virtual std::pair<uint32_t, uint32_t> num_available_variations_for_floor(Episode episode, uint8_t floor) const;
|
||||
virtual std::pair<uint32_t, uint32_t> num_free_roam_variations_for_floor(Episode episode, bool is_solo, uint8_t floor) const;
|
||||
virtual std::string map_filename_for_variation(
|
||||
uint8_t floor, uint32_t var1, uint32_t var2, Episode episode, GameMode mode, FilenameType type) const;
|
||||
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
template <bool IsBigEndian>
|
||||
void load_table_t(const std::string& data);
|
||||
|
||||
// Indexes are [floor][variation1][variation2]
|
||||
// floor is cumulative per episode, so Ep2 starts at floor=18.
|
||||
std::vector<std::vector<std::vector<SetEntry>>> entries;
|
||||
};
|
||||
|
||||
class SetDataTableDCNTE : public SetDataTableBase {
|
||||
public:
|
||||
SetDataTableDCNTE();
|
||||
virtual ~SetDataTableDCNTE() = default;
|
||||
|
||||
virtual std::pair<uint32_t, uint32_t> num_available_variations_for_floor(Episode episode, uint8_t floor) const;
|
||||
virtual std::pair<uint32_t, uint32_t> num_free_roam_variations_for_floor(Episode episode, bool is_solo, uint8_t floor) const;
|
||||
virtual std::string map_filename_for_variation(
|
||||
uint8_t floor, uint32_t var1, uint32_t var2, Episode episode, GameMode mode, FilenameType type) const;
|
||||
|
||||
private:
|
||||
static const std::array<std::vector<std::vector<std::string>>, 0x12> NAMES;
|
||||
};
|
||||
|
||||
class SetDataTableDC112000 : public SetDataTableBase {
|
||||
public:
|
||||
SetDataTableDC112000();
|
||||
virtual ~SetDataTableDC112000() = default;
|
||||
|
||||
virtual std::pair<uint32_t, uint32_t> num_available_variations_for_floor(Episode episode, uint8_t floor) const;
|
||||
virtual std::pair<uint32_t, uint32_t> num_free_roam_variations_for_floor(Episode episode, bool is_solo, uint8_t floor) const;
|
||||
virtual std::string map_filename_for_variation(
|
||||
uint8_t floor, uint32_t var1, uint32_t var2, Episode episode, GameMode mode, FilenameType type) const;
|
||||
|
||||
private:
|
||||
static const std::array<std::vector<std::vector<std::string>>, 0x12> NAMES;
|
||||
};
|
||||
|
||||
void generate_variations_deprecated(
|
||||
parray<le_uint32_t, 0x20>& variations,
|
||||
std::shared_ptr<PSOLFGEncryption> random,
|
||||
Version version,
|
||||
Episode episode,
|
||||
bool is_solo);
|
||||
|
||||
parray<le_uint32_t, 0x20> variation_maxes_deprecated(Version version, Episode episode, bool is_solo);
|
||||
bool next_variation_deprecated(parray<le_uint32_t, 0x20>& variations, Version version, Episode episode, bool is_solo);
|
||||
|
||||
std::vector<std::string> map_filenames_for_variation_deprecated(
|
||||
uint8_t floor, uint32_t var1, uint32_t var2, Version version, Episode episode, GameMode mode, bool is_enemies);
|
||||
std::vector<std::vector<std::string>> map_filenames_for_variations_deprecated(
|
||||
const parray<le_uint32_t, 0x20>& variations,
|
||||
Version version,
|
||||
Episode episode,
|
||||
GameMode mode,
|
||||
bool is_enemies);
|
||||
|
||||
+149
-146
@@ -1,146 +1,149 @@
|
||||
#pragma once
|
||||
|
||||
#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
|
||||
// aren't namespaced unless they're enum classes), so we can't use enums. But we
|
||||
// also want to be able to use non-enum values in switch statements without
|
||||
// casting values all over the place, so we can't use enum classes either.
|
||||
|
||||
namespace MenuID {
|
||||
constexpr uint32_t MAIN = 0x11000011;
|
||||
constexpr uint32_t CLEAR_LICENSE_CONFIRMATION = 0x11111111;
|
||||
constexpr uint32_t INFORMATION = 0x22000022;
|
||||
constexpr uint32_t LOBBY = 0x33000033;
|
||||
constexpr uint32_t GAME = 0x44000044;
|
||||
constexpr uint32_t QUEST_EP1 = 0x55010155;
|
||||
constexpr uint32_t QUEST_EP2 = 0x55020255;
|
||||
constexpr uint32_t QUEST_CATEGORIES = 0x66010166;
|
||||
constexpr uint32_t PROXY_DESTINATIONS = 0x77000077;
|
||||
constexpr uint32_t PROGRAMS = 0x88000088;
|
||||
constexpr uint32_t PATCHES = 0x99000099;
|
||||
constexpr uint32_t PATCH_SWITCHES = 0x99010199;
|
||||
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 PATCH_SWITCHES = 0x11676711;
|
||||
constexpr uint32_t PROGRAMS = 0x11777711;
|
||||
constexpr uint32_t DISCONNECT = 0x11888811;
|
||||
constexpr uint32_t CLEAR_LICENSE = 0x11999911;
|
||||
} // namespace MainMenuItemID
|
||||
|
||||
namespace ClearLicenseConfirmationMenuItemID {
|
||||
constexpr uint32_t CANCEL = 0x01010101;
|
||||
constexpr uint32_t CLEAR_LICENSE = 0x02020202;
|
||||
} // namespace ClearLicenseConfirmationMenuItemID
|
||||
|
||||
namespace InformationMenuItemID {
|
||||
constexpr uint32_t GO_BACK = 0x22FFFF22;
|
||||
}
|
||||
|
||||
namespace ProxyDestinationsMenuItemID {
|
||||
constexpr uint32_t GO_BACK = 0x77FFFF77;
|
||||
constexpr uint32_t OPTIONS = 0x77EEEE77;
|
||||
} // namespace ProxyDestinationsMenuItemID
|
||||
|
||||
namespace ProgramsMenuItemID {
|
||||
constexpr uint32_t GO_BACK = 0x88FFFF88;
|
||||
}
|
||||
|
||||
namespace PatchesMenuItemID {
|
||||
constexpr uint32_t GO_BACK = 0x99FFFF99;
|
||||
}
|
||||
|
||||
namespace ProxyOptionsMenuItemID {
|
||||
constexpr uint32_t GO_BACK = 0xAAFFFFAA;
|
||||
constexpr uint32_t CHAT_COMMANDS = 0xAA0101AA;
|
||||
constexpr uint32_t PLAYER_NOTIFICATIONS = 0xAA0202AA;
|
||||
constexpr uint32_t DROP_NOTIFICATIONS = 0xAA0303AA;
|
||||
constexpr uint32_t BLOCK_PINGS = 0xAA0404AA;
|
||||
constexpr uint32_t INFINITE_HP = 0xAA0505AA;
|
||||
constexpr uint32_t INFINITE_TP = 0xAA0606AA;
|
||||
constexpr uint32_t SWITCH_ASSIST = 0xAA0707AA;
|
||||
constexpr uint32_t BLOCK_EVENTS = 0xAA0808AA;
|
||||
constexpr uint32_t BLOCK_PATCHES = 0xAA0909AA;
|
||||
constexpr uint32_t SAVE_FILES = 0xAA0A0AAA;
|
||||
constexpr uint32_t RED_NAME = 0xAA0B0BAA;
|
||||
constexpr uint32_t BLANK_NAME = 0xAA0C0CAA;
|
||||
constexpr uint32_t SUPPRESS_LOGIN = 0xAA0D0DAA;
|
||||
constexpr uint32_t SKIP_CARD = 0xAA0E0EAA;
|
||||
constexpr uint32_t EP3_INFINITE_MESETA = 0xAA0F0FAA;
|
||||
constexpr uint32_t EP3_INFINITE_TIME = 0xAA1010AA;
|
||||
constexpr uint32_t EP3_UNMASK_WHISPERS = 0xAA1111AA;
|
||||
} // namespace ProxyOptionsMenuItemID
|
||||
|
||||
namespace TeamRewardMenuItemID {
|
||||
constexpr uint32_t TEAM_FLAG = 0x01010101;
|
||||
constexpr uint32_t DRESSING_ROOM = 0x02020202;
|
||||
constexpr uint32_t MEMBERS_20_LEADERS_3 = 0x03030303;
|
||||
constexpr uint32_t MEMBERS_40_LEADERS_5 = 0x04040404;
|
||||
constexpr uint32_t MEMBERS_70_LEADERS_8 = 0x05050505;
|
||||
constexpr uint32_t MEMBERS_100_LEADERS_10 = 0x06060606;
|
||||
// constexpr uint32_t POINT_OF_DISASTER = ...;
|
||||
// constexpr uint32_t TOYS_TWILIGHT = ...;
|
||||
// constexpr uint32_t COMMANDER_BLADE = ...;
|
||||
// constexpr uint32_t UNION_GUARD = ...;
|
||||
// constexpr uint32_t TEAM_POINTS_500 = ...;
|
||||
// constexpr uint32_t TEAM_POINTS_1000 = ...;
|
||||
// constexpr uint32_t TEAM_POINTS_5000 = ...;
|
||||
// constexpr uint32_t TEAM_POINTS_10000 = ...;
|
||||
} // namespace TeamRewardMenuItemID
|
||||
|
||||
struct MenuItem {
|
||||
enum Flag {
|
||||
// For menu items to be visible on DC NTE, they must not have either of the
|
||||
// following two flags. (The INVISIBLE_ON_GC_NTE flag behaves similarly.)
|
||||
INVISIBLE_ON_DC_PROTOS = 0x001,
|
||||
INVISIBLE_ON_DC = 0x002,
|
||||
INVISIBLE_ON_PC_NTE = 0x004,
|
||||
INVISIBLE_ON_PC = 0x008,
|
||||
INVISIBLE_ON_GC_NTE = 0x010,
|
||||
INVISIBLE_ON_GC = 0x020,
|
||||
INVISIBLE_ON_XB = 0x040,
|
||||
INVISIBLE_ON_BB = 0x080,
|
||||
DC_ONLY = INVISIBLE_ON_PC | INVISIBLE_ON_GC | INVISIBLE_ON_XB | INVISIBLE_ON_BB,
|
||||
PC_ONLY = INVISIBLE_ON_DC | INVISIBLE_ON_GC | INVISIBLE_ON_XB | INVISIBLE_ON_BB,
|
||||
GC_ONLY = INVISIBLE_ON_DC | INVISIBLE_ON_PC | INVISIBLE_ON_XB | INVISIBLE_ON_BB,
|
||||
XB_ONLY = INVISIBLE_ON_DC | INVISIBLE_ON_PC | INVISIBLE_ON_GC | INVISIBLE_ON_BB,
|
||||
BB_ONLY = INVISIBLE_ON_DC | INVISIBLE_ON_PC | INVISIBLE_ON_GC | INVISIBLE_ON_XB,
|
||||
REQUIRES_MESSAGE_BOXES = 0x100,
|
||||
REQUIRES_SEND_FUNCTION_CALL = 0x200,
|
||||
REQUIRES_SAVE_DISABLED = 0x400,
|
||||
INVISIBLE_IN_INFO_MENU = 0x800,
|
||||
};
|
||||
|
||||
uint32_t item_id;
|
||||
std::string name;
|
||||
std::string description;
|
||||
std::function<std::string()> get_description;
|
||||
uint32_t flags;
|
||||
|
||||
MenuItem(uint32_t item_id, const std::string& name, const std::string& description, uint32_t flags);
|
||||
MenuItem(uint32_t item_id, const std::string& name, std::function<std::string()> get_description, uint32_t flags);
|
||||
};
|
||||
|
||||
struct Menu {
|
||||
uint32_t menu_id;
|
||||
std::string name;
|
||||
std::vector<MenuItem> items;
|
||||
|
||||
Menu() = delete;
|
||||
Menu(uint32_t menu_id, const std::string& name);
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#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
|
||||
// aren't namespaced unless they're enum classes), so we can't use enums. But we
|
||||
// also want to be able to use non-enum values in switch statements without
|
||||
// casting values all over the place, so we can't use enum classes either.
|
||||
|
||||
namespace MenuID {
|
||||
constexpr uint32_t MAIN = 0x11000011;
|
||||
constexpr uint32_t CLEAR_LICENSE_CONFIRMATION = 0x11111111;
|
||||
constexpr uint32_t INFORMATION = 0x22000022;
|
||||
constexpr uint32_t LOBBY = 0x33000033;
|
||||
constexpr uint32_t GAME = 0x44000044;
|
||||
constexpr uint32_t QUEST_EP1 = 0x55010155;
|
||||
constexpr uint32_t QUEST_EP2 = 0x55020255;
|
||||
// See the decsription of the A2 command in CommandFormats.hh for why these
|
||||
// menu IDs don't fit the rest of the pattern.
|
||||
constexpr uint32_t QUEST_CATEGORIES_EP1 = 0x01000001;
|
||||
constexpr uint32_t QUEST_CATEGORIES_EP2 = 0x02000002;
|
||||
constexpr uint32_t PROXY_DESTINATIONS = 0x77000077;
|
||||
constexpr uint32_t PROGRAMS = 0x88000088;
|
||||
constexpr uint32_t PATCHES = 0x99000099;
|
||||
constexpr uint32_t PATCH_SWITCHES = 0x99010199;
|
||||
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 PATCH_SWITCHES = 0x11676711;
|
||||
constexpr uint32_t PROGRAMS = 0x11777711;
|
||||
constexpr uint32_t DISCONNECT = 0x11888811;
|
||||
constexpr uint32_t CLEAR_LICENSE = 0x11999911;
|
||||
} // namespace MainMenuItemID
|
||||
|
||||
namespace ClearLicenseConfirmationMenuItemID {
|
||||
constexpr uint32_t CANCEL = 0x01010101;
|
||||
constexpr uint32_t CLEAR_LICENSE = 0x02020202;
|
||||
} // namespace ClearLicenseConfirmationMenuItemID
|
||||
|
||||
namespace InformationMenuItemID {
|
||||
constexpr uint32_t GO_BACK = 0x22FFFF22;
|
||||
}
|
||||
|
||||
namespace ProxyDestinationsMenuItemID {
|
||||
constexpr uint32_t GO_BACK = 0x77FFFF77;
|
||||
constexpr uint32_t OPTIONS = 0x77EEEE77;
|
||||
} // namespace ProxyDestinationsMenuItemID
|
||||
|
||||
namespace ProgramsMenuItemID {
|
||||
constexpr uint32_t GO_BACK = 0x88FFFF88;
|
||||
}
|
||||
|
||||
namespace PatchesMenuItemID {
|
||||
constexpr uint32_t GO_BACK = 0x99FFFF99;
|
||||
}
|
||||
|
||||
namespace ProxyOptionsMenuItemID {
|
||||
constexpr uint32_t GO_BACK = 0xAAFFFFAA;
|
||||
constexpr uint32_t CHAT_COMMANDS = 0xAA0101AA;
|
||||
constexpr uint32_t PLAYER_NOTIFICATIONS = 0xAA0202AA;
|
||||
constexpr uint32_t DROP_NOTIFICATIONS = 0xAA0303AA;
|
||||
constexpr uint32_t BLOCK_PINGS = 0xAA0404AA;
|
||||
constexpr uint32_t INFINITE_HP = 0xAA0505AA;
|
||||
constexpr uint32_t INFINITE_TP = 0xAA0606AA;
|
||||
constexpr uint32_t SWITCH_ASSIST = 0xAA0707AA;
|
||||
constexpr uint32_t BLOCK_EVENTS = 0xAA0808AA;
|
||||
constexpr uint32_t BLOCK_PATCHES = 0xAA0909AA;
|
||||
constexpr uint32_t SAVE_FILES = 0xAA0A0AAA;
|
||||
constexpr uint32_t RED_NAME = 0xAA0B0BAA;
|
||||
constexpr uint32_t BLANK_NAME = 0xAA0C0CAA;
|
||||
constexpr uint32_t SUPPRESS_LOGIN = 0xAA0D0DAA;
|
||||
constexpr uint32_t SKIP_CARD = 0xAA0E0EAA;
|
||||
constexpr uint32_t EP3_INFINITE_MESETA = 0xAA0F0FAA;
|
||||
constexpr uint32_t EP3_INFINITE_TIME = 0xAA1010AA;
|
||||
constexpr uint32_t EP3_UNMASK_WHISPERS = 0xAA1111AA;
|
||||
} // namespace ProxyOptionsMenuItemID
|
||||
|
||||
namespace TeamRewardMenuItemID {
|
||||
constexpr uint32_t TEAM_FLAG = 0x01010101;
|
||||
constexpr uint32_t DRESSING_ROOM = 0x02020202;
|
||||
constexpr uint32_t MEMBERS_20_LEADERS_3 = 0x03030303;
|
||||
constexpr uint32_t MEMBERS_40_LEADERS_5 = 0x04040404;
|
||||
constexpr uint32_t MEMBERS_70_LEADERS_8 = 0x05050505;
|
||||
constexpr uint32_t MEMBERS_100_LEADERS_10 = 0x06060606;
|
||||
// constexpr uint32_t POINT_OF_DISASTER = ...;
|
||||
// constexpr uint32_t TOYS_TWILIGHT = ...;
|
||||
// constexpr uint32_t COMMANDER_BLADE = ...;
|
||||
// constexpr uint32_t UNION_GUARD = ...;
|
||||
// constexpr uint32_t TEAM_POINTS_500 = ...;
|
||||
// constexpr uint32_t TEAM_POINTS_1000 = ...;
|
||||
// constexpr uint32_t TEAM_POINTS_5000 = ...;
|
||||
// constexpr uint32_t TEAM_POINTS_10000 = ...;
|
||||
} // namespace TeamRewardMenuItemID
|
||||
|
||||
struct MenuItem {
|
||||
enum Flag {
|
||||
// For menu items to be visible on DC NTE, they must not have either of the
|
||||
// following two flags. (The INVISIBLE_ON_GC_NTE flag behaves similarly.)
|
||||
INVISIBLE_ON_DC_PROTOS = 0x001,
|
||||
INVISIBLE_ON_DC = 0x002,
|
||||
INVISIBLE_ON_PC_NTE = 0x004,
|
||||
INVISIBLE_ON_PC = 0x008,
|
||||
INVISIBLE_ON_GC_NTE = 0x010,
|
||||
INVISIBLE_ON_GC = 0x020,
|
||||
INVISIBLE_ON_XB = 0x040,
|
||||
INVISIBLE_ON_BB = 0x080,
|
||||
DC_ONLY = INVISIBLE_ON_PC | INVISIBLE_ON_GC | INVISIBLE_ON_XB | INVISIBLE_ON_BB,
|
||||
PC_ONLY = INVISIBLE_ON_DC | INVISIBLE_ON_GC | INVISIBLE_ON_XB | INVISIBLE_ON_BB,
|
||||
GC_ONLY = INVISIBLE_ON_DC | INVISIBLE_ON_PC | INVISIBLE_ON_XB | INVISIBLE_ON_BB,
|
||||
XB_ONLY = INVISIBLE_ON_DC | INVISIBLE_ON_PC | INVISIBLE_ON_GC | INVISIBLE_ON_BB,
|
||||
BB_ONLY = INVISIBLE_ON_DC | INVISIBLE_ON_PC | INVISIBLE_ON_GC | INVISIBLE_ON_XB,
|
||||
REQUIRES_MESSAGE_BOXES = 0x100,
|
||||
REQUIRES_SEND_FUNCTION_CALL = 0x200,
|
||||
REQUIRES_SAVE_DISABLED = 0x400,
|
||||
INVISIBLE_IN_INFO_MENU = 0x800,
|
||||
};
|
||||
|
||||
uint32_t item_id;
|
||||
std::string name;
|
||||
std::string description;
|
||||
std::function<std::string()> get_description;
|
||||
uint32_t flags;
|
||||
|
||||
MenuItem(uint32_t item_id, const std::string& name, const std::string& description, uint32_t flags);
|
||||
MenuItem(uint32_t item_id, const std::string& name, std::function<std::string()> get_description, uint32_t flags);
|
||||
};
|
||||
|
||||
struct Menu {
|
||||
uint32_t menu_id;
|
||||
std::string name;
|
||||
std::vector<MenuItem> items;
|
||||
|
||||
Menu() = delete;
|
||||
Menu(uint32_t menu_id, const std::string& name);
|
||||
};
|
||||
|
||||
+104
-104
@@ -1,104 +1,104 @@
|
||||
#include "NetworkAddresses.hh"
|
||||
|
||||
#include <arpa/inet.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>
|
||||
#include <phosg/Network.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace std;
|
||||
|
||||
uint32_t resolve_address(const char* address) {
|
||||
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()));
|
||||
}
|
||||
|
||||
std::unique_ptr<struct addrinfo, void (*)(struct addrinfo*)> res0_unique(res0, freeaddrinfo);
|
||||
struct addrinfo* res4 = nullptr;
|
||||
for (struct addrinfo* res = res0; res; res = res->ai_next) {
|
||||
if (res->ai_family == AF_INET) {
|
||||
res4 = res;
|
||||
}
|
||||
}
|
||||
if (!res4) {
|
||||
throw runtime_error(string_printf(
|
||||
"can\'t resolve hostname %s: no usable data", address));
|
||||
}
|
||||
|
||||
struct sockaddr_in* res_sin = (struct sockaddr_in*)res4->ai_addr;
|
||||
return ntohl(res_sin->sin_addr.s_addr);
|
||||
}
|
||||
|
||||
map<string, uint32_t> get_local_addresses() {
|
||||
struct ifaddrs* ifa_raw;
|
||||
if (getifaddrs(&ifa_raw)) {
|
||||
auto s = string_for_error(errno);
|
||||
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);
|
||||
|
||||
map<string, uint32_t> ret;
|
||||
for (struct ifaddrs* i = ifa.get(); i; i = i->ifa_next) {
|
||||
if (!i->ifa_addr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto* sin = reinterpret_cast<sockaddr_in*>(i->ifa_addr);
|
||||
if (sin->sin_family != AF_INET) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ret.emplace(i->ifa_name, ntohl(sin->sin_addr.s_addr));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool is_local_address(uint32_t addr) {
|
||||
uint8_t net = (addr >> 24) & 0xFF;
|
||||
return ((net == 127) || (net == 172) || (net == 10) || (net == 192));
|
||||
}
|
||||
|
||||
bool is_local_address(const sockaddr_storage& daddr) {
|
||||
if (daddr.ss_family != AF_INET) {
|
||||
return false;
|
||||
}
|
||||
const sockaddr_in* sin = reinterpret_cast<const sockaddr_in*>(&daddr);
|
||||
return is_local_address(ntohl(sin->sin_addr.s_addr));
|
||||
}
|
||||
|
||||
string string_for_address(uint32_t address) {
|
||||
return string_printf("%hhu.%hhu.%hhu.%hhu",
|
||||
static_cast<uint8_t>(address >> 24), static_cast<uint8_t>(address >> 16),
|
||||
static_cast<uint8_t>(address >> 8), static_cast<uint8_t>(address));
|
||||
}
|
||||
|
||||
uint32_t address_for_string(const char* address) {
|
||||
return ntohl(inet_addr(address));
|
||||
}
|
||||
|
||||
uint64_t devolution_phone_number_for_netloc(uint32_t addr, uint16_t port) {
|
||||
// It seems the address part of the number is fixed-width, but the port is
|
||||
// not. Why did they do it this way?
|
||||
if (port & 0xF000) {
|
||||
return (static_cast<uint64_t>(addr) << 16) | port;
|
||||
} else if (port & 0x0F00) {
|
||||
return (static_cast<uint64_t>(addr) << 12) | port;
|
||||
} else if (port & 0x00F0) {
|
||||
return (static_cast<uint64_t>(addr) << 8) | port;
|
||||
} else {
|
||||
return (static_cast<uint64_t>(addr) << 4) | port;
|
||||
}
|
||||
}
|
||||
#include "NetworkAddresses.hh"
|
||||
|
||||
#include <arpa/inet.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>
|
||||
#include <phosg/Network.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace std;
|
||||
|
||||
uint32_t resolve_address(const char* address) {
|
||||
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()));
|
||||
}
|
||||
|
||||
std::unique_ptr<struct addrinfo, void (*)(struct addrinfo*)> res0_unique(res0, freeaddrinfo);
|
||||
struct addrinfo* res4 = nullptr;
|
||||
for (struct addrinfo* res = res0; res; res = res->ai_next) {
|
||||
if (res->ai_family == AF_INET) {
|
||||
res4 = res;
|
||||
}
|
||||
}
|
||||
if (!res4) {
|
||||
throw runtime_error(string_printf(
|
||||
"can\'t resolve hostname %s: no usable data", address));
|
||||
}
|
||||
|
||||
struct sockaddr_in* res_sin = (struct sockaddr_in*)res4->ai_addr;
|
||||
return ntohl(res_sin->sin_addr.s_addr);
|
||||
}
|
||||
|
||||
map<string, uint32_t> get_local_addresses() {
|
||||
struct ifaddrs* ifa_raw;
|
||||
if (getifaddrs(&ifa_raw)) {
|
||||
auto s = string_for_error(errno);
|
||||
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);
|
||||
|
||||
map<string, uint32_t> ret;
|
||||
for (struct ifaddrs* i = ifa.get(); i; i = i->ifa_next) {
|
||||
if (!i->ifa_addr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto* sin = reinterpret_cast<sockaddr_in*>(i->ifa_addr);
|
||||
if (sin->sin_family != AF_INET) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ret.emplace(i->ifa_name, ntohl(sin->sin_addr.s_addr));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool is_local_address(uint32_t addr) {
|
||||
uint8_t net = (addr >> 24) & 0xFF;
|
||||
return ((net == 127) || (net == 172) || (net == 10) || (net == 192));
|
||||
}
|
||||
|
||||
bool is_local_address(const sockaddr_storage& daddr) {
|
||||
if (daddr.ss_family != AF_INET) {
|
||||
return false;
|
||||
}
|
||||
const sockaddr_in* sin = reinterpret_cast<const sockaddr_in*>(&daddr);
|
||||
return is_local_address(ntohl(sin->sin_addr.s_addr));
|
||||
}
|
||||
|
||||
string string_for_address(uint32_t address) {
|
||||
return string_printf("%hhu.%hhu.%hhu.%hhu",
|
||||
static_cast<uint8_t>(address >> 24), static_cast<uint8_t>(address >> 16),
|
||||
static_cast<uint8_t>(address >> 8), static_cast<uint8_t>(address));
|
||||
}
|
||||
|
||||
uint32_t address_for_string(const char* address) {
|
||||
return ntohl(inet_addr(address));
|
||||
}
|
||||
|
||||
uint64_t devolution_phone_number_for_netloc(uint32_t addr, uint16_t port) {
|
||||
// It seems the address part of the number is fixed-width, but the port is
|
||||
// not. Why did they do it this way?
|
||||
if (port & 0xF000) {
|
||||
return (static_cast<uint64_t>(addr) << 16) | port;
|
||||
} else if (port & 0x0F00) {
|
||||
return (static_cast<uint64_t>(addr) << 12) | port;
|
||||
} else if (port & 0x00F0) {
|
||||
return (static_cast<uint64_t>(addr) << 8) | port;
|
||||
} else {
|
||||
return (static_cast<uint64_t>(addr) << 4) | port;
|
||||
}
|
||||
}
|
||||
|
||||
+21
-21
@@ -1,21 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
// PSO is IPv4-only, so we just treat addresses as uint32_t everywhere because
|
||||
// it's easier
|
||||
|
||||
uint32_t resolve_address(const char* address);
|
||||
std::map<std::string, uint32_t> get_local_addresses();
|
||||
uint32_t get_connected_address(int fd);
|
||||
bool is_local_address(uint32_t daddr);
|
||||
bool is_local_address(const sockaddr_storage& daddr);
|
||||
|
||||
std::string string_for_address(uint32_t address);
|
||||
uint32_t address_for_string(const char* address);
|
||||
|
||||
uint64_t devolution_phone_number_for_netloc(uint32_t addr, uint16_t port);
|
||||
#pragma once
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
// PSO is IPv4-only, so we just treat addresses as uint32_t everywhere because
|
||||
// it's easier
|
||||
|
||||
uint32_t resolve_address(const char* address);
|
||||
std::map<std::string, uint32_t> get_local_addresses();
|
||||
uint32_t get_connected_address(int fd);
|
||||
bool is_local_address(uint32_t daddr);
|
||||
bool is_local_address(const sockaddr_storage& daddr);
|
||||
|
||||
std::string string_for_address(uint32_t address);
|
||||
uint32_t address_for_string(const char* address);
|
||||
|
||||
uint64_t devolution_phone_number_for_netloc(uint32_t addr, uint16_t port);
|
||||
|
||||
+914
-914
File diff suppressed because it is too large
Load Diff
+359
-359
@@ -1,359 +1,359 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <memory>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Random.hh>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Compression.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
class PSOEncryption {
|
||||
public:
|
||||
enum class Type {
|
||||
V2 = 0,
|
||||
V3,
|
||||
BB,
|
||||
JSD0,
|
||||
};
|
||||
|
||||
virtual ~PSOEncryption() = default;
|
||||
|
||||
virtual void encrypt(void* data, size_t size, bool advance = true) = 0;
|
||||
virtual void decrypt(void* data, size_t size, bool advance = true);
|
||||
|
||||
inline void encrypt(std::string& data, bool advance = true) {
|
||||
this->encrypt(data.data(), data.size(), advance);
|
||||
}
|
||||
inline void decrypt(std::string& data, bool advance = true) {
|
||||
this->decrypt(data.data(), data.size(), advance);
|
||||
}
|
||||
|
||||
virtual Type type() const = 0;
|
||||
|
||||
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);
|
||||
|
||||
inline uint32_t seed() const {
|
||||
return this->initial_seed;
|
||||
}
|
||||
uint32_t absolute_offset() const {
|
||||
return (this->cycles * this->end_offset) + this->offset;
|
||||
}
|
||||
|
||||
protected:
|
||||
PSOLFGEncryption(uint32_t seed, size_t stream_length, size_t end_offset);
|
||||
|
||||
virtual void update_stream() = 0;
|
||||
|
||||
std::vector<uint32_t> stream;
|
||||
size_t offset;
|
||||
size_t end_offset;
|
||||
uint32_t initial_seed;
|
||||
size_t cycles;
|
||||
};
|
||||
|
||||
class PSOV2Encryption : public PSOLFGEncryption {
|
||||
public:
|
||||
explicit PSOV2Encryption(uint32_t seed);
|
||||
virtual Type type() const;
|
||||
|
||||
protected:
|
||||
virtual void update_stream();
|
||||
|
||||
static constexpr size_t STREAM_LENGTH = 0x38;
|
||||
};
|
||||
|
||||
class PSOV3Encryption : public PSOLFGEncryption {
|
||||
public:
|
||||
explicit PSOV3Encryption(uint32_t key);
|
||||
virtual Type type() const;
|
||||
|
||||
protected:
|
||||
virtual void update_stream();
|
||||
|
||||
static constexpr size_t STREAM_LENGTH = 521;
|
||||
};
|
||||
|
||||
class PSOBBEncryption : public PSOEncryption {
|
||||
public:
|
||||
enum Subtype : uint8_t {
|
||||
STANDARD = 0x00,
|
||||
MOCB1 = 0x01,
|
||||
JSD1 = 0x02,
|
||||
TFS1 = 0x03,
|
||||
};
|
||||
|
||||
struct KeyFile {
|
||||
// initial_keys are actually a stream of uint32_ts, but we treat them as
|
||||
// bytes for code simplicity
|
||||
union InitialKeys {
|
||||
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) {}
|
||||
} __packed_ws__(InitialKeys, 0x48);
|
||||
union PrivateKeys {
|
||||
parray<uint8_t, 0x1000> as8;
|
||||
parray<le_uint32_t, 0x400> as32;
|
||||
PrivateKeys() : as32() {}
|
||||
PrivateKeys(const PrivateKeys& other) : as32(other.as32) {}
|
||||
} __packed_ws__(PrivateKeys, 0x1000);
|
||||
InitialKeys initial_keys;
|
||||
PrivateKeys private_keys;
|
||||
// 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;
|
||||
} __packed_ws__(KeyFile, 0x1050);
|
||||
|
||||
PSOBBEncryption(const KeyFile& key, const void* seed, size_t seed_size);
|
||||
|
||||
virtual void encrypt(void* data, size_t size, bool advance = true);
|
||||
virtual void decrypt(void* data, size_t size, bool advance = true);
|
||||
|
||||
virtual Type type() const;
|
||||
|
||||
protected:
|
||||
KeyFile state;
|
||||
|
||||
void tfs1_scramble(uint32_t* out1, uint32_t* out2) const;
|
||||
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
|
||||
|
||||
class PSOV2OrV3DetectorEncryption : public PSOEncryption {
|
||||
public:
|
||||
PSOV2OrV3DetectorEncryption(
|
||||
uint32_t key,
|
||||
const std::unordered_set<uint32_t>& v2_matches,
|
||||
const std::unordered_set<uint32_t>& v3_matches);
|
||||
|
||||
virtual void encrypt(void* data, size_t size, bool advance = true);
|
||||
|
||||
virtual Type type() const;
|
||||
|
||||
protected:
|
||||
uint32_t key;
|
||||
const std::unordered_set<uint32_t>& v2_matches;
|
||||
const std::unordered_set<uint32_t>& v3_matches;
|
||||
std::unique_ptr<PSOEncryption> active_crypt;
|
||||
};
|
||||
|
||||
class PSOV2OrV3ImitatorEncryption : public PSOEncryption {
|
||||
public:
|
||||
PSOV2OrV3ImitatorEncryption(
|
||||
uint32_t key, std::shared_ptr<PSOV2OrV3DetectorEncryption> client_crypt);
|
||||
|
||||
virtual void encrypt(void* data, size_t size, bool advance = true);
|
||||
|
||||
virtual Type type() const;
|
||||
|
||||
protected:
|
||||
uint32_t key;
|
||||
std::shared_ptr<const PSOV2OrV3DetectorEncryption> detector_crypt;
|
||||
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
|
||||
|
||||
class PSOBBMultiKeyDetectorEncryption : public PSOEncryption {
|
||||
public:
|
||||
PSOBBMultiKeyDetectorEncryption(
|
||||
const std::vector<std::shared_ptr<const PSOBBEncryption::KeyFile>>& possible_keys,
|
||||
const std::unordered_set<std::string>& expected_first_data,
|
||||
const void* seed,
|
||||
size_t seed_size);
|
||||
|
||||
virtual void encrypt(void* data, size_t size, bool advance = true);
|
||||
virtual void decrypt(void* data, size_t size, bool advance = true);
|
||||
|
||||
inline std::shared_ptr<const PSOBBEncryption::KeyFile> get_active_key() const {
|
||||
return this->active_key;
|
||||
}
|
||||
inline const std::string& get_seed() const {
|
||||
return this->seed;
|
||||
}
|
||||
|
||||
virtual Type type() const;
|
||||
|
||||
protected:
|
||||
std::vector<std::shared_ptr<const PSOBBEncryption::KeyFile>> possible_keys;
|
||||
std::shared_ptr<const PSOBBEncryption::KeyFile> active_key;
|
||||
std::shared_ptr<PSOBBEncryption> active_crypt;
|
||||
const std::unordered_set<std::string>& expected_first_data;
|
||||
std::string seed;
|
||||
};
|
||||
|
||||
class PSOBBMultiKeyImitatorEncryption : public PSOEncryption {
|
||||
public:
|
||||
PSOBBMultiKeyImitatorEncryption(
|
||||
std::shared_ptr<const PSOBBMultiKeyDetectorEncryption> client_crypt,
|
||||
const void* seed,
|
||||
size_t seed_size,
|
||||
bool jsd1_use_detector_seed);
|
||||
|
||||
virtual void encrypt(void* data, size_t size, bool advance = true);
|
||||
virtual void decrypt(void* data, size_t size, bool advance = true);
|
||||
|
||||
virtual Type type() const;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<PSOBBEncryption> ensure_crypt();
|
||||
|
||||
std::shared_ptr<const PSOBBMultiKeyDetectorEncryption> detector_crypt;
|
||||
std::shared_ptr<PSOBBEncryption> active_crypt;
|
||||
std::string seed;
|
||||
bool jsd1_use_detector_seed;
|
||||
};
|
||||
|
||||
class JSD0Encryption : public PSOEncryption {
|
||||
public:
|
||||
JSD0Encryption(const void* seed, size_t seed_size);
|
||||
|
||||
virtual void encrypt(void* data, size_t size, bool advance = true);
|
||||
virtual void decrypt(void* data, size_t size, bool advance = true);
|
||||
|
||||
virtual Type type() const = 0;
|
||||
|
||||
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);
|
||||
|
||||
template <bool IsBigEndian>
|
||||
class ChallengeTimeT {
|
||||
private:
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
U32T value;
|
||||
|
||||
public:
|
||||
ChallengeTimeT() = default;
|
||||
ChallengeTimeT(uint16_t v) {
|
||||
this->encode(v);
|
||||
}
|
||||
ChallengeTimeT(const ChallengeTimeT& other) = default;
|
||||
ChallengeTimeT(ChallengeTimeT&& other) = default;
|
||||
ChallengeTimeT& operator=(const ChallengeTimeT& other) = default;
|
||||
ChallengeTimeT& operator=(ChallengeTimeT&& other) = default;
|
||||
|
||||
bool has_value() const {
|
||||
return this->value != 0;
|
||||
}
|
||||
|
||||
uint32_t load_raw() const {
|
||||
return this->value;
|
||||
}
|
||||
void store_raw(uint32_t value) {
|
||||
this->value = value;
|
||||
}
|
||||
|
||||
uint16_t decode() const {
|
||||
return decrypt_challenge_time(this->value);
|
||||
}
|
||||
void encode(uint16_t v) {
|
||||
this->value = ((v == 0) || (v == 0xFFFF)) ? 0 : encrypt_challenge_time(v);
|
||||
}
|
||||
|
||||
operator ChallengeTimeT<!IsBigEndian>() const {
|
||||
ChallengeTimeT<!IsBigEndian> ret;
|
||||
ret.store_raw(this->value);
|
||||
return ret;
|
||||
}
|
||||
} __packed__;
|
||||
using ChallengeTime = ChallengeTimeT<false>;
|
||||
using ChallengeTimeBE = ChallengeTimeT<true>;
|
||||
check_struct_size(ChallengeTime, 4);
|
||||
check_struct_size(ChallengeTimeBE, 4);
|
||||
|
||||
std::string decrypt_v2_registry_value(const void* data, size_t size);
|
||||
|
||||
struct DecryptedPR2 {
|
||||
std::string compressed_data;
|
||||
size_t decompressed_size;
|
||||
};
|
||||
|
||||
template <bool IsBigEndian>
|
||||
DecryptedPR2 decrypt_pr2_data(const std::string& data) {
|
||||
using U32T = std::conditional_t<IsBigEndian, be_uint32_t, le_uint32_t>;
|
||||
|
||||
if (data.size() < 8) {
|
||||
throw std::runtime_error("not enough data for PR2 header");
|
||||
}
|
||||
StringReader r(data);
|
||||
DecryptedPR2 ret = {
|
||||
.compressed_data = data.substr(8),
|
||||
.decompressed_size = r.get<U32T>()};
|
||||
PSOV2Encryption crypt(r.get<U32T>());
|
||||
if (IsBigEndian) {
|
||||
crypt.encrypt_big_endian(ret.compressed_data.data(), ret.compressed_data.size());
|
||||
} else {
|
||||
crypt.decrypt(ret.compressed_data.data(), ret.compressed_data.size());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <bool IsBigEndian>
|
||||
std::string decrypt_and_decompress_pr2_data(const std::string& data) {
|
||||
auto decrypted = decrypt_pr2_data<IsBigEndian>(data);
|
||||
std::string decompressed = prs_decompress(decrypted.compressed_data);
|
||||
if (decompressed.size() != decrypted.decompressed_size) {
|
||||
throw std::runtime_error("decompressed size does not match expected size");
|
||||
}
|
||||
return decompressed;
|
||||
}
|
||||
|
||||
template <bool IsBigEndian>
|
||||
std::string encrypt_pr2_data(const std::string& data, size_t decompressed_size, uint32_t seed) {
|
||||
using U32T = std::conditional_t<IsBigEndian, be_uint32_t, le_uint32_t>;
|
||||
|
||||
StringWriter w;
|
||||
w.put<U32T>(decompressed_size);
|
||||
w.put<U32T>(seed);
|
||||
w.write(data);
|
||||
|
||||
std::string ret = std::move(w.str());
|
||||
PSOV2Encryption crypt(seed);
|
||||
if (IsBigEndian) {
|
||||
crypt.encrypt_big_endian(ret.data() + 8, ret.size() - 8);
|
||||
} else {
|
||||
crypt.decrypt(ret.data() + 8, ret.size() - 8);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline uint32_t random_from_optional_crypt(std::shared_ptr<PSOLFGEncryption> random_crypt) {
|
||||
return random_crypt ? random_crypt->next() : random_object<uint32_t>();
|
||||
}
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <memory>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Random.hh>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Compression.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
class PSOEncryption {
|
||||
public:
|
||||
enum class Type {
|
||||
V2 = 0,
|
||||
V3,
|
||||
BB,
|
||||
JSD0,
|
||||
};
|
||||
|
||||
virtual ~PSOEncryption() = default;
|
||||
|
||||
virtual void encrypt(void* data, size_t size, bool advance = true) = 0;
|
||||
virtual void decrypt(void* data, size_t size, bool advance = true);
|
||||
|
||||
inline void encrypt(std::string& data, bool advance = true) {
|
||||
this->encrypt(data.data(), data.size(), advance);
|
||||
}
|
||||
inline void decrypt(std::string& data, bool advance = true) {
|
||||
this->decrypt(data.data(), data.size(), advance);
|
||||
}
|
||||
|
||||
virtual Type type() const = 0;
|
||||
|
||||
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);
|
||||
|
||||
inline uint32_t seed() const {
|
||||
return this->initial_seed;
|
||||
}
|
||||
uint32_t absolute_offset() const {
|
||||
return (this->cycles * this->end_offset) + this->offset;
|
||||
}
|
||||
|
||||
protected:
|
||||
PSOLFGEncryption(uint32_t seed, size_t stream_length, size_t end_offset);
|
||||
|
||||
virtual void update_stream() = 0;
|
||||
|
||||
std::vector<uint32_t> stream;
|
||||
size_t offset;
|
||||
size_t end_offset;
|
||||
uint32_t initial_seed;
|
||||
size_t cycles;
|
||||
};
|
||||
|
||||
class PSOV2Encryption : public PSOLFGEncryption {
|
||||
public:
|
||||
explicit PSOV2Encryption(uint32_t seed);
|
||||
virtual Type type() const;
|
||||
|
||||
protected:
|
||||
virtual void update_stream();
|
||||
|
||||
static constexpr size_t STREAM_LENGTH = 0x38;
|
||||
};
|
||||
|
||||
class PSOV3Encryption : public PSOLFGEncryption {
|
||||
public:
|
||||
explicit PSOV3Encryption(uint32_t key);
|
||||
virtual Type type() const;
|
||||
|
||||
protected:
|
||||
virtual void update_stream();
|
||||
|
||||
static constexpr size_t STREAM_LENGTH = 521;
|
||||
};
|
||||
|
||||
class PSOBBEncryption : public PSOEncryption {
|
||||
public:
|
||||
enum Subtype : uint8_t {
|
||||
STANDARD = 0x00,
|
||||
MOCB1 = 0x01,
|
||||
JSD1 = 0x02,
|
||||
TFS1 = 0x03,
|
||||
};
|
||||
|
||||
struct KeyFile {
|
||||
// initial_keys are actually a stream of uint32_ts, but we treat them as
|
||||
// bytes for code simplicity
|
||||
union InitialKeys {
|
||||
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) {}
|
||||
} __packed_ws__(InitialKeys, 0x48);
|
||||
union PrivateKeys {
|
||||
parray<uint8_t, 0x1000> as8;
|
||||
parray<le_uint32_t, 0x400> as32;
|
||||
PrivateKeys() : as32() {}
|
||||
PrivateKeys(const PrivateKeys& other) : as32(other.as32) {}
|
||||
} __packed_ws__(PrivateKeys, 0x1000);
|
||||
InitialKeys initial_keys;
|
||||
PrivateKeys private_keys;
|
||||
// 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;
|
||||
} __packed_ws__(KeyFile, 0x1050);
|
||||
|
||||
PSOBBEncryption(const KeyFile& key, const void* seed, size_t seed_size);
|
||||
|
||||
virtual void encrypt(void* data, size_t size, bool advance = true);
|
||||
virtual void decrypt(void* data, size_t size, bool advance = true);
|
||||
|
||||
virtual Type type() const;
|
||||
|
||||
protected:
|
||||
KeyFile state;
|
||||
|
||||
void tfs1_scramble(uint32_t* out1, uint32_t* out2) const;
|
||||
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
|
||||
|
||||
class PSOV2OrV3DetectorEncryption : public PSOEncryption {
|
||||
public:
|
||||
PSOV2OrV3DetectorEncryption(
|
||||
uint32_t key,
|
||||
const std::unordered_set<uint32_t>& v2_matches,
|
||||
const std::unordered_set<uint32_t>& v3_matches);
|
||||
|
||||
virtual void encrypt(void* data, size_t size, bool advance = true);
|
||||
|
||||
virtual Type type() const;
|
||||
|
||||
protected:
|
||||
uint32_t key;
|
||||
const std::unordered_set<uint32_t>& v2_matches;
|
||||
const std::unordered_set<uint32_t>& v3_matches;
|
||||
std::unique_ptr<PSOEncryption> active_crypt;
|
||||
};
|
||||
|
||||
class PSOV2OrV3ImitatorEncryption : public PSOEncryption {
|
||||
public:
|
||||
PSOV2OrV3ImitatorEncryption(
|
||||
uint32_t key, std::shared_ptr<PSOV2OrV3DetectorEncryption> client_crypt);
|
||||
|
||||
virtual void encrypt(void* data, size_t size, bool advance = true);
|
||||
|
||||
virtual Type type() const;
|
||||
|
||||
protected:
|
||||
uint32_t key;
|
||||
std::shared_ptr<const PSOV2OrV3DetectorEncryption> detector_crypt;
|
||||
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
|
||||
|
||||
class PSOBBMultiKeyDetectorEncryption : public PSOEncryption {
|
||||
public:
|
||||
PSOBBMultiKeyDetectorEncryption(
|
||||
const std::vector<std::shared_ptr<const PSOBBEncryption::KeyFile>>& possible_keys,
|
||||
const std::unordered_set<std::string>& expected_first_data,
|
||||
const void* seed,
|
||||
size_t seed_size);
|
||||
|
||||
virtual void encrypt(void* data, size_t size, bool advance = true);
|
||||
virtual void decrypt(void* data, size_t size, bool advance = true);
|
||||
|
||||
inline std::shared_ptr<const PSOBBEncryption::KeyFile> get_active_key() const {
|
||||
return this->active_key;
|
||||
}
|
||||
inline const std::string& get_seed() const {
|
||||
return this->seed;
|
||||
}
|
||||
|
||||
virtual Type type() const;
|
||||
|
||||
protected:
|
||||
std::vector<std::shared_ptr<const PSOBBEncryption::KeyFile>> possible_keys;
|
||||
std::shared_ptr<const PSOBBEncryption::KeyFile> active_key;
|
||||
std::shared_ptr<PSOBBEncryption> active_crypt;
|
||||
const std::unordered_set<std::string>& expected_first_data;
|
||||
std::string seed;
|
||||
};
|
||||
|
||||
class PSOBBMultiKeyImitatorEncryption : public PSOEncryption {
|
||||
public:
|
||||
PSOBBMultiKeyImitatorEncryption(
|
||||
std::shared_ptr<const PSOBBMultiKeyDetectorEncryption> client_crypt,
|
||||
const void* seed,
|
||||
size_t seed_size,
|
||||
bool jsd1_use_detector_seed);
|
||||
|
||||
virtual void encrypt(void* data, size_t size, bool advance = true);
|
||||
virtual void decrypt(void* data, size_t size, bool advance = true);
|
||||
|
||||
virtual Type type() const;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<PSOBBEncryption> ensure_crypt();
|
||||
|
||||
std::shared_ptr<const PSOBBMultiKeyDetectorEncryption> detector_crypt;
|
||||
std::shared_ptr<PSOBBEncryption> active_crypt;
|
||||
std::string seed;
|
||||
bool jsd1_use_detector_seed;
|
||||
};
|
||||
|
||||
class JSD0Encryption : public PSOEncryption {
|
||||
public:
|
||||
JSD0Encryption(const void* seed, size_t seed_size);
|
||||
|
||||
virtual void encrypt(void* data, size_t size, bool advance = true);
|
||||
virtual void decrypt(void* data, size_t size, bool advance = true);
|
||||
|
||||
virtual Type type() const = 0;
|
||||
|
||||
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);
|
||||
|
||||
template <bool IsBigEndian>
|
||||
class ChallengeTimeT {
|
||||
private:
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
U32T value;
|
||||
|
||||
public:
|
||||
ChallengeTimeT() = default;
|
||||
ChallengeTimeT(uint16_t v) {
|
||||
this->encode(v);
|
||||
}
|
||||
ChallengeTimeT(const ChallengeTimeT& other) = default;
|
||||
ChallengeTimeT(ChallengeTimeT&& other) = default;
|
||||
ChallengeTimeT& operator=(const ChallengeTimeT& other) = default;
|
||||
ChallengeTimeT& operator=(ChallengeTimeT&& other) = default;
|
||||
|
||||
bool has_value() const {
|
||||
return this->value != 0;
|
||||
}
|
||||
|
||||
uint32_t load_raw() const {
|
||||
return this->value;
|
||||
}
|
||||
void store_raw(uint32_t value) {
|
||||
this->value = value;
|
||||
}
|
||||
|
||||
uint16_t decode() const {
|
||||
return decrypt_challenge_time(this->value);
|
||||
}
|
||||
void encode(uint16_t v) {
|
||||
this->value = ((v == 0) || (v == 0xFFFF)) ? 0 : encrypt_challenge_time(v);
|
||||
}
|
||||
|
||||
operator ChallengeTimeT<!IsBigEndian>() const {
|
||||
ChallengeTimeT<!IsBigEndian> ret;
|
||||
ret.store_raw(this->value);
|
||||
return ret;
|
||||
}
|
||||
} __packed__;
|
||||
using ChallengeTime = ChallengeTimeT<false>;
|
||||
using ChallengeTimeBE = ChallengeTimeT<true>;
|
||||
check_struct_size(ChallengeTime, 4);
|
||||
check_struct_size(ChallengeTimeBE, 4);
|
||||
|
||||
std::string decrypt_v2_registry_value(const void* data, size_t size);
|
||||
|
||||
struct DecryptedPR2 {
|
||||
std::string compressed_data;
|
||||
size_t decompressed_size;
|
||||
};
|
||||
|
||||
template <bool IsBigEndian>
|
||||
DecryptedPR2 decrypt_pr2_data(const std::string& data) {
|
||||
using U32T = std::conditional_t<IsBigEndian, be_uint32_t, le_uint32_t>;
|
||||
|
||||
if (data.size() < 8) {
|
||||
throw std::runtime_error("not enough data for PR2 header");
|
||||
}
|
||||
StringReader r(data);
|
||||
DecryptedPR2 ret = {
|
||||
.compressed_data = data.substr(8),
|
||||
.decompressed_size = r.get<U32T>()};
|
||||
PSOV2Encryption crypt(r.get<U32T>());
|
||||
if (IsBigEndian) {
|
||||
crypt.encrypt_big_endian(ret.compressed_data.data(), ret.compressed_data.size());
|
||||
} else {
|
||||
crypt.decrypt(ret.compressed_data.data(), ret.compressed_data.size());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <bool IsBigEndian>
|
||||
std::string decrypt_and_decompress_pr2_data(const std::string& data) {
|
||||
auto decrypted = decrypt_pr2_data<IsBigEndian>(data);
|
||||
std::string decompressed = prs_decompress(decrypted.compressed_data);
|
||||
if (decompressed.size() != decrypted.decompressed_size) {
|
||||
throw std::runtime_error("decompressed size does not match expected size");
|
||||
}
|
||||
return decompressed;
|
||||
}
|
||||
|
||||
template <bool IsBigEndian>
|
||||
std::string encrypt_pr2_data(const std::string& data, size_t decompressed_size, uint32_t seed) {
|
||||
using U32T = std::conditional_t<IsBigEndian, be_uint32_t, le_uint32_t>;
|
||||
|
||||
StringWriter w;
|
||||
w.put<U32T>(decompressed_size);
|
||||
w.put<U32T>(seed);
|
||||
w.write(data);
|
||||
|
||||
std::string ret = std::move(w.str());
|
||||
PSOV2Encryption crypt(seed);
|
||||
if (IsBigEndian) {
|
||||
crypt.encrypt_big_endian(ret.data() + 8, ret.size() - 8);
|
||||
} else {
|
||||
crypt.decrypt(ret.data() + 8, ret.size() - 8);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline uint32_t random_from_optional_crypt(std::shared_ptr<PSOLFGEncryption> random_crypt) {
|
||||
return random_crypt ? random_crypt->next() : random_object<uint32_t>();
|
||||
}
|
||||
|
||||
+270
-270
@@ -1,270 +1,270 @@
|
||||
#include "PSOProtocol.hh"
|
||||
|
||||
#include <event2/buffer.h>
|
||||
|
||||
#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;
|
||||
this->bb.flag = 0;
|
||||
}
|
||||
|
||||
uint16_t PSOCommandHeader::command(Version version) const {
|
||||
switch (version) {
|
||||
case Version::PC_PATCH:
|
||||
case Version::BB_PATCH:
|
||||
case Version::PC_NTE:
|
||||
case Version::PC_V2:
|
||||
return this->pc.command;
|
||||
case Version::DC_NTE:
|
||||
case Version::DC_V1_11_2000_PROTOTYPE:
|
||||
case Version::DC_V1:
|
||||
case Version::DC_V2:
|
||||
return this->dc.command;
|
||||
case Version::GC_NTE:
|
||||
case Version::GC_V3:
|
||||
case Version::GC_EP3_NTE:
|
||||
case Version::GC_EP3:
|
||||
return this->gc.command;
|
||||
case Version::XB_V3:
|
||||
return this->xb.command;
|
||||
case Version::BB_V4:
|
||||
return this->bb.command;
|
||||
default:
|
||||
throw logic_error("unknown game version");
|
||||
}
|
||||
}
|
||||
|
||||
void PSOCommandHeader::set_command(Version version, uint16_t command) {
|
||||
switch (version) {
|
||||
case Version::PC_PATCH:
|
||||
case Version::BB_PATCH:
|
||||
case Version::PC_NTE:
|
||||
case Version::PC_V2:
|
||||
this->pc.command = command;
|
||||
break;
|
||||
case Version::DC_NTE:
|
||||
case Version::DC_V1_11_2000_PROTOTYPE:
|
||||
case Version::DC_V1:
|
||||
case Version::DC_V2:
|
||||
this->dc.command = command;
|
||||
break;
|
||||
case Version::GC_NTE:
|
||||
case Version::GC_V3:
|
||||
case Version::GC_EP3_NTE:
|
||||
case Version::GC_EP3:
|
||||
this->gc.command = command;
|
||||
break;
|
||||
case Version::XB_V3:
|
||||
this->xb.command = command;
|
||||
break;
|
||||
case Version::BB_V4:
|
||||
this->bb.command = command;
|
||||
break;
|
||||
default:
|
||||
throw logic_error("unknown game version");
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t PSOCommandHeader::size(Version version) const {
|
||||
switch (version) {
|
||||
case Version::PC_PATCH:
|
||||
case Version::BB_PATCH:
|
||||
case Version::PC_NTE:
|
||||
case Version::PC_V2:
|
||||
return this->pc.size;
|
||||
case Version::DC_NTE:
|
||||
case Version::DC_V1_11_2000_PROTOTYPE:
|
||||
case Version::DC_V1:
|
||||
case Version::DC_V2:
|
||||
return this->dc.size;
|
||||
case Version::GC_NTE:
|
||||
case Version::GC_V3:
|
||||
case Version::GC_EP3_NTE:
|
||||
case Version::GC_EP3:
|
||||
return this->gc.size;
|
||||
case Version::XB_V3:
|
||||
return this->xb.size;
|
||||
case Version::BB_V4:
|
||||
return this->bb.size;
|
||||
default:
|
||||
throw logic_error("unknown game version");
|
||||
}
|
||||
}
|
||||
|
||||
void PSOCommandHeader::set_size(Version version, uint32_t size) {
|
||||
switch (version) {
|
||||
case Version::PC_PATCH:
|
||||
case Version::BB_PATCH:
|
||||
case Version::PC_NTE:
|
||||
case Version::PC_V2:
|
||||
this->pc.size = size;
|
||||
break;
|
||||
case Version::DC_NTE:
|
||||
case Version::DC_V1_11_2000_PROTOTYPE:
|
||||
case Version::DC_V1:
|
||||
case Version::DC_V2:
|
||||
this->dc.size = size;
|
||||
break;
|
||||
case Version::GC_NTE:
|
||||
case Version::GC_V3:
|
||||
case Version::GC_EP3_NTE:
|
||||
case Version::GC_EP3:
|
||||
this->gc.size = size;
|
||||
break;
|
||||
case Version::XB_V3:
|
||||
this->xb.size = size;
|
||||
break;
|
||||
case Version::BB_V4:
|
||||
this->bb.size = size;
|
||||
break;
|
||||
default:
|
||||
throw logic_error("unknown game version");
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t PSOCommandHeader::flag(Version version) const {
|
||||
switch (version) {
|
||||
case Version::PC_PATCH:
|
||||
case Version::BB_PATCH:
|
||||
case Version::PC_NTE:
|
||||
case Version::PC_V2:
|
||||
return this->pc.flag;
|
||||
case Version::DC_NTE:
|
||||
case Version::DC_V1_11_2000_PROTOTYPE:
|
||||
case Version::DC_V1:
|
||||
case Version::DC_V2:
|
||||
return this->dc.flag;
|
||||
case Version::GC_NTE:
|
||||
case Version::GC_V3:
|
||||
case Version::GC_EP3_NTE:
|
||||
case Version::GC_EP3:
|
||||
return this->gc.flag;
|
||||
case Version::XB_V3:
|
||||
return this->xb.flag;
|
||||
case Version::BB_V4:
|
||||
return this->bb.flag;
|
||||
default:
|
||||
throw logic_error("unknown game version");
|
||||
}
|
||||
}
|
||||
|
||||
void PSOCommandHeader::set_flag(Version version, uint32_t flag) {
|
||||
switch (version) {
|
||||
case Version::PC_PATCH:
|
||||
case Version::BB_PATCH:
|
||||
case Version::PC_NTE:
|
||||
case Version::PC_V2:
|
||||
this->pc.flag = flag;
|
||||
break;
|
||||
case Version::DC_NTE:
|
||||
case Version::DC_V1_11_2000_PROTOTYPE:
|
||||
case Version::DC_V1:
|
||||
case Version::DC_V2:
|
||||
this->dc.flag = flag;
|
||||
break;
|
||||
case Version::GC_NTE:
|
||||
case Version::GC_V3:
|
||||
case Version::GC_EP3_NTE:
|
||||
case Version::GC_EP3:
|
||||
this->gc.flag = flag;
|
||||
break;
|
||||
case Version::XB_V3:
|
||||
this->xb.flag = flag;
|
||||
break;
|
||||
case Version::BB_V4:
|
||||
this->bb.flag = flag;
|
||||
break;
|
||||
default:
|
||||
throw logic_error("unknown game version");
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
"command too small (expected at least 0x%zX bytes, received 0x%zX bytes)",
|
||||
min_size, size));
|
||||
}
|
||||
if (max_size < min_size) {
|
||||
max_size = min_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));
|
||||
}
|
||||
}
|
||||
|
||||
std::string prepend_command_header(
|
||||
Version version,
|
||||
bool encryption_enabled,
|
||||
uint16_t cmd,
|
||||
uint32_t flag,
|
||||
const std::string& data) {
|
||||
StringWriter ret;
|
||||
switch (version) {
|
||||
case Version::DC_NTE:
|
||||
case Version::DC_V1_11_2000_PROTOTYPE:
|
||||
case Version::DC_V1:
|
||||
case Version::DC_V2:
|
||||
case Version::GC_NTE:
|
||||
case Version::GC_V3:
|
||||
case Version::GC_EP3_NTE:
|
||||
case Version::GC_EP3:
|
||||
case Version::XB_V3: {
|
||||
PSOCommandHeaderDCV3 header;
|
||||
if (encryption_enabled) {
|
||||
header.size = (sizeof(header) + data.size() + 3) & ~3;
|
||||
} else {
|
||||
header.size = (sizeof(header) + data.size());
|
||||
}
|
||||
header.command = cmd;
|
||||
header.flag = flag;
|
||||
ret.put(header);
|
||||
break;
|
||||
}
|
||||
|
||||
case Version::PC_PATCH:
|
||||
case Version::BB_PATCH:
|
||||
case Version::PC_NTE:
|
||||
case Version::PC_V2: {
|
||||
PSOCommandHeaderPC header;
|
||||
if (encryption_enabled) {
|
||||
header.size = (sizeof(header) + data.size() + 3) & ~3;
|
||||
} else {
|
||||
header.size = (sizeof(header) + data.size());
|
||||
}
|
||||
header.command = cmd;
|
||||
header.flag = flag;
|
||||
ret.put(header);
|
||||
break;
|
||||
}
|
||||
|
||||
case Version::BB_V4: {
|
||||
PSOCommandHeaderBB header;
|
||||
if (encryption_enabled) {
|
||||
header.size = (sizeof(header) + data.size() + 3) & ~3;
|
||||
} else {
|
||||
header.size = (sizeof(header) + data.size());
|
||||
}
|
||||
header.command = cmd;
|
||||
header.flag = flag;
|
||||
ret.put(header);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
throw logic_error("unimplemented game version in prepend_command_header");
|
||||
}
|
||||
ret.write(data);
|
||||
return std::move(ret.str());
|
||||
}
|
||||
#include "PSOProtocol.hh"
|
||||
|
||||
#include <event2/buffer.h>
|
||||
|
||||
#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;
|
||||
this->bb.flag = 0;
|
||||
}
|
||||
|
||||
uint16_t PSOCommandHeader::command(Version version) const {
|
||||
switch (version) {
|
||||
case Version::PC_PATCH:
|
||||
case Version::BB_PATCH:
|
||||
case Version::PC_NTE:
|
||||
case Version::PC_V2:
|
||||
return this->pc.command;
|
||||
case Version::DC_NTE:
|
||||
case Version::DC_V1_11_2000_PROTOTYPE:
|
||||
case Version::DC_V1:
|
||||
case Version::DC_V2:
|
||||
return this->dc.command;
|
||||
case Version::GC_NTE:
|
||||
case Version::GC_V3:
|
||||
case Version::GC_EP3_NTE:
|
||||
case Version::GC_EP3:
|
||||
return this->gc.command;
|
||||
case Version::XB_V3:
|
||||
return this->xb.command;
|
||||
case Version::BB_V4:
|
||||
return this->bb.command;
|
||||
default:
|
||||
throw logic_error("unknown game version");
|
||||
}
|
||||
}
|
||||
|
||||
void PSOCommandHeader::set_command(Version version, uint16_t command) {
|
||||
switch (version) {
|
||||
case Version::PC_PATCH:
|
||||
case Version::BB_PATCH:
|
||||
case Version::PC_NTE:
|
||||
case Version::PC_V2:
|
||||
this->pc.command = command;
|
||||
break;
|
||||
case Version::DC_NTE:
|
||||
case Version::DC_V1_11_2000_PROTOTYPE:
|
||||
case Version::DC_V1:
|
||||
case Version::DC_V2:
|
||||
this->dc.command = command;
|
||||
break;
|
||||
case Version::GC_NTE:
|
||||
case Version::GC_V3:
|
||||
case Version::GC_EP3_NTE:
|
||||
case Version::GC_EP3:
|
||||
this->gc.command = command;
|
||||
break;
|
||||
case Version::XB_V3:
|
||||
this->xb.command = command;
|
||||
break;
|
||||
case Version::BB_V4:
|
||||
this->bb.command = command;
|
||||
break;
|
||||
default:
|
||||
throw logic_error("unknown game version");
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t PSOCommandHeader::size(Version version) const {
|
||||
switch (version) {
|
||||
case Version::PC_PATCH:
|
||||
case Version::BB_PATCH:
|
||||
case Version::PC_NTE:
|
||||
case Version::PC_V2:
|
||||
return this->pc.size;
|
||||
case Version::DC_NTE:
|
||||
case Version::DC_V1_11_2000_PROTOTYPE:
|
||||
case Version::DC_V1:
|
||||
case Version::DC_V2:
|
||||
return this->dc.size;
|
||||
case Version::GC_NTE:
|
||||
case Version::GC_V3:
|
||||
case Version::GC_EP3_NTE:
|
||||
case Version::GC_EP3:
|
||||
return this->gc.size;
|
||||
case Version::XB_V3:
|
||||
return this->xb.size;
|
||||
case Version::BB_V4:
|
||||
return this->bb.size;
|
||||
default:
|
||||
throw logic_error("unknown game version");
|
||||
}
|
||||
}
|
||||
|
||||
void PSOCommandHeader::set_size(Version version, uint32_t size) {
|
||||
switch (version) {
|
||||
case Version::PC_PATCH:
|
||||
case Version::BB_PATCH:
|
||||
case Version::PC_NTE:
|
||||
case Version::PC_V2:
|
||||
this->pc.size = size;
|
||||
break;
|
||||
case Version::DC_NTE:
|
||||
case Version::DC_V1_11_2000_PROTOTYPE:
|
||||
case Version::DC_V1:
|
||||
case Version::DC_V2:
|
||||
this->dc.size = size;
|
||||
break;
|
||||
case Version::GC_NTE:
|
||||
case Version::GC_V3:
|
||||
case Version::GC_EP3_NTE:
|
||||
case Version::GC_EP3:
|
||||
this->gc.size = size;
|
||||
break;
|
||||
case Version::XB_V3:
|
||||
this->xb.size = size;
|
||||
break;
|
||||
case Version::BB_V4:
|
||||
this->bb.size = size;
|
||||
break;
|
||||
default:
|
||||
throw logic_error("unknown game version");
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t PSOCommandHeader::flag(Version version) const {
|
||||
switch (version) {
|
||||
case Version::PC_PATCH:
|
||||
case Version::BB_PATCH:
|
||||
case Version::PC_NTE:
|
||||
case Version::PC_V2:
|
||||
return this->pc.flag;
|
||||
case Version::DC_NTE:
|
||||
case Version::DC_V1_11_2000_PROTOTYPE:
|
||||
case Version::DC_V1:
|
||||
case Version::DC_V2:
|
||||
return this->dc.flag;
|
||||
case Version::GC_NTE:
|
||||
case Version::GC_V3:
|
||||
case Version::GC_EP3_NTE:
|
||||
case Version::GC_EP3:
|
||||
return this->gc.flag;
|
||||
case Version::XB_V3:
|
||||
return this->xb.flag;
|
||||
case Version::BB_V4:
|
||||
return this->bb.flag;
|
||||
default:
|
||||
throw logic_error("unknown game version");
|
||||
}
|
||||
}
|
||||
|
||||
void PSOCommandHeader::set_flag(Version version, uint32_t flag) {
|
||||
switch (version) {
|
||||
case Version::PC_PATCH:
|
||||
case Version::BB_PATCH:
|
||||
case Version::PC_NTE:
|
||||
case Version::PC_V2:
|
||||
this->pc.flag = flag;
|
||||
break;
|
||||
case Version::DC_NTE:
|
||||
case Version::DC_V1_11_2000_PROTOTYPE:
|
||||
case Version::DC_V1:
|
||||
case Version::DC_V2:
|
||||
this->dc.flag = flag;
|
||||
break;
|
||||
case Version::GC_NTE:
|
||||
case Version::GC_V3:
|
||||
case Version::GC_EP3_NTE:
|
||||
case Version::GC_EP3:
|
||||
this->gc.flag = flag;
|
||||
break;
|
||||
case Version::XB_V3:
|
||||
this->xb.flag = flag;
|
||||
break;
|
||||
case Version::BB_V4:
|
||||
this->bb.flag = flag;
|
||||
break;
|
||||
default:
|
||||
throw logic_error("unknown game version");
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
"command too small (expected at least 0x%zX bytes, received 0x%zX bytes)",
|
||||
min_size, size));
|
||||
}
|
||||
if (max_size < min_size) {
|
||||
max_size = min_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));
|
||||
}
|
||||
}
|
||||
|
||||
std::string prepend_command_header(
|
||||
Version version,
|
||||
bool encryption_enabled,
|
||||
uint16_t cmd,
|
||||
uint32_t flag,
|
||||
const std::string& data) {
|
||||
StringWriter ret;
|
||||
switch (version) {
|
||||
case Version::DC_NTE:
|
||||
case Version::DC_V1_11_2000_PROTOTYPE:
|
||||
case Version::DC_V1:
|
||||
case Version::DC_V2:
|
||||
case Version::GC_NTE:
|
||||
case Version::GC_V3:
|
||||
case Version::GC_EP3_NTE:
|
||||
case Version::GC_EP3:
|
||||
case Version::XB_V3: {
|
||||
PSOCommandHeaderDCV3 header;
|
||||
if (encryption_enabled) {
|
||||
header.size = (sizeof(header) + data.size() + 3) & ~3;
|
||||
} else {
|
||||
header.size = (sizeof(header) + data.size());
|
||||
}
|
||||
header.command = cmd;
|
||||
header.flag = flag;
|
||||
ret.put(header);
|
||||
break;
|
||||
}
|
||||
|
||||
case Version::PC_PATCH:
|
||||
case Version::BB_PATCH:
|
||||
case Version::PC_NTE:
|
||||
case Version::PC_V2: {
|
||||
PSOCommandHeaderPC header;
|
||||
if (encryption_enabled) {
|
||||
header.size = (sizeof(header) + data.size() + 3) & ~3;
|
||||
} else {
|
||||
header.size = (sizeof(header) + data.size());
|
||||
}
|
||||
header.command = cmd;
|
||||
header.flag = flag;
|
||||
ret.put(header);
|
||||
break;
|
||||
}
|
||||
|
||||
case Version::BB_V4: {
|
||||
PSOCommandHeaderBB header;
|
||||
if (encryption_enabled) {
|
||||
header.size = (sizeof(header) + data.size() + 3) & ~3;
|
||||
} else {
|
||||
header.size = (sizeof(header) + data.size());
|
||||
}
|
||||
header.command = cmd;
|
||||
header.flag = flag;
|
||||
ret.put(header);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
throw logic_error("unimplemented game version in prepend_command_header");
|
||||
}
|
||||
ret.write(data);
|
||||
return std::move(ret.str());
|
||||
}
|
||||
|
||||
+130
-130
@@ -1,130 +1,130 @@
|
||||
#pragma once
|
||||
|
||||
#include <event2/bufferevent.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <functional>
|
||||
#include <phosg/Strings.hh>
|
||||
|
||||
#include "PSOEncryption.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
struct PSOCommandHeaderPC {
|
||||
le_uint16_t size;
|
||||
uint8_t command;
|
||||
uint8_t flag;
|
||||
} __packed_ws__(PSOCommandHeaderPC, 4);
|
||||
|
||||
struct PSOCommandHeaderDCV3 {
|
||||
uint8_t command;
|
||||
uint8_t flag;
|
||||
le_uint16_t size;
|
||||
} __packed_ws__(PSOCommandHeaderDCV3, 4);
|
||||
|
||||
struct PSOCommandHeaderBB {
|
||||
le_uint16_t size;
|
||||
le_uint16_t command;
|
||||
le_uint32_t flag;
|
||||
} __packed_ws__(PSOCommandHeaderBB, 8);
|
||||
|
||||
union PSOCommandHeader {
|
||||
PSOCommandHeaderDCV3 dc;
|
||||
PSOCommandHeaderPC pc;
|
||||
PSOCommandHeaderDCV3 gc;
|
||||
PSOCommandHeaderDCV3 xb;
|
||||
PSOCommandHeaderBB bb;
|
||||
|
||||
uint16_t command(Version version) const;
|
||||
void set_command(Version version, uint16_t command);
|
||||
uint16_t size(Version version) const;
|
||||
void set_size(Version version, uint32_t size);
|
||||
uint32_t flag(Version version) const;
|
||||
void set_flag(Version version, uint32_t flag);
|
||||
static inline size_t header_size(Version version) {
|
||||
return (version == Version::BB_V4) ? 8 : 4;
|
||||
}
|
||||
|
||||
PSOCommandHeader();
|
||||
} __packed_ws__(PSOCommandHeader, 8);
|
||||
|
||||
// This function is used in a lot of places to check received command sizes and
|
||||
// cast them to the appropriate type
|
||||
template <typename RetT, typename PtrT>
|
||||
RetT& check_size_generic(
|
||||
PtrT data,
|
||||
size_t size,
|
||||
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)",
|
||||
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<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 max_size) {
|
||||
return check_size_generic<const T, const void*>(data.data(), data.size(), sizeof(T), max_size);
|
||||
}
|
||||
template <typename T>
|
||||
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 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);
|
||||
|
||||
std::string prepend_command_header(
|
||||
Version version,
|
||||
bool encryption_enabled,
|
||||
uint16_t cmd,
|
||||
uint32_t flag,
|
||||
const std::string& data);
|
||||
#pragma once
|
||||
|
||||
#include <event2/bufferevent.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <functional>
|
||||
#include <phosg/Strings.hh>
|
||||
|
||||
#include "PSOEncryption.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
struct PSOCommandHeaderPC {
|
||||
le_uint16_t size;
|
||||
uint8_t command;
|
||||
uint8_t flag;
|
||||
} __packed_ws__(PSOCommandHeaderPC, 4);
|
||||
|
||||
struct PSOCommandHeaderDCV3 {
|
||||
uint8_t command;
|
||||
uint8_t flag;
|
||||
le_uint16_t size;
|
||||
} __packed_ws__(PSOCommandHeaderDCV3, 4);
|
||||
|
||||
struct PSOCommandHeaderBB {
|
||||
le_uint16_t size;
|
||||
le_uint16_t command;
|
||||
le_uint32_t flag;
|
||||
} __packed_ws__(PSOCommandHeaderBB, 8);
|
||||
|
||||
union PSOCommandHeader {
|
||||
PSOCommandHeaderDCV3 dc;
|
||||
PSOCommandHeaderPC pc;
|
||||
PSOCommandHeaderDCV3 gc;
|
||||
PSOCommandHeaderDCV3 xb;
|
||||
PSOCommandHeaderBB bb;
|
||||
|
||||
uint16_t command(Version version) const;
|
||||
void set_command(Version version, uint16_t command);
|
||||
uint16_t size(Version version) const;
|
||||
void set_size(Version version, uint32_t size);
|
||||
uint32_t flag(Version version) const;
|
||||
void set_flag(Version version, uint32_t flag);
|
||||
static inline size_t header_size(Version version) {
|
||||
return (version == Version::BB_V4) ? 8 : 4;
|
||||
}
|
||||
|
||||
PSOCommandHeader();
|
||||
} __packed_ws__(PSOCommandHeader, 8);
|
||||
|
||||
// This function is used in a lot of places to check received command sizes and
|
||||
// cast them to the appropriate type
|
||||
template <typename RetT, typename PtrT>
|
||||
RetT& check_size_generic(
|
||||
PtrT data,
|
||||
size_t size,
|
||||
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)",
|
||||
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<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 max_size) {
|
||||
return check_size_generic<const T, const void*>(data.data(), data.size(), sizeof(T), max_size);
|
||||
}
|
||||
template <typename T>
|
||||
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 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);
|
||||
|
||||
std::string prepend_command_header(
|
||||
Version version,
|
||||
bool encryption_enabled,
|
||||
uint16_t cmd,
|
||||
uint32_t flag,
|
||||
const std::string& data);
|
||||
|
||||
+162
-162
@@ -1,162 +1,162 @@
|
||||
#include "PatchFileIndex.hh"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <functional>
|
||||
#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) {}
|
||||
|
||||
std::shared_ptr<const std::string> PatchFileIndex::File::load_data() {
|
||||
if (!this->loaded_data) {
|
||||
string relative_path = join(this->path_directories, "/") + "/" + this->name;
|
||||
string full_path = this->index->root_dir + "/" + relative_path;
|
||||
patch_index_log.info("Loading data for %s", relative_path.c_str());
|
||||
this->loaded_data = make_shared<string>(load_file(full_path));
|
||||
this->size = this->loaded_data->size();
|
||||
}
|
||||
return this->loaded_data;
|
||||
}
|
||||
|
||||
PatchFileIndex::PatchFileIndex(const string& root_dir)
|
||||
: root_dir(root_dir) {
|
||||
|
||||
string metadata_cache_filename = root_dir + "/.metadata-cache.json";
|
||||
JSON metadata_cache_json;
|
||||
try {
|
||||
string metadata_text = load_file(metadata_cache_filename);
|
||||
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 = 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;
|
||||
JSON new_metadata_cache_json = JSON::dict();
|
||||
|
||||
vector<string> path_directories;
|
||||
function<void(const string&)> collect_dir = [&](const string& dir) -> void {
|
||||
path_directories.emplace_back(dir);
|
||||
|
||||
string relative_dirs = join(path_directories, "/");
|
||||
string full_dir_path = root_dir + '/' + relative_dirs;
|
||||
patch_index_log.info("Listing directory %s", full_dir_path.c_str());
|
||||
|
||||
for (const auto& item : list_directory(full_dir_path)) {
|
||||
// Skip invisible files (e.g. .DS_Store on macOS)
|
||||
if (starts_with(item, ".")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
string relative_item_path = relative_dirs + '/' + item;
|
||||
string full_item_path = root_dir + '/' + relative_item_path;
|
||||
if (isdir(full_item_path)) {
|
||||
collect_dir(item);
|
||||
} else if (isfile(full_item_path)) {
|
||||
|
||||
auto st = stat(full_item_path);
|
||||
|
||||
auto f = make_shared<File>(this);
|
||||
f->path_directories = path_directories;
|
||||
f->name = item;
|
||||
|
||||
string compute_crc32s_message; // If not empty, should compute crc32s
|
||||
JSON cache_item_json;
|
||||
try {
|
||||
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");
|
||||
}
|
||||
if (static_cast<uint64_t>(st.st_size) != cached_size) {
|
||||
throw runtime_error("file size has changed");
|
||||
}
|
||||
f->size = cached_size;
|
||||
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());
|
||||
}
|
||||
|
||||
} catch (const exception& e) {
|
||||
compute_crc32s_message = e.what();
|
||||
}
|
||||
|
||||
if (!compute_crc32s_message.empty()) {
|
||||
auto data = f->load_data(); // Sets f->size
|
||||
f->crc32 = crc32(data->data(), f->size);
|
||||
for (size_t x = 0; x < data->size(); x += 0x4000) {
|
||||
size_t chunk_bytes = min<size_t>(f->size - x, 0x4000);
|
||||
f->chunk_crcs.emplace_back(::crc32(data->data() + x, chunk_bytes));
|
||||
}
|
||||
|
||||
// File was modified or cache item was missing; make a new cache item
|
||||
auto chunk_crcs_item = JSON::list();
|
||||
for (uint32_t chunk_crc : f->chunk_crcs) {
|
||||
chunk_crcs_item.emplace_back(chunk_crc);
|
||||
}
|
||||
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.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)",
|
||||
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])",
|
||||
full_item_path.c_str(), f->size, f->chunk_crcs.size(), f->crc32, compute_crc32s_message.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
path_directories.pop_back();
|
||||
};
|
||||
|
||||
collect_dir(".");
|
||||
|
||||
if (should_write_metadata_cache) {
|
||||
try {
|
||||
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());
|
||||
}
|
||||
} else {
|
||||
patch_index_log.info("No files were modified; skipping metadata cache update");
|
||||
}
|
||||
}
|
||||
|
||||
const vector<shared_ptr<PatchFileIndex::File>>&
|
||||
PatchFileIndex::all_files() const {
|
||||
return this->files_by_patch_order;
|
||||
}
|
||||
|
||||
shared_ptr<PatchFileIndex::File> PatchFileIndex::get(
|
||||
const string& filename) const {
|
||||
return this->files_by_name.at(filename);
|
||||
}
|
||||
#include "PatchFileIndex.hh"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <functional>
|
||||
#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) {}
|
||||
|
||||
std::shared_ptr<const std::string> PatchFileIndex::File::load_data() {
|
||||
if (!this->loaded_data) {
|
||||
string relative_path = join(this->path_directories, "/") + "/" + this->name;
|
||||
string full_path = this->index->root_dir + "/" + relative_path;
|
||||
patch_index_log.info("Loading data for %s", relative_path.c_str());
|
||||
this->loaded_data = make_shared<string>(load_file(full_path));
|
||||
this->size = this->loaded_data->size();
|
||||
}
|
||||
return this->loaded_data;
|
||||
}
|
||||
|
||||
PatchFileIndex::PatchFileIndex(const string& root_dir)
|
||||
: root_dir(root_dir) {
|
||||
|
||||
string metadata_cache_filename = root_dir + "/.metadata-cache.json";
|
||||
JSON metadata_cache_json;
|
||||
try {
|
||||
string metadata_text = load_file(metadata_cache_filename);
|
||||
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 = 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;
|
||||
JSON new_metadata_cache_json = JSON::dict();
|
||||
|
||||
vector<string> path_directories;
|
||||
function<void(const string&)> collect_dir = [&](const string& dir) -> void {
|
||||
path_directories.emplace_back(dir);
|
||||
|
||||
string relative_dirs = join(path_directories, "/");
|
||||
string full_dir_path = root_dir + '/' + relative_dirs;
|
||||
patch_index_log.info("Listing directory %s", full_dir_path.c_str());
|
||||
|
||||
for (const auto& item : list_directory(full_dir_path)) {
|
||||
// Skip invisible files (e.g. .DS_Store on macOS)
|
||||
if (starts_with(item, ".")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
string relative_item_path = relative_dirs + '/' + item;
|
||||
string full_item_path = root_dir + '/' + relative_item_path;
|
||||
if (isdir(full_item_path)) {
|
||||
collect_dir(item);
|
||||
} else if (isfile(full_item_path)) {
|
||||
|
||||
auto st = stat(full_item_path);
|
||||
|
||||
auto f = make_shared<File>(this);
|
||||
f->path_directories = path_directories;
|
||||
f->name = item;
|
||||
|
||||
string compute_crc32s_message; // If not empty, should compute crc32s
|
||||
JSON cache_item_json;
|
||||
try {
|
||||
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");
|
||||
}
|
||||
if (static_cast<uint64_t>(st.st_size) != cached_size) {
|
||||
throw runtime_error("file size has changed");
|
||||
}
|
||||
f->size = cached_size;
|
||||
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());
|
||||
}
|
||||
|
||||
} catch (const exception& e) {
|
||||
compute_crc32s_message = e.what();
|
||||
}
|
||||
|
||||
if (!compute_crc32s_message.empty()) {
|
||||
auto data = f->load_data(); // Sets f->size
|
||||
f->crc32 = crc32(data->data(), f->size);
|
||||
for (size_t x = 0; x < data->size(); x += 0x4000) {
|
||||
size_t chunk_bytes = min<size_t>(f->size - x, 0x4000);
|
||||
f->chunk_crcs.emplace_back(::crc32(data->data() + x, chunk_bytes));
|
||||
}
|
||||
|
||||
// File was modified or cache item was missing; make a new cache item
|
||||
auto chunk_crcs_item = JSON::list();
|
||||
for (uint32_t chunk_crc : f->chunk_crcs) {
|
||||
chunk_crcs_item.emplace_back(chunk_crc);
|
||||
}
|
||||
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.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)",
|
||||
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])",
|
||||
full_item_path.c_str(), f->size, f->chunk_crcs.size(), f->crc32, compute_crc32s_message.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
path_directories.pop_back();
|
||||
};
|
||||
|
||||
collect_dir(".");
|
||||
|
||||
if (should_write_metadata_cache) {
|
||||
try {
|
||||
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());
|
||||
}
|
||||
} else {
|
||||
patch_index_log.info("No files were modified; skipping metadata cache update");
|
||||
}
|
||||
}
|
||||
|
||||
const vector<shared_ptr<PatchFileIndex::File>>&
|
||||
PatchFileIndex::all_files() const {
|
||||
return this->files_by_patch_order;
|
||||
}
|
||||
|
||||
shared_ptr<PatchFileIndex::File> PatchFileIndex::get(
|
||||
const string& filename) const {
|
||||
return this->files_by_name.at(filename);
|
||||
}
|
||||
|
||||
+52
-52
@@ -1,52 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
struct PatchFileIndex {
|
||||
explicit PatchFileIndex(const std::string& root_dir);
|
||||
|
||||
struct File {
|
||||
PatchFileIndex* index;
|
||||
std::vector<std::string> path_directories;
|
||||
std::string name;
|
||||
std::shared_ptr<const std::string> loaded_data;
|
||||
std::vector<uint32_t> chunk_crcs;
|
||||
uint32_t crc32;
|
||||
uint32_t size;
|
||||
|
||||
explicit File(PatchFileIndex* index);
|
||||
std::shared_ptr<const std::string> load_data();
|
||||
};
|
||||
|
||||
const std::vector<std::shared_ptr<File>>& all_files() const;
|
||||
std::shared_ptr<File> get(const std::string& filename) const;
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<File>> files_by_patch_order;
|
||||
std::unordered_map<std::string, std::shared_ptr<File>> files_by_name;
|
||||
std::string root_dir;
|
||||
};
|
||||
|
||||
struct PatchFileChecksumRequest {
|
||||
std::shared_ptr<PatchFileIndex::File> file;
|
||||
uint32_t crc32;
|
||||
uint32_t size;
|
||||
bool response_received;
|
||||
|
||||
explicit PatchFileChecksumRequest(std::shared_ptr<PatchFileIndex::File> file)
|
||||
: 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);
|
||||
}
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
struct PatchFileIndex {
|
||||
explicit PatchFileIndex(const std::string& root_dir);
|
||||
|
||||
struct File {
|
||||
PatchFileIndex* index;
|
||||
std::vector<std::string> path_directories;
|
||||
std::string name;
|
||||
std::shared_ptr<const std::string> loaded_data;
|
||||
std::vector<uint32_t> chunk_crcs;
|
||||
uint32_t crc32;
|
||||
uint32_t size;
|
||||
|
||||
explicit File(PatchFileIndex* index);
|
||||
std::shared_ptr<const std::string> load_data();
|
||||
};
|
||||
|
||||
const std::vector<std::shared_ptr<File>>& all_files() const;
|
||||
std::shared_ptr<File> get(const std::string& filename) const;
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<File>> files_by_patch_order;
|
||||
std::unordered_map<std::string, std::shared_ptr<File>> files_by_name;
|
||||
std::string root_dir;
|
||||
};
|
||||
|
||||
struct PatchFileChecksumRequest {
|
||||
std::shared_ptr<PatchFileIndex::File> file;
|
||||
uint32_t crc32;
|
||||
uint32_t size;
|
||||
bool response_received;
|
||||
|
||||
explicit PatchFileChecksumRequest(std::shared_ptr<PatchFileIndex::File> file)
|
||||
: 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);
|
||||
}
|
||||
};
|
||||
|
||||
+478
-478
@@ -1,478 +1,478 @@
|
||||
#include "PatchServer.hh"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <event2/buffer.h>
|
||||
#include <event2/bufferevent.h>
|
||||
#include <event2/event.h>
|
||||
#include <event2/listener.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Network.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <phosg/Time.hh>
|
||||
|
||||
#include "EventUtils.hh"
|
||||
#include "Loggers.hh"
|
||||
#include "PSOProtocol.hh"
|
||||
#include "ReceiveCommands.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
static atomic<uint64_t> next_id(1);
|
||||
|
||||
PatchServer::Client::Client(
|
||||
shared_ptr<PatchServer> server,
|
||||
struct bufferevent* bev,
|
||||
Version version,
|
||||
uint64_t idle_timeout_usecs,
|
||||
bool hide_data_from_logs)
|
||||
: server(server),
|
||||
id(next_id++),
|
||||
log(string_printf("[C-%" PRIX64 "] ", this->id), client_log.min_level),
|
||||
channel(bev, 0, version, 1, nullptr, nullptr, this, string_printf("C-%" PRIX64, this->id), TerminalFormat::FG_YELLOW, TerminalFormat::FG_GREEN),
|
||||
idle_timeout_usecs(idle_timeout_usecs),
|
||||
idle_timeout_event(
|
||||
event_new(bufferevent_get_base(bev), -1, EV_TIMEOUT, &PatchServer::Client::dispatch_idle_timeout, this),
|
||||
event_free) {
|
||||
this->reschedule_timeout_event();
|
||||
|
||||
// Don't print data sent to patch clients to the logs. The patch server
|
||||
// protocol is fully understood and data logs for patch clients are generally
|
||||
// more annoying than helpful at this point.
|
||||
if (hide_data_from_logs) {
|
||||
this->channel.terminal_recv_color = TerminalFormat::END;
|
||||
this->channel.terminal_send_color = TerminalFormat::END;
|
||||
}
|
||||
|
||||
this->log.info("Created");
|
||||
}
|
||||
|
||||
void PatchServer::Client::reschedule_timeout_event() {
|
||||
struct timeval idle_tv = usecs_to_timeval(this->idle_timeout_usecs);
|
||||
event_add(this->idle_timeout_event.get(), &idle_tv);
|
||||
}
|
||||
|
||||
void PatchServer::Client::dispatch_idle_timeout(evutil_socket_t, short, void* ctx) {
|
||||
reinterpret_cast<Client*>(ctx)->idle_timeout();
|
||||
}
|
||||
|
||||
void PatchServer::Client::idle_timeout() {
|
||||
this->log.info("Idle timeout expired");
|
||||
auto s = this->server.lock();
|
||||
if (s) {
|
||||
auto c = this->shared_from_this();
|
||||
s->disconnect_client(c);
|
||||
} else {
|
||||
this->channel.disconnect();
|
||||
this->log.info("Server is deleted; cannot disconnect client");
|
||||
}
|
||||
}
|
||||
|
||||
void PatchServer::send_server_init(shared_ptr<Client> c) const {
|
||||
uint32_t server_key = random_object<uint32_t>();
|
||||
uint32_t client_key = random_object<uint32_t>();
|
||||
|
||||
S_ServerInit_Patch_02 cmd;
|
||||
cmd.copyright.encode("Patch Server. Copyright SonicTeam, LTD. 2001");
|
||||
cmd.server_key = server_key;
|
||||
cmd.client_key = client_key;
|
||||
c->channel.send(0x02, 0x00, cmd);
|
||||
|
||||
c->channel.crypt_out = make_shared<PSOV2Encryption>(server_key);
|
||||
c->channel.crypt_in = make_shared<PSOV2Encryption>(client_key);
|
||||
}
|
||||
|
||||
void PatchServer::send_message_box(shared_ptr<Client> c, const string& text) const {
|
||||
StringWriter w;
|
||||
try {
|
||||
if (c->version() == Version::PC_PATCH) {
|
||||
w.write(tt_encode_marked_optional(text, c->channel.language, true));
|
||||
} else if (c->version() == Version::BB_PATCH) {
|
||||
w.write(tt_encode_marked_optional(add_color(text), c->channel.language, true));
|
||||
} else {
|
||||
throw logic_error("non-patch client on patch server");
|
||||
}
|
||||
} catch (const runtime_error& e) {
|
||||
log_warning("Failed to encode message for patch message box command: %s", e.what());
|
||||
return;
|
||||
}
|
||||
w.put_u16(0);
|
||||
while (w.str().size() & 3) {
|
||||
w.put_u8(0);
|
||||
}
|
||||
c->channel.send(0x13, 0x00, w.str());
|
||||
}
|
||||
|
||||
void PatchServer::send_enter_directory(shared_ptr<Client> c, const string& dir) const {
|
||||
S_EnterDirectory_Patch_09 cmd = {{dir, 1}};
|
||||
c->channel.send(0x09, 0x00, cmd);
|
||||
}
|
||||
|
||||
void PatchServer::on_02(shared_ptr<Client> c, string& data) {
|
||||
check_size_v(data.size(), 0);
|
||||
c->channel.send(0x04, 0x00); // This requests the user's login information
|
||||
}
|
||||
|
||||
void PatchServer::change_to_directory(
|
||||
shared_ptr<Client> c,
|
||||
vector<string>& client_path_directories,
|
||||
const vector<string>& file_path_directories) const {
|
||||
// First, exit all leaf directories that don't match the desired path
|
||||
while (!client_path_directories.empty() &&
|
||||
((client_path_directories.size() > file_path_directories.size()) ||
|
||||
(client_path_directories.back() != file_path_directories[client_path_directories.size() - 1]))) {
|
||||
c->channel.send(0x0A, 0x00);
|
||||
client_path_directories.pop_back();
|
||||
}
|
||||
|
||||
// At this point, client_path_directories should be a prefix of
|
||||
// file_path_directories (or should match exactly)
|
||||
if (client_path_directories.size() > file_path_directories.size()) {
|
||||
throw logic_error("did not exit all necessary directories");
|
||||
}
|
||||
for (size_t x = 0; x < client_path_directories.size(); x++) {
|
||||
if (client_path_directories[x] != file_path_directories[x]) {
|
||||
throw logic_error("intermediate path is not a prefix of final path");
|
||||
}
|
||||
}
|
||||
|
||||
// Second, enter all necessary leaf directories
|
||||
while (client_path_directories.size() < file_path_directories.size()) {
|
||||
const string& dir = file_path_directories[client_path_directories.size()];
|
||||
this->send_enter_directory(c, dir);
|
||||
client_path_directories.emplace_back(dir);
|
||||
}
|
||||
}
|
||||
|
||||
void PatchServer::on_04(shared_ptr<Client> c, string& data) {
|
||||
const auto& cmd = check_size_t<C_Login_Patch_04>(data);
|
||||
|
||||
string username = cmd.username.decode();
|
||||
string password = cmd.password.decode();
|
||||
|
||||
// There are 3 cases here:
|
||||
// - No login information at all: just proceed without checking credentials
|
||||
// - Username: check that account exists if allow_unregistered_users is off
|
||||
// - Username and password: call verify_bb
|
||||
if (!username.empty() && !password.empty()) {
|
||||
try {
|
||||
this->config->account_index->from_bb_credentials(username, &password, false);
|
||||
|
||||
} catch (const AccountIndex::incorrect_password& e) {
|
||||
this->send_message_box(c, string_printf("Login failed: %s", e.what()));
|
||||
this->disconnect_client(c);
|
||||
return;
|
||||
|
||||
} catch (const AccountIndex::missing_account& e) {
|
||||
if (!this->config->allow_unregistered_users) {
|
||||
this->send_message_box(c, string_printf("Login failed: %s", e.what()));
|
||||
this->disconnect_client(c);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (!username.empty() && !this->config->allow_unregistered_users) {
|
||||
try {
|
||||
this->config->account_index->from_bb_credentials(username, nullptr, false);
|
||||
} catch (const AccountIndex::missing_account& e) {
|
||||
this->send_message_box(c, string_printf("Login failed: %s", e.what()));
|
||||
this->disconnect_client(c);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this->config->message.empty()) {
|
||||
this->send_message_box(c, this->config->message.c_str());
|
||||
}
|
||||
|
||||
const auto& index = this->config->patch_file_index;
|
||||
if (index.get()) {
|
||||
c->channel.send(0x0B, 0x00); // Start patch session; go to root directory
|
||||
|
||||
vector<string> path_directories;
|
||||
for (const auto& file : index->all_files()) {
|
||||
this->change_to_directory(c, path_directories, file->path_directories);
|
||||
|
||||
S_FileChecksumRequest_Patch_0C req = {c->patch_file_checksum_requests.size(), {file->name, 1}};
|
||||
c->channel.send(0x0C, 0x00, req);
|
||||
c->patch_file_checksum_requests.emplace_back(file);
|
||||
}
|
||||
this->change_to_directory(c, path_directories, {});
|
||||
|
||||
c->channel.send(0x0D, 0x00); // End of checksum requests
|
||||
|
||||
} else {
|
||||
// No patch index present: just do something that will satisfy the client
|
||||
// without actually checking or downloading any files
|
||||
this->send_enter_directory(c, ".");
|
||||
this->send_enter_directory(c, "data");
|
||||
this->send_enter_directory(c, "scene");
|
||||
c->channel.send(0x0A, 0x00);
|
||||
c->channel.send(0x0A, 0x00);
|
||||
c->channel.send(0x0A, 0x00);
|
||||
c->channel.send(0x12, 0x00);
|
||||
}
|
||||
}
|
||||
|
||||
void PatchServer::on_0F(shared_ptr<Client> c, string& data) {
|
||||
auto& cmd = check_size_t<C_FileInformation_Patch_0F>(data);
|
||||
auto& req = c->patch_file_checksum_requests.at(cmd.request_id);
|
||||
req.crc32 = cmd.checksum;
|
||||
req.size = cmd.size;
|
||||
req.response_received = true;
|
||||
}
|
||||
|
||||
void PatchServer::on_10(shared_ptr<Client> c, string&) {
|
||||
S_StartFileDownloads_Patch_11 start_cmd = {0, 0};
|
||||
for (const auto& req : c->patch_file_checksum_requests) {
|
||||
if (!req.response_received) {
|
||||
throw runtime_error("client did not respond to checksum request");
|
||||
}
|
||||
if (req.needs_update()) {
|
||||
c->log.info("File %s needs update (CRC: %08" PRIX32 "/%08" PRIX32 ", size: %" PRIu32 "/%" PRIu32 ")",
|
||||
req.file->name.c_str(), req.file->crc32, req.crc32, req.file->size, req.size);
|
||||
start_cmd.total_bytes += req.file->size;
|
||||
start_cmd.num_files++;
|
||||
} else {
|
||||
c->log.info("File %s is up to date", req.file->name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if (start_cmd.num_files) {
|
||||
c->channel.send(0x11, 0x00, start_cmd);
|
||||
vector<string> path_directories;
|
||||
for (const auto& req : c->patch_file_checksum_requests) {
|
||||
if (req.needs_update()) {
|
||||
this->change_to_directory(c, path_directories, req.file->path_directories);
|
||||
|
||||
S_OpenFile_Patch_06 open_cmd = {0, req.file->size, {req.file->name, 1}};
|
||||
c->channel.send(0x06, 0x00, open_cmd);
|
||||
|
||||
for (size_t x = 0; x < req.file->chunk_crcs.size(); x++) {
|
||||
auto data = req.file->load_data();
|
||||
size_t chunk_size = min<uint32_t>(req.file->size - (x * 0x4000), 0x4000);
|
||||
|
||||
vector<pair<const void*, size_t>> blocks;
|
||||
S_WriteFileHeader_Patch_07 cmd_header = {x, req.file->chunk_crcs[x], chunk_size};
|
||||
blocks.emplace_back(&cmd_header, sizeof(cmd_header));
|
||||
blocks.emplace_back(data->data() + (x * 0x4000), chunk_size);
|
||||
c->channel.send(0x07, 0x00, blocks);
|
||||
}
|
||||
|
||||
S_CloseCurrentFile_Patch_08 close_cmd = {0};
|
||||
c->channel.send(0x08, 0x00, close_cmd);
|
||||
}
|
||||
}
|
||||
this->change_to_directory(c, path_directories, {});
|
||||
}
|
||||
|
||||
c->channel.send(0x12, 0x00);
|
||||
}
|
||||
|
||||
void PatchServer::disconnect_client(shared_ptr<Client> c) {
|
||||
if (c->channel.virtual_network_id) {
|
||||
server_log.info("Client disconnected: C-%" PRIX64 " on N-%" PRIu64, c->id, c->channel.virtual_network_id);
|
||||
} else if (c->channel.bev) {
|
||||
server_log.info("Client disconnected: C-%" PRIX64, c->id);
|
||||
} else {
|
||||
server_log.info("Client C-%" PRIX64 " removed from patch server", c->id);
|
||||
}
|
||||
|
||||
this->channel_to_client.erase(&c->channel);
|
||||
c->channel.disconnect();
|
||||
|
||||
// We can't just let c be destroyed here, since disconnect_client can be
|
||||
// called from within the client's channel's receive handler. So, we instead
|
||||
// move it to another set, which we'll clear in an immediately-enqueued
|
||||
// callback after the current event. This will also call the client's
|
||||
// disconnect hooks (if any).
|
||||
this->clients_to_destroy.insert(std::move(c));
|
||||
this->enqueue_destroy_clients();
|
||||
}
|
||||
|
||||
void PatchServer::enqueue_destroy_clients() {
|
||||
auto tv = usecs_to_timeval(0);
|
||||
event_add(this->destroy_clients_ev.get(), &tv);
|
||||
}
|
||||
|
||||
void PatchServer::dispatch_destroy_clients(evutil_socket_t, short, void* ctx) {
|
||||
reinterpret_cast<PatchServer*>(ctx)->clients_to_destroy.clear();
|
||||
}
|
||||
|
||||
void PatchServer::dispatch_on_listen_accept(
|
||||
struct evconnlistener* listener, evutil_socket_t fd,
|
||||
struct sockaddr* address, int socklen, void* ctx) {
|
||||
reinterpret_cast<PatchServer*>(ctx)->on_listen_accept(listener, fd, address, socklen);
|
||||
}
|
||||
|
||||
void PatchServer::dispatch_on_listen_error(
|
||||
struct evconnlistener* listener, void* ctx) {
|
||||
reinterpret_cast<PatchServer*>(ctx)->on_listen_error(listener);
|
||||
}
|
||||
|
||||
void PatchServer::on_listen_accept(struct evconnlistener* listener, evutil_socket_t fd, struct sockaddr*, int) {
|
||||
struct sockaddr_storage remote_addr;
|
||||
get_socket_addresses(fd, nullptr, &remote_addr);
|
||||
if (this->config->banned_ipv4_ranges->check(remote_addr)) {
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
int listen_fd = evconnlistener_get_fd(listener);
|
||||
ListeningSocket* listening_socket;
|
||||
try {
|
||||
listening_socket = &this->listening_sockets.at(listen_fd);
|
||||
} catch (const out_of_range& e) {
|
||||
server_log.warning("Can\'t determine version for socket %d; disconnecting client", listen_fd);
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
struct bufferevent* bev = bufferevent_socket_new(this->base.get(), fd, BEV_OPT_CLOSE_ON_FREE | BEV_OPT_DEFER_CALLBACKS);
|
||||
auto c = make_shared<Client>(
|
||||
this->shared_from_this(),
|
||||
bev,
|
||||
listening_socket->version,
|
||||
this->config->idle_timeout_usecs,
|
||||
this->config->hide_data_from_logs);
|
||||
c->channel.on_command_received = PatchServer::on_client_input;
|
||||
c->channel.on_error = PatchServer::on_client_error;
|
||||
c->channel.context_obj = this;
|
||||
this->channel_to_client.emplace(&c->channel, c);
|
||||
|
||||
server_log.info("Patch client connected: U-%" PRIX64 " on fd %d via %d (%s)",
|
||||
c->id, fd, listen_fd, listening_socket->addr_str.c_str());
|
||||
|
||||
this->send_server_init(c);
|
||||
}
|
||||
|
||||
void PatchServer::on_listen_error(struct evconnlistener* listener) {
|
||||
int err = EVUTIL_SOCKET_ERROR();
|
||||
server_log.error("Failure on listening socket %d: %d (%s)",
|
||||
evconnlistener_get_fd(listener), err, evutil_socket_error_to_string(err));
|
||||
event_base_loopexit(this->base.get(), nullptr);
|
||||
}
|
||||
|
||||
void PatchServer::on_client_input(Channel& ch, uint16_t command, uint32_t, std::string& data) {
|
||||
PatchServer* server = reinterpret_cast<PatchServer*>(ch.context_obj);
|
||||
shared_ptr<Client> c = server->channel_to_client.at(&ch);
|
||||
|
||||
try {
|
||||
switch (command) {
|
||||
case 0x02:
|
||||
server->on_02(c, data);
|
||||
break;
|
||||
case 0x04:
|
||||
server->on_04(c, data);
|
||||
break;
|
||||
case 0x0F:
|
||||
server->on_0F(c, data);
|
||||
break;
|
||||
case 0x10:
|
||||
server->on_10(c, data);
|
||||
break;
|
||||
default:
|
||||
throw runtime_error("invalid command");
|
||||
}
|
||||
} catch (const exception& e) {
|
||||
server_log.warning("Error processing client command: %s", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void PatchServer::on_client_error(Channel& ch, short events) {
|
||||
PatchServer* server = reinterpret_cast<PatchServer*>(ch.context_obj);
|
||||
shared_ptr<Client> c = server->channel_to_client.at(&ch);
|
||||
|
||||
if (events & BEV_EVENT_ERROR) {
|
||||
int err = EVUTIL_SOCKET_ERROR();
|
||||
server_log.warning("Client caused error %d (%s)", err, evutil_socket_error_to_string(err));
|
||||
}
|
||||
if (events & (BEV_EVENT_EOF | BEV_EVENT_ERROR)) {
|
||||
server->disconnect_client(c);
|
||||
}
|
||||
}
|
||||
|
||||
PatchServer::PatchServer(shared_ptr<const Config> config)
|
||||
: config(config) {
|
||||
if (config->shared_base) {
|
||||
this->base = config->shared_base;
|
||||
this->base_is_shared = true;
|
||||
} else {
|
||||
this->base.reset(event_base_new(), event_base_free);
|
||||
this->base_is_shared = false;
|
||||
}
|
||||
this->destroy_clients_ev.reset(
|
||||
event_new(this->base.get(), -1, EV_TIMEOUT, &PatchServer::dispatch_destroy_clients, this), event_free);
|
||||
if (!this->base_is_shared) {
|
||||
this->th = thread(&PatchServer::thread_fn, this);
|
||||
}
|
||||
}
|
||||
|
||||
void PatchServer::schedule_stop() {
|
||||
if (!this->base_is_shared) {
|
||||
event_base_loopexit(this->base.get(), nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void PatchServer::wait_for_stop() {
|
||||
if (!this->base_is_shared) {
|
||||
this->th.join();
|
||||
}
|
||||
}
|
||||
|
||||
void PatchServer::listen(const std::string& addr_str, const string& socket_path, Version version) {
|
||||
int fd = ::listen(socket_path, 0, SOMAXCONN);
|
||||
server_log.info("Listening on Unix socket %s on fd %d as %s", socket_path.c_str(), fd, addr_str.c_str());
|
||||
this->add_socket(addr_str, fd, version);
|
||||
}
|
||||
|
||||
void PatchServer::listen(const std::string& addr_str, const string& addr, int port, Version version) {
|
||||
if (port == 0) {
|
||||
this->listen(addr_str, addr, version);
|
||||
} else {
|
||||
int fd = ::listen(addr, port, SOMAXCONN);
|
||||
string netloc_str = render_netloc(addr, port);
|
||||
server_log.info("Listening on TCP interface %s on fd %d as %s", netloc_str.c_str(), fd, addr_str.c_str());
|
||||
this->add_socket(addr_str, fd, version);
|
||||
}
|
||||
}
|
||||
|
||||
void PatchServer::listen(const std::string& addr_str, int port, Version version) {
|
||||
this->listen(addr_str, "", port, version);
|
||||
}
|
||||
|
||||
PatchServer::ListeningSocket::ListeningSocket(PatchServer* s, const std::string& addr_str, int fd, Version version)
|
||||
: addr_str(addr_str),
|
||||
fd(fd),
|
||||
version(version),
|
||||
listener(evconnlistener_new(s->base.get(), PatchServer::dispatch_on_listen_accept, s, LEV_OPT_REUSEABLE, 0, this->fd),
|
||||
evconnlistener_free) {
|
||||
evconnlistener_set_error_cb(this->listener.get(), PatchServer::dispatch_on_listen_error);
|
||||
}
|
||||
|
||||
void PatchServer::add_socket(const std::string& addr_str, int fd, Version version) {
|
||||
this->listening_sockets.emplace(piecewise_construct, forward_as_tuple(fd), forward_as_tuple(this, addr_str, fd, version));
|
||||
}
|
||||
|
||||
void PatchServer::thread_fn() {
|
||||
event_base_loop(this->base.get(), EVLOOP_NO_EXIT_ON_EMPTY);
|
||||
}
|
||||
|
||||
void PatchServer::set_config(std::shared_ptr<const Config> config) {
|
||||
if (this->base_is_shared) {
|
||||
this->config = config;
|
||||
} else {
|
||||
forward_to_event_thread(this->base, [s = this->shared_from_this(), config = std::move(config)]() {
|
||||
s->config = config;
|
||||
});
|
||||
}
|
||||
}
|
||||
#include "PatchServer.hh"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <event2/buffer.h>
|
||||
#include <event2/bufferevent.h>
|
||||
#include <event2/event.h>
|
||||
#include <event2/listener.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Network.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <phosg/Time.hh>
|
||||
|
||||
#include "EventUtils.hh"
|
||||
#include "Loggers.hh"
|
||||
#include "PSOProtocol.hh"
|
||||
#include "ReceiveCommands.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
static atomic<uint64_t> next_id(1);
|
||||
|
||||
PatchServer::Client::Client(
|
||||
shared_ptr<PatchServer> server,
|
||||
struct bufferevent* bev,
|
||||
Version version,
|
||||
uint64_t idle_timeout_usecs,
|
||||
bool hide_data_from_logs)
|
||||
: server(server),
|
||||
id(next_id++),
|
||||
log(string_printf("[C-%" PRIX64 "] ", this->id), client_log.min_level),
|
||||
channel(bev, 0, version, 1, nullptr, nullptr, this, string_printf("C-%" PRIX64, this->id), TerminalFormat::FG_YELLOW, TerminalFormat::FG_GREEN),
|
||||
idle_timeout_usecs(idle_timeout_usecs),
|
||||
idle_timeout_event(
|
||||
event_new(bufferevent_get_base(bev), -1, EV_TIMEOUT, &PatchServer::Client::dispatch_idle_timeout, this),
|
||||
event_free) {
|
||||
this->reschedule_timeout_event();
|
||||
|
||||
// Don't print data sent to patch clients to the logs. The patch server
|
||||
// protocol is fully understood and data logs for patch clients are generally
|
||||
// more annoying than helpful at this point.
|
||||
if (hide_data_from_logs) {
|
||||
this->channel.terminal_recv_color = TerminalFormat::END;
|
||||
this->channel.terminal_send_color = TerminalFormat::END;
|
||||
}
|
||||
|
||||
this->log.info("Created");
|
||||
}
|
||||
|
||||
void PatchServer::Client::reschedule_timeout_event() {
|
||||
struct timeval idle_tv = usecs_to_timeval(this->idle_timeout_usecs);
|
||||
event_add(this->idle_timeout_event.get(), &idle_tv);
|
||||
}
|
||||
|
||||
void PatchServer::Client::dispatch_idle_timeout(evutil_socket_t, short, void* ctx) {
|
||||
reinterpret_cast<Client*>(ctx)->idle_timeout();
|
||||
}
|
||||
|
||||
void PatchServer::Client::idle_timeout() {
|
||||
this->log.info("Idle timeout expired");
|
||||
auto s = this->server.lock();
|
||||
if (s) {
|
||||
auto c = this->shared_from_this();
|
||||
s->disconnect_client(c);
|
||||
} else {
|
||||
this->channel.disconnect();
|
||||
this->log.info("Server is deleted; cannot disconnect client");
|
||||
}
|
||||
}
|
||||
|
||||
void PatchServer::send_server_init(shared_ptr<Client> c) const {
|
||||
uint32_t server_key = random_object<uint32_t>();
|
||||
uint32_t client_key = random_object<uint32_t>();
|
||||
|
||||
S_ServerInit_Patch_02 cmd;
|
||||
cmd.copyright.encode("Patch Server. Copyright SonicTeam, LTD. 2001");
|
||||
cmd.server_key = server_key;
|
||||
cmd.client_key = client_key;
|
||||
c->channel.send(0x02, 0x00, cmd);
|
||||
|
||||
c->channel.crypt_out = make_shared<PSOV2Encryption>(server_key);
|
||||
c->channel.crypt_in = make_shared<PSOV2Encryption>(client_key);
|
||||
}
|
||||
|
||||
void PatchServer::send_message_box(shared_ptr<Client> c, const string& text) const {
|
||||
StringWriter w;
|
||||
try {
|
||||
if (c->version() == Version::PC_PATCH) {
|
||||
w.write(tt_encode_marked_optional(text, c->channel.language, true));
|
||||
} else if (c->version() == Version::BB_PATCH) {
|
||||
w.write(tt_encode_marked_optional(add_color(text), c->channel.language, true));
|
||||
} else {
|
||||
throw logic_error("non-patch client on patch server");
|
||||
}
|
||||
} catch (const runtime_error& e) {
|
||||
log_warning("Failed to encode message for patch message box command: %s", e.what());
|
||||
return;
|
||||
}
|
||||
w.put_u16(0);
|
||||
while (w.str().size() & 3) {
|
||||
w.put_u8(0);
|
||||
}
|
||||
c->channel.send(0x13, 0x00, w.str());
|
||||
}
|
||||
|
||||
void PatchServer::send_enter_directory(shared_ptr<Client> c, const string& dir) const {
|
||||
S_EnterDirectory_Patch_09 cmd = {{dir, 1}};
|
||||
c->channel.send(0x09, 0x00, cmd);
|
||||
}
|
||||
|
||||
void PatchServer::on_02(shared_ptr<Client> c, string& data) {
|
||||
check_size_v(data.size(), 0);
|
||||
c->channel.send(0x04, 0x00); // This requests the user's login information
|
||||
}
|
||||
|
||||
void PatchServer::change_to_directory(
|
||||
shared_ptr<Client> c,
|
||||
vector<string>& client_path_directories,
|
||||
const vector<string>& file_path_directories) const {
|
||||
// First, exit all leaf directories that don't match the desired path
|
||||
while (!client_path_directories.empty() &&
|
||||
((client_path_directories.size() > file_path_directories.size()) ||
|
||||
(client_path_directories.back() != file_path_directories[client_path_directories.size() - 1]))) {
|
||||
c->channel.send(0x0A, 0x00);
|
||||
client_path_directories.pop_back();
|
||||
}
|
||||
|
||||
// At this point, client_path_directories should be a prefix of
|
||||
// file_path_directories (or should match exactly)
|
||||
if (client_path_directories.size() > file_path_directories.size()) {
|
||||
throw logic_error("did not exit all necessary directories");
|
||||
}
|
||||
for (size_t x = 0; x < client_path_directories.size(); x++) {
|
||||
if (client_path_directories[x] != file_path_directories[x]) {
|
||||
throw logic_error("intermediate path is not a prefix of final path");
|
||||
}
|
||||
}
|
||||
|
||||
// Second, enter all necessary leaf directories
|
||||
while (client_path_directories.size() < file_path_directories.size()) {
|
||||
const string& dir = file_path_directories[client_path_directories.size()];
|
||||
this->send_enter_directory(c, dir);
|
||||
client_path_directories.emplace_back(dir);
|
||||
}
|
||||
}
|
||||
|
||||
void PatchServer::on_04(shared_ptr<Client> c, string& data) {
|
||||
const auto& cmd = check_size_t<C_Login_Patch_04>(data);
|
||||
|
||||
string username = cmd.username.decode();
|
||||
string password = cmd.password.decode();
|
||||
|
||||
// There are 3 cases here:
|
||||
// - No login information at all: just proceed without checking credentials
|
||||
// - Username: check that account exists if allow_unregistered_users is off
|
||||
// - Username and password: call verify_bb
|
||||
if (!username.empty() && !password.empty()) {
|
||||
try {
|
||||
this->config->account_index->from_bb_credentials(username, &password, false);
|
||||
|
||||
} catch (const AccountIndex::incorrect_password& e) {
|
||||
this->send_message_box(c, string_printf("Login failed: %s", e.what()));
|
||||
this->disconnect_client(c);
|
||||
return;
|
||||
|
||||
} catch (const AccountIndex::missing_account& e) {
|
||||
if (!this->config->allow_unregistered_users) {
|
||||
this->send_message_box(c, string_printf("Login failed: %s", e.what()));
|
||||
this->disconnect_client(c);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (!username.empty() && !this->config->allow_unregistered_users) {
|
||||
try {
|
||||
this->config->account_index->from_bb_credentials(username, nullptr, false);
|
||||
} catch (const AccountIndex::missing_account& e) {
|
||||
this->send_message_box(c, string_printf("Login failed: %s", e.what()));
|
||||
this->disconnect_client(c);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this->config->message.empty()) {
|
||||
this->send_message_box(c, this->config->message.c_str());
|
||||
}
|
||||
|
||||
const auto& index = this->config->patch_file_index;
|
||||
if (index.get()) {
|
||||
c->channel.send(0x0B, 0x00); // Start patch session; go to root directory
|
||||
|
||||
vector<string> path_directories;
|
||||
for (const auto& file : index->all_files()) {
|
||||
this->change_to_directory(c, path_directories, file->path_directories);
|
||||
|
||||
S_FileChecksumRequest_Patch_0C req = {c->patch_file_checksum_requests.size(), {file->name, 1}};
|
||||
c->channel.send(0x0C, 0x00, req);
|
||||
c->patch_file_checksum_requests.emplace_back(file);
|
||||
}
|
||||
this->change_to_directory(c, path_directories, {});
|
||||
|
||||
c->channel.send(0x0D, 0x00); // End of checksum requests
|
||||
|
||||
} else {
|
||||
// No patch index present: just do something that will satisfy the client
|
||||
// without actually checking or downloading any files
|
||||
this->send_enter_directory(c, ".");
|
||||
this->send_enter_directory(c, "data");
|
||||
this->send_enter_directory(c, "scene");
|
||||
c->channel.send(0x0A, 0x00);
|
||||
c->channel.send(0x0A, 0x00);
|
||||
c->channel.send(0x0A, 0x00);
|
||||
c->channel.send(0x12, 0x00);
|
||||
}
|
||||
}
|
||||
|
||||
void PatchServer::on_0F(shared_ptr<Client> c, string& data) {
|
||||
auto& cmd = check_size_t<C_FileInformation_Patch_0F>(data);
|
||||
auto& req = c->patch_file_checksum_requests.at(cmd.request_id);
|
||||
req.crc32 = cmd.checksum;
|
||||
req.size = cmd.size;
|
||||
req.response_received = true;
|
||||
}
|
||||
|
||||
void PatchServer::on_10(shared_ptr<Client> c, string&) {
|
||||
S_StartFileDownloads_Patch_11 start_cmd = {0, 0};
|
||||
for (const auto& req : c->patch_file_checksum_requests) {
|
||||
if (!req.response_received) {
|
||||
throw runtime_error("client did not respond to checksum request");
|
||||
}
|
||||
if (req.needs_update()) {
|
||||
c->log.info("File %s needs update (CRC: %08" PRIX32 "/%08" PRIX32 ", size: %" PRIu32 "/%" PRIu32 ")",
|
||||
req.file->name.c_str(), req.file->crc32, req.crc32, req.file->size, req.size);
|
||||
start_cmd.total_bytes += req.file->size;
|
||||
start_cmd.num_files++;
|
||||
} else {
|
||||
c->log.info("File %s is up to date", req.file->name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if (start_cmd.num_files) {
|
||||
c->channel.send(0x11, 0x00, start_cmd);
|
||||
vector<string> path_directories;
|
||||
for (const auto& req : c->patch_file_checksum_requests) {
|
||||
if (req.needs_update()) {
|
||||
this->change_to_directory(c, path_directories, req.file->path_directories);
|
||||
|
||||
S_OpenFile_Patch_06 open_cmd = {0, req.file->size, {req.file->name, 1}};
|
||||
c->channel.send(0x06, 0x00, open_cmd);
|
||||
|
||||
for (size_t x = 0; x < req.file->chunk_crcs.size(); x++) {
|
||||
auto data = req.file->load_data();
|
||||
size_t chunk_size = min<uint32_t>(req.file->size - (x * 0x4000), 0x4000);
|
||||
|
||||
vector<pair<const void*, size_t>> blocks;
|
||||
S_WriteFileHeader_Patch_07 cmd_header = {x, req.file->chunk_crcs[x], chunk_size};
|
||||
blocks.emplace_back(&cmd_header, sizeof(cmd_header));
|
||||
blocks.emplace_back(data->data() + (x * 0x4000), chunk_size);
|
||||
c->channel.send(0x07, 0x00, blocks);
|
||||
}
|
||||
|
||||
S_CloseCurrentFile_Patch_08 close_cmd = {0};
|
||||
c->channel.send(0x08, 0x00, close_cmd);
|
||||
}
|
||||
}
|
||||
this->change_to_directory(c, path_directories, {});
|
||||
}
|
||||
|
||||
c->channel.send(0x12, 0x00);
|
||||
}
|
||||
|
||||
void PatchServer::disconnect_client(shared_ptr<Client> c) {
|
||||
if (c->channel.virtual_network_id) {
|
||||
server_log.info("Client disconnected: C-%" PRIX64 " on N-%" PRIu64, c->id, c->channel.virtual_network_id);
|
||||
} else if (c->channel.bev) {
|
||||
server_log.info("Client disconnected: C-%" PRIX64, c->id);
|
||||
} else {
|
||||
server_log.info("Client C-%" PRIX64 " removed from patch server", c->id);
|
||||
}
|
||||
|
||||
this->channel_to_client.erase(&c->channel);
|
||||
c->channel.disconnect();
|
||||
|
||||
// We can't just let c be destroyed here, since disconnect_client can be
|
||||
// called from within the client's channel's receive handler. So, we instead
|
||||
// move it to another set, which we'll clear in an immediately-enqueued
|
||||
// callback after the current event. This will also call the client's
|
||||
// disconnect hooks (if any).
|
||||
this->clients_to_destroy.insert(std::move(c));
|
||||
this->enqueue_destroy_clients();
|
||||
}
|
||||
|
||||
void PatchServer::enqueue_destroy_clients() {
|
||||
auto tv = usecs_to_timeval(0);
|
||||
event_add(this->destroy_clients_ev.get(), &tv);
|
||||
}
|
||||
|
||||
void PatchServer::dispatch_destroy_clients(evutil_socket_t, short, void* ctx) {
|
||||
reinterpret_cast<PatchServer*>(ctx)->clients_to_destroy.clear();
|
||||
}
|
||||
|
||||
void PatchServer::dispatch_on_listen_accept(
|
||||
struct evconnlistener* listener, evutil_socket_t fd,
|
||||
struct sockaddr* address, int socklen, void* ctx) {
|
||||
reinterpret_cast<PatchServer*>(ctx)->on_listen_accept(listener, fd, address, socklen);
|
||||
}
|
||||
|
||||
void PatchServer::dispatch_on_listen_error(
|
||||
struct evconnlistener* listener, void* ctx) {
|
||||
reinterpret_cast<PatchServer*>(ctx)->on_listen_error(listener);
|
||||
}
|
||||
|
||||
void PatchServer::on_listen_accept(struct evconnlistener* listener, evutil_socket_t fd, struct sockaddr*, int) {
|
||||
struct sockaddr_storage remote_addr;
|
||||
get_socket_addresses(fd, nullptr, &remote_addr);
|
||||
if (this->config->banned_ipv4_ranges->check(remote_addr)) {
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
int listen_fd = evconnlistener_get_fd(listener);
|
||||
ListeningSocket* listening_socket;
|
||||
try {
|
||||
listening_socket = &this->listening_sockets.at(listen_fd);
|
||||
} catch (const out_of_range& e) {
|
||||
server_log.warning("Can\'t determine version for socket %d; disconnecting client", listen_fd);
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
struct bufferevent* bev = bufferevent_socket_new(this->base.get(), fd, BEV_OPT_CLOSE_ON_FREE | BEV_OPT_DEFER_CALLBACKS);
|
||||
auto c = make_shared<Client>(
|
||||
this->shared_from_this(),
|
||||
bev,
|
||||
listening_socket->version,
|
||||
this->config->idle_timeout_usecs,
|
||||
this->config->hide_data_from_logs);
|
||||
c->channel.on_command_received = PatchServer::on_client_input;
|
||||
c->channel.on_error = PatchServer::on_client_error;
|
||||
c->channel.context_obj = this;
|
||||
this->channel_to_client.emplace(&c->channel, c);
|
||||
|
||||
server_log.info("Patch client connected: U-%" PRIX64 " on fd %d via %d (%s)",
|
||||
c->id, fd, listen_fd, listening_socket->addr_str.c_str());
|
||||
|
||||
this->send_server_init(c);
|
||||
}
|
||||
|
||||
void PatchServer::on_listen_error(struct evconnlistener* listener) {
|
||||
int err = EVUTIL_SOCKET_ERROR();
|
||||
server_log.error("Failure on listening socket %d: %d (%s)",
|
||||
evconnlistener_get_fd(listener), err, evutil_socket_error_to_string(err));
|
||||
event_base_loopexit(this->base.get(), nullptr);
|
||||
}
|
||||
|
||||
void PatchServer::on_client_input(Channel& ch, uint16_t command, uint32_t, std::string& data) {
|
||||
PatchServer* server = reinterpret_cast<PatchServer*>(ch.context_obj);
|
||||
shared_ptr<Client> c = server->channel_to_client.at(&ch);
|
||||
|
||||
try {
|
||||
switch (command) {
|
||||
case 0x02:
|
||||
server->on_02(c, data);
|
||||
break;
|
||||
case 0x04:
|
||||
server->on_04(c, data);
|
||||
break;
|
||||
case 0x0F:
|
||||
server->on_0F(c, data);
|
||||
break;
|
||||
case 0x10:
|
||||
server->on_10(c, data);
|
||||
break;
|
||||
default:
|
||||
throw runtime_error("invalid command");
|
||||
}
|
||||
} catch (const exception& e) {
|
||||
server_log.warning("Error processing client command: %s", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void PatchServer::on_client_error(Channel& ch, short events) {
|
||||
PatchServer* server = reinterpret_cast<PatchServer*>(ch.context_obj);
|
||||
shared_ptr<Client> c = server->channel_to_client.at(&ch);
|
||||
|
||||
if (events & BEV_EVENT_ERROR) {
|
||||
int err = EVUTIL_SOCKET_ERROR();
|
||||
server_log.warning("Client caused error %d (%s)", err, evutil_socket_error_to_string(err));
|
||||
}
|
||||
if (events & (BEV_EVENT_EOF | BEV_EVENT_ERROR)) {
|
||||
server->disconnect_client(c);
|
||||
}
|
||||
}
|
||||
|
||||
PatchServer::PatchServer(shared_ptr<const Config> config)
|
||||
: config(config) {
|
||||
if (config->shared_base) {
|
||||
this->base = config->shared_base;
|
||||
this->base_is_shared = true;
|
||||
} else {
|
||||
this->base.reset(event_base_new(), event_base_free);
|
||||
this->base_is_shared = false;
|
||||
}
|
||||
this->destroy_clients_ev.reset(
|
||||
event_new(this->base.get(), -1, EV_TIMEOUT, &PatchServer::dispatch_destroy_clients, this), event_free);
|
||||
if (!this->base_is_shared) {
|
||||
this->th = thread(&PatchServer::thread_fn, this);
|
||||
}
|
||||
}
|
||||
|
||||
void PatchServer::schedule_stop() {
|
||||
if (!this->base_is_shared) {
|
||||
event_base_loopexit(this->base.get(), nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void PatchServer::wait_for_stop() {
|
||||
if (!this->base_is_shared) {
|
||||
this->th.join();
|
||||
}
|
||||
}
|
||||
|
||||
void PatchServer::listen(const std::string& addr_str, const string& socket_path, Version version) {
|
||||
int fd = ::listen(socket_path, 0, SOMAXCONN);
|
||||
server_log.info("Listening on Unix socket %s on fd %d as %s", socket_path.c_str(), fd, addr_str.c_str());
|
||||
this->add_socket(addr_str, fd, version);
|
||||
}
|
||||
|
||||
void PatchServer::listen(const std::string& addr_str, const string& addr, int port, Version version) {
|
||||
if (port == 0) {
|
||||
this->listen(addr_str, addr, version);
|
||||
} else {
|
||||
int fd = ::listen(addr, port, SOMAXCONN);
|
||||
string netloc_str = render_netloc(addr, port);
|
||||
server_log.info("Listening on TCP interface %s on fd %d as %s", netloc_str.c_str(), fd, addr_str.c_str());
|
||||
this->add_socket(addr_str, fd, version);
|
||||
}
|
||||
}
|
||||
|
||||
void PatchServer::listen(const std::string& addr_str, int port, Version version) {
|
||||
this->listen(addr_str, "", port, version);
|
||||
}
|
||||
|
||||
PatchServer::ListeningSocket::ListeningSocket(PatchServer* s, const std::string& addr_str, int fd, Version version)
|
||||
: addr_str(addr_str),
|
||||
fd(fd),
|
||||
version(version),
|
||||
listener(evconnlistener_new(s->base.get(), PatchServer::dispatch_on_listen_accept, s, LEV_OPT_REUSEABLE, 0, this->fd),
|
||||
evconnlistener_free) {
|
||||
evconnlistener_set_error_cb(this->listener.get(), PatchServer::dispatch_on_listen_error);
|
||||
}
|
||||
|
||||
void PatchServer::add_socket(const std::string& addr_str, int fd, Version version) {
|
||||
this->listening_sockets.emplace(piecewise_construct, forward_as_tuple(fd), forward_as_tuple(this, addr_str, fd, version));
|
||||
}
|
||||
|
||||
void PatchServer::thread_fn() {
|
||||
event_base_loop(this->base.get(), EVLOOP_NO_EXIT_ON_EMPTY);
|
||||
}
|
||||
|
||||
void PatchServer::set_config(std::shared_ptr<const Config> config) {
|
||||
if (this->base_is_shared) {
|
||||
this->config = config;
|
||||
} else {
|
||||
forward_to_event_thread(this->base, [s = this->shared_from_this(), config = std::move(config)]() {
|
||||
s->config = config;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+131
-131
@@ -1,131 +1,131 @@
|
||||
#pragma once
|
||||
|
||||
#include <event2/event.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#include "Account.hh"
|
||||
#include "Channel.hh"
|
||||
#include "IPV4RangeSet.hh"
|
||||
#include "PatchFileIndex.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
class PatchServer : public std::enable_shared_from_this<PatchServer> {
|
||||
public:
|
||||
struct Config {
|
||||
bool allow_unregistered_users;
|
||||
bool hide_data_from_logs;
|
||||
uint64_t idle_timeout_usecs;
|
||||
std::string message;
|
||||
std::shared_ptr<AccountIndex> account_index;
|
||||
std::shared_ptr<const PatchFileIndex> patch_file_index;
|
||||
std::shared_ptr<const IPV4RangeSet> banned_ipv4_ranges;
|
||||
std::shared_ptr<struct event_base> shared_base;
|
||||
};
|
||||
|
||||
PatchServer() = delete;
|
||||
explicit PatchServer(std::shared_ptr<const Config> config);
|
||||
PatchServer(const PatchServer&) = delete;
|
||||
PatchServer(PatchServer&&) = delete;
|
||||
PatchServer& operator=(const PatchServer&) = delete;
|
||||
PatchServer& operator=(PatchServer&&) = delete;
|
||||
virtual ~PatchServer() = default;
|
||||
|
||||
void schedule_stop();
|
||||
void wait_for_stop();
|
||||
|
||||
void listen(const std::string& addr_str, const std::string& socket_path, Version version);
|
||||
void listen(const std::string& addr_str, const std::string& addr, int port, Version version);
|
||||
void listen(const std::string& addr_str, int port, Version version);
|
||||
void add_socket(const std::string& addr_str, int fd, Version version);
|
||||
|
||||
void set_config(std::shared_ptr<const Config> config);
|
||||
|
||||
private:
|
||||
class Client : public std::enable_shared_from_this<Client> {
|
||||
public:
|
||||
std::weak_ptr<PatchServer> server;
|
||||
uint64_t id;
|
||||
PrefixedLogger log;
|
||||
|
||||
Channel channel;
|
||||
std::vector<PatchFileChecksumRequest> patch_file_checksum_requests;
|
||||
uint64_t idle_timeout_usecs;
|
||||
|
||||
std::unique_ptr<struct event, void (*)(struct event*)> idle_timeout_event;
|
||||
|
||||
Client(
|
||||
std::shared_ptr<PatchServer> server,
|
||||
struct bufferevent* bev,
|
||||
Version version,
|
||||
uint64_t idle_timeout_usecs,
|
||||
bool hide_data_from_logs);
|
||||
~Client() = default;
|
||||
|
||||
void reschedule_timeout_event();
|
||||
|
||||
inline Version version() const {
|
||||
return this->channel.version;
|
||||
}
|
||||
|
||||
static void dispatch_idle_timeout(evutil_socket_t, short, void* ctx);
|
||||
void idle_timeout();
|
||||
|
||||
const std::string& get_bb_username() const;
|
||||
void set_bb_username(const std::string& bb_username);
|
||||
};
|
||||
|
||||
struct ListeningSocket {
|
||||
std::string addr_str;
|
||||
int fd;
|
||||
Version version;
|
||||
std::unique_ptr<struct evconnlistener, void (*)(struct evconnlistener*)> listener;
|
||||
|
||||
ListeningSocket(PatchServer* s, const std::string& name, int fd, Version version);
|
||||
};
|
||||
|
||||
std::shared_ptr<struct event_base> base;
|
||||
bool base_is_shared;
|
||||
std::shared_ptr<const Config> config;
|
||||
|
||||
std::unordered_set<std::shared_ptr<Client>> clients_to_destroy;
|
||||
std::shared_ptr<struct event> destroy_clients_ev;
|
||||
|
||||
std::unordered_map<int, ListeningSocket> listening_sockets;
|
||||
std::unordered_map<Channel*, std::shared_ptr<Client>> channel_to_client;
|
||||
|
||||
std::thread th;
|
||||
|
||||
void send_server_init(std::shared_ptr<Client> c) const;
|
||||
void send_message_box(std::shared_ptr<Client> c, const std::string& text) const;
|
||||
void send_enter_directory(std::shared_ptr<Client> c, const std::string& dir) const;
|
||||
void change_to_directory(
|
||||
std::shared_ptr<Client> c,
|
||||
std::vector<std::string>& client_path_directories,
|
||||
const std::vector<std::string>& file_path_directories) const;
|
||||
void on_02(std::shared_ptr<Client> c, std::string& data);
|
||||
void on_04(std::shared_ptr<Client> c, std::string& data);
|
||||
void on_0F(std::shared_ptr<Client> c, std::string& data);
|
||||
void on_10(std::shared_ptr<Client> c, std::string& data);
|
||||
|
||||
void disconnect_client(std::shared_ptr<Client> c);
|
||||
|
||||
void enqueue_destroy_clients();
|
||||
static void dispatch_destroy_clients(evutil_socket_t, short, void* ctx);
|
||||
|
||||
static void dispatch_on_listen_accept(struct evconnlistener* listener,
|
||||
evutil_socket_t fd, struct sockaddr* address, int socklen, void* ctx);
|
||||
static void dispatch_on_listen_error(struct evconnlistener* listener, void* ctx);
|
||||
|
||||
void on_listen_accept(struct evconnlistener* listener, evutil_socket_t fd, struct sockaddr* address, int socklen);
|
||||
void on_listen_error(struct evconnlistener* listener);
|
||||
|
||||
static void on_client_input(Channel& ch, uint16_t command, uint32_t flag, std::string& data);
|
||||
static void on_client_error(Channel& ch, short events);
|
||||
|
||||
void thread_fn();
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <event2/event.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#include "Account.hh"
|
||||
#include "Channel.hh"
|
||||
#include "IPV4RangeSet.hh"
|
||||
#include "PatchFileIndex.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
class PatchServer : public std::enable_shared_from_this<PatchServer> {
|
||||
public:
|
||||
struct Config {
|
||||
bool allow_unregistered_users;
|
||||
bool hide_data_from_logs;
|
||||
uint64_t idle_timeout_usecs;
|
||||
std::string message;
|
||||
std::shared_ptr<AccountIndex> account_index;
|
||||
std::shared_ptr<const PatchFileIndex> patch_file_index;
|
||||
std::shared_ptr<const IPV4RangeSet> banned_ipv4_ranges;
|
||||
std::shared_ptr<struct event_base> shared_base;
|
||||
};
|
||||
|
||||
PatchServer() = delete;
|
||||
explicit PatchServer(std::shared_ptr<const Config> config);
|
||||
PatchServer(const PatchServer&) = delete;
|
||||
PatchServer(PatchServer&&) = delete;
|
||||
PatchServer& operator=(const PatchServer&) = delete;
|
||||
PatchServer& operator=(PatchServer&&) = delete;
|
||||
virtual ~PatchServer() = default;
|
||||
|
||||
void schedule_stop();
|
||||
void wait_for_stop();
|
||||
|
||||
void listen(const std::string& addr_str, const std::string& socket_path, Version version);
|
||||
void listen(const std::string& addr_str, const std::string& addr, int port, Version version);
|
||||
void listen(const std::string& addr_str, int port, Version version);
|
||||
void add_socket(const std::string& addr_str, int fd, Version version);
|
||||
|
||||
void set_config(std::shared_ptr<const Config> config);
|
||||
|
||||
private:
|
||||
class Client : public std::enable_shared_from_this<Client> {
|
||||
public:
|
||||
std::weak_ptr<PatchServer> server;
|
||||
uint64_t id;
|
||||
PrefixedLogger log;
|
||||
|
||||
Channel channel;
|
||||
std::vector<PatchFileChecksumRequest> patch_file_checksum_requests;
|
||||
uint64_t idle_timeout_usecs;
|
||||
|
||||
std::unique_ptr<struct event, void (*)(struct event*)> idle_timeout_event;
|
||||
|
||||
Client(
|
||||
std::shared_ptr<PatchServer> server,
|
||||
struct bufferevent* bev,
|
||||
Version version,
|
||||
uint64_t idle_timeout_usecs,
|
||||
bool hide_data_from_logs);
|
||||
~Client() = default;
|
||||
|
||||
void reschedule_timeout_event();
|
||||
|
||||
inline Version version() const {
|
||||
return this->channel.version;
|
||||
}
|
||||
|
||||
static void dispatch_idle_timeout(evutil_socket_t, short, void* ctx);
|
||||
void idle_timeout();
|
||||
|
||||
const std::string& get_bb_username() const;
|
||||
void set_bb_username(const std::string& bb_username);
|
||||
};
|
||||
|
||||
struct ListeningSocket {
|
||||
std::string addr_str;
|
||||
int fd;
|
||||
Version version;
|
||||
std::unique_ptr<struct evconnlistener, void (*)(struct evconnlistener*)> listener;
|
||||
|
||||
ListeningSocket(PatchServer* s, const std::string& name, int fd, Version version);
|
||||
};
|
||||
|
||||
std::shared_ptr<struct event_base> base;
|
||||
bool base_is_shared;
|
||||
std::shared_ptr<const Config> config;
|
||||
|
||||
std::unordered_set<std::shared_ptr<Client>> clients_to_destroy;
|
||||
std::shared_ptr<struct event> destroy_clients_ev;
|
||||
|
||||
std::unordered_map<int, ListeningSocket> listening_sockets;
|
||||
std::unordered_map<Channel*, std::shared_ptr<Client>> channel_to_client;
|
||||
|
||||
std::thread th;
|
||||
|
||||
void send_server_init(std::shared_ptr<Client> c) const;
|
||||
void send_message_box(std::shared_ptr<Client> c, const std::string& text) const;
|
||||
void send_enter_directory(std::shared_ptr<Client> c, const std::string& dir) const;
|
||||
void change_to_directory(
|
||||
std::shared_ptr<Client> c,
|
||||
std::vector<std::string>& client_path_directories,
|
||||
const std::vector<std::string>& file_path_directories) const;
|
||||
void on_02(std::shared_ptr<Client> c, std::string& data);
|
||||
void on_04(std::shared_ptr<Client> c, std::string& data);
|
||||
void on_0F(std::shared_ptr<Client> c, std::string& data);
|
||||
void on_10(std::shared_ptr<Client> c, std::string& data);
|
||||
|
||||
void disconnect_client(std::shared_ptr<Client> c);
|
||||
|
||||
void enqueue_destroy_clients();
|
||||
static void dispatch_destroy_clients(evutil_socket_t, short, void* ctx);
|
||||
|
||||
static void dispatch_on_listen_accept(struct evconnlistener* listener,
|
||||
evutil_socket_t fd, struct sockaddr* address, int socklen, void* ctx);
|
||||
static void dispatch_on_listen_error(struct evconnlistener* listener, void* ctx);
|
||||
|
||||
void on_listen_accept(struct evconnlistener* listener, evutil_socket_t fd, struct sockaddr* address, int socklen);
|
||||
void on_listen_error(struct evconnlistener* listener);
|
||||
|
||||
static void on_client_input(Channel& ch, uint16_t command, uint32_t flag, std::string& data);
|
||||
static void on_client_error(Channel& ch, short events);
|
||||
|
||||
void thread_fn();
|
||||
};
|
||||
|
||||
+119
-119
@@ -1,119 +1,119 @@
|
||||
#include "PlayerFilesManager.hh"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Hash.hh>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "FileContentsCache.hh"
|
||||
#include "ItemData.hh"
|
||||
#include "Loggers.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "PSOProtocol.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "Text.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
PlayerFilesManager::PlayerFilesManager(std::shared_ptr<struct event_base> base)
|
||||
: base(base),
|
||||
clear_expired_files_event(
|
||||
event_new(this->base.get(), -1, EV_TIMEOUT | EV_PERSIST, &PlayerFilesManager::clear_expired_files, this),
|
||||
event_free) {
|
||||
auto tv = usecs_to_timeval(30 * 1000 * 1000);
|
||||
event_add(this->clear_expired_files_event.get(), &tv);
|
||||
}
|
||||
|
||||
template <typename KeyT, typename ValueT>
|
||||
size_t erase_unused(std::unordered_map<KeyT, std::shared_ptr<ValueT>>& m) {
|
||||
size_t ret = 0;
|
||||
for (auto it = m.begin(); it != m.end();) {
|
||||
if (it->second.use_count() <= 1) {
|
||||
it = m.erase(it);
|
||||
ret++;
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<PSOBBBaseSystemFile> PlayerFilesManager::get_system(const std::string& filename) {
|
||||
try {
|
||||
return this->loaded_system_files.at(filename);
|
||||
} catch (const out_of_range&) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<PSOBBCharacterFile> PlayerFilesManager::get_character(const std::string& filename) {
|
||||
try {
|
||||
return this->loaded_character_files.at(filename);
|
||||
} catch (const out_of_range&) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<PSOBBGuildCardFile> PlayerFilesManager::get_guild_card(const std::string& filename) {
|
||||
try {
|
||||
return this->loaded_guild_card_files.at(filename);
|
||||
} catch (const out_of_range&) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<PlayerBank> PlayerFilesManager::get_bank(const std::string& filename) {
|
||||
try {
|
||||
return this->loaded_bank_files.at(filename);
|
||||
} catch (const out_of_range&) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerFilesManager::set_system(const std::string& filename, std::shared_ptr<PSOBBBaseSystemFile> file) {
|
||||
if (!this->loaded_system_files.emplace(filename, file).second) {
|
||||
throw runtime_error("Guild Card file already loaded: " + filename);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerFilesManager::set_character(const std::string& filename, std::shared_ptr<PSOBBCharacterFile> file) {
|
||||
if (!this->loaded_character_files.emplace(filename, file).second) {
|
||||
throw runtime_error("character file already loaded: " + filename);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerFilesManager::set_guild_card(const std::string& filename, std::shared_ptr<PSOBBGuildCardFile> file) {
|
||||
if (!this->loaded_guild_card_files.emplace(filename, file).second) {
|
||||
throw runtime_error("Guild Card file already loaded: " + filename);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerFilesManager::set_bank(const std::string& filename, std::shared_ptr<PlayerBank> file) {
|
||||
if (!this->loaded_bank_files.emplace(filename, file).second) {
|
||||
throw runtime_error("bank file already loaded: " + filename);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerFilesManager::clear_expired_files(evutil_socket_t, short, void* ctx) {
|
||||
auto* self = reinterpret_cast<PlayerFilesManager*>(ctx);
|
||||
size_t num_deleted = erase_unused(self->loaded_system_files);
|
||||
if (num_deleted) {
|
||||
player_data_log.info("Cleared %zu expired system file(s)", num_deleted);
|
||||
}
|
||||
num_deleted = erase_unused(self->loaded_character_files);
|
||||
if (num_deleted) {
|
||||
player_data_log.info("Cleared %zu expired character file(s)", num_deleted);
|
||||
}
|
||||
num_deleted = erase_unused(self->loaded_guild_card_files);
|
||||
if (num_deleted) {
|
||||
player_data_log.info("Cleared %zu expired Guild Card file(s)", num_deleted);
|
||||
}
|
||||
num_deleted = erase_unused(self->loaded_bank_files);
|
||||
if (num_deleted) {
|
||||
player_data_log.info("Cleared %zu expired bank file(s)", num_deleted);
|
||||
}
|
||||
}
|
||||
#include "PlayerFilesManager.hh"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Hash.hh>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "FileContentsCache.hh"
|
||||
#include "ItemData.hh"
|
||||
#include "Loggers.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "PSOProtocol.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "Text.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
PlayerFilesManager::PlayerFilesManager(std::shared_ptr<struct event_base> base)
|
||||
: base(base),
|
||||
clear_expired_files_event(
|
||||
event_new(this->base.get(), -1, EV_TIMEOUT | EV_PERSIST, &PlayerFilesManager::clear_expired_files, this),
|
||||
event_free) {
|
||||
auto tv = usecs_to_timeval(30 * 1000 * 1000);
|
||||
event_add(this->clear_expired_files_event.get(), &tv);
|
||||
}
|
||||
|
||||
template <typename KeyT, typename ValueT>
|
||||
size_t erase_unused(std::unordered_map<KeyT, std::shared_ptr<ValueT>>& m) {
|
||||
size_t ret = 0;
|
||||
for (auto it = m.begin(); it != m.end();) {
|
||||
if (it->second.use_count() <= 1) {
|
||||
it = m.erase(it);
|
||||
ret++;
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<PSOBBBaseSystemFile> PlayerFilesManager::get_system(const std::string& filename) {
|
||||
try {
|
||||
return this->loaded_system_files.at(filename);
|
||||
} catch (const out_of_range&) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<PSOBBCharacterFile> PlayerFilesManager::get_character(const std::string& filename) {
|
||||
try {
|
||||
return this->loaded_character_files.at(filename);
|
||||
} catch (const out_of_range&) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<PSOBBGuildCardFile> PlayerFilesManager::get_guild_card(const std::string& filename) {
|
||||
try {
|
||||
return this->loaded_guild_card_files.at(filename);
|
||||
} catch (const out_of_range&) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<PlayerBank200> PlayerFilesManager::get_bank(const std::string& filename) {
|
||||
try {
|
||||
return this->loaded_bank_files.at(filename);
|
||||
} catch (const out_of_range&) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerFilesManager::set_system(const std::string& filename, std::shared_ptr<PSOBBBaseSystemFile> file) {
|
||||
if (!this->loaded_system_files.emplace(filename, file).second) {
|
||||
throw runtime_error("Guild Card file already loaded: " + filename);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerFilesManager::set_character(const std::string& filename, std::shared_ptr<PSOBBCharacterFile> file) {
|
||||
if (!this->loaded_character_files.emplace(filename, file).second) {
|
||||
throw runtime_error("character file already loaded: " + filename);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerFilesManager::set_guild_card(const std::string& filename, std::shared_ptr<PSOBBGuildCardFile> file) {
|
||||
if (!this->loaded_guild_card_files.emplace(filename, file).second) {
|
||||
throw runtime_error("Guild Card file already loaded: " + filename);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerFilesManager::set_bank(const std::string& filename, std::shared_ptr<PlayerBank200> file) {
|
||||
if (!this->loaded_bank_files.emplace(filename, file).second) {
|
||||
throw runtime_error("bank file already loaded: " + filename);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerFilesManager::clear_expired_files(evutil_socket_t, short, void* ctx) {
|
||||
auto* self = reinterpret_cast<PlayerFilesManager*>(ctx);
|
||||
size_t num_deleted = erase_unused(self->loaded_system_files);
|
||||
if (num_deleted) {
|
||||
player_data_log.info("Cleared %zu expired system file(s)", num_deleted);
|
||||
}
|
||||
num_deleted = erase_unused(self->loaded_character_files);
|
||||
if (num_deleted) {
|
||||
player_data_log.info("Cleared %zu expired character file(s)", num_deleted);
|
||||
}
|
||||
num_deleted = erase_unused(self->loaded_guild_card_files);
|
||||
if (num_deleted) {
|
||||
player_data_log.info("Cleared %zu expired Guild Card file(s)", num_deleted);
|
||||
}
|
||||
num_deleted = erase_unused(self->loaded_bank_files);
|
||||
if (num_deleted) {
|
||||
player_data_log.info("Cleared %zu expired bank file(s)", num_deleted);
|
||||
}
|
||||
}
|
||||
|
||||
+47
-47
@@ -1,47 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include <event2/event.h>
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <array>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "Episode3/DataIndexes.hh"
|
||||
#include "ItemCreator.hh"
|
||||
#include "ItemNameIndex.hh"
|
||||
#include "LevelTable.hh"
|
||||
#include "PlayerSubordinates.hh"
|
||||
#include "SaveFileFormats.hh"
|
||||
#include "Text.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
class PlayerFilesManager {
|
||||
public:
|
||||
explicit PlayerFilesManager(std::shared_ptr<struct event_base> base);
|
||||
~PlayerFilesManager() = default;
|
||||
|
||||
std::shared_ptr<PSOBBBaseSystemFile> get_system(const std::string& filename);
|
||||
std::shared_ptr<PSOBBCharacterFile> get_character(const std::string& filename);
|
||||
std::shared_ptr<PSOBBGuildCardFile> get_guild_card(const std::string& filename);
|
||||
std::shared_ptr<PlayerBank> get_bank(const std::string& filename);
|
||||
|
||||
void set_system(const std::string& filename, std::shared_ptr<PSOBBBaseSystemFile> file);
|
||||
void set_character(const std::string& filename, std::shared_ptr<PSOBBCharacterFile> file);
|
||||
void set_guild_card(const std::string& filename, std::shared_ptr<PSOBBGuildCardFile> file);
|
||||
void set_bank(const std::string& filename, std::shared_ptr<PlayerBank> file);
|
||||
|
||||
private:
|
||||
std::shared_ptr<struct event_base> base;
|
||||
std::unique_ptr<struct event, void (*)(struct event*)> clear_expired_files_event;
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<PSOBBBaseSystemFile>> loaded_system_files;
|
||||
std::unordered_map<std::string, std::shared_ptr<PSOBBCharacterFile>> loaded_character_files;
|
||||
std::unordered_map<std::string, std::shared_ptr<PSOBBGuildCardFile>> loaded_guild_card_files;
|
||||
std::unordered_map<std::string, std::shared_ptr<PlayerBank>> loaded_bank_files;
|
||||
|
||||
static void clear_expired_files(evutil_socket_t fd, short events, void* ctx);
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <event2/event.h>
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <array>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "Episode3/DataIndexes.hh"
|
||||
#include "ItemCreator.hh"
|
||||
#include "ItemNameIndex.hh"
|
||||
#include "LevelTable.hh"
|
||||
#include "PlayerSubordinates.hh"
|
||||
#include "SaveFileFormats.hh"
|
||||
#include "Text.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
class PlayerFilesManager {
|
||||
public:
|
||||
explicit PlayerFilesManager(std::shared_ptr<struct event_base> base);
|
||||
~PlayerFilesManager() = default;
|
||||
|
||||
std::shared_ptr<PSOBBBaseSystemFile> get_system(const std::string& filename);
|
||||
std::shared_ptr<PSOBBCharacterFile> get_character(const std::string& filename);
|
||||
std::shared_ptr<PSOBBGuildCardFile> get_guild_card(const std::string& filename);
|
||||
std::shared_ptr<PlayerBank200> get_bank(const std::string& filename);
|
||||
|
||||
void set_system(const std::string& filename, std::shared_ptr<PSOBBBaseSystemFile> file);
|
||||
void set_character(const std::string& filename, std::shared_ptr<PSOBBCharacterFile> file);
|
||||
void set_guild_card(const std::string& filename, std::shared_ptr<PSOBBGuildCardFile> file);
|
||||
void set_bank(const std::string& filename, std::shared_ptr<PlayerBank200> file);
|
||||
|
||||
private:
|
||||
std::shared_ptr<struct event_base> base;
|
||||
std::unique_ptr<struct event, void (*)(struct event*)> clear_expired_files_event;
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<PSOBBBaseSystemFile>> loaded_system_files;
|
||||
std::unordered_map<std::string, std::shared_ptr<PSOBBCharacterFile>> loaded_character_files;
|
||||
std::unordered_map<std::string, std::shared_ptr<PSOBBGuildCardFile>> loaded_guild_card_files;
|
||||
std::unordered_map<std::string, std::shared_ptr<PlayerBank200>> loaded_bank_files;
|
||||
|
||||
static void clear_expired_files(evutil_socket_t fd, short events, void* ctx);
|
||||
};
|
||||
|
||||
+33
-13
@@ -3,6 +3,7 @@
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/JSON.hh>
|
||||
@@ -46,12 +47,14 @@ class ItemParameterTable;
|
||||
|
||||
template <bool IsBigEndian>
|
||||
struct PlayerInventoryItemT {
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
|
||||
/* 00 */ uint8_t present = 0;
|
||||
/* 01 */ uint8_t unknown_a1 = 0;
|
||||
// See note above about these fields
|
||||
/* 02 */ uint8_t extension_data1 = 0;
|
||||
/* 03 */ uint8_t extension_data2 = 0;
|
||||
/* 04 */ le_uint32_t flags = 0; // 8 = equipped
|
||||
/* 04 */ U32T flags = 0; // 8 = equipped
|
||||
/* 08 */ ItemData data;
|
||||
/* 1C */
|
||||
|
||||
@@ -73,6 +76,7 @@ struct PlayerInventoryItemT {
|
||||
ret.extension_data2 = this->extension_data2;
|
||||
ret.flags = this->flags.load();
|
||||
ret.data = this->data;
|
||||
ret.data.id.store_raw(bswap32(ret.data.id.load_raw()));
|
||||
return ret;
|
||||
}
|
||||
} __packed__;
|
||||
@@ -230,6 +234,7 @@ struct PlayerInventoryT {
|
||||
}
|
||||
|
||||
size_t remove_all_items_of_type(uint8_t data1_0, int16_t data1_1 = -1) {
|
||||
|
||||
size_t write_offset = 0;
|
||||
for (size_t read_offset = 0; read_offset < this->num_items; read_offset++) {
|
||||
bool should_delete = ((this->items[read_offset].data.data1[0] == data1_0) &&
|
||||
@@ -297,14 +302,14 @@ using PlayerInventoryBE = PlayerInventoryT<true>;
|
||||
check_struct_size(PlayerInventory, 0x34C);
|
||||
check_struct_size(PlayerInventoryBE, 0x34C);
|
||||
|
||||
template <bool IsBigEndian>
|
||||
template <size_t SlotCount, bool IsBigEndian>
|
||||
struct PlayerBankT {
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
|
||||
/* 0000 */ U32T num_items = 0;
|
||||
/* 0004 */ U32T meseta = 0;
|
||||
/* 0008 */ parray<PlayerBankItemT<IsBigEndian>, 200> items;
|
||||
/* 12C8 */
|
||||
/* 0008 */ parray<PlayerBankItemT<IsBigEndian>, SlotCount> items;
|
||||
/* 05A8 for 60 items (v1/v2), 12C8 for 200 items (v3/v4) */
|
||||
|
||||
void add_item(const ItemData& item, const ItemData::StackLimits& limits) {
|
||||
uint32_t primary_identifier = item.primary_identifier();
|
||||
@@ -337,7 +342,7 @@ struct PlayerBankT {
|
||||
}
|
||||
}
|
||||
|
||||
if (this->num_items >= 200) {
|
||||
if (this->num_items >= SlotCount) {
|
||||
throw std::runtime_error("no free space in bank");
|
||||
}
|
||||
auto& last_item = this->items[this->num_items];
|
||||
@@ -391,17 +396,32 @@ struct PlayerBankT {
|
||||
}
|
||||
}
|
||||
|
||||
operator PlayerBankT<!IsBigEndian>() const {
|
||||
PlayerBankT<!IsBigEndian> ret;
|
||||
ret.num_items = this->num_items.load();
|
||||
ret.meseta = this->meseta.load();
|
||||
void decode_from_client(Version v) {
|
||||
for (size_t z = 0; z < this->items.size(); z++) {
|
||||
this->items[z].data.decode_for_version(v);
|
||||
}
|
||||
}
|
||||
|
||||
void encode_for_client(Version v) {
|
||||
for (size_t z = 0; z < this->items.size(); z++) {
|
||||
this->items[z].data.encode_for_version(v, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
template <size_t DestSlotCount, bool DestIsBigEndian>
|
||||
operator PlayerBankT<DestSlotCount, DestIsBigEndian>() const {
|
||||
PlayerBankT<DestSlotCount, DestIsBigEndian> ret;
|
||||
ret.num_items = std::min<size_t>(ret.items.size(), this->num_items.load());
|
||||
ret.meseta = this->meseta.load();
|
||||
for (size_t z = 0; z < std::min<size_t>(ret.items.size(), this->items.size()); z++) {
|
||||
ret.items[z] = this->items[z];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
} __packed__;
|
||||
using PlayerBank = PlayerBankT<false>;
|
||||
using PlayerBankBE = PlayerBankT<true>;
|
||||
check_struct_size(PlayerBank, 0x12C8);
|
||||
check_struct_size(PlayerBankBE, 0x12C8);
|
||||
using PlayerBank60 = PlayerBankT<60, false>;
|
||||
using PlayerBank200 = PlayerBankT<200, false>;
|
||||
using PlayerBank200BE = PlayerBankT<200, true>;
|
||||
check_struct_size(PlayerBank60, 0x05A8);
|
||||
check_struct_size(PlayerBank200, 0x12C8);
|
||||
check_struct_size(PlayerBank200BE, 0x12C8);
|
||||
|
||||
@@ -176,8 +176,8 @@ void XBNetworkLocation::clear() {
|
||||
this->external_ipv4_address = 0;
|
||||
this->port = 0;
|
||||
this->mac_address.clear(0);
|
||||
this->unknown_a1 = 0;
|
||||
this->unknown_a2 = 0;
|
||||
this->sg_ip_address = 0;
|
||||
this->spi = 0;
|
||||
this->account_id = 0;
|
||||
this->unknown_a3.clear(0);
|
||||
}
|
||||
|
||||
+36
-19
@@ -359,24 +359,41 @@ struct GuildCardPC {
|
||||
operator GuildCardBB() const;
|
||||
} __packed_ws__(GuildCardPC, 0xF0);
|
||||
|
||||
template <bool IsBigEndian>
|
||||
// 0000 | 62 00 AC 00 06 2A 00 00 00 00 01 00 90 96 66 8C | b * f
|
||||
// 0010 | 31 31 31 31 00 00 00 00 00 00 00 00 00 00 00 00 | 1111
|
||||
// 0020 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
|
||||
// 0030 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
|
||||
// 0040 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
|
||||
// 0050 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
|
||||
// 0060 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
|
||||
// 0070 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
|
||||
// 0080 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
|
||||
// 0090 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
|
||||
// 00A0 | 00 00 00 00 00 00 00 00 01 00 06 00 |
|
||||
|
||||
template <bool IsBigEndian, size_t DescriptionLength>
|
||||
struct GuildCardGCT {
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
|
||||
/* 00 */ U32T player_tag = 0x00010000;
|
||||
/* 04 */ U32T guild_card_number = 0;
|
||||
/* 08 */ pstring<TextEncoding::ASCII, 0x18> name;
|
||||
/* 20 */ pstring<TextEncoding::MARKED, 0x6C> description;
|
||||
/* 8C */ uint8_t present = 0;
|
||||
/* 8D */ uint8_t language = 0;
|
||||
/* 8E */ uint8_t section_id = 0;
|
||||
/* 8F */ uint8_t char_class = 0;
|
||||
/* 90 */
|
||||
/* NTE:Final */
|
||||
/* 00:00 */ U32T player_tag = 0x00010000;
|
||||
/* 04:04 */ U32T guild_card_number = 0;
|
||||
/* 08:08 */ pstring<TextEncoding::ASCII, 0x18> name;
|
||||
/* 20:20 */ pstring<TextEncoding::MARKED, DescriptionLength> description;
|
||||
/* 8C:8C */ uint8_t present = 0;
|
||||
/* 8D:8D */ uint8_t language = 0;
|
||||
/* 8E:8E */ uint8_t section_id = 0;
|
||||
/* 8F:8F */ uint8_t char_class = 0;
|
||||
/* 90:90 */
|
||||
|
||||
operator GuildCardBB() const;
|
||||
} __packed__;
|
||||
using GuildCardGC = GuildCardGCT<false>;
|
||||
using GuildCardGCBE = GuildCardGCT<true>;
|
||||
using GuildCardGCNTE = GuildCardGCT<false, 0x80>;
|
||||
using GuildCardGCNTEBE = GuildCardGCT<true, 0x80>;
|
||||
using GuildCardGC = GuildCardGCT<false, 0x6C>;
|
||||
using GuildCardGCBE = GuildCardGCT<true, 0x6C>;
|
||||
check_struct_size(GuildCardGCNTE, 0xA4);
|
||||
check_struct_size(GuildCardGCNTEBE, 0xA4);
|
||||
check_struct_size(GuildCardGC, 0x90);
|
||||
check_struct_size(GuildCardGCBE, 0x90);
|
||||
|
||||
@@ -412,9 +429,9 @@ struct GuildCardBB {
|
||||
operator GuildCardDCNTE() const;
|
||||
operator GuildCardDC() const;
|
||||
operator GuildCardPC() const;
|
||||
template <bool IsBigEndian>
|
||||
operator GuildCardGCT<IsBigEndian>() const {
|
||||
GuildCardGCT<IsBigEndian> ret;
|
||||
template <bool IsBigEndian, size_t DescriptionLength>
|
||||
operator GuildCardGCT<IsBigEndian, DescriptionLength>() const {
|
||||
GuildCardGCT<IsBigEndian, DescriptionLength> ret;
|
||||
ret.player_tag = 0x00010000;
|
||||
ret.guild_card_number = this->guild_card_number.load();
|
||||
ret.name.encode(this->name.decode(this->language), this->language);
|
||||
@@ -428,8 +445,8 @@ struct GuildCardBB {
|
||||
operator GuildCardXB() const;
|
||||
} __packed_ws__(GuildCardBB, 0x108);
|
||||
|
||||
template <bool IsBigEndian>
|
||||
GuildCardGCT<IsBigEndian>::operator GuildCardBB() const {
|
||||
template <bool IsBigEndian, size_t DescriptionLength>
|
||||
GuildCardGCT<IsBigEndian, DescriptionLength>::operator GuildCardBB() const {
|
||||
GuildCardBB ret;
|
||||
ret.guild_card_number = this->guild_card_number.load();
|
||||
ret.name.encode(this->name.decode(this->language), this->language);
|
||||
@@ -471,8 +488,8 @@ struct XBNetworkLocation {
|
||||
/* 04 */ le_uint32_t external_ipv4_address = 0x23232323;
|
||||
/* 08 */ le_uint16_t port = 9500;
|
||||
/* 0A */ parray<uint8_t, 6> mac_address = 0x77;
|
||||
/* 10 */ le_uint32_t unknown_a1;
|
||||
/* 14 */ le_uint32_t unknown_a2;
|
||||
/* 10 */ le_uint32_t sg_ip_address = 0x0B0B0B0B;
|
||||
/* 14 */ le_uint32_t spi = 0xCCCCCCCC;
|
||||
/* 18 */ le_uint64_t account_id = 0xFFFFFFFFFFFFFFFF;
|
||||
/* 20 */ parray<le_uint32_t, 4> unknown_a3;
|
||||
/* 30 */
|
||||
|
||||
+2376
-2379
File diff suppressed because it is too large
Load Diff
+15
-15
@@ -1,15 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ProxyServer.hh"
|
||||
#include "ServerState.hh"
|
||||
|
||||
void on_proxy_command(
|
||||
std::shared_ptr<ProxyServer::LinkedSession> ses,
|
||||
bool from_server,
|
||||
uint16_t command,
|
||||
uint32_t flag,
|
||||
std::string& data);
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ProxyServer.hh"
|
||||
#include "ServerState.hh"
|
||||
|
||||
void on_proxy_command(
|
||||
std::shared_ptr<ProxyServer::LinkedSession> ses,
|
||||
bool from_server,
|
||||
uint16_t command,
|
||||
uint32_t flag,
|
||||
std::string& data);
|
||||
|
||||
+1029
-1029
File diff suppressed because it is too large
Load Diff
+307
-307
@@ -1,307 +1,307 @@
|
||||
#pragma once
|
||||
|
||||
#include <event2/event.h>
|
||||
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#include "PSOEncryption.hh"
|
||||
#include "PSOProtocol.hh"
|
||||
#include "ServerState.hh"
|
||||
|
||||
class ProxyServer : public std::enable_shared_from_this<ProxyServer> {
|
||||
public:
|
||||
ProxyServer() = delete;
|
||||
ProxyServer(const ProxyServer&) = delete;
|
||||
ProxyServer(ProxyServer&&) = delete;
|
||||
ProxyServer(
|
||||
std::shared_ptr<struct event_base> base,
|
||||
std::shared_ptr<ServerState> state);
|
||||
virtual ~ProxyServer() = default;
|
||||
|
||||
void listen(const std::string& addr, uint16_t port, Version version, const struct sockaddr_storage* default_destination = nullptr);
|
||||
|
||||
void connect_virtual_client(struct bufferevent* bev, uint64_t virtual_network_id, uint16_t server_port);
|
||||
|
||||
struct LinkedSession : std::enable_shared_from_this<LinkedSession> {
|
||||
std::weak_ptr<ProxyServer> server;
|
||||
uint64_t id;
|
||||
PrefixedLogger log;
|
||||
|
||||
std::unique_ptr<struct event, void (*)(struct event*)> timeout_event;
|
||||
|
||||
std::shared_ptr<Login> login;
|
||||
|
||||
Channel client_channel;
|
||||
Channel server_channel;
|
||||
uint16_t local_port;
|
||||
struct sockaddr_storage next_destination;
|
||||
|
||||
enum class DisconnectAction {
|
||||
LONG_TIMEOUT = 0,
|
||||
MEDIUM_TIMEOUT,
|
||||
SHORT_TIMEOUT,
|
||||
CLOSE_IMMEDIATELY,
|
||||
};
|
||||
DisconnectAction disconnect_action;
|
||||
|
||||
uint8_t prev_server_command_bytes[6];
|
||||
uint32_t remote_ip_crc;
|
||||
bool enable_remote_ip_crc_patch;
|
||||
|
||||
uint32_t sub_version;
|
||||
std::string character_name;
|
||||
std::string hardware_id; // Only used for DC sessions
|
||||
std::string login_command_bb;
|
||||
XBNetworkLocation xb_netloc;
|
||||
parray<le_uint32_t, 3> xb_9E_unknown_a1a;
|
||||
|
||||
uint32_t challenge_rank_color_override;
|
||||
std::string challenge_rank_title_override;
|
||||
int64_t remote_guild_card_number;
|
||||
parray<uint8_t, 0x20> remote_client_config_data;
|
||||
Client::Config config;
|
||||
// A null handler in here means to forward the response to the remote server
|
||||
std::deque<std::function<void(uint32_t return_value, uint32_t checksum)>> function_call_return_handler_queue;
|
||||
RecentSwitchFlags recent_switch_flags; // used for switch assist
|
||||
ItemData next_drop_item;
|
||||
uint32_t next_item_id;
|
||||
|
||||
enum class DropMode {
|
||||
DISABLED = 0,
|
||||
PASSTHROUGH,
|
||||
INTERCEPT,
|
||||
};
|
||||
DropMode drop_mode;
|
||||
std::shared_ptr<std::string> quest_dat_data;
|
||||
std::shared_ptr<ItemCreator> item_creator;
|
||||
std::shared_ptr<Map> map;
|
||||
|
||||
struct LobbyPlayer {
|
||||
uint32_t guild_card_number = 0;
|
||||
uint64_t xb_user_id = 0;
|
||||
std::string name;
|
||||
uint8_t language = 0;
|
||||
uint8_t section_id = 0;
|
||||
uint8_t char_class = 0;
|
||||
};
|
||||
std::vector<LobbyPlayer> lobby_players;
|
||||
size_t lobby_client_id;
|
||||
size_t leader_client_id;
|
||||
uint16_t floor;
|
||||
float x;
|
||||
float z;
|
||||
bool is_in_game;
|
||||
bool is_in_quest;
|
||||
uint8_t lobby_event;
|
||||
uint8_t lobby_difficulty;
|
||||
uint8_t lobby_section_id;
|
||||
GameMode lobby_mode;
|
||||
Episode lobby_episode;
|
||||
uint32_t lobby_random_seed;
|
||||
uint64_t client_ping_start_time = 0;
|
||||
uint64_t server_ping_start_time = 0;
|
||||
|
||||
std::shared_ptr<PSOBBMultiKeyDetectorEncryption> detector_crypt;
|
||||
|
||||
struct SavingFile {
|
||||
std::string basename;
|
||||
std::string output_filename;
|
||||
bool is_download;
|
||||
size_t remaining_bytes;
|
||||
std::deque<std::string> blocks;
|
||||
|
||||
SavingFile(
|
||||
const std::string& basename,
|
||||
const std::string& output_filename,
|
||||
size_t remaining_bytes,
|
||||
bool is_download);
|
||||
};
|
||||
std::unordered_map<std::string, SavingFile> saving_files;
|
||||
|
||||
// TODO: This first constructor should be private
|
||||
LinkedSession(
|
||||
std::shared_ptr<ProxyServer> server,
|
||||
uint64_t id,
|
||||
uint16_t local_port,
|
||||
Version version);
|
||||
LinkedSession(
|
||||
std::shared_ptr<ProxyServer> server,
|
||||
uint16_t local_port,
|
||||
Version version,
|
||||
std::shared_ptr<Login> login,
|
||||
const Client::Config& config);
|
||||
LinkedSession(
|
||||
std::shared_ptr<ProxyServer> server,
|
||||
uint16_t local_port,
|
||||
Version version,
|
||||
std::shared_ptr<Login> login,
|
||||
const struct sockaddr_storage& next_destination);
|
||||
LinkedSession(
|
||||
std::shared_ptr<ProxyServer> server,
|
||||
uint64_t id,
|
||||
uint16_t local_port,
|
||||
Version version,
|
||||
const struct sockaddr_storage& next_destination);
|
||||
|
||||
std::shared_ptr<ProxyServer> require_server() const;
|
||||
std::shared_ptr<ServerState> require_server_state() const;
|
||||
|
||||
inline Version version() const {
|
||||
return this->client_channel.version;
|
||||
}
|
||||
inline uint8_t language() const {
|
||||
return this->client_channel.language;
|
||||
}
|
||||
void set_version(Version v);
|
||||
|
||||
void resume(
|
||||
Channel&& client_channel,
|
||||
std::shared_ptr<PSOBBMultiKeyDetectorEncryption> detector_crypt,
|
||||
uint32_t sub_version,
|
||||
const std::string& character_name,
|
||||
const std::string& hardware_id,
|
||||
const XBNetworkLocation& xb_netloc,
|
||||
const parray<le_uint32_t, 3>& xb_9E_unknown_a1a);
|
||||
void resume(
|
||||
Channel&& client_channel,
|
||||
std::shared_ptr<PSOBBMultiKeyDetectorEncryption> detector_crypt,
|
||||
std::string&& login_command_bb);
|
||||
void resume(Channel&& client_channel);
|
||||
void resume_inner(
|
||||
Channel&& client_channel,
|
||||
std::shared_ptr<PSOBBMultiKeyDetectorEncryption> detector_crypt);
|
||||
void connect();
|
||||
|
||||
static uint64_t timeout_for_disconnect_action(DisconnectAction action);
|
||||
static void dispatch_on_timeout(evutil_socket_t fd, short what, void* ctx);
|
||||
static void on_input(Channel& ch, uint16_t, uint32_t, std::string& msg);
|
||||
static void on_error(Channel& ch, short events);
|
||||
void on_timeout();
|
||||
|
||||
void update_channel_names();
|
||||
|
||||
void clear_lobby_players(size_t num_slots);
|
||||
|
||||
void set_drop_mode(DropMode new_mode);
|
||||
|
||||
void send_to_game_server(const char* error_message = nullptr);
|
||||
void disconnect();
|
||||
bool is_connected() const;
|
||||
};
|
||||
|
||||
std::shared_ptr<LinkedSession> get_session() const;
|
||||
std::shared_ptr<LinkedSession> get_session_by_name(const std::string& name) const;
|
||||
const std::unordered_map<uint64_t, std::shared_ptr<LinkedSession>>& all_sessions() const;
|
||||
|
||||
std::shared_ptr<LinkedSession> create_logged_in_session(
|
||||
std::shared_ptr<Login> login,
|
||||
uint16_t local_port,
|
||||
Version version,
|
||||
const Client::Config& config);
|
||||
void delete_session(uint64_t id);
|
||||
|
||||
size_t num_sessions() const;
|
||||
|
||||
size_t delete_disconnected_sessions();
|
||||
|
||||
private:
|
||||
struct ListeningSocket {
|
||||
ProxyServer* server;
|
||||
|
||||
PrefixedLogger log;
|
||||
uint16_t port;
|
||||
scoped_fd fd;
|
||||
std::unique_ptr<struct evconnlistener, void (*)(struct evconnlistener*)> listener;
|
||||
Version version;
|
||||
struct sockaddr_storage default_destination;
|
||||
|
||||
ListeningSocket(
|
||||
ProxyServer* server,
|
||||
const std::string& addr,
|
||||
uint16_t port,
|
||||
Version version,
|
||||
const struct sockaddr_storage* default_destination);
|
||||
|
||||
static void dispatch_on_listen_accept(struct evconnlistener* listener,
|
||||
evutil_socket_t fd, struct sockaddr* address, int socklen, void* ctx);
|
||||
static void dispatch_on_listen_error(struct evconnlistener* listener, void* ctx);
|
||||
void on_listen_accept(int fd);
|
||||
void on_listen_error();
|
||||
};
|
||||
|
||||
struct UnlinkedSession {
|
||||
std::weak_ptr<ProxyServer> server;
|
||||
uint64_t id;
|
||||
|
||||
PrefixedLogger log;
|
||||
Channel channel;
|
||||
uint16_t local_port;
|
||||
struct sockaddr_storage next_destination;
|
||||
|
||||
std::shared_ptr<PSOBBMultiKeyDetectorEncryption> detector_crypt;
|
||||
|
||||
// Temporary state used just before resuming a LinkedSession. These aren't
|
||||
// just local variables inside on_input because XB requires two commands to
|
||||
// get started (9E and 9F), so we need to store this state somewhere between
|
||||
// those commands.
|
||||
std::shared_ptr<Login> login;
|
||||
uint32_t sub_version = 0;
|
||||
std::string character_name;
|
||||
Client::Config config;
|
||||
std::string login_command_bb;
|
||||
std::string hardware_id;
|
||||
XBNetworkLocation xb_netloc;
|
||||
parray<le_uint32_t, 3> xb_9E_unknown_a1a;
|
||||
|
||||
UnlinkedSession(
|
||||
std::shared_ptr<ProxyServer> server,
|
||||
uint64_t id,
|
||||
struct bufferevent* bev,
|
||||
uint64_t virtual_network_id,
|
||||
uint16_t port,
|
||||
Version version);
|
||||
|
||||
std::shared_ptr<ProxyServer> require_server() const;
|
||||
std::shared_ptr<ServerState> require_server_state() const;
|
||||
|
||||
inline Version version() const {
|
||||
return this->channel.version;
|
||||
}
|
||||
|
||||
void receive_and_process_commands();
|
||||
|
||||
static void on_input(Channel& ch, uint16_t command, uint32_t flag, std::string& msg);
|
||||
static void on_error(Channel& ch, short events);
|
||||
};
|
||||
|
||||
std::shared_ptr<struct event_base> base;
|
||||
std::shared_ptr<struct event> destroy_sessions_ev;
|
||||
std::shared_ptr<ServerState> state;
|
||||
std::map<int, std::shared_ptr<ListeningSocket>> listeners;
|
||||
std::unordered_map<uint64_t, std::shared_ptr<UnlinkedSession>> id_to_unlinked_session;
|
||||
std::unordered_set<std::shared_ptr<UnlinkedSession>> unlinked_sessions_to_destroy;
|
||||
std::unordered_map<uint64_t, std::shared_ptr<LinkedSession>> id_to_linked_session;
|
||||
uint64_t next_unlinked_session_id;
|
||||
uint64_t next_logged_out_session_id;
|
||||
|
||||
static void dispatch_destroy_sessions(evutil_socket_t, short, void* ctx);
|
||||
void destroy_sessions();
|
||||
|
||||
void on_client_connect(
|
||||
struct bufferevent* bev,
|
||||
uint64_t virtual_network_id,
|
||||
uint16_t listen_port,
|
||||
Version version,
|
||||
const struct sockaddr_storage* default_destination);
|
||||
|
||||
static constexpr uint64_t MIN_UNLINKED_SESSION_ID = 0xC000000000000000;
|
||||
static constexpr uint64_t MIN_LINKED_LOGGED_OUT_SESSION_ID = 0x1000000000000000;
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <event2/event.h>
|
||||
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#include "PSOEncryption.hh"
|
||||
#include "PSOProtocol.hh"
|
||||
#include "ServerState.hh"
|
||||
|
||||
class ProxyServer : public std::enable_shared_from_this<ProxyServer> {
|
||||
public:
|
||||
ProxyServer() = delete;
|
||||
ProxyServer(const ProxyServer&) = delete;
|
||||
ProxyServer(ProxyServer&&) = delete;
|
||||
ProxyServer(
|
||||
std::shared_ptr<struct event_base> base,
|
||||
std::shared_ptr<ServerState> state);
|
||||
virtual ~ProxyServer() = default;
|
||||
|
||||
void listen(const std::string& addr, uint16_t port, Version version, const struct sockaddr_storage* default_destination = nullptr);
|
||||
|
||||
void connect_virtual_client(struct bufferevent* bev, uint64_t virtual_network_id, uint16_t server_port);
|
||||
|
||||
struct LinkedSession : std::enable_shared_from_this<LinkedSession> {
|
||||
std::weak_ptr<ProxyServer> server;
|
||||
uint64_t id;
|
||||
PrefixedLogger log;
|
||||
|
||||
std::unique_ptr<struct event, void (*)(struct event*)> timeout_event;
|
||||
|
||||
std::shared_ptr<Login> login;
|
||||
|
||||
Channel client_channel;
|
||||
Channel server_channel;
|
||||
uint16_t local_port;
|
||||
struct sockaddr_storage next_destination;
|
||||
|
||||
enum class DisconnectAction {
|
||||
LONG_TIMEOUT = 0,
|
||||
MEDIUM_TIMEOUT,
|
||||
SHORT_TIMEOUT,
|
||||
CLOSE_IMMEDIATELY,
|
||||
};
|
||||
DisconnectAction disconnect_action;
|
||||
|
||||
uint8_t prev_server_command_bytes[6];
|
||||
uint32_t remote_ip_crc;
|
||||
bool enable_remote_ip_crc_patch;
|
||||
|
||||
uint32_t sub_version;
|
||||
std::string character_name;
|
||||
std::string hardware_id; // Only used for DC sessions
|
||||
std::string login_command_bb;
|
||||
XBNetworkLocation xb_netloc;
|
||||
parray<le_uint32_t, 3> xb_9E_unknown_a1a;
|
||||
|
||||
uint32_t challenge_rank_color_override;
|
||||
std::string challenge_rank_title_override;
|
||||
int64_t remote_guild_card_number;
|
||||
parray<uint8_t, 0x20> remote_client_config_data;
|
||||
Client::Config config;
|
||||
// A null handler in here means to forward the response to the remote server
|
||||
std::deque<std::function<void(uint32_t return_value, uint32_t checksum)>> function_call_return_handler_queue;
|
||||
RecentSwitchFlags recent_switch_flags; // used for switch assist
|
||||
ItemData next_drop_item;
|
||||
uint32_t next_item_id;
|
||||
|
||||
enum class DropMode {
|
||||
DISABLED = 0,
|
||||
PASSTHROUGH,
|
||||
INTERCEPT,
|
||||
};
|
||||
DropMode drop_mode;
|
||||
std::shared_ptr<std::string> quest_dat_data;
|
||||
std::shared_ptr<ItemCreator> item_creator;
|
||||
std::shared_ptr<Map> map;
|
||||
|
||||
struct LobbyPlayer {
|
||||
uint32_t guild_card_number = 0;
|
||||
uint64_t xb_user_id = 0;
|
||||
std::string name;
|
||||
uint8_t language = 0;
|
||||
uint8_t section_id = 0;
|
||||
uint8_t char_class = 0;
|
||||
};
|
||||
std::vector<LobbyPlayer> lobby_players;
|
||||
size_t lobby_client_id;
|
||||
size_t leader_client_id;
|
||||
uint16_t floor;
|
||||
float x;
|
||||
float z;
|
||||
bool is_in_game;
|
||||
bool is_in_quest;
|
||||
uint8_t lobby_event;
|
||||
uint8_t lobby_difficulty;
|
||||
uint8_t lobby_section_id;
|
||||
GameMode lobby_mode;
|
||||
Episode lobby_episode;
|
||||
uint32_t lobby_random_seed;
|
||||
uint64_t client_ping_start_time = 0;
|
||||
uint64_t server_ping_start_time = 0;
|
||||
|
||||
std::shared_ptr<PSOBBMultiKeyDetectorEncryption> detector_crypt;
|
||||
|
||||
struct SavingFile {
|
||||
std::string basename;
|
||||
std::string output_filename;
|
||||
bool is_download;
|
||||
size_t remaining_bytes;
|
||||
std::deque<std::string> blocks;
|
||||
|
||||
SavingFile(
|
||||
const std::string& basename,
|
||||
const std::string& output_filename,
|
||||
size_t remaining_bytes,
|
||||
bool is_download);
|
||||
};
|
||||
std::unordered_map<std::string, SavingFile> saving_files;
|
||||
|
||||
// TODO: This first constructor should be private
|
||||
LinkedSession(
|
||||
std::shared_ptr<ProxyServer> server,
|
||||
uint64_t id,
|
||||
uint16_t local_port,
|
||||
Version version);
|
||||
LinkedSession(
|
||||
std::shared_ptr<ProxyServer> server,
|
||||
uint16_t local_port,
|
||||
Version version,
|
||||
std::shared_ptr<Login> login,
|
||||
const Client::Config& config);
|
||||
LinkedSession(
|
||||
std::shared_ptr<ProxyServer> server,
|
||||
uint16_t local_port,
|
||||
Version version,
|
||||
std::shared_ptr<Login> login,
|
||||
const struct sockaddr_storage& next_destination);
|
||||
LinkedSession(
|
||||
std::shared_ptr<ProxyServer> server,
|
||||
uint64_t id,
|
||||
uint16_t local_port,
|
||||
Version version,
|
||||
const struct sockaddr_storage& next_destination);
|
||||
|
||||
std::shared_ptr<ProxyServer> require_server() const;
|
||||
std::shared_ptr<ServerState> require_server_state() const;
|
||||
|
||||
inline Version version() const {
|
||||
return this->client_channel.version;
|
||||
}
|
||||
inline uint8_t language() const {
|
||||
return this->client_channel.language;
|
||||
}
|
||||
void set_version(Version v);
|
||||
|
||||
void resume(
|
||||
Channel&& client_channel,
|
||||
std::shared_ptr<PSOBBMultiKeyDetectorEncryption> detector_crypt,
|
||||
uint32_t sub_version,
|
||||
const std::string& character_name,
|
||||
const std::string& hardware_id,
|
||||
const XBNetworkLocation& xb_netloc,
|
||||
const parray<le_uint32_t, 3>& xb_9E_unknown_a1a);
|
||||
void resume(
|
||||
Channel&& client_channel,
|
||||
std::shared_ptr<PSOBBMultiKeyDetectorEncryption> detector_crypt,
|
||||
std::string&& login_command_bb);
|
||||
void resume(Channel&& client_channel);
|
||||
void resume_inner(
|
||||
Channel&& client_channel,
|
||||
std::shared_ptr<PSOBBMultiKeyDetectorEncryption> detector_crypt);
|
||||
void connect();
|
||||
|
||||
static uint64_t timeout_for_disconnect_action(DisconnectAction action);
|
||||
static void dispatch_on_timeout(evutil_socket_t fd, short what, void* ctx);
|
||||
static void on_input(Channel& ch, uint16_t, uint32_t, std::string& msg);
|
||||
static void on_error(Channel& ch, short events);
|
||||
void on_timeout();
|
||||
|
||||
void update_channel_names();
|
||||
|
||||
void clear_lobby_players(size_t num_slots);
|
||||
|
||||
void set_drop_mode(DropMode new_mode);
|
||||
|
||||
void send_to_game_server(const char* error_message = nullptr);
|
||||
void disconnect();
|
||||
bool is_connected() const;
|
||||
};
|
||||
|
||||
std::shared_ptr<LinkedSession> get_session() const;
|
||||
std::shared_ptr<LinkedSession> get_session_by_name(const std::string& name) const;
|
||||
const std::unordered_map<uint64_t, std::shared_ptr<LinkedSession>>& all_sessions() const;
|
||||
|
||||
std::shared_ptr<LinkedSession> create_logged_in_session(
|
||||
std::shared_ptr<Login> login,
|
||||
uint16_t local_port,
|
||||
Version version,
|
||||
const Client::Config& config);
|
||||
void delete_session(uint64_t id);
|
||||
|
||||
size_t num_sessions() const;
|
||||
|
||||
size_t delete_disconnected_sessions();
|
||||
|
||||
private:
|
||||
struct ListeningSocket {
|
||||
ProxyServer* server;
|
||||
|
||||
PrefixedLogger log;
|
||||
uint16_t port;
|
||||
scoped_fd fd;
|
||||
std::unique_ptr<struct evconnlistener, void (*)(struct evconnlistener*)> listener;
|
||||
Version version;
|
||||
struct sockaddr_storage default_destination;
|
||||
|
||||
ListeningSocket(
|
||||
ProxyServer* server,
|
||||
const std::string& addr,
|
||||
uint16_t port,
|
||||
Version version,
|
||||
const struct sockaddr_storage* default_destination);
|
||||
|
||||
static void dispatch_on_listen_accept(struct evconnlistener* listener,
|
||||
evutil_socket_t fd, struct sockaddr* address, int socklen, void* ctx);
|
||||
static void dispatch_on_listen_error(struct evconnlistener* listener, void* ctx);
|
||||
void on_listen_accept(int fd);
|
||||
void on_listen_error();
|
||||
};
|
||||
|
||||
struct UnlinkedSession {
|
||||
std::weak_ptr<ProxyServer> server;
|
||||
uint64_t id;
|
||||
|
||||
PrefixedLogger log;
|
||||
Channel channel;
|
||||
uint16_t local_port;
|
||||
struct sockaddr_storage next_destination;
|
||||
|
||||
std::shared_ptr<PSOBBMultiKeyDetectorEncryption> detector_crypt;
|
||||
|
||||
// Temporary state used just before resuming a LinkedSession. These aren't
|
||||
// just local variables inside on_input because XB requires two commands to
|
||||
// get started (9E and 9F), so we need to store this state somewhere between
|
||||
// those commands.
|
||||
std::shared_ptr<Login> login;
|
||||
uint32_t sub_version = 0;
|
||||
std::string character_name;
|
||||
Client::Config config;
|
||||
std::string login_command_bb;
|
||||
std::string hardware_id;
|
||||
XBNetworkLocation xb_netloc;
|
||||
parray<le_uint32_t, 3> xb_9E_unknown_a1a;
|
||||
|
||||
UnlinkedSession(
|
||||
std::shared_ptr<ProxyServer> server,
|
||||
uint64_t id,
|
||||
struct bufferevent* bev,
|
||||
uint64_t virtual_network_id,
|
||||
uint16_t port,
|
||||
Version version);
|
||||
|
||||
std::shared_ptr<ProxyServer> require_server() const;
|
||||
std::shared_ptr<ServerState> require_server_state() const;
|
||||
|
||||
inline Version version() const {
|
||||
return this->channel.version;
|
||||
}
|
||||
|
||||
void receive_and_process_commands();
|
||||
|
||||
static void on_input(Channel& ch, uint16_t command, uint32_t flag, std::string& msg);
|
||||
static void on_error(Channel& ch, short events);
|
||||
};
|
||||
|
||||
std::shared_ptr<struct event_base> base;
|
||||
std::shared_ptr<struct event> destroy_sessions_ev;
|
||||
std::shared_ptr<ServerState> state;
|
||||
std::map<int, std::shared_ptr<ListeningSocket>> listeners;
|
||||
std::unordered_map<uint64_t, std::shared_ptr<UnlinkedSession>> id_to_unlinked_session;
|
||||
std::unordered_set<std::shared_ptr<UnlinkedSession>> unlinked_sessions_to_destroy;
|
||||
std::unordered_map<uint64_t, std::shared_ptr<LinkedSession>> id_to_linked_session;
|
||||
uint64_t next_unlinked_session_id;
|
||||
uint64_t next_logged_out_session_id;
|
||||
|
||||
static void dispatch_destroy_sessions(evutil_socket_t, short, void* ctx);
|
||||
void destroy_sessions();
|
||||
|
||||
void on_client_connect(
|
||||
struct bufferevent* bev,
|
||||
uint64_t virtual_network_id,
|
||||
uint16_t listen_port,
|
||||
Version version,
|
||||
const struct sockaddr_storage* default_destination);
|
||||
|
||||
static constexpr uint64_t MIN_UNLINKED_SESSION_ID = 0xC000000000000000;
|
||||
static constexpr uint64_t MIN_LINKED_LOGGED_OUT_SESSION_ID = 0x1000000000000000;
|
||||
};
|
||||
|
||||
+1381
-1343
File diff suppressed because it is too large
Load Diff
+202
-189
@@ -1,189 +1,202 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "IntegralExpression.hh"
|
||||
#include "PlayerSubordinates.hh"
|
||||
#include "QuestScript.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "TeamIndex.hh"
|
||||
|
||||
enum class QuestFileFormat {
|
||||
BIN_DAT = 0,
|
||||
BIN_DAT_UNCOMPRESSED,
|
||||
BIN_DAT_GCI,
|
||||
BIN_DAT_VMS,
|
||||
BIN_DAT_DLQ,
|
||||
QST,
|
||||
};
|
||||
|
||||
enum class QuestMenuType {
|
||||
NORMAL = 0,
|
||||
BATTLE = 1,
|
||||
CHALLENGE = 2,
|
||||
SOLO = 3,
|
||||
GOVERNMENT = 4,
|
||||
DOWNLOAD = 5,
|
||||
EP3_DOWNLOAD = 6,
|
||||
// 7 can't be used as a menu type (it enables the per-episode filter)
|
||||
};
|
||||
|
||||
struct QuestCategoryIndex {
|
||||
struct Category {
|
||||
uint32_t category_id;
|
||||
uint8_t enabled_flags;
|
||||
std::string directory_name;
|
||||
std::string name;
|
||||
std::string description;
|
||||
|
||||
explicit Category(uint32_t category_id, const JSON& json);
|
||||
|
||||
[[nodiscard]] inline bool check_flag(QuestMenuType menu_type) const {
|
||||
return this->enabled_flags & (1 << static_cast<uint8_t>(menu_type));
|
||||
}
|
||||
[[nodiscard]] inline bool enable_episode_filter() const {
|
||||
return this->enabled_flags & 0x80;
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<std::shared_ptr<Category>> categories;
|
||||
|
||||
explicit QuestCategoryIndex(const JSON& json);
|
||||
|
||||
std::shared_ptr<const Category> at(uint32_t category_id) const;
|
||||
};
|
||||
|
||||
struct VersionedQuest {
|
||||
uint32_t quest_number;
|
||||
uint32_t category_id;
|
||||
Episode episode;
|
||||
bool joinable;
|
||||
std::string name;
|
||||
Version version;
|
||||
uint8_t language;
|
||||
bool is_dlq_encoded;
|
||||
std::string short_description;
|
||||
std::string long_description;
|
||||
std::shared_ptr<const std::string> bin_contents;
|
||||
std::shared_ptr<const std::string> dat_contents;
|
||||
std::shared_ptr<const std::string> dat_contents_decompressed;
|
||||
std::shared_ptr<const std::string> pvr_contents;
|
||||
std::shared_ptr<const BattleRules> battle_rules;
|
||||
ssize_t challenge_template_index;
|
||||
std::shared_ptr<const IntegralExpression> available_expression;
|
||||
std::shared_ptr<const IntegralExpression> enabled_expression;
|
||||
|
||||
VersionedQuest(
|
||||
uint32_t quest_number,
|
||||
uint32_t category_id,
|
||||
Version version,
|
||||
uint8_t language,
|
||||
std::shared_ptr<const std::string> bin_contents,
|
||||
std::shared_ptr<const std::string> dat_contents,
|
||||
std::shared_ptr<const std::string> pvr_contents,
|
||||
std::shared_ptr<const BattleRules> battle_rules = nullptr,
|
||||
ssize_t challenge_template_index = -1,
|
||||
std::shared_ptr<const IntegralExpression> available_expression = nullptr,
|
||||
std::shared_ptr<const IntegralExpression> enabled_expression = nullptr);
|
||||
|
||||
std::string bin_filename() const;
|
||||
std::string dat_filename() const;
|
||||
std::string pvr_filename() const;
|
||||
std::string xb_filename() const;
|
||||
|
||||
std::shared_ptr<VersionedQuest> create_download_quest(uint8_t override_language = 0xFF) const;
|
||||
std::string encode_qst() const;
|
||||
};
|
||||
|
||||
class Quest {
|
||||
public:
|
||||
Quest() = delete;
|
||||
explicit Quest(std::shared_ptr<const VersionedQuest> initial_version);
|
||||
Quest(const Quest&) = default;
|
||||
Quest(Quest&&) = default;
|
||||
Quest& operator=(const Quest&) = default;
|
||||
Quest& operator=(Quest&&) = default;
|
||||
|
||||
void add_version(std::shared_ptr<const VersionedQuest> vq);
|
||||
bool has_version(Version v, uint8_t language) const;
|
||||
bool has_version_any_language(Version v) const;
|
||||
std::shared_ptr<const VersionedQuest> version(Version v, uint8_t language) const;
|
||||
|
||||
static uint32_t versions_key(Version v, uint8_t language);
|
||||
|
||||
uint32_t quest_number;
|
||||
uint32_t category_id;
|
||||
Episode episode;
|
||||
bool joinable;
|
||||
std::string name;
|
||||
std::shared_ptr<const BattleRules> battle_rules;
|
||||
ssize_t challenge_template_index;
|
||||
std::shared_ptr<const IntegralExpression> available_expression;
|
||||
std::shared_ptr<const IntegralExpression> enabled_expression;
|
||||
std::map<uint32_t, std::shared_ptr<const VersionedQuest>> versions;
|
||||
};
|
||||
|
||||
struct QuestIndex {
|
||||
enum class IncludeState {
|
||||
HIDDEN = 0,
|
||||
AVAILABLE,
|
||||
DISABLED,
|
||||
};
|
||||
using IncludeCondition = std::function<IncludeState(std::shared_ptr<const Quest>)>;
|
||||
|
||||
std::string directory;
|
||||
std::shared_ptr<const QuestCategoryIndex> category_index;
|
||||
|
||||
std::map<uint32_t, std::shared_ptr<Quest>> quests_by_number;
|
||||
std::map<std::string, std::shared_ptr<Quest>> quests_by_name;
|
||||
std::map<uint32_t, std::map<uint32_t, std::shared_ptr<Quest>>> quests_by_category_id_and_number;
|
||||
|
||||
QuestIndex(const std::string& directory, std::shared_ptr<const QuestCategoryIndex> category_index, bool is_ep3);
|
||||
|
||||
std::shared_ptr<const Quest> get(uint32_t quest_number) const;
|
||||
std::shared_ptr<const Quest> get(const std::string& name) const;
|
||||
|
||||
std::vector<std::shared_ptr<const QuestCategoryIndex::Category>> categories(
|
||||
QuestMenuType menu_type,
|
||||
Episode episode,
|
||||
Version version,
|
||||
IncludeCondition include_condition = nullptr) const;
|
||||
std::vector<std::pair<QuestIndex::IncludeState, std::shared_ptr<const Quest>>> filter(
|
||||
Episode episode,
|
||||
Version version,
|
||||
uint32_t category_id,
|
||||
IncludeCondition include_condition = nullptr,
|
||||
size_t limit = 0) const;
|
||||
};
|
||||
|
||||
std::string encode_download_quest_data(
|
||||
const std::string& compressed_data,
|
||||
size_t decompressed_size = 0,
|
||||
uint32_t encryption_seed = 0);
|
||||
|
||||
std::string decode_gci_data(
|
||||
const std::string& data,
|
||||
ssize_t find_seed_num_threads = -1,
|
||||
int64_t known_seed = -1,
|
||||
bool skip_checksum = false);
|
||||
std::string decode_vms_data(
|
||||
const std::string& data,
|
||||
ssize_t find_seed_num_threads = -1,
|
||||
int64_t known_seed = -1,
|
||||
bool skip_checksum = false);
|
||||
std::string decode_dlq_data(const std::string& data);
|
||||
std::unordered_map<std::string, std::string> decode_qst_data(const std::string& data);
|
||||
|
||||
std::string encode_qst_file(
|
||||
const std::unordered_map<std::string, std::shared_ptr<const std::string>>& files,
|
||||
const std::string& name,
|
||||
uint32_t quest_number,
|
||||
const std::string& xb_filename,
|
||||
Version version,
|
||||
bool is_dlq_encoded);
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "IntegralExpression.hh"
|
||||
#include "PlayerSubordinates.hh"
|
||||
#include "QuestScript.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "TeamIndex.hh"
|
||||
|
||||
enum class QuestFileFormat {
|
||||
BIN_DAT = 0,
|
||||
BIN_DAT_UNCOMPRESSED,
|
||||
BIN_DAT_GCI,
|
||||
BIN_DAT_VMS,
|
||||
BIN_DAT_DLQ,
|
||||
QST,
|
||||
};
|
||||
|
||||
enum class QuestMenuType {
|
||||
NORMAL = 0,
|
||||
BATTLE = 1,
|
||||
CHALLENGE = 2,
|
||||
SOLO = 3,
|
||||
GOVERNMENT = 4,
|
||||
DOWNLOAD = 5,
|
||||
EP3_DOWNLOAD = 6,
|
||||
// 7 can't be used as a menu type (it enables the per-episode filter)
|
||||
};
|
||||
|
||||
struct QuestCategoryIndex {
|
||||
struct Category {
|
||||
uint32_t category_id;
|
||||
uint16_t enabled_flags;
|
||||
std::string directory_name;
|
||||
std::string name;
|
||||
std::string description;
|
||||
|
||||
explicit Category(uint32_t category_id, const JSON& json);
|
||||
|
||||
[[nodiscard]] inline bool check_flag(QuestMenuType menu_type) const {
|
||||
return this->enabled_flags & (1 << static_cast<uint8_t>(menu_type));
|
||||
}
|
||||
[[nodiscard]] inline bool enable_episode_filter() const {
|
||||
return this->enabled_flags & 0x080;
|
||||
}
|
||||
[[nodiscard]] inline bool use_ep2_icon() const {
|
||||
return this->enabled_flags & 0x100;
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<std::shared_ptr<Category>> categories;
|
||||
|
||||
explicit QuestCategoryIndex(const JSON& json);
|
||||
|
||||
std::shared_ptr<const Category> at(uint32_t category_id) const;
|
||||
};
|
||||
|
||||
struct VersionedQuest {
|
||||
uint32_t quest_number;
|
||||
uint32_t category_id;
|
||||
Episode episode;
|
||||
bool allow_start_from_chat_command;
|
||||
bool joinable;
|
||||
int16_t lock_status_register;
|
||||
std::string name;
|
||||
Version version;
|
||||
uint8_t language;
|
||||
bool is_dlq_encoded;
|
||||
std::string short_description;
|
||||
std::string long_description;
|
||||
std::shared_ptr<const std::string> bin_contents;
|
||||
std::shared_ptr<const std::string> dat_contents;
|
||||
std::shared_ptr<const std::string> dat_contents_decompressed;
|
||||
std::shared_ptr<const std::string> pvr_contents;
|
||||
std::shared_ptr<const BattleRules> battle_rules;
|
||||
ssize_t challenge_template_index;
|
||||
uint8_t description_flag;
|
||||
std::shared_ptr<const IntegralExpression> available_expression;
|
||||
std::shared_ptr<const IntegralExpression> enabled_expression;
|
||||
|
||||
VersionedQuest(
|
||||
uint32_t quest_number,
|
||||
uint32_t category_id,
|
||||
Version version,
|
||||
uint8_t language,
|
||||
std::shared_ptr<const std::string> bin_contents,
|
||||
std::shared_ptr<const std::string> dat_contents,
|
||||
std::shared_ptr<const std::string> pvr_contents,
|
||||
std::shared_ptr<const BattleRules> battle_rules = nullptr,
|
||||
ssize_t challenge_template_index = -1,
|
||||
uint8_t description_flag = 0,
|
||||
std::shared_ptr<const IntegralExpression> available_expression = nullptr,
|
||||
std::shared_ptr<const IntegralExpression> enabled_expression = nullptr,
|
||||
bool allow_start_from_chat_command = false,
|
||||
bool force_joinable = false,
|
||||
int16_t lock_status_register = -1);
|
||||
|
||||
std::string bin_filename() const;
|
||||
std::string dat_filename() const;
|
||||
std::string pvr_filename() const;
|
||||
std::string xb_filename() const;
|
||||
|
||||
std::shared_ptr<VersionedQuest> create_download_quest(uint8_t override_language = 0xFF) const;
|
||||
std::string encode_qst() const;
|
||||
};
|
||||
|
||||
class Quest {
|
||||
public:
|
||||
Quest() = delete;
|
||||
explicit Quest(std::shared_ptr<const VersionedQuest> initial_version);
|
||||
Quest(const Quest&) = default;
|
||||
Quest(Quest&&) = default;
|
||||
Quest& operator=(const Quest&) = default;
|
||||
Quest& operator=(Quest&&) = default;
|
||||
|
||||
void add_version(std::shared_ptr<const VersionedQuest> vq);
|
||||
bool has_version(Version v, uint8_t language) const;
|
||||
bool has_version_any_language(Version v) const;
|
||||
std::shared_ptr<const VersionedQuest> version(Version v, uint8_t language) const;
|
||||
|
||||
static uint32_t versions_key(Version v, uint8_t language);
|
||||
|
||||
uint32_t quest_number;
|
||||
uint32_t category_id;
|
||||
Episode episode;
|
||||
bool allow_start_from_chat_command;
|
||||
bool joinable;
|
||||
int16_t lock_status_register;
|
||||
std::string name;
|
||||
std::shared_ptr<const BattleRules> battle_rules;
|
||||
ssize_t challenge_template_index;
|
||||
uint8_t description_flag;
|
||||
std::shared_ptr<const IntegralExpression> available_expression;
|
||||
std::shared_ptr<const IntegralExpression> enabled_expression;
|
||||
std::map<uint32_t, std::shared_ptr<const VersionedQuest>> versions;
|
||||
};
|
||||
|
||||
struct QuestIndex {
|
||||
enum class IncludeState {
|
||||
HIDDEN = 0,
|
||||
AVAILABLE,
|
||||
DISABLED,
|
||||
};
|
||||
using IncludeCondition = std::function<IncludeState(std::shared_ptr<const Quest>)>;
|
||||
|
||||
std::string directory;
|
||||
std::shared_ptr<const QuestCategoryIndex> category_index;
|
||||
|
||||
std::map<uint32_t, std::shared_ptr<Quest>> quests_by_number;
|
||||
std::map<std::string, std::shared_ptr<Quest>> quests_by_name;
|
||||
std::map<uint32_t, std::map<uint32_t, std::shared_ptr<Quest>>> quests_by_category_id_and_number;
|
||||
|
||||
QuestIndex(const std::string& directory, std::shared_ptr<const QuestCategoryIndex> category_index, bool is_ep3);
|
||||
|
||||
std::shared_ptr<const Quest> get(uint32_t quest_number) const;
|
||||
std::shared_ptr<const Quest> get(const std::string& name) const;
|
||||
|
||||
std::vector<std::shared_ptr<const QuestCategoryIndex::Category>> categories(
|
||||
QuestMenuType menu_type,
|
||||
Episode episode,
|
||||
Version version,
|
||||
IncludeCondition include_condition = nullptr) const;
|
||||
std::vector<std::pair<QuestIndex::IncludeState, std::shared_ptr<const Quest>>> filter(
|
||||
Episode episode,
|
||||
Version version,
|
||||
uint32_t category_id,
|
||||
IncludeCondition include_condition = nullptr,
|
||||
size_t limit = 0) const;
|
||||
};
|
||||
|
||||
std::string encode_download_quest_data(
|
||||
const std::string& compressed_data,
|
||||
size_t decompressed_size = 0,
|
||||
uint32_t encryption_seed = 0);
|
||||
|
||||
std::string decode_gci_data(
|
||||
const std::string& data,
|
||||
ssize_t find_seed_num_threads = -1,
|
||||
int64_t known_seed = -1,
|
||||
bool skip_checksum = false);
|
||||
std::string decode_vms_data(
|
||||
const std::string& data,
|
||||
ssize_t find_seed_num_threads = -1,
|
||||
int64_t known_seed = -1,
|
||||
bool skip_checksum = false);
|
||||
std::string decode_dlq_data(const std::string& data);
|
||||
std::unordered_map<std::string, std::string> decode_qst_data(const std::string& data);
|
||||
|
||||
std::string encode_qst_file(
|
||||
const std::unordered_map<std::string, std::shared_ptr<const std::string>>& files,
|
||||
const std::string& name,
|
||||
uint32_t quest_number,
|
||||
const std::string& xb_filename,
|
||||
Version version,
|
||||
bool is_dlq_encoded);
|
||||
|
||||
+332
-54
@@ -36,7 +36,11 @@ ToT as_type(const FromT& v) {
|
||||
|
||||
static const char* name_for_header_episode_number(uint8_t episode) {
|
||||
static const array<const char*, 3> names = {"Episode1", "Episode2", "Episode4"};
|
||||
return names.at(episode);
|
||||
try {
|
||||
return names.at(episode);
|
||||
} catch (const out_of_range&) {
|
||||
return "Episode1 # invalid value in header";
|
||||
}
|
||||
}
|
||||
|
||||
static TextEncoding encoding_for_language(uint8_t language) {
|
||||
@@ -681,7 +685,7 @@ static const QuestScriptOpcodeDefinition opcode_defs[] = {
|
||||
{0xF8B4, "write2", {INT32, INT32}, F_V3_V4 | F_ARGS},
|
||||
{0xF8B5, "write4", {REG, REG}, F_V2},
|
||||
{0xF8B5, "write4", {INT32, INT32}, F_V3_V4 | F_ARGS},
|
||||
{0xF8B6, "check_for_hacking", {REG}, F_V2}, // Returns a bitmask of 5 different types of detectable hacking. But it only works on DCv2 - it crashes on all other versions.
|
||||
{0xF8B6, "check_for_hacking", {REG}, F_V2_V4}, // Returns a bitmask of 5 different types of detectable hacking. But it only works on DCv2 - it crashes on all other versions.
|
||||
{0xF8B7, "unknown_F8B7", {REG}, F_V2_V4}, // TODO (DX) - Challenge mode. Appears to be timing-related; regA is expected to be in [60, 3600]. Encodes the value with encrypt_challenge_time even though it's never sent over the network and is only decrypted locally.
|
||||
{0xF8B8, "disable_retry_menu", {}, F_V2_V4},
|
||||
{0xF8B9, "chl_recovery", {}, F_V2_V4},
|
||||
@@ -900,7 +904,7 @@ opcodes_by_name_for_version(Version v) {
|
||||
return index;
|
||||
}
|
||||
|
||||
std::string disassemble_quest_script(const void* data, size_t size, Version version, uint8_t language, bool reassembly_mode) {
|
||||
std::string disassemble_quest_script(const void* data, size_t size, Version version, uint8_t override_language, bool reassembly_mode) {
|
||||
StringReader r(data, size);
|
||||
deque<string> lines;
|
||||
lines.emplace_back(string_printf(".version %s", name_for_enum(version)));
|
||||
@@ -908,6 +912,7 @@ std::string disassemble_quest_script(const void* data, size_t size, Version vers
|
||||
bool use_wstrs = false;
|
||||
size_t code_offset = 0;
|
||||
size_t function_table_offset = 0;
|
||||
uint8_t language;
|
||||
switch (version) {
|
||||
case Version::DC_NTE: {
|
||||
const auto& header = r.get<PSOQuestHeaderDCNTE>();
|
||||
@@ -923,8 +928,12 @@ std::string disassemble_quest_script(const void* data, size_t size, Version vers
|
||||
const auto& header = r.get<PSOQuestHeaderDC>();
|
||||
code_offset = header.code_offset;
|
||||
function_table_offset = header.function_table_offset;
|
||||
if (header.language < 5) {
|
||||
if (override_language != 0xFF) {
|
||||
language = override_language;
|
||||
} else if (header.language < 5) {
|
||||
language = header.language;
|
||||
} else {
|
||||
language = 1;
|
||||
}
|
||||
lines.emplace_back(string_printf(".quest_num %hu", header.quest_number.load()));
|
||||
lines.emplace_back(string_printf(".language %hhu", header.language));
|
||||
@@ -939,8 +948,12 @@ std::string disassemble_quest_script(const void* data, size_t size, Version vers
|
||||
const auto& header = r.get<PSOQuestHeaderPC>();
|
||||
code_offset = header.code_offset;
|
||||
function_table_offset = header.function_table_offset;
|
||||
if (header.language < 8) {
|
||||
if (override_language != 0xFF) {
|
||||
language = override_language;
|
||||
} else if (header.language < 8) {
|
||||
language = header.language;
|
||||
} else {
|
||||
language = 1;
|
||||
}
|
||||
lines.emplace_back(string_printf(".quest_num %hu", header.quest_number.load()));
|
||||
lines.emplace_back(string_printf(".language %hhu", header.language));
|
||||
@@ -957,8 +970,12 @@ std::string disassemble_quest_script(const void* data, size_t size, Version vers
|
||||
const auto& header = r.get<PSOQuestHeaderGC>();
|
||||
code_offset = header.code_offset;
|
||||
function_table_offset = header.function_table_offset;
|
||||
if (header.language < 5) {
|
||||
if (override_language != 0xFF) {
|
||||
language = override_language;
|
||||
} else if (header.language < 5) {
|
||||
language = header.language;
|
||||
} else {
|
||||
language = 1;
|
||||
}
|
||||
lines.emplace_back(string_printf(".quest_num %hhu", header.quest_number));
|
||||
lines.emplace_back(string_printf(".language %hhu", header.language));
|
||||
@@ -973,9 +990,14 @@ std::string disassemble_quest_script(const void* data, size_t size, Version vers
|
||||
const auto& header = r.get<PSOQuestHeaderBB>();
|
||||
code_offset = header.code_offset;
|
||||
function_table_offset = header.function_table_offset;
|
||||
if (override_language != 0xFF) {
|
||||
language = override_language;
|
||||
} else {
|
||||
language = 1;
|
||||
}
|
||||
lines.emplace_back(string_printf(".quest_num %hu", header.quest_number.load()));
|
||||
lines.emplace_back(string_printf(".episode %s", name_for_header_episode_number(header.episode)));
|
||||
lines.emplace_back(string_printf(".max_players %hhu", header.episode));
|
||||
lines.emplace_back(string_printf(".max_players %hhu", header.max_players ? header.max_players : 4));
|
||||
if (header.joinable) {
|
||||
lines.emplace_back(".joinable");
|
||||
}
|
||||
@@ -1757,6 +1779,190 @@ Episode episode_for_quest_episode_number(uint8_t episode_number) {
|
||||
}
|
||||
}
|
||||
|
||||
struct RegisterAssigner {
|
||||
struct Register {
|
||||
string name;
|
||||
int16_t number = -1; // -1 = unassigned (any number)
|
||||
shared_ptr<Register> prev;
|
||||
shared_ptr<Register> next;
|
||||
unordered_set<size_t> offsets;
|
||||
|
||||
std::string str() const {
|
||||
return string_printf("Register(%p, name=\"%s\", number=%hd)", this, this->name.c_str(), this->number);
|
||||
}
|
||||
};
|
||||
|
||||
~RegisterAssigner() {
|
||||
for (auto& it : this->named_regs) {
|
||||
it.second->prev.reset();
|
||||
it.second->next.reset();
|
||||
}
|
||||
for (auto& reg : this->numbered_regs) {
|
||||
if (reg) {
|
||||
reg->prev.reset();
|
||||
reg->next.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr<Register> get_or_create(const string& name, int16_t number) {
|
||||
if ((number < -1) || (number >= 0x100)) {
|
||||
throw runtime_error("invalid register number");
|
||||
}
|
||||
|
||||
shared_ptr<Register> reg;
|
||||
if (!name.empty()) {
|
||||
try {
|
||||
reg = this->named_regs.at(name);
|
||||
} catch (const out_of_range&) {
|
||||
}
|
||||
}
|
||||
if (!reg && number >= 0) {
|
||||
reg = this->numbered_regs.at(number);
|
||||
}
|
||||
|
||||
if (!reg) {
|
||||
reg = make_shared<Register>();
|
||||
}
|
||||
|
||||
if (number >= 0) {
|
||||
if (reg->number < 0) {
|
||||
reg->number = number;
|
||||
auto& numbered_reg = this->numbered_regs.at(reg->number);
|
||||
if (numbered_reg) {
|
||||
throw runtime_error(reg->str() + " cannot be assigned due to conflict with " + numbered_reg->str());
|
||||
}
|
||||
this->numbered_regs.at(reg->number) = reg;
|
||||
} else if (reg->number != number) {
|
||||
throw runtime_error(string_printf("register %s is assigned multiple numbers", reg->name.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
if (!name.empty()) {
|
||||
if (reg->name.empty()) {
|
||||
reg->name = name;
|
||||
if (!this->named_regs.emplace(reg->name, reg).second) {
|
||||
throw runtime_error(string_printf("name %s is already assigned to a different register", reg->name.c_str()));
|
||||
}
|
||||
} else if (reg->name != name) {
|
||||
throw runtime_error(string_printf("register %hd is assigned multiple names", reg->number));
|
||||
}
|
||||
}
|
||||
|
||||
return reg;
|
||||
}
|
||||
|
||||
void assign_number(shared_ptr<Register> reg, uint8_t number) {
|
||||
if (reg->number < 0) {
|
||||
reg->number = number;
|
||||
if (this->numbered_regs.at(reg->number)) {
|
||||
throw logic_error(string_printf("register number %hd assigned multiple times", reg->number));
|
||||
}
|
||||
this->numbered_regs.at(reg->number) = reg;
|
||||
} else if (reg->number != static_cast<int16_t>(number)) {
|
||||
throw runtime_error(string_printf("assigning different register number %hhu over existing register number %hd", number, reg->number));
|
||||
}
|
||||
}
|
||||
|
||||
void constrain(shared_ptr<Register> first_reg, shared_ptr<Register> second_reg) {
|
||||
if (!first_reg->next) {
|
||||
first_reg->next = second_reg;
|
||||
} else if (first_reg->next != second_reg) {
|
||||
throw runtime_error(string_printf("register %s must come after %s, but is already constrained to another register", second_reg->name.c_str(), first_reg->name.c_str()));
|
||||
}
|
||||
if (!second_reg->prev) {
|
||||
second_reg->prev = first_reg;
|
||||
} else if (second_reg->prev != first_reg) {
|
||||
throw runtime_error(string_printf("register %s must come before %s, but is already constrained to another register", first_reg->name.c_str(), second_reg->name.c_str()));
|
||||
}
|
||||
if ((first_reg->number >= 0) && (second_reg->number >= 0) && (first_reg->number != ((second_reg->number - 1) & 0xFF))) {
|
||||
throw runtime_error(string_printf("register %s must come before %s, but both registers already have non-consecutive numbers", first_reg->name.c_str(), second_reg->name.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
void assign_all() {
|
||||
// TODO: Technically, we should assign the biggest blocks first to minimize
|
||||
// fragmentation. I am lazy and haven't implemented this yet.
|
||||
vector<shared_ptr<Register>> unassigned;
|
||||
for (auto it : this->named_regs) {
|
||||
if (it.second->number < 0) {
|
||||
unassigned.emplace_back(it.second);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto reg : unassigned) {
|
||||
// If this register is already assigned, skip it
|
||||
if (reg->number >= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If any next register is assigned, assign this register
|
||||
size_t next_delta = 1;
|
||||
for (auto next_reg = reg->next; next_reg; next_reg = next_reg->next, next_delta++) {
|
||||
if (next_reg->number >= 0) {
|
||||
this->assign_number(reg, (next_reg->number - next_delta) & 0xFF);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (reg->number >= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If any prev register is assigned, assign this register
|
||||
size_t prev_delta = 1;
|
||||
for (auto prev_reg = reg->prev; prev_reg; prev_reg = prev_reg->prev, prev_delta++) {
|
||||
if (prev_reg->number >= 0) {
|
||||
this->assign_number(reg, (prev_reg->number + prev_delta) & 0xFF);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (reg->number >= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// No prev or next register is assigned; find an interval in the register
|
||||
// number space that fits this block of registers. The total number of
|
||||
// register numbers needed is (prev_delta - 1) + (next_delta - 1) + 1.
|
||||
size_t num_regs = prev_delta + next_delta - 1;
|
||||
this->assign_number(reg, (this->find_register_number_space(num_regs) + (prev_delta - 1)) & 0xFF);
|
||||
|
||||
// We don't need to assign the prev and next registers; they should also
|
||||
// be in the unassigned set and will be assigned by the above logic
|
||||
}
|
||||
|
||||
// At this point, all registers should be assigned
|
||||
for (const auto& it : this->named_regs) {
|
||||
if (it.second->number < 0) {
|
||||
throw logic_error(string_printf("register %s was not assigned", it.second->name.c_str()));
|
||||
}
|
||||
}
|
||||
for (size_t z = 0; z < 0x100; z++) {
|
||||
auto reg = this->numbered_regs[z];
|
||||
if (reg && (reg->number != static_cast<int16_t>(z))) {
|
||||
throw logic_error(string_printf("register %zu has incorrect number %hd", z, reg->number));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t find_register_number_space(size_t num_regs) const {
|
||||
for (size_t candidate = 0; candidate < 0x100; candidate++) {
|
||||
size_t z;
|
||||
for (z = 0; z < num_regs; z++) {
|
||||
if (this->numbered_regs[candidate + z]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (z == num_regs) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
throw runtime_error("not enough space to assign registers");
|
||||
}
|
||||
|
||||
map<string, shared_ptr<Register>> named_regs;
|
||||
array<shared_ptr<Register>, 0x100> numbered_regs;
|
||||
};
|
||||
|
||||
std::string assemble_quest_script(const std::string& text) {
|
||||
auto lines = split(text, '\n');
|
||||
|
||||
@@ -1832,7 +2038,7 @@ std::string assemble_quest_script(const std::string& text) {
|
||||
ssize_t index = -1;
|
||||
ssize_t offset = -1;
|
||||
};
|
||||
unordered_map<string, shared_ptr<Label>> labels_by_name;
|
||||
map<string, shared_ptr<Label>> labels_by_name;
|
||||
map<ssize_t, shared_ptr<Label>> labels_by_index;
|
||||
for (size_t line_num = 1; line_num <= lines.size(); line_num++) {
|
||||
const auto& line = lines[line_num - 1];
|
||||
@@ -1883,6 +2089,88 @@ std::string assemble_quest_script(const std::string& text) {
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare to collect named registers
|
||||
RegisterAssigner reg_assigner;
|
||||
auto parse_reg = [®_assigner](const string& arg, bool allow_unnumbered = true) -> shared_ptr<RegisterAssigner::Register> {
|
||||
if (arg.size() < 2) {
|
||||
throw runtime_error("register argument is too short");
|
||||
}
|
||||
if ((arg[0] != 'r') && (arg[0] != 'f')) {
|
||||
throw runtime_error("a register is required");
|
||||
}
|
||||
string name;
|
||||
ssize_t number = -1;
|
||||
if (arg[1] == ':') {
|
||||
auto tokens = split(arg.substr(2), '@');
|
||||
if (tokens.size() == 1) {
|
||||
name = std::move(tokens[0]);
|
||||
} else if (tokens.size() == 2) {
|
||||
name = std::move(tokens[0]);
|
||||
number = stoull(tokens[1], nullptr, 0);
|
||||
} else {
|
||||
throw runtime_error("invalid register specification");
|
||||
}
|
||||
} else {
|
||||
number = stoull(arg.substr(1), nullptr, 0);
|
||||
}
|
||||
if (!allow_unnumbered && (number < 0)) {
|
||||
throw runtime_error("a numbered register is required");
|
||||
}
|
||||
if (number > 0xFF) {
|
||||
throw runtime_error("invalid register number");
|
||||
}
|
||||
return reg_assigner.get_or_create(name, number);
|
||||
};
|
||||
auto parse_reg_set_fixed = [®_assigner, &parse_reg](const string& name, size_t expected_count) -> vector<shared_ptr<RegisterAssigner::Register>> {
|
||||
if (expected_count == 0) {
|
||||
throw logic_error("REG_SET_FIXED argument expects no registers");
|
||||
}
|
||||
if (name.empty()) {
|
||||
throw runtime_error("no register specified for REG_SET_FIXED argument");
|
||||
}
|
||||
vector<shared_ptr<RegisterAssigner::Register>> regs;
|
||||
if ((name[0] == '(') && (name.back() == ')')) {
|
||||
auto tokens = split(name.substr(1, name.size() - 2), ',');
|
||||
if (tokens.size() != expected_count) {
|
||||
throw runtime_error("incorrect number of registers in REG_SET_FIXED");
|
||||
}
|
||||
for (auto& token : tokens) {
|
||||
strip_trailing_whitespace(token);
|
||||
strip_leading_whitespace(token);
|
||||
regs.emplace_back(parse_reg(token));
|
||||
if (regs.size() > 1) {
|
||||
reg_assigner.constrain(regs.at(regs.size() - 2), regs.back());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
auto tokens = split(name, '-');
|
||||
if (tokens.size() == 1) {
|
||||
regs.emplace_back(parse_reg(tokens[0], false));
|
||||
while (regs.size() < expected_count) {
|
||||
regs.emplace_back(parse_reg("", (regs.back()->number + 1) & 0xFF));
|
||||
reg_assigner.constrain(regs.at(regs.size() - 2), regs.back());
|
||||
}
|
||||
} else if (tokens.size() == 2) {
|
||||
regs.emplace_back(parse_reg(tokens[0], false));
|
||||
while (regs.size() < expected_count - 1) {
|
||||
regs.emplace_back(reg_assigner.get_or_create("", (regs.back()->number + 1) & 0xFF));
|
||||
reg_assigner.constrain(regs.at(regs.size() - 2), regs.back());
|
||||
}
|
||||
regs.emplace_back(parse_reg(tokens[1], false));
|
||||
if (static_cast<size_t>(regs.back()->number - regs.front()->number + 1) != expected_count) {
|
||||
throw runtime_error("incorrect number of registers used");
|
||||
}
|
||||
reg_assigner.constrain(regs.at(regs.size() - 2), regs.back());
|
||||
} else {
|
||||
throw runtime_error("invalid fixed register set syntax");
|
||||
}
|
||||
}
|
||||
if (regs.empty() || regs.size() != expected_count) {
|
||||
throw logic_error("incorrect register count in REG_SET_FIXED after parsing");
|
||||
}
|
||||
return regs;
|
||||
};
|
||||
|
||||
// Assemble code segment
|
||||
bool version_has_args = F_HAS_ARGS & v_flag(quest_version);
|
||||
const auto& opcodes = opcodes_by_name_for_version(quest_version);
|
||||
@@ -1956,16 +2244,6 @@ std::string assemble_quest_script(const std::string& text) {
|
||||
strip_leading_whitespace(arg);
|
||||
|
||||
try {
|
||||
auto parse_reg = +[](const string& name) -> uint8_t {
|
||||
if ((name[0] != 'r') && (name[0] != 'f')) {
|
||||
throw runtime_error("a register is required");
|
||||
}
|
||||
size_t reg_num = stoull(name.substr(1), nullptr, 0);
|
||||
if (reg_num > 0xFF) {
|
||||
throw runtime_error("invalid register number");
|
||||
}
|
||||
return reg_num;
|
||||
};
|
||||
auto add_cstr = [&](const string& text) -> void {
|
||||
switch (quest_version) {
|
||||
case Version::DC_NTE:
|
||||
@@ -2001,37 +2279,33 @@ std::string assemble_quest_script(const std::string& text) {
|
||||
} else if (label_it != labels_by_name.end()) {
|
||||
code_w.put_u8(0x4B); // arg_pushw
|
||||
code_w.put_u16l(label_it->second->index);
|
||||
} else if ((arg[0] == 'r') || (arg[0] == 'f')) {
|
||||
} else if ((arg[0] == 'r') || (arg[0] == 'f') || ((arg[0] == '(') && (arg.back() == ')'))) {
|
||||
// If the corresponding argument is a REG or REG_SET_FIXED, push
|
||||
// the register number, not the register's value, since it's an
|
||||
// out-param
|
||||
if ((arg_def.type == Type::REG) || (arg_def.type == Type::REG32)) {
|
||||
code_w.put_u8(0x4A); // arg_pushb
|
||||
code_w.put_u8(parse_reg(arg));
|
||||
auto reg = parse_reg(arg);
|
||||
reg->offsets.emplace(code_w.size());
|
||||
code_w.put_u8(reg->number);
|
||||
} else if (
|
||||
(arg_def.type == Type::REG_SET_FIXED) ||
|
||||
(arg_def.type == Type::REG32_SET_FIXED)) {
|
||||
auto tokens = split(arg, '-');
|
||||
uint8_t start_reg;
|
||||
if (tokens.size() == 1) {
|
||||
start_reg = parse_reg(tokens[0]);
|
||||
} else if (tokens.size() == 2) {
|
||||
start_reg = parse_reg(tokens[0]);
|
||||
if (static_cast<size_t>(parse_reg(tokens[1]) - start_reg + 1) != arg_def.count) {
|
||||
throw runtime_error("incorrect number of registers used");
|
||||
}
|
||||
} else {
|
||||
throw runtime_error("invalid fixed register set syntax");
|
||||
}
|
||||
auto regs = parse_reg_set_fixed(arg, arg_def.count);
|
||||
code_w.put_u8(0x4A); // arg_pushb
|
||||
code_w.put_u8(start_reg);
|
||||
regs[0]->offsets.emplace(code_w.size());
|
||||
code_w.put_u8(regs[0]->number);
|
||||
} else {
|
||||
code_w.put_u8(0x48); // arg_pushr
|
||||
code_w.put_u8(parse_reg(arg));
|
||||
auto reg = parse_reg(arg);
|
||||
reg->offsets.emplace(code_w.size());
|
||||
code_w.put_u8(reg->number);
|
||||
}
|
||||
} else if ((arg[0] == '@') && ((arg[1] == 'r') || (arg[1] == 'f'))) {
|
||||
code_w.put_u8(0x4C); // arg_pusha
|
||||
code_w.put_u8(parse_reg(arg.substr(1)));
|
||||
auto reg = parse_reg(arg.substr(1));
|
||||
reg->offsets.emplace(code_w.size());
|
||||
code_w.put_u8(reg->number);
|
||||
} else if ((arg[0] == '@') && labels_by_name.count(arg.substr(1))) {
|
||||
code_w.put_u8(0x4D); // arg_pusho
|
||||
code_w.put_u16(labels_by_name.at(arg.substr(1))->index);
|
||||
@@ -2076,11 +2350,12 @@ std::string assemble_quest_script(const std::string& text) {
|
||||
code_w.put_u16(labels_by_name.at(name)->index);
|
||||
}
|
||||
};
|
||||
auto add_reg = [&](const string& name, bool is32) -> void {
|
||||
auto add_reg = [&](shared_ptr<RegisterAssigner::Register> reg, bool is32) -> void {
|
||||
reg->offsets.emplace(code_w.size());
|
||||
if (is32) {
|
||||
code_w.put_u32l(parse_reg(name));
|
||||
code_w.put_u32l(reg->number & 0xFF);
|
||||
} else {
|
||||
code_w.put_u8(parse_reg(name));
|
||||
code_w.put_u8(reg->number);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2112,30 +2387,21 @@ std::string assemble_quest_script(const std::string& text) {
|
||||
}
|
||||
case Type::REG:
|
||||
case Type::REG32:
|
||||
add_reg(arg, arg_def.type == Type::REG32);
|
||||
add_reg(parse_reg(arg), arg_def.type == Type::REG32);
|
||||
break;
|
||||
case Type::REG_SET_FIXED:
|
||||
case Type::REG32_SET_FIXED: {
|
||||
auto tokens = split(arg, '-');
|
||||
if (tokens.size() == 1) {
|
||||
add_reg(tokens[0], arg_def.type == Type::REG32_SET_FIXED);
|
||||
} else if (tokens.size() == 2) {
|
||||
if (static_cast<size_t>(parse_reg(tokens[1]) - parse_reg(tokens[0]) + 1) != arg_def.count) {
|
||||
throw runtime_error("incorrect number of registers used");
|
||||
}
|
||||
add_reg(tokens[0], arg_def.type == Type::REG32_SET_FIXED);
|
||||
} else {
|
||||
throw runtime_error("invalid fixed register set syntax");
|
||||
}
|
||||
auto regs = parse_reg_set_fixed(arg, arg_def.count);
|
||||
add_reg(regs[0], arg_def.type == Type::REG32_SET_FIXED);
|
||||
break;
|
||||
}
|
||||
case Type::REG_SET: {
|
||||
auto regs = split_set(arg);
|
||||
code_w.put_u8(regs.size());
|
||||
for (auto reg : regs) {
|
||||
strip_trailing_whitespace(reg);
|
||||
strip_leading_whitespace(reg);
|
||||
add_reg(reg, false);
|
||||
for (auto reg_arg : regs) {
|
||||
strip_trailing_whitespace(reg_arg);
|
||||
strip_leading_whitespace(reg_arg);
|
||||
add_reg(parse_reg(reg_arg), false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -2180,6 +2446,18 @@ std::string assemble_quest_script(const std::string& text) {
|
||||
code_w.put_u8(0);
|
||||
}
|
||||
|
||||
// Assign all register numbers and patch the code section if needed
|
||||
reg_assigner.assign_all();
|
||||
for (size_t z = 0; z < 0x100; z++) {
|
||||
auto reg = reg_assigner.numbered_regs[z];
|
||||
if (!reg) {
|
||||
continue;
|
||||
}
|
||||
for (size_t offset : reg->offsets) {
|
||||
code_w.pput_u8(offset, reg->number);
|
||||
}
|
||||
}
|
||||
|
||||
// Generate function table
|
||||
ssize_t function_table_size = labels_by_index.rbegin()->first + 1;
|
||||
vector<le_uint32_t> function_table;
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ struct PSOQuestHeaderBB {
|
||||
|
||||
Episode episode_for_quest_episode_number(uint8_t episode_number);
|
||||
|
||||
std::string disassemble_quest_script(const void* data, size_t size, Version version, uint8_t language, bool reassembly_mode);
|
||||
std::string disassemble_quest_script(const void* data, size_t size, Version version, uint8_t override_language = 0xFF, bool reassembly_mode = false);
|
||||
std::string assemble_quest_script(const std::string& text);
|
||||
|
||||
Episode find_quest_episode_from_script(const void* data, size_t size, Version version);
|
||||
|
||||
+653
-653
File diff suppressed because it is too large
Load Diff
+113
-113
@@ -1,113 +1,113 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <phosg/JSON.hh>
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
#include "AFSArchive.hh"
|
||||
#include "GSLArchive.hh"
|
||||
#include "ItemNameIndex.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "Text.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
class RareItemSet {
|
||||
public:
|
||||
struct ExpandedDrop {
|
||||
uint32_t probability = 0;
|
||||
ItemData data;
|
||||
|
||||
std::string str() const;
|
||||
std::string str(std::shared_ptr<const ItemNameIndex> name_index) const;
|
||||
};
|
||||
|
||||
RareItemSet();
|
||||
RareItemSet(const AFSArchive& afs, bool is_v1);
|
||||
RareItemSet(const GSLArchive& gsl, bool is_big_endian);
|
||||
RareItemSet(const std::string& rel, bool is_big_endian);
|
||||
RareItemSet(const JSON& json, std::shared_ptr<const ItemNameIndex> name_index = nullptr);
|
||||
~RareItemSet() = default;
|
||||
|
||||
std::vector<ExpandedDrop> get_enemy_specs(GameMode mode, Episode episode, uint8_t difficulty, uint8_t secid, uint8_t rt_index) const;
|
||||
std::vector<ExpandedDrop> get_box_specs(GameMode mode, Episode episode, uint8_t difficulty, uint8_t secid, uint8_t area) const;
|
||||
|
||||
std::string serialize_afs(bool is_v1) const;
|
||||
std::string serialize_gsl(bool big_endian) const;
|
||||
JSON json(std::shared_ptr<const ItemNameIndex> name_index = nullptr) const;
|
||||
|
||||
void multiply_all_rates(double factor);
|
||||
|
||||
void print_collection(
|
||||
FILE* stream,
|
||||
GameMode mode,
|
||||
Episode episode,
|
||||
uint8_t difficulty,
|
||||
uint8_t section_id,
|
||||
std::shared_ptr<const ItemNameIndex> name_index = nullptr) const;
|
||||
void print_all_collections(FILE* stream, std::shared_ptr<const ItemNameIndex> name_index = nullptr) const;
|
||||
|
||||
protected:
|
||||
struct SpecCollection {
|
||||
std::vector<std::vector<ExpandedDrop>> rt_index_to_specs;
|
||||
std::vector<std::vector<ExpandedDrop>> box_area_to_specs;
|
||||
};
|
||||
|
||||
struct ParsedRELData {
|
||||
struct PackedDrop {
|
||||
uint8_t probability = 0;
|
||||
parray<uint8_t, 3> item_code;
|
||||
|
||||
PackedDrop() = default;
|
||||
explicit PackedDrop(const ExpandedDrop&);
|
||||
ExpandedDrop expand() const;
|
||||
} __packed_ws__(PackedDrop, 4);
|
||||
|
||||
template <bool IsBigEndian>
|
||||
struct OffsetsT {
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
/* 00 */ U32T monster_rares_offset; // -> parray<PackedDrop, 0x65> (or 0x33 on v1)
|
||||
/* 04 */ U32T box_count; // Usually 30 (0x1E)
|
||||
/* 08 */ U32T box_areas_offset; // -> parray<uint8_t, 0x1E>
|
||||
/* 0C */ U32T box_rares_offset; // -> parray<PackedDrop, 0x1E>
|
||||
/* 10 */
|
||||
} __packed__;
|
||||
using Offsets = OffsetsT<false>;
|
||||
using OffsetsBE = OffsetsT<true>;
|
||||
check_struct_size(Offsets, 0x10);
|
||||
check_struct_size(OffsetsBE, 0x10);
|
||||
|
||||
struct BoxRare {
|
||||
uint8_t area;
|
||||
ExpandedDrop drop;
|
||||
};
|
||||
|
||||
std::vector<ExpandedDrop> monster_rares;
|
||||
std::vector<BoxRare> box_rares;
|
||||
|
||||
ParsedRELData() = default;
|
||||
ParsedRELData(StringReader r, bool big_endian, bool is_v1);
|
||||
explicit ParsedRELData(const SpecCollection& collection);
|
||||
std::string serialize(bool big_endian, bool is_v1) const;
|
||||
|
||||
template <bool IsBigEndian>
|
||||
void parse_t(StringReader r, bool is_v1);
|
||||
template <bool IsBigEndian>
|
||||
std::string serialize_t(bool is_v1) const;
|
||||
|
||||
SpecCollection as_collection() const;
|
||||
};
|
||||
|
||||
std::unordered_map<uint16_t, SpecCollection> collections;
|
||||
|
||||
const SpecCollection& get_collection(GameMode mode, Episode episode, uint8_t difficulty, uint8_t secid) const;
|
||||
|
||||
static std::string gsl_entry_name_for_table(GameMode mode, Episode episode, uint8_t difficulty, uint8_t section_id);
|
||||
static uint16_t key_for_params(GameMode mode, Episode episode, uint8_t difficulty, uint8_t secid);
|
||||
|
||||
static uint32_t expand_rate(uint8_t pc);
|
||||
static uint8_t compress_rate(uint32_t probability);
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <phosg/JSON.hh>
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
#include "AFSArchive.hh"
|
||||
#include "GSLArchive.hh"
|
||||
#include "ItemNameIndex.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "Text.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
class RareItemSet {
|
||||
public:
|
||||
struct ExpandedDrop {
|
||||
uint32_t probability = 0;
|
||||
ItemData data;
|
||||
|
||||
std::string str() const;
|
||||
std::string str(std::shared_ptr<const ItemNameIndex> name_index) const;
|
||||
};
|
||||
|
||||
RareItemSet();
|
||||
RareItemSet(const AFSArchive& afs, bool is_v1);
|
||||
RareItemSet(const GSLArchive& gsl, bool is_big_endian);
|
||||
RareItemSet(const std::string& rel, bool is_big_endian);
|
||||
RareItemSet(const JSON& json, std::shared_ptr<const ItemNameIndex> name_index = nullptr);
|
||||
~RareItemSet() = default;
|
||||
|
||||
std::vector<ExpandedDrop> get_enemy_specs(GameMode mode, Episode episode, uint8_t difficulty, uint8_t secid, uint8_t rt_index) const;
|
||||
std::vector<ExpandedDrop> get_box_specs(GameMode mode, Episode episode, uint8_t difficulty, uint8_t secid, uint8_t area) const;
|
||||
|
||||
std::string serialize_afs(bool is_v1) const;
|
||||
std::string serialize_gsl(bool big_endian) const;
|
||||
JSON json(std::shared_ptr<const ItemNameIndex> name_index = nullptr) const;
|
||||
|
||||
void multiply_all_rates(double factor);
|
||||
|
||||
void print_collection(
|
||||
FILE* stream,
|
||||
GameMode mode,
|
||||
Episode episode,
|
||||
uint8_t difficulty,
|
||||
uint8_t section_id,
|
||||
std::shared_ptr<const ItemNameIndex> name_index = nullptr) const;
|
||||
void print_all_collections(FILE* stream, std::shared_ptr<const ItemNameIndex> name_index = nullptr) const;
|
||||
|
||||
protected:
|
||||
struct SpecCollection {
|
||||
std::vector<std::vector<ExpandedDrop>> rt_index_to_specs;
|
||||
std::vector<std::vector<ExpandedDrop>> box_area_to_specs;
|
||||
};
|
||||
|
||||
struct ParsedRELData {
|
||||
struct PackedDrop {
|
||||
uint8_t probability = 0;
|
||||
parray<uint8_t, 3> item_code;
|
||||
|
||||
PackedDrop() = default;
|
||||
explicit PackedDrop(const ExpandedDrop&);
|
||||
ExpandedDrop expand() const;
|
||||
} __packed_ws__(PackedDrop, 4);
|
||||
|
||||
template <bool IsBigEndian>
|
||||
struct OffsetsT {
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
/* 00 */ U32T monster_rares_offset; // -> parray<PackedDrop, 0x65> (or 0x33 on v1)
|
||||
/* 04 */ U32T box_count; // Usually 30 (0x1E)
|
||||
/* 08 */ U32T box_areas_offset; // -> parray<uint8_t, 0x1E>
|
||||
/* 0C */ U32T box_rares_offset; // -> parray<PackedDrop, 0x1E>
|
||||
/* 10 */
|
||||
} __packed__;
|
||||
using Offsets = OffsetsT<false>;
|
||||
using OffsetsBE = OffsetsT<true>;
|
||||
check_struct_size(Offsets, 0x10);
|
||||
check_struct_size(OffsetsBE, 0x10);
|
||||
|
||||
struct BoxRare {
|
||||
uint8_t area;
|
||||
ExpandedDrop drop;
|
||||
};
|
||||
|
||||
std::vector<ExpandedDrop> monster_rares;
|
||||
std::vector<BoxRare> box_rares;
|
||||
|
||||
ParsedRELData() = default;
|
||||
ParsedRELData(StringReader r, bool big_endian, bool is_v1);
|
||||
explicit ParsedRELData(const SpecCollection& collection);
|
||||
std::string serialize(bool big_endian, bool is_v1) const;
|
||||
|
||||
template <bool IsBigEndian>
|
||||
void parse_t(StringReader r, bool is_v1);
|
||||
template <bool IsBigEndian>
|
||||
std::string serialize_t(bool is_v1) const;
|
||||
|
||||
SpecCollection as_collection() const;
|
||||
};
|
||||
|
||||
std::unordered_map<uint16_t, SpecCollection> collections;
|
||||
|
||||
const SpecCollection& get_collection(GameMode mode, Episode episode, uint8_t difficulty, uint8_t secid) const;
|
||||
|
||||
static std::string gsl_entry_name_for_table(GameMode mode, Episode episode, uint8_t difficulty, uint8_t section_id);
|
||||
static uint16_t key_for_params(GameMode mode, Episode episode, uint8_t difficulty, uint8_t secid);
|
||||
|
||||
static uint32_t expand_rate(uint8_t pc);
|
||||
static uint8_t compress_rate(uint32_t probability);
|
||||
};
|
||||
|
||||
+5680
-5550
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user