Compare commits
1044 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 81edf93e3b | |||
| 05d508230b | |||
| 27734a6944 | |||
| bf346d3f95 | |||
| 6933a4338b | |||
| 08361ad597 | |||
| fbefb1fb21 | |||
| 08dd67d894 | |||
| de0e56f37c | |||
| 57a5476ff8 | |||
| a211bd07ac | |||
| 5a30272869 | |||
| 4bc5f1b90f | |||
| c0c7bf9b16 | |||
| 6ec41a279e | |||
| 519933c44d | |||
| 9d0ba3a97b | |||
| 2e36cebbcc | |||
| e8d8b94ffa | |||
| 8c2ce5210d | |||
| 13dacc013a | |||
| 85ef84a6d5 | |||
| 08a1bf3238 | |||
| d66c1f5de9 | |||
| ba09188b82 | |||
| 0bb9718da3 | |||
| 04d92d93e5 | |||
| e2f72f3088 | |||
| 22ceb2d1f7 | |||
| 112896bb34 | |||
| 5d71b66f84 | |||
| 7005b573f5 | |||
| 7d95efa803 | |||
| 0a3528b978 | |||
| 78698a0a89 | |||
| 01033287f2 | |||
| 1d8c78166d | |||
| 4e29f22655 | |||
| 31c0a35bb6 | |||
| 9fd19d2676 | |||
| bb89bc9b7b | |||
| 76ad50886f | |||
| 8b1fab916d | |||
| 16bb320ed8 | |||
| 453a05fb8c | |||
| c33af99ae5 | |||
| 8ad27e9001 | |||
| 132daf2c0e | |||
| d39f1eb74c | |||
| 9da756cc14 | |||
| a693fcd48e | |||
| 462f4842aa | |||
| 99fff5baf2 | |||
| 40da9e5604 | |||
| 41c07a3da8 | |||
| 9677d0fca4 | |||
| a674721727 | |||
| aa76631073 | |||
| 3902c64424 | |||
| 226140deb7 | |||
| 812310054c | |||
| 5673de78be | |||
| 32af88cd9b | |||
| 3bb8ac5c43 | |||
| ea7f655408 | |||
| 948985b057 | |||
| 8df36ea3c2 | |||
| e723e80171 | |||
| 29dd0caaab | |||
| 30394e7120 | |||
| eee420f2e1 | |||
| 065c11ac90 | |||
| 6bebcc841e | |||
| c2b2239df0 | |||
| abd87054ac | |||
| 07b1e9cde3 | |||
| d5cc91a9bf | |||
| 9fd90ee324 | |||
| 8a6a7fb47f | |||
| f77e21800c | |||
| 2478f18298 | |||
| bb1c0f1d1a | |||
| 9cf53c85a2 | |||
| ab5d8e4522 | |||
| e4bb5bc28c | |||
| 1cb0d5bcec | |||
| 88d887a58a | |||
| 77f64d3496 | |||
| cdb3943d9f | |||
| 532bcab0b6 | |||
| ab3c27772e | |||
| 682632f1c5 | |||
| 6850bc0e06 | |||
| 6368ebcd71 | |||
| a23dabd58e | |||
| da37fc1fee | |||
| 15c08c0101 | |||
| 7e84a5cb6a | |||
| 3c4019f705 | |||
| 040356d365 | |||
| f0c339e040 | |||
| 38aaffd4bd | |||
| e81e60b543 | |||
| da48712449 | |||
| ceefe44b96 | |||
| bc22327361 | |||
| 37c4cbd8f3 | |||
| d90fc2a543 | |||
| 2dca523a4b | |||
| 4aa156a322 | |||
| e9b6b681bd | |||
| 8cf0b9f947 | |||
| bbe42b765c | |||
| 507b2fbcac | |||
| 5fe21b8eec | |||
| d488ccd100 | |||
| 403c17b42d | |||
| a0ff0cf8e7 | |||
| feded3e891 | |||
| 74307ea7a2 | |||
| 45ea21860d | |||
| 6a6fb91acb | |||
| 8aaadf81ac | |||
| 1f34b6bb90 | |||
| fbdfdb085a | |||
| 5c5da8e10b | |||
| 103e5325a3 | |||
| 02584e4458 | |||
| 263e9114c5 | |||
| fed50aec6b | |||
| b9057cf562 | |||
| 63f6aff4ed | |||
| a4961ad69d | |||
| f0bd2c7aa6 | |||
| ac13bf13b2 | |||
| 98dc2af278 | |||
| b7ceeb029a | |||
| f036f137f7 | |||
| 187bfa1756 | |||
| 5e14a8449c | |||
| 65f8dea0da | |||
| 995a05c409 | |||
| 885d125fc4 | |||
| 949ad0d260 | |||
| 9272feff8f | |||
| 058b040975 | |||
| 8b544830a0 | |||
| 0c2ecd4ebb | |||
| 6b5e672ebb | |||
| 7f7aaf920b | |||
| 5c48c75fdc | |||
| 2846e73710 | |||
| 2ee1891153 | |||
| cc70280761 | |||
| 85897baaeb | |||
| 14973f7453 | |||
| fe984a4284 | |||
| 99b508a256 | |||
| 6e522459ae | |||
| be0e616df7 | |||
| 1bf3e6869d | |||
| 0df670893f | |||
| de9d52b352 | |||
| 3542200379 | |||
| 82c877f55d | |||
| 19499bf23d | |||
| 4cf1895f4d | |||
| aa25f7e79a | |||
| 93906f8ff3 | |||
| 931258e8ac | |||
| 5b907d4413 | |||
| a8c7da70e0 | |||
| 3682c082ea | |||
| de110a1c88 | |||
| 7e4664ea25 | |||
| 3d0a842496 | |||
| 64bbeb0f70 | |||
| 2eb429436f | |||
| adad870aff | |||
| ecaea3fe49 | |||
| 4f16243e41 | |||
| 7706adc7cb | |||
| 3cf39887e8 | |||
| c65b012ea5 | |||
| ed97279436 | |||
| 9cb9e8064a | |||
| 80b9af46db | |||
| 83ecbf77ab | |||
| 8952a4d56b | |||
| 4575adea11 | |||
| 9e8a59798c | |||
| bb92feb9a5 | |||
| 72155939d5 | |||
| 3c1c63f24e | |||
| ef7f5fb798 | |||
| 49be421ff4 | |||
| e27bce9313 | |||
| fbe621173f | |||
| ae518eaaf6 | |||
| e858b79b33 | |||
| 04c34e1b22 | |||
| f799cfe87c | |||
| 24f3ddef40 | |||
| 30e1aacaf0 | |||
| 4741091b9f | |||
| 4ddc4fce1d | |||
| 1d45c18ce8 | |||
| 5caa21bccb | |||
| 9cef4a14f8 | |||
| 27081bd3da | |||
| 2115f188d1 | |||
| bf55da55bf | |||
| 550b62dec9 | |||
| 215c181798 | |||
| 2f663ef2b3 | |||
| b07748d07f | |||
| f708ecc035 | |||
| fb52047e7c | |||
| a8d09363f1 | |||
| 15566f7143 | |||
| 7657d4f2fc | |||
| d843a54245 | |||
| df013784fc | |||
| 1f6f76a6dc | |||
| b885442a4b | |||
| e64fa10a58 | |||
| 66ca3ed6dd | |||
| 013e099f50 | |||
| debc920997 | |||
| 80f79aa13c | |||
| 7585eaeae5 | |||
| 52ed062ed9 | |||
| 753b89c78d | |||
| fa48b58773 | |||
| aa48dd5e15 | |||
| 0863c4f27c | |||
| f12fdaf165 | |||
| e890bfad63 | |||
| f8198580dd | |||
| a40d1ad851 | |||
| 901b2b78d2 | |||
| 24439a9dc3 | |||
| 4498fe1232 | |||
| b9fc225786 | |||
| c430340c9d | |||
| 9c3f764cd9 | |||
| 9dcdece1f9 | |||
| d663472aae | |||
| 245ebd92c6 | |||
| c1ed1afa5b | |||
| 39e491eb1e | |||
| 15b9c05004 | |||
| cfa4e3b8b0 | |||
| bd6102a894 | |||
| c45b4cced7 | |||
| 548aca8cc0 | |||
| 75fab887e1 | |||
| d2a589d968 | |||
| 71d3d4e27c | |||
| 74ff094012 | |||
| bbab6968d1 | |||
| af781dbc09 | |||
| f771643880 | |||
| 2b2d8dfb3d | |||
| 66f584d475 | |||
| 3b69d3484d | |||
| 013a19885f | |||
| 3a7277bc5d | |||
| 9f943cf5d8 | |||
| c3edb93248 | |||
| 5712ff3e3e | |||
| 2cb2dd3b24 | |||
| da431cc174 | |||
| 7c6a1e730e | |||
| 85dbea215b | |||
| 8449a6d21a | |||
| 2eda283f8f | |||
| ba7951a9f4 | |||
| e566a247e4 | |||
| 5b038364a1 | |||
| ee7c574fdf | |||
| 02b0bf622c | |||
| 39d1b338b7 | |||
| b27b458557 | |||
| f642e2f5a8 | |||
| 50ded155ed | |||
| eab453413e | |||
| 2304a17dd0 | |||
| be4837cccf | |||
| 2235103efe | |||
| 466eb49c55 | |||
| a842880123 | |||
| 897ff4c9ff | |||
| d93866146a | |||
| 1d0c0088d6 | |||
| 99a8ab3a21 | |||
| c944c7bca0 | |||
| 39330bc6f2 | |||
| 300d3cd825 | |||
| 8adbe38617 | |||
| dd5ef0c8a4 | |||
| 27b368c2fb | |||
| 107ffb0997 | |||
| 36186578f8 | |||
| 52b21f8b88 | |||
| b9912ad80f | |||
| 666464dd06 | |||
| c0f4f7af5f | |||
| 102fe92c3a | |||
| 87118049ab | |||
| 7e55719983 | |||
| 9b66e07c06 | |||
| f657012d8e | |||
| 1f674b9c34 | |||
| 6192270040 | |||
| 2574c74e6b | |||
| 0ea3993103 | |||
| 2cd1038468 | |||
| c7c2d54183 | |||
| c57b031156 | |||
| 6d4430da13 | |||
| 7d37a58e6e | |||
| a3f3608f76 | |||
| f13609c02b | |||
| d2b2e1f978 | |||
| 825cd1fcb7 | |||
| 48a6dae50c | |||
| 911b17df7e | |||
| 308c58e761 | |||
| 6c69828f1a | |||
| 194f7b6275 | |||
| 132b8b071f | |||
| f563d5d873 | |||
| 668c9f9457 | |||
| 8cd1106818 | |||
| 4858ccd812 | |||
| 64e637dbfb | |||
| 419d3500bd | |||
| 0d9bfa966d | |||
| acba5c670f | |||
| 73a68911e8 | |||
| b1531139c0 | |||
| 7dd00c75a9 | |||
| 4284d163d8 | |||
| ba5aad0296 | |||
| ea60cfb507 | |||
| b6052620be | |||
| 0df83632d0 | |||
| b8f7d8f554 | |||
| 01d0203de6 | |||
| 97daebdf83 | |||
| acfa708332 | |||
| 3e22d31c42 | |||
| d2d1ae723d | |||
| e34c9856ec | |||
| ff9305144b | |||
| 12c4e66cc2 | |||
| 1c9239bade | |||
| 80ae6ecac8 | |||
| 90f1df105b | |||
| a409ee696c | |||
| 81049d2765 | |||
| a81793f695 | |||
| 9916fb946d | |||
| 4442ca0250 | |||
| b324173d8e | |||
| b5635f50f8 | |||
| a8e7caa0b3 | |||
| de14d61835 | |||
| 9acb542689 | |||
| af56b6d2c6 | |||
| aced59ea7a | |||
| 42c5c496dc | |||
| cd367fe5bd | |||
| 160cf24642 | |||
| 8656222be3 | |||
| e1b4bd32c9 | |||
| fcc43e24c5 | |||
| 12f8e44cb4 | |||
| 4793b072ae | |||
| 4190a9e03d | |||
| 9602773021 | |||
| d6f8fb8917 | |||
| fba31bfc8d | |||
| 8b4f353182 | |||
| a3a1396e6c | |||
| fd4138c7cc | |||
| 476e22b368 | |||
| 40ed4c9c9a | |||
| 13c061323c | |||
| 16bfaf8910 | |||
| 4bbb31b0c6 | |||
| cbe6480da6 | |||
| 63538088d2 | |||
| 0d3da65ca7 | |||
| d65615da16 | |||
| d7b1e66f88 | |||
| 912fec458f | |||
| 5c9242a156 | |||
| 15954c9576 | |||
| 52e6dafad1 | |||
| 5842d70094 | |||
| 9a6c0b6c9a | |||
| 8db058871f | |||
| 26dc50930b | |||
| 6468af6eb7 | |||
| e8fcf2884a | |||
| 8926c22eae | |||
| 46dd11fab0 | |||
| 2b3cc6bcdf | |||
| 2de37a4733 | |||
| 10dfd8aa5c | |||
| 1291de4387 | |||
| d7bb3b3576 | |||
| 24c5ad1d06 | |||
| dcbfeebc37 | |||
| bcaa2a493e | |||
| f2f8d64d44 | |||
| 7ac7d7c360 | |||
| 9995f9cca8 | |||
| 10ab688207 | |||
| f333a88aaf | |||
| aead8aae71 | |||
| 3226efab1e | |||
| 036049a13f | |||
| 5ebf73779c | |||
| bfe8391cc9 | |||
| 4904c356f7 | |||
| 71ebf01b0b | |||
| 1a72f7c90a | |||
| 6224479d76 | |||
| e18c3fc43d | |||
| 276284cd39 | |||
| 8c183a6f0c | |||
| 8c6ccd1cfe | |||
| 47f07bbc51 | |||
| c053d87a6c | |||
| 9f78790e14 | |||
| 148d327d9f | |||
| 53a9b527e4 | |||
| 3ef2f76705 | |||
| 95346118f0 | |||
| a963c3316c | |||
| 0c12e6c4bc | |||
| 65c08667cc | |||
| 0386d14638 | |||
| ee837712aa | |||
| 27e95ee343 | |||
| 25b6c594bd | |||
| d6eee92645 | |||
| d60404ff0a | |||
| e1f584984f | |||
| 368d6ad93b | |||
| 615ea8d7b0 | |||
| 5ab2a215b5 | |||
| db282cb533 | |||
| 5e93076243 | |||
| c4153f5f6e | |||
| 2c95782687 | |||
| 3cd13863cb | |||
| bdb0c05220 | |||
| afd93047c1 | |||
| 54a734e049 | |||
| 9ec72212cf | |||
| 5cba72934f | |||
| cf3a09a241 | |||
| 4ae23f4eff | |||
| de3ea6b850 | |||
| dbd6c59a0b | |||
| 03c26b587a | |||
| 7ae87f9949 | |||
| 81d0353144 | |||
| 780dbd769c | |||
| 695e53a714 | |||
| f813ed68df | |||
| a7b3c496d0 | |||
| 65813b7170 | |||
| fc672978d8 | |||
| 90a3be7803 | |||
| 8dc5e9f281 | |||
| 6654030bd3 | |||
| 4f2e333d6c | |||
| 617cf73c5e | |||
| 42fa3955d8 | |||
| 4509d9f37b | |||
| 91e484e514 | |||
| b733f4e199 | |||
| 31ecf917af | |||
| f954a7f834 | |||
| 42e2301a8e | |||
| 35845ea49b | |||
| c4e3eb238f | |||
| e98d01d7e9 | |||
| b6f71fffbf | |||
| 38469119ad | |||
| e56d572585 | |||
| 58011c5a00 | |||
| 42a4a599dc | |||
| 5e05b3d11f | |||
| a06aa2f1fa | |||
| 3b9a76eec8 | |||
| 06ba95ed97 | |||
| be83cafe0d | |||
| 0007a1af56 | |||
| a7dbfd9781 | |||
| 2ed6427773 | |||
| dd1c5a2d0c | |||
| b4946f5f1e | |||
| 4c248c5ee5 | |||
| b58f354c41 | |||
| dcebc61b13 | |||
| c48a998750 | |||
| b281eecfee | |||
| 40ca249b8a | |||
| 077bfb2e7d | |||
| fadc0e9f71 | |||
| 3dda420c3a | |||
| 618d9180cd | |||
| 032f0bb2c5 | |||
| f92822fff0 | |||
| 7426c5ad1f | |||
| 45cac5a084 | |||
| 5ef5ddcbae | |||
| 59bfa66dad | |||
| 711bbf0a21 | |||
| 2291d758ac | |||
| dc7277a2a4 | |||
| 2f19f5ce0b | |||
| cf0902b6ed | |||
| eebffc0d13 | |||
| 60dd22a7f6 | |||
| dc9112dfdd | |||
| f45a76af13 | |||
| 47ac90ea6b | |||
| f05641a8b9 | |||
| cfcdd6acad | |||
| a3249ab19b | |||
| 7af363fec4 | |||
| 4ba5689b25 | |||
| 838e53a91e | |||
| 6cdbc3e8e0 | |||
| 30cc5fbb44 | |||
| b935760d64 | |||
| 2932488d00 | |||
| 612f305c3a | |||
| 61a9a0ce8d | |||
| 159f80cce3 | |||
| a35d835f31 | |||
| 3418afcc66 | |||
| d5ececfa87 | |||
| aea43781ea | |||
| 707b021c88 | |||
| 5e07075977 | |||
| 85072e9db9 | |||
| 2fcc77772f | |||
| 8b4785eb36 | |||
| ef0f33351a | |||
| c5f05de082 | |||
| 2c5f0ea904 | |||
| f45516d359 | |||
| be6cff7b89 | |||
| 6fde0f186f | |||
| c3aca29d9c | |||
| 94bbd5685e | |||
| 4a4f06e9ac | |||
| 34afd42391 | |||
| 6e80ccca54 | |||
| a485c25eb8 | |||
| fe5a15a1ab | |||
| 203a2aaeb4 | |||
| 78968f86dd | |||
| f1a64e6dbf | |||
| 215f5deff6 | |||
| 2b959386d7 | |||
| b3ab759717 | |||
| 1595555b53 | |||
| fdee74195b | |||
| bac429af94 | |||
| 8f0a33eb77 | |||
| c7009569b7 | |||
| 0250e3c9e5 | |||
| fdf7af20bc | |||
| 4ed641e6f4 | |||
| 9ff23b2aee | |||
| 34812d5037 | |||
| 79b0e82c50 | |||
| 43395492b2 | |||
| 97172717da | |||
| 078fd4ac08 | |||
| fc6a26ee38 | |||
| 32c08032c5 | |||
| 138d2609a2 | |||
| 37438c94c7 | |||
| ca551039ce | |||
| bfdb6c0695 | |||
| 1394dd681e | |||
| ba4a017ffb | |||
| d5773b93da | |||
| bebb69649c | |||
| 4946978ed7 | |||
| 1eba82c739 | |||
| ef11592439 | |||
| 6955b7ea0c | |||
| 95c1b4b6e8 | |||
| 3bb061951d | |||
| 649246cda2 | |||
| ca439c7a0f | |||
| e9899a33a2 | |||
| 6ced274108 | |||
| 6ffeda93a7 | |||
| c45246c1b5 | |||
| 8582e18861 | |||
| ed770a8b74 | |||
| 3cf309a008 | |||
| d1a830040f | |||
| 64d7ec5cde | |||
| 77f919980a | |||
| c5f4f2907e | |||
| 0ffa03d2b6 | |||
| 1fdbcd6c4e | |||
| ec453d1fa8 | |||
| a631fd50b4 | |||
| 8affe23c0d | |||
| 8cf11b3c48 | |||
| c39e60af8b | |||
| 194ed550e1 | |||
| ef0b72e95b | |||
| f3481fbd9f | |||
| 39d394cfae | |||
| 1b0f6cccf6 | |||
| 37c8491dc3 | |||
| e364ce2d9c | |||
| 15bbaa0837 | |||
| edf234c0ff | |||
| 4b63475662 | |||
| 4da71e127d | |||
| 9d688c2092 | |||
| d669f7ce6c | |||
| b02c82bb0d | |||
| a4f52b9b22 | |||
| 9b136d9444 | |||
| 7a5e759d9a | |||
| f923f51c22 | |||
| 133ca0b3cc | |||
| a937e50681 | |||
| b5b7345e5f | |||
| 61751d681e | |||
| 9ac01875fb | |||
| d076838747 | |||
| 8c5160e36f | |||
| e77228fa97 | |||
| 517a735ab2 | |||
| 353614e65c | |||
| d337517317 | |||
| 3c7b652f3a | |||
| cb11677214 | |||
| 1dbdd3f191 | |||
| 007e439281 | |||
| 350afbb436 | |||
| 08386c4019 | |||
| f57f903207 | |||
| 6727a25df0 | |||
| a57b6ce57b | |||
| b52700c08e | |||
| 68abac4fd4 | |||
| 52db9008a8 | |||
| eb2463a820 | |||
| dfad80eb9a | |||
| de7239e3fb | |||
| d6256183b5 | |||
| dbfb088630 | |||
| 3bb33a4de7 | |||
| 5a25c3e865 | |||
| 007359e220 | |||
| 5094db1306 | |||
| be5d85fa04 | |||
| 2ff3f8b4fb | |||
| 090379e520 | |||
| f3dfa0989f | |||
| c8b89a7cad | |||
| 1042b8df46 | |||
| afacf72034 | |||
| 53938cf6a6 | |||
| f2751a4e49 | |||
| 7c98f42722 | |||
| 5175c50945 | |||
| 13c438273b | |||
| 99c8d9957a | |||
| a28ef86c60 | |||
| aa19fd347e | |||
| e5a9b1f330 | |||
| 2eb4770bdd | |||
| a6ac56943c | |||
| d288fca087 | |||
| 889913400a | |||
| 5e2a42d852 | |||
| abd2fb9e92 | |||
| 5625999a90 | |||
| 08dfbbcb5c | |||
| 224e0df87e | |||
| 1bb0545b21 | |||
| 27cdf7e078 | |||
| c01d1f623c | |||
| 7612621fe9 | |||
| fa95a2f6d8 | |||
| 0b17b7174f | |||
| cf2f1ef529 | |||
| ae49ca0189 | |||
| 79374d3dd1 | |||
| 846401469e | |||
| 6f11410107 | |||
| 025556ecd3 | |||
| 5bcd16b6f2 | |||
| d52b882679 | |||
| 0d7f69eb66 | |||
| 391a70f68d | |||
| e858b2101d | |||
| ed2568fc7a | |||
| 9a2ed4c5ec | |||
| 398a93b56f | |||
| cceaf5efde | |||
| 14639c63e3 | |||
| 2ee7ca8600 | |||
| e800fd3fff | |||
| fb4aa0df22 | |||
| b0a32600be | |||
| 12caf95f5d | |||
| c3192bb398 | |||
| 8323c5e0af | |||
| bdff48c343 | |||
| 5f04cbaecb | |||
| 93f42a9398 | |||
| 2eacaa993e | |||
| 9bb168b693 | |||
| 9a1ba56982 | |||
| 8c2ea48b80 | |||
| d4115450b2 | |||
| fd8f968994 | |||
| 7634e61400 | |||
| 1a7981dff5 | |||
| c3c6f60664 | |||
| 421f27d63c | |||
| c314cb7cec | |||
| 9f4b53178a | |||
| 85fbd1b389 | |||
| 4f57ea30a1 | |||
| 1ea44ac55c | |||
| d44be66958 | |||
| 1a5d2537ad | |||
| f68308a242 | |||
| f622c9c91e | |||
| 0828029051 | |||
| 2e3089cb10 | |||
| f8da4ac7be | |||
| b82be91edd | |||
| 0870d66806 | |||
| 8efc9f1b3e | |||
| 95b4d34593 | |||
| 2819798791 | |||
| dc319e3a5d | |||
| 53efff5c4a | |||
| 37153fae79 | |||
| 81dcc14934 | |||
| 41a858935b | |||
| 9f2f0ccc14 | |||
| 8481ba23c5 | |||
| 3e8fa44be9 | |||
| 9dfaad9ae8 | |||
| ad3d9869ed | |||
| 85bdb1a7a2 | |||
| 759442ee62 | |||
| 51c13b8462 | |||
| 17496ab9fe | |||
| 690d4bdb14 | |||
| fd0ba1bbf6 | |||
| e321fd5bca | |||
| 7be3aad58b | |||
| b4410594b0 | |||
| 94e6ba2a91 | |||
| 5998fee2a7 | |||
| cb1e405a66 | |||
| dab83f27d3 | |||
| 92c51830bb | |||
| 846100cf16 | |||
| b0edffdef1 | |||
| debca5aad4 | |||
| 1421e633be | |||
| a0a802f42f | |||
| 247904f019 | |||
| 10ab632c59 | |||
| 51ccecf1bd | |||
| dedea228b1 | |||
| 3e74bde880 | |||
| 0a1eb5f0d7 | |||
| ed81599cc9 | |||
| 2ce9e58177 | |||
| 52625aed9c | |||
| 9140b04ca6 | |||
| c9e5d1f677 | |||
| 0e53ea08ba | |||
| 378fd0521e | |||
| 4edcbc5d4d | |||
| 14837447a3 | |||
| 23a0424acf | |||
| 4f63d3672e | |||
| 0033cb2eda | |||
| 239ffd1323 | |||
| f18953c31e | |||
| f088454c25 | |||
| 48905bfa10 | |||
| 830a151db7 | |||
| 5b3a94f018 | |||
| 1cb14b48c9 | |||
| 3d036404f7 | |||
| 4eb46b293e | |||
| 026befe6ac | |||
| d9413b3559 | |||
| e14a4f83db | |||
| ba928306ba | |||
| d5154f0a5d | |||
| 7ffa043941 | |||
| 513fab03c8 | |||
| e2525ffd36 | |||
| 9e161d99cf | |||
| 6a0df79fad | |||
| ce87348bf5 | |||
| 50e1b79b1e | |||
| a16c207f4d | |||
| f6987d6627 | |||
| 1c6ba33be3 | |||
| 63958b7c5d | |||
| 7ed0866c2b | |||
| 333fc803ce | |||
| 32176caff8 | |||
| 73278fe9ab | |||
| 5ec90db9eb | |||
| 6afc029152 | |||
| 44e28fd906 | |||
| 0969a6eb1d | |||
| 8d206133a3 | |||
| e4b5fbf2ba | |||
| 867f86da5e | |||
| e273629cd1 | |||
| bc071155b0 | |||
| 295bb9c4a4 | |||
| c9d62e26ef | |||
| c8cb3e61f7 | |||
| 0b85f46ce2 | |||
| a01472666c | |||
| 613789057f | |||
| dbf44e60ff | |||
| a8f888b829 | |||
| 125c8f910c | |||
| 27bccc5571 | |||
| 1a477b28a0 | |||
| fbc0eaeaa1 | |||
| 96caa94d1e | |||
| 95220bfbdc | |||
| cd01848eb9 | |||
| 34cde304dc | |||
| 0951132c01 | |||
| 7d950e01ab | |||
| e73fb2fbba | |||
| 8f2bf60d62 | |||
| bdc60ac601 | |||
| 6e6b161847 | |||
| d4d7797741 | |||
| 110db06191 | |||
| a9cf98a24f | |||
| 9524d05279 | |||
| c43fa7a40d | |||
| 5d314f4e96 | |||
| 29fc74470d | |||
| 7bcb040e8d | |||
| afba535e00 | |||
| 152a90a37b | |||
| e998cb4a92 | |||
| 79dde31d7f | |||
| a1c86189e4 | |||
| 8afc952294 | |||
| 30426acbbe | |||
| 38117390f7 | |||
| fb08c45cb7 | |||
| 58aef33edc | |||
| e7a821bcba | |||
| dcf89865f5 | |||
| 5b93ac046f | |||
| 481b9b3040 | |||
| 34d32418e3 | |||
| b9902f6189 | |||
| 1b949c67da | |||
| 1a3dd26cb3 | |||
| 42d12e2a18 | |||
| 19b093cfc5 | |||
| 425338877d | |||
| 764a930213 | |||
| f166dae1c6 | |||
| 176e0fb6d6 | |||
| 60bb758bc4 | |||
| 3e5a961b68 | |||
| 0180296c49 | |||
| 8937333a2b | |||
| 861d4e432a | |||
| c46db6eccd | |||
| 9a35f5ca63 | |||
| 89285fef98 | |||
| b6d6474356 | |||
| 010f753a08 | |||
| 3a7c3c0fe9 | |||
| 01e4518c8e | |||
| 47c2269fca | |||
| 507af79203 | |||
| 74fdf3cdeb | |||
| e0b0ff989a | |||
| e8f79628ca | |||
| 6eb77a7193 | |||
| 1ed06283a2 | |||
| 0908ba5599 | |||
| 8ef18eab13 | |||
| d2bcc5d261 | |||
| f59347c5c2 | |||
| bca76322bf | |||
| dc278a7843 | |||
| 34b70a8a03 | |||
| 7380b34d9d | |||
| 5d3d1e1900 | |||
| 4abd91cb8f | |||
| 56494f7e9d | |||
| 5ede882715 | |||
| b612d50c17 | |||
| eaf1ad036c | |||
| c5375c11aa | |||
| 77cea58fc5 | |||
| e808a7b6a3 | |||
| 4066f80407 | |||
| 7cce105a09 | |||
| 202427e331 | |||
| 2a7fdceba9 | |||
| 6af3a8e8cd | |||
| 1fdf258e7f | |||
| 3e14bc306f | |||
| c592542f07 | |||
| d2b9023cfc | |||
| 716825ffaf | |||
| 907883d176 | |||
| a0d994962f | |||
| a6442c6208 | |||
| 8bff95052c | |||
| 8c82fccb5b | |||
| c1ea579758 | |||
| 25c68ef43c | |||
| d006359f87 | |||
| 39c7b37a84 | |||
| 50643df49e | |||
| c62f1e9fa0 | |||
| 69d2c6d95c | |||
| b4780a80a8 | |||
| e958753a09 | |||
| aa8cf5fd1b | |||
| 7a1eb677dc | |||
| 9b837c5b6c | |||
| 176641aebe | |||
| 80bac6c89e | |||
| c43c023b4b | |||
| 293cc86092 | |||
| 09f0d1f3de | |||
| 8f75823f7d | |||
| 42c1d251eb | |||
| ed36471a4e | |||
| 1164f99957 | |||
| 8c7cee8fd5 | |||
| 442f33733d | |||
| 286997188e | |||
| f4517ab92e | |||
| 7c28ee05cc | |||
| 8ac15c9aa3 | |||
| 431cd480e8 | |||
| 2cb49030f0 | |||
| cf59858e1e | |||
| b901e8846d | |||
| 174c53d751 | |||
| 89cb07a376 | |||
| 4b666a079b | |||
| 0ebf2ba8ef | |||
| 2fe51519d4 | |||
| 7f7137ed81 | |||
| ecf02943d4 | |||
| ca2c17360d | |||
| ea62275f89 | |||
| 415aa88bd3 | |||
| e6b05196fd | |||
| 02e98008d3 | |||
| ce2cf1b56b | |||
| 22c36b4874 | |||
| ec205062ad | |||
| d61c65cf16 | |||
| 7461d36cb8 | |||
| 7983f71159 | |||
| 4c20097de7 | |||
| df80933f40 | |||
| 52a853092c | |||
| 515a0b70be | |||
| a2e53b2b33 | |||
| 8d16ff7e7c | |||
| 8f64c2f3ba | |||
| 309a347312 | |||
| 0d57bee368 | |||
| c3ccd74e80 | |||
| e55cf3bc7c | |||
| 4163f2affa | |||
| 5f836711c7 | |||
| 37b7119ea5 | |||
| f43a7c9277 | |||
| 2590a2f24b | |||
| ff7031544a | |||
| 34ab156451 | |||
| 0a115427a1 | |||
| abe64af17b | |||
| 39942dc4bd | |||
| 41d03670d6 | |||
| b031f2e8ad | |||
| 5dba862117 | |||
| 9cf306b73c | |||
| a8fb7a2eda | |||
| 0327e242fc | |||
| 10cb76aefd | |||
| 949a651be1 | |||
| e5227080b8 | |||
| 58f0501010 | |||
| b0319d34a0 | |||
| 070db173dd | |||
| 2394a330ff | |||
| d5308449e3 | |||
| f823c2b907 | |||
| a7e3d4853a | |||
| 38b0539124 | |||
| d543db187f | |||
| 3b1f4f4324 | |||
| 2bb3118c1a | |||
| 7064821ac5 | |||
| 9f81041dc7 | |||
| a81df27bc9 | |||
| 38ca60bcbe | |||
| 6b958c9f25 |
@@ -0,0 +1,28 @@
|
||||
Standard: c++20
|
||||
BasedOnStyle: LLVM
|
||||
IndentWidth: 2
|
||||
ColumnLimit: 0
|
||||
AccessModifierOffset: -2
|
||||
NamespaceIndentation: None
|
||||
BreakBeforeBraces: Custom
|
||||
PointerAlignment: Left
|
||||
IndentCaseLabels: true
|
||||
PackConstructorInitializers: CurrentLine
|
||||
BraceWrapping:
|
||||
AfterEnum: false
|
||||
AfterStruct: false
|
||||
AfterClass: false
|
||||
SplitEmptyFunction: false
|
||||
AfterControlStatement: false
|
||||
AfterNamespace: false
|
||||
AfterFunction: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: false
|
||||
AlignTrailingComments: false
|
||||
AlignAfterOpenBracket: DontAlign
|
||||
AlignOperands: DontAlign
|
||||
AlignEscapedNewlines: Left
|
||||
@@ -54,4 +54,4 @@ jobs:
|
||||
|
||||
- name: Test
|
||||
working-directory: ${{github.workspace}}/build
|
||||
run: ctest -C ${{env.BUILD_TYPE}}
|
||||
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure
|
||||
|
||||
+20
-3
@@ -5,17 +5,34 @@
|
||||
newserv
|
||||
|
||||
# CMake files
|
||||
cmake_install.cmake
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
Makefile
|
||||
CTestTestFile.cmake
|
||||
Testing
|
||||
cmake_install.cmake
|
||||
install_manifest.txt
|
||||
Makefile
|
||||
Testing
|
||||
|
||||
# Files modified by the user and/or server that don't have defaults
|
||||
system/config.json
|
||||
system/ep3/battle-records/*.mzrd
|
||||
system/ep3/tournament-state.json
|
||||
system/licenses.nsi
|
||||
system/licenses/*.json
|
||||
system/players/player_*
|
||||
system/players/account_*
|
||||
system/players/bank_*
|
||||
system/patch-pc/.metadata-cache.json
|
||||
system/patch-bb/.metadata-cache.json
|
||||
|
||||
# Files fuzziqersoftware uses that don't make sense to be committed to the main
|
||||
# repository
|
||||
files
|
||||
make_release.py
|
||||
old-khyller
|
||||
old-newserv
|
||||
release
|
||||
release.zip
|
||||
system/patch-bb/data
|
||||
system/patch-bb/psobb.pat
|
||||
system/dol
|
||||
|
||||
+102
-54
@@ -14,10 +14,11 @@ else()
|
||||
add_compile_options(-Wall -Wextra -Werror -Wno-address-of-packed-member)
|
||||
endif()
|
||||
|
||||
include_directories("/usr/local/include")
|
||||
link_directories("/usr/local/lib")
|
||||
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
set(LOCAL_INCLUDE_DIR "/usr/local/include")
|
||||
set(LOCAL_LIB_DIR "/usr/local/lib")
|
||||
list(APPEND CMAKE_PREFIX_PATH ${LOCAL_LIB_DIR})
|
||||
include_directories(${LOCAL_INCLUDE_DIR})
|
||||
link_directories(${LOCAL_LIB_DIR})
|
||||
|
||||
|
||||
|
||||
@@ -31,70 +32,117 @@ set (LIBEVENT_LIBRARIES
|
||||
${LIBEVENT_LIBRARY}
|
||||
${LIBEVENT_CORE})
|
||||
|
||||
find_path (RESOURCE_FILE_INCLUDE_DIR NAMES resource_file/ResourceFile.hh)
|
||||
find_library (RESOURCE_FILE_LIBRARY NAMES resource_file)
|
||||
|
||||
if(RESOURCE_FILE_INCLUDE_DIR AND RESOURCE_FILE_LIBRARY)
|
||||
set(RESOURCE_FILE_FOUND 1)
|
||||
else()
|
||||
set(RESOURCE_FILE_FOUND 0)
|
||||
endif()
|
||||
find_package(phosg REQUIRED)
|
||||
find_package(resource_file QUIET)
|
||||
|
||||
|
||||
|
||||
# Executable definition
|
||||
|
||||
add_executable(newserv
|
||||
src/Channel.cc
|
||||
src/ChatCommands.cc
|
||||
src/Client.cc
|
||||
src/Compression.cc
|
||||
src/DNSServer.cc
|
||||
src/Episode3.cc
|
||||
src/FileContentsCache.cc
|
||||
src/FunctionCompiler.cc
|
||||
src/IPFrameInfo.cc
|
||||
src/IPStackSimulator.cc
|
||||
src/Items.cc
|
||||
src/LevelTable.cc
|
||||
src/License.cc
|
||||
src/Lobby.cc
|
||||
src/Main.cc
|
||||
src/Map.cc
|
||||
src/Menu.cc
|
||||
src/NetworkAddresses.cc
|
||||
src/Player.cc
|
||||
src/ProxyCommands.cc
|
||||
src/ProxyServer.cc
|
||||
src/PSOEncryption.cc
|
||||
src/PSOProtocol.cc
|
||||
src/Quest.cc
|
||||
src/RareItemSet.cc
|
||||
src/ReceiveCommands.cc
|
||||
src/ReceiveSubcommands.cc
|
||||
src/SendCommands.cc
|
||||
src/Server.cc
|
||||
src/ServerShell.cc
|
||||
src/ServerState.cc
|
||||
src/Shell.cc
|
||||
src/StaticGameData.cc
|
||||
src/Text.cc
|
||||
src/Version.cc
|
||||
src/AFSArchive.cc
|
||||
src/BattleParamsIndex.cc
|
||||
src/BMLArchive.cc
|
||||
src/CatSession.cc
|
||||
src/Channel.cc
|
||||
src/ChatCommands.cc
|
||||
src/Client.cc
|
||||
src/CommonItemSet.cc
|
||||
src/Compression.cc
|
||||
src/DCSerialNumbers.cc
|
||||
src/DNSServer.cc
|
||||
src/EnemyType.cc
|
||||
src/Episode3/AssistServer.cc
|
||||
src/Episode3/BattleRecord.cc
|
||||
src/Episode3/Card.cc
|
||||
src/Episode3/CardSpecial.cc
|
||||
src/Episode3/DataIndexes.cc
|
||||
src/Episode3/DeckState.cc
|
||||
src/Episode3/MapState.cc
|
||||
src/Episode3/PlayerState.cc
|
||||
src/Episode3/PlayerStateSubordinates.cc
|
||||
src/Episode3/RulerServer.cc
|
||||
src/Episode3/Server.cc
|
||||
src/Episode3/Tournament.cc
|
||||
src/FileContentsCache.cc
|
||||
src/FunctionCompiler.cc
|
||||
src/GSLArchive.cc
|
||||
src/GVMEncoder.cc
|
||||
src/IPFrameInfo.cc
|
||||
src/IPStackSimulator.cc
|
||||
src/ItemCreator.cc
|
||||
src/ItemData.cc
|
||||
src/ItemParameterTable.cc
|
||||
src/Items.cc
|
||||
src/LevelTable.cc
|
||||
src/License.cc
|
||||
src/Lobby.cc
|
||||
src/Loggers.cc
|
||||
src/Main.cc
|
||||
src/Map.cc
|
||||
src/Menu.cc
|
||||
src/NetworkAddresses.cc
|
||||
src/PatchFileIndex.cc
|
||||
src/Player.cc
|
||||
src/PlayerSubordinates.cc
|
||||
src/ProxyCommands.cc
|
||||
src/ProxyServer.cc
|
||||
src/PSOEncryption.cc
|
||||
src/PSOGCObjectGraph.cc
|
||||
src/PSOProtocol.cc
|
||||
src/Quest.cc
|
||||
src/QuestScript.cc
|
||||
src/RareItemSet.cc
|
||||
src/ReceiveCommands.cc
|
||||
src/ReceiveSubcommands.cc
|
||||
src/ReplaySession.cc
|
||||
src/SaveFileFormats.cc
|
||||
src/SendCommands.cc
|
||||
src/Server.cc
|
||||
src/ServerShell.cc
|
||||
src/ServerState.cc
|
||||
src/Shell.cc
|
||||
src/StaticGameData.cc
|
||||
src/Text.cc
|
||||
src/TextArchive.cc
|
||||
src/Version.cc
|
||||
src/WordSelectTable.cc
|
||||
)
|
||||
target_include_directories(newserv PUBLIC ${LIBEVENT_INCLUDE_DIR})
|
||||
target_link_libraries(newserv phosg ${LIBEVENT_LIBRARIES})
|
||||
target_link_libraries(newserv phosg ${LIBEVENT_LIBRARIES} pthread)
|
||||
|
||||
if(RESOURCE_FILE_FOUND)
|
||||
target_compile_definitions(newserv PUBLIC HAVE_RESOURCE_FILE)
|
||||
target_include_directories(newserv PUBLIC ${RESOURCE_FILE_INCLUDE_DIR})
|
||||
target_link_libraries(newserv ${RESOURCE_FILE_LIBRARY})
|
||||
message(STATUS "libresource_file found; enabling patch support")
|
||||
if(resource_file_FOUND)
|
||||
target_compile_definitions(newserv PUBLIC HAVE_RESOURCE_FILE)
|
||||
target_link_libraries(newserv resource_file)
|
||||
message(STATUS "libresource_file found; enabling patch support")
|
||||
else()
|
||||
message(WARNING "libresource_file not available; disabling patch support")
|
||||
message(WARNING "libresource_file not found; disabling patch support")
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
# Test configuration
|
||||
|
||||
enable_testing()
|
||||
|
||||
file(GLOB LogTestCases ${CMAKE_SOURCE_DIR}/tests/*.test.txt)
|
||||
|
||||
foreach(LogTestCase IN ITEMS ${LogTestCases})
|
||||
add_test(
|
||||
NAME ${LogTestCase}
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
COMMAND ${CMAKE_BINARY_DIR}/newserv replay-log ${LogTestCase} --config=${CMAKE_SOURCE_DIR}/tests/config.json --require-basic-credentials)
|
||||
endforeach()
|
||||
|
||||
file(GLOB ScriptTestCases ${CMAKE_SOURCE_DIR}/tests/*.test.sh)
|
||||
|
||||
foreach(ScriptTestCase IN ITEMS ${ScriptTestCases})
|
||||
add_test(
|
||||
NAME ${ScriptTestCase}
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
COMMAND ${ScriptTestCase} ${CMAKE_BINARY_DIR}/newserv)
|
||||
endforeach()
|
||||
|
||||
# Installation configuration
|
||||
|
||||
install(TARGETS newserv DESTINATION bin)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018 Martin Michelsen
|
||||
Copyright (c) 2023 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
|
||||
|
||||
@@ -1,111 +1,326 @@
|
||||
# newserv
|
||||
# newserv <img align="right" src="s-newserv.png" />
|
||||
|
||||
newserv is a game server and proxy for Phantasy Star Online (PSO).
|
||||
newserv is a game server, proxy, and reverse-engineering tool for Phantasy Star Online (PSO).
|
||||
|
||||
This project includes code that was reverse-engineered by the community in ages long past, and has been included in many projects since then. It also includes some game data from Phantasy Star Online itself; this data was originally created by Sega.
|
||||
This project includes code that was reverse-engineered by the community in ages long past, and has been included in many projects since then. It also includes some game data from Phantasy Star Online itself, which was originally created by Sega.
|
||||
|
||||
This project is a rewrite of a rewrite of a game server that I wrote many years ago. So far, it works well with PSO GC Episodes 1 & 2, and lobbies (but not games) are implemented on Episode 3. Some basic functionality works on PSO PC and PSO BB, but there are probably still some cases that lead to errors (which will disconnect the client). The proxy works well with PSO GC and PSO BB.
|
||||
* Background
|
||||
* [History](#history)
|
||||
* [Future (and to-do list)](#future)
|
||||
* [Compatibility](#compatibility)
|
||||
* Setup
|
||||
* [Configuration](#configuration)
|
||||
* [Installing quests](#installing-quests)
|
||||
* [Episode 3 features](#episode-3-features)
|
||||
* [Client patch directories for PC and BB](#client-patch-directories)
|
||||
* [Memory patches and DOL files for GC](#memory-patches-and-dol-files)
|
||||
* [Using newserv as a proxy](#using-newserv-as-a-proxy)
|
||||
* [Chat commands](#chat-commands)
|
||||
* How to connect
|
||||
* Connecting local clients
|
||||
* [PSO DC](#pso-dc)
|
||||
* [PSO DC on Flycast](#pso-dc-on-flycast)
|
||||
* [PSO PC](#pso-pc)
|
||||
* [PSO GC on a real GameCube](#pso-gc-on-a-real-gamecube)
|
||||
* [PSO GC on Dolphin](#pso-gc-on-dolphin)
|
||||
* [Connecting external clients](#connecting-external-clients)
|
||||
* [Non-server features](#non-server-features)
|
||||
|
||||
Feel free to submit GitHub issues if you find bugs or have feature requests. I'd like to make the server as stable and complete as possible, but I can't promise that I'll respond to issues in a timely manner.
|
||||
## History
|
||||
|
||||
The history of this project essentially mirrors my development as a software engineer from the beginning of my hobby until now. If you don't care about the story, skip to the "Compatibility" or "Setup" sections below.
|
||||
|
||||
I originally purchased PSO GC when I heard about PSUL, and wanted to play around with running homebrew on my GameCube. This pathway eventually led to [GCARS-CS](https://github.com/fuzziqersoftware/gcars-cs), but that's another story.
|
||||
|
||||
<img align="left" src="s-khyps.png" /> After playing PSO for a while, both offline and online, I wrote a proxy called Khyps sometime in 2003. This was back in the days of the official Sega servers, where vulnerabilities weren't addressed in a timely manner or at all. It was common for malicious players using their own proxies or Action Replay codes (a story for another time) to send invalid commands that the servers would blindly forward, and cause the receiving clients to crash. These crashes were more than simply inconvenient; they could also corrupt your save data, destroying the hours of work you may have put into hunting items and leveling up your character.
|
||||
|
||||
For a while it was essentially necessary to use a proxy to go online at all, so the proxy could block these invalid commands. Khyps was designed primarily with this function in mind, though it also implemented some convenient cheats, like the ability to give yourself or other players infinite HP and allow you to teleport to different places without using an in-game teleporter.
|
||||
|
||||
<img align="left" src="s-khyller.png" /> After Khyps I took on the larger challenge of writing a server, which resulted in Khyller sometime in 2005. This was the first server of any type I had ever written. This project eventually evolved into a full-featured environment supporting all versions of the game that I had access to - at the time, PC, GC, and BB. (However, I suspect from reading the ancient source files that Khyller's BB support was very buggy.) As Khyller evolved, the code became increasingly cumbersome, littered with debugging filth that I never cleaned up and odd coding patterns I had picked up over the years. My understanding of the C++ language was woefully incomplete as well (as opposed to now, when it is still incomplete but not woefully so), which resulted in Khyller being essentially a C project that had a couple of classes in it.
|
||||
|
||||
<img align="left" src="s-aeon.png" /> Sometime in 2006 or 2007, I abandoned Khyller and rebuilt the entire thing from scratch, resulting in Aeon. Aeon was substantially cleaner in code than Khyller but still fairly hard to work with, and it lacked a few of the more arcane features I had originally written (for example, the ability to convert any quest into a download quest). In addition, the code still had some stability problems... it turns out that Aeon's concurrency primitives were simply incorrect. I had derived the concept of a mutex myself, before taking any real computer engineering classes, but had implemented it incorrectly. I made the race window as small as possible, but Aeon would still randomly crash after running seemingly fine for a few days.
|
||||
|
||||
At the time of its inception, Aeon was also called newserv, and you may find some beta releases floating around the Internet with filenames like `newserv-b3.zip`. I had released betas 1, 2, and 3 before I released the entire source of beta 5 and stopped working on the project when I went to college. This was around the time when I switched from writing software primarily on Windows to primarily on macOS and Linux, so Aeon beta 5 was the last server I wrote that specifically targeted Windows. (newserv, which you're looking at now, is a bit tedious to compile on Windows but does work.)
|
||||
|
||||
<img align="left" src="s-newserv.png" /> After a long hiatus from PSO and much professional and personal development in my technical abilities, I was reminiscing sometime in October 2018 by reading my old code archives. Somehow inspired when I came across Aeon, I spent a weekend and a couple more evenings rewriting the entire project again, cleaning up ancient patterns I had used eleven years ago, replacing entire modules with simple STL containers, and eliminating even more support files in favor of configuration autodetection. The code is now suitably modern and stable, and I'm not embarrassed by its existence, as I am by Aeon beta 5's source code and my archive of Khyller (which, thankfully, no one else ever saw).
|
||||
|
||||
## Future
|
||||
|
||||
This project is primarily for my own nostalgia; I offer no guarantees on how or when this project will advance.
|
||||
newserv is many things - a server, a proxy, an encryption and decryption tool, a decoder of various PSO-related formats, and more. Primarily, it's a reverse-engineering project in which I try to unravel the secrets of a 20-year-old video game, for honestly no reason. Solving these problems and documenting them in code has been fun, and I'll continue to do it when my time allows.
|
||||
|
||||
Current known issues / missing features:
|
||||
- Test all the communication features (info board, simple mail, card search, etc.)
|
||||
- The trade window isn't implemented yet.
|
||||
- PSO PC and PSOBB are not well-tested and likely will disconnect when clients try to use unimplemented features. Only GC is known to be stable and mostly complete.
|
||||
- Patches currently are platform-specific but not version-specific. This makes them quite a bit harder to use properly.
|
||||
- Find a way to silence audio in RunDOL.s. Some old DOLs don't reset audio systems at load time and it's annoying to hear the crash buzz when the GC hasn't actually crashed.
|
||||
- Implement private lobbies, and add a way to make games persistent.
|
||||
With that said, I offer no guarantees on how or when this project will advance. Feel free to submit GitHub issues if you find bugs or have feature requests; I'd like to make the server as stable and complete as possible, but I can't promise that I'll respond to issues in a timely manner. If you feel like contributing to newserv yourself, pull requests are welcome as well.
|
||||
|
||||
## Usage
|
||||
See TODO.md for a list of known issues and future work.
|
||||
|
||||
Currently this code should build on macOS and Ubuntu. It will likely work on other Linux flavors too. It should work on Windows as well, but I haven't tested it - the build process could be very manual.
|
||||
## Compatibility
|
||||
|
||||
There is a probably-not-too-old macOS release on the newserv GitHub repository (look in the right sidebar).
|
||||
newserv supports several versions of PSO. Specifically:
|
||||
| Version | Login | Lobbies | Games | Proxy |
|
||||
|----------------|--------------|--------------|--------------|--------------|
|
||||
| DC Trial | Yes (3) | Yes (3) | Yes (3) | No |
|
||||
| DC Prototype | Yes (3) | Yes (3) | Yes (3) | No |
|
||||
| DC V1 | Yes | Yes | Yes | Yes |
|
||||
| DC V2 | Yes | Yes | Yes | Yes |
|
||||
| PC | Yes | Yes | Yes | Yes |
|
||||
| GC Ep1&2 Trial | Untested (1) | Untested (1) | Untested (1) | Untested (1) |
|
||||
| GC Ep1&2 | Yes | Yes | Yes | Yes |
|
||||
| GC Ep1&2 Plus | Yes | Yes | Yes | Yes |
|
||||
| GC Ep3 Trial | Yes | Yes | Partial (4) | Yes |
|
||||
| GC Ep3 | Yes | Yes | Yes | Yes |
|
||||
| XBOX Ep1&2 | Untested (1) | Untested (1) | Untested (1) | Untested (1) |
|
||||
| BB (vanilla) | Yes | Yes | Yes (2) | Yes |
|
||||
| BB (Tethealla) | Yes | Yes | Yes (2) | Yes |
|
||||
|
||||
If you're running Linux or want to build newserv yourself, here's what you do:
|
||||
1. Make sure you have CMake and libevent installed. (`brew install cmake libevent` on macOS, `sudo apt-get install cmake libevent-dev` on most Linuxes)
|
||||
2. Build and install phosg (https://github.com/fuzziqersoftware/phosg).
|
||||
3. Optionally, install resource_dasm (https://github.com/fuzziqersoftware/resource_dasm). This will enable newserv to load DOL files on PSO GC clients. PSO GC clients can play PSO normally on newserv without this.
|
||||
4. Run `cmake . && make` on the newserv directory.
|
||||
*Notes:*
|
||||
1. *newserv's implementations of these versions are based on disassembly of the client executables and have never been tested.*
|
||||
2. *BB games are mostly playable, but there are still some unimplemented features (for example, some quests that use rare commands may not work). Please submit a GitHub issue if you find something that doesn't work.*
|
||||
3. *Support for PSO Dreamcast Trial Edition and the December 2000 prototype is somewhat incomplete and probably never will be complete. These versions are rather unstable and seem to crash often, but it's not obvious whether it's because they're prototypes or because newserv sends data they can't handle.*
|
||||
4. *Creating a game works and battle setup behaves mostly normally, but starting a battle doesn't work.*
|
||||
|
||||
## Setup
|
||||
|
||||
### Configuration
|
||||
|
||||
Currently newserv works on macOS, Windows, and Ubuntu Linux. It will likely work on other Linux flavors too.
|
||||
|
||||
There is a fairly recent macOS ARM64 release on the newserv GitHub repository. You may need to install libevent manually even if you use this release (run `brew install libevent`).
|
||||
|
||||
There is a fairly recent Windows release on the newserv GitHub repository also. It's built with Cygwin, and all the necessary DLL files should be included. That said, I've only tested it on my own machine and there is no CI for Windows builds like there is for macOS and Linux, so if it doesn't work for you, please open a GitHub issue to let me know.
|
||||
|
||||
If you're not using a release from the GitHub repository, do this to build newserv:
|
||||
1. If you're on Windows, install Cygwin. While doing so, install the `cmake`, `gcc-core`, `gcc-g++`, `git`, `libevent2.1_7`, `make`, and `zlib` packages. Do the rest of these steps inside a Cygwin shell (not a Windows cmd shell or PowerShell).
|
||||
2. Make sure you have CMake and libevent installed. (On macOS, `brew install cmake libevent`; on most Linuxes, `sudo apt-get install cmake libevent-dev`; on Windows, you already did this in step 1.)
|
||||
3. Build and install phosg (https://github.com/fuzziqersoftware/phosg).
|
||||
4. Optionally, install resource_dasm (https://github.com/fuzziqersoftware/resource_dasm). This will enable newserv to send memory patches and load DOL files on PSO GC clients. PSO GC clients can play PSO normally on newserv without this.
|
||||
5. Run `cmake . && make` in the newserv directory.
|
||||
|
||||
After building newserv or downloading a release, do this to set it up and use it:
|
||||
1. In the system/ directory, make a copy of config.example.json named config.json, and edit it appropriately.
|
||||
2. Run `./newserv` in the newserv directory. This will start the game server and run the interactive shell. You may need `sudo` if newserv's built-in DNS server is enabled.
|
||||
3. Use the interactive shell to add a license. Run `help` in the shell to see how to do this.
|
||||
2. If you plan to play PSO Blue Burst on newserv, set up the patch directory. See the "Client patch directories" section below.
|
||||
3. Run `./newserv` in the newserv directory. This will start the game server and run the interactive shell. You may need `sudo` if newserv's built-in DNS server is enabled.
|
||||
4. If you set AllowUnregisteredUsers to false in config.json, use the interactive shell to add your license. Run `help` in the shell to see how to do this.
|
||||
5. Set your client's network settings appropriately and start an online game. See the "Connecting local clients" or "Connecting remote clients" section to see how to get your game client to connect.
|
||||
|
||||
To use newserv in other ways (e.g. for translating data), see the end of this document.
|
||||
|
||||
### Installing quests
|
||||
|
||||
newserv automatically finds quests in the system/quests/ directory. To install your own quests, or to use quests you've saved using the proxy's set-save-files option, just put them in that directory and name them appropriately.
|
||||
newserv automatically finds quests in the system/quests/ directory. To install your own quests, or to use quests you've saved using the proxy's "save files" option, just put them in that directory and name them appropriately.
|
||||
|
||||
Standard quest file names should be like `q###-CATEGORY-VERSION.EXT`; battle quests should be named like `b###-VERSION.EXT`, and challenge quests should be named like `c###-VERSION.EXT`. The fields in each filename are:
|
||||
- `###`: quest number (this doesn't really matter; it should just be unique for the version)
|
||||
- `CATEGORY`: ret = Retrieval, ext = Extermination, evt = Events, shp = Shops, vr = VR, twr = Tower, gov = Government (BB only), dl = Download (these don't appear during online play), 1p = Solo (BB only)
|
||||
- `VERSION`: d1 = Dreamcast v1, dc = Dreamcast v2, pc = PC, gc = GameCube Episodes 1 & 2, gc3 = Episode 3, bb = Blue Burst
|
||||
- `EXT`: file extension (bin, dat, bin.gci, dat.gci, bin.dlq, dat.dlq, or qst)
|
||||
Standard quest files should be named like `q###-CATEGORY-VERSION-LANGUAGE.EXT`, battle quests should be named like `b###-VERSION-LANGUAGE.EXT`, challenge quests should be named like `c###-VERSION-LANGUAGE.EXT` for Episode 1 or `d###-VERSION-LANGUAGE.EXT` for Episode 2. The fields in each filename are:
|
||||
- `###`: quest number (this doesn't really matter; it should just be unique across the PSO version)
|
||||
- `CATEGORY`: ret = Retrieval, ext = Extermination, evt = Events, shp = Shops, vr = VR, twr = Tower, gv1/gv2/gv4 = Government (BB only), dl = Download (these don't appear during online play), 1p = Solo (BB only)
|
||||
- `VERSION`: dn = Dreamcast NTE, d1 = Dreamcast v1, dc = Dreamcast v2, pc = PC, gcn = GameCube Trial Edition, gc = GameCube Episodes 1 & 2, gc3 = Episode 3 (see below), xb = Xbox, bb = Blue Burst
|
||||
- `LANGUAGE`: j = Japanese, e = English, g = German, f = French, s = Spanish
|
||||
- `EXT`: file extension (see table below)
|
||||
|
||||
There are multiple PSO quest formats out there; newserv supports most of them. Specifically, newserv can use quests in any of the following formats:
|
||||
- bin/dat format: These quests consist of two files with the same base name, a .bin file and a .dat file.
|
||||
- Unencrypted GCI format: These quests also consist of a .bin and .dat file, but an encoding is applied on top of them. The filenames should end in .bin.gci and .dat.gci. (Note that there also exists an encrypted GCI format, which newserv does not support.)
|
||||
- Encrypted DLQ format: These quests also consist of a .bin and .dat file, but download quest encryption is applied on top of them. The filenames should end in .bin.dlq and .dat.dlq.
|
||||
- QST format: These quests consist of only a .qst file, which contains both the .bin and .dat files within it.
|
||||
On .dat files, the `LANGUAGE` token may be omitted. If it's present, then that .dat file will only be used for that version of the quest; if omitted, then that .dat file will be used for all versions of the quest.
|
||||
|
||||
For example, the GameCube version of Lost HEAT SWORD is in two files named `q058-ret-gc-e.bin` and `q058-ret-gc.dat`. newserv knows these files are quests because they're in the system/quests/ directory, it knows they're for PSO GC because the filenames contain `-gc`, it knows this is the English version of the quest because the .bin filename ends with `-e` (even though the .dat filename does not), and it puts them in the Retrieval category because the filenames contain `-ret`.
|
||||
|
||||
The type identifiers (`b`, `c`, `d`, `e`, or `q`) and categories are configurable. See QuestCategories in config.example.json for more information on how to make new categories or edit the existing categories.
|
||||
|
||||
There are multiple PSO quest formats out there; newserv supports all of them. It can also decode any known format to standard .bin/.dat format. Specifically:
|
||||
|
||||
| Format | Extension | Supported | Decode action |
|
||||
|------------------|-----------------------|------------|------------------|
|
||||
| Compressed | .bin and .dat | Yes | None (1) |
|
||||
| Compressed Ep3 | .bin or .mnm | Yes (4) | None (1) |
|
||||
| Uncompressed | .bind and .datd | Yes | compress-prs (2) |
|
||||
| Uncompressed Ep3 | .bind or .mnmd | Yes (4) | compress-prs (2) |
|
||||
| VMS (DCv1) | .bin.vms and .dat.vms | Yes | decode-vms |
|
||||
| VMS (DCv2) | .bin.vms and .dat.vms | Decode (3) | decode-vms (3) |
|
||||
| GCI (decrypted) | .bin.gci and .dat.gci | Yes | decode-gci |
|
||||
| GCI (with key) | .bin.gci and .dat.gci | Yes | decode-gci |
|
||||
| GCI (no key) | .bin.gci and .dat.gci | Decode (3) | decode-gci (3) |
|
||||
| GCI (Ep3) | .bin.gci or .mnm.gci | Yes | decode-gci |
|
||||
| GCI (Ep3 Trial) | .bin.gci or .mnm.gci | Decode (3) | decode-gci (3) |
|
||||
| DLQ | .bin.dlq and .dat.dlq | Yes | decode-dlq |
|
||||
| DLQ (Ep3) | .bin.dlq or .mnm.dlq | Yes | decode-dlq |
|
||||
| QST (online) | .qst | Yes | decode-qst |
|
||||
| QST (download) | .qst | Yes | decode-qst |
|
||||
|
||||
*Notes:*
|
||||
1. *This is the default format. You can convert these to uncompressed format by running `newserv decompress-prs FILENAME.bin FILENAME.bind` (and similarly for .dat -> .datd)*
|
||||
2. *Similar to (1), to compress an uncompressed quest file: `newserv compress-prs FILENAME.bind FILENAME.bin` (and likewise for .datd -> .dat)*
|
||||
3. *Use the decode action to convert these quests to .bin/.dat format before putting them into the server's quests directory. If you know the encryption seed (serial number), pass it in as a hex string with the `--seed=` option. If you don't know the encryption seed, newserv will find it for you, which will likely take a long time.*
|
||||
4. *Episode 3 quests don't go in the system/quests directory. See the Episode 3 section below.*
|
||||
|
||||
Episode 3 download quests consist only of a .bin file - there is no corresponding .dat file. Episode 3 download quest files may be named with the .mnm extension instead of .bin, since the format is the same as the standard map files (in system/ep3/). These files can be encoded in any of the formats described above, except .qst.
|
||||
|
||||
When newserv indexes the quests during startup, it will warn (but not fail) if any quests are corrupt or in unrecognized formats.
|
||||
|
||||
If you've changed the contents of the quests directory, you can re-index the quests without restarting the server by running `reload quests` in the interactive shell.
|
||||
Quest contents are cached in memory, but if you've changed the contents of the quests directory, you can re-index the quests without restarting the server by running `reload quests` in the interactive shell. The new quests will be available immediately, but any games with quests already in progress will continue using the old versions of the quests until those quests end.
|
||||
|
||||
All quests, including those originally in GCI or DLQ format, are treated as online quests unless their filenames specify the dl category. newserv allows players to download all quests, even those in non-download categories.
|
||||
|
||||
### Patches and DOL files
|
||||
### Episode 3 features
|
||||
|
||||
newserv supports many features unique to Episode 3:
|
||||
* CARD battles. Not every combination of abilities has been tested yet, so if you find a feature or card ability that doesn't work like it's supposed to, please make a GitHub issue and describe the situation (the attacking card(s), defending card(s), and ability or condition that didn't work).
|
||||
* Spectator teams.
|
||||
* Tournaments. (But they work differently than Sega's tournaments did - see below)
|
||||
* Downloading quests.
|
||||
* Trading cards.
|
||||
* Participating in card auctions. (The auction contents must be configured in config.json.)
|
||||
* Decorations in lobbies. Currently only images are supported; the game also supports loading custom 3D models in lobbies, but newserv does not implement this (yet).
|
||||
|
||||
#### Battle records
|
||||
|
||||
After playing a battle, you can save the record of the battle with the $saverec command. You can then replay the battle later by using the $playrec command in a lobby - this will create a spectator team and play the recording of the battle as if it were happening in realtime. Note that there is a bug in older versions of Dolphin that seems to be frequently triggered when playing battle records, which causes the emulator to crash with the message `QObject::~QObject: Timers cannot be stopped from another thread`. To avoid this, use the latest version of Dolphin.
|
||||
|
||||
#### Tournaments
|
||||
|
||||
Tournaments work differently than they did on Sega's servers. Tournaments can be created with the `create-tournament` shell command, which enables players to register for them. (Use `help` to see all the arguments - there are many!) The `start-tournament` shell command starts the tournament (and prevents further registrations), but this doesn't schedule any matches. Instead, players who are ready to play their next match can all stand at the 4-player battle table near the lobby warp in the same CARD lobby, and the tournament match will start automatically.
|
||||
|
||||
These tournament semantics mean that there can be multiple matches in the same tournament in play simultaneously, and not all matches in a round must be complete before the next round can begin - only the matches preceding each individual match must be complete for that match to be playable.
|
||||
|
||||
The Meseta rewards for winning tournament matches can be configured in config.json.
|
||||
|
||||
#### Episode 3 files
|
||||
|
||||
Episode 3 state and game data is stored in the system/ep3 directory. The files in there are:
|
||||
* card-definitions.mnr: Compressed card definition list, sent to Episode 3 clients at connect time. Card stats and abilities can be changed by editing this file.
|
||||
* card-definitions.mnrd: Decompressed version of the above. If present, newserv will use this instead of the compressed version, since this is easier to edit.
|
||||
* card-text.mnr: Compressed card text archive. Generally only used for debugging.
|
||||
* card-text.mnrd: Decompressed card text archive; same format as TextCardE.bin. Generally only used for debugging.
|
||||
* com-decks.json: COM decks used in tournaments. The default decks in this file come from logs from Sega's servers, so the file doesn't include every COM deck Sega ever made - the rest are probably lost to time.
|
||||
* maps/: Online free battle and quest maps (.mnm/.bin/.mnmd/.bind files). newserv comes with 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-download/: Download maps and quests (.mnm/.bin/.mnmd/.bind files). Files in this directory 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 maps-download/ (a symbolic link is acceptable).
|
||||
* 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.
|
||||
|
||||
Like quests, Episode 3 card definitions, maps, and quests are cached in memory. If you've changed any of these files, you can run `reload ep3` in the interactive shell to make the changes take effect without restarting the server.
|
||||
|
||||
### Client patch directories
|
||||
|
||||
If you're not playing PSO Blue Burst on newserv, you can skip these steps.
|
||||
|
||||
newserv implements a patch server for PSO PC and PSO BB game data. Any file or directory you put in the system/patch-bb or system/patch-pc directories will be synced to clients when they connect to the patch server.
|
||||
|
||||
To make server startup faster, newserv caches the modification times, sizes, and checksums of the files in the patch directories. If the patch server appears to be misbehaving, try deleting the .metadata-cache.json file in the relevant patch directory to force newserv to recompute all the checksums. Also, in the case when checksums are cached, newserv may not actually load the data for a patch file until it's needed by a client. Therefore, modifying any part of the patch tree while newserv is running can cause clients to see an inconsistent view of it.
|
||||
|
||||
For BB clients, newserv reads some files out of the patch data to implement game logic, so it's important that certain game files are synchronized between the server and the client. newserv contains defaults for these files in the system/blueburst/map directory, but if these don't match the client's copies of the files, odd behavior will occur in games.
|
||||
|
||||
Specifically, the patch-bb directory should contain at least the data.gsl file and all map_*.dat files from the version of PSOBB that you want to play on newserv. You can copy these files out of the client's data directory from a clean installation, and put them in system/patch-bb/data.
|
||||
|
||||
Patch directory contents are cached in memory. If you've changed any of these files, you can run `reload patches` in the interactive shell to make the changes take effect without restarting the server.
|
||||
|
||||
### Memory patches and DOL files
|
||||
|
||||
Everything in this section requires resource_dasm to be installed, so newserv can use the PowerPC assembler and disassembler from its libresource_file library. If resource_dasm is not installed, newserv will still build and run, but these features will not be available.
|
||||
|
||||
You can put patches in the system/ppc directory with filenames like PatchName.patch.s and they will appear in the Patches menu for PSO GC clients that support patching. Patches are written in PowerPC assembly and are compiled when newserv is started. See system/ppc/WriteMemory.s for a commented example of such a function.
|
||||
In addition, these features are only supported for the following game versions:
|
||||
* PSO GameCube Episodes 1&2 JP, USA, and EU (not Plus)
|
||||
* PSO GameCube Episodes 1&2 Plus JP v1.04 (not v1.05)
|
||||
* PSO GameCube Episode 3 Trial Edition
|
||||
* PSO GameCube Episode 3 JP
|
||||
* PSO GameCube Episode 3 USA (experimental; must be manually enabled in config.json)
|
||||
|
||||
You can also put DOL files in the system/dol directory, and they will appear in the Programs menu. Selecting a DOL file there will load the file into their GameCube's memory and run it, just like the old homebrew loaders (PSUL and PSOload) did. For this to work, ReadMemoryWord.s, WriteMemory.s, and RunDOL.s must be present in the system/ppc directory. This has been tested on Dolphin but not on a real GameCube, so results may vary.
|
||||
You can put memory patches in the system/ppc directory with filenames like PatchName.patch.s and they will appear in the Patches menu for PSO GC clients that support patching. Memory patches are written in PowerPC assembly and are compiled when newserv is started. The PowerPC assembly system's features are documented in the comments in system/ppc/WriteMemory.s - this file is not a memory patch itself, but it describes how memory patches may be written and the restrictions that apply to them.
|
||||
|
||||
You can also put DOL files in the system/dol directory, and they will appear in the Programs menu. Selecting a DOL file there will load the file into the GameCube's memory and run it, just like the old homebrew loaders (PSUL and PSOload) did. For this to work, ReadMemoryWord.s, WriteMemory.s, and RunDOL.s must be present in the system/ppc directory. This has been tested on Dolphin but not on a real GameCube, so results may vary.
|
||||
|
||||
Like other kinds of data, functions and DOL files are cached in memory. If you've changed any of these files, you can run `reload functions` or `reload dol-files` in the interactive shell to make the changes take effect without restarting the server.
|
||||
|
||||
I mainly built the DOL loading functionality for documentation purposes. By now, there are many better ways to load homebrew code on an unmodified GameCube, but to my knowledge there isn't another open-source implementation of this method in existence.
|
||||
|
||||
### Using newserv as a proxy
|
||||
|
||||
If you want to play online on remote servers rather than running your own server, newserv also includes a PSO proxy. Currently this works with PSO GC and may work with PC and DC; it also works with some BB clients in specific situations.
|
||||
|
||||
To use the proxy for PSO DC, PC, or GC, add an entry to the corresponding ProxyDestinations dictionary in config.json, then run newserv and connect to it as normal (see below). You'll see a "Proxy server" option in the main menu, and you can pick which remote server to connect to.
|
||||
|
||||
To use the proxy for PSO BB, set the ProxyDestination-BB entry in config.json. If this option is set, it essentially disables the game server for all PSO BB clients - all clients will be proxied to the specified destination instead. Unfortunately, because PSO BB uses a different set of handlers for the data server phase and character selection, there's no in-game way to present the player with a list of options, like there is on PSO PC and PSO GC.
|
||||
|
||||
When you're on PSO DC, PC, or GC and are connected to a remote server through newserv's proxy, choosing the Change Ship or Change Block action from the lobby counter will send you back to newserv's main menu instead of the remote server's ship or block select menu. You can go back to the server you were just on by choosing it from the proxy server menu again.
|
||||
|
||||
There are many options available when starting a proxy session. All options are off by default unless otherwise noted. The options are:
|
||||
* **Chat commands**: enables chat commands in the proxy session (on by default).
|
||||
* **Chat filter**: enables escape sequences in chat messages and info board (on by default).
|
||||
* **Player notifications**: shows a message when any player joins or leaves the game or lobby you're in.
|
||||
* **Block pings**: blocks automatic pings sent by the client, and responds to ping commands from the server automatically. This works around a bug in Sylverant's login server.
|
||||
* **Infinite HP**: automatically heals you whenever you get hit. An attack that kills you in one hit will still kill you, however.
|
||||
* **Infinite TP**: automatically restores your TP whenever you use any technique.
|
||||
* **Switch assist**: attempts to unlock doors that require two players in a one-player game.
|
||||
* **Infinite Meseta** (Episode 3 only): gives you 1,000,000 Meseta, regardless of the value sent by the remote server.
|
||||
* **Block events**: disables holiday events sent by the remote server.
|
||||
* **Block patches**: prevents any B2 (patch) commands from reaching the client.
|
||||
* **Save files**: saves copies of several kinds of files when they're sent by the remote server. The files are written to the current directory (which is usually the directory containing the system/ directory). These kinds of files can be saved:
|
||||
* Online quests and download quests (saved as .bin/.dat files)
|
||||
* GBA games (saved as .gba files)
|
||||
* Patches (saved as .bin files, and disassembled into PowerPC assembly if newserv is built with patch support)
|
||||
* Player data from BB sessions (saved as .bin files, which are not the same format as .nsc files)
|
||||
* Episode 3 online quests and maps (saved as .mnmd files)
|
||||
* Episode 3 download quests (saved as .mnm files)
|
||||
* Episode 3 card definitions (saved as .mnr files)
|
||||
* Episode 3 media updates (saved as .gvm, .bml, or .bin files)
|
||||
|
||||
The remote server will probably try to assign you a Guild Card number that doesn't match the one you have on newserv. On PSO DC, PC and GC, the proxy server rewrites the commands in transit to make it look like the remote server assigned you the same Guild Card number as you have on newserv, but if the remote server has some external integrations (e.g. forum or Discord bots), they will use the Guild Card number that the remote server believes it has assigned to you. The number assigned by the remote server is shown to you when you first connect to the remote server, and you can retrieve it in lobbies or during games with the $li command.
|
||||
|
||||
Some chat commands (see below) have the same basic function on the proxy server but have different effects or conditions. In addition, there are some server shell commands that affect clients on the proxy (run `help` in the shell to see what they are). If there's only one proxy session open, the shell's proxy commands will affect that session. Otherwise, you'll have to specify which session to affect with the `on` prefix - to send a chat message in LinkedSession:17205AE4, for example, you would run `on 17205AE4 chat ...`.
|
||||
|
||||
### Chat commands
|
||||
|
||||
The server's shell supports a variety of administration commands. If the interactive shell is enabled, you can enter these commands at any time, even if the prompt isn't visible. Run `help` in the server's shell to see all of the commands and how to use them.
|
||||
|
||||
newserv also supports a variety of commands players can use via the chat interface. Any chat message that begins with `$` is treated as a chat command. (If you actually want to send a chat message starting with `$`, type `$$` instead.)
|
||||
newserv supports a variety of commands players can use by chatting in-game. Any chat message that begins with `$` is treated as a chat command. (If you actually want to send a chat message starting with `$`, type `$$` instead.)
|
||||
|
||||
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 (remote Guild Card number, client ID, etc.) instead.
|
||||
* `$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.).
|
||||
* `$what` (game server only): Shows the type, name, and stats of the nearest item on the ground.
|
||||
* `$matcount` (game server only): Shows how many of each type of material you've used.
|
||||
|
||||
* Debugging commands
|
||||
* `$debug` (game server only): Enable or disable debug. You need the DEBUG permission in your user license to use this command. When debug is enabled, you'll see in-game messages from the server when you take certain actions. You'll also be placed into the highest available slot in lobbies and games instead of the lowest, which is useful for finding commands for which newserv doesn't handle client IDs properly. This setting also disables certain safeguards and allows you to do some things that might crash your client.
|
||||
* `$call <function-id>`: Call a quest function on your client.
|
||||
* `$gc` (game server only): Send your own Guild Card to yourself.
|
||||
* `$persist` (game server only): Enable or disable persistence for the current lobby or game. This determines whether the lobby/game is deleted when the last player leaves. You need the DEBUG permission in your user license to use this command because there are no game state checks when you do this. For example, if you make a game persistent, start a quest, then leave the game, the game can't be joined by anyone but also can't be deleted.
|
||||
* `$sc <data>`: Send a command to yourself.
|
||||
* `$ss <data>` (proxy server only): Send a command to the remote server.
|
||||
|
||||
* Personal state commands
|
||||
* `$arrow <color-id>`: Changes your lobby arrow color.
|
||||
* `$secid <section-id>`: Sets your override section ID. After running this command, any games you create will use your override section ID for rare drops instead of your character's actual section ID. To revert to your actual section id, run `$secid` with no name after it.
|
||||
* `$secid <section-id>`: Sets your override section ID. After running this command, any games you create will use your override section ID for rare drops instead of your character's actual section ID. To revert to your actual section id, run `$secid` with no name after it. On the proxy server, this will not work if the remote server controls item drops (e.g. on BB, or on Schtserv with server drops enabled).
|
||||
* `$rand <seed>`: Sets your override random seed (specified as a 32-bit hex value). This will make any games you create use the given seed for rare enemies. This also makes item drops deterministic in Blue Burst games hosted by newserv. On the proxy server, this command can cause desyncs with other players in the same game, since they will not see the overridden random seed. To remove the override, run `$rand` with no arguments.
|
||||
* `$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.
|
||||
* `$exit`: If you're in a lobby, sends you to the main menu (which ends your proxy session, if you're in one). If you're in a game or spectator team, sends you to the lobby (but does not end your proxy session if you're in one). Does nothing if you're in a non-Episode 3 game and no quest is in progress.
|
||||
* `$patch <name>`: Run a patch on your client. `<name>` must exactly match the name of a patch on the server.
|
||||
|
||||
* Blue Burst player commands (game server only)
|
||||
* `$bbchar <username> <password> <1-4>`: 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.
|
||||
* `$bbchar <username> <password> <1-4>`: 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. Any character already in that slot is overwritten.
|
||||
* `$edit <stat> <value>`: Modifies your character data.
|
||||
* `$item <data>`: Sets the next item to be dropped from an enemy or box.
|
||||
|
||||
* Game state commands (game server only)
|
||||
* `$maxlevel <level>`: Sets the maximum level for players to join the current game.
|
||||
* `$maxlevel <level>`: Sets the maximum level for players to join the current game. (This only applies when joining; if a player joins and then levels up past this level during the game, they are not kicked out, but won't be able to rejoin if they leave.)
|
||||
* `$minlevel <level>`: Sets the minimum level for players to join the current game.
|
||||
* `$password <password>`: Sets the game's join password. To unlock the game, run `$password` with nothing after it.
|
||||
* `$raretable`: Switches between using the client's or the server's drop table. No effect on BB (the server's drop table is always used). The server's rare tables are defined in JSON files in the system/rare-tables directory.
|
||||
|
||||
* Episode 3 commands (game server only)
|
||||
* `$spec`: Toggles the allow spectators flag for Episode 3 games. If any players are spectating when this flag is disabled, they will be sent back to the lobby.
|
||||
* `$inftime`: Toggles infinite-time mode. Must be used before starting a battle. If infinite-time mode is enabled, the overall and per-phase time limits will be disabled regardless of the values chosen during battle setup. After completing a battle, infinite-time mode is reset to the server's default value (which can be set in Episode3BehaviorFlags in config.json).
|
||||
* `$defrange <min>-<max>`: Sets the DEF dice range for the next battle. If this is used, the dice range set during battle rules setup will apply only to ATK dice; DEF dice will use this range instead. Assist cards and other dice effects will still apply. Dice exchange also still applies if it is enabled.
|
||||
* `$stat <what>`: Shows a statistic about your player or team in the current battle. `<what>` can be `duration`, `fcs-destroyed`, `cards-destroyed`, `damage-given`, `damage-taken`, `opp-cards-destroyed`, `own-cards-destroyed`, `move-distance`, `cards-set`, `fcs-set`, `attack-actions-set`, `techs-set`, `assists-set`, `defenses-self`, `defenses-ally`, `cards-drawn`, `max-attack-damage`, `max-combo`, `attacks-given`, `attacks-taken`, `sc-damage`, `damage-defended`, or `rank`.
|
||||
* `$surrender`: Causes your team to immediately lose the current battle.
|
||||
* `$saverec <name>`: Saves the recording of the last battle.
|
||||
* `$playrec <name>`: Plays a battle recording. This command creates a spectator team and replays the specified battle log within it. There is a bug in Dolphin that makes use of this command unstable in emulation (see the "Battle records" section above).
|
||||
|
||||
* Cheat mode commands
|
||||
* `$cheat`: Enables or disables cheat mode for the current game. All other cheat mode commands do nothing if cheat mode is disabled. This command does nothing on the proxy server, since cheat mode is always enabled there.
|
||||
* `$cheat`: Enables or disables cheat mode for the current game. All other cheat mode commands do nothing if cheat mode is disabled. By default, cheat mode is off in new games but can be enabled; there is an option in config.json that allows you to disable cheat mode entirely, or set it to on by default in new games.
|
||||
* `$infhp` / `$inftp`: Enables or disables infinite HP or TP mode. Applies to only you. In infinite HP mode, one-hit KO attacks will still kill you.
|
||||
* `$warp <area-id>`: Warps yourself to the given area.
|
||||
* `$next` (game server only): Warps yourself to the next area.
|
||||
* `$warpme <area-id>`: Warps yourself to the given area.
|
||||
* `$warpall <area-id>`: Warps everyone in the game to the given area. You must be the leader to use this command, unless you're on the proxy server.
|
||||
* `$next`: Warps yourself to the next area.
|
||||
* `$swa`: Enables or disables switch assist. When enabled, the server will attempt to automatically unlock two-player doors in solo games if you step on both switches sequentially.
|
||||
* `$item <desc>` (or `$i <desc>`): Create an item. `desc` may be a description of the item (e.g. "Hell Saber +5 0/10/25/0/10") or a string of hex data specifying the item code. Item codes are 16 hex bytes; at least 2 bytes must be specified, and all unspecified bytes are zeroes. If you are on the proxy server, you must not be using Blue Burst for this command to work. On the game server, this command works for all versions.
|
||||
* `$unset <index>`: In an Episode 3 battle, removes one of your set cards from the field. `<index>` is the index of the set card as it appears on your screen - 1 is the card next to your SC's icon, 2 is the card to the right of 1, etc. This does not cause a Hunters-side SC to lose HP, as they normally do when their items are destroyed.
|
||||
|
||||
* 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, only you will see the new event; other players will not.
|
||||
* `$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>` (game server only, Episode 3 only): Plays a specific song in the current lobby.
|
||||
* `$song <song-id>` (Episode 3 only): Plays a specific song in the current lobby.
|
||||
|
||||
* Administration commands (game server only)
|
||||
* `$ann <message>`: Sends an announcement message. The message text is sent to all players in all games and lobbies.
|
||||
@@ -114,36 +329,79 @@ Some commands only work on the game server and not on the proxy server. The chat
|
||||
* `$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.
|
||||
|
||||
### Using newserv as a proxy
|
||||
|
||||
If you want to play online on remote servers rather than running your own server, newserv also includes a PSO proxy. Currently this works with PSO GC and may work with PC; it also works with some BB clients in specific situations.
|
||||
|
||||
To use the proxy, add an entry to the ProxyDestinations dictionary in config.json, then run newserv and connect to it as normal (see below). You'll see a "Proxy server" option in the main menu, and you can pick which remote server to connect to.
|
||||
|
||||
A few things to be aware of when using the proxy server:
|
||||
- On PC and GC, using the Change Ship or Change Block actions from the lobby counter will bring you back to newserv's main menu, not the remote server's ship select. You can go back to the server you were just on by choosing it from newserv's proxy server menu again.
|
||||
- The remote server will probably try to assign you a Guild Card number that doesn't match the one you have on newserv. The proxy server rewrites the commands on the fly to make it look like the remote server assigned you the same Guild Card number as you have on newserv, but if the remote server has some external integrations (e.g. forum or Discord bots), they will use the Guild Card number that the remote server believes it has assigned to you. The number assigned by the remote server is shown to you when you first connect to the remote server, and you can retrieve it in lobbies or during games with the $li command.
|
||||
- There are shell commands that affect clients on the proxy (run 'help' in the shell to see what they are). All proxy commands in the shell only work when there's exactly one client connected through the proxy, since there isn't (yet) a way to say via the shell which session you want to affect.
|
||||
|
||||
### Connecting local clients
|
||||
|
||||
If you're running PSO on a real GameCube, you can make it connect to newserv by setting its default gateway and DNS server addresses to newserv's address. newserv's DNS server must be running on port 53 and accessible.
|
||||
#### PSO DC
|
||||
|
||||
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, 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.
|
||||
Some versions of PSO DC will connect to a private server if you just set their DNS server address (in the network configuration) to newserv's address, and enable newserv's DNS server. This will not work for other versions; for those, you'll need a cheat code. Creating such a code is beyond the scope of this document.
|
||||
|
||||
If you're emulating PSO using a version of Dolphin with tapserver support (currently only the macOS version), you can make it connect to a newserv instance running on the same machine via the tapserver interface. This works for all PSO versions, including Plus and Episode III, without the trickery described above. To do this:
|
||||
- Set Dolphin's BBA type to tapserver (Config -> GameCube -> SP1).
|
||||
- Enable newserv's IP stack simulator according to the comments in config.json, and start newserv. You do not need to install or run tapserver.
|
||||
- In PSO, you have to configure the network settings manually (DHCP doesn't work), but the actual values don't matter as long as they're valid IP addresses. Example values:
|
||||
- IP address: `10.0.1.5`
|
||||
- Subnet mask: `255.255.255.0`
|
||||
- Default gateway: `10.0.1.1`
|
||||
- DNS server address 1: `10.0.1.1`
|
||||
- Leave everything else blank
|
||||
- Start an online game.
|
||||
If you're emulating PSO DC or have a disc image, you can patch the appropriate files within the disc image to make it connect to any address you want. Creating such a patch is also beyond the scope of this document.
|
||||
|
||||
#### PSO DC on Flycast
|
||||
|
||||
If you're emulating PSO DC, all versions will connect to newserv by setting the following options in Flycast's `emu.cfg` file under `[network]`:
|
||||
- DNS = Your newserv's server address (newserv's DNS server must be running on port 53)
|
||||
- EmulateBBA = no (while some versions support the BBA, some do not, and all versions support the modem)
|
||||
- Enable = yes
|
||||
|
||||
Once set up, the EU and US versions will work without any extra set up (other than the HL Check Disable code for USv2), while the JP versions require HL Check Disable codes to be running, and an e-mail account set up. The easiest way to set up an e-mail account is through PlanetWeb's Internet Browser for Dreamcast.
|
||||
|
||||
If the server is running on the same machine as Flycast, this might not work, even if you point Flycast's DNS queries at your local IP address (instead of 127.0.0.1). In this case, you can modify the loaded executable in memory to make it connect anywhere you want. There is a script included with newserv that can do this on macOS; a similar technique could be done manually using scanmem on Linux or Cheat Engine on Windows. To use the script, do this:
|
||||
1. Build and install memwatch (https://github.com/fuzziqersoftware/memwatch).
|
||||
2. Start Flycast and run PSO. (You must start PSO before running the script; it won't work if you run the script before loading the game.)
|
||||
3. Run `sudo patch_flycast_memory.py <original-destination>`. Replace `<original-destination>` with the hostname that PSO wants to connect to (you can find this out by using Wireshark and looking for DNS queries). The script may take up to a minute; you can continue using Flycast while it runs, but don't start an online game until the script is done.
|
||||
4. Run newserv and start an online game in PSO.
|
||||
|
||||
If you use this method, you'll have to run the script every time you start PSO in Flycast, but you won't have to run it again if you start another online game without restarting emulation.
|
||||
|
||||
#### PSO PC
|
||||
|
||||
The version of PSO PC I have has the server addresses starting at offset 0x29CB34 in pso.exe. Using a hex editor, change those to "localhost" (without quotes) if you just want to connect to a locally-running newserv instance. Alternatively, you can add an entry to the Windows hosts file (C:\Windows\System32\drivers\etc\hosts) to redirect the connection to 127.0.0.1 (localhost) or any other IP address.
|
||||
|
||||
#### PSO GC on a real GameCube
|
||||
|
||||
You can make PSO connect to newserv by setting its default gateway and DNS server addresses to newserv's address. newserv's DNS server must be running on port 53 and must be accessible to the GameCube.
|
||||
|
||||
If you have PSO Plus or Episode III, it won't want to connect to a server on the same local network as the GameCube itself, as determined by the GameCube's IP address and subnet mask. In the old days, one way to get around this was to create a fake network adapter on the server (or use an existing real one) that has an IP address on a different subnet, tell the GameCube that the server is the default gateway (as above), and have the server reply to the DNS request with its non-local IP address. To do this with newserv, just set LocalAddress in the config file to a different interface. For example, if the GameCube is on the 192.168.0.x network and your other adapter has address 10.0.1.6, set newserv's LocalAddress to 10.0.1.6 and set PSO's DNS server and default gateway addresses to the server's 192.168.0.x address. This may not work on modern systems or on non-Windows machines - I haven't tested it in many years.
|
||||
|
||||
#### PSO GC on Dolphin
|
||||
|
||||
If you're using the HLE BBA type, set the BBA's DNS server address to newserv's IP address and it should work. (If newserv is on the same machine as Dolphin, try your local IP address or 127.0.0.1.) In PSO, use the example values below in PSO's network configuration.
|
||||
|
||||
If you're using the TAP BBA type, you'll have to set PSO's network settings appropriately for your tap interface. Set the DNS server address in PSO's network settings to newserv's IP address.
|
||||
|
||||
If you're using a version of Dolphin with tapserver support, you can make it connect to a newserv instance running on the same machine via the tapserver interface. You do not need to install or run tapserver. To do this:
|
||||
1. Set Dolphin's BBA type to tapserver (Config -> GameCube -> SP1).
|
||||
2. Enable newserv's IP stack simulator according to the comments in config.json and start newserv.
|
||||
3. In PSO's network settings, enable DHCP ("Automatically obtain an IP address"), set DNS server address to "Automatic", and leave DHCP Hostname as "Not set". Leave the proxy server settings blank.
|
||||
4. Start an online game.
|
||||
|
||||
### Connecting external clients
|
||||
|
||||
If you want to accept connections from outside your local network, you'll need to set ExternalAddress to your public IP address in the configuration file, and you'll likely need to open some ports in your router's NAT configuration - specifically, all the TCP ports listed in PortConfiguration in config.json.
|
||||
|
||||
For GC clients, you'll have to use newserv's built-in DNS server or set up your own DNS server as well. If you want external clients to be able to use your DNS server, you'll have to forward UDP port 53 to your newserv instance. Remote players can then connect to your server by entering your DNS server's IP address in their client's network configuration.
|
||||
|
||||
### Non-server features
|
||||
|
||||
newserv has many CLI options, which can be used to access functionality other than the game and proxy server. Run `newserv help` to see these options and how to use them. The non-server things newserv can do are:
|
||||
|
||||
* Compress or decompress data in PRS, PR2, or BC0 format (`compress-prs`, `compress-pr2`, `compress-bc0`, `decompress-prs`, `decompress-pr2`, `decompress-bc0`)
|
||||
* Compute the decompressed size of compressed PRS data without decompressing it (`prs-size`)
|
||||
* Encrypt or decrypt data using any PSO version's network encryption scheme (`encrypt-data`, `decrypt-data`)
|
||||
* Encrypt or decrypt data using Episode 3's trivial scheme (`encrypt-trivial-data`, `decrypt-trivial-data`)
|
||||
* Encrypt or decrypt data using the Challenge Mode text algorithm (`encrypt-challenge-data`, `decrypt-challenge-data`)
|
||||
* Encrypt or decrypt PSO GC save data (.gci files) (`encrypt-gci-save`, `decrypt-gci-save`)
|
||||
* Convert a PSO GC or Episode 3 snapshot file to a BMP image (`decode-gci-snapshot`)
|
||||
* Find the likely round1 or round2 seed for a corrupt save file (`salvage-gci`)
|
||||
* Run a brute-force search for a decryption seed (`find-decryption-seed`)
|
||||
* Decode Shift-JIS text to UTF-16 (`decode-sjis`)
|
||||
* Convert quests in .gci, .vms, .dlq, or .qst format to .bin/.dat format (`decode-gci`, `decode-vms`, `decode-dlq`, `decode-qst`)
|
||||
* Convert quests in .bin/.dat to .qst format (`encode-qst`)
|
||||
* Convert text archives (e.g. TextEnglish.pr2) to JSON and vice versa (`decode-text-archive`, `encode-text-archive`)
|
||||
* Disassemble quest scripts (`disassemble-quest-script`)
|
||||
* Format Episode 3 game data in a human-readable manner (`show-ep3-maps`, `show-ep3-cards`)
|
||||
* Convert item data to a human-readable description, or vice versa (`describe-item`, `encode-item`)
|
||||
* Connect to another PSO server and pretend to be a client (`cat-client`)
|
||||
* Replay a session log for testing (`replay-log`)
|
||||
* Extract the contents of a .gsl or .bml archive (`extract-gsl`, `extract-bml`)
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
## General
|
||||
|
||||
- Test PSOX (blocked on Insignia private server support)
|
||||
- Implement server-side drops on non-BB game versions
|
||||
- Find a way to silence audio in RunDOL.s
|
||||
- Encapsulate BB server-side random state and make replays deterministic
|
||||
- Implement choice search
|
||||
- Write a simple status API
|
||||
- Implement per-game logging
|
||||
- Add default values in all command structures (like we use for Episode 3 battle commands)
|
||||
- Check for RCE potential in 6x6B-6x6E commands
|
||||
- Build an exception-handling abstraction in ChatCommands that shows formatted error messages in all cases
|
||||
- Make reloading happen on separate threads so compression doesn't block active clients
|
||||
- Implement decrypt/encrypt actions for VMS files
|
||||
- Make UI strings localizable (e.g. entries in menus, welcome message, etc.)
|
||||
- Figure out what causes the corruption message on PC proxy sessions and fix it
|
||||
- Enable item tracking in battle/challenge games (everything should already be set up for it to work)
|
||||
- Rewrite REL-based parsers so they don't assume any fixed offsets
|
||||
|
||||
## Episode 3
|
||||
|
||||
- Make disconnecting during a tournament match cause you to forfeit the match
|
||||
- Enforce tournament deck restrictions (e.g. rank checks, No Assist option) when populating COMs at tournament start time
|
||||
- It may be possible to send spectators back to the waiting room after a non-tournament battle by sending 6xB4x05 with environment 0x19, then 6xB4x3B again; try this
|
||||
- Add support for recording battles on the proxy server (both in primary and spectator teams)
|
||||
- When `reload ep3` happens and the defs file is changed, send the new defs file to all connected players who aren't in a game (if this even works - when exactly does the client decompress the defs file from the server?)
|
||||
- Make `reload licenses` not vulnerable to online players' licenses overwriting licenses on disk somehow
|
||||
- Implement ranks (based on total Meseta earned)
|
||||
|
||||
## PSOBB
|
||||
|
||||
- Find any remaining mismatches in enemy IDs / experience
|
||||
- Support EXP multipliers
|
||||
- Sale prices for non-rare weapons with specials are computed incorrectly when buying/selling at shops
|
||||
- Replace enemy list, game episode, etc. with quest data when loading a quest
|
||||
- Implement trade window
|
||||
- Fix some edge cases on the BB proxy server (e.g. Change Ship)
|
||||
- Implement less-common subcommands
|
||||
- 6xAC: Sort inventory
|
||||
- 6xC1, 6xC2, 6xCD, 6xCE
|
||||
- 6xCC: Exchange item for team points
|
||||
- 6xD8: Add S-rank weapon special
|
||||
- 6xDE: Good Luck quest
|
||||
- 6xE0
|
||||
- 6xE1: Gallon's Plan quest
|
||||
- Implement team commands
|
||||
@@ -0,0 +1,16 @@
|
||||
struct AITalkBin {
|
||||
be_uint32_t num_scs;
|
||||
be_uint32_t sc_offsets[num_scs];
|
||||
|
||||
struct SCDialogueEntry {
|
||||
be_uint32_t num_entries;
|
||||
be_uint32_t unknown_a1;
|
||||
be_uint32_t size; // in bytes
|
||||
struct WhenEntry {
|
||||
be_uint32_t when;
|
||||
be_uint32_t percent_chance; // 0-100
|
||||
be_uint32_t count;
|
||||
be_uint32_t string_ids[count];
|
||||
} __attribute__((packed));
|
||||
} __attribute__((packed));
|
||||
} __attribute__((packed));
|
||||
@@ -0,0 +1,266 @@
|
||||
(Ep1&2 USA) Unlock all songs in BGM test
|
||||
(Note: sadly, there are no secret/unused ones)
|
||||
04368960 38600001
|
||||
04368964 4E800020
|
||||
|
||||
(Ep1&2 USA v1.01) Play lobby (and event) music on Pioneer 2 also
|
||||
0417E0F0 60000000
|
||||
|
||||
(Ep3 USA) Play lobby (and event) music in Morgue also
|
||||
040B7028 60000000
|
||||
|
||||
(Ep3 USA) Skip white logo screens during startup
|
||||
0409D774 38000007
|
||||
(Episodes 1&2 USA v1.01) Skip white logo screens during startup
|
||||
0413F190 38000007
|
||||
|
||||
(Ep3 USA) Skip agreement prompts before online game
|
||||
041B50C8 38000003
|
||||
(Episodes 1&2 USA v1.01) Skip agreement prompt before online game
|
||||
04327D80 38000003
|
||||
|
||||
(Ep3 USA) Disable rate limit for pressing A during loading screens
|
||||
042F9B30 38000000
|
||||
|
||||
(Ep3 USA) Auto-press A as fast as possible during loading screens
|
||||
042F9AC0 60000000
|
||||
|
||||
(Ep3 USA) Replace loading screen A button sounds with random sounds
|
||||
042F9B18 4804BB19
|
||||
042F9B1C 5463063E
|
||||
042F9B20 60631400
|
||||
042F9B24 64630005
|
||||
042F9B28 38800000
|
||||
|
||||
(Ep3 USA) Change color of loading screens
|
||||
(Replace AA, RR, GG, BB appropriately)
|
||||
042FA704 3CC0AARR
|
||||
042FA708 60C6GGBB
|
||||
|
||||
(Ep3 USA) Use 16:9 aspect ratio
|
||||
04383DC8 4BC87F99
|
||||
0400BD60 C042DED0
|
||||
0400BD64 EC5D00B2
|
||||
0400BD68 4E800020
|
||||
|
||||
(Ep3 USA) Disable darkening effect during battle details mode
|
||||
042F951C 4E800020
|
||||
|
||||
(Ep3 USA) Unlock all COM decks
|
||||
042CA908 38600001
|
||||
|
||||
(Ep3 USA) Enable all lobby counter options in non-CARD lobbies
|
||||
04096A8C 480000C0
|
||||
04096B4C 38800007
|
||||
04096BFC 4BFFFF2C
|
||||
|
||||
(Ep3 USA) Change HUD color mask
|
||||
0438CA8C 3C00RRGG
|
||||
0438CA90 6000BBAA
|
||||
|
||||
(Ep3 USA) Disable lobby event music (but keep the visuals)
|
||||
040B705C 38000000
|
||||
|
||||
(Ep3 USA) Enable Pinz's Shop Super Card Capsule Machine as a fourth option
|
||||
043101C0 38800004
|
||||
04310238 2C1D0004
|
||||
04487E8C 000000C8
|
||||
|
||||
(Ep3 USA) Change color of pulsing orange text (e.g. card ability names)
|
||||
0457EE18 RRRRRRRR // Phase 1 (long) red component as 32-bit float (0.0-255.0)
|
||||
0457EE20 GGGGGGGG // Phase 1 (long) green component as 32-bit float (0.0-255.0)
|
||||
0457EE10 BBBBBBBB // Phase 1 (long) blue component as 32-bit float (0.0-255.0)
|
||||
0457EE1C RRRRRRRR // Phase 2 (short) red component as 32-bit float (0.0-255.0)
|
||||
0457EE24 GGGGGGGG // Phase 2 (short) green component as 32-bit float (0.0-255.0)
|
||||
0457EE14 BBBBBBBB // Phase 2 (short) blue component as 32-bit float (0.0-255.0)
|
||||
|
||||
(Ep3 USA) Change color of pulsing orange text to be random every frame
|
||||
04155D78 7CA802A6
|
||||
04155D7C 7C661B78
|
||||
04155D80 481EF8B1
|
||||
04155D84 7C671B78
|
||||
04155D88 481EF8A9
|
||||
04155D8C 50677822
|
||||
04155D90 64E7FF00
|
||||
04155D94 90E60024
|
||||
04155D98 7CA803A6
|
||||
04155D9C 4E800020
|
||||
|
||||
(Ep3 USA) Enable color and symbol codes in info board text
|
||||
(Use codes like e.g. $CG to change text colors, as described in CommandFormats.hh)
|
||||
040F2E80 4BF0D41D
|
||||
040F0274 4BF10025
|
||||
040EFC58 4BF10641
|
||||
04000298 38810008
|
||||
0400029C 38C3FFFF
|
||||
040002A0 8CA60001
|
||||
040002A4 28050024
|
||||
040002A8 4082000C
|
||||
040002AC 38000009
|
||||
040002B0 98060000
|
||||
040002B4 28050000
|
||||
040002B8 4082FFE8
|
||||
040002BC 7C633050
|
||||
040002C0 4E800020
|
||||
|
||||
(Ep3 USA) Unlock all offline free battle maps
|
||||
042CAA00 38600001
|
||||
(This unlocks ALL maps, including a bunch of maps with garbage names that crash if you try to play them)
|
||||
|
||||
(Ep3 USA) Talk to auction counter offline to get all cards
|
||||
042F5D18 4BD160E8
|
||||
0400BE00 9421FFE0
|
||||
0400BE04 7C0802A6
|
||||
0400BE08 90010024
|
||||
0400BE0C 93E10010
|
||||
0400BE10 93C10014
|
||||
0400BE14 93A10018
|
||||
0400BE18 9381001C
|
||||
0400BE1C 3C60802A
|
||||
0400BE20 60631BAC
|
||||
0400BE24 7C6903A6
|
||||
0400BE28 38600000
|
||||
0400BE2C 4E800421
|
||||
0400BE30 7C7F1B78
|
||||
0400BE34 3C60802A
|
||||
0400BE38 606315BC
|
||||
0400BE3C 7C6903A6
|
||||
0400BE40 7FE3FB78
|
||||
0400BE44 4E800421
|
||||
0400BE48 3F80802A
|
||||
0400BE4C 639C17AC
|
||||
0400BE50 3BC00001
|
||||
0400BE54 3BA00063
|
||||
0400BE58 7FE3FB78
|
||||
0400BE5C 7FC4F378
|
||||
0400BE60 7F8903A6
|
||||
0400BE64 4E800421
|
||||
0400BE68 3BBDFFFF
|
||||
0400BE6C 281D0000
|
||||
0400BE70 4082FFE8
|
||||
0400BE74 3BDE0001
|
||||
0400BE78 281E02F0
|
||||
0400BE7C 4081FFD8
|
||||
0400BE80 3C60802A
|
||||
0400BE84 6063160C
|
||||
0400BE88 7C6903A6
|
||||
0400BE8C 7FE3FB78
|
||||
0400BE90 4E800421
|
||||
0400BE94 83E10010
|
||||
0400BE98 83C10014
|
||||
0400BE9C 83A10018
|
||||
0400BEA0 8381001C
|
||||
0400BEA4 80010024
|
||||
0400BEA8 38210020
|
||||
0400BEAC 7C0803A6
|
||||
0400BEB0 482E9FC0
|
||||
|
||||
(Episodes 1&2 USA v1.01) Press L for enemy debug; enable various other debug messages
|
||||
040FD9D8 38600001 # Various enemy debug messages
|
||||
00153E53 00000001 # Poison fog debug 1
|
||||
00153E4B 00000001 # Poison fog debug 2
|
||||
040FDA18 60000000 # TObjRoomId
|
||||
025CB6AA 00000000
|
||||
4A588EA0 00000040
|
||||
025CB6AA 00000001
|
||||
TODO: Figure out more debug message conditionals (vars/functions) and add them here
|
||||
|
||||
(Episode 3 USA) Able to find VIP cards offline (but they're still rare)
|
||||
042C0B20 4800000C
|
||||
|
||||
(Ep3 USA) Hold L when starting battle to enter debug menu
|
||||
042C5460 4BD3AF78
|
||||
040003D8 3C60804A
|
||||
040003DC 60630518
|
||||
040003E0 3C800002
|
||||
040003E4 480C9F35
|
||||
040003E8 2C030000
|
||||
040003EC 4082000C
|
||||
040003F0 8801001A
|
||||
040003F4 48000008
|
||||
040003F8 3800001A
|
||||
040003FC 482C5068
|
||||
|
||||
(Ep3 USA) Dressing room always accessible
|
||||
041A16FC 38600001
|
||||
|
||||
(Ep3 USA) Full dressing room v1
|
||||
Can't change your class, but you start with your existing appearance
|
||||
Go online with this code on after using the dressing room to fully save changes
|
||||
0418EB5C 60000000
|
||||
042A0184 389D0370
|
||||
042A0188 387E2120
|
||||
|
||||
(Ep3 USA) Full dressing room v2
|
||||
Can change your class, but you start with the default appearance
|
||||
Go online with this code on after using the dressing room to fully save changes
|
||||
04186ECC 4BFFFFD8
|
||||
042A0184 389D0370
|
||||
042A0188 387E2120
|
||||
|
||||
(Ep3 USA) Replace Options menu with debug menu
|
||||
04149E70 38600019
|
||||
|
||||
(Ep3 USA) Jukebox is free
|
||||
0430D1DC 48000024
|
||||
|
||||
(Ep3 USA) Use own character in battle (online only)
|
||||
041FFAB0 4800001C
|
||||
042A54D8 4BD5B0F9
|
||||
04200A34 4BDFFB9D
|
||||
041FFA9C 4BE00B35
|
||||
040005D0 38600000
|
||||
040005D4 3CA08049
|
||||
040005D8 80A54160
|
||||
040005DC 2805000F
|
||||
040005E0 41820008
|
||||
040005E4 481E8E24
|
||||
040005E8 80ADA448
|
||||
040005EC 7C042800
|
||||
040005F0 41820008
|
||||
040005F4 481E8E14
|
||||
040005F8 38600001
|
||||
040005FC 4E800020
|
||||
|
||||
(Ep3 USA) Disable chat smut filter
|
||||
0412F8B8 7D0802A6
|
||||
0412F8BC 7C661B78
|
||||
0412F8C0 7C872378
|
||||
0412F8C4 48217285
|
||||
0412F8C8 38A30001
|
||||
0412F8CC 7CE33B78
|
||||
0412F8D0 7CC43378
|
||||
0412F8D4 7D0803A6
|
||||
0412F8D8 4BEDEBF4
|
||||
|
||||
(Ep3 USA) Metal tiles don't appear in Simulator map
|
||||
04296904 4E800020
|
||||
|
||||
(Ep3 USA) Enable Boooo and Laughter soundchat sounds
|
||||
Note: Without a TextEnglish.pr2/pr3 patch, the menu items for these sounds will be blank (but they will still work)
|
||||
0430B734 38800029
|
||||
0430B770 2C1F0029
|
||||
0430B59C 2C030029
|
||||
0430B5A8 5460083C
|
||||
0430B5B4 7C63022E
|
||||
0442B690 80258026
|
||||
0442B694 8227852D
|
||||
0442B698 80308031
|
||||
0442B69C 8A3F8532
|
||||
0442B6A0 8A408533
|
||||
0442B6A4 8A418A28
|
||||
0442B6A8 8A388A29
|
||||
0442B6AC 8A39852E
|
||||
0442B6B0 802F853D
|
||||
0442B6B4 85348535
|
||||
0442B6B8 853B8536
|
||||
0442B6BC 8537852B
|
||||
0442B6C0 853A853C
|
||||
0442B6C4 853E8044
|
||||
0442B6C8 80458046
|
||||
0442B6CC 80478048
|
||||
0442B6D0 8049804A
|
||||
0442B6D4 804B804C
|
||||
0442B6D8 804D804E
|
||||
0442B6DC 804F802A
|
||||
0442B6E0 802C0000
|
||||
@@ -0,0 +1,5 @@
|
||||
DC NTE: pso02.dricas.ne.jp
|
||||
Nov 2000 proto: test1.st-pso.games.sega.net
|
||||
Dec 2000 proto: sg107634.csrd.sega.co.jp
|
||||
Jan 2001 proto: master.pso.dream-key.com
|
||||
Aug 2001 proto (v2): ???
|
||||
@@ -0,0 +1,45 @@
|
||||
Ep3 card text corrections (from THG Discord):
|
||||
- AP Absorption: Does not block Tech attacks, instead they deal 2 extra damage.
|
||||
- Assault: Adds 5 AP minus the number of FCs on your field, not in your deck.
|
||||
- Assist Return: If this replaces an Assist card that was not in its owner's own Assist slot, that card gets re-played in to that slot.
|
||||
- Barble: His "Unfilial" ability does 3 damage, not 1.
|
||||
- Berdysh: Equip requirements are Hunter and Humanoid, not either one.
|
||||
- Black King Bar: "Machine Influence" doesn't need the opponent to be an attacker.
|
||||
- Blade Dance: "Insanity" doesn't exist. Has "Steady Damage".
|
||||
- Combo/Explosion: Adds +(# of Combo cards played in phase squared) AP, but the effect only applies once per attacker.
|
||||
- EGM: "Timed EXP Sacrifice" gives 9 EXP, not 6.
|
||||
- Fix: Sets all FC attacks to 2 damage, not FC attackers to 2 AP.
|
||||
- Flatland: Allows summoning in any space on the board, not summoning for free.
|
||||
- Ghost Blast: Damage added is 1/3 death count, not 1x.
|
||||
- Gibbles +: Curse' sets MV to 1 for 6 turns, not permanently.
|
||||
- Govulmer: His "AP Silence" reduces AP by 3, not to 0.
|
||||
- Guil Shark: +2 damage per Guil for the "Group" ability, not +1.
|
||||
- Gulgus: His "Copy" ability gives full AP and TP, not 1/2.
|
||||
- Holy Ray: Doesn't have the "Enemy Bonus" ability.
|
||||
- Kaladbolg: "Attack AC Unable" was a lie.
|
||||
- Lock on 3: Also has the ability "DEF Cost 4 Disable".
|
||||
- Mighty Knuckle: Adds 1.5x points spent as damage, not those points +1.
|
||||
- Migium: Gains TP from it's "Combo" ability, not AP.
|
||||
- Orland: "Sword AP Count" looks at your team, not the whole field.
|
||||
- Pofuilly Slime: His "Copy" ability gives 1/2 AP and TP, not full.
|
||||
- Rainbow Baton: Correctly reads as Tech OK.
|
||||
- Red Slicer: "Native Influence" doesn't need the opponent to be an attacker.
|
||||
- Rufina: She doubles the AP of action cards used, not her own.
|
||||
- Unit Blow: Adds +3 AP per Unit Blow played in the entire Combat Phase, but the effect only applies once per attacker.
|
||||
|
||||
List of changes Sega made to Ep3 cards online (from THG Discord):
|
||||
- Rebalanced Vanilla Cards (E rank is gone, so some cards nerfed b/c they aren’t locked to 1x)
|
||||
- Meteor Cudgel: [Cost]5 ---> [Cost]4
|
||||
- Frozen Shooter: Frozen Target now only freezes self for 2 Turns, on a 20% chance.
|
||||
- Snow Queen: Frozen Target now only freezes self for 2 Turns, on a 25% chance.
|
||||
- Hand Break: Hand Disruptor added (old card description is now accurate)
|
||||
- Rush: [Cost]6 [AP]+0 ---> [Cost]4 [AP]+1
|
||||
- Explosion: [Cost]5 ---> [Cost]4
|
||||
- Resta: Range changed to Anti’s range (hits all ally SCs and FCs)
|
||||
- Dice Half: [Cost]5 ---> [Cost]4
|
||||
- Resistance: [Cost]5 ---> [Cost]4
|
||||
- Independant: [Cost]4 ---> [Cost]3
|
||||
- Dreamaga: [Cost]1 ---> [Cost]2
|
||||
- Dengeki: [Cost]1 ---> [Cost]2
|
||||
- EGM: [Cost]1 ---> [Cost]2
|
||||
- Beat: [AP]+5 ---> [AP]+4
|
||||
@@ -0,0 +1,127 @@
|
||||
|
||||
0457EE18 437F0000 CG_color_r_phase1
|
||||
0457EE20 00000000 CG_color_g_phase1
|
||||
0457EE10 00000000 CG_color_b_phase1
|
||||
0457EE1C 00000000 CG_color_r_phase2
|
||||
0457EE24 437F0000 CG_color_g_phase2
|
||||
0457EE14 00000000 CG_color_b_phase2
|
||||
|
||||
437F0000 == 255.0f
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(Ep3 USA) Change color of pulsing orange text (e.g. card ability names)
|
||||
0457EE18 RRRRRRRR // Phase 1 (long) red component as 32-bit float (0.0-255.0)
|
||||
0457EE20 GGGGGGGG // Phase 1 (long) green component as 32-bit float (0.0-255.0)
|
||||
0457EE10 BBBBBBBB // Phase 1 (long) blue component as 32-bit float (0.0-255.0)
|
||||
0457EE1C RRRRRRRR // Phase 2 (short) red component as 32-bit float (0.0-255.0)
|
||||
0457EE24 GGGGGGGG // Phase 2 (short) green component as 32-bit float (0.0-255.0)
|
||||
0457EE14 BBBBBBBB // Phase 2 (short) blue component as 32-bit float (0.0-255.0)
|
||||
|
||||
(Ep3 USA) Change color of pulsing orange text to be random every frame
|
||||
04155D78 7CA802A6
|
||||
04155D7C 7C661B78
|
||||
04155D80 481EF8B1
|
||||
04155D84 7C671B78
|
||||
04155D88 481EF8A9
|
||||
04155D8C 50677822
|
||||
04155D90 64E7FF00
|
||||
04155D94 90E60024
|
||||
04155D98 7CA803A6
|
||||
04155D9C 4E800020
|
||||
|
||||
|
||||
|
||||
color codes in info board
|
||||
|
||||
patch 800F2E80 48253CC9 bl strlen
|
||||
./m68kdasm --assemble-ppc32 --ppc32 --start-address=800F2E80
|
||||
bl [8000029C]
|
||||
040F2E80 4BF0D41D bl -0x000F2BE4 /* 8000029C */
|
||||
|
||||
patch/preserve 800f0274 38810008 addi param_2,r1,0x8
|
||||
./m68kdasm --assemble-ppc32 --ppc32 --start-address=800F0274
|
||||
bl [80000298]
|
||||
040F0274 4BF10025 bl -0x000EFFDC /* 80000298 */
|
||||
|
||||
patch/preserve 800efc58 38810008 addi r4,r1,0x8
|
||||
./m68kdasm --assemble-ppc32 --ppc32 --start-address=800EFC58
|
||||
bl [80000298]
|
||||
040EFC58 4BF10641 bl -0x000EF9C0 /* 80000298 */
|
||||
|
||||
./m68kdasm --assemble-ppc32 --ppc32 --start-address=80000298
|
||||
entry_from_send_61_and_send_98:
|
||||
addi r4, r1, 8
|
||||
entry_from_send_D8:
|
||||
subi r6, r3, 1
|
||||
again:
|
||||
lbzu r5, [r6 + 1]
|
||||
cmplwi r5, 0x24
|
||||
bne skip_char
|
||||
li r0, 0x09
|
||||
stb [r6], r0
|
||||
skip_char:
|
||||
cmplwi r5, 0
|
||||
bne again
|
||||
sub r3, r6, r3
|
||||
blr
|
||||
04000298 38810008 addi r4, r1, 0x0008
|
||||
0400029C 38C3FFFF subi r6, r3, 0x0001
|
||||
040002A0 8CA60001 lbzu r5, [r6 + 0x0001]
|
||||
040002A4 28050024 cmplwi r5, 36
|
||||
040002A8 4082000C bne +0x0000000C /* 800002B4 */
|
||||
040002AC 38000009 li r0, 0x0009
|
||||
040002B0 98060000 stb [r6], r0
|
||||
040002B4 28050000 cmplwi r5, 0
|
||||
040002B8 4082FFE8 bne -0x00000018 /* 800002A0 */
|
||||
040002BC 7C633050 subf r3, r3, r6
|
||||
040002C0 4E800020 blr
|
||||
|
||||
|
||||
|
||||
Ep1&2 v1.01 version of the above code
|
||||
|
||||
send_D9
|
||||
./m68kdasm --assemble-ppc32 --ppc32 --start-address=801DA398
|
||||
bl [800002D4]
|
||||
041DA398 4BE25F3D bl -0x001DA0C4 /* 800002D4 */
|
||||
|
||||
send_61
|
||||
./m68kdasm --assemble-ppc32 --ppc32 --start-address=801DC2AC
|
||||
bl [800002D0]
|
||||
041DC2AC 4BE24025 bl -0x001DBFDC /* 800002D0 */
|
||||
|
||||
send_98
|
||||
./m68kdasm --assemble-ppc32 --ppc32 --start-address=801DC144
|
||||
bl [800002D0]
|
||||
041DC144 4BE2418D bl -0x001DBE74 /* 800002D0 */
|
||||
|
||||
./m68kdasm --assemble-ppc32 --ppc32 --start-address=800002D0
|
||||
entry_from_send_61_and_send_98:
|
||||
addi r4, r1, 8
|
||||
entry_from_send_D8:
|
||||
subi r6, r3, 1
|
||||
again:
|
||||
lbzu r5, [r6 + 1]
|
||||
cmplwi r5, 0x24
|
||||
bne skip_char
|
||||
li r0, 0x09
|
||||
stb [r6], r0
|
||||
skip_char:
|
||||
cmplwi r5, 0
|
||||
bne again
|
||||
sub r3, r6, r3
|
||||
blr
|
||||
040002D0 38810008 addi r4, r1, 0x0008
|
||||
040002D4 38C3FFFF subi r6, r3, 0x0001
|
||||
040002D8 8CA60001 lbzu r5, [r6 + 0x0001]
|
||||
040002DC 28050024 cmplwi r5, 36
|
||||
040002E0 4082000C bne +0x0000000C /* 800002EC */
|
||||
040002E4 38000009 li r0, 0x0009
|
||||
040002E8 98060000 stb [r6], r0
|
||||
040002EC 28050000 cmplwi r5, 0
|
||||
040002F0 4082FFE8 bne -0x00000018 /* 800002D8 */
|
||||
040002F4 7C633050 subf r3, r3, r6
|
||||
040002F8 4E800020 blr
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
star value tables
|
||||
|
||||
psobb [B1-437]
|
||||
00010203 04090909 01020304 05090909 01020304 05090909 01020304 05090909 01020304 05090909 00010203 04090909 01020304 05090909 01020304 05090909 01020304 05090909 00010203 09090901 02030409 09090102 03040909 09090A0A 090A0A09 0A0A090C 0B0A0A0A 0A0A0A0B 0A090A0A 0A0A0A09 0A0A0A0A 0A0A0A0A 0A0A0B0A 0C0C0B0A 0A090A09 090A0A0A 0A0C090C 0B0A090A 090C0A0B 0A0A0A0A 0A0A0A0B 0B0A0A0A 09090A09 0C0A0A0A 0B0A0B09 0A0A090A 0A0B090B 0A0B0B0A 090A090A 0B090A0A 0A0A0A0A 0A0A0A09 090C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0009 0A0A0A0B 090A0A09 0A0A0B0A 0A0A0A0A 0A0A0A0A 0A0A0A0A 0A0A0A0A 0A0A0A0A 0B0B0B0B 0B0B0B0B 0B0B0B0A 0C0A0C0B 0A0A0A0A 0A0B0A0B 0B0B0B0B 0A0A090A 0A0A090B 0B0B0B0C 0C0C0C0C 0A0A0C0A 090A0C09 0A0B0A0A 0A0A0C0A 0A0A0A09 0A0C0A09 0A0A0A0A 0A090C0B 09090909 09090909 09090909 09090909 0909090B 0A0C0A0B 0B0C0A0A 0A090A0A 0A0A0B0A 0A0A0A0A 0909090A 0A090C0A 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0102 03040102 03040203 04020304 01020304 01020304 01020304 01020304 01020304 01020304 03040000 00010102 02030304 04050506 06070707 07080808 08080809 09090A0A 0A0A0A0A 0B0C0A0A 0A0A0A0A 0B0B0B0A 0B0B0C0B 0B0B0B0B 0A0A0A0A 0A0A0C09 0909090A 0A0B0C09 0B0A0A0A 0A0A0A0A 0A0A0A0B 0A0A0A0A 0A0A0A00 00010203 03040405 05050606 07070808 08080808 0A0A0A0A 0A0A0909 090A0A0A 0A0A0A0A 0A0A0B0A 0A0B0A09 0909090A 0B0B0000 0B000000 00080808 08080808 09080808 09080808 09070707 07070909 090C0909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 0A0A0B0A 0B0A0909 0B0B0B0C 0A0A0A09 0A0A0A0A 090A0A0A 0A0A0A0A 0A0A0A0A 0203050B 0203050B 0203050B 0203050B 0204060B 0204060B 0203050B 080B080A 0B020305 02030502 03050304 06030405 07080B04 06090406 09040609 06090B06 090B0909 09090909 0A0B0B0B 0B0B0B0B 0B0B0B0B 0B0B0B0B 0B0B0B0B 0A0B0B0B 0B0B0B0B
|
||||
|
||||
psogc [94-2F7]
|
||||
00010203 04090909 01020304 05090909 01020304 05090909 01020304 05090909 01020304 05090909 00010203 04090909 01020304 05090909 01020304 05090909 01020304 05090909 00010203 09090901 02030409 09090102 03040909 09090A0A 090A0A09 0A0A090C 0B0A0A0A 0A0A0A0B 0A090A0A 0A0A0A09 0A0A0A0A 0A0A0A0A 0A0A0B0A 0C0C0B0A 0A090A09 090A0A0A 0A0C090C 0B0A090A 090C0A0B 0A0A0A0A 0A0A0A0B 0B0A0A0A 09090A09 0C0A0A0A 0B0A0B09 0A0A090A 0A0B090B 0A0B0B0A 090A090A 0B090A0A 0A0A0A0A 0A0A0A09 090C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0C0C 0C0C0009 0A0A0A0B 090A0A09 0A0A0B0A 0A0A0A0A 0A0A0A0A 0A0A0A0A 0A0A0A0A 0A0A0A0A 0B0B0B0B 0B0B0B0B 0B0B0B0A 0C0A0C0B 0A0A0A0A 0A0B0A0B 0B0B0B0B 0A0A090A 0A0A090B 0B0B0B0C 0C0C0C0C 01020304 01020304 02030402 03040102 03040102 03040102 03040102 03040102 03040102 03040304 00000001 01020203 03040405 05060607 07070708 08080808 08090909 0A0A0A0A 0A0A0B0C 0A0A0A0A 0A0A0B0B 0B0A0B0B 0C0B0B0B 0B0B0000 01020303 04040505 05060607 07080808 0808080A 0A0A0A0A 0A090909 0A0A0A0A 0A0A0A0A 0A0B0A0A 0B0A0909 09090A0B 0B000000 00000000 08080808 08080809 08080809 08080809 07070707 07090909 0C090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090909 09090902 03050B02 03050B02 03050B02 03050B02 04060B02 04060B02 03050B08 0B080A0B 02030502 03050203 05030406 03040507 080B0406 09040609 04060906 090B0609 0B090909 090909
|
||||
|
||||
|
||||
|
||||
0203050B0203050B0203050B0203050B
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#!/bin/env python3
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def get_ip_address(ifname):
|
||||
data = subprocess.check_output(['ifconfig', ifname])
|
||||
for line in data.splitlines():
|
||||
line = line.strip()
|
||||
if line.startswith(b'inet '):
|
||||
return line.split()[1].decode('ascii')
|
||||
raise RuntimeError('cannot get address for interface ' + ifname)
|
||||
|
||||
|
||||
def main(argv):
|
||||
if len(argv) < 2:
|
||||
raise RuntimeError(f'Usage: {argv[0]} <original-destination> [new-destination]')
|
||||
if os.geteuid() != 0:
|
||||
raise RuntimeError('You must use sudo to run this script')
|
||||
original_destination = argv[1]
|
||||
new_destination = argv[2] if len(argv) > 2 else get_ip_address('en0')
|
||||
|
||||
print(f'Finding occurrences of \"{original_destination}\"')
|
||||
addresses_str = subprocess.check_output(['memwatch', 'Flycast.app', 'find', f'\"{original_destination}\"'])
|
||||
for line in addresses_str.splitlines():
|
||||
# line is like '(0) 00007FFF038500A0 (rw-)' (we care only about the address)
|
||||
tokens = line.split()
|
||||
if len(tokens) != 3:
|
||||
continue
|
||||
print(f'Replacing \"{original_destination}\" with \"{new_destination}\" at {tokens[1]} in Flycast')
|
||||
subprocess.check_call(['memwatch', 'Flycast.app', 'write', tokens[1], f'\"{new_destination}\" 00'])
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 364 B |
Binary file not shown.
|
After Width: | Height: | Size: 364 B |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 442 B |
Binary file not shown.
|
After Width: | Height: | Size: 560 B |
@@ -0,0 +1,56 @@
|
||||
#include "AFSArchive.hh"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
|
||||
using namespace std;
|
||||
|
||||
AFSArchive::AFSArchive(std::shared_ptr<const std::string> data)
|
||||
: data(data) {
|
||||
struct FileHeader {
|
||||
be_uint32_t magic;
|
||||
le_uint32_t num_files;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct FileEntry {
|
||||
le_uint32_t offset;
|
||||
le_uint32_t size;
|
||||
} __attribute__((packed));
|
||||
|
||||
StringReader r(*this->data);
|
||||
const auto& header = r.get<FileHeader>();
|
||||
if (header.magic != 0x41465300) {
|
||||
throw runtime_error("file is not an AFS archive");
|
||||
}
|
||||
|
||||
while (this->entries.size() < header.num_files) {
|
||||
const auto& entry = r.get<FileEntry>();
|
||||
this->entries.emplace_back(Entry{.offset = entry.offset, .size = entry.size});
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<const void*, size_t> AFSArchive::get(size_t index) const {
|
||||
const auto& entry = this->entries.at(index);
|
||||
if (entry.offset > this->data->size()) {
|
||||
throw out_of_range("entry begins beyond end of archive");
|
||||
}
|
||||
if (entry.offset + entry.size > this->data->size()) {
|
||||
throw out_of_range("entry extends beyond end of archive");
|
||||
}
|
||||
|
||||
return make_pair(this->data->data() + entry.offset, entry.size);
|
||||
}
|
||||
|
||||
std::string AFSArchive::get_copy(size_t index) const {
|
||||
auto ret = this->get(index);
|
||||
return string(reinterpret_cast<const char*>(ret.first), ret.second);
|
||||
}
|
||||
|
||||
StringReader AFSArchive::get_reader(size_t index) const {
|
||||
auto ret = this->get(index);
|
||||
return StringReader(ret.first, ret.second);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
class AFSArchive {
|
||||
public:
|
||||
AFSArchive(std::shared_ptr<const std::string> data);
|
||||
~AFSArchive() = default;
|
||||
|
||||
struct Entry {
|
||||
uint64_t offset;
|
||||
uint32_t size;
|
||||
};
|
||||
inline const std::vector<Entry>& all_entries() const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
std::pair<const void*, size_t> get(size_t index) const;
|
||||
std::string get_copy(size_t index) const;
|
||||
StringReader get_reader(size_t index) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<const std::string> data;
|
||||
std::vector<Entry> entries;
|
||||
};
|
||||
@@ -0,0 +1,106 @@
|
||||
#include "BMLArchive.hh"
|
||||
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "Text.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <bool IsBigEndian>
|
||||
struct BMLHeader {
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
|
||||
parray<uint8_t, 0x04> unknown_a1;
|
||||
U32T num_entries;
|
||||
parray<uint8_t, 0x38> unknown_a2;
|
||||
} __attribute__((packed));
|
||||
|
||||
template <bool IsBigEndian>
|
||||
struct BMLHeaderEntry {
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
|
||||
ptext<char, 0x20> filename;
|
||||
U32T compressed_size;
|
||||
parray<uint8_t, 0x04> unknown_a1;
|
||||
U32T decompressed_size;
|
||||
U32T compressed_gvm_size;
|
||||
U32T decompressed_gvm_size;
|
||||
parray<uint8_t, 0x0C> unknown_a2;
|
||||
} __attribute__((packed));
|
||||
|
||||
template <bool IsBigEndian>
|
||||
void BMLArchive::load_t() {
|
||||
StringReader r(*this->data);
|
||||
|
||||
const auto& header = r.get<BMLHeader<IsBigEndian>>();
|
||||
|
||||
size_t offset = 0x800;
|
||||
while (this->entries.size() < header.num_entries) {
|
||||
const auto& entry = r.get<BMLHeaderEntry<IsBigEndian>>();
|
||||
|
||||
if (offset + entry.compressed_size > this->data->size()) {
|
||||
throw runtime_error("BML data entry extends beyond end of data");
|
||||
}
|
||||
size_t data_offset = offset;
|
||||
offset = (offset + entry.compressed_size + 0x1F) & (~0x1F);
|
||||
|
||||
if (offset + entry.compressed_gvm_size > this->data->size()) {
|
||||
throw runtime_error("BML GVM entry extends beyond end of data");
|
||||
}
|
||||
size_t gvm_offset = offset;
|
||||
offset = (offset + entry.compressed_gvm_size + 0x1F) & (~0x1F);
|
||||
|
||||
this->entries.emplace(entry.filename, Entry{data_offset, entry.compressed_size, gvm_offset, entry.compressed_gvm_size});
|
||||
}
|
||||
}
|
||||
|
||||
BMLArchive::BMLArchive(shared_ptr<const string> data, bool big_endian)
|
||||
: data(data) {
|
||||
if (big_endian) {
|
||||
this->load_t<true>();
|
||||
} else {
|
||||
this->load_t<false>();
|
||||
}
|
||||
}
|
||||
|
||||
const unordered_map<string, BMLArchive::Entry> BMLArchive::all_entries() const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
pair<const void*, size_t> BMLArchive::get(const std::string& name) const {
|
||||
try {
|
||||
const auto& entry = this->entries.at(name);
|
||||
return make_pair(this->data->data() + entry.offset, entry.size);
|
||||
} catch (const out_of_range&) {
|
||||
throw out_of_range("BML does not contain file: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
pair<const void*, size_t> BMLArchive::get_gvm(const std::string& name) const {
|
||||
try {
|
||||
const auto& entry = this->entries.at(name);
|
||||
return make_pair(this->data->data() + entry.gvm_offset, entry.gvm_size);
|
||||
} catch (const out_of_range&) {
|
||||
throw out_of_range("BML does not contain file: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
string BMLArchive::get_copy(const string& name) const {
|
||||
try {
|
||||
const auto& entry = this->entries.at(name);
|
||||
return this->data->substr(entry.offset, entry.size);
|
||||
} catch (const out_of_range&) {
|
||||
throw out_of_range("BML does not contain file: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
StringReader BMLArchive::get_reader(const string& name) const {
|
||||
try {
|
||||
const auto& entry = this->entries.at(name);
|
||||
return StringReader(this->data->data() + entry.offset, entry.size);
|
||||
} catch (const out_of_range&) {
|
||||
throw out_of_range("BML does not contain file: " + name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
class BMLArchive {
|
||||
public:
|
||||
BMLArchive(std::shared_ptr<const std::string> data, bool big_endian);
|
||||
~BMLArchive() = default;
|
||||
|
||||
struct Entry {
|
||||
uint64_t offset;
|
||||
uint32_t size;
|
||||
uint64_t gvm_offset;
|
||||
uint32_t gvm_size;
|
||||
};
|
||||
const std::unordered_map<std::string, Entry> all_entries() const;
|
||||
|
||||
std::pair<const void*, size_t> get(const std::string& name) const;
|
||||
std::pair<const void*, size_t> get_gvm(const std::string& name) const;
|
||||
std::string get_copy(const std::string& name) const;
|
||||
StringReader get_reader(const std::string& name) const;
|
||||
|
||||
private:
|
||||
template <bool IsBigEndian>
|
||||
void load_t();
|
||||
|
||||
std::shared_ptr<const std::string> data;
|
||||
|
||||
std::unordered_map<std::string, Entry> entries;
|
||||
};
|
||||
@@ -0,0 +1,115 @@
|
||||
#include "BattleParamsIndex.hh"
|
||||
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
|
||||
#include "Loggers.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "StaticGameData.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
string BattleParamsIndex::Entry::str() const {
|
||||
string a1str = format_data_string(this->unknown_a1.data(), this->unknown_a1.bytes());
|
||||
return string_printf(
|
||||
"BattleParamsEntry[ATP=%hu PSV=%hu EVP=%hu HP=%hu DFP=%hu ATA=%hu LCK=%hu ESP=%hu a1=%s EXP=%" PRIu32 " diff=%" PRIu32 "]",
|
||||
this->atp.load(),
|
||||
this->psv.load(),
|
||||
this->evp.load(),
|
||||
this->hp.load(),
|
||||
this->dfp.load(),
|
||||
this->ata.load(),
|
||||
this->lck.load(),
|
||||
this->esp.load(),
|
||||
a1str.c_str(),
|
||||
this->experience.load(),
|
||||
this->difficulty.load());
|
||||
}
|
||||
|
||||
void BattleParamsIndex::Table::print(FILE* stream) const {
|
||||
auto print_entry = +[](FILE* stream, const Entry& e) {
|
||||
string a1str = format_data_string(e.unknown_a1.data(), e.unknown_a1.bytes());
|
||||
fprintf(stream,
|
||||
"%5hu %5hu %5hu %5hu %5hu %5hu %5hu %5hu %s %5" PRIu32 " %5" PRIu32,
|
||||
e.atp.load(),
|
||||
e.psv.load(),
|
||||
e.evp.load(),
|
||||
e.hp.load(),
|
||||
e.dfp.load(),
|
||||
e.ata.load(),
|
||||
e.lck.load(),
|
||||
e.esp.load(),
|
||||
a1str.c_str(),
|
||||
e.experience.load(),
|
||||
e.difficulty.load());
|
||||
};
|
||||
|
||||
for (size_t diff = 0; diff < 4; diff++) {
|
||||
fprintf(stream, "%c ZZ ATP PSV EVP HP DFP ATA LCK ESP A1 EXP DIFF\n",
|
||||
abbreviation_for_difficulty(diff));
|
||||
for (size_t z = 0; z < 0x60; z++) {
|
||||
fprintf(stream, " %02zX ", z);
|
||||
print_entry(stream, this->difficulty[diff][z]);
|
||||
fputc('\n', stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BattleParamsIndex::BattleParamsIndex(
|
||||
shared_ptr<const string> data_on_ep1,
|
||||
shared_ptr<const string> data_on_ep2,
|
||||
shared_ptr<const string> data_on_ep4,
|
||||
shared_ptr<const string> data_off_ep1,
|
||||
shared_ptr<const string> data_off_ep2,
|
||||
shared_ptr<const string> data_off_ep4) {
|
||||
this->files[0][0].data = data_on_ep1;
|
||||
this->files[0][1].data = data_on_ep2;
|
||||
this->files[0][2].data = data_on_ep4;
|
||||
this->files[1][0].data = data_off_ep1;
|
||||
this->files[1][1].data = data_off_ep2;
|
||||
this->files[1][2].data = data_off_ep4;
|
||||
|
||||
for (uint8_t is_solo = 0; is_solo < 2; is_solo++) {
|
||||
for (uint8_t episode = 0; episode < 3; episode++) {
|
||||
auto& file = this->files[is_solo][episode];
|
||||
if (file.data->size() < sizeof(Table)) {
|
||||
throw runtime_error(string_printf(
|
||||
"battle params table size is incorrect (expected %zX bytes, have %zX bytes; is_solo=%hhu, episode=%hhu)",
|
||||
sizeof(Table), file.data->size(), is_solo, episode));
|
||||
}
|
||||
file.table = reinterpret_cast<const Table*>(file.data->data());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const BattleParamsIndex::Entry& BattleParamsIndex::get(
|
||||
bool solo, Episode episode, uint8_t difficulty, EnemyType type) const {
|
||||
return this->get(solo, episode, difficulty, battle_param_index_for_enemy_type(episode, type));
|
||||
}
|
||||
|
||||
const BattleParamsIndex::Entry& BattleParamsIndex::get(
|
||||
bool solo, Episode episode, uint8_t difficulty, size_t index) const {
|
||||
if (difficulty > 4) {
|
||||
throw invalid_argument("incorrect difficulty");
|
||||
}
|
||||
if (index >= 0x60) {
|
||||
throw invalid_argument("incorrect monster type");
|
||||
}
|
||||
|
||||
uint8_t ep_index;
|
||||
switch (episode) {
|
||||
case Episode::EP1:
|
||||
ep_index = 0;
|
||||
break;
|
||||
case Episode::EP2:
|
||||
ep_index = 1;
|
||||
break;
|
||||
case Episode::EP4:
|
||||
ep_index = 2;
|
||||
break;
|
||||
default:
|
||||
throw invalid_argument("invalid episode");
|
||||
}
|
||||
|
||||
return this->files[!!solo][ep_index].table->difficulty[difficulty][index];
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <memory>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "EnemyType.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
class BattleParamsIndex {
|
||||
public:
|
||||
struct Entry {
|
||||
le_uint16_t atp; // attack power
|
||||
le_uint16_t psv; // perseverance (intelligence?)
|
||||
le_uint16_t evp; // evasion
|
||||
le_uint16_t hp; // hit points
|
||||
le_uint16_t dfp; // defense
|
||||
le_uint16_t ata; // accuracy
|
||||
le_uint16_t lck; // luck
|
||||
le_uint16_t esp; // ???
|
||||
parray<uint8_t, 0x0C> unknown_a1;
|
||||
le_uint32_t experience;
|
||||
le_uint32_t difficulty;
|
||||
|
||||
std::string str() const;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Table {
|
||||
parray<parray<Entry, 0x60>, 4> difficulty;
|
||||
|
||||
void print(FILE* stream) const;
|
||||
} __attribute__((packed));
|
||||
|
||||
BattleParamsIndex(
|
||||
std::shared_ptr<const std::string> data_on_ep1, // BattleParamEntry_on.dat
|
||||
std::shared_ptr<const std::string> data_on_ep2, // BattleParamEntry_lab_on.dat
|
||||
std::shared_ptr<const std::string> data_on_ep4, // BattleParamEntry_ep4_on.dat
|
||||
std::shared_ptr<const std::string> data_off_ep1, // BattleParamEntry.dat
|
||||
std::shared_ptr<const std::string> data_off_ep2, // BattleParamEntry_lab.dat
|
||||
std::shared_ptr<const std::string> data_off_ep4); // BattleParamEntry_ep4.dat
|
||||
|
||||
const Entry& get(
|
||||
bool solo, Episode episode, uint8_t difficulty, EnemyType type) const;
|
||||
const Entry& get(
|
||||
bool solo, Episode episode, uint8_t difficulty, size_t entry_index) const;
|
||||
|
||||
private:
|
||||
struct LoadedFile {
|
||||
std::shared_ptr<const std::string> data;
|
||||
const Table* table;
|
||||
};
|
||||
|
||||
// online/offline, episode
|
||||
LoadedFile files[2][3];
|
||||
};
|
||||
@@ -0,0 +1,137 @@
|
||||
#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::CatSession(
|
||||
shared_ptr<struct event_base> base,
|
||||
const struct sockaddr_storage& remote,
|
||||
GameVersion version,
|
||||
shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file)
|
||||
: Shell(base),
|
||||
log("[CatSession] ", proxy_server_log.min_level),
|
||||
channel(
|
||||
version,
|
||||
CatSession::dispatch_on_channel_input,
|
||||
CatSession::dispatch_on_channel_error,
|
||||
this,
|
||||
"CatSession"),
|
||||
bb_key_file(bb_key_file) {
|
||||
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);
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
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 (this->channel.version != GameVersion::BB) {
|
||||
if (command == 0x02 || command == 0x17 || command == 0x91 || command == 0x9B) {
|
||||
const auto& cmd = check_size_t<S_ServerInitDefault_DC_PC_V3_02_17_91_9B>(data, 0xFFFF);
|
||||
if ((this->channel.version == GameVersion::GC) ||
|
||||
(this->channel.version == GameVersion::XB)) {
|
||||
this->channel.crypt_in.reset(new PSOV3Encryption(cmd.server_key));
|
||||
this->channel.crypt_out.reset(new 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.reset(new PSOV2Encryption(cmd.server_key));
|
||||
this->channel.crypt_out.reset(new 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.reset(new PSOBBEncryption(*this->bb_key_file, &cmd.server_key[0], sizeof(cmd.server_key)));
|
||||
this->channel.crypt_out.reset(new PSOBBEncryption(*this->bb_key_file, &cmd.client_key[0], sizeof(cmd.client_key)));
|
||||
this->log.info("Enabled BB encryption");
|
||||
}
|
||||
}
|
||||
|
||||
// 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::print_prompt() {}
|
||||
|
||||
void CatSession::execute_command(const std::string& command) {
|
||||
string full_cmd = parse_data_string(command, nullptr, ParseDataFlags::ALLOW_FILES);
|
||||
send_command_with_header(this->channel, full_cmd.data(), full_cmd.size());
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#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"
|
||||
#include "Shell.hh"
|
||||
|
||||
class CatSession : public Shell {
|
||||
public:
|
||||
CatSession(
|
||||
std::shared_ptr<struct event_base> base,
|
||||
const struct sockaddr_storage& remote,
|
||||
GameVersion version,
|
||||
std::shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file);
|
||||
virtual ~CatSession() = default;
|
||||
|
||||
protected:
|
||||
PrefixedLogger log;
|
||||
Channel channel;
|
||||
std::shared_ptr<const PSOBBEncryption::KeyFile> bb_key_file;
|
||||
|
||||
virtual void print_prompt();
|
||||
virtual void execute_command(const std::string& command);
|
||||
|
||||
static void dispatch_on_channel_input(
|
||||
Channel& ch, uint16_t command, uint32_t flag, std::string& msg);
|
||||
static void dispatch_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);
|
||||
};
|
||||
+92
-75
@@ -1,32 +1,27 @@
|
||||
#include "Channel.hh"
|
||||
|
||||
#include <errno.h>
|
||||
#include <event2/buffer.h>
|
||||
#include <event2/bufferevent.h>
|
||||
#include <event2/event.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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(
|
||||
GameVersion version,
|
||||
on_command_received_t on_command_received,
|
||||
@@ -35,14 +30,14 @@ Channel::Channel(
|
||||
const string& name,
|
||||
TerminalFormat terminal_send_color,
|
||||
TerminalFormat terminal_recv_color)
|
||||
: bev(nullptr, flush_and_free_bufferevent),
|
||||
version(version),
|
||||
name(name),
|
||||
terminal_send_color(terminal_send_color),
|
||||
terminal_recv_color(terminal_recv_color),
|
||||
on_command_received(on_command_received),
|
||||
on_error(on_error),
|
||||
context_obj(context_obj) {
|
||||
: bev(nullptr, flush_and_free_bufferevent),
|
||||
version(version),
|
||||
name(name),
|
||||
terminal_send_color(terminal_send_color),
|
||||
terminal_recv_color(terminal_recv_color),
|
||||
on_command_received(on_command_received),
|
||||
on_error(on_error),
|
||||
context_obj(context_obj) {
|
||||
}
|
||||
|
||||
Channel::Channel(
|
||||
@@ -54,14 +49,14 @@ Channel::Channel(
|
||||
const string& name,
|
||||
TerminalFormat terminal_send_color,
|
||||
TerminalFormat terminal_recv_color)
|
||||
: bev(nullptr, flush_and_free_bufferevent),
|
||||
version(version),
|
||||
name(name),
|
||||
terminal_send_color(terminal_send_color),
|
||||
terminal_recv_color(terminal_recv_color),
|
||||
on_command_received(on_command_received),
|
||||
on_error(on_error),
|
||||
context_obj(context_obj) {
|
||||
: bev(nullptr, flush_and_free_bufferevent),
|
||||
version(version),
|
||||
name(name),
|
||||
terminal_send_color(terminal_send_color),
|
||||
terminal_recv_color(terminal_recv_color),
|
||||
on_command_received(on_command_received),
|
||||
on_error(on_error),
|
||||
context_obj(context_obj) {
|
||||
this->set_bufferevent(bev);
|
||||
}
|
||||
|
||||
@@ -113,8 +108,6 @@ void Channel::set_bufferevent(struct bufferevent* bev) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Channel::disconnect() {
|
||||
if (this->bev.get()) {
|
||||
// If the output buffer is not empty, move the bufferevent into the draining
|
||||
@@ -133,7 +126,8 @@ void Channel::disconnect() {
|
||||
auto on_error = +[](struct bufferevent* bev, short events, void*) -> void {
|
||||
if (events & BEV_EVENT_ERROR) {
|
||||
int err = EVUTIL_SOCKET_ERROR();
|
||||
log(WARNING, "Disconnecting channel caused error %d (%s)", err,
|
||||
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)) {
|
||||
@@ -155,15 +149,12 @@ void Channel::disconnect() {
|
||||
this->crypt_out.reset();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Channel::Message Channel::recv(bool print_contents) {
|
||||
Channel::Message Channel::recv() {
|
||||
struct evbuffer* buf = bufferevent_get_input(this->bev.get());
|
||||
|
||||
size_t header_size = (this->version == GameVersion::BB) ? 8 : 4;
|
||||
PSOCommandHeader header;
|
||||
if (evbuffer_copyout(buf, &header, header_size)
|
||||
< static_cast<ssize_t>(header_size)) {
|
||||
if (evbuffer_copyout(buf, &header, header_size) < static_cast<ssize_t>(header_size)) {
|
||||
throw out_of_range("no command available");
|
||||
}
|
||||
|
||||
@@ -177,7 +168,8 @@ Channel::Message Channel::recv(bool print_contents) {
|
||||
// is not reflected in the size field. This logic does not occur if encryption
|
||||
// is not yet enabled.
|
||||
size_t command_physical_size = (this->crypt_in.get() && (version == GameVersion::BB))
|
||||
? ((command_logical_size + 7) & ~7) : command_logical_size;
|
||||
? ((command_logical_size + 7) & ~7)
|
||||
: command_logical_size;
|
||||
if (evbuffer_get_length(buf) < command_physical_size) {
|
||||
throw out_of_range("no command available");
|
||||
}
|
||||
@@ -188,8 +180,7 @@ Channel::Message Channel::recv(bool print_contents) {
|
||||
// consistent state.
|
||||
|
||||
string header_data(header_size, '\0');
|
||||
if (evbuffer_remove(buf, header_data.data(), header_data.size())
|
||||
< static_cast<ssize_t>(header_data.size())) {
|
||||
if (evbuffer_remove(buf, header_data.data(), header_data.size()) < static_cast<ssize_t>(header_data.size())) {
|
||||
throw logic_error("enough bytes available, but could not remove them");
|
||||
}
|
||||
if (this->crypt_in.get()) {
|
||||
@@ -197,34 +188,46 @@ Channel::Message Channel::recv(bool print_contents) {
|
||||
}
|
||||
|
||||
string command_data(command_physical_size - header_size, '\0');
|
||||
if (evbuffer_remove(buf, command_data.data(), command_data.size())
|
||||
< static_cast<ssize_t>(command_data.size())) {
|
||||
if (evbuffer_remove(buf, command_data.data(), command_data.size()) < static_cast<ssize_t>(command_data.size())) {
|
||||
throw logic_error("enough bytes available, but could not remove them");
|
||||
}
|
||||
|
||||
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 (print_contents && (this->terminal_recv_color != TerminalFormat::END)) {
|
||||
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);
|
||||
}
|
||||
|
||||
string name_token;
|
||||
if (!this->name.empty()) {
|
||||
name_token = " from " + this->name;
|
||||
if (version == GameVersion::BB) {
|
||||
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_version(this->version),
|
||||
header.command(this->version),
|
||||
header.flag(this->version));
|
||||
}
|
||||
log(INFO, "Received%s (version=%s command=%04hX flag=%08X)",
|
||||
name_token.c_str(),
|
||||
name_for_version(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);
|
||||
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);
|
||||
@@ -232,25 +235,35 @@ Channel::Message Channel::recv(bool print_contents) {
|
||||
}
|
||||
|
||||
return {
|
||||
.command = header.command(this->version),
|
||||
.flag = header.flag(this->version),
|
||||
.data = move(command_data),
|
||||
.command = header.command(this->version),
|
||||
.flag = header.flag(this->version),
|
||||
.data = std::move(command_data),
|
||||
};
|
||||
}
|
||||
|
||||
void Channel::send(uint16_t cmd, uint32_t flag, const void* data, size_t size,
|
||||
bool print_contents) {
|
||||
void Channel::send(uint16_t cmd, uint32_t flag, bool 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()) {
|
||||
log(WARNING, "Attempted to send command on closed channel; dropping data");
|
||||
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 GameVersion::DC:
|
||||
case GameVersion::GC:
|
||||
case GameVersion::DC: {
|
||||
PSOCommandHeaderDCGC header;
|
||||
case GameVersion::XB: {
|
||||
PSOCommandHeaderDCV3 header;
|
||||
if (this->crypt_out.get()) {
|
||||
send_data_size = (sizeof(header) + size + 3) & ~3;
|
||||
} else {
|
||||
@@ -306,28 +319,30 @@ void Channel::send(uint16_t cmd, uint32_t flag, const void* data, size_t size,
|
||||
throw logic_error("unimplemented game version in send_command");
|
||||
}
|
||||
|
||||
// All versions of PSO I've seen (PC, GC, BB) have a receive buffer 0x7C00
|
||||
// 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");
|
||||
}
|
||||
|
||||
if (send_data.size() < send_data_size) {
|
||||
send_data.append(reinterpret_cast<const char*>(data), size);
|
||||
send_data.resize(send_data_size, '\0');
|
||||
send_data.reserve(send_data_size);
|
||||
for (const auto& b : blocks) {
|
||||
send_data.append(reinterpret_cast<const char*>(b.first), b.second);
|
||||
}
|
||||
send_data.resize(send_data_size, '\0');
|
||||
|
||||
if (print_contents && (this->terminal_send_color != TerminalFormat::END)) {
|
||||
string name_token;
|
||||
if (!this->name.empty()) {
|
||||
name_token = " to " + this->name;
|
||||
}
|
||||
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);
|
||||
}
|
||||
log(INFO, "Sending%s (version=%s command=%04hX flag=%08X)",
|
||||
name_token.c_str(), name_for_version(version), cmd, flag);
|
||||
print_data(stderr, send_data.data(), logical_size, 0, nullptr, PrintDataFlags::PRINT_ASCII | PrintDataFlags::DISABLE_COLOR);
|
||||
if (version == GameVersion::BB) {
|
||||
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_version(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);
|
||||
}
|
||||
@@ -341,11 +356,15 @@ void Channel::send(uint16_t cmd, uint32_t flag, const void* data, size_t size,
|
||||
evbuffer_add(buf, send_data.data(), send_data.size());
|
||||
}
|
||||
|
||||
void Channel::send(uint16_t cmd, uint32_t flag, const string& data, bool print_contents) {
|
||||
this->send(cmd, flag, data.data(), data.size(), print_contents);
|
||||
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(const void* data, size_t size, bool print_contents) {
|
||||
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 == GameVersion::BB) ? 8 : 4;
|
||||
const auto* header = reinterpret_cast<const PSOCommandHeader*>(data);
|
||||
this->send(
|
||||
@@ -353,15 +372,13 @@ void Channel::send(const void* data, size_t size, bool print_contents) {
|
||||
header->flag(this->version),
|
||||
reinterpret_cast<const uint8_t*>(data) + header_size,
|
||||
size - header_size,
|
||||
print_contents);
|
||||
silent);
|
||||
}
|
||||
|
||||
void Channel::send(const string& data, bool print_contents) {
|
||||
return this->send(data.data(), data.size(), print_contents);
|
||||
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
|
||||
@@ -373,7 +390,7 @@ void Channel::dispatch_on_input(struct bufferevent*, void* ctx) {
|
||||
} catch (const out_of_range&) {
|
||||
break;
|
||||
} catch (const exception& e) {
|
||||
log(WARNING, "Error receiving on channel: %s", e.what());
|
||||
channel_exceptions_log.warning("Error receiving on channel: %s", e.what());
|
||||
ch->on_error(*ch, BEV_EVENT_ERROR);
|
||||
break;
|
||||
}
|
||||
|
||||
+15
-8
@@ -9,8 +9,6 @@
|
||||
#include "PSOProtocol.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
|
||||
|
||||
struct Channel {
|
||||
std::unique_ptr<struct bufferevent, void (*)(struct bufferevent*)> bev;
|
||||
struct sockaddr_storage local_addr;
|
||||
@@ -38,14 +36,16 @@ struct Channel {
|
||||
on_error_t on_error;
|
||||
void* context_obj;
|
||||
|
||||
// Creates an unconnected channel
|
||||
Channel(
|
||||
GameVersion version,
|
||||
on_command_received_t on_command_received,
|
||||
on_error_t on_error,
|
||||
void* context_obj,
|
||||
const std::string& name = "",
|
||||
const std::string& name,
|
||||
TerminalFormat terminal_send_color = TerminalFormat::END,
|
||||
TerminalFormat terminal_recv_color = TerminalFormat::END);
|
||||
// Creates a connected channel
|
||||
Channel(
|
||||
struct bufferevent* bev,
|
||||
GameVersion version,
|
||||
@@ -75,16 +75,23 @@ struct Channel {
|
||||
void disconnect();
|
||||
|
||||
// Receives a message. Throws std::out_of_range if no messages are available.
|
||||
Message recv(bool print_contents = true);
|
||||
Message recv();
|
||||
|
||||
// Sends a message with an automatically-constructed header.
|
||||
void send(uint16_t cmd, uint32_t flag = 0, const void* data = nullptr, size_t size = 0, bool print_contents = true);
|
||||
void send(uint16_t cmd, uint32_t flag, const std::string& data, bool print_contents = true);
|
||||
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 = nullptr, size_t size = 0, bool print_contents = true);
|
||||
void send(const std::string& data, bool print_contents = true);
|
||||
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);
|
||||
|
||||
+1144
-388
File diff suppressed because it is too large
Load Diff
+4
-6
@@ -5,12 +5,10 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "ServerState.hh"
|
||||
#include "Lobby.hh"
|
||||
#include "Client.hh"
|
||||
#include "Lobby.hh"
|
||||
#include "ProxyServer.hh"
|
||||
#include "ServerState.hh"
|
||||
|
||||
void process_chat_command(std::shared_ptr<ServerState> s, std::shared_ptr<Lobby> l,
|
||||
std::shared_ptr<Client> c, const std::u16string& text);
|
||||
void process_chat_command(std::shared_ptr<ServerState> s,
|
||||
ProxyServer::LinkedSession& session, const std::u16string& text);
|
||||
void on_chat_command(std::shared_ptr<Client> c, const std::u16string& text);
|
||||
void on_chat_command(std::shared_ptr<ProxyServer::LinkedSession> ses, const std::u16string& text);
|
||||
|
||||
+197
-33
@@ -1,68 +1,183 @@
|
||||
#include "Client.hh"
|
||||
|
||||
#include <errno.h>
|
||||
#include <event2/buffer.h>
|
||||
#include <event2/bufferevent.h>
|
||||
#include <errno.h>
|
||||
#include <event2/event.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <phosg/Network.hh>
|
||||
#include <phosg/Time.hh>
|
||||
|
||||
#include "Loggers.hh"
|
||||
#include "Server.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
const uint64_t CLIENT_CONFIG_MAGIC = 0x492A890E82AC9839;
|
||||
|
||||
static atomic<uint64_t> next_id(1);
|
||||
|
||||
ClientOptions::ClientOptions()
|
||||
: switch_assist(false),
|
||||
infinite_hp(false),
|
||||
infinite_tp(false),
|
||||
debug(false),
|
||||
override_section_id(-1),
|
||||
override_lobby_event(-1),
|
||||
override_lobby_number(-1),
|
||||
override_random_seed(-1),
|
||||
save_files(false),
|
||||
enable_chat_commands(true),
|
||||
enable_chat_filter(true),
|
||||
enable_player_notifications(false),
|
||||
suppress_client_pings(false),
|
||||
suppress_remote_login(false),
|
||||
zero_remote_guild_card(false),
|
||||
ep3_infinite_meseta(false),
|
||||
ep3_infinite_time(false),
|
||||
red_name(false),
|
||||
blank_name(false),
|
||||
function_call_return_value(-1) {}
|
||||
|
||||
Client::Client(
|
||||
shared_ptr<Server> server,
|
||||
struct bufferevent* bev,
|
||||
GameVersion version,
|
||||
ServerBehavior server_behavior)
|
||||
: version(version),
|
||||
bb_game_state(0),
|
||||
flags(flags_for_version(this->version, 0)),
|
||||
channel(bev, this->version, nullptr, nullptr, this, "", TerminalFormat::FG_YELLOW, TerminalFormat::FG_GREEN),
|
||||
server_behavior(server_behavior),
|
||||
should_disconnect(false),
|
||||
should_send_to_lobby_server(false),
|
||||
proxy_destination_address(0),
|
||||
proxy_destination_port(0),
|
||||
x(0.0f),
|
||||
z(0.0f),
|
||||
area(0),
|
||||
lobby_id(0),
|
||||
lobby_client_id(0),
|
||||
lobby_arrow_color(0),
|
||||
prefer_high_lobby_client_id(false),
|
||||
next_exp_value(0),
|
||||
override_section_id(-1),
|
||||
infinite_hp(false),
|
||||
infinite_tp(false),
|
||||
switch_assist(false),
|
||||
can_chat(true),
|
||||
pending_bb_save_player_index(0),
|
||||
dol_base_addr(0) {
|
||||
this->last_switch_enabled_command.subcommand = 0;
|
||||
: server(server),
|
||||
id(next_id++),
|
||||
log(string_printf("[C-%" PRIX64 "] ", this->id), client_log.min_level),
|
||||
bb_game_state(0),
|
||||
flags(flags_for_version(version, -1)),
|
||||
specific_version(default_specific_version_for_version(version, -1)),
|
||||
channel(bev, version, nullptr, nullptr, this, string_printf("C-%" PRIX64, this->id), TerminalFormat::FG_YELLOW, TerminalFormat::FG_GREEN),
|
||||
server_behavior(server_behavior),
|
||||
should_disconnect(false),
|
||||
should_send_to_lobby_server(false),
|
||||
should_send_to_proxy_server(false),
|
||||
proxy_destination_address(0),
|
||||
proxy_destination_port(0),
|
||||
x(0.0f),
|
||||
z(0.0f),
|
||||
area(0),
|
||||
lobby_client_id(0),
|
||||
lobby_arrow_color(0),
|
||||
preferred_lobby_id(-1),
|
||||
save_game_data_event(
|
||||
event_new(
|
||||
bufferevent_get_base(bev), -1, EV_TIMEOUT | EV_PERSIST,
|
||||
&Client::dispatch_save_game_data, this),
|
||||
event_free),
|
||||
send_ping_event(
|
||||
event_new(
|
||||
bufferevent_get_base(bev), -1, EV_TIMEOUT,
|
||||
&Client::dispatch_send_ping, this),
|
||||
event_free),
|
||||
idle_timeout_event(
|
||||
event_new(
|
||||
bufferevent_get_base(bev), -1, EV_TIMEOUT,
|
||||
&Client::dispatch_idle_timeout, this),
|
||||
event_free),
|
||||
card_battle_table_number(-1),
|
||||
card_battle_table_seat_number(0),
|
||||
card_battle_table_seat_state(0),
|
||||
next_exp_value(0),
|
||||
can_chat(true),
|
||||
use_server_rare_tables(false),
|
||||
pending_bb_save_player_index(0),
|
||||
dol_base_addr(0) {
|
||||
this->last_switch_enabled_command.header.subcommand = 0;
|
||||
memset(&this->next_connection_addr, 0, sizeof(this->next_connection_addr));
|
||||
|
||||
if (this->version() == GameVersion::BB) {
|
||||
struct timeval tv = usecs_to_timeval(60000000); // 1 minute
|
||||
event_add(this->save_game_data_event.get(), &tv);
|
||||
}
|
||||
this->reschedule_ping_and_timeout_events();
|
||||
|
||||
this->log.info("Created");
|
||||
}
|
||||
|
||||
void Client::set_license(shared_ptr<const License> l) {
|
||||
this->license = l;
|
||||
this->game_data.serial_number = this->license->serial_number;
|
||||
if (this->version == GameVersion::BB) {
|
||||
this->game_data.bb_username = this->license->username;
|
||||
Client::~Client() {
|
||||
if (!this->disconnect_hooks.empty()) {
|
||||
this->log.warning("Disconnect hooks pending at client destruction time:");
|
||||
for (const auto& it : this->disconnect_hooks) {
|
||||
this->log.warning(" %s", it.first.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
this->log.info("Deleted");
|
||||
}
|
||||
|
||||
void Client::reschedule_ping_and_timeout_events() {
|
||||
struct timeval ping_tv = usecs_to_timeval(30000000); // 30 seconds
|
||||
event_add(this->send_ping_event.get(), &ping_tv);
|
||||
struct timeval idle_tv = usecs_to_timeval(60000000); // 1 minute
|
||||
event_add(this->idle_timeout_event.get(), &idle_tv);
|
||||
}
|
||||
|
||||
QuestScriptVersion Client::quest_version() const {
|
||||
switch (this->version()) {
|
||||
case GameVersion::DC:
|
||||
if (this->flags & Flag::IS_DC_TRIAL_EDITION) {
|
||||
return QuestScriptVersion::DC_NTE;
|
||||
} else if (this->flags & Flag::IS_DC_V1) {
|
||||
return QuestScriptVersion::DC_V1;
|
||||
} else {
|
||||
return QuestScriptVersion::DC_V2;
|
||||
}
|
||||
case GameVersion::PC:
|
||||
return QuestScriptVersion::PC_V2;
|
||||
case GameVersion::GC:
|
||||
if (this->flags & Flag::IS_GC_TRIAL_EDITION) {
|
||||
return QuestScriptVersion::GC_NTE;
|
||||
} else if (this->flags & Flag::IS_EPISODE_3) {
|
||||
return QuestScriptVersion::GC_EP3;
|
||||
} else {
|
||||
return QuestScriptVersion::GC_V3;
|
||||
}
|
||||
case GameVersion::XB:
|
||||
return QuestScriptVersion::XB_V3;
|
||||
case GameVersion::BB:
|
||||
return QuestScriptVersion::BB_V4;
|
||||
default:
|
||||
throw logic_error("client\'s game version does not have a quest version");
|
||||
}
|
||||
}
|
||||
|
||||
void Client::set_license(shared_ptr<License> l) {
|
||||
this->license = l;
|
||||
this->game_data.guild_card_number = this->license->serial_number;
|
||||
if (this->version() == GameVersion::BB) {
|
||||
this->game_data.bb_username = this->license->bb_username;
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr<ServerState> Client::require_server_state() const {
|
||||
auto server = this->server.lock();
|
||||
if (!server) {
|
||||
throw logic_error("server is deleted");
|
||||
}
|
||||
return server->get_state();
|
||||
}
|
||||
|
||||
shared_ptr<Lobby> Client::require_lobby() const {
|
||||
auto l = this->lobby.lock();
|
||||
if (!l) {
|
||||
throw runtime_error("client not in any lobby");
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
ClientConfig Client::export_config() const {
|
||||
ClientConfig cc;
|
||||
cc.magic = CLIENT_CONFIG_MAGIC;
|
||||
cc.flags = this->flags;
|
||||
cc.specific_version = this->specific_version;
|
||||
cc.proxy_destination_address = this->proxy_destination_address;
|
||||
cc.proxy_destination_port = this->proxy_destination_port;
|
||||
cc.unused.clear(0xFF);
|
||||
@@ -83,6 +198,7 @@ void Client::import_config(const ClientConfig& cc) {
|
||||
throw invalid_argument("invalid client config");
|
||||
}
|
||||
this->flags = cc.flags;
|
||||
this->specific_version = cc.specific_version;
|
||||
this->proxy_destination_address = cc.proxy_destination_address;
|
||||
this->proxy_destination_port = cc.proxy_destination_port;
|
||||
}
|
||||
@@ -92,3 +208,51 @@ void Client::import_config(const ClientConfigBB& cc) {
|
||||
this->bb_game_state = cc.bb_game_state;
|
||||
this->game_data.bb_player_index = cc.bb_player_index;
|
||||
}
|
||||
|
||||
void Client::dispatch_save_game_data(evutil_socket_t, short, void* ctx) {
|
||||
reinterpret_cast<Client*>(ctx)->save_game_data();
|
||||
}
|
||||
|
||||
void Client::save_game_data() {
|
||||
if (this->version() != GameVersion::BB) {
|
||||
throw logic_error("save_game_data called for non-BB client");
|
||||
}
|
||||
if (this->game_data.account(false)) {
|
||||
this->game_data.save_account_data();
|
||||
}
|
||||
if (this->game_data.player(false)) {
|
||||
this->game_data.save_player_data();
|
||||
}
|
||||
}
|
||||
|
||||
void Client::dispatch_send_ping(evutil_socket_t, short, void* ctx) {
|
||||
reinterpret_cast<Client*>(ctx)->send_ping();
|
||||
}
|
||||
|
||||
void Client::send_ping() {
|
||||
if (this->version() != GameVersion::PATCH) {
|
||||
this->log.info("Sending ping command");
|
||||
// The game doesn't use this timestamp; we only use it for debugging purposes
|
||||
be_uint64_t timestamp = now();
|
||||
try {
|
||||
this->channel.send(0x1D, 0x00, ×tamp, sizeof(be_uint64_t));
|
||||
} catch (const exception& e) {
|
||||
this->log.info("Failed to send ping: %s", e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Client::dispatch_idle_timeout(evutil_socket_t, short, void* ctx) {
|
||||
reinterpret_cast<Client*>(ctx)->idle_timeout();
|
||||
}
|
||||
|
||||
void 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->log.info("Server is deleted; cannot disconnect client");
|
||||
}
|
||||
}
|
||||
|
||||
+148
-41
@@ -6,66 +6,133 @@
|
||||
|
||||
#include "Channel.hh"
|
||||
#include "CommandFormats.hh"
|
||||
#include "Episode3/BattleRecord.hh"
|
||||
#include "Episode3/Tournament.hh"
|
||||
#include "FileContentsCache.hh"
|
||||
#include "FunctionCompiler.hh"
|
||||
#include "License.hh"
|
||||
#include "Player.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "PSOProtocol.hh"
|
||||
#include "PatchFileIndex.hh"
|
||||
#include "Player.hh"
|
||||
#include "QuestScript.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
|
||||
|
||||
extern const uint64_t CLIENT_CONFIG_MAGIC;
|
||||
|
||||
class Server;
|
||||
struct Lobby;
|
||||
|
||||
struct ClientOptions {
|
||||
// Options used on both game and proxy server
|
||||
bool switch_assist;
|
||||
bool infinite_hp;
|
||||
bool infinite_tp;
|
||||
bool debug;
|
||||
int16_t override_section_id; // -1 = no override
|
||||
int16_t override_lobby_event; // -1 = no override
|
||||
int16_t override_lobby_number; // -1 = no override
|
||||
int64_t override_random_seed;
|
||||
|
||||
struct Client {
|
||||
// Options used only on proxy server
|
||||
bool save_files;
|
||||
bool enable_chat_commands;
|
||||
bool enable_chat_filter;
|
||||
bool enable_player_notifications;
|
||||
bool suppress_client_pings;
|
||||
bool suppress_remote_login;
|
||||
bool zero_remote_guild_card;
|
||||
bool ep3_infinite_meseta;
|
||||
bool ep3_infinite_time;
|
||||
bool red_name;
|
||||
bool blank_name;
|
||||
int64_t function_call_return_value; // -1 = don't block function calls
|
||||
|
||||
ClientOptions();
|
||||
};
|
||||
|
||||
struct Client : public std::enable_shared_from_this<Client> {
|
||||
enum Flag {
|
||||
// Client is DC Network Trial Edition, which is missing a lot of features
|
||||
// and uses some different command numbers than any other version
|
||||
IS_DC_TRIAL_EDITION = 0x00002000,
|
||||
// A 90 01 command has been sent (which proto will send a 93 in response to,
|
||||
// and actual DCv1 will send a 92)
|
||||
CHECKED_FOR_DC_V1_PROTOTYPE = 0x00080000,
|
||||
// Client is DC v1 prototype
|
||||
IS_DC_V1_PROTOTYPE = 0x00040000,
|
||||
// Client is DC v1
|
||||
IS_DC_V1 = 0x00000010,
|
||||
// Client is GC Episodes 1&2 Trial Edition, which is much more like PC than
|
||||
// actual GC Episodes 1&2 - it uses PC encryption and is missing most of the
|
||||
// features added in Episodes 1&2
|
||||
IS_GC_TRIAL_EDITION = 0x00200000,
|
||||
// Client is GC Episode 3 Trial Edition, which is fairly close to the final
|
||||
// Episode 3 build, but is missing a few commands that we'll have to avoid
|
||||
// sending
|
||||
IS_EP3_TRIAL_EDITION = 0x00400000,
|
||||
// For patch server clients, client is Blue Burst rather than PC
|
||||
BB_PATCH = 0x0001,
|
||||
IS_BB_PATCH = 0x00000001,
|
||||
// After joining a lobby, client will no longer send D6 commands when they
|
||||
// close message boxes
|
||||
NO_MESSAGE_BOX_CLOSE_CONFIRMATION_AFTER_LOBBY_JOIN = 0x0002,
|
||||
NO_D6_AFTER_LOBBY = 0x00000002,
|
||||
// Client has the above flag and has already joined a lobby, or is not GC
|
||||
NO_MESSAGE_BOX_CLOSE_CONFIRMATION = 0x0004,
|
||||
NO_D6 = 0x00000004,
|
||||
// Client is Episode 3, should be able to see CARD lobbies, and should only
|
||||
// be able to see/join games with the IS_EPISODE_3 flag
|
||||
EPISODE_3 = 0x0008,
|
||||
// Client is DC v1 (disables some features)
|
||||
DCV1 = 0x0010,
|
||||
// be able to see/join games with the EPISODE_3_ONLY flag
|
||||
IS_EPISODE_3 = 0x00000008,
|
||||
// Client disconnects if it receives B2 (send_function_call)
|
||||
NO_SEND_FUNCTION_CALL = 0x00000200,
|
||||
// Client requires doubly-encrypted code section in send_function_call
|
||||
ENCRYPTED_SEND_FUNCTION_CALL = 0x00000800,
|
||||
// Client supports send_function_call but does not actually run the code
|
||||
SEND_FUNCTION_CALL_CHECKSUM_ONLY = 0x00001000,
|
||||
// Client supports send_function_call and clears its caches properly before
|
||||
// calling the function (so we don't need to patch it)
|
||||
SEND_FUNCTION_CALL_NO_CACHE_PATCH = 0x00020000,
|
||||
// Client is vulnerable to a buffer overflow that we can use to enable
|
||||
// send_function_call
|
||||
USE_OVERFLOW_FOR_SEND_FUNCTION_CALL = 0x00008000,
|
||||
|
||||
// Client is loading into a game
|
||||
LOADING = 0x0020,
|
||||
LOADING = 0x00000020,
|
||||
// Client is loading a quest
|
||||
LOADING_QUEST = 0x0040,
|
||||
LOADING_QUEST = 0x00000040,
|
||||
// Client is loading a joinable quest that has already started
|
||||
LOADING_RUNNING_QUEST = 0x00100000,
|
||||
// Client is waiting for other players to join a tournament game
|
||||
LOADING_TOURNAMENT = 0x00010000,
|
||||
// Client is in the information menu (login server only)
|
||||
IN_INFORMATION_MENU = 0x0080,
|
||||
IN_INFORMATION_MENU = 0x00000080,
|
||||
// Client is at the welcome message (login server only)
|
||||
AT_WELCOME_MESSAGE = 0x0100,
|
||||
// Client disconnect if it receives B2 (send_function_call)
|
||||
DOES_NOT_SUPPORT_SEND_FUNCTION_CALL = 0x0200,
|
||||
AT_WELCOME_MESSAGE = 0x00000100,
|
||||
// Client has already received a 97 (enable saves) command, so don't show
|
||||
// the programs menu anymore
|
||||
SAVE_ENABLED = 0x0400,
|
||||
SAVE_ENABLED = 0x00000400,
|
||||
// Client has received newserv's Episode 3 card definitions, so don't send
|
||||
// them again
|
||||
HAS_EP3_CARD_DEFS = 0x00004000,
|
||||
// Client has received newserv's Episode 3 media updates, so don't send them
|
||||
// again
|
||||
HAS_EP3_MEDIA_UPDATES = 0x00800000,
|
||||
|
||||
// TODO: Do DCv1 and PC support send_function_call? Here we assume they don't
|
||||
DEFAULT_V1 = DCV1 | NO_MESSAGE_BOX_CLOSE_CONFIRMATION | DOES_NOT_SUPPORT_SEND_FUNCTION_CALL,
|
||||
DEFAULT_V2_DC = NO_MESSAGE_BOX_CLOSE_CONFIRMATION,
|
||||
DEFAULT_V2_PC = NO_MESSAGE_BOX_CLOSE_CONFIRMATION | DOES_NOT_SUPPORT_SEND_FUNCTION_CALL,
|
||||
DEFAULT_V3_GC = 0x0000,
|
||||
DEFAULT_V3_GC_PLUS = NO_MESSAGE_BOX_CLOSE_CONFIRMATION_AFTER_LOBBY_JOIN | DOES_NOT_SUPPORT_SEND_FUNCTION_CALL,
|
||||
DEFAULT_V3_GC_EP3 = NO_MESSAGE_BOX_CLOSE_CONFIRMATION_AFTER_LOBBY_JOIN | EPISODE_3 | DOES_NOT_SUPPORT_SEND_FUNCTION_CALL,
|
||||
DEFAULT_V4_BB = NO_MESSAGE_BOX_CLOSE_CONFIRMATION_AFTER_LOBBY_JOIN | NO_MESSAGE_BOX_CLOSE_CONFIRMATION | SAVE_ENABLED,
|
||||
UNUSED_FLAG_BITS = 0xFF010000,
|
||||
};
|
||||
|
||||
std::weak_ptr<Server> server;
|
||||
std::weak_ptr<ServerState> server_state;
|
||||
uint64_t id;
|
||||
PrefixedLogger log;
|
||||
|
||||
// License & account
|
||||
std::shared_ptr<const License> license;
|
||||
GameVersion version;
|
||||
std::shared_ptr<License> license;
|
||||
|
||||
// Note: these fields are included in the client config. On GC, the client
|
||||
// config can be up to 0x20 bytes; on BB it can be 0x28 bytes. We don't use
|
||||
// all of that space.
|
||||
uint8_t bb_game_state;
|
||||
uint16_t flags;
|
||||
uint32_t flags;
|
||||
uint32_t specific_version;
|
||||
|
||||
// Network
|
||||
Channel channel;
|
||||
@@ -73,40 +140,80 @@ struct Client {
|
||||
ServerBehavior server_behavior;
|
||||
bool should_disconnect;
|
||||
bool should_send_to_lobby_server;
|
||||
bool should_send_to_proxy_server;
|
||||
uint32_t proxy_destination_address;
|
||||
uint16_t proxy_destination_port;
|
||||
std::unordered_map<std::string, std::function<void()>> disconnect_hooks;
|
||||
|
||||
// Patch server
|
||||
std::vector<PatchFileChecksumRequest> patch_file_checksum_requests;
|
||||
|
||||
// Lobby/positioning
|
||||
ClientOptions options;
|
||||
float x;
|
||||
float z;
|
||||
uint32_t area; // which area is the client in?
|
||||
uint32_t lobby_id; // which lobby is this person in?
|
||||
uint8_t lobby_client_id; // which client number is this person?
|
||||
uint8_t lobby_arrow_color; // lobby arrow color ID
|
||||
bool prefer_high_lobby_client_id;
|
||||
uint32_t area;
|
||||
std::weak_ptr<Lobby> lobby;
|
||||
uint8_t lobby_client_id;
|
||||
uint8_t lobby_arrow_color;
|
||||
int64_t preferred_lobby_id; // <0 = no preference
|
||||
ClientGameData game_data;
|
||||
std::unique_ptr<struct event, void (*)(struct event*)> save_game_data_event;
|
||||
std::unique_ptr<struct event, void (*)(struct event*)> 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<Episode3::BattleRecord> ep3_prev_battle_record;
|
||||
std::shared_ptr<const Menu> last_menu_sent;
|
||||
|
||||
// Miscellaneous (used by chat commands)
|
||||
uint32_t next_exp_value; // next EXP value to give
|
||||
int16_t override_section_id; // valid if >= 0
|
||||
bool infinite_hp; // cheats enabled
|
||||
bool infinite_tp; // cheats enabled
|
||||
bool switch_assist; // cheats enabled
|
||||
G_SwitchStateChanged_6x05 last_switch_enabled_command;
|
||||
bool can_chat;
|
||||
bool use_server_rare_tables;
|
||||
std::string pending_bb_save_username;
|
||||
uint8_t pending_bb_save_player_index;
|
||||
std::deque<std::function<void(uint32_t, uint32_t)>> function_call_response_queue;
|
||||
|
||||
// DOL file loading state
|
||||
// File loading state
|
||||
uint32_t dol_base_addr;
|
||||
std::shared_ptr<DOLFileIndex::DOLFile> loading_dol_file;
|
||||
std::unordered_map<std::string, std::shared_ptr<const std::string>> sending_files;
|
||||
|
||||
Client(struct bufferevent* bev, GameVersion version, ServerBehavior server_behavior);
|
||||
Client(
|
||||
std::shared_ptr<Server> server,
|
||||
struct bufferevent* bev,
|
||||
GameVersion version,
|
||||
ServerBehavior server_behavior);
|
||||
~Client();
|
||||
|
||||
void set_license(std::shared_ptr<const License> l);
|
||||
void reschedule_ping_and_timeout_events();
|
||||
|
||||
inline uint8_t language() const {
|
||||
auto p = this->game_data.player(true, false);
|
||||
return p ? p->inventory.language : 1; // English by default
|
||||
}
|
||||
inline GameVersion version() const {
|
||||
return this->channel.version;
|
||||
}
|
||||
QuestScriptVersion quest_version() const;
|
||||
|
||||
void set_license(std::shared_ptr<License> l);
|
||||
|
||||
std::shared_ptr<ServerState> require_server_state() const;
|
||||
std::shared_ptr<Lobby> require_lobby() const;
|
||||
|
||||
ClientConfig export_config() const;
|
||||
ClientConfigBB export_config_bb() const;
|
||||
void import_config(const ClientConfig& cc);
|
||||
void import_config(const ClientConfigBB& cc);
|
||||
|
||||
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();
|
||||
};
|
||||
|
||||
+5198
-1586
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,212 @@
|
||||
#include "CommonItemSet.hh"
|
||||
|
||||
#include "StaticGameData.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
CommonItemSet::CommonItemSet(shared_ptr<const string> data)
|
||||
: gsl(data, true) {}
|
||||
|
||||
const CommonItemSet::Table<true>& CommonItemSet::get_table(
|
||||
Episode episode, GameMode mode, uint8_t difficulty, uint8_t secid) const {
|
||||
// TODO: What should we do for Ep4?
|
||||
string filename = string_printf(
|
||||
"ItemPT%s%s%c%1d.rel",
|
||||
((mode == GameMode::CHALLENGE) ? "c" : ""),
|
||||
((episode == Episode::EP2) ? "l" : ""),
|
||||
tolower(abbreviation_for_difficulty(difficulty)),
|
||||
(mode == GameMode::CHALLENGE) ? 0 : secid);
|
||||
auto data = this->gsl.get(filename);
|
||||
if (data.second < sizeof(Table<true>)) {
|
||||
throw runtime_error(string_printf(
|
||||
"ItemPT entry %s is too small (received %zX bytes, expected %zX bytes)",
|
||||
filename.c_str(), data.second, sizeof(Table<true>)));
|
||||
}
|
||||
return *reinterpret_cast<const Table<true>*>(data.first);
|
||||
}
|
||||
|
||||
RELFileSet::RELFileSet(std::shared_ptr<const std::string> data)
|
||||
: data(data),
|
||||
r(*this->data) {}
|
||||
|
||||
ArmorRandomSet::ArmorRandomSet(std::shared_ptr<const std::string> data)
|
||||
: RELFileSet(data) {
|
||||
// For some reason the footer tables are doubly indirect in this file
|
||||
uint32_t specs_offset_offset = this->r.pget_u32b(data->size() - 0x10);
|
||||
uint32_t specs_offset = this->r.pget_u32b(specs_offset_offset);
|
||||
this->tables = &this->r.pget<parray<TableSpec, 3>>(specs_offset);
|
||||
}
|
||||
|
||||
std::pair<const ArmorRandomSet::WeightTableEntry8*, size_t>
|
||||
ArmorRandomSet::get_armor_table(size_t index) const {
|
||||
return this->get_table<WeightTableEntry8>(this->tables->at(0), index);
|
||||
}
|
||||
|
||||
std::pair<const ArmorRandomSet::WeightTableEntry8*, size_t>
|
||||
ArmorRandomSet::get_shield_table(size_t index) const {
|
||||
return this->get_table<WeightTableEntry8>(this->tables->at(1), index);
|
||||
}
|
||||
|
||||
std::pair<const ArmorRandomSet::WeightTableEntry8*, size_t>
|
||||
ArmorRandomSet::get_unit_table(size_t index) const {
|
||||
return this->get_table<WeightTableEntry8>(this->tables->at(2), index);
|
||||
}
|
||||
|
||||
ToolRandomSet::ToolRandomSet(std::shared_ptr<const std::string> data)
|
||||
: RELFileSet(data) {
|
||||
uint32_t specs_offset = r.pget_u32b(data->size() - 0x10);
|
||||
this->common_recovery_table_spec = &r.pget<TableSpec>(r.pget_u32b(
|
||||
specs_offset));
|
||||
this->rare_recovery_table_spec = &r.pget<TableSpec>(
|
||||
r.pget_u32b(specs_offset + sizeof(uint32_t)),
|
||||
2 * sizeof(TableSpec));
|
||||
this->tech_disk_table_spec = this->rare_recovery_table_spec + 1;
|
||||
this->tech_disk_level_table_spec = &r.pget<TableSpec>(r.pget_u32b(
|
||||
specs_offset + 2 * sizeof(uint32_t)));
|
||||
}
|
||||
|
||||
pair<const uint8_t*, size_t> ToolRandomSet::get_common_recovery_table(
|
||||
size_t index) const {
|
||||
return this->get_table<uint8_t>(*this->common_recovery_table_spec, index);
|
||||
}
|
||||
|
||||
pair<const ToolRandomSet::WeightTableEntry8*, size_t>
|
||||
ToolRandomSet::get_rare_recovery_table(size_t index) const {
|
||||
return this->get_table<WeightTableEntry8>(*this->rare_recovery_table_spec, index);
|
||||
}
|
||||
|
||||
pair<const ToolRandomSet::WeightTableEntry8*, size_t>
|
||||
ToolRandomSet::get_tech_disk_table(size_t index) const {
|
||||
return this->get_table<WeightTableEntry8>(*this->tech_disk_table_spec, index);
|
||||
}
|
||||
|
||||
pair<const ToolRandomSet::TechDiskLevelEntry*, size_t>
|
||||
ToolRandomSet::get_tech_disk_level_table(size_t index) const {
|
||||
return this->get_table<TechDiskLevelEntry>(*this->tech_disk_level_table_spec, index);
|
||||
}
|
||||
|
||||
WeaponRandomSet::WeaponRandomSet(std::shared_ptr<const std::string> data)
|
||||
: RELFileSet(data) {
|
||||
uint32_t offsets_offset = this->r.pget_u32b(data->size() - 0x10);
|
||||
this->offsets = &this->r.pget<Offsets>(offsets_offset);
|
||||
}
|
||||
|
||||
std::pair<const WeaponRandomSet::WeightTableEntry8*, size_t>
|
||||
WeaponRandomSet::get_weapon_type_table(size_t index) const {
|
||||
const auto& spec = this->r.pget<TableSpec>(
|
||||
this->offsets->weapon_type_table + index * sizeof(TableSpec));
|
||||
const auto* data = &this->r.pget<WeightTableEntry8>(
|
||||
spec.offset, spec.entries_per_table * sizeof(WeightTableEntry8));
|
||||
return make_pair(data, spec.entries_per_table);
|
||||
}
|
||||
|
||||
const parray<WeaponRandomSet::WeightTableEntry32, 6>*
|
||||
WeaponRandomSet::get_bonus_type_table(size_t which, size_t index) const {
|
||||
uint32_t base_offset = which ? this->offsets->bonus_type_table2 : this->offsets->bonus_type_table1;
|
||||
return &this->r.pget<parray<WeightTableEntry32, 6>>(
|
||||
base_offset + sizeof(parray<WeightTableEntry32, 6>) * index);
|
||||
}
|
||||
|
||||
const WeaponRandomSet::RangeTableEntry*
|
||||
WeaponRandomSet::get_bonus_range(size_t which, size_t index) const {
|
||||
uint32_t base_offset = which ? this->offsets->bonus_range_table2 : this->offsets->bonus_range_table1;
|
||||
return &this->r.pget<RangeTableEntry>(
|
||||
base_offset + sizeof(RangeTableEntry) * index);
|
||||
}
|
||||
|
||||
const parray<WeaponRandomSet::WeightTableEntry32, 3>*
|
||||
WeaponRandomSet::get_special_mode_table(size_t index) const {
|
||||
return &this->r.pget<parray<WeightTableEntry32, 3>>(
|
||||
this->offsets->special_mode_table + sizeof(parray<WeightTableEntry32, 3>) * index);
|
||||
}
|
||||
|
||||
const WeaponRandomSet::RangeTableEntry*
|
||||
WeaponRandomSet::get_standard_grind_range(size_t index) const {
|
||||
return &this->r.pget<RangeTableEntry>(
|
||||
this->offsets->standard_grind_range_table + sizeof(RangeTableEntry) * index);
|
||||
}
|
||||
|
||||
const WeaponRandomSet::RangeTableEntry*
|
||||
WeaponRandomSet::get_favored_grind_range(size_t index) const {
|
||||
return &this->r.pget<RangeTableEntry>(
|
||||
this->offsets->favored_grind_range_table + sizeof(RangeTableEntry) * index);
|
||||
}
|
||||
|
||||
TekkerAdjustmentSet::TekkerAdjustmentSet(std::shared_ptr<const std::string> data)
|
||||
: data(data),
|
||||
r(*data) {
|
||||
this->offsets = &this->r.pget<Offsets>(this->r.pget_u32b(this->r.size() - 0x10));
|
||||
}
|
||||
|
||||
const ProbabilityTable<uint8_t, 100>& TekkerAdjustmentSet::get_table(
|
||||
std::array<ProbabilityTable<uint8_t, 100>, 10>& tables_default,
|
||||
std::array<ProbabilityTable<uint8_t, 100>, 10>& tables_favored,
|
||||
uint32_t offset_and_count_offset,
|
||||
bool favored,
|
||||
uint8_t section_id) const {
|
||||
if (section_id >= 10) {
|
||||
throw runtime_error("invalid section ID");
|
||||
}
|
||||
ProbabilityTable<uint8_t, 100>& table = favored ? tables_favored[section_id] : tables_default[section_id];
|
||||
if (table.count == 0) {
|
||||
uint32_t offset = r.pget_u32b(offset_and_count_offset);
|
||||
uint32_t count_per_section_id = r.pget_u32b(offset_and_count_offset + 4);
|
||||
auto* entries = &r.pget<DeltaProbabilityEntry>(offset, sizeof(DeltaProbabilityEntry) * count_per_section_id * 10);
|
||||
for (size_t z = count_per_section_id * section_id; z < count_per_section_id * (section_id + 1); z++) {
|
||||
size_t count = favored ? entries[z].count_favored : entries[z].count_default;
|
||||
for (size_t w = 0; w < count; w++) {
|
||||
table.push(entries[z].delta_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
const ProbabilityTable<uint8_t, 100>& TekkerAdjustmentSet::get_special_upgrade_prob_table(uint8_t section_id, bool favored) const {
|
||||
return this->get_table(
|
||||
this->special_upgrade_prob_tables_default,
|
||||
this->special_upgrade_prob_tables_favored,
|
||||
this->offsets->special_upgrade_prob_table_offset,
|
||||
favored, section_id);
|
||||
}
|
||||
|
||||
const ProbabilityTable<uint8_t, 100>& TekkerAdjustmentSet::get_grind_delta_prob_table(uint8_t section_id, bool favored) const {
|
||||
return this->get_table(
|
||||
this->grind_delta_prob_tables_default,
|
||||
this->grind_delta_prob_tables_favored,
|
||||
this->offsets->grind_delta_prob_table_offset,
|
||||
favored, section_id);
|
||||
}
|
||||
|
||||
const ProbabilityTable<uint8_t, 100>& TekkerAdjustmentSet::get_bonus_delta_prob_table(uint8_t section_id, bool favored) const {
|
||||
return this->get_table(
|
||||
this->bonus_delta_prob_tables_default,
|
||||
this->bonus_delta_prob_tables_favored,
|
||||
this->offsets->bonus_delta_prob_table_offset,
|
||||
favored, section_id);
|
||||
}
|
||||
|
||||
int8_t TekkerAdjustmentSet::get_luck(uint32_t start_offset, uint8_t delta_index) const {
|
||||
StringReader sub_r = r.sub(start_offset);
|
||||
while (!sub_r.eof()) {
|
||||
const auto& entry = sub_r.get<LuckTableEntry>();
|
||||
if (entry.delta_index == 0xFF) {
|
||||
return 0;
|
||||
} else if (entry.delta_index == delta_index) {
|
||||
return entry.luck;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int8_t TekkerAdjustmentSet::get_luck_for_special_upgrade(uint8_t delta_index) const {
|
||||
return this->get_luck(this->offsets->special_upgrade_luck_table_offset, delta_index);
|
||||
}
|
||||
|
||||
int8_t TekkerAdjustmentSet::get_luck_for_grind_delta(uint8_t delta_index) const {
|
||||
return this->get_luck(this->offsets->grind_delta_luck_table_offset, delta_index);
|
||||
}
|
||||
|
||||
int8_t TekkerAdjustmentSet::get_luck_for_bonus_delta(uint8_t delta_index) const {
|
||||
return this->get_luck(this->offsets->bonus_delta_luck_offset, delta_index);
|
||||
}
|
||||
@@ -0,0 +1,550 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <phosg/Encoding.hh>
|
||||
|
||||
#include "GSLArchive.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
// Note: There are clearly better ways of doing this, but this implementation
|
||||
// closely follows what the original code in the client does.
|
||||
template <typename ItemT, size_t MaxCount>
|
||||
struct ProbabilityTable {
|
||||
ItemT items[MaxCount];
|
||||
size_t count;
|
||||
|
||||
ProbabilityTable() : count(0) {}
|
||||
|
||||
void push(ItemT item) {
|
||||
if (this->count == MaxCount) {
|
||||
throw std::runtime_error("push to full probability table");
|
||||
}
|
||||
this->items[this->count++] = item;
|
||||
}
|
||||
|
||||
ItemT pop() {
|
||||
if (this->count == 0) {
|
||||
throw std::runtime_error("pop from empty probability table");
|
||||
}
|
||||
return this->items[--this->count];
|
||||
}
|
||||
|
||||
void shuffle(PSOLFGEncryption& random_crypt) {
|
||||
for (size_t z = 1; z < this->count; z++) {
|
||||
size_t other_z = random_crypt.next() % (z + 1);
|
||||
ItemT t = this->items[z];
|
||||
this->items[z] = this->items[other_z];
|
||||
this->items[other_z] = t;
|
||||
}
|
||||
}
|
||||
|
||||
ItemT sample(PSOLFGEncryption& random_crypt) const {
|
||||
if (this->count == 0) {
|
||||
throw std::runtime_error("pop from empty probability table");
|
||||
} else if (this->count == 1) {
|
||||
return this->items[0];
|
||||
} else {
|
||||
return this->items[random_crypt.next() % this->count];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class CommonItemSet {
|
||||
public:
|
||||
template <typename IntT>
|
||||
struct Range {
|
||||
IntT min;
|
||||
IntT max;
|
||||
} __attribute__((packed));
|
||||
|
||||
// The Table structure below describes the format of a single ItemPT entry
|
||||
// (which corresponds to a single difficulty, episode, section ID, and
|
||||
// challenge flag). ItemPT entries (within ItemPT.gsl) are named like this:
|
||||
// string_printf("ItemPT%s%s%c%1d.rel",
|
||||
// (is_challenge ? "c" : ""),
|
||||
// (is_ep2 ? "l" : ""),
|
||||
// char_for_difficulty(difficulty), // One of "nhvu"
|
||||
// section_id);
|
||||
template <bool IsBigEndian>
|
||||
struct Table {
|
||||
using U16T = typename std::conditional<IsBigEndian, be_uint16_t, le_uint16_t>::type;
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
// This data structure uses index probability tables in multiple places. An
|
||||
// index probability table is a table where each entry holds the probability
|
||||
// that that entry's index is used. For example, if the armor slot count
|
||||
// probability table contains [77, 17, 5, 1, 0], this means there is a 77%
|
||||
// chance of no slots, 17% chance of 1 slot, 5% chance of 2 slots, 1% chance
|
||||
// of 3 slots, and no chance of 4 slots. The values in index probability
|
||||
// tables do not have to add up to 100; the game sums all of them and
|
||||
// chooses a random number less than that maximum.
|
||||
|
||||
// The area (floor) number is used in many places as well. Unlike the normal
|
||||
// area numbers, which start with Pioneer 2, the area numbers in this
|
||||
// structure start with Forest 1, and boss areas are treated as the first
|
||||
// area of the next section (so De Rol Le has Mines 1 drops, for example).
|
||||
// Final boss areas are treated as the last non-boss area (so Dark Falz
|
||||
// boxes are like Ruins 3 boxes). We refer to these adjusted area numbers as
|
||||
// (area - 1).
|
||||
|
||||
// This index probability table determines the types of non-rare weapons.
|
||||
// The indexes in this table correspond to the non-rare weapon types 01
|
||||
// through 0C (Saber through Wand).
|
||||
/* 0000 */ parray<uint8_t, 0x0C> base_weapon_type_prob_table;
|
||||
|
||||
// This table specifies the base subtype for each weapon type. Negative
|
||||
// values here mean that the weapon cannot be found in the first N areas (so
|
||||
// -2, for example, means that the weapon never appears in Forest 1 or 2 at
|
||||
// all). Nonnegative values here mean the subtype can be found in all areas,
|
||||
// and specify the base subtype (usually in the range [0, 4]). The subtype
|
||||
// of weapon that actually appears depends on this value and a value from
|
||||
// the following table.
|
||||
/* 000C */ parray<int8_t, 0x0C> subtype_base_table;
|
||||
|
||||
// This table specifies how many areas each weapon subtype appears in. For
|
||||
// example, if Sword (subtype 02, which is index 1 in this table and the
|
||||
// table above) has a subtype base of -2 and a subtype area length of 4,
|
||||
// then Sword items can be found when area - 1 is 2, 3, 4, or 5 (Cave 1
|
||||
// through Mine 1), and Gigush (the next sword subtype) can be found in Mine
|
||||
// 1 through Ruins 3.
|
||||
/* 0018 */ parray<uint8_t, 0x0C> subtype_area_length_table;
|
||||
|
||||
// This index probability table specifies how likely each possible grind
|
||||
// value is. The table is indexed as [grind][subtype_area_index], where the
|
||||
// subtype area index is how many areas the player is beyond the first area
|
||||
// in which the subtype can first be found (clamped to [0, 3]). To continue
|
||||
// the example above, in Cave 3, subtype_area_index would be 2, since Swords
|
||||
// can first be found two areas earlier in Cave 1.
|
||||
// For example, this table could look like this:
|
||||
// [64 1E 19 14] // Chance of getting a grind +0
|
||||
// [00 1E 17 0F] // Chance of getting a grind +1
|
||||
// [00 14 14 0E] // Chance of getting a grind +2
|
||||
// ...
|
||||
// C1 C2 C3 M1 // (Episode 1 area values from the example for reference)
|
||||
/* 0024 */ parray<parray<uint8_t, 4>, 9> grind_prob_tables;
|
||||
|
||||
// This array specifies the chance that a rare weapon will have each
|
||||
// possible bonus value. This is indexed as [(bonus_value - 10 / 5)][spec],
|
||||
// so the first row refers the probability of getting a -10% bonus, the next
|
||||
// row is the chance of getting -5%, etc., all the way up to +100%. For
|
||||
// non-rare items, spec is determined randomly based on the following field;
|
||||
// for rare items, spec is always 5.
|
||||
/* 0048 */ parray<parray<U16T, 6>, 0x17> bonus_value_prob_tables;
|
||||
|
||||
// This array specifies the value of spec to be used in the above lookup for
|
||||
// non-rare items. This is NOT an index probability table; this is a direct
|
||||
// lookup with indexes [bonus_index][area - 1]. A value of 0xFF in any byte
|
||||
// of this array prevents any weapon from having a bonus in that slot.
|
||||
// For example, the array might look like this:
|
||||
// [00 00 00 01 01 01 01 02 02 02]
|
||||
// [FF FF FF 00 00 00 01 01 01 01]
|
||||
// [FF FF FF FF FF FF FF FF FF 00]
|
||||
// F1 F2 C1 C2 C3 M1 M2 R1 R2 R3 // (Episode 1 areas, for reference)
|
||||
// In this example, spec is 0, 1, or 2 in all cases where a weapon can have
|
||||
// a bonus. In Forest 1 and 2 and Cave 1, weapons may have at most one
|
||||
// bonus; in all other areas except Ruins 3, they can have at most two
|
||||
// bonuses, and in Ruins 3, they can have up to three bonuses.
|
||||
/* 015C */ parray<parray<uint8_t, 10>, 3> nonrare_bonus_prob_spec;
|
||||
|
||||
// This array specifies the chance that a weapon will have each bonus type.
|
||||
// The table is indexed as [bonus_type][area - 1] for non-rare items; for
|
||||
// rare items, a random value in the range [0, 9] is used instead of
|
||||
// (area - 1).
|
||||
// For example, the table might look like this:
|
||||
// [46 46 3F 3E 3E 3D 3C 3C 3A 3A] // Chance of getting no bonus
|
||||
// [14 14 0A 0A 09 02 02 04 05 05] // Chance of getting Native bonus
|
||||
// [0A 0A 12 11 11 09 09 08 08 08] // Chance of getting A.Beast bonus
|
||||
// [00 00 09 0A 0B 13 12 08 09 09] // Chance of getting Machine bonus
|
||||
// [00 00 00 01 01 08 0A 13 13 13] // Chance of getting Dark bonus
|
||||
// [00 00 00 00 00 01 01 01 01 01] // Chance of getting Hit bonus
|
||||
// F1 F2 C1 C2 C3 M1 M2 R1 R2 R3 // (Episode 1 areas, for reference)
|
||||
/* 017A */ parray<parray<uint8_t, 10>, 6> bonus_type_prob_tables;
|
||||
|
||||
// This array (indexed by area - 1) specifies a multiplier of used in
|
||||
// special ability determination. It seems this uses the star values from
|
||||
// ItemPMT, but not yet clear exactly in what way.
|
||||
// TODO: Figure out exactly what this does. Anchor: 80106FEC
|
||||
/* 01B6 */ parray<uint8_t, 0x0A> special_mult;
|
||||
|
||||
// This array (indexed by area - 1) specifies the probability that any
|
||||
// non-rare weapon will have a special ability.
|
||||
/* 01C0 */ parray<uint8_t, 0x0A> special_percent;
|
||||
|
||||
// TODO: Figure out exactly how this table is used. Anchor: 80106D34
|
||||
/* 01CA */ parray<uint8_t, 0x05> armor_shield_type_index_prob_table;
|
||||
|
||||
// This index probability table specifies how common each possible slot
|
||||
// count is for armor drops.
|
||||
/* 01CF */ parray<uint8_t, 0x05> armor_slot_count_prob_table;
|
||||
|
||||
// These values specify maximum indexes into another array which is
|
||||
// generated at runtime. The values here are multiplied by a random float in
|
||||
// the range [0, n] to look up the value in the secondary array, which is
|
||||
// what ends up determining the unit type.
|
||||
// TODO: Figure out and document the exact logic here. Anchor: 80106364
|
||||
/* 01D4 */ parray<uint8_t, 0x0A> unit_maxes;
|
||||
|
||||
// This index probability table is indexed by [tool_class][area - 1]. The
|
||||
// tool class refers to an entry in ItemPMT, which links it to the actual
|
||||
// item code.
|
||||
/* 01DE */ parray<parray<U16T, 0x0A>, 0x1C> tool_class_prob_table;
|
||||
|
||||
// This index probability table determines how likely each technique is to
|
||||
// appear. The table is indexed as [technique_num][area - 1].
|
||||
/* 040E */ parray<parray<uint8_t, 0x0A>, 0x13> technique_index_prob_table;
|
||||
|
||||
// This table specifies the ranges for technique disk levels. The table is
|
||||
// indexed as [technique_num][area - 1]. If either min or max in the range
|
||||
// is 0xFF, or if max < min, technique disks are not dropped for that
|
||||
// technique and area pair.
|
||||
/* 04CC */ parray<parray<Range<uint8_t>, 0x0A>, 0x13> technique_level_ranges;
|
||||
|
||||
// Each byte in this table (indexed by enemy_type) represents the percent
|
||||
// chance that the enemy drops anything at all. (This check is done before
|
||||
// the rare drop check, so the chance of getting a rare item from an enemy
|
||||
// is essentially this probability multiplied by the rare drop rate.)
|
||||
/* 0648 */ parray<uint8_t, 0x64> enemy_type_drop_probs;
|
||||
|
||||
// This array (indexed by enemy_id) specifies the range of meseta values
|
||||
// that each enemy can drop.
|
||||
/* 06AC */ parray<Range<U16T>, 0x64> enemy_meseta_ranges;
|
||||
|
||||
// Each byte in this table (indexed by enemy_type) represents the class of
|
||||
// item that the enemy can drop. The values are:
|
||||
// 00 = weapon
|
||||
// 01 = armor
|
||||
// 02 = shield
|
||||
// 03 = unit
|
||||
// 04 = tool
|
||||
// 05 = meseta
|
||||
// Anything else = no item
|
||||
/* 083C */ parray<uint8_t, 0x64> enemy_item_classes;
|
||||
|
||||
// This table (indexed by area - 1) specifies the ranges of meseta values
|
||||
// that can drop from boxes.
|
||||
/* 08A0 */ parray<Range<U16T>, 0x0A> box_meseta_ranges;
|
||||
|
||||
// This index probability table determines which type of items drop from
|
||||
// boxes. The table is indexed as [item_class][area - 1], with item_class as
|
||||
// the result value (that is, in the example below, the game looks at a
|
||||
// single column and sums the values going down, then the chosen item class
|
||||
// is one of the row indexes based on the weight values in the column.) The
|
||||
// resulting item_class value has the same meaning as in enemy_item_classes
|
||||
// above.
|
||||
// For example, this array might look like the following:
|
||||
// [07 07 08 08 06 07 08 09 09 0A] // Chances per area of a weapon drop
|
||||
// [02 02 02 02 03 02 02 02 03 03] // Chances per area of an armor drop
|
||||
// [02 02 02 02 03 02 02 02 03 03] // Chances per area of a shield drop
|
||||
// [00 00 03 03 03 04 03 04 05 05] // Chances per area of a unit drop
|
||||
// [11 11 12 12 12 12 12 12 12 12] // Chances per area of a tool drop
|
||||
// [32 32 32 32 32 32 32 32 32 32] // Chances per area of a meseta drop
|
||||
// [16 16 11 11 11 11 11 0F 0C 0B] // Chances per area of an empty box
|
||||
// F1 F2 C1 C2 C3 M1 M2 R1 R2 R3 // (Episode 1 areas, for reference)
|
||||
/* 08C8 */ parray<parray<uint8_t, 10>, 7> box_item_class_prob_tables;
|
||||
|
||||
/* 090E */ parray<uint8_t, 2> unused1;
|
||||
|
||||
/* 0910 */ U32T base_weapon_type_prob_table_offset;
|
||||
/* 0914 */ U32T subtype_base_table_offset;
|
||||
/* 0918 */ U32T subtype_area_length_table_offset;
|
||||
/* 091C */ U32T grind_prob_tables_offset;
|
||||
/* 0920 */ U32T armor_shield_type_index_prob_table_offset;
|
||||
/* 0924 */ U32T armor_slot_count_prob_table_offset;
|
||||
/* 0928 */ U32T enemy_meseta_ranges_offset;
|
||||
/* 092C */ U32T enemy_type_drop_probs_offset;
|
||||
/* 0930 */ U32T enemy_item_classes_offset;
|
||||
/* 0934 */ U32T box_meseta_ranges_offset;
|
||||
/* 0938 */ U32T bonus_value_prob_tables_offset;
|
||||
/* 093C */ U32T nonrare_bonus_prob_spec_offset;
|
||||
/* 0940 */ U32T bonus_type_prob_tables_offset;
|
||||
/* 0944 */ U32T special_mult_offset;
|
||||
/* 0948 */ U32T special_percent_offset;
|
||||
/* 094C */ U32T tool_class_prob_table_offset;
|
||||
/* 0950 */ U32T technique_index_prob_table_offset;
|
||||
/* 0954 */ U32T technique_level_ranges_offset;
|
||||
/* 0958 */ uint8_t armor_or_shield_type_bias;
|
||||
/* 0959 */ parray<uint8_t, 3> unused2;
|
||||
/* 095C */ U32T unit_maxes_offset;
|
||||
/* 0960 */ U32T box_item_class_prob_tables_offset;
|
||||
/* 0964 */ U32T unused_offset2;
|
||||
/* 0968 */ U32T unused_offset3;
|
||||
/* 096C */ U32T unused_offset4;
|
||||
/* 0970 */ U32T unused_offset5;
|
||||
/* 0974 */ U32T unused_offset6;
|
||||
/* 0978 */ U32T unused_offset7;
|
||||
/* 097C */ U32T unused_offset8;
|
||||
/* 0980 */ U16T unknown_f1[0x20];
|
||||
/* 09C0 */ U32T unknown_f1_offset;
|
||||
/* 09C4 */ U32T unknown_f2[3];
|
||||
/* 09D0 */ U32T offset_table_offset;
|
||||
/* 09D4 */ U32T unknown_f3[3];
|
||||
/* 09E0 (end of structure) */
|
||||
|
||||
void print(FILE* stream) const;
|
||||
} __attribute__((packed));
|
||||
|
||||
CommonItemSet(std::shared_ptr<const std::string> data);
|
||||
|
||||
const Table<true>& get_table(
|
||||
Episode episode, GameMode mode, uint8_t difficulty, uint8_t secid) const;
|
||||
|
||||
private:
|
||||
GSLArchive gsl;
|
||||
};
|
||||
|
||||
class RELFileSet {
|
||||
public:
|
||||
template <typename ValueT, typename WeightT = ValueT>
|
||||
struct WeightTableEntry {
|
||||
ValueT value;
|
||||
WeightT weight;
|
||||
} __attribute__((packed));
|
||||
|
||||
using WeightTableEntry8 = WeightTableEntry<uint8_t>;
|
||||
using WeightTableEntry32 = WeightTableEntry<be_uint32_t>;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<const std::string> data;
|
||||
StringReader r;
|
||||
|
||||
struct TableSpec {
|
||||
be_uint32_t offset;
|
||||
uint8_t entries_per_table;
|
||||
parray<uint8_t, 3> unused;
|
||||
} __attribute__((packed));
|
||||
|
||||
RELFileSet(std::shared_ptr<const std::string> data);
|
||||
|
||||
template <typename T>
|
||||
std::pair<const T*, size_t> get_table(
|
||||
const TableSpec& spec, size_t index) const {
|
||||
const T* entries = &r.pget<T>(
|
||||
spec.offset + index * spec.entries_per_table * sizeof(T),
|
||||
spec.entries_per_table * sizeof(T));
|
||||
return std::make_pair(entries, spec.entries_per_table);
|
||||
}
|
||||
};
|
||||
|
||||
class ArmorRandomSet : public RELFileSet {
|
||||
public:
|
||||
// This class parses and accesses data from ArmorRandom.rel
|
||||
ArmorRandomSet(std::shared_ptr<const std::string> data);
|
||||
|
||||
std::pair<const WeightTableEntry8*, size_t> get_armor_table(size_t index) const;
|
||||
std::pair<const WeightTableEntry8*, size_t> get_shield_table(size_t index) const;
|
||||
std::pair<const WeightTableEntry8*, size_t> get_unit_table(size_t index) const;
|
||||
|
||||
private:
|
||||
const parray<TableSpec, 3>* tables;
|
||||
};
|
||||
|
||||
class ToolRandomSet : public RELFileSet {
|
||||
public:
|
||||
// This class parses and accesses data from ToolRandom.rel
|
||||
ToolRandomSet(std::shared_ptr<const std::string> data);
|
||||
|
||||
struct TechDiskLevelEntry {
|
||||
enum class Mode : uint8_t {
|
||||
LEVEL_1 = 0,
|
||||
PLAYER_LEVEL_DIVISOR = 1,
|
||||
RANDOM_IN_RANGE = 2,
|
||||
};
|
||||
Mode mode;
|
||||
uint8_t player_level_divisor_or_min_level;
|
||||
uint8_t max_level;
|
||||
} __attribute__((packed));
|
||||
|
||||
std::pair<const uint8_t*, size_t> get_common_recovery_table(size_t index) const;
|
||||
std::pair<const WeightTableEntry8*, size_t> get_rare_recovery_table(size_t index) const;
|
||||
std::pair<const WeightTableEntry8*, size_t> get_tech_disk_table(size_t index) const;
|
||||
std::pair<const TechDiskLevelEntry*, size_t> get_tech_disk_level_table(size_t index) const;
|
||||
|
||||
private:
|
||||
const TableSpec* common_recovery_table_spec;
|
||||
const TableSpec* rare_recovery_table_spec;
|
||||
const TableSpec* tech_disk_table_spec;
|
||||
const TableSpec* tech_disk_level_table_spec;
|
||||
};
|
||||
|
||||
class WeaponRandomSet : public RELFileSet {
|
||||
public:
|
||||
// This class parses and accesses data from WeaponRandom*.rel
|
||||
WeaponRandomSet(std::shared_ptr<const std::string> data);
|
||||
|
||||
struct RangeTableEntry {
|
||||
be_uint32_t min;
|
||||
be_uint32_t max;
|
||||
} __attribute__((packed));
|
||||
|
||||
std::pair<const WeightTableEntry8*, size_t> get_weapon_type_table(size_t index) const;
|
||||
const parray<WeightTableEntry32, 6>* get_bonus_type_table(size_t which, size_t index) const;
|
||||
const RangeTableEntry* get_bonus_range(size_t which, size_t index) const;
|
||||
const parray<WeightTableEntry32, 3>* get_special_mode_table(size_t index) const;
|
||||
const RangeTableEntry* get_standard_grind_range(size_t index) const;
|
||||
const RangeTableEntry* get_favored_grind_range(size_t index) const;
|
||||
|
||||
private:
|
||||
struct Offsets {
|
||||
be_uint32_t weapon_type_table; // [{c, o -> (table)}](10)
|
||||
be_uint32_t bonus_type_table1; // [[{u32 value, u32 weight}](6)](9)
|
||||
be_uint32_t bonus_type_table2; // [[{u32 value, u32 weight}](6)](9)
|
||||
be_uint32_t bonus_range_table1; // [{u32 min_index, u32 max_index}](9)
|
||||
be_uint32_t bonus_range_table2; // [{u32 min_index, u32 max_index}](9)
|
||||
be_uint32_t special_mode_table; // [[{u32 value, u32 weight}](3)](8)
|
||||
be_uint32_t standard_grind_range_table; // [{u32 min, u32 max}](6)
|
||||
be_uint32_t favored_grind_range_table; // [{u32 min, u32 max}](6)
|
||||
} __attribute__((packed));
|
||||
|
||||
const Offsets* offsets;
|
||||
};
|
||||
|
||||
class TekkerAdjustmentSet {
|
||||
public:
|
||||
// This class parses and accesses data from JudgeItem.rel
|
||||
TekkerAdjustmentSet(std::shared_ptr<const std::string> data);
|
||||
|
||||
const ProbabilityTable<uint8_t, 100>& get_special_upgrade_prob_table(uint8_t section_id, bool favored) const;
|
||||
const ProbabilityTable<uint8_t, 100>& get_grind_delta_prob_table(uint8_t section_id, bool favored) const;
|
||||
const ProbabilityTable<uint8_t, 100>& get_bonus_delta_prob_table(uint8_t section_id, bool favored) const;
|
||||
int8_t get_luck_for_special_upgrade(uint8_t delta_index) const;
|
||||
int8_t get_luck_for_grind_delta(uint8_t delta_index) const;
|
||||
int8_t get_luck_for_bonus_delta(uint8_t delta_index) const;
|
||||
|
||||
private:
|
||||
const ProbabilityTable<uint8_t, 100>& get_table(
|
||||
std::array<ProbabilityTable<uint8_t, 100>, 10>& tables_default,
|
||||
std::array<ProbabilityTable<uint8_t, 100>, 10>& tables_favored,
|
||||
uint32_t offset_and_count_offset,
|
||||
bool favored,
|
||||
uint8_t section_id) const;
|
||||
int8_t get_luck(uint32_t start_offset, uint8_t delta_index) const;
|
||||
|
||||
std::shared_ptr<const std::string> data;
|
||||
StringReader r;
|
||||
|
||||
struct DeltaProbabilityEntry {
|
||||
uint8_t delta_index;
|
||||
uint8_t count_default;
|
||||
uint8_t count_favored;
|
||||
} __attribute__((packed));
|
||||
struct LuckTableEntry {
|
||||
uint8_t delta_index;
|
||||
int8_t luck;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Offsets {
|
||||
// Each section ID's favored weapon class has different probabilities than
|
||||
// those used for all other weapons. The tables are labeled with (D) for the
|
||||
// default values and (F) for the favored-class values.
|
||||
|
||||
// Note that the favored bonuses for Redria are all zero; these values are
|
||||
// unused because Redria does not have a favored weapon type. Curiously,
|
||||
// Yellowboze also does not have a favored weapon type, but the values for
|
||||
// Yellowboze are not all zero.
|
||||
|
||||
// This table specifies how likely a special is to be upgraded or
|
||||
// downgraded by one level.
|
||||
// In PSO GC, the special upgrade table is:
|
||||
// Viridia => (D) +1=10%, 0=60%, -1=30%
|
||||
// Viridia => (F) +1=25%, 0=50%, -1=25%
|
||||
// Greennill => (D) +1=25%, 0=65%, -1=10%
|
||||
// Greennill => (F) +1=40%, 0=55%, -1=5%
|
||||
// Skyly => (D) +1=15%, 0=70%, -1=15%
|
||||
// Skyly => (F) +1=30%, 0=60%, -1=10%
|
||||
// Bluefull => (D) +1=10%, 0=60%, -1=30%
|
||||
// Bluefull => (F) +1=25%, 0=50%, -1=25%
|
||||
// Purplenum => (D) +1=25%, 0=65%, -1=10%
|
||||
// Purplenum => (F) +1=40%, 0=55%, -1=5%
|
||||
// Pinkal => (D) +1=15%, 0=70%, -1=15%
|
||||
// Pinkal => (F) +1=30%, 0=60%, -1=10%
|
||||
// Redria => (D) +1=20%, 0=60%, -1=20%
|
||||
// Redria => (F) +1=0%, 0=0%, -1=0%
|
||||
// Oran => (D) +1=15%, 0=70%, -1=15%
|
||||
// Oran => (F) +1=30%, 0=60%, -1=10%
|
||||
// Yellowboze => (D) +1=25%, 0=65%, -1=10%
|
||||
// Yellowboze => (F) +1=40%, 0=55%, -1=5%
|
||||
// Whitill => (D) +1=10%, 0=60%, -1=30%
|
||||
// Whitill => (F) +1=25%, 0=50%, -1=25%
|
||||
be_uint32_t special_upgrade_prob_table_offset; // [{c, o -> (DeltaProbabilityEntry)[10][c]})
|
||||
|
||||
// This table specifies how likely a weapon's grind is to be upgraded or
|
||||
// downgraded, and by how much. The final grind value is clamped to the
|
||||
// range between 0 and the weapon's maximum grind from ItemPMT, inclusive.
|
||||
// In PSO GC, the grind delta table is:
|
||||
// Viridia => (D) +3=3%, +2=7%, +1=13%, 0=60%, -1=10%, -2=7%, -3=0%
|
||||
// Viridia => (F) +3=5%, +2=13%, +1=25%, 0=50%, -1=7%, -2=0%, -3=0%
|
||||
// Greennill => (D) +3=0%, +2=5%, +1=10%, 0=70%, -1=10%, -2=5%, -3=0%
|
||||
// Greennill => (F) +3=3%, +2=7%, +1=20%, 0=60%, -1=10%, -2=0%, -3=0%
|
||||
// Skyly => (D) +3=0%, +2=7%, +1=10%, 0=60%, -1=13%, -2=7%, -3=3%
|
||||
// Skyly => (F) +3=3%, +2=12%, +1=20%, 0=50%, -1=10%, -2=5%, -3=0%
|
||||
// Bluefull => (D) +3=3%, +2=7%, +1=13%, 0=60%, -1=10%, -2=7%, -3=0%
|
||||
// Bluefull => (F) +3=5%, +2=13%, +1=25%, 0=50%, -1=7%, -2=0%, -3=0%
|
||||
// Purplenum => (D) +3=0%, +2=5%, +1=10%, 0=70%, -1=10%, -2=5%, -3=0%
|
||||
// Purplenum => (F) +3=3%, +2=7%, +1=20%, 0=60%, -1=10%, -2=0%, -3=0%
|
||||
// Pinkal => (D) +3=0%, +2=7%, +1=10%, 0=60%, -1=13%, -2=7%, -3=3%
|
||||
// Pinkal => (F) +3=3%, +2=12%, +1=20%, 0=50%, -1=10%, -2=5%, -3=0%
|
||||
// Redria => (D) +3=0%, +2=7%, +1=10%, 0=60%, -1=13%, -2=7%, -3=3%
|
||||
// Redria => (F) +3=0%, +2=0%, +1=0%, 0=0%, -1=0%, -2=0%, -3=0%
|
||||
// Oran => (D) +3=0%, +2=7%, +1=10%, 0=60%, -1=13%, -2=7%, -3=3%
|
||||
// Oran => (F) +3=3%, +2=12%, +1=20%, 0=50%, -1=10%, -2=5%, -3=0%
|
||||
// Yellowboze => (D) +3=0%, +2=5%, +1=10%, 0=70%, -1=10%, -2=5%, -3=0%
|
||||
// Yellowboze => (F) +3=3%, +2=7%, +1=20%, 0=60%, -1=10%, -2=0%, -3=0%
|
||||
// Whitill => (D) +3=3%, +2=7%, +1=13%, 0=60%, -1=10%, -2=7%, -3=0%
|
||||
// Whitill => (F) +3=5%, +2=13%, +1=25%, 0=50%, -1=7%, -2=0%, -3=0%
|
||||
be_uint32_t grind_delta_prob_table_offset; // [{c, o -> (DeltaProbabilityEntry)[10][c]})
|
||||
|
||||
// This table specifies how likely a weapon's bonuses are to be upgraded
|
||||
// or downgraded, and by how much. The final bonuses are capped above at
|
||||
// 100, but there is no lower limit (so negative results are possible).
|
||||
// In PSO GC, the bonus delta table is:
|
||||
// Viridia => (D) +10=5%, +5=15%, 0=60%, -5=15%, -10=5%
|
||||
// Viridia => (F) +10=8%, +5=20%, 0=60%, -5=10%, -10=2%
|
||||
// Greennill => (D) +10=5%, +5=10%, 0=50%, -5=25%, -10=10%
|
||||
// Greennill => (F) +10=8%, +5=15%, 0=50%, -5=20%, -10=7%
|
||||
// Skyly => (D) +10=10%, +5=25%, 0=50%, -5=10%, -10=5%
|
||||
// Skyly => (F) +10=13%, +5=30%, 0=50%, -5=5%, -10=2%
|
||||
// Bluefull => (D) +10=5%, +5=15%, 0=60%, -5=15%, -10=5%
|
||||
// Bluefull => (F) +10=8%, +5=20%, 0=60%, -5=10%, -10=2%
|
||||
// Purplenum => (D) +10=5%, +5=10%, 0=50%, -5=25%, -10=10%
|
||||
// Purplenum => (F) +10=8%, +5=15%, 0=50%, -5=20%, -10=7%
|
||||
// Pinkal => (D) +10=10%, +5=25%, 0=50%, -5=10%, -10=5%
|
||||
// Pinkal => (F) +10=13%, +5=30%, 0=50%, -5=5%, -10=2%
|
||||
// Redria => (D) +10=10%, +5=25%, 0=50%, -5=10%, -10=5%
|
||||
// Redria => (F) +10=0%, +5=0%, 0=0%, -5=0%, -10=0%
|
||||
// Oran => (D) +10=10%, +5=25%, 0=50%, -5=10%, -10=5%
|
||||
// Oran => (F) +10=13%, +5=30%, 0=50%, -5=5%, -10=2%
|
||||
// Yellowboze => (D) +10=5%, +5=10%, 0=50%, -5=25%, -10=10%
|
||||
// Yellowboze => (F) +10=8%, +5=15%, 0=50%, -5=20%, -10=7%
|
||||
// Whitill => (D) +10=5%, +5=15%, 0=60%, -5=15%, -10=5%
|
||||
// Whitill => (F) +10=8%, +5=20%, 0=60%, -5=10%, -10=2%
|
||||
be_uint32_t bonus_delta_prob_table_offset; // [{c, o -> (DeltaProbabilityEntry)[10][c]})
|
||||
|
||||
// There is a secondary computation done during weapon adjustment that
|
||||
// appears to determine how "good" the resulting weapon is compared to its
|
||||
// original state. If the result of this computation is positive, the game
|
||||
// plays a jingle when the tekker result is accepted. These tables describe
|
||||
// how much each delta affects this value, which we call luck.
|
||||
|
||||
// In PSO GC, the special upgrade luck table is:
|
||||
// +1 => +20, 0 => 0, -1 => -20
|
||||
be_uint32_t special_upgrade_luck_table_offset; // LuckTableEntry[...]; ending with FF FF
|
||||
|
||||
// In PSO GC, the grind delta luck table is:
|
||||
// +3 => +10, +2 => +5, +1 => +3, 0 => 0, -1 => -3, -2 => -5, -3 => -10
|
||||
be_uint32_t grind_delta_luck_table_offset; // LuckTableEntry[...]; ending with FF FF
|
||||
|
||||
// In PSO GC, the bonus delta luck table is:
|
||||
// +10 => +15, +5 => +8, 0 => 0, -5 => -8, -10 => -15
|
||||
be_uint32_t bonus_delta_luck_offset; // LuckTableEntry[...]; ending with FF FF
|
||||
} __attribute__((packed));
|
||||
|
||||
const Offsets* offsets;
|
||||
|
||||
mutable std::array<ProbabilityTable<uint8_t, 100>, 10> special_upgrade_prob_tables_default;
|
||||
mutable std::array<ProbabilityTable<uint8_t, 100>, 10> special_upgrade_prob_tables_favored;
|
||||
mutable std::array<ProbabilityTable<uint8_t, 100>, 10> grind_delta_prob_tables_default;
|
||||
mutable std::array<ProbabilityTable<uint8_t, 100>, 10> grind_delta_prob_tables_favored;
|
||||
mutable std::array<ProbabilityTable<uint8_t, 100>, 10> bonus_delta_prob_tables_default;
|
||||
mutable std::array<ProbabilityTable<uint8_t, 100>, 10> bonus_delta_prob_tables_favored;
|
||||
};
|
||||
+1257
-317
File diff suppressed because it is too large
Load Diff
+215
-4
@@ -2,12 +2,223 @@
|
||||
|
||||
#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,
|
||||
};
|
||||
|
||||
std::string prs_compress(const void* vdata, size_t size);
|
||||
std::string prs_compress(const std::string& data);
|
||||
template <>
|
||||
const char* name_for_enum<CompressPhase>(CompressPhase v);
|
||||
|
||||
std::string prs_decompress(const std::string& data, size_t max_size = 0);
|
||||
size_t prs_decompress_size(const std::string& data, size_t max_size = 0);
|
||||
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);
|
||||
|
||||
// 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);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
// dc_serial_number_is_valid_slow is Sega's implementation;
|
||||
// dc_serial_number_is_valid_fast produces identical results but is between 3000
|
||||
// and 7500 times faster, depending on the compiler's optimization level.
|
||||
bool dc_serial_number_is_valid_slow(
|
||||
const std::string& s, uint8_t domain, uint8_t subdomain = 0xFF);
|
||||
bool dc_serial_number_is_valid_fast(
|
||||
const std::string& s, uint8_t domain, uint8_t subdomain = 0xFF);
|
||||
bool dc_serial_number_is_valid_fast(
|
||||
uint32_t serial_number, uint8_t domain, uint8_t subdomain = 0xFF);
|
||||
bool decoded_dc_serial_number_is_valid_fast(
|
||||
uint32_t serial_number, uint8_t domain, uint8_t subdomain = 0xFF);
|
||||
|
||||
std::string generate_dc_serial_number(uint8_t domain, uint8_t subdomain = 0xFF);
|
||||
std::unordered_map<uint32_t, std::string> generate_all_dc_serial_numbers(uint8_t domain = 0xFF, uint8_t subdomain = 0xFF);
|
||||
|
||||
void dc_serial_number_speed_test(uint64_t seed = 0xFFFFFFFFFFFFFFFF);
|
||||
+16
-15
@@ -1,27 +1,28 @@
|
||||
#include "DNSServer.hh"
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <poll.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <poll.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Network.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Loggers.hh"
|
||||
#include "NetworkAddresses.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
DNSServer::DNSServer(shared_ptr<struct event_base> base,
|
||||
uint32_t local_connect_address, uint32_t external_connect_address) :
|
||||
base(base), local_connect_address(local_connect_address),
|
||||
external_connect_address(external_connect_address) { }
|
||||
DNSServer::DNSServer(
|
||||
shared_ptr<struct event_base> base,
|
||||
uint32_t local_connect_address, uint32_t external_connect_address)
|
||||
: base(base),
|
||||
local_connect_address(local_connect_address),
|
||||
external_connect_address(external_connect_address) {}
|
||||
|
||||
DNSServer::~DNSServer() {
|
||||
for (const auto& it : this->fd_to_receive_event) {
|
||||
@@ -42,11 +43,11 @@ void DNSServer::listen(int port) {
|
||||
}
|
||||
|
||||
void DNSServer::add_socket(int fd) {
|
||||
unique_ptr<struct event, void(*)(struct event*)> e(event_new(this->base.get(),
|
||||
fd, EV_READ | EV_PERSIST, &DNSServer::dispatch_on_receive_message,
|
||||
this), event_free);
|
||||
unique_ptr<struct event, void (*)(struct event*)> e(
|
||||
event_new(this->base.get(), fd, EV_READ | EV_PERSIST, &DNSServer::dispatch_on_receive_message, this),
|
||||
event_free);
|
||||
event_add(e.get(), nullptr);
|
||||
this->fd_to_receive_event.emplace(fd, move(e));
|
||||
this->fd_to_receive_event.emplace(fd, std::move(e));
|
||||
}
|
||||
|
||||
void DNSServer::dispatch_on_receive_message(evutil_socket_t fd,
|
||||
@@ -91,7 +92,7 @@ void DNSServer::on_receive_message(int fd, short) {
|
||||
|
||||
if (bytes < 0) {
|
||||
if (errno != EAGAIN) {
|
||||
log(INFO, "[DNSServer] input error %d", errno);
|
||||
dns_server_log.error("input error %d", errno);
|
||||
throw runtime_error("cannot read from udp socket");
|
||||
}
|
||||
break;
|
||||
@@ -100,7 +101,7 @@ void DNSServer::on_receive_message(int fd, short) {
|
||||
break;
|
||||
|
||||
} else if (bytes < 0x0C) {
|
||||
log(WARNING, "[DNSServer] input query too small");
|
||||
dns_server_log.warning("input query too small");
|
||||
print_data(stderr, input.data(), bytes);
|
||||
|
||||
} else {
|
||||
|
||||
+3
-4
@@ -3,10 +3,9 @@
|
||||
#include <event2/event.h>
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <set>
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
class DNSServer {
|
||||
public:
|
||||
@@ -28,7 +27,7 @@ public:
|
||||
|
||||
private:
|
||||
std::shared_ptr<struct event_base> base;
|
||||
std::unordered_map<int, std::unique_ptr<struct event, void(*)(struct event*)>> fd_to_receive_event;
|
||||
std::unordered_map<int, std::unique_ptr<struct event, void (*)(struct event*)>> fd_to_receive_event;
|
||||
uint32_t local_connect_address;
|
||||
uint32_t external_connect_address;
|
||||
|
||||
|
||||
+1050
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,145 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <phosg/Tools.hh>
|
||||
|
||||
#include "StaticGameData.hh"
|
||||
|
||||
enum class EnemyType {
|
||||
UNKNOWN = -1,
|
||||
NONE = 0,
|
||||
AL_RAPPY,
|
||||
ASTARK,
|
||||
BA_BOOTA,
|
||||
BARBA_RAY,
|
||||
BARBAROUS_WOLF,
|
||||
BEE_L,
|
||||
BEE_R,
|
||||
BOOMA,
|
||||
BOOTA,
|
||||
BULCLAW,
|
||||
CANADINE,
|
||||
CANADINE_GROUP,
|
||||
CANANE,
|
||||
CHAOS_BRINGER,
|
||||
CHAOS_SORCERER,
|
||||
CLAW,
|
||||
DARK_BELRA,
|
||||
DARK_FALZ_1,
|
||||
DARK_FALZ_2,
|
||||
DARK_FALZ_3,
|
||||
DARK_GUNNER,
|
||||
DARVANT,
|
||||
DARVANT_ULTIMATE,
|
||||
DE_ROL_LE,
|
||||
DE_ROL_LE_BODY,
|
||||
DE_ROL_LE_MINE,
|
||||
DEATH_GUNNER,
|
||||
DEL_LILY,
|
||||
DEL_RAPPY,
|
||||
DEL_RAPPY_ALT,
|
||||
DELBITER,
|
||||
DELDEPTH,
|
||||
DELSABER,
|
||||
DIMENIAN,
|
||||
DOLMDARL,
|
||||
DOLMOLM,
|
||||
DORPHON,
|
||||
DORPHON_ECLAIR,
|
||||
DRAGON,
|
||||
DUBCHIC,
|
||||
DUBWITCH, // Has no entry in battle params
|
||||
EGG_RAPPY,
|
||||
EPSIGUARD,
|
||||
EPSILON,
|
||||
EVIL_SHARK,
|
||||
GAEL,
|
||||
GAL_GRYPHON,
|
||||
GARANZ,
|
||||
GEE,
|
||||
GI_GUE,
|
||||
GIBBLES,
|
||||
GIGOBOOMA,
|
||||
GILLCHIC,
|
||||
GIRTABLULU,
|
||||
GOBOOMA,
|
||||
GOL_DRAGON,
|
||||
GORAN,
|
||||
GORAN_DETONATOR,
|
||||
GRASS_ASSASSIN,
|
||||
GUIL_SHARK,
|
||||
HALLO_RAPPY,
|
||||
HIDOOM,
|
||||
HILDEBEAR,
|
||||
HILDEBLUE,
|
||||
ILL_GILL,
|
||||
KONDRIEU,
|
||||
LA_DIMENIAN,
|
||||
LOVE_RAPPY,
|
||||
MERICAROL,
|
||||
MERICUS,
|
||||
MERIKLE,
|
||||
MERILLIA,
|
||||
MERILTAS,
|
||||
MERISSA_A,
|
||||
MERISSA_AA,
|
||||
MIGIUM,
|
||||
MONEST,
|
||||
MORFOS,
|
||||
MOTHMANT,
|
||||
NANO_DRAGON,
|
||||
NAR_LILY,
|
||||
OLGA_FLOW_1,
|
||||
OLGA_FLOW_2,
|
||||
PAL_SHARK,
|
||||
PAN_ARMS,
|
||||
PAZUZU,
|
||||
PAZUZU_ALT,
|
||||
PIG_RAY,
|
||||
POFUILLY_SLIME,
|
||||
POUILLY_SLIME,
|
||||
POISON_LILY,
|
||||
PYRO_GORAN,
|
||||
RAG_RAPPY,
|
||||
RECOBOX,
|
||||
RECON,
|
||||
SAINT_MILLION,
|
||||
SAINT_RAPPY,
|
||||
SAND_RAPPY,
|
||||
SAND_RAPPY_ALT,
|
||||
SATELLITE_LIZARD,
|
||||
SATELLITE_LIZARD_ALT,
|
||||
SAVAGE_WOLF,
|
||||
SHAMBERTIN,
|
||||
SINOW_BEAT,
|
||||
SINOW_BERILL,
|
||||
SINOW_GOLD,
|
||||
SINOW_SPIGELL,
|
||||
SINOW_ZELE,
|
||||
SINOW_ZOA,
|
||||
SO_DIMENIAN,
|
||||
UL_GIBBON,
|
||||
VOL_OPT_1,
|
||||
VOL_OPT_2,
|
||||
VOL_OPT_AMP,
|
||||
VOL_OPT_CORE,
|
||||
VOL_OPT_MONITOR,
|
||||
VOL_OPT_PILLAR,
|
||||
YOWIE,
|
||||
YOWIE_ALT,
|
||||
ZE_BOOTA,
|
||||
ZOL_GIBBON,
|
||||
ZU,
|
||||
ZU_ALT,
|
||||
MAX_ENEMY_TYPE,
|
||||
};
|
||||
|
||||
template <>
|
||||
const char* name_for_enum<EnemyType>(EnemyType type);
|
||||
template <>
|
||||
EnemyType enum_for_name<EnemyType>(const char* name);
|
||||
|
||||
bool enemy_type_valid_for_episode(Episode episode, EnemyType enemy_type);
|
||||
uint8_t battle_param_index_for_enemy_type(Episode episode, EnemyType enemy_type);
|
||||
uint8_t rare_table_index_for_enemy_type(EnemyType enemy_type);
|
||||
-894
@@ -1,894 +0,0 @@
|
||||
#include "Episode3.hh"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <array>
|
||||
#include <phosg/Filesystem.hh>
|
||||
|
||||
#include "Compression.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
static const vector<const char*> name_for_card_type({
|
||||
"HunterSC",
|
||||
"ArkzSC",
|
||||
"Item",
|
||||
"Creature",
|
||||
"Action",
|
||||
"Assist",
|
||||
});
|
||||
|
||||
static const unordered_map<uint8_t, const char*> description_for_when({
|
||||
{0x01, "Set"}, // TODO: Is 01 this, or "Permanent"?
|
||||
{0x02, "Attack"},
|
||||
{0x03, "??? (TODO)"},
|
||||
{0x04, "Before turn"},
|
||||
{0x05, "Destroyed"},
|
||||
{0x0A, "Permanent"}, // only used on Tollaw; could be same as 01
|
||||
{0x0B, "Battle"},
|
||||
{0x0C, "Opponent destroyed"}, // TODO: but this is also used for some support things like Shifta, and for Snatch, which also applies when opponents are not destroyed
|
||||
{0x0D, "Attack lands"},
|
||||
{0x0E, "Before attack phase"},
|
||||
{0x16, "Battle end"},
|
||||
{0x17, "Each defense"},
|
||||
{0x20, "Each attack"},
|
||||
{0x22, "Act phase"},
|
||||
{0x27, "Move phase"},
|
||||
{0x29, "Set and act phases"},
|
||||
{0x33, "Defense phase"},
|
||||
{0x3D, "Battle"}, // TODO: how is this different from 3D and 0B?
|
||||
{0x3E, "Battle"}, // TODO: how is this different from 3D and 0B?
|
||||
{0x3F, "Each defense"}, // TODO: how is this different from 17?
|
||||
{0x46, "On specific turn"},
|
||||
});
|
||||
|
||||
static const unordered_map<string, const char*> description_for_expr_token({
|
||||
{"f", "Number of FCs controlled by current SC"},
|
||||
{"d", "Die roll"},
|
||||
{"ap", "Attacker AP"}, // Unused
|
||||
{"tp", "Attacker TP"},
|
||||
{"hp", "Attacker HP"}, // TODO: How is this different from ehp?
|
||||
{"mhp", "Attacker maximum HP"},
|
||||
{"dm", "Unknown: dm"}, // Unused
|
||||
{"tdm", "Unknown: tdm"}, // Unused
|
||||
{"tf", "Number of SC\'s destroyed FCs"},
|
||||
{"ac", "Remaining ATK points"},
|
||||
{"php", "Unknown: php"}, // Unused
|
||||
{"dc", "Unknown: dc"}, // Unused
|
||||
{"cs", "Unknown: cs"}, // Unused
|
||||
{"a", "Unknown: a"}, // Unused
|
||||
{"kap", "Action cards AP"},
|
||||
{"ktp", "Action cards TP"},
|
||||
{"dn", "Unknown: dn"}, // Unused
|
||||
{"hf", "Unknown: hf"}, // Unused
|
||||
{"df", "Number of destroyed ally FCs (including SC\'s own)"},
|
||||
{"ff", "Number of ally FCs (including SC\'s own)"},
|
||||
{"ef", "Number of enemy FCs"},
|
||||
{"bi", "Number of Native FCs on either team"},
|
||||
{"ab", "Number of A.Beast FCs on either team"},
|
||||
{"mc", "Number of Machine FCs on either team"},
|
||||
{"dk", "Number of Dark FCs on either team"},
|
||||
{"sa", "Number of Sword-type items on either team"},
|
||||
{"gn", "Number of Gun-type items on either team"},
|
||||
{"wd", "Number of Cane-type items on either team"},
|
||||
{"tt", "Unknown: tt"}, // Unused
|
||||
{"lv", "Dice bonus"},
|
||||
{"adm", "Attack damage"},
|
||||
{"ddm", "Defending damage"},
|
||||
{"sat", "Number of Sword-type items on SC\'s team"},
|
||||
{"edm", "Defending damage"}, // TODO: How is this different from ddm?
|
||||
{"ldm", "Unknown: ldm"}, // Unused
|
||||
{"rdm", "Defending damage"}, // TODO: How is this different from ddm/edm?
|
||||
{"fdm", "Final damage (after defense)"},
|
||||
{"ndm", "Unknown: ndm"}, // Unused
|
||||
{"ehp", "Attacker HP"},
|
||||
});
|
||||
|
||||
// Arguments are encoded as 3-character null-terminated strings (why?!), and are
|
||||
// used for adding conditions to effects (e.g. making them only trigger in
|
||||
// certain situations) or otherwise customizing their results.
|
||||
// Argument meanings:
|
||||
// a01 = ???
|
||||
// cXY/CXY = linked items (require item with cYX/CYX to be equipped as well)
|
||||
// dXY = roll one die; require result between X and Y inclusive
|
||||
// e00 = effect lasts while equipped? (in contrast to tXX)
|
||||
// hXX = require HP >= XX
|
||||
// iXX = require HP <= XX
|
||||
// nXX = require condition XX (see description_for_n_condition)
|
||||
// oXX = seems to be "require previous random-condition effect to have happened"
|
||||
// TODO: this is used as both o01 (recovery) and o11 (reflection)
|
||||
// conditions - why the difference?
|
||||
// pXX = who to target (see description_for_p_target)
|
||||
// rXX = randomly pass with XX% chance (if XX == 00, 100% chance?)
|
||||
// sXY = require card cost between X and Y ATK points (inclusive)
|
||||
// tXX = lasts XX turns, or activate after XX turns
|
||||
|
||||
static const vector<const char*> description_for_n_condition({
|
||||
/* n00 */ "Always true",
|
||||
/* n01 */ "??? (TODO)",
|
||||
/* n02 */ "Destroyed with a single attack?",
|
||||
/* n03 */ "Unknown", // Unused
|
||||
/* n04 */ "Attack has Pierce",
|
||||
/* n05 */ "Attack has Rampage",
|
||||
/* n06 */ "Native attribute",
|
||||
/* n07 */ "A.Beast attribute",
|
||||
/* n08 */ "Machine attribute",
|
||||
/* n09 */ "Dark attribute",
|
||||
/* n10 */ "Sword-type item",
|
||||
/* n11 */ "Gun-type item",
|
||||
/* n12 */ "Cane-type item",
|
||||
/* n13 */ "Guard item",
|
||||
/* n14 */ "Story Character",
|
||||
/* n15 */ "Attacker does not use action cards",
|
||||
/* n16 */ "Aerial attribute",
|
||||
/* n17 */ "Same AP as opponent",
|
||||
/* n18 */ "Opponent is SC",
|
||||
/* n19 */ "Has Paralyzed condition",
|
||||
/* n20 */ "Has Frozen condition",
|
||||
});
|
||||
|
||||
static const vector<const char*> description_for_p_target({
|
||||
/* p00 */ "Unknown: p00", // Unused; probably invalid
|
||||
/* p01 */ "SC / FC who set the card",
|
||||
/* p02 */ "Attacking SC / FC",
|
||||
/* p03 */ "Unknown: p03", // Unused
|
||||
/* p04 */ "Unknown: p04", // Unused
|
||||
/* p05 */ "Unknown: p05", // Unused
|
||||
/* p06 */ "??? (TODO)",
|
||||
/* p07 */ "??? (TODO; Weakness)",
|
||||
/* p08 */ "FC's owner SC",
|
||||
/* p09 */ "Unknown: p09", // Unused
|
||||
/* p10 */ "All ally FCs",
|
||||
/* p11 */ "All ally FCs", // TODO: how is this different from p10?
|
||||
/* p12 */ "All non-aerial FCs on both teams",
|
||||
/* p13 */ "All FCs on both teams that are Frozen",
|
||||
/* p14 */ "All FCs on both teams that have <= 3 HP",
|
||||
/* p15 */ "All FCs except SCs", // TODO: used during attacks only?
|
||||
/* p16 */ "All FCs except SCs", // TODO: used during attacks only? how is this different from p15?
|
||||
/* p17 */ "This card",
|
||||
/* p18 */ "SC who equipped this card",
|
||||
/* p19 */ "Unknown: p19", // Unused
|
||||
/* p20 */ "Unknown: p20", // Unused
|
||||
/* p21 */ "Unknown: p21", // Unused
|
||||
/* p22 */ "All characters (SCs & FCs) including this card", // TODO: But why does Shifta apply only to allies then?
|
||||
/* p23 */ "All characters (SCs & FCs) except this card",
|
||||
/* p24 */ "All FCs on both teams that have Paralysis",
|
||||
/* p25 */ "Unknown: p25", // Unused
|
||||
/* p26 */ "Unknown: p26", // Unused
|
||||
/* p27 */ "Unknown: p27", // Unused
|
||||
/* p28 */ "Unknown: p28", // Unused
|
||||
/* p29 */ "Unknown: p29", // Unused
|
||||
/* p30 */ "Unknown: p30", // Unused
|
||||
/* p31 */ "Unknown: p31", // Unused
|
||||
/* p32 */ "Unknown: p32", // Unused
|
||||
/* p33 */ "Unknown: p33", // Unused
|
||||
/* p34 */ "Unknown: p34", // Unused
|
||||
/* p35 */ "All characters (SCs & FCs) within range", // Used for Explosion effect
|
||||
/* p36 */ "All ally SCs within range, but not the caster", // Resta
|
||||
/* p37 */ "All FCs or all opponent FCs (TODO)", // TODO: when to use which selector? is a3 involved here somehow?
|
||||
/* p38 */ "All allies except items within range (and not this card)",
|
||||
/* p39 */ "All FCs that cost 4 or more points",
|
||||
/* p40 */ "All FCs that cost 3 or fewer points",
|
||||
/* p41 */ "Unknown: p41", // Unused
|
||||
/* p42 */ "Attacker during defense phase", // Only used by TP Defense
|
||||
/* p43 */ "Owner SC of defending FC during attack",
|
||||
/* p44 */ "SC\'s own creature FCs within range",
|
||||
/* p45 */ "Both attacker and defender", // Used for Snatch, which moves EXP from one to the other
|
||||
/* p46 */ "All SCs & FCs one space left or right of this card",
|
||||
/* p47 */ "FC\'s owner Boss SC", // Only used for Gibbles+ which explicitly mentions Boss SC, so it looks like this is p08 but for bosses
|
||||
/* p48 */ "Everything within range, including this card\'s user", // Madness
|
||||
/* p49 */ "All ally FCs within range except this card",
|
||||
});
|
||||
|
||||
struct Ep3AbilityDescription {
|
||||
uint8_t command;
|
||||
bool has_expr;
|
||||
const char* name;
|
||||
const char* description;
|
||||
};
|
||||
|
||||
static const std::vector<Ep3AbilityDescription> name_for_effect_command({
|
||||
{0x00, false, nullptr, nullptr},
|
||||
{0x01, true, "AP Boost", "Temporarily increase AP by N"},
|
||||
{0x02, false, "Rampage", "Rampage"},
|
||||
{0x03, true, "Multi Strike", "Duplicate attack N times"},
|
||||
{0x04, true, "Damage Modifier 1", "Set attack damage / AP to N after action cards applied (step 1)"},
|
||||
{0x05, false, "Immobile", "Give Immobile condition"},
|
||||
{0x06, false, "Hold", "Give Hold condition"},
|
||||
{0x07, false, nullptr, nullptr},
|
||||
{0x08, true, "TP Boost", "Add N TP temporarily during attack"},
|
||||
{0x09, true, "Give Damage", "Cause direct N HP loss"},
|
||||
{0x0A, false, "Guom", "Give Guom condition"},
|
||||
{0x0B, false, "Paralyze", "Give Paralysis condition"},
|
||||
{0x0C, false, nullptr, nullptr},
|
||||
{0x0D, false, "A/H Swap", "Swap AP and HP temporarily"},
|
||||
{0x0E, false, "Pierce", "Attack SC directly even if they have items equipped"},
|
||||
{0x0F, false, nullptr, nullptr},
|
||||
{0x10, true, "Heal", "Increase HP by N"},
|
||||
{0x11, false, "Return to Hand", "Return card to hand"},
|
||||
{0x12, false, nullptr, nullptr},
|
||||
{0x13, false, nullptr, nullptr},
|
||||
{0x14, false, "Acid", "Give Acid condition"},
|
||||
{0x15, false, nullptr, nullptr},
|
||||
{0x16, true, "Mighty Knuckle", "Temporarily increase AP by N, and set ATK dice to zero"},
|
||||
{0x17, true, "Unit Blow", "Temporarily increase AP by N * number of this card set within phase"},
|
||||
{0x18, false, "Curse", "Give Curse condition"},
|
||||
{0x19, false, "Combo (AP)", "Temporarily increase AP by number of this card set within phase"},
|
||||
{0x1A, false, "Pierce/Rampage Block", "Block attack if Pierce/Rampage (?)"},
|
||||
{0x1B, false, "Ability Trap", "Temporarily disable opponent abilities"},
|
||||
{0x1C, false, "Freeze", "Give Freeze condition"},
|
||||
{0x1D, false, "Anti-Abnormality", "Cure all conditions"},
|
||||
{0x1E, false, nullptr, nullptr},
|
||||
{0x1F, false, "Explosion", "Damage all SCs and FCs by number of this same card set * 2"},
|
||||
{0x20, false, nullptr, nullptr},
|
||||
{0x21, false, nullptr, nullptr},
|
||||
{0x22, false, nullptr, nullptr},
|
||||
{0x23, false, "Return to Deck", "Cancel discard and move to bottom of deck instead"},
|
||||
{0x24, false, "Aerial", "Give Aerial status"},
|
||||
{0x25, true, "AP Loss", "Make attacker temporarily lose N AP during defense"},
|
||||
{0x26, true, "Bonus From Leader", "Gain AP equal to the number of cards of type N on the field"},
|
||||
{0x27, false, "Free Maneuver", "Enable movement over occupied tiles"},
|
||||
{0x28, false, "Haste", "Make move actions free"},
|
||||
{0x29, true, "Clone", "Make setting this card free if at least one card of type N is already on the field"},
|
||||
{0x2A, true, "DEF Disable by Cost", "Disable use of any defense cards costing between (N / 10) and (N % 10) points, inclusive"},
|
||||
{0x2B, true, "Filial", "Increase controlling SC\'s HP by N when this card is destroyed"},
|
||||
{0x2C, true, "Snatch", "Steal N EXP during attack"},
|
||||
{0x2D, true, "Hand Disrupter", "DIscard N cards from hand immediately"},
|
||||
{0x2E, false, "Drop", "Give Drop condition"},
|
||||
{0x2F, false, "Action Disrupter", "Destroy all action cards used by attacker"},
|
||||
{0x30, true, "Set HP", "Set HP to N (?) (TODO)"},
|
||||
{0x31, false, "Native Shield", "Block attacks from Native creatures"},
|
||||
{0x32, false, "A.Beast Shield", "Block attacks from A.Beast creatures"},
|
||||
{0x33, false, "Machine Shield", "Block attacks from Machine creatures"},
|
||||
{0x34, false, "Dark Shield", "Block attacks from Dark creatures"},
|
||||
{0x35, false, "Sword Shield", "Block attacks from Sword items"},
|
||||
{0x36, false, "Gun Shield", "Block attacks from Gun items"},
|
||||
{0x37, false, "Cane Shield", "Block attacks from Cane items"},
|
||||
{0x38, false, nullptr, nullptr},
|
||||
{0x39, false, nullptr, nullptr},
|
||||
{0x3A, false, "Defender", "Make attacks go to setter of this card instead of original target"},
|
||||
{0x3B, false, "Survival Decoys", "Redirect damage for multi-sided attack"},
|
||||
{0x3C, true, "Give/Take EXP", "Give N EXP, or take if N is negative"},
|
||||
{0x3D, false, nullptr, nullptr},
|
||||
{0x3E, false, "Death Companion", "If this card has 1 or 2 HP, set its HP to N"},
|
||||
{0x3F, true, "EXP Decoy", "If defender has EXP, lose EXP instead of getting damage when attacked"},
|
||||
{0x40, true, "Set MV", "Set MV to N"},
|
||||
{0x41, true, "Group", "Temporarily increase AP by N * number of this card on field, excluding itself"},
|
||||
{0x42, false, "Berserk", "User of this card receives the same damage as target, and isn't helped by target's defense cards"},
|
||||
{0x43, false, "Guard Creature", "Attacks on controlling SC damage this card instead"},
|
||||
{0x44, false, "Tech", "Technique cards cost 1 fewer ATK point"},
|
||||
{0x45, false, "Big Swing", "Increase all attacking ATK costs by 1"},
|
||||
{0x46, false, nullptr, nullptr},
|
||||
{0x47, false, "Shield Weapon", "Limit attacker\'s choice of target to guard items"},
|
||||
{0x48, false, "ATK Dice Boost", "Increase ATK dice roll by 1"},
|
||||
{0x49, false, nullptr, nullptr},
|
||||
{0x4A, false, "Major Pierce", "If SC has over half of max HP, attacks target SC instead of equipped items"},
|
||||
{0x4B, false, "Heavy Pierce", "If SC has 3 or more items equipped, attacks target SC instead of equipped items"},
|
||||
{0x4C, false, "Major Rampage", "If SC has over half of max HP, attacks target SC and all equipped items"},
|
||||
{0x4D, false, "Heavy Rampage", "If SC has 3 or more items equipped, attacks target SC and all equipped items"},
|
||||
{0x4E, true, "AP Growth", "Permanently increase AP by N"},
|
||||
{0x4F, true, "TP Growth", "Permanently increase TP by N"},
|
||||
{0x50, true, "Reborn", "If any card of type N is on the field, this card goes to the hand when destroyed instead of being discarded"},
|
||||
{0x51, true, "Copy", "Temporarily set AP/TP to N percent (or 100% if N is 0) of opponent\'s values"},
|
||||
{0x52, false, nullptr, nullptr},
|
||||
{0x53, true, "Misc. Guards", "Add N to card's defense value"},
|
||||
{0x54, true, "AP Override", "Set AP to N temporarily"},
|
||||
{0x55, true, "TP Override", "Set TP to N temporarily"},
|
||||
{0x56, false, "Return", "Return card to hand on destruction instead of discarding"},
|
||||
{0x57, false, "A/T Swap Perm", "Permanently swap AP and TP"},
|
||||
{0x58, false, "A/H Swap Perm", "Permanently swap AP and HP"},
|
||||
{0x59, true, "Slayers/Assassins", "Temporarily increase AP during attack"},
|
||||
{0x5A, false, "Anti-Abnormality", "Remove all conditions"},
|
||||
{0x5B, false, "Fixed Range", "Use SC\'s range instead of weapon or attack card ranges"},
|
||||
{0x5C, false, "Elude", "SC does not lose HP when equipped items are destroyed"},
|
||||
{0x5D, false, "Parry", "Forward attack to a random FC within one tile of original target, excluding attacker and original target"},
|
||||
{0x5E, false, "Block Attack", "Completely block attack"},
|
||||
{0x5F, false, nullptr, nullptr},
|
||||
{0x60, false, nullptr, nullptr},
|
||||
{0x61, true, "Combo (TP)", "Gain TP equal to the number of cards of type N on the field"},
|
||||
{0x62, true, "Misc. AP Bonuses", "Temporarily increase AP by N"},
|
||||
{0x63, true, "Misc. TP Bonuses", "Temporarily increase TP by N"},
|
||||
{0x64, false, nullptr, nullptr},
|
||||
{0x65, true, "Misc. Defense Bonuses", "Decrease damage by N"},
|
||||
{0x66, true, "Mostly Halfguards", "Reduce damage from incoming attack by N"},
|
||||
{0x67, false, "Periodic Field", "Swap immunity to tech or physical attacks"},
|
||||
{0x68, false, "Unlimited Summoning", "Allow unlimited summoning"},
|
||||
{0x69, false, nullptr, nullptr},
|
||||
{0x6A, true, "MV Bonus", "Increase MV by N"},
|
||||
{0x6B, true, "Forward Damage", "Give N damage back to attacker during defense (?) (TODO)"},
|
||||
{0x6C, true, "Weak Spot / Influence", "Temporarily decrease AP by N"},
|
||||
{0x6D, true, "Damage Modifier 2", "Set attack damage / AP after action cards applied (step 2)"},
|
||||
{0x6E, true, "Weak Hit Block", "Block all attacks of N damage or less"},
|
||||
{0x6F, true, "AP Silence", "Temporarily decrease AP of opponent by N"},
|
||||
{0x70, true, "TP Silence", "Temporarily decrease TP of opponent by N"},
|
||||
{0x71, false, "A/T Swap", "Temporarily swap AP and TP"},
|
||||
{0x72, true, "Halfguard", "Halve damage from attacks that would inflict N or more damage"},
|
||||
{0x73, false, nullptr, nullptr},
|
||||
{0x74, true, "Rampage AP Loss", "Temporarily reduce AP by N"},
|
||||
{0x75, false, nullptr, nullptr},
|
||||
{0x76, false, "Reflect", "Generate reverse attack"},
|
||||
});
|
||||
|
||||
void Ep3CardStats::Stat::decode_code() {
|
||||
this->type = static_cast<Type>(this->code / 1000);
|
||||
int16_t value = this->code - (this->type * 1000);
|
||||
if (value != 999) {
|
||||
switch (this->type) {
|
||||
case Type::BLANK:
|
||||
this->stat = 0;
|
||||
break;
|
||||
case Type::STAT:
|
||||
case Type::PLUS_STAT:
|
||||
case Type::EQUALS_STAT:
|
||||
this->stat = value;
|
||||
break;
|
||||
case Type::MINUS_STAT:
|
||||
this->stat = -value;
|
||||
break;
|
||||
default:
|
||||
throw runtime_error("invalid card stat type");
|
||||
}
|
||||
} else {
|
||||
this->stat = 0;
|
||||
this->type = static_cast<Type>(this->type + 4);
|
||||
}
|
||||
}
|
||||
|
||||
string Ep3CardStats::Stat::str() const {
|
||||
switch (this->type) {
|
||||
case Type::BLANK:
|
||||
return "";
|
||||
case Type::STAT:
|
||||
return string_printf("%hhd", this->stat);
|
||||
case Type::PLUS_STAT:
|
||||
return string_printf("+%hhd", this->stat);
|
||||
case Type::MINUS_STAT:
|
||||
return string_printf("-%d", -this->stat);
|
||||
case Type::EQUALS_STAT:
|
||||
return string_printf("=%hhd", this->stat);
|
||||
case Type::UNKNOWN:
|
||||
return "?";
|
||||
case Type::PLUS_UNKNOWN:
|
||||
return "+?";
|
||||
case Type::MINUS_UNKNOWN:
|
||||
return "-?";
|
||||
case Type::EQUALS_UNKNOWN:
|
||||
return "=?";
|
||||
default:
|
||||
return string_printf("[%02hhX %02hhX]", this->type, this->stat);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Ep3CardStats::Effect::is_empty() const {
|
||||
return (this->command == 0 &&
|
||||
this->expr.is_filled_with(0) &&
|
||||
this->when == 0 &&
|
||||
this->arg1.is_filled_with(0) &&
|
||||
this->arg2.is_filled_with(0) &&
|
||||
this->arg3.is_filled_with(0) &&
|
||||
this->unknown_a3.is_filled_with(0));
|
||||
}
|
||||
|
||||
string Ep3CardStats::Effect::str_for_arg(const std::string& arg) {
|
||||
if (arg.empty()) {
|
||||
return arg;
|
||||
}
|
||||
if (arg.size() != 3) {
|
||||
return arg + "/(invalid)";
|
||||
}
|
||||
size_t value;
|
||||
try {
|
||||
value = stoul(arg.c_str() + 1, nullptr, 10);
|
||||
} catch (const invalid_argument&) {
|
||||
return arg + "/(invalid)";
|
||||
}
|
||||
|
||||
switch (arg[0]) {
|
||||
case 'a':
|
||||
return arg + "/(unknown)";
|
||||
case 'C':
|
||||
case 'c':
|
||||
return string_printf("%s/Req. linked item (%zu=>%zu)", arg.c_str(), value / 10, value % 10);
|
||||
case 'd':
|
||||
return string_printf("%s/Req. die roll in [%zu, %zu]", arg.c_str(), value / 10, value % 10);
|
||||
case 'e':
|
||||
return arg + "/While equipped";
|
||||
case 'h':
|
||||
return string_printf("%s/Req. HP >= %zu", arg.c_str(), value);
|
||||
case 'i':
|
||||
return string_printf("%s/Req. HP <= %zu", arg.c_str(), value);
|
||||
case 'n':
|
||||
try {
|
||||
return string_printf("%s/Req. condition: %s", arg.c_str(), description_for_n_condition.at(value));
|
||||
} catch (const out_of_range&) {
|
||||
return arg + "/(unknown)";
|
||||
}
|
||||
case 'o':
|
||||
return arg + "/Req. prev effect conditions passed";
|
||||
case 'p':
|
||||
try {
|
||||
return string_printf("%s/Target: %s", arg.c_str(), description_for_p_target.at(value));
|
||||
} catch (const out_of_range&) {
|
||||
return arg + "/(unknown)";
|
||||
}
|
||||
case 'r':
|
||||
return string_printf("%s/Req. random with %zu%% chance", arg.c_str(), value == 0 ? 100 : value);
|
||||
case 's':
|
||||
return string_printf("%s/Req. cost in [%zu, %zu]", arg.c_str(), value / 10, value % 10);
|
||||
case 't':
|
||||
return string_printf("%s/Turns: %zu", arg.c_str(), value);
|
||||
default:
|
||||
return arg + "/(unknown)";
|
||||
}
|
||||
}
|
||||
|
||||
string Ep3CardStats::Effect::str() const {
|
||||
string cmd_str = string_printf("%02hhX", this->command);
|
||||
try {
|
||||
const char* name = name_for_effect_command.at(this->command).name;
|
||||
if (name) {
|
||||
cmd_str += ':';
|
||||
cmd_str += name;
|
||||
}
|
||||
} catch (const out_of_range&) { }
|
||||
|
||||
string when_str = string_printf("%02hhX", this->when);
|
||||
try {
|
||||
const char* name = description_for_when.at(this->when);
|
||||
if (name) {
|
||||
when_str += ':';
|
||||
when_str += name;
|
||||
}
|
||||
} catch (const out_of_range&) { }
|
||||
|
||||
string expr_str = this->expr;
|
||||
if (!expr_str.empty()) {
|
||||
expr_str = ", expr=" + expr_str;
|
||||
}
|
||||
|
||||
string arg1str = this->str_for_arg(this->arg1);
|
||||
string arg2str = this->str_for_arg(this->arg2);
|
||||
string arg3str = this->str_for_arg(this->arg3);
|
||||
string a3str = format_data_string(this->unknown_a3.data(), sizeof(this->unknown_a3));
|
||||
return string_printf("(cmd=%s%s, when=%s, arg1=%s, arg2=%s, arg3=%s, a3=%s)",
|
||||
cmd_str.c_str(), expr_str.c_str(), when_str.c_str(), arg1str.data(),
|
||||
arg2str.data(), arg3str.data(), a3str.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Ep3CardStats::decode_range() {
|
||||
// If the cell representing the FC is nonzero, the card has a range from a
|
||||
// list of constants. Otherwise, its range is already defined in the range
|
||||
// array and should be left alone.
|
||||
uint8_t index = (this->range[4] >> 8) & 0xF;
|
||||
if (index != 0) {
|
||||
this->range.clear(0);
|
||||
switch (index) {
|
||||
case 1: // Single cell in front of FC
|
||||
this->range[3] = 0x00000100;
|
||||
break;
|
||||
case 2: // Cell in front of FC and the front-left and front-right (Slash)
|
||||
this->range[3] = 0x00001110;
|
||||
break;
|
||||
case 3: // 3 cells in a line in front of FC
|
||||
this->range[1] = 0x00000100;
|
||||
this->range[2] = 0x00000100;
|
||||
this->range[3] = 0x00000100;
|
||||
break;
|
||||
case 4: // All 8 cells around FC
|
||||
this->range[3] = 0x00001110;
|
||||
this->range[4] = 0x00001010;
|
||||
this->range[5] = 0x00001110;
|
||||
break;
|
||||
case 5: // 2 cells in a line in front of FC
|
||||
this->range[2] = 0x00000100;
|
||||
this->range[3] = 0x00000100;
|
||||
break;
|
||||
case 6: // Entire field (renders as "A")
|
||||
for (size_t x = 0; x < 6; x++) {
|
||||
this->range[x] = 0x000FFFFF;
|
||||
}
|
||||
break;
|
||||
case 7: // Superposition of 4 and 5 (unused)
|
||||
this->range[2] = 0x00000100;
|
||||
this->range[3] = 0x00001110;
|
||||
this->range[4] = 0x00001010;
|
||||
this->range[5] = 0x00001110;
|
||||
break;
|
||||
case 8: // All 8 cells around FC and FC's cell
|
||||
this->range[3] = 0x00001110;
|
||||
this->range[4] = 0x00001110;
|
||||
this->range[5] = 0x00001110;
|
||||
break;
|
||||
case 9: // No cells
|
||||
break;
|
||||
// The table in the DOL file only appears to contain 9 entries; there are
|
||||
// some pointers immediately after. So probably if a card specified A-F,
|
||||
// its range would be filled in with garbage in the original game.
|
||||
default:
|
||||
throw runtime_error("invalid fixed range index");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string name_for_rarity(uint8_t rarity) {
|
||||
static const vector<const char*> names({
|
||||
"N1",
|
||||
"R1",
|
||||
"S",
|
||||
"E",
|
||||
"N2",
|
||||
"N3",
|
||||
"N4",
|
||||
"R2",
|
||||
"R3",
|
||||
"R4",
|
||||
"SS",
|
||||
"D1",
|
||||
"D2",
|
||||
"INVIS",
|
||||
});
|
||||
try {
|
||||
return names.at(rarity - 1);
|
||||
} catch (const out_of_range&) {
|
||||
return string_printf("(%02hhX)", rarity);
|
||||
}
|
||||
}
|
||||
|
||||
string name_for_target_mode(uint8_t target_mode) {
|
||||
static const vector<const char*> names({
|
||||
"NONE",
|
||||
"SINGLE",
|
||||
"MULTI",
|
||||
"SELF",
|
||||
"TEAM",
|
||||
"ALL",
|
||||
"MULTI-ALLY",
|
||||
"ALL-ALLY",
|
||||
"ALL-ATTACK",
|
||||
"OWN-FCS",
|
||||
});
|
||||
try {
|
||||
return names.at(target_mode);
|
||||
} catch (const out_of_range&) {
|
||||
return string_printf("(%02hhX)", target_mode);
|
||||
}
|
||||
}
|
||||
|
||||
string string_for_colors(const parray<uint8_t, 8>& colors) {
|
||||
string ret;
|
||||
for (size_t x = 0; x < 8; x++) {
|
||||
if (colors[x]) {
|
||||
ret += '0' + colors[x];
|
||||
}
|
||||
}
|
||||
if (ret.empty()) {
|
||||
return "none";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
string string_for_assist_turns(uint8_t turns) {
|
||||
if (turns == 90) {
|
||||
return "ONCE";
|
||||
} else if (turns == 99) {
|
||||
return "FOREVER";
|
||||
} else {
|
||||
return string_printf("%hhu", turns);
|
||||
}
|
||||
}
|
||||
|
||||
string string_for_range(const parray<be_uint32_t, 6>& range) {
|
||||
string ret;
|
||||
for (size_t x = 0; x < 6; x++) {
|
||||
ret += string_printf("%05" PRIX32 "/", range[x].load());
|
||||
}
|
||||
while (starts_with(ret, "00000/")) {
|
||||
ret = ret.substr(6);
|
||||
}
|
||||
if (!ret.empty()) {
|
||||
ret.resize(ret.size() - 1);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
string Ep3CardStats::str() const {
|
||||
string type_str;
|
||||
try {
|
||||
type_str = name_for_card_type.at(this->type);
|
||||
} catch (const out_of_range&) {
|
||||
type_str = string_printf("%02hhX", this->type);
|
||||
}
|
||||
string rarity_str = name_for_rarity(this->rarity);
|
||||
string target_mode_str = name_for_target_mode(this->target_mode);
|
||||
string range_str = string_for_range(this->range);
|
||||
string assist_turns_str = string_for_assist_turns(this->assist_turns);
|
||||
string hp_str = this->hp.str();
|
||||
string ap_str = this->ap.str();
|
||||
string tp_str = this->tp.str();
|
||||
string mv_str = this->mv.str();
|
||||
string left_str = string_for_colors(this->left_colors);
|
||||
string right_str = string_for_colors(this->right_colors);
|
||||
string top_str = string_for_colors(this->top_colors);
|
||||
string effects_str;
|
||||
for (size_t x = 0; x < 3; x++) {
|
||||
if (this->effects[x].is_empty()) {
|
||||
continue;
|
||||
}
|
||||
if (!effects_str.empty()) {
|
||||
effects_str += ", ";
|
||||
}
|
||||
effects_str += this->effects[x].str();
|
||||
}
|
||||
return string_printf(
|
||||
"[Card: %04" PRIX32 " name=%s type=%s-%02hhX rare=%s cost=%hhX+%hhX "
|
||||
"target=%s range=%s assist_turns=%s cannot_move=%s cannot_attack=%s "
|
||||
"hidden=%s hp=%s ap=%s tp=%s mv=%s left=%s right=%s top=%s a2=%08" PRIX32 " "
|
||||
"assist_effect=[%hu, %hu] a3=[%hu, %hu] has_effects=%s effects=[%s]]",
|
||||
this->card_id.load(),
|
||||
this->name.data(),
|
||||
type_str.c_str(),
|
||||
this->subtype,
|
||||
rarity_str.c_str(),
|
||||
this->self_cost,
|
||||
this->ally_cost,
|
||||
target_mode_str.c_str(),
|
||||
range_str.c_str(),
|
||||
assist_turns_str.c_str(),
|
||||
this->cannot_move ? "true" : "false",
|
||||
this->cannot_attack ? "true" : "false",
|
||||
this->hide_in_deck_edit ? "true" : "false",
|
||||
hp_str.c_str(),
|
||||
ap_str.c_str(),
|
||||
tp_str.c_str(),
|
||||
mv_str.c_str(),
|
||||
left_str.c_str(),
|
||||
right_str.c_str(),
|
||||
top_str.c_str(),
|
||||
this->unknown_a2.load(),
|
||||
this->assist_effect[0].load(),
|
||||
this->assist_effect[1].load(),
|
||||
this->unknown_a3[0].load(),
|
||||
this->unknown_a3[1].load(),
|
||||
this->has_effects ? "true" : "false",
|
||||
effects_str.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Ep3DataIndex::Ep3DataIndex(const string& directory) {
|
||||
static constexpr bool debug_enabled = false;
|
||||
|
||||
unordered_map<uint32_t, vector<string>> card_tags;
|
||||
if (debug_enabled) {
|
||||
unordered_map<uint32_t, string> card_text;
|
||||
try {
|
||||
string data = prs_decompress(load_file(directory + "/cardtext.mnr"));
|
||||
StringReader r(data);
|
||||
|
||||
while (!r.eof()) {
|
||||
uint32_t card_id = stoul(r.get_cstr());
|
||||
|
||||
// Most cards have multiple pages, but we only care about the first page
|
||||
// (for now)
|
||||
string text = r.get_cstr();
|
||||
|
||||
// Preprocess text: first, delete all color markers
|
||||
size_t offset = text.find("\tC");
|
||||
while (offset != string::npos) {
|
||||
text = text.substr(0, offset) + text.substr(offset + 3);
|
||||
offset = text.find("\tC");
|
||||
}
|
||||
// Preprocess text: delete all initial lines that don't start with \t
|
||||
offset = text.find('\t');
|
||||
if (offset == string::npos) {
|
||||
text.clear();
|
||||
} else {
|
||||
text = text.substr(offset);
|
||||
}
|
||||
// Preprocess text: merge lines that don't begin with \t
|
||||
for (offset = 0; offset < text.size(); offset++) {
|
||||
if (text[offset] == '\n' && text[offset + 1] != '\t') {
|
||||
text = text.substr(0, offset) + text.substr(offset + 1);
|
||||
offset--;
|
||||
}
|
||||
}
|
||||
|
||||
// Split text into tags
|
||||
vector<string> tags;
|
||||
auto lines = split(text, '\n');
|
||||
for (const auto& line : lines) {
|
||||
if (line[0] == '\t' && line[1] == 'D') {
|
||||
tags.emplace_back("D: " + line.substr(2));
|
||||
} else if (line[0] == '\t' && line[1] == 'S') {
|
||||
tags.emplace_back("S: " + line.substr(2));
|
||||
}
|
||||
}
|
||||
|
||||
if (!card_text.emplace(card_id, move(text)).second) {
|
||||
throw runtime_error("duplicate card text id");
|
||||
}
|
||||
if (!card_tags.emplace(card_id, move(tags)).second) {
|
||||
throw logic_error("duplicate card tags id");
|
||||
}
|
||||
|
||||
r.go((r.where() + 0x3FF) & (~0x3FF));
|
||||
}
|
||||
|
||||
} catch (const exception& e) {
|
||||
log(WARNING, "Failed to load card text: %s", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
this->compressed_card_definitions = load_file(directory + "/cardupdate.mnr");
|
||||
string data = prs_decompress(this->compressed_card_definitions);
|
||||
// There's a footer after the card definitions, but we ignore it
|
||||
if (data.size() % sizeof(Ep3CardStats) != sizeof(Ep3CardStatsFooter)) {
|
||||
throw runtime_error(string_printf(
|
||||
"decompressed card update file size %zX is not aligned with card definition size %zX (%zX extra bytes)",
|
||||
data.size(), sizeof(Ep3CardStats), data.size() % sizeof(Ep3CardStats)));
|
||||
}
|
||||
const auto* stats = reinterpret_cast<const Ep3CardStats*>(data.data());
|
||||
size_t max_cards = data.size() / sizeof(Ep3CardStats);
|
||||
for (size_t x = 0; x < max_cards; x++) {
|
||||
// The last card entry has the build date and some other metadata (and
|
||||
// isn't a real card, obviously), so skip it. Seems like the card ID is
|
||||
// always a large number that won't fit in a uint16_t, so we use that to
|
||||
// determine if the entry is a real card or not.
|
||||
if (stats[x].card_id & 0xFFFF0000) {
|
||||
continue;
|
||||
}
|
||||
shared_ptr<CardEntry> entry(new CardEntry({stats[x], {}}));
|
||||
if (!this->card_definitions.emplace(entry->stats.card_id, entry).second) {
|
||||
throw runtime_error(string_printf(
|
||||
"duplicate card id: %08" PRIX32, entry->stats.card_id.load()));
|
||||
}
|
||||
|
||||
entry->stats.hp.decode_code();
|
||||
entry->stats.ap.decode_code();
|
||||
entry->stats.tp.decode_code();
|
||||
entry->stats.mv.decode_code();
|
||||
entry->stats.decode_range();
|
||||
|
||||
if (debug_enabled) {
|
||||
string card_str = entry->stats.str();
|
||||
try {
|
||||
string tags_str = join(card_tags.at(stats[x].card_id), ", ");
|
||||
fprintf(stderr, "%s tags: [%s]\n", card_str.c_str(), tags_str.c_str());
|
||||
} catch (const out_of_range&) {
|
||||
fprintf(stderr, "%s\n", card_str.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log(INFO, "Indexed %zu Episode 3 card definitions", this->card_definitions.size());
|
||||
} catch (const exception& e) {
|
||||
log(WARNING, "Failed to load Episode 3 card update: %s", e.what());
|
||||
}
|
||||
|
||||
for (const auto& filename : list_directory(directory)) {
|
||||
try {
|
||||
shared_ptr<MapEntry> entry;
|
||||
|
||||
if (ends_with(filename, ".mnmd")) {
|
||||
entry.reset(new MapEntry(load_object_file<Ep3Map>(directory + "/" + filename)));
|
||||
} else if (ends_with(filename, ".mnm")) {
|
||||
entry.reset(new MapEntry(load_file(directory + "/" + filename)));
|
||||
}
|
||||
|
||||
if (entry.get()) {
|
||||
if (!this->maps.emplace(entry->map.map_number, entry).second) {
|
||||
throw runtime_error("duplicate map number");
|
||||
}
|
||||
string name = entry->map.name;
|
||||
log(INFO, "Indexed Episode 3 map %s (%08" PRIX32 "; %s)",
|
||||
filename.c_str(), entry->map.map_number.load(), name.c_str());
|
||||
}
|
||||
|
||||
} catch (const exception& e) {
|
||||
log(WARNING, "Failed to index Episode 3 map %s: %s",
|
||||
filename.c_str(), e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ep3DataIndex::MapEntry::MapEntry(const Ep3Map& map) : map(map) { }
|
||||
|
||||
Ep3DataIndex::MapEntry::MapEntry(const string& compressed)
|
||||
: compressed_data(compressed) {
|
||||
string decompressed = prs_decompress(this->compressed_data);
|
||||
if (decompressed.size() != sizeof(Ep3Map)) {
|
||||
throw runtime_error(string_printf(
|
||||
"decompressed data size is incorrect (expected %zu bytes, read %zu bytes)",
|
||||
sizeof(Ep3Map), decompressed.size()));
|
||||
}
|
||||
this->map = *reinterpret_cast<const Ep3Map*>(decompressed.data());
|
||||
}
|
||||
|
||||
string Ep3DataIndex::MapEntry::compressed() const {
|
||||
if (this->compressed_data.empty()) {
|
||||
this->compressed_data = prs_compress(&this->map, sizeof(this->map));
|
||||
}
|
||||
return this->compressed_data;
|
||||
}
|
||||
|
||||
const string& Ep3DataIndex::get_compressed_card_definitions() const {
|
||||
if (this->compressed_card_definitions.empty()) {
|
||||
throw runtime_error("card definitions are not available");
|
||||
}
|
||||
return this->compressed_card_definitions;
|
||||
}
|
||||
|
||||
shared_ptr<const Ep3DataIndex::CardEntry> Ep3DataIndex::get_card_definition(
|
||||
uint32_t id) const {
|
||||
return this->card_definitions.at(id);
|
||||
}
|
||||
|
||||
const string& Ep3DataIndex::get_compressed_map_list() const {
|
||||
if (this->compressed_map_list.empty()) {
|
||||
// TODO: Write a version of prs_compress that takes iovecs (or something
|
||||
// similar) so we can eliminate all this string copying here.
|
||||
StringWriter entries_w;
|
||||
StringWriter strings_w;
|
||||
|
||||
for (const auto& map_it : this->maps) {
|
||||
Ep3MapList::Entry e;
|
||||
const auto& map = map_it.second->map;
|
||||
e.map_x = map.map_x;
|
||||
e.map_y = map.map_y;
|
||||
e.scene_data2 = map.scene_data2;
|
||||
e.map_number = map.map_number.load();
|
||||
e.width = map.width;
|
||||
e.height = map.height;
|
||||
e.map_tiles = map.map_tiles;
|
||||
e.modification_tiles = map.modification_tiles;
|
||||
|
||||
e.name_offset = strings_w.size();
|
||||
strings_w.write(map.name.data(), map.name.len());
|
||||
strings_w.put_u8(0);
|
||||
e.location_name_offset = strings_w.size();
|
||||
strings_w.write(map.location_name.data(), map.location_name.len());
|
||||
strings_w.put_u8(0);
|
||||
e.quest_name_offset = strings_w.size();
|
||||
strings_w.write(map.quest_name.data(), map.quest_name.len());
|
||||
strings_w.put_u8(0);
|
||||
e.description_offset = strings_w.size();
|
||||
strings_w.write(map.description.data(), map.description.len());
|
||||
strings_w.put_u8(0);
|
||||
|
||||
e.unknown_a2 = 0xFF000000;
|
||||
|
||||
entries_w.put(e);
|
||||
}
|
||||
|
||||
Ep3MapList header;
|
||||
header.num_maps = this->maps.size();
|
||||
header.unknown_a1 = 0;
|
||||
header.strings_offset = entries_w.size();
|
||||
header.total_size = sizeof(Ep3MapList) + entries_w.size() + strings_w.size();
|
||||
|
||||
StringWriter w;
|
||||
w.put(header);
|
||||
w.write(entries_w.str());
|
||||
w.write(strings_w.str());
|
||||
|
||||
StringWriter compressed_w;
|
||||
compressed_w.put_u32b(w.str().size());
|
||||
compressed_w.write(prs_compress(w.str()));
|
||||
this->compressed_map_list = move(compressed_w.str());
|
||||
log(INFO, "Generated Episode 3 compressed map list (%zu -> %zu bytes)",
|
||||
w.size(), this->compressed_map_list.size());
|
||||
}
|
||||
return this->compressed_map_list;
|
||||
}
|
||||
|
||||
shared_ptr<const Ep3DataIndex::MapEntry> Ep3DataIndex::get_map(uint32_t id) const {
|
||||
return this->maps.at(id);
|
||||
}
|
||||
-351
@@ -1,351 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <phosg/Encoding.hh>
|
||||
|
||||
#include "Text.hh"
|
||||
|
||||
|
||||
|
||||
// Note: Much of the structures and enums here are based on the card list file,
|
||||
// and comparing the card text with the data in the file. Some inferences may be
|
||||
// incorrect here, since Episode 3's card text is wrong in various places.
|
||||
|
||||
struct Ep3CardStats {
|
||||
enum Rarity : uint8_t {
|
||||
N1 = 0x01,
|
||||
R1 = 0x02,
|
||||
S = 0x03,
|
||||
E = 0x04,
|
||||
N2 = 0x05,
|
||||
N3 = 0x06,
|
||||
N4 = 0x07,
|
||||
R2 = 0x08,
|
||||
R3 = 0x09,
|
||||
R4 = 0x0A,
|
||||
SS = 0x0B,
|
||||
D1 = 0x0C,
|
||||
D2 = 0x0D,
|
||||
INVIS = 0x0E,
|
||||
};
|
||||
|
||||
enum Type : uint8_t {
|
||||
SC_HUNTERS = 0x00, // No subtypes
|
||||
SC_ARKZ = 0x01, // No subtypes
|
||||
ITEM = 0x02, // Subtype 01 = sword, 02 = gun, 03 = cane. TODO: there are many more subtypes than those 3
|
||||
CREATURE = 0x03, // No subtypes (TODO: Where are attributes stored then?)
|
||||
ACTION = 0x04, // TODO: What do the subtypes mean? Are they actually flags instead?
|
||||
ASSIST = 0x05, // No subtypes
|
||||
};
|
||||
|
||||
struct Stat {
|
||||
enum Type : uint8_t {
|
||||
BLANK = 0,
|
||||
STAT = 1,
|
||||
PLUS_STAT = 2,
|
||||
MINUS_STAT = 3,
|
||||
EQUALS_STAT = 4,
|
||||
UNKNOWN = 5,
|
||||
PLUS_UNKNOWN = 6,
|
||||
MINUS_UNKNOWN = 7,
|
||||
EQUALS_UNKNOWN = 8,
|
||||
};
|
||||
be_uint16_t code;
|
||||
Type type;
|
||||
int8_t stat;
|
||||
|
||||
void decode_code();
|
||||
std::string str() const;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Effect {
|
||||
uint8_t command;
|
||||
ptext<char, 0x0F> expr; // May be blank if the command doesn't use it
|
||||
uint8_t when;
|
||||
ptext<char, 4> arg1;
|
||||
ptext<char, 4> arg2;
|
||||
ptext<char, 4> arg3;
|
||||
parray<uint8_t, 3> unknown_a3;
|
||||
|
||||
bool is_empty() const;
|
||||
static std::string str_for_arg(const std::string& arg);
|
||||
std::string str() const;
|
||||
} __attribute__((packed));
|
||||
|
||||
be_uint32_t card_id;
|
||||
parray<uint8_t, 0x40> jp_name;
|
||||
int8_t type; // Type enum. If <0, then this is the end of the card list
|
||||
uint8_t self_cost; // ATK dice points required
|
||||
uint8_t ally_cost; // ATK points from allies required; PBs use this
|
||||
uint8_t unused_a0; // Always 0
|
||||
Stat hp;
|
||||
Stat ap;
|
||||
Stat tp;
|
||||
Stat mv;
|
||||
parray<uint8_t, 8> left_colors;
|
||||
parray<uint8_t, 8> right_colors;
|
||||
parray<uint8_t, 8> top_colors;
|
||||
parray<be_uint32_t, 6> range;
|
||||
be_uint32_t unused_a1; // Always 0
|
||||
// Target modes:
|
||||
// 00 = no targeting (used for defense cards, mags, shields, etc.)
|
||||
// 01 = single enemy
|
||||
// 02 = multiple enemies (with range)
|
||||
// 03 = self (assist)
|
||||
// 04 = team (assist)
|
||||
// 05 = everyone (assist)
|
||||
// 06 = multiple allies (with range); only used by Shifta
|
||||
// 07 = all allies including yourself; see Anti, Resta, Leilla
|
||||
// 08 = all (attack); see e.g. Last Judgment, Earthquake
|
||||
// 09 = your own FCs but not SCs; see Traitor
|
||||
uint8_t target_mode;
|
||||
uint8_t assist_turns; // 90 (dec) = once, 99 (dec) = forever
|
||||
uint8_t cannot_move; // 0 for SC and creature cards; 1 for everything else
|
||||
uint8_t cannot_attack; // 1 for shields, mags, defense actions, and assist cards
|
||||
uint8_t unused_a2; // Always 0
|
||||
uint8_t hide_in_deck_edit; // 0 = player can use this card (appears in deck edit)
|
||||
uint8_t subtype; // e.g. gun, sword, etc. (used for checking if SCs can use it)
|
||||
uint8_t rarity; // Rarity enum
|
||||
be_uint32_t unknown_a2;
|
||||
// These two fields seem to always contain the same value, and are always 0
|
||||
// for non-assist cards and nonzero for assists. Each assist card has a unique
|
||||
// value here and no effects, which makes it look like this is how assist
|
||||
// effects are implemented. There seems to be some 1k-modulation going on here
|
||||
// too; most cards are in the range 101-174 but a few have e.g. 1150, 2141. A
|
||||
// few pairs of cards have the same effect, which makes it look like some
|
||||
// other fields are also involved in determining their effects (see e.g. Skip
|
||||
// Draw / Skip Move, Dice Fever / Dice Fever +, Reverse Card / Rich +).
|
||||
parray<be_uint16_t, 2> assist_effect;
|
||||
parray<be_uint16_t, 2> unknown_a3;
|
||||
ptext<char, 0x14> name;
|
||||
ptext<char, 0x0B> jp_short_name;
|
||||
ptext<char, 0x07> short_name;
|
||||
be_uint16_t has_effects; // 1 if any of the following structs are not blank
|
||||
Effect effects[3];
|
||||
|
||||
void decode_range();
|
||||
std::string str() const;
|
||||
} __attribute__((packed)); // 0x128 bytes in total
|
||||
|
||||
struct Ep3CardStatsFooter {
|
||||
be_uint32_t num_cards1;
|
||||
be_uint32_t unknown_a1;
|
||||
be_uint32_t num_cards2;
|
||||
be_uint32_t unknown_a2[11];
|
||||
be_uint32_t unknown_offset_a3;
|
||||
be_uint32_t unknown_a4[3];
|
||||
be_uint32_t footer_offset;
|
||||
be_uint32_t unknown_a5[3];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Ep3Deck {
|
||||
ptext<char, 0x10> name;
|
||||
be_uint32_t client_id; // 0-3
|
||||
// List of card IDs. The card count is the number of nonzero entries here
|
||||
// before a zero entry (or 50 if no entries are nonzero). The first card ID is
|
||||
// the SC card, which the game implicitly subtracts from the limit - so a
|
||||
// valid deck should actually have 31 cards in it.
|
||||
parray<le_uint16_t, 50> card_ids;
|
||||
be_uint32_t unknown_a1;
|
||||
// Last modification time
|
||||
le_uint16_t year;
|
||||
uint8_t month;
|
||||
uint8_t day;
|
||||
uint8_t hour;
|
||||
uint8_t minute;
|
||||
uint8_t second;
|
||||
uint8_t unknown_a2;
|
||||
} __attribute__((packed)); // 0x84 bytes in total
|
||||
|
||||
struct Ep3Config {
|
||||
// Offsets in comments in this struct are relative to start of 61/98 command
|
||||
/* 0728 */ parray<uint8_t, 0x1434> unknown_a1;
|
||||
/* 1B5C */ parray<Ep3Deck, 25> decks;
|
||||
/* 2840 */ uint64_t unknown_a2;
|
||||
/* 2848 */ be_uint32_t offline_clv_exp; // CLvOff = this / 100
|
||||
/* 284C */ be_uint32_t online_clv_exp; // CLvOn = this / 100
|
||||
/* 2850 */ parray<uint8_t, 0x14C> unknown_a3;
|
||||
/* 299C */ ptext<char, 0x10> name;
|
||||
// Other records are probably somewhere in here - e.g. win/loss, play time, etc.
|
||||
/* 29AC */ parray<uint8_t, 0xCC> unknown_a4;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Ep3BattleRules {
|
||||
// When this structure is used in a map/quest definition, FF in any of these
|
||||
// fields means the user is allowed to override it. Any non-FF fields are
|
||||
// fixed for the map/quest and cannot be overridden.
|
||||
uint8_t overall_time_limit; // In increments of 5 minutes; 0 = unlimited
|
||||
uint8_t phase_time_limit; // In seconds; 0 = unlimited
|
||||
uint8_t allowed_cards; // 0 = any, 1 = N-rank only, 2 = N and R, 3 = N, R, and S
|
||||
uint8_t min_dice; // 0 = default (1)
|
||||
// 4
|
||||
uint8_t max_dice; // 0 = default (6)
|
||||
uint8_t disable_deck_shuffle; // 0 = shuffle on, 1 = off
|
||||
uint8_t disable_deck_loop; // 0 = loop on, 1 = off
|
||||
uint8_t char_hp;
|
||||
// 8
|
||||
uint8_t hp_type; // 0 = defeat player, 1 = defeat team, 2 = common hp
|
||||
uint8_t no_assist_cards; // 1 = assist cards disallowed
|
||||
uint8_t disable_dialogue; // 0 = dialogue on, 1 = dialogue off
|
||||
uint8_t dice_exchange_mode; // 0 = high attack, 1 = high defense, 2 = none
|
||||
// C
|
||||
uint8_t disable_dice_boost; // 0 = dice boost on, 1 = off
|
||||
parray<uint8_t, 3> unused;
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
|
||||
struct Ep3MapList {
|
||||
be_uint32_t num_maps;
|
||||
be_uint32_t unknown_a1; // Always 0?
|
||||
be_uint32_t strings_offset; // From after total_size field (add 0x10 to this value)
|
||||
be_uint32_t total_size; // Including header, entries, and strings
|
||||
|
||||
struct Entry { // Should be 0x220 bytes in total
|
||||
// These 3 fields probably include the location ID (scenery to load) and the
|
||||
// music ID
|
||||
be_uint16_t map_x;
|
||||
be_uint16_t map_y;
|
||||
be_uint16_t scene_data2;
|
||||
be_uint16_t map_number;
|
||||
// Text offsets are from the beginning of the strings block after all map
|
||||
// entries (that is, add strings_offset to them to get the string offset)
|
||||
be_uint32_t name_offset;
|
||||
be_uint32_t location_name_offset;
|
||||
be_uint32_t quest_name_offset;
|
||||
be_uint32_t description_offset;
|
||||
be_uint16_t width;
|
||||
be_uint16_t height;
|
||||
parray<uint8_t, 0x100> map_tiles;
|
||||
parray<uint8_t, 0x100> modification_tiles;
|
||||
be_uint32_t unknown_a2; // Seems to always be 0xFF000000
|
||||
} __attribute__((packed));
|
||||
|
||||
// Variable-length fields:
|
||||
// Entry entries[num_maps];
|
||||
// char strings[...EOF]; // Null-terminated strings, pointed to by offsets in Entry structs
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Ep3CompressedMapHeader { // .mnm file format
|
||||
le_uint32_t map_number;
|
||||
le_uint32_t compressed_data_size;
|
||||
// Compressed data immediately follows (which decompresses to an Ep3Map)
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Ep3Map { // .mnmd format
|
||||
/* 0000 */ be_uint32_t unknown_a1;
|
||||
/* 0004 */ be_uint32_t map_number;
|
||||
/* 0008 */ uint8_t width;
|
||||
/* 0009 */ uint8_t height;
|
||||
/* 000A */ uint8_t scene_data2; // TODO: What is this?
|
||||
// All alt_maps fields (including the floats) past num_alt_maps are filled in
|
||||
// with FF. For example, if num_alt_maps == 8, the last two fields in each
|
||||
// alt_maps array are filled with FF.
|
||||
/* 000B */ uint8_t num_alt_maps; // TODO: What are the alt maps for?
|
||||
// In the map_tiles array, the values are:
|
||||
// 00 = not a valid tile
|
||||
// 01 = valid tile unless punched out (later)
|
||||
// 02 = team A start (1v1)
|
||||
// 03, 04 = team A start (2v2)
|
||||
// 05 = ???
|
||||
// 06, 07 = team B start (2v2)
|
||||
// 08 = team B start (1v1)
|
||||
// Note that the game displays the map reversed vertically in the preview
|
||||
// window. For example, player 1 is on team A, which usually starts at the top
|
||||
// of the map as defined in this struct, or at the bottom as shown in the
|
||||
// preview window.
|
||||
/* 000C */ parray<uint8_t, 0x100> map_tiles;
|
||||
/* 010C */ parray<uint8_t, 0x0C> unknown_a2;
|
||||
/* 0118 */ parray<uint8_t, 0x100> alt_maps1[0x0A];
|
||||
/* 0B18 */ parray<uint8_t, 0x100> alt_maps2[0x0A];
|
||||
/* 1518 */ parray<be_float, 0x12> alt_maps_unknown_a3[0x0A];
|
||||
/* 17E8 */ parray<be_float, 0x12> alt_maps_unknown_a4[0x0A];
|
||||
/* 1AB8 */ parray<be_float, 0x6C> unknown_a5;
|
||||
// In the modification_tiles array, the values are:
|
||||
// 10 = blocked (as if the corresponding map_tiles value was 00)
|
||||
// 20 = blocked (maybe one of 10 or 20 are passable by Aerial characters though)
|
||||
// 30, 31 = teleporters (green, red)
|
||||
// 40-44 = ???? (used in 244, 2E4, 2F9)
|
||||
// 50 = appears as improperly-z-buffered teal cube in preview
|
||||
// TODO: There may be more values that are valid here.
|
||||
/* 1C68 */ parray<uint8_t, 0x100> modification_tiles;
|
||||
/* 1D68 */ parray<uint8_t, 0x74> unknown_a6;
|
||||
/* 1DDC */ Ep3BattleRules default_rules;
|
||||
/* 1DEC */ parray<uint8_t, 4> unknown_a7;
|
||||
/* 1DF0 */ ptext<char, 0x14> name;
|
||||
/* 1E04 */ ptext<char, 0x14> location_name;
|
||||
/* 1E18 */ ptext<char, 0x3C> quest_name; // == location_name if not a quest
|
||||
/* 1E54 */ ptext<char, 0x190> description;
|
||||
/* 1FE4 */ be_uint16_t map_x;
|
||||
/* 1FE6 */ be_uint16_t map_y;
|
||||
struct NPCDeck {
|
||||
ptext<char, 0x18> name;
|
||||
parray<be_uint16_t, 0x20> card_ids; // Last one appears to always be FFFF
|
||||
} __attribute__((packed));
|
||||
/* 1FE8 */ NPCDeck npc_decks[3]; // Unused if name[0] == 0
|
||||
struct NPCCharacter {
|
||||
parray<be_uint16_t, 2> unknown_a1;
|
||||
parray<uint8_t, 4> unknown_a2;
|
||||
ptext<char, 0x10> name;
|
||||
parray<be_uint16_t, 0x7E> unknown_a3;
|
||||
} __attribute__((packed));
|
||||
/* 20F0 */ NPCCharacter npc_chars[3]; // Unused if name[0] == 0
|
||||
/* 242C */ parray<uint8_t, 0x14> unknown_a8; // Always FF?
|
||||
/* 2440 */ ptext<char, 0x190> before_message;
|
||||
/* 25D0 */ ptext<char, 0x190> after_message;
|
||||
/* 2760 */ ptext<char, 0x190> dispatch_message; // Usually "You can only dispatch <character>" or blank
|
||||
struct DialogueSet {
|
||||
be_uint16_t unknown_a1;
|
||||
be_uint16_t unknown_a2; // Always 0x0064 if valid, 0xFFFF if unused?
|
||||
ptext<char, 0x40> strings[4];
|
||||
} __attribute__((packed)); // Total size: 0x104 bytes
|
||||
/* 28F0 */ DialogueSet dialogue_sets[3][0x10]; // Up to 0x10 per valid NPC
|
||||
/* 59B0 */ be_uint16_t reward_card_id; // TODO: This could be an array. The only examples I've seen have only one here
|
||||
/* 59B2 */ parray<be_uint16_t, 0x33> unknown_a9;
|
||||
/* 5A18 */
|
||||
} __attribute__((packed));
|
||||
|
||||
class Ep3DataIndex {
|
||||
public:
|
||||
explicit Ep3DataIndex(const std::string& directory);
|
||||
|
||||
struct CardEntry {
|
||||
Ep3CardStats stats;
|
||||
std::vector<std::string> text;
|
||||
};
|
||||
|
||||
class MapEntry {
|
||||
public:
|
||||
Ep3Map map;
|
||||
|
||||
MapEntry(const Ep3Map& map);
|
||||
MapEntry(const std::string& compressed_data);
|
||||
|
||||
std::string compressed() const;
|
||||
|
||||
private:
|
||||
mutable std::string compressed_data;
|
||||
};
|
||||
|
||||
const std::string& get_compressed_card_definitions() const;
|
||||
std::shared_ptr<const CardEntry> get_card_definition(uint32_t id) const;
|
||||
|
||||
const std::string& get_compressed_map_list() const;
|
||||
std::shared_ptr<const MapEntry> get_map(uint32_t id) const;
|
||||
|
||||
private:
|
||||
std::string compressed_card_definitions;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<CardEntry>> card_definitions;
|
||||
|
||||
// The compressed map list is generated on demand from the maps map below.
|
||||
// It's marked mutable because the logical consistency of the Ep3DataIndex
|
||||
// object is not violated from the caller's perspective even if we don't
|
||||
// generate the compressed map list at load time.
|
||||
mutable std::string compressed_map_list;
|
||||
std::map<uint32_t, std::shared_ptr<MapEntry>> maps;
|
||||
};
|
||||
@@ -0,0 +1,280 @@
|
||||
#include "AssistServer.hh"
|
||||
|
||||
#include "Server.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
// Note: This order matches the order that the cards are defined in the original
|
||||
// code. This is relevant for consistency of results when choosing a random card
|
||||
// (for God Whim).
|
||||
const vector<uint16_t> ALL_ASSIST_CARD_IDS = {
|
||||
0x0018, 0x0019, 0x001A, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA,
|
||||
0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF, 0x0100, 0x0101, 0x0102, 0x0103,
|
||||
0x0104, 0x0105, 0x0106, 0x0107, 0x0108, 0x0109, 0x010A, 0x010B, 0x010C,
|
||||
0x010D, 0x010E, 0x010F, 0x0121, 0x0125, 0x0126, 0x0127, 0x0128, 0x0129,
|
||||
0x012A, 0x012B, 0x012C, 0x012D, 0x012E, 0x012F, 0x0130, 0x0131, 0x0132,
|
||||
0x0133, 0x0134, 0x0135, 0x0136, 0x0137, 0x0138, 0x0139, 0x013A, 0x013B,
|
||||
0x013C, 0x013D, 0x013E, 0x013F, 0x0140, 0x0141, 0x0142, 0x0143, 0x0144,
|
||||
0x0145, 0x0146, 0x0148, 0x014A, 0x014B, 0x014C, 0x014D, 0x014E, 0x023F,
|
||||
0x0240, 0x0241, 0x0242};
|
||||
|
||||
AssistEffect assist_effect_number_for_card_id(uint16_t card_id) {
|
||||
static const unordered_map<uint16_t, AssistEffect> card_id_to_effect({
|
||||
{0x00F5, /* 0x0001 */ AssistEffect::DICE_HALF},
|
||||
{0x00F6, /* 0x0002 */ AssistEffect::DICE_PLUS_1},
|
||||
{0x00F7, /* 0x0003 */ AssistEffect::DICE_FEVER},
|
||||
{0x00F8, /* 0x0004 */ AssistEffect::CARD_RETURN},
|
||||
{0x00F9, /* 0x0005 */ AssistEffect::LAND_PRICE},
|
||||
{0x00FA, /* 0x0006 */ AssistEffect::POWERLESS_RAIN},
|
||||
{0x00FB, /* 0x0007 */ AssistEffect::BRAVE_WIND},
|
||||
{0x00FC, /* 0x0008 */ AssistEffect::SILENT_COLOSSEUM},
|
||||
{0x00FD, /* 0x0009 */ AssistEffect::RESISTANCE},
|
||||
{0x00FE, /* 0x000A */ AssistEffect::INDEPENDENT},
|
||||
{0x00FF, /* 0x000B */ AssistEffect::ASSISTLESS},
|
||||
{0x0100, /* 0x000C */ AssistEffect::ATK_DICE_2},
|
||||
{0x0101, /* 0x000D */ AssistEffect::DEFLATION},
|
||||
{0x0102, /* 0x000E */ AssistEffect::INFLATION},
|
||||
{0x0103, /* 0x000F */ AssistEffect::EXCHANGE},
|
||||
{0x0104, /* 0x0010 */ AssistEffect::INFLUENCE},
|
||||
{0x0105, /* 0x0011 */ AssistEffect::SKIP_SET},
|
||||
{0x0106, /* 0x0012 */ AssistEffect::SKIP_MOVE},
|
||||
{0x0121, /* 0x0013 */ AssistEffect::SKIP_ACT},
|
||||
{0x0137, /* 0x0014 */ AssistEffect::SKIP_DRAW},
|
||||
{0x0107, /* 0x0015 */ AssistEffect::FLY},
|
||||
{0x0108, /* 0x0016 */ AssistEffect::NECROMANCER},
|
||||
{0x0109, /* 0x0017 */ AssistEffect::PERMISSION},
|
||||
{0x010A, /* 0x0018 */ AssistEffect::SHUFFLE_ALL},
|
||||
{0x010B, /* 0x0019 */ AssistEffect::LEGACY},
|
||||
{0x010C, /* 0x001A */ AssistEffect::ASSIST_REVERSE},
|
||||
{0x010D, /* 0x001B */ AssistEffect::STAMINA},
|
||||
{0x010E, /* 0x001C */ AssistEffect::AP_ABSORPTION},
|
||||
{0x010F, /* 0x001D */ AssistEffect::HEAVY_FOG},
|
||||
{0x0125, /* 0x001E */ AssistEffect::TRASH_1},
|
||||
{0x0126, /* 0x001F */ AssistEffect::EMPTY_HAND},
|
||||
{0x0127, /* 0x0020 */ AssistEffect::HITMAN},
|
||||
{0x0128, /* 0x0021 */ AssistEffect::ASSIST_TRASH},
|
||||
{0x0129, /* 0x0022 */ AssistEffect::SHUFFLE_GROUP},
|
||||
{0x012A, /* 0x0023 */ AssistEffect::ASSIST_VANISH},
|
||||
{0x012B, /* 0x0024 */ AssistEffect::CHARITY},
|
||||
{0x012C, /* 0x0025 */ AssistEffect::INHERITANCE},
|
||||
{0x012D, /* 0x0026 */ AssistEffect::FIX},
|
||||
{0x012E, /* 0x0027 */ AssistEffect::MUSCULAR},
|
||||
{0x012F, /* 0x0028 */ AssistEffect::CHANGE_BODY},
|
||||
{0x0130, /* 0x0029 */ AssistEffect::GOD_WHIM},
|
||||
{0x0131, /* 0x002A */ AssistEffect::GOLD_RUSH},
|
||||
{0x0132, /* 0x002B */ AssistEffect::ASSIST_RETURN},
|
||||
{0x0133, /* 0x002C */ AssistEffect::REQUIEM},
|
||||
{0x0134, /* 0x002D */ AssistEffect::RANSOM},
|
||||
{0x0135, /* 0x002E */ AssistEffect::SIMPLE},
|
||||
{0x0136, /* 0x002F */ AssistEffect::SLOW_TIME},
|
||||
{0x023F, /* 0x0030 */ AssistEffect::QUICK_TIME},
|
||||
{0x0138, /* 0x0031 */ AssistEffect::TERRITORY},
|
||||
{0x0139, /* 0x0032 */ AssistEffect::OLD_TYPE},
|
||||
{0x013A, /* 0x0033 */ AssistEffect::FLATLAND},
|
||||
{0x013B, /* 0x0034 */ AssistEffect::IMMORTALITY},
|
||||
{0x013C, /* 0x0035 */ AssistEffect::SNAIL_PACE},
|
||||
{0x013D, /* 0x0036 */ AssistEffect::TECH_FIELD},
|
||||
{0x013E, /* 0x0037 */ AssistEffect::FOREST_RAIN},
|
||||
{0x013F, /* 0x0038 */ AssistEffect::CAVE_WIND},
|
||||
{0x0140, /* 0x0039 */ AssistEffect::MINE_BRIGHTNESS},
|
||||
{0x0141, /* 0x003A */ AssistEffect::RUIN_DARKNESS},
|
||||
{0x0142, /* 0x003B */ AssistEffect::SABER_DANCE},
|
||||
{0x0143, /* 0x003C */ AssistEffect::BULLET_STORM},
|
||||
{0x0144, /* 0x003D */ AssistEffect::CANE_PALACE},
|
||||
{0x0145, /* 0x003E */ AssistEffect::GIANT_GARDEN},
|
||||
{0x0146, /* 0x003F */ AssistEffect::MARCH_OF_THE_MEEK},
|
||||
{0x0148, /* 0x0040 */ AssistEffect::SUPPORT},
|
||||
{0x014A, /* 0x0041 */ AssistEffect::RICH},
|
||||
{0x014B, /* 0x0042 */ AssistEffect::REVERSE_CARD},
|
||||
{0x014C, /* 0x0043 */ AssistEffect::VENGEANCE},
|
||||
{0x014D, /* 0x0044 */ AssistEffect::SQUEEZE},
|
||||
{0x014E, /* 0x0045 */ AssistEffect::HOMESICK},
|
||||
{0x0240, /* 0x0046 */ AssistEffect::BOMB},
|
||||
{0x0241, /* 0x0047 */ AssistEffect::SKIP_TURN},
|
||||
{0x0242, /* 0x0048 */ AssistEffect::BATTLE_ROYALE},
|
||||
{0x0018, /* 0x0049 */ AssistEffect::DICE_FEVER_PLUS},
|
||||
{0x0019, /* 0x004A */ AssistEffect::RICH_PLUS},
|
||||
{0x001A, /* 0x004B */ AssistEffect::CHARITY_PLUS},
|
||||
});
|
||||
try {
|
||||
return card_id_to_effect.at(card_id);
|
||||
} catch (const out_of_range&) {
|
||||
return AssistEffect::NONE;
|
||||
}
|
||||
}
|
||||
|
||||
AssistServer::AssistServer(shared_ptr<Server> server)
|
||||
: w_server(server),
|
||||
assist_effects(AssistEffect::NONE),
|
||||
num_assist_cards_set(0),
|
||||
client_ids_with_assists(0xFF),
|
||||
active_assist_effects(AssistEffect::NONE),
|
||||
num_active_assists(0) {}
|
||||
|
||||
shared_ptr<Server> AssistServer::server() {
|
||||
auto s = this->w_server.lock();
|
||||
if (!s) {
|
||||
throw runtime_error("server is deleted");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
shared_ptr<const Server> AssistServer::server() const {
|
||||
auto s = this->w_server.lock();
|
||||
if (!s) {
|
||||
throw runtime_error("server is deleted");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
uint16_t AssistServer::card_id_for_card_ref(uint16_t card_ref) const {
|
||||
return this->server()->card_id_for_card_ref(card_ref);
|
||||
}
|
||||
|
||||
shared_ptr<const CardIndex::CardEntry> AssistServer::definition_for_card_id(
|
||||
uint16_t card_id) const {
|
||||
return this->server()->definition_for_card_id(card_id);
|
||||
}
|
||||
|
||||
uint32_t AssistServer::compute_num_assist_effects_for_client(uint16_t client_id) {
|
||||
this->populate_effects();
|
||||
this->num_assist_cards_set = 0;
|
||||
if (this->should_block_assist_effects_for_client(client_id)) {
|
||||
this->num_active_assists = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (size_t z = 0; z < 4; z++) {
|
||||
auto ce = this->assist_card_defs[z];
|
||||
auto hes = this->hand_and_equip_states[z];
|
||||
if (ce && (!hes || (hes->assist_delay_turns < 1))) {
|
||||
bool affected = false;
|
||||
if (ce->def.target_mode == TargetMode::TEAM) {
|
||||
auto this_deck_entry = this->deck_entries[client_id];
|
||||
auto other_deck_entry = this->deck_entries[z];
|
||||
if (this_deck_entry && other_deck_entry &&
|
||||
(this_deck_entry->team_id == other_deck_entry->team_id)) {
|
||||
affected = true;
|
||||
}
|
||||
} else if ((ce->def.target_mode == TargetMode::SELF) && (z == client_id)) {
|
||||
affected = true;
|
||||
} else if (ce->def.target_mode == TargetMode::EVERYONE) {
|
||||
affected = true;
|
||||
}
|
||||
if (affected) {
|
||||
this->client_ids_with_assists[this->num_assist_cards_set++] = z;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->recompute_effects();
|
||||
return this->num_assist_cards_set;
|
||||
}
|
||||
|
||||
uint32_t AssistServer::compute_num_assist_effects_for_team(uint32_t team_id) {
|
||||
this->num_assist_cards_set = 0;
|
||||
for (size_t z = 0; z < 4; z++) {
|
||||
auto ce = this->assist_card_defs[z];
|
||||
auto hes = this->hand_and_equip_states[z];
|
||||
if (ce && (!hes || (hes->assist_delay_turns < 1))) {
|
||||
bool affected = false;
|
||||
if (ce->def.target_mode == TargetMode::TEAM) {
|
||||
if (this->deck_entries[z] && (this->deck_entries[z]->team_id == team_id)) {
|
||||
affected = true;
|
||||
}
|
||||
} else if (ce->def.target_mode == TargetMode::EVERYONE) {
|
||||
affected = true;
|
||||
}
|
||||
if (affected) {
|
||||
this->client_ids_with_assists[this->num_assist_cards_set++] = z;
|
||||
}
|
||||
}
|
||||
}
|
||||
this->recompute_effects();
|
||||
return this->num_assist_cards_set;
|
||||
}
|
||||
|
||||
bool AssistServer::should_block_assist_effects_for_client(uint16_t client_id) const {
|
||||
for (size_t z = 0; z < 4; z++) {
|
||||
auto eff = this->assist_effects[z];
|
||||
auto ce = this->assist_card_defs[z];
|
||||
if (((eff == AssistEffect::RESISTANCE) || (eff == AssistEffect::INDEPENDENT)) && ce) {
|
||||
if (ce->def.target_mode == TargetMode::TEAM) {
|
||||
if (this->deck_entries[client_id] && this->deck_entries[z] &&
|
||||
(this->deck_entries[client_id]->team_id == this->deck_entries[z]->team_id)) {
|
||||
return true;
|
||||
}
|
||||
} else if ((ce->def.target_mode == TargetMode::SELF) && (client_id == z)) {
|
||||
return true;
|
||||
} else if (ce->def.target_mode == TargetMode::EVERYONE) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
AssistEffect AssistServer::get_active_assist_by_index(size_t index) const {
|
||||
if (index < this->num_active_assists) {
|
||||
return this->active_assist_effects[index];
|
||||
}
|
||||
return AssistEffect::NONE;
|
||||
}
|
||||
|
||||
void AssistServer::populate_effects() {
|
||||
for (size_t z = 0; z < 4; z++) {
|
||||
this->assist_card_defs[z] = nullptr;
|
||||
this->assist_effects[z] = AssistEffect::NONE;
|
||||
const auto& hes = this->hand_and_equip_states[z];
|
||||
if (hes) {
|
||||
uint16_t card_id = hes->assist_card_id == 0xFFFF
|
||||
? this->card_id_for_card_ref(hes->assist_card_ref)
|
||||
: hes->assist_card_id.load();
|
||||
this->assist_effects[z] = assist_effect_number_for_card_id(card_id);
|
||||
if (this->assist_effects[z] != AssistEffect::NONE) {
|
||||
this->assist_card_defs[z] = this->definition_for_card_id(card_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AssistServer::recompute_effects() {
|
||||
for (size_t z = 0; z < 4; z++) {
|
||||
this->active_assist_effects[z] = AssistEffect::NONE;
|
||||
this->active_assist_card_defs[z] = nullptr;
|
||||
}
|
||||
this->num_active_assists = 0;
|
||||
|
||||
if (this->num_assist_cards_set != 0) {
|
||||
for (size_t z = 0; z < this->num_assist_cards_set; z++) {
|
||||
auto eff = this->assist_effects[this->client_ids_with_assists[z]];
|
||||
if (eff == AssistEffect::RESISTANCE || eff == AssistEffect::INDEPENDENT) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Note: this->num_assist_cards_set is > 0 when we get here
|
||||
for (size_t z = 0; z < this->num_assist_cards_set - 1; z++) {
|
||||
for (size_t w = z + 1; w < this->num_assist_cards_set; w++) {
|
||||
uint8_t z_client_id = this->client_ids_with_assists[z];
|
||||
uint8_t w_client_id = this->client_ids_with_assists[w];
|
||||
if (this->hand_and_equip_states[w_client_id]->assist_card_set_number <
|
||||
this->hand_and_equip_states[z_client_id]->assist_card_set_number) {
|
||||
this->client_ids_with_assists[z] = w_client_id;
|
||||
this->client_ids_with_assists[w] = z_client_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->num_active_assists = this->num_assist_cards_set;
|
||||
for (size_t z = 0; z < this->num_assist_cards_set; z++) {
|
||||
this->active_assist_effects[z] = this->assist_effects[this->client_ids_with_assists[z]];
|
||||
this->active_assist_card_defs[z] = this->assist_card_defs[this->client_ids_with_assists[z]];
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
} // namespace Episode3
|
||||
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "DataIndexes.hh"
|
||||
#include "DeckState.hh"
|
||||
#include "PlayerState.hh"
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
class Server;
|
||||
|
||||
extern const std::vector<uint16_t> ALL_ASSIST_CARD_IDS;
|
||||
|
||||
AssistEffect assist_effect_number_for_card_id(uint16_t card_id);
|
||||
|
||||
class AssistServer {
|
||||
public:
|
||||
explicit AssistServer(std::shared_ptr<Server> server);
|
||||
std::shared_ptr<Server> server();
|
||||
std::shared_ptr<const Server> server() const;
|
||||
|
||||
uint16_t card_id_for_card_ref(uint16_t card_ref) const;
|
||||
std::shared_ptr<const CardIndex::CardEntry> definition_for_card_id(uint16_t card_id) const;
|
||||
|
||||
uint32_t compute_num_assist_effects_for_client(uint16_t client_id);
|
||||
uint32_t compute_num_assist_effects_for_team(uint32_t team_id);
|
||||
|
||||
bool should_block_assist_effects_for_client(uint16_t client_id) const;
|
||||
AssistEffect get_active_assist_by_index(size_t index) const;
|
||||
|
||||
void populate_effects();
|
||||
void recompute_effects();
|
||||
|
||||
private:
|
||||
std::weak_ptr<Server> w_server;
|
||||
|
||||
public:
|
||||
parray<AssistEffect, 4> assist_effects;
|
||||
std::shared_ptr<const CardIndex::CardEntry> assist_card_defs[4];
|
||||
uint32_t num_assist_cards_set;
|
||||
parray<uint8_t, 4> client_ids_with_assists;
|
||||
parray<AssistEffect, 4> active_assist_effects;
|
||||
std::shared_ptr<const CardIndex::CardEntry> active_assist_card_defs[4];
|
||||
uint32_t num_active_assists;
|
||||
std::shared_ptr<HandAndEquipState> hand_and_equip_states[4];
|
||||
std::shared_ptr<parray<CardShortStatus, 0x10>> card_short_statuses[4];
|
||||
std::shared_ptr<DeckEntry> deck_entries[4];
|
||||
std::shared_ptr<parray<ActionChainWithConds, 9>> set_card_action_chains[4];
|
||||
std::shared_ptr<parray<ActionMetadata, 9>> set_card_action_metadatas[4];
|
||||
};
|
||||
|
||||
} // namespace Episode3
|
||||
@@ -0,0 +1,373 @@
|
||||
#include "BattleRecord.hh"
|
||||
|
||||
#include <phosg/Time.hh>
|
||||
|
||||
#include "../CommandFormats.hh"
|
||||
#include "../SendCommands.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
BattleRecord::Event::Event(StringReader& r) {
|
||||
this->type = r.get<Event::Type>();
|
||||
this->timestamp = r.get_u64l();
|
||||
switch (this->type) {
|
||||
case Event::Type::PLAYER_JOIN:
|
||||
this->players.emplace_back(r.get<PlayerEntry>());
|
||||
break;
|
||||
case Event::Type::PLAYER_LEAVE:
|
||||
this->leaving_client_id = r.get_u8();
|
||||
break;
|
||||
case Event::Type::SET_INITIAL_PLAYERS: {
|
||||
uint8_t count = r.get_u8();
|
||||
while (this->players.size() < count) {
|
||||
this->players.emplace_back(r.get<PlayerEntry>());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Event::Type::CHAT_MESSAGE:
|
||||
this->guild_card_number = r.get_u32l();
|
||||
[[fallthrough]];
|
||||
case Event::Type::GAME_COMMAND:
|
||||
case Event::Type::BATTLE_COMMAND:
|
||||
case Event::Type::EP3_GAME_COMMAND:
|
||||
this->data = r.read(r.get_u16l());
|
||||
break;
|
||||
default:
|
||||
throw logic_error("unknown event type");
|
||||
}
|
||||
}
|
||||
|
||||
void BattleRecord::Event::serialize(StringWriter& w) const {
|
||||
w.put(this->type);
|
||||
w.put_u64l(this->timestamp);
|
||||
switch (this->type) {
|
||||
case Event::Type::PLAYER_JOIN:
|
||||
if (this->players.size() != 1) {
|
||||
throw logic_error("player join event does not contain 1 player entry");
|
||||
}
|
||||
w.put(this->players[0]);
|
||||
break;
|
||||
case Event::Type::PLAYER_LEAVE:
|
||||
w.put_u8(this->leaving_client_id);
|
||||
break;
|
||||
case Event::Type::SET_INITIAL_PLAYERS:
|
||||
w.put_u8(this->players.size());
|
||||
for (const auto& player : this->players) {
|
||||
w.put(player);
|
||||
}
|
||||
break;
|
||||
case Event::Type::CHAT_MESSAGE:
|
||||
w.put_u32l(this->guild_card_number);
|
||||
[[fallthrough]];
|
||||
case Event::Type::GAME_COMMAND:
|
||||
case Event::Type::BATTLE_COMMAND:
|
||||
case Event::Type::EP3_GAME_COMMAND:
|
||||
w.put_u16l(this->data.size());
|
||||
w.write(this->data);
|
||||
break;
|
||||
default:
|
||||
throw logic_error("unknown event type");
|
||||
}
|
||||
}
|
||||
|
||||
BattleRecord::BattleRecord(uint32_t behavior_flags)
|
||||
: is_writable(true),
|
||||
behavior_flags(behavior_flags),
|
||||
battle_start_timestamp(0),
|
||||
battle_end_timestamp(0) {}
|
||||
|
||||
BattleRecord::BattleRecord(const string& data)
|
||||
: is_writable(false),
|
||||
behavior_flags(0),
|
||||
battle_start_timestamp(0),
|
||||
battle_end_timestamp(0) {
|
||||
StringReader r(data);
|
||||
uint64_t signature = r.get_u64l();
|
||||
if (signature != this->SIGNATURE) {
|
||||
throw runtime_error("incorrect battle record signature");
|
||||
}
|
||||
|
||||
this->battle_start_timestamp = r.get_u64l();
|
||||
this->battle_end_timestamp = r.get_u64l();
|
||||
this->behavior_flags = r.get_u32l();
|
||||
while (!r.eof()) {
|
||||
this->events.emplace_back(r);
|
||||
}
|
||||
}
|
||||
|
||||
string BattleRecord::serialize() const {
|
||||
StringWriter w;
|
||||
w.put_u64l(this->SIGNATURE);
|
||||
w.put_u64l(this->battle_start_timestamp);
|
||||
w.put_u64l(this->battle_end_timestamp);
|
||||
w.put_u32l(this->behavior_flags);
|
||||
for (const auto& ev : this->events) {
|
||||
ev.serialize(w);
|
||||
}
|
||||
return std::move(w.str());
|
||||
}
|
||||
|
||||
bool BattleRecord::writable() const {
|
||||
return this->is_writable;
|
||||
}
|
||||
|
||||
bool BattleRecord::battle_in_progress() const {
|
||||
return (this->battle_start_timestamp != 0);
|
||||
}
|
||||
|
||||
const BattleRecord::Event* BattleRecord::get_first_event() const {
|
||||
if (this->events.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
return &this->events.front();
|
||||
}
|
||||
|
||||
void BattleRecord::add_player(
|
||||
const PlayerLobbyDataDCGC& lobby_data,
|
||||
const PlayerInventory& inventory,
|
||||
const PlayerDispDataDCPCV3& disp,
|
||||
uint32_t level) {
|
||||
if (!this->is_writable) {
|
||||
throw logic_error("cannot write to battle record");
|
||||
}
|
||||
if (this->battle_start_timestamp != 0) {
|
||||
throw runtime_error("cannot add player during battle");
|
||||
}
|
||||
Event& ev = this->events.emplace_back();
|
||||
ev.type = Event::Type::PLAYER_JOIN;
|
||||
ev.timestamp = now();
|
||||
auto& player = ev.players.emplace_back();
|
||||
player.lobby_data = lobby_data;
|
||||
player.inventory = inventory;
|
||||
player.disp = disp;
|
||||
player.level = level;
|
||||
}
|
||||
|
||||
void BattleRecord::delete_player(uint8_t client_id) {
|
||||
if (!this->is_writable) {
|
||||
throw logic_error("cannot write to battle record");
|
||||
}
|
||||
Event& ev = this->events.emplace_back();
|
||||
ev.type = Event::Type::PLAYER_LEAVE;
|
||||
ev.timestamp = now();
|
||||
ev.leaving_client_id = client_id;
|
||||
}
|
||||
|
||||
void BattleRecord::add_command(Event::Type type, const void* data, size_t size) {
|
||||
if (!this->is_writable) {
|
||||
throw logic_error("cannot write to battle record");
|
||||
}
|
||||
Event& ev = this->events.emplace_back();
|
||||
ev.type = type;
|
||||
ev.timestamp = now();
|
||||
ev.data.assign(reinterpret_cast<const char*>(data), size);
|
||||
}
|
||||
|
||||
void BattleRecord::add_command(Event::Type type, string&& data) {
|
||||
if (!this->is_writable) {
|
||||
throw logic_error("cannot write to battle record");
|
||||
}
|
||||
Event& ev = this->events.emplace_back();
|
||||
ev.type = type;
|
||||
ev.timestamp = now();
|
||||
ev.data = std::move(data);
|
||||
}
|
||||
|
||||
void BattleRecord::add_chat_message(
|
||||
uint32_t guild_card_number, string&& data) {
|
||||
if (!this->is_writable) {
|
||||
throw logic_error("cannot write to battle record");
|
||||
}
|
||||
Event& ev = this->events.emplace_back();
|
||||
ev.type = Event::Type::CHAT_MESSAGE;
|
||||
ev.timestamp = now();
|
||||
ev.guild_card_number = guild_card_number;
|
||||
ev.data = std::move(data);
|
||||
}
|
||||
|
||||
bool BattleRecord::is_map_definition_event(const Event& ev) {
|
||||
if (ev.type == Event::Type::BATTLE_COMMAND) {
|
||||
auto& header = check_size_t<G_CardBattleCommandHeader>(ev.data, 0xFFFF);
|
||||
if (header.subcommand == 0xB6) {
|
||||
auto& header = check_size_t<G_MapSubsubcommand_GC_Ep3_6xB6>(ev.data, 0xFFFF);
|
||||
if (header.subsubcommand == 0x41) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void BattleRecord::set_battle_start_timestamp() {
|
||||
if (this->battle_start_timestamp != 0) {
|
||||
throw logic_error("battle start timestamp is already set");
|
||||
}
|
||||
this->battle_start_timestamp = now();
|
||||
|
||||
// First, find the correct map definition subcommand to keep, and execute
|
||||
// player join/leave events to get the present players
|
||||
size_t num_map_events = 0;
|
||||
PlayerEntry players[4];
|
||||
bool players_present[4];
|
||||
for (auto& ev : this->events) {
|
||||
if (ev.type == Event::Type::PLAYER_JOIN) {
|
||||
if (ev.players.size() != 1) {
|
||||
throw logic_error("player join event does not contain 1 player entry");
|
||||
}
|
||||
auto& player = ev.players[0];
|
||||
if (player.lobby_data.client_id >= 4) {
|
||||
throw runtime_error("invalid client ID");
|
||||
}
|
||||
players[player.lobby_data.client_id] = player;
|
||||
players_present[player.lobby_data.client_id] = true;
|
||||
|
||||
} else if (ev.type == Event::Type::PLAYER_LEAVE) {
|
||||
if (ev.leaving_client_id >= 4) {
|
||||
throw logic_error("invalid client ID");
|
||||
}
|
||||
players_present[ev.leaving_client_id] = false;
|
||||
|
||||
} else if (ev.type == Event::Type::SET_INITIAL_PLAYERS) {
|
||||
throw logic_error("BattleRecord::set_battle_start_timestamp called twice");
|
||||
|
||||
} else if (this->is_map_definition_event(ev)) {
|
||||
num_map_events++;
|
||||
}
|
||||
}
|
||||
|
||||
deque<Event> new_events;
|
||||
|
||||
// Generate the initial players event
|
||||
Event initial_ev;
|
||||
initial_ev.type = Event::Type::SET_INITIAL_PLAYERS;
|
||||
initial_ev.timestamp = this->battle_start_timestamp;
|
||||
for (size_t z = 0; z < 4; z++) {
|
||||
if (players_present[z]) {
|
||||
initial_ev.players.emplace_back(players[z]);
|
||||
}
|
||||
}
|
||||
new_events.emplace_back(std::move(initial_ev));
|
||||
|
||||
// Skip all events before the last map definition event, and only retain
|
||||
// battle commands between then and now (since these battle commands will all
|
||||
// be replayed at once)
|
||||
auto it = this->events.begin();
|
||||
for (; it != this->events.end(); it++) {
|
||||
if (this->is_map_definition_event(*it)) {
|
||||
num_map_events--;
|
||||
if (num_map_events == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (; it != this->events.end(); it++) {
|
||||
if (it->type == Event::Type::BATTLE_COMMAND) {
|
||||
new_events.emplace_back(std::move(*it));
|
||||
}
|
||||
}
|
||||
this->events = std::move(new_events);
|
||||
}
|
||||
|
||||
void BattleRecord::set_battle_end_timestamp() {
|
||||
this->battle_end_timestamp = now();
|
||||
}
|
||||
|
||||
BattleRecordPlayer::BattleRecordPlayer(
|
||||
shared_ptr<const BattleRecord> rec,
|
||||
shared_ptr<struct event_base> base)
|
||||
: record(rec),
|
||||
event_it(this->record->events.begin()),
|
||||
play_start_timestamp(0),
|
||||
base(base),
|
||||
next_command_ev(event_new(this->base.get(), -1, EV_TIMEOUT, &BattleRecordPlayer::dispatch_schedule_events, this), event_free) {}
|
||||
|
||||
shared_ptr<const BattleRecord> BattleRecordPlayer::get_record() const {
|
||||
return this->record;
|
||||
}
|
||||
|
||||
void BattleRecordPlayer::set_lobby(std::shared_ptr<Lobby> l) {
|
||||
this->lobby = l;
|
||||
}
|
||||
|
||||
void BattleRecordPlayer::start() {
|
||||
if (this->play_start_timestamp == 0) {
|
||||
this->play_start_timestamp = now();
|
||||
this->schedule_events();
|
||||
}
|
||||
}
|
||||
|
||||
void BattleRecordPlayer::dispatch_schedule_events(
|
||||
evutil_socket_t, short, void* ctx) {
|
||||
reinterpret_cast<BattleRecordPlayer*>(ctx)->schedule_events();
|
||||
}
|
||||
|
||||
void BattleRecordPlayer::schedule_events() {
|
||||
// If the lobby is destroyed, we can't replay anything - just return without
|
||||
// rescheduling
|
||||
auto l = this->lobby.lock();
|
||||
if (!l) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
uint64_t relative_ts = now() - this->play_start_timestamp + this->record->battle_start_timestamp;
|
||||
|
||||
if (this->event_it == this->record->events.end()) {
|
||||
if (relative_ts >= this->record->battle_end_timestamp) {
|
||||
// If the record is complete and the end timestamp has been reached,
|
||||
// send exit commands to all players in the lobby, and don't reschedule
|
||||
// the event (it will be deleted along with the Player when the lobby is
|
||||
// destroyed, when the last client leaves)
|
||||
send_command(l, 0xED, 0x00);
|
||||
|
||||
} else {
|
||||
// There are no more events to play, but the battle has not officially
|
||||
// ended yet - reschedule the event for the end time
|
||||
auto tv = usecs_to_timeval(this->record->battle_end_timestamp - relative_ts);
|
||||
event_add(this->next_command_ev.get(), &tv);
|
||||
}
|
||||
break;
|
||||
|
||||
} else {
|
||||
if (this->event_it->timestamp <= relative_ts) {
|
||||
// Play the next event
|
||||
auto& ev = *this->event_it;
|
||||
switch (ev.type) {
|
||||
case BattleRecord::Event::Type::PLAYER_JOIN:
|
||||
// Technically we can support this, but it should never happen
|
||||
throw runtime_error("player join event during battle replay");
|
||||
case BattleRecord::Event::Type::PLAYER_LEAVE:
|
||||
send_player_leave_notification(l, ev.leaving_client_id);
|
||||
break;
|
||||
case BattleRecord::Event::Type::SET_INITIAL_PLAYERS:
|
||||
// This should have been handled before the lobby was even created
|
||||
break;
|
||||
case BattleRecord::Event::Type::BATTLE_COMMAND:
|
||||
send_command(l, (ev.data.size() >= 0x400) ? 0x6C : 0xC9, 0x00, ev.data);
|
||||
break;
|
||||
case BattleRecord::Event::Type::GAME_COMMAND:
|
||||
send_command(l, (ev.data.size() >= 0x400) ? 0x6C : 0x60, 0x00, ev.data);
|
||||
break;
|
||||
case BattleRecord::Event::Type::EP3_GAME_COMMAND:
|
||||
send_command(l, 0xC9, 0x00, ev.data);
|
||||
break;
|
||||
case BattleRecord::Event::Type::CHAT_MESSAGE:
|
||||
send_chat_message(l, ev.guild_card_number, decode_sjis(ev.data));
|
||||
break;
|
||||
}
|
||||
this->event_it++;
|
||||
|
||||
} else {
|
||||
// The next event should not occur yet, so reschedule for the time when
|
||||
// it should occur
|
||||
auto tv = usecs_to_timeval(this->event_it->timestamp - relative_ts);
|
||||
event_add(this->next_command_ev.get(), &tv);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Episode3
|
||||
@@ -0,0 +1,121 @@
|
||||
#pragma once
|
||||
|
||||
#include <event2/event.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
#include "../Player.hh"
|
||||
|
||||
struct Lobby;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
// The comment in Server.hh does not apply to this file (and BattleRecord.cc).
|
||||
|
||||
class BattleRecord {
|
||||
public:
|
||||
struct PlayerEntry {
|
||||
PlayerLobbyDataDCGC lobby_data;
|
||||
PlayerInventory inventory;
|
||||
PlayerDispDataDCPCV3 disp;
|
||||
le_uint32_t level;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Event {
|
||||
enum class Type : uint8_t {
|
||||
PLAYER_JOIN = 0,
|
||||
PLAYER_LEAVE = 1,
|
||||
SET_INITIAL_PLAYERS = 2,
|
||||
BATTLE_COMMAND = 3,
|
||||
GAME_COMMAND = 4,
|
||||
EP3_GAME_COMMAND = 5,
|
||||
CHAT_MESSAGE = 6,
|
||||
};
|
||||
|
||||
// Fields used for all events
|
||||
Type type;
|
||||
uint64_t timestamp;
|
||||
// Fields used for PLAYER_JOIN and SET_INITIAL_PLAYERS only
|
||||
std::vector<PlayerEntry> players;
|
||||
// Fields used for PLAYER_LEAVE only
|
||||
uint8_t leaving_client_id;
|
||||
// Fields used for CHAT_MESSAGE only
|
||||
uint32_t guild_card_number;
|
||||
// Fields used for the COMMAND types and CHAT_MESSAGE
|
||||
std::string data;
|
||||
|
||||
Event() = default;
|
||||
explicit Event(StringReader& r);
|
||||
void serialize(StringWriter& w) const;
|
||||
};
|
||||
|
||||
explicit BattleRecord(uint32_t behavior_flags);
|
||||
explicit BattleRecord(const std::string& data);
|
||||
std::string serialize() const;
|
||||
|
||||
bool writable() const;
|
||||
bool battle_in_progress() const;
|
||||
|
||||
const Event* get_first_event() const;
|
||||
|
||||
void add_player(
|
||||
const PlayerLobbyDataDCGC& lobby_data,
|
||||
const PlayerInventory& inventory,
|
||||
const PlayerDispDataDCPCV3& disp,
|
||||
uint32_t level);
|
||||
void delete_player(uint8_t client_id);
|
||||
void add_command(Event::Type type, const void* data, size_t size);
|
||||
void add_command(Event::Type type, std::string&& data);
|
||||
void add_chat_message(uint32_t guild_card_number, std::string&& data);
|
||||
// This function collapses all the existing player join/leave events into a
|
||||
// single SET_INITIAL_PLAYERS event, and deletes all events before the latest
|
||||
// BATTLE_COMMAND command that specifies the battle map. This should provide a
|
||||
// minimal set of commands to set up and start the battle during a replay.
|
||||
void set_battle_start_timestamp();
|
||||
void set_battle_end_timestamp();
|
||||
|
||||
private:
|
||||
static constexpr uint64_t SIGNATURE = 0x14C946D56D1DAC50;
|
||||
|
||||
static bool is_map_definition_event(const Event& ev);
|
||||
|
||||
bool is_writable;
|
||||
|
||||
uint32_t behavior_flags;
|
||||
uint64_t battle_start_timestamp;
|
||||
uint64_t battle_end_timestamp;
|
||||
std::deque<Event> events;
|
||||
|
||||
friend class BattleRecordPlayer;
|
||||
};
|
||||
|
||||
class BattleRecordPlayer {
|
||||
public:
|
||||
BattleRecordPlayer(
|
||||
std::shared_ptr<const BattleRecord> rec,
|
||||
std::shared_ptr<struct event_base> base);
|
||||
~BattleRecordPlayer() = default;
|
||||
|
||||
std::shared_ptr<const BattleRecord> get_record() const;
|
||||
|
||||
void set_lobby(std::shared_ptr<Lobby> l);
|
||||
void start();
|
||||
|
||||
private:
|
||||
static void dispatch_schedule_events(evutil_socket_t, short, void* ctx);
|
||||
void schedule_events();
|
||||
|
||||
std::shared_ptr<const BattleRecord> record;
|
||||
std::deque<BattleRecord::Event>::const_iterator event_it;
|
||||
uint64_t play_start_timestamp;
|
||||
std::shared_ptr<struct event_base> base;
|
||||
std::weak_ptr<Lobby> lobby;
|
||||
std::shared_ptr<struct event> next_command_ev;
|
||||
};
|
||||
|
||||
} // namespace Episode3
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,127 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "../CommandFormats.hh"
|
||||
#include "../Text.hh"
|
||||
#include "DataIndexes.hh"
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
class Server;
|
||||
class PlayerState;
|
||||
|
||||
class Card : public std::enable_shared_from_this<Card> {
|
||||
public:
|
||||
Card(
|
||||
uint16_t card_id,
|
||||
uint16_t card_ref,
|
||||
uint16_t client_id,
|
||||
std::shared_ptr<Server> server);
|
||||
void init();
|
||||
std::shared_ptr<Server> server();
|
||||
std::shared_ptr<const Server> server() const;
|
||||
std::shared_ptr<PlayerState> player_state();
|
||||
std::shared_ptr<const PlayerState> player_state() const;
|
||||
|
||||
ssize_t apply_abnormal_condition(
|
||||
const CardDefinition::Effect& eff,
|
||||
uint8_t def_effect_index,
|
||||
uint16_t target_card_ref,
|
||||
uint16_t sc_card_ref,
|
||||
int16_t value,
|
||||
int8_t dice_roll_value,
|
||||
int8_t random_percent);
|
||||
void apply_ap_adjust_assists_to_attack(
|
||||
std::shared_ptr<const Card> attacker_card,
|
||||
int16_t* inout_attacker_ap,
|
||||
int16_t* in_defense_power) const;
|
||||
bool card_type_is_sc_or_creature() const;
|
||||
bool check_card_flag(uint32_t flags) const;
|
||||
void commit_attack(
|
||||
int16_t damage,
|
||||
std::shared_ptr<Card> attacker_card,
|
||||
G_ApplyConditionEffect_GC_Ep3_6xB4x06* cmd,
|
||||
size_t strike_number,
|
||||
int16_t* out_effective_damage);
|
||||
int16_t compute_defense_power_for_attacker_card(
|
||||
std::shared_ptr<const Card> attacker_card);
|
||||
void destroy_set_card(std::shared_ptr<Card> attacker_card);
|
||||
int32_t error_code_for_move_to_location(const Location& loc) const;
|
||||
void execute_attack(std::shared_ptr<Card> attacker_card);
|
||||
bool get_attack_condition_value(
|
||||
ConditionType cond_type,
|
||||
uint16_t card_ref,
|
||||
uint8_t def_effect_index,
|
||||
uint16_t value,
|
||||
uint16_t* out_value) const;
|
||||
std::shared_ptr<const CardIndex::CardEntry> get_definition() const;
|
||||
uint16_t get_card_ref() const;
|
||||
uint16_t get_card_id() const;
|
||||
uint8_t get_client_id() const;
|
||||
uint8_t get_current_hp() const;
|
||||
uint8_t get_max_hp() const;
|
||||
CardShortStatus get_short_status();
|
||||
uint8_t get_team_id() const;
|
||||
int32_t move_to_location(const Location& loc);
|
||||
void propagate_shared_hp_if_needed();
|
||||
void send_6xB4x4E_4C_4D_if_needed(bool always_send = false);
|
||||
void send_6xB4x4E_if_needed(bool always_send = false);
|
||||
void set_current_and_max_hp(int16_t hp);
|
||||
void set_current_hp(
|
||||
uint32_t new_hp, bool propagate_shared_hp = true, bool enforce_max_hp = true);
|
||||
void update_stats_on_destruction();
|
||||
void clear_action_chain_and_metadata_and_most_flags();
|
||||
void compute_action_chain_results(
|
||||
bool apply_action_conditions, bool ignore_this_card_ap_tp);
|
||||
void unknown_802380C0();
|
||||
void unknown_80237F98(bool require_condition_20_or_21);
|
||||
void unknown_80237F88();
|
||||
void unknown_80235AA0();
|
||||
void unknown_80235AD4();
|
||||
void unknown_80235B10();
|
||||
void unknown_80236374(std::shared_ptr<Card> other_card, const ActionState* as);
|
||||
void unknown_802379BC(uint16_t card_ref);
|
||||
void unknown_802379DC(const ActionState& pa);
|
||||
void unknown_80237A90(const ActionState& pa, uint16_t action_card_ref);
|
||||
void unknown_8023813C();
|
||||
bool is_guard_item() const;
|
||||
bool unknown_80236554(std::shared_ptr<Card> other_card, const ActionState* as);
|
||||
void unknown_802362D8(std::shared_ptr<Card> other_card);
|
||||
void apply_attack_result();
|
||||
|
||||
private:
|
||||
std::weak_ptr<Server> w_server;
|
||||
std::weak_ptr<PlayerState> w_player_state;
|
||||
|
||||
public:
|
||||
int16_t max_hp;
|
||||
int16_t current_hp;
|
||||
std::shared_ptr<const CardIndex::CardEntry> def_entry;
|
||||
uint8_t client_id;
|
||||
uint16_t card_id;
|
||||
uint16_t card_ref;
|
||||
uint16_t sc_card_ref;
|
||||
std::shared_ptr<const CardIndex::CardEntry> sc_def_entry;
|
||||
CardType sc_card_type;
|
||||
uint8_t team_id;
|
||||
uint32_t card_flags;
|
||||
Location loc;
|
||||
Direction facing_direction;
|
||||
ActionChainWithConds action_chain;
|
||||
ActionMetadata action_metadata;
|
||||
int16_t ap;
|
||||
int16_t tp;
|
||||
uint32_t num_ally_fcs_destroyed_at_set_time;
|
||||
uint32_t num_cards_destroyed_by_team_at_set_time;
|
||||
uint32_t unknown_a9;
|
||||
int16_t last_attack_preliminary_damage;
|
||||
int16_t last_attack_final_damage;
|
||||
uint32_t num_destroyed_ally_fcs;
|
||||
std::weak_ptr<Card> w_destroyer_sc_card;
|
||||
int16_t current_defense_power;
|
||||
};
|
||||
|
||||
} // namespace Episode3
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,341 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "../Text.hh"
|
||||
#include "DataIndexes.hh"
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
struct InterferenceProbabilityEntry {
|
||||
uint16_t card_id;
|
||||
uint8_t attack_probability;
|
||||
uint8_t defense_probability;
|
||||
};
|
||||
|
||||
const InterferenceProbabilityEntry* get_interference_probability_entry(
|
||||
uint16_t row_card_id,
|
||||
uint16_t column_card_id,
|
||||
bool is_attack);
|
||||
|
||||
class CardSpecial {
|
||||
public:
|
||||
enum class ExpressionTokenType {
|
||||
SPACE = 0, // Also used for end of string (get_next_expr_token returns null)
|
||||
REFERENCE = 1, // Reference to a value from the env stats (e.g. hp)
|
||||
NUMBER = 2, // Constant value (e.g. 2)
|
||||
SUBTRACT = 3, // "-" in input string
|
||||
ADD = 4, // "+" in input string
|
||||
ROUND_DIVIDE = 5, // "/" in input string
|
||||
FLOOR_DIVIDE = 6, // "//" in input string
|
||||
MULTIPLY = 7, // "*" in input string
|
||||
};
|
||||
|
||||
struct DiceRoll {
|
||||
uint8_t client_id;
|
||||
uint8_t unknown_a2;
|
||||
uint8_t value;
|
||||
bool value_used_in_expr;
|
||||
uint16_t unknown_a5;
|
||||
|
||||
DiceRoll();
|
||||
void clear();
|
||||
};
|
||||
|
||||
struct AttackEnvStats {
|
||||
uint32_t num_set_cards; // "f" in expr
|
||||
uint32_t dice_roll_value1; // "d" in expr
|
||||
uint32_t effective_ap; // "ap" in expr
|
||||
uint32_t effective_tp; // "tp" in expr
|
||||
uint32_t current_hp; // "hp" in expr
|
||||
uint32_t max_hp; // "mhp" in expr
|
||||
uint32_t effective_ap_if_not_tech; // "dm" in expr
|
||||
uint32_t effective_ap_if_not_physical; // "tdm" in expr
|
||||
uint32_t player_num_destroyed_fcs; // "tf" in expr
|
||||
uint32_t player_num_atk_points; // "ac" in expr
|
||||
uint32_t defined_max_hp; // "php" in expr
|
||||
uint32_t dice_roll_value2; // "dc" in expr
|
||||
uint32_t card_cost; // "cs" in expr
|
||||
uint32_t total_num_set_cards; // "a" in expr
|
||||
uint32_t action_cards_ap; // "kap" in expr
|
||||
uint32_t action_cards_tp; // "ktp" in expr
|
||||
uint32_t unknown_a1; // "dn" in expr
|
||||
uint32_t num_item_or_creature_cards_in_hand; // "hf" in expr
|
||||
uint32_t num_destroyed_ally_fcs; // "df" in expr
|
||||
uint32_t target_team_num_set_cards; // "ff" in expr
|
||||
uint32_t condition_giver_team_num_set_cards; // "ef" in expr
|
||||
uint32_t num_native_creatures; // "bi" in expr
|
||||
uint32_t num_a_beast_creatures; // "ab" in expr
|
||||
uint32_t num_machine_creatures; // "mc" in expr
|
||||
uint32_t num_dark_creatures; // "dk" in expr
|
||||
uint32_t num_sword_type_items; // "sa" in expr
|
||||
uint32_t num_gun_type_items; // "gn" in expr
|
||||
uint32_t num_cane_type_items; // "wd" in expr
|
||||
uint32_t effective_ap_if_not_tech2; // "tt" in expr
|
||||
uint32_t team_dice_boost; // "lv" in expr
|
||||
uint32_t sc_effective_ap; // "adm" in expr
|
||||
uint32_t attack_bonus; // "ddm" in expr
|
||||
uint32_t num_sword_type_items_on_team; // "sat" in expr
|
||||
uint32_t target_attack_bonus; // "edm" in expr
|
||||
uint32_t last_attack_preliminary_damage; // "ldm" in expr
|
||||
uint32_t last_attack_damage; // "rdm" in expr
|
||||
uint32_t total_last_attack_damage; // "fdm" in expr
|
||||
uint32_t last_attack_damage_count; // "ndm" in expr
|
||||
uint32_t target_current_hp; // "ehp" in expr
|
||||
|
||||
AttackEnvStats();
|
||||
void clear();
|
||||
void print(FILE* stream) const;
|
||||
|
||||
uint32_t at(size_t index) const;
|
||||
} __attribute__((packed));
|
||||
|
||||
CardSpecial(std::shared_ptr<Server> server);
|
||||
std::shared_ptr<Server> server();
|
||||
std::shared_ptr<const Server> server() const;
|
||||
|
||||
void adjust_attack_damage_due_to_conditions(
|
||||
std::shared_ptr<const Card> target_card, int16_t* inout_damage, uint16_t attacker_card_ref);
|
||||
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,
|
||||
std::shared_ptr<const Card> attacker_card,
|
||||
std::shared_ptr<Card> defender_card,
|
||||
uint32_t flags,
|
||||
const ActionState* as);
|
||||
bool apply_attribute_guard_if_possible(
|
||||
uint32_t flags,
|
||||
CardClass card_class,
|
||||
std::shared_ptr<Card> card,
|
||||
uint16_t condition_giver_card_ref,
|
||||
uint16_t attacker_card_ref);
|
||||
bool apply_defense_condition(
|
||||
uint8_t when,
|
||||
Condition* defender_cond,
|
||||
uint8_t cond_index,
|
||||
const ActionState& defense_state,
|
||||
std::shared_ptr<Card> defender_card,
|
||||
uint32_t flags,
|
||||
bool unknown_p8);
|
||||
bool apply_defense_conditions(
|
||||
const ActionState& as,
|
||||
uint8_t when,
|
||||
std::shared_ptr<Card> defender_card,
|
||||
uint32_t flags);
|
||||
bool apply_stat_deltas_to_all_cards_from_all_conditions_with_card_ref(
|
||||
uint16_t card_ref);
|
||||
bool apply_stat_deltas_to_card_from_condition_and_clear_cond(
|
||||
Condition& cond, std::shared_ptr<Card> card);
|
||||
bool apply_stats_deltas_to_card_from_all_conditions_with_card_ref(
|
||||
uint16_t card_ref, std::shared_ptr<Card> card);
|
||||
bool card_has_condition_with_ref(
|
||||
std::shared_ptr<const Card> card,
|
||||
ConditionType cond_type,
|
||||
uint16_t card_ref,
|
||||
uint16_t match_card_ref) const;
|
||||
bool card_is_destroyed(std::shared_ptr<const Card> card) const;
|
||||
void compute_attack_ap(
|
||||
std::shared_ptr<const Card> target_card,
|
||||
int16_t* out_value,
|
||||
uint16_t attacker_card_ref);
|
||||
AttackEnvStats compute_attack_env_stats(
|
||||
const ActionState& pa,
|
||||
std::shared_ptr<const Card> card,
|
||||
const DiceRoll& dice_roll,
|
||||
uint16_t target_card_ref,
|
||||
uint16_t condition_giver_card_ref);
|
||||
std::shared_ptr<Card> compute_replaced_target_based_on_conditions(
|
||||
uint16_t target_card_ref,
|
||||
int unknown_p3,
|
||||
int unknown_p4,
|
||||
uint16_t attacker_card_ref,
|
||||
uint16_t set_card_ref,
|
||||
int unknown_p7,
|
||||
uint32_t* unknown_p9,
|
||||
uint8_t def_effect_index,
|
||||
uint32_t* unknown_p11,
|
||||
uint16_t sc_card_ref);
|
||||
StatSwapType compute_stat_swap_type(std::shared_ptr<const Card> card) const;
|
||||
void compute_team_dice_boost(uint8_t team_id);
|
||||
bool condition_has_when_20_or_21(const Condition& cond) const;
|
||||
size_t count_action_cards_with_condition_for_all_current_attacks(
|
||||
ConditionType cond_type, uint16_t card_ref) const;
|
||||
size_t count_action_cards_with_condition_for_current_attack(
|
||||
std::shared_ptr<const Card> card, ConditionType cond_type, uint16_t card_ref) const;
|
||||
size_t count_cards_with_card_id_except_card_ref(
|
||||
uint16_t card_id, uint16_t card_ref) const;
|
||||
std::vector<std::shared_ptr<const Card>> get_all_set_cards_by_team_and_class(
|
||||
CardClass card_class, uint8_t team_id, bool exclude_destroyed_cards) const;
|
||||
ActionState create_attack_state_from_card_action_chain(
|
||||
std::shared_ptr<const Card> attacker_card) const;
|
||||
ActionState create_defense_state_for_card_pair_action_chains(
|
||||
std::shared_ptr<const Card> attacker_card,
|
||||
std::shared_ptr<const Card> defender_card) const;
|
||||
void destroy_card_if_hp_zero(
|
||||
std::shared_ptr<Card> card, uint16_t attacker_card_ref);
|
||||
bool evaluate_effect_arg2_condition(
|
||||
const ActionState& as,
|
||||
std::shared_ptr<const Card> card,
|
||||
const char* arg2_text,
|
||||
DiceRoll& dice_roll,
|
||||
uint16_t set_card_ref,
|
||||
uint16_t sc_card_ref,
|
||||
uint8_t random_percent,
|
||||
uint8_t when) const;
|
||||
int32_t evaluate_effect_expr(
|
||||
const AttackEnvStats& ast,
|
||||
const char* expr,
|
||||
DiceRoll& dice_roll) const;
|
||||
bool execute_effect(
|
||||
Condition& cond,
|
||||
std::shared_ptr<Card> card,
|
||||
int16_t expr_value,
|
||||
int16_t unknown_p5,
|
||||
ConditionType cond_type,
|
||||
uint32_t unknown_p7,
|
||||
uint16_t attacker_card_ref);
|
||||
const Condition* find_condition_with_parameters(
|
||||
std::shared_ptr<const Card> card,
|
||||
ConditionType cond_type,
|
||||
uint16_t set_card_ref,
|
||||
uint8_t def_effect_index) const;
|
||||
Condition* find_condition_with_parameters(
|
||||
std::shared_ptr<Card> card,
|
||||
ConditionType cond_type,
|
||||
uint16_t set_card_ref,
|
||||
uint8_t def_effect_index) const;
|
||||
static void get_card1_loc_with_card2_opposite_direction(
|
||||
Location* out_loc,
|
||||
std::shared_ptr<const Card> card1,
|
||||
std::shared_ptr<const Card> card2);
|
||||
uint16_t get_card_id_with_effective_range(
|
||||
std::shared_ptr<const Card> card1, uint16_t default_card_id, std::shared_ptr<const Card> card2) const;
|
||||
static void get_effective_ap_tp(
|
||||
StatSwapType type,
|
||||
int16_t* effective_ap,
|
||||
int16_t* effective_tp,
|
||||
int16_t hp,
|
||||
int16_t ap,
|
||||
int16_t tp);
|
||||
const char* get_next_expr_token(
|
||||
const char* expr, ExpressionTokenType* out_type, int32_t* out_value) const;
|
||||
std::vector<std::shared_ptr<const Card>> get_targeted_cards_for_condition(
|
||||
uint16_t card_ref,
|
||||
uint8_t def_effect_index,
|
||||
uint16_t setter_card_ref,
|
||||
const ActionState& as,
|
||||
int16_t p_target_type,
|
||||
bool apply_usability_filters) const;
|
||||
std::vector<std::shared_ptr<Card>> get_targeted_cards_for_condition(
|
||||
uint16_t card_ref,
|
||||
uint8_t def_effect_index,
|
||||
uint16_t setter_card_ref,
|
||||
const ActionState& as,
|
||||
int16_t p_target_type,
|
||||
bool apply_usability_filters);
|
||||
bool is_card_targeted_by_condition(
|
||||
const Condition& cond, const ActionState& as, std::shared_ptr<const Card> card) const;
|
||||
void on_card_set(std::shared_ptr<PlayerState> ps, uint16_t card_ref);
|
||||
const CardDefinition::Effect* original_definition_for_condition(
|
||||
const Condition& cond) const;
|
||||
bool card_ref_has_ability_trap(const Condition& eff) const;
|
||||
void send_6xB4x06_for_exp_change(
|
||||
std::shared_ptr<const Card> card,
|
||||
uint16_t attacker_card_ref,
|
||||
uint8_t dice_roll_value,
|
||||
bool unknown_p5) const;
|
||||
void send_6xB4x06_for_card_destroyed(
|
||||
std::shared_ptr<const Card> destroyed_card, uint16_t attacker_card_ref) const;
|
||||
uint16_t send_6xB4x06_if_card_ref_invalid(
|
||||
uint16_t card_ref, int16_t value) const;
|
||||
void send_6xB4x06_for_stat_delta(
|
||||
std::shared_ptr<const Card> card,
|
||||
uint16_t attacker_card_ref,
|
||||
uint32_t flags,
|
||||
int16_t hp_delta,
|
||||
bool unknown_p6,
|
||||
bool unknown_p7) const;
|
||||
bool should_cancel_condition_due_to_anti_abnormality(
|
||||
const CardDefinition::Effect& eff,
|
||||
std::shared_ptr<const Card> card,
|
||||
uint16_t target_card_ref,
|
||||
uint16_t sc_card_ref) const;
|
||||
bool should_return_card_ref_to_hand_on_destruction(
|
||||
uint16_t card_ref) const;
|
||||
size_t sum_last_attack_damage(
|
||||
std::vector<std::shared_ptr<const Card>>* out_cards,
|
||||
int32_t* out_damage_sum,
|
||||
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 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,
|
||||
uint16_t set_card_ref,
|
||||
const ActionState& as,
|
||||
uint16_t sc_card_ref,
|
||||
bool apply_defense_condition_to_all_cards = true,
|
||||
uint16_t apply_defense_condition_to_card_ref = 0xFFFF);
|
||||
std::vector<std::shared_ptr<const Card>> get_all_set_cards() const;
|
||||
std::vector<std::shared_ptr<const Card>> find_cards_by_condition_inc_exc(
|
||||
ConditionType include_cond,
|
||||
ConditionType exclude_cond = ConditionType::NONE,
|
||||
AssistEffect include_eff = AssistEffect::NONE,
|
||||
AssistEffect exclude_eff = AssistEffect::NONE) const;
|
||||
void clear_invalid_conditions_on_card(
|
||||
std::shared_ptr<Card> card, const ActionState& as);
|
||||
void on_card_destroyed(
|
||||
std::shared_ptr<Card> attacker_card, std::shared_ptr<Card> destroyed_card);
|
||||
std::vector<std::shared_ptr<const Card>> find_cards_in_hp_range(
|
||||
int16_t min, int16_t max) const;
|
||||
std::vector<std::shared_ptr<const Card>> find_all_cards_by_aerial_attribute(bool is_aerial) const;
|
||||
std::vector<std::shared_ptr<const Card>> find_cards_damaged_by_at_least(int16_t damage) const;
|
||||
std::vector<std::shared_ptr<const Card>> find_all_set_cards_on_client_team(uint8_t client_id) const;
|
||||
std::vector<std::shared_ptr<const Card>> find_all_cards_on_same_or_other_team(uint8_t client_id, bool same_team) const;
|
||||
std::shared_ptr<const Card> sc_card_for_client_id(uint8_t client_id) const;
|
||||
std::shared_ptr<const Card> get_attacker_card(const ActionState& as) const;
|
||||
std::vector<std::shared_ptr<const Card>> get_attacker_card_and_sc_if_item(const ActionState& as) const;
|
||||
std::vector<std::shared_ptr<const Card>> find_all_set_cards_with_cost_in_range(uint8_t min_cost, uint8_t max_cost) const;
|
||||
std::vector<std::shared_ptr<const Card>> filter_cards_by_range(
|
||||
const std::vector<std::shared_ptr<const Card>>& cards,
|
||||
std::shared_ptr<const Card> card1,
|
||||
const Location& card1_loc,
|
||||
std::shared_ptr<const Card> card2) const;
|
||||
void unknown_8024AAB8(const ActionState& as);
|
||||
void unknown_80244BE4(std::shared_ptr<Card> unknown_p2);
|
||||
void unknown_80244CA8(std::shared_ptr<Card> card);
|
||||
template <uint8_t When1, uint8_t When2>
|
||||
void unknown1_t(
|
||||
std::shared_ptr<Card> unknown_p2, const ActionState* existing_as = nullptr);
|
||||
void unknown_80249060(std::shared_ptr<Card> unknown_p2);
|
||||
void unknown_80249254(std::shared_ptr<Card> unknown_p2);
|
||||
void unknown_8024945C(std::shared_ptr<Card> unknown_p2, const ActionState& existing_as);
|
||||
void unknown_8024966C(std::shared_ptr<Card> unknown_p2, const ActionState* existing_as);
|
||||
static std::shared_ptr<Card> sc_card_for_card(std::shared_ptr<Card> unknown_p2);
|
||||
void unknown_8024A9D8(const ActionState& pa, uint16_t action_card_ref);
|
||||
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);
|
||||
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);
|
||||
std::vector<std::shared_ptr<const Card>> find_all_sc_cards_of_class(
|
||||
CardClass card_class) const;
|
||||
|
||||
private:
|
||||
std::weak_ptr<Server> w_server;
|
||||
ActionState unknown_action_state_a1;
|
||||
ActionState action_state;
|
||||
uint16_t unknown_a2;
|
||||
};
|
||||
|
||||
} // namespace Episode3
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,318 @@
|
||||
#include "DeckState.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
NameEntry::NameEntry() {
|
||||
this->clear();
|
||||
}
|
||||
|
||||
void NameEntry::clear() {
|
||||
this->client_id = 0xFF;
|
||||
this->present = 0;
|
||||
this->is_cpu_player = 0;
|
||||
this->unused = 0;
|
||||
}
|
||||
|
||||
DeckEntry::DeckEntry() {
|
||||
this->clear();
|
||||
}
|
||||
|
||||
void DeckEntry::clear() {
|
||||
this->team_id = 0xFFFFFFFF;
|
||||
this->god_whim_flag = 3;
|
||||
this->unused1 = 0;
|
||||
this->player_level = 0;
|
||||
this->unused2.clear(0);
|
||||
this->card_ids.clear(0xFFFF);
|
||||
}
|
||||
|
||||
uint8_t index_for_card_ref(uint16_t card_ref) {
|
||||
return card_ref & 0xFF;
|
||||
}
|
||||
|
||||
uint8_t client_id_for_card_ref(uint16_t card_ref) {
|
||||
return (card_ref >> 8) & 0xFF;
|
||||
}
|
||||
|
||||
uint8_t DeckState::num_drawable_cards() const {
|
||||
return this->card_refs.size() - this->draw_index;
|
||||
}
|
||||
|
||||
bool DeckState::set_card_ref_in_play(uint16_t card_ref) {
|
||||
if (!this->contains_card_ref(card_ref)) {
|
||||
return false;
|
||||
}
|
||||
uint8_t index = index_for_card_ref(card_ref);
|
||||
if (this->entries[index].state == CardState::IN_HAND) {
|
||||
this->entries[index].state = CardState::IN_PLAY;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool DeckState::contains_card_ref(uint16_t card_ref) const {
|
||||
return index_for_card_ref(card_ref) < this->entries.size();
|
||||
}
|
||||
|
||||
void DeckState::disable_loop() {
|
||||
this->loop_enabled = false;
|
||||
}
|
||||
|
||||
void DeckState::disable_shuffle() {
|
||||
this->shuffle_enabled = false;
|
||||
}
|
||||
|
||||
uint16_t DeckState::draw_card() {
|
||||
if (this->num_drawable_cards() == 0) {
|
||||
this->restart();
|
||||
}
|
||||
if (this->num_drawable_cards() == 0) {
|
||||
return 0xFFFF;
|
||||
}
|
||||
|
||||
uint16_t ref = this->card_refs[this->draw_index++];
|
||||
this->entries[index_for_card_ref(ref)].state = CardState::IN_HAND;
|
||||
return ref;
|
||||
}
|
||||
|
||||
bool DeckState::draw_card_by_ref(uint16_t card_ref) {
|
||||
if (card_ref == 0xFFFF) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t index = index_for_card_ref(card_ref);
|
||||
if (index > this->entries.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the card is discarded, then it should be before the draw index, and we
|
||||
// can just change its state.
|
||||
if (this->entries[index].state == CardState::DISCARDED) {
|
||||
this->entries[index].state = CardState::IN_HAND;
|
||||
return true;
|
||||
|
||||
// If the card is still drawable, we need to move it so it's just in front of
|
||||
// the draw index, then immediately draw it
|
||||
} else if (this->entries[index].state == CardState::DRAWABLE) {
|
||||
ssize_t ref_index;
|
||||
for (ref_index = this->card_refs.size(); ref_index >= 0; ref_index--) {
|
||||
if (this->card_refs[ref_index] == card_ref) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ref_index < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t ref_uindex = ref_index;
|
||||
for (; ref_uindex > this->draw_index; ref_uindex--) {
|
||||
// Note: draw_index is also unsigned, so ref_uindex cannot be zero here
|
||||
this->card_refs[ref_uindex] = this->card_refs[ref_uindex - 1];
|
||||
}
|
||||
this->card_refs[this->draw_index] = card_ref;
|
||||
this->entries[index].state = CardState::IN_HAND;
|
||||
this->draw_index++;
|
||||
return true;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t DeckState::card_id_for_card_ref(uint16_t card_ref) const {
|
||||
if (card_ref == 0xFFFF) {
|
||||
return 0xFFFF;
|
||||
}
|
||||
|
||||
uint8_t index = index_for_card_ref(card_ref);
|
||||
if (index < this->entries.size()) {
|
||||
return this->entries[index].card_id;
|
||||
} else {
|
||||
return 0xFFFF;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t DeckState::sc_card_id() const {
|
||||
return this->entries[0].card_id;
|
||||
}
|
||||
|
||||
uint16_t DeckState::sc_card_ref() const {
|
||||
return this->card_refs[0];
|
||||
}
|
||||
|
||||
uint16_t DeckState::card_ref_for_index(uint8_t index) const {
|
||||
return this->card_ref_base | index;
|
||||
}
|
||||
|
||||
DeckState::CardState DeckState::state_for_card_ref(uint16_t card_ref) const {
|
||||
uint8_t index = index_for_card_ref(card_ref);
|
||||
return (index < this->entries.size()) ? this->entries[index].state : CardState::INVALID;
|
||||
}
|
||||
|
||||
void DeckState::restart() {
|
||||
// First, if deck loop is on, return all discarded cards to the drawable state
|
||||
if (this->loop_enabled) {
|
||||
for (size_t z = 0; z < this->entries.size(); z++) {
|
||||
if (this->entries[z].state == CardState::DISCARDED) {
|
||||
this->entries[z].state = CardState::DRAWABLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For any cards that are still in hand or still in play, move their refs to
|
||||
// the already-drawn part of the deck
|
||||
this->draw_index = 0;
|
||||
for (size_t z = 0; z < this->entries.size(); z++) {
|
||||
if (this->entries[z].state != CardState::DRAWABLE) {
|
||||
this->card_refs[this->draw_index++] = this->card_ref_for_index(z);
|
||||
}
|
||||
}
|
||||
|
||||
// For now-drawable cards, put their refs after the draw index
|
||||
size_t index = this->draw_index;
|
||||
for (size_t z = 0; z < this->entries.size(); z++) {
|
||||
if (this->entries[z].state == CardState::DRAWABLE) {
|
||||
this->card_refs[index++] = this->card_ref_for_index(z);
|
||||
}
|
||||
}
|
||||
|
||||
this->shuffle();
|
||||
}
|
||||
|
||||
void DeckState::do_mulligan() {
|
||||
for (size_t z = 0; z < this->entries.size(); z++) {
|
||||
if (this->entries[z].state == CardState::DISCARDED) {
|
||||
this->entries[z].state = CardState::DRAWABLE;
|
||||
}
|
||||
}
|
||||
this->draw_index = 1;
|
||||
|
||||
if (this->shuffle_enabled) {
|
||||
// Get the next 5 cards from the deck, and put the previous 5 cards after
|
||||
// them (so they will be shuffled back in).
|
||||
for (uint8_t z = 0; z < 5; z++) {
|
||||
uint8_t index = z + this->draw_index;
|
||||
uint16_t temp_ref = this->card_refs[index];
|
||||
this->card_refs[index] = this->card_refs[index + 5];
|
||||
this->card_refs[index + 5] = temp_ref;
|
||||
}
|
||||
|
||||
// Shuffle the deck, except the first 5 cards (which are about to be drawn).
|
||||
size_t max = this->num_drawable_cards() - 5;
|
||||
uint8_t base_index = this->draw_index + 5;
|
||||
for (size_t z = 0; z < this->card_refs.size(); z++) {
|
||||
uint8_t index1 = this->random_crypt->next() % max;
|
||||
uint8_t index2 = this->random_crypt->next() % max;
|
||||
uint16_t temp_ref = this->card_refs[base_index + index1];
|
||||
this->card_refs[base_index + index1] = this->card_refs[base_index + index2];
|
||||
this->card_refs[base_index + index2] = temp_ref;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool DeckState::set_card_ref_drawable_next(uint16_t card_ref) {
|
||||
if (card_ref == 0xFFFF) {
|
||||
return false;
|
||||
}
|
||||
if (client_id_for_card_ref(card_ref) != this->client_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t index = index_for_card_ref(card_ref);
|
||||
if (this->entries[index].state == CardState::DRAWABLE) {
|
||||
return false;
|
||||
} else if (this->draw_index < 1) {
|
||||
return false;
|
||||
} else {
|
||||
this->entries[index].state = CardState::DRAWABLE;
|
||||
this->card_refs[--this->draw_index] = card_ref;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool DeckState::set_card_ref_drawable_at_end(uint16_t card_ref) {
|
||||
if (this->set_card_ref_drawable_next(card_ref)) {
|
||||
uint16_t head_card_ref = this->card_refs[this->draw_index];
|
||||
if (this->draw_index < this->card_refs.size() - 1) {
|
||||
for (size_t z = this->draw_index; z < this->card_refs.size() - 1; z++) {
|
||||
this->card_refs[z] = this->card_refs[z + 1];
|
||||
}
|
||||
}
|
||||
this->card_refs[this->card_refs.size() - 1] = head_card_ref;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void DeckState::set_card_discarded(uint16_t card_ref) {
|
||||
uint8_t index = index_for_card_ref(card_ref);
|
||||
if (index < this->entries.size()) {
|
||||
this->entries[index].state = CardState::DISCARDED;
|
||||
}
|
||||
}
|
||||
|
||||
void DeckState::shuffle() {
|
||||
if (this->shuffle_enabled) {
|
||||
size_t max = this->num_drawable_cards();
|
||||
for (size_t z = 0; z < this->card_refs.size(); z++) {
|
||||
// Note: This is the way Sega originally implemented shuffling - they just
|
||||
// do N swaps on the entire array. A more uniform way to do it would be to
|
||||
// instead swap each item with another random item (possibly itself) that
|
||||
// doesn't appear earlier than it in the array, but this is not what Sega
|
||||
// did.
|
||||
uint8_t index1 = this->draw_index + this->random_crypt->next() % max;
|
||||
uint8_t index2 = this->draw_index + this->random_crypt->next() % max;
|
||||
uint16_t temp_ref = this->card_refs[index1];
|
||||
this->card_refs[index1] = this->card_refs[index2];
|
||||
this->card_refs[index2] = temp_ref;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const char* name_for_card_state(DeckState::CardState st) {
|
||||
switch (st) {
|
||||
case DeckState::CardState::DRAWABLE:
|
||||
return "DRAWABLE";
|
||||
case DeckState::CardState::STORY_CHARACTER:
|
||||
return "STORY_CHARACTER";
|
||||
case DeckState::CardState::IN_HAND:
|
||||
return "IN_HAND";
|
||||
case DeckState::CardState::IN_PLAY:
|
||||
return "IN_PLAY";
|
||||
case DeckState::CardState::DISCARDED:
|
||||
return "DISCARDED";
|
||||
case DeckState::CardState::INVALID:
|
||||
return "INVALID";
|
||||
default:
|
||||
return "__UNKNOWN__";
|
||||
}
|
||||
}
|
||||
|
||||
void DeckState::print(FILE* stream, std::shared_ptr<const CardIndex> card_index) const {
|
||||
fprintf(stream, "DeckState: client_id=%hhu draw_index=%hhu card_ref_base=@%04hX shuffle=%s loop=%s\n",
|
||||
this->client_id, this->draw_index, this->card_ref_base, this->shuffle_enabled ? "true" : "false", this->loop_enabled ? "true" : "false");
|
||||
for (size_t z = 0; z < 31; z++) {
|
||||
const auto& e = this->entries[z];
|
||||
shared_ptr<const CardIndex::CardEntry> ce;
|
||||
if (card_index) {
|
||||
try {
|
||||
ce = card_index->definition_for_id(e.card_id);
|
||||
} catch (const out_of_range&) {
|
||||
}
|
||||
}
|
||||
if (ce) {
|
||||
string name = ce->def.en_name;
|
||||
fprintf(stream, " (%02zu) index=%02hhX ref=@%04hX card_id=#%04hX \"%s\" %s\n",
|
||||
z, e.deck_index, this->card_refs[z], e.card_id, name.c_str(), name_for_card_state(e.state));
|
||||
} else {
|
||||
fprintf(stream, " (%02zu) index=%02hhX ref=@%04hX card_id=#%04hX %s\n",
|
||||
z, e.deck_index, this->card_refs[z], e.card_id, name_for_card_state(e.state));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Episode3
|
||||
@@ -0,0 +1,116 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "../PSOEncryption.hh"
|
||||
#include "../Text.hh"
|
||||
#include "DataIndexes.hh"
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
struct NameEntry {
|
||||
parray<char, 0x10> name;
|
||||
uint8_t client_id;
|
||||
uint8_t present;
|
||||
uint8_t is_cpu_player;
|
||||
uint8_t unused;
|
||||
|
||||
NameEntry();
|
||||
void clear();
|
||||
} __attribute__((packed));
|
||||
|
||||
struct DeckEntry {
|
||||
ptext<char, 0x10> name;
|
||||
le_uint32_t team_id;
|
||||
parray<le_uint16_t, 31> card_ids;
|
||||
// If the following flag is not set to 3, then the God Whim assist effect can
|
||||
// use cards that are hidden from the player during deck building. The client
|
||||
// always sets this to 3, and it's not clear why this even exists.
|
||||
uint8_t god_whim_flag;
|
||||
uint8_t unused1;
|
||||
le_uint16_t player_level;
|
||||
parray<uint8_t, 2> unused2;
|
||||
|
||||
DeckEntry();
|
||||
void clear();
|
||||
} __attribute__((packed));
|
||||
|
||||
uint8_t index_for_card_ref(uint16_t card_ref);
|
||||
uint8_t client_id_for_card_ref(uint16_t card_ref);
|
||||
|
||||
class DeckState {
|
||||
public:
|
||||
enum class CardState {
|
||||
DRAWABLE = 0,
|
||||
STORY_CHARACTER = 1,
|
||||
IN_HAND = 2,
|
||||
IN_PLAY = 3,
|
||||
DISCARDED = 4,
|
||||
INVALID = 5,
|
||||
};
|
||||
|
||||
template <typename CardIDT>
|
||||
DeckState(
|
||||
uint8_t client_id,
|
||||
const parray<CardIDT, 0x1F>& card_ids,
|
||||
std::shared_ptr<PSOLFGEncryption> random_crypt)
|
||||
: client_id(client_id),
|
||||
draw_index(1),
|
||||
card_ref_base(this->client_id << 8),
|
||||
shuffle_enabled(true),
|
||||
loop_enabled(true),
|
||||
random_crypt(random_crypt) {
|
||||
for (size_t z = 0; z < card_ids.size(); z++) {
|
||||
auto& e = this->entries[z];
|
||||
e.card_id = card_ids[z];
|
||||
e.deck_index = z;
|
||||
e.state = CardState::DRAWABLE;
|
||||
this->card_refs[z] = this->card_ref_for_index(z);
|
||||
}
|
||||
this->entries[0].state = CardState::STORY_CHARACTER;
|
||||
}
|
||||
|
||||
void disable_loop();
|
||||
void disable_shuffle();
|
||||
|
||||
uint8_t num_drawable_cards() const;
|
||||
bool contains_card_ref(uint16_t card_ref) const;
|
||||
uint16_t card_id_for_card_ref(uint16_t card_ref) const;
|
||||
uint16_t sc_card_id() const;
|
||||
uint16_t sc_card_ref() const;
|
||||
uint16_t card_ref_for_index(uint8_t index) const;
|
||||
CardState state_for_card_ref(uint16_t card_ref) const;
|
||||
|
||||
uint16_t draw_card();
|
||||
bool draw_card_by_ref(uint16_t card_ref);
|
||||
bool set_card_ref_in_play(uint16_t card_ref);
|
||||
bool set_card_ref_drawable_next(uint16_t card_ref);
|
||||
bool set_card_ref_drawable_at_end(uint16_t card_ref);
|
||||
void set_card_discarded(uint16_t card_ref);
|
||||
|
||||
void restart();
|
||||
void shuffle();
|
||||
void do_mulligan();
|
||||
|
||||
void print(FILE* stream, std::shared_ptr<const CardIndex> card_index = nullptr) const;
|
||||
|
||||
private:
|
||||
struct CardEntry {
|
||||
uint16_t card_id;
|
||||
uint8_t deck_index;
|
||||
CardState state;
|
||||
};
|
||||
uint8_t client_id;
|
||||
uint8_t draw_index;
|
||||
uint16_t card_ref_base;
|
||||
bool shuffle_enabled;
|
||||
bool loop_enabled;
|
||||
parray<CardEntry, 31> entries;
|
||||
parray<uint16_t, 31> card_refs;
|
||||
|
||||
std::shared_ptr<PSOLFGEncryption> random_crypt;
|
||||
};
|
||||
|
||||
} // namespace Episode3
|
||||
@@ -0,0 +1,84 @@
|
||||
#include "MapState.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
MapState::MapState() {
|
||||
this->clear();
|
||||
}
|
||||
|
||||
void MapState::clear() {
|
||||
this->width = 0;
|
||||
this->height = 0;
|
||||
for (size_t y = 0; y < this->tiles.size(); y++) {
|
||||
this->tiles[y].clear(0);
|
||||
}
|
||||
for (size_t z = 0; z < 2; z++) {
|
||||
this->start_tile_definitions[z].clear(0);
|
||||
}
|
||||
}
|
||||
|
||||
void MapState::print(FILE* stream) const {
|
||||
fprintf(stream, "[Map: w=%hu h=%hu]\n", this->width.load(), this->height.load());
|
||||
for (size_t y = 0; y < this->height; y++) {
|
||||
fputc(' ', stream);
|
||||
for (size_t x = 0; x < this->width; x++) {
|
||||
fprintf(stream, " %02hhX", this->tiles[y][x]);
|
||||
}
|
||||
fputc('\n', stream);
|
||||
}
|
||||
}
|
||||
|
||||
MapAndRulesState::MapAndRulesState() {
|
||||
this->clear();
|
||||
}
|
||||
|
||||
void MapAndRulesState::clear() {
|
||||
this->map.clear();
|
||||
this->num_players = 0;
|
||||
this->unused1 = 0;
|
||||
this->environment_number = 0;
|
||||
this->num_players_per_team = 0;
|
||||
this->num_team0_players = 0;
|
||||
this->unused2 = 0;
|
||||
this->start_facing_directions = 0;
|
||||
this->unused3 = 0;
|
||||
this->map_number = 0;
|
||||
this->unused4 = 0;
|
||||
this->rules.clear();
|
||||
}
|
||||
|
||||
bool MapAndRulesState::loc_is_within_bounds(uint8_t x, uint8_t y) const {
|
||||
return (x < this->map.width) && (y < this->map.height);
|
||||
}
|
||||
|
||||
bool MapAndRulesState::tile_is_vacant(uint8_t x, uint8_t y) {
|
||||
if (!this->loc_is_within_bounds(x, y)) {
|
||||
return false;
|
||||
}
|
||||
return (this->map.tiles[y][x] == 1);
|
||||
}
|
||||
|
||||
void MapAndRulesState::set_occupied_bit_for_tile(uint8_t x, uint8_t y) {
|
||||
this->map.tiles[y][x] |= 0x10;
|
||||
}
|
||||
|
||||
void MapAndRulesState::clear_occupied_bit_for_tile(uint8_t x, uint8_t y) {
|
||||
this->map.tiles[y][x] &= 0xEF;
|
||||
}
|
||||
|
||||
OverlayState::OverlayState() {
|
||||
this->clear();
|
||||
}
|
||||
|
||||
void OverlayState::clear() {
|
||||
for (size_t y = 0; y < this->tiles.size(); y++) {
|
||||
this->tiles[y].clear(0);
|
||||
}
|
||||
this->unused1.clear(0);
|
||||
this->unused2.clear(0);
|
||||
this->unused3.clear(0);
|
||||
}
|
||||
|
||||
} // namespace Episode3
|
||||
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "../Text.hh"
|
||||
#include "DataIndexes.hh"
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
struct MapState {
|
||||
le_uint16_t width;
|
||||
le_uint16_t height;
|
||||
parray<parray<uint8_t, 0x10>, 0x10> tiles;
|
||||
parray<parray<uint8_t, 6>, 2> start_tile_definitions;
|
||||
|
||||
MapState();
|
||||
void clear();
|
||||
|
||||
void print(FILE* stream) const;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct MapAndRulesState {
|
||||
MapState map;
|
||||
uint8_t num_players;
|
||||
uint8_t unused1;
|
||||
uint8_t environment_number;
|
||||
uint8_t num_players_per_team;
|
||||
uint8_t num_team0_players;
|
||||
uint8_t unused2;
|
||||
le_uint16_t start_facing_directions;
|
||||
uint32_t unused3;
|
||||
le_uint32_t map_number;
|
||||
uint32_t unused4;
|
||||
Rules rules;
|
||||
|
||||
MapAndRulesState();
|
||||
void clear();
|
||||
|
||||
bool loc_is_within_bounds(uint8_t x, uint8_t y) const;
|
||||
bool tile_is_vacant(uint8_t x, uint8_t y);
|
||||
|
||||
void set_occupied_bit_for_tile(uint8_t x, uint8_t y);
|
||||
void clear_occupied_bit_for_tile(uint8_t x, uint8_t y);
|
||||
} __attribute__((packed));
|
||||
|
||||
struct OverlayState {
|
||||
parray<parray<uint8_t, 0x10>, 0x10> tiles;
|
||||
parray<le_uint32_t, 5> unused1;
|
||||
parray<le_uint32_t, 0x10> unused2;
|
||||
parray<le_uint16_t, 0x10> unused3;
|
||||
|
||||
OverlayState();
|
||||
void clear();
|
||||
} __attribute__((packed));
|
||||
|
||||
} // namespace Episode3
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,214 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "../Text.hh"
|
||||
#include "Card.hh"
|
||||
#include "DataIndexes.hh"
|
||||
#include "DeckState.hh"
|
||||
#include "PlayerStateSubordinates.hh"
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
class Server;
|
||||
|
||||
enum AssistFlag : uint32_t {
|
||||
// Note: This enum is a uint32_t even though only 16 bits are used because
|
||||
// the corresponding field in the protocol is a 32-bit field. There may also
|
||||
// be bits used only by the client which are not documented here.
|
||||
|
||||
// clang-format off
|
||||
READY_TO_END_PHASE = 0x0001,
|
||||
DICE_WERE_EXCHANGED = 0x0002,
|
||||
HAS_WON_BATTLE = 0x0004,
|
||||
READY_TO_END_STARTER_ROLL_PHASE = 0x0008,
|
||||
FIXED_RANGE = 0x0010,
|
||||
SUMMONING_IS_FREE = 0x0020,
|
||||
LIMIT_MOVE_TO_1 = 0x0040,
|
||||
IS_SKIPPING_TURN = 0x0080,
|
||||
IMMORTAL = 0x0100,
|
||||
SAME_CARD_BANNED = 0x0200,
|
||||
CANNOT_SET_FIELD_CHARACTERS = 0x0400,
|
||||
WINNER_DECIDED_BY_DEFEAT = 0x0800,
|
||||
WINNER_DECIDED_BY_RANDOM = 0x1000,
|
||||
READY_TO_END_ACTION_PHASE = 0x2000,
|
||||
BATTLE_DID_NOT_END_DUE_TO_TIME_LIMIT = 0x4000,
|
||||
ELIGIBLE_FOR_DICE_BOOST = 0x8000,
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
class PlayerState : public std::enable_shared_from_this<PlayerState> {
|
||||
public:
|
||||
PlayerState(uint8_t client_id, std::shared_ptr<Server> server);
|
||||
void init();
|
||||
std::shared_ptr<Server> server();
|
||||
std::shared_ptr<const Server> server() const;
|
||||
|
||||
bool draw_cards_allowed() const;
|
||||
void apply_assist_card_effect_on_set(std::shared_ptr<PlayerState> setter_ps);
|
||||
void apply_dice_effects();
|
||||
uint16_t card_ref_for_hand_index(size_t hand_index) const;
|
||||
int16_t compute_attack_or_defense_atk_costs(const ActionState& pa) const;
|
||||
void compute_total_set_cards_cost();
|
||||
size_t count_set_cards() const;
|
||||
size_t count_set_refs() const;
|
||||
void discard_all_assist_cards_from_hand();
|
||||
void discard_all_attack_action_cards_from_hand();
|
||||
void discard_all_item_and_creature_cards_from_hand();
|
||||
void discard_and_redraw_hand();
|
||||
bool discard_card_or_add_to_draw_pile(
|
||||
uint16_t card_ref, bool add_to_draw_pile);
|
||||
void discard_random_hand_card();
|
||||
bool discard_ref_from_hand(uint16_t card_ref);
|
||||
void discard_set_assist_card();
|
||||
bool do_mulligan();
|
||||
void draw_hand(ssize_t override_count = 0);
|
||||
void draw_initial_hand();
|
||||
int32_t error_code_for_client_setting_card(
|
||||
uint16_t card_ref,
|
||||
uint8_t card_index,
|
||||
const Location* loc,
|
||||
uint8_t assist_target_client_id) const;
|
||||
std::vector<uint16_t> get_all_cards_within_range(
|
||||
const parray<uint8_t, 9 * 9>& range,
|
||||
const Location& loc,
|
||||
uint8_t target_team_id) const;
|
||||
uint8_t get_atk_points() const;
|
||||
void get_short_status_for_card_index_in_hand(
|
||||
size_t hand_index, CardShortStatus* stat) const;
|
||||
std::shared_ptr<DeckState> get_deck();
|
||||
uint8_t get_def_points() const;
|
||||
uint8_t get_dice_result(size_t which) const;
|
||||
size_t get_hand_size() const;
|
||||
uint16_t get_sc_card_id() const;
|
||||
std::shared_ptr<Card> get_sc_card();
|
||||
std::shared_ptr<const Card> get_sc_card() const;
|
||||
uint16_t get_sc_card_ref() const;
|
||||
CardType get_sc_card_type() const;
|
||||
std::shared_ptr<Card> get_set_card(size_t set_index);
|
||||
std::shared_ptr<const Card> get_set_card(size_t set_index) const;
|
||||
uint16_t get_set_ref(size_t set_index) const;
|
||||
uint8_t get_team_id() const;
|
||||
ssize_t hand_index_for_card_ref(uint16_t card_ref) const;
|
||||
size_t set_index_for_card_ref(uint16_t card_ref) const;
|
||||
bool is_mulligan_allowed() const;
|
||||
bool is_team_turn() const;
|
||||
void log_discard(uint16_t card_ref, uint16_t reason);
|
||||
bool move_card_to_location_by_card_index(
|
||||
size_t card_index, const Location& new_loc);
|
||||
void move_null_hand_refs_to_end();
|
||||
void on_cards_destroyed();
|
||||
void replace_all_set_assists_with_random_assists();
|
||||
bool replace_assist_card_by_id(uint16_t card_id);
|
||||
bool return_set_card_to_hand2(uint16_t card_ref);
|
||||
bool return_set_card_to_hand1(uint16_t card_ref);
|
||||
uint8_t roll_dice(size_t num_dice);
|
||||
uint8_t roll_dice_with_effects(size_t num_dice);
|
||||
void send_set_card_updates(bool always_send = false);
|
||||
void set_assist_flags_from_assist_effects();
|
||||
bool set_card_from_hand(
|
||||
uint16_t card_ref,
|
||||
uint8_t card_index,
|
||||
const Location* loc,
|
||||
uint8_t assist_target_client_id,
|
||||
bool skip_error_checks_and_atk_sub);
|
||||
void set_initial_location();
|
||||
void set_map_occupied_bit_for_card_on_warp_tile(
|
||||
std::shared_ptr<const Card> card);
|
||||
void set_map_occupied_bits_for_sc_and_creatures();
|
||||
void subtract_def_points(uint8_t cost);
|
||||
bool subtract_or_check_atk_or_def_points_for_action(
|
||||
const ActionState& pa, bool deduct_points);
|
||||
void subtract_atk_points(uint8_t cost);
|
||||
G_UpdateHand_GC_Ep3_6xB4x02 prepare_6xB4x02() const;
|
||||
void update_hand_and_equip_state_and_send_6xB4x02_if_needed(
|
||||
bool always_send = false);
|
||||
void set_random_assist_card_from_hand_for_free();
|
||||
G_UpdateShortStatuses_GC_Ep3_6xB4x04 prepare_6xB4x04() const;
|
||||
void send_6xB4x04_if_needed(bool always_send = false);
|
||||
std::vector<uint16_t> get_card_refs_within_range_from_all_players(
|
||||
const parray<uint8_t, 9 * 9>& range,
|
||||
const Location& loc,
|
||||
CardType type) const;
|
||||
void unknown_80239460();
|
||||
void unknown_802394C4();
|
||||
void unknown_80239528();
|
||||
void handle_before_turn_assist_effects();
|
||||
int16_t get_assist_turns_remaining();
|
||||
bool set_action_cards_for_action_state(const ActionState& pa);
|
||||
void unknown_8023C174();
|
||||
void handle_homesick_assist_effect(std::shared_ptr<Card> card);
|
||||
void apply_main_die_assist_effects(uint8_t* die_value) const;
|
||||
void roll_main_dice();
|
||||
void unknown_8023C110();
|
||||
void compute_team_dice_boost_after_draw_phase();
|
||||
|
||||
private:
|
||||
std::weak_ptr<Server> w_server;
|
||||
|
||||
public:
|
||||
std::shared_ptr<Card> sc_card;
|
||||
std::shared_ptr<Card> set_cards[8];
|
||||
uint8_t client_id;
|
||||
uint16_t num_mulligans_allowed;
|
||||
CardType sc_card_type;
|
||||
uint8_t team_id;
|
||||
uint8_t atk_points;
|
||||
uint8_t def_points;
|
||||
uint8_t atk_points2;
|
||||
uint8_t atk_points2_max;
|
||||
uint8_t atk_bonuses;
|
||||
uint8_t def_bonuses;
|
||||
parray<uint8_t, 2> dice_results;
|
||||
uint8_t unknown_a4;
|
||||
uint8_t dice_max;
|
||||
uint8_t total_set_cards_cost;
|
||||
uint16_t sc_card_id;
|
||||
uint16_t sc_card_ref;
|
||||
|
||||
// This array is unfortunately heterogeneous; specifically:
|
||||
// [0] through [5] are hand refs
|
||||
// [6] is the current assist card ref (which may belong to another player)
|
||||
// [7] is the previous assist card ref
|
||||
// [8] through [15] are set refs
|
||||
parray<uint16_t, 0x10> card_refs;
|
||||
|
||||
std::shared_ptr<DeckState> deck_state;
|
||||
parray<uint16_t, 0x10> discard_log_card_refs;
|
||||
parray<uint16_t, 0x10> discard_log_reasons;
|
||||
uint8_t assist_remaining_turns;
|
||||
uint16_t assist_card_set_number;
|
||||
uint16_t set_assist_card_id;
|
||||
bool god_whim_can_use_hidden_cards;
|
||||
ActionChainWithConds unknown_a12;
|
||||
ActionMetadata unknown_a13;
|
||||
uint32_t unknown_a14;
|
||||
uint32_t assist_flags;
|
||||
uint8_t assist_delay_turns;
|
||||
Direction start_facing_direction;
|
||||
std::shared_ptr<HandAndEquipState> hand_and_equip;
|
||||
|
||||
// Like card_refs above, these arrays are also heterogeneous, but the indices
|
||||
// are not the same as for card_refs! THe indices here are:
|
||||
// [0] is the SC card status
|
||||
// [1] through [6] are hand cards
|
||||
// [7] through [14] are set cards
|
||||
// [15] is the assist card
|
||||
std::shared_ptr<parray<CardShortStatus, 0x10>> card_short_statuses;
|
||||
parray<CardShortStatus, 0x10> prev_card_short_statuses;
|
||||
|
||||
// In these arrays, [0] is the SC card and the rest are the set cards.
|
||||
std::shared_ptr<parray<ActionChainWithConds, 9>> set_card_action_chains;
|
||||
std::shared_ptr<parray<ActionMetadata, 9>> set_card_action_metadatas;
|
||||
parray<ActionChainWithConds, 9> prev_set_card_action_chains;
|
||||
parray<ActionMetadata, 9> prev_set_card_action_metadatas;
|
||||
|
||||
uint32_t num_destroyed_fcs;
|
||||
uint8_t unknown_a16;
|
||||
uint8_t unknown_a17;
|
||||
PlayerBattleStats stats;
|
||||
};
|
||||
|
||||
} // namespace Episode3
|
||||
@@ -0,0 +1,835 @@
|
||||
#include "PlayerState.hh"
|
||||
|
||||
#include "Server.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
template <size_t Count>
|
||||
std::string string_for_refs(const parray<le_uint16_t, Count>& card_refs) {
|
||||
string ret = "[";
|
||||
for (size_t z = 0; z < Count; z++) {
|
||||
if (card_refs[z] != 0xFFFF) {
|
||||
ret += string_printf("%zu:@$%04X ", z, card_refs[z].load());
|
||||
}
|
||||
}
|
||||
if (!ret.empty()) {
|
||||
ret.back() = ']'; // Replace the ' ' from the last added item
|
||||
} else {
|
||||
ret.push_back(']');
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Condition::Condition() {
|
||||
this->clear();
|
||||
}
|
||||
|
||||
bool Condition::operator==(const Condition& other) const {
|
||||
return (this->type == other.type) &&
|
||||
(this->remaining_turns == other.remaining_turns) &&
|
||||
(this->a_arg_value == other.a_arg_value) &&
|
||||
(this->dice_roll_value == other.dice_roll_value) &&
|
||||
(this->flags == other.flags) &&
|
||||
(this->card_definition_effect_index == other.card_definition_effect_index) &&
|
||||
(this->card_ref == other.card_ref) &&
|
||||
(this->value == other.value) &&
|
||||
(this->condition_giver_card_ref == other.condition_giver_card_ref) &&
|
||||
(this->random_percent == other.random_percent) &&
|
||||
(this->value8 == other.value8) &&
|
||||
(this->order == other.order) &&
|
||||
(this->unknown_a8 == other.unknown_a8);
|
||||
}
|
||||
bool Condition::operator!=(const Condition& other) const {
|
||||
return !this->operator==(other);
|
||||
}
|
||||
|
||||
void Condition::clear() {
|
||||
this->type = ConditionType::NONE;
|
||||
this->remaining_turns = 0;
|
||||
this->a_arg_value = 0;
|
||||
this->dice_roll_value = 0;
|
||||
this->flags = 0;
|
||||
this->card_definition_effect_index = 0;
|
||||
this->card_ref = 0xFFFF;
|
||||
this->value = 0;
|
||||
this->condition_giver_card_ref = 0xFFFF;
|
||||
this->random_percent = 0;
|
||||
this->value8 = 0;
|
||||
this->order = 0;
|
||||
this->unknown_a8 = 0;
|
||||
}
|
||||
|
||||
void Condition::clear_FF() {
|
||||
this->type = ConditionType::INVALID_FF;
|
||||
this->remaining_turns = 0xFF;
|
||||
this->a_arg_value = -1;
|
||||
this->dice_roll_value = 0xFF;
|
||||
this->flags = 0xFF;
|
||||
this->card_definition_effect_index = 0xFF;
|
||||
this->card_ref = 0xFFFF;
|
||||
this->value = -1;
|
||||
this->condition_giver_card_ref = 0xFFFF;
|
||||
this->random_percent = 0xFF;
|
||||
this->value8 = -1;
|
||||
this->order = 0xFF;
|
||||
this->unknown_a8 = 0xFF;
|
||||
}
|
||||
|
||||
std::string Condition::str() const {
|
||||
return string_printf(
|
||||
"Condition[type=%s, turns=%hhu, a_arg=%hhd, dice=%hhu, flags=%02hhX, "
|
||||
"def_eff_index=%hhu, ref=@%04hX, value=%hd, giver_ref=@%04hX "
|
||||
"percent=%hhu value8=%hd order=%hu a8=%hu]",
|
||||
name_for_condition_type(this->type),
|
||||
this->remaining_turns,
|
||||
this->a_arg_value,
|
||||
this->dice_roll_value,
|
||||
this->flags,
|
||||
this->card_definition_effect_index,
|
||||
this->card_ref.load(),
|
||||
this->value.load(),
|
||||
this->condition_giver_card_ref.load(),
|
||||
this->random_percent,
|
||||
this->value8,
|
||||
this->order,
|
||||
this->unknown_a8);
|
||||
}
|
||||
|
||||
EffectResult::EffectResult() {
|
||||
this->clear();
|
||||
}
|
||||
|
||||
void EffectResult::clear() {
|
||||
this->attacker_card_ref = 0xFFFF;
|
||||
this->target_card_ref = 0xFFFF;
|
||||
this->value = 0;
|
||||
this->current_hp = 0;
|
||||
this->ap = 0;
|
||||
this->tp = 0;
|
||||
this->flags = 0;
|
||||
this->operation = 0;
|
||||
this->condition_index = 0;
|
||||
this->dice_roll_value = 0;
|
||||
}
|
||||
|
||||
std::string EffectResult::str() const {
|
||||
return string_printf(
|
||||
"EffectResult[att_ref=@%04hX, target_ref=@%04hX, value=%hhd, "
|
||||
"cur_hp=%hhd, ap=%hhd, tp=%hhd, flags=%02hhX, op=%hhd, "
|
||||
"cond_index=%hhu, dice=%hhu]",
|
||||
this->attacker_card_ref.load(),
|
||||
this->target_card_ref.load(),
|
||||
this->value,
|
||||
this->current_hp,
|
||||
this->ap,
|
||||
this->tp,
|
||||
this->flags,
|
||||
this->operation,
|
||||
this->condition_index,
|
||||
this->dice_roll_value);
|
||||
}
|
||||
|
||||
CardShortStatus::CardShortStatus() {
|
||||
this->clear();
|
||||
}
|
||||
|
||||
bool CardShortStatus::operator==(const CardShortStatus& other) const {
|
||||
return (this->card_ref == other.card_ref) &&
|
||||
(this->current_hp == other.current_hp) &&
|
||||
(this->card_flags == other.card_flags) &&
|
||||
(this->loc == other.loc) &&
|
||||
(this->unused1 == other.unused1) &&
|
||||
(this->max_hp == other.max_hp) &&
|
||||
(this->unused2 == other.unused2);
|
||||
}
|
||||
bool CardShortStatus::operator!=(const CardShortStatus& other) const {
|
||||
return !this->operator==(other);
|
||||
}
|
||||
|
||||
std::string CardShortStatus::str() const {
|
||||
string loc_s = this->loc.str();
|
||||
return string_printf(
|
||||
"CardShortStatus[ref=@%04hX, cur_hp=%hd, flags=%08" PRIX32 ", loc=%s, "
|
||||
"u1=%04hX, max_hp=%hhd, u2=%hhu]",
|
||||
this->card_ref.load(),
|
||||
this->current_hp.load(),
|
||||
this->card_flags.load(),
|
||||
loc_s.c_str(),
|
||||
this->unused1.load(),
|
||||
this->max_hp,
|
||||
this->unused2);
|
||||
}
|
||||
|
||||
void CardShortStatus::clear() {
|
||||
this->card_ref = 0xFFFF;
|
||||
this->current_hp = 0;
|
||||
this->card_flags = 0;
|
||||
this->loc.clear();
|
||||
this->unused1 = 0xFFFF;
|
||||
this->max_hp = 0;
|
||||
this->unused2 = 0;
|
||||
}
|
||||
|
||||
void CardShortStatus::clear_FF() {
|
||||
this->card_ref = 0xFFFF;
|
||||
this->current_hp = 0xFFFF;
|
||||
this->card_flags = 0xFFFFFFFF;
|
||||
this->loc.clear_FF();
|
||||
this->unused1 = 0xFFFF;
|
||||
this->max_hp = -1;
|
||||
this->unused2 = 0xFF;
|
||||
}
|
||||
|
||||
ActionState::ActionState() {
|
||||
this->clear();
|
||||
}
|
||||
|
||||
void ActionState::clear() {
|
||||
this->client_id = 0xFFFF;
|
||||
this->unused = 0;
|
||||
this->facing_direction = Direction::RIGHT;
|
||||
this->attacker_card_ref = 0xFFFF;
|
||||
this->defense_card_ref = 0xFFFF;
|
||||
this->original_attacker_card_ref = 0xFFFF;
|
||||
this->target_card_refs.clear(0xFFFF);
|
||||
this->action_card_refs.clear(0xFFFF);
|
||||
}
|
||||
|
||||
std::string ActionState::str() const {
|
||||
string target_refs_s = string_for_refs(this->target_card_refs);
|
||||
string action_refs_s = string_for_refs(this->action_card_refs);
|
||||
return string_printf(
|
||||
"ActionState[client=%hu, u=%hhu, facing=%s, attacker_ref=@%04hX, "
|
||||
"def_ref=@%04hX, target_refs=%s, action_refs=%s, "
|
||||
"orig_attacker_ref=@%04hX]",
|
||||
this->client_id.load(),
|
||||
this->unused,
|
||||
name_for_direction(this->facing_direction),
|
||||
this->attacker_card_ref.load(),
|
||||
this->defense_card_ref.load(),
|
||||
target_refs_s.c_str(),
|
||||
action_refs_s.c_str(),
|
||||
this->original_attacker_card_ref.load());
|
||||
}
|
||||
|
||||
ActionChain::ActionChain() {
|
||||
this->clear();
|
||||
}
|
||||
|
||||
bool ActionChain::operator==(const ActionChain& other) const {
|
||||
return (this->effective_ap == other.effective_ap) &&
|
||||
(this->effective_tp == other.effective_tp) &&
|
||||
(this->ap_effect_bonus == other.ap_effect_bonus) &&
|
||||
(this->damage == other.damage) &&
|
||||
(this->acting_card_ref == other.acting_card_ref) &&
|
||||
(this->unknown_card_ref_a3 == other.unknown_card_ref_a3) &&
|
||||
(this->attack_action_card_refs == other.attack_action_card_refs) &&
|
||||
(this->attack_action_card_ref_count == other.attack_action_card_ref_count) &&
|
||||
(this->attack_medium == other.attack_medium) &&
|
||||
(this->target_card_ref_count == other.target_card_ref_count) &&
|
||||
(this->action_subphase == other.action_subphase) &&
|
||||
(this->strike_count == other.strike_count) &&
|
||||
(this->damage_multiplier == other.damage_multiplier) &&
|
||||
(this->attack_number == other.attack_number) &&
|
||||
(this->tp_effect_bonus == other.tp_effect_bonus) &&
|
||||
(this->unused1 == other.unused1) &&
|
||||
(this->unused2 == other.unused2) &&
|
||||
(this->card_ap == other.card_ap) &&
|
||||
(this->card_tp == other.card_tp) &&
|
||||
(this->flags == other.flags) &&
|
||||
(this->target_card_refs == other.target_card_refs);
|
||||
}
|
||||
bool ActionChain::operator!=(const ActionChain& other) const {
|
||||
return !this->operator==(other);
|
||||
}
|
||||
|
||||
std::string ActionChain::str() const {
|
||||
string attack_action_card_refs_s = string_for_refs(this->attack_action_card_refs);
|
||||
string target_card_refs_s = string_for_refs(this->target_card_refs);
|
||||
return string_printf(
|
||||
"ActionChain[eff_ap=%hhd, eff_tp=%hhd, ap_bonus=%hhd, damage=%hhd, "
|
||||
"acting_ref=@%04hX, unknown_ref_a3=@%04hX, "
|
||||
"attack_action_refs=%s, attack_action_ref_count=%hhu, "
|
||||
"medium=%s, target_ref_count=%hhu, subphase=%s, "
|
||||
"strikes=%hhu, damage_mult=%hhd, attack_num=%hhu, "
|
||||
"tp_bonus=%hhd, u1=%hhu, u2=%hhu, card_ap=%hhd, "
|
||||
"card_tp=%hhd, flags=%08" PRIX32 ", target_refs=%s]",
|
||||
this->effective_ap,
|
||||
this->effective_tp,
|
||||
this->ap_effect_bonus,
|
||||
this->damage,
|
||||
this->acting_card_ref.load(),
|
||||
this->unknown_card_ref_a3.load(),
|
||||
attack_action_card_refs_s.c_str(),
|
||||
this->attack_action_card_ref_count,
|
||||
name_for_attack_medium(this->attack_medium),
|
||||
this->target_card_ref_count,
|
||||
name_for_action_subphase(this->action_subphase),
|
||||
this->strike_count,
|
||||
this->damage_multiplier,
|
||||
this->attack_number,
|
||||
this->tp_effect_bonus,
|
||||
this->unused1,
|
||||
this->unused2,
|
||||
this->card_ap,
|
||||
this->card_tp,
|
||||
this->flags.load(),
|
||||
target_card_refs_s.c_str());
|
||||
}
|
||||
|
||||
void ActionChain::clear() {
|
||||
this->effective_ap = 0;
|
||||
this->effective_tp = 0;
|
||||
this->ap_effect_bonus = 0;
|
||||
this->damage = 0;
|
||||
this->acting_card_ref = 0xFFFF;
|
||||
this->unknown_card_ref_a3 = 0xFFFF;
|
||||
this->attack_action_card_ref_count = 0;
|
||||
this->attack_medium = AttackMedium::UNKNOWN;
|
||||
this->target_card_ref_count = 0;
|
||||
this->action_subphase = ActionSubphase::INVALID_FF;
|
||||
this->strike_count = 1;
|
||||
this->damage_multiplier = 1;
|
||||
this->attack_number = 0xFF;
|
||||
this->tp_effect_bonus = 0;
|
||||
this->unused1 = 0;
|
||||
this->unused2 = 0;
|
||||
this->card_ap = 0;
|
||||
this->card_tp = 0;
|
||||
this->flags = 0;
|
||||
this->attack_action_card_refs.clear(0xFFFF);
|
||||
this->target_card_refs.clear(0xFFFF);
|
||||
}
|
||||
|
||||
void ActionChain::clear_FF() {
|
||||
this->effective_ap = -1;
|
||||
this->effective_tp = -1;
|
||||
this->ap_effect_bonus = -1;
|
||||
this->damage = -1;
|
||||
this->acting_card_ref = 0xFFFF;
|
||||
this->unknown_card_ref_a3 = 0xFFFF;
|
||||
this->attack_action_card_refs.clear(0xFFFF);
|
||||
this->attack_action_card_ref_count = 0xFF;
|
||||
this->attack_medium = AttackMedium::INVALID_FF;
|
||||
this->target_card_ref_count = 0xFF;
|
||||
this->action_subphase = ActionSubphase::INVALID_FF;
|
||||
this->strike_count = 0xFF;
|
||||
this->damage_multiplier = -1;
|
||||
this->attack_number = 0xFF;
|
||||
this->tp_effect_bonus = -1;
|
||||
this->unused1 = 0xFF;
|
||||
this->unused2 = 0xFF;
|
||||
this->card_ap = -1;
|
||||
this->card_tp = -1;
|
||||
this->flags = 0xFFFFFFFF;
|
||||
this->target_card_refs.clear(0xFFFF);
|
||||
}
|
||||
|
||||
ActionChainWithConds::ActionChainWithConds() {
|
||||
this->clear();
|
||||
}
|
||||
|
||||
bool ActionChainWithConds::operator==(const ActionChainWithConds& other) const {
|
||||
return (this->chain == other.chain && this->conditions == other.conditions);
|
||||
}
|
||||
bool ActionChainWithConds::operator!=(const ActionChainWithConds& other) const {
|
||||
return !this->operator==(other);
|
||||
}
|
||||
|
||||
std::string ActionChainWithConds::str() const {
|
||||
string ret = "ActionChainWithConds[chain=";
|
||||
ret += this->chain.str();
|
||||
ret += ", conds=[";
|
||||
for (size_t z = 0; z < this->conditions.size(); z++) {
|
||||
if (this->conditions[z].type != ConditionType::NONE) {
|
||||
if (ret.back() != '=') {
|
||||
ret += ", ";
|
||||
}
|
||||
ret += string_printf("%zu:", z);
|
||||
ret += this->conditions[z].str();
|
||||
}
|
||||
}
|
||||
ret += "]]";
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ActionChainWithConds::clear() {
|
||||
this->chain.effective_ap = 0;
|
||||
this->chain.effective_tp = 0;
|
||||
this->chain.ap_effect_bonus = 0;
|
||||
this->chain.damage = 0;
|
||||
this->clear_inner();
|
||||
}
|
||||
|
||||
void ActionChainWithConds::clear_FF() {
|
||||
this->chain.clear_FF();
|
||||
for (size_t z = 0; z < 9; z++) {
|
||||
this->conditions[z].clear_FF();
|
||||
}
|
||||
}
|
||||
|
||||
void ActionChainWithConds::clear_inner() {
|
||||
this->chain.unknown_card_ref_a3 = 0xFFFF;
|
||||
this->chain.acting_card_ref = 0xFFFF;
|
||||
this->chain.attack_medium = AttackMedium::INVALID_FF;
|
||||
this->chain.flags = 0;
|
||||
this->chain.action_subphase = ActionSubphase::INVALID_FF;
|
||||
this->chain.attack_number = 0xFF;
|
||||
this->reset();
|
||||
this->clear_target_card_refs();
|
||||
this->chain.attack_action_card_ref_count = 0;
|
||||
this->chain.attack_action_card_refs.clear(0xFFFF);
|
||||
}
|
||||
|
||||
void ActionChainWithConds::clear_target_card_refs() {
|
||||
this->chain.target_card_ref_count = 0;
|
||||
this->chain.target_card_refs.clear(0xFFFF);
|
||||
}
|
||||
|
||||
void ActionChainWithConds::reset() {
|
||||
this->chain.effective_ap = 0;
|
||||
this->chain.effective_tp = 0;
|
||||
this->chain.ap_effect_bonus = 0;
|
||||
this->chain.tp_effect_bonus = 0;
|
||||
this->chain.unused1 = 0;
|
||||
this->chain.unused2 = 0;
|
||||
this->chain.damage = 0;
|
||||
this->chain.strike_count = 1;
|
||||
this->chain.damage_multiplier = 1;
|
||||
}
|
||||
|
||||
bool ActionChainWithConds::check_flag(uint32_t flags) const {
|
||||
return (this->chain.flags & flags) != 0;
|
||||
}
|
||||
|
||||
void ActionChainWithConds::clear_flags(uint32_t flags) {
|
||||
this->chain.flags &= ~flags;
|
||||
}
|
||||
|
||||
void ActionChainWithConds::set_flags(uint32_t flags) {
|
||||
this->chain.flags |= flags;
|
||||
}
|
||||
|
||||
void ActionChainWithConds::add_attack_action_card_ref(
|
||||
uint16_t card_ref, shared_ptr<Server> server) {
|
||||
if (card_ref != 0xFFFF) {
|
||||
this->chain.attack_action_card_refs[this->chain.attack_action_card_ref_count++] = card_ref;
|
||||
}
|
||||
this->set_flags(8);
|
||||
this->chain.action_subphase = server->get_current_action_subphase();
|
||||
}
|
||||
|
||||
void ActionChainWithConds::add_target_card_ref(uint16_t card_ref) {
|
||||
if (card_ref != 0xFFFF &&
|
||||
this->chain.target_card_ref_count < this->chain.target_card_refs.size()) {
|
||||
this->chain.target_card_refs[this->chain.target_card_ref_count++] = card_ref;
|
||||
}
|
||||
}
|
||||
|
||||
void ActionChainWithConds::compute_attack_medium(shared_ptr<Server> server) {
|
||||
this->chain.attack_medium = AttackMedium::PHYSICAL;
|
||||
for (size_t z = 0; z < this->chain.attack_action_card_ref_count; z++) {
|
||||
uint16_t card_ref = this->chain.attack_action_card_refs[z];
|
||||
if (card_ref == 0xFFFF) {
|
||||
break;
|
||||
}
|
||||
auto ce = server->definition_for_card_ref(card_ref);
|
||||
if (!ce) {
|
||||
continue;
|
||||
}
|
||||
if (card_class_is_tech_like(ce->def.card_class())) {
|
||||
this->chain.attack_medium = AttackMedium::TECH;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ActionChainWithConds::get_condition_value(
|
||||
ConditionType cond_type,
|
||||
uint16_t card_ref,
|
||||
uint8_t def_effect_index,
|
||||
uint16_t value,
|
||||
uint16_t* out_value) const {
|
||||
bool any_found = false;
|
||||
uint8_t max_order = 10;
|
||||
for (size_t z = 0; z < 9; z++) {
|
||||
auto& cond = this->conditions[z];
|
||||
if (((cond_type == ConditionType::ANY) || (cond.type == cond_type)) &&
|
||||
((def_effect_index == 0xFF) || (cond.card_definition_effect_index == def_effect_index)) &&
|
||||
((card_ref == 0xFFFF) || (cond.card_ref == card_ref)) &&
|
||||
((value == 0xFFFF) || (cond.value == value))) {
|
||||
if (!any_found || (max_order < cond.order)) {
|
||||
if (!out_value) {
|
||||
return true;
|
||||
}
|
||||
*out_value = cond.value;
|
||||
max_order = cond.order;
|
||||
}
|
||||
any_found = true;
|
||||
}
|
||||
}
|
||||
return any_found;
|
||||
}
|
||||
|
||||
void ActionChainWithConds::set_action_subphase_from_card(
|
||||
shared_ptr<const Card> card) {
|
||||
this->chain.action_subphase = card->server()->get_current_action_subphase();
|
||||
}
|
||||
|
||||
bool ActionChainWithConds::can_apply_attack() const {
|
||||
return this->check_flag(4) ? false : (this->chain.target_card_ref_count != 0);
|
||||
}
|
||||
|
||||
ActionMetadata::ActionMetadata() {
|
||||
this->clear();
|
||||
}
|
||||
|
||||
bool ActionMetadata::operator==(const ActionMetadata& other) const {
|
||||
return (this->card_ref == other.card_ref) &&
|
||||
(this->target_card_ref_count == other.target_card_ref_count) &&
|
||||
(this->defense_card_ref_count == other.defense_card_ref_count) &&
|
||||
(this->action_subphase == other.action_subphase) &&
|
||||
(this->defense_power == other.defense_power) &&
|
||||
(this->defense_bonus == other.defense_bonus) &&
|
||||
(this->attack_bonus == other.attack_bonus) &&
|
||||
(this->flags == other.flags) &&
|
||||
(this->target_card_refs == other.target_card_refs) &&
|
||||
(this->defense_card_refs == other.defense_card_refs) &&
|
||||
(this->original_attacker_card_refs == other.original_attacker_card_refs);
|
||||
}
|
||||
bool ActionMetadata::operator!=(const ActionMetadata& other) const {
|
||||
return !this->operator==(other);
|
||||
}
|
||||
|
||||
std::string ActionMetadata::str() const {
|
||||
string target_card_refs_s = string_for_refs(this->target_card_refs);
|
||||
string defense_card_refs_s = string_for_refs(this->defense_card_refs);
|
||||
string original_attacker_card_refs_s = string_for_refs(this->original_attacker_card_refs);
|
||||
return string_printf(
|
||||
"ActionMetadata[ref=@%04hX, target_ref_count=%hhu, def_ref_count=%hhu, "
|
||||
"subphase=%s, def_power=%hhd, def_bonus=%hhd, "
|
||||
"att_bonus=%hhd, flags=%08" PRIX32 ", target_refs=%s, "
|
||||
"defense_refs=%s, original_attacker_refs=%s]",
|
||||
this->card_ref.load(),
|
||||
this->target_card_ref_count,
|
||||
this->defense_card_ref_count,
|
||||
name_for_action_subphase(this->action_subphase),
|
||||
this->defense_power,
|
||||
this->defense_bonus,
|
||||
this->attack_bonus,
|
||||
this->flags.load(),
|
||||
target_card_refs_s.c_str(),
|
||||
defense_card_refs_s.c_str(),
|
||||
original_attacker_card_refs_s.c_str());
|
||||
}
|
||||
|
||||
void ActionMetadata::clear() {
|
||||
this->card_ref = 0xFFFF;
|
||||
this->target_card_ref_count = 0;
|
||||
this->defense_card_ref_count = 0;
|
||||
this->action_subphase = ActionSubphase::INVALID_FF;
|
||||
this->defense_power = 0;
|
||||
this->defense_bonus = 0;
|
||||
this->attack_bonus = 0;
|
||||
this->flags = 0;
|
||||
this->target_card_refs.clear(0xFFFF);
|
||||
this->defense_card_refs.clear(0xFFFF);
|
||||
this->original_attacker_card_refs.clear(0xFFFF);
|
||||
}
|
||||
|
||||
void ActionMetadata::clear_FF() {
|
||||
this->card_ref = 0xFFFF;
|
||||
this->target_card_ref_count = 0xFF;
|
||||
this->defense_card_ref_count = 0xFF;
|
||||
this->action_subphase = ActionSubphase::INVALID_FF;
|
||||
this->defense_power = -1;
|
||||
this->defense_bonus = -1;
|
||||
this->attack_bonus = -1;
|
||||
this->flags = 0xFFFFFFFF;
|
||||
this->target_card_refs.clear(0xFFFF);
|
||||
this->defense_card_refs.clear(0xFFFF);
|
||||
this->original_attacker_card_refs.clear(0xFFFF);
|
||||
}
|
||||
|
||||
bool ActionMetadata::check_flag(uint32_t mask) const {
|
||||
return (this->flags & mask) != 0;
|
||||
}
|
||||
|
||||
void ActionMetadata::set_flags(uint32_t flags) {
|
||||
this->flags |= flags;
|
||||
}
|
||||
|
||||
void ActionMetadata::clear_flags(uint32_t flags) {
|
||||
this->flags &= ~flags;
|
||||
}
|
||||
|
||||
void ActionMetadata::clear_defense_and_attacker_card_refs() {
|
||||
this->defense_card_ref_count = 0;
|
||||
this->defense_card_refs.clear(0xFFFF);
|
||||
this->original_attacker_card_refs.clear(0xFFFF);
|
||||
}
|
||||
|
||||
void ActionMetadata::clear_target_card_refs() {
|
||||
this->target_card_ref_count = 0;
|
||||
this->target_card_refs.clear(0xFFFF);
|
||||
}
|
||||
|
||||
void ActionMetadata::add_target_card_ref(uint16_t card_ref) {
|
||||
if (card_ref != 0xFFFF &&
|
||||
this->target_card_ref_count < this->target_card_refs.size()) {
|
||||
this->target_card_refs[this->target_card_ref_count++] = card_ref;
|
||||
}
|
||||
}
|
||||
|
||||
void ActionMetadata::add_defense_card_ref(
|
||||
uint16_t defense_card_ref,
|
||||
shared_ptr<Card> card,
|
||||
uint16_t original_attacker_card_ref) {
|
||||
if ((defense_card_ref != 0xFFFF) && (this->defense_card_ref_count < 8)) {
|
||||
this->defense_card_refs[this->defense_card_ref_count] = defense_card_ref;
|
||||
this->original_attacker_card_refs[this->defense_card_ref_count] = original_attacker_card_ref;
|
||||
this->defense_card_ref_count++;
|
||||
this->action_subphase = card->server()->get_current_action_subphase();
|
||||
}
|
||||
}
|
||||
|
||||
HandAndEquipState::HandAndEquipState() {
|
||||
this->clear();
|
||||
}
|
||||
|
||||
std::string HandAndEquipState::str() const {
|
||||
string hand_card_refs_s = string_for_refs(this->hand_card_refs);
|
||||
string set_card_refs_s = string_for_refs(this->set_card_refs);
|
||||
string hand_card_refs2_s = string_for_refs(this->hand_card_refs2);
|
||||
string set_card_refs2_s = string_for_refs(this->set_card_refs2);
|
||||
return string_printf(
|
||||
"HandAndEquipState[dice=[%hhu, %hhu], atk=%hhu, def=%hhu, atk2=%hhu, "
|
||||
"a1=%hhu, total_set_cost=%hhu, is_cpu=%hhu, "
|
||||
"assist_flags=%08" PRIX32 ", hand_refs=%s, "
|
||||
"assist_ref=@%04hX, set_refs=%s, sc_ref=@%04hX, "
|
||||
"hand_refs2=%s, set_refs2=%s, assist_ref2=@%04hX, "
|
||||
"assist_set_num=%hu, assist_card_id=#%04hX, "
|
||||
"assist_turns=%hhu, assit_dely=%hhu, atk_bonus=%hhu, "
|
||||
"def_bonus=%hhu, u2=[%hhu, %hhu]]",
|
||||
this->dice_results[0],
|
||||
this->dice_results[1],
|
||||
this->atk_points,
|
||||
this->def_points,
|
||||
this->atk_points2,
|
||||
this->unknown_a1,
|
||||
this->total_set_cards_cost,
|
||||
this->is_cpu_player,
|
||||
this->assist_flags.load(),
|
||||
hand_card_refs_s.c_str(),
|
||||
this->assist_card_ref.load(),
|
||||
set_card_refs_s.c_str(),
|
||||
this->sc_card_ref.load(),
|
||||
hand_card_refs2_s.c_str(),
|
||||
set_card_refs2_s.c_str(),
|
||||
this->assist_card_ref2.load(),
|
||||
this->assist_card_set_number.load(),
|
||||
this->assist_card_id.load(),
|
||||
this->assist_remaining_turns,
|
||||
this->assist_delay_turns,
|
||||
this->atk_bonuses,
|
||||
this->def_bonuses,
|
||||
this->unused2[0],
|
||||
this->unused2[1]);
|
||||
}
|
||||
|
||||
void HandAndEquipState::clear() {
|
||||
this->dice_results.clear(0);
|
||||
this->atk_points = 0;
|
||||
this->def_points = 0;
|
||||
this->atk_points2 = 0;
|
||||
this->unknown_a1 = 0;
|
||||
this->total_set_cards_cost = 0;
|
||||
this->is_cpu_player = 0;
|
||||
this->assist_flags = 0;
|
||||
this->hand_card_refs.clear(0xFFFF);
|
||||
this->assist_card_ref = 0xFFFF;
|
||||
this->set_card_refs.clear(0xFFFF);
|
||||
this->sc_card_ref = 0xFFFF;
|
||||
this->hand_card_refs2.clear(0xFFFF);
|
||||
this->set_card_refs2.clear(0xFFFF);
|
||||
this->assist_card_ref2 = 0xFFFF;
|
||||
this->assist_card_set_number = 0;
|
||||
this->assist_card_id = 0xFFFF;
|
||||
this->assist_remaining_turns = 0;
|
||||
this->assist_delay_turns = 0;
|
||||
this->atk_bonuses = 0;
|
||||
this->def_bonuses = 0;
|
||||
this->unused2.clear(0);
|
||||
}
|
||||
|
||||
void HandAndEquipState::clear_FF() {
|
||||
this->dice_results.clear(0xFF);
|
||||
this->atk_points = 0xFF;
|
||||
this->def_points = 0xFF;
|
||||
this->atk_points2 = 0xFF;
|
||||
this->unknown_a1 = 0xFF;
|
||||
this->total_set_cards_cost = 0xFF;
|
||||
this->is_cpu_player = 0xFF;
|
||||
this->assist_flags = 0xFFFFFFFF;
|
||||
this->hand_card_refs.clear(0xFFFF);
|
||||
this->assist_card_ref = 0xFFFF;
|
||||
this->set_card_refs.clear(0xFFFF);
|
||||
this->sc_card_ref = 0xFFFF;
|
||||
this->hand_card_refs2.clear(0xFFFF);
|
||||
this->set_card_refs2.clear(0xFFFF);
|
||||
this->assist_card_ref2 = 0xFFFF;
|
||||
this->assist_card_set_number = 0xFFFF;
|
||||
this->assist_card_id = 0xFFFF;
|
||||
this->assist_remaining_turns = 0xFF;
|
||||
this->assist_delay_turns = 0xFF;
|
||||
this->atk_bonuses = 0xFF;
|
||||
this->def_bonuses = 0xFF;
|
||||
this->unused2.clear(0xFF);
|
||||
}
|
||||
|
||||
PlayerBattleStats::PlayerBattleStats() {
|
||||
this->clear();
|
||||
}
|
||||
|
||||
void PlayerBattleStats::clear() {
|
||||
this->damage_given = 0;
|
||||
this->damage_taken = 0;
|
||||
this->num_opponent_cards_destroyed = 0;
|
||||
this->num_owned_cards_destroyed = 0;
|
||||
this->total_move_distance = 0;
|
||||
this->num_cards_set = 0;
|
||||
this->num_item_or_creature_cards_set = 0;
|
||||
this->num_attack_actions_set = 0;
|
||||
this->num_tech_cards_set = 0;
|
||||
this->num_assist_cards_set = 0;
|
||||
this->defense_actions_set_on_self = 0;
|
||||
this->defense_actions_set_on_ally = 0;
|
||||
this->num_cards_drawn = 0;
|
||||
this->max_attack_damage = 0;
|
||||
this->max_attack_combo_size = 0;
|
||||
this->num_attacks_given = 0;
|
||||
this->num_attacks_taken = 0;
|
||||
this->sc_damage_taken = 0;
|
||||
this->action_card_negated_damage = 0;
|
||||
this->unused = 0;
|
||||
}
|
||||
|
||||
float PlayerBattleStats::score(size_t num_rounds) const {
|
||||
// Note: This formula doesn't match the formula on PSO-World, which is:
|
||||
// 35
|
||||
// + (Attack Damage - Damage Taken)
|
||||
// + (Max Card Combo x 3)
|
||||
// - (Story Character Damage x 1.8)
|
||||
// - (Turns x 2.7)
|
||||
// + (Action Card Negated Damage x 0.8)
|
||||
// I don't know where that formula came from, but this one came from the USA
|
||||
// Ep3 PsoV3.dol, so it's presumably correct. Is the PSO-World formula simply
|
||||
// incorrect, or is it from e.g. the Japanese version, which may have a
|
||||
// different rank calculation function?
|
||||
return 38.0f + 0.8f * this->action_card_negated_damage - 2.3f * num_rounds - 1.8f * this->sc_damage_taken + 3.0f * this->max_attack_combo_size + (this->damage_given - this->damage_taken);
|
||||
}
|
||||
|
||||
uint8_t PlayerBattleStats::rank(size_t num_rounds) const {
|
||||
return this->rank_for_score(this->score(num_rounds));
|
||||
}
|
||||
|
||||
const char* PlayerBattleStats::rank_name(size_t num_rounds) const {
|
||||
return this->name_for_rank(this->rank_for_score(this->score(num_rounds)));
|
||||
}
|
||||
|
||||
constexpr size_t RANK_THRESHOLD_COUNT = 9;
|
||||
static const float RANK_THRESHOLDS[RANK_THRESHOLD_COUNT] = {
|
||||
15.0f, 25.0f, 30.0f, 40.0f, 50.0f, 60.0f, 65.0f, 75.0f, 85.0f};
|
||||
static const char* RANK_NAMES[RANK_THRESHOLD_COUNT + 1] = {
|
||||
"E", "D", "D+", "C", "C+", "B", "B+", "A", "A+", "S"};
|
||||
|
||||
uint8_t PlayerBattleStats::rank_for_score(float score) {
|
||||
size_t rank = 0;
|
||||
while (rank < RANK_THRESHOLD_COUNT && RANK_THRESHOLDS[rank] <= score) {
|
||||
rank++;
|
||||
}
|
||||
return rank;
|
||||
}
|
||||
|
||||
const char* PlayerBattleStats::name_for_rank(uint8_t rank) {
|
||||
if (rank >= RANK_THRESHOLD_COUNT + 1) {
|
||||
throw invalid_argument("invalid rank");
|
||||
}
|
||||
return RANK_NAMES[rank];
|
||||
}
|
||||
|
||||
static bool is_card_within_range(
|
||||
const parray<uint8_t, 9 * 9>& range,
|
||||
const Location& anchor_loc,
|
||||
const CardShortStatus& ss,
|
||||
PrefixedLogger* log) {
|
||||
if (ss.card_ref == 0xFFFF) {
|
||||
if (log) {
|
||||
log->debug("is_card_within_range: (false) ss.card_ref missing");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (range[0] == 2) {
|
||||
if (log) {
|
||||
log->debug("is_card_within_range: (true) range is entire field");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((ss.loc.x < anchor_loc.x - 4) || (ss.loc.x > anchor_loc.x + 4)) {
|
||||
if (log) {
|
||||
log->debug("is_card_within_range: (false) outside x range (ss.loc.x=%hhu, anchor_loc.x=%hhu)", ss.loc.x, anchor_loc.x);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if ((ss.loc.y < anchor_loc.y - 4) || (ss.loc.y > anchor_loc.y + 4)) {
|
||||
if (log) {
|
||||
log->debug("is_card_within_range: (false) outside y range (ss.loc.y=%hhu, anchor_loc.y=%hhu)", ss.loc.y, anchor_loc.y);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t y_index = (ss.loc.y - anchor_loc.y) + 4;
|
||||
uint8_t x_index = (ss.loc.x - anchor_loc.x) + 4;
|
||||
bool ret = (range[y_index * 9 + x_index] != 0);
|
||||
if (log) {
|
||||
log->debug("is_card_within_range: (%s) (ss.loc=(%hhu,%hhu), anchor_loc=(%hhu,%hhu), indexes=(%hhu,%hhu))",
|
||||
ret ? "true" : "false", ss.loc.x, ss.loc.y, anchor_loc.x, anchor_loc.y, x_index, y_index);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
vector<uint16_t> get_card_refs_within_range(
|
||||
const parray<uint8_t, 9 * 9>& range,
|
||||
const Location& loc,
|
||||
const parray<CardShortStatus, 0x10>& short_statuses,
|
||||
PrefixedLogger* log) {
|
||||
vector<uint16_t> ret;
|
||||
if (is_card_within_range(range, loc, short_statuses[0], log)) {
|
||||
if (log) {
|
||||
log->debug("get_card_refs_within_range: sc card @%04hX within range", short_statuses[0].card_ref.load());
|
||||
}
|
||||
ret.emplace_back(short_statuses[0].card_ref);
|
||||
} else {
|
||||
if (log) {
|
||||
log->debug("get_card_refs_within_range: sc card @%04hX not within range", short_statuses[0].card_ref.load());
|
||||
}
|
||||
}
|
||||
for (size_t card_index = 7; card_index < 15; card_index++) {
|
||||
const auto& ss = short_statuses[card_index];
|
||||
if (is_card_within_range(range, loc, ss, log)) {
|
||||
if (log) {
|
||||
log->debug("get_card_refs_within_range: card @%04hX within range", ss.card_ref.load());
|
||||
}
|
||||
ret.emplace_back(ss.card_ref);
|
||||
} else {
|
||||
if (log) {
|
||||
log->debug("get_card_refs_within_range: card @%04hX not within range", ss.card_ref.load());
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace Episode3
|
||||
@@ -0,0 +1,275 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "../Text.hh"
|
||||
#include "DataIndexes.hh"
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
class Server;
|
||||
class Card;
|
||||
|
||||
struct Condition {
|
||||
ConditionType type;
|
||||
uint8_t remaining_turns;
|
||||
int8_t a_arg_value;
|
||||
uint8_t dice_roll_value;
|
||||
uint8_t flags;
|
||||
uint8_t card_definition_effect_index;
|
||||
le_uint16_t card_ref;
|
||||
le_int16_t value;
|
||||
le_uint16_t condition_giver_card_ref;
|
||||
uint8_t random_percent;
|
||||
int8_t value8;
|
||||
uint8_t order;
|
||||
uint8_t unknown_a8;
|
||||
|
||||
Condition();
|
||||
bool operator==(const Condition& other) const;
|
||||
bool operator!=(const Condition& other) const;
|
||||
|
||||
void clear();
|
||||
void clear_FF();
|
||||
|
||||
std::string str() const;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct EffectResult {
|
||||
le_uint16_t attacker_card_ref;
|
||||
le_uint16_t target_card_ref;
|
||||
int8_t value;
|
||||
int8_t current_hp;
|
||||
int8_t ap;
|
||||
int8_t tp;
|
||||
uint8_t flags;
|
||||
int8_t operation; // May be a negative condition number
|
||||
uint8_t condition_index;
|
||||
uint8_t dice_roll_value;
|
||||
|
||||
EffectResult();
|
||||
bool operator==(const EffectResult& other) const;
|
||||
bool operator!=(const EffectResult& other) const;
|
||||
|
||||
std::string str() const;
|
||||
|
||||
void clear();
|
||||
} __attribute__((packed));
|
||||
|
||||
struct CardShortStatus {
|
||||
le_uint16_t card_ref;
|
||||
le_uint16_t current_hp;
|
||||
le_uint32_t card_flags;
|
||||
Location loc;
|
||||
le_uint16_t unused1;
|
||||
int8_t max_hp;
|
||||
uint8_t unused2;
|
||||
|
||||
CardShortStatus();
|
||||
bool operator==(const CardShortStatus& other) const;
|
||||
bool operator!=(const CardShortStatus& other) const;
|
||||
|
||||
void clear();
|
||||
void clear_FF();
|
||||
|
||||
std::string str() const;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct ActionState {
|
||||
le_uint16_t client_id;
|
||||
uint8_t unused;
|
||||
Direction facing_direction;
|
||||
le_uint16_t attacker_card_ref;
|
||||
le_uint16_t defense_card_ref;
|
||||
parray<le_uint16_t, 4 * 9> target_card_refs;
|
||||
parray<le_uint16_t, 9> action_card_refs;
|
||||
le_uint16_t original_attacker_card_ref;
|
||||
|
||||
ActionState();
|
||||
bool operator==(const ActionState& other) const;
|
||||
bool operator!=(const ActionState& other) const;
|
||||
|
||||
void clear();
|
||||
|
||||
std::string str() const;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct ActionChain {
|
||||
int8_t effective_ap;
|
||||
int8_t effective_tp;
|
||||
int8_t ap_effect_bonus;
|
||||
int8_t damage;
|
||||
le_uint16_t acting_card_ref;
|
||||
le_uint16_t unknown_card_ref_a3;
|
||||
parray<le_uint16_t, 8> attack_action_card_refs;
|
||||
uint8_t attack_action_card_ref_count;
|
||||
AttackMedium attack_medium;
|
||||
uint8_t target_card_ref_count;
|
||||
ActionSubphase action_subphase;
|
||||
uint8_t strike_count;
|
||||
int8_t damage_multiplier;
|
||||
uint8_t attack_number;
|
||||
int8_t tp_effect_bonus;
|
||||
uint8_t unused1;
|
||||
uint8_t unused2;
|
||||
int8_t card_ap;
|
||||
int8_t card_tp;
|
||||
le_uint32_t flags;
|
||||
parray<le_uint16_t, 4 * 9> target_card_refs;
|
||||
|
||||
ActionChain();
|
||||
bool operator==(const ActionChain& other) const;
|
||||
bool operator!=(const ActionChain& other) const;
|
||||
|
||||
void clear();
|
||||
void clear_FF();
|
||||
|
||||
std::string str() const;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct ActionChainWithConds {
|
||||
ActionChain chain;
|
||||
parray<Condition, 9> conditions;
|
||||
|
||||
ActionChainWithConds();
|
||||
bool operator==(const ActionChainWithConds& other) const;
|
||||
bool operator!=(const ActionChainWithConds& other) const;
|
||||
|
||||
void clear();
|
||||
void clear_FF();
|
||||
void clear_inner();
|
||||
void clear_target_card_refs();
|
||||
void reset();
|
||||
|
||||
bool check_flag(uint32_t flags) const;
|
||||
void clear_flags(uint32_t flags);
|
||||
void set_flags(uint32_t flags);
|
||||
|
||||
void add_attack_action_card_ref(uint16_t card_ref, std::shared_ptr<Server> server);
|
||||
void add_target_card_ref(uint16_t card_ref);
|
||||
|
||||
void compute_attack_medium(std::shared_ptr<Server> server);
|
||||
bool get_condition_value(
|
||||
ConditionType cond_type,
|
||||
uint16_t card_ref,
|
||||
uint8_t def_effect_index,
|
||||
uint16_t value,
|
||||
uint16_t* out_value) const;
|
||||
|
||||
void set_action_subphase_from_card(std::shared_ptr<const Card> card);
|
||||
bool can_apply_attack() const;
|
||||
|
||||
std::string str() const;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct ActionMetadata {
|
||||
le_uint16_t card_ref;
|
||||
uint8_t target_card_ref_count;
|
||||
uint8_t defense_card_ref_count;
|
||||
ActionSubphase action_subphase;
|
||||
int8_t defense_power;
|
||||
int8_t defense_bonus;
|
||||
int8_t attack_bonus;
|
||||
le_uint32_t flags;
|
||||
parray<le_uint16_t, 4 * 9> target_card_refs;
|
||||
parray<le_uint16_t, 8> defense_card_refs;
|
||||
parray<le_uint16_t, 8> original_attacker_card_refs;
|
||||
|
||||
ActionMetadata();
|
||||
bool operator==(const ActionMetadata& other) const;
|
||||
bool operator!=(const ActionMetadata& other) const;
|
||||
|
||||
std::string str() const;
|
||||
|
||||
void clear();
|
||||
void clear_FF();
|
||||
|
||||
bool check_flag(uint32_t mask) const;
|
||||
void set_flags(uint32_t flags);
|
||||
void clear_flags(uint32_t flags);
|
||||
|
||||
void clear_defense_and_attacker_card_refs();
|
||||
void clear_target_card_refs();
|
||||
void add_target_card_ref(uint16_t card_ref);
|
||||
void add_defense_card_ref(
|
||||
uint16_t defense_card_ref,
|
||||
std::shared_ptr<Card> card,
|
||||
uint16_t original_attacker_card_ref);
|
||||
} __attribute__((packed));
|
||||
|
||||
struct HandAndEquipState {
|
||||
parray<uint8_t, 2> dice_results;
|
||||
uint8_t atk_points;
|
||||
uint8_t def_points;
|
||||
uint8_t atk_points2; // TODO: rename this to something more appropriate
|
||||
uint8_t unknown_a1;
|
||||
uint8_t total_set_cards_cost;
|
||||
uint8_t is_cpu_player;
|
||||
le_uint32_t assist_flags;
|
||||
parray<le_uint16_t, 6> hand_card_refs;
|
||||
le_uint16_t assist_card_ref;
|
||||
parray<le_uint16_t, 8> set_card_refs;
|
||||
le_uint16_t sc_card_ref;
|
||||
parray<le_uint16_t, 6> hand_card_refs2;
|
||||
parray<le_uint16_t, 8> set_card_refs2;
|
||||
le_uint16_t assist_card_ref2;
|
||||
le_uint16_t assist_card_set_number;
|
||||
le_uint16_t assist_card_id;
|
||||
uint8_t assist_remaining_turns;
|
||||
uint8_t assist_delay_turns;
|
||||
uint8_t atk_bonuses;
|
||||
uint8_t def_bonuses;
|
||||
parray<uint8_t, 2> unused2;
|
||||
|
||||
HandAndEquipState();
|
||||
bool operator==(const HandAndEquipState& other) const;
|
||||
bool operator!=(const HandAndEquipState& other) const;
|
||||
|
||||
void clear();
|
||||
void clear_FF();
|
||||
|
||||
std::string str() const;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct PlayerBattleStats {
|
||||
le_uint16_t damage_given;
|
||||
le_uint16_t damage_taken;
|
||||
le_uint16_t num_opponent_cards_destroyed;
|
||||
le_uint16_t num_owned_cards_destroyed;
|
||||
le_uint16_t total_move_distance;
|
||||
le_uint16_t num_cards_set;
|
||||
le_uint16_t num_item_or_creature_cards_set;
|
||||
le_uint16_t num_attack_actions_set;
|
||||
le_uint16_t num_tech_cards_set;
|
||||
le_uint16_t num_assist_cards_set;
|
||||
le_uint16_t defense_actions_set_on_self;
|
||||
le_uint16_t defense_actions_set_on_ally;
|
||||
le_uint16_t num_cards_drawn;
|
||||
le_uint16_t max_attack_damage;
|
||||
le_uint16_t max_attack_combo_size;
|
||||
le_uint16_t num_attacks_given;
|
||||
le_uint16_t num_attacks_taken;
|
||||
le_uint16_t sc_damage_taken;
|
||||
le_uint16_t action_card_negated_damage;
|
||||
le_uint16_t unused;
|
||||
|
||||
PlayerBattleStats();
|
||||
void clear();
|
||||
|
||||
float score(size_t num_rounds) const;
|
||||
uint8_t rank(size_t num_rounds) const;
|
||||
const char* rank_name(size_t num_rounds) const;
|
||||
|
||||
static uint8_t rank_for_score(float score);
|
||||
static const char* name_for_rank(uint8_t rank);
|
||||
} __attribute__((packed));
|
||||
|
||||
std::vector<uint16_t> get_card_refs_within_range(
|
||||
const parray<uint8_t, 9 * 9>& range,
|
||||
const Location& loc,
|
||||
const parray<CardShortStatus, 0x10>& short_statuses,
|
||||
PrefixedLogger* log = nullptr);
|
||||
|
||||
} // namespace Episode3
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,228 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "AssistServer.hh"
|
||||
#include "DataIndexes.hh"
|
||||
#include "DeckState.hh"
|
||||
#include "PlayerState.hh"
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
class Server;
|
||||
|
||||
void compute_effective_range(
|
||||
parray<uint8_t, 9 * 9>& ret,
|
||||
std::shared_ptr<const CardIndex> card_index,
|
||||
uint16_t card_id,
|
||||
const Location& loc,
|
||||
std::shared_ptr<const MapAndRulesState> map_and_rules,
|
||||
PrefixedLogger* log = nullptr);
|
||||
|
||||
bool card_linkage_is_valid(
|
||||
std::shared_ptr<const CardIndex::CardEntry> right_def,
|
||||
std::shared_ptr<const CardIndex::CardEntry> left_def,
|
||||
std::shared_ptr<const CardIndex::CardEntry> sc_def,
|
||||
bool has_permission_effect);
|
||||
|
||||
class RulerServer {
|
||||
public:
|
||||
struct MovePath {
|
||||
int32_t length;
|
||||
uint32_t remaining_distance;
|
||||
Location end_loc;
|
||||
parray<Location, 11> step_locs;
|
||||
uint32_t num_occupied_tiles;
|
||||
uint32_t cost;
|
||||
|
||||
MovePath();
|
||||
void add_step(const Location& loc);
|
||||
uint32_t get_cost() const;
|
||||
uint32_t get_length_plus1() const;
|
||||
void reset_totals();
|
||||
bool is_valid() const;
|
||||
};
|
||||
|
||||
explicit RulerServer(std::shared_ptr<Server> server);
|
||||
std::shared_ptr<Server> server();
|
||||
std::shared_ptr<const Server> server() const;
|
||||
|
||||
ActionChainWithConds* action_chain_with_conds_for_card_ref(
|
||||
uint16_t card_ref);
|
||||
const ActionChainWithConds* action_chain_with_conds_for_card_ref(
|
||||
uint16_t card_ref) const;
|
||||
bool any_attack_action_card_is_support_tech_or_support_pb(
|
||||
const ActionState& pa) const;
|
||||
bool card_has_pierce_or_rampage(
|
||||
uint8_t client_id,
|
||||
ConditionType cond_type,
|
||||
bool* out_has_rampage,
|
||||
uint16_t attacker_card_ref,
|
||||
uint16_t action_card_ref,
|
||||
uint8_t def_effect_index,
|
||||
AttackMedium attack_medium) const;
|
||||
bool attack_action_has_rampage_and_not_pierce(
|
||||
const ActionState& pa, uint16_t card_ref) const;
|
||||
bool attack_action_has_pierce_and_not_rampage(
|
||||
const ActionState& pa, uint8_t client_id);
|
||||
bool card_exists_by_status(const CardShortStatus& stat) const;
|
||||
bool card_has_mighty_knuckle(uint32_t card_ref) const;
|
||||
uint16_t card_id_for_card_ref(uint16_t card_ref) const;
|
||||
static bool card_id_is_boss_sc(uint16_t card_id);
|
||||
static bool card_id_is_support_tech_or_support_pb(uint16_t card_id);
|
||||
bool card_ref_can_attack(uint16_t card_ref);
|
||||
bool card_ref_can_move(
|
||||
uint8_t client_id, uint16_t card_ref, bool ignore_atk_points) const;
|
||||
bool card_ref_has_class_usability_condition(
|
||||
uint16_t card_ref) const;
|
||||
bool card_ref_has_free_maneuver(uint16_t card_ref) const;
|
||||
bool card_ref_is_aerial(uint16_t card_ref) const;
|
||||
bool card_ref_is_aerial_or_has_free_maneuver(
|
||||
uint16_t card_ref) const;
|
||||
bool card_ref_is_boss_sc(uint32_t card_ref) const;
|
||||
bool card_ref_or_any_set_card_has_condition_46(
|
||||
uint16_t card_ref) const;
|
||||
bool card_ref_or_sc_has_fixed_range(uint16_t card_ref) const;
|
||||
bool check_move_path_and_get_cost(
|
||||
uint8_t client_id,
|
||||
uint16_t card_ref,
|
||||
parray<uint8_t, 0x100>* visited_map,
|
||||
MovePath* out_path,
|
||||
uint32_t* out_cost) const;
|
||||
bool check_pierce_and_rampage(
|
||||
uint16_t card_ref,
|
||||
ConditionType cond_type,
|
||||
bool* out_has_pierce,
|
||||
uint16_t attacker_card_ref,
|
||||
uint16_t action_card_ref,
|
||||
uint8_t def_effect_index,
|
||||
AttackMedium attack_medium) const;
|
||||
bool check_usability_or_apply_condition_for_card_refs(
|
||||
uint16_t card_ref1,
|
||||
uint16_t card_ref2,
|
||||
uint16_t card_ref3,
|
||||
uint8_t def_effect_index,
|
||||
AttackMedium attack_medium) const;
|
||||
bool check_usability_or_condition_apply(
|
||||
uint8_t client_id1,
|
||||
uint16_t card_id1,
|
||||
uint8_t client_id2,
|
||||
uint16_t card_id2,
|
||||
uint16_t card_id3,
|
||||
uint8_t def_effect_index,
|
||||
bool is_condition_check,
|
||||
AttackMedium attack_medium) const;
|
||||
uint16_t compute_attack_or_defense_costs(
|
||||
const ActionState& pa,
|
||||
bool allow_mighty_knuckle,
|
||||
uint8_t* out_ally_cost) const;
|
||||
bool compute_effective_range_and_target_mode_for_attack(
|
||||
const ActionState& pa,
|
||||
uint16_t* out_effective_card_id,
|
||||
TargetMode* out_effective_target_mode,
|
||||
uint16_t* out_orig_card_ref) const;
|
||||
size_t count_rampage_targets_for_attack(
|
||||
const ActionState& pa, uint8_t client_id) const;
|
||||
bool defense_card_can_apply_to_attack(
|
||||
uint16_t defense_card_ref,
|
||||
uint16_t attacker_card_ref,
|
||||
uint16_t attacker_sc_card_ref) const;
|
||||
bool defense_card_matches_any_attack_card_top_color(
|
||||
const ActionState& pa) const;
|
||||
std::shared_ptr<const CardIndex::CardEntry> definition_for_card_ref(uint16_t card_ref) const;
|
||||
int32_t error_code_for_client_setting_card(
|
||||
uint8_t client_id,
|
||||
uint16_t card_ref,
|
||||
const Location* loc,
|
||||
uint8_t assist_target_client_id) const;
|
||||
bool find_condition_on_card_ref(
|
||||
uint16_t card_ref,
|
||||
ConditionType cond_type,
|
||||
Condition* out_se = nullptr,
|
||||
size_t* out_value_sum = nullptr,
|
||||
bool find_first_instead_of_max = false) const;
|
||||
bool flood_fill_move_path(
|
||||
const ActionChainWithConds& chain,
|
||||
int8_t x,
|
||||
int8_t y,
|
||||
Direction direction,
|
||||
uint8_t max_atk_points,
|
||||
int16_t max_distance,
|
||||
bool is_free_maneuver_or_aerial,
|
||||
bool is_aerial,
|
||||
parray<uint8_t, 0x100>* visited_map,
|
||||
MovePath* path,
|
||||
size_t num_occupied_tiles,
|
||||
size_t num_vacant_tiles) const;
|
||||
uint16_t get_ally_sc_card_ref(uint16_t card_ref) const;
|
||||
std::shared_ptr<const CardIndex::CardEntry> definition_for_card_id(
|
||||
uint32_t card_id) const;
|
||||
uint32_t get_card_id_with_effective_range(
|
||||
uint16_t card_ref, uint16_t card_id_override, TargetMode* out_target_mode) const;
|
||||
uint8_t get_card_ref_max_hp(uint16_t card_ref) const;
|
||||
bool get_creature_summon_area(
|
||||
uint8_t client_id, Location* out_loc, uint8_t* out_region_size) const;
|
||||
std::shared_ptr<HandAndEquipState> get_hand_and_equip_state_for_client_id(
|
||||
uint8_t client_id);
|
||||
std::shared_ptr<const HandAndEquipState> get_hand_and_equip_state_for_client_id(
|
||||
uint8_t client_id) const;
|
||||
bool get_move_path_length_and_cost(
|
||||
uint32_t client_id,
|
||||
uint32_t card_ref,
|
||||
const Location& loc,
|
||||
uint32_t* out_length,
|
||||
uint32_t* out_cost) const;
|
||||
ssize_t get_path_cost(
|
||||
const ActionChainWithConds& chain,
|
||||
ssize_t path_length,
|
||||
ssize_t cost_penalty) const;
|
||||
ActionType get_pending_action_type(const ActionState& pa) const;
|
||||
bool is_attack_valid(const ActionState& pa);
|
||||
bool is_attack_or_defense_valid(const ActionState& pa);
|
||||
bool is_card_ref_in_hand(uint16_t card_ref) const;
|
||||
bool is_defense_valid(const ActionState& pa);
|
||||
void link_objects(
|
||||
std::shared_ptr<MapAndRulesState> map_and_rules,
|
||||
std::shared_ptr<StateFlags> state_flags,
|
||||
std::shared_ptr<AssistServer> assist_server);
|
||||
size_t max_move_distance_for_card_ref(uint32_t card_ref) const;
|
||||
static void offsets_for_direction(
|
||||
const Location& loc, int32_t* out_x_offset, int32_t* out_y_offset);
|
||||
void register_player(
|
||||
uint8_t client_id,
|
||||
std::shared_ptr<HandAndEquipState> hes,
|
||||
std::shared_ptr<parray<CardShortStatus, 0x10>> short_statuses,
|
||||
std::shared_ptr<DeckEntry> deck_entry,
|
||||
std::shared_ptr<parray<ActionChainWithConds, 9>> set_card_action_chains,
|
||||
std::shared_ptr<parray<ActionMetadata, 9>> set_card_action_metadatas);
|
||||
void replace_D1_D2_rank_cards_with_Attack(parray<le_uint16_t, 0x1F>& card_ids) const;
|
||||
AttackMedium get_attack_medium(const ActionState& pa) const;
|
||||
void set_client_team_id(uint8_t client_id, uint8_t team_id);
|
||||
int32_t set_cost_for_card(uint8_t client_id, uint16_t card_ref) const;
|
||||
const CardShortStatus* short_status_for_card_ref(uint16_t card_ref) const;
|
||||
bool should_allow_attacks_on_current_turn() const;
|
||||
int32_t verify_deck(
|
||||
const parray<le_uint16_t, 0x1F>& card_ids,
|
||||
const parray<uint8_t, 0x2F0>* owned_card_counts = nullptr) const;
|
||||
|
||||
private:
|
||||
std::weak_ptr<Server> w_server;
|
||||
|
||||
public:
|
||||
std::shared_ptr<HandAndEquipState> hand_and_equip_states[4];
|
||||
std::shared_ptr<parray<CardShortStatus, 0x10>> short_statuses[4];
|
||||
std::shared_ptr<DeckEntry> deck_entries[4];
|
||||
std::shared_ptr<parray<ActionChainWithConds, 9>> set_card_action_chains[4];
|
||||
std::shared_ptr<parray<ActionMetadata, 9>> set_card_action_metadatas[4];
|
||||
std::shared_ptr<MapAndRulesState> map_and_rules;
|
||||
std::shared_ptr<StateFlags> state_flags;
|
||||
std::shared_ptr<AssistServer> assist_server;
|
||||
parray<uint8_t, 4> team_id_for_client_id;
|
||||
int32_t error_code1;
|
||||
int32_t error_code2;
|
||||
int32_t error_code3;
|
||||
};
|
||||
|
||||
} // namespace Episode3
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,318 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
|
||||
#include "../Channel.hh"
|
||||
#include "../CommandFormats.hh"
|
||||
#include "../Text.hh"
|
||||
#include "AssistServer.hh"
|
||||
#include "CardSpecial.hh"
|
||||
#include "MapState.hh"
|
||||
#include "PlayerState.hh"
|
||||
#include "RulerServer.hh"
|
||||
#include "Tournament.hh"
|
||||
|
||||
struct Lobby;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
/**
|
||||
* This implementation of Episode 3 battles is derived from Sega's original
|
||||
* server implementation, reverse-engineered from the Episode 3 client
|
||||
* executable. The control flow, function breakdown, and structure definitions
|
||||
* in these files map very closely to how their server implementation was
|
||||
* written; notable differences (due to necessary environment differences or bug
|
||||
* fixes) are described in the comments therein.
|
||||
*
|
||||
* The following files are direct reverse-engineerings of Sega's original code,
|
||||
* except where noted in the comments:
|
||||
* AssistServer.hh/cc
|
||||
* Card.hh/cc
|
||||
* CardSpecial.hh/cc
|
||||
* DeckState.hh/cc
|
||||
* MapState.hh/cc
|
||||
* PlayerState.hh/cc
|
||||
* PlayerStateSubordinates.hh/cc
|
||||
* RulerServer.hh/cc
|
||||
* Server.hh/cc
|
||||
*
|
||||
* There are likely undiscovered bugs in this code, some originally written by
|
||||
* Sega, but more written by me as I manually transcribed and updated this code.
|
||||
*
|
||||
* Class ownership levels (classes may only contain weak_ptrs, not shared_ptrs,
|
||||
* to classes at the same or higher level):
|
||||
* - Server
|
||||
* - - RulerServer
|
||||
* - - - AssistServer
|
||||
* - - - CardSpecial
|
||||
* - - - - StateFlags
|
||||
* - - - - DeckEntry
|
||||
* - - - - PlayerState
|
||||
* - - - - - Card
|
||||
* - - - - - - CardShortStatus
|
||||
* - - - - - - DeckState
|
||||
* - - - - - - HandAndEquipState
|
||||
* - - - - - - MapAndRulesState / OverlayState
|
||||
* - - - - - - - Everything within DataIndexes
|
||||
*/
|
||||
|
||||
class Server : public std::enable_shared_from_this<Server> {
|
||||
// In the original code, there is a TCardServerBase class and a TCardServer
|
||||
// class, with the former containing some basic parts of the game state and
|
||||
// a pointer to the latter. It seems these two classes exist (instead of one
|
||||
// big class) so that the force reset command could be implemented; however,
|
||||
// it appears that that command is never sent by the client, so we combine
|
||||
// the two classes into one in our implementation.
|
||||
public:
|
||||
struct Options {
|
||||
std::shared_ptr<const CardIndex> card_index;
|
||||
std::shared_ptr<const MapIndex> map_index;
|
||||
uint32_t behavior_flags;
|
||||
std::shared_ptr<PSOLFGEncryption> random_crypt;
|
||||
std::shared_ptr<const Tournament> tournament;
|
||||
std::array<std::vector<uint16_t>, 5> trap_card_ids;
|
||||
};
|
||||
Server(std::shared_ptr<Lobby> lobby, Options&& options);
|
||||
~Server() noexcept(false);
|
||||
void init();
|
||||
|
||||
class StackLogger : public PrefixedLogger {
|
||||
public:
|
||||
StackLogger(const Server* s, const std::string& prefix);
|
||||
StackLogger(const Server* s, const std::string& prefix, LogLevel min_level);
|
||||
StackLogger(const StackLogger&) = delete;
|
||||
StackLogger(StackLogger&&);
|
||||
StackLogger& operator=(const StackLogger&) = delete;
|
||||
StackLogger& operator=(StackLogger&&);
|
||||
~StackLogger() noexcept(false);
|
||||
|
||||
private:
|
||||
const Server* server;
|
||||
};
|
||||
StackLogger log_stack(const std::string& prefix) const;
|
||||
const StackLogger& log() const;
|
||||
|
||||
int8_t get_winner_team_id() const;
|
||||
|
||||
template <typename T>
|
||||
void send(const T& cmd) const {
|
||||
if (cmd.header.size != sizeof(cmd) / 4) {
|
||||
throw std::logic_error("outbound command size field is incorrect");
|
||||
}
|
||||
if (cmd.header.subsubcommand == 0x06) {
|
||||
this->num_6xB4x06_commands_sent++;
|
||||
this->prev_num_6xB4x06_commands_sent = this->num_6xB4x06_commands_sent;
|
||||
if (this->num_6xB4x06_commands_sent > 0x100) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
this->send(&cmd, cmd.header.size * 4);
|
||||
}
|
||||
void send(const void* data, size_t size) const;
|
||||
void send_commands_for_joining_spectator(Channel& ch, uint8_t language, bool is_trial) const;
|
||||
|
||||
void force_battle_result(uint8_t surrendered_client_id, bool set_winner);
|
||||
void force_destroy_field_character(uint8_t client_id, size_t set_index);
|
||||
|
||||
__attribute__((format(printf, 2, 3))) void send_debug_message_printf(const char* fmt, ...) const;
|
||||
__attribute__((format(printf, 2, 3))) void send_info_message_printf(const char* fmt, ...) const;
|
||||
void send_debug_command_received_message(
|
||||
uint8_t client_id, uint8_t subsubcommand, const char* description) const;
|
||||
void send_debug_command_received_message(
|
||||
uint8_t subsubcommand, const char* description) const;
|
||||
void send_debug_message_if_error_code_nonzero(
|
||||
uint8_t client_id, int32_t error_code) const;
|
||||
|
||||
void send_6xB4x46() const;
|
||||
|
||||
void add_team_exp(uint8_t team_id, int32_t exp);
|
||||
bool advance_battle_phase();
|
||||
void action_phase_after();
|
||||
void draw_phase_before();
|
||||
std::shared_ptr<const CardIndex::CardEntry> definition_for_card_ref(uint16_t card_ref) const;
|
||||
std::shared_ptr<Card> card_for_set_card_ref(uint16_t card_ref);
|
||||
std::shared_ptr<const Card> card_for_set_card_ref(uint16_t card_ref) const;
|
||||
uint16_t card_id_for_card_ref(uint16_t card_ref) const;
|
||||
bool card_ref_is_empty_or_has_valid_card_id(uint16_t card_ref) const;
|
||||
bool check_for_battle_end();
|
||||
void check_for_destroyed_cards_and_send_6xB4x05_6xB4x02();
|
||||
bool check_presence_entry(uint8_t client_id) const;
|
||||
void clear_player_flags_after_dice_phase();
|
||||
void compute_all_map_occupied_bits();
|
||||
void compute_team_dice_boost(uint8_t team_id);
|
||||
void copy_player_states_to_prev_states();
|
||||
std::shared_ptr<const CardIndex::CardEntry> definition_for_card_id(uint16_t card_id) const;
|
||||
void destroy_cards_with_zero_hp();
|
||||
void determine_first_team_turn();
|
||||
void dice_phase_after();
|
||||
void set_phase_before();
|
||||
void draw_phase_after();
|
||||
void dice_phase_before();
|
||||
void end_attack_list_for_client(uint8_t client_id);
|
||||
void end_action_phase();
|
||||
bool enqueue_attack_or_defense(uint8_t client_id, ActionState* pa);
|
||||
BattlePhase get_battle_phase() const;
|
||||
ActionSubphase get_current_action_subphase() const;
|
||||
uint8_t get_current_team_turn() const;
|
||||
std::shared_ptr<PlayerState> get_player_state(uint8_t client_id);
|
||||
std::shared_ptr<const PlayerState> get_player_state(uint8_t client_id) const;
|
||||
uint32_t get_random(uint32_t max);
|
||||
float get_random_float_0_1();
|
||||
uint32_t get_round_num() const;
|
||||
SetupPhase get_setup_phase() const;
|
||||
uint32_t get_should_copy_prev_states_to_current_states() const;
|
||||
bool is_registration_complete() const;
|
||||
void move_phase_after();
|
||||
void action_phase_before();
|
||||
void send_6xB4x1C_names_update();
|
||||
int8_t send_6xB4x33_remove_ally_atk_if_needed(const ActionState& pa);
|
||||
void send_all_state_updates();
|
||||
void send_set_card_updates_and_6xB4x04_if_needed();
|
||||
void set_battle_ended();
|
||||
void set_battle_started();
|
||||
void set_client_id_ready_to_advance_phase(uint8_t client_id);
|
||||
void set_phase_after();
|
||||
void move_phase_before();
|
||||
void set_player_deck_valid(uint8_t client_id);
|
||||
void setup_and_start_battle();
|
||||
G_SetStateFlags_GC_Ep3_6xB4x03 prepare_6xB4x03() const;
|
||||
void update_battle_state_flags_and_send_6xB4x03_if_needed(
|
||||
bool always_send = false);
|
||||
bool update_registration_phase();
|
||||
void on_server_data_input(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx0B_mulligan_hand(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx0C_end_mulligan_phase(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx0D_end_non_action_phase(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx0E_discard_card_from_hand(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx0F_set_card_from_hand(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx10_move_fc_to_location(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx11_enqueue_attack_or_defense(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx12_end_attack_list(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx13_update_map_during_setup(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx14_update_deck_during_setup(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx15_unused_hard_reset_server_state(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx1B_update_player_name(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx1D_start_battle(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx21_end_battle(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx28_end_defense_list(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx2B_legacy_set_card(std::shared_ptr<Client> sender_c, const std::string&);
|
||||
void handle_CAx34_subtract_ally_atk_points(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx37_client_ready_to_advance_from_starter_roll_phase(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx3A_time_limit_expired(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx40_map_list_request(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx41_map_request(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx48_end_turn(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void handle_CAx49_card_counts(std::shared_ptr<Client> sender_c, const std::string& data);
|
||||
void compute_losing_team_id_and_add_winner_flags(uint32_t flags);
|
||||
uint32_t get_team_exp(uint8_t team_id) const;
|
||||
uint32_t send_6xB4x06_if_card_ref_invalid(
|
||||
uint16_t card_ref, int16_t negative_value);
|
||||
void unknown_8023EEF4();
|
||||
void execute_bomb_assist_effect();
|
||||
void replace_targets_due_to_destruction_or_conditions(
|
||||
ActionState* as);
|
||||
bool any_target_exists_for_attack(const ActionState& as);
|
||||
uint8_t get_current_team_turn2() const;
|
||||
void unknown_8023EE48();
|
||||
void unknown_8023EE80();
|
||||
void unknown_802402F4();
|
||||
void send_6xB4x39() const;
|
||||
void send_6xB4x05(); // Recomputes the map occupied bits, so can't be const
|
||||
void send_6xB4x02_for_all_players_if_needed(bool always_send = false);
|
||||
void send_6xB4x50_trap_tile_locations() const;
|
||||
|
||||
G_UpdateDecks_GC_Ep3_6xB4x07 prepare_6xB4x07_decks_update() const;
|
||||
G_SetPlayerNames_GC_Ep3_6xB4x1C prepare_6xB4x1C_names_update() const;
|
||||
static std::string prepare_6xB6x41_map_definition(
|
||||
std::shared_ptr<const MapIndex::Map> map, uint8_t language, bool is_trial);
|
||||
void send_6xB6x41_to_all_clients() const;
|
||||
G_SetTrapTileLocations_GC_Ep3_6xB4x50 prepare_6xB4x50_trap_tile_locations() const;
|
||||
|
||||
std::vector<std::shared_ptr<Card>> const_cast_set_cards_v(
|
||||
const std::vector<std::shared_ptr<const Card>>& cards);
|
||||
|
||||
private:
|
||||
typedef void (Server::*handler_t)(std::shared_ptr<Client>, const std::string&);
|
||||
static const std::unordered_map<uint8_t, handler_t> subcommand_handlers;
|
||||
|
||||
public:
|
||||
// These fields are not part of the original implementation
|
||||
std::weak_ptr<Lobby> lobby;
|
||||
Options options;
|
||||
std::shared_ptr<const MapIndex::Map> last_chosen_map;
|
||||
bool tournament_match_result_sent;
|
||||
uint8_t override_environment_number;
|
||||
mutable std::deque<StackLogger*> logger_stack;
|
||||
|
||||
// These fields were originally contained in the TCardServerBase object
|
||||
struct PresenceEntry {
|
||||
uint8_t player_present;
|
||||
uint8_t deck_valid;
|
||||
uint8_t is_cpu_player;
|
||||
PresenceEntry();
|
||||
void clear();
|
||||
} __attribute__((packed));
|
||||
std::shared_ptr<MapAndRulesState> map_and_rules;
|
||||
std::shared_ptr<DeckEntry> deck_entries[4];
|
||||
parray<PresenceEntry, 4> presence_entries;
|
||||
uint8_t num_clients_present;
|
||||
parray<NameEntry, 4> name_entries;
|
||||
parray<uint8_t, 4> name_entries_valid;
|
||||
OverlayState overlay_state;
|
||||
parray<parray<uint8_t, 0x2F0>, 4> client_card_counts;
|
||||
|
||||
// These fields were originally contained in the TCardServer object
|
||||
uint32_t battle_finished;
|
||||
uint32_t battle_in_progress;
|
||||
uint32_t round_num;
|
||||
BattlePhase battle_phase;
|
||||
uint8_t first_team_turn;
|
||||
uint8_t current_team_turn1;
|
||||
SetupPhase setup_phase;
|
||||
RegistrationPhase registration_phase;
|
||||
ActionSubphase action_subphase;
|
||||
uint8_t current_team_turn2;
|
||||
ActionState pending_attacks[0x20];
|
||||
uint32_t num_pending_attacks;
|
||||
parray<uint8_t, 4> client_done_enqueuing_attacks;
|
||||
parray<uint8_t, 4> player_ready_to_end_phase;
|
||||
uint32_t unknown_a10;
|
||||
uint32_t overall_time_expired;
|
||||
// Note: In the original implementation, this is a uint32_t and is measured in
|
||||
// seconds. In our environment, the simplest implementation uses now(), which
|
||||
// returns microseconds, so we use a uint64_t instead.
|
||||
uint64_t battle_start_usecs;
|
||||
uint32_t should_copy_prev_states_to_current_states;
|
||||
std::shared_ptr<CardSpecial> card_special;
|
||||
std::shared_ptr<StateFlags> state_flags;
|
||||
std::shared_ptr<PlayerState> player_states[4];
|
||||
parray<uint32_t, 4> clients_done_in_mulligan_phase;
|
||||
uint32_t num_pending_attacks_with_cards;
|
||||
std::shared_ptr<Card> attack_cards[0x20];
|
||||
ActionState pending_attacks_with_cards[0x20];
|
||||
uint32_t unknown_a14;
|
||||
uint32_t unknown_a15;
|
||||
parray<uint32_t, 4> defense_list_ended_for_client;
|
||||
std::shared_ptr<AssistServer> assist_server;
|
||||
uint16_t next_assist_card_set_number;
|
||||
std::shared_ptr<RulerServer> ruler_server;
|
||||
parray<parray<parray<uint8_t, 2>, 2>, 5> warp_positions; // Array indexes are (type, end, x/y)
|
||||
parray<int16_t, 2> team_exp;
|
||||
parray<int16_t, 2> team_dice_boost;
|
||||
parray<uint32_t, 2> team_client_count;
|
||||
parray<uint32_t, 2> team_num_ally_fcs_destroyed;
|
||||
parray<uint32_t, 2> team_num_cards_destroyed;
|
||||
parray<uint8_t, 5> num_trap_tiles_of_type;
|
||||
parray<uint8_t, 5> chosen_trap_tile_index_of_type;
|
||||
parray<parray<parray<uint8_t, 2>, 8>, 5> trap_tile_locs;
|
||||
ActionState pb_action_states[4];
|
||||
parray<uint8_t, 4> has_done_pb;
|
||||
parray<parray<uint8_t, 4>, 4> has_done_pb_with_client;
|
||||
mutable uint32_t num_6xB4x06_commands_sent;
|
||||
mutable uint32_t prev_num_6xB4x06_commands_sent;
|
||||
};
|
||||
|
||||
} // namespace Episode3
|
||||
@@ -0,0 +1,951 @@
|
||||
#include "Tournament.hh"
|
||||
|
||||
#include <phosg/Random.hh>
|
||||
|
||||
#include "../CommandFormats.hh"
|
||||
#include "../SendCommands.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
Tournament::PlayerEntry::PlayerEntry(uint32_t serial_number, const string& player_name)
|
||||
: serial_number(serial_number),
|
||||
player_name(player_name) {}
|
||||
|
||||
Tournament::PlayerEntry::PlayerEntry(shared_ptr<Client> c)
|
||||
: serial_number(c->license->serial_number),
|
||||
client(c),
|
||||
player_name(encode_sjis(c->game_data.player()->disp.name)) {}
|
||||
|
||||
Tournament::PlayerEntry::PlayerEntry(
|
||||
shared_ptr<const COMDeckDefinition> com_deck)
|
||||
: serial_number(0),
|
||||
com_deck(com_deck) {}
|
||||
|
||||
bool Tournament::PlayerEntry::is_com() const {
|
||||
return (this->com_deck != nullptr);
|
||||
}
|
||||
|
||||
bool Tournament::PlayerEntry::is_human() const {
|
||||
return (this->serial_number != 0);
|
||||
}
|
||||
|
||||
Tournament::Team::Team(
|
||||
shared_ptr<Tournament> tournament, size_t index, size_t max_players)
|
||||
: tournament(tournament),
|
||||
index(index),
|
||||
max_players(max_players),
|
||||
name(""),
|
||||
password(""),
|
||||
num_rounds_cleared(0),
|
||||
is_active(true) {}
|
||||
|
||||
string Tournament::Team::str() const {
|
||||
size_t num_human_players = 0;
|
||||
size_t num_com_players = 0;
|
||||
for (const auto& player : this->players) {
|
||||
num_human_players += player.is_human();
|
||||
num_com_players += player.is_com();
|
||||
}
|
||||
|
||||
string ret = string_printf("[Team/%zu %s %zuH/%zuC/%zuP name=%s pass=%s rounds=%zu",
|
||||
this->index, this->is_active ? "active" : "inactive",
|
||||
num_human_players, num_com_players, this->max_players, this->name.c_str(),
|
||||
this->password.c_str(), this->num_rounds_cleared);
|
||||
for (const auto& player : this->players) {
|
||||
if (player.is_human()) {
|
||||
if (player.player_name.empty()) {
|
||||
ret += string_printf(" %08" PRIX32, player.serial_number);
|
||||
} else {
|
||||
ret += string_printf(" %08" PRIX32 " (%s)", player.serial_number, player.player_name.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret + "]";
|
||||
}
|
||||
|
||||
void Tournament::Team::register_player(
|
||||
shared_ptr<Client> c,
|
||||
const string& team_name,
|
||||
const string& password) {
|
||||
if (this->players.size() >= this->max_players) {
|
||||
throw runtime_error("team is full");
|
||||
}
|
||||
|
||||
if (!this->name.empty() && (password != this->password)) {
|
||||
throw runtime_error("incorrect password");
|
||||
}
|
||||
|
||||
auto tournament = this->tournament.lock();
|
||||
if (!tournament) {
|
||||
throw runtime_error("tournament has been deleted");
|
||||
}
|
||||
if (!tournament->all_player_serial_numbers.emplace(c->license->serial_number).second) {
|
||||
throw runtime_error("player already registered in same tournament");
|
||||
}
|
||||
|
||||
for (const auto& player : this->players) {
|
||||
if (player.is_human() && (player.serial_number == c->license->serial_number)) {
|
||||
throw logic_error("player already registered in team but not in tournament");
|
||||
}
|
||||
}
|
||||
|
||||
this->players.emplace_back(c);
|
||||
|
||||
if (this->name.empty()) {
|
||||
this->name = team_name;
|
||||
this->password = password;
|
||||
}
|
||||
}
|
||||
|
||||
bool Tournament::Team::unregister_player(uint32_t serial_number) {
|
||||
size_t index;
|
||||
for (index = 0; index < this->players.size(); index++) {
|
||||
if (this->players[index].is_human() &&
|
||||
(this->players[index].serial_number == serial_number)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (index < this->players.size()) {
|
||||
this->players.erase(this->players.begin() + index);
|
||||
|
||||
if (this->players.empty()) {
|
||||
this->name.clear();
|
||||
this->password.clear();
|
||||
}
|
||||
|
||||
auto tournament = this->tournament.lock();
|
||||
if (!tournament) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the tournament has already started, make the team forfeit their game.
|
||||
// If any player withdraws from a team after the registration phase, the
|
||||
// entire team essentially forfeits their entry.
|
||||
if (tournament->get_state() != Tournament::State::REGISTRATION) {
|
||||
// Look through the pending matches to see if this team is involved in any
|
||||
// of them
|
||||
for (auto match : tournament->pending_matches) {
|
||||
if (!match->preceding_a || !match->preceding_b) {
|
||||
throw logic_error("zero-round match is pending after tournament registration phase");
|
||||
}
|
||||
if (match->preceding_a->winner_team.get() == this) {
|
||||
match->set_winner_team(match->preceding_b->winner_team);
|
||||
break;
|
||||
} else if (match->preceding_b->winner_team.get() == this) {
|
||||
match->set_winner_team(match->preceding_a->winner_team);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If the tournament has not started yet, just remove the player from the
|
||||
// team
|
||||
} else {
|
||||
if (!tournament->all_player_serial_numbers.erase(serial_number)) {
|
||||
throw logic_error("player removed from team but not from tournament");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Tournament::Team::has_any_human_players() const {
|
||||
for (const auto& player : this->players) {
|
||||
if (player.is_human()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t Tournament::Team::num_human_players() const {
|
||||
size_t ret = 0;
|
||||
for (const auto& player : this->players) {
|
||||
ret += player.is_human();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t Tournament::Team::num_com_players() const {
|
||||
size_t ret = 0;
|
||||
for (const auto& player : this->players) {
|
||||
ret += player.is_com();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Tournament::Match::Match(
|
||||
shared_ptr<Tournament> tournament,
|
||||
shared_ptr<Match> preceding_a,
|
||||
shared_ptr<Match> preceding_b)
|
||||
: tournament(tournament),
|
||||
preceding_a(preceding_a),
|
||||
preceding_b(preceding_b),
|
||||
winner_team(nullptr),
|
||||
round_num(0) {
|
||||
if (this->preceding_a->round_num != this->preceding_b->round_num) {
|
||||
throw logic_error("preceding matches have different round numbers");
|
||||
}
|
||||
this->round_num = this->preceding_a->round_num + 1;
|
||||
}
|
||||
|
||||
Tournament::Match::Match(
|
||||
shared_ptr<Tournament> tournament,
|
||||
shared_ptr<Team> winner_team)
|
||||
: tournament(tournament),
|
||||
preceding_a(nullptr),
|
||||
preceding_b(nullptr),
|
||||
winner_team(winner_team),
|
||||
round_num(0) {}
|
||||
|
||||
string Tournament::Match::str() const {
|
||||
string winner_str = this->winner_team ? this->winner_team->str() : "(none)";
|
||||
return string_printf("[Match round=%zu winner=%s]", this->round_num, winner_str.c_str());
|
||||
}
|
||||
|
||||
bool Tournament::Match::resolve_if_skippable() {
|
||||
if (this->winner_team) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto winner_a = this->preceding_a->winner_team;
|
||||
auto winner_b = this->preceding_b->winner_team;
|
||||
|
||||
// If at least one match before this is not resolved, don't resolve this one
|
||||
if (!winner_a || !winner_b) {
|
||||
return false;
|
||||
}
|
||||
// If one of the preceding winner teams is empty, make the other the winner
|
||||
if (winner_a->players.empty() != winner_b->players.empty()) {
|
||||
this->set_winner_team(winner_a->players.empty() ? winner_b : winner_a);
|
||||
return true;
|
||||
}
|
||||
// If neither preceding winner team has any humans on it, skip this match
|
||||
// entirely and just make one team advance arbitrarily (note that this also
|
||||
// handles the case where both preceding winner teams are empty)
|
||||
if (!winner_a->has_any_human_players() && !winner_b->has_any_human_players()) {
|
||||
this->set_winner_team((random_object<uint8_t>() & 1) ? winner_b : winner_a);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Tournament::Match::on_winner_team_set() {
|
||||
auto tournament = this->tournament.lock();
|
||||
if (!tournament) {
|
||||
return;
|
||||
}
|
||||
|
||||
tournament->pending_matches.erase(this->shared_from_this());
|
||||
|
||||
// Resolve the following match if possible (this skips CPU-only matches). If
|
||||
// the following match can't be resolved, mark it pending.
|
||||
auto following = this->following.lock();
|
||||
if (following && !following->resolve_if_skippable()) {
|
||||
tournament->pending_matches.emplace(following);
|
||||
}
|
||||
|
||||
// If there are no pending matches, then the tournament is complete
|
||||
if (tournament->pending_matches.empty()) {
|
||||
tournament->current_state = Tournament::State::COMPLETE;
|
||||
}
|
||||
|
||||
// Unlink the losing team's players (if any) - this allows them to enter
|
||||
// another tournament before this tournament has ended
|
||||
if (this->preceding_a && this->preceding_b) {
|
||||
auto losing_team = (this->winner_team == this->preceding_a->winner_team)
|
||||
? this->preceding_b->winner_team
|
||||
: this->preceding_a->winner_team;
|
||||
for (auto& player : losing_team->players) {
|
||||
auto c = player.client.lock();
|
||||
if (c) {
|
||||
c->ep3_tournament_team.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Tournament::Match::set_winner_team_without_triggers(shared_ptr<Team> team) {
|
||||
if (!this->preceding_a || !this->preceding_b) {
|
||||
throw logic_error("set_winner_team called on zero-round match");
|
||||
}
|
||||
if ((team != this->preceding_a->winner_team) &&
|
||||
(team != this->preceding_b->winner_team)) {
|
||||
throw logic_error("winner team did not participate in match");
|
||||
}
|
||||
|
||||
this->winner_team = team;
|
||||
|
||||
this->winner_team->num_rounds_cleared++;
|
||||
if (this->winner_team == this->preceding_a->winner_team) {
|
||||
this->preceding_b->winner_team->is_active = false;
|
||||
} else {
|
||||
this->preceding_a->winner_team->is_active = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Tournament::Match::set_winner_team(shared_ptr<Team> team) {
|
||||
this->set_winner_team_without_triggers(team);
|
||||
this->on_winner_team_set();
|
||||
}
|
||||
|
||||
shared_ptr<Tournament::Team> Tournament::Match::opponent_team_for_team(
|
||||
shared_ptr<Team> team) const {
|
||||
if (!this->preceding_a || !this->preceding_b) {
|
||||
throw logic_error("zero-round matches do not have opponents");
|
||||
}
|
||||
if (team == this->preceding_a->winner_team) {
|
||||
return this->preceding_b->winner_team;
|
||||
} else if (team == this->preceding_b->winner_team) {
|
||||
return this->preceding_a->winner_team;
|
||||
} else {
|
||||
throw logic_error("team is not registered for this match");
|
||||
}
|
||||
}
|
||||
|
||||
Tournament::Tournament(
|
||||
shared_ptr<const MapIndex> map_index,
|
||||
shared_ptr<const COMDeckIndex> com_deck_index,
|
||||
const string& name,
|
||||
shared_ptr<const MapIndex::Map> map,
|
||||
const Rules& rules,
|
||||
size_t num_teams,
|
||||
uint8_t flags)
|
||||
: log(string_printf("[Tournament/%s] ", name.c_str())),
|
||||
map_index(map_index),
|
||||
com_deck_index(com_deck_index),
|
||||
name(name),
|
||||
map(map),
|
||||
rules(rules),
|
||||
num_teams(num_teams),
|
||||
flags(flags),
|
||||
current_state(State::REGISTRATION),
|
||||
menu_item_id(0xFFFFFFFF) {
|
||||
if (this->num_teams < 4) {
|
||||
throw invalid_argument("team count must be 4 or more");
|
||||
}
|
||||
if (this->num_teams > 32) {
|
||||
throw invalid_argument("team count must be 32 or fewer");
|
||||
}
|
||||
if (this->num_teams & (this->num_teams - 1)) {
|
||||
throw invalid_argument("team count must be a power of 2");
|
||||
}
|
||||
}
|
||||
|
||||
Tournament::Tournament(
|
||||
shared_ptr<const MapIndex> map_index,
|
||||
shared_ptr<const COMDeckIndex> com_deck_index,
|
||||
const JSON& json)
|
||||
: log(string_printf("[Tournament/%s] ", json.get_string("name").c_str())),
|
||||
map_index(map_index),
|
||||
com_deck_index(com_deck_index),
|
||||
source_json(json),
|
||||
current_state(State::REGISTRATION) {}
|
||||
|
||||
void Tournament::init() {
|
||||
vector<size_t> team_index_to_rounds_cleared;
|
||||
|
||||
bool is_registration_complete;
|
||||
if (!this->source_json.is_null()) {
|
||||
this->name = this->source_json.get_string("name");
|
||||
this->map = this->map_index->for_number(this->source_json.get_int("map_number"));
|
||||
this->rules = Rules(this->source_json.at("rules"));
|
||||
this->flags = this->source_json.get_int("flags", 0x02);
|
||||
if (this->source_json.get_bool("is_2v2", false)) {
|
||||
this->flags |= Flag::IS_2V2;
|
||||
}
|
||||
is_registration_complete = this->source_json.get_bool("is_registration_complete");
|
||||
|
||||
for (const auto& team_json : this->source_json.get_list("teams")) {
|
||||
auto& team = this->teams.emplace_back(new Team(
|
||||
this->shared_from_this(),
|
||||
this->teams.size(),
|
||||
team_json->get_int("max_players")));
|
||||
team->name = team_json->get_string("name");
|
||||
team->password = team_json->get_string("password");
|
||||
team_index_to_rounds_cleared.emplace_back(team_json->get_int("num_rounds_cleared"));
|
||||
for (const auto& player_json : team_json->get_list("player_specs")) {
|
||||
if (player_json->is_list()) {
|
||||
uint32_t serial_number = player_json->at(0).as_int();
|
||||
team->players.emplace_back(serial_number, player_json->at(1).as_string());
|
||||
this->all_player_serial_numbers.emplace(serial_number);
|
||||
} else if (player_json->is_int()) {
|
||||
uint32_t serial_number = player_json->as_int();
|
||||
team->players.emplace_back(serial_number);
|
||||
this->all_player_serial_numbers.emplace(serial_number);
|
||||
} else if (player_json->is_string()) {
|
||||
team->players.emplace_back(this->com_deck_index->deck_for_name(player_json->as_string()));
|
||||
} else {
|
||||
throw runtime_error("invalid player spec");
|
||||
}
|
||||
}
|
||||
}
|
||||
this->num_teams = this->teams.size();
|
||||
|
||||
this->source_json = nullptr;
|
||||
|
||||
} else {
|
||||
// Create empty teams
|
||||
while (this->teams.size() < this->num_teams) {
|
||||
auto t = make_shared<Team>(
|
||||
this->shared_from_this(), this->teams.size(), (this->flags & Flag::IS_2V2) ? 2 : 1);
|
||||
this->teams.emplace_back(t);
|
||||
}
|
||||
is_registration_complete = false;
|
||||
}
|
||||
|
||||
// Compute the match state from the teams' states
|
||||
if (is_registration_complete) {
|
||||
this->current_state = State::IN_PROGRESS;
|
||||
this->create_bracket_matches();
|
||||
|
||||
// Start with all zero-round matches in the match queue
|
||||
unordered_set<shared_ptr<Match>> match_queue;
|
||||
for (auto match : this->zero_round_matches) {
|
||||
match_queue.emplace(match->following.lock());
|
||||
}
|
||||
if (match_queue.count(nullptr)) {
|
||||
throw logic_error("null match in match queue");
|
||||
}
|
||||
|
||||
// For each match in the queue, either resolve it from the previous state or
|
||||
// mark it as unresolvable (hence it should be pending when we're done)
|
||||
while (!match_queue.empty()) {
|
||||
auto match_it = match_queue.begin();
|
||||
auto match = *match_it;
|
||||
match_queue.erase(match_it);
|
||||
|
||||
if (!match->preceding_a->winner_team || !match->preceding_b->winner_team) {
|
||||
throw logic_error("preceding matches are not resolved");
|
||||
}
|
||||
size_t& a_rounds_cleared = team_index_to_rounds_cleared[match->preceding_a->winner_team->index];
|
||||
size_t& b_rounds_cleared = team_index_to_rounds_cleared[match->preceding_b->winner_team->index];
|
||||
if (a_rounds_cleared && b_rounds_cleared) {
|
||||
throw runtime_error("both teams won the same match");
|
||||
}
|
||||
if (!a_rounds_cleared && !b_rounds_cleared) {
|
||||
this->pending_matches.emplace(match); // Neither team has won yet
|
||||
} else {
|
||||
if (a_rounds_cleared) {
|
||||
a_rounds_cleared--;
|
||||
match->set_winner_team_without_triggers(match->preceding_a->winner_team);
|
||||
} else {
|
||||
b_rounds_cleared--;
|
||||
match->set_winner_team_without_triggers(match->preceding_b->winner_team);
|
||||
}
|
||||
|
||||
// If both preceding matches of the following match are resolved, put
|
||||
// the following match on the queue since it may be resolvable as well
|
||||
auto following = match->following.lock();
|
||||
if (following &&
|
||||
following->preceding_a->winner_team &&
|
||||
following->preceding_b->winner_team) {
|
||||
match_queue.emplace(following);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!this->final_match->winner_team == this->pending_matches.empty()) {
|
||||
throw logic_error("there must be pending matches if and only if the final match is not resolved");
|
||||
}
|
||||
|
||||
// If all matches are resolved, then the tournament is complete
|
||||
if (this->final_match->winner_team) {
|
||||
this->current_state = State::COMPLETE;
|
||||
}
|
||||
|
||||
} else {
|
||||
this->current_state = State::REGISTRATION;
|
||||
}
|
||||
}
|
||||
|
||||
void Tournament::create_bracket_matches() {
|
||||
if (this->teams.size() < 4) {
|
||||
throw logic_error("tournaments must have at least 4 teams");
|
||||
}
|
||||
if (this->teams.size() > 32) {
|
||||
throw logic_error("tournaments must have at most 32 teams");
|
||||
}
|
||||
if (this->teams.size() & (this->teams.size() - 1)) {
|
||||
throw logic_error("tournaments team count is not a power of 2");
|
||||
}
|
||||
|
||||
// Create the zero-round matches, and make them all pending if registration
|
||||
// is still open
|
||||
this->zero_round_matches.clear();
|
||||
for (const auto& team : this->teams) {
|
||||
auto m = make_shared<Match>(this->shared_from_this(), team);
|
||||
this->zero_round_matches.emplace_back(m);
|
||||
if (this->current_state == State::REGISTRATION) {
|
||||
this->pending_matches.emplace(m);
|
||||
}
|
||||
}
|
||||
|
||||
// Create the bracket matches
|
||||
vector<shared_ptr<Match>> current_round_matches = this->zero_round_matches;
|
||||
while (current_round_matches.size() > 1) {
|
||||
vector<shared_ptr<Match>> next_round_matches;
|
||||
for (size_t z = 0; z < current_round_matches.size(); z += 2) {
|
||||
auto m = make_shared<Match>(
|
||||
this->shared_from_this(),
|
||||
current_round_matches[z],
|
||||
current_round_matches[z + 1]);
|
||||
current_round_matches[z]->following = m;
|
||||
current_round_matches[z + 1]->following = m;
|
||||
next_round_matches.emplace_back(std::move(m));
|
||||
}
|
||||
current_round_matches = std::move(next_round_matches);
|
||||
}
|
||||
this->final_match = current_round_matches.at(0);
|
||||
}
|
||||
|
||||
JSON Tournament::json() const {
|
||||
auto teams_list = JSON::list();
|
||||
for (auto team : this->teams) {
|
||||
auto players_list = JSON::list();
|
||||
for (const auto& player : team->players) {
|
||||
if (player.is_human()) {
|
||||
if (!player.player_name.empty()) {
|
||||
players_list.emplace_back(JSON::list({player.serial_number, player.player_name}));
|
||||
} else {
|
||||
players_list.emplace_back(player.serial_number);
|
||||
}
|
||||
} else {
|
||||
players_list.emplace_back(player.com_deck->deck_name);
|
||||
}
|
||||
}
|
||||
teams_list.emplace_back(JSON::dict({
|
||||
{"max_players", team->max_players},
|
||||
{"player_specs", std::move(players_list)},
|
||||
{"name", team->name},
|
||||
{"password", team->password},
|
||||
{"num_rounds_cleared", team->num_rounds_cleared},
|
||||
}));
|
||||
}
|
||||
return JSON::dict({
|
||||
{"name", this->name},
|
||||
{"map_number", this->map->map_number},
|
||||
{"rules", this->rules.json()},
|
||||
{"flags", this->flags},
|
||||
{"is_registration_complete", (this->current_state != State::REGISTRATION)},
|
||||
{"teams", std::move(teams_list)},
|
||||
});
|
||||
}
|
||||
|
||||
shared_ptr<Tournament::Team> Tournament::get_winner_team() const {
|
||||
if (this->current_state != State::COMPLETE) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!this->final_match) {
|
||||
throw logic_error("tournament is complete but final match is missing");
|
||||
}
|
||||
if (!this->final_match->winner_team) {
|
||||
throw logic_error("tournament is complete but winner is not set");
|
||||
}
|
||||
return this->final_match->winner_team;
|
||||
}
|
||||
|
||||
shared_ptr<Tournament::Match> Tournament::next_match_for_team(
|
||||
shared_ptr<Team> team) const {
|
||||
if (this->current_state == Tournament::State::REGISTRATION) {
|
||||
return nullptr;
|
||||
}
|
||||
for (auto match : this->pending_matches) {
|
||||
if (!match->preceding_a || !match->preceding_b) {
|
||||
throw logic_error("zero-round match is pending after tournament registration phase");
|
||||
}
|
||||
if ((team == match->preceding_a->winner_team) ||
|
||||
(team == match->preceding_b->winner_team)) {
|
||||
return match;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
shared_ptr<Tournament::Match> Tournament::get_final_match() const {
|
||||
return this->final_match;
|
||||
}
|
||||
|
||||
shared_ptr<Tournament::Team> Tournament::team_for_serial_number(
|
||||
uint32_t serial_number) const {
|
||||
if (!this->all_player_serial_numbers.count(serial_number)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (auto team : this->teams) {
|
||||
for (const auto& player : team->players) {
|
||||
if (player.serial_number == serial_number) {
|
||||
return team->is_active ? team : nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw logic_error("serial number registered in tournament but not in any team");
|
||||
}
|
||||
|
||||
const set<uint32_t>& Tournament::get_all_player_serial_numbers() const {
|
||||
return this->all_player_serial_numbers;
|
||||
}
|
||||
|
||||
void Tournament::start() {
|
||||
if (this->current_state != State::REGISTRATION) {
|
||||
throw runtime_error("tournament has already started");
|
||||
}
|
||||
|
||||
bool has_com_teams = (this->flags & Flag::HAS_COM_TEAMS);
|
||||
|
||||
// If there aren't enough entrants (1 if has_com_teams is false, else 2),
|
||||
// don't allow the tournament to start (because it would enter the COMPLETE
|
||||
// state immediately)
|
||||
size_t num_human_teams = 0;
|
||||
for (size_t z = 0; z < this->teams.size(); z++) {
|
||||
if (this->teams[z]->has_any_human_players()) {
|
||||
num_human_teams++;
|
||||
}
|
||||
}
|
||||
if (num_human_teams < (has_com_teams ? 1 : 2)) {
|
||||
throw runtime_error("not enough registrants to start tournament");
|
||||
}
|
||||
|
||||
if ((this->flags & Flag::SHUFFLE_ENTRIES) && (this->flags & Flag::RESIZE_ON_START)) {
|
||||
// If both of these flags are set, pack the human teams into the lowest part
|
||||
// of the teams list so we can resize the tournament to the smallest
|
||||
// possible size. This is OK since we're going to shuffle them later anyway
|
||||
size_t r_offset = 0, w_offset = 0;
|
||||
for (; r_offset < this->teams.size(); r_offset++) {
|
||||
if (this->teams[r_offset]->has_any_human_players()) {
|
||||
if (r_offset != w_offset) {
|
||||
this->teams[r_offset].swap(this->teams[w_offset]);
|
||||
}
|
||||
w_offset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this->flags & Flag::RESIZE_ON_START) {
|
||||
// Resize the tournament by repeatedly deleting the second half of it, until
|
||||
// the second half contains human players or the tournament size is 4
|
||||
while (this->teams.size() > 4) {
|
||||
size_t z;
|
||||
for (z = this->teams.size() >> 1; z < this->teams.size(); z++) {
|
||||
if (this->teams[z]->has_any_human_players()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (z == this->teams.size()) {
|
||||
this->teams.resize(this->teams.size() >> 1);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->num_teams = this->teams.size();
|
||||
}
|
||||
|
||||
if (this->flags & Flag::SHUFFLE_ENTRIES) {
|
||||
// Shuffle all the tournament entries
|
||||
for (size_t z = this->teams.size(); z > 0; z--) {
|
||||
size_t index = random_object<uint32_t>() % z;
|
||||
if (index != z - 1) {
|
||||
this->teams[z - 1].swap(this->teams[index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->current_state = State::IN_PROGRESS;
|
||||
this->create_bracket_matches();
|
||||
|
||||
// Assign names to COM teams, and assign COM decks to all empty slots unless
|
||||
// has_com_teams is false
|
||||
for (size_t z = 0; z < this->zero_round_matches.size(); z++) {
|
||||
auto m = this->zero_round_matches[z];
|
||||
auto t = m->winner_team;
|
||||
if (t->name.empty()) {
|
||||
t->name = has_com_teams ? string_printf("COM:%zu", z) : "(no entrant)";
|
||||
}
|
||||
for (const auto& player : t->players) {
|
||||
if (player.is_com()) {
|
||||
throw logic_error("non-human player on team before tournament start");
|
||||
}
|
||||
}
|
||||
if (this->com_deck_index->num_decks() < t->max_players - t->players.size()) {
|
||||
throw runtime_error("not enough COM decks to complete team");
|
||||
}
|
||||
// If we allow all-COM teams, or this is a 2v2 tournament and the team has
|
||||
// only one human on it, add a COM
|
||||
if (has_com_teams || !t->players.empty()) {
|
||||
// TODO: Don't allow duplicate COM decks, nor duplicate COM SCs on the
|
||||
// same team
|
||||
while (t->players.size() < t->max_players) {
|
||||
t->players.emplace_back(this->com_deck_index->random_deck());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve all possible skippable matches
|
||||
for (auto m : this->zero_round_matches) {
|
||||
m->on_winner_team_set();
|
||||
}
|
||||
}
|
||||
|
||||
void Tournament::send_all_state_updates() const {
|
||||
for (const auto& team : this->teams) {
|
||||
for (const auto& player : team->players) {
|
||||
auto c = player.client.lock();
|
||||
// Note: The last check here is to make sure the client is still linked
|
||||
// with this instance of the tournament - an intervening shell command
|
||||
// `reload ep3` could have changed the client's linkage
|
||||
if (c &&
|
||||
(c->flags & Client::Flag::IS_EPISODE_3) &&
|
||||
!(c->flags & Client::Flag::IS_EP3_TRIAL_EDITION) &&
|
||||
(c->ep3_tournament_team.lock() == team)) {
|
||||
send_ep3_confirm_tournament_entry(c, this->shared_from_this());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Tournament::send_all_state_updates_on_deletion() const {
|
||||
for (const auto& team : this->teams) {
|
||||
for (const auto& player : team->players) {
|
||||
auto c = player.client.lock();
|
||||
if (c &&
|
||||
(c->flags & Client::Flag::IS_EPISODE_3) &&
|
||||
!(c->flags & Client::Flag::IS_EP3_TRIAL_EDITION) &&
|
||||
(c->ep3_tournament_team.lock() == team)) {
|
||||
send_ep3_confirm_tournament_entry(c, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Tournament::print_bracket(FILE* stream) const {
|
||||
function<void(shared_ptr<Match>, size_t)> print_match = [&](shared_ptr<Match> m, size_t indent_level) -> void {
|
||||
for (size_t z = 0; z < indent_level; z++) {
|
||||
fputc(' ', stream);
|
||||
fputc(' ', stream);
|
||||
}
|
||||
string match_str = m->str();
|
||||
fprintf(stream, "%s%s\n", match_str.c_str(), this->pending_matches.count(m) ? " (PENDING)" : "");
|
||||
if (m->preceding_a) {
|
||||
print_match(m->preceding_a, indent_level + 1);
|
||||
}
|
||||
if (m->preceding_b) {
|
||||
print_match(m->preceding_b, indent_level + 1);
|
||||
}
|
||||
};
|
||||
fprintf(stream, "Tournament \"%s\"\n", this->name.c_str());
|
||||
auto en_vm = this->map->version(1);
|
||||
if (en_vm) {
|
||||
string map_name = en_vm->map->name;
|
||||
fprintf(stream, " Map: %08" PRIX32 " (%s)\n", this->map->map_number, map_name.c_str());
|
||||
} else {
|
||||
fprintf(stream, " Map: %08" PRIX32 "\n", this->map->map_number);
|
||||
}
|
||||
string rules_str = this->rules.str();
|
||||
fprintf(stream, " Rules: %s\n", rules_str.c_str());
|
||||
fprintf(stream, " Structure: %s, %zu entries\n", (this->flags & Flag::IS_2V2) ? "2v2" : "1v1", this->num_teams);
|
||||
fprintf(stream, " COM teams: %s\n", (this->flags & Flag::HAS_COM_TEAMS) ? "allowed" : "forbidden");
|
||||
fprintf(stream, " Shuffle entries: %s\n", (this->flags & Flag::SHUFFLE_ENTRIES) ? "yes" : "no");
|
||||
fprintf(stream, " Resize on start: %s\n", (this->flags & Flag::RESIZE_ON_START) ? "yes" : "no");
|
||||
switch (this->current_state) {
|
||||
case State::REGISTRATION:
|
||||
fprintf(stream, " State: REGISTRATION\n");
|
||||
break;
|
||||
case State::IN_PROGRESS:
|
||||
fprintf(stream, " State: IN_PROGRESS\n");
|
||||
break;
|
||||
case State::COMPLETE:
|
||||
fprintf(stream, " State: COMPLETE\n");
|
||||
break;
|
||||
default:
|
||||
fprintf(stream, " State: UNKNOWN\n");
|
||||
break;
|
||||
}
|
||||
if (this->final_match) {
|
||||
fprintf(stream, " Standings:\n");
|
||||
print_match(this->final_match, 2);
|
||||
}
|
||||
if (this->current_state == State::REGISTRATION) {
|
||||
fprintf(stream, " Teams:\n");
|
||||
for (const auto& team : this->teams) {
|
||||
string team_str = team->str();
|
||||
fprintf(stream, " %s\n", team_str.c_str());
|
||||
}
|
||||
} else {
|
||||
fprintf(stream, " Pending matches:\n");
|
||||
for (const auto& match : this->pending_matches) {
|
||||
string match_str = match->str();
|
||||
fprintf(stream, " %s\n", match_str.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TournamentIndex::TournamentIndex(
|
||||
shared_ptr<const MapIndex> map_index,
|
||||
shared_ptr<const COMDeckIndex> com_deck_index,
|
||||
const string& state_filename,
|
||||
bool skip_load_state)
|
||||
: map_index(map_index),
|
||||
com_deck_index(com_deck_index),
|
||||
state_filename(state_filename) {
|
||||
if (this->state_filename.empty() || skip_load_state) {
|
||||
return;
|
||||
}
|
||||
|
||||
JSON json;
|
||||
try {
|
||||
json = JSON::parse(load_file(this->state_filename));
|
||||
} catch (const cannot_open_file&) {
|
||||
json = JSON::list();
|
||||
}
|
||||
|
||||
if (json.is_list()) {
|
||||
if (json.size() > 0x20) {
|
||||
throw runtime_error("tournament JSON list length is incorrect");
|
||||
}
|
||||
for (size_t z = 0; z < min<size_t>(json.size(), 0x20); z++) {
|
||||
if (!json.at(z).is_null()) {
|
||||
shared_ptr<Tournament> tourn(new Tournament(this->map_index, this->com_deck_index, json.at(z)));
|
||||
tourn->init();
|
||||
if (!this->name_to_tournament.emplace(tourn->get_name(), tourn).second) {
|
||||
throw runtime_error("multiple tournaments have the same name: " + tourn->get_name());
|
||||
}
|
||||
tourn->set_menu_item_id(this->menu_item_id_to_tournament.size());
|
||||
this->menu_item_id_to_tournament.emplace_back(tourn);
|
||||
}
|
||||
}
|
||||
} else if (json.is_dict()) {
|
||||
if (json.size() > 0x20) {
|
||||
throw runtime_error("tournament JSON dict length is incorrect");
|
||||
}
|
||||
for (const auto& it : json.as_dict()) {
|
||||
shared_ptr<Tournament> tourn(new Tournament(this->map_index, this->com_deck_index, *it.second));
|
||||
tourn->init();
|
||||
if (!this->name_to_tournament.emplace(tourn->get_name(), tourn).second) {
|
||||
// This is logic_error instead of runtime_error because JSON dicts are
|
||||
// supposed to already have unique keys
|
||||
throw logic_error("multiple tournaments have the same name: " + tourn->get_name());
|
||||
}
|
||||
tourn->set_menu_item_id(this->menu_item_id_to_tournament.size());
|
||||
this->menu_item_id_to_tournament.emplace_back(tourn);
|
||||
}
|
||||
} else {
|
||||
throw runtime_error("tournament state root JSON is not a list or dict");
|
||||
}
|
||||
}
|
||||
|
||||
void TournamentIndex::save() const {
|
||||
if (this->state_filename.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto json = JSON::dict();
|
||||
for (const auto& it : this->name_to_tournament) {
|
||||
json.emplace(it.second->get_name(), it.second->json());
|
||||
}
|
||||
save_file(this->state_filename, json.serialize(JSON::SerializeOption::FORMAT | JSON::SerializeOption::HEX_INTEGERS));
|
||||
}
|
||||
|
||||
shared_ptr<Tournament> TournamentIndex::create_tournament(
|
||||
const string& name,
|
||||
shared_ptr<const MapIndex::Map> map,
|
||||
const Rules& rules,
|
||||
size_t num_teams,
|
||||
uint8_t flags) {
|
||||
if (this->name_to_tournament.size() >= 0x20) {
|
||||
throw runtime_error("there can be at most 32 tournaments at a time");
|
||||
}
|
||||
|
||||
auto t = make_shared<Tournament>(
|
||||
this->map_index, this->com_deck_index, name, map, rules, num_teams, flags);
|
||||
t->init();
|
||||
if (!this->name_to_tournament.emplace(t->get_name(), t).second) {
|
||||
throw runtime_error("a tournament with the same name already exists");
|
||||
}
|
||||
|
||||
size_t z;
|
||||
for (z = 0; z < this->menu_item_id_to_tournament.size(); z++) {
|
||||
if (!this->menu_item_id_to_tournament[z]) {
|
||||
t->set_menu_item_id(z);
|
||||
this->menu_item_id_to_tournament[z] = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (z == this->menu_item_id_to_tournament.size()) {
|
||||
t->set_menu_item_id(this->menu_item_id_to_tournament.size());
|
||||
this->menu_item_id_to_tournament.emplace_back(t);
|
||||
}
|
||||
|
||||
this->save();
|
||||
return t;
|
||||
}
|
||||
|
||||
bool TournamentIndex::delete_tournament(const string& name) {
|
||||
auto it = this->name_to_tournament.find(name);
|
||||
if (it == this->name_to_tournament.end()) {
|
||||
return false;
|
||||
}
|
||||
for (size_t z = 0; z < this->menu_item_id_to_tournament.size(); z++) {
|
||||
if (this->menu_item_id_to_tournament[z] == it->second) {
|
||||
this->menu_item_id_to_tournament[z] = nullptr;
|
||||
it->second->set_menu_item_id(0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
it->second->send_all_state_updates_on_deletion();
|
||||
this->name_to_tournament.erase(it);
|
||||
this->save();
|
||||
return true;
|
||||
}
|
||||
|
||||
shared_ptr<Tournament::Team> TournamentIndex::team_for_serial_number(uint32_t serial_number) const {
|
||||
for (const auto& it : this->name_to_tournament) {
|
||||
const auto& tourn = it.second;
|
||||
auto team = tourn->team_for_serial_number(serial_number);
|
||||
if (team) {
|
||||
return team;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void TournamentIndex::link_client(shared_ptr<Client> c) {
|
||||
if (!(c->flags & Client::Flag::IS_EPISODE_3)) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto team = this->team_for_serial_number(c->license->serial_number);
|
||||
auto tourn = team ? team->tournament.lock() : nullptr;
|
||||
if (team && team->is_active && tourn) {
|
||||
for (auto& player : team->players) {
|
||||
if (player.serial_number == c->license->serial_number) {
|
||||
c->ep3_tournament_team = team;
|
||||
player.client = c;
|
||||
if (!(c->flags & Client::Flag::IS_EP3_TRIAL_EDITION)) {
|
||||
send_ep3_confirm_tournament_entry(c, tourn);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw logic_error("tournament team found for player, but player not found on team");
|
||||
} else {
|
||||
c->ep3_tournament_team.reset();
|
||||
if (!(c->flags & Client::Flag::IS_EP3_TRIAL_EDITION)) {
|
||||
send_ep3_confirm_tournament_entry(c, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TournamentIndex::link_all_clients(std::shared_ptr<ServerState> s) {
|
||||
for (const auto& c_it : s->channel_to_client) {
|
||||
this->link_client(c_it.second);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Episode3
|
||||
@@ -0,0 +1,247 @@
|
||||
#pragma once
|
||||
|
||||
#include <event2/event.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <phosg/JSON.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#include "../Player.hh"
|
||||
|
||||
struct Lobby;
|
||||
struct Client;
|
||||
struct ServerState;
|
||||
|
||||
namespace Episode3 {
|
||||
|
||||
class Tournament : public std::enable_shared_from_this<Tournament> {
|
||||
public:
|
||||
enum Flag : uint8_t {
|
||||
IS_2V2 = 0x01,
|
||||
HAS_COM_TEAMS = 0x02,
|
||||
SHUFFLE_ENTRIES = 0x04,
|
||||
RESIZE_ON_START = 0x08,
|
||||
};
|
||||
enum class State {
|
||||
REGISTRATION = 0,
|
||||
IN_PROGRESS,
|
||||
COMPLETE,
|
||||
};
|
||||
|
||||
struct PlayerEntry {
|
||||
// Invariant: (serial_number == 0) != (com_deck == nullptr)
|
||||
// (that is, exactly one of the following must be valid)
|
||||
uint32_t serial_number;
|
||||
std::shared_ptr<const COMDeckDefinition> com_deck;
|
||||
|
||||
// client is valid if serial_number is nonzero and the client is connected
|
||||
std::weak_ptr<Client> client;
|
||||
std::string player_name; // Not used for COM decks
|
||||
|
||||
explicit PlayerEntry(uint32_t serial_number, const std::string& player_name = "");
|
||||
explicit PlayerEntry(std::shared_ptr<Client> c);
|
||||
explicit PlayerEntry(std::shared_ptr<const COMDeckDefinition> com_deck);
|
||||
|
||||
bool is_com() const;
|
||||
bool is_human() const;
|
||||
|
||||
JSON json() const;
|
||||
};
|
||||
|
||||
struct Team : public std::enable_shared_from_this<Team> {
|
||||
std::weak_ptr<Tournament> tournament;
|
||||
size_t index;
|
||||
size_t max_players;
|
||||
|
||||
std::vector<PlayerEntry> players;
|
||||
std::string name;
|
||||
std::string password;
|
||||
size_t num_rounds_cleared;
|
||||
bool is_active;
|
||||
|
||||
Team(
|
||||
std::shared_ptr<Tournament> tournament,
|
||||
size_t index,
|
||||
size_t max_players);
|
||||
std::string str() const;
|
||||
|
||||
void register_player(
|
||||
std::shared_ptr<Client> c,
|
||||
const std::string& team_name,
|
||||
const std::string& password);
|
||||
bool unregister_player(uint32_t serial_number);
|
||||
|
||||
bool has_any_human_players() const;
|
||||
size_t num_human_players() const;
|
||||
size_t num_com_players() const;
|
||||
};
|
||||
|
||||
struct Match : public std::enable_shared_from_this<Match> {
|
||||
std::weak_ptr<Tournament> tournament;
|
||||
std::shared_ptr<Match> preceding_a;
|
||||
std::shared_ptr<Match> preceding_b;
|
||||
std::weak_ptr<Match> following;
|
||||
std::shared_ptr<Team> winner_team;
|
||||
size_t round_num;
|
||||
|
||||
Match(
|
||||
std::shared_ptr<Tournament> tournament,
|
||||
std::shared_ptr<Match> preceding_a,
|
||||
std::shared_ptr<Match> preceding_b);
|
||||
Match(
|
||||
std::shared_ptr<Tournament> tournament,
|
||||
std::shared_ptr<Team> winner_team);
|
||||
std::string str() const;
|
||||
|
||||
bool resolve_if_skippable();
|
||||
void on_winner_team_set();
|
||||
void set_winner_team(std::shared_ptr<Team> team);
|
||||
void set_winner_team_without_triggers(std::shared_ptr<Team> team);
|
||||
std::shared_ptr<Team> opponent_team_for_team(std::shared_ptr<Team> team) const;
|
||||
};
|
||||
|
||||
Tournament(
|
||||
std::shared_ptr<const MapIndex> map_index,
|
||||
std::shared_ptr<const COMDeckIndex> com_deck_index,
|
||||
const std::string& name,
|
||||
std::shared_ptr<const MapIndex::Map> map,
|
||||
const Rules& rules,
|
||||
size_t num_teams,
|
||||
uint8_t flags);
|
||||
Tournament(
|
||||
std::shared_ptr<const MapIndex> map_index,
|
||||
std::shared_ptr<const COMDeckIndex> com_deck_index,
|
||||
const JSON& json);
|
||||
~Tournament() = default;
|
||||
void init();
|
||||
|
||||
JSON json() const;
|
||||
|
||||
inline const std::string& get_name() const {
|
||||
return this->name;
|
||||
}
|
||||
inline std::shared_ptr<const MapIndex::Map> get_map() const {
|
||||
return this->map;
|
||||
}
|
||||
inline const Rules& get_rules() const {
|
||||
return this->rules;
|
||||
}
|
||||
inline uint8_t get_flags() const {
|
||||
return this->flags;
|
||||
}
|
||||
inline State get_state() const {
|
||||
return this->current_state;
|
||||
}
|
||||
inline const std::vector<std::shared_ptr<Team>>& all_teams() const {
|
||||
return this->teams;
|
||||
}
|
||||
inline std::shared_ptr<Team> get_team(size_t index) const {
|
||||
return this->teams.at(index);
|
||||
}
|
||||
inline uint32_t get_menu_item_id() const {
|
||||
return this->menu_item_id;
|
||||
}
|
||||
inline void set_menu_item_id(uint32_t menu_item_id) {
|
||||
this->menu_item_id = menu_item_id;
|
||||
}
|
||||
|
||||
std::shared_ptr<Team> get_winner_team() const;
|
||||
std::shared_ptr<Match> next_match_for_team(std::shared_ptr<Team> team) const;
|
||||
std::shared_ptr<Match> get_final_match() const;
|
||||
std::shared_ptr<Team> team_for_serial_number(uint32_t serial_number) const;
|
||||
const std::set<uint32_t>& get_all_player_serial_numbers() const;
|
||||
|
||||
void start();
|
||||
|
||||
void send_all_state_updates() const;
|
||||
void send_all_state_updates_on_deletion() const;
|
||||
|
||||
void print_bracket(FILE* stream) const;
|
||||
|
||||
private:
|
||||
void create_bracket_matches();
|
||||
|
||||
PrefixedLogger log;
|
||||
|
||||
std::shared_ptr<const MapIndex> map_index;
|
||||
std::shared_ptr<const COMDeckIndex> com_deck_index;
|
||||
JSON source_json;
|
||||
std::string name;
|
||||
std::shared_ptr<const MapIndex::Map> map;
|
||||
Rules rules;
|
||||
size_t num_teams;
|
||||
uint8_t flags;
|
||||
State current_state;
|
||||
uint32_t menu_item_id;
|
||||
|
||||
std::set<uint32_t> all_player_serial_numbers;
|
||||
std::unordered_set<std::shared_ptr<Match>> pending_matches;
|
||||
|
||||
// This vector contains all teams in the original starting order of the
|
||||
// tournament (that is, all teams in the first round). The order within this
|
||||
// vector determines which team will play against which other team in the
|
||||
// first round: [0] will play against [1], [2] will play against [3], etc.
|
||||
std::vector<std::shared_ptr<Team>> teams;
|
||||
// The tournament begins with a "zero round", in which each team automatically
|
||||
// "wins" a match, putting them into the first round. This is just to make the
|
||||
// data model easier to manage, so we don't have to have a type of match with
|
||||
// no preceding round.
|
||||
std::vector<std::shared_ptr<Match>> zero_round_matches;
|
||||
std::shared_ptr<Match> final_match;
|
||||
};
|
||||
|
||||
class TournamentIndex {
|
||||
public:
|
||||
explicit TournamentIndex(
|
||||
std::shared_ptr<const MapIndex> map_index,
|
||||
std::shared_ptr<const COMDeckIndex> com_deck_index,
|
||||
const std::string& state_filename,
|
||||
bool skip_load_state = false);
|
||||
~TournamentIndex() = default;
|
||||
|
||||
void save() const;
|
||||
|
||||
inline const std::unordered_map<std::string, std::shared_ptr<Tournament>>& all_tournaments() const {
|
||||
return this->name_to_tournament;
|
||||
}
|
||||
inline std::shared_ptr<Tournament> get_tournament(uint32_t menu_item_id) const {
|
||||
try {
|
||||
return this->menu_item_id_to_tournament.at(menu_item_id);
|
||||
} catch (const std::out_of_range&) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
inline std::shared_ptr<Tournament> get_tournament(const std::string& name) const {
|
||||
try {
|
||||
return this->name_to_tournament.at(name);
|
||||
} catch (const std::out_of_range&) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Tournament> create_tournament(
|
||||
const std::string& name,
|
||||
std::shared_ptr<const MapIndex::Map> map,
|
||||
const Rules& rules,
|
||||
size_t num_teams,
|
||||
uint8_t flags);
|
||||
bool delete_tournament(const std::string& name);
|
||||
|
||||
std::shared_ptr<Tournament::Team> team_for_serial_number(uint32_t serial_number) const;
|
||||
|
||||
void link_client(std::shared_ptr<Client> c);
|
||||
void link_all_clients(std::shared_ptr<ServerState> s);
|
||||
|
||||
private:
|
||||
std::shared_ptr<const MapIndex> map_index;
|
||||
std::shared_ptr<const COMDeckIndex> com_deck_index;
|
||||
std::string state_filename;
|
||||
std::unordered_map<std::string, std::shared_ptr<Tournament>> name_to_tournament;
|
||||
std::vector<std::shared_ptr<Tournament>> menu_item_id_to_tournament;
|
||||
};
|
||||
|
||||
} // namespace Episode3
|
||||
+53
-20
@@ -7,37 +7,70 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
FileContentsCache::FileContentsCache(uint64_t ttl_usecs) : ttl_usecs(ttl_usecs) {}
|
||||
|
||||
FileContentsCache::File::File(const string& name, shared_ptr<const string> contents,
|
||||
uint64_t load_time) : name(name), contents(contents), load_time(load_time) { }
|
||||
FileContentsCache::File::File(
|
||||
const string& name,
|
||||
string&& data,
|
||||
uint64_t load_time)
|
||||
: name(name),
|
||||
data(new string(std::move(data))),
|
||||
load_time(load_time) {}
|
||||
|
||||
shared_ptr<const string> FileContentsCache::get(const std::string& name) {
|
||||
return this->get(name, [name]() -> string { return load_file(name); });
|
||||
shared_ptr<const FileContentsCache::File> FileContentsCache::replace(
|
||||
const string& name, string&& data, uint64_t t) {
|
||||
if (t == 0) {
|
||||
t = now();
|
||||
}
|
||||
shared_ptr<File> new_file(new File(name, std::move(data), t));
|
||||
auto emplace_ret = this->name_to_file.emplace(name, new_file);
|
||||
if (!emplace_ret.second) {
|
||||
emplace_ret.first->second = new_file;
|
||||
}
|
||||
return new_file;
|
||||
}
|
||||
|
||||
shared_ptr<const string> FileContentsCache::get(const char* name) {
|
||||
return this->get(string(name));
|
||||
shared_ptr<const FileContentsCache::File> FileContentsCache::replace(
|
||||
const string& name, const void* data, size_t size, uint64_t t) {
|
||||
string s(reinterpret_cast<const char*>(data), size);
|
||||
return this->replace(name, std::move(s), t);
|
||||
}
|
||||
|
||||
shared_ptr<const string> FileContentsCache::get(const std::string& name,
|
||||
std::function<std::string()> generate) {
|
||||
FileContentsCache::GetResult FileContentsCache::get_or_load(const std::string& name) {
|
||||
return this->get(name, load_file);
|
||||
}
|
||||
|
||||
FileContentsCache::GetResult FileContentsCache::get_or_load(const char* name) {
|
||||
return this->get_or_load(string(name));
|
||||
}
|
||||
|
||||
shared_ptr<const FileContentsCache::File> FileContentsCache::get_or_throw(
|
||||
const std::string& name) {
|
||||
auto throw_fn = +[](const std::string&) -> string {
|
||||
throw out_of_range("file missing from cache");
|
||||
};
|
||||
return this->get(name, throw_fn).file;
|
||||
}
|
||||
|
||||
shared_ptr<const FileContentsCache::File> FileContentsCache::get_or_throw(
|
||||
const char* name) {
|
||||
return this->get_or_throw(string(name));
|
||||
}
|
||||
|
||||
FileContentsCache::GetResult FileContentsCache::get(const std::string& name,
|
||||
std::function<std::string(const std::string&)> generate) {
|
||||
uint64_t t = now();
|
||||
try {
|
||||
auto& entry = this->name_to_file.at(name);
|
||||
if (t - entry.load_time < 300000000) { // not 5 minutes old? return it
|
||||
return entry.contents;
|
||||
if (this->ttl_usecs && (t - entry->load_time < this->ttl_usecs)) {
|
||||
return {entry, false};
|
||||
}
|
||||
} catch (const out_of_range& e) { }
|
||||
|
||||
shared_ptr<const string> contents(new string(generate()));
|
||||
this->name_to_file.erase(name);
|
||||
this->name_to_file.emplace(piecewise_construct, forward_as_tuple(name),
|
||||
forward_as_tuple(name, contents, t));
|
||||
|
||||
return contents;
|
||||
} catch (const out_of_range& e) {
|
||||
}
|
||||
return {this->replace(name, generate(name)), true};
|
||||
}
|
||||
|
||||
shared_ptr<const string> FileContentsCache::get(const char* name,
|
||||
std::function<std::string()> generate) {
|
||||
FileContentsCache::GetResult FileContentsCache::get(const char* name,
|
||||
std::function<std::string(const std::string&)> generate) {
|
||||
return this->get(string(name), generate);
|
||||
}
|
||||
|
||||
+74
-16
@@ -1,23 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <functional>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include <phosg/Time.hh>
|
||||
|
||||
class FileContentsCache {
|
||||
private:
|
||||
public:
|
||||
struct File {
|
||||
std::string name;
|
||||
std::shared_ptr<const std::string> contents;
|
||||
std::shared_ptr<const std::string> data;
|
||||
uint64_t load_time;
|
||||
|
||||
File() = delete;
|
||||
File(const std::string& name, std::shared_ptr<const std::string> contents,
|
||||
uint64_t load_time);
|
||||
File(const std::string& name, std::string&& contents, uint64_t load_time);
|
||||
File(const File&) = delete;
|
||||
File(File&&) = delete;
|
||||
File& operator=(const File&) = delete;
|
||||
@@ -25,22 +23,82 @@ private:
|
||||
~File() = default;
|
||||
};
|
||||
|
||||
public:
|
||||
FileContentsCache() = default;
|
||||
explicit FileContentsCache(uint64_t ttl_usecs);
|
||||
FileContentsCache(const FileContentsCache&) = delete;
|
||||
FileContentsCache(FileContentsCache&&) = delete;
|
||||
FileContentsCache& operator=(const FileContentsCache&) = delete;
|
||||
FileContentsCache& operator=(FileContentsCache&&) = delete;
|
||||
~FileContentsCache() = default;
|
||||
|
||||
std::shared_ptr<const std::string> get(const std::string& name);
|
||||
std::shared_ptr<const std::string> get(const char* name);
|
||||
template <typename NameT>
|
||||
bool delete_key(NameT key) {
|
||||
return this->name_to_file.erase(key);
|
||||
}
|
||||
|
||||
std::shared_ptr<const std::string> get(
|
||||
const std::string& name, std::function<std::string()> generate);
|
||||
std::shared_ptr<const std::string> get(
|
||||
const char* name, std::function<std::string()> generate);
|
||||
std::shared_ptr<const File> replace(const std::string& name, std::string&& data, uint64_t t = 0);
|
||||
std::shared_ptr<const File> replace(const std::string& name, const void* data, size_t size, uint64_t t = 0);
|
||||
|
||||
struct GetResult {
|
||||
std::shared_ptr<const File> file;
|
||||
bool generate_called;
|
||||
};
|
||||
|
||||
GetResult get_or_load(const std::string& name);
|
||||
GetResult get_or_load(const char* name);
|
||||
std::shared_ptr<const File> get_or_throw(const std::string& name);
|
||||
std::shared_ptr<const File> get_or_throw(const char* name);
|
||||
|
||||
GetResult get(const std::string& name, std::function<std::string(const std::string&)> generate);
|
||||
GetResult get(const char* name, std::function<std::string(const std::string&)> generate);
|
||||
|
||||
template <typename T>
|
||||
struct GetObjResult {
|
||||
const T& obj;
|
||||
std::shared_ptr<const File> data;
|
||||
bool generate_called;
|
||||
};
|
||||
|
||||
template <typename T, typename NameT>
|
||||
GetObjResult<T> get_obj_or_load(NameT name) {
|
||||
auto res = this->get_or_load(name);
|
||||
if (res.file->data->size() != sizeof(T)) {
|
||||
throw std::runtime_error("cached string size is incorrect");
|
||||
}
|
||||
return {*reinterpret_cast<const T*>(res.file->data->data()), res.file, res.generate_called};
|
||||
}
|
||||
template <typename T, typename NameT>
|
||||
GetObjResult<T> get_obj_or_throw(NameT name) {
|
||||
auto res = this->get_or_throw(name);
|
||||
if (res.file->data->size() != sizeof(T)) {
|
||||
throw std::runtime_error("cached string size is incorrect");
|
||||
}
|
||||
return {*reinterpret_cast<const T*>(res.file->data->data()), res.file, res.generate_called};
|
||||
}
|
||||
template <typename T, typename NameT>
|
||||
GetObjResult<T> get_obj(NameT name, std::function<T(const std::string&)> generate) {
|
||||
uint64_t t = now();
|
||||
try {
|
||||
auto& f = this->name_to_file.at(name);
|
||||
if (f->data->size() != sizeof(T)) {
|
||||
throw std::runtime_error("cached string size is incorrect");
|
||||
}
|
||||
if (this->ttl_usecs && (t - f->load_time < this->ttl_usecs)) {
|
||||
return {*reinterpret_cast<const T*>(f->data->data()), f, false};
|
||||
}
|
||||
} catch (const std::out_of_range& e) {
|
||||
}
|
||||
T value = generate(name);
|
||||
auto ret = this->replace_obj(name, value);
|
||||
ret.generate_called = true;
|
||||
return ret;
|
||||
}
|
||||
template <typename T, typename NameT>
|
||||
GetObjResult<T> replace_obj(NameT name, const T& value) {
|
||||
auto cached_value = this->replace(name, &value, sizeof(value));
|
||||
return {*reinterpret_cast<const T*>(cached_value->data->data()), cached_value, false};
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, File> name_to_file;
|
||||
std::unordered_map<std::string, std::shared_ptr<File>> name_to_file;
|
||||
uint64_t ttl_usecs;
|
||||
};
|
||||
|
||||
+218
-70
@@ -3,37 +3,56 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Hash.hh>
|
||||
#include <phosg/Time.hh>
|
||||
#include <stdexcept>
|
||||
|
||||
#ifdef HAVE_RESOURCE_FILE
|
||||
#include <resource_file/Emulators/PPC32Emulator.hh>
|
||||
#endif
|
||||
|
||||
#include "CommandFormats.hh"
|
||||
#include "Compression.hh"
|
||||
#include "Loggers.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
static bool is_function_compiler_available = true;
|
||||
|
||||
bool function_compiler_available() {
|
||||
#ifndef HAVE_RESOURCE_FILE
|
||||
return false;
|
||||
#else
|
||||
return true;
|
||||
return is_function_compiler_available;
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_function_compiler_available(bool is_available) {
|
||||
is_function_compiler_available = is_available;
|
||||
}
|
||||
|
||||
const char* name_for_architecture(CompiledFunctionCode::Architecture arch) {
|
||||
switch (arch) {
|
||||
case CompiledFunctionCode::Architecture::POWERPC:
|
||||
return "PowerPC";
|
||||
case CompiledFunctionCode::Architecture::X86:
|
||||
return "x86";
|
||||
default:
|
||||
throw logic_error("invalid architecture");
|
||||
}
|
||||
}
|
||||
|
||||
string CompiledFunctionCode::generate_client_command(
|
||||
const unordered_map<string, uint32_t>& label_writes,
|
||||
const string& suffix) const {
|
||||
S_ExecuteCode_Footer_GC_B2 footer;
|
||||
template <typename FooterT>
|
||||
string CompiledFunctionCode::generate_client_command_t(
|
||||
const unordered_map<string, uint32_t>& label_writes,
|
||||
const string& suffix,
|
||||
uint32_t override_relocations_offset) const {
|
||||
FooterT footer;
|
||||
footer.num_relocations = this->relocation_deltas.size();
|
||||
footer.unused1.clear();
|
||||
footer.unused1.clear(0);
|
||||
footer.entrypoint_addr_offset = this->entrypoint_offset_offset;
|
||||
footer.unused2.clear();
|
||||
footer.unused2.clear(0);
|
||||
|
||||
StringWriter w;
|
||||
if (!label_writes.empty()) {
|
||||
@@ -55,50 +74,72 @@ string CompiledFunctionCode::generate_client_command(
|
||||
}
|
||||
|
||||
footer.relocations_offset = w.size();
|
||||
for (uint16_t delta : this->relocation_deltas) {
|
||||
w.put_u16b(delta);
|
||||
|
||||
// Always write at least 4 bytes even if there are no relocations
|
||||
if (this->relocation_deltas.empty()) {
|
||||
w.put_u32(0);
|
||||
}
|
||||
if (this->relocation_deltas.size() & 1) {
|
||||
w.put_u16(0);
|
||||
|
||||
if (override_relocations_offset) {
|
||||
footer.relocations_offset = override_relocations_offset;
|
||||
} else {
|
||||
for (uint16_t delta : this->relocation_deltas) {
|
||||
w.put<typename FooterT::U16T>(delta);
|
||||
}
|
||||
if (this->relocation_deltas.size() & 1) {
|
||||
w.put_u16(0);
|
||||
}
|
||||
}
|
||||
|
||||
w.put(footer);
|
||||
return move(w.str());
|
||||
return std::move(w.str());
|
||||
}
|
||||
|
||||
string CompiledFunctionCode::generate_client_command(
|
||||
const unordered_map<string, uint32_t>& label_writes,
|
||||
const string& suffix,
|
||||
uint32_t override_relocations_offset) const {
|
||||
if (this->arch == Architecture::POWERPC) {
|
||||
return this->generate_client_command_t<S_ExecuteCode_Footer_GC_B2>(
|
||||
label_writes, suffix, override_relocations_offset);
|
||||
} else if ((this->arch == Architecture::X86) || (this->arch == Architecture::SH4)) {
|
||||
return this->generate_client_command_t<S_ExecuteCode_Footer_DC_PC_XB_BB_B2>(
|
||||
label_writes, suffix, override_relocations_offset);
|
||||
} else {
|
||||
throw logic_error("invalid architecture");
|
||||
}
|
||||
}
|
||||
|
||||
bool CompiledFunctionCode::is_big_endian() const {
|
||||
return this->arch == Architecture::POWERPC;
|
||||
}
|
||||
|
||||
shared_ptr<CompiledFunctionCode> compile_function_code(
|
||||
const string& directory, const string& name, const string& text) {
|
||||
CompiledFunctionCode::Architecture arch,
|
||||
const string& directory,
|
||||
const string& name,
|
||||
const string& text) {
|
||||
#ifndef HAVE_RESOURCE_FILE
|
||||
(void)arch;
|
||||
(void)directory;
|
||||
(void)name;
|
||||
(void)text;
|
||||
throw runtime_error("PowerPC assembler is not available");
|
||||
throw runtime_error("function compiler is not available");
|
||||
|
||||
#else
|
||||
std::unordered_set<string> get_include_stack; // For mutual recursion detection
|
||||
function<string(const string&)> get_include = [&](const string& name) -> string {
|
||||
if (!get_include_stack.emplace(name).second) {
|
||||
throw runtime_error("mutual recursion between includes");
|
||||
}
|
||||
|
||||
string filename = directory + "/" + name + ".inc.s";
|
||||
if (isfile(filename)) {
|
||||
return PPC32Emulator::assemble(load_file(filename), get_include).code;
|
||||
}
|
||||
filename = directory + "/" + name + ".inc.bin";
|
||||
if (isfile(filename)) {
|
||||
return load_file(filename);
|
||||
}
|
||||
throw runtime_error("data not found for include " + name);
|
||||
};
|
||||
|
||||
shared_ptr<CompiledFunctionCode> ret(new CompiledFunctionCode());
|
||||
ret->arch = arch;
|
||||
ret->name = name;
|
||||
ret->index = 0;
|
||||
ret->hide_from_patches_menu = false;
|
||||
|
||||
auto assembled = PPC32Emulator::assemble(text, get_include);
|
||||
ret->code = move(assembled.code);
|
||||
ret->label_offsets = move(assembled.label_offsets);
|
||||
if (arch == CompiledFunctionCode::Architecture::POWERPC) {
|
||||
auto assembled = PPC32Emulator::assemble(text, {directory});
|
||||
ret->code = std::move(assembled.code);
|
||||
ret->label_offsets = std::move(assembled.label_offsets);
|
||||
} else if (arch == CompiledFunctionCode::Architecture::X86) {
|
||||
throw runtime_error("x86 assembler is not implemented");
|
||||
}
|
||||
|
||||
set<uint32_t> reloc_indexes;
|
||||
for (const auto& it : ret->label_offsets) {
|
||||
@@ -106,6 +147,8 @@ shared_ptr<CompiledFunctionCode> compile_function_code(
|
||||
reloc_indexes.emplace(it.second / 4);
|
||||
} else if (starts_with(it.first, "newserv_index_")) {
|
||||
ret->index = stoul(it.first.substr(14), nullptr, 16);
|
||||
} else if (it.first == "hide_from_patches_menu") {
|
||||
ret->hide_from_patches_menu = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,11 +172,9 @@ shared_ptr<CompiledFunctionCode> compile_function_code(
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
FunctionCodeIndex::FunctionCodeIndex(const string& directory) {
|
||||
if (!function_compiler_available()) {
|
||||
log(INFO, "Function compiler is not available");
|
||||
function_compiler_log.info("Function compiler is not available");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -145,62 +186,99 @@ FunctionCodeIndex::FunctionCodeIndex(const string& directory) {
|
||||
bool is_patch = ends_with(filename, ".patch.s");
|
||||
string name = filename.substr(0, filename.size() - (is_patch ? 8 : 2));
|
||||
|
||||
// Check for specific_version token
|
||||
uint32_t specific_version = 0;
|
||||
string patch_name = name;
|
||||
if (is_patch &&
|
||||
(filename.size() >= 13) &&
|
||||
(filename[filename.size() - 13] == '.') &&
|
||||
isdigit(filename[filename.size() - 12]) &&
|
||||
(filename[filename.size() - 11] == 'O' || filename[filename.size() - 11] == 'S') &&
|
||||
(filename[filename.size() - 10] == 'E' || filename[filename.size() - 10] == 'J' || filename[filename.size() - 10] == 'P') &&
|
||||
(isdigit(filename[filename.size() - 9]) || filename[filename.size() - 9] == 'T')) {
|
||||
specific_version = 0x33000000 | (filename[filename.size() - 11] << 16) | (filename[filename.size() - 10] << 8) | filename[filename.size() - 9];
|
||||
patch_name = filename.substr(0, filename.size() - 13);
|
||||
}
|
||||
|
||||
try {
|
||||
string path = directory + "/" + filename;
|
||||
string text = load_file(path);
|
||||
auto code = compile_function_code(directory, name, text);
|
||||
auto code = compile_function_code(
|
||||
CompiledFunctionCode::Architecture::POWERPC, directory, name, text);
|
||||
if (code->index != 0) {
|
||||
if (!this->index_to_function.emplace(code->index, code).second) {
|
||||
throw runtime_error(string_printf(
|
||||
"duplicate function index: %08" PRIX32, code->index));
|
||||
}
|
||||
}
|
||||
code->specific_version = specific_version;
|
||||
code->patch_name = patch_name;
|
||||
this->name_to_function.emplace(name, code);
|
||||
if (is_patch) {
|
||||
this->menu_item_id_to_patch_function.emplace(next_menu_item_id++, code);
|
||||
this->name_to_patch_function.emplace(name, code);
|
||||
}
|
||||
if (code->index) {
|
||||
log(INFO, "Compiled function %02X => %s", code->index, name.c_str());
|
||||
} else {
|
||||
log(INFO, "Compiled function %s", name.c_str());
|
||||
code->menu_item_id = next_menu_item_id++;
|
||||
this->menu_item_id_and_specific_version_to_patch_function.emplace(
|
||||
static_cast<uint64_t>(code->menu_item_id) << 32 | specific_version, code);
|
||||
this->name_and_specific_version_to_patch_function.emplace(
|
||||
string_printf("%s-%08" PRIX32, patch_name.c_str(), specific_version), code);
|
||||
}
|
||||
|
||||
string index_prefix = code->index ? string_printf("%02X => ", code->index) : "";
|
||||
string patch_prefix = is_patch ? string_printf("[%08" PRIX32 "/%08" PRIX32 "] ", code->menu_item_id, code->specific_version) : "";
|
||||
function_compiler_log.info("Compiled function %s%s%s (%s)",
|
||||
index_prefix.c_str(), patch_prefix.c_str(), name.c_str(), name_for_architecture(code->arch));
|
||||
|
||||
} catch (const exception& e) {
|
||||
log(WARNING, "Failed to compile function %s: %s", name.c_str(), e.what());
|
||||
function_compiler_log.warning("Failed to compile function %s: %s", name.c_str(), e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vector<MenuItem> FunctionCodeIndex::patch_menu() const {
|
||||
vector<MenuItem> ret;
|
||||
ret.emplace_back(PatchesMenuItemID::GO_BACK, u"Go back", u"", 0);
|
||||
for (const auto& it : this->name_to_patch_function) {
|
||||
shared_ptr<const Menu> FunctionCodeIndex::patch_menu(uint32_t specific_version) const {
|
||||
auto suffix = string_printf("-%08" PRIX32, specific_version);
|
||||
|
||||
shared_ptr<Menu> ret(new Menu(MenuID::PATCHES, u"Patches"));
|
||||
ret->items.emplace_back(PatchesMenuItemID::GO_BACK, u"Go back", u"Return to the\nmain menu", 0);
|
||||
for (const auto& it : this->name_and_specific_version_to_patch_function) {
|
||||
const auto& fn = it.second;
|
||||
ret.emplace_back(fn->menu_item_id, decode_sjis(fn->name), u"",
|
||||
MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL);
|
||||
if (!fn->hide_from_patches_menu && ends_with(it.first, suffix)) {
|
||||
ret->items.emplace_back(fn->menu_item_id, decode_sjis(fn->patch_name), u"",
|
||||
MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool FunctionCodeIndex::patch_menu_empty(uint32_t specific_version) const {
|
||||
for (const auto& it : this->menu_item_id_and_specific_version_to_patch_function) {
|
||||
if ((it.first & 0xFF000000) == (specific_version & 0xFF000000)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
DOLFileIndex::DOLFileIndex(const string& directory) {
|
||||
if (!function_compiler_available()) {
|
||||
log(INFO, "Function compiler is not available");
|
||||
function_compiler_log.info("Function compiler is not available");
|
||||
return;
|
||||
}
|
||||
if (!isdir(directory)) {
|
||||
log(INFO, "DOL file directory is missing");
|
||||
function_compiler_log.info("DOL file directory is missing");
|
||||
return;
|
||||
}
|
||||
|
||||
shared_ptr<Menu> menu(new Menu(MenuID::PROGRAMS, u"Programs"));
|
||||
this->menu = menu;
|
||||
menu->items.emplace_back(ProgramsMenuItemID::GO_BACK, u"Go back", u"Return to the\nmain menu", 0);
|
||||
|
||||
uint32_t next_menu_item_id = 0;
|
||||
for (const auto& filename : list_directory(directory)) {
|
||||
if (!ends_with(filename, ".dol")) {
|
||||
for (const auto& filename : list_directory_sorted(directory)) {
|
||||
bool is_dol = ends_with(filename, ".dol");
|
||||
bool is_compressed_dol = ends_with(filename, ".dol.prs");
|
||||
if (!is_dol && !is_compressed_dol) {
|
||||
continue;
|
||||
}
|
||||
string name = filename.substr(0, filename.size() - 4);
|
||||
string name = filename.substr(0, filename.size() - (is_compressed_dol ? 8 : 4));
|
||||
|
||||
try {
|
||||
shared_ptr<DOLFile> dol(new DOLFile());
|
||||
@@ -208,24 +286,94 @@ DOLFileIndex::DOLFileIndex(const string& directory) {
|
||||
dol->name = name;
|
||||
|
||||
string path = directory + "/" + filename;
|
||||
dol->data = load_file(path);
|
||||
string file_data = load_file(path);
|
||||
|
||||
string description;
|
||||
if (is_compressed_dol) {
|
||||
size_t decompressed_size = prs_decompress_size(file_data);
|
||||
|
||||
StringWriter w;
|
||||
w.put_u32b(file_data.size());
|
||||
w.put_u32b(decompressed_size);
|
||||
w.write(file_data);
|
||||
while (w.size() & 3) {
|
||||
w.put_u8(0);
|
||||
}
|
||||
dol->data = std::move(w.str());
|
||||
|
||||
string compressed_size_str = format_size(file_data.size());
|
||||
string decompressed_size_str = format_size(decompressed_size);
|
||||
function_compiler_log.info("Loaded compressed DOL file %s (%s -> %s)",
|
||||
dol->name.c_str(), compressed_size_str.c_str(), decompressed_size_str.c_str());
|
||||
description = string_printf("$C6%s$C7\n%s\n%s (orig)",
|
||||
dol->name.c_str(), compressed_size_str.c_str(), decompressed_size_str.c_str());
|
||||
|
||||
} else {
|
||||
StringWriter w;
|
||||
w.put_u32b(0);
|
||||
w.put_u32b(file_data.size());
|
||||
w.write(file_data);
|
||||
while (w.size() & 3) {
|
||||
w.put_u8(0);
|
||||
}
|
||||
dol->data = std::move(w.str());
|
||||
|
||||
string size_str = format_size(dol->data.size());
|
||||
function_compiler_log.info("Loaded DOL file %s (%s)", filename.c_str(), size_str.c_str());
|
||||
description = string_printf("$C6%s$C7\n%s", dol->name.c_str(), size_str.c_str());
|
||||
}
|
||||
|
||||
this->name_to_file.emplace(dol->name, dol);
|
||||
this->item_id_to_file.emplace_back(dol);
|
||||
log(INFO, "Loaded DOL file %s", filename.c_str());
|
||||
|
||||
menu->items.emplace_back(dol->menu_item_id, decode_sjis(dol->name),
|
||||
decode_sjis(description), MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL);
|
||||
|
||||
} catch (const exception& e) {
|
||||
log(WARNING, "Failed to load DOL file %s: %s", filename.c_str(), e.what());
|
||||
function_compiler_log.warning("Failed to load DOL file %s: %s", filename.c_str(), e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vector<MenuItem> DOLFileIndex::menu() const {
|
||||
vector<MenuItem> ret;
|
||||
ret.emplace_back(ProgramsMenuItemID::GO_BACK, u"Go back", u"", 0);
|
||||
for (const auto& dol : this->item_id_to_file) {
|
||||
ret.emplace_back(dol->menu_item_id, decode_sjis(dol->name), u"",
|
||||
MenuItem::Flag::REQUIRES_SEND_FUNCTION_CALL);
|
||||
uint32_t specific_version_for_gc_header_checksum(uint32_t header_checksum) {
|
||||
static unordered_map<uint32_t, uint32_t> checksum_to_specific_version;
|
||||
if (checksum_to_specific_version.empty()) {
|
||||
struct {
|
||||
char system_code = 'G';
|
||||
char game_code1 = 'P';
|
||||
char game_code2;
|
||||
char region_code;
|
||||
char developer_code1 = '8';
|
||||
char developer_code2 = 'P';
|
||||
uint8_t disc_number = 0;
|
||||
uint8_t version_code;
|
||||
} __attribute__((packed)) data;
|
||||
for (const char* game_code2 = "OS"; *game_code2; game_code2++) {
|
||||
data.game_code2 = *game_code2;
|
||||
for (const char* region_code = "JEP"; *region_code; region_code++) {
|
||||
data.region_code = *region_code;
|
||||
for (uint8_t version_code = 0; version_code < 8; version_code++) {
|
||||
data.version_code = version_code;
|
||||
uint32_t checksum = crc32(&data, sizeof(data));
|
||||
uint32_t specific_version = 0x33000030 | (*game_code2 << 16) | (*region_code << 8) | version_code;
|
||||
if (!checksum_to_specific_version.emplace(checksum, specific_version).second) {
|
||||
throw logic_error("multiple specific_versions have same header checksum");
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
// Generate entries for Trial Editions
|
||||
data.region_code = 'J';
|
||||
data.system_code = 'D';
|
||||
data.version_code = 0;
|
||||
uint32_t checksum = crc32(&data, sizeof(data));
|
||||
uint32_t specific_version = 0x33004A54 | (*game_code2 << 16);
|
||||
if (!checksum_to_specific_version.emplace(checksum, specific_version).second) {
|
||||
throw logic_error("multiple specific_versions have same header checksum");
|
||||
}
|
||||
data.system_code = 'G';
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
return checksum_to_specific_version.at(header_checksum);
|
||||
}
|
||||
|
||||
+40
-24
@@ -2,75 +2,91 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "Menu.hh"
|
||||
|
||||
|
||||
|
||||
bool function_compiler_available();
|
||||
void set_function_compiler_available(bool is_available);
|
||||
|
||||
|
||||
|
||||
// TODO: Support x86 function calls in the future. Currently we only support
|
||||
// PPC32 because I haven't written an appropriate x86 assembler yet.
|
||||
// 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 {
|
||||
POWERPC = 0, // 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 name;
|
||||
std::string patch_name; // Blank if not a patch
|
||||
uint32_t index; // 0 = unused (not registered in index_to_function)
|
||||
uint32_t menu_item_id;
|
||||
bool hide_from_patches_menu;
|
||||
uint32_t specific_version;
|
||||
|
||||
bool is_big_endian() const;
|
||||
|
||||
template <typename FooterT>
|
||||
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 = "") const;
|
||||
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(const std::string& directory);
|
||||
FunctionCodeIndex() = default;
|
||||
explicit FunctionCodeIndex(const std::string& directory);
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<CompiledFunctionCode>> name_to_function;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<CompiledFunctionCode>> index_to_function;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<CompiledFunctionCode>> menu_item_id_to_patch_function;
|
||||
std::unordered_map<uint64_t, std::shared_ptr<CompiledFunctionCode>> menu_item_id_and_specific_version_to_patch_function;
|
||||
// Key here is e.g. "PATCHNAME-SPECIFICVERSION", with the latter in hex
|
||||
std::map<std::string, std::shared_ptr<CompiledFunctionCode>> name_and_specific_version_to_patch_function;
|
||||
|
||||
std::map<std::string, std::shared_ptr<CompiledFunctionCode>> name_to_patch_function;
|
||||
|
||||
std::vector<MenuItem> patch_menu() const;
|
||||
inline bool patch_menu_empty() const {
|
||||
return this->name_to_patch_function.empty();
|
||||
}
|
||||
std::shared_ptr<const Menu> patch_menu(uint32_t specific_version) const;
|
||||
bool patch_menu_empty(uint32_t specific_version) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct DOLFileIndex {
|
||||
struct DOLFile {
|
||||
uint32_t menu_item_id;
|
||||
std::string name;
|
||||
std::string data;
|
||||
bool is_compressed;
|
||||
};
|
||||
|
||||
std::vector<std::shared_ptr<DOLFile>> item_id_to_file;
|
||||
std::map<std::string, std::shared_ptr<DOLFile>> name_to_file;
|
||||
std::unordered_map<std::string, std::shared_ptr<DOLFile>> name_to_file;
|
||||
std::shared_ptr<const Menu> menu;
|
||||
|
||||
DOLFileIndex(const std::string& directory);
|
||||
DOLFileIndex() = default;
|
||||
explicit DOLFileIndex(const std::string& directory);
|
||||
|
||||
std::vector<MenuItem> menu() const;
|
||||
inline bool empty() const {
|
||||
return this->name_to_file.empty() && this->item_id_to_file.empty();
|
||||
}
|
||||
};
|
||||
|
||||
uint32_t specific_version_for_gc_header_checksum(uint32_t header_checksum);
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
#include "GSLArchive.hh"
|
||||
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "Text.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <bool IsBigEndian>
|
||||
struct GSLHeaderEntry {
|
||||
using U32T = typename std::conditional<IsBigEndian, be_uint32_t, le_uint32_t>::type;
|
||||
|
||||
ptext<char, 0x20> filename;
|
||||
U32T offset; // In pages, so actual offset is this * 0x800
|
||||
U32T size;
|
||||
uint64_t unused;
|
||||
} __attribute__((packed));
|
||||
|
||||
template <bool IsBigEndian>
|
||||
void GSLArchive::load_t() {
|
||||
StringReader r(*this->data);
|
||||
uint64_t min_data_offset = 0xFFFFFFFFFFFFFFFF;
|
||||
while (r.where() < min_data_offset) {
|
||||
const auto& entry = r.get<GSLHeaderEntry<IsBigEndian>>();
|
||||
if (entry.filename.len() == 0) {
|
||||
break;
|
||||
}
|
||||
uint64_t offset = static_cast<uint64_t>(entry.offset) * 0x800;
|
||||
if (offset + entry.size > this->data->size()) {
|
||||
throw runtime_error("GSL entry extends beyond end of data");
|
||||
}
|
||||
this->entries.emplace(entry.filename, Entry{offset, entry.size});
|
||||
}
|
||||
}
|
||||
|
||||
GSLArchive::GSLArchive(shared_ptr<const string> data, bool big_endian)
|
||||
: data(data) {
|
||||
if (big_endian) {
|
||||
this->load_t<true>();
|
||||
} else {
|
||||
this->load_t<false>();
|
||||
}
|
||||
}
|
||||
|
||||
const unordered_map<string, GSLArchive::Entry> GSLArchive::all_entries() const {
|
||||
return this->entries;
|
||||
}
|
||||
|
||||
pair<const void*, size_t> GSLArchive::get(const std::string& name) const {
|
||||
try {
|
||||
const auto& entry = this->entries.at(name);
|
||||
return make_pair(this->data->data() + entry.offset, entry.size);
|
||||
} catch (const out_of_range&) {
|
||||
throw out_of_range("GSL does not contain file: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
string GSLArchive::get_copy(const string& name) const {
|
||||
try {
|
||||
const auto& entry = this->entries.at(name);
|
||||
return this->data->substr(entry.offset, entry.size);
|
||||
} catch (const out_of_range&) {
|
||||
throw out_of_range("GSL does not contain file: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
StringReader GSLArchive::get_reader(const string& name) const {
|
||||
try {
|
||||
const auto& entry = this->entries.at(name);
|
||||
return StringReader(this->data->data() + entry.offset, entry.size);
|
||||
} catch (const out_of_range&) {
|
||||
throw out_of_range("GSL does not contain file: " + name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
class GSLArchive {
|
||||
public:
|
||||
GSLArchive(std::shared_ptr<const std::string> data, bool big_endian);
|
||||
~GSLArchive() = default;
|
||||
|
||||
struct Entry {
|
||||
uint64_t offset;
|
||||
uint32_t size;
|
||||
};
|
||||
const std::unordered_map<std::string, Entry> all_entries() const;
|
||||
|
||||
std::pair<const void*, size_t> get(const std::string& name) const;
|
||||
std::string get_copy(const std::string& name) const;
|
||||
StringReader get_reader(const std::string& name) const;
|
||||
|
||||
private:
|
||||
template <bool IsBigEndian>
|
||||
void load_t();
|
||||
|
||||
std::shared_ptr<const std::string> data;
|
||||
|
||||
std::unordered_map<std::string, Entry> entries;
|
||||
};
|
||||
@@ -0,0 +1,118 @@
|
||||
#include "GVMEncoder.hh"
|
||||
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Image.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
|
||||
#include "Text.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
static uint16_t encode_rgb565(uint8_t r, uint8_t g, uint8_t b) {
|
||||
return ((r << 8) & 0xF800) | ((g << 3) & 0x07E0) | ((b >> 3) & 0x001F);
|
||||
}
|
||||
|
||||
static uint16_t encode_rgb5a3(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
|
||||
if ((a & 0xE0) == 0xE0) {
|
||||
return 0x8000 | ((r << 7) & 0x7C00) | ((g << 2) & 0x03E0) | ((b >> 3) & 0x001F);
|
||||
} else {
|
||||
return ((a << 7) & 0x7000) | ((r << 4) & 0x0F00) | (g & 0x00F0) | ((b >> 4) & 0x000F);
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t encode_argb8888(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
|
||||
return (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
struct GVMFileEntry {
|
||||
be_uint16_t file_num;
|
||||
ptext<char, 28> name;
|
||||
parray<be_uint32_t, 2> unknown_a1;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct GVMFileHeader {
|
||||
be_uint32_t magic; // 'GVMH'
|
||||
le_uint32_t header_size;
|
||||
be_uint16_t flags;
|
||||
be_uint16_t num_files;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct GVRHeader {
|
||||
be_uint32_t magic; // 'GVRT'
|
||||
le_uint32_t data_size;
|
||||
be_uint16_t unknown;
|
||||
uint8_t format_flags; // High 4 bits are pixel format, low 4 are data flags
|
||||
GVRDataFormat data_format;
|
||||
be_uint16_t width;
|
||||
be_uint16_t height;
|
||||
} __attribute__((packed));
|
||||
|
||||
string encode_gvm(const Image& img, GVRDataFormat data_format) {
|
||||
if (img.get_width() > 0xFFFF) {
|
||||
throw runtime_error("image is too wide to be encoded as a GVR texture");
|
||||
}
|
||||
if (img.get_height() > 0xFFFF) {
|
||||
throw runtime_error("image is too tall to be encoded as a GVR texture");
|
||||
}
|
||||
if (img.get_width() & 3) {
|
||||
throw runtime_error("image width is not a multiple of 4");
|
||||
}
|
||||
if (img.get_height() & 3) {
|
||||
throw runtime_error("image height is not a multiple of 4");
|
||||
}
|
||||
size_t pixel_count = img.get_width() * img.get_height();
|
||||
size_t pixel_bytes = 0;
|
||||
switch (data_format) {
|
||||
case GVRDataFormat::RGB565:
|
||||
case GVRDataFormat::RGB5A3:
|
||||
pixel_bytes = pixel_count * 2;
|
||||
break;
|
||||
case GVRDataFormat::ARGB8888:
|
||||
pixel_bytes = pixel_count * 2;
|
||||
break;
|
||||
default:
|
||||
throw invalid_argument("cannot encode pixel format");
|
||||
}
|
||||
|
||||
StringWriter w;
|
||||
w.put<GVMFileHeader>({.magic = 0x47564D48, .header_size = 0x48, .flags = 0x010F, .num_files = 1});
|
||||
GVMFileEntry file_entry;
|
||||
file_entry.file_num = 0;
|
||||
file_entry.name = "img";
|
||||
file_entry.unknown_a1.clear(0);
|
||||
w.put(file_entry);
|
||||
w.extend_to(0x50, 0x00);
|
||||
w.put<GVRHeader>({.magic = 0x47565254,
|
||||
.data_size = pixel_bytes + 8,
|
||||
.unknown = 0,
|
||||
.format_flags = 0,
|
||||
.data_format = data_format,
|
||||
.width = img.get_width(),
|
||||
.height = img.get_height()});
|
||||
|
||||
for (size_t y = 0; y < img.get_height(); y += 4) {
|
||||
for (size_t x = 0; x < img.get_width(); x += 4) {
|
||||
for (size_t yy = 0; yy < 4; yy++) {
|
||||
for (size_t xx = 0; xx < 4; xx++) {
|
||||
uint64_t a, r, g, b;
|
||||
img.read_pixel(x + xx, y + yy, &r, &g, &b, &a);
|
||||
switch (data_format) {
|
||||
case GVRDataFormat::RGB565:
|
||||
w.put_u16b(encode_rgb565(r, g, b));
|
||||
break;
|
||||
case GVRDataFormat::RGB5A3:
|
||||
w.put_u16b(encode_rgb5a3(r, g, b, a));
|
||||
break;
|
||||
case GVRDataFormat::ARGB8888:
|
||||
w.put_u32b(encode_argb8888(r, g, b, a));
|
||||
break;
|
||||
default:
|
||||
throw logic_error("cannot encode pixel format");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return std::move(w.str());
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <phosg/Image.hh>
|
||||
#include <phosg/Strings.hh>
|
||||
|
||||
#include "Text.hh"
|
||||
|
||||
enum class GVRDataFormat : uint8_t {
|
||||
INTENSITY_4 = 0x00,
|
||||
INTENSITY_8 = 0x01,
|
||||
INTENSITY_A4 = 0x02,
|
||||
INTENSITY_A8 = 0x03,
|
||||
RGB565 = 0x04,
|
||||
RGB5A3 = 0x05,
|
||||
ARGB8888 = 0x06,
|
||||
INDEXED_4 = 0x08,
|
||||
INDEXED_8 = 0x09,
|
||||
DXT1 = 0x0E,
|
||||
};
|
||||
|
||||
std::string encode_gvm(const Image& img, GVRDataFormat data_format);
|
||||
+33
-32
@@ -6,8 +6,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
static inline uint16_t collapse_checksum(uint32_t sum) {
|
||||
// It's impossible for this to be necessary more than twice: the first
|
||||
// addition can carry out at most a single bit.
|
||||
@@ -15,35 +13,33 @@ static inline uint16_t collapse_checksum(uint32_t sum) {
|
||||
return (sum & 0xFFFF) + (sum >> 16);
|
||||
}
|
||||
|
||||
|
||||
|
||||
FrameInfo::FrameInfo()
|
||||
: ether(nullptr),
|
||||
ether_protocol(0),
|
||||
ipv4(nullptr),
|
||||
arp(nullptr),
|
||||
udp(nullptr),
|
||||
tcp(nullptr),
|
||||
header_start(nullptr),
|
||||
payload(nullptr),
|
||||
total_size(0),
|
||||
tcp_options_size(0),
|
||||
payload_size(0) { }
|
||||
: ether(nullptr),
|
||||
ether_protocol(0),
|
||||
ipv4(nullptr),
|
||||
arp(nullptr),
|
||||
udp(nullptr),
|
||||
tcp(nullptr),
|
||||
header_start(nullptr),
|
||||
payload(nullptr),
|
||||
total_size(0),
|
||||
tcp_options_size(0),
|
||||
payload_size(0) {}
|
||||
|
||||
FrameInfo::FrameInfo(const string& data) : FrameInfo(data.data(), data.size()) { }
|
||||
FrameInfo::FrameInfo(const string& data) : FrameInfo(data.data(), data.size()) {}
|
||||
|
||||
FrameInfo::FrameInfo(const void* header_start, size_t size)
|
||||
: ether(nullptr),
|
||||
ether_protocol(0),
|
||||
ipv4(nullptr),
|
||||
arp(nullptr),
|
||||
udp(nullptr),
|
||||
tcp(nullptr),
|
||||
header_start(header_start),
|
||||
payload(nullptr),
|
||||
total_size(size),
|
||||
tcp_options_size(0),
|
||||
payload_size(size) {
|
||||
: ether(nullptr),
|
||||
ether_protocol(0),
|
||||
ipv4(nullptr),
|
||||
arp(nullptr),
|
||||
udp(nullptr),
|
||||
tcp(nullptr),
|
||||
header_start(header_start),
|
||||
payload(nullptr),
|
||||
total_size(size),
|
||||
tcp_options_size(0),
|
||||
payload_size(size) {
|
||||
|
||||
// Parse ethernet header
|
||||
if (this->payload_size < sizeof(EthernetHeader)) {
|
||||
@@ -125,26 +121,31 @@ string FrameInfo::header_str() const {
|
||||
return "<invalid-frame-info>";
|
||||
}
|
||||
|
||||
string ret = string_printf("%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX->%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX",
|
||||
string ret = string_printf(
|
||||
"%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX->%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX",
|
||||
this->ether->src_mac[0], this->ether->src_mac[1], this->ether->src_mac[2],
|
||||
this->ether->src_mac[3], this->ether->src_mac[4], this->ether->src_mac[5],
|
||||
this->ether->dest_mac[0], this->ether->dest_mac[1], this->ether->dest_mac[2],
|
||||
this->ether->dest_mac[3], this->ether->dest_mac[4], this->ether->dest_mac[5]);
|
||||
|
||||
if (this->arp) {
|
||||
ret += string_printf(",ARP,hw_type=%04hX,proto_type=%04hX,hw_addr_len=%02hhX,proto_addr_len=%02hhX,op=%04hX",
|
||||
ret += string_printf(
|
||||
",ARP,hw_type=%04hX,proto_type=%04hX,hw_addr_len=%02hhX,proto_addr_len=%02hhX,op=%04hX",
|
||||
this->arp->hardware_type.load(), this->arp->protocol_type.load(), this->arp->hwaddr_len, this->arp->paddr_len, this->arp->operation.load());
|
||||
|
||||
} else if (this->ipv4) {
|
||||
ret += string_printf(",IPv4,size=%04hX,src=%08" PRIX32 ",dest=%08" PRIX32,
|
||||
ret += string_printf(
|
||||
",IPv4,size=%04hX,src=%08" PRIX32 ",dest=%08" PRIX32,
|
||||
this->ipv4->size.load(), this->ipv4->src_addr.load(), this->ipv4->dest_addr.load());
|
||||
|
||||
if (this->udp) {
|
||||
ret += string_printf(",UDP,src_port=%04hX,dest_port=%04hX,size=%04hX",
|
||||
ret += string_printf(
|
||||
",UDP,src_port=%04hX,dest_port=%04hX,size=%04hX",
|
||||
this->udp->src_port.load(), this->udp->dest_port.load(), this->udp->size.load());
|
||||
|
||||
} else if (this->tcp) {
|
||||
ret += string_printf(",TCP,src_port=%04hX,dest_port=%04hX,seq=%08" PRIX32 ",ack=%08" PRIX32 ",flags=%04hX(",
|
||||
ret += string_printf(
|
||||
",TCP,src_port=%04hX,dest_port=%04hX,seq=%08" PRIX32 ",ack=%08" PRIX32 ",flags=%04hX(",
|
||||
this->tcp->src_port.load(), this->tcp->dest_port.load(), this->tcp->seq_num.load(), this->tcp->ack_num.load(), this->tcp->flags.load());
|
||||
if (this->tcp->flags & TCPHeader::Flag::FIN) {
|
||||
ret += "FIN,";
|
||||
|
||||
+21
-5
@@ -4,11 +4,11 @@
|
||||
|
||||
#include <phosg/Encoding.hh>
|
||||
|
||||
|
||||
#include "Text.hh"
|
||||
|
||||
struct EthernetHeader {
|
||||
uint8_t dest_mac[6];
|
||||
uint8_t src_mac[6];
|
||||
parray<uint8_t, 6> dest_mac;
|
||||
parray<uint8_t, 6> src_mac;
|
||||
be_uint16_t protocol;
|
||||
} __attribute__((packed));
|
||||
|
||||
@@ -42,7 +42,7 @@ struct UDPHeader {
|
||||
|
||||
struct TCPHeader {
|
||||
enum Flag {
|
||||
NS = 0x0100,
|
||||
NS = 0x0100,
|
||||
CWR = 0x0080, // congestion window reduced
|
||||
ECE = 0x0040, // ECN capable / congestion experienced
|
||||
URG = 0x0020, // urgent pointer used
|
||||
@@ -63,7 +63,23 @@ struct TCPHeader {
|
||||
be_uint16_t urgent_ptr;
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
struct DHCPHeader {
|
||||
uint8_t opcode = 0;
|
||||
uint8_t hardware_type = 1; // 1 = Ethernet
|
||||
uint8_t hardware_address_length = 6; // 6 for Ethernet
|
||||
uint8_t hops = 0;
|
||||
be_uint32_t transaction_id = 0;
|
||||
be_uint16_t seconds_elapsed = 0;
|
||||
be_uint16_t flags = 0;
|
||||
be_uint32_t client_ip_address = 0;
|
||||
be_uint32_t your_ip_address = 0;
|
||||
be_uint32_t server_ip_address = 0;
|
||||
be_uint32_t gateway_ip_address = 0;
|
||||
parray<uint8_t, 0x10> client_hardware_address;
|
||||
parray<uint8_t, 0xC0> unused_bootp_legacy;
|
||||
be_uint32_t magic = 0x63825363;
|
||||
// Options follow here, terminated with FF
|
||||
} __attribute__((packed));
|
||||
|
||||
struct FrameInfo {
|
||||
// This is always valid
|
||||
|
||||
+363
-225
@@ -1,35 +1,25 @@
|
||||
#include "IPStackSimulator.hh"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <event2/buffer.h>
|
||||
#include <event2/bufferevent.h>
|
||||
#include <event2/listener.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef PHOSG_WINDOWS
|
||||
#include <arpa/inet.h>
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <phosg/Network.hh>
|
||||
#include <phosg/Random.hh>
|
||||
#include <phosg/Time.hh>
|
||||
#include <string>
|
||||
|
||||
#include "IPFrameInfo.hh"
|
||||
#include "DNSServer.hh"
|
||||
#include "IPFrameInfo.hh"
|
||||
#include "Loggers.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
static const size_t DEFAULT_RESEND_PUSH_USECS = 200000; // 200ms
|
||||
PrefixedLogger IPStackSimulator::log("[IPStackSimulator] ");
|
||||
|
||||
|
||||
|
||||
// Note: these functions exist because seq nums are allowed to wrap around the
|
||||
// 32-bit integer space by design. We have to do the subtraction before the
|
||||
@@ -51,8 +41,6 @@ static __attribute__((unused)) inline bool seq_num_greater_or_equal(uint32_t a,
|
||||
return (a == b) || seq_num_greater(a, b);
|
||||
}
|
||||
|
||||
|
||||
|
||||
string IPStackSimulator::str_for_ipv4_netloc(uint32_t addr, uint16_t port) {
|
||||
be_uint32_t be_addr = addr;
|
||||
char addr_str[INET_ADDRSTRLEN];
|
||||
@@ -73,16 +61,14 @@ string IPStackSimulator::str_for_tcp_connection(shared_ptr<const IPClient> c,
|
||||
fd, key, client_netloc_str.c_str(), server_netloc_str.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
IPStackSimulator::IPStackSimulator(
|
||||
std::shared_ptr<struct event_base> base,
|
||||
std::shared_ptr<ServerState> state)
|
||||
: base(base),
|
||||
state(state),
|
||||
pcap_text_log_file(state->ip_stack_debug ? fopen("IPStackSimulator-Log.txt", "wt") : nullptr) {
|
||||
memset(this->host_mac_address_bytes, 0x90, 6);
|
||||
memset(this->broadcast_mac_address_bytes, 0xFF, 6);
|
||||
shared_ptr<struct event_base> base,
|
||||
shared_ptr<ServerState> state)
|
||||
: base(base),
|
||||
state(state),
|
||||
pcap_text_log_file(state->ip_stack_debug ? fopen("IPStackSimulator-Log.txt", "wt") : nullptr) {
|
||||
this->host_mac_address_bytes.clear(0x90);
|
||||
this->broadcast_mac_address_bytes.clear(0xFF);
|
||||
}
|
||||
|
||||
IPStackSimulator::~IPStackSimulator() {
|
||||
@@ -91,34 +77,40 @@ IPStackSimulator::~IPStackSimulator() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void IPStackSimulator::listen(const std::string& socket_path) {
|
||||
this->add_socket(::listen(socket_path, 0, SOMAXCONN));
|
||||
void IPStackSimulator::listen(const string& name, const string& socket_path) {
|
||||
int fd = ::listen(socket_path, 0, SOMAXCONN);
|
||||
ip_stack_simulator_log.info("Listening on Unix socket %s on fd %d as %s", socket_path.c_str(), fd, name.c_str());
|
||||
this->add_socket(name, fd);
|
||||
}
|
||||
|
||||
void IPStackSimulator::listen(const std::string& addr, int port) {
|
||||
this->add_socket(::listen(addr, port, SOMAXCONN));
|
||||
void IPStackSimulator::listen(const string& name, const string& addr, int port) {
|
||||
if (port == 0) {
|
||||
this->listen(name, addr);
|
||||
} else {
|
||||
int fd = ::listen(addr, port, SOMAXCONN);
|
||||
string netloc_str = render_netloc(addr, port);
|
||||
ip_stack_simulator_log.info("Listening on TCP interface %s on fd %d as %s", netloc_str.c_str(), fd, name.c_str());
|
||||
this->add_socket(name, fd);
|
||||
}
|
||||
}
|
||||
|
||||
void IPStackSimulator::listen(int port) {
|
||||
this->add_socket(::listen("", port, SOMAXCONN));
|
||||
void IPStackSimulator::listen(const string& name, int port) {
|
||||
this->listen(name, "", port);
|
||||
}
|
||||
|
||||
void IPStackSimulator::add_socket(int fd) {
|
||||
this->listeners.emplace(
|
||||
void IPStackSimulator::add_socket(const string& name, int fd) {
|
||||
unique_listener l(
|
||||
evconnlistener_new(
|
||||
this->base.get(),
|
||||
IPStackSimulator::dispatch_on_listen_accept,
|
||||
this,
|
||||
LEV_OPT_REUSEABLE,
|
||||
0,
|
||||
fd),
|
||||
this->base.get(),
|
||||
IPStackSimulator::dispatch_on_listen_accept,
|
||||
this,
|
||||
LEV_OPT_REUSEABLE,
|
||||
0,
|
||||
fd),
|
||||
evconnlistener_free);
|
||||
this->listening_sockets.emplace(piecewise_construct, forward_as_tuple(fd), forward_as_tuple(name, std::move(l)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t IPStackSimulator::connect_address_for_remote_address(uint32_t remote_addr) {
|
||||
// Use an address not on the same subnet as the client, so that PSO Plus and
|
||||
// Episode III will think they're talking to a remote network and won't reject
|
||||
@@ -130,14 +122,29 @@ uint32_t IPStackSimulator::connect_address_for_remote_address(uint32_t remote_ad
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
IPStackSimulator::IPClient::IPClient(struct bufferevent* bev)
|
||||
: bev(bev, bufferevent_free), ipv4_addr(0) {
|
||||
memset(this->mac_addr, 0, 6);
|
||||
IPStackSimulator::IPClient::IPClient(shared_ptr<IPStackSimulator> sim, struct bufferevent* bev)
|
||||
: sim(sim),
|
||||
bev(bev, bufferevent_free),
|
||||
mac_addr(0),
|
||||
ipv4_addr(0),
|
||||
idle_timeout_event(event_new(sim->base.get(), -1, EV_TIMEOUT, &IPStackSimulator::IPClient::dispatch_on_idle_timeout, this), event_free) {
|
||||
struct timeval tv = usecs_to_timeval(60 * 1000 * 1000);
|
||||
event_add(this->idle_timeout_event.get(), &tv);
|
||||
}
|
||||
|
||||
void IPStackSimulator::IPClient::dispatch_on_idle_timeout(evutil_socket_t, short, void* ctx) {
|
||||
reinterpret_cast<IPStackSimulator::IPClient*>(ctx)->on_idle_timeout();
|
||||
}
|
||||
|
||||
void IPStackSimulator::IPClient::on_idle_timeout() {
|
||||
auto sim = this->sim.lock();
|
||||
if (sim) {
|
||||
ip_stack_simulator_log.info("Idle timeout expired on virtual network %d", bufferevent_getfd(this->bev.get()));
|
||||
sim->disconnect_client(this->bev.get());
|
||||
} else {
|
||||
ip_stack_simulator_log.info("Idle timeout expired on virtual network %d, but simulator is missing", bufferevent_getfd(this->bev.get()));
|
||||
}
|
||||
}
|
||||
|
||||
static void flush_and_free_bufferevent(struct bufferevent* bev) {
|
||||
bufferevent_flush(bev, EV_READ | EV_WRITE, BEV_FINISHED);
|
||||
@@ -145,15 +152,29 @@ static void flush_and_free_bufferevent(struct bufferevent* bev) {
|
||||
}
|
||||
|
||||
IPStackSimulator::IPClient::TCPConnection::TCPConnection()
|
||||
: server_bev(nullptr, flush_and_free_bufferevent),
|
||||
pending_data(evbuffer_new(), evbuffer_free),
|
||||
resend_push_event(nullptr, event_free) { }
|
||||
|
||||
: server_bev(nullptr, flush_and_free_bufferevent),
|
||||
pending_data(evbuffer_new(), evbuffer_free),
|
||||
resend_push_event(nullptr, event_free),
|
||||
awaiting_first_ack(true),
|
||||
server_addr(0),
|
||||
server_port(0),
|
||||
client_port(0),
|
||||
next_client_seq(0),
|
||||
acked_server_seq(0),
|
||||
resend_push_usecs(DEFAULT_RESEND_PUSH_USECS),
|
||||
next_push_max_frame_size(1024),
|
||||
max_frame_size(1024),
|
||||
bytes_received(0),
|
||||
bytes_sent(0) {}
|
||||
|
||||
void IPStackSimulator::disconnect_client(struct bufferevent* bev) {
|
||||
ip_stack_simulator_log.info("Virtual network %d disconnected", bufferevent_getfd(bev));
|
||||
this->bev_to_client.erase(bev);
|
||||
}
|
||||
|
||||
void IPStackSimulator::dispatch_on_listen_accept(
|
||||
struct evconnlistener* listener, evutil_socket_t fd,
|
||||
struct sockaddr *address, int socklen, void* ctx) {
|
||||
struct sockaddr* address, int socklen, void* ctx) {
|
||||
reinterpret_cast<IPStackSimulator*>(ctx)->on_listen_accept(
|
||||
listener, fd, address, socklen);
|
||||
}
|
||||
@@ -161,13 +182,21 @@ void IPStackSimulator::dispatch_on_listen_accept(
|
||||
void IPStackSimulator::on_listen_accept(struct evconnlistener* listener,
|
||||
evutil_socket_t fd, struct sockaddr*, int) {
|
||||
int listen_fd = evconnlistener_get_fd(listener);
|
||||
this->log(INFO, "Client fd %d connected via fd %d",
|
||||
fd, listen_fd);
|
||||
|
||||
struct bufferevent *bev = bufferevent_socket_new(this->base.get(), fd,
|
||||
const ListeningSocket* listening_socket;
|
||||
try {
|
||||
listening_socket = &this->listening_sockets.at(listen_fd);
|
||||
} catch (const out_of_range&) {
|
||||
ip_stack_simulator_log.info("Virtual network %d connected via unknown listener %d; disconnecting", fd, listen_fd);
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
ip_stack_simulator_log.info("Virtual network %d connected via %s", fd, listening_socket->name.c_str());
|
||||
|
||||
struct bufferevent* bev = bufferevent_socket_new(this->base.get(), fd,
|
||||
BEV_OPT_CLOSE_ON_FREE | BEV_OPT_DEFER_CALLBACKS);
|
||||
shared_ptr<IPClient> c(new IPClient(bev));
|
||||
c->sim = this;
|
||||
shared_ptr<IPClient> c(new IPClient(this->shared_from_this(), bev));
|
||||
this->bev_to_client.emplace(make_pair(bev, c));
|
||||
|
||||
bufferevent_setcb(bev, &IPStackSimulator::dispatch_on_client_input, nullptr,
|
||||
@@ -182,13 +211,11 @@ void IPStackSimulator::dispatch_on_listen_error(
|
||||
|
||||
void IPStackSimulator::on_listen_error(struct evconnlistener* listener) {
|
||||
int err = EVUTIL_SOCKET_ERROR();
|
||||
this->log(ERROR, "Failure on listening socket %d: %d (%s)",
|
||||
ip_stack_simulator_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 IPStackSimulator::dispatch_on_client_input(
|
||||
struct bufferevent* bev, void* ctx) {
|
||||
reinterpret_cast<IPStackSimulator*>(ctx)->on_client_input(bev);
|
||||
@@ -202,12 +229,15 @@ void IPStackSimulator::on_client_input(struct bufferevent* bev) {
|
||||
c = this->bev_to_client.at(bev);
|
||||
} catch (const out_of_range&) {
|
||||
size_t bytes = evbuffer_get_length(buf);
|
||||
this->log(ERROR, "Ignoring data received from unregistered client (0x%zX bytes)",
|
||||
ip_stack_simulator_log.warning("Ignoring data received from unregistered virtual network (0x%zX bytes)",
|
||||
bytes);
|
||||
evbuffer_drain(buf, bytes);
|
||||
return;
|
||||
}
|
||||
|
||||
struct timeval tv = usecs_to_timeval(60 * 1000 * 1000);
|
||||
event_add(c->idle_timeout_event.get(), &tv);
|
||||
|
||||
while (evbuffer_get_length(buf) >= 2) {
|
||||
uint16_t frame_size;
|
||||
evbuffer_copyout(buf, &frame_size, 2);
|
||||
@@ -222,8 +252,7 @@ void IPStackSimulator::on_client_input(struct bufferevent* bev) {
|
||||
try {
|
||||
this->on_client_frame(c, frame);
|
||||
} catch (const exception& e) {
|
||||
if (this->state->ip_stack_debug) {
|
||||
this->log(WARNING, "Failed to process client frame: %s", e.what());
|
||||
if (ip_stack_simulator_log.warning("Failed to process frame: %s", e.what())) {
|
||||
print_data(stderr, frame);
|
||||
}
|
||||
}
|
||||
@@ -234,36 +263,29 @@ void IPStackSimulator::dispatch_on_client_error(
|
||||
struct bufferevent* bev, short events, void* ctx) {
|
||||
reinterpret_cast<IPStackSimulator*>(ctx)->on_client_error(bev, events);
|
||||
}
|
||||
void IPStackSimulator::on_client_error(struct bufferevent* bev,
|
||||
short events) {
|
||||
void IPStackSimulator::on_client_error(struct bufferevent* bev, short events) {
|
||||
if (events & BEV_EVENT_ERROR) {
|
||||
int err = EVUTIL_SOCKET_ERROR();
|
||||
this->log(WARNING, "Client caused error %d (%s)", err,
|
||||
ip_stack_simulator_log.warning("Virtual network caused error %d (%s)", err,
|
||||
evutil_socket_error_to_string(err));
|
||||
}
|
||||
if (events & (BEV_EVENT_EOF | BEV_EVENT_ERROR)) {
|
||||
this->log(INFO, "Client fd %d disconnected",
|
||||
bufferevent_getfd(bev));
|
||||
|
||||
this->bev_to_client.erase(bev);
|
||||
this->disconnect_client(bev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void IPStackSimulator::on_client_frame(
|
||||
shared_ptr<IPClient> c, const string& frame) {
|
||||
if (this->state->ip_stack_debug) {
|
||||
fputc('\n', stderr);
|
||||
this->log(INFO, "Client sent frame");
|
||||
if (ip_stack_simulator_log.debug("Virtual network sent frame")) {
|
||||
print_data(stderr, frame);
|
||||
fputc('\n', stderr);
|
||||
}
|
||||
this->log_frame(frame);
|
||||
|
||||
FrameInfo fi(frame);
|
||||
if (this->state->ip_stack_debug) {
|
||||
if (ip_stack_simulator_log.should_log(LogLevel::DEBUG)) {
|
||||
string fi_header = fi.header_str();
|
||||
this->log(INFO, "Frame header: %s", fi_header.c_str());
|
||||
ip_stack_simulator_log.debug("Frame header: %s", fi_header.c_str());
|
||||
}
|
||||
|
||||
if (fi.arp) {
|
||||
@@ -276,10 +298,14 @@ void IPStackSimulator::on_client_frame(
|
||||
"IPv4 header checksum is incorrect (%04hX expected, %04hX received)",
|
||||
expected_ipv4_checksum, fi.ipv4->checksum.load()));
|
||||
}
|
||||
if (memcmp(fi.ether->src_mac, c->mac_addr, 6)) {
|
||||
|
||||
// Populate the client's addresses if needed
|
||||
if (c->mac_addr.is_filled_with(0)) {
|
||||
c->mac_addr = fi.ether->src_mac;
|
||||
} else if ((fi.ether->src_mac != c->mac_addr) && (fi.ether->src_mac != this->broadcast_mac_address_bytes)) {
|
||||
throw runtime_error("client sent IPv4 packet from different MAC address");
|
||||
}
|
||||
if (fi.ipv4->src_addr != c->ipv4_addr) {
|
||||
if ((fi.ipv4->src_addr != c->ipv4_addr) && (fi.ipv4->src_addr != 0)) {
|
||||
throw runtime_error("client sent IPv4 packet from different IPv4 address");
|
||||
}
|
||||
|
||||
@@ -310,8 +336,6 @@ void IPStackSimulator::on_client_frame(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void IPStackSimulator::on_client_arp_frame(
|
||||
shared_ptr<IPClient> c, const FrameInfo& fi) {
|
||||
if (fi.arp->hwaddr_len != 6 ||
|
||||
@@ -324,18 +348,14 @@ void IPStackSimulator::on_client_arp_frame(
|
||||
throw runtime_error("ARP payload too small");
|
||||
}
|
||||
|
||||
// Populate the client's addresses if needed
|
||||
if (!memcmp(c->mac_addr, "\0\0\0\0\0\0", 6)) {
|
||||
memcpy(c->mac_addr, fi.ether->src_mac, 6);
|
||||
}
|
||||
if (c->ipv4_addr == 0) {
|
||||
c->ipv4_addr = *reinterpret_cast<const be_uint32_t*>(
|
||||
reinterpret_cast<const uint8_t*>(fi.payload) + 6);
|
||||
reinterpret_cast<const uint8_t*>(fi.payload) + 6);
|
||||
}
|
||||
|
||||
EthernetHeader r_ether;
|
||||
memcpy(r_ether.dest_mac, fi.ether->src_mac, 6);
|
||||
memcpy(r_ether.src_mac, this->host_mac_address_bytes, 6);
|
||||
r_ether.dest_mac = fi.ether->src_mac;
|
||||
r_ether.src_mac = this->host_mac_address_bytes;
|
||||
r_ether.protocol = fi.ether->protocol;
|
||||
|
||||
ARPHeader r_arp;
|
||||
@@ -359,7 +379,7 @@ void IPStackSimulator::on_client_arp_frame(
|
||||
const char* payload_bytes = reinterpret_cast<const char*>(fi.payload);
|
||||
|
||||
uint8_t r_payload[20];
|
||||
memcpy(&r_payload[0], this->host_mac_address_bytes, 6);
|
||||
memcpy(&r_payload[0], this->host_mac_address_bytes.data(), 6);
|
||||
memcpy(&r_payload[6], payload_bytes + 16, 4);
|
||||
memcpy(&r_payload[10], payload_bytes, 10);
|
||||
|
||||
@@ -371,9 +391,7 @@ void IPStackSimulator::on_client_arp_frame(
|
||||
evbuffer_add(out_buf, &r_arp, sizeof(r_arp));
|
||||
evbuffer_add(out_buf, r_payload, sizeof(r_payload));
|
||||
|
||||
if (this->state->ip_stack_debug) {
|
||||
this->log(INFO, "Sending ARP response");
|
||||
}
|
||||
ip_stack_simulator_log.debug("Sending ARP response");
|
||||
|
||||
if (this->pcap_text_log_file) {
|
||||
StringWriter w;
|
||||
@@ -384,21 +402,15 @@ void IPStackSimulator::on_client_arp_frame(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void IPStackSimulator::on_client_udp_frame(
|
||||
shared_ptr<IPClient> c, const FrameInfo& fi) {
|
||||
// We only implement the DNS server here
|
||||
if (fi.udp->dest_port != 53) {
|
||||
throw runtime_error("UDP packet is not DNS");
|
||||
}
|
||||
if (fi.payload_size < 0x0C) {
|
||||
throw runtime_error("DNS payload too small");
|
||||
}
|
||||
// We only implement DHCP and newserv's DNS server here
|
||||
|
||||
// Every received UDP packet will elicit exactly one UDP response from
|
||||
// newserv, so we prepare the response headers in advance
|
||||
EthernetHeader r_ether;
|
||||
memcpy(r_ether.dest_mac, fi.ether->src_mac, 6);
|
||||
memcpy(r_ether.src_mac, this->host_mac_address_bytes, 6);
|
||||
r_ether.dest_mac = fi.ether->src_mac;
|
||||
r_ether.src_mac = this->host_mac_address_bytes;
|
||||
r_ether.protocol = fi.ether->protocol;
|
||||
|
||||
IPv4Header r_ipv4;
|
||||
@@ -419,55 +431,179 @@ void IPStackSimulator::on_client_udp_frame(
|
||||
// r_udp.size filled in later
|
||||
// r_udp.checksum filled in later
|
||||
|
||||
uint32_t resolved_address = this->connect_address_for_remote_address(c->ipv4_addr);
|
||||
string r_data;
|
||||
if (fi.udp->dest_port == 67) { // DHCP
|
||||
StringReader r(fi.payload, fi.payload_size);
|
||||
const auto& dhcp = r.get<DHCPHeader>();
|
||||
if (dhcp.hardware_type != 1) {
|
||||
throw runtime_error("unknown DHCP hardware type");
|
||||
}
|
||||
if (dhcp.hardware_address_length != 6) {
|
||||
throw runtime_error("unknown DHCP hardware address length");
|
||||
}
|
||||
if (dhcp.magic != 0x63825363) {
|
||||
throw runtime_error("incorrect DHCP magic cookie");
|
||||
}
|
||||
if (dhcp.opcode != 1) { // Request
|
||||
throw runtime_error("DHCP packet is not a request");
|
||||
}
|
||||
|
||||
string r_data = DNSServer::response_for_query(
|
||||
fi.payload, fi.payload_size, resolved_address);
|
||||
unordered_map<uint8_t, string> option_data;
|
||||
for (;;) {
|
||||
uint8_t option = r.get_u8();
|
||||
if (option == 0xFF) {
|
||||
break;
|
||||
}
|
||||
uint8_t size = r.get_u8();
|
||||
option_data.emplace(option, r.read(size));
|
||||
}
|
||||
|
||||
r_ipv4.size = sizeof(IPv4Header) + sizeof(UDPHeader) + r_data.size();
|
||||
r_udp.size = sizeof(UDPHeader) + r_data.size();
|
||||
r_ipv4.checksum = FrameInfo::computed_ipv4_header_checksum(r_ipv4);
|
||||
r_udp.checksum = FrameInfo::computed_udp4_checksum(
|
||||
r_ipv4, r_udp, r_data.data(), r_data.size());
|
||||
uint8_t command = 0;
|
||||
try {
|
||||
command = option_data.at(53).at(0);
|
||||
} catch (const out_of_range&) {
|
||||
throw runtime_error("client did not send a DHCP command option");
|
||||
}
|
||||
|
||||
struct evbuffer* out_buf = bufferevent_get_output(c->bev.get());
|
||||
if (command == 7) {
|
||||
// Release IP address (we just ignore these)
|
||||
|
||||
if (this->state->ip_stack_debug) {
|
||||
string remote_str = this->str_for_ipv4_netloc(fi.ipv4->src_addr, fi.udp->src_port);
|
||||
this->log(INFO, "Sending DNS response to %s", remote_str.c_str());
|
||||
} else if ((command == 1) || (command == 3)) {
|
||||
// Populate the client's addresses
|
||||
c->mac_addr = dhcp.client_hardware_address.data();
|
||||
c->ipv4_addr = 0x0A000105; // 10.0.1.5
|
||||
// In this case, the client doesn't know its IPv4 address or ours yet,
|
||||
// so we overwrite the existing fields with the appropriate addresses.
|
||||
r_ipv4.src_addr = 0x0A000101; // 10.0.1.1
|
||||
r_ipv4.dest_addr = c->ipv4_addr;
|
||||
|
||||
if ((command != 1) && (command != 3)) {
|
||||
throw runtime_error("client sent unknown DHCP command option");
|
||||
}
|
||||
|
||||
StringWriter w;
|
||||
DHCPHeader r_dhcp;
|
||||
r_dhcp.opcode = 2; // Response
|
||||
r_dhcp.hardware_type = 1; // Ethernet
|
||||
r_dhcp.hardware_address_length = 6; // Ethernet
|
||||
r_dhcp.hops = 0;
|
||||
r_dhcp.transaction_id = dhcp.transaction_id;
|
||||
r_dhcp.seconds_elapsed = 0;
|
||||
r_dhcp.flags = 0;
|
||||
r_dhcp.client_ip_address = 0;
|
||||
r_dhcp.your_ip_address = r_ipv4.dest_addr;
|
||||
r_dhcp.server_ip_address = r_ipv4.src_addr;
|
||||
r_dhcp.gateway_ip_address = 0;
|
||||
r_dhcp.client_hardware_address = c->mac_addr;
|
||||
r_dhcp.unused_bootp_legacy.clear(0);
|
||||
r_dhcp.magic = 0x63825363;
|
||||
w.put(r_dhcp);
|
||||
// DHCP message type option
|
||||
w.put_u8(53);
|
||||
w.put_u8(1);
|
||||
w.put_u8(static_cast<uint8_t>((command == 3) ? 5 : 2)); // Offer or ack
|
||||
// DHCP server ID option
|
||||
w.put_u8(54);
|
||||
w.put_u8(4);
|
||||
w.put_u32b(0x0A000101); // 10.0.1.1
|
||||
// Lease time option
|
||||
w.put_u8(51);
|
||||
w.put_u8(4);
|
||||
w.put_u32b(60 * 60 * 24 * 7); // 1 week
|
||||
// Renewal time option
|
||||
w.put_u8(58);
|
||||
w.put_u8(4);
|
||||
w.put_u32b(60 * 60 * 24 * 7); // 1 week
|
||||
// Rebind time option
|
||||
w.put_u8(59);
|
||||
w.put_u8(4);
|
||||
w.put_u32b(60 * 60 * 24 * 7); // 1 week
|
||||
// Subnet mask option
|
||||
w.put_u8(1);
|
||||
w.put_u8(4);
|
||||
w.put_u32b(0xFFFFFF00); // 255.255.255.0
|
||||
// Broadcast IP option
|
||||
w.put_u8(28);
|
||||
w.put_u8(4);
|
||||
w.put_u32b(c->ipv4_addr | 0x000000FF);
|
||||
// DNS server option
|
||||
w.put_u8(6);
|
||||
w.put_u8(4);
|
||||
w.put_u32b(0x0A000101); // 10.0.1.1
|
||||
// Domain name option
|
||||
w.put_u8(15);
|
||||
w.put_u8(7);
|
||||
w.write("newserv");
|
||||
// Default gateway option
|
||||
w.put_u8(3);
|
||||
w.put_u8(4);
|
||||
w.put_u32b(0x0A000101); // 10.0.1.1
|
||||
// End option list
|
||||
w.put_u8(0xFF);
|
||||
|
||||
r_data = std::move(w.str());
|
||||
|
||||
} else {
|
||||
throw runtime_error("client sent unknown DHCP command");
|
||||
}
|
||||
|
||||
} else if (fi.udp->dest_port == 53) { // DNS
|
||||
if (fi.payload_size < 0x0C) {
|
||||
throw runtime_error("DNS payload too small");
|
||||
}
|
||||
|
||||
uint32_t resolved_address = this->connect_address_for_remote_address(c->ipv4_addr);
|
||||
r_data = DNSServer::response_for_query(fi.payload, fi.payload_size, resolved_address);
|
||||
|
||||
} else { // Not DHCP or DNS
|
||||
throw runtime_error("UDP packet is not DHCP or DNS");
|
||||
}
|
||||
|
||||
uint16_t frame_size = sizeof(r_ether) + sizeof(r_ipv4) + sizeof(r_udp) + r_data.size();
|
||||
evbuffer_add(out_buf, &frame_size, 2);
|
||||
evbuffer_add(out_buf, &r_ether, sizeof(r_ether));
|
||||
evbuffer_add(out_buf, &r_ipv4, sizeof(r_ipv4));
|
||||
evbuffer_add(out_buf, &r_udp, sizeof(r_udp));
|
||||
evbuffer_add(out_buf, r_data.data(), r_data.size());
|
||||
if (!r_data.empty()) {
|
||||
r_ipv4.size = sizeof(IPv4Header) + sizeof(UDPHeader) + r_data.size();
|
||||
r_udp.size = sizeof(UDPHeader) + r_data.size();
|
||||
r_ipv4.checksum = FrameInfo::computed_ipv4_header_checksum(r_ipv4);
|
||||
r_udp.checksum = FrameInfo::computed_udp4_checksum(
|
||||
r_ipv4, r_udp, r_data.data(), r_data.size());
|
||||
|
||||
if (this->pcap_text_log_file) {
|
||||
StringWriter w;
|
||||
w.write(&r_ether, sizeof(r_ether));
|
||||
w.write(&r_ipv4, sizeof(r_ipv4));
|
||||
w.write(&r_udp, sizeof(r_udp));
|
||||
w.write(r_data.data(), r_data.size());
|
||||
this->log_frame(w.str());
|
||||
struct evbuffer* out_buf = bufferevent_get_output(c->bev.get());
|
||||
|
||||
if (ip_stack_simulator_log.should_log(LogLevel::DEBUG)) {
|
||||
string remote_str = this->str_for_ipv4_netloc(fi.ipv4->src_addr, fi.udp->src_port);
|
||||
ip_stack_simulator_log.debug("Sending UDP response to %s", remote_str.c_str());
|
||||
print_data(stderr, r_data);
|
||||
}
|
||||
|
||||
uint16_t frame_size = sizeof(r_ether) + sizeof(r_ipv4) + sizeof(r_udp) + r_data.size();
|
||||
evbuffer_add(out_buf, &frame_size, 2);
|
||||
evbuffer_add(out_buf, &r_ether, sizeof(r_ether));
|
||||
evbuffer_add(out_buf, &r_ipv4, sizeof(r_ipv4));
|
||||
evbuffer_add(out_buf, &r_udp, sizeof(r_udp));
|
||||
evbuffer_add(out_buf, r_data.data(), r_data.size());
|
||||
|
||||
if (this->pcap_text_log_file) {
|
||||
StringWriter w;
|
||||
w.write(&r_ether, sizeof(r_ether));
|
||||
w.write(&r_ipv4, sizeof(r_ipv4));
|
||||
w.write(&r_udp, sizeof(r_udp));
|
||||
w.write(r_data.data(), r_data.size());
|
||||
this->log_frame(w.str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint64_t IPStackSimulator::tcp_conn_key_for_connection(
|
||||
const IPClient::TCPConnection& conn) {
|
||||
return (static_cast<uint64_t>(conn.server_addr) << 32) |
|
||||
(static_cast<uint64_t>(conn.server_port) << 16) |
|
||||
static_cast<uint64_t>(conn.client_port);
|
||||
(static_cast<uint64_t>(conn.server_port) << 16) |
|
||||
static_cast<uint64_t>(conn.client_port);
|
||||
}
|
||||
|
||||
uint64_t IPStackSimulator::tcp_conn_key_for_client_frame(
|
||||
const IPv4Header& ipv4, const TCPHeader& tcp) {
|
||||
return (static_cast<uint64_t>(ipv4.dest_addr) << 32) |
|
||||
(static_cast<uint64_t>(tcp.dest_port) << 16) |
|
||||
static_cast<uint64_t>(tcp.src_port);
|
||||
(static_cast<uint64_t>(tcp.dest_port) << 16) |
|
||||
static_cast<uint64_t>(tcp.src_port);
|
||||
}
|
||||
|
||||
uint64_t IPStackSimulator::tcp_conn_key_for_client_frame(const FrameInfo& fi) {
|
||||
@@ -477,16 +613,12 @@ uint64_t IPStackSimulator::tcp_conn_key_for_client_frame(const FrameInfo& fi) {
|
||||
return IPStackSimulator::tcp_conn_key_for_client_frame(*fi.ipv4, *fi.tcp);
|
||||
}
|
||||
|
||||
|
||||
void IPStackSimulator::on_client_tcp_frame(
|
||||
shared_ptr<IPClient> c, const FrameInfo& fi) {
|
||||
if (this->state->ip_stack_debug) {
|
||||
this->log(INFO, "Client sent TCP frame (seq=%08" PRIX32 ", ack=%08" PRIX32 ")",
|
||||
fi.tcp->seq_num.load(), fi.tcp->ack_num.load());
|
||||
}
|
||||
ip_stack_simulator_log.debug("Virtual network sent TCP frame (seq=%08" PRIX32 ", ack=%08" PRIX32 ")",
|
||||
fi.tcp->seq_num.load(), fi.tcp->ack_num.load());
|
||||
|
||||
if (fi.tcp->flags & (TCPHeader::Flag::NS | TCPHeader::Flag::CWR |
|
||||
TCPHeader::Flag::ECE | TCPHeader::Flag::URG)) {
|
||||
if (fi.tcp->flags & (TCPHeader::Flag::NS | TCPHeader::Flag::CWR | TCPHeader::Flag::ECE | TCPHeader::Flag::URG)) {
|
||||
throw runtime_error("unsupported flag in TCP packet");
|
||||
}
|
||||
|
||||
@@ -539,7 +671,6 @@ void IPStackSimulator::on_client_tcp_frame(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint64_t key = this->tcp_conn_key_for_client_frame(fi);
|
||||
auto emplace_ret = c->tcp_connections.emplace(key, IPClient::TCPConnection());
|
||||
auto& conn = emplace_ret.first->second;
|
||||
@@ -556,17 +687,15 @@ void IPStackSimulator::on_client_tcp_frame(
|
||||
conn.next_client_seq = fi.tcp->seq_num + 1;
|
||||
conn.acked_server_seq = random_object<uint32_t>();
|
||||
conn.resend_push_usecs = DEFAULT_RESEND_PUSH_USECS;
|
||||
conn.next_push_max_frame_size = max_frame_size;
|
||||
conn.awaiting_first_ack = true;
|
||||
conn.max_frame_size = max_frame_size;
|
||||
conn.bytes_received = 0;
|
||||
conn.bytes_sent = 0;
|
||||
|
||||
conn_str = this->str_for_tcp_connection(c, conn);
|
||||
if (this->state->ip_stack_debug) {
|
||||
this->log(INFO, "Client opened TCP connection %s (acked_server_seq=%08" PRIX32 ", next_client_seq=%08" PRIX32 ")",
|
||||
conn_str.c_str(), conn.acked_server_seq, conn.next_client_seq);
|
||||
} else {
|
||||
this->log(INFO, "Client opened TCP connection %s",
|
||||
conn_str.c_str());
|
||||
}
|
||||
ip_stack_simulator_log.info("Client opened TCP connection %s (acked_server_seq=%08" PRIX32 ", next_client_seq=%08" PRIX32 ")",
|
||||
conn_str.c_str(), conn.acked_server_seq, conn.next_client_seq);
|
||||
|
||||
} else {
|
||||
// Connection is NOT new; this is probably a resend of an earlier SYN
|
||||
@@ -576,18 +705,14 @@ void IPStackSimulator::on_client_tcp_frame(
|
||||
// TODO: We should check the syn/ack numbers here instead of just assuming
|
||||
// they're correct
|
||||
conn_str = this->str_for_tcp_connection(c, conn);
|
||||
if (this->state->ip_stack_debug) {
|
||||
this->log(INFO, "Client resent SYN for TCP connection %s",
|
||||
conn_str.c_str());
|
||||
}
|
||||
ip_stack_simulator_log.debug("Client resent SYN for TCP connection %s",
|
||||
conn_str.c_str());
|
||||
}
|
||||
|
||||
// Send a SYN+ACK (send_tcp_frame always adds the ACK flag)
|
||||
this->send_tcp_frame(c, conn, TCPHeader::Flag::SYN);
|
||||
if (this->state->ip_stack_debug) {
|
||||
this->log(INFO, "Sent SYN+ACK on %s (acked_server_seq=%08" PRIX32 ", next_client_seq=%08" PRIX32 ")",
|
||||
conn_str.c_str(), conn.acked_server_seq, conn.next_client_seq);
|
||||
}
|
||||
ip_stack_simulator_log.debug("Sent SYN+ACK on %s (acked_server_seq=%08" PRIX32 ", next_client_seq=%08" PRIX32 ")",
|
||||
conn_str.c_str(), conn.acked_server_seq, conn.next_client_seq);
|
||||
|
||||
} else {
|
||||
// This frame isn't a SYN, so a connection object should already exist
|
||||
@@ -601,9 +726,7 @@ void IPStackSimulator::on_client_tcp_frame(
|
||||
bool conn_valid = true;
|
||||
|
||||
if (fi.tcp->flags & TCPHeader::Flag::ACK) {
|
||||
if (this->state->ip_stack_debug) {
|
||||
this->log(INFO, "Client sent ACK %08" PRIX32, fi.tcp->ack_num.load());
|
||||
}
|
||||
ip_stack_simulator_log.debug("Client sent ACK %08" PRIX32, fi.tcp->ack_num.load());
|
||||
if (conn->awaiting_first_ack) {
|
||||
if (fi.tcp->ack_num != conn->acked_server_seq + 1) {
|
||||
throw runtime_error("first ack_num was not acked_server_seq + 1");
|
||||
@@ -613,9 +736,7 @@ void IPStackSimulator::on_client_tcp_frame(
|
||||
|
||||
} else {
|
||||
if (seq_num_greater(fi.tcp->ack_num, conn->acked_server_seq)) {
|
||||
if (this->state->ip_stack_debug) {
|
||||
this->log(INFO, "Advancing acked_server_seq from %08" PRIX32, conn->acked_server_seq);
|
||||
}
|
||||
ip_stack_simulator_log.debug("Advancing acked_server_seq from %08" PRIX32, conn->acked_server_seq);
|
||||
uint32_t ack_delta = fi.tcp->ack_num - conn->acked_server_seq;
|
||||
size_t pending_bytes = evbuffer_get_length(conn->pending_data.get());
|
||||
if (pending_bytes < ack_delta) {
|
||||
@@ -625,11 +746,10 @@ void IPStackSimulator::on_client_tcp_frame(
|
||||
evbuffer_drain(conn->pending_data.get(), ack_delta);
|
||||
conn->acked_server_seq += ack_delta;
|
||||
conn->resend_push_usecs = DEFAULT_RESEND_PUSH_USECS;
|
||||
conn->next_push_max_frame_size = conn->max_frame_size;
|
||||
|
||||
if (this->state->ip_stack_debug) {
|
||||
this->log(INFO, "Removed %08" PRIX32 " bytes from pending buffer and advanced acked_server_seq to %08" PRIX32,
|
||||
ack_delta, conn->acked_server_seq);
|
||||
}
|
||||
ip_stack_simulator_log.debug("Removed %08" PRIX32 " bytes from pending buffer and advanced acked_server_seq to %08" PRIX32,
|
||||
ack_delta, conn->acked_server_seq);
|
||||
|
||||
} else if (seq_num_less(fi.tcp->ack_num, conn->acked_server_seq)) {
|
||||
throw runtime_error("client sent lower ack num than previous frame");
|
||||
@@ -648,7 +768,7 @@ void IPStackSimulator::on_client_tcp_frame(
|
||||
}
|
||||
|
||||
string conn_str = this->str_for_tcp_connection(c, *conn);
|
||||
this->log(INFO, "Client closed TCP connection %s", conn_str.c_str());
|
||||
ip_stack_simulator_log.info("Client closed TCP connection %s", conn_str.c_str());
|
||||
|
||||
// TODO: Are we supposed to send a response to an RST? Here we do, and the
|
||||
// client probably just ignores it anyway
|
||||
@@ -659,16 +779,18 @@ void IPStackSimulator::on_client_tcp_frame(
|
||||
c->tcp_connections.erase(key);
|
||||
conn_valid = false;
|
||||
|
||||
// Note: The PSH flag isn't required to be set on all packets that contain
|
||||
// data. The PSH flag just means "tell the application that data is
|
||||
// available", so some senders only set the PSH flag on the last frame of a
|
||||
// large segment of data, since the application wouldn't be able to process
|
||||
// the segment until all of it is available. newserv can handle incomplete
|
||||
// commands, so we just ignore the PSH flag and forward any data to the
|
||||
// server immediately.
|
||||
// Note: The PSH flag isn't required to be set on all packets that contain
|
||||
// data. The PSH flag just means "tell the application that data is
|
||||
// available", so some senders only set the PSH flag on the last frame of a
|
||||
// large segment of data, since the application wouldn't be able to process
|
||||
// the segment until all of it is available. newserv can handle incomplete
|
||||
// commands, so we just ignore the PSH flag and forward any data to the
|
||||
// server immediately.
|
||||
} else if (fi.payload_size != 0) {
|
||||
|
||||
string conn_str = this->state->ip_stack_debug ? this->str_for_tcp_connection(c, *conn) : "";
|
||||
string conn_str = ip_stack_simulator_log.should_log(LogLevel::WARNING)
|
||||
? this->str_for_tcp_connection(c, *conn)
|
||||
: "";
|
||||
|
||||
size_t payload_skip_bytes;
|
||||
if (fi.tcp->seq_num == conn->next_client_seq) {
|
||||
@@ -688,11 +810,9 @@ void IPStackSimulator::on_client_tcp_frame(
|
||||
// Payload is in the future - we must have missed a data frame. We'll
|
||||
// ignore it (but warn) and send an ACK later, and the client should
|
||||
// retransmit the lost data
|
||||
if (this->state->ip_stack_debug) {
|
||||
this->log(WARNING,
|
||||
"Client sent out-of-order sequence number (expected %08" PRIX32 ", received %08" PRIX32 ", 0x%zX data bytes)",
|
||||
conn->next_client_seq, fi.tcp->seq_num.load(), fi.payload_size);
|
||||
}
|
||||
ip_stack_simulator_log.warning(
|
||||
"Client sent out-of-order sequence number (expected %08" PRIX32 ", received %08" PRIX32 ", 0x%zX data bytes)",
|
||||
conn->next_client_seq, fi.tcp->seq_num.load(), fi.payload_size);
|
||||
payload_skip_bytes = fi.payload_size;
|
||||
}
|
||||
|
||||
@@ -704,14 +824,15 @@ void IPStackSimulator::on_client_tcp_frame(
|
||||
const void* payload = reinterpret_cast<const uint8_t*>(fi.payload) + payload_skip_bytes;
|
||||
size_t payload_size = fi.payload_size - payload_skip_bytes;
|
||||
|
||||
if (this->state->ip_stack_debug) {
|
||||
if (payload_skip_bytes) {
|
||||
this->log(INFO, "Client sent data on TCP connection %s, overlapping existing ack'ed data (0x%zX bytes ignored)",
|
||||
conn_str.c_str(), payload_skip_bytes);
|
||||
} else {
|
||||
this->log(INFO, "Client sent data on TCP connection %s",
|
||||
conn_str.c_str());
|
||||
}
|
||||
bool was_logged;
|
||||
if (payload_skip_bytes) {
|
||||
was_logged = ip_stack_simulator_log.debug("Client sent data on TCP connection %s, overlapping existing ack'ed data (0x%zX bytes ignored)",
|
||||
conn_str.c_str(), payload_skip_bytes);
|
||||
} else {
|
||||
was_logged = ip_stack_simulator_log.debug("Client sent data on TCP connection %s",
|
||||
conn_str.c_str());
|
||||
}
|
||||
if (was_logged) {
|
||||
print_data(stderr, payload, payload_size);
|
||||
}
|
||||
|
||||
@@ -723,14 +844,16 @@ void IPStackSimulator::on_client_tcp_frame(
|
||||
// Update the sequence number and stats
|
||||
conn->next_client_seq += payload_size;
|
||||
conn->bytes_received += payload_size;
|
||||
if (conn->next_client_seq < payload_size) {
|
||||
ip_stack_simulator_log.warning("Client sequence number has wrapped (next=%08" PRIX32 ", bytes=%zX)",
|
||||
fi.tcp->seq_num.load(), payload_size);
|
||||
}
|
||||
}
|
||||
|
||||
// Send an ACK
|
||||
this->send_tcp_frame(c, *conn);
|
||||
if (this->state->ip_stack_debug) {
|
||||
this->log(INFO, "Sent PSH ACK on %s (acked_server_seq=%08" PRIX32 ", next_client_seq=%08" PRIX32 ", bytes_received=0x%zX)",
|
||||
conn_str.c_str(), conn->acked_server_seq, conn->next_client_seq, conn->bytes_received);
|
||||
}
|
||||
ip_stack_simulator_log.debug("Sent PSH ACK on %s (acked_server_seq=%08" PRIX32 ", next_client_seq=%08" PRIX32 ", bytes_received=0x%zX)",
|
||||
conn_str.c_str(), conn->acked_server_seq, conn->next_client_seq, conn->bytes_received);
|
||||
}
|
||||
|
||||
if (conn_valid) {
|
||||
@@ -769,21 +892,22 @@ void IPStackSimulator::open_server_connection(
|
||||
string conn_str = this->str_for_tcp_connection(c, conn);
|
||||
if (port_config->behavior == ServerBehavior::PROXY_SERVER) {
|
||||
if (!this->state->proxy_server.get()) {
|
||||
this->log(ERROR, "TCP connection %s is to non-running proxy server",
|
||||
ip_stack_simulator_log.error("TCP connection %s is to non-running proxy server",
|
||||
conn_str.c_str());
|
||||
flush_and_free_bufferevent(bevs[1]);
|
||||
} else {
|
||||
this->state->proxy_server->connect_client(bevs[1], conn.server_port);
|
||||
this->log(INFO, "Connected TCP connection %s to proxy server",
|
||||
ip_stack_simulator_log.info("Connected TCP connection %s to proxy server",
|
||||
conn_str.c_str());
|
||||
}
|
||||
} else if (this->state->game_server.get()) {
|
||||
this->state->game_server->connect_client(bevs[1], c->ipv4_addr,
|
||||
conn.client_port, port_config->version, port_config->behavior);
|
||||
this->log(INFO, "Connected TCP connection %s to game server",
|
||||
conn.client_port, conn.server_port, port_config->version,
|
||||
port_config->behavior);
|
||||
ip_stack_simulator_log.info("Connected TCP connection %s to game server",
|
||||
conn_str.c_str());
|
||||
} else {
|
||||
this->log(ERROR, "No server available for TCP connection %s",
|
||||
ip_stack_simulator_log.error("No server available for TCP connection %s",
|
||||
conn_str.c_str());
|
||||
flush_and_free_bufferevent(bevs[1]);
|
||||
}
|
||||
@@ -796,12 +920,10 @@ void IPStackSimulator::send_pending_push_frame(
|
||||
return;
|
||||
}
|
||||
|
||||
size_t bytes_to_send = min<size_t>(pending_bytes, conn.max_frame_size);
|
||||
size_t bytes_to_send = min<size_t>(pending_bytes, conn.next_push_max_frame_size);
|
||||
|
||||
if (this->state->ip_stack_debug) {
|
||||
this->log(INFO, "Sending PSH frame with seq_num %08" PRIX32 ", 0x%zX/0x%zX data bytes",
|
||||
conn.acked_server_seq, bytes_to_send, pending_bytes);
|
||||
}
|
||||
ip_stack_simulator_log.debug("Sending PSH frame with seq_num %08" PRIX32 ", 0x%zX/0x%zX data bytes",
|
||||
conn.acked_server_seq, bytes_to_send, pending_bytes);
|
||||
|
||||
this->send_tcp_frame(c, conn, TCPHeader::Flag::PSH, conn.pending_data.get(),
|
||||
bytes_to_send);
|
||||
@@ -811,11 +933,14 @@ void IPStackSimulator::send_pending_push_frame(
|
||||
// If the client isn't responding to our PSHes, back off exponentially up to
|
||||
// a limit of 5 seconds between PSH frames. This window is reset when
|
||||
// acked_server_seq changes (that is, when the client has acknowledged any new
|
||||
// data)
|
||||
// data). It seems some situations cause GameCube clients to drop packets more
|
||||
// often; to alleviate this, we also try to resend less data.
|
||||
conn.resend_push_usecs *= 2;
|
||||
if (conn.resend_push_usecs > 5000000) {
|
||||
conn.resend_push_usecs = 5000000;
|
||||
}
|
||||
conn.next_push_max_frame_size = max<size_t>(
|
||||
0x100, conn.next_push_max_frame_size - 0x100);
|
||||
}
|
||||
|
||||
void IPStackSimulator::send_tcp_frame(
|
||||
@@ -829,8 +954,8 @@ void IPStackSimulator::send_tcp_frame(
|
||||
}
|
||||
|
||||
EthernetHeader ether;
|
||||
memcpy(ether.dest_mac, c->mac_addr, 6);
|
||||
memcpy(ether.src_mac, this->host_mac_address_bytes, 6);
|
||||
ether.dest_mac = c->mac_addr;
|
||||
ether.src_mac = this->host_mac_address_bytes;
|
||||
ether.protocol = 0x0800; // IPv4
|
||||
|
||||
IPv4Header ipv4;
|
||||
@@ -887,9 +1012,14 @@ void IPStackSimulator::dispatch_on_resend_push(evutil_socket_t, short, void* ctx
|
||||
auto* conn = reinterpret_cast<IPClient::TCPConnection*>(ctx);
|
||||
auto c = conn->client.lock();
|
||||
if (!c.get()) {
|
||||
IPStackSimulator::log(WARNING, "Resend push event triggered for deleted client; ignoring");
|
||||
ip_stack_simulator_log.warning("Resend push event triggered for deleted client; ignoring");
|
||||
} else {
|
||||
c->sim->on_resend_push(c, *conn);
|
||||
auto sim = c->sim.lock();
|
||||
if (!sim) {
|
||||
ip_stack_simulator_log.warning("Resend push event triggered for client on deleted simulator; ignoring");
|
||||
} else {
|
||||
sim->on_resend_push(c, *conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -901,18 +1031,24 @@ void IPStackSimulator::dispatch_on_server_input(struct bufferevent*, void* ctx)
|
||||
auto* conn = reinterpret_cast<IPClient::TCPConnection*>(ctx);
|
||||
auto c = conn->client.lock();
|
||||
if (!c.get()) {
|
||||
IPStackSimulator::log(WARNING, "Server input event triggered for deleted client; ignoring");
|
||||
ip_stack_simulator_log.warning("Server input event triggered for deleted client; ignoring");
|
||||
} else {
|
||||
c->sim->on_server_input(c, *conn);
|
||||
auto sim = c->sim.lock();
|
||||
if (!sim) {
|
||||
ip_stack_simulator_log.warning("Server input event triggered for client on deleted simulator; ignoring");
|
||||
} else {
|
||||
sim->on_server_input(c, *conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IPStackSimulator::on_server_input(shared_ptr<IPClient> c, IPClient::TCPConnection& conn) {
|
||||
struct evbuffer* buf = bufferevent_get_input(conn.server_bev.get());
|
||||
if (this->state->ip_stack_debug) {
|
||||
this->log(INFO, "Server input event: 0x%zX bytes to read",
|
||||
evbuffer_get_length(buf));
|
||||
}
|
||||
ip_stack_simulator_log.debug("Server input event: 0x%zX bytes to read",
|
||||
evbuffer_get_length(buf));
|
||||
|
||||
struct timeval tv = usecs_to_timeval(60 * 1000 * 1000);
|
||||
event_add(c->idle_timeout_event.get(), &tv);
|
||||
|
||||
evbuffer_add_buffer(conn.pending_data.get(), buf);
|
||||
this->send_pending_push_frame(c, conn);
|
||||
@@ -923,9 +1059,14 @@ void IPStackSimulator::dispatch_on_server_error(
|
||||
auto* conn = reinterpret_cast<IPClient::TCPConnection*>(ctx);
|
||||
auto c = conn->client.lock();
|
||||
if (!c.get()) {
|
||||
IPStackSimulator::log(WARNING, "Server error event triggered for deleted client; ignoring");
|
||||
ip_stack_simulator_log.warning("Server error event triggered for deleted client; ignoring");
|
||||
} else {
|
||||
c->sim->on_server_error(c, *conn, events);
|
||||
auto sim = c->sim.lock();
|
||||
if (!sim) {
|
||||
ip_stack_simulator_log.warning("Server error event triggered for client on deleted simulator; ignoring");
|
||||
} else {
|
||||
sim->on_server_error(c, *conn, events);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -933,7 +1074,7 @@ void IPStackSimulator::on_server_error(
|
||||
shared_ptr<IPClient> c, IPClient::TCPConnection& conn, short events) {
|
||||
if (events & BEV_EVENT_ERROR) {
|
||||
int err = EVUTIL_SOCKET_ERROR();
|
||||
this->log(WARNING, "Received error %d from virtual connection (%s)", err,
|
||||
ip_stack_simulator_log.warning("Received error %d from virtual connection (%s)", err,
|
||||
evutil_socket_error_to_string(err));
|
||||
}
|
||||
if (events & (BEV_EVENT_EOF | BEV_EVENT_ERROR)) {
|
||||
@@ -945,14 +1086,11 @@ void IPStackSimulator::on_server_error(
|
||||
// Delete the connection object (this also flushes and frees the server
|
||||
// virtual connection bufferevent)
|
||||
string conn_str = this->str_for_tcp_connection(c, conn);
|
||||
this->log(INFO, "Server closed TCP connection %s",
|
||||
conn_str.c_str());
|
||||
ip_stack_simulator_log.info("Server closed TCP connection %s", conn_str.c_str());
|
||||
c->tcp_connections.erase(this->tcp_conn_key_for_connection(conn));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void IPStackSimulator::log_frame(const string& data) const {
|
||||
if (this->pcap_text_log_file) {
|
||||
print_data(this->pcap_text_log_file, data, 0, nullptr,
|
||||
|
||||
+45
-36
@@ -1,47 +1,45 @@
|
||||
#include <stdint.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <deque>
|
||||
#include <string>
|
||||
#include <phosg/Process.hh>
|
||||
#include <phosg/Filesystem.hh>
|
||||
#include <phosg/Process.hh>
|
||||
#include <string>
|
||||
|
||||
#include "IPFrameInfo.hh"
|
||||
#include "Server.hh"
|
||||
#include "ProxyServer.hh"
|
||||
#include "Server.hh"
|
||||
#include "ServerState.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
|
||||
|
||||
class IPStackSimulator {
|
||||
class IPStackSimulator : public std::enable_shared_from_this<IPStackSimulator> {
|
||||
public:
|
||||
IPStackSimulator(
|
||||
std::shared_ptr<struct event_base> base,
|
||||
std::shared_ptr<ServerState> state);
|
||||
~IPStackSimulator();
|
||||
|
||||
void listen(const std::string& socket_path);
|
||||
void listen(const std::string& addr, int port);
|
||||
void listen(int port);
|
||||
void add_socket(int fd);
|
||||
void listen(const std::string& name, const std::string& socket_path);
|
||||
void listen(const std::string& name, const std::string& addr, int port);
|
||||
void listen(const std::string& name, int port);
|
||||
void add_socket(const std::string& name, int fd);
|
||||
|
||||
static uint32_t connect_address_for_remote_address(uint32_t remote_addr);
|
||||
|
||||
private:
|
||||
static PrefixedLogger log;
|
||||
std::shared_ptr<struct event_base> base;
|
||||
std::shared_ptr<ServerState> state;
|
||||
|
||||
using unique_listener = std::unique_ptr<struct evconnlistener, void(*)(struct evconnlistener*)>;
|
||||
using unique_bufferevent = std::unique_ptr<struct bufferevent, void(*)(struct bufferevent*)>;
|
||||
using unique_evbuffer = std::unique_ptr<struct evbuffer, void(*)(struct evbuffer*)>;
|
||||
using unique_event = std::unique_ptr<struct event, void(*)(struct event*)>;
|
||||
using unique_listener = std::unique_ptr<struct evconnlistener, void (*)(struct evconnlistener*)>;
|
||||
using unique_bufferevent = std::unique_ptr<struct bufferevent, void (*)(struct bufferevent*)>;
|
||||
using unique_evbuffer = std::unique_ptr<struct evbuffer, void (*)(struct evbuffer*)>;
|
||||
using unique_event = std::unique_ptr<struct event, void (*)(struct event*)>;
|
||||
|
||||
struct IPClient {
|
||||
IPStackSimulator* sim;
|
||||
std::weak_ptr<IPStackSimulator> sim;
|
||||
|
||||
unique_bufferevent bev;
|
||||
uint8_t mac_addr[6];
|
||||
parray<uint8_t, 6> mac_addr;
|
||||
uint32_t ipv4_addr;
|
||||
|
||||
struct TCPConnection {
|
||||
@@ -66,6 +64,7 @@ private:
|
||||
uint32_t next_client_seq;
|
||||
uint32_t acked_server_seq;
|
||||
size_t resend_push_usecs;
|
||||
size_t next_push_max_frame_size;
|
||||
size_t max_frame_size;
|
||||
size_t bytes_received;
|
||||
size_t bytes_sent;
|
||||
@@ -74,21 +73,35 @@ private:
|
||||
};
|
||||
std::unordered_map<uint64_t, TCPConnection> tcp_connections;
|
||||
|
||||
IPClient(struct bufferevent* bev);
|
||||
unique_event idle_timeout_event;
|
||||
|
||||
IPClient(std::shared_ptr<IPStackSimulator> sim, struct bufferevent* bev);
|
||||
|
||||
static void dispatch_on_idle_timeout(evutil_socket_t fd, short events, void* ctx);
|
||||
void on_idle_timeout();
|
||||
};
|
||||
|
||||
std::unordered_set<unique_listener> listeners;
|
||||
struct ListeningSocket {
|
||||
std::string name;
|
||||
unique_listener listener;
|
||||
|
||||
ListeningSocket(const std::string& name, unique_listener&& l)
|
||||
: name(name),
|
||||
listener(std::move(l)) {}
|
||||
};
|
||||
|
||||
std::unordered_map<int, ListeningSocket> listening_sockets;
|
||||
std::unordered_map<struct bufferevent*, std::shared_ptr<IPClient>> bev_to_client;
|
||||
|
||||
uint8_t host_mac_address_bytes[6];
|
||||
uint8_t broadcast_mac_address_bytes[6];
|
||||
parray<uint8_t, 6> host_mac_address_bytes;
|
||||
parray<uint8_t, 6> broadcast_mac_address_bytes;
|
||||
|
||||
FILE* pcap_text_log_file;
|
||||
|
||||
static uint64_t tcp_conn_key_for_connection(
|
||||
const IPClient::TCPConnection& conn);
|
||||
static uint64_t tcp_conn_key_for_client_frame(
|
||||
const IPv4Header& ipv4, const TCPHeader& tcp);
|
||||
void disconnect_client(struct bufferevent* bev);
|
||||
|
||||
static uint64_t tcp_conn_key_for_connection(const IPClient::TCPConnection& conn);
|
||||
static uint64_t tcp_conn_key_for_client_frame(const IPv4Header& ipv4, const TCPHeader& tcp);
|
||||
static uint64_t tcp_conn_key_for_client_frame(const FrameInfo& fi);
|
||||
|
||||
static std::string str_for_ipv4_netloc(uint32_t addr, uint16_t port);
|
||||
@@ -96,16 +109,15 @@ private:
|
||||
const IPClient::TCPConnection& conn);
|
||||
|
||||
static void dispatch_on_listen_accept(struct evconnlistener* listener,
|
||||
evutil_socket_t fd, struct sockaddr *address, int socklen, void* ctx);
|
||||
evutil_socket_t fd, struct sockaddr* address, int socklen, void* ctx);
|
||||
void on_listen_accept(struct evconnlistener* listener, evutil_socket_t fd,
|
||||
struct sockaddr *address, int socklen);
|
||||
struct sockaddr* address, int socklen);
|
||||
static void dispatch_on_listen_error(struct evconnlistener* listener, void* ctx);
|
||||
void on_listen_error(struct evconnlistener* listener);
|
||||
|
||||
static void dispatch_on_client_input(struct bufferevent* bev, void* ctx);
|
||||
void on_client_input(struct bufferevent* bev);
|
||||
static void dispatch_on_client_error(struct bufferevent* bev, short events,
|
||||
void* ctx);
|
||||
static void dispatch_on_client_error(struct bufferevent* bev, short events, void* ctx);
|
||||
void on_client_error(struct bufferevent* bev, short events);
|
||||
|
||||
void on_client_frame(std::shared_ptr<IPClient> c, const std::string& frame);
|
||||
@@ -113,18 +125,15 @@ private:
|
||||
void on_client_udp_frame(std::shared_ptr<IPClient> c, const FrameInfo& fi);
|
||||
void on_client_tcp_frame(std::shared_ptr<IPClient> c, const FrameInfo& fi);
|
||||
|
||||
static void dispatch_on_resend_push(evutil_socket_t fd, short events,
|
||||
void* ctx);
|
||||
static void dispatch_on_resend_push(evutil_socket_t fd, short events, void* ctx);
|
||||
void on_resend_push(std::shared_ptr<IPClient> c, IPClient::TCPConnection& conn);
|
||||
|
||||
static void dispatch_on_server_input(struct bufferevent* bev, void* ctx);
|
||||
void on_server_input(std::shared_ptr<IPClient> c, IPClient::TCPConnection& conn);
|
||||
static void dispatch_on_server_error(struct bufferevent* bev, short events,
|
||||
void* ctx);
|
||||
static void dispatch_on_server_error(struct bufferevent* bev, short events, void* ctx);
|
||||
void on_server_error(std::shared_ptr<IPClient> c, IPClient::TCPConnection& conn, short events);
|
||||
|
||||
void send_pending_push_frame(
|
||||
std::shared_ptr<IPClient> c, IPClient::TCPConnection& conn);
|
||||
void send_pending_push_frame(std::shared_ptr<IPClient> c, IPClient::TCPConnection& conn);
|
||||
void send_tcp_frame(
|
||||
std::shared_ptr<IPClient> c,
|
||||
IPClient::TCPConnection& conn,
|
||||
|
||||
+1701
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,155 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "CommonItemSet.hh"
|
||||
#include "ItemParameterTable.hh"
|
||||
#include "PSOEncryption.hh"
|
||||
#include "PlayerSubordinates.hh"
|
||||
#include "RareItemSet.hh"
|
||||
#include "StaticGameData.hh"
|
||||
|
||||
class ItemCreator {
|
||||
public:
|
||||
ItemCreator(
|
||||
std::shared_ptr<const CommonItemSet> common_item_set,
|
||||
std::shared_ptr<const RareItemSet> rare_item_set,
|
||||
std::shared_ptr<const ArmorRandomSet> armor_random_set,
|
||||
std::shared_ptr<const ToolRandomSet> tool_random_set,
|
||||
std::shared_ptr<const WeaponRandomSet> weapon_random_set,
|
||||
std::shared_ptr<const TekkerAdjustmentSet> tekker_adjustment_set,
|
||||
std::shared_ptr<const ItemParameterTable> item_parameter_table,
|
||||
Episode episode,
|
||||
GameMode mode,
|
||||
uint8_t difficulty,
|
||||
uint8_t section_id,
|
||||
uint32_t random_seed,
|
||||
std::shared_ptr<const BattleRules> restrictions = nullptr);
|
||||
~ItemCreator() = default;
|
||||
|
||||
ItemData on_monster_item_drop(uint32_t enemy_type, uint8_t area);
|
||||
ItemData on_box_item_drop(uint8_t area);
|
||||
ItemData on_specialized_box_item_drop(uint32_t def0, uint32_t def1, uint32_t def2);
|
||||
|
||||
std::vector<ItemData> generate_armor_shop_contents(size_t player_level);
|
||||
std::vector<ItemData> generate_tool_shop_contents(size_t player_level);
|
||||
std::vector<ItemData> generate_weapon_shop_contents(size_t player_level);
|
||||
|
||||
// This function adjusts the item in-place, and returns the luck value.
|
||||
// See the comments in TekkerAdjustmentSet for what this value means.
|
||||
ssize_t apply_tekker_deltas(ItemData& item, uint8_t section_id);
|
||||
|
||||
inline void set_restrictions(std::shared_ptr<const BattleRules> restrictions) {
|
||||
this->restrictions = restrictions;
|
||||
}
|
||||
|
||||
private:
|
||||
PrefixedLogger log;
|
||||
Episode episode;
|
||||
GameMode mode;
|
||||
uint8_t difficulty;
|
||||
uint8_t section_id;
|
||||
std::shared_ptr<const CommonItemSet> common_item_set;
|
||||
std::shared_ptr<const RareItemSet> rare_item_set;
|
||||
std::shared_ptr<const ArmorRandomSet> armor_random_set;
|
||||
std::shared_ptr<const ToolRandomSet> tool_random_set;
|
||||
std::shared_ptr<const WeaponRandomSet> weapon_random_set;
|
||||
std::shared_ptr<const TekkerAdjustmentSet> tekker_adjustment_set;
|
||||
std::shared_ptr<const ItemParameterTable> item_parameter_table;
|
||||
const CommonItemSet::Table<true>* pt;
|
||||
std::shared_ptr<const BattleRules> restrictions;
|
||||
|
||||
parray<uint8_t, 0x88> unit_weights_table1;
|
||||
parray<int8_t, 0x0D> unit_weights_table2;
|
||||
|
||||
// Note: The original implementation uses 17 different random states for some
|
||||
// reason. We forego that and use only one for simplicity.
|
||||
PSOV2Encryption random_crypt;
|
||||
|
||||
bool are_rare_drops_allowed() const;
|
||||
uint8_t normalize_area_number(uint8_t area) const;
|
||||
|
||||
ItemData on_monster_item_drop_with_norm_area(
|
||||
uint32_t enemy_type, uint8_t norm_area);
|
||||
ItemData on_box_item_drop_with_norm_area(uint8_t area_norm);
|
||||
|
||||
uint32_t rand_int(uint64_t max);
|
||||
float rand_float_0_1_from_crypt();
|
||||
|
||||
template <size_t NumRanges>
|
||||
uint32_t choose_meseta_amount(
|
||||
const parray<CommonItemSet::Range<be_uint16_t>, NumRanges> ranges,
|
||||
size_t table_index);
|
||||
|
||||
bool should_allow_meseta_drops() const;
|
||||
|
||||
ItemData check_rare_spec_and_create_rare_enemy_item(uint32_t enemy_type);
|
||||
ItemData check_rare_specs_and_create_rare_box_item(uint8_t area_norm);
|
||||
ItemData check_rate_and_create_rare_item(const RareItemSet::ExpandedDrop& drop);
|
||||
|
||||
void generate_rare_weapon_bonuses(ItemData& item, uint32_t random_sample);
|
||||
void deduplicate_weapon_bonuses(ItemData& item) const;
|
||||
void set_item_kill_count_if_unsealable(ItemData& item) const;
|
||||
void set_item_unidentified_flag_if_challenge(ItemData& item) const;
|
||||
void set_tool_item_amount_to_1(ItemData& item) const;
|
||||
|
||||
void generate_common_item_variances(uint32_t norm_area, ItemData& item);
|
||||
void generate_common_armor_slots_and_bonuses(ItemData& item);
|
||||
void generate_common_armor_slot_count(ItemData& item);
|
||||
void generate_common_armor_or_shield_type_and_variances(
|
||||
char area_norm, ItemData& item);
|
||||
void generate_common_tool_variances(uint32_t area_norm, ItemData& item);
|
||||
uint8_t generate_tech_disk_level(uint32_t tech_num, uint32_t area_norm);
|
||||
void generate_common_tool_type(uint8_t tool_class, ItemData& item) const;
|
||||
void generate_common_mag_variances(ItemData& item) const;
|
||||
void generate_common_weapon_variances(uint8_t area_norm, ItemData& item);
|
||||
void generate_common_weapon_grind(ItemData& item,
|
||||
uint8_t offset_within_subtype_range);
|
||||
void generate_common_weapon_bonuses(ItemData& item, uint8_t area_norm);
|
||||
void generate_common_weapon_special(ItemData& item, uint8_t area_norm);
|
||||
uint8_t choose_weapon_special(uint8_t det);
|
||||
void generate_unit_weights_tables();
|
||||
void generate_common_unit_variances(uint8_t det, ItemData& item);
|
||||
void choose_tech_disk_level_for_tool_shop(
|
||||
ItemData& item, size_t player_level, uint8_t tech_num_index);
|
||||
static void clear_tool_item_if_invalid(ItemData& item);
|
||||
void clear_item_if_restricted(ItemData& item) const;
|
||||
|
||||
static size_t get_table_index_for_armor_shop(size_t player_level);
|
||||
static bool shop_does_not_contain_duplicate_armor(
|
||||
const std::vector<ItemData>& shop, const ItemData& item);
|
||||
static bool shop_does_not_contain_duplicate_tech_disk(
|
||||
const std::vector<ItemData>& shop, const ItemData& item);
|
||||
static bool shop_does_not_contain_duplicate_or_too_many_similar_weapons(
|
||||
const std::vector<ItemData>& shop, const ItemData& item);
|
||||
static bool shop_does_not_contain_duplicate_item_by_primary_identifier(
|
||||
const std::vector<ItemData>& shop, const ItemData& item);
|
||||
void generate_armor_shop_armors(
|
||||
std::vector<ItemData>& shop, size_t player_level);
|
||||
void generate_armor_shop_shields(
|
||||
std::vector<ItemData>& shop, size_t player_level);
|
||||
void generate_armor_shop_units(
|
||||
std::vector<ItemData>& shop, size_t player_level);
|
||||
|
||||
static size_t get_table_index_for_tool_shop(size_t player_level);
|
||||
void generate_common_tool_shop_recovery_items(
|
||||
std::vector<ItemData>& shop, size_t player_level);
|
||||
void generate_rare_tool_shop_recovery_items(
|
||||
std::vector<ItemData>& shop, size_t player_level);
|
||||
void generate_tool_shop_tech_disks(
|
||||
std::vector<ItemData>& shop, size_t player_level);
|
||||
|
||||
void generate_weapon_shop_item_grind(ItemData& item, size_t player_level);
|
||||
void generate_weapon_shop_item_special(ItemData& item, size_t player_level);
|
||||
void generate_weapon_shop_item_bonus1(ItemData& item, size_t player_level);
|
||||
void generate_weapon_shop_item_bonus2(ItemData& item, size_t player_level);
|
||||
|
||||
template <typename IntT>
|
||||
IntT get_rand_from_weighted_tables(
|
||||
const IntT* tables, size_t offset, size_t num_values, size_t stride);
|
||||
template <typename IntT, size_t X>
|
||||
IntT get_rand_from_weighted_tables_1d(const parray<IntT, X>& tables);
|
||||
template <typename IntT, size_t X, size_t Y>
|
||||
IntT get_rand_from_weighted_tables_2d_vertical(
|
||||
const parray<parray<IntT, X>, Y>& tables, size_t offset);
|
||||
};
|
||||
+2013
File diff suppressed because it is too large
Load Diff
+157
@@ -0,0 +1,157 @@
|
||||
#pragma once
|
||||
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <string>
|
||||
|
||||
#include "Text.hh"
|
||||
#include "Version.hh"
|
||||
|
||||
constexpr uint32_t MESETA_IDENTIFIER = 0x00040000;
|
||||
|
||||
struct ItemMagStats {
|
||||
uint16_t iq;
|
||||
uint16_t synchro;
|
||||
uint16_t def;
|
||||
uint16_t pow;
|
||||
uint16_t dex;
|
||||
uint16_t mind;
|
||||
uint8_t flags;
|
||||
uint8_t photon_blasts;
|
||||
uint8_t color;
|
||||
|
||||
ItemMagStats()
|
||||
: iq(0),
|
||||
synchro(40),
|
||||
def(500),
|
||||
pow(0),
|
||||
dex(0),
|
||||
mind(0),
|
||||
flags(0),
|
||||
photon_blasts(0),
|
||||
color(14) {}
|
||||
|
||||
inline uint16_t def_level() const {
|
||||
return this->def / 100;
|
||||
}
|
||||
inline uint16_t pow_level() const {
|
||||
return this->pow / 100;
|
||||
}
|
||||
inline uint16_t dex_level() const {
|
||||
return this->dex / 100;
|
||||
}
|
||||
inline uint16_t mind_level() const {
|
||||
return this->mind / 100;
|
||||
}
|
||||
inline uint16_t level() const {
|
||||
return this->def_level() + this->pow_level() + this->dex_level() + this->mind_level();
|
||||
}
|
||||
};
|
||||
|
||||
struct ItemData { // 0x14 bytes
|
||||
// QUICK ITEM FORMAT REFERENCE
|
||||
// data1/0 data1/4 data1/8 data2
|
||||
// Weapon: 00ZZZZGG SS00AABB AABBAABB 00000000
|
||||
// Armor: 0101ZZ00 FFTTDDDD EEEE0000 00000000
|
||||
// Shield: 0102ZZ00 FFTTDDDD EEEE0000 00000000
|
||||
// Unit: 0103ZZ00 FF0000RR RR000000 00000000
|
||||
// Mag: 02ZZLLWW HHHHIIII JJJJKKKK YYQQPPVV
|
||||
// Tool: 03ZZZZFF 00CC0000 00000000 00000000
|
||||
// Meseta: 04000000 00000000 00000000 MMMMMMMM
|
||||
// A = attribute type (for S-ranks, custom name)
|
||||
// B = attribute amount (for S-ranks, custom name)
|
||||
// C = stack size (for tools)
|
||||
// D = DEF bonus
|
||||
// E = EVP bonus
|
||||
// F = flags (40=present; for tools, unused if item is stackable)
|
||||
// G = weapon grind
|
||||
// H = mag DEF
|
||||
// I = mag POW
|
||||
// J = mag DEX
|
||||
// K = mag MIND
|
||||
// L = mag level
|
||||
// M = meseta amount
|
||||
// P = mag flags (40=present, 04=has left pb, 02=has right pb, 01=has center pb)
|
||||
// Q = mag IQ
|
||||
// R = unit modifier (little-endian)
|
||||
// S = weapon flags (80=unidentified, 40=present) and special (low 6 bits)
|
||||
// T = slot count
|
||||
// V = mag color
|
||||
// W = photon blasts
|
||||
// Y = mag synchro
|
||||
// Z = item ID
|
||||
// Note: PSO GC erroneously byteswaps data2 even when the item is a mag. This
|
||||
// makes it incompatible with little-endian versions of PSO (i.e. all other
|
||||
// versions). We manually byteswap data2 upon receipt and immediately before
|
||||
// sending where needed.
|
||||
// Related note: PSO V2 has an annoyingly complicated format for mags that
|
||||
// doesn't match the above table. We decode this upon receipt and encode it
|
||||
// imemdiately before sending when interacting with V2 clients; see the
|
||||
// implementation of decode_if_mag() for details.
|
||||
|
||||
union {
|
||||
parray<uint8_t, 12> data1;
|
||||
parray<le_uint16_t, 6> data1w;
|
||||
parray<le_uint32_t, 3> data1d;
|
||||
} __attribute__((packed));
|
||||
le_uint32_t id;
|
||||
union {
|
||||
parray<uint8_t, 4> data2;
|
||||
parray<le_uint16_t, 2> data2w;
|
||||
le_uint32_t data2d;
|
||||
} __attribute__((packed));
|
||||
|
||||
ItemData();
|
||||
explicit ItemData(const std::string& orig_description, bool allow_raw_data = true);
|
||||
ItemData(const ItemData& other);
|
||||
ItemData& operator=(const ItemData& other);
|
||||
|
||||
void parse(const std::string& desc, bool skip_specials);
|
||||
|
||||
bool operator==(const ItemData& other) const;
|
||||
bool operator!=(const ItemData& other) const;
|
||||
|
||||
void clear();
|
||||
|
||||
std::string hex() const;
|
||||
std::string name(bool include_color_codes) const;
|
||||
uint32_t primary_identifier() const;
|
||||
|
||||
bool is_wrapped() const;
|
||||
void wrap();
|
||||
void unwrap();
|
||||
|
||||
bool is_stackable() const;
|
||||
size_t stack_size() const;
|
||||
size_t max_stack_size() const;
|
||||
|
||||
static bool is_common_consumable(uint32_t primary_identifier);
|
||||
bool is_common_consumable() const;
|
||||
|
||||
void assign_mag_stats(const ItemMagStats& mag);
|
||||
void clear_mag_stats();
|
||||
uint16_t compute_mag_level() const;
|
||||
uint16_t compute_mag_strength_flags() const;
|
||||
uint8_t mag_photon_blast_for_slot(uint8_t slot) const;
|
||||
bool mag_has_photon_blast_in_any_slot(uint8_t pb_num) const;
|
||||
void add_mag_photon_blast(uint8_t pb_num);
|
||||
void decode_if_mag(GameVersion version);
|
||||
void encode_if_mag(GameVersion version);
|
||||
|
||||
uint16_t get_sealed_item_kill_count() const;
|
||||
void set_sealed_item_kill_count(uint16_t v);
|
||||
uint8_t get_tool_item_amount() const;
|
||||
void set_tool_item_amount(uint8_t amount);
|
||||
int16_t get_armor_or_shield_defense_bonus() const;
|
||||
void set_armor_or_shield_defense_bonus(int16_t bonus);
|
||||
int16_t get_common_armor_evasion_bonus() const;
|
||||
void set_common_armor_evasion_bonus(int16_t bonus);
|
||||
int16_t get_unit_bonus() const;
|
||||
void set_unit_bonus(int16_t bonus);
|
||||
|
||||
bool has_bonuses() const;
|
||||
bool is_s_rank_weapon() const;
|
||||
|
||||
bool empty() const;
|
||||
|
||||
static bool compare_for_sort(const ItemData& a, const ItemData& b);
|
||||
} __attribute__((packed));
|
||||
@@ -0,0 +1,383 @@
|
||||
#include "ItemParameterTable.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
ItemParameterTable::ItemParameterTable(shared_ptr<const string> data)
|
||||
: data(data),
|
||||
r(*data) {
|
||||
size_t offset_table_offset = this->r.pget_u32l(this->data->size() - 0x10);
|
||||
this->offsets = &r.pget<TableOffsets>(offset_table_offset);
|
||||
}
|
||||
|
||||
const ItemParameterTable::Weapon& ItemParameterTable::get_weapon(
|
||||
uint8_t data1_1, uint8_t data1_2) const {
|
||||
if (data1_1 >= 0xED) {
|
||||
throw runtime_error("weapon ID out of range");
|
||||
}
|
||||
const auto& co = this->r.pget<CountAndOffset>(
|
||||
this->offsets->weapon_table + sizeof(CountAndOffset) * data1_1);
|
||||
if (data1_2 >= co.count) {
|
||||
throw runtime_error("weapon ID out of range");
|
||||
}
|
||||
return this->r.pget<Weapon>(co.offset + sizeof(Weapon) * data1_2);
|
||||
}
|
||||
|
||||
const ItemParameterTable::ArmorOrShield& ItemParameterTable::get_armor_or_shield(
|
||||
uint8_t data1_1, uint8_t data1_2) const {
|
||||
if ((data1_1 < 1) || (data1_1 > 2)) {
|
||||
throw runtime_error("armor/shield ID out of range");
|
||||
}
|
||||
const auto& co = this->r.pget<CountAndOffset>(
|
||||
this->offsets->armor_table + sizeof(CountAndOffset) * (data1_1 - 1));
|
||||
if (data1_2 >= co.count) {
|
||||
throw runtime_error("armor/shield ID out of range");
|
||||
}
|
||||
return this->r.pget<ArmorOrShield>(co.offset + sizeof(ArmorOrShield) * data1_2);
|
||||
}
|
||||
|
||||
const ItemParameterTable::Unit& ItemParameterTable::get_unit(
|
||||
uint8_t data1_2) const {
|
||||
const auto& co = this->r.pget<CountAndOffset>(this->offsets->unit_table);
|
||||
if (data1_2 >= co.count) {
|
||||
throw runtime_error("unit ID out of range");
|
||||
}
|
||||
return this->r.pget<Unit>(co.offset + sizeof(Unit) * data1_2);
|
||||
}
|
||||
|
||||
const ItemParameterTable::Tool& ItemParameterTable::get_tool(
|
||||
uint8_t data1_1, uint8_t data1_2) const {
|
||||
if (data1_1 > 0x1A) {
|
||||
throw runtime_error("tool ID out of range");
|
||||
}
|
||||
const auto& co = this->r.pget<CountAndOffset>(
|
||||
this->offsets->tool_table + sizeof(CountAndOffset) * data1_1);
|
||||
if (data1_2 >= co.count) {
|
||||
throw runtime_error("tool ID out of range");
|
||||
}
|
||||
return this->r.pget<Tool>(co.offset + sizeof(Tool) * data1_2);
|
||||
}
|
||||
|
||||
pair<uint8_t, uint8_t> ItemParameterTable::find_tool_by_class(
|
||||
uint8_t tool_class) const {
|
||||
const auto& cos = this->r.pget<parray<CountAndOffset, 0x18>>(
|
||||
this->offsets->tool_table);
|
||||
for (size_t z = 0; z < cos.size(); z++) {
|
||||
const auto& co = cos[z];
|
||||
const auto* defs = &this->r.pget<Tool>(co.offset, sizeof(Tool) * co.count);
|
||||
for (size_t y = 0; y < co.count; y++) {
|
||||
if (defs[y].base.id == tool_class) {
|
||||
return make_pair(z, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw runtime_error("invalid tool class");
|
||||
}
|
||||
|
||||
const ItemParameterTable::Mag& ItemParameterTable::get_mag(
|
||||
uint8_t data1_1) const {
|
||||
const auto& co = this->r.pget<CountAndOffset>(this->offsets->mag_table);
|
||||
if (data1_1 >= co.count) {
|
||||
throw runtime_error("unit ID out of range");
|
||||
}
|
||||
return this->r.pget<Mag>(co.offset + sizeof(Mag) * data1_1);
|
||||
}
|
||||
|
||||
float ItemParameterTable::get_sale_divisor(uint8_t data1_0, uint8_t data1_1) const {
|
||||
if (data1_0 == 0) { // Weapon
|
||||
if (data1_1 < 0xED) {
|
||||
return this->r.pget_f32l(
|
||||
this->offsets->weapon_sale_divisor_table + data1_1 * sizeof(float));
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
const auto& divisors = this->r.pget<NonWeaponSaleDivisors>(
|
||||
this->offsets->sale_divisor_table);
|
||||
if (data1_0 == 1) {
|
||||
switch (data1_1) {
|
||||
case 1:
|
||||
return divisors.armor_divisor;
|
||||
case 2:
|
||||
return divisors.shield_divisor;
|
||||
case 3:
|
||||
return divisors.unit_divisor;
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
if (data1_0 == 2) {
|
||||
return divisors.mag_divisor;
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
const ItemParameterTable::MagFeedResult& ItemParameterTable::get_mag_feed_result(
|
||||
uint8_t table_index, uint8_t item_index) const {
|
||||
if (table_index >= 8) {
|
||||
throw runtime_error("invalid mag feed table index");
|
||||
}
|
||||
if (item_index >= 11) {
|
||||
throw runtime_error("invalid mag feed item index");
|
||||
}
|
||||
const auto& table_offsets = this->r.pget<MagFeedResultsListOffsets>(this->offsets->mag_feed_table);
|
||||
const auto& results = this->r.pget<MagFeedResultsList>(table_offsets.offsets[table_index]);
|
||||
return results.results[item_index];
|
||||
}
|
||||
|
||||
uint8_t ItemParameterTable::get_item_stars(uint16_t slot) const {
|
||||
if ((slot >= 0xB1) && (slot < 0x437)) {
|
||||
return this->r.pget_u8(this->offsets->star_value_table + slot - 0xB1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t ItemParameterTable::get_special_stars(uint8_t det) const {
|
||||
if (!(det & 0x3F) || (det & 0x80)) {
|
||||
return 0;
|
||||
}
|
||||
// Note: PSO GC uses 0x1CB here. 0x256 was chosen to point to the same data in
|
||||
// PSO BB's ItemPMT file.
|
||||
return this->get_item_stars(det + 0x0256);
|
||||
}
|
||||
|
||||
const ItemParameterTable::Special& ItemParameterTable::get_special(uint8_t special) const {
|
||||
special &= 0x3F;
|
||||
if (special >= 0x29) {
|
||||
throw runtime_error("invalid special index");
|
||||
}
|
||||
return this->r.pget<Special>(this->offsets->special_data_table + sizeof(Special) * special);
|
||||
}
|
||||
|
||||
uint8_t ItemParameterTable::get_max_tech_level(uint8_t char_class, uint8_t tech_num) const {
|
||||
if (char_class >= 12) {
|
||||
throw runtime_error("invalid character class");
|
||||
}
|
||||
if (tech_num >= 19) {
|
||||
throw runtime_error("invalid technique number");
|
||||
}
|
||||
return r.pget_u8(this->offsets->max_tech_level_table + tech_num * 12 + char_class);
|
||||
}
|
||||
|
||||
const ItemParameterTable::ItemBase& ItemParameterTable::get_item_definition(
|
||||
const ItemData& item) const {
|
||||
switch (item.data1[0]) {
|
||||
case 0:
|
||||
return this->get_weapon(item.data1[1], item.data1[2]).base;
|
||||
case 1:
|
||||
if (item.data1[1] == 3) {
|
||||
return this->get_unit(item.data1[2]).base;
|
||||
} else if ((item.data1[1] == 1) || (item.data1[1] == 2)) {
|
||||
return this->get_armor_or_shield(item.data1[1], item.data1[2]).base;
|
||||
}
|
||||
throw runtime_error("invalid item");
|
||||
case 2:
|
||||
return this->get_mag(item.data1[1]).base;
|
||||
case 3:
|
||||
if (item.data1[1] == 2) {
|
||||
return this->get_tool(2, item.data1[4]).base;
|
||||
} else {
|
||||
return this->get_tool(item.data1[1], item.data1[2]).base;
|
||||
}
|
||||
throw logic_error("this should be impossible");
|
||||
case 4:
|
||||
throw runtime_error("item is meseta and therefore has no definition");
|
||||
default:
|
||||
throw runtime_error("invalid item");
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ItemParameterTable::get_item_base_stars(const ItemData& item) const {
|
||||
if (item.data1[0] == 2) {
|
||||
return (item.data1[1] > 0x27) ? 12 : 0;
|
||||
} else if (item.data1[0] < 2) {
|
||||
return this->get_item_stars(this->get_item_definition(item).id);
|
||||
} else if (item.data1[0] == 3) {
|
||||
const auto& def = (item.data1[1] == 2)
|
||||
? this->get_tool(2, item.data1[4])
|
||||
: this->get_tool(item.data1[1], item.data1[2]);
|
||||
return (def.item_flag & 0x80) ? 12 : 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ItemParameterTable::get_item_adjusted_stars(const ItemData& item) const {
|
||||
uint8_t ret = this->get_item_base_stars(item);
|
||||
if (item.data1[0] == 0) {
|
||||
if (ret < 9) {
|
||||
if (!(item.data1[4] & 0x80)) {
|
||||
ret += this->get_special_stars(item.data1[4]);
|
||||
}
|
||||
} else if (item.data1[4] & 0x80) {
|
||||
ret = 0;
|
||||
}
|
||||
} else if (item.data1[0] == 1) {
|
||||
if (item.data1[1] == 3) {
|
||||
int16_t unit_bonus = item.get_unit_bonus();
|
||||
if (unit_bonus < 0) {
|
||||
ret--;
|
||||
} else if (unit_bonus > 0) {
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return min<uint8_t>(ret, 12);
|
||||
}
|
||||
|
||||
bool ItemParameterTable::is_item_rare(const ItemData& item) const {
|
||||
return (this->get_item_base_stars(item) >= 9);
|
||||
}
|
||||
|
||||
bool ItemParameterTable::is_unsealable_item(const ItemData& item) const {
|
||||
const auto& co = this->r.pget<CountAndOffset>(this->offsets->unsealable_table);
|
||||
const auto* defs = &this->r.pget<UnsealableItem>(
|
||||
co.offset, co.count * sizeof(UnsealableItem));
|
||||
for (size_t z = 0; z < co.count; z++) {
|
||||
if ((defs[z].item[0] == item.data1[0]) &&
|
||||
(defs[z].item[1] == item.data1[1]) &&
|
||||
(defs[z].item[2] == item.data1[2])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ItemParameterTable::populate_item_combination_index() const {
|
||||
if (!this->item_combination_index.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& co = this->r.pget<CountAndOffset>(this->offsets->combination_table);
|
||||
const auto* defs = &this->r.pget<ItemCombination>(
|
||||
co.offset, co.count * sizeof(ItemCombination));
|
||||
for (size_t z = 0; z < co.count; z++) {
|
||||
const auto& def = defs[z];
|
||||
uint32_t key = (def.used_item[0] << 16) | (def.used_item[1] << 8) | def.used_item[2];
|
||||
this->item_combination_index[key].emplace_back(def);
|
||||
}
|
||||
}
|
||||
|
||||
const ItemParameterTable::ItemCombination& ItemParameterTable::get_item_combination(
|
||||
const ItemData& used_item, const ItemData& equipped_item) const {
|
||||
for (const auto& def : this->get_all_combinations_for_used_item(used_item)) {
|
||||
if ((def.equipped_item[0] == 0xFF || def.equipped_item[0] == equipped_item.data1[0]) &&
|
||||
(def.equipped_item[1] == 0xFF || def.equipped_item[1] == equipped_item.data1[1]) &&
|
||||
(def.equipped_item[2] == 0xFF || def.equipped_item[2] == equipped_item.data1[2])) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
throw out_of_range("no item combination applies");
|
||||
}
|
||||
|
||||
const std::vector<ItemParameterTable::ItemCombination>& ItemParameterTable::get_all_combinations_for_used_item(
|
||||
const ItemData& used_item) const {
|
||||
try {
|
||||
uint32_t key = (used_item.data1[0] << 16) | (used_item.data1[1] << 8) | used_item.data1[2];
|
||||
return this->get_all_item_combinations().at(key);
|
||||
} catch (const out_of_range&) {
|
||||
static const vector<ItemCombination> ret;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
const std::map<uint32_t, std::vector<ItemParameterTable::ItemCombination>>& ItemParameterTable::get_all_item_combinations() const {
|
||||
this->populate_item_combination_index();
|
||||
return this->item_combination_index;
|
||||
}
|
||||
|
||||
std::pair<const ItemParameterTable::EventItem*, size_t> ItemParameterTable::get_event_items(uint8_t event_number) const {
|
||||
const auto& co = this->r.pget<CountAndOffset>(this->offsets->unwrap_table);
|
||||
if (event_number >= co.count) {
|
||||
throw runtime_error("invalid event number");
|
||||
}
|
||||
const auto& event_co = this->r.pget<CountAndOffset>(co.offset + sizeof(CountAndOffset) * event_number);
|
||||
const auto* defs = &this->r.pget<EventItem>(event_co.offset, event_co.count * sizeof(ItemCombination));
|
||||
return make_pair(defs, event_co.count);
|
||||
}
|
||||
|
||||
size_t ItemParameterTable::price_for_item(const ItemData& item) const {
|
||||
switch (item.data1[0]) {
|
||||
case 0: {
|
||||
if (item.data1[4] & 0x80) {
|
||||
return 8;
|
||||
}
|
||||
if (this->is_item_rare(item)) {
|
||||
return 80;
|
||||
}
|
||||
|
||||
float sale_divisor = this->get_sale_divisor(item.data1[0], item.data1[1]);
|
||||
if (sale_divisor == 0.0) {
|
||||
throw runtime_error("item sale divisor is zero");
|
||||
}
|
||||
|
||||
const auto& def = this->get_weapon(item.data1[1], item.data1[2]);
|
||||
double atp_max = def.atp_max + item.data1[3];
|
||||
double atp_factor = ((atp_max * atp_max) / sale_divisor);
|
||||
|
||||
double bonus_factor = 0.0;
|
||||
for (size_t bonus_index = 0; bonus_index < 3; bonus_index++) {
|
||||
uint8_t bonus_type = item.data1[(2 * bonus_index) + 6];
|
||||
if ((bonus_type > 0) && (bonus_type < 6)) {
|
||||
bonus_factor += item.data1[(2 * bonus_index) + 7];
|
||||
}
|
||||
bonus_factor += 100.0;
|
||||
}
|
||||
|
||||
size_t special_stars = this->get_special_stars(item.data1[4]);
|
||||
double special_stars_factor = 1000.0 * special_stars * special_stars;
|
||||
|
||||
return special_stars_factor + ((atp_factor * bonus_factor) / 100.0);
|
||||
}
|
||||
|
||||
case 1: {
|
||||
if (this->is_item_rare(item)) {
|
||||
return 80;
|
||||
}
|
||||
|
||||
if (item.data1[1] == 3) { // Unit
|
||||
return this->get_item_adjusted_stars(item) * this->get_sale_divisor(item.data1[0], 3);
|
||||
}
|
||||
|
||||
double sale_divisor = (double)this->get_sale_divisor(item.data1[0], item.data1[1]);
|
||||
if (sale_divisor == 0.0) {
|
||||
throw runtime_error("item sale divisor is zero");
|
||||
}
|
||||
|
||||
int16_t def_bonus = item.get_armor_or_shield_defense_bonus();
|
||||
int16_t evp_bonus = item.get_common_armor_evasion_bonus();
|
||||
|
||||
const auto& def = this->get_armor_or_shield(item.data1[1], item.data1[2]);
|
||||
double power_factor = def.dfp + def.evp + def_bonus + evp_bonus;
|
||||
double power_factor_floor = static_cast<int32_t>((power_factor * power_factor) / sale_divisor);
|
||||
return power_factor_floor + (70.0 * static_cast<double>(item.data1[5] + 1) * static_cast<double>(def.required_level + 1));
|
||||
}
|
||||
|
||||
case 2:
|
||||
return (item.data1[2] + 1) * this->get_sale_divisor(2, item.data1[1]);
|
||||
|
||||
case 3: {
|
||||
const auto& def = this->get_tool(item.data1[1], item.data1[2]);
|
||||
return def.cost * ((item.data1[1] == 2) ? (item.data1[2] + 1) : 1);
|
||||
}
|
||||
|
||||
case 4:
|
||||
return item.data2d;
|
||||
|
||||
default:
|
||||
throw runtime_error("invalid item");
|
||||
}
|
||||
throw logic_error("this should be impossible");
|
||||
}
|
||||
|
||||
MagEvolutionTable::MagEvolutionTable(shared_ptr<const string> data)
|
||||
: data(data),
|
||||
r(*data) {
|
||||
size_t offset_table_offset = this->r.pget_u32l(this->data->size() - 0x10);
|
||||
this->offsets = &r.pget<TableOffsets>(offset_table_offset);
|
||||
}
|
||||
|
||||
uint8_t MagEvolutionTable::get_evolution_number(uint8_t data1_1) const {
|
||||
const auto& table = this->r.pget<EvolutionNumberTable>(this->offsets->evolution_number);
|
||||
return table.values[data1_1];
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ItemData.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
class ItemParameterTable {
|
||||
public:
|
||||
struct CountAndOffset {
|
||||
le_uint32_t count;
|
||||
le_uint32_t offset;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct ItemBase {
|
||||
le_uint32_t id;
|
||||
le_uint16_t type;
|
||||
le_uint16_t skin;
|
||||
le_uint32_t team_points;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct ArmorOrShield {
|
||||
ItemBase base;
|
||||
le_uint16_t dfp;
|
||||
le_uint16_t evp;
|
||||
uint8_t block_particle;
|
||||
uint8_t block_effect;
|
||||
uint8_t item_class;
|
||||
uint8_t unknown_a1;
|
||||
uint8_t required_level;
|
||||
uint8_t efr;
|
||||
uint8_t eth;
|
||||
uint8_t eic;
|
||||
uint8_t edk;
|
||||
uint8_t elt;
|
||||
uint8_t dfp_range;
|
||||
uint8_t evp_range;
|
||||
uint8_t stat_boost;
|
||||
uint8_t tech_boost;
|
||||
le_uint16_t unknown_a2;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Unit {
|
||||
ItemBase base;
|
||||
le_uint16_t stat;
|
||||
le_uint16_t stat_amount;
|
||||
le_int16_t modifier_amount;
|
||||
parray<uint8_t, 2> unused;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Mag {
|
||||
ItemBase base;
|
||||
le_uint16_t feed_table;
|
||||
uint8_t photon_blast;
|
||||
uint8_t activation;
|
||||
uint8_t on_pb_full;
|
||||
uint8_t on_low_hp;
|
||||
uint8_t on_death;
|
||||
uint8_t on_boss;
|
||||
uint8_t on_pb_full_flag;
|
||||
uint8_t on_low_hp_flag;
|
||||
uint8_t on_death_flag;
|
||||
uint8_t on_boss_flag;
|
||||
uint8_t item_class;
|
||||
parray<uint8_t, 3> unused;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Tool {
|
||||
ItemBase base;
|
||||
le_uint16_t amount;
|
||||
le_uint16_t tech;
|
||||
le_int32_t cost;
|
||||
uint8_t item_flag;
|
||||
parray<uint8_t, 3> unused;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Weapon {
|
||||
ItemBase base;
|
||||
uint8_t item_class;
|
||||
uint8_t unknown_a0;
|
||||
le_uint16_t atp_min;
|
||||
le_uint16_t atp_max;
|
||||
le_uint16_t atp_required;
|
||||
le_uint16_t mst_required;
|
||||
le_uint16_t ata_required;
|
||||
le_uint16_t mst;
|
||||
uint8_t max_grind;
|
||||
uint8_t photon;
|
||||
uint8_t special;
|
||||
uint8_t ata;
|
||||
uint8_t stat_boost;
|
||||
uint8_t projectile;
|
||||
int8_t trail1_x;
|
||||
int8_t trail1_y;
|
||||
int8_t trail2_x;
|
||||
int8_t trail2_y;
|
||||
int8_t color;
|
||||
uint8_t unknown_a1;
|
||||
uint8_t unknown_a2;
|
||||
uint8_t unknown_a3;
|
||||
uint8_t unknown_a4;
|
||||
uint8_t unknown_a5;
|
||||
uint8_t tech_boost;
|
||||
uint8_t combo_type;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct MagFeedResult {
|
||||
int8_t def;
|
||||
int8_t pow;
|
||||
int8_t dex;
|
||||
int8_t mind;
|
||||
int8_t iq;
|
||||
int8_t synchro;
|
||||
parray<uint8_t, 2> unused;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct MagFeedResultsList {
|
||||
parray<MagFeedResult, 11> results;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct MagFeedResultsListOffsets {
|
||||
parray<le_uint32_t, 8> offsets; // Offsets of MagFeedResultsList structs
|
||||
} __attribute__((packed));
|
||||
|
||||
struct ItemStarValue {
|
||||
uint8_t num_stars;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct Special {
|
||||
le_uint16_t type;
|
||||
le_uint16_t amount;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct StatBoost {
|
||||
uint8_t stat1;
|
||||
uint8_t stat2;
|
||||
le_uint16_t amount1;
|
||||
le_uint16_t amount2;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct MaxTechniqueLevels {
|
||||
// Indexed as [tech_num][char_class]
|
||||
parray<parray<uint8_t, 12>, 19> max_level;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct ItemCombination {
|
||||
parray<uint8_t, 3> used_item;
|
||||
parray<uint8_t, 3> equipped_item;
|
||||
parray<uint8_t, 3> result_item;
|
||||
uint8_t mag_level;
|
||||
uint8_t grind;
|
||||
uint8_t level;
|
||||
uint8_t char_class;
|
||||
parray<uint8_t, 3> unused;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct TechniqueBoost {
|
||||
le_uint32_t tech1;
|
||||
le_float boost1;
|
||||
le_uint32_t tech2;
|
||||
le_float boost2;
|
||||
le_uint32_t tech3;
|
||||
le_float boost3;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct EventItem {
|
||||
parray<uint8_t, 3> item;
|
||||
uint8_t probability;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct UnsealableItem {
|
||||
parray<uint8_t, 3> item;
|
||||
uint8_t unused;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct NonWeaponSaleDivisors {
|
||||
le_float armor_divisor;
|
||||
le_float shield_divisor;
|
||||
le_float unit_divisor;
|
||||
le_float mag_divisor;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct TableOffsets {
|
||||
/* 00 / 14884 */ le_uint32_t weapon_table; // -> [{count, offset -> [Weapon]}](0xED)
|
||||
/* 04 / 1478C */ le_uint32_t armor_table; // -> [{count, offset -> [ArmorOrShield]}](2; armors and shields)
|
||||
/* 08 / 1479C */ le_uint32_t unit_table; // -> {count, offset -> [Unit]} (last if out of range)
|
||||
/* 0C / 147AC */ le_uint32_t tool_table; // -> [{count, offset -> [Tool]}](0x1A) (last if out of range)
|
||||
/* 10 / 147A4 */ le_uint32_t mag_table; // -> {count, offset -> [Mag]}
|
||||
/* 14 / 0F4B8 */ le_uint32_t attack_animation_table; // -> [uint8_t](0xED)
|
||||
/* 18 / 0DE7C */ le_uint32_t photon_color_table; // -> [0x24-byte structs](0x20)
|
||||
/* 1C / 0E194 */ le_uint32_t weapon_range_table; // -> ???
|
||||
/* 20 / 0F5A8 */ le_uint32_t weapon_sale_divisor_table; // -> [float](0xED)
|
||||
/* 24 / 0F83C */ le_uint32_t sale_divisor_table; // -> NonWeaponSaleDivisors
|
||||
/* 28 / 1502C */ le_uint32_t mag_feed_table; // -> MagFeedResultsTable
|
||||
/* 2C / 0FB0C */ le_uint32_t star_value_table; // -> [uint8_t] (indexed by .id from weapon, armor, etc.)
|
||||
/* 30 / 0FE3C */ le_uint32_t special_data_table; // -> [Special]
|
||||
/* 34 / 0FEE0 */ le_uint32_t weapon_effect_table; // -> [16-byte structs]
|
||||
/* 38 / 1275C */ le_uint32_t stat_boost_table; // -> [StatBoost]
|
||||
/* 3C / 11C80 */ le_uint32_t shield_effect_table; // -> [8-byte structs]
|
||||
/* 40 / 12894 */ le_uint32_t max_tech_level_table; // -> MaxTechniqueLevels
|
||||
/* 44 / 14FF4 */ le_uint32_t combination_table; // -> {count, offset -> [ItemCombination]}
|
||||
/* 48 / 12754 */ le_uint32_t unknown_a1;
|
||||
/* 4C / 14278 */ le_uint32_t tech_boost_table; // -> [TechniqueBoost] (always 0x2C of them? from counts struct?)
|
||||
/* 50 / 15014 */ le_uint32_t unwrap_table; // -> {count, offset -> [{count, offset -> [EventItem]}]}
|
||||
/* 54 / 1501C */ le_uint32_t unsealable_table; // -> {count, offset -> [UnsealableItem]}
|
||||
/* 58 / 15024 */ le_uint32_t ranged_special_table; // -> {count, offset -> [4-byte structs]}
|
||||
} __attribute__((packed));
|
||||
|
||||
ItemParameterTable(std::shared_ptr<const std::string> data);
|
||||
~ItemParameterTable() = default;
|
||||
|
||||
const Weapon& get_weapon(uint8_t data1_1, uint8_t data1_2) const;
|
||||
const ArmorOrShield& get_armor_or_shield(uint8_t data1_1, uint8_t data1_2) const;
|
||||
const Unit& get_unit(uint8_t data1_2) const;
|
||||
const Tool& get_tool(uint8_t data1_1, uint8_t data1_2) const;
|
||||
std::pair<uint8_t, uint8_t> find_tool_by_class(uint8_t tool_class) const;
|
||||
const Mag& get_mag(uint8_t data1_1) const;
|
||||
float get_sale_divisor(uint8_t data1_0, uint8_t data1_1) const;
|
||||
const MagFeedResult& get_mag_feed_result(uint8_t table_index, uint8_t which) const;
|
||||
uint8_t get_item_stars(uint16_t slot) const;
|
||||
uint8_t get_special_stars(uint8_t det) const;
|
||||
const Special& get_special(uint8_t special) const;
|
||||
uint8_t get_max_tech_level(uint8_t char_class, uint8_t tech_num) const;
|
||||
|
||||
const ItemBase& get_item_definition(const ItemData& item) const;
|
||||
uint8_t get_item_base_stars(const ItemData& item) const;
|
||||
uint8_t get_item_adjusted_stars(const ItemData& item) const;
|
||||
bool is_item_rare(const ItemData& item) const;
|
||||
bool is_unsealable_item(const ItemData& param_1) const;
|
||||
const ItemCombination& get_item_combination(const ItemData& used_item, const ItemData& equipped_item) const;
|
||||
const std::vector<ItemCombination>& get_all_combinations_for_used_item(const ItemData& used_item) const;
|
||||
const std::map<uint32_t, std::vector<ItemCombination>>& get_all_item_combinations() const;
|
||||
std::pair<const EventItem*, size_t> get_event_items(uint8_t event_number) const;
|
||||
|
||||
size_t price_for_item(const ItemData& item) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<const std::string> data;
|
||||
StringReader r;
|
||||
const TableOffsets* offsets;
|
||||
|
||||
// Key is used_item. We can't index on (used_item, equipped_item) because
|
||||
// equipped_item may contain wildcards, and the matching order matters.
|
||||
void populate_item_combination_index() const;
|
||||
mutable std::map<uint32_t, std::vector<ItemCombination>> item_combination_index;
|
||||
};
|
||||
|
||||
class MagEvolutionTable {
|
||||
public:
|
||||
struct TableOffsets {
|
||||
/* 00 / 0400 */ le_uint32_t unknown_a1; // -> [offset -> (0xC-byte struct)[0x53], offset -> (same as first offset)]
|
||||
/* 04 / 0408 */ le_uint32_t unknown_a2; // -> (2-byte struct, or single word)[0x53]
|
||||
/* 08 / 04AE */ le_uint32_t unknown_a3; // -> (0xA8 bytes; possibly (8-byte struct)[0x15])
|
||||
/* 0C / 0556 */ le_uint32_t unknown_a4; // -> (uint8_t)[0x53]
|
||||
/* 10 / 05AC */ le_uint32_t unknown_a5; // -> (float)[0x48]
|
||||
/* 14 / 06CC */ le_uint32_t evolution_number; // -> (uint8_t)[0x53]
|
||||
} __attribute__((packed));
|
||||
|
||||
struct EvolutionNumberTable {
|
||||
parray<uint8_t, 0x53> values;
|
||||
} __attribute__((packed));
|
||||
|
||||
MagEvolutionTable(std::shared_ptr<const std::string> data);
|
||||
~MagEvolutionTable() = default;
|
||||
|
||||
uint8_t get_evolution_number(uint8_t data1_1) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<const std::string> data;
|
||||
StringReader r;
|
||||
const TableOffsets* offsets;
|
||||
};
|
||||
+402
-526
@@ -4,584 +4,460 @@
|
||||
|
||||
#include <phosg/Random.hh>
|
||||
|
||||
#include "SendCommands.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* these items all need some kind of special handling that hasn't been implemented yet.
|
||||
|
||||
030B04 = TP Material (?)
|
||||
030C00 = Cell Of MAG 502
|
||||
030C01 = Cell Of MAG 213
|
||||
030C02 = Parts Of RoboChao
|
||||
030C03 = Heart Of Opa Opa
|
||||
030C04 = Heart Of Pian
|
||||
030C05 = Heart Of Chao
|
||||
|
||||
030D00 = Sorcerer's Right Arm
|
||||
030D01 = S-beat's Arms
|
||||
030D02 = P-arm's Arms
|
||||
030D03 = Delsabre's Right Arm
|
||||
030D04 = C-bringer's Right Arm
|
||||
030D05 = Delsabre's Left Arm
|
||||
030D06 = S-red's Arms
|
||||
030D07 = Dragon's Claw
|
||||
030D08 = Hildebear's Head
|
||||
030D09 = Hildeblue's Head
|
||||
030D0A = Parts of Baranz
|
||||
030D0B = Belra's Right Arms
|
||||
030D0C = GIGUE'S ARMS
|
||||
030D0D = S-BERILL'S ARMS
|
||||
030D0E = G-ASSASIN'S ARMS
|
||||
030D0F = BOOMA'S RIGHT ARMS
|
||||
030D10 = GOBOOMA'S RIGHT ARMS
|
||||
030D11 = GIGOBOOMA'S RIGHT ARMS
|
||||
030D12 = GAL WIND
|
||||
030D13 = RAPPY'S WING
|
||||
|
||||
030E00 = BERILL PHOTON
|
||||
030E01 = PARASITIC GENE FLOW
|
||||
030E02 = MAGICSTONE IRITISTA
|
||||
030E03 = BLUE BLACK STONE
|
||||
030E04 = SYNCESTA
|
||||
030E05 = MAGIC WATER
|
||||
030E06 = PARASITIC CELL TYPE D
|
||||
030E07 = MAGIC ROCK HEART KEY
|
||||
030E08 = MAGIC ROCK MOOLA
|
||||
030E09 = STAR AMPLIFIER
|
||||
030E0A = BOOK OF HITOGATA
|
||||
030E0B = HEART OF CHU CHU
|
||||
030E0C = PART OF EGG BLASTER
|
||||
030E0D = HEART OF ANGLE
|
||||
030E0E = HEART OF DEVIL
|
||||
030E0F = KIT OF HAMBERGER
|
||||
030E10 = PANTHER'S SPIRIT
|
||||
030E11 = KIT OF MARK3
|
||||
030E12 = KIT OF MASTER SYSTEM
|
||||
030E13 = KIT OF GENESIS
|
||||
030E14 = KIT OF SEGA SATURN
|
||||
030E15 = KIT OF DREAMCAST
|
||||
030E16 = AMP. RESTA
|
||||
030E17 = AMP. ANTI
|
||||
030E18 = AMP. SHIFTA
|
||||
030E19 = AMP. DEBAND
|
||||
030E1A = AMP.
|
||||
030E1B = AMP.
|
||||
030E1C = AMP.
|
||||
030E1D = AMP.
|
||||
030E1E = AMP.
|
||||
030E1F = AMP.
|
||||
030E20 = AMP.
|
||||
030E21 = AMP.
|
||||
030E22 = AMP.
|
||||
030E23 = AMP.
|
||||
030E24 = AMP.
|
||||
030E25 = AMP.
|
||||
030E26 = HEART OF KAPUKAPU
|
||||
030E27 = PROTON BOOSTER
|
||||
030F00 = ADD SLOT
|
||||
031000 = PHOTON DROP
|
||||
031001 = PHOTON SPHERE
|
||||
031002 = PHOTON CRYSTAL
|
||||
031100 = BOOK OF KATANA 1
|
||||
031101 = BOOK OF KATANA 2
|
||||
031102 = BOOK OF KATANA 3
|
||||
031200 = WEAPONS BRONZE BADGE
|
||||
031201 = WEAPONS SILVER BADGE
|
||||
031202 = WEAPONS GOLD BADGE
|
||||
031203 = WEAPONS CRYSTAL BADGE
|
||||
031204 = WEAPONS STEEL BADGE
|
||||
031205 = WEAPONS ALUMINUM BADGE
|
||||
031206 = WEAPONS LEATHER BADGE
|
||||
031207 = WEAPONS BONE BADGE
|
||||
031208 = LETTER OF APPRECATION
|
||||
031209 = AUTOGRAPH ALBUM
|
||||
03120A = VALENTINE'S CHOCOLATE
|
||||
03120B = NEWYEAR'S CARD
|
||||
03120C = CRISMAS CARD
|
||||
03120D = BIRTHDAY CARD
|
||||
03120E = PROOF OF SONIC TEAM
|
||||
03120F = SPECIAL EVENT TICKET
|
||||
031300 = PRESENT
|
||||
031400 = CHOCOLATE
|
||||
031401 = CANDY
|
||||
031402 = CAKE
|
||||
031403 = SILVER BADGE
|
||||
031404 = GOLD BADGE
|
||||
031405 = CRYSTAL BADGE
|
||||
031406 = IRON BADGE
|
||||
031407 = ALUMINUM BADGE
|
||||
031408 = LEATHER BADGE
|
||||
031409 = BONE BADGE
|
||||
03140A = BONQUET
|
||||
03140B = DECOCTION
|
||||
031500 = CRISMAS PRESENT
|
||||
031501 = EASTER EGG
|
||||
031502 = JACK-O'S-LANTERN
|
||||
031700 = HUNTERS REPORT
|
||||
031701 = HUNTERS REPORT RANK A
|
||||
031702 = HUNTERS REPORT RANK B
|
||||
031703 = HUNTERS REPORT RANK C
|
||||
031704 = HUNTERS REPORT RANK F
|
||||
031705 = HUNTERS REPORT
|
||||
031705 = HUNTERS REPORT
|
||||
031705 = HUNTERS REPORT
|
||||
031705 = HUNTERS REPORT
|
||||
031705 = HUNTERS REPORT
|
||||
031705 = HUNTERS REPORT
|
||||
031705 = HUNTERS REPORT
|
||||
031705 = HUNTERS REPORT
|
||||
031705 = HUNTERS REPORT
|
||||
031802 = Dragon Scale
|
||||
031803 = Heaven Striker Coat
|
||||
031807 = Rappys Beak
|
||||
031802 = Dragon Scale */
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void player_use_item(shared_ptr<Client> c, size_t item_index) {
|
||||
auto s = c->require_server_state();
|
||||
|
||||
// On PC (and presumably DC), the client sends a 6x29 after this to delete the
|
||||
// used item. On GC and later versions, this does not happen, so we should
|
||||
// delete the item here.
|
||||
bool should_delete_item = (c->version() != GameVersion::DC) && (c->version() != GameVersion::PC);
|
||||
|
||||
auto player = c->game_data.player();
|
||||
auto& item = player->inventory.items[item_index];
|
||||
uint32_t item_identifier = item.data.primary_identifier();
|
||||
|
||||
ssize_t equipped_weapon = -1;
|
||||
// ssize_t equipped_armor = -1;
|
||||
// ssize_t equipped_shield = -1;
|
||||
// ssize_t equipped_mag = -1;
|
||||
for (size_t y = 0; y < c->game_data.player()->inventory.num_items; y++) {
|
||||
if (c->game_data.player()->inventory.items[y].equip_flags & 0x0008) {
|
||||
if (c->game_data.player()->inventory.items[y].data.data1[0] == 0) {
|
||||
equipped_weapon = y;
|
||||
}
|
||||
// else if ((c->game_data.player()->inventory.items[y].data.data1[0] == 1) &&
|
||||
// (c->game_data.player()->inventory.items[y].data.data1[1] == 1)) {
|
||||
// equipped_armor = y;
|
||||
// } else if ((c->game_data.player()->inventory.items[y].data.data1[0] == 1) &&
|
||||
// (c->game_data.player()->inventory.items[y].data.data1[1] == 2)) {
|
||||
// equipped_shield = y;
|
||||
// } else if (c->game_data.player()->inventory.items[y].data.data1[0] == 2) {
|
||||
// equipped_mag = y;
|
||||
// }
|
||||
if (item.data.is_common_consumable()) { // Monomate, etc.
|
||||
// Nothing to do (it should be deleted)
|
||||
|
||||
} else if (item_identifier == 0x030200) { // Technique disk
|
||||
uint8_t max_level = s->item_parameter_table->get_max_tech_level(player->disp.visual.char_class, item.data.data1[4]);
|
||||
if (item.data.data1[2] > max_level) {
|
||||
throw runtime_error("technique level too high");
|
||||
}
|
||||
}
|
||||
player->set_technique_level(item.data.data1[4], item.data.data1[2]);
|
||||
|
||||
bool should_delete_item = true;
|
||||
|
||||
auto& item = c->game_data.player()->inventory.items[item_index];
|
||||
if (item.data.data1w[0] == 0x0203) { // technique disk
|
||||
c->game_data.player()->disp.technique_levels.data()[item.data.data1[4]] = item.data.data1[2];
|
||||
|
||||
} else if (item.data.data1w[0] == 0x0A03) { // grinder
|
||||
if (equipped_weapon < 0) {
|
||||
throw invalid_argument("grinder used with no weapon equipped");
|
||||
}
|
||||
} else if ((item_identifier & 0xFFFF00) == 0x030A00) { // Grinder
|
||||
if (item.data.data1[2] > 2) {
|
||||
throw invalid_argument("incorrect grinder value");
|
||||
throw runtime_error("incorrect grinder value");
|
||||
}
|
||||
c->game_data.player()->inventory.items[equipped_weapon].data.data1[3] += (item.data.data1[2] + 1);
|
||||
// TODO: we should check for max grind here
|
||||
auto& weapon = player->inventory.items[player->inventory.find_equipped_weapon()];
|
||||
auto weapon_def = s->item_parameter_table->get_weapon(weapon.data.data1[1], weapon.data.data1[2]);
|
||||
if (weapon.data.data1[3] >= weapon_def.max_grind) {
|
||||
throw runtime_error("weapon already at maximum grind");
|
||||
}
|
||||
weapon.data.data1[3] += (item.data.data1[2] + 1);
|
||||
|
||||
} else if (item.data.data1w[0] == 0x0B03) { // material
|
||||
} else if ((item_identifier & 0xFFFF00) == 0x030B00) { // Material
|
||||
auto p = c->game_data.player();
|
||||
using Type = SavedPlayerDataBB::MaterialType;
|
||||
switch (item.data.data1[2]) {
|
||||
case 0: // Power Material
|
||||
c->game_data.player()->disp.stats.atp += 2;
|
||||
p->set_material_usage(Type::POWER, p->get_material_usage(Type::POWER) + 1);
|
||||
p->disp.stats.char_stats.atp += 2;
|
||||
break;
|
||||
case 1: // Mind Material
|
||||
c->game_data.player()->disp.stats.mst += 2;
|
||||
p->set_material_usage(Type::MIND, p->get_material_usage(Type::MIND) + 1);
|
||||
p->disp.stats.char_stats.mst += 2;
|
||||
break;
|
||||
case 2: // Evade Material
|
||||
c->game_data.player()->disp.stats.evp += 2;
|
||||
p->set_material_usage(Type::EVADE, p->get_material_usage(Type::EVADE) + 1);
|
||||
p->disp.stats.char_stats.evp += 2;
|
||||
break;
|
||||
case 3: // HP Material
|
||||
c->game_data.player()->inventory.hp_materials_used += 2;
|
||||
p->set_material_usage(Type::HP, p->get_material_usage(Type::HP) + 1);
|
||||
break;
|
||||
case 4: // TP Material
|
||||
c->game_data.player()->inventory.tp_materials_used += 2;
|
||||
p->set_material_usage(Type::TP, p->get_material_usage(Type::TP) + 1);
|
||||
break;
|
||||
case 5: // Def Material
|
||||
c->game_data.player()->disp.stats.dfp += 2;
|
||||
p->set_material_usage(Type::DEF, p->get_material_usage(Type::DEF) + 1);
|
||||
p->disp.stats.char_stats.dfp += 2;
|
||||
break;
|
||||
case 6: // Luck Material
|
||||
c->game_data.player()->disp.stats.lck += 2;
|
||||
p->set_material_usage(Type::LUCK, p->get_material_usage(Type::LUCK) + 1);
|
||||
p->disp.stats.char_stats.lck += 2;
|
||||
break;
|
||||
default:
|
||||
throw invalid_argument("unknown material used");
|
||||
throw runtime_error("unknown material used");
|
||||
}
|
||||
|
||||
} else if ((item_identifier & 0xFFFF00) == 0x030F00) { // AddSlot
|
||||
auto& armor = player->inventory.items[player->inventory.find_equipped_armor()];
|
||||
if (armor.data.data1[5] >= 4) {
|
||||
throw runtime_error("armor already at maximum slot count");
|
||||
}
|
||||
armor.data.data1[5]++;
|
||||
|
||||
} else if (item.data.is_wrapped()) {
|
||||
// Unwrap present
|
||||
item.data.unwrap();
|
||||
should_delete_item = false;
|
||||
|
||||
} else if (item_identifier == 0x003300) {
|
||||
// Unseal Sealed J-Sword => Tsumikiri J-Sword
|
||||
item.data.data1[1] = 0x32;
|
||||
should_delete_item = false;
|
||||
|
||||
} else if (item_identifier == 0x00AB00) {
|
||||
// Unseal Lame d'Argent => Excalibur
|
||||
item.data.data1[1] = 0xAC;
|
||||
should_delete_item = false;
|
||||
|
||||
} else if (item_identifier == 0x01034D) {
|
||||
// Unseal Limiter => Adept
|
||||
item.data.data1[2] = 0x4E;
|
||||
should_delete_item = false;
|
||||
|
||||
} else if (item_identifier == 0x01034F) {
|
||||
// Unseal Swordsman Lore => Proof of Sword-Saint
|
||||
item.data.data1[2] = 0x50;
|
||||
should_delete_item = false;
|
||||
|
||||
} else if (item_identifier == 0x030C00) {
|
||||
// Cell of MAG 502
|
||||
auto& mag = player->inventory.items[player->inventory.find_equipped_mag()];
|
||||
mag.data.data1[1] = (player->disp.visual.section_id & 1) ? 0x1D : 0x21;
|
||||
|
||||
} else if (item_identifier == 0x030C01) {
|
||||
// Cell of MAG 213
|
||||
auto& mag = player->inventory.items[player->inventory.find_equipped_mag()];
|
||||
mag.data.data1[1] = (player->disp.visual.section_id & 1) ? 0x27 : 0x22;
|
||||
|
||||
} else if (item_identifier == 0x030C02) {
|
||||
// Parts of RoboChao
|
||||
auto& mag = player->inventory.items[player->inventory.find_equipped_mag()];
|
||||
mag.data.data1[1] = 0x28;
|
||||
|
||||
} else if (item_identifier == 0x030C03) {
|
||||
// Heart of Opa Opa
|
||||
auto& mag = player->inventory.items[player->inventory.find_equipped_mag()];
|
||||
mag.data.data1[1] = 0x29;
|
||||
|
||||
} else if (item_identifier == 0x030C04) {
|
||||
// Heart of Pian
|
||||
auto& mag = player->inventory.items[player->inventory.find_equipped_mag()];
|
||||
mag.data.data1[1] = 0x2A;
|
||||
|
||||
} else if (item_identifier == 0x030C05) {
|
||||
// Heart of Chao
|
||||
auto& mag = player->inventory.items[player->inventory.find_equipped_mag()];
|
||||
mag.data.data1[1] = 0x2B;
|
||||
|
||||
} else if ((item_identifier & 0xFFFF00) == 0x031500) {
|
||||
// Christmas Present, etc. - use unwrap_table + probabilities therein
|
||||
auto table = s->item_parameter_table->get_event_items(item.data.data1[2]);
|
||||
size_t sum = 0;
|
||||
for (size_t z = 0; z < table.second; z++) {
|
||||
sum += table.first[z].probability;
|
||||
}
|
||||
if (sum == 0) {
|
||||
throw runtime_error("no unwrap results available for event");
|
||||
}
|
||||
size_t det = random_object<size_t>() % sum;
|
||||
for (size_t z = 0; z < table.second; z++) {
|
||||
const auto& entry = table.first[z];
|
||||
if (det > entry.probability) {
|
||||
det -= entry.probability;
|
||||
} else {
|
||||
item.data.data2d = 0;
|
||||
item.data.data1[0] = entry.item[0];
|
||||
item.data.data1[1] = entry.item[1];
|
||||
item.data.data1[2] = entry.item[2];
|
||||
item.data.data1.clear_after(3);
|
||||
should_delete_item = false;
|
||||
|
||||
auto l = c->lobby.lock();
|
||||
if (l) {
|
||||
send_create_inventory_item(c, item.data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// default item action is to unwrap the item if it's a present
|
||||
if ((item.data.data1[0] == 2) && (item.data.data2[2] & 0x40)) {
|
||||
item.data.data2[2] &= 0xBF;
|
||||
should_delete_item = false;
|
||||
} else if ((item.data.data1[0] != 2) && (item.data.data1[4] & 0x40)) {
|
||||
item.data.data1[4] &= 0xBF;
|
||||
should_delete_item = false;
|
||||
// Use item combinations table from ItemPMT
|
||||
bool combo_applied = false;
|
||||
for (size_t z = 0; z < player->inventory.num_items; z++) {
|
||||
auto& inv_item = player->inventory.items[z];
|
||||
if (!(inv_item.flags & 0x00000008)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
const auto& combo = s->item_parameter_table->get_item_combination(
|
||||
item.data, inv_item.data);
|
||||
if (combo.char_class != 0xFF && combo.char_class != player->disp.visual.char_class) {
|
||||
throw runtime_error("item combination requires specific char_class");
|
||||
}
|
||||
if (combo.mag_level != 0xFF) {
|
||||
if (inv_item.data.data1[0] != 2) {
|
||||
throw runtime_error("item combination applies with mag level requirement, but equipped item is not a mag");
|
||||
}
|
||||
if (inv_item.data.compute_mag_level() < combo.mag_level) {
|
||||
throw runtime_error("item combination applies with mag level requirement, but equipped mag level is too low");
|
||||
}
|
||||
}
|
||||
if (combo.grind != 0xFF) {
|
||||
if (inv_item.data.data1[0] != 0) {
|
||||
throw runtime_error("item combination applies with grind requirement, but equipped item is not a weapon");
|
||||
}
|
||||
if (inv_item.data.data1[3] < combo.grind) {
|
||||
throw runtime_error("item combination applies with grind requirement, but equipped weapon grind is too low");
|
||||
}
|
||||
}
|
||||
if (combo.level != 0xFF && player->disp.stats.level + 1 < combo.level) {
|
||||
throw runtime_error("item combination applies with level requirement, but player level is too low");
|
||||
}
|
||||
// If we get here, then the combo applies
|
||||
if (combo_applied) {
|
||||
throw runtime_error("multiple combinations apply");
|
||||
}
|
||||
combo_applied = true;
|
||||
|
||||
inv_item.data.data1[0] = combo.result_item[0];
|
||||
inv_item.data.data1[1] = combo.result_item[1];
|
||||
inv_item.data.data1[2] = combo.result_item[2];
|
||||
inv_item.data.data1[3] = 0; // Grind
|
||||
inv_item.data.data1[4] = 0; // Flags + special
|
||||
} catch (const out_of_range&) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!combo_applied) {
|
||||
throw runtime_error("no combinations apply");
|
||||
}
|
||||
}
|
||||
|
||||
if (should_delete_item) {
|
||||
c->game_data.player()->remove_item(item.data.id, 1);
|
||||
// Allow overdrafting meseta if the client is not BB, since the server isn't
|
||||
// informed when meseta is added or removed from the bank.
|
||||
player->remove_item(item.data.id, 1, c->version() != GameVersion::BB);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void player_feed_mag(std::shared_ptr<Client> c, size_t mag_item_index, size_t fed_item_index) {
|
||||
static const unordered_map<uint32_t, size_t> result_index_for_fed_item({
|
||||
{0x030000, 0}, // Monomate
|
||||
{0x030001, 1}, // Dimate
|
||||
{0x030002, 2}, // Trimate
|
||||
{0x030100, 3}, // Monofluid
|
||||
{0x030101, 4}, // Difluid
|
||||
{0x030102, 5}, // Trifluid
|
||||
{0x030600, 6}, // Antidote
|
||||
{0x030601, 7}, // Antiparalysis
|
||||
{0x030300, 8}, // Sol Atomizer
|
||||
{0x030400, 9}, // Moon Atomizer
|
||||
{0x030500, 10}, // Star Atomizer
|
||||
});
|
||||
|
||||
// reads the non-rare item preferences from the config file.
|
||||
CommonItemCreator::CommonItemCreator(
|
||||
const vector<uint32_t>& enemy_item_categories,
|
||||
const vector<uint32_t>& box_item_categories,
|
||||
const vector<vector<uint8_t>>& unit_types) :
|
||||
enemy_item_categories(enemy_item_categories),
|
||||
box_item_categories(box_item_categories),
|
||||
unit_types(unit_types) {
|
||||
auto s = c->require_server_state();
|
||||
auto player = c->game_data.player();
|
||||
auto& fed_item = player->inventory.items[fed_item_index];
|
||||
auto& mag_item = player->inventory.items[mag_item_index];
|
||||
|
||||
// sanity check the values
|
||||
if (this->enemy_item_categories.size() != 8) {
|
||||
throw invalid_argument("enemy item categories is incorrect length");
|
||||
}
|
||||
if (this->box_item_categories.size() != 8) {
|
||||
throw invalid_argument("box item categories is incorrect length");
|
||||
}
|
||||
if (this->unit_types.size() != 4) {
|
||||
throw invalid_argument("unit types is incorrect length");
|
||||
}
|
||||
size_t result_index = result_index_for_fed_item.at(fed_item.data.primary_identifier());
|
||||
const auto& mag_def = s->item_parameter_table->get_mag(mag_item.data.data1[1]);
|
||||
const auto& feed_result = s->item_parameter_table->get_mag_feed_result(mag_def.feed_table, result_index);
|
||||
|
||||
{
|
||||
uint64_t sum = 0;
|
||||
for (uint32_t v : this->enemy_item_categories) {
|
||||
sum += v;
|
||||
}
|
||||
if (sum > 0xFFFFFFFF) {
|
||||
throw invalid_argument("enemy item category sum is too large");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
uint64_t sum = 0;
|
||||
for (uint32_t v : this->box_item_categories) {
|
||||
sum += v;
|
||||
}
|
||||
if (sum > 0xFFFFFFFF) {
|
||||
throw invalid_argument("box item category sum is too large");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t CommonItemCreator::decide_item_type(bool is_box) const {
|
||||
uint32_t determinant = random_object<uint32_t>();
|
||||
|
||||
const auto* v = is_box ? &this->box_item_categories : &this->enemy_item_categories;
|
||||
for (size_t x = 0; x < v->size(); x++) {
|
||||
uint32_t probability = v->at(x);
|
||||
if (probability > determinant) {
|
||||
return x;
|
||||
}
|
||||
determinant -= probability;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
ItemData CommonItemCreator::create_drop_item(bool is_box, uint8_t episode,
|
||||
uint8_t difficulty, uint8_t area, uint8_t) const {
|
||||
// TODO: use the section ID (last argument) to vary drop frequencies appropriately
|
||||
// change the area if it's invalid (data for the bosses are actually in other areas)
|
||||
if (area > 10) {
|
||||
if (episode == 1) {
|
||||
if (area == 11) {
|
||||
area = 3; // dragon
|
||||
} else if (area == 12) {
|
||||
area = 6; // de rol le
|
||||
} else if (area == 13) {
|
||||
area = 8; // vol opt
|
||||
} else if (area == 14) {
|
||||
area = 10; // dark falz
|
||||
} else {
|
||||
area = 1; // unknown area -> forest 1
|
||||
auto update_stat = +[](ItemData& data, size_t which, int8_t delta) -> void {
|
||||
uint16_t existing_stat = data.data1w[which] % 100;
|
||||
if ((delta > 0) || ((delta < 0) && (-delta < existing_stat))) {
|
||||
uint16_t level = data.compute_mag_level();
|
||||
if (level > 200) {
|
||||
throw runtime_error("mag level is too high");
|
||||
}
|
||||
} else if (episode == 2) {
|
||||
if (area == 12) {
|
||||
area = 9; // gal gryphon
|
||||
} else if (area == 13) {
|
||||
area = 10; // olga flow
|
||||
} else if (area == 14) {
|
||||
area = 3; // barba ray
|
||||
} else if (area == 15) {
|
||||
area = 6; // gol dragon
|
||||
} else {
|
||||
area = 10; // tower
|
||||
if ((level == 200) && ((99 - existing_stat) < delta)) {
|
||||
delta = 99 - existing_stat;
|
||||
}
|
||||
} else if (episode == 3) {
|
||||
area = 1;
|
||||
data.data1w[which] += delta;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ItemData item;
|
||||
update_stat(mag_item.data, 2, feed_result.def);
|
||||
update_stat(mag_item.data, 3, feed_result.pow);
|
||||
update_stat(mag_item.data, 4, feed_result.dex);
|
||||
update_stat(mag_item.data, 5, feed_result.mind);
|
||||
mag_item.data.data2[0] = clamp<ssize_t>(static_cast<ssize_t>(mag_item.data.data2[0]) + feed_result.synchro, 0, 120);
|
||||
mag_item.data.data2[1] = clamp<ssize_t>(static_cast<ssize_t>(mag_item.data.data2[1]) + feed_result.iq, 0, 200);
|
||||
|
||||
// picks a random non-rare item type, then gives it appropriate random stats
|
||||
// modify some of the constants in this section to change the system's
|
||||
// parameters
|
||||
int32_t type = this->decide_item_type(is_box);
|
||||
switch (type) {
|
||||
case 0x00: // material
|
||||
item.data1[0] = 0x03;
|
||||
item.data1[1] = 0x0B;
|
||||
item.data1[2] = random_int(0, 6);
|
||||
break;
|
||||
uint8_t mag_level = mag_item.data.compute_mag_level();
|
||||
mag_item.data.data1[2] = mag_level;
|
||||
uint8_t evolution_number = s->mag_evolution_table->get_evolution_number(mag_item.data.data1[1]);
|
||||
uint8_t mag_number = mag_item.data.data1[1];
|
||||
|
||||
case 0x01: // equipment
|
||||
switch (random_int(0, 3)) {
|
||||
case 0x00: // weapon
|
||||
item.data1[1] = random_int(1, 12); // random normal class
|
||||
item.data1[2] = difficulty + random_int(0, 2); // special type
|
||||
if ((item.data1[1] > 0x09) && (item.data1[2] > 0x04)) {
|
||||
item.data1[2] = 0x04; // no special classes above 4
|
||||
// Note: Sega really did just hardcode all these rules into the client. There
|
||||
// is no data file describing these evolutions, unfortunately.
|
||||
|
||||
if (mag_level < 10) {
|
||||
// Nothing to do
|
||||
|
||||
} else if (mag_level < 35) { // Level 10 evolution
|
||||
if (evolution_number < 1) {
|
||||
switch (player->disp.visual.char_class) {
|
||||
case 0: // HUmar
|
||||
case 1: // HUnewearl
|
||||
case 2: // HUcast
|
||||
case 9: // HUcaseal
|
||||
mag_item.data.data1[1] = 0x01; // Varuna
|
||||
break;
|
||||
case 3: // RAmar
|
||||
case 11: // RAmarl
|
||||
case 4: // RAcast
|
||||
case 5: // RAcaseal
|
||||
mag_item.data.data1[1] = 0x0D; // Kalki
|
||||
break;
|
||||
case 10: // FOmar
|
||||
case 6: // FOmarl
|
||||
case 7: // FOnewm
|
||||
case 8: // FOnewearl
|
||||
mag_item.data.data1[1] = 0x19; // Vritra
|
||||
break;
|
||||
default:
|
||||
throw runtime_error("invalid character class");
|
||||
}
|
||||
}
|
||||
|
||||
} else if (mag_level < 50) { // Level 35 evolution
|
||||
if (evolution_number < 2) {
|
||||
uint16_t flags = mag_item.data.compute_mag_strength_flags();
|
||||
if (mag_number == 0x0D) {
|
||||
if ((flags & 0x110) == 0) {
|
||||
mag_item.data.data1[1] = 0x02;
|
||||
} else if (flags & 8) {
|
||||
mag_item.data.data1[1] = 0x03;
|
||||
} else if (flags & 0x20) {
|
||||
mag_item.data.data1[1] = 0x0B;
|
||||
}
|
||||
} else if (mag_number == 1) {
|
||||
if (flags & 0x108) {
|
||||
mag_item.data.data1[1] = 0x0E;
|
||||
} else if (flags & 0x10) {
|
||||
mag_item.data.data1[1] = 0x0F;
|
||||
} else if (flags & 0x20) {
|
||||
mag_item.data.data1[1] = 0x04;
|
||||
}
|
||||
} else if (mag_number == 0x19) {
|
||||
if (flags & 0x120) {
|
||||
mag_item.data.data1[1] = 0x1A;
|
||||
} else if (flags & 8) {
|
||||
mag_item.data.data1[1] = 0x1B;
|
||||
} else if (flags & 0x10) {
|
||||
mag_item.data.data1[1] = 0x14;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if ((mag_level % 5) == 0) { // Level 50 (and beyond) evolutions
|
||||
if (evolution_number < 4) {
|
||||
|
||||
if (mag_level >= 100) {
|
||||
uint8_t section_id_group = player->disp.visual.section_id % 3;
|
||||
uint16_t def = mag_item.data.data1w[2] / 100;
|
||||
uint16_t pow = mag_item.data.data1w[3] / 100;
|
||||
uint16_t dex = mag_item.data.data1w[4] / 100;
|
||||
uint16_t mind = mag_item.data.data1w[5] / 100;
|
||||
bool is_male = char_class_is_male(player->disp.visual.char_class);
|
||||
size_t table_index = (is_male ? 0 : 1) + section_id_group * 2;
|
||||
|
||||
bool is_hunter = char_class_is_hunter(player->disp.visual.char_class);
|
||||
bool is_ranger = char_class_is_ranger(player->disp.visual.char_class);
|
||||
bool is_force = char_class_is_force(player->disp.visual.char_class);
|
||||
if (is_force) {
|
||||
table_index += 12;
|
||||
} else if (is_ranger) {
|
||||
table_index += 6;
|
||||
} else if (!is_hunter) {
|
||||
throw logic_error("char class is not any of the top-level classes");
|
||||
}
|
||||
|
||||
// Note: The original code checks the class (hunter/ranger/force) again
|
||||
// here, and goes into 3 branches that each do these same checks.
|
||||
// However, the result of all 3 branches is exactly the same!
|
||||
if (((section_id_group == 0) && (pow + mind == def + dex)) ||
|
||||
((section_id_group == 1) && (pow + dex == mind + def)) ||
|
||||
((section_id_group == 2) && (pow + def == mind + dex))) {
|
||||
// clang-format off
|
||||
static const uint8_t result_table[] = {
|
||||
// M0 F0 M1 F1 M2 F2
|
||||
0x39, 0x3B, 0x3A, 0x3B, 0x3A, 0x3B, // Hunter
|
||||
0x3D, 0x3C, 0x3D, 0x3C, 0x3D, 0x3E, // Ranger
|
||||
0x41, 0x3F, 0x41, 0x40, 0x41, 0x40, // Force
|
||||
};
|
||||
// clang-format on
|
||||
mag_item.data.data1[1] = result_table[table_index];
|
||||
}
|
||||
}
|
||||
|
||||
// If a special evolution did not occur, do a normal level 50 evolution
|
||||
if (mag_number == mag_item.data.data1[1]) {
|
||||
uint16_t flags = mag_item.data.compute_mag_strength_flags();
|
||||
uint16_t def = mag_item.data.data1w[2] / 100;
|
||||
uint16_t pow = mag_item.data.data1w[3] / 100;
|
||||
uint16_t dex = mag_item.data.data1w[4] / 100;
|
||||
uint16_t mind = mag_item.data.data1w[5] / 100;
|
||||
|
||||
bool is_hunter = char_class_is_hunter(player->disp.visual.char_class);
|
||||
bool is_ranger = char_class_is_ranger(player->disp.visual.char_class);
|
||||
bool is_force = char_class_is_force(player->disp.visual.char_class);
|
||||
if (is_hunter + is_ranger + is_force != 1) {
|
||||
throw logic_error("char class is not exactly one of the top-level classes");
|
||||
}
|
||||
|
||||
if (is_hunter) {
|
||||
if (flags & 0x108) {
|
||||
mag_item.data.data1[1] = (player->disp.visual.section_id & 1)
|
||||
? ((dex < mind) ? 0x08 : 0x06)
|
||||
: ((dex < mind) ? 0x0C : 0x05);
|
||||
} else if (flags & 0x010) {
|
||||
mag_item.data.data1[1] = (player->disp.visual.section_id & 1)
|
||||
? ((mind < pow) ? 0x12 : 0x10)
|
||||
: ((mind < pow) ? 0x17 : 0x13);
|
||||
} else if (flags & 0x020) {
|
||||
mag_item.data.data1[1] = (player->disp.visual.section_id & 1)
|
||||
? ((pow < dex) ? 0x16 : 0x24)
|
||||
: ((pow < dex) ? 0x07 : 0x1E);
|
||||
}
|
||||
item.data1[4] = 0x80; // untekked
|
||||
if (item.data1[2] < 0x04) {
|
||||
item.data1[4] |= random_int(0, 40); // give a special
|
||||
} else if (is_ranger) {
|
||||
if (flags & 0x110) {
|
||||
mag_item.data.data1[1] = (player->disp.visual.section_id & 1)
|
||||
? ((mind < pow) ? 0x0A : 0x05)
|
||||
: ((mind < pow) ? 0x0C : 0x06);
|
||||
} else if (flags & 0x008) {
|
||||
mag_item.data.data1[1] = (player->disp.visual.section_id & 1)
|
||||
? ((dex < mind) ? 0x0A : 0x26)
|
||||
: ((dex < mind) ? 0x0C : 0x06);
|
||||
} else if (flags & 0x020) {
|
||||
mag_item.data.data1[1] = (player->disp.visual.section_id & 1)
|
||||
? ((pow < dex) ? 0x18 : 0x1E)
|
||||
: ((pow < dex) ? 0x08 : 0x05);
|
||||
}
|
||||
for (size_t x = 0, y = 0; (x < 5) && (y < 3); x++) { // percentages
|
||||
if (random_int(0, 10) == 1) { // 1/11 chance of getting each type of percentage
|
||||
item.data1[6 + (y * 2)] = x + 1;
|
||||
item.data1[7 + (y * 2)] = random_int(0, 10) * 5;
|
||||
y++;
|
||||
} else if (is_force) {
|
||||
if (flags & 0x120) {
|
||||
if (def < 45) {
|
||||
mag_item.data.data1[1] = (player->disp.visual.section_id & 1)
|
||||
? ((pow < dex) ? 0x17 : 0x09)
|
||||
: ((pow < dex) ? 0x1E : 0x1C);
|
||||
} else {
|
||||
mag_item.data.data1[1] = 0x24;
|
||||
}
|
||||
} else if (flags & 0x008) {
|
||||
if (def < 45) {
|
||||
mag_item.data.data1[1] = (player->disp.visual.section_id & 1)
|
||||
? ((dex < mind) ? 0x1C : 0x20)
|
||||
: ((dex < mind) ? 0x1F : 0x25);
|
||||
} else {
|
||||
mag_item.data.data1[1] = 0x23;
|
||||
}
|
||||
} else if (flags & 0x010) {
|
||||
if (def < 45) {
|
||||
mag_item.data.data1[1] = (player->disp.visual.section_id & 1)
|
||||
? ((mind < pow) ? 0x12 : 0x0C)
|
||||
: ((mind < pow) ? 0x15 : 0x11);
|
||||
} else {
|
||||
mag_item.data.data1[1] = 0x24;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01: // armor
|
||||
item.data1[0] = 0x01;
|
||||
item.data1[1] = 0x01;
|
||||
item.data1[2] = (6 * difficulty) + random_int(0, ((area / 2) + 2) - 1); // standard type based on difficulty and area
|
||||
if (item.data1[2] > 0x17) {
|
||||
item.data1[2] = 0x17; // no standard types above 0x17
|
||||
}
|
||||
if (random_int(0, 10) == 0) { // +/-
|
||||
item.data1[4] = random_int(0, 5);
|
||||
item.data1[6] = random_int(0, 2);
|
||||
}
|
||||
item.data1[5] = random_int(0, 4); // slots
|
||||
break;
|
||||
|
||||
case 0x02: // shield
|
||||
item.data1[0] = 0x01;
|
||||
item.data1[1] = 0x02;
|
||||
item.data1[2] = (5 * difficulty) + random_int(0, ((area / 2) + 2) - 1); // standard type based on difficulty and area
|
||||
if (item.data1[2] > 0x14) {
|
||||
item.data1[2] = 0x14; // no standard types above 0x14
|
||||
}
|
||||
if (random_int(0, 10) == 0) { // +/-
|
||||
item.data1[4] = random_int(0, 5);
|
||||
item.data1[6] = random_int(0, 5);
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x03: { // unit
|
||||
const auto& type_table = this->unit_types.at(difficulty);
|
||||
uint8_t type = type_table[random_int(0, type_table.size() - 1)];
|
||||
if (type == 0xFF) {
|
||||
throw out_of_range("no item dropped"); // 0xFF -> no item drops
|
||||
}
|
||||
item.data1[0] = 0x01;
|
||||
item.data1[1] = 0x03;
|
||||
item.data1[2] = type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02: // technique
|
||||
item.data1[0] = 0x03;
|
||||
item.data1[1] = 0x02;
|
||||
item.data1[4] = random_int(0, 18); // tech type
|
||||
if ((item.data1[4] != 14) && (item.data1[4] != 17)) { // if not ryuker or reverser, give it a level
|
||||
if (item.data1[4] == 16) { // if not anti, give it a level between 1 and 30
|
||||
if (area > 3) {
|
||||
item.data1[2] = difficulty + random_int(0, ((area - 1) / 2) - 1);
|
||||
} else {
|
||||
item.data1[2] = difficulty;
|
||||
}
|
||||
if (item.data1[2] > 6) {
|
||||
item.data1[2] = 6;
|
||||
}
|
||||
} else {
|
||||
item.data1[2] = (5 * difficulty) + random_int(0, ((area * 3) / 2) - 1); // else between 1 and 7
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x03: // scape doll
|
||||
item.data1[0] = 0x03;
|
||||
item.data1[1] = 0x09;
|
||||
item.data1[2] = 0x00;
|
||||
break;
|
||||
|
||||
case 0x04: // grinder
|
||||
item.data1[0] = 0x03;
|
||||
item.data1[1] = 0x0A;
|
||||
item.data1[2] = random_int(0, 2); // mono, di, tri
|
||||
break;
|
||||
|
||||
case 0x05: // consumable
|
||||
item.data1[0] = 0x03;
|
||||
item.data1[5] = 0x01;
|
||||
switch (random_int(0, 2)) {
|
||||
case 0: // antidote / antiparalysis
|
||||
item.data1[1] = 6;
|
||||
item.data1[2] = random_int(0, 1);
|
||||
break;
|
||||
|
||||
case 1: // telepipe / trap vision
|
||||
item.data1[1] = 7 + random_int(0, 1);
|
||||
break;
|
||||
|
||||
case 2: // sol / moon / star atomizer
|
||||
item.data1[1] = 3 + random_int(0, 2);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x06: // consumable
|
||||
item.data1[0] = 0x03;
|
||||
item.data1[5] = 0x01;
|
||||
item.data1[1] = random_int(0, 1); // mate or fluid
|
||||
if (difficulty == 0) {
|
||||
item.data1[2] = random_int(0, 1); // only mono and di on normal
|
||||
} else if (difficulty == 3) {
|
||||
item.data1[2] = random_int(1, 2); // only di and tri on ultimate
|
||||
} else {
|
||||
item.data1[2] = random_int(0, 2); // else, any of the three
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x07: // meseta
|
||||
item.data1[0] = 0x04;
|
||||
item.data2d = (90 * difficulty) + (random_int(1, 20) * (area * 2)); // meseta amount
|
||||
break;
|
||||
|
||||
default:
|
||||
throw out_of_range("no item created");
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
ItemData CommonItemCreator::create_shop_item(uint8_t difficulty,
|
||||
uint8_t item_type) const {
|
||||
static const uint8_t max_percentages[4] = {20, 35, 45, 50};
|
||||
static const uint8_t max_quantity[4] = { 1, 1, 2, 2};
|
||||
static const uint8_t max_tech_level[4] = { 8, 15, 23, 30};
|
||||
static const uint8_t max_anti_level[4] = { 2, 4, 6, 7};
|
||||
|
||||
ItemData item;
|
||||
|
||||
item.data1[0] = item_type;
|
||||
while (item.data1[0] == 2) {
|
||||
item.data1[0] = rand() % 3;
|
||||
}
|
||||
switch (item.data1[0]) {
|
||||
case 0: { // weapon
|
||||
item.data1[1] = (rand() % 12) + 1;
|
||||
if (item.data1[1] > 9) {
|
||||
item.data1[2] = difficulty;
|
||||
} else {
|
||||
item.data1[2] = (rand() & 1) + difficulty;
|
||||
}
|
||||
|
||||
item.data1[3] = rand() % 11;
|
||||
item.data1[4] = rand() % 11;
|
||||
|
||||
size_t num_percentages = 0;
|
||||
for (size_t x = 0; (x < 5) && (num_percentages < 3); x++) {
|
||||
if ((rand() % 4) == 1) {
|
||||
item.data1[(num_percentages * 2) + 6] = x;
|
||||
item.data1[(num_percentages * 2) + 7] = rand() % (max_percentages[difficulty] + 1);
|
||||
num_percentages++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 1: // armor
|
||||
item.data1[1] = 0;
|
||||
while (item.data1[1] == 0) {
|
||||
item.data1[1] = rand() & 3;
|
||||
}
|
||||
switch (item.data1[1]) {
|
||||
case 1:
|
||||
item.data1[2] = (rand() % 6) + (difficulty * 6);
|
||||
item.data1[5] = rand() % 5;
|
||||
break;
|
||||
case 2:
|
||||
item.data2[2] = (rand() % 6) + (difficulty * 5);
|
||||
*reinterpret_cast<short*>(&item.data1[6]) = (rand() % 9) - 4;
|
||||
*reinterpret_cast<short*>(&item.data1[9]) = (rand() % 9) - 4;
|
||||
break;
|
||||
case 3:
|
||||
item.data2[2] = rand() % 0x3B;
|
||||
*reinterpret_cast<short*>(&item.data1[7]) = (rand() % 5) - 4;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 3: // tool
|
||||
item.data1[1] = rand() % 12;
|
||||
switch (item.data1[1]) {
|
||||
case 0:
|
||||
case 1:
|
||||
if (difficulty == 0) {
|
||||
item.data1[2] = 0;
|
||||
} else if (difficulty == 1) {
|
||||
item.data1[2] = rand() % 2;
|
||||
} else if (difficulty == 2) {
|
||||
item.data1[2] = (rand() % 2) + 1;
|
||||
} else if (difficulty == 3) {
|
||||
item.data1[2] = 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case 6:
|
||||
item.data1[2] = rand() % 2;
|
||||
break;
|
||||
|
||||
case 10:
|
||||
item.data1[2] = rand() % 3;
|
||||
break;
|
||||
|
||||
case 11:
|
||||
item.data1[2] = rand() % 7;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (item.data1[1]) {
|
||||
case 2:
|
||||
item.data1[4] = rand() % 19;
|
||||
switch (item.data1[4]) {
|
||||
case 14:
|
||||
case 17:
|
||||
item.data1[2] = 0; // reverser & ryuker always level 1
|
||||
break;
|
||||
case 16:
|
||||
item.data1[2] = rand() % max_anti_level[difficulty];
|
||||
break;
|
||||
default:
|
||||
item.data1[2] = rand() % max_tech_level[difficulty];
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 16:
|
||||
item.data1[5] = rand() % (max_quantity[difficulty] + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
// If the mag has evolved, add its new photon blast
|
||||
if (mag_number != mag_item.data.data1[1]) {
|
||||
const auto& new_mag_def = s->item_parameter_table->get_mag(mag_item.data.data1[1]);
|
||||
mag_item.data.add_mag_photon_blast(new_mag_def.photon_blast);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-16
@@ -3,23 +3,11 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <random>
|
||||
|
||||
#include "Lobby.hh"
|
||||
#include "Client.hh"
|
||||
#include "ServerState.hh"
|
||||
#include "StaticGameData.hh"
|
||||
|
||||
void player_use_item(std::shared_ptr<Client> c, size_t item_index);
|
||||
|
||||
struct CommonItemCreator {
|
||||
std::vector<uint32_t> enemy_item_categories;
|
||||
std::vector<uint32_t> box_item_categories;
|
||||
std::vector<std::vector<uint8_t>> unit_types;
|
||||
|
||||
CommonItemCreator(const std::vector<uint32_t>& enemy_item_categories,
|
||||
const std::vector<uint32_t>& box_item_categories,
|
||||
const std::vector<std::vector<uint8_t>>& unit_types);
|
||||
|
||||
int32_t decide_item_type(bool is_box) const;
|
||||
ItemData create_drop_item(bool is_box, uint8_t episode, uint8_t difficulty,
|
||||
uint8_t area, uint8_t section_id) const;
|
||||
ItemData create_shop_item(uint8_t difficulty, uint8_t shop_type) const;
|
||||
};
|
||||
void player_feed_mag(std::shared_ptr<Client> c, size_t mag_item_index, size_t fed_item_index);
|
||||
|
||||
+40
-21
@@ -8,46 +8,65 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
LevelTable::LevelTable(const string& filename, bool compressed) {
|
||||
|
||||
string data = load_file(filename);
|
||||
if (compressed) {
|
||||
data = prs_decompress(data);
|
||||
}
|
||||
|
||||
if (data.size() < sizeof(*this)) {
|
||||
throw invalid_argument("level table size is incorrect");
|
||||
}
|
||||
|
||||
memcpy(this, data.data(), sizeof(*this));
|
||||
void PlayerStats::reset_to_base(uint8_t char_class, shared_ptr<const LevelTable> level_table) {
|
||||
this->level = 0;
|
||||
this->char_stats = level_table->base_stats_for_class(char_class);
|
||||
}
|
||||
|
||||
const PlayerStats& LevelTable::base_stats_for_class(uint8_t char_class) const {
|
||||
void PlayerStats::advance_to_level(uint8_t char_class, uint32_t level, shared_ptr<const LevelTable> level_table) {
|
||||
for (; this->level < level; this->level++) {
|
||||
const auto& level_stats = level_table->stats_delta_for_level(char_class, this->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
|
||||
this->char_stats.atp += level_stats.atp;
|
||||
this->char_stats.mst += level_stats.mst;
|
||||
this->char_stats.evp += level_stats.evp;
|
||||
this->char_stats.hp += level_stats.hp;
|
||||
this->char_stats.dfp += level_stats.dfp;
|
||||
this->char_stats.ata += level_stats.ata;
|
||||
// Note: It is not a bug that lck is ignored here; the original code
|
||||
// ignores it too.
|
||||
this->experience = level_stats.experience;
|
||||
}
|
||||
}
|
||||
|
||||
LevelTable::LevelTable(shared_ptr<const string> data, bool compressed) {
|
||||
if (compressed) {
|
||||
this->data.reset(new string(prs_decompress(*data)));
|
||||
} else {
|
||||
this->data = data;
|
||||
}
|
||||
|
||||
if (this->data->size() < sizeof(Table)) {
|
||||
throw invalid_argument("level table size is incorrect");
|
||||
}
|
||||
this->table = reinterpret_cast<const Table*>(this->data->data());
|
||||
}
|
||||
|
||||
const CharacterStats& LevelTable::base_stats_for_class(uint8_t char_class) const {
|
||||
if (char_class >= 12) {
|
||||
throw out_of_range("invalid character class");
|
||||
}
|
||||
return this->base_stats[char_class];
|
||||
return this->table->base_stats[char_class];
|
||||
}
|
||||
|
||||
const LevelStats& LevelTable::stats_for_level(uint8_t char_class,
|
||||
uint8_t level) const {
|
||||
const LevelTable::LevelStats& LevelTable::stats_delta_for_level(
|
||||
uint8_t char_class, uint8_t level) const {
|
||||
if (char_class >= 12) {
|
||||
throw invalid_argument("invalid character class");
|
||||
}
|
||||
if (level >= 200) {
|
||||
throw invalid_argument("invalid character level");
|
||||
}
|
||||
return this->levels[char_class][level];
|
||||
return this->table->levels[char_class][level];
|
||||
}
|
||||
|
||||
// Levels up a character by adding the level-up bonuses to the player's stats.
|
||||
void LevelStats::apply(PlayerStats& ps) const {
|
||||
void LevelTable::LevelStats::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;
|
||||
}
|
||||
|
||||
+81
-30
@@ -2,45 +2,96 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <string>
|
||||
|
||||
class LevelTable;
|
||||
|
||||
struct CharacterStats {
|
||||
le_uint16_t atp = 0;
|
||||
le_uint16_t mst = 0;
|
||||
le_uint16_t evp = 0;
|
||||
le_uint16_t hp = 0;
|
||||
le_uint16_t dfp = 0;
|
||||
le_uint16_t ata = 0;
|
||||
le_uint16_t lck = 0;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct PlayerStats {
|
||||
le_uint16_t atp;
|
||||
le_uint16_t mst;
|
||||
le_uint16_t evp;
|
||||
le_uint16_t hp;
|
||||
le_uint16_t dfp;
|
||||
le_uint16_t ata;
|
||||
le_uint16_t lck;
|
||||
/* 00 */ CharacterStats char_stats;
|
||||
/* 0E */ le_uint16_t unknown_a1 = 0;
|
||||
/* 10 */ le_float unknown_a2 = 0.0;
|
||||
/* 14 */ le_float unknown_a3 = 0.0;
|
||||
/* 18 */ le_uint32_t level = 0;
|
||||
/* 1C */ le_uint32_t experience = 0;
|
||||
/* 20 */ le_uint32_t meseta = 0;
|
||||
/* 24 */
|
||||
|
||||
PlayerStats() noexcept;
|
||||
void reset_to_base(uint8_t char_class, std::shared_ptr<const LevelTable> level_table);
|
||||
void advance_to_level(uint8_t char_class, uint32_t level, std::shared_ptr<const LevelTable> level_table);
|
||||
} __attribute__((packed));
|
||||
|
||||
// information on a single level for a single class
|
||||
struct LevelStats {
|
||||
uint8_t atp; // atp to add on level up
|
||||
uint8_t mst; // mst to add on level up
|
||||
uint8_t evp; // evp to add on level up
|
||||
uint8_t hp; // hp to add on level up
|
||||
uint8_t dfp; // dfp to add on level up
|
||||
uint8_t ata; // ata to add on level up
|
||||
uint8_t unknown[2];
|
||||
le_uint32_t experience; // EXP value of this level
|
||||
class LevelTable { // from PlyLevelTbl.prs
|
||||
public:
|
||||
struct LevelStats {
|
||||
uint8_t atp;
|
||||
uint8_t mst;
|
||||
uint8_t evp;
|
||||
uint8_t hp;
|
||||
uint8_t dfp;
|
||||
uint8_t ata;
|
||||
uint8_t lck;
|
||||
uint8_t tp;
|
||||
le_uint32_t experience;
|
||||
|
||||
void apply(PlayerStats& ps) const;
|
||||
} __attribute__((packed));
|
||||
void apply(CharacterStats& ps) const;
|
||||
} __attribute__((packed));
|
||||
|
||||
// level table format (PlyLevelTbl.prs)
|
||||
struct LevelTable {
|
||||
PlayerStats base_stats[12];
|
||||
le_uint32_t unknown[12];
|
||||
LevelStats levels[12][200];
|
||||
struct Table {
|
||||
CharacterStats base_stats[12];
|
||||
le_uint32_t unknown[12];
|
||||
LevelStats levels[12][200];
|
||||
} __attribute__((packed));
|
||||
|
||||
LevelTable(const std::string& filename, bool compressed);
|
||||
LevelTable(std::shared_ptr<const std::string> data, bool compressed);
|
||||
|
||||
const PlayerStats& base_stats_for_class(uint8_t char_class) const;
|
||||
const LevelStats& stats_for_level(uint8_t char_class, uint8_t level) const;
|
||||
} __attribute__((packed));
|
||||
const CharacterStats& base_stats_for_class(uint8_t char_class) const;
|
||||
const LevelStats& stats_delta_for_level(uint8_t char_class, uint8_t level) const;
|
||||
|
||||
private:
|
||||
// TODO: Currently we only support the BB version of this file. It'd be nice
|
||||
// to support non-BB versions, but their formats are very different:
|
||||
//
|
||||
// BB:
|
||||
// root:
|
||||
// u32 offset:
|
||||
// u32[12] unknown
|
||||
// u32 offset:
|
||||
// u32[12] offsets:
|
||||
// LevelStats[200] level_stats
|
||||
// u32 offset:
|
||||
// CharacterStats[12] base_stats
|
||||
// GC:
|
||||
// root:
|
||||
// u32 offset:
|
||||
// u32[12] offsets:
|
||||
// LevelStats[200] level_stats
|
||||
// PC:
|
||||
// root:
|
||||
// u32 offset:
|
||||
// u32 offset[9]:
|
||||
// LevelStats[200] level_stats
|
||||
// u32 offset:
|
||||
// (0x18 bytes)
|
||||
// u32 offset:
|
||||
// PlayerStats[9] max_stats
|
||||
// u32 offset:
|
||||
// PlayerStats[9] level100_stats
|
||||
// u32 offset:
|
||||
// u32 offset[9]:
|
||||
// CharacterStats level1_stats
|
||||
// (11 more pointers)
|
||||
std::shared_ptr<const std::string> data;
|
||||
const Table* table;
|
||||
};
|
||||
|
||||
+180
-150
@@ -6,195 +6,225 @@
|
||||
#include <phosg/Time.hh>
|
||||
|
||||
#include "License.hh"
|
||||
#include "Loggers.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
License::License(const JSON& json)
|
||||
: serial_number(0),
|
||||
flags(0),
|
||||
ban_end_time(0),
|
||||
ep3_current_meseta(0),
|
||||
ep3_total_meseta_earned(0) {
|
||||
this->serial_number = json.get_int("SerialNumber");
|
||||
this->access_key = json.get_string("AccessKey", "");
|
||||
this->gc_password = json.get_string("GCPassword", "");
|
||||
this->bb_username = json.get_string("BBUsername", "");
|
||||
this->bb_password = json.get_string("BBPassword", "");
|
||||
this->flags = json.get_int("Flags", 0);
|
||||
this->ban_end_time = json.get_int("BanEndTime", 0);
|
||||
this->ep3_current_meseta = json.get_int("Ep3CurrentMeseta", 0);
|
||||
this->ep3_total_meseta_earned = json.get_int("Ep3TotalMesetaEarned", 0);
|
||||
}
|
||||
|
||||
JSON License::json() const {
|
||||
return JSON::dict({
|
||||
{"SerialNumber", this->serial_number},
|
||||
{"AccessKey", this->access_key},
|
||||
{"GCPassword", this->gc_password},
|
||||
{"BBUsername", this->bb_username},
|
||||
{"BBPassword", this->bb_password},
|
||||
{"Flags", this->flags},
|
||||
{"BanEndTime", this->ban_end_time},
|
||||
{"Ep3CurrentMeseta", this->ep3_current_meseta},
|
||||
{"Ep3TotalMesetaEarned", this->ep3_total_meseta_earned},
|
||||
});
|
||||
}
|
||||
|
||||
License::License() : serial_number(0), privileges(0), ban_end_time(0) { }
|
||||
void License::save() const {
|
||||
auto json = this->json();
|
||||
string json_data = json.serialize(JSON::SerializeOption::FORMAT | JSON::SerializeOption::HEX_INTEGERS);
|
||||
string filename = string_printf("system/licenses/%010" PRIu32 ".json", this->serial_number);
|
||||
save_file(filename, json_data);
|
||||
}
|
||||
|
||||
void License::delete_file() const {
|
||||
string filename = string_printf("system/licenses/%010" PRIu32 ".json", this->serial_number);
|
||||
remove(filename.c_str());
|
||||
}
|
||||
|
||||
string License::str() const {
|
||||
string ret = string_printf("License(serial_number=%" PRIu32, this->serial_number);
|
||||
if (!this->username.empty()) {
|
||||
ret += ", username=";
|
||||
ret += this->username;
|
||||
}
|
||||
if (!this->bb_password.empty()) {
|
||||
ret += ", bb-password=";
|
||||
ret += this->bb_password;
|
||||
}
|
||||
vector<string> tokens;
|
||||
tokens.emplace_back(string_printf("serial_number=%010" PRIu32 "/%08" PRIX32, this->serial_number, this->serial_number));
|
||||
if (!this->access_key.empty()) {
|
||||
ret += ", access-key=";
|
||||
ret += this->access_key;
|
||||
tokens.emplace_back("access_key=" + this->access_key);
|
||||
}
|
||||
if (!this->gc_password.empty()) {
|
||||
ret += ", gc-password=";
|
||||
ret += this->gc_password;
|
||||
tokens.emplace_back("gc_password=" + this->gc_password);
|
||||
}
|
||||
ret += string_printf(", privileges=%" PRIu32, this->privileges);
|
||||
if (!this->bb_username.empty()) {
|
||||
tokens.emplace_back("bb_username=" + this->bb_username);
|
||||
}
|
||||
if (!this->bb_password.empty()) {
|
||||
tokens.emplace_back("bb_password=" + this->bb_password);
|
||||
}
|
||||
tokens.emplace_back(string_printf("flags=%08" PRIX32, this->flags));
|
||||
if (this->ban_end_time) {
|
||||
ret += string_printf(", banned-until=%" PRIu64, this->ban_end_time);
|
||||
tokens.emplace_back(string_printf("ban_end_time=%016" PRIX64, this->ban_end_time));
|
||||
}
|
||||
return ret + ")";
|
||||
if (this->ep3_current_meseta) {
|
||||
tokens.emplace_back(string_printf("ep3_current_meseta=%" PRIu32, this->ep3_current_meseta));
|
||||
}
|
||||
if (this->ep3_total_meseta_earned) {
|
||||
tokens.emplace_back(string_printf("ep3_total_meseta_earned=%" PRIu32, this->ep3_total_meseta_earned));
|
||||
}
|
||||
return "[License: " + join(tokens, ", ") + "]";
|
||||
}
|
||||
|
||||
struct BinaryLicense {
|
||||
ptext<char, 0x14> username; // BB username (max. 16 chars; should technically be Unicode)
|
||||
ptext<char, 0x14> bb_password; // BB password (max. 16 chars)
|
||||
uint32_t serial_number; // PC/GC serial number. MUST BE PRESENT FOR BB LICENSES TOO; this is also the player's guild card number.
|
||||
ptext<char, 0x10> access_key; // PC/GC access key. (to log in using PC on a GC license, just enter the first 8 characters of the GC access key)
|
||||
ptext<char, 0x0C> gc_password; // GC password
|
||||
uint32_t privileges; // privilege level
|
||||
uint64_t ban_end_time; // end time of ban (zero = not banned)
|
||||
} __attribute__((packed));
|
||||
|
||||
LicenseIndex::LicenseIndex() {
|
||||
if (!isdir("system/licenses")) {
|
||||
mkdir("system/licenses", 0755);
|
||||
}
|
||||
|
||||
LicenseManager::LicenseManager(const string& filename) : filename(filename) {
|
||||
try {
|
||||
auto licenses = load_vector_file<License>(this->filename);
|
||||
for (const auto& read_license : licenses) {
|
||||
shared_ptr<License> license(new License(read_license));
|
||||
|
||||
// Before the temporary flag existed, licenses with root privileges would
|
||||
// have the temporary flag set. To migrate these, explicitly unset the
|
||||
// flag for all licenses loaded from the license file.
|
||||
license->privileges &= ~Privilege::TEMPORARY;
|
||||
|
||||
uint32_t serial_number = license->serial_number;
|
||||
this->bb_username_to_license.emplace(license->username, license);
|
||||
this->serial_number_to_license.emplace(serial_number, license);
|
||||
// Convert binary licenses to JSON licenses and save them
|
||||
if (isfile("system/licenses.nsi")) {
|
||||
auto bin_licenses = load_vector_file<BinaryLicense>("system/licenses.nsi");
|
||||
for (const auto& bin_license : bin_licenses) {
|
||||
// Only add licenses from the binary file if there isn't a JSON version of
|
||||
// the same license
|
||||
try {
|
||||
this->get(bin_license.serial_number);
|
||||
} catch (const missing_license&) {
|
||||
License license;
|
||||
license.serial_number = bin_license.serial_number;
|
||||
license.access_key = bin_license.access_key;
|
||||
license.gc_password = bin_license.gc_password;
|
||||
license.bb_username = bin_license.username;
|
||||
license.bb_password = bin_license.bb_password;
|
||||
license.flags = bin_license.privileges;
|
||||
license.ban_end_time = bin_license.ban_end_time;
|
||||
license.ep3_current_meseta = 0;
|
||||
license.ep3_total_meseta_earned = 0;
|
||||
license.save();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (const cannot_open_file&) {
|
||||
log(WARNING, "File %s does not exist; no licenses are registered",
|
||||
this->filename.c_str());
|
||||
::remove("system/licenses.nsi");
|
||||
}
|
||||
}
|
||||
|
||||
void LicenseManager::save() const {
|
||||
auto f = fopen_unique(this->filename, "wb");
|
||||
for (const auto& it : this->serial_number_to_license) {
|
||||
if (it.second->privileges & Privilege::TEMPORARY) {
|
||||
continue;
|
||||
for (const auto& item : list_directory("system/licenses")) {
|
||||
if (ends_with(item, ".json")) {
|
||||
JSON json = JSON::parse(load_file("system/licenses/" + item));
|
||||
shared_ptr<License> license(new License(json));
|
||||
this->add(license);
|
||||
}
|
||||
fwritex(f.get(), it.second.get(), sizeof(License));
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr<const License> LicenseManager::verify_pc(uint32_t serial_number,
|
||||
const string& access_key) const {
|
||||
auto& license = this->serial_number_to_license.at(serial_number);
|
||||
if (!license->access_key.eq_n(access_key, 8)) {
|
||||
throw invalid_argument("incorrect access key");
|
||||
}
|
||||
|
||||
if (license->ban_end_time && (license->ban_end_time >= now())) {
|
||||
throw invalid_argument("user is banned");
|
||||
}
|
||||
return license;
|
||||
}
|
||||
|
||||
shared_ptr<const License> LicenseManager::verify_gc(uint32_t serial_number,
|
||||
const string& access_key) const {
|
||||
auto& license = this->serial_number_to_license.at(serial_number);
|
||||
if (!license->access_key.eq_n(access_key, 12)) {
|
||||
throw invalid_argument("incorrect access key");
|
||||
}
|
||||
if (license->ban_end_time && (license->ban_end_time >= now())) {
|
||||
throw invalid_argument("user is banned");
|
||||
}
|
||||
return license;
|
||||
}
|
||||
|
||||
shared_ptr<const License> LicenseManager::verify_gc(uint32_t serial_number,
|
||||
const string& access_key, const string& password) const {
|
||||
auto& license = this->serial_number_to_license.at(serial_number);
|
||||
if (!license->access_key.eq_n(access_key, 12)) {
|
||||
throw invalid_argument("incorrect access key");
|
||||
}
|
||||
if (license->gc_password != password) {
|
||||
throw invalid_argument("incorrect password");
|
||||
}
|
||||
if (license->ban_end_time && (license->ban_end_time >= now())) {
|
||||
throw invalid_argument("user is banned");
|
||||
}
|
||||
return license;
|
||||
}
|
||||
|
||||
shared_ptr<const License> LicenseManager::verify_bb(const string& username,
|
||||
const string& password) const {
|
||||
auto& license = this->bb_username_to_license.at(username);
|
||||
if (license->bb_password != password) {
|
||||
throw invalid_argument("incorrect password");
|
||||
}
|
||||
|
||||
if (license->ban_end_time && (license->ban_end_time >= now())) {
|
||||
throw invalid_argument("user is banned");
|
||||
}
|
||||
return license;
|
||||
}
|
||||
|
||||
size_t LicenseManager::count() const {
|
||||
size_t LicenseIndex::count() const {
|
||||
return this->serial_number_to_license.size();
|
||||
}
|
||||
|
||||
void LicenseManager::ban_until(uint32_t serial_number, uint64_t end_time) {
|
||||
this->serial_number_to_license.at(serial_number)->ban_end_time = end_time;
|
||||
this->save();
|
||||
}
|
||||
|
||||
void LicenseManager::add(shared_ptr<License> l) {
|
||||
uint32_t serial_number = l->serial_number;
|
||||
this->serial_number_to_license.emplace(serial_number, l);
|
||||
if (!l->username.empty()) {
|
||||
this->bb_username_to_license.emplace(l->username, l);
|
||||
shared_ptr<License> LicenseIndex::get(uint32_t serial_number) const {
|
||||
try {
|
||||
return this->serial_number_to_license.at(serial_number);
|
||||
} catch (const out_of_range&) {
|
||||
throw missing_license();
|
||||
}
|
||||
this->save();
|
||||
}
|
||||
|
||||
void LicenseManager::remove(uint32_t serial_number) {
|
||||
auto l = this->serial_number_to_license.at(serial_number);
|
||||
this->serial_number_to_license.erase(l->serial_number);
|
||||
if (!l->username.empty()) {
|
||||
this->bb_username_to_license.erase(l->username);
|
||||
}
|
||||
this->save();
|
||||
}
|
||||
|
||||
vector<License> LicenseManager::snapshot() const {
|
||||
vector<License> ret;
|
||||
for (auto it : this->serial_number_to_license) {
|
||||
ret.emplace_back(*it.second);
|
||||
vector<shared_ptr<License>> LicenseIndex::all() const {
|
||||
vector<shared_ptr<License>> ret;
|
||||
ret.reserve(this->serial_number_to_license.size());
|
||||
for (const auto& it : this->serial_number_to_license) {
|
||||
ret.emplace_back(it.second);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
shared_ptr<License> LicenseManager::create_license_pc(
|
||||
uint32_t serial_number, const string& access_key, bool temporary) {
|
||||
shared_ptr<License> l(new License());
|
||||
l->serial_number = serial_number;
|
||||
l->access_key = access_key;
|
||||
if (temporary) {
|
||||
l->privileges |= Privilege::TEMPORARY;
|
||||
void LicenseIndex::add(shared_ptr<License> l) {
|
||||
this->serial_number_to_license[l->serial_number] = l;
|
||||
if (!l->bb_username.empty()) {
|
||||
this->bb_username_to_license[l->bb_username] = l;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
shared_ptr<License> LicenseManager::create_license_gc(
|
||||
uint32_t serial_number, const string& access_key, const string& password,
|
||||
bool temporary) {
|
||||
shared_ptr<License> l(new License());
|
||||
l->serial_number = serial_number;
|
||||
l->access_key = access_key;
|
||||
l->gc_password = password;
|
||||
if (temporary) {
|
||||
l->privileges |= Privilege::TEMPORARY;
|
||||
void LicenseIndex::remove(uint32_t serial_number) {
|
||||
auto l = this->serial_number_to_license.at(serial_number);
|
||||
this->serial_number_to_license.erase(l->serial_number);
|
||||
if (!l->bb_username.empty()) {
|
||||
this->bb_username_to_license.erase(l->bb_username);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
shared_ptr<License> LicenseManager::create_license_bb(
|
||||
uint32_t serial_number, const string& username, const string& password,
|
||||
bool temporary) {
|
||||
shared_ptr<License> l(new License());
|
||||
l->serial_number = serial_number;
|
||||
l->username = username;
|
||||
l->bb_password = password;
|
||||
if (temporary) {
|
||||
l->privileges |= Privilege::TEMPORARY;
|
||||
shared_ptr<License> LicenseIndex::verify_v1_v2(uint32_t serial_number, const string& access_key) const {
|
||||
try {
|
||||
auto& license = this->serial_number_to_license.at(serial_number);
|
||||
if (license->access_key.compare(0, 8, access_key) != 0) {
|
||||
throw incorrect_access_key();
|
||||
}
|
||||
if (license->ban_end_time && (license->ban_end_time >= now())) {
|
||||
throw invalid_argument("user is banned");
|
||||
}
|
||||
return license;
|
||||
} catch (const out_of_range&) {
|
||||
throw missing_license();
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr<License> LicenseIndex::verify_gc(uint32_t serial_number, const string& access_key) const {
|
||||
try {
|
||||
auto& license = this->serial_number_to_license.at(serial_number);
|
||||
if (license->access_key != access_key) {
|
||||
throw incorrect_access_key();
|
||||
}
|
||||
if (license->ban_end_time && (license->ban_end_time >= now())) {
|
||||
throw invalid_argument("user is banned");
|
||||
}
|
||||
return license;
|
||||
} catch (const out_of_range&) {
|
||||
throw missing_license();
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr<License> LicenseIndex::verify_gc(uint32_t serial_number, const string& access_key, const string& password) const {
|
||||
try {
|
||||
auto& license = this->serial_number_to_license.at(serial_number);
|
||||
if (license->access_key != access_key) {
|
||||
throw incorrect_access_key();
|
||||
}
|
||||
if (license->gc_password != password) {
|
||||
throw incorrect_password();
|
||||
}
|
||||
if (license->ban_end_time && (license->ban_end_time >= now())) {
|
||||
throw invalid_argument("user is banned");
|
||||
}
|
||||
return license;
|
||||
} catch (const out_of_range&) {
|
||||
throw missing_license();
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr<License> LicenseIndex::verify_bb(const string& username, const string& password) const {
|
||||
try {
|
||||
auto& license = this->bb_username_to_license.at(username);
|
||||
if (license->bb_password != password) {
|
||||
throw incorrect_password();
|
||||
}
|
||||
if (license->ban_end_time && (license->ban_end_time >= now())) {
|
||||
throw invalid_argument("user is banned");
|
||||
}
|
||||
return license;
|
||||
} catch (const out_of_range&) {
|
||||
throw missing_license();
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
+66
-59
@@ -1,83 +1,90 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <phosg/JSON.hh>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "Text.hh"
|
||||
|
||||
enum Privilege {
|
||||
KICK_USER = 0x00000001,
|
||||
BAN_USER = 0x00000002,
|
||||
SILENCE_USER = 0x00000004,
|
||||
CHANGE_LOBBY_INFO = 0x00000008,
|
||||
CHANGE_EVENT = 0x00000010,
|
||||
ANNOUNCE = 0x00000020,
|
||||
FREE_JOIN_GAMES = 0x00000040,
|
||||
UNLOCK_GAMES = 0x00000080,
|
||||
|
||||
MODERATOR = 0x00000007,
|
||||
ADMINISTRATOR = 0x0000003F,
|
||||
ROOT = 0x7FFFFFFF,
|
||||
|
||||
TEMPORARY = 0x80000000,
|
||||
};
|
||||
|
||||
enum LicenseVerifyAction {
|
||||
BB = 0x00,
|
||||
GC = 0x01,
|
||||
PC = 0x02,
|
||||
SERIAL_NUMBER = 0x03,
|
||||
};
|
||||
class LicenseIndex;
|
||||
|
||||
struct License {
|
||||
ptext<char, 0x14> username; // BB username (max. 16 chars; should technically be Unicode)
|
||||
ptext<char, 0x14> bb_password; // BB password (max. 16 chars)
|
||||
uint32_t serial_number; // PC/GC serial number. MUST BE PRESENT FOR BB LICENSES TOO; this is also the player's guild card number.
|
||||
ptext<char, 0x10> access_key; // PC/GC access key. (to log in using PC on a GC license, just enter the first 8 characters of the GC access key)
|
||||
ptext<char, 0x0C> gc_password; // GC password
|
||||
uint32_t privileges; // privilege level
|
||||
uint64_t ban_end_time; // end time of ban (zero = not banned)
|
||||
enum Flag : uint32_t {
|
||||
// clang-format off
|
||||
KICK_USER = 0x00000001,
|
||||
BAN_USER = 0x00000002,
|
||||
SILENCE_USER = 0x00000004,
|
||||
CHANGE_LOBBY_INFO = 0x00000008,
|
||||
CHANGE_EVENT = 0x00000010,
|
||||
ANNOUNCE = 0x00000020,
|
||||
FREE_JOIN_GAMES = 0x00000040,
|
||||
UNLOCK_GAMES = 0x00000080,
|
||||
DEBUG = 0x01000000,
|
||||
MODERATOR = 0x00000007,
|
||||
ADMINISTRATOR = 0x000000FF,
|
||||
ROOT = 0x010000FF,
|
||||
|
||||
UNUSED_BITS = 0xFEFFFF00,
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
uint32_t serial_number = 0;
|
||||
std::string access_key;
|
||||
std::string gc_password;
|
||||
std::string bb_username;
|
||||
std::string bb_password;
|
||||
|
||||
uint32_t flags = 0;
|
||||
uint64_t ban_end_time = 0; // 0 = not banned
|
||||
|
||||
uint32_t ep3_current_meseta = 0;
|
||||
uint32_t ep3_total_meseta_earned = 0;
|
||||
|
||||
License() = default;
|
||||
explicit License(const JSON& json);
|
||||
|
||||
JSON json() const;
|
||||
void save() const;
|
||||
void delete_file() const;
|
||||
|
||||
License();
|
||||
std::string str() const;
|
||||
} __attribute__((packed));
|
||||
};
|
||||
|
||||
class LicenseManager {
|
||||
class LicenseIndex {
|
||||
public:
|
||||
LicenseManager(const std::string& filename);
|
||||
~LicenseManager() = default;
|
||||
class incorrect_password : public std::invalid_argument {
|
||||
public:
|
||||
incorrect_password() : invalid_argument("incorrect password") {}
|
||||
};
|
||||
|
||||
std::shared_ptr<const License> verify_pc(uint32_t serial_number,
|
||||
const std::string& access_key) const;
|
||||
std::shared_ptr<const License> verify_gc(uint32_t serial_number,
|
||||
const std::string& access_key) const;
|
||||
std::shared_ptr<const License> verify_gc(uint32_t serial_number,
|
||||
const std::string& access_key, const std::string& password) const;
|
||||
std::shared_ptr<const License> verify_bb(const std::string& username,
|
||||
const std::string& password) const;
|
||||
void ban_until(uint32_t serial_number, uint64_t seconds);
|
||||
class incorrect_access_key : public std::invalid_argument {
|
||||
public:
|
||||
incorrect_access_key() : invalid_argument("incorrect access key") {}
|
||||
};
|
||||
|
||||
class missing_license : public std::invalid_argument {
|
||||
public:
|
||||
missing_license() : invalid_argument("missing license") {}
|
||||
};
|
||||
|
||||
LicenseIndex();
|
||||
~LicenseIndex() = default;
|
||||
|
||||
size_t count() const;
|
||||
std::shared_ptr<License> get(uint32_t serial_number) const;
|
||||
std::vector<std::shared_ptr<License>> all() const;
|
||||
|
||||
void add(std::shared_ptr<License> l);
|
||||
void remove(uint32_t serial_number);
|
||||
std::vector<License> snapshot() const;
|
||||
|
||||
static std::shared_ptr<License> create_license_pc(
|
||||
uint32_t serial_number, const std::string& access_key, bool temporary);
|
||||
static std::shared_ptr<License> create_license_gc(
|
||||
uint32_t serial_number, const std::string& access_key,
|
||||
const std::string& password, bool temporary);
|
||||
static std::shared_ptr<License> create_license_bb(
|
||||
uint32_t serial_number, const std::string& username,
|
||||
const std::string& password, bool temporary);
|
||||
std::shared_ptr<License> verify_v1_v2(uint32_t serial_number, const std::string& access_key) const;
|
||||
std::shared_ptr<License> verify_gc(uint32_t serial_number, const std::string& access_key) const;
|
||||
std::shared_ptr<License> verify_gc(uint32_t serial_number, const std::string& access_key, const std::string& password) const;
|
||||
std::shared_ptr<License> verify_bb(const std::string& username, const std::string& password) const;
|
||||
|
||||
protected:
|
||||
void save() const;
|
||||
|
||||
std::string filename;
|
||||
std::unordered_map<std::string, std::shared_ptr<License>> bb_username_to_license;
|
||||
std::unordered_map<uint32_t, std::shared_ptr<License>> serial_number_to_license;
|
||||
};
|
||||
|
||||
+186
-49
@@ -4,22 +4,91 @@
|
||||
|
||||
#include <phosg/Random.hh>
|
||||
|
||||
#include "Loggers.hh"
|
||||
#include "SendCommands.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
Lobby::Lobby() : lobby_id(0), min_level(0), max_level(0xFFFFFFFF),
|
||||
next_game_item_id(0x00810000), version(GameVersion::GC), section_id(0),
|
||||
episode(1), difficulty(0), mode(0), rare_seed(random_object<uint32_t>()),
|
||||
event(0), block(0), type(0), leader_id(0), max_clients(12), flags(0) {
|
||||
|
||||
Lobby::Lobby(shared_ptr<ServerState> s, uint32_t id)
|
||||
: server_state(s),
|
||||
log(string_printf("[Lobby/%" PRIX32 "] ", id), lobby_log.min_level),
|
||||
lobby_id(id),
|
||||
min_level(0),
|
||||
max_level(0xFFFFFFFF),
|
||||
next_game_item_id(0x00810000),
|
||||
base_version(GameVersion::GC),
|
||||
allowed_versions(0xFFFF),
|
||||
section_id(0),
|
||||
episode(Episode::NONE),
|
||||
mode(GameMode::NORMAL),
|
||||
difficulty(0),
|
||||
exp_multiplier(1),
|
||||
random_seed(random_object<uint32_t>()),
|
||||
event(0),
|
||||
block(0),
|
||||
leader_id(0),
|
||||
max_clients(12),
|
||||
flags(0) {
|
||||
for (size_t x = 0; x < 12; x++) {
|
||||
this->next_item_id[x] = 0x00010000 + 0x00200000 * x;
|
||||
}
|
||||
this->next_drop_item = PlayerInventoryItem();
|
||||
}
|
||||
|
||||
shared_ptr<ServerState> Lobby::require_server_state() const {
|
||||
auto s = this->server_state.lock();
|
||||
if (!s) {
|
||||
throw logic_error("server is deleted");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
void Lobby::create_item_creator() {
|
||||
auto s = this->require_server_state();
|
||||
|
||||
shared_ptr<const RareItemSet> rare_item_set;
|
||||
if (this->base_version == GameVersion::BB) {
|
||||
rare_item_set = s->rare_item_sets.at("default-v4");
|
||||
} else if (this->base_version == GameVersion::GC || this->base_version == GameVersion::XB) {
|
||||
rare_item_set = s->rare_item_sets.at("default-v3");
|
||||
} else {
|
||||
// TODO: Should there be a separate table for V1 eventually?
|
||||
rare_item_set = s->rare_item_sets.at("default-v2");
|
||||
}
|
||||
this->item_creator.reset(new ItemCreator(
|
||||
s->common_item_set,
|
||||
rare_item_set,
|
||||
s->armor_random_set,
|
||||
s->tool_random_set,
|
||||
s->weapon_random_sets.at(this->difficulty),
|
||||
s->tekker_adjustment_set,
|
||||
s->item_parameter_table,
|
||||
this->episode,
|
||||
(this->mode == GameMode::SOLO) ? GameMode::NORMAL : this->mode,
|
||||
this->difficulty,
|
||||
this->section_id,
|
||||
this->random_seed));
|
||||
}
|
||||
|
||||
void Lobby::create_ep3_server() {
|
||||
auto s = this->require_server_state();
|
||||
if (!this->ep3_server) {
|
||||
this->log.info("Creating Episode 3 server state");
|
||||
} else {
|
||||
this->log.info("Recreating Episode 3 server state");
|
||||
}
|
||||
auto tourn = this->tournament_match ? this->tournament_match->tournament.lock() : nullptr;
|
||||
bool is_trial = (this->flags & Lobby::Flag::IS_EP3_TRIAL);
|
||||
Episode3::Server::Options options = {
|
||||
.card_index = is_trial ? s->ep3_card_index_trial : s->ep3_card_index,
|
||||
.map_index = s->ep3_map_index,
|
||||
.behavior_flags = s->ep3_behavior_flags,
|
||||
.random_crypt = this->random_crypt,
|
||||
.tournament = tourn,
|
||||
.trap_card_ids = s->ep3_trap_card_ids,
|
||||
};
|
||||
this->ep3_server = make_shared<Episode3::Server>(this->shared_from_this(), std::move(options));
|
||||
this->ep3_server->init();
|
||||
}
|
||||
|
||||
void Lobby::reassign_leader_on_client_departure(size_t leaving_client_index) {
|
||||
@@ -40,7 +109,7 @@ bool Lobby::any_client_loading() const {
|
||||
if (!this->clients[x].get()) {
|
||||
continue;
|
||||
}
|
||||
if (this->clients[x]->flags & (Client::Flag::LOADING | Client::Flag::LOADING_QUEST)) {
|
||||
if (this->clients[x]->flags & (Client::Flag::LOADING | Client::Flag::LOADING_QUEST | Client::Flag::LOADING_RUNNING_QUEST)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -57,20 +126,29 @@ size_t Lobby::count_clients() const {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Lobby::add_client(shared_ptr<Client> c) {
|
||||
void Lobby::add_client(shared_ptr<Client> c, ssize_t required_client_id) {
|
||||
ssize_t index;
|
||||
if (c->prefer_high_lobby_client_id) {
|
||||
for (index = max_clients - 1; index >= 0; index--) {
|
||||
ssize_t min_client_id = (this->flags & Lobby::Flag::IS_SPECTATOR_TEAM) ? 4 : 0;
|
||||
|
||||
if (required_client_id >= 0) {
|
||||
if (this->clients[required_client_id].get()) {
|
||||
throw out_of_range("required slot is in use");
|
||||
}
|
||||
this->clients[required_client_id] = c;
|
||||
index = required_client_id;
|
||||
|
||||
} else if (c->options.debug) {
|
||||
for (index = max_clients - 1; index >= min_client_id; index--) {
|
||||
if (!this->clients[index].get()) {
|
||||
this->clients[index] = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index < 0) {
|
||||
if (index < min_client_id) {
|
||||
throw out_of_range("no space left in lobby");
|
||||
}
|
||||
} else {
|
||||
for (index = 0; index < max_clients; index++) {
|
||||
for (index = min_client_id; index < max_clients; index++) {
|
||||
if (!this->clients[index].get()) {
|
||||
this->clients[index] = c;
|
||||
break;
|
||||
@@ -82,29 +160,55 @@ void Lobby::add_client(shared_ptr<Client> c) {
|
||||
}
|
||||
|
||||
c->lobby_client_id = index;
|
||||
c->lobby_id = this->lobby_id;
|
||||
c->lobby = this->weak_from_this();
|
||||
|
||||
// If there's no one else in the lobby, set the leader id as well
|
||||
if (index == (max_clients - 1) * c->prefer_high_lobby_client_id) {
|
||||
for (index = 0; index < max_clients; index++) {
|
||||
if (this->clients[index].get() && this->clients[index] != c) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index >= max_clients) {
|
||||
this->leader_id = c->lobby_client_id;
|
||||
size_t leader_index;
|
||||
for (leader_index = 0; leader_index < max_clients; leader_index++) {
|
||||
if (this->clients[leader_index] && (this->clients[leader_index] != c)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (leader_index >= max_clients) {
|
||||
this->leader_id = c->lobby_client_id;
|
||||
}
|
||||
|
||||
// If the lobby is a game and item tracking is enabled, assign the inventory's
|
||||
// item IDs
|
||||
if (this->is_game() && (this->flags & Lobby::Flag::ITEM_TRACKING_ENABLED)) {
|
||||
auto& inv = c->game_data.player()->inventory;
|
||||
auto p = c->game_data.player();
|
||||
auto& inv = p->inventory;
|
||||
size_t count = min<uint8_t>(inv.num_items, 30);
|
||||
for (size_t x = 0; x < count; x++) {
|
||||
inv.items[x].data.id = this->generate_item_id(c->lobby_client_id);
|
||||
}
|
||||
c->game_data.player()->print_inventory(stderr);
|
||||
p->print_inventory(stderr);
|
||||
}
|
||||
|
||||
// If the lobby is recording a battle record, add the player join event
|
||||
if (this->battle_record) {
|
||||
auto p = c->game_data.player();
|
||||
PlayerLobbyDataDCGC lobby_data;
|
||||
lobby_data.player_tag = 0x00010000;
|
||||
lobby_data.guild_card = c->license->serial_number;
|
||||
lobby_data.name = encode_sjis(p->disp.name);
|
||||
this->battle_record->add_player(
|
||||
lobby_data,
|
||||
p->inventory,
|
||||
p->disp.to_dcpcv3(),
|
||||
c->game_data.ep3_config ? (c->game_data.ep3_config->online_clv_exp / 100) : 0);
|
||||
}
|
||||
|
||||
// Send spectator count notifications if needed
|
||||
if (this->is_game() && this->is_ep3()) {
|
||||
if (this->flags & Lobby::Flag::IS_SPECTATOR_TEAM) {
|
||||
auto watched_l = this->watched_lobby.lock();
|
||||
if (watched_l) {
|
||||
send_ep3_update_game_metadata(watched_l);
|
||||
}
|
||||
} else {
|
||||
send_ep3_update_game_metadata(this->shared_from_this());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,37 +220,64 @@ void Lobby::remove_client(shared_ptr<Client> c) {
|
||||
c->lobby_client_id,
|
||||
static_cast<uint8_t>(other_c ? other_c->lobby_client_id : 0xFF)));
|
||||
}
|
||||
|
||||
this->clients[c->lobby_client_id] = nullptr;
|
||||
|
||||
// Unassign the client's lobby if it matches the current lobby's id (it may
|
||||
// not match if the client was already added to another lobby - this can
|
||||
// happen during the lobby change procedure)
|
||||
if (c->lobby_id == this->lobby_id) {
|
||||
c->lobby_id = 0;
|
||||
// Unassign the client's lobby if it matches the current lobby (it may not
|
||||
// match if the client was already added to another lobby - this can happen
|
||||
// during the lobby change procedure)
|
||||
{
|
||||
auto c_lobby = c->lobby.lock();
|
||||
if (c_lobby.get() == this) {
|
||||
c->lobby.reset();
|
||||
}
|
||||
}
|
||||
|
||||
this->reassign_leader_on_client_departure(c->lobby_client_id);
|
||||
|
||||
// If the lobby is recording a battle record, add the player leave event
|
||||
if (this->battle_record) {
|
||||
this->battle_record->delete_player(c->lobby_client_id);
|
||||
}
|
||||
|
||||
// If the lobby is Episode 3, update the appropriate spectator counts
|
||||
if (this->is_game() && this->is_ep3()) {
|
||||
if (this->flags & Lobby::Flag::IS_SPECTATOR_TEAM) {
|
||||
auto watched_l = this->watched_lobby.lock();
|
||||
if (watched_l) {
|
||||
send_ep3_update_game_metadata(watched_l);
|
||||
}
|
||||
} else {
|
||||
send_ep3_update_game_metadata(this->shared_from_this());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Lobby::move_client_to_lobby(shared_ptr<Lobby> dest_lobby,
|
||||
shared_ptr<Client> c) {
|
||||
void Lobby::move_client_to_lobby(
|
||||
shared_ptr<Lobby> dest_lobby,
|
||||
shared_ptr<Client> c,
|
||||
ssize_t required_client_id) {
|
||||
if (dest_lobby.get() == this) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (dest_lobby->count_clients() >= dest_lobby->max_clients) {
|
||||
throw out_of_range("no space left in lobby");
|
||||
if (required_client_id >= 0) {
|
||||
if (dest_lobby->clients[required_client_id]) {
|
||||
throw out_of_range("required slot is in use");
|
||||
}
|
||||
} else {
|
||||
ssize_t min_client_id = (this->flags & Lobby::Flag::IS_SPECTATOR_TEAM) ? 4 : 0;
|
||||
size_t available_slots = dest_lobby->max_clients - min_client_id;
|
||||
if (dest_lobby->count_clients() >= available_slots) {
|
||||
throw out_of_range("no space left in lobby");
|
||||
}
|
||||
}
|
||||
|
||||
this->remove_client(c);
|
||||
dest_lobby->add_client(c);
|
||||
dest_lobby->add_client(c, required_client_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
shared_ptr<Client> Lobby::find_client(const u16string* identifier,
|
||||
uint64_t serial_number) {
|
||||
shared_ptr<Client> Lobby::find_client(
|
||||
const u16string* identifier, uint64_t serial_number) {
|
||||
for (size_t x = 0; x < this->max_clients; x++) {
|
||||
if (!this->clients[x]) {
|
||||
continue;
|
||||
@@ -163,8 +294,6 @@ shared_ptr<Client> Lobby::find_client(const u16string* identifier,
|
||||
throw out_of_range("client not found");
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t Lobby::game_event_for_lobby_event(uint8_t lobby_event) {
|
||||
if (lobby_event > 7) {
|
||||
return 0;
|
||||
@@ -178,22 +307,20 @@ uint8_t Lobby::game_event_for_lobby_event(uint8_t lobby_event) {
|
||||
return lobby_event;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Lobby::add_item(const PlayerInventoryItem& item, uint8_t area, float x, float z) {
|
||||
auto& fi = this->item_id_to_floor_item[item.data.id];
|
||||
fi.inv_item = item;
|
||||
void Lobby::add_item(const ItemData& data, uint8_t area, float x, float z) {
|
||||
auto& fi = this->item_id_to_floor_item[data.id];
|
||||
fi.data = data;
|
||||
fi.area = area;
|
||||
fi.x = x;
|
||||
fi.z = z;
|
||||
}
|
||||
|
||||
PlayerInventoryItem Lobby::remove_item(uint32_t item_id) {
|
||||
ItemData Lobby::remove_item(uint32_t item_id) {
|
||||
auto item_it = this->item_id_to_floor_item.find(item_id);
|
||||
if (item_it == this->item_id_to_floor_item.end()) {
|
||||
throw out_of_range("item not present");
|
||||
}
|
||||
PlayerInventoryItem ret = move(item_it->second.inv_item);
|
||||
ItemData ret = item_it->second.data;
|
||||
this->item_id_to_floor_item.erase(item_it);
|
||||
return ret;
|
||||
}
|
||||
@@ -204,3 +331,13 @@ uint32_t Lobby::generate_item_id(uint8_t client_id) {
|
||||
}
|
||||
return this->next_game_item_id++;
|
||||
}
|
||||
|
||||
unordered_map<uint32_t, shared_ptr<Client>> Lobby::clients_by_serial_number() const {
|
||||
unordered_map<uint32_t, shared_ptr<Client>> ret;
|
||||
for (auto c : this->clients) {
|
||||
if (c) {
|
||||
ret.emplace(c->license->serial_number, c);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
+101
-37
@@ -3,102 +3,166 @@
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <phosg/Encoding.hh>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "Client.hh"
|
||||
#include "Player.hh"
|
||||
#include "CommandFormats.hh"
|
||||
#include "Episode3/BattleRecord.hh"
|
||||
#include "Episode3/Server.hh"
|
||||
#include "ItemCreator.hh"
|
||||
#include "Map.hh"
|
||||
#include "RareItemSet.hh"
|
||||
#include "Text.hh"
|
||||
#include "Player.hh"
|
||||
#include "Quest.hh"
|
||||
#include "StaticGameData.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
struct Lobby {
|
||||
struct ServerState;
|
||||
|
||||
struct Lobby : public std::enable_shared_from_this<Lobby> {
|
||||
enum Flag {
|
||||
GAME = 0x00000001,
|
||||
EPISODE_3_ONLY = 0x00000002,
|
||||
GAME = 0x00000001,
|
||||
PERSISTENT = 0x00000002,
|
||||
|
||||
// Flags used only for games
|
||||
CHEATS_ENABLED = 0x00000100,
|
||||
QUEST_IN_PROGRESS = 0x00000200,
|
||||
JOINABLE_QUEST_IN_PROGRESS = 0x00000400,
|
||||
ITEM_TRACKING_ENABLED = 0x00000800,
|
||||
CHEATS_ENABLED = 0x00000100,
|
||||
QUEST_IN_PROGRESS = 0x00000200,
|
||||
BATTLE_IN_PROGRESS = 0x00000400,
|
||||
JOINABLE_QUEST_IN_PROGRESS = 0x00000800,
|
||||
ITEM_TRACKING_ENABLED = 0x00001000,
|
||||
IS_SPECTATOR_TEAM = 0x00002000, // episode must be EP3 also
|
||||
SPECTATORS_FORBIDDEN = 0x00004000,
|
||||
START_BATTLE_PLAYER_IMMEDIATELY = 0x00008000,
|
||||
DROPS_ENABLED = 0x00010000, // Does not affect BB
|
||||
IS_EP3_TRIAL = 0x00020000,
|
||||
USE_SERVER_RARE_TABLE = 0x00040000, // Does not affect BB
|
||||
|
||||
// Flags used only for lobbies
|
||||
PUBLIC = 0x00010000,
|
||||
DEFAULT = 0x00020000,
|
||||
PERSISTENT = 0x00040000,
|
||||
PUBLIC = 0x01000000,
|
||||
DEFAULT = 0x02000000,
|
||||
V2_AND_LATER = 0x04000000, // Lobby does not appear on v1
|
||||
IS_OVERFLOW = 0x08000000,
|
||||
};
|
||||
|
||||
std::weak_ptr<ServerState> server_state;
|
||||
PrefixedLogger log;
|
||||
|
||||
uint32_t lobby_id;
|
||||
|
||||
uint32_t min_level;
|
||||
uint32_t max_level;
|
||||
|
||||
// item info
|
||||
// Item info
|
||||
struct FloorItem {
|
||||
PlayerInventoryItem inv_item;
|
||||
ItemData data;
|
||||
float x;
|
||||
float z;
|
||||
uint8_t area;
|
||||
};
|
||||
std::vector<PSOEnemy> enemies;
|
||||
std::shared_ptr<const RareItemSet> rare_item_set;
|
||||
std::shared_ptr<Map> map;
|
||||
std::array<uint32_t, 12> next_item_id;
|
||||
uint32_t next_game_item_id;
|
||||
PlayerInventoryItem next_drop_item;
|
||||
std::unordered_map<uint32_t, FloorItem> item_id_to_floor_item;
|
||||
parray<le_uint32_t, 0x20> variations;
|
||||
|
||||
// game config
|
||||
GameVersion version;
|
||||
// Game config
|
||||
GameVersion 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
|
||||
// QuestScriptVersion enum.
|
||||
uint16_t allowed_versions;
|
||||
uint8_t section_id;
|
||||
uint8_t episode; // 1 = Ep1, 2 = Ep2, 3 = Ep4, 0xFF = Ep3
|
||||
uint8_t difficulty;
|
||||
uint8_t mode;
|
||||
Episode episode;
|
||||
GameMode mode;
|
||||
uint8_t difficulty; // 0-3
|
||||
uint16_t exp_multiplier;
|
||||
std::u16string password;
|
||||
std::u16string name;
|
||||
uint32_t rare_seed;
|
||||
// This seed is also sent to the client for rare enemy generation
|
||||
uint32_t random_seed;
|
||||
std::shared_ptr<PSOLFGEncryption> random_crypt;
|
||||
std::shared_ptr<ItemCreator> item_creator;
|
||||
|
||||
//EP3_GAME_CONFIG* ep3; // only present if this is an Episode 3 game
|
||||
// Ep3 stuff
|
||||
// There are three kinds of Episode 3 games. All of these types have the flag
|
||||
// EPISODE_3_ONLY; 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_GC_Ep3_6xB4x4B> ep3_ex_result_values;
|
||||
|
||||
// lobby stuff
|
||||
// Lobby stuff
|
||||
uint8_t event;
|
||||
uint8_t block;
|
||||
uint8_t type; // number to give to PSO for the lobby number
|
||||
uint8_t leader_id;
|
||||
uint8_t max_clients;
|
||||
uint32_t flags;
|
||||
std::shared_ptr<const Quest> loading_quest;
|
||||
std::shared_ptr<const Quest> quest;
|
||||
std::array<std::shared_ptr<Client>, 12> clients;
|
||||
// Keys in this map are client_id
|
||||
std::unordered_map<size_t, std::weak_ptr<Client>> clients_to_add;
|
||||
|
||||
Lobby();
|
||||
Lobby(std::shared_ptr<ServerState> s, uint32_t id);
|
||||
Lobby(const Lobby&) = delete;
|
||||
Lobby(Lobby&&) = delete;
|
||||
Lobby& operator=(const Lobby&) = delete;
|
||||
Lobby& operator=(Lobby&&) = delete;
|
||||
|
||||
std::shared_ptr<ServerState> require_server_state() const;
|
||||
void create_item_creator();
|
||||
void create_ep3_server();
|
||||
|
||||
inline bool is_game() const {
|
||||
return this->flags & Flag::GAME;
|
||||
}
|
||||
inline bool is_ep3() const {
|
||||
return this->episode == Episode::EP3;
|
||||
}
|
||||
|
||||
inline bool version_is_allowed(QuestScriptVersion v) const {
|
||||
return this->allowed_versions & (1 << static_cast<size_t>(v));
|
||||
}
|
||||
inline void allow_version(QuestScriptVersion 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_client_loading() const;
|
||||
|
||||
void add_client(std::shared_ptr<Client> c);
|
||||
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);
|
||||
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::u16string* identifier = nullptr,
|
||||
uint64_t serial_number = 0);
|
||||
|
||||
void add_item(const PlayerInventoryItem& item, uint8_t area, float x, float z);
|
||||
PlayerInventoryItem remove_item(uint32_t item_id);
|
||||
void add_item(const ItemData& item, uint8_t area, float x, float z);
|
||||
ItemData remove_item(uint32_t item_id);
|
||||
size_t find_item(uint32_t item_id);
|
||||
uint32_t generate_item_id(uint8_t client_id);
|
||||
|
||||
static uint8_t game_event_for_lobby_event(uint8_t lobby_event);
|
||||
|
||||
std::unordered_map<uint32_t, std::shared_ptr<Client>> clients_by_serial_number() const;
|
||||
};
|
||||
|
||||
@@ -0,0 +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");
|
||||
}
|
||||
@@ -0,0 +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);
|
||||
+2094
-354
File diff suppressed because it is too large
Load Diff
+776
-422
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