├── .gitignore ├── LICENSE ├── README.md ├── choice.cpp ├── choice.h ├── csxparser.cpp ├── csxparser.h ├── csxtool.pro ├── docs ├── 010Editor Binary Templates │ ├── CSX Choices.bt │ ├── CSX Hops.bt │ └── CSX.bt ├── CSX English Notes (New).txt ├── CSX English Notes.txt ├── CSX Image File.pdf ├── CSX Parser Jumps.rtf └── CSX Russian Notes.txt ├── functionsection.cpp ├── functionsection.h ├── header.cpp ├── header.h ├── imagesection.cpp ├── imagesection.h ├── main.cpp ├── positioncomputer.cpp ├── positioncomputer.h ├── section.cpp ├── section.h ├── special.cpp ├── special.h ├── talk.cpp ├── talk.h ├── tools ├── YNSRouteChecker.py ├── lineChecker.py ├── lineFixer.py └── linemerger.py ├── txtparser.cpp ├── txtparser.h ├── unicodestring.cpp └── unicodestring.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | /.idea -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CSXTool 2 | This program created to modify cotopha/EntisGLS binary (csx) files, without the need to decompile the file. It simply just edits the hexadecimal values and replaces the text. 3 | 4 | Usage: csxtool (import [--alternativeSpace decimalFirstByteLittleEndian decimalSecondByteLittleEndian] [--ignoreExactLineBreaks] file.csx scenario1.txt [scenario2.txt scenario3.txt ...]|export file.csx) 5 | 6 | import options 7 | 8 | --alternativeSpace decimalFirstByteLittleEndian decimalSecondByteLittleEndian 9 | 10 | This option changes the space character. The default is 0x20 0x00. 11 | 12 | --ignoreExactLineBreaks 13 | 14 | This option makes it so that when the line is exactly 56 half-width characters wide, a new line is not 15 | inserted but instead the word wrapper built into the game takes care of word wrapping. This resolves 16 | a HNS issue with double line breaks, but breaks YNS due to YNS' word wrapper using dash character to 17 | indicate a word-wrapped word. 18 | 19 | This program was created by Amanojaku, I requested his permission to upload it. 20 | 21 | 22 | # Line Merger 23 | 24 | This program is used to merge two txt files that are created by the csxtool, this is useful to combine various translations of the same csx file. 25 | 26 | Usage: linemerger mainFile.txt TLFile.txt 27 | 28 | The program will place lines from TLFile.txt below the lines in mainFile.txt, it should be noted that if the txt file is modified in any way then the program may not work. 29 | In that case re-export a new txt file from the csx file using the csxtool. 30 | 31 | The main (textMerger) function was made by [Shuvi](https://github.com/ShuviSchwarze) and the framework was done by [MrWicked](https://github.com/TheRealMrWicked). 32 | 33 | 34 | # Line Checker 35 | 36 | This program is used on files created by the csxtool, it checks for blank lines and writes them to a file. 37 | 38 | Usage: linechecker file.txt 39 | 40 | 41 | # Line Fixer 42 | 43 | This program is used on files created by the csxtool, it moves the index count of each line back one number. 44 | 45 | Usage: linefixer file.txt -------------------------------------------------------------------------------- /choice.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "choice.h" 4 | 5 | const char choiceSequencePrefix[] = { 0x02, 0x00, 0x06 }; 6 | const char choicePostfix[] = { 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x08, 0x05, 0x02, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 'A', 0x00, 'd', 0x00, 'd', 0x00, 'S', 0x00, 'e', 0x00, 'l', 0x00, 'e', 0x00, 'c', 0x00, 't', 0x00 }; 7 | const char choiceContPostfix[] = { 0x01, 0x02, 0x00, 0x06 }; 8 | const char choiceFinalPostfix[] = { 0x01, 0x02, 0x03, 0x04 }; 9 | 10 | size_t Choice::byteSize() const { 11 | return sizeof(choiceSequencePrefix) + 2 * sizeof(choicePostfix) + sizeof(choiceContPostfix) + sizeof(choiceFinalPostfix) + choice1.byteSize() + choice2.byteSize(); 12 | } 13 | 14 | size_t Choice::writeToData(char *data) const { 15 | size_t len = 0; 16 | 17 | memcpy(data, choiceSequencePrefix, sizeof(choiceSequencePrefix)); 18 | len += sizeof(choiceSequencePrefix); 19 | 20 | choice1.writeToData(data + len); 21 | len += choice1.byteSize(); 22 | 23 | memcpy(data + len, choicePostfix, sizeof(choicePostfix)); 24 | len += sizeof(choicePostfix); 25 | memcpy(data + len, choiceContPostfix, sizeof(choiceContPostfix)); 26 | len += sizeof(choiceContPostfix); 27 | 28 | choice2.writeToData(data + len); 29 | len += choice2.byteSize(); 30 | 31 | memcpy(data + len, choicePostfix, sizeof(choicePostfix)); 32 | len += sizeof(choicePostfix); 33 | memcpy(data + len, choiceFinalPostfix, sizeof(choiceFinalPostfix)); 34 | len += sizeof(choiceFinalPostfix); 35 | 36 | return len; 37 | } 38 | 39 | bool tryParseChoice(Choice *choice, const char *contentBegin, size_t contentLength, size_t offset, uint32_t sectionPosition) { 40 | const char *contentEnd = contentBegin + contentLength; 41 | size_t curr = offset; 42 | 43 | choice->choicePos = offset; 44 | 45 | if (curr + sizeof(choiceSequencePrefix) > contentLength || memcmp(contentBegin + curr, choiceSequencePrefix, sizeof(choiceSequencePrefix)) != 0) { 46 | return false; 47 | } 48 | curr += sizeof(choiceSequencePrefix); 49 | 50 | if (isShortUnicodeString(contentBegin + curr, contentEnd)) { 51 | choice->choice1 = parseUnicodeString(contentBegin + curr, contentEnd, curr + sectionPosition); 52 | curr += choice->choice1.byteSize(); 53 | } else { 54 | return false; 55 | } 56 | 57 | if (curr + sizeof(choicePostfix) > contentLength || memcmp(contentBegin + curr, choicePostfix, sizeof(choicePostfix)) != 0) { 58 | return false; 59 | } 60 | curr += sizeof(choicePostfix); 61 | 62 | if (curr + sizeof(choiceContPostfix) > contentLength || memcmp(contentBegin + curr, choiceContPostfix, sizeof(choiceContPostfix)) != 0) { 63 | return false; 64 | } 65 | curr += sizeof(choiceContPostfix); 66 | 67 | if (isShortUnicodeString(contentBegin + curr, contentEnd)) { 68 | choice->choice2 = parseUnicodeString(contentBegin + curr, contentEnd, curr + sectionPosition); 69 | curr += choice->choice2.byteSize(); 70 | } else { 71 | return false; 72 | } 73 | 74 | if (curr + sizeof(choicePostfix) > contentLength || memcmp(contentBegin + curr, choicePostfix, sizeof(choicePostfix)) != 0) { 75 | return false; 76 | } 77 | curr += sizeof(choicePostfix); 78 | 79 | if (curr + sizeof(choiceFinalPostfix) > contentLength || memcmp(contentBegin + curr, choiceFinalPostfix, sizeof(choiceFinalPostfix)) != 0) { 80 | return false; 81 | } 82 | 83 | return true; 84 | } 85 | -------------------------------------------------------------------------------- /choice.h: -------------------------------------------------------------------------------- 1 | #ifndef CHOICE_H 2 | #define CHOICE_H 3 | 4 | #include 5 | #include "unicodestring.h" 6 | 7 | class Choice { 8 | public: 9 | Choice(): index(-1), choicePos(0) {} 10 | 11 | int index; 12 | size_t choicePos; 13 | UnicodeString choice1; 14 | UnicodeString choice2; 15 | 16 | size_t byteSize() const; 17 | size_t writeToData(char *data) const; 18 | }; 19 | 20 | bool tryParseChoice(Choice *choice, const char *contentBegin, size_t contentLength, size_t offset, uint32_t sectionPosition); 21 | 22 | #endif // CHOICE_H 23 | -------------------------------------------------------------------------------- /csxparser.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "csxparser.h" 6 | #include "txtparser.h" 7 | 8 | static const char entisFT[] = { 'E', 'n', 't', 'i', 's', 0x1a, 0x00, 0x00 }; 9 | static const char newLine[] = { '\r', 0x00, '\n', 0x00 }; 10 | 11 | void CSXParser::exportCsx(std::string origCsxFilename, std::string utfFilename) { 12 | std::cout << "Parsing CSX..." << std::endl; 13 | parseCsx(origCsxFilename); 14 | std::cout << "Performing checks..." << std::endl; 15 | check(); 16 | std::cout << "Extracting scenario..." << std::endl; 17 | image.extractStrings(); 18 | std::cout << "Scenario has " << image.messages.size() << " messages and " << image.choices.size() << " choices." << std::endl; 19 | std::cout << "Writing TXT file..." << std::endl; 20 | TxtParser txt; 21 | txt.messages.swap(image.messages); 22 | txt.choices.swap(image.choices); 23 | txt.writeTxt(utfFilename); 24 | } 25 | 26 | void CSXParser::importCsx(std::string origCsxFilename, std::string tlCsxFilename, std::deque utfFilenames, const char *customSpace, bool ignoreExactLineBreaks) { 27 | std::cout << "Parsing CSX..." << std::endl; 28 | parseCsx(origCsxFilename); 29 | std::cout << "Performing checks on the original file..." << std::endl; 30 | check(); 31 | std::cout << "Extracting scenario..." << std::endl; 32 | image.extractStrings(); 33 | std::cout << "Scenario has " << image.messages.size() << " messages and " << image.choices.size() << " choices." << std::endl; 34 | std::cout << "Parsing TXT files..." << std::endl; 35 | TxtParser txt; 36 | TxtParser::Stats totalStats; 37 | for (size_t i = 0; i < utfFilenames.size(); ++i) { 38 | TxtParser::Stats fileStats = txt.parseTxt(utfFilenames[i], customSpace); 39 | totalStats += fileStats; 40 | std::cout << "File " << utfFilenames[i] << ": " << fileStats << std::endl; 41 | } 42 | std::cout << "Total: " << totalStats << std::endl; 43 | std::cout << "Updating scenario..." << std::endl; 44 | image.substituteStrings(txt.messages, txt.choices, txt.specials, ignoreExactLineBreaks); 45 | std::cout << "Updating short jump offsets..." << std::endl; 46 | image.updateShortHops(); 47 | std::cout << "Fixing line width..." << std::endl; 48 | image.fixLineWidth(); 49 | std::cout << "Updating long jump offsets..." << std::endl; 50 | function.updateOffsets(image.positionsComputer()); 51 | std::cout << "Updating header..." << std::endl; 52 | updateHeader(); 53 | std::cout << "Writing CSX file..." << std::endl; 54 | writeCsx(tlCsxFilename); 55 | } 56 | 57 | void CSXParser::parseCsx(std::string csxFilename) { 58 | std::ifstream fin(csxFilename.c_str(), std::ios_base::in | std::ios_base::binary); 59 | if (!fin) { 60 | throw std::runtime_error("Couldn't open file " + csxFilename + "."); 61 | } 62 | 63 | // Header reading and check 64 | fin >> header; 65 | 66 | if (!fin) { 67 | throw std::runtime_error("Corrupted header data."); 68 | } 69 | 70 | if (memcmp(header.fileType, entisFT, sizeof(entisFT)) != 0) { 71 | throw std::runtime_error("Wrong file type."); 72 | } 73 | 74 | if (header.zero != 0) { 75 | throw std::runtime_error("Corrupted header data."); 76 | } 77 | 78 | if (strncmp(header.imageType, "Cotopha Image file", 18) != 0) { 79 | throw std::runtime_error("Wrong image type."); 80 | } 81 | 82 | // Read raw data of sections and do size checks 83 | fin >> image >> function >> global >> data >> conststr >> linkinf; 84 | 85 | image.position = 64; // size of header 86 | function.position = image.position + image.size + 16; 87 | global.position = function.position + function.size + 16; 88 | data.position = global.position + global.size + 16; 89 | conststr.position = data.position + data.size + 16; 90 | linkinf.position = conststr.position + conststr.size + 16; 91 | 92 | image.contentStartByte = image.position + 16; 93 | 94 | if (!fin || header.size != 16 * 6 + image.size + function.size + global.size + data.size + conststr.size + linkinf.size || fin.peek() >= 0) { 95 | throw std::runtime_error("Wrong content size."); 96 | } 97 | 98 | fin.close(); 99 | } 100 | 101 | void CSXParser::check() const { 102 | image.check(); 103 | } 104 | 105 | void CSXParser::updateHeader() { 106 | header.size = 16 * 6 + image.size + function.size + global.size + data.size + conststr.size + linkinf.size; 107 | } 108 | 109 | void CSXParser::writeCsx(std::string csxFilename) const { 110 | std::ofstream fout(csxFilename.c_str(), std::ios_base::out | std::ios_base::binary); 111 | if (!fout) { 112 | throw std::runtime_error("Couldn't open file " + csxFilename + "."); 113 | } 114 | 115 | fout << header << image << function << global << data << conststr << linkinf; 116 | 117 | fout.close(); 118 | } 119 | -------------------------------------------------------------------------------- /csxparser.h: -------------------------------------------------------------------------------- 1 | #ifndef CSXPARSER_H 2 | #define CSXPARSER_H 3 | 4 | #include 5 | #include 6 | #include "section.h" 7 | #include "functionsection.h" 8 | #include "imagesection.h" 9 | #include "header.h" 10 | 11 | class CSXParser { 12 | public: 13 | void exportCsx(std::string origCsxFilename, std::string utfFilename); 14 | void importCsx(std::string origCsxFilename, std::string tlCsxFilename, std::deque utfFilenames, const char *customSpace, bool ignoreExactLineBreaks); 15 | 16 | private: 17 | Header header; 18 | ImageSection image; 19 | FunctionSection function; 20 | Section global, data, conststr, linkinf; 21 | 22 | void parseCsx(std::string csxFilename); 23 | void check() const; 24 | void updateHeader(); 25 | void writeCsx(std::string csxFilename) const; 26 | }; 27 | 28 | #endif // CSXPARSER_H 29 | -------------------------------------------------------------------------------- /csxtool.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | CONFIG += console c++11 3 | CONFIG -= qt 4 | 5 | win32 { 6 | LIBS += -liconv 7 | } 8 | 9 | QMAKE_LFLAGS += -static -static-libgcc -static-libstdc++ 10 | QMAKE_CXXFLAGS += -Wno-narrowing 11 | CONFIG(release, debug|release) { 12 | QMAKE_CXXFLAGS += -DNDEBUG 13 | } 14 | 15 | SOURCES += main.cpp \ 16 | functionsection.cpp \ 17 | section.cpp \ 18 | imagesection.cpp \ 19 | unicodestring.cpp \ 20 | csxparser.cpp \ 21 | positioncomputer.cpp \ 22 | header.cpp \ 23 | talk.cpp \ 24 | choice.cpp \ 25 | txtparser.cpp \ 26 | special.cpp 27 | 28 | HEADERS += \ 29 | functionsection.h \ 30 | section.h \ 31 | imagesection.h \ 32 | unicodestring.h \ 33 | csxparser.h \ 34 | positioncomputer.h \ 35 | header.h \ 36 | talk.h \ 37 | choice.h \ 38 | txtparser.h \ 39 | special.h 40 | 41 | OTHER_FILES += 42 | 43 | -------------------------------------------------------------------------------- /docs/010Editor Binary Templates/CSX Choices.bt: -------------------------------------------------------------------------------- 1 | struct UNICODE { 2 | int32 len; 3 | wchar_t str[len]; 4 | }; 5 | 6 | char stuff[0xcc1ead] ; 7 | 8 | char st[3] ; 9 | UNICODE choice1 ; 10 | char ukn1[13] ; // 02 00 04 00 00 00 00 08 05 02 00 00 00 11 | UNICODE adds1 ; 12 | char p1[4] ; 13 | UNICODE choice2 ; 14 | char ukn2[13] ; // 02 00 04 00 00 00 00 08 05 02 00 00 00 15 | UNICODE adds2 ; 16 | 17 | if (st[0] != 2 || st[1] != 0 || st[2] != 6) { 18 | return 1; 19 | } -------------------------------------------------------------------------------- /docs/010Editor Binary Templates/CSX Hops.bt: -------------------------------------------------------------------------------- 1 | struct UNICODE { 2 | int32 len; 3 | wchar_t str[len]; 4 | }; 5 | 6 | 7 | char stuff[0xb3dad6] ; 8 | //char stuff[0xc4f55e] ; 9 | 10 | UNICODE u ; 11 | int16 p1 ; 12 | int32 p2 ; 13 | char skipp[p2] ; 14 | char r1 ; 15 | int32 r2 ; 16 | char skipr[r2] ; 17 | 18 | 19 | // double arg in 0x991C05, 0x7E1260, 0x706EF6, 0x50250D, 0x493F16, 0x444FA1, 0x3362FE, 0x2209B1, 0x1C1D7D 20 | /* 21 | char stuff[0x4a57f1] ; 22 | 23 | UNICODE u ; 24 | int16 p1 ; 25 | int32 p2 ; 26 | int16 p3 ; 27 | int32 p4 ; 28 | char skipp[p4] ; 29 | 30 | char r1 ; 31 | char r2[8] ; 32 | char r3[3] ; 33 | */ -------------------------------------------------------------------------------- /docs/010Editor Binary Templates/CSX.bt: -------------------------------------------------------------------------------- 1 | typedef char s8[8]; 2 | 3 | struct SECTION { 4 | s8 prefix; 5 | int32 size; 6 | int32 unknown; 7 | char content[size]; 8 | }; 9 | 10 | struct UNICODE { 11 | int32 len; 12 | wchar_t str[len]; 13 | }; 14 | 15 | struct IMAGE { 16 | s8 prefix; 17 | int32 size; 18 | int32 unknown; 19 | char content[size]; 20 | }; 21 | 22 | struct FUNCTION { 23 | s8 prefix; 24 | int32 size; 25 | int32 unknown1; 26 | int32 records1; 27 | int32 offset[records1]; 28 | int32 unknown2; 29 | int32 records2; 30 | struct { 31 | int32 offset; 32 | UNICODE name; 33 | } namedOffsets[records2] ; 34 | }; 35 | 36 | struct CSX { 37 | struct HEADER { 38 | s8 prefix; 39 | int32 unknown1; 40 | int32 zero; 41 | char imageType[40]; 42 | int32 size; 43 | int32 unknown2; 44 | } header ; 45 | 46 | IMAGE image ; 47 | FUNCTION function ; 48 | SECTION global ; 49 | SECTION data ; 50 | SECTION conststr ; 51 | SECTION linkinf ; 52 | } csx; 53 | 54 | if (csx.header.prefix != "Entis\x1A\x00\x00") { 55 | return 1; 56 | } 57 | 58 | if (csx.header.imageType != "Cotopha Image file") { 59 | return 2; 60 | } 61 | 62 | if (csx.header.zero != 0) { 63 | return 3; 64 | } 65 | 66 | if (csx.header.size + 64 != FileSize()) { 67 | return 4; 68 | } 69 | 70 | if (csx.image.prefix != "image ") { 71 | return 5; 72 | } 73 | 74 | if (csx.function.prefix != "function") { 75 | return 6; 76 | } 77 | 78 | if (csx.global.prefix != "global ") { 79 | return 7; 80 | } 81 | 82 | if (csx.data.prefix != "data ") { 83 | return 8; 84 | } 85 | 86 | if (csx.conststr.prefix != "conststr") { 87 | return 9; 88 | } 89 | 90 | if (csx.linkinf.prefix != "linkinf ") { 91 | return 10; 92 | } -------------------------------------------------------------------------------- /docs/CSX English Notes (New).txt: -------------------------------------------------------------------------------- 1 | ===== CSX File Format Notes 2 | used types: 3 | basic: uint16, uint32, char[] 4 | 5 | [US] - unicode string with format: 6 | [length : uint32] [content : char[2*length]] 7 | where is sequence of utf-16 little endian characters 8 | 9 | ------ Normal Short Jumps 10 | [prefix : uint16] [distance : uint32] 11 | prefix - make jump if certain number (0106 or 0700) 12 | distance: distance to skip after reading last arg (distance) 13 | 14 | -- OnFlag 15 | OnFlag [prefix : uint16] [distance : uint32] 16 | jump prefix: 0106 17 | other prefixes: 0100, 0102 18 | 19 | -- ChkFlagOn 20 | ChkFlagOn [prefix : uint16] [distance : uint32] 21 | jump prefix: 0700 22 | other prefixes: 0100, 0200, 0900 23 | 24 | -- IsGameClear 25 | IsGameClear [prefix : uint16] [distance : uint32] 26 | jump prefix: 0700 27 | other prefixes: 0000, 0200 28 | 29 | -- ChkSelect 30 | ChkSelect [prefix : uint16] [distance : uint32] 31 | jump prefix: 0700 32 | other prefixes: 0100 33 | 34 | -- All 35 | series of skips ended on: 36 | (6x) 02 00 06 37 | (9x) 02 00 04 38 | (3x) 08 05 00 39 | (1x) 09 00 02 40 | (probably nothing special, but good for confirmation) 41 | 42 | -- Double-skip 43 | if after skipping distance we have double-skip code: 44 | 0x06 [distance : uint32] 45 | skip that distance again. do it until as many times as needed. 46 | 47 | ------ IsRecollectMode Jump 48 | IsRecollectMode [prefix1 : uint16] [distance1 : uint32] [prefix2 : uint16] [distance2 : uint32] 49 | prefix1: make jump by distance1 if 0700 50 | other prefixes1: 0000, 0200 51 | prefix2: make jump by distance2 if 0506 (only if prefix1 made jump) 52 | other prefixes2: 0200 53 | distance1, distance2: distance to skip after reading distance1/distance2 arg (the one to skip from) 54 | 55 | skips1 end on: 56 | (9x) 08 05 00 57 | (17x) 02 00 06 58 | (1x) 02 00 04 59 | skips2 end on: 60 | (all, 9x) 04 00 00 00 00 00 00 00 00 02 00 06 [US] 61 | (probably nothing special, but good for confirmation) 62 | 63 | ----- Choices 64 | Sequence of 2 choices is as follows: 65 | 02 00 06 66 | [choice1 : US] 67 | 02 00 04 00 00 00 00 08 05 02 00 00 00 68 | ["AddSelect" : US] 69 | 01 02 00 06 70 | [choice2 : US] 71 | 02 00 04 00 00 00 00 08 05 02 00 00 00 72 | ["AddSelect" : US] 73 | 01 02 03 04 74 | presumably the part between stars can be repeated as many times as needed. 75 | 76 | ----- Hitret (untested) 77 | probable combination for Hitret (command to split into another page, that could be used to split 78 | messages into 3-line-long pages): 79 | 04 [index : uint16] 80 | 00 00 08 05 01 00 00 00 06 00 00 00 48 00 69 00 81 | 74 00 72 00 65 00 74 00 03 FF 01 02 03 04 01 00 82 | 00 00 02 00 04 1E 00 00 00 0E 01 02 03 04 01 00 83 | 00 00 02 00 04 14 00 00 00 0E 01 0C 06 07 00 46 84 | 00 00 00 02 00 06 0D 00 00 00 45 00 58 00 49 00 85 | 54 00 5F 00 53 00 43 00 45 00 4E 00 41 00 52 00 86 | 49 00 4F 00 08 05 01 00 00 00 06 00 00 00 43 00 87 | 68 00 61 00 6E 00 67 00 65 00 01 02 00 04 00 00 88 | 00 00 09 00 06 1F 00 00 00 02 03 04 01 00 00 00 89 | 02 00 04 28 00 00 00 0E 01 07 00 09 00 00 00 02 90 | 00 04 00 00 00 00 09 00 91 | where index is some kind of counter increased by 1 after each message 92 | 93 | 94 | ===== Yosuga no Sora specific notes 95 | - in name field, there is place for 20 half-width characters in 1 line 96 | - in message, there is place for 56 half-width characters in a line and there are 3 lines 97 | - both name field and message field are automatically scrolled if not enough lines 98 | - we don't need to split messages into Talk and Mess parts - it is done by the game engine 99 | -------------------------------------------------------------------------------- /docs/CSX English Notes.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheRealMrWicked/CSXTool/e4b7bf9978e7dffbdadee328b39bf98a0becd195/docs/CSX English Notes.txt -------------------------------------------------------------------------------- /docs/CSX Image File.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheRealMrWicked/CSXTool/e4b7bf9978e7dffbdadee328b39bf98a0becd195/docs/CSX Image File.pdf -------------------------------------------------------------------------------- /docs/CSX Parser Jumps.rtf: -------------------------------------------------------------------------------- 1 | {\rtf1\ansi\ansicpg1251\uc2\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1049\deflangfe2052{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;} 2 | {\f2\fmodern\fcharset0\fprq1{\*\panose 02070309020205020404}Courier New;}{\f11\froman\fcharset128\fprq1{\*\panose 02020609040205080304}\'82\'6c\'82\'72 \'96\'be\'92\'a9{\*\falt ?l?r ???fc};} 3 | {\f37\froman\fcharset128\fprq1{\*\panose 02020609040205080304}@\'82\'6c\'82\'72 \'96\'be\'92\'a9;}{\f44\froman\fcharset238\fprq2 Times New Roman CE;}{\f45\froman\fcharset204\fprq2 Times New Roman Cyr;}{\f47\froman\fcharset161\fprq2 Times New Roman Greek;} 4 | {\f48\froman\fcharset162\fprq2 Times New Roman Tur;}{\f49\froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\f50\froman\fcharset178\fprq2 Times New Roman (Arabic);}{\f51\froman\fcharset186\fprq2 Times New Roman Baltic;} 5 | {\f52\froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\f64\fmodern\fcharset238\fprq1 Courier New CE;}{\f65\fmodern\fcharset204\fprq1 Courier New Cyr;}{\f67\fmodern\fcharset161\fprq1 Courier New Greek;} 6 | {\f68\fmodern\fcharset162\fprq1 Courier New Tur;}{\f69\fmodern\fcharset177\fprq1 Courier New (Hebrew);}{\f70\fmodern\fcharset178\fprq1 Courier New (Arabic);}{\f71\fmodern\fcharset186\fprq1 Courier New Baltic;} 7 | {\f72\fmodern\fcharset163\fprq1 Courier New (Vietnamese);}{\f156\froman\fcharset0\fprq1 MS Mincho Western{\*\falt ?l?r ???fc};}{\f154\froman\fcharset238\fprq1 MS Mincho CE{\*\falt ?l?r ???fc};} 8 | {\f155\froman\fcharset204\fprq1 MS Mincho Cyr{\*\falt ?l?r ???fc};}{\f157\froman\fcharset161\fprq1 MS Mincho Greek{\*\falt ?l?r ???fc};}{\f158\froman\fcharset162\fprq1 MS Mincho Tur{\*\falt ?l?r ???fc};} 9 | {\f161\froman\fcharset186\fprq1 MS Mincho Baltic{\*\falt ?l?r ???fc};}{\f416\froman\fcharset0\fprq1 @\'82\'6c\'82\'72 \'96\'be\'92\'a9 Western;}{\f414\froman\fcharset238\fprq1 @\'82\'6c\'82\'72 \'96\'be\'92\'a9 CE;} 10 | {\f415\froman\fcharset204\fprq1 @\'82\'6c\'82\'72 \'96\'be\'92\'a9 Cyr;}{\f417\froman\fcharset161\fprq1 @\'82\'6c\'82\'72 \'96\'be\'92\'a9 Greek;}{\f418\froman\fcharset162\fprq1 @\'82\'6c\'82\'72 \'96\'be\'92\'a9 Tur;} 11 | {\f421\froman\fcharset186\fprq1 @\'82\'6c\'82\'72 \'96\'be\'92\'a9 Baltic;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0; 12 | \red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;\red51\green153\blue102;\red255\green102\blue0; 13 | \red153\green153\blue153;}{\stylesheet{\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs24\lang1049\langfe1049\cgrid\langnp1049\langfenp1049 \snext0 Normal;}{\*\cs10 \additive \ssemihidden Default Paragraph Font;}{\* 14 | \ts11\tsrowd\trftsWidthB3\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\trcbpat1\trcfpat1\tscellwidthfts0\tsvertalt\tsbrdrt\tsbrdrl\tsbrdrb\tsbrdrr\tsbrdrdgl\tsbrdrdgr\tsbrdrh\tsbrdrv 15 | \ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs20\lang1024\langfe1024\cgrid\langnp1024\langfenp1024 \snext11 \ssemihidden Normal Table;}}{\*\rsidtbl \rsid1471889\rsid1597492\rsid1710997\rsid2364253\rsid2893799\rsid3432392 16 | \rsid4216197\rsid5972573\rsid7559999\rsid7946097\rsid8469683\rsid8525371\rsid13924250\rsid14577774\rsid14707771\rsid16676260}{\*\generator Microsoft Word 10.0.6612;}{\info 17 | {\title 11C500 11C507 11C509 11C518 11C525 11C52C 11C53E 11C53F 11C57A 11C58C 11C58D 11C59A 11C5AC 11C5AD}{\author Proger_XP}{\operator Proger_XP}{\creatim\yr2009\mo5\dy28\hr14\min28}{\revtim\yr2009\mo5\dy29\hr22\min23}{\version11}{\edmins75}{\nofpages1} 18 | {\nofwords208}{\nofchars1189}{\nofcharsws1395}{\vern16389}}\paperw11906\paperh16838\margl1701\margr850\margt1134\margb1134\gutter0 19 | \deftab708\widowctrl\ftnbj\aenddoc\noxlattoyen\expshrtn\noultrlspc\dntblnsbdb\nospaceforul\hyphcaps0\formshade\horzdoc\dgmargin\dghspace180\dgvspace180\dghorigin1701\dgvorigin1134\dghshow1\dgvshow1 20 | \jexpand\viewkind1\viewscale100\pgbrdrhead\pgbrdrfoot\splytwnine\ftnlytwnine\htmautsp\nolnhtadjtbl\useltbaln\alntblind\lytcalctblwd\lyttblrtgr\lnbrkrule\nobrkwrptbl\snaptogridincell\allowfieldendsel\wrppunct\asianbrkrule\rsidroot1471889 \fet0\sectd 21 | \linex0\headery708\footery708\colsx708\endnhere\sectlinegrid360\sectdefaultcl\sftnbj {\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang {\pntxta \hich .}}{\*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang {\pntxta \hich .}}{\*\pnseclvl3 22 | \pndec\pnstart1\pnindent720\pnhang {\pntxta \hich .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang {\pntxta \hich )}}{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang {\pntxtb \hich (}{\pntxta \hich )}}{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang 23 | {\pntxtb \hich (}{\pntxta \hich )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb \hich (}{\pntxta \hich )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb \hich (}{\pntxta \hich )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang 24 | {\pntxtb \hich (}{\pntxta \hich )}}\pard\plain \qc \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid2364253 \fs24\lang1049\langfe1049\cgrid\langnp1049\langfenp1049 { 25 | \fs32\lang1024\langfe1024\noproof\langnp1033\insrsid2364253\charrsid3432392 Entis CSX: }{\b\fs32\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid2364253\charrsid3432392 Cotopha Image file}{ 26 | \b\fs32\lang1024\langfe1024\noproof\langnp1033\insrsid2364253\charrsid3432392 27 | \par }{\i\lang1024\langfe1024\noproof\langnp1033\insrsid2364253\charrsid2364253 (}{\i\cf15\lang1024\langfe1024\noproof\langnp1033\insrsid2364253\charrsid3432392 Wanko to Lily,}{\i\lang1024\langfe1024\noproof\langnp1033\insrsid2364253\charrsid2364253 system\\ 28 | wanko.csx}{\i\cf15\lang1024\langfe1024\noproof\langnp1033\insrsid2364253\charrsid3432392 , 3 813 713 bytes}{\i\lang1024\langfe1024\noproof\langnp1033\insrsid2364253\charrsid2364253 ) 29 | \par }\pard \ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid2364253 {\lang1024\langfe1024\noproof\langnp1033\insrsid2364253 30 | \par }{\lang1024\langfe1024\noproof\langnp1033\insrsid3432392 31 | \par }{\i\lang1024\langfe1024\noproof\langnp1033\insrsid14577774\charrsid14577774 parser jumps: 32 | \par }\pard \ql \li180\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin180\itap0\pararsid14577774 {\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1597492 11C}{ 33 | \fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid1597492 4}{\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid7946097\charrsid1597492 FF}{\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1597492\charrsid1597492 }{ 34 | \lang1024\langfe1024\noproof\langnp1033\insrsid1597492\charrsid1597492 \uc1\u8594\'3f}{\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1597492\charrsid1597492 }{\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid1597492 35 | 11C50}{\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid7946097\charrsid1597492 6}{\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1597492\charrsid1597492 \uc1\u8594\'3f }{ 36 | \fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1597492 11C50}{\fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid7946097\charrsid1597492 8}{\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1597492\charrsid1597492 37 | \uc1\u8594\'3f }{\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid1597492 11C51}{\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid7946097\charrsid1597492 7}{ 38 | \fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1597492\charrsid1597492 \uc1\u8594\'3f }{\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1597492 11C52}{ 39 | \fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid7946097\charrsid1597492 4}{\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1597492\charrsid1597492 \uc1\u8594\'3f }{ 40 | \fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid1597492 11C52}{\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid7946097\charrsid1597492 B}{ 41 | \fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1597492\charrsid1597492 \uc1\u8594\'3f }{\fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1597492 11C53}{ 42 | \fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid7946097\charrsid1597492 D}{\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1597492\charrsid1597492 \uc1\u8594\'3f}{\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid13924250 }{ 43 | \cf17\lang1024\langfe1024\loch\af11\hich\af11\dbch\af11\noproof\langnp1033\insrsid13924250\charrsid2893799 \loch\af11\hich\af11\dbch\f11 \uc1\u10112\'3f}{\cf17\lang1024\langfe1024\loch\af11\hich\af11\dbch\af11\noproof\langnp1033\insrsid13924250 44 | \hich\af11\dbch\af11\loch\f11 }{\fs20\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid1471889\charrsid1710997 11C53}{\fs20\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid7946097\charrsid1710997 E}{ 45 | \fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1597492\charrsid1597492 \uc1\u8594\'3f }{\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1597492 11C57}{ 46 | \fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid7946097\charrsid1597492 9}{\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1597492\charrsid1597492 \uc1\u8594\'3f }{ 47 | \fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid1597492 11C58}{\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid7946097\charrsid1597492 B}{ 48 | \fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1597492\charrsid1597492 \uc1\u8594\'3f }{\cf5\lang1024\langfe1024\loch\af11\hich\af11\dbch\af11\noproof\langnp1033\insrsid13924250\charrsid2893799 \loch\af11\hich\af11\dbch\f11 \uc1\u10113\'3f}{ 49 | \cf5\lang1024\langfe1024\loch\af11\hich\af11\dbch\af11\noproof\langnp1033\insrsid13924250 \hich\af11\dbch\af11\loch\f11 }{\fs20\cf8\lang1024\langfe1024\highlight5\noproof\langnp1033\insrsid1471889\charrsid2893799 11C58}{ 50 | \fs20\cf8\lang1024\langfe1024\highlight5\noproof\langnp1033\insrsid7946097\charrsid2893799 C}{\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1597492\charrsid1597492 \uc1\u8594\'3f }{ 51 | \fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid1597492 11C59}{\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid7946097\charrsid1597492 9}{ 52 | \fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1597492\charrsid1597492 \uc1\u8594\'3f }{\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1597492 11C5A}{ 53 | \fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid7946097\charrsid1597492 B}{\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1597492\charrsid1597492 \uc1\u8594\'3f }{ 54 | \fs20\cf15\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1597492 11C5A}{\fs20\cf15\lang1024\langfe1024\noproof\langnp1033\insrsid7946097\charrsid1597492 C}{\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1597492 55 | \par }\pard \ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid1471889 {\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889 56 | \par }{\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1597492\charrsid1471889 57 | \par }{\f2\fs20\cf18\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 0011C4FC }{\f2\fs20\cf15\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid7559999 00 00 00}{ 58 | \f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 }{\f2\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid7559999 02}{\f2\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid7559999 }{ 59 | \f2\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid7559999 }{\f2\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 00 04 02 00 00 00 }{ 60 | \f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid7559999 0E 01}{\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid7559999 }{\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid7559999 }{ 61 | \f2\fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid7559999 07}{\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 }{ 62 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ....}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 63 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ....}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 64 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ....}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 65 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 .}{\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889 66 | \par }{\f2\fs20\cf18\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 0011C509 }{\f2\fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 00 09 00 00 }{ 67 | \f2\fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid7559999 }{\f2\fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 00 02 00 04 00 00 00 00 }{\f2\fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid7559999 }{ 68 | \f2\fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 09}{\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 }{ 69 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ....}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 70 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ....}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 71 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ....}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 72 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 . 73 | \par }{\f2\fs20\cf18\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 0011C516 }{\f2\fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 00 }{ 74 | \f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid7559999 02 00 06 }{\f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid7559999 }{ 75 | \f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid7559999 03 00 00 00 C3 5F 6E 30}{\f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid7559999 }{ 76 | \f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid7559999 F0}{\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid7559999 }{ 77 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ....}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 78 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ....}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 79 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 A_n0}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 80 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ? 81 | \par }{\f2\fs20\cf18\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 0011C523 }{\f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid7559999 58 02}{ 82 | \f2\fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid8525371 }{\f2\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 00 04 }{\f2\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid7559999 }{ 83 | \f2\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 00 00 00 00 }{\b\f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid4216197 08 05 02 00}{ 84 | \f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid1471889 }{\f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid7559999 }{ 85 | \f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid1471889 00}{\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 X...}{ 86 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ....}{ 87 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ....}{ 88 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 . 89 | \par }{\f2\fs20\cf18\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 0011C530 }{\f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid1471889 00 04 00 00 }{ 90 | \f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid7559999 }{\f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid1471889 00 }{ 91 | \f2\fs20\cf17\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid5972573 54 00 61 00 6C 00 6B }{\f2\fs20\cf17\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid7559999\charrsid5972573 }{ 92 | \f2\fs20\cf17\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid5972573 00}{\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 93 | ....}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 .}{ 94 | \f2\fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid4216197 T.a}{\f2\fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid4216197 }{ 95 | \f2\fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid4216197 .l.k}{\f2\fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid4216197 }{ 96 | \f2\fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid4216197 . 97 | \par }{\f2\fs20\cf18\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 0011C53D }{\f2\fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid7946097 01}{ 98 | \f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid8525371 }{\f2\fs20\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid1471889\charrsid1597492 02 00 06 }{ 99 | \f2\fs20\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid7559999\charrsid1597492 }{\i\f2\fs20\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid1471889\charrsid1597492 1A 00 00 00}{ 100 | \f2\fs20\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid1471889\charrsid1597492 }{\f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid1471889\charrsid1597492 00 30 BF 7D }{ 101 | \f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid7559999\charrsid1597492 }{\f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid1471889\charrsid1597492 D3}{ 102 | \f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ....}{ 103 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ....}{ 104 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 .0?\}}{ 105 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 O 106 | \par }{\f2\fs20\cf18\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 0011C54A }{\f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid1471889\charrsid1597492 83 50 5B 7F }{ 107 | \f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid7559999\charrsid1597492 }{\f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid1471889\charrsid1597492 30 5F 30 44 30 6A 30 1F }{ 108 | \f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid7559999\charrsid1597492 }{\f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid1471889\charrsid1597492 77}{ 109 | \f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ?P[}{ 110 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 0_0D}{ 111 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 0j0.}{ 112 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 w 113 | \par }{\f2\fs20\cf18\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 0011C557 }{\f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid1471889\charrsid1597492 63 30 7D 76 }{ 114 | \f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid7559999\charrsid1597492 }{\f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid1471889\charrsid1597492 67 30 06 52 9A 53 44 30 }{ 115 | \f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid7559999\charrsid1597492 }{\f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid1471889\charrsid1597492 F2}{ 116 | \f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 c0\}v}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 117 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 g0.R}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 118 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 sSD0}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 119 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 o}{\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 120 | \par }{\f2\fs20\cf18\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 0011C564 }{\f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid1471889\charrsid1597492 96 4C 30 01 }{ 121 | \f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid7559999\charrsid1597492 }{\f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid1471889\charrsid1597492 30 6E 30 93 30 73 30 8A }{ 122 | \f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid7559999\charrsid1597492 }{\f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid1471889\charrsid1597492 30}{ 123 | \lang1024\langfe1024\noproof\langnp1033\insrsid1471889 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 \endash L0.}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 124 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 0n0\'93}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 125 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 0s0S}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 126 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 0}{\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 127 | \par }{\f2\fs20\cf18\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 0011C571 }{\f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid1471889\charrsid1597492 68 30 41 6D }{ 128 | \f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid7559999\charrsid1597492 }{\f2\fs20\ul\cf8\lang1024\langfe1024\highlight11\noproof\langnp1033\insrsid1471889\charrsid1597492 8C 30 66 30}{ 129 | \f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid7946097 }{\b\f2\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid14707771 08}{\b\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid14707771 130 | }{\b\f2\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid14707771 05 01 00}{\f2\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 }{\f2\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid7559999 }{ 131 | \f2\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 00 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 h0Am}{ 132 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ?0f0}{ 133 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ....}{ 134 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 .}{\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 135 | 136 | \par }{\f2\fs20\cf18\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 0011C57E }{\f2\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 00 04 00 00 }{ 137 | \f2\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid7559999 }{\f2\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 00 }{\f2\fs20\cf5\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid5972573 138 | 4D 00 65 00 73 00 73 }{\f2\fs20\cf5\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid5972573 }{\f2\fs20\cf5\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid5972573 00}{ 139 | \f2\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ....}{ 140 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 .}{ 141 | \f2\fs20\cf5\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid4216197 M.e}{\f2\fs20\cf5\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid4216197 }{ 142 | \f2\fs20\cf5\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid4216197 .s.s}{\f2\fs20\cf5\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid4216197 }{ 143 | \f2\fs20\cf5\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid4216197 . 144 | \par }{\f2\fs20\cf18\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 0011C58B }{\f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid8469683 01}{ 145 | \f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid8469683 }{\f2\fs20\cf8\lang1024\langfe1024\highlight5\noproof\langnp1033\insrsid1471889\charrsid2893799 02 00 06 }{ 146 | \f2\fs20\cf8\lang1024\langfe1024\highlight5\noproof\langnp1033\insrsid7559999\charrsid2893799 }{\i\f2\fs20\cf8\lang1024\langfe1024\highlight5\noproof\langnp1033\insrsid1471889\charrsid2893799 03 00 00 00}{ 147 | \f2\fs20\cf8\lang1024\langfe1024\highlight5\noproof\langnp1033\insrsid1471889\charrsid2893799 }{\f2\fs20\ul\cf8\lang1024\langfe1024\highlight5\noproof\langnp1033\insrsid1471889\charrsid4216197 44 30 8B 30}{ 148 | \f2\fs20\ul\cf8\lang1024\langfe1024\highlight5\noproof\langnp1033\insrsid7559999\charrsid4216197 }{\f2\fs20\ul\cf8\lang1024\langfe1024\highlight5\noproof\langnp1033\insrsid1471889\charrsid4216197 02}{ 149 | \f2\fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid4216197 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ....}{ 150 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ....}{ 151 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 D0\'8b0}{ 152 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 .}{ 153 | \f2\fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid8525371 154 | \par }{\f2\fs20\cf18\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 0011C598 }{\f2\fs20\ul\cf8\lang1024\langfe1024\highlight5\noproof\langnp1033\insrsid1471889\charrsid4216197 30}{ 155 | \f2\fs20\cf17\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid8525371 }{\b\f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid1710997 08 05 01 }{ 156 | \b\f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid7559999\charrsid1710997 }{\b\f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid1710997 00}{ 157 | \f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid8525371 00 00 04 00 00 00 4D}{\f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid7559999 }{ 158 | \f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid8525371 00}{\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 }{ 159 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 0...}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 160 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ....}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 161 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ...M}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 162 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 .}{\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 163 | \par }{\f2\fs20\cf18\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 0011C5A5 }{\f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid8525371 65 00 73 00 }{ 164 | \f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid7559999 }{\f2\fs20\lang1024\langfe1024\highlight7\noproof\langnp1033\insrsid1471889\charrsid8525371 73 00}{\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid14707771 165 | }{\f2\fs20\cf6\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid14707771 01 }{\f2\fs20\cf15\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid8525371 02 03 04 02 00 }{ 166 | \f2\fs20\cf15\lang1024\langfe1024\noproof\langnp1033\insrsid7559999 }{\f2\fs20\cf15\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid8525371 00}{\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 }{ 167 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 e.s.}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 168 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 s...}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 169 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 ....}{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{ 170 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid16676260 .}{\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid1471889 171 | \par }\pard \ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid8525371 {\f2\fs20\cf18\lang1024\langfe1024\noproof\langnp1033\insrsid8525371\charrsid16676260 0011C5B2 }{ 172 | \f2\fs20\cf15\lang1024\langfe1024\noproof\langnp1033\insrsid8525371\charrsid8525371 00 02 00 04 }{\f2\fs20\cf15\lang1024\langfe1024\noproof\langnp1033\insrsid7559999 }{\f2\fs20\cf15\lang1024\langfe1024\noproof\langnp1033\insrsid8525371\charrsid8525371 173 | 97 09 00 00 08 05 01 00}{\f2\fs20\cf15\lang1024\langfe1024\noproof\langnp1033\insrsid7559999 }{\f2\fs20\cf15\lang1024\langfe1024\noproof\langnp1033\insrsid8525371\charrsid8525371 00}{ 174 | \f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid8525371\charrsid8525371 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid8525371\charrsid16676260 ....}{ 175 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid8525371\charrsid16676260 \emdash ...}{ 176 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid8525371\charrsid16676260 ....}{ 177 | \f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid7559999\charrsid16676260 }{\f2\fs20\cf19\lang1024\langfe1024\noproof\langnp1033\insrsid8525371\charrsid16676260 .}{ 178 | \f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid1471889\charrsid14577774 179 | \par }{\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid14707771 180 | \par }{\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid14707771\charrsid14707771 181 | \par }\pard \qc \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14707771 {\i\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid14707771\charrsid14707771 Total characters}{ 182 | \f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid14707771 | }{\f2\fs20\ul\lang1024\langfe1024\noproof\langnp1033\insrsid14707771 Unicode string}{\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid14707771\charrsid14707771 | }{ 183 | \b\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid4216197 Next command}{\b\f2\fs20\lang1024\langfe1024\noproof\langnp1033\insrsid14707771 184 | \par }{\lang1024\langfe1024\noproof\langnp1033\insrsid14707771\charrsid1597492 185 | \par }\pard \qc \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid1710997 {\cf17\lang1024\langfe1024\loch\af11\hich\af11\dbch\af11\noproof\langnp1033\langfenp1041\insrsid2893799\charrsid2893799 \loch\af11\hich\af11\dbch\f11 186 | \uc1\u10112\'3f}{\lang1024\langfe1024\loch\af11\hich\af11\dbch\af11\noproof\langnp1033\langfenp1041\insrsid2893799\charrsid2893799 \loch\af11\hich\af11\dbch\f11 \u12288\'81\'40}{ 187 | \lang1024\langfe1024\dbch\af11\noproof\langfenp1041\insrsid14707771\charrsid1710997 \loch\af0\hich\af0\dbch\f11 \u32191\'96\'c8\loch\af0\hich\af0\dbch\f11 \u-31789\'89\'d9\loch\af0\hich\af0\dbch\f11 \u23376\'8e\'71\loch\af0\hich\af0\dbch\f11 \u12415 188 | \'82\'dd\loch\af0\hich\af0\dbch\f11 \u12383\'82\'bd\loch\af0\hich\af0\dbch\f11 \u12356\'82\'a2\loch\af0\hich\af0\dbch\f11 \u12394\'82\'c8\loch\af0\hich\af0\dbch\f11 \u30495\'90\'5e\loch\af0\hich\af0\dbch\f11 \u12387\'82\'c1\loch\af0\hich\af0\dbch\f11 189 | \u30333\'94\'92\loch\af0\hich\af0\dbch\f11 \u12391\'82\'c5\loch\af0\hich\af0\dbch\f11 \u20998\'95\'aa\loch\af0\hich\af0\dbch\f11 \u21402\'8c\'fa\loch\af0\hich\af0\dbch\f11 \u12356\'82\'a2\loch\af0\hich\af0\dbch\f11 \u-26894\'89\'5f 190 | \loch\af0\hich\af0\dbch\f11 \u12364\'82\'aa\loch\af0\hich\af0\dbch\f11 \u12289\'81\'41\loch\af0\hich\af0\dbch\f11 \u12398\'82\'cc\loch\af0\hich\af0\dbch\f11 \u12435\'82\'f1\loch\af0\hich\af0\dbch\f11 \u12403\'82\'d1\loch\af0\hich\af0\dbch\f11 \u12426 191 | \'82\'e8\loch\af0\hich\af0\dbch\f11 \u12392\'82\'c6\loch\af0\hich\af0\dbch\f11 \u27969\'97\'ac\loch\af0\hich\af0\dbch\f11 \u12428\'82\'ea\loch\af0\hich\af0\dbch\f11 \u12390\'82\'c4}{ 192 | \lang1024\langfe1024\dbch\af11\noproof\langnp1033\langfenp1041\insrsid14707771\charrsid2893799 193 | \par }{\cf5\lang1024\langfe1024\loch\af11\hich\af11\dbch\af11\noproof\langnp1033\insrsid2893799\charrsid2893799 \loch\af11\hich\af11\dbch\f11 \uc1\u10113\'3f}{\lang1024\langfe1024\loch\af11\hich\af11\dbch\af11\noproof\langnp1033\insrsid2893799\charrsid2893799 194 | \loch\af11\hich\af11\dbch\f11 \u12288\'81\'40}{\lang1024\langfe1024\dbch\af11\noproof\insrsid1710997\charrsid1710997 \loch\af0\hich\af0\dbch\f11 \u12356\'82\'a2\loch\af0\hich\af0\dbch\f11 \u12427\'82\'e9\loch\af0\hich\af0\dbch\f11 \u12290\'81\'42}{ 195 | \lang1024\langfe1024\dbch\af11\noproof\insrsid1710997\charrsid1710997 196 | \par }} -------------------------------------------------------------------------------- /docs/CSX Russian Notes.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheRealMrWicked/CSXTool/e4b7bf9978e7dffbdadee328b39bf98a0becd195/docs/CSX Russian Notes.txt -------------------------------------------------------------------------------- /functionsection.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "functionsection.h" 5 | 6 | void FunctionSection::updateOffsets(const PositionComputer &posCom) { 7 | char *curr = content; 8 | const char *sectionEnd = content + size; 9 | 10 | if (size < 4) { 11 | throw std::runtime_error("Corrupted function section (size too small)."); 12 | } 13 | 14 | uint32_t offsetsCount1 = *((uint32_t *)curr); 15 | curr += 4; 16 | 17 | if (size < 16 + offsetsCount1 * 4) { 18 | throw std::runtime_error("Corrupted function section (size too small)."); 19 | } 20 | 21 | for (uint32_t i = 0; i < offsetsCount1; ++i) { 22 | uint32_t offset = *((uint32_t *)curr); 23 | *((uint32_t *)curr) = posCom.position(offset); 24 | curr += 4; 25 | } 26 | 27 | curr += 4; 28 | uint32_t offsetsCount2 = *((uint32_t *)curr); 29 | curr += 4; 30 | 31 | for (uint32_t i = 0; i < offsetsCount2; ++i) { 32 | if (curr + 8 >= sectionEnd) { 33 | std::stringstream msg; 34 | msg << "Corrupted function section (unexpected end of record at byte 0x" << std::hex << position + 16 + (uint32_t)(curr - content) << ")."; 35 | throw std::runtime_error(msg.str()); 36 | } 37 | uint32_t offset = *((uint32_t *)curr); 38 | *((uint32_t *)curr) = posCom.position(offset); 39 | curr += 4; 40 | uint32_t nameLen = *((uint32_t *)curr); 41 | curr += 4 + nameLen * 2; 42 | if (curr > sectionEnd) { 43 | std::stringstream msg; 44 | msg << "Corrupted function section (unexpected end of record at byte 0x" << std::hex << position + 16 + (uint32_t)(curr - content) << ")."; 45 | throw std::runtime_error(msg.str()); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /functionsection.h: -------------------------------------------------------------------------------- 1 | #ifndef FUNCTIONSECTION_H 2 | #define FUNCTIONSECTION_H 3 | 4 | #include 5 | #include "section.h" 6 | #include "positioncomputer.h" 7 | 8 | class FunctionSection : public Section { 9 | public: 10 | void updateOffsets(const PositionComputer &posCom); 11 | }; 12 | 13 | #endif // FUNCTIONSECTION_H 14 | -------------------------------------------------------------------------------- /header.cpp: -------------------------------------------------------------------------------- 1 | #include "header.h" 2 | 3 | std::ifstream &operator >>(std::ifstream &fin, Header &header) { 4 | fin.read((char *)header.fileType, 8); 5 | fin.read((char *)&header.unknown1, 4); 6 | fin.read((char *)&header.zero, 4); 7 | fin.read((char *)header.imageType, 40); 8 | fin.read((char *)&header.size, 4); 9 | fin.read((char *)&header.unknown2, 4); 10 | return fin; 11 | } 12 | 13 | std::ofstream &operator <<(std::ofstream &fout, const Header &header) { 14 | fout.write((const char *)header.fileType, 8); 15 | fout.write((const char *)&header.unknown1, 4); 16 | fout.write((const char *)&header.zero, 4); 17 | fout.write((const char *)header.imageType, 40); 18 | fout.write((const char *)&header.size, 4); 19 | fout.write((const char *)&header.unknown2, 4); 20 | return fout; 21 | } 22 | -------------------------------------------------------------------------------- /header.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_H 2 | #define HEADER_H 3 | 4 | #include 5 | #include 6 | 7 | struct Header { 8 | char fileType[8]; 9 | uint32_t unknown1; 10 | uint32_t zero; 11 | char imageType[40]; 12 | uint32_t size; 13 | uint32_t unknown2; 14 | }; 15 | 16 | std::ifstream &operator >>(std::ifstream &fin, Header &header); 17 | std::ofstream &operator <<(std::ofstream &fout, const Header &header); 18 | 19 | #endif // HEADER_H 20 | -------------------------------------------------------------------------------- /imagesection.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "imagesection.h" 11 | #include "talk.h" 12 | 13 | static const char chkFlagOnShortHop[] = { 0x09, 0x00, 0x00, 0x00, 'C', 0x00, 'h', 0x00, 'k', 0x00, 'F', 0x00, 'l', 0x00, 'a', 0x00, 'g', 0x00, 'O', 0x00, 'n', 0x00 }; 14 | static const char chkSelectShortHop[] = { 0x09, 0x00, 0x00, 0x00, 'C', 0x00, 'h', 0x00, 'k', 0x00, 'S', 0x00, 'e', 0x00, 'l', 0x00, 'e', 0x00, 'c', 0x00, 't', 0x00 }; 15 | static const char onFlagShortHop[] = { 0x06, 0x00, 0x00, 0x00, 'O', 0x00, 'n', 0x00, 'F', 0x00, 'l', 0x00, 'a', 0x00, 'g', 0x00 }; 16 | static const char isGameClearShortHop[] = { 0x0b, 0x00, 0x00, 0x00, 'I', 0x00, 's', 0x00, 'G', 0x00, 'a', 0x00, 'm', 0x00, 'e', 0x00, 'C', 0x00, 'l', 0x00, 'e', 0x00, 'a', 0x00, 'r', 0x00 }; 17 | static const char isRecollectModeShortHop[] = { 0x0f, 0x00, 0x00, 0x00, 'I', 0x00, 's', 0x00, 'R', 0x00, 'e', 0x00, 'c', 0x00, 'o', 0x00, 'l', 0x00, 'l', 0x00, 'e', 0x00, 'c', 0x00, 't', 0x00, 'M', 0x00, 'o', 0x00, 'd', 0x00, 'e', 0x00 }; 18 | static const uint16_t jumpPrefixArg1[] = { 0x0601, 0x0007 }; 19 | static const uint16_t jumpPrefixArg2 = 0x0605; 20 | static const char doubleSkipPrefix = 0x06; 21 | static const char lineWidthCode[] = { 0x0F, 0xFF, 0x03, 0xFF, 0x01, 0x00, 0x01, 0x04, 0x03, 0x00, 0x00, 0x00, 0x6E, 0x00, 0x75, 0x00, 0x6D, 0x00, 0x02, 0x00, 0x04 }; 22 | 23 | void ImageSection::extractStrings() { 24 | messages.clear(); 25 | choices.clear(); 26 | 27 | int messageIndex = 1; 28 | int choiceIndex = 1; 29 | for (size_t i = 0; i < size; ++i) { 30 | try { 31 | if (isTalkPrefix(content, size, i)) { 32 | Talk talk = parseTalk(content, size, i, position + 16); 33 | talk.index = messageIndex; 34 | ++messageIndex; 35 | messages.push_back(talk); 36 | } else { 37 | Choice choice; 38 | if (tryParseChoice(&choice, content, size, i, position + 16)) { 39 | choice.index = choiceIndex; 40 | choices.push_back(choice); 41 | ++choiceIndex; 42 | } 43 | } 44 | } catch (std::runtime_error e) { 45 | std::cout << "Warning: Could not extract a talk. " << e.what() << "\n"; 46 | } 47 | } 48 | } 49 | 50 | class ImageStringGroup { 51 | public: 52 | ImageStringGroup(const Talk &talk): message(&talk), choice(0), special(0) {} 53 | ImageStringGroup(const Choice &ch): message(0), choice(&ch), special(0) {} 54 | ImageStringGroup(const Special &sp): message(0), choice(0), special(&sp) {} 55 | 56 | bool operator <(const ImageStringGroup &rhs) const { 57 | return pos() < rhs.pos(); 58 | } 59 | 60 | size_t pos() const { 61 | if (message != 0) { 62 | return message->talkPos; 63 | } else if (choice != 0) { 64 | return choice->choicePos; 65 | } else { 66 | return special->pos; 67 | } 68 | } 69 | 70 | const Talk *message; 71 | const Choice *choice; 72 | const Special *special; 73 | }; 74 | 75 | void ImageSection::substituteStrings(std::deque newMessages, std::deque newChoices, std::deque specials, bool ignoreExactLineBreaks) { 76 | for (size_t i = 0; i < specials.size(); ++i) { 77 | specials[i].pos -= contentStartByte; 78 | } 79 | 80 | posComp.reset(); 81 | 82 | // creating mapping index -> message/choice 83 | std::map newMessagesMap; 84 | for (size_t i = 0; i < newMessages.size(); ++i) { 85 | if (newMessagesMap.find(newMessages[i].index) != newMessagesMap.end()) { 86 | std::stringstream ss; 87 | ss << "Duplicate message index " << newMessages[i].index; 88 | throw std::runtime_error(ss.str()); 89 | } 90 | newMessagesMap[newMessages[i].index] = &newMessages[i]; 91 | } 92 | 93 | std::map newChoicesMap; 94 | for (size_t i = 0; i < newChoices.size(); ++i) { 95 | if (newChoicesMap.find(newChoices[i].index) != newChoicesMap.end()) { 96 | std::stringstream ss; 97 | ss << "Duplicate choice index: " << newChoices[i].index; 98 | throw std::runtime_error(ss.str()); 99 | } 100 | newChoicesMap[newChoices[i].index] = &newChoices[i]; 101 | } 102 | 103 | // initializing queue of messages and choices in order of appearance in image content 104 | std::deque origStringsQueue; 105 | for (size_t i = 0; i < messages.size(); ++i) { 106 | origStringsQueue.push_back(ImageStringGroup(messages[i])); 107 | } 108 | for (size_t i = 0; i < choices.size(); ++i) { 109 | origStringsQueue.push_back(ImageStringGroup(choices[i])); 110 | } 111 | for (size_t i = 0; i < specials.size(); ++i) { 112 | if (specials[i].pos >= size) { 113 | throw std::runtime_error("Invalid special position."); 114 | } 115 | origStringsQueue.push_back(ImageStringGroup(specials[i])); 116 | } 117 | std::sort(origStringsQueue.begin(), origStringsQueue.end()); 118 | 119 | // estimating new size of content 120 | size_t totalNewStringsSize = 0; 121 | for (size_t i = 0; i < newMessages.size(); ++i) { 122 | totalNewStringsSize += newMessages[i].speaker.byteSize() + newMessages[i].message.byteSize(); 123 | } 124 | for (size_t i = 0; i < newChoices.size(); ++i) { 125 | totalNewStringsSize += newChoices[i].byteSize(); 126 | } 127 | for (size_t i = 0; i < specials.size(); ++i) { 128 | totalNewStringsSize += specials[i].substitution.byteSize(); 129 | } 130 | 131 | // rewriting content with new messages while keeping track of changes in positions 132 | char *newContent = new char[size * 2 + totalNewStringsSize]; 133 | size_t pos = 0; 134 | size_t origPos = 0; 135 | 136 | for (size_t i = 0; i < origStringsQueue.size(); ++i) { 137 | const ImageStringGroup &origImageString = origStringsQueue[i]; 138 | 139 | if (origImageString.pos() < origPos) { 140 | throw std::runtime_error("Not disjunctive data."); 141 | } 142 | 143 | if (origImageString.message != 0) { 144 | if (newMessagesMap.find(origImageString.message->index) == newMessagesMap.end()) { 145 | continue; 146 | } 147 | 148 | const Talk &origMessage = *origImageString.message; 149 | const Talk &message = *newMessagesMap[origMessage.index]; 150 | 151 | if (origMessage.hasSpeaker()) { 152 | memcpy(newContent + pos, content + origPos, origMessage.speakerPos - origPos); 153 | pos += origMessage.speakerPos - origPos; 154 | message.speaker.writeToData(newContent + pos); 155 | pos += message.speaker.byteSize(); 156 | origPos = origMessage.speakerPos + origMessage.speaker.byteSize(); 157 | posComp.setPos(origPos, pos); 158 | } 159 | 160 | memcpy(newContent + pos, content + origPos, origMessage.talkPos - origPos); 161 | pos += origMessage.talkPos - origPos; 162 | origPos = origMessage.talkPos; 163 | pos += message.writeToData(newContent + pos, ignoreExactLineBreaks); 164 | origPos += origMessage.talkContentBytes; 165 | posComp.setPos(origPos, pos); 166 | } else if (origImageString.choice != 0) { 167 | if (newChoicesMap.find(origImageString.choice->index) == newChoicesMap.end()) { 168 | continue; 169 | } 170 | 171 | const Choice &origChoice = *origImageString.choice; 172 | const Choice &choice = *newChoicesMap[origChoice.index]; 173 | 174 | memcpy(newContent + pos, content + origPos, origChoice.choicePos - origPos); 175 | pos += origChoice.choicePos - origPos; 176 | origPos = origChoice.choicePos; 177 | pos += choice.writeToData(newContent + pos); 178 | origPos += origChoice.byteSize(); 179 | posComp.setPos(origPos, pos); 180 | } else { 181 | assert(origImageString.special != 0); 182 | 183 | const Special &special = *origImageString.special; 184 | size_t origByteSize = parseSpecialByteSize(content + special.pos, content + size, special.pos + position + 16); 185 | 186 | std::cerr << "Substituting special "; 187 | for (size_t i = 0; i < 16 && i < origByteSize; ++i) { 188 | std::cerr << std::hex << std::setw(2) << std::setfill('0') << (unsigned int) (unsigned char) (content[special.pos + i]) << " "; 189 | } 190 | if (origByteSize > 16) { 191 | std::cerr << "..."; 192 | } 193 | std::cerr << "\n"; 194 | 195 | memcpy(newContent + pos, content + origPos, special.pos - origPos); 196 | pos += special.pos - origPos; 197 | origPos = special.pos; 198 | pos += special.writeToData(newContent + pos); 199 | origPos += origByteSize; 200 | posComp.setPos(origPos, pos); 201 | } 202 | } 203 | 204 | memcpy(newContent + pos, content + origPos, size - origPos); 205 | pos += size - origPos; 206 | assert(posComp.position(size) == pos); 207 | 208 | delete[] content; 209 | content = newContent; 210 | size = pos; 211 | } 212 | 213 | void ImageSection::updateShortHops() { 214 | updatedJumpPos.clear(); 215 | 216 | for (size_t i = 0; i < size; ++i) { 217 | Jump jump = detectJump(i); 218 | switch (jump.type) { 219 | case Jump::Jump1Arg: 220 | updateJump(jump.arg1Pos); 221 | break; 222 | 223 | case Jump::Jump2Arg: 224 | updateJump(jump.arg1Pos); 225 | updateJump(jump.arg2Pos); 226 | break; 227 | 228 | default: 229 | break; 230 | } 231 | } 232 | } 233 | 234 | void ImageSection::fixLineWidth() { 235 | for (size_t i = 0; i < size - sizeof(lineWidthCode) + 1; ++i) { 236 | bool foundLineWidthCode = true; 237 | 238 | for (size_t j = 0; j < sizeof(lineWidthCode); ++j) { 239 | if (content[i + j] != lineWidthCode[j]) { 240 | foundLineWidthCode = false; 241 | break; 242 | } 243 | } 244 | 245 | if (foundLineWidthCode) { 246 | content[i + sizeof(lineWidthCode)] = 0x38; 247 | std::cout << "Found the line width code at byte " << i << " of the content of the image section. Replacing the value with 0x38.\n"; 248 | return; 249 | } 250 | } 251 | 252 | std::cout << "Warning: Could not find the line width code. It was not replaced with 0x38.\n"; 253 | } 254 | 255 | void ImageSection::check() const { 256 | // parsing talks/choices without saving them 257 | for (size_t i = 0; i < size; ++i) { 258 | try { 259 | if (isTalkPrefix(content, size, i)) { 260 | parseTalk(content, size, i, position + 16); 261 | } else { 262 | Choice choice; 263 | tryParseChoice(&choice, content, size, i, position + 16); 264 | } 265 | } catch (std::runtime_error e) { 266 | std::cout << "Warning: Could not read a talk. " << e.what() << "\n"; 267 | } 268 | } 269 | 270 | // parsing jumps 271 | for (size_t i = 0; i < size; ++i) { 272 | Jump jump = detectJump(i); 273 | std::deque jumpPositions; 274 | switch (jump.type) { 275 | case Jump::Jump1Arg: 276 | jumpPositions.push_back(jump.arg1Pos); 277 | break; 278 | 279 | case Jump::Jump2Arg: 280 | jumpPositions.push_back(jump.arg1Pos); 281 | jumpPositions.push_back(jump.arg2Pos); 282 | break; 283 | 284 | default: 285 | break; 286 | } 287 | 288 | for (size_t i = 0; i < jumpPositions.size(); ++i) { 289 | uint32_t distance = *((uint32_t *)(content + jumpPositions[i])); 290 | if (jumpPositions[i] + distance + 5 > size) { 291 | std::stringstream msg; 292 | msg << "Short jump distance (0x" << std::hex << distance << ") out of bounds at byte 0x" << std::hex << position + 16 + jumpPositions[i] << "."; 293 | throw std::runtime_error(msg.str()); 294 | } 295 | } 296 | } 297 | } 298 | 299 | ImageSection::Jump ImageSection::detectJump(size_t pos) const { 300 | Jump jump; 301 | jump.type = Jump::NoJump; 302 | 303 | size_t currPos = pos; 304 | bool try1Arg = false; 305 | bool try2Arg = false; 306 | 307 | if (currPos + 4 >= size || content[currPos + 1] != 0 || content[currPos + 2] != 0 || content[currPos + 3] != 0) { 308 | // small optimization 309 | return jump; 310 | } else if (currPos + sizeof(chkFlagOnShortHop) + 6 <= size && memcmp(content + currPos, chkFlagOnShortHop, sizeof(chkFlagOnShortHop)) == 0) { 311 | currPos += sizeof(chkFlagOnShortHop); 312 | try1Arg = true; 313 | } else if (currPos + sizeof(chkSelectShortHop) + 6 <= size && memcmp(content + currPos, chkSelectShortHop, sizeof(chkSelectShortHop)) == 0) { 314 | currPos += sizeof(chkSelectShortHop); 315 | try1Arg = true; 316 | } else if (currPos + sizeof(onFlagShortHop) + 6 <= size && memcmp(content + currPos, onFlagShortHop, sizeof(onFlagShortHop)) == 0) { 317 | currPos += sizeof(onFlagShortHop); 318 | try1Arg = true; 319 | } else if (currPos + sizeof(isGameClearShortHop) + 6 <= size && memcmp(content + currPos, isGameClearShortHop, sizeof(isGameClearShortHop)) == 0) { 320 | currPos += sizeof(isGameClearShortHop); 321 | try1Arg = true; 322 | } else if (currPos + sizeof(isRecollectModeShortHop) + 12 <= size && memcmp(content + currPos, isRecollectModeShortHop, sizeof(isRecollectModeShortHop)) == 0) { 323 | currPos += sizeof(isRecollectModeShortHop); 324 | try1Arg = true; 325 | try2Arg = true; 326 | } 327 | 328 | if (try1Arg) { 329 | uint16_t prefix = *((uint16_t *)(content + currPos)); 330 | currPos += 2; 331 | for (size_t i = 0; i < sizeof(jumpPrefixArg1) / sizeof(jumpPrefixArg1[0]); ++i) { 332 | if (prefix == jumpPrefixArg1[i]) { 333 | jump.type = Jump::Jump1Arg; 334 | jump.arg1Pos = currPos; 335 | currPos += 4; 336 | break; 337 | } 338 | } 339 | 340 | if (try2Arg && jump.type == Jump::Jump1Arg) { 341 | uint16_t prefix = *((uint16_t *)(content + currPos)); 342 | currPos += 2; 343 | if (prefix == jumpPrefixArg2) { 344 | jump.type = Jump::Jump2Arg; 345 | jump.arg2Pos = currPos; 346 | } 347 | } 348 | } 349 | 350 | return jump; 351 | } 352 | 353 | void ImageSection::updateJump(size_t pos) { 354 | // checking if the jump wasn't updated already 355 | if (updatedJumpPos.find(pos) != updatedJumpPos.end()) { 356 | return; 357 | } 358 | 359 | updatedJumpPos.insert(pos); 360 | 361 | uint32_t distance = *((uint32_t *)(content + pos)); 362 | uint32_t delta = posComp.delta(pos + 4, distance); 363 | if (pos + distance + 5 > size) { 364 | std::stringstream msg; 365 | msg << "Original short jump distance (0x" << std::hex << distance << ") out of bounds."; 366 | throw std::runtime_error(msg.str()); 367 | } 368 | //std::cerr << "updating jump on " << std::hex << (pos + 80) << std::dec << " " << distance << " -> " << delta << "\n"; 369 | *((uint32_t *)(content + pos)) = delta; 370 | if (pos + delta + 5 > size) { 371 | throw std::runtime_error("Short jump distance out of bounds."); 372 | } 373 | 374 | if (content[pos + delta + 4] == doubleSkipPrefix) { 375 | updateJump(pos + delta + 5); 376 | } else { 377 | if ((content[pos + delta + 4] != 2 || content[pos + delta + 5] != 0 || content[pos + delta + 6] != 6) && 378 | (content[pos + delta + 4] != 2 || content[pos + delta + 5] != 0 || content[pos + delta + 6] != 4) && 379 | (content[pos + delta + 4] != 8 || content[pos + delta + 5] != 5 || content[pos + delta + 6] != 0) && 380 | (content[pos + delta + 4] != 9 || content[pos + delta + 5] != 0 || content[pos + delta + 6] != 2) && 381 | (content[pos + delta + 4] != 4 || content[pos + delta + 5] != 0 || content[pos + delta + 6] != 0)) { 382 | std::cerr << "Warning: unusual data after short jump.\n"; 383 | } 384 | } 385 | } 386 | -------------------------------------------------------------------------------- /imagesection.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGESECTION_H 2 | #define IMAGESECTION_H 3 | 4 | #include 5 | #include 6 | #include "section.h" 7 | #include "unicodestring.h" 8 | #include "positioncomputer.h" 9 | #include "talk.h" 10 | #include "choice.h" 11 | #include "special.h" 12 | 13 | class ImageSection : public Section { 14 | public: 15 | size_t contentStartByte; 16 | std::deque messages; 17 | std::deque choices; 18 | 19 | void extractStrings(); 20 | void extractChoices(); 21 | void substituteStrings(std::deque newMessages, std::deque newChoices, std::deque specials, bool ignoreExactLineBreaks); 22 | void updateShortHops(); 23 | const PositionComputer &positionsComputer() { return posComp; } 24 | void fixLineWidth(); 25 | 26 | void check() const; 27 | 28 | private: 29 | struct Jump { 30 | enum JumpType { 31 | NoJump, 32 | Jump1Arg, 33 | Jump2Arg 34 | }; 35 | 36 | JumpType type; 37 | size_t arg1Pos; 38 | size_t arg2Pos; 39 | }; 40 | 41 | Jump detectJump(size_t pos) const; 42 | void updateJump(size_t pos); 43 | 44 | PositionComputer posComp; 45 | std::set updatedJumpPos; 46 | }; 47 | 48 | #endif // IMAGESECTION_H 49 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "csxparser.h" 8 | 9 | void usage() { 10 | std::cerr << "Usage: csxtool (import [--alternativeSpace decimalFirstByteLittleEndian decimalSecondByteLittleEndian] [--ignoreExactLineBreaks] file.csx scenario1.txt [scenario2.txt scenario3.txt ...]|export file.csx)\n"; 11 | } 12 | 13 | int main(int argc, const char **argv) { 14 | if (argc < 3) { 15 | usage(); 16 | return 1; 17 | } 18 | 19 | std::cout << "csxtool 1.5\n"; 20 | 21 | char customSpace[] = { 0x20, 0x00 }; 22 | 23 | bool alternativeSpace = false; 24 | if (argc >= 6) { 25 | alternativeSpace = std::string(argv[2]) == std::string("--alternativeSpace"); 26 | customSpace[0] = std::atoi(argv[3]); 27 | customSpace[1] = std::atoi(argv[4]); 28 | 29 | if (!alternativeSpace) { 30 | alternativeSpace = std::string(argv[3]) == std::string("--alternativeSpace"); 31 | customSpace[0] = std::atoi(argv[4]); 32 | customSpace[1] = std::atoi(argv[5]); 33 | } 34 | } 35 | 36 | bool ignoreExactLineBreaks = false; 37 | if (argc >= 4) { 38 | ignoreExactLineBreaks = std::string(argv[2]) == std::string("--ignoreExactLineBreaks") || std::string(argv[3]) == std::string("--ignoreExactLineBreaks"); 39 | } 40 | 41 | std::string command(argv[1]); 42 | std::string csxFilename(argv[2 + alternativeSpace * 3 + ignoreExactLineBreaks]); 43 | std::string filenamePrefix = csxFilename.substr(0, csxFilename.find_last_of('.')); 44 | 45 | if (command == "export") { 46 | if (argc != 3) { 47 | usage(); 48 | return 1; 49 | } 50 | std::string utfFilename = filenamePrefix + ".txt"; 51 | 52 | std::cout << "Exporting " << csxFilename << " to " << utfFilename << "..." << std::endl; 53 | 54 | CSXParser csx; 55 | try { 56 | csx.exportCsx(csxFilename, utfFilename); 57 | } catch (std::runtime_error &e) { 58 | std::cerr << e.what() << "\n"; 59 | return 1; 60 | } 61 | 62 | std::cout << "Export successful!" << std::endl; 63 | return 0; 64 | } else if (command == "import") { 65 | if (argc < 4 + alternativeSpace * 3 + ignoreExactLineBreaks) { 66 | usage(); 67 | return 1; 68 | } 69 | 70 | std::string origCsxFilename = filenamePrefix + "_original.csx"; 71 | std::deque utfFilenames; 72 | for (int i = 3 + alternativeSpace * 3 + ignoreExactLineBreaks; i < argc; ++i) { 73 | utfFilenames.push_back(argv[i]); 74 | } 75 | 76 | std::cout << "Importing "; 77 | for (size_t i = 0; i < utfFilenames.size(); ++i) { 78 | if (i != 0) { 79 | std::cout << ", "; 80 | } 81 | std::cout << utfFilenames[i]; 82 | } 83 | std::cout << " and " << origCsxFilename << " to " << csxFilename << "..." << std::endl; 84 | 85 | if (alternativeSpace) { 86 | std::cout << "Alternative space mode: replacing spaces with " << (unsigned int)(unsigned char)customSpace[0] << " " << (unsigned int)(unsigned char)customSpace[1] << " UTF-16LE character." << std::endl; 87 | } 88 | 89 | if (ignoreExactLineBreaks) { 90 | std::cout << "Ignoring exact line breaks mode: not adding line breaks when the line is exactly 56 half-width characters long."; 91 | } 92 | 93 | CSXParser csx; 94 | try { 95 | csx.importCsx(origCsxFilename, csxFilename, utfFilenames, alternativeSpace ? customSpace : NULL, ignoreExactLineBreaks); 96 | } catch (std::runtime_error &e) { 97 | std::cerr << e.what() << "\n"; 98 | return 1; 99 | } 100 | 101 | std::cout << "Import successful!" << std::endl; 102 | return 0; 103 | } else { 104 | usage(); 105 | return 1; 106 | } 107 | 108 | return 0; 109 | } 110 | -------------------------------------------------------------------------------- /positioncomputer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "positioncomputer.h" 3 | 4 | size_t PositionComputer::position(size_t originalPos) const { 5 | if (offsetsMap.empty()) { 6 | return originalPos; 7 | } 8 | 9 | std::map::const_iterator it = offsetsMap.upper_bound(originalPos); 10 | 11 | if (it == offsetsMap.end()) { 12 | --it; 13 | } else if (it == offsetsMap.begin()) { 14 | return originalPos; 15 | } else { 16 | --it; 17 | } 18 | 19 | return originalPos + it->second - it->first; 20 | } 21 | 22 | std::map::const_iterator moved(std::map::const_iterator it, int direction) { 23 | if (direction >= 0) { 24 | ++it; 25 | } else { 26 | --it; 27 | } 28 | 29 | return it; 30 | } 31 | 32 | size_t PositionComputer::reversePosition(size_t pos) const { 33 | if (offsetsMap.empty() || pos < offsetsMap.begin()->second) { 34 | return pos; 35 | } 36 | 37 | std::map::const_iterator it = offsetsMap.upper_bound(pos); 38 | 39 | while (it != offsetsMap.end() && it->second < pos) { 40 | ++it; 41 | } 42 | 43 | if (it == offsetsMap.end()) { 44 | --it; 45 | } 46 | 47 | while (it->second > pos) { 48 | --it; 49 | } 50 | 51 | assert(moved(it, 1) == offsetsMap.end() || moved(it, 1)->second > pos); 52 | 53 | return pos + it->first - it->second; 54 | } 55 | 56 | size_t PositionComputer::delta(size_t pos, size_t originalDelta) const { 57 | assert(position(reversePosition(pos)) == pos); 58 | return position(reversePosition(pos) + originalDelta) - pos; 59 | } 60 | 61 | void PositionComputer::reset() { 62 | offsetsMap.clear(); 63 | } 64 | 65 | void PositionComputer::setPos(size_t origPos, size_t pos) { 66 | offsetsMap[origPos] = pos; 67 | assert(offsetsMap.find(origPos) == offsetsMap.begin() || moved(offsetsMap.find(origPos), -1)->second < pos); 68 | assert(moved(offsetsMap.find(origPos), 1) == offsetsMap.end() || moved(offsetsMap.find(origPos), 1)->second > pos); 69 | } 70 | -------------------------------------------------------------------------------- /positioncomputer.h: -------------------------------------------------------------------------------- 1 | #ifndef POSITIONCOMPUTER_H 2 | #define POSITIONCOMPUTER_H 3 | 4 | #include 5 | #include 6 | 7 | class PositionComputer { 8 | public: 9 | size_t position(size_t originalPos) const; 10 | size_t reversePosition(size_t pos) const; 11 | size_t delta(size_t pos, size_t originalDelta) const; 12 | 13 | void reset(); 14 | void setPos(size_t origPos, size_t pos); 15 | 16 | private: 17 | std::map offsetsMap; 18 | }; 19 | 20 | #endif // POSITIONCOMPUTER_H 21 | -------------------------------------------------------------------------------- /section.cpp: -------------------------------------------------------------------------------- 1 | #include "section.h" 2 | 3 | Section::Section(): 4 | content(0) { 5 | } 6 | 7 | Section::~Section() { 8 | delete[] content; 9 | } 10 | 11 | std::ifstream &operator >>(std::ifstream &fin, Section §ion) { 12 | fin.read((char *)section.id, 8); 13 | fin.read((char *)§ion.size, 4); 14 | fin.read((char *)§ion.unknown, 4); 15 | section.content = new char[section.size]; 16 | fin.read(section.content, section.size); 17 | return fin; 18 | } 19 | 20 | std::ofstream &operator <<(std::ofstream &fout, const Section §ion) { 21 | fout.write((const char *)section.id, 8); 22 | fout.write((const char *)§ion.size, 4); 23 | fout.write((const char *)§ion.unknown, 4); 24 | fout.write(section.content, section.size); 25 | return fout; 26 | } 27 | -------------------------------------------------------------------------------- /section.h: -------------------------------------------------------------------------------- 1 | #ifndef SECTION_H 2 | #define SECTION_H 3 | 4 | #include 5 | #include 6 | 7 | class Section { 8 | public: 9 | Section(); 10 | virtual ~Section(); 11 | 12 | char id[8]; 13 | uint32_t size; 14 | uint32_t unknown; 15 | char *content; 16 | 17 | // for debugging purposes 18 | uint32_t position; 19 | }; 20 | 21 | std::ifstream &operator >>(std::ifstream &fin, Section §ion); 22 | std::ofstream &operator <<(std::ofstream &fout, const Section §ion); 23 | 24 | #endif // SECTION_H 25 | -------------------------------------------------------------------------------- /special.cpp: -------------------------------------------------------------------------------- 1 | #include "special.h" 2 | 3 | size_t Special::writeToData(char *data) const { 4 | substitution.writeToData(data); 5 | return substitution.byteSize(); 6 | } 7 | 8 | size_t parseSpecialByteSize(const char *source, const char *sourceEnd, uint32_t sourcePosition) { 9 | return parseUnicodeString(source, sourceEnd, sourcePosition).byteSize(); 10 | } 11 | -------------------------------------------------------------------------------- /special.h: -------------------------------------------------------------------------------- 1 | #ifndef SPECIAL_H 2 | #define SPECIAL_H 3 | 4 | #include 5 | #include "unicodestring.h" 6 | 7 | class Special { 8 | public: 9 | Special(): pos(0) {} 10 | 11 | size_t pos; 12 | UnicodeString substitution; 13 | 14 | size_t writeToData(char *data) const; 15 | }; 16 | 17 | size_t parseSpecialByteSize(const char *source, const char *sourceEnd, uint32_t sourcePosition); 18 | 19 | #endif // SPECIAL_H 20 | -------------------------------------------------------------------------------- /talk.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "talk.h" 8 | 9 | static const char talkMsg[] = { 0x08, 0x05, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 'T', 0x00, 'a', 0x00, 'l', 0x00, 'k', 0x00, 0x01, 0x02, 0x00, 0x06 }; 10 | static const char messMsg[] = { 0x08, 0x05, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 'M', 0x00, 'e', 0x00, 's', 0x00, 's', 0x00 }; 11 | static const char finalMessPrefix[] = { 0x01, 0x02, 0x03, 0x04 }; 12 | static const char blackoutFinalMessPrefix[] = { 0x01, 0x02, 0x00, 0x04 }; 13 | static const char specialFinalMessPrefix[] = { 0x01, 0x02, 0x00, 0x06, 0x08, 0x00, 0x00, 0x00, 'C', 0x00, 'F', 0x00 }; 14 | static const char contMessPrefix[] = { 0x01, 0x02, 0x00, 0x06 }; 15 | static const char afterName1[] = { 0x02, 0x00, 0x06 }; 16 | static const char afterName1WithNull[] = { 0x02, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00 }; 17 | static const char narratorName[] = { 0xC3, 0x5F, 0x6E, 0x30, 0xF0, 0x58 }; 18 | static const char space[] = { ' ', 0x00 }; 19 | static const char scenarioNewLine[] = { 0x0F, 0xFF }; 20 | static const size_t lineWidth = 2 * 29; 21 | 22 | size_t Talk::writeToData(char *data, bool ignoreExactLineBreaks) const { 23 | size_t len = 0; 24 | memcpy(data, talkMsg, sizeof(talkMsg)); 25 | len += sizeof(talkMsg); 26 | 27 | // word wrapping 28 | // keeping whole words unless there is a word longer than line width - in that case it will be alone 29 | UnicodeString spaceUs(space, sizeof(space) / 2); 30 | UnicodeString scenarioNewLineUs(scenarioNewLine, sizeof(scenarioNewLine) / 2); 31 | UnicodeString wordWrappedMessage; 32 | 33 | std::deque lines = message.split(scenarioNewLine, sizeof(scenarioNewLine) / 2); 34 | for (size_t l = 0; l < lines.size(); ++l) { 35 | if (l != 0) { 36 | wordWrappedMessage += scenarioNewLineUs; 37 | } 38 | 39 | std::deque words = lines[l].split(space, sizeof(space) / 2); 40 | size_t currentLineWidth = 0; 41 | for (size_t i = 0; i < words.size(); ++i) { 42 | if (i != 0) { 43 | if (ignoreExactLineBreaks && currentLineWidth + scenarioNewLineUs.width() == lineWidth) { 44 | // a hack that relies on the software to word-wrap the line by simply cutting the line automatically after lineWidth characters 45 | // this is needed because scenarioNewLineUs as the last character causes the software to make two line breaks in HNS 46 | currentLineWidth = 0; 47 | } else if (currentLineWidth + spaceUs.width() + scenarioNewLineUs.width() + words[i].width() > lineWidth) { 48 | wordWrappedMessage += scenarioNewLineUs; 49 | currentLineWidth = 0; 50 | } else { 51 | wordWrappedMessage += spaceUs; 52 | currentLineWidth += spaceUs.width(); 53 | } 54 | } 55 | 56 | wordWrappedMessage += words[i]; 57 | currentLineWidth += words[i].width(); 58 | } 59 | } 60 | 61 | wordWrappedMessage.writeToData(data + len); 62 | len += wordWrappedMessage.byteSize(); 63 | 64 | return len; 65 | } 66 | 67 | bool isTalkPrefix(const char *contentBegin, size_t contentLength, size_t offset) { 68 | return offset + sizeof(talkMsg) + 6 < contentLength && memcmp(contentBegin + offset, talkMsg, sizeof(talkMsg)) == 0; 69 | } 70 | 71 | Talk parseTalk(const char *contentBegin, size_t contentLength, size_t offset, uint32_t sectionPosition) { 72 | assert(offset < contentLength); 73 | const char *contentEnd = contentBegin + contentLength; 74 | 75 | Talk talk; 76 | // parsing speaker name 77 | talk.speakerPos = 0; 78 | 79 | const char *name = 0; 80 | if (offset >= sizeof(afterName1WithNull) && memcmp(contentBegin + offset - sizeof(afterName1WithNull), afterName1WithNull, sizeof(afterName1WithNull)) == 0) { 81 | // Haruka and Kokoro no Koe 82 | name = searchBackwardsForShortUnicodeString(contentBegin, offset - sizeof(afterName1WithNull)); 83 | } else { 84 | // The rest 85 | const char *unknownId = searchBackwardsForShortUnicodeString(contentBegin, offset); 86 | int unknownIdOffset = (unknownId - sizeof(afterName1)) - contentBegin; 87 | if (unknownId != 0 && unknownIdOffset >= 0 && memcmp(unknownId - sizeof(afterName1), afterName1, sizeof(afterName1)) == 0) { 88 | name = searchBackwardsForShortUnicodeString(contentBegin, unknownIdOffset); 89 | } 90 | } 91 | 92 | if (name == 0) { 93 | std::stringstream msg; 94 | msg << "No speaker in talk at byte 0x" << std::hex << offset + sectionPosition << "."; 95 | throw std::runtime_error(msg.str()); 96 | } else { 97 | assert(name >= contentBegin); 98 | talk.speaker = parseUnicodeString(name, contentEnd, (uint32_t)(name - contentBegin) + sectionPosition); 99 | assert(name + talk.speaker.byteSize() <= contentEnd); 100 | UnicodeString narrator(narratorName, sizeof(narratorName) / 2); 101 | 102 | if (narrator == talk.speaker) { 103 | talk.speaker = UnicodeString(); 104 | } else { 105 | talk.speakerPos = name - contentBegin; 106 | } 107 | } 108 | 109 | // parsing message content 110 | talk.talkPos = offset; 111 | const char *curr = contentBegin + offset; 112 | 113 | if (!isTalkPrefix(contentBegin, contentLength, offset)) { 114 | std::stringstream msg; 115 | msg << "Invalid talk prefix at byte 0x" << std::hex << offset + sectionPosition << "."; 116 | throw std::runtime_error(msg.str()); 117 | } 118 | curr += sizeof(talkMsg); 119 | 120 | // parsing the first part of the talk (the "message") 121 | talk.message = parseUnicodeString(curr, contentEnd, (uint32_t)(curr - contentBegin) + sectionPosition); 122 | assert(curr + talk.message.byteSize() <= contentEnd); 123 | curr += talk.message.byteSize(); 124 | 125 | if (talk.message.length > lineWidth) { 126 | std::cerr << "Warning: Mess longer than two lines at byte 0x" << std::hex << (uint32_t)(curr - talk.message.byteSize() - contentBegin) + sectionPosition << ".\n"; 127 | } 128 | 129 | while (curr + sizeof(messMsg) < contentEnd && memcmp(curr, messMsg, sizeof(messMsg)) == 0) { 130 | curr += sizeof(messMsg); 131 | 132 | // end of message 133 | if ((curr + sizeof(finalMessPrefix) < contentEnd && memcmp(curr, finalMessPrefix, sizeof(finalMessPrefix)) == 0) || 134 | (curr + sizeof(specialFinalMessPrefix) < contentEnd && memcmp(curr, specialFinalMessPrefix, sizeof(specialFinalMessPrefix)) == 0) || 135 | (curr + sizeof(blackoutFinalMessPrefix) < contentEnd && memcmp(curr, blackoutFinalMessPrefix, sizeof(blackoutFinalMessPrefix)) == 0)) { 136 | talk.talkContentBytes = (curr - sizeof(messMsg)) - (contentBegin + offset); 137 | if (talk.message.length == 0) { 138 | std::cerr << "Warning: empty Mess in talk at byte 0x" << std::hex << (uint32_t)(curr - sizeof(messMsg) - talk.message.byteSize() - contentBegin) + sectionPosition << ".\n"; 139 | } 140 | return talk; 141 | // continued message 142 | } else if (curr + sizeof(contMessPrefix) < contentEnd && memcmp(curr, contMessPrefix, sizeof(contMessPrefix)) == 0) { 143 | curr += sizeof(contMessPrefix); 144 | UnicodeString us = parseUnicodeString(curr, contentEnd, (uint32_t)(curr - contentBegin) + sectionPosition); 145 | curr += us.byteSize(); 146 | talk.message += us; 147 | 148 | if (talk.message.length > lineWidth) { 149 | std::cerr << "Warning: Mess longer than two lines at byte 0x" << std::hex << (uint32_t)(curr - talk.message.byteSize() - contentBegin) + sectionPosition << ".\n"; 150 | } 151 | } else { 152 | break; 153 | } 154 | } 155 | 156 | std::stringstream msg; 157 | msg << "No final mess in talk at byte 0x" << std::hex << offset + sectionPosition << "."; 158 | throw std::runtime_error(msg.str()); 159 | } 160 | -------------------------------------------------------------------------------- /talk.h: -------------------------------------------------------------------------------- 1 | #ifndef TALK_H 2 | #define TALK_H 3 | 4 | #include 5 | #include "unicodestring.h" 6 | 7 | class Talk { 8 | public: 9 | Talk(): index(-1), speakerPos(0), talkPos(0), talkContentBytes(0) {} 10 | 11 | int index; 12 | size_t speakerPos; 13 | UnicodeString speaker; 14 | size_t talkPos; 15 | size_t talkContentBytes; 16 | UnicodeString message; 17 | 18 | bool hasSpeaker() const { return speaker.length != 0; } 19 | size_t writeToData(char *data, bool ignoreExactLineBreaks) const; 20 | }; 21 | 22 | bool isTalkPrefix(const char *contentBegin, size_t contentLength, size_t offset); 23 | Talk parseTalk(const char *contentBegin, size_t contentLength, size_t offset, uint32_t sectionPosition); 24 | 25 | #endif // TALK_H 26 | -------------------------------------------------------------------------------- /tools/YNSRouteChecker.py: -------------------------------------------------------------------------------- 1 | # IMPORTS, SETUP, AND INFO # -------------------------------------------------------------------------------------- import os, sys, re # this script flags all English lines in the input files for style guide violations # style guide violations are defined by the regex expressions in rules # results are outputted as a _violations.txt file # to-do # complete and sort the properNounsList # complete and sort the honorificsList # complete and sort the exclamationsList (ex: Yay, Geez, etc) # sort rules list so that we get proper priority for overlaps # consider using nltk or some other service to determine proper nouns and maybe grammar usage = 'Usage: python autoCheck.py text_file.txt' # probably not necessary, even if your system locale is not set to JP # import locale # locale.setlocale(locale.LC_ALL, 'ja') # -------------------------------------------------------------------------------------- # PROGRAM DEFINITIONS # -------------------------------------------------------------------------------------- # word sets to ignore for capitalization rules properNounsList = ['Migiwa', 'Sora', 'Kasugano', 'Nogisaka', 'Amatsume', 'Ryouhei', 'Hiro', 'Kazu', 'Haru', 'Akira', 'Nakazato', 'Ryou', 'Motoka', 'Yahiro', 'Nao', 'Onii', 'Ojou', 'Master', 'M\'lady', 'Princess', 'Onee', 'Japanese', 'Senpai', 'Sensei', 'Shinto', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', 'Tokyo', 'Takano'] properNouns = '|'.join(properNounsList) honorificsList = ['sama', 'san', 'chan', 'kun', 'senpai', 'sensei'] honorificsLower = '|'.join(honorificsList) honorificsUpper = '|'.join(map(lambda x: x[0].upper() + x[1:], honorificsList)) exclamationsList = [] # rules is a tuple of (description of rule, regex pattern) # each element of rules is checked for each line #| Class || Description | | Regular Expression | # Capitalization rules = [('Capitalization: Uppercase in middle of word', '[a-z][A-Z]' ), ('Capitalization: Uppercase in middle of sentence', '[^\.\?\!\~"\*;\),\]]\s+(?!I[^a-zA-Z]|' + properNouns + ')[A-Z](?!.*\])'), ('Capitalization: Lowercase after punctuation', '(?:(?:(?>> brackets, and then list out the description of all violations in order for flaggedLine in flaggedLines: markedLine = flaggedLine[0] for violation in flaggedLine[1]: markedLine = markedLine.replace(violation[0], '<<<' + violation[0] + '>>>') writeFile.write(markedLine + '\n') for num, violation in enumerate(flaggedLine[1]): writeFile.write(str(num + 1) + ': ' + violation[1] + '\n') writeFile.write('\n') writeFile.close() print('Flagged ' + str(len(flaggedLines)) + ' lines out of ' + str(countProcessedLines) + ' total lines in file ' + path) # -------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /tools/lineChecker.py: -------------------------------------------------------------------------------- 1 | import re 2 | import os 3 | 4 | while True: 5 | file = input("What is the file name?\n") # Asks the user which file they want to check. 6 | if os.path.exists(file): 7 | break 8 | else: 9 | print("That file does not exist.\n") # Tells the user that the file doesnt exist. 10 | continue 11 | 12 | textformat = open("missed.txt", "w", encoding="UTF-8") # Reopens the file for writing the new data to the file. 13 | pattern = re.compile("\[EN.*\] \n") # Outputs the blank lines. 14 | for line in open(file, "r", encoding="UTF-8"): 15 | for match in re.finditer(pattern, line): 16 | textformat.write(line) # Writes the variable into the file. 17 | 18 | textformat.close() # Closes the file stream. 19 | 20 | print("The missed lines are now in the missed.txt") 21 | input("Press enter to end the program.") -------------------------------------------------------------------------------- /tools/lineFixer.py: -------------------------------------------------------------------------------- 1 | fileName = input("What is the filename?\n") 2 | originalIndex = input("What is the starting index?\n") 3 | finalIndex = input("What is the final index in the list?\n") 4 | newIndex = int(originalIndex) - 1 5 | 6 | textformat = open(fileName, "r", encoding="UTF-8") # Opens the new file into the file stream. 7 | data = textformat.read() # Declaring the data variable used to store the changes to the text. 8 | 9 | while int(originalIndex) <= int(finalIndex): 10 | data = data.replace("[EN" + str(originalIndex).zfill(5) + "]", "[EN" + str(newIndex).zfill(5) + "]") 11 | data = data.replace("[JP" + str(originalIndex).zfill(5) + "]", "[JP" + str(newIndex).zfill(5) + "]") 12 | originalIndex = int(originalIndex) + 1 13 | newIndex = int(newIndex) + 1 14 | 15 | textformat = open("final.txt", "w", encoding="UTF-8") # Reopens the file for writing the new data to the file. 16 | textformat.write(data) # Writes the variable into the file. 17 | textformat.close() # Closes the file stream. -------------------------------------------------------------------------------- /tools/linemerger.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | import re 4 | 5 | 6 | def mainFileFormatter(): # Formats the file to work with the textMerger function. 7 | textformat = open(sys.argv[1], "r", encoding="UTF-8") # Opens the new file into the file stream. 8 | data = textformat.read() # Declaring the data variable used to store the changes to the text. 9 | 10 | data = re.sub("\[EN.*] ", "", string=data) # Removes the blank EN text boxes. 11 | data = re.sub("\n\n\n\n\n\n\n\n\n\n", "\n\n\n", string=data) # Removes whitespaces. 12 | data = re.sub("\n\n\n\n\n\n\n\n\n", "\n\n\n", string=data) # Removes whitespaces. 13 | data = re.sub("\n\n\n\n\n\n\n\n", "\n\n\n", string=data) # Removes whitespaces. 14 | data = re.sub("\n\n\n\n\n\n\n", "\n\n\n", string=data) # Removes whitespaces. 15 | data = re.sub("\n\n\n\n\n\n", "\n\n\n", string=data) # Removes whitespaces. 16 | data = re.sub("\n\n\n\n\n", "\n\n\n", string=data) # Removes whitespaces. 17 | data = re.sub("\n\n\n\n", "\n\n\n", string=data) # Removes whitespaces. 18 | 19 | textformat = open("temp.txt", "w", encoding="UTF-8") # Reopens the file for writing the new data to the file. 20 | textformat.write(data) # Writes the variable into the file. 21 | textformat.close() # Closes the file stream. 22 | 23 | 24 | def TLFileFormatter(): # Formats the file to work with the textMerger function. 25 | textformat = open(sys.argv[2], "r", encoding="UTF-8") # Opens the new file into the file stream. 26 | data = textformat.read() # Declaring the data variable used to store the changes to the text. 27 | 28 | data = re.sub("\[EN.*] ", "", string=data) # Removes the blank EN text boxes. 29 | data = re.sub("\n\n\n\n\n\n\n\n\n\n", "\n", string=data) # Removes whitespaces. 30 | data = re.sub("\n\n\n\n\n\n\n\n\n", "\n", string=data) # Removes whitespaces. 31 | data = re.sub("\n\n\n\n\n\n\n\n", "\n", string=data) # Removes whitespaces. 32 | data = re.sub("\n\n\n\n\n\n\n", "\n", string=data) # Removes whitespaces. 33 | data = re.sub("\n\n\n\n\n\n", "\n", string=data) # Removes whitespaces. 34 | data = re.sub("\n\n\n\n\n", "\n", string=data) # Removes whitespaces. 35 | data = re.sub("\n\n\n\n", "\n", string=data) # Removes whitespaces. 36 | data = re.sub("\n\n\n", "\n", string=data) # Removes whitespaces. 37 | data = re.sub("\n\n", "\n", string=data) # Removes whitespaces. 38 | data = data.replace("[JP", "[EN") # Changes the tag from JP to EN. 39 | 40 | textformat = open("temp2.txt", "w", encoding="UTF-8") # Reopens the file for writing the new data to the file. 41 | textformat.write(data) # Writes the variable into the file. 42 | textformat.close() # Closes the file stream. 43 | 44 | 45 | def removeLastLine(): # Removes the last line to prevent an index error in the textMerger function. 46 | fd = open("temp2.txt", "r", encoding="UTF-8") 47 | d = fd.read() 48 | fd.close() 49 | m = d.split("\n") 50 | s = "\n".join(m[:-1]) 51 | fd = open("temp2.txt", "w+", encoding="UTF-8") 52 | for i in range(len(s)): 53 | fd.write(s[i]) 54 | fd.close() 55 | 56 | 57 | def textMerger(): # Merges the two files together. 58 | insertTag = "[JP" 59 | if os.path.exists("temp.txt") and os.path.exists("temp2.txt"): 60 | file_1 = open("temp.txt", "r", encoding="UTF-8") 61 | file_2 = open("temp2.txt", "r", encoding="UTF-8") 62 | output = open("merged.txt", "x", encoding="UTF-8") 63 | 64 | line_block = file_1.read().split("\n\n") 65 | translations = file_2.read().split("\n") 66 | tl_len = len(translations) 67 | flush = " "*len(str(tl_len)) 68 | 69 | for block in line_block: 70 | tl_lines = [] 71 | tl_rem = 0 72 | 73 | block = block.split("\n") 74 | block_len = len(block) 75 | 76 | match_start = False 77 | match_end = False 78 | tl_print = True 79 | line_print = True 80 | 81 | for i in range(block_len): 82 | line = block[i] 83 | if line[:3] == insertTag: 84 | match_start = True 85 | elif match_start: 86 | match_end = True 87 | 88 | if line[:3] == insertTag and i == block_len - 1: 89 | output.write(f"{line}\n") 90 | line_print = False 91 | match_end = True 92 | 93 | if match_end and tl_print: 94 | found = False 95 | tl_print = False 96 | match_end = False 97 | 98 | try: 99 | tag = line.split()[0][3:] 100 | except IndexError: 101 | pass 102 | 103 | for tl in translations: 104 | if tl.split()[0][3:] == tag: 105 | output.write(f"{tl}\n") 106 | tl_rem += 1 107 | found = True 108 | elif found: 109 | break 110 | 111 | if line_print: 112 | output.write(f"{line}\n") 113 | line_print = True 114 | 115 | output.write("\n") 116 | 117 | for i in range(tl_rem): 118 | del translations[0] 119 | print(f"{len(translations)}/{tl_len} remaining{flush}",end="\r",flush=True) 120 | 121 | 122 | if len(sys.argv) != 3: 123 | print("Usage: linemerger mainFile.txt TLFile.txt") 124 | quit() 125 | 126 | try: 127 | os.remove("merged.txt") 128 | except OSError: 129 | pass 130 | 131 | print("Processing...") 132 | 133 | mainFileFormatter() 134 | TLFileFormatter() 135 | removeLastLine() 136 | textMerger() 137 | 138 | print("\nFinished! The file merged.txt has been created.") 139 | 140 | try: 141 | os.remove("temp.txt") or os.remove("temp2.txt") 142 | except OSError: 143 | pass 144 | -------------------------------------------------------------------------------- /txtparser.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "txtparser.h" 8 | 9 | static const char *choiceTlPrefix = "[EN|CHOICE"; 10 | static const char *specialTlPrefix = "[EN|SPECIAL"; 11 | static const char *tlPrefix = "[EN"; 12 | static const char openingBracket[] = { '[', 0x00 }; 13 | static const char endingBracket[] = { ']', 0x00 }; 14 | static const char space[] = { ' ', 0x00 }; 15 | static const char utf8Bom[] = { 0xef, 0xbb, 0xbf }; 16 | static const char scenarioNewLine[] = { 0x0F, 0xFF }; 17 | 18 | TxtParser::Stats &TxtParser::Stats::operator +=(const TxtParser::Stats &rhs) { 19 | translatedMessages += rhs.translatedMessages; 20 | totalMessages += rhs.totalMessages; 21 | translatedChoices += rhs.translatedChoices; 22 | totalChoices += rhs.totalChoices; 23 | return *this; 24 | } 25 | 26 | double TxtParser::Stats::messagesPercent() const { 27 | if (totalMessages == 0) { 28 | return 100; 29 | } else { 30 | return 100 * (double)translatedMessages / (double)totalMessages; 31 | } 32 | } 33 | 34 | double TxtParser::Stats::choicesPercent() const { 35 | if (totalChoices == 0) { 36 | return 100; 37 | } else { 38 | return 100 * (double)translatedChoices / (double)totalChoices; 39 | } 40 | } 41 | 42 | void TxtParser::writeTxt(std::string utfFilename) const { 43 | std::ofstream fout(utfFilename.c_str(), std::ios_base::out | std::ios_base::binary); 44 | 45 | for (size_t i = 0; i < choices.size(); ++i) { 46 | const Choice &choice = choices[i]; 47 | 48 | fout << "[JP|CHOICE" << std::setw(2) << std::setfill('0') << choice.index << "] "; 49 | printUtf8(fout, choice.choice1); 50 | fout << "\r\n"; 51 | 52 | fout << "[JP|CHOICE" << std::setw(2) << std::setfill('0') << choice.index << "] "; 53 | printUtf8(fout, choice.choice2); 54 | fout << "\r\n"; 55 | 56 | fout << choiceTlPrefix << std::setw(2) << std::setfill('0') << choice.index << "] \r\n"; 57 | fout << choiceTlPrefix << std::setw(2) << std::setfill('0') << choice.index << "] \r\n"; 58 | 59 | fout << "\r\n\r\n"; 60 | } 61 | 62 | for (size_t i = 0; i < messages.size(); ++i) { 63 | const Talk &talk = messages[i]; 64 | std::deque lines = talk.message.split(scenarioNewLine, sizeof(scenarioNewLine) / 2); 65 | 66 | for (size_t j = 0; j < lines.size(); ++j) { 67 | fout << "[JP" << std::setw(5) << std::setfill('0') << talk.index << "] "; 68 | 69 | if (j == 0 && talk.hasSpeaker()) { 70 | fout << "["; 71 | printUtf8(fout, talk.speaker); 72 | fout << "] "; 73 | } 74 | 75 | printUtf8(fout, lines[j]); 76 | fout << "\r\n"; 77 | } 78 | 79 | for (size_t j = 0; j < lines.size(); ++j) { 80 | fout << tlPrefix << std::setw(5) << std::setfill('0') << talk.index << "] "; 81 | 82 | if (j == 0 && talk.hasSpeaker()) { 83 | fout << "["; 84 | printUtf8(fout, talk.speaker); 85 | fout << "] "; 86 | } 87 | 88 | // exporting message id and position in original csx for debug 89 | //fout << talk.index << " " << std::hex << (talk.talkPos + sizeof(Header) + 16) << std::dec; 90 | 91 | fout << "\r\n"; 92 | } 93 | 94 | fout << "\r\n\r\n"; 95 | } 96 | 97 | fout.close(); 98 | } 99 | 100 | static int parseNumber(const char *numStr, size_t length) { 101 | int res = 0; 102 | for (size_t i = 0; i < length; ++i) { 103 | res *= 10; 104 | if (numStr[i] < '0' || numStr[i] > '9') { 105 | throw std::runtime_error("Invalid number."); 106 | } 107 | res += numStr[i] - '0'; 108 | } 109 | return res; 110 | } 111 | 112 | struct Line { 113 | const char *content; 114 | size_t size; 115 | size_t lineNumber; 116 | }; 117 | 118 | // splits utf-8 text into lines and trims lines 119 | static std::deque splitIntoLines(const char *str, size_t strLen) { 120 | std::deque result; 121 | size_t begin = 0; 122 | size_t lineNumber = 1; 123 | 124 | for (size_t i = 0; i < strLen; ++i) { 125 | if (str[i] == '\n' || i == strLen - 1) { 126 | size_t end = i; 127 | while (begin < end && (str[end - 1] == '\r' || str[end - 1] == ' ')) { 128 | --end; 129 | } 130 | 131 | while (begin < end && str[begin] == ' ') { 132 | ++begin; 133 | } 134 | 135 | if (begin < end) { 136 | Line line; 137 | line.content = str + begin; 138 | line.size = end - begin; 139 | line.lineNumber = lineNumber; 140 | result.push_back(line); 141 | } 142 | 143 | begin = i + 1; 144 | ++lineNumber; 145 | } 146 | } 147 | 148 | return result; 149 | } 150 | 151 | static size_t numOfSpaces(const char *str, size_t length) { 152 | size_t spaces = 0; 153 | while (spaces < length && memcmp(str + spaces, space, sizeof(space)) == 0) { 154 | ++spaces; 155 | } 156 | return spaces; 157 | } 158 | 159 | static size_t findSubstring(const char *str, size_t strLen, const char *substr, size_t substrLen) { 160 | for (size_t i = 0; i < strLen - substrLen + 1; ++i) { 161 | if (memcmp(str + i * 2, substr, substrLen * 2) == 0) { 162 | return i; 163 | } 164 | } 165 | return (size_t)-1; 166 | } 167 | 168 | TxtParser::Stats TxtParser::parseTxt(std::string utfFilename, const char *customSpace) { 169 | size_t initMessagesSize = messages.size() + specials.size(); 170 | size_t initChoicesSize = choices.size(); 171 | Stats stats; 172 | 173 | // reading the whole file into a buffer 174 | std::ifstream fin(utfFilename.c_str(), std::ios_base::in | std::ios_base::binary); 175 | if (!fin) { 176 | throw std::runtime_error("Could not open the file for reading (file " + utfFilename + ")."); 177 | } 178 | 179 | int buffLen = 4 * 1024 * 1024; 180 | int len = 0; 181 | char *contents = new char[buffLen]; 182 | 183 | while (fin) { 184 | fin.read(contents + len, buffLen - len); 185 | len += fin.gcount(); 186 | char *temp = new char[buffLen + 1024 * 1024]; 187 | memcpy(temp, contents, buffLen); 188 | delete[] contents; 189 | contents = temp; 190 | buffLen += 1024 * 1024; 191 | } 192 | 193 | if (len < 128) { 194 | throw std::runtime_error("File too short (file " + utfFilename + ")."); 195 | } 196 | 197 | // support for UTF-8 with and without BOM 198 | int utfBomSkip = 0; 199 | if (memcmp(contents, utf8Bom, sizeof(utf8Bom)) != 0) { 200 | utfBomSkip = 3; 201 | } 202 | 203 | const size_t tlPrefixLen = strlen(tlPrefix); 204 | const size_t choiceTlPrefixLen = strlen(choiceTlPrefix); 205 | const size_t specialTlPrefixLen = strlen(specialTlPrefix); 206 | bool expectsSecondChoice = false; 207 | 208 | auto lines = splitIntoLines(contents + utfBomSkip, len - utfBomSkip); 209 | for (size_t i = 0; i < lines.size(); ++i) { 210 | Line line = lines[i]; 211 | if (choiceTlPrefixLen + 3 <= line.size && memcmp(line.content, choiceTlPrefix, choiceTlPrefixLen) == 0) { 212 | if (expectsSecondChoice) { 213 | ++stats.totalChoices; 214 | } 215 | 216 | int index = parseNumber(line.content + choiceTlPrefixLen, 2); 217 | if (line.content[choiceTlPrefixLen + 2] != ']') { 218 | throw std::runtime_error("Invalid choice (line " + std::to_string(line.lineNumber) + " of file " + utfFilename + ")."); 219 | } 220 | 221 | if (choiceTlPrefixLen + 3 < line.size) { 222 | UnicodeString lineContent = utf8ToUnicodeString(line.content + choiceTlPrefixLen + 3, line.size - choiceTlPrefixLen - 3); 223 | size_t offset = 2 * numOfSpaces(lineContent.str, lineContent.length); 224 | 225 | UnicodeString choiceString = UnicodeString(lineContent.str + offset, lineContent.length - offset / 2, customSpace); 226 | 227 | if (choiceString.length > 0) { 228 | if (expectsSecondChoice) { 229 | if (!choices.empty() && choices.back().index != index) { 230 | throw std::runtime_error("Invalid choice index (line " + std::to_string(line.lineNumber) + " of file " + utfFilename + ")."); 231 | } 232 | choices.back().choice2 = choiceString; 233 | } else { 234 | Choice choice; 235 | choice.index = index; 236 | choice.choice1 = choiceString; 237 | choices.push_back(choice); 238 | } 239 | } 240 | } 241 | 242 | expectsSecondChoice = !expectsSecondChoice; 243 | } else if (specialTlPrefixLen + 10 <= line.size && memcmp(line.content, specialTlPrefix, specialTlPrefixLen) == 0) { 244 | Special special; 245 | special.pos = parseNumber(line.content + specialTlPrefixLen, 9); 246 | if (line.content[specialTlPrefixLen + 9] != ']') { 247 | throw std::runtime_error("Invalid special message (line " + std::to_string(line.lineNumber) + " of file " + utfFilename + ")."); 248 | } 249 | 250 | ++stats.totalMessages; 251 | 252 | if (specialTlPrefixLen + 10 < line.size) { 253 | UnicodeString lineContent = utf8ToUnicodeString(line.content + specialTlPrefixLen + 10, line.size - specialTlPrefixLen - 10); 254 | size_t offset = 2 * numOfSpaces(lineContent.str, lineContent.length); 255 | 256 | special.substitution = UnicodeString(lineContent.str + offset, lineContent.length - offset / 2, customSpace); 257 | if (special.substitution.length > 0) { 258 | specials.push_back(special); 259 | } 260 | } 261 | } else if (tlPrefixLen + 6 <= line.size && memcmp(line.content, tlPrefix, tlPrefixLen) == 0) { 262 | Talk talk; 263 | talk.index = parseNumber(line.content + tlPrefixLen, 5); 264 | if (line.content[tlPrefixLen + 5] != ']') { 265 | throw std::runtime_error("Invalid message (line " + std::to_string(line.lineNumber) + " of file " + utfFilename + ")."); 266 | } 267 | 268 | if (messages.size() == 0 || messages.back().index != talk.index) { 269 | ++stats.totalMessages; 270 | } 271 | 272 | if (tlPrefixLen + 6 < line.size) { 273 | UnicodeString lineContent = utf8ToUnicodeString(line.content + tlPrefixLen + 6, line.size - tlPrefixLen - 6); 274 | size_t offset = 2 * numOfSpaces(lineContent.str, lineContent.length); 275 | 276 | if (offset + sizeof(openingBracket) < lineContent.length * 2 && memcmp(lineContent.str + offset, openingBracket, sizeof(openingBracket)) == 0) { 277 | offset += sizeof(openingBracket); 278 | const char *usStr = lineContent.str + offset; 279 | size_t usStrLen = findSubstring(usStr, lineContent.length - offset / 2, endingBracket, sizeof(endingBracket) / 2); 280 | if (usStrLen == (size_t)-1) { 281 | throw std::runtime_error("Invalid speaker name (line " + std::to_string(line.lineNumber) + " of file " + utfFilename + ")."); 282 | } 283 | talk.speaker = UnicodeString(usStr, usStrLen); 284 | offset += 2 * talk.speaker.length + sizeof(endingBracket); 285 | offset += 2 * numOfSpaces(lineContent.str + offset, lineContent.length - offset / 2); 286 | } 287 | 288 | talk.message = UnicodeString(lineContent.str + offset, lineContent.length - offset / 2, customSpace); 289 | if (talk.message.length > 0) { 290 | if (messages.size() == 0 || messages.back().index != talk.index) { 291 | messages.push_back(talk); 292 | } else { 293 | if (talk.hasSpeaker()) { 294 | throw std::runtime_error("Speaker name not in present in the first line (line " + std::to_string(line.lineNumber) + " of file " + utfFilename + ")."); 295 | } 296 | messages.back().message += UnicodeString(scenarioNewLine, sizeof(scenarioNewLine) / 2); 297 | messages.back().message += talk.message; 298 | } 299 | } 300 | } 301 | } 302 | } 303 | 304 | if (expectsSecondChoice) { 305 | throw std::runtime_error("Both choices from one question or neither of them must be translated (file " + utfFilename + ")."); 306 | } 307 | 308 | delete[] contents; 309 | 310 | stats.translatedMessages = messages.size() + specials.size() - initMessagesSize; 311 | stats.translatedChoices = choices.size() - initChoicesSize; 312 | 313 | return stats; 314 | } 315 | 316 | std::ostream &operator <<(std::ostream &os, const TxtParser::Stats &stats) { 317 | os << stats.translatedMessages << "/" << stats.totalMessages << " (" << std::setprecision(2) << std::setiosflags(std::ios_base::fixed) << stats.messagesPercent() << "%) lines, "; 318 | os << stats.translatedChoices << "/" << stats.totalChoices << " (" << stats.choicesPercent() << "%) choices"; 319 | return os; 320 | } 321 | -------------------------------------------------------------------------------- /txtparser.h: -------------------------------------------------------------------------------- 1 | #ifndef TXTPARSER_H 2 | #define TXTPARSER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "talk.h" 8 | #include "choice.h" 9 | #include "special.h" 10 | 11 | class TxtParser { 12 | public: 13 | std::deque messages; 14 | std::deque choices; 15 | std::deque specials; 16 | 17 | struct Stats { 18 | size_t translatedMessages; 19 | size_t totalMessages; 20 | size_t translatedChoices; 21 | size_t totalChoices; 22 | 23 | Stats(): translatedMessages(0), totalMessages(0), translatedChoices(0), totalChoices(0) {} 24 | Stats &operator +=(const Stats &other); 25 | double messagesPercent() const; 26 | double choicesPercent() const; 27 | }; 28 | 29 | void writeTxt(std::string utfFilename) const; 30 | Stats parseTxt(std::string utfFilename, const char *customSpace); 31 | }; 32 | 33 | std::ostream &operator <<(std::ostream &os, const TxtParser::Stats &stats); 34 | 35 | #endif // TXTPARSER_H 36 | -------------------------------------------------------------------------------- /unicodestring.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "unicodestring.h" 9 | 10 | static const size_t shortLength = 64; 11 | 12 | UnicodeString::UnicodeString(const char *s, uint32_t l, const char *customSpace): 13 | length(l) { 14 | assert(s != 0 || l > 0); 15 | char *usStr = new char[2 * length]; 16 | 17 | memcpy(usStr, s, 2 * length); 18 | 19 | if (customSpace) { 20 | for (size_t i = 0; i < length; ++i) { 21 | if (usStr[2 * i] == ' ' && usStr[2 * i + 1] == 0) { 22 | usStr[2 * i] = customSpace[0]; 23 | usStr[2 * i + 1] = customSpace[1]; 24 | } 25 | } 26 | } 27 | 28 | str = usStr; 29 | } 30 | 31 | UnicodeString::UnicodeString(const UnicodeString &orig): 32 | length(orig.length) { 33 | char *usStr = new char[2 * length]; 34 | memcpy(usStr, orig.str, 2 * length); 35 | str = usStr; 36 | } 37 | 38 | UnicodeString::~UnicodeString() { 39 | delete[] str; 40 | } 41 | 42 | UnicodeString &UnicodeString::operator =(const UnicodeString &rhs) { 43 | if (this == &rhs) { 44 | return *this; 45 | } 46 | 47 | delete[] str; 48 | length = rhs.length; 49 | char *usStr = new char[2 * length]; 50 | memcpy(usStr, rhs.str, 2 * length); 51 | str = usStr; 52 | 53 | return *this; 54 | } 55 | 56 | size_t UnicodeString::width() const { 57 | size_t w = 0; 58 | for (size_t i = 0; i < length; ++i) { 59 | if (str[2 * i + 1] == 0) { 60 | w += 1; 61 | } else { 62 | w += 2; 63 | } 64 | } 65 | 66 | return w; 67 | } 68 | 69 | std::deque UnicodeString::split(const char *sep, size_t sepLen) const { 70 | assert(sepLen > 0); 71 | std::deque result; 72 | 73 | size_t begin = 0; 74 | for (size_t i = 0; i < length - sepLen + 1; ++i) { 75 | if (memcmp(str + 2 * i, sep, sepLen * 2) == 0) { 76 | if (begin < i) { 77 | UnicodeString us(str + (2 * begin), i - begin); 78 | result.push_back(us); 79 | } 80 | 81 | begin = i + sepLen; 82 | } 83 | } 84 | 85 | if (begin < length) { 86 | UnicodeString us(str + (2 * begin), length - begin); 87 | result.push_back(us); 88 | } 89 | 90 | return result; 91 | } 92 | 93 | std::deque UnicodeString::split(size_t len) const { 94 | std::deque result; 95 | 96 | for (size_t i = 0; i < length; i += len) { 97 | UnicodeString us(str + i * 2, std::min(len, length - i)); 98 | result.push_back(us); 99 | } 100 | 101 | return result; 102 | } 103 | 104 | UnicodeString &UnicodeString::operator +=(const UnicodeString &rhs) { 105 | char *sum = new char[(length + rhs.length) * 2]; 106 | memcpy(sum, str, length * 2); 107 | memcpy(sum + (length * 2), rhs.str, rhs.length * 2); 108 | 109 | delete[] str; 110 | 111 | str = sum; 112 | length = length + rhs.length; 113 | return *this; 114 | } 115 | 116 | bool UnicodeString::operator ==(const UnicodeString &rhs) const { 117 | return this == &rhs || (length == rhs.length && memcmp(str, rhs.str, length) == 0); 118 | } 119 | 120 | int UnicodeString::byteSize() const { 121 | return length * 2 + 4; 122 | } 123 | 124 | void UnicodeString::writeToData(char *data) const { 125 | memcpy(data, &length, 4); 126 | memcpy(data + 4, str, length * 2); 127 | } 128 | 129 | UnicodeString parseUnicodeString(const char *source, const char *sourceEnd, uint32_t position) { 130 | if (source + 4 >= sourceEnd) { 131 | std::stringstream msg; 132 | msg << "Unicode string out of bounds at byte 0x " << std::hex << position << "."; 133 | throw std::runtime_error(msg.str()); 134 | } 135 | UnicodeString res; 136 | res.length = *((uint32_t *)source); 137 | if (source + 4 + 2 * res.length > sourceEnd) { 138 | std::stringstream msg; 139 | msg << "Unicode string out of bounds at byte 0x " << std::hex << position << "."; 140 | throw std::runtime_error(msg.str()); 141 | } 142 | char *usStr = new char[res.length * 2]; 143 | memcpy(usStr, source + 4, res.length * 2); 144 | res.str = usStr; 145 | return res; 146 | } 147 | 148 | bool isShortUnicodeString(const char *source, const char *sourceEnd) { 149 | if (source + 4 >= sourceEnd) { 150 | return false; 151 | } 152 | uint32_t length = *((uint32_t *)source); 153 | return length <= shortLength && source + 4 + 2 * length <= sourceEnd; 154 | } 155 | 156 | const char *searchBackwardsForShortUnicodeString(const char *contentBegin, size_t startOffset) { 157 | const char *curr = contentBegin + startOffset - 6; 158 | const char *minPos = contentBegin - std::min(startOffset, shortLength * 2 + 4); 159 | while (curr >= minPos) { 160 | if (curr[5] == 0x00 && curr[6] == 0x00) { 161 | break; 162 | } 163 | 164 | uint32_t currAsInt = *((uint32_t *)curr); 165 | if (currAsInt <= shortLength && curr + (4 + currAsInt * 2) == contentBegin + startOffset) { 166 | return curr; 167 | } 168 | 169 | curr -= 2; 170 | } 171 | 172 | return 0; 173 | } 174 | 175 | void unicodeStringToUtf8(char **utf8, size_t *utf8Len, const UnicodeString &us) { 176 | iconv_t conv = iconv_open("UTF-8", "UTF-16LE"); 177 | if (conv == (iconv_t)-1) { 178 | throw std::runtime_error("Cannot initialize iconv."); 179 | } 180 | 181 | const size_t startUtf8Bytes = us.length * 3; 182 | size_t utf8BytesLeft = startUtf8Bytes; 183 | *utf8 = new char[utf8BytesLeft]; 184 | char *buff = *utf8; 185 | const char *usStr = us.str; 186 | size_t usBytesLeft = us.length * 2; 187 | size_t res = iconv(conv, const_cast(&usStr), &usBytesLeft, &buff, &utf8BytesLeft); 188 | if (res == (size_t)-1) { 189 | throw std::runtime_error("iconv conversion fail."); 190 | } 191 | *utf8Len = startUtf8Bytes - utf8BytesLeft; 192 | 193 | iconv_close(conv); 194 | } 195 | 196 | UnicodeString utf8ToUnicodeString(const char *utf8, size_t utf8Len) { 197 | iconv_t conv = iconv_open("UTF-16LE", "UTF-8"); 198 | if (conv == (iconv_t)-1) { 199 | throw std::runtime_error("Cannot initialize iconv."); 200 | } 201 | 202 | UnicodeString us; 203 | const size_t startUsBytes = utf8Len * 2; 204 | size_t usBytesLeft = startUsBytes; 205 | char *buff = new char[usBytesLeft]; 206 | us.str = buff; 207 | size_t utf8BytesLeft = utf8Len; 208 | const char *utf8Str = utf8; 209 | size_t res = iconv(conv, const_cast(&utf8Str), &utf8BytesLeft, &buff, &usBytesLeft); 210 | if (res == (size_t)-1) { 211 | throw std::runtime_error("iconv conversion fail."); 212 | } 213 | us.length = (startUsBytes - usBytesLeft) / 2; 214 | 215 | iconv_close(conv); 216 | 217 | return us; 218 | } 219 | 220 | void printUtf8(std::ofstream &fout, const UnicodeString &us) { 221 | char *utf8; 222 | size_t len; 223 | unicodeStringToUtf8(&utf8, &len, us); 224 | assert(len > 0); 225 | fout.write(utf8, len); 226 | } 227 | -------------------------------------------------------------------------------- /unicodestring.h: -------------------------------------------------------------------------------- 1 | #ifndef UNICODESTRING_H 2 | #define UNICODESTRING_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class UnicodeString { 9 | public: 10 | const char *str; 11 | uint32_t length; 12 | 13 | UnicodeString(): str(0), length(0) {} 14 | // can convert space to \xff on the fly 15 | UnicodeString(const char *s, uint32_t l, const char* customSpace = NULL); 16 | UnicodeString(const UnicodeString &orig); 17 | ~UnicodeString(); 18 | UnicodeString &operator =(const UnicodeString &rhs); 19 | 20 | // width of text - ascii has width of 1, other characters of 2 21 | size_t width() const; 22 | 23 | // split UnicodeString with supplied separator wchar, separator is dropped 24 | std::deque split(const char *sep, size_t sepLen) const; 25 | // split UnicodeString into parts of maximum of len size 26 | std::deque split(size_t len) const; 27 | 28 | UnicodeString &operator +=(const UnicodeString &rhs); 29 | bool operator ==(const UnicodeString &rhs) const; 30 | int byteSize() const; 31 | void writeToData(char *data) const; 32 | }; 33 | 34 | UnicodeString parseUnicodeString(const char *source); 35 | UnicodeString parseUnicodeString(const char *source, const char *sourceEnd, uint32_t position); 36 | 37 | bool isShortUnicodeString(const char *source, const char *sourceEnd); 38 | 39 | // search for unicode string backwards 40 | // it must be at most 255 wchars long, not contain any 0x0000 (wchar nulls) and 41 | // end exactly at str - 1 42 | const char *searchBackwardsForShortUnicodeString(const char *content, size_t startOffset); 43 | 44 | void unicodeStringToUtf8(char **utf8, size_t *utf8Len, const UnicodeString &utf16le); 45 | UnicodeString utf8ToUnicodeString(const char *utf8, size_t utf8Len); 46 | 47 | void printUtf8(std::ofstream &fout, const UnicodeString &us); 48 | 49 | 50 | #endif // UNICODESTRING_H 51 | --------------------------------------------------------------------------------