From 9c1ffdccc19084b4edcd8efa0f3df33dfc58b9bc Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Mon, 22 Mar 2021 21:56:29 +0000 Subject: [PATCH] Very old Powder Toy source code tar ~2009 --- LICENSE | 340 +++ Makefile | 74 + fbi.h | 223 ++ font.h | 194 ++ font/Makefile | 5 + font/editor.c | 284 +++ font/font.bin | Bin 0 -> 30980 bytes font/packer.c | 100 + http.c | 856 +++++++ http.h | 21 + icon.h | 309 +++ md5.c | 225 ++ md5.h | 17 + powder-res.rc | 2 + powder.c | 5907 +++++++++++++++++++++++++++++++++++++++++++++++++ powder.ico | Bin 0 -> 15406 bytes update.c | 188 ++ update.h | 8 + 18 files changed, 8753 insertions(+) create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 fbi.h create mode 100644 font.h create mode 100644 font/Makefile create mode 100644 font/editor.c create mode 100644 font/font.bin create mode 100644 font/packer.c create mode 100644 http.c create mode 100644 http.h create mode 100644 icon.h create mode 100644 md5.c create mode 100644 md5.h create mode 100644 powder-res.rc create mode 100644 powder.c create mode 100644 powder.ico create mode 100644 update.c create mode 100644 update.h diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..983f982a1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..0489154d4 --- /dev/null +++ b/Makefile @@ -0,0 +1,74 @@ +SOURCES := powder.c http.c md5.c update.c +HEADERS := font.h http.h md5.h icon.h update.h fbi.h + +CFLAGS := -Wall -std=c99 -D_POSIX_C_SOURCE=200112L -fgnu89-inline +OFLAGS := -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations +LFLAGS := -lSDL -lm -lbz2 +MFLAGS_SSE3 := -march=k8 -DX86 -DX86_SSE3 -msse3 +MFLAGS_SSE2 := -march=k8 -DX86 -DX86_SSE2 +MFLAGS_SSE := -march=pentium3 -DX86 -DX86_SSE + +LINUX_TARG := powder-64-sse2 powder-sse powder-sse2 +WIN32_TARG := powder-sse.exe powder-sse2.exe + +powder: $(SOURCES) $(HEADERS) + gcc -m64 -DINTERNAL -o$@ $(CFLAGS) $(OFLAGS) $(LFLAGS) $(MFLAGS_SSE3) $(SOURCES) -DLIN64 + +powder-sse3: $(SOURCES) $(HEADERS) + gcc -m32 -o$@ $(CFLAGS) $(OFLAGS) $(LFLAGS) $(MFLAGS_SSE3) $(SOURCES) -DLIN32 + strip $@ +powder-sse2: $(SOURCES) $(HEADERS) + gcc -m32 -o$@ $(CFLAGS) $(OFLAGS) $(LFLAGS) $(MFLAGS_SSE2) $(SOURCES) -DLIN32 + strip $@ +powder-sse: $(SOURCES) $(HEADERS) + gcc -m32 -o$@ $(CFLAGS) $(OFLAGS) $(LFLAGS) $(MFLAGS_SSE) $(SOURCES) -DLIN32 + strip $@ + +powder-64-sse3: $(SOURCES) $(HEADERS) + gcc -m64 -o$@ $(CFLAGS) $(OFLAGS) $(LFLAGS) $(MFLAGS_SSE3) $(SOURCES) -DLIN64 + strip $@ +powder-64-sse2: $(SOURCES) $(HEADERS) + gcc -m64 -o$@ $(CFLAGS) $(OFLAGS) $(LFLAGS) $(MFLAGS_SSE2) $(SOURCES) -DLIN64 + strip $@ + +powder-res.o: powder-res.rc powder.ico + i586-mingw32msvc-windres powder-res.rc powder-res.o + +powder-sse3.exe: $(SOURCES) $(HEADERS) powder-res.o + i586-mingw32msvc-gcc -o$@ $(CFLAGS) $(OFLAGS) $(MFLAGS_SSE3) $(SOURCES) powder-res.o -lmingw32 -lws2_32 -lSDLmain $(LFLAGS) -mwindows -DWIN32 + strip $@ + chmod 0644 $@ +powder-sse2.exe: $(SOURCES) $(HEADERS) powder-res.o + i586-mingw32msvc-gcc -o$@ $(CFLAGS) $(OFLAGS) $(MFLAGS_SSE2) $(SOURCES) powder-res.o -lmingw32 -lws2_32 -lSDLmain $(LFLAGS) -mwindows -DWIN32 + strip $@ + chmod 0644 $@ +powder-sse.exe: $(SOURCES) $(HEADERS) powder-res.o + i586-mingw32msvc-gcc -o$@ $(CFLAGS) $(OFLAGS) $(MFLAGS_SSE) $(SOURCES) powder-res.o -lmingw32 -lws2_32 -lSDLmain $(LFLAGS) -mwindows -DWIN32 + strip $@ + chmod 0644 $@ + +powder-src.tar.bz2: *.c *.h *.rc *.ico Makefile + mkdir powder-src + cp *.c *.h *.rc *.ico Makefile powder-src/ + tar cfj powder-src.tar.bz2 powder-src + rm -rf powder-src + +release: $(LINUX_TARG) $(WIN32_TARG) powder-src.tar.bz2 + tar cfz powder-linux.tar.gz $(LINUX_TARG) + cp /usr/i586-mingw32msvc/bin/SDL.dll . + zip powder-win32.zip $(WIN32_TARG) SDL.dll + mkdir -p release + mv powder-linux.tar.gz release/ + mv powder-win32.zip release/ + mv powder-src.tar.bz2 release/ + cp powder-sse.exe powder.exe + rm -f release/powder.zip + zip release/powder.zip powder.exe SDL.dll + cp powder-64-sse2 release/powder64 + rm -f release/powder64.gz + gzip release/powder64 + rm -f release/powder.gz + cp powder-sse release/powder + gzip release/powder + cd release; tar czf powder-bin.tar.gz powder.gz powder64.gz powder-linux.tar.gz powder-win32.zip powder.zip; cd .. + rm -f $(LINUX_TARG) $(WIN32_TARG) SDL.dll powder.exe diff --git a/fbi.h b/fbi.h new file mode 100644 index 000000000..933a21d12 --- /dev/null +++ b/fbi.h @@ -0,0 +1,223 @@ +#define FBI_W 268 +#define FBI_H 201 +#define FBI_CMP 3464 + +unsigned char fbi[FBI_CMP] = { + 0x42, 0x5A, 0x68, 0x39, 0x31, 0x41, 0x59, 0x26, 0x53, 0x59, 0xE5, 0x00, 0x24, 0xC9, 0x00, 0x01, + 0x88, 0x7F, 0xFF, 0xD2, 0x49, 0x24, 0xB2, 0x68, 0x24, 0xB2, 0x48, 0x14, 0x90, 0x49, 0x24, 0x9A, + 0x48, 0x28, 0x92, 0x09, 0x24, 0x96, 0x41, 0x04, 0x92, 0x49, 0x26, 0x92, 0x49, 0x01, 0x82, 0x41, + 0x24, 0x92, 0xC8, 0x60, 0x1D, 0x5E, 0xF2, 0x57, 0xD8, 0x02, 0xD1, 0xA9, 0x65, 0x8D, 0xB0, 0x00, + 0x01, 0xAD, 0x1A, 0x24, 0x12, 0xA3, 0x4A, 0xD3, 0x6C, 0x1B, 0x60, 0x00, 0x69, 0x40, 0x24, 0x6B, + 0x4B, 0xDE, 0x2F, 0x7A, 0x88, 0x8B, 0xD6, 0x1B, 0x29, 0x8D, 0x33, 0x85, 0xDC, 0x15, 0xAE, 0x08, + 0xC9, 0x6C, 0xEB, 0xA3, 0xBB, 0xAB, 0x80, 0x50, 0x05, 0x04, 0x54, 0xCD, 0x92, 0x4C, 0x40, 0x1A, + 0x68, 0x68, 0xF5, 0x00, 0xD0, 0xD0, 0x00, 0x0D, 0x00, 0x03, 0x40, 0x68, 0x04, 0x84, 0x44, 0x24, + 0x48, 0xF5, 0x0F, 0x53, 0xF4, 0x89, 0xB5, 0x1A, 0x68, 0x19, 0x0C, 0x00, 0x41, 0x81, 0x31, 0x0C, + 0x83, 0xD1, 0xA1, 0xC6, 0x4C, 0x9A, 0x31, 0x0D, 0x34, 0x30, 0x13, 0x43, 0x13, 0x46, 0x99, 0x31, + 0x03, 0x23, 0x09, 0xA3, 0x4D, 0x30, 0x83, 0x26, 0x12, 0x7A, 0xA5, 0x28, 0x90, 0x0A, 0x7A, 0x8C, + 0x00, 0x26, 0x4C, 0x86, 0x00, 0x00, 0x00, 0x09, 0x88, 0x32, 0x18, 0x21, 0x2A, 0x9A, 0x53, 0x6A, + 0x9A, 0x32, 0x68, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x81, 0xA0, 0x34, 0x0A, 0x9A, 0x95, + 0x4D, 0x12, 0x80, 0x1A, 0x34, 0x64, 0x00, 0x00, 0x68, 0x1A, 0x06, 0x4D, 0x00, 0x00, 0x00, 0x77, + 0xBD, 0x8E, 0xD8, 0x28, 0x92, 0x6C, 0x8A, 0x26, 0xD6, 0x50, 0x0B, 0x64, 0x4D, 0xB2, 0x94, 0x1B, + 0x9D, 0xB5, 0x73, 0x6C, 0x59, 0xB2, 0xA3, 0x13, 0x56, 0xA2, 0xAC, 0x6D, 0x45, 0xB5, 0x36, 0x6D, + 0xDB, 0x11, 0x54, 0x63, 0x51, 0x45, 0x16, 0x92, 0xC9, 0xA5, 0xFC, 0x25, 0x33, 0x11, 0x28, 0x52, + 0x94, 0x04, 0x3C, 0xB1, 0xA3, 0x4A, 0x9A, 0x21, 0x17, 0x67, 0x45, 0x32, 0xF0, 0x88, 0x80, 0x6C, + 0xCD, 0x59, 0x54, 0x0E, 0x48, 0x25, 0x2D, 0x56, 0xB6, 0xD3, 0xE6, 0x6D, 0x64, 0xA3, 0x63, 0x06, + 0xA2, 0x35, 0xA1, 0x11, 0xA5, 0x0A, 0x11, 0xA4, 0x8E, 0xEE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0x02, 0xD1, 0xAA, 0x48, 0x92, + 0x22, 0x2D, 0x51, 0x98, 0xC8, 0xC6, 0x2D, 0xB2, 0x5B, 0x4C, 0x13, 0x51, 0x0D, 0x88, 0x10, 0x1A, + 0x12, 0xD5, 0x1A, 0xD8, 0x9A, 0x21, 0x18, 0x93, 0x08, 0x51, 0x52, 0x6B, 0x5A, 0x4D, 0x46, 0xC4, + 0xD4, 0x8C, 0xC8, 0xB6, 0x1E, 0x20, 0xA8, 0x08, 0xA1, 0x38, 0x22, 0x99, 0x24, 0x96, 0x09, 0x99, + 0x20, 0x98, 0x20, 0x36, 0x18, 0xB1, 0xB2, 0x64, 0x03, 0x25, 0x0D, 0x04, 0x49, 0x30, 0x0D, 0x14, + 0x4D, 0x2C, 0xCA, 0x45, 0x25, 0x98, 0x34, 0x62, 0xA4, 0xC4, 0x8A, 0x98, 0x32, 0xCC, 0x65, 0x49, + 0xB1, 0xB5, 0x95, 0x81, 0x55, 0x1A, 0x35, 0x93, 0x1A, 0x2A, 0x31, 0x68, 0x8C, 0x18, 0xD0, 0x54, + 0x54, 0x5A, 0xA3, 0x5B, 0x05, 0x26, 0xB6, 0x0C, 0x64, 0x21, 0x36, 0x8D, 0x92, 0xD8, 0xD4, 0x62, + 0xDB, 0x26, 0x35, 0x21, 0xA4, 0xD8, 0xD1, 0xA8, 0xB1, 0xAB, 0x1A, 0xD4, 0x54, 0xCB, 0x09, 0x80, + 0x31, 0xB0, 0x6D, 0x49, 0x62, 0xB6, 0x0A, 0x31, 0xA3, 0x6A, 0x0A, 0xC5, 0x8C, 0x46, 0xD4, 0x9A, + 0x88, 0x93, 0x15, 0x82, 0x36, 0x11, 0x4C, 0x98, 0xA5, 0x99, 0x48, 0xAD, 0x32, 0x8D, 0x26, 0xD4, + 0x26, 0x34, 0x9A, 0x88, 0xC6, 0xA9, 0x35, 0x88, 0x8A, 0x89, 0x2B, 0x68, 0xDA, 0xC6, 0xDB, 0x41, + 0x56, 0x8B, 0x6D, 0x14,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x62, 0x92, 0x26, 0x46, 0xA3, 0x12, 0x26, 0xC1, + 0x8A, 0xC4, 0x64, 0x8B, 0x44, 0x48, 0x96, 0x26, 0xEE, 0xB9, 0x62, 0x93, 0x48, 0x06, 0x42, 0x44, + 0x26, 0x6D, 0x30, 0x11, 0x49, 0x34, 0x9B, 0x63, 0x31, 0x48, 0x42, 0xB0, 0xCD, 0x21, 0x8A, 0x28, + 0xD2, 0x59, 0x22, 0x91, 0x81, 0x51, 0x46, 0x4D, 0xA3, 0x18, 0x29, 0x24, 0x4D, 0x5D, 0x0E, 0xEE, + 0x9A, 0x19, 0xCA, 0xB8, 0x43, 0x0C, 0xC9, 0x60, 0x58, 0x8D, 0xAD, 0x1A, 0xD5, 0x10, 0x69, 0xD0, + 0x03, 0xA4, 0xD1, 0xB1, 0x9B, 0x3A, 0xE5, 0xD2, 0x77, 0x75, 0x86, 0x45, 0xCD, 0xCA, 0x52, 0x6B, + 0xBA, 0xE1, 0x14, 0xD0, 0xC7, 0x73, 0xB7, 0x13, 0xBB, 0x71, 0x9A, 0x13, 0x12, 0x24, 0x84, 0xA5, + 0x14, 0x9A, 0x1A, 0x50, 0x95, 0x13, 0x24, 0x89, 0x8C, 0x88, 0x91, 0x83, 0x49, 0x15, 0x1B, 0x31, + 0x88, 0xC8, 0xD3, 0x41, 0x04, 0x40, 0x62, 0xC5, 0x06, 0x48, 0x89, 0x28, 0x14, 0xA8, 0x8B, 0x32, + 0x87, 0x3B, 0x2E, 0x5C, 0x72, 0xE2, 0x6E, 0xEA, 0x4C, 0xDB, 0x9D, 0x55, 0xB8, 0x72, 0x23, 0x9C, + 0xB8, 0x6E, 0x3B, 0x89, 0xB0, 0xC1, 0x10, 0xD2, 0x0A, 0x29, 0xA3, 0x73, 0x8C, 0xDD, 0xD5, 0x74, + 0xB0, 0x14, 0x94, 0x29, 0x19, 0xB3, 0x48, 0x3B, 0xAE, 0xC4, 0x8A, 0x22, 0xA8, 0xDB, 0x3B, 0x18, + 0x05, 0xD6, 0x22, 0x18, 0xD9, 0xA0, 0xC3, 0x44, 0x14, 0x04, 0x11, 0x8C, 0xA1, 0x9A, 0x28, 0xC8, + 0x73, 0xAA, 0xB3, 0x3B, 0xBB, 0x10, 0xC6, 0x58, 0xD4, 0xC3, 0x7F, 0x9D, 0xB6, 0x97, 0x3C, 0x95, + 0xB9, 0xA6, 0x12, 0x24, 0xA8, 0x94, 0xC0, 0xAE, 0x6E, 0xF8, 0x6D, 0x6D, 0x57, 0xF7, 0x17, 0x72, + 0x45, 0x38, 0x50, 0x90, 0xE5, 0x00, 0x24, 0xC9, +}; diff --git a/font.h b/font.h new file mode 100644 index 000000000..15fe39314 --- /dev/null +++ b/font.h @@ -0,0 +1,194 @@ +#define FONT_H 10 +char font_data[] = { + 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0xC7, 0x31, 0x0C, 0x02, 0x70, 0x04, 0x00, 0x00, + 0x05, 0xCC, 0x74, 0x23, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x80, 0x19, 0xCC, 0xE0, 0x3F, 0xCC, 0xF0, 0x2F, 0xCC, 0x90, 0x09, 0x00, 0x00, 0x00, + 0x06, 0x30, 0xD0, 0x3F, 0x33, 0xE1, 0x07, 0xF4, 0x12, 0x33, 0xFF, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x07, 0x2D, 0xCE, 0xCC, 0xE1, 0x1D, 0xC0, 0x03, 0x74, 0x4B, 0x33, 0xB3, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x7D, 0x30, 0x0C, 0x13, 0xD0, 0x32, 0xB3, 0x33, 0x1C, 0x7D, 0x07, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x4C, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x34, 0x1D, 0x07, 0x03, 0x07, 0x1D, 0x34, 0x00, 0x00, 0x00, + 0x04, 0x07, 0x1D, 0x34, 0x30, 0x34, 0x1D, 0x07, 0x00, 0x00, 0x00, + 0x06, 0x44, 0xD0, 0x1C, 0x64, 0xF0, 0x3F, 0x64, 0xD0, 0x1C, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x02, 0x30, 0xE0, 0x2F, 0x30, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0D, 0x03, 0x00, + 0x05, 0x00, 0x00, 0x00, 0xC0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x40, 0x70, 0x00, 0x00, 0x00, + 0x06, 0x80, 0x02, 0x0C, 0xA0, 0x00, 0x03, 0x28, 0xC0, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xF8, 0xE0, 0x39, 0x07, 0x33, 0x32, 0x03, 0xB3, 0x38, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x30, 0xF0, 0x60, 0x03, 0x0C, 0x30, 0xC0, 0x40, 0x07, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xFC, 0xB1, 0x34, 0x41, 0x03, 0x0A, 0x2C, 0x70, 0x00, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xFC, 0x71, 0x34, 0x01, 0x03, 0x1E, 0x00, 0x33, 0x34, 0xFE, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xC0, 0x03, 0x37, 0x1C, 0x73, 0x34, 0xBF, 0x03, 0x30, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xFF, 0x33, 0x00, 0x57, 0xE0, 0x2F, 0x00, 0x13, 0x30, 0xFE, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xF4, 0xD3, 0x00, 0x07, 0xF0, 0x1F, 0x03, 0x33, 0x34, 0xFD, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xFF, 0x07, 0x34, 0x80, 0x03, 0x0E, 0x38, 0xD0, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xFC, 0xB1, 0x34, 0x03, 0xD3, 0x1F, 0x03, 0x73, 0x34, 0xFD, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xFC, 0xB1, 0x34, 0x03, 0xC3, 0x3F, 0x40, 0x23, 0x30, 0xFD, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x70, 0x04, 0x40, 0x70, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x1C, 0x04, 0x00, 0x0C, 0x0D, 0x03, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0xC0, 0xC3, 0x0B, 0x1B, 0xC0, 0x0B, 0xC0, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x0F, 0x90, 0x83, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xFD, 0x71, 0x30, 0x81, 0x03, 0x0E, 0x34, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0xF8, 0x0F, 0x1D, 0x30, 0xE7, 0x37, 0x73, 0x1C, 0xE3, 0x2F, 0x07, 0x00, 0xFD, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x74, 0xD0, 0x1D, 0x47, 0x33, 0x30, 0xFF, 0x33, 0x30, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xBF, 0x30, 0x38, 0x43, 0xF3, 0x1F, 0x43, 0x33, 0x34, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xF4, 0xD1, 0x34, 0x03, 0x31, 0x00, 0x03, 0x70, 0x34, 0xFD, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x7F, 0x30, 0x1D, 0x43, 0x33, 0x30, 0x03, 0x33, 0x34, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xFF, 0x32, 0x00, 0x03, 0xF0, 0x0B, 0x03, 0x30, 0x10, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xFF, 0x33, 0x10, 0x03, 0xF0, 0x0B, 0x03, 0x30, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xF4, 0xD1, 0x34, 0x03, 0x30, 0x3E, 0x03, 0x73, 0x34, 0xFD, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x47, 0x33, 0x30, 0x03, 0xF3, 0x3F, 0x03, 0x33, 0x30, 0x47, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x1D, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1D, 0x00, 0x00, 0x00, + 0x06, 0xD0, 0x01, 0x0C, 0xC0, 0x00, 0x0C, 0xC0, 0x10, 0x0D, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x07, 0x47, 0xC3, 0x34, 0x70, 0x03, 0xBC, 0x00, 0xB3, 0xC0, 0xB0, 0x70, 0xB4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x07, 0x30, 0x00, 0x03, 0x30, 0x00, 0x03, 0x30, 0x10, 0xFF, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x03, 0x30, 0x1F, 0x3D, 0x7B, 0x3B, 0xE3, 0x32, 0x83, 0x30, 0x03, 0x30, 0x03, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x07, 0x07, 0xCD, 0x03, 0x73, 0xC3, 0x8C, 0x32, 0xC3, 0xCD, 0xC0, 0x33, 0xD0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x07, 0xF4, 0x41, 0xC7, 0x71, 0xD0, 0x0C, 0x30, 0x03, 0xCD, 0xD1, 0xD1, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x7F, 0x30, 0x1D, 0x43, 0x73, 0x34, 0xFF, 0x31, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x07, 0xF4, 0x41, 0xD3, 0x71, 0xD0, 0x0C, 0x30, 0xC3, 0xCD, 0xD1, 0xD1, 0xDF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xFF, 0x31, 0x34, 0x03, 0xF3, 0x0F, 0xD7, 0x30, 0x34, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xFC, 0xB1, 0x31, 0x07, 0xD0, 0x0F, 0x90, 0x23, 0x34, 0xFE, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xFF, 0x13, 0x13, 0x30, 0x00, 0x03, 0x30, 0x00, 0x03, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x07, 0x03, 0xCC, 0x00, 0x33, 0xC0, 0x0C, 0x30, 0x03, 0xCD, 0xD2, 0xD1, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x03, 0x33, 0x30, 0x03, 0xB3, 0x38, 0xCD, 0xC1, 0x0D, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x03, 0x30, 0x43, 0x30, 0xC7, 0x34, 0xCD, 0x1C, 0xED, 0x1E, 0x2C, 0x0E, 0x0C, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x07, 0x03, 0x4C, 0xC3, 0x81, 0x3B, 0xD0, 0x03, 0xDC, 0x42, 0xC3, 0x31, 0xC0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x03, 0xB3, 0x38, 0xDC, 0x40, 0x07, 0x30, 0x00, 0x03, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x07, 0xFF, 0x0F, 0xD0, 0x02, 0x2C, 0xC0, 0x02, 0x2D, 0xC0, 0x06, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x2F, 0x03, 0x03, 0x03, 0x03, 0x03, 0x2F, 0x00, 0x00, 0x00, + 0x05, 0x03, 0x28, 0xC0, 0x00, 0x0A, 0x30, 0x80, 0x02, 0x0C, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x3E, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3E, 0x00, 0x00, 0x00, + 0x04, 0x1D, 0x37, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x83, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0xD0, 0x47, 0x30, 0xFC, 0x0C, 0xD3, 0x1F, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x07, 0x0C, 0xF0, 0xC7, 0x35, 0xC3, 0x0C, 0xF3, 0x07, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0xD0, 0xC3, 0x25, 0x03, 0x4C, 0xD2, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x05, 0xD0, 0x00, 0x83, 0x8F, 0x33, 0xC3, 0x1C, 0xD3, 0x1F, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0xD0, 0xC7, 0x30, 0xBF, 0x0C, 0xD0, 0x0B, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x3D, 0x07, 0x03, 0x2F, 0x03, 0x03, 0x07, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0xC0, 0xCB, 0x32, 0xC3, 0xF4, 0x03, 0x4C, 0x30, 0x7E, 0x00, 0x00, + 0x05, 0x03, 0x0C, 0xF0, 0xC7, 0x39, 0xC3, 0x0C, 0x73, 0x1C, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x04, 0x1C, 0x00, 0x0D, 0x0C, 0x0C, 0x1D, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x30, 0x00, 0x34, 0x30, 0x30, 0x30, 0x30, 0x1E, 0x00, + 0x05, 0x03, 0x0C, 0x31, 0xCE, 0x0E, 0x1F, 0xCC, 0x31, 0x1C, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x47, 0x3D, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x9B, 0x71, 0x37, 0x33, 0x33, 0x32, 0x43, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0xF0, 0xC7, 0x31, 0xC3, 0x0C, 0x33, 0x0D, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0xD0, 0xC7, 0x31, 0xC3, 0x4C, 0xD3, 0x07, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0xF0, 0xC7, 0x31, 0xC3, 0x4C, 0xF3, 0xC7, 0x00, 0x03, 0x00, 0x00, + 0x05, 0x00, 0x00, 0xD0, 0xDF, 0x31, 0xC3, 0x4C, 0xD3, 0x0F, 0x30, 0xC0, 0x00, 0x05, + 0x03, 0x00, 0x30, 0x7F, 0xC7, 0x30, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0xC0, 0xC7, 0x10, 0x3C, 0x04, 0xF3, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x1C, 0x74, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x70, 0xDC, 0x30, 0xC3, 0x4C, 0xD3, 0x1F, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x30, 0xCC, 0x30, 0xD3, 0xDC, 0xC2, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x47, 0x33, 0x32, 0x33, 0x73, 0x37, 0xCD, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x30, 0xCD, 0x32, 0x7D, 0x8C, 0x73, 0x0C, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x30, 0xCC, 0x30, 0xC7, 0x74, 0x43, 0x07, 0x0C, 0x1F, 0x00, 0x00, + 0x05, 0x00, 0x00, 0xF0, 0x4F, 0x2C, 0x2C, 0x2C, 0xF1, 0x0F, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x38, 0x0C, 0x0C, 0x03, 0x0C, 0x0C, 0x38, 0x00, 0x00, 0x00, + 0x02, 0x32, 0x33, 0x33, 0x13, 0x00, + 0x04, 0x0B, 0x0C, 0x0C, 0x30, 0x0C, 0x0C, 0x0B, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x1D, 0x72, 0x37, 0xD2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x07, 0x00, 0x1F, 0x00, 0x7F, 0x00, 0xFF, 0x01, 0xFF, 0x07, 0xFF, 0x1F, 0xFF, 0x7F, 0xFF, 0x1B, 0xBF, 0x01, 0x1B, 0x00, + 0x0C, 0x00, 0x40, 0xFF, 0x00, 0x00, 0xF8, 0xF0, 0x3F, 0xEE, 0x2C, 0x30, 0xCB, 0x0B, 0x30, 0x42, 0xC3, 0x33, 0x00, 0x03, 0x30, 0x00, 0xF3, 0x33, 0x00, 0x03, 0x30, 0x00, 0xFF, 0x3F, 0x00, + 0x0C, 0xC2, 0x00, 0x00, 0xCB, 0x00, 0x00, 0xEE, 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0x03, 0x00, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x09, 0xFE, 0xFF, 0xE3, 0xFF, 0x0F, 0xAA, 0x3E, 0x0A, 0xF8, 0x2E, 0xE0, 0xBF, 0x80, 0xFF, 0xAA, 0xFE, 0xFF, 0xE2, 0xFF, 0x02, 0x02, 0x00, 0x00, + 0x09, 0x00, 0x80, 0x04, 0xD0, 0xE2, 0xFF, 0x02, 0x00, 0x00, 0xFF, 0x6F, 0x00, 0x40, 0xE6, 0xAF, 0x50, 0x00, 0x09, 0x00, 0x20, 0x00, 0x64, 0x00, + 0x09, 0xE0, 0x3F, 0x70, 0x60, 0x63, 0xC0, 0xE4, 0x80, 0xC2, 0x03, 0x07, 0x0F, 0x1E, 0x6C, 0xFF, 0x27, 0xFF, 0x3F, 0xE0, 0x2F, 0x00, 0x00, 0x00, + 0x09, 0x44, 0x44, 0x00, 0x12, 0x41, 0x88, 0x04, 0x21, 0x21, 0x84, 0x48, 0x20, 0x23, 0xC2, 0xCC, 0x08, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x78, 0x00, 0xB4, 0x07, 0xF0, 0x2F, 0xC0, 0xFB, 0x00, 0xBE, 0x02, 0xF4, 0x07, 0xFD, 0xFF, 0x01, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x40, 0x01, 0x00, 0x19, 0x00, 0xA8, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x3F, 0x00, 0x00, 0xF0, 0x03, 0x00, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0xF0, 0x03, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0xFC, 0xFF, 0x3F, 0x00, 0xF0, 0xDC, 0xCB, 0x03, 0x00, 0xFF, 0xFF, 0x4F, 0x07, 0x40, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x0F, 0xFF, 0x3F, 0xFC, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0A, 0xFF, 0xFF, 0x3F, 0x00, 0xC0, 0x07, 0x00, 0xBD, 0x02, 0xE8, 0xB3, 0xE0, 0x3C, 0xAC, 0xC3, 0x03, 0x0F, 0x3C, 0x00, 0xC0, 0x03, 0x00, 0xFC, 0xFF, 0xFF, + 0x0B, 0xC0, 0xC8, 0xC0, 0x91, 0x1B, 0xCD, 0x36, 0xE7, 0x00, 0x47, 0x03, 0xA7, 0x80, 0x36, 0xFD, 0xFF, 0xC1, 0x9B, 0xF9, 0xB8, 0xB8, 0xB8, 0xB7, 0x99, 0xF7, 0xFF, 0xFF, 0x0F, + 0x0B, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0xF0, 0x03, 0x00, 0xFC, 0x00, 0xC0, 0xFF, 0x00, 0xF0, 0x3F, 0x00, 0xFF, 0x3F, 0xF0, 0xFF, 0x3F, 0xFC, 0xFF, 0xCF, 0xFF, 0xFF, 0x0F, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x1F, 0xCB, 0x30, 0xC3, 0x3F, 0xC7, 0x00, 0x7E, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 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0x00, + 0x05, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x39, 0xC0, 0x00, 0x43, 0x2F, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0xD0, 0x87, 0x30, 0x60, 0x60, 0x60, 0xC0, 0x3F, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0xD0, 0x87, 0x30, 0xB8, 0x00, 0x23, 0x4C, 0x1F, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x0E, 0x36, 0xC6, 0xFC, 0x03, 0x0C, 0x30, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0xF0, 0xCB, 0x00, 0x7F, 0x40, 0x13, 0x8C, 0x1F, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0xD0, 0xCB, 0x10, 0x2F, 0x4C, 0x33, 0x4C, 0x1F, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0xF0, 0x0F, 0x30, 0x60, 0x60, 0xC0, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0xD0, 0xC7, 0x30, 0x7D, 0x4C, 0x33, 0x4C, 0x1F, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0xD0, 0xC7, 0x30, 0xC6, 0xE0, 0x03, 0x8C, 0x1F, 0x00, 0x00, 0x00, + 0x04, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, + 0x03, 0xC0, 0xF0, 0x3C, 0xCF, 0xF3, 0x3C, 0x03, 0x00, + 0x03, 0x00, 0xCC, 0xF3, 0x3C, 0xCF, 0xF3, 0x30, 0x00, + 0x05, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x00, +}; +short font_ptrs[] = { + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x000E, 0x0017, 0x0025, 0x0035, 0x0045, 0x0058, 0x0068, + 0x0071, 0x007C, 0x0087, 0x0097, 0x00A7, 0x00B2, 0x00C0, 0x00C9, + 0x00D9, 0x00E9, 0x00F7, 0x0107, 0x0117, 0x0127, 0x0137, 0x0147, + 0x0157, 0x0167, 0x0177, 0x0180, 0x018B, 0x019B, 0x01AB, 0x01BB, + 0x01CB, 0x01E0, 0x01F0, 0x0200, 0x0210, 0x0220, 0x0230, 0x0240, + 0x0250, 0x0260, 0x026B, 0x027B, 0x028E, 0x029E, 0x02B3, 0x02C6, + 0x02D9, 0x02E9, 0x02FC, 0x030C, 0x031C, 0x032C, 0x033F, 0x034F, + 0x0364, 0x0377, 0x0387, 0x039A, 0x03A5, 0x03B3, 0x03BE, 0x03C9, + 0x03D9, 0x03E2, 0x03F0, 0x03FE, 0x040C, 0x041A, 0x0428, 0x0433, + 0x0441, 0x044F, 0x045A, 0x0465, 0x0473, 0x047E, 0x048E, 0x049C, + 0x04AA, 0x04B8, 0x04C6, 0x04CF, 0x04DD, 0x04E8, 0x04F6, 0x0504, + 0x0514, 0x0522, 0x0530, 0x053E, 0x0549, 0x054F, 0x055A, 0x056A, + 0x0575, 0x058A, 0x05A9, 0x05C8, 0x05E2, 0x0601, 0x061B, 0x0635, + 0x064F, 0x0669, 0x0683, 0x069D, 0x06B7, 0x06D6, 0x06E6, 0x0700, + 0x071A, 0x0734, 0x074E, 0x0763, 0x0780, 0x079D, 0x07BC, 0x07DB, + 0x07F3, 0x080B, 0x0823, 0x083B, 0x0853, 0x086B, 0x0883, 0x089B, + 0x08B3, 0x08CB, 0x08E3, 0x08FD, 0x091A, 0x0937, 0x094C, 0x0966, + 0x0980, 0x099A, 0x09B4, 0x09CC, 0x09D7, 0x09E0, 0x09E9, 0x09F7, + 0x0A05, 0x0A13, 0x0A21, 0x0A2F, 0x0A3D, 0x0A4B, 0x0A59, 0x0A67, + 0x0A75, 0x0A83, 0x0A8E, 0x0A97, 0x0AA0, 0x0AAE, 0x0AAE, 0x0AAE, + 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, + 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, + 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, + 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, + 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, + 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, + 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, + 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, 0x0AAE, +}; diff --git a/font/Makefile b/font/Makefile new file mode 100644 index 000000000..e3b0c8c16 --- /dev/null +++ b/font/Makefile @@ -0,0 +1,5 @@ +editor: editor.c + gcc -oeditor -DSCALE=2 editor.c -lSDL -lm -O3 -ffast-math -march=k8 -Wall -std=c99 + +clean: + rm -f editor packer diff --git a/font/editor.c b/font/editor.c new file mode 100644 index 000000000..71c5aa039 --- /dev/null +++ b/font/editor.c @@ -0,0 +1,284 @@ +#include +#include +#include +#include +#include + +#define CELLW 12 +#define CELLH 10 + +#define XRES 800 +#define YRES 600 + +char xsize=CELLW, ysize=CELLH; +char base=7, top=2; +char font[256][CELLH][CELLW]; +char width[256]; + +void blendpixel(unsigned *vid, int x, int y, int r, int g, int b, int a) +{ + int t; + if(x<0 || y<0 || x>=XRES || y>=YRES) + return; + if(a!=255) { + t = vid[y*XRES+x]; + r = (a*r + (255-a)*((t>>16)&255)) >> 8; + g = (a*g + (255-a)*((t>>8)&255)) >> 8; + b = (a*b + (255-a)*(t&255)) >> 8; + } + vid[y*XRES+x] = (r<<16)|(g<<8)|b; +} + +int drawchar(unsigned *vid, int x, int y, int c, int r, int g, int b) +{ + int i, j; + for(j=0; jabs(x2-x1), x, y, dx, dy, sy; + float e, de; + if(cp) { + y = x1; + x1 = y1; + y1 = y; + y = x2; + x2 = y2; + y2 = y; + } + if(x1 > x2) { + y = x1; + x1 = x2; + x2 = y; + y = y1; + y1 = y2; + y2 = y; + } + dx = x2 - x1; + dy = abs(y2 - y1); + e = 0.0f; + de = dy/(float)dx; + y = y1; + sy = (y1= 0.5f) { + y += sy; + e -= 1.0f; + } + } +} + +void drawcell(unsigned *vid, int i, int j, int c, int m) +{ + int x,y,x0=i*32+64,y0=j*32+64; + for(y=1;y<32;y++) + for(x=1;x<32;x++) + blendpixel(vid, x0+x, y0+y, 127*m, 127*m, 127*m, c); + for(x=0;x<32;x+=2) { + if(!j) + blendpixel(vid, x0+x, y0, 64*m, 64*m, 64*m, 255); + if(!i) + blendpixel(vid, x0, y0+x, 64*m, 64*m, 64*m, 255); + blendpixel(vid, x0+x, y0+32, 64*m, 64*m, 64*m, 255); + blendpixel(vid, x0+32, y0+x, 64*m, 64*m, 64*m, 255); + } +} + +/*********************************************************** + * SDL OUTPUT * + ***********************************************************/ + +SDL_Surface *sdl_scrn; +int sdl_key; +void sdl_open(void) +{ + if(SDL_Init(SDL_INIT_VIDEO)<0) { + fprintf(stderr, "Initializing SDL: %s\n", SDL_GetError()); + exit(1); + } + atexit(SDL_Quit); + sdl_scrn=SDL_SetVideoMode(XRES*SCALE,YRES*SCALE + 40*SCALE,32,SDL_SWSURFACE); + if(!sdl_scrn) { + fprintf(stderr, "Creating window: %s\n", SDL_GetError()); + exit(1); + } +} + +void sdl_blit(int x, int y, int w, int h, unsigned int *src, int pitch) +{ + unsigned *dst,i,j,k; + if(SDL_MUSTLOCK(sdl_scrn)) + if(SDL_LockSurface(sdl_scrn)<0) + return; + dst=(unsigned *)sdl_scrn->pixels+y*sdl_scrn->pitch/4+x; + for(j=0;jpitch/4; + } + src+=pitch/4; + } + if(SDL_MUSTLOCK(sdl_scrn)) + SDL_UnlockSurface(sdl_scrn); + SDL_UpdateRect(sdl_scrn,0,0,0,0); +} + +int frame_idx=0; +void dump_frame(unsigned int *src, int w, int h, int pitch) +{ + char frame_name[32]; + unsigned j,i,c; + FILE *f; + sprintf(frame_name,"frame%04d.ppm",frame_idx); + f=fopen(frame_name,"w"); + fprintf(f,"P6\n%d %d\n255\n",w,h); + for(j=0;j>16)|(src[i]&0x00FF00)|((src[i]&0x0000FF)<<16); + fwrite(&c,3,1,f); + } + src+=pitch/4; + } + fclose(f); + frame_idx++; +} + +int sdl_poll(void) +{ + SDL_Event event; + sdl_key=0; + while(SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_KEYDOWN: + sdl_key=event.key.keysym.sym; + break; + case SDL_QUIT: + return 1; + } + } + return 0; +} + +/*********************************************************** + * MAIN PROGRAM * + ***********************************************************/ + +char *tag = "(c) 2008 Stanislaw Skowronek"; + +int main(int argc, char *argv[]) +{ + unsigned *vid_buf = calloc(XRES*YRES, sizeof(unsigned)); + int x, y, b = 0, lb, c = 0xA0, i, j, dc = 0; + int mode = 0; + FILE *f; + + f = fopen("font.bin", "r"); + if(f) { + fread(&xsize, 1, 1, f); + fread(&ysize, 1, 1, f); + fread(&base, 1, 1, f); + fread(&top, 1, 1, f); + fread(width, 1, 256, f); + fread(font, CELLW*CELLH, 256, f); + fclose(f); + } + + sdl_open(); + while(!sdl_poll()) { + if(sdl_key=='q' || sdl_key==SDLK_ESCAPE) + break; + if(sdl_key==' ' || sdl_key=='=') { + c++; + printf("Current: %02X '%c'\n", c, c); + } + if(sdl_key=='\b' || sdl_key=='-') { + c--; + printf("Current: %02X '%c'\n", c, c); + } + + lb = b; + b = SDL_GetMouseState(&x, &y); + if(b) { + x /= SCALE; + y /= SCALE; + } + + i = x/32-2; + j = y/32-2; + if(!lb && b && (i<0 || i>=CELLW)) { + if(abs(j-base) < abs(j-top)) + mode = 2; // BASE + else + mode = 3; // TOP + } else if(!lb && b && (j<0 || j>=CELLH)) + mode = 4; // LEFT + else if(!lb && b) { + mode = 1; // DRAW + if(b==1) + dc = (font[c][j][i]+3)%4; + else + dc = (font[c][j][i]+1)%4; + } + + if(b) + switch(mode) { + case 1: + if(i>=0 && j>=0 && i=width[c]?1:2); + drawline(vid_buf, 32, 64+base*32, 128+32*CELLW, 64+base*32, 128, 255, 128, 255); + drawline(vid_buf, 32, 64+top*32, 128+32*CELLW, 64+top*32, 128, 128, 255, 255); + drawline(vid_buf, 64+width[c]*32, 32, 64+width[c]*32, 128+32*CELLH, 255, 128, 128, 255); + + drawtext(vid_buf, 64, 192+32*CELLH, "A quick brown fox jumps over the lazy dog.", 255, 255, 255); + drawtext(vid_buf, 64, 192+33*CELLH, "A QUICK BROWN FOX JUMPS OVER THE LAZY DOG.", 255, 255, 255); + drawtext(vid_buf, 64, 192+34*CELLH, "0123456789 ~`!@#$%^&*()-=_+[]{}\\|;:'\",./<>?", 255, 255, 255); + + drawchar(vid_buf, 32, 192+32*CELLH, c, 255, 255, 255); + + sdl_blit(0, 0, XRES, YRES, vid_buf, XRES*4); + } + + f = fopen("font.bin", "w"); + fwrite(&xsize, 1, 1, f); + fwrite(&ysize, 1, 1, f); + fwrite(&base, 1, 1, f); + fwrite(&top, 1, 1, f); + fwrite(width, 1, 256, f); + fwrite(font, CELLW*CELLH, 256, f); + fclose(f); + + return 0; +} diff --git a/font/font.bin b/font/font.bin new file mode 100644 index 0000000000000000000000000000000000000000..b81615a3d7ad7e8a7aab2b62ac92e7c02939bfd5 GIT binary patch literal 30980 zcmeHO4R_l(4ovLS&9?dfzxQVFId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 zTwP`7PZ*hDdVCsCv2%GAZtxTGK;8cmmJ7zEMB2Wcu&3QLiD7N^`DF()dR=h&n3Bpsv#6?XzoukDZZ!;hD`?_y&~i!4 z$S!JfV6z5NCA3L1VeMgvPj7{i=@5D##(NL3&BHK1eb_=;`^0y64#AOXq^7_(HLmys}TR=f^{7`k!t)$Ov^FMLbh#Z^S&6)=D|^o%OY}7 zKl!Ni$E6vS%;zMwgqc##uS=>&tC|&!xWzc~D?^Oo_Dy~(7ZHIvE1Y<4<$%c)JoJ$k z^I}o#V)7Aki>6TTtIb zJm;M;pCS%;-}{kw*e^(77liQf zKcIrt2eiT z&BzvEq5M@G0IFB}v6_P4q-G++9~GHa5}+OH>SsGt@m<3w%N)Z4viK^da>X%Z@bOA# za+aQh15BfhJoFV)xok;|>E}O=aMfXD`TE(+$dG%bKge=+sqgu03LZ=?VCs9P-c84o+1-t?F|4Hj)ViE=7ml1ex=Uy8qS(Yg02WecTm)rXSw`DzB69! zD}EJ|G)g|ZzFOO#kR`@Jtbn1_Oui%!46}hSe~C#cD|(t>-^pFlvpN=H;C<4 zGQvq&f*Wi^FOW-I6<8Hm6<8Hm6<8Hm6<8Hm6<8Hm6<8Hm6<8Hm6<8Hm6<8Hm6<8Hm a6<8Hm6<8Hm6<8Hm6<8Hm75Klez<&Tpk|~z} literal 0 HcmV?d00001 diff --git a/font/packer.c b/font/packer.c new file mode 100644 index 000000000..db57b1a08 --- /dev/null +++ b/font/packer.c @@ -0,0 +1,100 @@ +#include +#include +#include +#include + +#define CELLW 12 +#define CELLH 10 + +char xsize=CELLW, ysize=CELLH; +char base=7, top=2; +char font[256][CELLH][CELLW]; +char width[256]; + +int bits_n = 0, bits_a = 0; +int flush_bits(void) +{ + if(bits_n) { + bits_a >>= 8-bits_n; + printf("0x%02X, ", bits_a); + bits_a = 0; + bits_n = 0; + return 1; + } + return 0; +} +int stock_bits(int b, int nb) +{ + bits_a >>= nb; + bits_a |= b << (8-nb); + bits_n += nb; + if(bits_n >= 8) { + printf("0x%02X, ", bits_a); + bits_a = 0; + bits_n = 0; + return 1; + } + return 0; +} + +int save_char(int c) +{ + int nb = 1; + int x, y; + + if(!width[c]) + return 0; + + printf(" 0x%02X, ", width[c]); + + for(y=0; y +#include +#include +#include +#include +#ifndef MACOSX +#include +#endif +#include +#ifdef WIN32 +#define _WIN32_WINNT 0x0501 +#include +#include +#else +#include +#include +#include +#include +#include +#endif + +#include "http.h" +#include "md5.h" + +#ifdef WIN32 +#define PERROR SOCKET_ERROR +#define PERRNO WSAGetLastError() +#define PEAGAIN WSAEWOULDBLOCK +#define PEINTR WSAEINTR +#define PEINPROGRESS WSAEINPROGRESS +#define PEALREADY WSAEALREADY +#define PCLOSE closesocket +#else +#define PERROR -1 +#define PERRNO errno +#define PEAGAIN EAGAIN +#define PEINTR EINTR +#define PEINPROGRESS EINPROGRESS +#define PEALREADY EALREADY +#define PCLOSE close +#endif + +static int http_up = 0; +static long http_timeout = 15; +static int http_use_proxy = 0; +static struct sockaddr_in http_proxy; + +static char *mystrdup(char *s) +{ + char *x; + if(s) { + x = malloc(strlen(s)+1); + strcpy(x, s); + return x; + } + return s; +} + +static int splituri(char *uri, char **host, char **path) +{ + char *p=uri,*q,*x,*y; + if(!strncmp(p, "http://", 7)) + p += 7; + q = strchr(p, '/'); + if(!q) + q = p + strlen(p); + x = malloc(q-p+1); + if(*q) + y = mystrdup(q); + else + y = mystrdup("/"); + strncpy(x, p, q-p); + x[q-p] = 0; + if(q==p || x[q-p-1]==':') { + free(x); + free(y); + return 1; + } + *host = x; + *path = y; + return 0; +} + +static char *getserv(char *host) +{ + char *q, *x = mystrdup(host); + q = strchr(x, ':'); + if(q) + *q = 0; + return x; +} + +static char *getport(char *host) +{ + char *p, *q; + q = strchr(host, ':'); + if(q) + p = mystrdup(q+1); + else + p = mystrdup("80"); + return p; +} + +static int resolve(char *dns, char *srv, struct sockaddr_in *addr) +{ + struct addrinfo hnt, *res = 0; + if(http_use_proxy) { + memcpy(addr, &http_proxy, sizeof(struct sockaddr_in)); + return 0; + } + memset(&hnt, 0, sizeof(hnt)); + hnt.ai_family = AF_INET; + hnt.ai_socktype = SOCK_STREAM; + if(getaddrinfo(dns, srv, &hnt, &res)) + return 1; + if(res) { + if(res->ai_family != AF_INET) { + freeaddrinfo(res); + return 1; + } + memcpy(addr, res->ai_addr, res->ai_addrlen); + freeaddrinfo(res); + return 0; + } + return 1; +} + +void http_init(char *proxy) +{ + char *host, *port; +#ifdef WIN32 + WSADATA wsadata; + if(!WSAStartup(MAKEWORD(2,2), &wsadata)) + http_up = 1; +#else + signal(SIGPIPE, SIG_IGN); + http_up = 1; +#endif + if(proxy) { + host = getserv(proxy); + port = getport(proxy); + if(resolve(host, port, &http_proxy)) + http_up = 0; + else + http_use_proxy = 1; + free(host); + free(port); + } +} + +void http_done(void) +{ +#ifdef WIN32 + WSACleanup(); +#endif + http_up = 0; +} + +#define CHUNK 4096 + +#define HTS_STRT 0 +#define HTS_RSLV 1 +#define HTS_CONN 2 +#define HTS_IDLE 3 +#define HTS_XMIT 4 +#define HTS_RECV 5 +#define HTS_DONE 6 +struct http_ctx { + int state; + long last; + int keep; + int ret; + char *host, *path; + char *thdr; + int thlen; + char *txd; + int txdl; + struct sockaddr_in addr; + char *tbuf; + int tlen, tptr; + char *hbuf; + int hlen, hptr; + char *rbuf; + int rlen, rptr; + int chunked, chunkhdr, rxtogo, contlen, cclose; + int fd; + char *fdhost; +}; +void *http_async_req_start(void *ctx, char *uri, char *data, int dlen, int keep) +{ + struct http_ctx *cx = ctx; + if(!ctx) { + ctx = calloc(1, sizeof(struct http_ctx)); + cx = ctx; + cx->fd = PERROR; + } + + if(!cx->hbuf) { + cx->hbuf = malloc(256); + cx->hlen = 256; + } + + if(!http_up) { + cx->ret = 604; + cx->state = HTS_DONE; + return ctx; + } + + if(cx->state!=HTS_STRT && cx->state!=HTS_IDLE) { + fprintf(stderr, "HTTP: unclean request restart state.\n"); + exit(1); + } + + cx->keep = keep; + cx->ret = 600; + if(splituri(uri, &cx->host, &cx->path)) { + cx->ret = 601; + cx->state = HTS_DONE; + return ctx; + } + if(http_use_proxy) { + free(cx->path); + cx->path = mystrdup(uri); + } + if(cx->fdhost && strcmp(cx->host, cx->fdhost)) { + free(cx->fdhost); + cx->fdhost = NULL; + PCLOSE(cx->fd); + cx->fd = PERROR; + cx->state = HTS_STRT; + } + if(data) { + if(!dlen) + dlen = strlen(data); + cx->txd = malloc(dlen); + memcpy(cx->txd, data, dlen); + cx->txdl = dlen; + } else + cx->txdl = 0; + + cx->contlen = 0; + cx->chunked = 0; + cx->chunkhdr = 0; + cx->rxtogo = 0; + cx->cclose = 0; + + cx->tptr = 0; + cx->tlen = 0; + + cx->last = time(NULL); + + return ctx; +} + +void http_async_add_header(void *ctx, char *name, char *data) +{ + struct http_ctx *cx = ctx; + cx->thdr = realloc(cx->thdr, cx->thlen + strlen(name) + strlen(data) + 4); + cx->thlen += sprintf(cx->thdr+cx->thlen, "%s: %s\n", name, data); +} + +static void process_header(struct http_ctx *cx, char *str) +{ + char *p; + if(cx->chunkhdr) { + p = strchr(str, ';'); + if(p) + *p = 0; + cx->rxtogo = strtoul(str, NULL, 16); + cx->chunkhdr = 0; + if(!cx->rxtogo) + cx->chunked = 0; + } + if(!str[0]) { + cx->rxtogo = cx->contlen; + cx->chunkhdr = cx->chunked; + if(!cx->contlen && !cx->chunked && cx->ret!=100) + cx->state = HTS_DONE; + return; + } + if(!strncmp(str, "HTTP/", 5)) { + p = strchr(str, ' '); + if(!p) { + cx->ret = 603; + cx->state = HTS_DONE; + return; + } + p++; + cx->ret = atoi(p); + return; + } + if(!strncmp(str, "Content-Length: ", 16)) { + cx->contlen = atoi(str+16); + return; + } + if(!strcmp(str, "Transfer-Encoding: chunked")) { + cx->chunked = 1; + return; + } + if(!strcmp(str, "Connection: close")) { + cx->cclose = 1; + return; + } +} + +static void process_byte(struct http_ctx *cx, char ch) +{ + if(cx->rxtogo) { + cx->rxtogo--; + + if(!cx->rbuf) { + cx->rbuf = malloc(256); + cx->rlen = 256; + } + if(cx->rptr >= cx->rlen-1) { + cx->rlen *= 2; + cx->rbuf = realloc(cx->rbuf, cx->rlen); + } + cx->rbuf[cx->rptr++] = ch; + + if(!cx->rxtogo && !cx->chunked) + cx->state = HTS_DONE; + } else { + if(ch == '\n') { + cx->hbuf[cx->hptr] = 0; + process_header(cx, cx->hbuf); + cx->hptr = 0; + } else if(ch != '\r') { + if(cx->hptr >= cx->hlen-1) { + cx->hlen *= 2; + cx->hbuf = realloc(cx->hbuf, cx->hlen); + } + cx->hbuf[cx->hptr++] = ch; + } + } +} + +int http_async_req_status(void *ctx) +{ + struct http_ctx *cx = ctx; + char *dns,*srv,buf[CHUNK]; + int tmp, i; + long now = time(NULL); +#ifdef WIN32 + unsigned long tmp2; +#endif + + switch(cx->state) { + case HTS_STRT: + dns = getserv(cx->host); + srv = getport(cx->host); + if(resolve(dns, srv, &cx->addr)) { + free(dns); + free(srv); + cx->state = HTS_DONE; + cx->ret = 602; + return 1; + } + free(dns); + free(srv); + cx->state = HTS_RSLV; + return 0; + case HTS_RSLV: + cx->state = HTS_CONN; + cx->last = now; + return 0; + case HTS_CONN: + if(cx->fd == PERROR) { + cx->fd = socket(AF_INET, SOCK_STREAM, 0); + if(cx->fd == PERROR) + goto fail; + cx->fdhost = mystrdup(cx->host); +#ifdef WIN32 + tmp2 = 1; + if(ioctlsocket(cx->fd, FIONBIO, &tmp2) == SOCKET_ERROR) + goto fail; +#else + tmp = fcntl(cx->fd, F_GETFL); + if(tmp < 0) + goto fail; + if(fcntl(cx->fd, F_SETFL, tmp|O_NONBLOCK) < 0) + goto fail; +#endif + } + if(!connect(cx->fd, (struct sockaddr *)&cx->addr, sizeof(cx->addr))) + cx->state = HTS_IDLE; +#ifdef WIN32 + else if(PERRNO==WSAEISCONN) + cx->state = HTS_IDLE; +#endif +#ifdef MACOSX + else if(PERRNO==EISCONN) + cx->state = HTS_IDLE; +#endif + else if(PERRNO!=PEINPROGRESS && PERRNO!=PEALREADY +#ifdef WIN32 + && PERRNO!=PEAGAIN && PERRNO!=WSAEINVAL +#endif + ) + goto fail; + if(now-cx->last>http_timeout) + goto timeout; + return 0; + case HTS_IDLE: + if(cx->txdl) { + // generate POST + cx->tbuf = malloc(strlen(cx->host) + strlen(cx->path) + 96 + cx->txdl + cx->thlen); + cx->tptr = 0; + cx->tlen = 0; + cx->tlen += sprintf(cx->tbuf+cx->tlen, "POST %s HTTP/1.1\n", cx->path); + cx->tlen += sprintf(cx->tbuf+cx->tlen, "Host: %s\n", cx->host); + if(!cx->keep) + cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\n"); + if(cx->thdr) { + memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen); + cx->tlen += cx->thlen; + free(cx->thdr); + cx->thdr = NULL; + cx->thlen = 0; + } + cx->tlen += sprintf(cx->tbuf+cx->tlen, "Content-Length: %d\n", cx->txdl); + cx->tlen += sprintf(cx->tbuf+cx->tlen, "\n"); + memcpy(cx->tbuf+cx->tlen, cx->txd, cx->txdl); + cx->tlen += cx->txdl; + free(cx->txd); + cx->txd = NULL; + cx->txdl = 0; + } else { + // generate GET + cx->tbuf = malloc(strlen(cx->host) + strlen(cx->path) + 64 + cx->thlen); + cx->tptr = 0; + cx->tlen = 0; + cx->tlen += sprintf(cx->tbuf+cx->tlen, "GET %s HTTP/1.1\n", cx->path); + cx->tlen += sprintf(cx->tbuf+cx->tlen, "Host: %s\n", cx->host); + if(cx->thdr) { + memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen); + cx->tlen += cx->thlen; + free(cx->thdr); + cx->thdr = NULL; + cx->thlen = 0; + } + if(!cx->keep) + cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\n"); + cx->tlen += sprintf(cx->tbuf+cx->tlen, "\n"); + } + cx->state = HTS_XMIT; + cx->last = now; + return 0; + case HTS_XMIT: + tmp = send(cx->fd, cx->tbuf+cx->tptr, cx->tlen-cx->tptr, 0); + if(tmp==PERROR && PERRNO!=PEAGAIN && PERRNO!=PEINTR) + goto fail; + if(tmp!=PERROR) { + cx->tptr += tmp; + if(cx->tptr == cx->tlen) { + cx->tptr = 0; + cx->tlen = 0; + free(cx->tbuf); + cx->state = HTS_RECV; + } + cx->last = now; + } + if(now-cx->last>http_timeout) + goto timeout; + return 0; + case HTS_RECV: + tmp = recv(cx->fd, buf, CHUNK, 0); + if(tmp==PERROR && PERRNO!=PEAGAIN && PERRNO!=PEINTR) + goto fail; + if(tmp!=PERROR) { + for(i=0;istate == HTS_DONE) + return 1; + } + cx->last = now; + } + if(now-cx->last>http_timeout) + goto timeout; + return 0; + case HTS_DONE: + return 1; + } + return 0; + +fail: + cx->ret = 600; + cx->state = HTS_DONE; + return 1; + +timeout: + cx->ret = 605; + cx->state = HTS_DONE; + return 1; +} + +char *http_async_req_stop(void *ctx, int *ret, int *len) +{ + struct http_ctx *cx = ctx; + char *rxd; + + if(cx->state != HTS_DONE) + while(!http_async_req_status(ctx)) ; + + if(cx->host) { + free(cx->host); + cx->host = NULL; + } + if(cx->path) { + free(cx->path); + cx->path = NULL; + } + if(cx->txd) { + free(cx->txd); + cx->txd = NULL; + cx->txdl = 0; + } + if(cx->hbuf) { + free(cx->hbuf); + cx->hbuf = NULL; + } + if(cx->thdr) { + free(cx->thdr); + cx->thdr = NULL; + cx->thlen = 0; + } + + if(ret) + *ret = cx->ret; + if(len) + *len = cx->rptr; + if(cx->rbuf) + cx->rbuf[cx->rptr] = 0; + rxd = cx->rbuf; + cx->rbuf = NULL; + cx->rlen = 0; + cx->rptr = 0; + cx->contlen = 0; + + if(!cx->keep) + http_async_req_close(ctx); + else if(cx->cclose) { + PCLOSE(cx->fd); + cx->fd = PERROR; + if(cx->fdhost) { + free(cx->fdhost); + cx->fdhost = NULL; + } + cx->state = HTS_STRT; + } else + cx->state = HTS_IDLE; + + return rxd; +} + +void http_async_get_length(void *ctx, int *total, int *done) +{ + struct http_ctx *cx = ctx; + if(done) + *done = cx->rptr; + if(total) + *total = cx->contlen; +} + +void http_async_req_close(void *ctx) +{ + struct http_ctx *cx = ctx; + void *tmp; + if(cx->host) { + cx->keep = 1; + tmp = http_async_req_stop(ctx, NULL, NULL); + if(tmp) + free(tmp); + } + if(cx->fdhost) + free(cx->fdhost); + PCLOSE(cx->fd); + free(ctx); +} + +char *http_simple_get(char *uri, int *ret, int *len) +{ + void *ctx = http_async_req_start(NULL, uri, NULL, 0, 0); + if(!ctx) { + if(ret) + *ret = 600; + if(len) + *len = 0; + return NULL; + } + return http_async_req_stop(ctx, ret, len); +} + +char *http_simple_post(char *uri, char *data, int dlen, int *ret, int *len) +{ + void *ctx = http_async_req_start(NULL, uri, data, dlen, 0); + if(!ctx) { + if(ret) + *ret = 600; + if(len) + *len = 0; + return NULL; + } + return http_async_req_stop(ctx, ret, len); +} + +char *http_ret_text(int ret) +{ + switch(ret) { + case 100: return "Continue"; + case 101: return "Switching Protocols"; + case 102: return "Processing"; + + case 200: return "OK"; + case 201: return "Created"; + case 202: return "Accepted"; + case 203: return "Non-Authoritative Information"; + case 204: return "No Content"; + case 205: return "Reset Content"; + case 206: return "Partial Content"; + case 207: return "Multi-Status"; + + case 300: return "Multiple Choices"; + case 301: return "Moved Permanently"; + case 302: return "Found"; + case 303: return "See Other"; + case 304: return "Not Modified"; + case 305: return "Use Proxy"; + case 306: return "Switch Proxy"; + case 307: return "Temporary Redirect"; + + case 400: return "Bad Request"; + case 401: return "Unauthorized"; + case 402: return "Payment Required"; + case 403: return "Forbidden"; + case 404: return "Not Found"; + case 405: return "Method Not Allowed"; + case 406: return "Not Acceptable"; + case 407: return "Proxy Authentication Required"; + case 408: return "Request Timeout"; + case 409: return "Conflict"; + case 410: return "Gone"; + case 411: return "Length Required"; + case 412: return "Precondition Failed"; + case 413: return "Request Entity Too Large"; + case 414: return "Request URI Too Long"; + case 415: return "Unsupported Media Type"; + case 416: return "Requested Range Not Satisfiable"; + case 417: return "Expectation Failed"; + case 422: return "Unprocessable Entity"; + case 423: return "Locked"; + case 424: return "Failed Dependency"; + case 425: return "Unordered Collection"; + case 426: return "Upgrade Required"; + + case 500: return "Internal Server Error"; + case 501: return "Not Implemented"; + case 502: return "Bad Gateway"; + case 503: return "Service Unavailable"; + case 504: return "Gateway Timeout"; + case 505: return "HTTP Version Not Supported"; + case 506: return "Variant Also Negotiates"; + case 507: return "Insufficient Storage"; + case 509: return "Bandwidth Limit Exceeded"; + case 510: return "Not Extended"; + + case 600: return "Internal Client Error"; + case 601: return "Unsupported Protocol"; + case 602: return "Server Not Found"; + case 603: return "Malformed Response"; + case 604: return "Network Not Available"; + case 605: return "Request Timed Out"; + default: return "Unknown Status Code"; + } +} + +static char hex[] = "0123456789abcdef"; +char *http_multipart_post(char *uri, char **names, char **parts, int *plens, char *user, char *pass, int *ret, int *len) +{ + void *ctx; + char *data = NULL, *tmp, *p; + int dlen = 0, i, j, m; + unsigned char hash[16]; + unsigned char boundary[32], ch; + int blen = 0; + unsigned int map[62]; + struct md5_context md5; + int own_plen = 0; + + if(names) { + if(!plens) { + own_plen = 1; + for(i=0;names[i];i++) ; + plens = calloc(i, sizeof(int)); + for(i=0;names[i];i++) + plens[i] = strlen(parts[i]); + } + + retry: + if(blen >= 31) + goto fail; + memset(map, 0, 62*sizeof(int)); + for(i=0;names[i];i++) { + for(j=0;j='0' && ch<='9') + map[ch-'0']++; + else if(ch>='A' && ch<='Z') + map[ch-'A'+10]++; + else if(ch>='a' && ch<='z') + map[ch-'a'+36]++; + } + } + m = ~0; + j = 61; + for(i=0;i<62;i++) + if(map[i]>4]; + tmp[i*2+1] = hex[hash[i]&15]; + } + tmp[32] = 0; + http_async_add_header(ctx, "X-Auth-Hash", tmp); + free(tmp); + } + } + + if(data) { + tmp = malloc(32+strlen((char *)boundary)); + sprintf(tmp, "multipart/form-data, boundary=%s", boundary); + http_async_add_header(ctx, "Content-type", tmp); + free(tmp); + free(data); + } + + if(own_plen) + free(plens); + return http_async_req_stop(ctx, ret, len); + +fail: + if(data) + free(data); + if(own_plen) + free(plens); + if(ret) + *ret = 600; + if(len) + *len = 0; + return NULL; +} diff --git a/http.h b/http.h new file mode 100644 index 000000000..af78b2711 --- /dev/null +++ b/http.h @@ -0,0 +1,21 @@ +#ifndef HTTP_H +#define HTTP_H + +void http_init(char *proxy); +void http_done(void); + +char *http_simple_get(char *uri, int *ret, int *len); +char *http_simple_post(char *uri, char *data, int dlen, int *ret, int *len); + +void *http_async_req_start(void *ctx, char *uri, char *data, int dlen, int keep); +void http_async_add_header(void *ctx, char *name, char *data); +int http_async_req_status(void *ctx); +void http_async_get_length(void *ctx, int *total, int *done); +char *http_async_req_stop(void *ctx, int *ret, int *len); +void http_async_req_close(void *ctx); + +char *http_multipart_post(char *uri, char **names, char **parts, int *plens, char *user, char *pass, int *ret, int *len); + +char *http_ret_text(int ret); + +#endif diff --git a/icon.h b/icon.h new file mode 100644 index 000000000..9784b8d7b --- /dev/null +++ b/icon.h @@ -0,0 +1,309 @@ +static unsigned char app_icon[] = { +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05, +0x01,0x00,0x0b,0x02,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x0a,0x00,0x00,0x16,0x02, +0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x08,0x00,0x00,0x1b,0x02,0x00,0x0e,0x01,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x19,0x01,0x00, +0x62,0x09,0x02,0x4b,0x07,0x01,0x06,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x04,0x00,0x00,0x30,0x01,0x00,0x80,0x04,0x00,0x6c, +0x04,0x01,0x23,0x01,0x00,0x03,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x09,0x00,0x00,0x4d, +0x01,0x00,0xbc,0x08,0x01,0xdf,0x13,0x04,0x74,0x08, +0x01,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01, +0x00,0x00,0x15,0x00,0x00,0x78,0x04,0x00,0xf7,0x12, +0x02,0xfe,0x15,0x02,0xa2,0x06,0x00,0x28,0x00,0x00, +0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x24,0x00, +0x00,0xa7,0x08,0x01,0xff,0x28,0x07,0xff,0x26,0x06, +0xea,0x14,0x04,0x65,0x03,0x00,0x0e,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x04,0x00,0x00,0x32,0x00,0x00,0xc0,0x0e,0x01, +0xff,0x3e,0x0a,0xff,0x42,0x0a,0xff,0x2e,0x07,0x97, +0x09,0x01,0x1c,0x00,0x00,0x01,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00, +0x3f,0x00,0x00,0xca,0x14,0x01,0xff,0x46,0x05,0xff, +0x57,0x07,0xfe,0x33,0x02,0x9f,0x06,0x00,0x28,0x00, +0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x09,0x00,0x00,0x46,0x01,0x00,0xd2, +0x1f,0x02,0xff,0x5e,0x08,0xff,0x75,0x0c,0xff,0x4e, +0x08,0xae,0x0f,0x00,0x32,0x00,0x00,0x04,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0a, +0x00,0x00,0x4a,0x02,0x00,0xd5,0x26,0x01,0xff,0x72, +0x0a,0xff,0x9e,0x12,0xff,0x7c,0x0d,0xc1,0x26,0x01, +0x39,0x02,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x0a,0x00,0x00,0x4b,0x04, +0x00,0xd7,0x37,0x02,0xff,0x90,0x0a,0xff,0xc5,0x15, +0xff,0xad,0x14,0xca,0x3f,0x03,0x42,0x05,0x00,0x08, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x0a,0x00,0x00,0x4b,0x08,0x00,0xd7,0x48,0x02, +0xff,0xb5,0x10,0xff,0xf4,0x20,0xff,0xd2,0x19,0xcd, +0x56,0x03,0x48,0x0c,0x00,0x0b,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0a,0x00,0x00, +0x48,0x0c,0x00,0xd4,0x58,0x04,0xff,0xdc,0x1b,0xff, +0xff,0x2c,0xff,0xe7,0x1c,0xcb,0x69,0x03,0x4c,0x15, +0x00,0x0d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x08,0x00,0x00,0x3f,0x0e,0x00,0xbc, +0x56,0x01,0xfe,0xd6,0x16,0xff,0xff,0x36,0xff,0xea, +0x20,0xc9,0x72,0x02,0x4d,0x1c,0x00,0x0e,0x01,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05, +0x00,0x00,0x33,0x0d,0x00,0x96,0x51,0x02,0xfa,0xd5, +0x1f,0xff,0xff,0x4f,0xff,0xf1,0x32,0xca,0x7c,0x05, +0x50,0x21,0x00,0x10,0x01,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x28,0x0d, +0x00,0x84,0x50,0x04,0xf6,0xdd,0x32,0xff,0xff,0x75, +0xff,0xf7,0x51,0xd0,0x89,0x0f,0x53,0x28,0x00,0x11, +0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x02,0x00,0x00,0x22,0x0c,0x00,0x79,0x4e,0x07, +0xf3,0xd7,0x3c,0xff,0xff,0x87,0xff,0xfc,0x6d,0xd5, +0x9b,0x20,0x5a,0x32,0x02,0x14,0x06,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00, +0x1d,0x0d,0x00,0x72,0x53,0x0d,0xf2,0xde,0x55,0xff, +0xff,0xb1,0xff,0xff,0x9e,0xe5,0xbc,0x41,0x72,0x48, +0x0b,0x1f,0x0b,0x00,0x02,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x01,0x00,0x00,0x18,0x0e,0x00,0x69, +0x56,0x14,0xef,0xe4,0x74,0xff,0xff,0xeb,0xff,0xff, +0xe8,0xfd,0xe9,0x83,0xad,0x74,0x25,0x37,0x19,0x02, +0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x11,0x0b,0x00,0x60,0x51,0x17,0xec,0xe5, +0x84,0xff,0xff,0xfa,0xff,0xff,0xfe,0xff,0xff,0xca, +0xe6,0xab,0x46,0x46,0x21,0x04,0x07,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0a,0x06, +0x00,0x4c,0x3c,0x0f,0xdc,0xca,0x63,0xff,0xff,0xd6, +0xff,0xff,0xdc,0xff,0xfb,0x9c,0xb7,0x79,0x2a,0x30, +0x18,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x04,0x02,0x00,0x2c,0x1c,0x03, +0x8e,0x66,0x22,0xfb,0xf3,0x7f,0xff,0xfb,0x86,0xfb, +0xf0,0x6c,0x5f,0x32,0x0a,0x13,0x07,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x01,0x00,0x00,0x0c,0x04,0x00,0x2f,0x19,0x02,0xec, +0xc4,0x44,0xfa,0xd4,0x4b,0xe9,0xb9,0x40,0x1a,0x09, +0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x06,0x02,0x00,0xbc,0x97,0x38,0xcb,0xa3, +0x3c,0xbe,0x99,0x3a,0x01,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0xb2,0x94,0x3b,0xc0,0xa0,0x40,0xb8,0x99,0x3d, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xb2,0x94,0x3c, +0xc0,0xa0,0x40,0xb8,0x9a,0x3e,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x74,0x61,0x26,0x86,0x70,0x2c,0x79, +0x64,0x28,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00}; diff --git a/md5.c b/md5.c new file mode 100644 index 000000000..7275e9a03 --- /dev/null +++ b/md5.c @@ -0,0 +1,225 @@ +// based on public-domain code from Colin Plumb (1993) + +#include +#include "md5.h" + +static unsigned getu32(const unsigned char *addr) +{ + return (((((unsigned long)addr[3] << 8) | addr[2]) << 8) | addr[1]) << 8 | addr[0]; +} + +static void putu32(unsigned data, unsigned char *addr) +{ + addr[0] = (unsigned char)data; + addr[1] = (unsigned char)(data >> 8); + addr[2] = (unsigned char)(data >> 16); + addr[3] = (unsigned char)(data >> 24); +} + +void md5_init(struct md5_context *ctx) +{ + ctx->buf[0] = 0x67452301; + ctx->buf[1] = 0xefcdab89; + ctx->buf[2] = 0x98badcfe; + ctx->buf[3] = 0x10325476; + + ctx->bits[0] = 0; + ctx->bits[1] = 0; +} + +void md5_update(struct md5_context *ctx, unsigned char const *buf, unsigned len) +{ + unsigned t; + + // update bit count + t = ctx->bits[0]; + if((ctx->bits[0] = (t + ((unsigned)len << 3)) & 0xffffffff) < t) + ctx->bits[1]++; // carry + ctx->bits[1] += len >> 29; + + t = (t >> 3) & 0x3f; + + // use leading data to top up the buffer + + if(t) { + unsigned char *p = ctx->in + t; + + t = 64-t; + if (len < t) { + memcpy(p, buf, len); + return; + } + memcpy(p, buf, t); + md5_transform(ctx->buf, ctx->in); + buf += t; + len -= t; + } + + // following 64-byte chunks + + while(len >= 64) { + memcpy(ctx->in, buf, 64); + md5_transform(ctx->buf, ctx->in); + buf += 64; + len -= 64; + } + + // save rest of bytes for later + + memcpy(ctx->in, buf, len); +} + +void md5_final(unsigned char digest[16], struct md5_context *ctx) +{ + unsigned count; + unsigned char *p; + + // #bytes mod64 + count = (ctx->bits[0] >> 3) & 0x3F; + + // first char of padding = 0x80 + p = ctx->in + count; + *p++ = 0x80; + + // calculate # of bytes to pad + count = 64 - 1 - count; + + // Pad out to 56 mod 64 + if(count < 8) { + // we need to finish a whole block before padding + memset(p, 0, count); + md5_transform(ctx->buf, ctx->in); + memset(ctx->in, 0, 56); + } else { + // just pad to 56 bytes + memset(p, 0, count-8); + } + + // append length & final transform + putu32(ctx->bits[0], ctx->in + 56); + putu32(ctx->bits[1], ctx->in + 60); + + md5_transform(ctx->buf, ctx->in); + putu32(ctx->buf[0], digest); + putu32(ctx->buf[1], digest + 4); + putu32(ctx->buf[2], digest + 8); + putu32(ctx->buf[3], digest + 12); + memset(ctx, 0, sizeof(ctx)); +} + +#define F1(x, y, z) (z ^ (x & (y ^ z))) +#define F2(x, y, z) F1(z, x, y) +#define F3(x, y, z) (x ^ y ^ z) +#define F4(x, y, z) (y ^ (x | ~z)) + +#define MD5STEP(f, w, x, y, z, data, s) \ + ( w += f(x, y, z) + data, w &= 0xffffffff, w = w<>(32-s), w += x ) + +void md5_transform(unsigned buf[4], const unsigned char inraw[64]) +{ + unsigned a, b, c, d; + unsigned in[16]; + int i; + + for (i = 0; i < 16; ++i) + in[i] = getu32 (inraw + 4 * i); + + a = buf[0]; + b = buf[1]; + c = buf[2]; + d = buf[3]; + + MD5STEP(F1, a, b, c, d, in[ 0]+0xd76aa478, 7); + MD5STEP(F1, d, a, b, c, in[ 1]+0xe8c7b756, 12); + MD5STEP(F1, c, d, a, b, in[ 2]+0x242070db, 17); + MD5STEP(F1, b, c, d, a, in[ 3]+0xc1bdceee, 22); + MD5STEP(F1, a, b, c, d, in[ 4]+0xf57c0faf, 7); + MD5STEP(F1, d, a, b, c, in[ 5]+0x4787c62a, 12); + MD5STEP(F1, c, d, a, b, in[ 6]+0xa8304613, 17); + MD5STEP(F1, b, c, d, a, in[ 7]+0xfd469501, 22); + MD5STEP(F1, a, b, c, d, in[ 8]+0x698098d8, 7); + MD5STEP(F1, d, a, b, c, in[ 9]+0x8b44f7af, 12); + MD5STEP(F1, c, d, a, b, in[10]+0xffff5bb1, 17); + MD5STEP(F1, b, c, d, a, in[11]+0x895cd7be, 22); + MD5STEP(F1, a, b, c, d, in[12]+0x6b901122, 7); + MD5STEP(F1, d, a, b, c, in[13]+0xfd987193, 12); + MD5STEP(F1, c, d, a, b, in[14]+0xa679438e, 17); + MD5STEP(F1, b, c, d, a, in[15]+0x49b40821, 22); + + MD5STEP(F2, a, b, c, d, in[ 1]+0xf61e2562, 5); + MD5STEP(F2, d, a, b, c, in[ 6]+0xc040b340, 9); + MD5STEP(F2, c, d, a, b, in[11]+0x265e5a51, 14); + MD5STEP(F2, b, c, d, a, in[ 0]+0xe9b6c7aa, 20); + MD5STEP(F2, a, b, c, d, in[ 5]+0xd62f105d, 5); + MD5STEP(F2, d, a, b, c, in[10]+0x02441453, 9); + MD5STEP(F2, c, d, a, b, in[15]+0xd8a1e681, 14); + MD5STEP(F2, b, c, d, a, in[ 4]+0xe7d3fbc8, 20); + MD5STEP(F2, a, b, c, d, in[ 9]+0x21e1cde6, 5); + MD5STEP(F2, d, a, b, c, in[14]+0xc33707d6, 9); + MD5STEP(F2, c, d, a, b, in[ 3]+0xf4d50d87, 14); + MD5STEP(F2, b, c, d, a, in[ 8]+0x455a14ed, 20); + MD5STEP(F2, a, b, c, d, in[13]+0xa9e3e905, 5); + MD5STEP(F2, d, a, b, c, in[ 2]+0xfcefa3f8, 9); + MD5STEP(F2, c, d, a, b, in[ 7]+0x676f02d9, 14); + MD5STEP(F2, b, c, d, a, in[12]+0x8d2a4c8a, 20); + + MD5STEP(F3, a, b, c, d, in[ 5]+0xfffa3942, 4); + MD5STEP(F3, d, a, b, c, in[ 8]+0x8771f681, 11); + MD5STEP(F3, c, d, a, b, in[11]+0x6d9d6122, 16); + MD5STEP(F3, b, c, d, a, in[14]+0xfde5380c, 23); + MD5STEP(F3, a, b, c, d, in[ 1]+0xa4beea44, 4); + MD5STEP(F3, d, a, b, c, in[ 4]+0x4bdecfa9, 11); + MD5STEP(F3, c, d, a, b, in[ 7]+0xf6bb4b60, 16); + MD5STEP(F3, b, c, d, a, in[10]+0xbebfbc70, 23); + MD5STEP(F3, a, b, c, d, in[13]+0x289b7ec6, 4); + MD5STEP(F3, d, a, b, c, in[ 0]+0xeaa127fa, 11); + MD5STEP(F3, c, d, a, b, in[ 3]+0xd4ef3085, 16); + MD5STEP(F3, b, c, d, a, in[ 6]+0x04881d05, 23); + MD5STEP(F3, a, b, c, d, in[ 9]+0xd9d4d039, 4); + MD5STEP(F3, d, a, b, c, in[12]+0xe6db99e5, 11); + MD5STEP(F3, c, d, a, b, in[15]+0x1fa27cf8, 16); + MD5STEP(F3, b, c, d, a, in[ 2]+0xc4ac5665, 23); + + MD5STEP(F4, a, b, c, d, in[ 0]+0xf4292244, 6); + MD5STEP(F4, d, a, b, c, in[ 7]+0x432aff97, 10); + MD5STEP(F4, c, d, a, b, in[14]+0xab9423a7, 15); + MD5STEP(F4, b, c, d, a, in[ 5]+0xfc93a039, 21); + MD5STEP(F4, a, b, c, d, in[12]+0x655b59c3, 6); + MD5STEP(F4, d, a, b, c, in[ 3]+0x8f0ccc92, 10); + MD5STEP(F4, c, d, a, b, in[10]+0xffeff47d, 15); + MD5STEP(F4, b, c, d, a, in[ 1]+0x85845dd1, 21); + MD5STEP(F4, a, b, c, d, in[ 8]+0x6fa87e4f, 6); + MD5STEP(F4, d, a, b, c, in[15]+0xfe2ce6e0, 10); + MD5STEP(F4, c, d, a, b, in[ 6]+0xa3014314, 15); + MD5STEP(F4, b, c, d, a, in[13]+0x4e0811a1, 21); + MD5STEP(F4, a, b, c, d, in[ 4]+0xf7537e82, 6); + MD5STEP(F4, d, a, b, c, in[11]+0xbd3af235, 10); + MD5STEP(F4, c, d, a, b, in[ 2]+0x2ad7d2bb, 15); + MD5STEP(F4, b, c, d, a, in[ 9]+0xeb86d391, 21); + + buf[0] += a; + buf[1] += b; + buf[2] += c; + buf[3] += d; +} + +static char hex[] = "0123456789abcdef"; +void md5_ascii(char *result, unsigned char const *buf, unsigned len) +{ + struct md5_context md5; + unsigned char hash[16]; + int i; + + if(len==0) + len = strlen((char *)buf); + + md5_init(&md5); + md5_update(&md5, buf, len); + md5_final(hash, &md5); + + for(i=0;i<16;i++) { + result[i*2] = hex[hash[i]>>4]; + result[i*2+1] = hex[hash[i]&15]; + } + result[32] = 0; +} diff --git a/md5.h b/md5.h new file mode 100644 index 000000000..3f675d62a --- /dev/null +++ b/md5.h @@ -0,0 +1,17 @@ +#ifndef MD5_H +#define MD5_H + +struct md5_context { + unsigned buf[4]; + unsigned bits[2]; + unsigned char in[64]; +}; + +void md5_init(struct md5_context *context); +void md5_update(struct md5_context *context, unsigned char const *buf, unsigned len); +void md5_final(unsigned char digest[16], struct md5_context *context); +void md5_transform(unsigned buf[4], const unsigned char in[64]); + +void md5_ascii(char *result, unsigned char const *buf, unsigned len); + +#endif diff --git a/powder-res.rc b/powder-res.rc new file mode 100644 index 000000000..569b629dc --- /dev/null +++ b/powder-res.rc @@ -0,0 +1,2 @@ +#define IDI_ICON1 101 +IDI_ICON1 ICON DISCARDABLE "powder.ico" diff --git a/powder.c b/powder.c new file mode 100644 index 000000000..d1b52b2a6 --- /dev/null +++ b/powder.c @@ -0,0 +1,5907 @@ +/** + * Powder Toy - Main source + * + * Powder Toy is the legal property of Stanislaw Skowronek. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA + */ + +#include +#include +#include +#include +#include +#include +#include + +#ifdef WIN32 +#include +#else +#include +#endif + +#include "http.h" +#include "md5.h" +#include "update.h" + +#define SAVE_VERSION 24 +#define MINOR_VERSION 9 + +#define SERVER "powder.unaligned.org" + +#undef PLOSS + +#define XRES 512 +#define YRES 384 + +#define ZSIZE 16 +#define ZFACTOR 8 + +#define CELL 4 +#define ISTP (CELL/2) +#define CFDS (4.0f/CELL) + +#ifdef PIX16 +#define PIXELSIZE 2 +typedef unsigned short pixel; +#define PIXPACK(x) ((((x)>>8)&0xF800)|(((x)>>5)&0x07E0)|(((x)>>3)&0x001F)) +#define PIXRGB(r,g,b) ((((r)<<8)&0xF800)|(((g)<<3)&0x07E0)|(((b)>>3)&0x001F)) +#define PIXR(x) (((x)>>8)&0xF8) +#define PIXG(x) (((x)>>3)&0xFC) +#define PIXB(x) (((x)<<3)&0xF8) +#else +#define PIXELSIZE 4 +typedef unsigned int pixel; +#ifdef PIX32BGR +#define PIXPACK(x) ((((x)>>16)&0x0000FF)|((x)&0x00FF00)|(((x)<<16)&0xFF0000)) +#define PIXRGB(r,g,b) (((b)<<16)|((g)<<8)|(r)) +#define PIXR(x) ((x)&0xFF) +#define PIXG(x) (((x)>>8)&0xFF) +#define PIXB(x) ((x)>>16) +#else +#define PIXPACK(x) (x) +#define PIXRGB(r,g,b) (((r)<<16)|((g)<<8)|(b)) +#define PIXR(x) ((x)>>16) +#define PIXG(x) (((x)>>8)&0xFF) +#define PIXB(x) ((x)&0xFF) +#endif +#endif + +char *it_msg = + "\brThe Powder Toy\n" + "\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\n" + "\bwMaterials on the bottom right are walls, materials on the bottom left are particles.\n" + "\n" + "\bgPick your material from the bottom bar using mouse left/right buttons.\n" + "Draw freeform lines by dragging your mouse left/right button across the drawing area.\n" + "Shift+drag will create straight lines of particles.\n" + "Ctrl+drag will result in filled rectangles.\n" + "Ctrl+Shift+click will flood-fill a closed area.\n" + "\n\boUse 'Z' for a zoom tool. Click to make the drawable zoom window stay around.\n" + "Use 'S' to save parts of the window as 'stamps'.\n" + "'L' will load the most recent stamp, 'K' shows a library of stamps you saved.\n" + "\n" + "\brhttp://powder.unaligned.org/\n" + "\bbirc.unaligned.org #wtf\n" + "\n" + "\bg(c) 2008-9 Stanislaw K Skowronek\n" + "\n" + "\bgSpecial thanks to Brian Ledbetter for maintaining ports & server development." + "\nThanks to CW for hosting the server." +#ifdef WIN32 + "\nThanks to Akuryo for Windows icons." +#endif + ; + +char *old_ver_msg = "A new version is available - click here!"; + +int sys_pause = 0; + +int amd = 0; + +unsigned char fire_r[YRES/CELL][XRES/CELL]; +unsigned char fire_g[YRES/CELL][XRES/CELL]; +unsigned char fire_b[YRES/CELL][XRES/CELL]; + +#define MAXSIGNS 16 + +struct sign { + int x,y,ju; + char text[256]; +} signs[MAXSIGNS]; + +/*********************************************************** + * AIR FLOW SIMULATOR * + ***********************************************************/ + +unsigned char bmap[YRES/CELL][XRES/CELL]; +unsigned char emap[YRES/CELL][XRES/CELL]; +unsigned cmode = 3; + +float vx[YRES/CELL][XRES/CELL], ovx[YRES/CELL][XRES/CELL]; +float vy[YRES/CELL][XRES/CELL], ovy[YRES/CELL][XRES/CELL]; +float pv[YRES/CELL][XRES/CELL], opv[YRES/CELL][XRES/CELL]; +float fvx[YRES/CELL][XRES/CELL], fvy[YRES/CELL][XRES/CELL]; +#define TSTEPP 0.3f +#define TSTEPV 0.4f +#define VADV 0.3f +#define VLOSS 0.999f +#define PLOSS 0.9999f + +float kernel[9]; +void make_kernel(void) +{ + int i, j; + float s = 0.0f; + for(j=-1; j<2; j++) + for(i=-1; i<2; i++) { + kernel[(i+1)+3*(j+1)] = exp(-2.0f*(i*i+j*j)); + s += kernel[(i+1)+3*(j+1)]; + } + s = 1.0f / s; + for(j=-1; j<2; j++) + for(i=-1; i<2; i++) + kernel[(i+1)+3*(j+1)] *= s; +} + +void update_air(void) +{ + int x, y, i, j; + float dp, dx, dy, f, tx, ty; + + for(y=1; y0 && y+j0 && x+i=2 && i=2 && j 256.0f) dp = 256.0f; + if(dp < -256.0f) dp = -256.0f; + if(dx > 256.0f) dx = 256.0f; + if(dx < -256.0f) dx = -256.0f; + if(dy > 256.0f) dy = 256.0f; + if(dy < -256.0f) dy = -256.0f; + + ovx[y][x] = dx; + ovy[y][x] = dy; + opv[y][x] = dp; + } + memcpy(vx, ovx, sizeof(vx)); + memcpy(vy, ovy, sizeof(vy)); + memcpy(pv, opv, sizeof(pv)); +} + +unsigned clamp_flt(float f, float min, float max) +{ + if(fmax) + return 255; + return (int)(255.0f*(f-min)/(max-min)); +} + +void draw_air(pixel *vid) +{ + int x, y, i, j; + pixel c; + + if(cmode == 2) + return; + + for(y=0; y 0.0f) + c = PIXRGB(clamp_flt(pv[y][x], 0.0f, 8.0f), 0, 0); + else + c = PIXRGB(0, 0, clamp_flt(-pv[y][x], 0.0f, 8.0f)); + } else + c = PIXRGB(clamp_flt(fabs(vx[y][x]), 0.0f, 8.0f), + clamp_flt(pv[y][x], 0.0f, 8.0f), + clamp_flt(fabs(vy[y][x]), 0.0f, 8.0f)); + for(j=0; j=XRES || ny>=YRES) + return 0; + if(x==nx && y==ny) + return 1; + r = pmap[ny][nx]; + if(r && (r>>8)>8].type; + + if(falldown[parts[i].type]!=2 && bmap[ny/CELL][nx/CELL]==3) + return 0; + if(parts[i].type==PT_NEUT && bmap[ny/CELL][nx/CELL]==7 && !emap[ny/CELL][nx/CELL]) + return 0; + if(r && (r>>8)>8)>= 8; + parts[r].x += x-nx; + parts[r].y += y-ny; + } + + return 1; +} + +void kill_part(int i) +{ + int x, y; + parts[i].type = PT_NONE; + + x = (int)(parts[i].x+0.5f); + y = (int)(parts[i].y+0.5f); + + if(x>=0 && y>=0 && x=XRES || y>=YRES) + return -1; + + if(t==PT_SPRK) { + if((pmap[y][x]&0xFF)!=PT_WIRE && + (pmap[y][x]&0xFF)!=PT_WATR) + return -1; + parts[pmap[y][x]>>8].type = PT_SPRK; + parts[pmap[y][x]>>8].life = 4; + parts[pmap[y][x]>>8].ctype = pmap[y][x]&0xFF; + pmap[y][x] = (pmap[y][x]&~0xFF) | PT_SPRK; + return pmap[y][x]>>8; + } + + if(p==-1) { + if(pmap[y][x]) + return -1; + if(pfree == -1) + return -1; + i = pfree; + pfree = parts[i].life; + } else + i = p; + + parts[i].x = x; + parts[i].y = y; + parts[i].type = t; + parts[i].vx = 0; + parts[i].vy = 0; + parts[i].life = 0; + parts[i].ctype = 0; + if(t==PT_FIRE) + parts[i].life = rand()%50+120; + if(t==PT_LAVA) + parts[i].life = rand()%120+240; + if(t==PT_NEUT) { + float r = (rand()%128+128)/127.0f; + float a = (rand()%360)*3.14159f/180.0f; + parts[i].life = rand()%480+480; + parts[i].vx = r*cos(a); + parts[i].vy = r*sin(a); + } + + pmap[y][x] = t|(i<<8); + + return i; +} + +void delete_part(int x, int y) +{ + unsigned i; + + if(x<0 || y<0 || x>=XRES || y>=YRES) + return; + i = pmap[y][x]; + if(!i || (i>>8)>=NPART) + return; + + kill_part(i>>8); + pmap[y][x] = 0; // just in case +} + +void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a) +{ + pixel t; + if(x<0 || y<0 || x>=XRES || y>=YRES) + return; + if(a!=255) { + t = vid[y*XRES+x]; + r = (a*r + (255-a)*PIXR(t)) >> 8; + g = (a*g + (255-a)*PIXG(t)) >> 8; + b = (a*b + (255-a)*PIXB(t)) >> 8; + } + vid[y*XRES+x] = PIXRGB(r,g,b); +} + +inline void addpixel(pixel *vid, int x, int y, int r, int g, int b, int a) +{ + pixel t; + if(x<0 || y<0 || x>=XRES || y>=YRES) + return; + t = vid[y*XRES+x]; + r = (a*r + 255*PIXR(t)) >> 8; + g = (a*g + 255*PIXG(t)) >> 8; + b = (a*b + 255*PIXB(t)) >> 8; + if(r>255) + r = 255; + if(g>255) + g = 255; + if(b>255) + b = 255; + vid[y*XRES+x] = PIXRGB(r,g,b); +} + +int drawtext(pixel *vid, int x, int y, char *s, int r, int g, int b, int a); + +int is_wire(int x, int y) +{ + return bmap[y][x]==6 || bmap[y][x]==7 || bmap[y][x]==3 || bmap[y][x]==8; +} +int is_wire_off(int x, int y) +{ + return (bmap[y][x]==6 || bmap[y][x]==7 || bmap[y][x]==3 || bmap[y][x]==8) && emap[y][x]<8; +} + +void set_emap(int x, int y) +{ + int x1, x2; + + if(!is_wire_off(x, y)) + return; + + // go left as far as possible + x1 = x2 = x; + while(x1>0) { + if(!is_wire_off(x1-1, y)) + break; + x1--; + } + while(x21 && x1==x2 && + is_wire(x1-1, y-1) && is_wire(x1, y-1) && is_wire(x1+1, y-1) && + !is_wire(x1-1, y-2) && is_wire(x1, y-2) && !is_wire(x1+1, y-2)) + set_emap(x1, y-2); + else if(y>0) + for(x=x1; x<=x2; x++) + if(is_wire_off(x, y-1)) { + if(x==x1 || x==x2 || y>=YRES/CELL-1 || + is_wire(x-1, y-1) || is_wire(x+1, y-1) || + is_wire(x-1, y+1) || !is_wire(x, y+1) || is_wire(x+1, y+1)) + set_emap(x, y-1); + } + + if(y=0 && y>=0 && x>1)&1; i 255) cr = 255; fire_r[y][x] = cr; + cg += fire_g[y][x]; if(cg > 255) cg = 255; fire_g[y][x] = cg; + cb += fire_b[y][x]; if(cb > 255) cb = 255; fire_b[y][x] = cb; + } + } + if(bmap[y][x]==4) + for(j=0; j>1)&1; i>1)&1; i 255) cr = 255; fire_r[y][x] = cr; + cg += fire_g[y][x]; if(cg > 255) cg = 255; fire_g[y][x] = cg; + cb += fire_b[y][x]; if(cb > 255) cb = 255; fire_b[y][x] = cb; + } + } + if(bmap[y][x]==7) { + if(emap[y][x]) { + cr = cg = cb = 128; + cr += fire_r[y][x]; if(cr > 255) cr = 255; fire_r[y][x] = cr; + cg += fire_g[y][x]; if(cg > 255) cg = 255; fire_g[y][x] = cg; + cb += fire_b[y][x]; if(cb > 255) cb = 255; fire_b[y][x] = cb; + for(j=0; j 255) cr = 255; fire_r[y][x] = cr; + cg += fire_g[y][x]; if(cg > 255) cg = 255; fire_g[y][x] = cg; + cb += fire_b[y][x]; if(cb > 255) cb = 255; fire_b[y][x] = cb; + } + } + if(emap[y][x] && !sys_pause) + emap[y][x] --; + } + + for(i=0; i=XRES || y>=YRES || + bmap[y/CELL][x/CELL]==1 || + bmap[y/CELL][x/CELL]==8 || + (bmap[y/CELL][x/CELL]==2) || + (bmap[y/CELL][x/CELL]==3 && falldown[t]!=2) || + (bmap[y/CELL][x/CELL]==6 && (t==PT_WIRE || t==PT_SPRK)) || + (bmap[y/CELL][x/CELL]==7 && !emap[y/CELL][x/CELL])) { + kill_part(i); + continue; + } + + vx[y/CELL][x/CELL] *= airloss[t]; + vy[y/CELL][x/CELL] *= airloss[t]; + vx[y/CELL][x/CELL] += airdrag[t]*parts[i].vx; + vy[y/CELL][x/CELL] += airdrag[t]*parts[i].vy; + if(t==PT_GASS) { + if(pv[y/CELL][x/CELL]<3.5f) + pv[y/CELL][x/CELL] += hotair[t]*(3.5f-pv[y/CELL][x/CELL]); + if(y+CELL2.5f) { + parts[i].life = rand()%80+180; + parts[i].type = PT_FIRE; + pv[y/CELL][x/CELL] += 0.25f * CFDS; + t = PT_FIRE; + } + + parts[i].vx *= loss[t]; + parts[i].vy *= loss[t]; + + if(t==PT_DFRM && !parts[i].life) { + if(pv[y/CELL][x/CELL]>1.0f) { + parts[i].vx += advection[t]*vx[y/CELL][x/CELL]; + parts[i].vy += advection[t]*vy[y/CELL][x/CELL]; + parts[i].life = rand()%80+300; + } + } else { + parts[i].vx += advection[t]*vx[y/CELL][x/CELL]; + parts[i].vy += advection[t]*vy[y/CELL][x/CELL] + gravity[t]; + } + + if(diffusion[t]) { + parts[i].vx += diffusion[t]*(rand()/(0.5f*RAND_MAX)-1.0f); + parts[i].vy += diffusion[t]*(rand()/(0.5f*RAND_MAX)-1.0f); + } + + // interpolator + mv = fmaxf(fabs(parts[i].vx), fabs(parts[i].vy)); + if(mv < ISTP) { + parts[i].x += parts[i].vx; + parts[i].y += parts[i].vy; + ix = parts[i].x; + iy = parts[i].y; + } else { + dx = parts[i].vx*ISTP/mv; + dy = parts[i].vy*ISTP/mv; + ix = parts[i].x; + iy = parts[i].y; + while(1) { + mv -= ISTP; + if(mv <= 0.0f) { + // nothing found + parts[i].x += parts[i].vx; + parts[i].y += parts[i].vy; + ix = parts[i].x; + iy = parts[i].y; + break; + } + ix += dx; + iy += dy; + nx = (int)(ix+0.5f); + ny = (int)(iy+0.5f); + if(nx<0 || ny<0 || nx>=XRES || ny>=YRES || pmap[ny][nx] || (bmap[ny/CELL][nx/CELL] && bmap[ny/CELL][nx/CELL]!=5)) { + parts[i].x = ix; + parts[i].y = iy; + break; + } + } + } + + a = nt = 0; + for(nx=-1; nx<2; nx++) + for(ny=-1; ny<2; ny++) + if(x+nx>=0 && y+ny>0 && + x+nx4.0f) + t = parts[i].type = PT_OILL; + if(t==PT_OILL && pv[y/CELL][x/CELL]<-4.0f) + t = parts[i].type = PT_GASS; + if(t==PT_ICEI && pv[y/CELL][x/CELL]>0.8f) + t = parts[i].type = PT_SNOW; + if(t==PT_PLUT && 1>rand()%100 && ((int)(5.0f*pv[y/CELL][x/CELL]))>(rand()%1000)) { + t = PT_NEUT; + create_part(i, x, y, t); + } + + if(t==PT_WATR || t==PT_WIRE || t==PT_SPRK) { + nx = x % CELL; + if(nx == 0) + nx = x/CELL - 1; + else if(nx == CELL-1) + nx = x/CELL + 1; + else + nx = x/CELL; + ny = y % CELL; + if(ny == 0) + ny = y/CELL - 1; + else if(ny == CELL-1) + ny = y/CELL + 1; + else + ny = y/CELL; + if(nx>=0 && ny>=0 && nx=0 && y+ny>0 && + x+nx>8)>=NPART || !r) + continue; + if((r&0xFF)==PT_WATR && 1>(rand()%1000)) { + t = parts[i].type = PT_ICEI; + parts[r>>8].type = PT_ICEI; + } + if(t==PT_SNOW && (r&0xFF)==PT_WATR && 15>(rand()%1000)) + t = parts[i].type = PT_WATR; + } + } + + fe = 0; + if(t==PT_NEUT) { + rt = 3 + (int)pv[y/CELL][x/CELL]; + for(nx=-1; nx<2; nx++) + for(ny=-1; ny<2; ny++) + if(x+nx>=0 && y+ny>0 && + x+nx>8)>=NPART || !r) + continue; + if((r&0xFF)==PT_WATR || (r&0xFF)==PT_ICEI || (r&0xFF)==PT_SNOW) { + parts[i].vx *= 0.995; + parts[i].vy *= 0.995; + } + if((r&0xFF)==PT_PLUT && rt>(rand()%1000)) { + if(33>rand()%100) { + create_part(r>>8, x+nx, y+ny, rand()%2 ? PT_LAVA : PT_FIRE); + } else { + create_part(r>>8, x+nx, y+ny, PT_NEUT); + parts[r>>8].vx = 0.25f*parts[r>>8].vx + parts[i].vx; + parts[r>>8].vy = 0.25f*parts[r>>8].vy + parts[i].vy; + } + pv[y/CELL][x/CELL] += 2.00f * CFDS; + fe ++; + } + if((r&0xFF)==PT_GUNP && 15>(rand()%1000)) + parts[r>>8].type = PT_DUST; + if((r&0xFF)==PT_PLEX && 15>(rand()%1000)) + parts[r>>8].type = PT_DFRM; + if((r&0xFF)==PT_NITR && 15>(rand()%1000)) + parts[r>>8].type = PT_OILL; + if((r&0xFF)==PT_OILL && 5>(rand()%1000)) + parts[r>>8].type = PT_GASS; + } + } + + if(t==PT_FIRE || t==PT_LAVA || t==PT_SPRK || fe) { + for(nx=-2; nx<3; nx++) + for(ny=-2; ny<3; ny++) + if(x+nx>=0 && y+ny>0 && + x+nx>8)>=NPART || !r) + continue; + if(bmap[(y+ny)/CELL][(x+nx)/CELL] && bmap[(y+ny)/CELL][(x+nx)/CELL]!=5) + continue; + rt = parts[r>>8].type; + if((a || explosive[rt]) && + (t!=PT_LAVA || parts[i].life>0 || (rt!=PT_METL && rt!=PT_WIRE)) && + flammable[rt] && (flammable[rt] + (int)(pv[(y+ny)/CELL][(x+nx)/CELL]*10.0f))>(rand()%1000)) { + parts[r>>8].type = PT_FIRE; + parts[r>>8].life = rand()%80+180; + if(explosive[rt]) + pv[y/CELL][x/CELL] += 0.25f * CFDS; + continue; + } + lpv = (int)pv[(y+ny)/CELL][(x+nx)/CELL]; + if(lpv < 1) lpv = 1; + if(t!=PT_SPRK && meltable[rt] && (t!=PT_FIRE || rt!=PT_WIRE) && + meltable[rt]*lpv>(rand()%1000)) { + if(t!=PT_LAVA || parts[i].life>0) { + parts[r>>8].type = PT_LAVA; + parts[r>>8].life = rand()%120+240; + } else { + parts[i].life = 0; + t = parts[i].type = rt; + goto killed; + } + } + if(t!=PT_SPRK && (rt==PT_ICEI || rt==PT_SNOW)) { + parts[r>>8].type = PT_WATR; + if(t==PT_FIRE) { + parts[i].x = lx; + parts[i].y = ly; + kill_part(i); + goto killed; + } + if(t==PT_LAVA) { + parts[i].life = 0; + t = parts[i].type = PT_METL; + goto killed; + } + } + if(t!=PT_SPRK && rt==PT_WATR) { + kill_part(r>>8); + if(t==PT_FIRE) { + parts[i].x = lx; + parts[i].y = ly; + kill_part(i); + goto killed; + } + if(t==PT_LAVA) { + parts[i].life = 0; + t = parts[i].type = PT_METL; + goto killed; + } + } + if(t==PT_SPRK && rt==PT_WIRE && parts[r>>8].life==0 && + (parts[i].life<3 || ((r>>8)>8].type = PT_SPRK; + parts[r>>8].life = 4; + parts[r>>8].ctype = rt; + } + if(t==PT_SPRK && rt==PT_WATR && parts[r>>8].life==0 && + (parts[i].life<2 || ((r>>8)>8].type = PT_SPRK; + parts[r>>8].life = 6; + parts[r>>8].ctype = rt; + } + } + killed: + if(parts[i].type == PT_NONE) + continue; + } + + if(t==PT_CLNE) { + if(!parts[i].ctype) { + for(nx=-1; nx<2; nx++) + for(ny=-1; ny<2; ny++) + if(x+nx>=0 && y+ny>0 && + x+nx=XRES-CELL || + ny=YRES-CELL) { + parts[i].x = lx; + parts[i].y = ly; + kill_part(i); + continue; + } + + rt = parts[i].flags & FLAG_STAGNANT; + parts[i].flags &= ~FLAG_STAGNANT; + if(!try_move(i, x, y, nx, ny)) { + parts[i].x = lx; + parts[i].y = ly; + if(falldown[t]) { + if(nx!=x && try_move(i, x, y, nx, y)) { + parts[i].x = ix; + parts[i].vx *= collision[t]; + parts[i].vy *= collision[t]; + } else if(ny!=y && try_move(i, x, y, x, ny)) { + parts[i].y = iy; + parts[i].vx *= collision[t]; + parts[i].vy *= collision[t]; + } else { + r = (rand()%2)*2-1; + if(ny!=y && try_move(i, x, y, x+r, ny)) { + parts[i].x += r; + parts[i].y = iy; + parts[i].vx *= collision[t]; + parts[i].vy *= collision[t]; + } else if(ny!=y && try_move(i, x, y, x-r, ny)) { + parts[i].x -= r; + parts[i].y = iy; + parts[i].vx *= collision[t]; + parts[i].vy *= collision[t]; + } else if(nx!=x && try_move(i, x, y, nx, y+r)) { + parts[i].x = ix; + parts[i].y += r; + parts[i].vx *= collision[t]; + parts[i].vy *= collision[t]; + } else if(nx!=x && try_move(i, x, y, nx, y-r)) { + parts[i].x = ix; + parts[i].y -= r; + parts[i].vx *= collision[t]; + parts[i].vy *= collision[t]; + } else if(falldown[t]>1 && parts[i].vy>fabs(parts[i].vx)) { + s = 0; + if(!rt || nt) + rt = 50; + else + rt = 10; + for(j=x+r; j>=0 && j>=x-rt && j0) + r = 1; + else + r = -1; + if(s) + for(j=y+r; j>=0 && j=y-rt && jx+ISTP) nx=x+ISTP; + if(nxy+ISTP) ny=y+ISTP; + if(ny(rand()%1000)) { + kill_part(i); + continue; + } else if(try_move(i, x, y, 2*x-nx, ny)) { + parts[i].x = 2*x-nx; + parts[i].y = iy; + parts[i].vx *= collision[t]; + } else if(try_move(i, x, y, nx, 2*y-ny)) { + parts[i].x = ix; + parts[i].y = 2*y-ny; + parts[i].vy *= collision[t]; + } else { + parts[i].vx *= collision[t]; + parts[i].vy *= collision[t]; + } + } + } + + justdraw: + + nx = (int)(parts[i].x+0.5f); + ny = (int)(parts[i].y+0.5f); + + if(nx=XRES-CELL || + ny=YRES-CELL) { + kill_part(i); + continue; + } + + if(t==PT_NEUT) { + if(cmode == 3) { + vid[ny*XRES+nx] = pcolors[t]; + cg = 8; + cb = 12; + x = nx/CELL; + y = ny/CELL; + cg += fire_g[y][x]; if(cg > 255) cg = 255; fire_g[y][x] = cg; + cb += fire_b[y][x]; if(cb > 255) cb = 255; fire_b[y][x] = cb; + } else { + cr = 0x20; + cg = 0xE0; + cb = 0xFF; + blendpixel(vid, nx, ny, cr, cg, cb, 192); + blendpixel(vid, nx+1, ny, cr, cg, cb, 96); + blendpixel(vid, nx-1, ny, cr, cg, cb, 96); + blendpixel(vid, nx, ny+1, cr, cg, cb, 96); + blendpixel(vid, nx, ny-1, cr, cg, cb, 96); + blendpixel(vid, nx+1, ny-1, cr, cg, cb, 32); + blendpixel(vid, nx-1, ny+1, cr, cg, cb, 32); + blendpixel(vid, nx+1, ny+1, cr, cg, cb, 32); + blendpixel(vid, nx-1, ny-1, cr, cg, cb, 32); + } + } else if(t==PT_FIRE && parts[i].life) { + if(cmode == 3) { + cr = parts[i].life / 4; + cg = parts[i].life / 16; + cb = parts[i].life / 32; + if(cr>255) cr = 255; + if(cg>192) cg = 212; + if(cb>128) cb = 192; + x = nx/CELL; + y = ny/CELL; + cr += fire_r[y][x]; if(cr > 255) cr = 255; fire_r[y][x] = cr; + cg += fire_g[y][x]; if(cg > 255) cg = 255; fire_g[y][x] = cg; + cb += fire_b[y][x]; if(cb > 255) cb = 255; fire_b[y][x] = cb; + } else { + cr = parts[i].life * 8; + cg = parts[i].life * 2; + cb = parts[i].life; + if(cr>255) cr = 255; + if(cg>192) cg = 212; + if(cb>128) cb = 192; + blendpixel(vid, nx, ny, cr, cg, cb, 255); + blendpixel(vid, nx+1, ny, cr, cg, cb, 96); + blendpixel(vid, nx-1, ny, cr, cg, cb, 96); + blendpixel(vid, nx, ny+1, cr, cg, cb, 96); + blendpixel(vid, nx, ny-1, cr, cg, cb, 96); + blendpixel(vid, nx+1, ny-1, cr, cg, cb, 32); + blendpixel(vid, nx-1, ny+1, cr, cg, cb, 32); + blendpixel(vid, nx+1, ny+1, cr, cg, cb, 32); + blendpixel(vid, nx-1, ny-1, cr, cg, cb, 32); + } + } else if(t==PT_LAVA && parts[i].life) { + cr = parts[i].life * 2 + 0xE0; + cg = parts[i].life * 1 + 0x50; + cb = parts[i].life/2 + 0x10; + if(cr>255) cr = 255; + if(cg>192) cg = 192; + if(cb>128) cb = 128; + blendpixel(vid, nx, ny, cr, cg, cb, 255); + blendpixel(vid, nx+1, ny, cr, cg, cb, 64); + blendpixel(vid, nx-1, ny, cr, cg, cb, 64); + blendpixel(vid, nx, ny+1, cr, cg, cb, 64); + blendpixel(vid, nx, ny-1, cr, cg, cb, 64); + if(cmode == 3) { + cr /= 32; + cg /= 32; + cb /= 32; + x = nx/CELL; + y = ny/CELL; + cr += fire_r[y][x]; if(cr > 255) cr = 255; fire_r[y][x] = cr; + cg += fire_g[y][x]; if(cg > 255) cg = 255; fire_g[y][x] = cg; + cb += fire_b[y][x]; if(cb > 255) cb = 255; fire_b[y][x] = cb; + } + } else if(t==PT_LAVA || t==PT_SPRK) { + vid[ny*XRES+nx] = pcolors[t]; + if(cmode == 3) { + if(t == PT_LAVA) { + cr = 3; + cg = i%2; + cb = 0; + } else { + cr = 8; + cg = 12; + cb = 16; + } + x = nx/CELL; + y = ny/CELL; + cr += fire_r[y][x]; if(cr > 255) cr = 255; fire_r[y][x] = cr; + cg += fire_g[y][x]; if(cg > 255) cg = 255; fire_g[y][x] = cg; + cb += fire_b[y][x]; if(cb > 255) cb = 255; fire_b[y][x] = cb; + } + } else + vid[ny*XRES+nx] = pcolors[t]; + } + + for(y=0; y=XRES || ny<0 || ny>=YRES) + break; + addpixel(vid, nx, ny, 255, 255, 255, 64); + i = nx/CELL; + j = ny/CELL; + lx += vx[j][i]*0.125f; + ly += vy[j][i]*0.125f; + if(bmap[j][i]==5 && i!=x && j!=y) + break; + } + drawtext(vid, x*CELL, y*CELL-2, "\x8D", 255, 255, 255, 128); + } +} + +/*********************************************************** + * SDL OUTPUT * + ***********************************************************/ + +int sdl_scale = 1; +SDL_Surface *sdl_scrn; +SDLMod sdl_mod; +int sdl_key, sdl_wheel, sdl_caps=0, sdl_ascii, sdl_zoom_trig=0; + +#include "icon.h" +void sdl_seticon(void) +{ + SDL_Surface *icon = + SDL_CreateRGBSurfaceFrom(app_icon, 32, 32, 24, 96, + 0x0000FF, 0x00FF00, 0xFF0000, 0); + SDL_WM_SetIcon(icon, NULL); +} + +void sdl_open(void) +{ + if(SDL_Init(SDL_INIT_VIDEO)<0) { + fprintf(stderr, "Initializing SDL: %s\n", SDL_GetError()); + exit(1); + } + atexit(SDL_Quit); +#ifdef PIX16 + sdl_scrn=SDL_SetVideoMode(XRES*sdl_scale,YRES*sdl_scale + 60*sdl_scale,16,SDL_SWSURFACE); +#else + sdl_scrn=SDL_SetVideoMode(XRES*sdl_scale,YRES*sdl_scale + 60*sdl_scale,32,SDL_SWSURFACE); +#endif + if(!sdl_scrn) { + fprintf(stderr, "Creating window: %s\n", SDL_GetError()); + exit(1); + } + SDL_WM_SetCaption("The Powder Toy", "Powder Toy"); + sdl_seticon(); + SDL_EnableUNICODE(1); +} + +void sdl_blit_1(int x, int y, int w, int h, pixel *src, int pitch) +{ + pixel *dst; + unsigned j; + if(SDL_MUSTLOCK(sdl_scrn)) + if(SDL_LockSurface(sdl_scrn)<0) + return; + dst=(pixel *)sdl_scrn->pixels+y*sdl_scrn->pitch/PIXELSIZE+x; + for(j=0;jpitch/PIXELSIZE; + src+=pitch; + } + if(SDL_MUSTLOCK(sdl_scrn)) + SDL_UnlockSurface(sdl_scrn); + SDL_UpdateRect(sdl_scrn,0,0,0,0); +} + +void sdl_blit_2(int x, int y, int w, int h, pixel *src, int pitch) +{ + pixel *dst; + unsigned j; + unsigned i,k; + if(SDL_MUSTLOCK(sdl_scrn)) + if(SDL_LockSurface(sdl_scrn)<0) + return; + dst=(pixel *)sdl_scrn->pixels+y*sdl_scrn->pitch/PIXELSIZE+x; + for(j=0;jpitch/PIXELSIZE; + } + src+=pitch; + } + if(SDL_MUSTLOCK(sdl_scrn)) + SDL_UnlockSurface(sdl_scrn); + SDL_UpdateRect(sdl_scrn,0,0,0,0); +} +void sdl_blit(int x, int y, int w, int h, pixel *src, int pitch) +{ + if(sdl_scale == 2) + sdl_blit_2(x, y, w, h, src, pitch); + else + sdl_blit_1(x, y, w, h, src, pitch); +} + +int frame_idx=0; +void dump_frame(pixel *src, int w, int h, int pitch) +{ + char frame_name[32]; + unsigned j,i; + unsigned char c[3]; + FILE *f; + sprintf(frame_name,"frame%04d.ppm",frame_idx); + f=fopen(frame_name,"wb"); + fprintf(f,"P6\n%d %d\n255\n",w,h); + for(j=0;j=0 && x=0 && yPT_NUM) + return 2; + if(c[5]!=CELL || c[6]!=XRES/CELL || c[7]!=YRES/CELL) + return 3; + i = XRES*YRES; + d = malloc(i); + if(!d) + return 1; + + if(BZ2_bzBuffToBuffDecompress((char *)d, (unsigned *)&i, (char *)(c+8), size-8, 0, 0)) + return 1; + size = i; + } else + d = c; + + if(size < XRES*YRES) { + if(bzip2) + free(d); + return 1; + } + + sy = 0; + for(y=0;y+scl<=YRES;y+=scl) { + sx = 0; + for(x=0;x+scl<=XRES;x+=scl) { + a = 0; + r = g = b = 0; + for(j=0;j=PT_NUM) + goto corrupt; + r += PIXR(pcolors[t]); + g += PIXG(pcolors[t]); + b += PIXB(pcolors[t]); + a ++; + } + } + if(a) { + a = 256/a; + r = (r*a)>>8; + g = (g*a)>>8; + b = (b*a)>>8; + } + drawpixel(vid_buf, px+sx, py+sy, r, g, b, 255); + sx++; + } + sy++; + } + + if(bzip2) + free(d); + return 0; + +corrupt: + if(bzip2) + free(d); + return 1; +} + +static char *mystrdup(char *s) +{ + char *x; + if(s) { + x = malloc(strlen(s)+1); + strcpy(x, s); + return x; + } + return s; +} + +void *build_save(int *size, int x0, int y0, int w, int h) +{ + unsigned char *d=calloc(1,3*(XRES/CELL)*(YRES/CELL)+(XRES*YRES)*6+MAXSIGNS*262), *c; + int i,j,x,y,p=0,*m=calloc(XRES*YRES, sizeof(int)); + int bx0=x0/CELL, by0=y0/CELL, bw=(w+CELL-1)/CELL, bh=(h+CELL-1)/CELL; + + // normalize coordinates + x0 = bx0*CELL; + y0 = by0*CELL; + w = bw *CELL; + h = bh *CELL; + + // save the required air state + for(y=by0; y255) i=255; + d[p++] = i; + } + for(y=by0; y255) i=255; + d[p++] = i; + } + + // save the particle map + for(i=0; i=x0 && x=y0 && y255) x=255; + if(y<0) y=0; + if(y>255) y=255; + d[p++] = x; + d[p++] = y; + } + } + for(j=0; j=x0 && signs[i].x=y0 && signs[i].y=x0 && signs[i].x=y0 && signs[i].y>8; + d[p++] = (signs[i].y-y0); + d[p++] = (signs[i].y-y0)>>8; + d[p++] = signs[i].ju; + x = strlen(signs[i].text); + d[p++] = x; + memcpy(d+p, signs[i].text, x); + p+=x; + } + + i = (p*101+99)/100 + 612; + c = malloc(i); + c[0] = 0x66; + c[1] = 0x75; + c[2] = 0x43; + c[3] = 0x4B; + c[4] = SAVE_VERSION; + c[5] = CELL; + c[6] = bw; + c[7] = bh; + c[8] = p; + c[9] = p >> 8; + c[10] = p >> 16; + c[11] = p >> 24; + + i -= 12; + + if(BZ2_bzBuffToBuffCompress((char *)(c+12), (unsigned *)&i, (char *)d, p, 9, 0, 0) != BZ_OK) { + free(d); + free(c); + return NULL; + } + free(d); + + *size = i+12; + return c; +} + +int parse_save(void *save, int size, int replace, int x0, int y0) +{ + unsigned char *d,*c=save; + int i,j,k,x,y,p=0,*m=calloc(XRES*YRES, sizeof(int)), ver, pty, ty; + int bx0=x0/CELL, by0=y0/CELL, bw, bh, w, h; + int fp[NPART], nf=0; + + if(size<16) + return 1; + if(c[3]!=0x4B || c[2]!=0x43 || c[1]!=0x75 || c[0]!=0x66) + return 1; + if(c[4]>SAVE_VERSION) + return 2; + ver = c[4]; + + bw = c[6]; + bh = c[7]; + if(bx0+bw > XRES/CELL) + bx0 = XRES/CELL - bw; + if(by0+bh > YRES/CELL) + by0 = YRES/CELL - bh; + if(bx0 < 0) + bx0 = 0; + if(by0 < 0) + by0 = 0; + + if(c[5]!=CELL || bx0+bw>XRES/CELL || by0+bh>YRES/CELL) + return 3; + i = (unsigned)c[8]; + i |= ((unsigned)c[9])<<8; + i |= ((unsigned)c[10])<<16; + i |= ((unsigned)c[11])<<24; + d = malloc(i); + if(!d) + return 1; + + if(BZ2_bzBuffToBuffDecompress((char *)d, (unsigned *)&i, (char *)(c+12), size-12, 0, 0)) + return 1; + size = i; + + if(size < bw*bh) + return 1; + + // normalize coordinates + x0 = bx0*CELL; + y0 = by0*CELL; + w = bw *CELL; + h = bh *CELL; + + if(replace) { + memset(bmap, 0, sizeof(bmap)); + memset(emap, 0, sizeof(emap)); + memset(signs, 0, sizeof(signs)); + memset(parts, 0, sizeof(particle)*NPART); + memset(pmap, 0, sizeof(pmap)); + memset(vx, 0, sizeof(vx)); + memset(vy, 0, sizeof(vy)); + memset(pv, 0, sizeof(pv)); + } + + // make a catalog of free parts + memset(pmap, 0, sizeof(pmap)); + for(i=0; i= size) + goto corrupt; + fvx[y][x] = (d[p++]-127.0)/64.0; + } + for(y=by0; y= size) + goto corrupt; + fvy[y][x] = (d[p++]-127.0)/64.0; + } + + // load the particle map + i = 0; + pty = p; + for(y=y0;y= size) + goto corrupt; + j=d[p++]; + if(j >= PT_NUM) + goto corrupt; + if(j) { + if(pmap[y][x]) { + k = pmap[y][x]>>8; + parts[k].type = j; + parts[k].x = x; + parts[k].y = y; + m[(x-x0)+(y-y0)*w] = k+1; + } else if(i < nf) { + parts[fp[i]].type = j; + parts[fp[i]].x = x; + parts[fp[i]].y = y; + m[(x-x0)+(y-y0)*w] = fp[i]+1; + i++; + } else + m[(x-x0)+(y-y0)*w] = NPART+1; + } + } + + // load particle properties + for(j=0; j= size) + goto corrupt; + if(i < NPART) { + parts[i].vx = (d[p++]-127.0)/16.0; + parts[i].vy = (d[p++]-127.0)/16.0; + } else + p += 2; + } + } + for(j=0; j= size) + goto corrupt; + if(i <= NPART) + parts[i-1].life = d[p++]*4; + else + p++; + } + } + for(j=0; j=21))) { + if(p >= size) + goto corrupt; + if(i <= NPART) + parts[i-1].ctype = d[p++]; + else + p++; + } + } + + if(p >= size) + goto version1; + j = d[p++]; + for(i=0; i size) + goto corrupt; + for(k=0; k size) + goto corrupt; + if(kSAVE_VERSION) + return NULL; + + bw = c[6]; + bh = c[7]; + w = bw*CELL; + h = bh*CELL; + + if(c[5]!=CELL) + return NULL; + + i = (unsigned)c[8]; + i |= ((unsigned)c[9])<<8; + i |= ((unsigned)c[10])<<16; + i |= ((unsigned)c[11])<<24; + d = malloc(i); + if(!d) + return NULL; + fb = calloc(w*h, PIXELSIZE); + if(!fb) { + free(d); + return NULL; + } + + if(BZ2_bzBuffToBuffDecompress((char *)d, (unsigned *)&i, (char *)(c+12), size-12, 0, 0)) + goto corrupt; + size = i; + + if(size < bw*bh) + goto corrupt; + + k = 0; + for(y=0; y>1)&1; i>1)&1; i>1)&1; i=size) + goto corrupt; + + for(y=0;y= size) + goto corrupt; + j=d[p++]; + if(j0) + fb[y*w+x] = pcolors[j]; + } + + free(d); + *width = w; + *height = h; + return fb; + +corrupt: + free(d); + free(fb); + return NULL; +} + +// FBI. I'm not kidding. + +#include "fbi.h" + +pixel *render_packed_rgb(void *image, int width, int height, int cmp_size) +{ + unsigned char *tmp; + pixel *res; + int i; + + tmp = malloc(width*height*3); + if(!tmp) + return NULL; + res = malloc(width*height*PIXELSIZE); + if(!res) { + free(tmp); + return NULL; + } + + i = width*height*3; + if(BZ2_bzBuffToBuffDecompress((char *)tmp, (unsigned *)&i, (char *)image, cmp_size, 0, 0)) { + free(res); + free(tmp); + return NULL; + } + + for(i=0; i1) { + r = (r+c/2)/c; + g = (g+c/2)/c; + b = (b+c/2)/c; + } + q[y*w+x] = PIXRGB(r, g, b); + } + *qw = w; + *qh = h; + return q; +} + +void stamp_gen_thumb(int i) +{ + char fn[64]; + void *data; + int size, factor_x, factor_y; + pixel *tmp; + + if(stamps[i].thumb) { + free(stamps[i].thumb); + stamps[i].thumb = NULL; + } + + sprintf(fn, "stamps" PATH_SEP "%s.stm", stamps[i].name); + data = file_load(fn, &size); + + if(data) { + stamps[i].thumb = prerender_save(data, size, &(stamps[i].thumb_w), &(stamps[i].thumb_h)); + if(stamps[i].thumb && (stamps[i].thumb_w>XRES/STAMP_X || stamps[i].thumb_h>YRES/STAMP_Y)) { + factor_x = (stamps[i].thumb_w+XRES/STAMP_X-1) / (XRES/STAMP_X); + factor_y = (stamps[i].thumb_h+YRES/STAMP_Y-1) / (YRES/STAMP_Y); + if(factor_y > factor_x) + factor_x = factor_y; + tmp = rescale_img(stamps[i].thumb, stamps[i].thumb_w, stamps[i].thumb_h, &(stamps[i].thumb_w), &(stamps[i].thumb_h), factor_x); + free(stamps[i].thumb); + stamps[i].thumb = tmp; + } + } + + free(data); +} + +void stamp_save(int x, int y, int w, int h) +{ + FILE *f; + int n; + char fn[64], sn[16]; + void *s=build_save(&n, x, y, w, h); + +#ifdef WIN32 + _mkdir("stamps"); +#else + mkdir("stamps", 0755); +#endif + + stamp_gen_name(sn); + sprintf(fn, "stamps" PATH_SEP "%s.stm", sn); + + f = fopen(fn, "wb"); + if(!f) + return; + fwrite(s, n, 1, f); + fclose(f); + + free(s); + + if(stamps[STAMP_X*STAMP_Y-1].thumb) + free(stamps[STAMP_X*STAMP_Y-1].thumb); + memmove(stamps+1, stamps, sizeof(struct stamp_info)*(STAMP_X*STAMP_Y-1)); + memset(stamps, 0, sizeof(struct stamp_info)); + + strcpy(stamps[0].name, sn); + stamp_gen_thumb(0); + + stamp_update(); +} + +void *stamp_load(int i, int *size) +{ + void *data; + char fn[64]; + struct stamp_info tmp; + + if(!stamps[i].thumb || !stamps[i].name[0]) + return NULL; + + sprintf(fn, "stamps" PATH_SEP "%s.stm", stamps[i].name); + data = file_load(fn, size); + if(!data) + return NULL; + + if(i>0) { + memcpy(&tmp, stamps+i, sizeof(struct stamp_info)); + memmove(stamps+1, stamps, sizeof(struct stamp_info)*i); + memcpy(stamps, &tmp, sizeof(struct stamp_info)); + + stamp_update(); + } + + return data; +} + +void stamp_init(void) +{ + int i; + FILE *f; + + memset(stamps, 0, sizeof(stamps)); + + f=fopen("stamps" PATH_SEP "stamps.def", "rb"); + if(!f) + return; + for(i=0; i=XRES || y>=YRES+60) + return; + if(a!=255) { + t = vid[y*XRES+x]; + r = (a*r + (255-a)*PIXR(t)) >> 8; + g = (a*g + (255-a)*PIXG(t)) >> 8; + b = (a*b + (255-a)*PIXB(t)) >> 8; + } + vid[y*XRES+x] = PIXRGB(r,g,b); +} + +int drawchar(pixel *vid, int x, int y, int c, int r, int g, int b, int a) +{ + int i, j, w, bn = 0, ba = 0; + char *rp = font_data + font_ptrs[c]; + w = *(rp++); + for(j=0; j>= 2; + bn -= 2; + } + return x + w; +} + +int drawtext(pixel *vid, int x, int y, char *s, int r, int g, int b, int a) +{ + int sx = x; + for(;*s;s++) { + if(*s == '\n') { + x = sx; + y += FONT_H+2; + } else if(*s == '\b') { + switch(s[1]) { + case 'w': + r = g = b = 255; + break; + case 'g': + r = g = b = 192; + break; + case 'o': + r = 255; + g = 216; + b = 32; + break; + case 'r': + r = 255; + g = b = 0; + break; + case 'b': + r = g = 0; + b = 255; + break; + } + s++; + } else + x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a); + } + return x; +} + +void drawrect(pixel *vid, int x, int y, int w, int h, int r, int g, int b, int a) +{ + int i; + for(i=0; i<=w; i++) { + drawpixel(vid, x+i, y, r, g, b, a); + drawpixel(vid, x+i, y+h, r, g, b, a); + } + for(i=1; i=w && x+textwidth(s)>=w+5) + break; + x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a); + } + if(*s) + for(i=0; i<3; i++) + x = drawchar(vid, x, y, '.', r, g, b, a); + return x; +} + +int textnwidth(char *s, int n) +{ + int x = 0; + for(;*s;s++) { + if(!n) + break; + x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + n--; + } + return x-1; +} +int textwidthx(char *s, int w) +{ + int x=0,n=0,cw; + for(;*s;s++) { + cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if(x+(cw/2) >= w) + break; + x += cw; + n++; + } + return n; +} + +/*********************************************************** + * MAIN PROGRAM * + ***********************************************************/ + +void draw_tool(pixel *vid_buf, int b, int sl, int sr, unsigned pc) +{ + int x, y, i, j, c; + x = 2+32*(b/2); + y = YRES+2+20*(b%2); + + if(b>=PT_NUM) + x -= 512-XRES; + + if(b==22) + for(j=1; j<15; j++) + for(i=1; i<27; i++) { + if(!(i%2) && !(j%2)) + vid_buf[XRES*(y+j)+(x+i)] = pc; + else + vid_buf[XRES*(y+j)+(x+i)] = 0x808080; + } + else if(b==23) { + for(j=1; j<15; j++) { + for(i=1; i<6+j; i++) + if(!(i&j&1)) + vid_buf[XRES*(y+j)+(x+i)] = pc; + for(; i<27; i++) + if(i&j&1) + vid_buf[XRES*(y+j)+(x+i)] = pc; + } + } else if(b==24) + for(j=1; j<15; j+=2) + for(i=1+(1&(j>>1)); i<27; i+=2) + vid_buf[XRES*(y+j)+(x+i)] = pc; + else if(b==25) { + for(j=1; j<15; j++) + for(i=1; i<27; i++) + vid_buf[XRES*(y+j)+(x+i)] = i==1||i==26||j==1||j==14 ? 0xA0A0A0 : 0x000000; + drawtext(vid_buf, x+4, y+3, "\x8D", 255, 255, 255, 255); + for(i=9; i<27; i++) + drawpixel(vid_buf, x+i, y+8+(int)(3.9f*cos(i*0.3f)), 255, 255, 255, 255); + } else if(b==26) { + for(j=1; j<15; j++) + for(i=1; i<27; i++) + vid_buf[XRES*(y+j)+(x+i)] = i==1||i==26||j==1||j==14 ? 0xA0A0A0 : 0x000000; + drawtext(vid_buf, x+9, y+3, "\xA1", 32, 64, 128, 255); + drawtext(vid_buf, x+9, y+3, "\xA0", 255, 255, 255, 255); + } else if(b==27) + for(j=1; j<15; j+=2) + for(i=1+(1&(j>>1)); i<27; i+=2) + vid_buf[XRES*(y+j)+(x+i)] = pc; + else if(b==28) + for(j=1; j<15; j++) + for(i=1; i<27; i++) { + if(!(i%2) && !(j%2)) + vid_buf[XRES*(y+j)+(x+i)] = pc; + } + else if(b==29) + for(j=1; j<15; j+=2) + for(i=1+(1&(j>>1)); i<27; i+=2) + vid_buf[XRES*(y+j)+(x+i)] = pc; + else if(b==30) { + for(j=1; j<15; j+=2) + for(i=1+(1&(j>>1)); i<13; i+=2) + vid_buf[XRES*(y+j)+(x+i)] = pc; + for(j=1; j<15; j++) + for(i=14; i<27; i++) + vid_buf[XRES*(y+j)+(x+i)] = pc; + } else + for(j=1; j<15; j++) + for(i=1; i<27; i++) + vid_buf[XRES*(y+j)+(x+i)] = pc; + + if(b==30 || b==0) + for(j=4; j<12; j++) { + vid_buf[XRES*(y+j)+(x+j+6)] = PIXPACK(0xFF0000); + vid_buf[XRES*(y+j)+(x+j+7)] = PIXPACK(0xFF0000); + vid_buf[XRES*(y+j)+(x-j+21)] = PIXPACK(0xFF0000); + vid_buf[XRES*(y+j)+(x-j+22)] = PIXPACK(0xFF0000); + } + + if(b>0 && b=0 && i+u=0 && j+vabs(x2-x1), x, y, dx, dy, sy; + float e, de; + if(cp) { + y = x1; + x1 = y1; + y1 = y; + y = x2; + x2 = y2; + y2 = y; + } + if(x1 > x2) { + y = x1; + x1 = x2; + x2 = y; + y = y1; + y1 = y2; + y2 = y; + } + dx = x2 - x1; + dy = abs(y2 - y1); + e = 0.0f; + if(dx) + de = dy/(float)dx; + else + de = 0.0f; + y = y1; + sy = (y1= 0.5f) { + y += sy; + if(c==31 || c==29 || c==28 || c==27 || c==25 || c==24 || c==23 || c==22 || !r) { + if(cp) + create_parts(y, x, r, c); + else + create_parts(x, y, r, c); + } + e -= 1.0f; + } + } +} + +void create_box(int x1, int y1, int x2, int y2, int c) +{ + int i, j; + if(x1>x2) { + i = x2; + x2 = x1; + x1 = i; + } + if(y1>y2) { + j = y2; + y2 = y1; + y1 = j; + } + for(j=y1; j<=y2; j++) + for(i=x1; i<=x2; i++) + create_parts(i, j, 1, c); +} + +int flood_parts(int x, int y, int c, int cm, int bm) +{ + int x1, x2, dy = (c=CELL) { + if((pmap[y][x1-1]&0xFF)!=cm || bmap[y/CELL][(x1-1)/CELL]!=bm) + break; + x1--; + } + while(x2=CELL+dy) + for(x=x1; x<=x2; x++) + if((pmap[y-dy][x]&0xFF)==cm && bmap[(y-dy)/CELL][x/CELL]==bm) + if(!flood_parts(x, y-dy, c, cm, bm)) + return 0; + if(y=XRES || y>=YRES) + return; + c = vid[y*XRES+x]; + c = PIXB(c) + 3*PIXG(c) + 2*PIXR(c); + if(c<512) + vid[y*XRES+x] = PIXPACK(0xC0C0C0); + else + vid[y*XRES+x] = PIXPACK(0x404040); +} + +void xor_line(int x1, int y1, int x2, int y2, pixel *vid) +{ + int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy; + float e, de; + if(cp) { + y = x1; + x1 = y1; + y1 = y; + y = x2; + x2 = y2; + y2 = y; + } + if(x1 > x2) { + y = x1; + x1 = x2; + x2 = y; + y = y1; + y1 = y2; + y2 = y; + } + dx = x2 - x1; + dy = abs(y2 - y1); + e = 0.0f; + if(dx) + de = dy/(float)dx; + else + de = 0.0f; + y = y1; + sy = (y1= 0.5f) { + y += sy; + e -= 1.0f; + } + } +} + +void draw_svf_ui(pixel *vid_buf) +{ + int c; + + drawtext(vid_buf, 4, YRES+44, "\x81", 255, 255, 255, 255); + drawrect(vid_buf, 1, YRES+42, 16, 14, 255, 255, 255, 255); + + c = svf_open ? 255 : 128; + drawtext(vid_buf, 23, YRES+44, "\x91", c, c, c, 255); + drawrect(vid_buf, 19, YRES+42, 16, 14, c, c, c, 255); + + c = svf_login ? 255 : 128; + drawtext(vid_buf, 40, YRES+44, "\x82", c, c, c, 255); + if(svf_open) + drawtext(vid_buf, 58, YRES+46, svf_name, c, c, c, 255); + else + drawtext(vid_buf, 58, YRES+46, "[untitled simulation]", c, c, c, 255); + drawrect(vid_buf, 37, YRES+42, 150, 14, c, c, c, 255); + if(svf_open && svf_own) + drawdots(vid_buf, 55, YRES+43, 12, c, c, c, 255); + + c = (svf_login && svf_open) ? 255 : 128; + drawtext(vid_buf, 192, YRES+44, "\x83", c, c, c, 255); + if(svf_tags[0]) + drawtextmax(vid_buf, 210, YRES+46, 154, svf_tags, c, c, c, 255); + else + drawtext(vid_buf, 210, YRES+46, "[no tags set]", c, c, c, 255); + drawrect(vid_buf, 189, YRES+42, 176, 14, c, c, c, 255); + + drawtext(vid_buf, 371, YRES+44, "\x92", 255, 255, 255, 255); + drawrect(vid_buf, 367, YRES+42, 16, 14, 255, 255, 255, 255); + + drawtext(vid_buf, 388, YRES+45, "\x84", 255, 255, 255, 255); + if(svf_login) + drawtext(vid_buf, 406, YRES+46, svf_user, 255, 255, 255, 255); + else + drawtext(vid_buf, 406, YRES+46, "[sign in]", 255, 255, 255, 255); + drawrect(vid_buf, 385, YRES+42, 91, 14, 255, 255, 255, 255); + + if(sys_pause) { + fillrect(vid_buf, 493, YRES+41, 16, 16, 255, 255, 255, 255); + drawtext(vid_buf, 496, YRES+44, "\x90", 0, 0, 0, 255); + } else { + drawtext(vid_buf, 496, YRES+44, "\x90", 255, 255, 255, 255); + drawrect(vid_buf, 494, YRES+42, 14, 14, 255, 255, 255, 255); + } + + switch(cmode) { + case 0: + drawtext(vid_buf, 481, YRES+45, "\x98", 128, 160, 255, 255); + break; + case 1: + drawtext(vid_buf, 481, YRES+45, "\x99", 255, 212, 32, 255); + break; + case 2: + drawtext(vid_buf, 481, YRES+45, "\x9A", 212, 212, 212, 255); + break; + case 3: + drawtext(vid_buf, 481, YRES+45, "\x9B", 255, 0, 0, 255); + drawtext(vid_buf, 481, YRES+45, "\x9C", 255, 255, 64, 255); + break; + } + drawrect(vid_buf, 478, YRES+42, 14, 14, 255, 255, 255, 255); + + if(svf_admin) { + drawtext(vid_buf, 463, YRES+44, "\xA4", 0, 32, 0, 255); + drawtext(vid_buf, 463, YRES+44, "\xA3", 0, 255, 127, 255); + } else if(amd) + drawtext(vid_buf, 465, YRES+45, "\x97", 0, 230, 153, 255); +} + +typedef struct ui_edit { + int x, y, w, nx; + char str[256],*def; + int focus, cursor, hide; +} ui_edit; +void ui_edit_draw(pixel *vid_buf, ui_edit *ed) +{ + int cx, i; + char echo[256], *str; + + if(ed->hide) { + for(i=0;ed->str[i];i++) + echo[i] = 0x8D; + echo[i] = 0; + str = echo; + } else + str = ed->str; + + if(ed->str[0]) { + drawtext(vid_buf, ed->x, ed->y, str, 255, 255, 255, 255); + drawtext(vid_buf, ed->x+ed->w-11, ed->y-1, "\xAA", 128, 128, 128, 255); + } else if(!ed->focus) + drawtext(vid_buf, ed->x, ed->y, ed->def, 128, 128, 128, 255); + if(ed->focus) { + cx = textnwidth(str, ed->cursor); + for(i=-3; i<9; i++) + drawpixel(vid_buf, ed->x+cx, ed->y+i, 255, 255, 255, 255); + } +} +char *shift_0="`1234567890-=[]\\;',./"; +char *shift_1="~!@#$%^&*()_+{}|:\"<>?"; +void ui_edit_process(int mx, int my, int mb, ui_edit *ed) +{ + char ch, ts[2], echo[256], *str; + int l, i; +#ifdef RAWINPUT + char *p; +#endif + + if(mb) { + if(ed->hide) { + for(i=0;ed->str[i];i++) + echo[i] = 0x8D; + echo[i] = 0; + str = echo; + } else + str = ed->str; + + if(mx>=ed->x+ed->w-11 && mxx+ed->w && my>=ed->y-5 && myy+11) { + ed->focus = 1; + ed->cursor = 0; + ed->str[0] = 0; + } else if(mx>=ed->x-ed->nx && mxx+ed->w && my>=ed->y-5 && myy+11) { + ed->focus = 1; + ed->cursor = textwidthx(str, mx-ed->x); + } else + ed->focus = 0; + } + if(ed->focus && sdl_key) { + if(ed->hide) { + for(i=0;ed->str[i];i++) + echo[i] = 0x8D; + echo[i] = 0; + str = echo; + } else + str = ed->str; + + l = strlen(ed->str); + switch(sdl_key) { + case SDLK_HOME: + ed->cursor = 0; + break; + case SDLK_END: + ed->cursor = l; + break; + case SDLK_LEFT: + if(ed->cursor > 0) + ed->cursor --; + break; + case SDLK_RIGHT: + if(ed->cursor < l) + ed->cursor ++; + break; + case SDLK_DELETE: + if(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)) + ed->str[ed->cursor] = 0; + else if(ed->cursor < l) + memmove(ed->str+ed->cursor, ed->str+ed->cursor+1, l-ed->cursor); + break; + case SDLK_BACKSPACE: + if(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)) { + if(ed->cursor > 0) + memmove(ed->str, ed->str+ed->cursor, l-ed->cursor+1); + ed->cursor = 0; + } else if(ed->cursor > 0) { + ed->cursor--; + memmove(ed->str+ed->cursor, ed->str+ed->cursor+1, l-ed->cursor); + } + break; + default: +#ifdef RAWINPUT + if(sdl_key>=SDLK_SPACE && sdl_key<=SDLK_z && l<255) { + ch = sdl_key; + if((sdl_mod & (KMOD_LSHIFT|KMOD_RSHIFT|KMOD_CAPS))) { + if(ch>='a' && ch<='z') + ch &= ~0x20; + p = strchr(shift_0, ch); + if(p) + ch = shift_1[p-shift_0]; + } + ts[0]=ed->hide?0x8D:ch; + ts[1]=0; + if(textwidth(str)+textwidth(ts) > ed->w-14) + break; + memmove(ed->str+ed->cursor+1, ed->str+ed->cursor, l+1-ed->cursor); + ed->str[ed->cursor] = ch; + ed->cursor++; + } +#else + if(sdl_ascii>=' ' && sdl_ascii<127) { + ch = sdl_ascii; + ts[0]=ed->hide?0x8D:ch; + ts[1]=0; + if(textwidth(str)+textwidth(ts) > ed->w-14) + break; + memmove(ed->str+ed->cursor+1, ed->str+ed->cursor, l+1-ed->cursor); + ed->str[ed->cursor] = ch; + ed->cursor++; + } +#endif + break; + } + } +} + +void error_ui(pixel *vid_buf, int err, char *txt) +{ + int x0=(XRES-240)/2,y0=(YRES-60)/2,b=1,bq,mx,my; + char *msg; + + msg = malloc(strlen(txt)+16); + if(err) + sprintf(msg, "%03d %s", err, txt); + else + sprintf(msg, "%s", txt); + + while(!sdl_poll()) { + b = SDL_GetMouseState(&mx, &my); + if(!b) + break; + } + + while(!sdl_poll()) { + bq = b; + b = SDL_GetMouseState(&mx, &my); + mx /= sdl_scale; + my /= sdl_scale; + + clearrect(vid_buf, x0-2, y0-2, 244, 64); + drawrect(vid_buf, x0, y0, 240, 60, 192, 192, 192, 255); + if(err) + drawtext(vid_buf, x0+8, y0+8, "HTTP error:", 255, 64, 32, 255); + else + drawtext(vid_buf, x0+8, y0+8, "Error:", 255, 64, 32, 255); + drawtext(vid_buf, x0+8, y0+26, msg, 255, 255, 255, 255); + drawtext(vid_buf, x0+5, y0+49, "Dismiss", 255, 255, 255, 255); + drawrect(vid_buf, x0, y0+44, 240, 16, 192, 192, 192, 255); + sdl_blit(0, 0, XRES, YRES+60, vid_buf, XRES); + + if(b && !bq && mx>=x0 && mx=y0+44 && my<=y0+60) + break; + + if(sdl_key==SDLK_RETURN) + break; + if(sdl_key==SDLK_ESCAPE) + break; + } + + free(msg); + + while(!sdl_poll()) { + b = SDL_GetMouseState(&mx, &my); + if(!b) + break; + } +} + +void info_ui(pixel *vid_buf, char *top, char *txt) +{ + int x0=(XRES-240)/2,y0=(YRES-60)/2,b=1,bq,mx,my; + + while(!sdl_poll()) { + b = SDL_GetMouseState(&mx, &my); + if(!b) + break; + } + + while(!sdl_poll()) { + bq = b; + b = SDL_GetMouseState(&mx, &my); + mx /= sdl_scale; + my /= sdl_scale; + + clearrect(vid_buf, x0-2, y0-2, 244, 64); + drawrect(vid_buf, x0, y0, 240, 60, 192, 192, 192, 255); + drawtext(vid_buf, x0+8, y0+8, top, 160, 160, 255, 255); + drawtext(vid_buf, x0+8, y0+26, txt, 255, 255, 255, 255); + drawtext(vid_buf, x0+5, y0+49, "OK", 255, 255, 255, 255); + drawrect(vid_buf, x0, y0+44, 240, 16, 192, 192, 192, 255); + sdl_blit(0, 0, XRES, YRES+60, vid_buf, XRES); + + if(b && !bq && mx>=x0 && mx=y0+44 && my<=y0+60) + break; + + if(sdl_key==SDLK_RETURN) + break; + if(sdl_key==SDLK_ESCAPE) + break; + } + + while(!sdl_poll()) { + b = SDL_GetMouseState(&mx, &my); + if(!b) + break; + } +} + +void info_box(pixel *vid_buf, char *msg) +{ + int w = textwidth(msg)+16; + int x0=(XRES-w)/2,y0=(YRES-24)/2; + + clearrect(vid_buf, x0-2, y0-2, w+4, 28); + drawrect(vid_buf, x0, y0, w, 24, 192, 192, 192, 255); + drawtext(vid_buf, x0+8, y0+8, msg, 192, 192, 240, 255); + sdl_blit(0, 0, XRES, YRES+60, vid_buf, XRES); +} + +int confirm_ui(pixel *vid_buf, char *top, char *msg, char *btn) +{ + int x0=(XRES-240)/2,y0=(YRES-60)/2,b=1,bq,mx,my; + int ret = 0; + + while(!sdl_poll()) { + b = SDL_GetMouseState(&mx, &my); + if(!b) + break; + } + + while(!sdl_poll()) { + bq = b; + b = SDL_GetMouseState(&mx, &my); + mx /= sdl_scale; + my /= sdl_scale; + + clearrect(vid_buf, x0-2, y0-2, 244, 64); + drawrect(vid_buf, x0, y0, 240, 60, 192, 192, 192, 255); + drawtext(vid_buf, x0+8, y0+8, top, 255, 216, 32, 255); + drawtext(vid_buf, x0+8, y0+26, msg, 255, 255, 255, 255); + drawtext(vid_buf, x0+5, y0+49, "Cancel", 255, 255, 255, 255); + drawtext(vid_buf, x0+165, y0+49, btn, 255, 216, 32, 255); + drawrect(vid_buf, x0, y0+44, 160, 16, 192, 192, 192, 255); + drawrect(vid_buf, x0+160, y0+44, 80, 16, 192, 192, 192, 255); + sdl_blit(0, 0, XRES, YRES+60, vid_buf, XRES); + + if(b && !bq && mx>=x0+160 && mx=y0+44 && my<=y0+60) { + ret = 1; + break; + } + if(b && !bq && mx>=x0 && mx=y0+44 && my<=y0+60) + break; + + if(sdl_key==SDLK_RETURN) { + ret = 1; + break; + } + if(sdl_key==SDLK_ESCAPE) + break; + } + + while(!sdl_poll()) { + b = SDL_GetMouseState(&mx, &my); + if(!b) + break; + } + + return ret; +} + +int execute_tagop(pixel *vid_buf, char *op, char *tag) +{ + int status; + char *result; + + char *names[] = {"id", "tag", NULL}; + char *parts[2]; + + char *uri = malloc(strlen(SERVER)+strlen(op)+32); + sprintf(uri, "http://" SERVER "/powder/tag%s.php", op); + + parts[0] = svf_id; + parts[1] = tag; + + result = http_multipart_post( + uri, + names, parts, NULL, + svf_user, svf_pass, + &status, NULL); + + free(uri); + + if(status!=200) { + error_ui(vid_buf, status, http_ret_text(status)); + if(result) + free(result); + return 1; + } + if(result && strncmp(result, "OK", 2)) { + error_ui(vid_buf, 0, result); + free(result); + return 1; + } + + if(result[2]) { + strncpy(svf_tags, result+3, 255); + svf_id[15] = 0; + } + + if(result) + free(result); + + return 0; +} + +struct strlist { + char *str; + struct strlist *next; +}; +void strlist_add(struct strlist **list, char *str) +{ + struct strlist *item = malloc(sizeof(struct strlist)); + item->str = mystrdup(str); + item->next = *list; + *list = item; +} +int strlist_find(struct strlist **list, char *str) +{ + struct strlist *item; + for(item=*list;item;item=item->next) + if(!strcmp(item->str, str)) + return 1; + return 0; +} +void strlist_free(struct strlist **list) +{ + struct strlist *item; + while(*list) { + item = *list; + *list = (*list)->next; + free(item); + } +} + +void tag_list_ui(pixel *vid_buf) +{ + int y,d,x0=(XRES-192)/2,y0=(YRES-256)/2,b=1,bq,mx,my,vp,vn; + char *p,*q,s; + char *tag=NULL, *op=NULL; + ui_edit ed; + struct strlist *vote=NULL,*down=NULL; + + ed.x = x0+25; + ed.y = y0+221; + ed.w = 158; + ed.nx = 1; + ed.def = "[new tag]"; + ed.focus = 0; + ed.hide = 0; + ed.cursor = 0; + strcpy(ed.str, ""); + + fillrect(vid_buf, -1, -1, XRES, YRES+60, 0, 0, 0, 192); + while(!sdl_poll()) { + bq = b; + b = SDL_GetMouseState(&mx, &my); + mx /= sdl_scale; + my /= sdl_scale; + + op = tag = NULL; + + drawrect(vid_buf, x0, y0, 192, 256, 192, 192, 192, 255); + clearrect(vid_buf, x0, y0, 192, 256); + drawtext(vid_buf, x0+8, y0+8, "Current tags:", 255, 255, 255, 255); + p = svf_tags; + s = svf_tags[0] ? ' ' : 0; + y = 36 + y0; + while(s) { + q = strchr(p, ' '); + if(!q) + q = p+strlen(p); + s = *q; + *q = 0; + if(svf_own || svf_admin) { + drawtext(vid_buf, x0+20, y-1, "\x86", 160, 48, 32, 255); + drawtext(vid_buf, x0+20, y-1, "\x85", 255, 255, 255, 255); + d = 14; + if(b && !bq && mx>=x0+18 && mx=y-2 && my=x0+d+18 && mx=y-2 && my=x0+d+32 && mx=y-2 && my=x0 && mx<=x0+192 && my>=y0+240 && my=x0+9 && mx=y0+218 && my=x0+9 && mx=y0+22 && my=x0 && mx=y0+52+YRES/4 && my=x0+9 && mx=y0+22 && my=x0+9 && mx=y0+42 && my=x0 && mx=y0+64 && my<=y0+80) + break; + + if(sdl_key==SDLK_RETURN) { + if(!ed1.focus) + break; + ed1.focus = 0; + ed2.focus = 1; + } + if(sdl_key==SDLK_ESCAPE) { + if(!ed1.focus && !ed2.focus) + return; + ed1.focus = 0; + ed2.focus = 0; + } + } + + strcpy(svf_user, ed1.str); + md5_ascii(svf_pass, (unsigned char *)ed2.str, 0); + + res = http_multipart_post( + "http://" SERVER "/powder/login.php", + NULL, NULL, NULL, + svf_user, svf_pass, + &err, NULL); + if(err != 200) { + error_ui(vid_buf, err, http_ret_text(err)); + if(res) + free(res); + goto fail; + } + if(res && !strncmp(res, "OK", 2)) { + if(!strcmp(res, "OK ADMIN")) + svf_admin = 1; + else + svf_admin = 0; + free(res); + svf_login = 1; + return; + } + if(!res) + res = mystrdup("Unspecified Error"); + error_ui(vid_buf, 0, res); + free(res); + +fail: + strcpy(svf_user, ""); + strcpy(svf_pass, ""); + svf_login = 0; + svf_own = 0; + svf_admin = 0; +} + +void execute_delete(pixel *vid_buf, char *id) +{ + int status; + char *result; + + char *names[] = {"id", NULL}; + char *parts[1]; + + parts[0] = id; + + result = http_multipart_post( + "http://" SERVER "/powder/delete.php", + names, parts, NULL, + svf_user, svf_pass, + &status, NULL); + + if(status!=200) { + error_ui(vid_buf, status, http_ret_text(status)); + if(result) + free(result); + return; + } + if(result && strncmp(result, "OK", 2)) { + error_ui(vid_buf, 0, result); + free(result); + return; + } + + if(result) + free(result); +} + +static char hex[] = "0123456789ABCDEF"; +void strcaturl(char *dst, char *src) +{ + char *d; + unsigned char *s; + + for(d=dst; *d; d++) ; + + for(s=(unsigned char *)src; *s; s++) { + if((*s>='0' && *s<='9') || + (*s>='a' && *s<='z') || + (*s>='A' && *s<='Z')) + *(d++) = *s; + else { + *(d++) = '%'; + *(d++) = hex[*s>>4]; + *(d++) = hex[*s&15]; + } + } + *d = 0; +} + +#define THUMB_CACHE_SIZE 256 + +char *thumb_cache_id[THUMB_CACHE_SIZE]; +void *thumb_cache_data[THUMB_CACHE_SIZE]; +int thumb_cache_size[THUMB_CACHE_SIZE]; +int thumb_cache_lru[THUMB_CACHE_SIZE]; + +void thumb_cache_inval(char *id) +{ + int i,j; + for(i=0;i= THUMB_CACHE_SIZE) + return; + free(thumb_cache_id[i]); + free(thumb_cache_data[i]); + thumb_cache_id[i] = NULL; + for(j=0;j thumb_cache_lru[i]) + thumb_cache_lru[j]--; +} +void thumb_cache_add(char *id, void *thumb, int size) +{ + int i,m=-1,j=-1; + thumb_cache_inval(id); + for(i=0;i m) { + m = thumb_cache_lru[i]; + j = i; + } + } + if(i >= THUMB_CACHE_SIZE) { + thumb_cache_inval(thumb_cache_id[j]); + i = j; + } + for(j=0;j= THUMB_CACHE_SIZE) + return 0; + for(j=0;j=GRID_X*GRID_Y) + break; + if(votes) { + s = strchr(str, ' '); + if(!s) + return i; + *(s++) = 0; + q = strchr(s, ' '); + } else + q = strchr(str, ' '); + if(!q) + return i; + *(q++) = 0; + r = strchr(q, ' '); + if(!r) + return i; + *(r++) = 0; + search_ids[i] = mystrdup(str); + search_owners[i] = mystrdup(q); + search_names[i] = mystrdup(r); + if(s) + search_votes[i] = atoi(s); + thumb_cache_find(str, search_thumbs+i, search_thsizes+i); + i++; + } else { + if(j >= TAG_MAX) { + str = p; + continue; + } + q = strchr(str+4, ' '); + if(!q) { + str = p; + continue; + } + *(q++) = 0; + tag_names[j] = mystrdup(str+4); + tag_votes[j] = atoi(q); + j++; + } + str = p; + } + if(*str) + i++; + return i; +} + +#define IMGCONNS 3 +#define TIMEOUT 100 +#define HTTP_TIMEOUT 10 + +int search_own = 0; +int search_date = 0; +int search_page = 0; +char search_expr[256] = ""; + +int search_ui(pixel *vid_buf) +{ + int b=1,bq,mx=0,my=0,mxq=0,myq=0,mmt=0,gi,gj,gx,gy,pos,i,mp,dp,own,last_own=search_own,page_count=0,last_page=0,last_date=0,j,w,h,st=0; + int is_p1=0, exp_res=GRID_X*GRID_Y, tp, view_own=0, http_last_use=HTTP_TIMEOUT; + ui_edit ed; + + void *http = NULL; + int active = 0; + char *last = NULL; + int search = 0; + int lasttime = TIMEOUT; + char *uri; + int status; + char *results; + char *tmp, ts[64]; + + void *img_http[IMGCONNS]; + char *img_id[IMGCONNS]; + void *thumb, *data; + int thlen, dlen; + + memset(img_http, 0, sizeof(img_http)); + memset(img_id, 0, sizeof(img_id)); + + memset(search_ids, 0, sizeof(search_ids)); + memset(search_names, 0, sizeof(search_names)); + memset(search_owners, 0, sizeof(search_owners)); + memset(search_thumbs, 0, sizeof(search_thumbs)); + memset(search_thsizes, 0, sizeof(search_thsizes)); + + while(!sdl_poll()) { + b = SDL_GetMouseState(&mx, &my); + if(!b) + break; + } + + ed.x = 65; + ed.y = 13; + ed.w = XRES-200; + ed.nx = 1; + ed.def = "[search terms]"; + ed.focus = 1; + ed.hide = 0; + ed.cursor = strlen(search_expr); + strcpy(ed.str, search_expr); + + sdl_wheel = 0; + + while(!sdl_poll()) { + bq = b; + mxq = mx; + myq = my; + b = SDL_GetMouseState(&mx, &my); + mx /= sdl_scale; + my /= sdl_scale; + + if(mx!=mxq || my!=myq || sdl_wheel || b) + mmt = 0; + else if(mmt 9) { + drawtext(vid_buf, XRES-15, YRES+44, "\x95", 255, 255, 255, 255); + drawrect(vid_buf, XRES-18, YRES+40, 16, 16, 255, 255, 255, 255); + } + + ui_edit_draw(vid_buf, &ed); + + tp = -1; + if(is_p1) { + drawtext(vid_buf, (XRES-textwidth("Popular tags:"))/2, 31, "Popular tags:", 255, 192, 64, 255); + for(gj=0;gj<((GRID_Y-GRID_P)*YRES)/(GRID_Y*14);gj++) + for(gi=0;giTAG_MAX || !tag_names[pos]) + break; + if(tag_votes[0]) + i = 127+(128*tag_votes[pos])/tag_votes[0]; + else + i = 192; + w = textwidth(tag_names[pos]); + if(w>XRES/GRID_X-5) + w = XRES/GRID_X-5; + gx = (XRES/GRID_X)*gi; + gy = gj*14 + 46; + if(mx>=gx && mx=gy && my XRES/GRID_X-10) { + tmp = malloc(strlen(search_names[pos])+4); + strcpy(tmp, search_names[pos]); + j = textwidthx(tmp, XRES/GRID_X-15); + strcpy(tmp+j, "..."); + drawtext(vid_buf, gx+XRES/(GRID_S*2)-textwidth(tmp)/2, gy+YRES/GRID_S+7, tmp, 192, 192, 192, 255); + free(tmp); + } else + drawtext(vid_buf, gx+XRES/(GRID_S*2)-textwidth(search_names[pos])/2, gy+YRES/GRID_S+7, search_names[pos], 192, 192, 192, 255); + j = textwidth(search_owners[pos]); + if(mx>=gx+XRES/(GRID_S*2)-j/2 && mx<=gx+XRES/(GRID_S*2)+j/2 && + my>=gy+YRES/GRID_S+18 && my<=gy+YRES/GRID_S+31) { + st = 1; + drawtext(vid_buf, gx+XRES/(GRID_S*2)-j/2, gy+YRES/GRID_S+20, search_owners[pos], 128, 128, 160, 255); + } else + drawtext(vid_buf, gx+XRES/(GRID_S*2)-j/2, gy+YRES/GRID_S+20, search_owners[pos], 128, 128, 128, 255); + if(search_thumbs[pos]) + render_thumb(search_thumbs[pos], search_thsizes[pos], 1, vid_buf, gx, gy, GRID_S); + own = svf_login && (!strcmp(svf_user, search_owners[pos]) || svf_admin); + if(mx>=gx-2 && mx<=gx+XRES/GRID_S+3 && my>=gy-2 && my<=gy+YRES/GRID_S+30) + mp = pos; + if(own) { + if(mx>=gx+XRES/GRID_S-4 && mx<=gx+XRES/GRID_S+6 && my>=gy-6 && my<=gy+4) { + mp = -1; + dp = pos; + } + } + if(mp==pos && !st) + drawrect(vid_buf, gx-2, gy-2, XRES/GRID_S+3, YRES/GRID_S+3, 160, 160, 192, 255); + else + drawrect(vid_buf, gx-2, gy-2, XRES/GRID_S+3, YRES/GRID_S+3, 128, 128, 128, 255); + if(own) { + if(dp == pos) + drawtext(vid_buf, gx+XRES/GRID_S-4, gy-6, "\x86", 255, 48, 32, 255); + else + drawtext(vid_buf, gx+XRES/GRID_S-4, gy-6, "\x86", 160, 48, 32, 255); + drawtext(vid_buf, gx+XRES/GRID_S-4, gy-6, "\x85", 255, 255, 255, 255); + } + if(view_own || svf_admin) { + sprintf(ts+1, "%d", search_votes[pos]); + ts[0] = 0xBB; + for(j=1; ts[j]; j++) + ts[j] = 0xBC; + ts[j-1] = 0xB9; + ts[j] = 0xBA; + ts[j+1] = 0; + w = gx+XRES/GRID_S-2-textwidth(ts); + h = gy+YRES/GRID_S-11; + drawtext(vid_buf, w, h, ts, 16, 72, 16, 255); + for(j=0; ts[j]; j++) + ts[j] -= 14; + drawtext(vid_buf, w, h, ts, 192, 192, 192, 255); + sprintf(ts, "%d", search_votes[pos]); + for(j=0; ts[j]; j++) + ts[j] += 127; + drawtext(vid_buf, w+3, h, ts, 255, 255, 255, 255); + } + } + + if(mp!=-1 && mmt>=TIMEOUT/5 && !st) { + gi = mp % GRID_X; + gj = mp / GRID_X; + if(is_p1) + gj += GRID_Y-GRID_P; + gx = ((XRES/GRID_X)*gi) + (XRES/GRID_X-XRES/GRID_S)/2; + gy = (((YRES+15)/GRID_Y)*gj) + (YRES/GRID_Y-YRES/GRID_S+10)/2 + 18; + i = w = textwidth(search_names[mp]); + h = YRES/GRID_Z+30; + if(w=XRES-2) gx=XRES-3-w; + if(gy<32) gy=32; + if(gy+h>=YRES+58) gy=YRES+57-h; + clearrect(vid_buf, gx-2, gy-3, w+4, h); + drawrect(vid_buf, gx-2, gy-3, w+4, h, 160, 160, 192, 255); + if(search_thumbs[mp]) + render_thumb(search_thumbs[mp], search_thsizes[mp], 1, vid_buf, gx+(w-(XRES/GRID_Z))/2, gy, GRID_Z); + drawtext(vid_buf, gx+(w-i)/2, gy+YRES/GRID_Z+4, search_names[mp], 192, 192, 192, 255); + drawtext(vid_buf, gx+(w-textwidth(search_owners[mp]))/2, gy+YRES/GRID_Z+16, search_owners[mp], 128, 128, 128, 255); + } + + sdl_blit(0, 0, XRES, YRES+60, vid_buf, XRES); + + ui_edit_process(mx, my, b, &ed); + + if(sdl_key==SDLK_RETURN) { + if(!last || (!active && (strcmp(last, ed.str) || last_own!=search_own || last_date!=search_date || last_page!=search_page))) + lasttime = TIMEOUT; + else if(search_ids[0] && !search_ids[1]) { + bq = 0; + b = 1; + mp = 0; + } + } + if(sdl_key==SDLK_ESCAPE) + goto finish; + + if((b && !bq && mx>=1 && mx<=17 && my>=YRES+40 && my0) { + if(search_page) { + search_page --; + lasttime = TIMEOUT; + } + sdl_wheel = 0; + } + if((b && !bq && mx>=XRES-18 && mx<=XRES-1 && my>=YRES+40 && myexp_res) { + lasttime = TIMEOUT; + search_page ++; + page_count = exp_res; + } + sdl_wheel = 0; + } + + if(b && !bq && mx>=XRES-64 && mx<=XRES-8 && my>=8 && my<=24 && svf_login) { + search_own = !search_own; + lasttime = TIMEOUT; + } + if(b && !bq && mx>=XRES-129 && mx<=XRES-65 && my>=8 && my<=24) { + search_date = !search_date; + lasttime = TIMEOUT; + } + + if(b && !bq && dp!=-1) + if(confirm_ui(vid_buf, "Do you want to delete?", search_names[dp], "Delete")) { + execute_delete(vid_buf, search_ids[dp]); + lasttime = TIMEOUT; + if(last) { + free(last); + last = NULL; + } + } + + if(b && !bq && tp!=-1) { + strncpy(ed.str, tag_names[tp], 255); + lasttime = TIMEOUT; + } + + if(b && !bq && mp!=-1 && st) { + sprintf(ed.str, "user:%s", search_owners[mp]); + lasttime = TIMEOUT; + } + + if(b && !bq && mp!=-1 && !st) { + info_box(vid_buf, "Loading..."); + + uri = malloc(strlen(search_ids[mp])*3+strlen(SERVER)+64); + strcpy(uri, "http://" SERVER "/powder/saves/"); + strcaturl(uri, search_ids[mp]); + data = http_simple_get(uri, &status, &dlen); + free(uri); + + if(status == 200) { + status = parse_save(data, dlen, 1, 0, 0); + switch(status) { + case 1: + error_ui(vid_buf, 0, "Simulation corrupted"); + break; + case 2: + error_ui(vid_buf, 0, "Simulation from a newer version"); + break; + case 3: + error_ui(vid_buf, 0, "Simulation on a too large grid"); + break; + } + if(!status) { + if(svf_last) + free(svf_last); + svf_last = data; + svf_lsize = dlen; + + uri = malloc(strlen(search_ids[mp])*3+strlen(SERVER)+64); + strcpy(uri, "http://" SERVER "/powder/tags.php?id="); + strcaturl(uri, search_ids[mp]); + data = http_simple_get(uri, &status, NULL); + free(uri); + + svf_open = 1; + svf_own = svf_login && !strcmp(search_owners[mp], svf_user); + strcpy(svf_id, search_ids[mp]); + strcpy(svf_name, search_names[mp]); + if(status == 200) { + if(data) { + strncpy(svf_tags, data, 255); + svf_tags[255] = 0; + } else + svf_tags[0] = 0; + } else + svf_tags[0] = 0; + } else { + svf_open = 0; + svf_own = 0; + svf_id[0] = 0; + svf_name[0] = 0; + svf_tags[0] = 0; + if(svf_last) + free(svf_last); + svf_last = NULL; + } + } else + error_ui(vid_buf, status, http_ret_text(status)); + + if(data) + free(data); + goto finish; + } + + if(!last) + search = 1; + else if(!active && (strcmp(last, ed.str) || last_own!=search_own || last_date!=search_date || last_page!=search_page)) { + search = 1; + if(strcmp(last, ed.str) || last_own!=search_own || last_date!=search_date) { + search_page = 0; + page_count = 0; + } + free(last); + last = NULL; + } else + search = 0; + + if(search && lasttime>=TIMEOUT) { + lasttime = 0; + last = mystrdup(ed.str); + last_own = search_own; + last_date = search_date; + last_page = search_page; + active = 1; + uri = malloc(strlen(last)*3+80+strlen(SERVER)+strlen(svf_user)); + if(search_own || svf_admin) + tmp = "&v=1"; + else + tmp = ""; + if(!search_own && !search_date && !*last) { + if(search_page) { + exp_res = GRID_X*GRID_Y; + sprintf(uri, "http://" SERVER "/powder/search.php?s=%d&n=%d%s&q=", (search_page-1)*GRID_X*GRID_Y+GRID_X*GRID_P, exp_res+1, tmp); + } else { + exp_res = GRID_X*GRID_P; + sprintf(uri, "http://" SERVER "/powder/search.php?s=%d&n=%d&t=%d%s&q=", 0, exp_res+1, ((GRID_Y-GRID_P)*YRES)/(GRID_Y*14)*GRID_X, tmp); + } + } else { + exp_res = GRID_X*GRID_Y; + sprintf(uri, "http://" SERVER "/powder/search.php?s=%d&n=%d%s&q=", search_page*GRID_X*GRID_Y, exp_res+1, tmp); + } + strcaturl(uri, last); + if(search_own) { + strcaturl(uri, " user:"); + strcaturl(uri, svf_user); + } + if(search_date) + strcaturl(uri, " sort:date"); + http = http_async_req_start(http, uri, NULL, 0, 1); + http_last_use = time(NULL); + free(uri); + } + + if(active && http_async_req_status(http)) { + http_last_use = time(NULL); + results = http_async_req_stop(http, &status, NULL); + view_own = last_own; + if(status == 200) + page_count = search_results(results, last_own||svf_admin); + is_p1 = (exp_res < GRID_X*GRID_Y); + free(results); + active = 0; + } + + if(http && !active && (time(NULL)>http_last_use+HTTP_TIMEOUT)) { + http_async_req_close(http); + http = NULL; + } + + for(i=0;i=x && mx=y && my 18) ? signs[i].y - 18 : signs[i].y + 4; +} + +void draw_icon(pixel *vid_buf, int x, int y, char ch, int flag) +{ + char t[2]; + t[0] = ch; + t[1] = 0; + if(flag) { + fillrect(vid_buf, x-1, y-1, 17, 17, 255, 255, 255, 255); + drawtext(vid_buf, x+3, y+2, t, 0, 0, 0, 255); + } else { + drawrect(vid_buf, x, y, 15, 15, 255, 255, 255, 255); + drawtext(vid_buf, x+3, y+2, t, 255, 255, 255, 255); + } +} + +void render_signs(pixel *vid_buf) +{ + int i, j, x, y, w, h, dx, dy; + for(i=0; i 18) ? -1 : 1; + for(j=0; j<4; j++) { + drawpixel(vid_buf, x, y, 192, 192, 192, 255); + x+=dx; + y+=dy; + } + } +} + +void add_sign_ui(pixel *vid_buf, int mx, int my) +{ + int i, w, h, x, y, nm=0, ju; + int x0=(XRES-192)/2,y0=(YRES-80)/2,b=1,bq; + ui_edit ed; + + // check if it is an existing sign + for(i=0; i=x && mx<=x+w && my>=y && my<=y+h) + break; + } + // else look for empty spot + if(i >= MAXSIGNS) { + nm = 1; + for(i=0; i= MAXSIGNS) + return; + + if(nm) { + signs[i].x = mx; + signs[i].y = my; + signs[i].ju = 1; + } + + while(!sdl_poll()) { + b = SDL_GetMouseState(&mx, &my); + if(!b) + break; + } + + ed.x = x0+25; + ed.y = y0+25; + ed.w = 158; + ed.nx = 1; + ed.def = "[message]"; + ed.focus = 1; + ed.hide = 0; + ed.cursor = strlen(signs[i].text); + strcpy(ed.str, signs[i].text); + ju = signs[i].ju; + + fillrect(vid_buf, -1, -1, XRES, YRES+60, 0, 0, 0, 192); + while(!sdl_poll()) { + bq = b; + b = SDL_GetMouseState(&mx, &my); + mx /= sdl_scale; + my /= sdl_scale; + + drawrect(vid_buf, x0, y0, 192, 80, 192, 192, 192, 255); + clearrect(vid_buf, x0, y0, 192, 80); + drawtext(vid_buf, x0+8, y0+8, nm ? "New sign:" : "Edit sign:", 255, 255, 255, 255); + drawtext(vid_buf, x0+12, y0+23, "\xA1", 32, 64, 128, 255); + drawtext(vid_buf, x0+12, y0+23, "\xA0", 255, 255, 255, 255); + drawrect(vid_buf, x0+8, y0+20, 176, 16, 192, 192, 192, 255); + ui_edit_draw(vid_buf, &ed); + drawtext(vid_buf, x0+8, y0+46, "Justify:", 255, 255, 255, 255); + draw_icon(vid_buf, x0+50, y0+42, 0x9D, ju == 0); + draw_icon(vid_buf, x0+68, y0+42, 0x9E, ju == 1); + draw_icon(vid_buf, x0+86, y0+42, 0x9F, ju == 2); + + if(!nm) { + drawtext(vid_buf, x0+138, y0+45, "\x86", 160, 48, 32, 255); + drawtext(vid_buf, x0+138, y0+45, "\x85", 255, 255, 255, 255); + drawtext(vid_buf, x0+152, y0+46, "Delete", 255, 255, 255, 255); + drawrect(vid_buf, x0+134, y0+42, 50, 15, 255, 255, 255, 255); + } + + drawtext(vid_buf, x0+5, y0+69, "OK", 255, 255, 255, 255); + drawrect(vid_buf, x0, y0+64, 192, 16, 192, 192, 192, 255); + + sdl_blit(0, 0, XRES, YRES+60, vid_buf, XRES); + + ui_edit_process(mx, my, b, &ed); + + if(b && !bq && mx>=x0+50 && mx<=x0+67 && my>=y0+42 && my<=y0+59) + ju = 0; + if(b && !bq && mx>=x0+68 && mx<=x0+85 && my>=y0+42 && my<=y0+59) + ju = 1; + if(b && !bq && mx>=x0+86 && mx<=x0+103 && my>=y0+42 && my<=y0+59) + ju = 2; + + if(b && !bq && mx>=x0+9 && mx=y0+22 && my=x0 && mx=y0+64 && my<=y0+80) + break; + + if(!nm && b && !bq && mx>=x0+134 && my>=y0+42 && mx<=x0+184 && my<=y0+59) { + signs[i].text[0] = 0; + return; + } + + if(sdl_key==SDLK_RETURN) + break; + if(sdl_key==SDLK_ESCAPE) { + if(!ed.focus) + return; + ed.focus = 0; + } + } + + strcpy(signs[i].text, ed.str); + signs[i].ju = ju; +} + +/*********************************************************** + * CONFIG FILE * + ***********************************************************/ + +char http_proxy[256] = ""; + +void save_string(FILE *f, char *str) +{ + int li = strlen(str); + unsigned char lb[2]; + lb[0] = li; + lb[1] = li >> 8; + fwrite(lb, 2, 1, f); + fwrite(str, li, 1, f); +} + +int load_string(FILE *f, char *str, int max) +{ + int li; + unsigned char lb[2]; + fread(lb, 2, 1, f); + li = lb[0] | (lb[1] << 8); + if(li > max) { + str[0] = 0; + return 1; + } + fread(str, li, 1, f); + str[li] = 0; + return 0; +} + +unsigned char last_major=0, last_minor=0, update_flag=0; + +void save_presets(int do_update) +{ + FILE *f=fopen("powder.def", "wb"); + unsigned char sig[4] = {0x4D, 0x6F, 0x46, 0x6F}; + unsigned char tmp = sdl_scale; + if(!f) + return; + fwrite(sig, 1, 4, f); + save_string(f, svf_user); + save_string(f, svf_pass); + fwrite(&tmp, 1, 1, f); + tmp = cmode; + fwrite(&tmp, 1, 1, f); + tmp = svf_admin; + fwrite(&tmp, 1, 1, f); + save_string(f, http_proxy); + tmp = SAVE_VERSION; + fwrite(&tmp, 1, 1, f); + tmp = MINOR_VERSION; + fwrite(&tmp, 1, 1, f); + tmp = do_update; + fwrite(&tmp, 1, 1, f); + fclose(f); +} + +void load_presets(void) +{ + FILE *f=fopen("powder.def", "rb"); + unsigned char sig[4], tmp; + if(!f) + return; + fread(sig, 1, 4, f); + if(sig[0]!=0x4D || sig[1]!=0x6F || sig[2]!=0x46 || sig[3]!=0x6F) + return; + if(load_string(f, svf_user, 63)) + goto fail; + if(load_string(f, svf_pass, 63)) + goto fail; + svf_login = !!svf_user[0]; + if(fread(&tmp, 1, 1, f) != 1) + goto fail; + sdl_scale = (tmp == 2) ? 2 : 1; + if(fread(&tmp, 1, 1, f) != 1) + goto fail; + cmode = tmp%4; + if(fread(&tmp, 1, 1, f) != 1) + goto fail; + svf_admin = tmp; + if(load_string(f, http_proxy, 255)) + goto fail; + if(fread(sig, 1, 3, f) != 3) + goto fail; + last_major = sig[0]; + last_minor = sig[1]; + update_flag = sig[2]; +fail: + fclose(f); +} + +void dim_copy(pixel *dst, pixel *src) +{ + int i,r,g,b; + for(i=0;i0) + r--; + if(g>0) + g--; + if(b>0) + b--; + dst[i] = PIXRGB(r,g,b); + } +} + +unsigned int fire_alpha[CELL*3][CELL*3]; +void prepare_alpha(void) +{ + int x,y,i,j; + float temp[CELL*3][CELL*3]; + memset(temp, 0, sizeof(temp)); + for(x=0; x=0 && j+y>=0 && i+x4 ? r-4 : 0; + fire_g[j][i] = g>4 ? g-4 : 0; + fire_b[j][i] = b>4 ? b-4 : 0; + } +} + +int zoom_en = 0; +int zoom_x=(XRES-ZSIZE)/2, zoom_y=(YRES-ZSIZE)/2; +int zoom_wx=0, zoom_wy=0; +void render_zoom(pixel *img) +{ + int x, y, i, j; + pixel pix; + drawrect(img, zoom_wx-2, zoom_wy-2, ZSIZE*ZFACTOR+2, ZSIZE*ZFACTOR+2, 192, 192, 192, 255); + drawrect(img, zoom_wx-1, zoom_wy-1, ZSIZE*ZFACTOR, ZSIZE*ZFACTOR, 0, 0, 0, 255); + clearrect(img, zoom_wx, zoom_wy, ZSIZE*ZFACTOR, ZSIZE*ZFACTOR); + for(j=0; jr*r || i*i+(j+1)*(j+1)>r*r)) { + xor_pixel(x+i, y+j, vid); + if(j) xor_pixel(x+i, y-j, vid); + if(i) xor_pixel(x-i, y+j, vid); + if(i&&j) xor_pixel(x-i, y-j, vid); + } + } else { + x = (x/CELL) * CELL; + y = (y/CELL) * CELL; + for(i=0; iSAVE_VERSION || (major==SAVE_VERSION && minor>MINOR_VERSION)) + old_version = 1; + free(ver_data); + } + http_ver_check = NULL; + } + do_check = (do_check+1) & 15; + } + + if(sdl_key=='q' || sdl_key==SDLK_ESCAPE) + break; + if((sdl_key=='l' || sdl_key=='k') && stamps[0].name[0]) { + if(load_mode) { + free(load_img); + free(load_data); + load_mode = 0; + load_data = NULL; + load_img = NULL; + } + if(it > 50) + it = 50; + if(sdl_key=='k' && stamps[1].name[0]) { + j = stamp_ui(vid_buf); + if(j>=0) + load_data = stamp_load(j, &load_size); + else + load_data = NULL; + } else + load_data = stamp_load(0, &load_size); + if(load_data) { + load_img = prerender_save(load_data, load_size, &load_w, &load_h); + if(load_img) + load_mode = 1; + else + free(load_data); + } + } + if(sdl_key=='s') { + if(it > 50) + it = 50; + save_mode = 1; + } + if(sdl_key==SDLK_SPACE) + sys_pause = !sys_pause; + if(sdl_key=='p') + dump_frame(vid_buf, XRES, YRES, XRES); + if(sdl_key=='c') { + set_cmode((cmode+1) % 4); + if(it > 50) + it = 50; + } +#ifdef INTERNAL + if(sdl_key=='v') + vs = !vs; + if(vs) + dump_frame(vid_buf, XRES, YRES, XRES); +#endif + + if(sdl_wheel) { + bs += sdl_wheel; + if(bs>6) + bs = 6; + if(bs<0) + bs = 0; + sdl_wheel = 0; + if(su >= PT_NUM) { + if(sl < PT_NUM) + su = sl; + if(sr < PT_NUM) + su = sr; + } + } + + bq = b; + b = SDL_GetMouseState(&x, &y); + + if(zoom_en && x>=sdl_scale*zoom_wx && y>=sdl_scale*zoom_wy + && xSAVE_VERSION || (last_major==SAVE_VERSION && last_minor>=MINOR_VERSION)) { + update_cleanup(); + error_ui(vid_buf, 0, "Update failed - try downloading a new version."); + } else { + if(update_finish()) + error_ui(vid_buf, 0, "Update failed - try downloading a new version."); + else + info_ui(vid_buf, "Update success", "You have successfully updated the Powder Toy!"); + } + update_flag = 0; + } + + if(b && !bq && x>=(512-19-old_ver_len)*sdl_scale && + x<=(512-14)*sdl_scale && y>=(YRES-22)*sdl_scale && y<=(YRES-9)*sdl_scale && old_version) { + tmp = malloc(64); + sprintf(tmp, "Your version: %d.%d, new version: %d.%d.", SAVE_VERSION, MINOR_VERSION, major, minor); + if(confirm_ui(vid_buf, "Do you want to update The Powder Toy?", tmp, "Update")) { + free(tmp); + tmp = download_ui(vid_buf, my_uri, &i); + if(tmp) { + save_presets(1); + if(update_start(tmp, i)) { + update_cleanup(); + save_presets(0); + error_ui(vid_buf, 0, "Update failed - try downloading a new version."); + } else + return 0; + } + } else + free(tmp); + } + + if(y>=sdl_scale*YRES && y=0 && c=22 && c<32)) { + db = c; + if(da < 51) + da ++; + } else { + if(da > 0) + da --; + } + } else if(y>=sdl_scale*(YRES+40)) { + if(x>=189*sdl_scale && x<=365*sdl_scale && svf_login && svf_open) { + db = svf_own ? 257 : 256; + if(da < 51) + da ++; + } else if(x>=367*sdl_scale && x<383*sdl_scale) { + db = 266; + if(da < 51) + da ++; + } else if(x>=37*sdl_scale && x<=187*sdl_scale && svf_login) { + db = 259; + if(svf_open && svf_own && x<=55*sdl_scale) + db = 258; + if(da < 51) + da ++; + } else if(x>=385*sdl_scale && x<=476*sdl_scale) { + db = svf_login ? 261 : 260; + if(svf_admin) + db = 268; + if(da < 51) + da ++; + } else if(x>=sdl_scale && x<=17*sdl_scale) { + db = 262; + if(da < 51) + da ++; + } else if(x>=494*sdl_scale && x<=509*sdl_scale) { + db = sys_pause ? 264 : 263; + if(da < 51) + da ++; + } else if(x>=476*sdl_scale && x<=491*sdl_scale) { + db = 267; + if(da < 51) + da ++; + } else if(x>=19*sdl_scale && x<=35*sdl_scale && svf_open) { + db = 265; + if(da < 51) + da ++; + } else if(da > 0) + da --; + } else + if(da > 0) + da --; + + if(!sdl_zoom_trig && zoom_en==1) + zoom_en = 0; + + if(sdl_key==Z_keysym && zoom_en==2) + zoom_en = 1; + + if(load_mode) { + load_x = CELL*((mx/sdl_scale-load_w/2+CELL/2)/CELL); + load_y = CELL*((my/sdl_scale-load_h/2+CELL/2)/CELL); + if(load_x+load_w>XRES) load_x=XRES-load_w; + if(load_y+load_h>YRES) load_y=YRES-load_h; + if(load_x<0) load_x=0; + if(load_y<0) load_y=0; + if(bq==1 && !b) { + parse_save(load_data, load_size, 0, load_x, load_y); + free(load_data); + free(load_img); + load_mode = 0; + } else if(bq==4 && !b) { + free(load_data); + free(load_img); + load_mode = 0; + } + } else if(save_mode==1) { + save_x = (mx/sdl_scale)/CELL; + save_y = (my/sdl_scale)/CELL; + if(save_x >= XRES/CELL) save_x = XRES/CELL-1; + if(save_y >= YRES/CELL) save_y = YRES/CELL-1; + save_w = 1; + save_h = 1; + if(b==1) + save_mode = 2; + else if(b==4) + save_mode = 0; + } else if(save_mode==2) { + save_w = (mx/sdl_scale+CELL/2)/CELL - save_x; + save_h = (my/sdl_scale+CELL/2)/CELL - save_y; + if(save_w>XRES/CELL) save_w = XRES/CELL; + if(save_h>YRES/CELL) save_h = YRES/CELL; + if(save_w<1) save_w = 1; + if(save_h<1) save_h = 1; + if(!b) { + stamp_save(save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL); + save_mode = 0; + } + } else if(sdl_zoom_trig && zoom_en<2) { + x /= sdl_scale; + y /= sdl_scale; + x -= ZSIZE/2; + y -= ZSIZE/2; + if(x<0) x=0; + if(y<0) y=0; + if(x>XRES-ZSIZE) x=XRES-ZSIZE; + if(y>YRES-ZSIZE) y=YRES-ZSIZE; + zoom_x = x; + zoom_y = y; + zoom_wx = (x 50) + it = 50; + x /= sdl_scale; + y /= sdl_scale; + if(y>=YRES && y=PT_NUM) { + tx = (x+512-XRES)/32; + c = 2*tx+ty; + } + if((c>=0 && c=22 && c<32)) { + if(b&1) { + sl = c; + su = c; + } else { + sr = c; + su = c; + } + } + lb = 0; + } + } else if(y>=YRES+40) { + if(!lb) { + if(x>=189 && x<=365 && svf_login && svf_open) + tag_list_ui(vid_buf); + if(x>=367 && x<=383 && !bq) { + memset(signs, 0, sizeof(signs)); + memset(pv, 0, sizeof(pv)); + memset(vx, 0, sizeof(vx)); + memset(vy, 0, sizeof(vy)); + memset(fvx, 0, sizeof(fvx)); + memset(fvy, 0, sizeof(fvy)); + memset(bmap, 0, sizeof(bmap)); + memset(emap, 0, sizeof(emap)); + memset(parts, 0, sizeof(particle)*NPART); + for(i=0; i=385 && x<=476) { + login_ui(vid_buf); + if(svf_login) + save_presets(0); + } + if(x>=37 && x<=187 && svf_login) { + if(!svf_open || !svf_own || x>51) { + if(save_name_ui(vid_buf)) + execute_save(vid_buf); + } else + execute_save(vid_buf); + while(!sdl_poll()) + if(!SDL_GetMouseState(&x, &y)) + break; + b = bq = 0; + } + if(x>=1 && x<=17) { + search_ui(vid_buf); + memset(fire_bg, 0, XRES*YRES*PIXELSIZE); + memset(fire_r, 0, sizeof(fire_r)); + memset(fire_g, 0, sizeof(fire_g)); + memset(fire_b, 0, sizeof(fire_b)); + } + if(x>=19 && x<=35 && svf_last && svf_open) + parse_save(svf_last, svf_lsize, 1, 0, 0); + if(x>=476 && x<=491 && !bq) { + if(b & SDL_BUTTON_LMASK) + set_cmode((cmode+1) % 4); + if(b & SDL_BUTTON_RMASK) + set_cmode((cmode+3) % 4); + save_presets(0); + } + if(x>=494 && x<=509 && !bq) + sys_pause = !sys_pause; + lb = 0; + } + } else { + c = (b&1) ? sl : sr; + su = c; + if(c==26) { + if(!bq) + add_sign_ui(vid_buf, x, y); + } else if(lb) { + if(lm == 1) { + xor_line(lx, ly, x, y, vid_buf); + if(c==27 && lx>=0 && ly>=0 && lx=XRES || ly>=YRES || bmap[ly/CELL][lx/CELL]!=4) + create_line(lx, ly, x, y, bs, c); + } else + create_box(lx, ly, x, y, c); + lm = 0; + } + lb = 0; + } + + if(load_mode) { + draw_image(vid_buf, load_img, load_x, load_y, load_w, load_h, 128); + xor_rect(vid_buf, load_x, load_y, load_w, load_h); + } + + if(save_mode) { + xor_rect(vid_buf, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL); + da = 51; + db = 269; + } + + if(zoom_en!=1 && !load_mode && !save_mode) + render_cursor(vid_buf, mx/sdl_scale, my/sdl_scale, su, bs); + + if(zoom_en) + render_zoom(vid_buf); + + if(da) + switch(db) { + case 22: + drawtext(vid_buf, 16, YRES-24, "Wall. Indestructible. Blocks everything. Conductive.", 255, 255, 255, da*5); + break; + case 23: + drawtext(vid_buf, 16, YRES-24, "E-Wall. Becomes transparent when electricity is connected.", 255, 255, 255, da*5); + break; + case 24: + drawtext(vid_buf, 16, YRES-24, "Detector. Generates electricity when a particle is inside.", 255, 255, 255, da*5); + break; + case 25: + drawtext(vid_buf, 16, YRES-24, "Streamline. Set start point of a streamline.", 255, 255, 255, da*5); + break; + case 26: + drawtext(vid_buf, 16, YRES-24, "Sign. Click on a sign to edit it or anywhere else to place a new one.", 255, 255, 255, da*5); + break; + case 27: + drawtext(vid_buf, 16, YRES-24, "Fan. Accelerates air. Use line tool to set direction and strength.", 255, 255, 255, da*5); + break; + case 28: + drawtext(vid_buf, 16, YRES-24, "Wall. Blocks most particles but lets liquids through. Conductive.", 255, 255, 255, da*5); + break; + case 29: + drawtext(vid_buf, 16, YRES-24, "Wall. Absorbs particles but lets air currents through.", 255, 255, 255, da*5); + break; + case 30: + drawtext(vid_buf, 16, YRES-24, "Erases walls.", 255, 255, 255, da*5); + break; + case 31: + drawtext(vid_buf, 16, YRES-24, "Wall. Indestructible. Blocks everything.", 255, 255, 255, da*5); + break; + case 256: + drawtext(vid_buf, 16, YRES-24, "Add simulation tags.", 255, 255, 255, da*5); + break; + case 257: + drawtext(vid_buf, 16, YRES-24, "Add and remove simulation tags.", 255, 255, 255, da*5); + break; + case 258: + drawtext(vid_buf, 16, YRES-24, "Save the simulation under the current name.", 255, 255, 255, da*5); + break; + case 259: + drawtext(vid_buf, 16, YRES-24, "Save the simulation under a new name.", 255, 255, 255, da*5); + break; + case 260: + drawtext(vid_buf, 16, YRES-24, "Sign into the Simulation Server.", 255, 255, 255, da*5); + break; + case 261: + drawtext(vid_buf, 16, YRES-24, "Sign into the Simulation Server under a new name.", 255, 255, 255, da*5); + break; + case 262: + drawtext(vid_buf, 16, YRES-24, "Find & open a simulation", 255, 255, 255, da*5); + break; + case 263: + drawtext(vid_buf, 16, YRES-24, "Pause the simulation", 255, 255, 255, da*5); + break; + case 264: + drawtext(vid_buf, 16, YRES-24, "Resume the simulation", 255, 255, 255, da*5); + break; + case 265: + drawtext(vid_buf, 16, YRES-24, "Reload the simulation", 255, 255, 255, da*5); + break; + case 266: + drawtext(vid_buf, 16, YRES-24, "Erase all particles and walls", 255, 255, 255, da*5); + break; + case 267: + drawtext(vid_buf, 16, YRES-24, "Change display mode", 255, 255, 255, da*5); + break; + case 268: + drawtext(vid_buf, 16, YRES-24, "Annuit C\245ptis", 255, 255, 255, da*5); + break; + case 269: + drawtext(vid_buf, 16, YRES-24, "Click-and-drag to specify a rectangle to copy (right click = cancel).", 255, 216, 32, da*5); + break; + default: + drawtext(vid_buf, 16, YRES-24, descs[db], 255, 255, 255, da*5); + } + if(itc) { + itc--; + drawtext(vid_buf, (XRES-textwidth(itc_msg))/2, ((YRES/2)-10), itc_msg, 255, 255, 255, itc>51?255:itc*5); + } + if(it) { + it--; + if(fbi_img) + draw_image(vid_buf, fbi_img, (XRES-FBI_W)/2, (YRES-FBI_H)/2+25, FBI_W, FBI_H, it>12?64:it*5); + drawtext(vid_buf, 16, 20, it_msg, 255, 255, 255, it>51?255:it*5); + } + + if(old_version) { + clearrect(vid_buf, 512-21-old_ver_len, YRES-24, old_ver_len+9, 17); + drawtext(vid_buf, 512-16-old_ver_len, YRES-19, old_ver_msg, 255, 216, 32, 255); + drawrect(vid_buf, 512-19-old_ver_len, YRES-22, old_ver_len+5, 13, 255, 216, 32, 255); + } + + sdl_blit(0, 0, XRES, YRES+60, vid_buf, XRES); + } + + http_done(); + return 0; +} diff --git a/powder.ico b/powder.ico new file mode 100644 index 0000000000000000000000000000000000000000..c931a98051e7b8235ca17d2ab15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=T{< z(Ga4ZX<5FdLL+2pA?Z zwi#Z$!?graRn(lcUyOr%zb19THFPgU)CibcL-6LSKmO$e*heC5k8yIf{bOo)lVY91 zk9Ls#8#2zjg-)9hJ_4pBfU8@y!WrEF%ijlb3;2u@Ngt?1)!y$=(03GhkD`ehRg(P> z8K>VyyDbPVfXXE~oG8{C|6DBA9M+MD-y;vKHZLQek163#t`3r@fAfNSQD7cL$O5r&eqN%pn z_4DPT3CyWKXb$5@gzr&0SDB`eWhL2mQ@{ZV+)G{yN$pdPh_zgl#5GfzvDF>_oSjdA zT8O}1Qd*U9B$?-tcPaU8A)mL%VA)r{apcU@5(Ljn);J@99dr?pIPKJ zo(!ExM4W?hE<_g~TxZUMOaFOEa!6q)ytXR|ca6DZ7)r*`WOHmO3Is;+eC`VPO?RmkHI*5$@N$Esrd=H+7fft!;YdE}9)H>p`9qPe{CYhVJ9;@o`MUg-_^dxS$GJ)y3Uf^QmA$uozn zy~x~wOzC8ZC&~8&L=n)!xl(k~w*;On6?9eMw>A2RZ~>9`P*D%(-%P<#yIE z?>b<`V8=cM@?>HBt?YSDwck~PD#7m#wG%z*NSWLP8_CkTZ#pM}q9UwvwR4gY+=Rx|)oCe(34oeg;c zL`MjA*z}yUewcr!6_r{FV}Wd)D=bqWv%{eM56iG;@bg+!=OvlY)_vZX)dCb|oC z{u}Y}6nH_35K2>_@OHqPT740|YhcVRCl=X|vfA)+(EpnKm-%4%b1a4b*Q(x0-Zc;z slAjh!mpI5%zclBc`XgC|Vs~b^>LdSLNT6!zAufk_438!7Uzfl?05?nn)c^nh literal 0 HcmV?d00001 diff --git a/update.c b/update.c new file mode 100644 index 000000000..9fdabd584 --- /dev/null +++ b/update.c @@ -0,0 +1,188 @@ +/** + * Powder Toy - Update helper + * + * Powder Toy is the legal property of Stanislaw Skowronek. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA + */ + +#include +#ifndef MACOSX +#include +#endif +#include + +#ifdef WIN32 +#include +int __cdecl _stricmp(const char*, const char*); +#else +#include +#include +#endif +#ifdef MACOSX +#include +#include +#include +#endif + +#include "update.h" + +static char *exe_name(void) +{ +#if defined WIN32 + char *name=malloc(64), max=64, res; + while((res = GetModuleFileName(NULL, name, max)) >= max) { +#elif defined MACOSX + char *fn=malloc(64),*name=malloc(PATH_MAX), max=64, res; + if(_NSGetExecutablePath(fn, &max) != 0) { + fn = realloc(fn, max); + _NSGetExecutablePath(fn, &max); + } + if(realpath(fn, name) == NULL) { + free(fn); + free(name); + return NULL; + } + res = 1; +#else + char fn[64], *name=malloc(64), max=64, res; + sprintf(fn, "/proc/self/exe"); + memset(name, 0, max); + while((res = readlink(fn, name, max)) >= max-1) { +#endif +#ifndef MACOSX + max *= 2; + name = realloc(name, max); + memset(name, 0, max); + } +#endif + if(res <= 0) { + free(name); + return NULL; + } + return name; +} + +int update_start(char *data, int len) +{ + char *self=exe_name(), *temp; +#ifdef WIN32 + char *p; +#endif + FILE *f; + int res = 1; + + if(!self) + return 1; + +#ifdef WIN32 + temp = malloc(strlen(self)+12); + strcpy(temp, self); + p = temp + strlen(temp) - 4; + if(_stricmp(p, ".exe")) + p += 4; + strcpy(p, "_update.exe"); + + if(!MoveFile(self, temp)) + goto fail; + + f = fopen(self, "wb"); + if(!f) + goto fail; + if(fwrite(data, 1, len, f) != len) { + fclose(f); + DeleteFile(self); + goto fail; + } + fclose(f); + + if((int)ShellExecute(NULL, "open", self, NULL, NULL, SW_SHOWNORMAL) <= 32) { + DeleteFile(self); + goto fail; + } + + return 0; +#else + temp = malloc(strlen(self)+8); + strcpy(temp, self); + strcat(temp, "-update"); + + f = fopen(temp, "w"); + if(!f) + goto fail; + if(fwrite(data, 1, len, f) != len) { + fclose(f); + unlink(temp); + goto fail; + } + fclose(f); + + if(chmod(temp, 0755)) { + unlink(temp); + goto fail; + } + + if(rename(temp, self)) { + unlink(temp); + goto fail; + } + + execl(self, "powder-update", NULL); +#endif + +fail: + free(temp); + free(self); + return res; +} + +int update_finish(void) +{ +#ifdef WIN32 + char *temp, *self=exe_name(), *p; + int timeout = 60, err; + + temp = malloc(strlen(self)+12); + strcpy(temp, self); + p = temp + strlen(temp) - 4; + if(_stricmp(p, ".exe")) + p += 4; + strcpy(p, "_update.exe"); + + while(!DeleteFile(temp)) { + err = GetLastError(); + if(err == ERROR_FILE_NOT_FOUND) { + // just as well, then + free(temp); + return 0; + } + Sleep(500); + timeout--; + if(timeout <= 0) { + free(temp); + return 1; + } + } + free(temp); +#endif + return 0; +} + +void update_cleanup(void) +{ +#ifdef WIN32 + update_finish(); +#endif +} diff --git a/update.h b/update.h new file mode 100644 index 000000000..7b4351842 --- /dev/null +++ b/update.h @@ -0,0 +1,8 @@ +#ifndef UPDATE_H +#define UPDATE_H + +int update_start(char *data, int len); +int update_finish(void); +void update_cleanup(void); + +#endif