TS_RA2_Mission_Editor_sourcecode_23.02.2023_1

TS_RA2_Mission_Editor_sourcecode_23.02.2023_1
This commit is contained in:
brbarnesEA 2024-03-05 11:56:45 -08:00
commit a547a31a37
377 changed files with 90136 additions and 0 deletions

71
.gitignore vendored Normal file
View file

@ -0,0 +1,71 @@
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
# MSVC
[Dd]ebug*/
[Rr]elease*/
build/
build_*/
*.vs
*.user
*.spec
*.ncb
*.sdf
*.suo
*.sln
*.vcxproj
*.filters
*.aps
# CMake
CMakeFiles/
CMakeCache.txt
CMakeUserPresets.json
*.dir
# Windows
thumbs.db
desktop.ini
*.log
# Misc
*.tmp
*.bak
*.idb
# FinalSun/FinalAlert specific
dist/
intermediate/
vcpkg_installed/
vcpkg_downloads/
[Tt]emplate/

3
3rdParty/xcc/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
.vs/
Debug/
Release/

674
3rdParty/xcc/COPYING vendored Normal file
View file

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. 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
them 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 prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. 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.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey 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;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If 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 convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU 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 that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
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.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
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.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
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
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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 3 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, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program 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, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU 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 Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

19
3rdParty/xcc/Library/StdAfx.cpp vendored Normal file
View file

@ -0,0 +1,19 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"

45
3rdParty/xcc/Library/StdAfx.h vendored Normal file
View file

@ -0,0 +1,45 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
// #define WIN32_LEAN_AND_MEAN
#include <array>
#include <boost/algorithm/string.hpp>
#include <cassert>
#include <climits>
#include <cstdint>
#include <list>
#include <memory>
#include <map>
#include <set>
#include <span>
#include <string>
#include <vartypes.h>
#include <vector>
#include <xcc/data_ref.h>
#include <xcc/find_ptr.h>
#ifndef XCC_MINIMAL_BUILD
#include <xcc/string_view.h>
#endif
using namespace std;
using boost::iequals;
using boost::to_lower_copy;
using boost::trim_copy;

19
3rdParty/xcc/XCC.props vendored Normal file
View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>..\misc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4018;4201;4267;4554;4806;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<LanguageStandard>stdcpplatest</LanguageStandard>
<PreprocessorDefinitions>_HAS_STD_BYTE=0;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalManifestDependencies>"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'"</AdditionalManifestDependencies>
<AdditionalDependencies>dsound.lib;gdiplus.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
</Project>

427
3rdParty/xcc/misc/blowfish.cpp vendored Normal file
View file

@ -0,0 +1,427 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include <blowfish.h>
#include <memory.h>
const Cblowfish::t_bf_p g_p =
{
0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
0x9216d5d9, 0x8979fb1b,
};
const Cblowfish::t_bf_s g_s =
{
0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6,
};
void Cblowfish::set_key(data_ref key)
{
memcpy(m_p, g_p, sizeof(t_bf_p));
memcpy(m_s, g_s, sizeof(t_bf_s));
int j = 0;
for (int i = 0; i < 18; i++)
{
int a = key[j++]; j %= key.size();
int b = key[j++]; j %= key.size();
int c = key[j++]; j %= key.size();
int d = key[j++]; j %= key.size();
m_p[i] ^= a << 24 | b << 16 | c << 8 | d;
}
uint32_t datal = 0;
uint32_t datar = 0;
for (int i = 0; i < 18; )
{
encipher(datal, datar);
m_p[i++] = datal;
m_p[i++] = datar;
}
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 256; )
{
encipher(datal, datar);
m_s[i][j++] = datal;
m_s[i][j++] = datar;
}
}
}
uint32_t Cblowfish::S(uint32_t x, int i) const
{
return m_s[i][(x >> ((3 - i) << 3)) & 0xff];
}
uint32_t Cblowfish::bf_f(uint32_t x) const
{
return ((S(x, 0) + S(x, 1)) ^ S(x, 2)) + S(x, 3);
}
void Cblowfish::ROUND(uint32_t& a, uint32_t b, int n) const
{
a ^= bf_f(b) ^ m_p[n];
}
void Cblowfish::encipher(uint32_t& xl, uint32_t& xr) const
{
uint32_t Xl = xl;
uint32_t Xr = xr;
Xl ^= m_p[0];
ROUND (Xr, Xl, 1); ROUND (Xl, Xr, 2);
ROUND (Xr, Xl, 3); ROUND (Xl, Xr, 4);
ROUND (Xr, Xl, 5); ROUND (Xl, Xr, 6);
ROUND (Xr, Xl, 7); ROUND (Xl, Xr, 8);
ROUND (Xr, Xl, 9); ROUND (Xl, Xr, 10);
ROUND (Xr, Xl, 11); ROUND (Xl, Xr, 12);
ROUND (Xr, Xl, 13); ROUND (Xl, Xr, 14);
ROUND (Xr, Xl, 15); ROUND (Xl, Xr, 16);
Xr ^= m_p[17];
xr = Xl;
xl = Xr;
}
void Cblowfish::decipher(uint32_t& xl, uint32_t& xr) const
{
uint32_t Xl = xl;
uint32_t Xr = xr;
Xl ^= m_p[17];
ROUND (Xr, Xl, 16); ROUND (Xl, Xr, 15);
ROUND (Xr, Xl, 14); ROUND (Xl, Xr, 13);
ROUND (Xr, Xl, 12); ROUND (Xl, Xr, 11);
ROUND (Xr, Xl, 10); ROUND (Xl, Xr, 9);
ROUND (Xr, Xl, 8); ROUND (Xl, Xr, 7);
ROUND (Xr, Xl, 6); ROUND (Xl, Xr, 5);
ROUND (Xr, Xl, 4); ROUND (Xl, Xr, 3);
ROUND (Xr, Xl, 2); ROUND (Xl, Xr, 1);
Xr ^= m_p[0];
xl = Xr;
xr = Xl;
}
static uint32_t reverse(uint32_t v)
{
_asm
{
mov eax, v
xchg al, ah
rol eax, 16
xchg al, ah
mov v, eax
}
return v;
}
void Cblowfish::encipher(const void* s, void* d, int size) const
{
const uint32_t* r = reinterpret_cast<const uint32_t*>(s);
uint32_t* w = reinterpret_cast<uint32_t*>(d);
size >>= 3;
while (size--)
{
uint32_t a = reverse(*r++);
uint32_t b = reverse(*r++);
encipher(a, b);
*w++ = reverse(a);
*w++ = reverse(b);
}
}
void Cblowfish::decipher(const void* s, void* d, int size) const
{
const uint32_t* r = reinterpret_cast<const uint32_t*>(s);
uint32_t* w = reinterpret_cast<uint32_t*>(d);
size >>= 3;
while (size--)
{
uint32_t a = reverse(*r++);
uint32_t b = reverse(*r++);
decipher(a, b);
*w++ = reverse(a);
*w++ = reverse(b);
}
}

41
3rdParty/xcc/misc/blowfish.h vendored Normal file
View file

@ -0,0 +1,41 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <vartypes.h>
class Cblowfish
{
public:
using t_bf_p = uint32_t[18];
using t_bf_s = uint32_t[4][256];
void set_key(data_ref);
void encipher(const void* s, void* d, int size) const;
void decipher(const void* s, void* d, int size) const;
private:
void encipher(uint32_t& xl, uint32_t& xr) const;
void decipher(uint32_t& xl, uint32_t& xr) const;
uint32_t S(uint32_t x, int i) const;
uint32_t bf_f(uint32_t x) const;
void ROUND(uint32_t& a, uint32_t b, int n) const;
t_bf_p m_p;
t_bf_s m_s;
};

520
3rdParty/xcc/misc/cc_file.cpp vendored Normal file
View file

@ -0,0 +1,520 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "cc_file.h"
#ifndef XCC_MINIMAL_BUILD
#include "aud_file.h"
#include "avi_file.h"
#include "big_file.h"
#include "bin_file.h"
#include "bink_file.h"
#include "bmp_file.h"
#include "csf_file.h"
#include "cps_file.h"
#include "dds_file.h"
#include "fnt_file.h"
#include "hva_file.h"
#include "id_log.h"
#include "jpeg_file.h"
#include "map_td_ini_reader.h"
#include "map_ra_ini_reader.h"
#include "map_ts_ini_reader.h"
#include "mix_file.h"
#include "mix_rg_file.h"
#include "mp3_file.h"
#include "null_ini_reader.h"
#include "ogg_file.h"
#include "pak_file.h"
#include "pal_file.h"
#include "pcx_file.h"
#include "png_file.h"
#include "pkt_ts_ini_reader.h"
#include "shp_dune2_file.h"
#include "shp_file.h"
#include "shp_ts_file.h"
#include "sound_ts_ini_reader.h"
#include "st_file.h"
#include "string_conversion.h"
#include "text_file.h"
#include "tga_file.h"
#include "theme_ts_ini_reader.h"
#include "tmp_file.h"
#include "tmp_ra_file.h"
#include "tmp_ts_file.h"
#include "virtual_tfile.h"
#include "voc_file.h"
#include "vqa_file.h"
#include "vqp_file.h"
#include "vxl_file.h"
#include "w3d_file.h"
#include "wav_file.h"
#include "wsa_dune2_file.h"
#include "wsa_file.h"
#include "xcc_dirs.h"
#include "xcc_file.h"
#include "xcc_lmd_file.h"
#include "xif_file.h"
#else
#include "mix_file.h"
#include "xcc_dirs.h"
#endif
const char* ft_name[] =
{
"aud",
"avi",
"big",
"bin",
"bink",
"bmp",
"clipboard",
"csf",
"cps",
"csv",
"dds",
"dir",
"drive",
"fnt",
"html",
"hva",
"ini",
"jpeg",
"jpeg (single)",
"map (dune2)",
"map (td)",
"map (ra)",
"map (ts)",
"map (ts) preview",
"map (ra2)",
"mix",
"mix (rg)",
"mng",
"mp3",
"mrf",
"ogg",
"pak",
"pal",
"pal (jasc)",
"pcx (single)",
"pcx",
"png (single)",
"png",
"pkt (ts)",
"riff",
"rules ini (ts)",
"rules ini (ra2)",
"shp (dune2)",
"shp",
"shp (ts)",
"sound ini (ts)",
"sound ini (ra2)",
"string table",
"text",
"tga",
"tga (single)",
"theme ini (ts)",
"theme ini (ra2)",
"tmp",
"tmp (ra)",
"tmp (ts)",
"voc",
"vpl",
"vqa",
"vqp",
"vxl",
"w3d",
"wav",
"pcm wav",
"ima adpcm wav",
"wsa (dune2)",
"wsa",
"xcc lmd",
"xcc unknown",
"xif",
"zip",
"unknown"
};
Ccc_file::Ccc_file(bool read_on_open) :
m_read_on_open(read_on_open)
{
}
#define test_fail(res) { int v = res; if (v) { close(); return v; }}
#ifndef NO_MIX_SUPPORT
int Ccc_file::open(unsigned int id, Cmix_file& mix_f)
{
if (mix_f.get_index(id) == -1)
return -1;
m_f = mix_f.m_f;
m_offset = mix_f.m_offset + mix_f.get_offset(id);
m_size = mix_f.get_size(id);
m_p = 0;
m_is_open = true;
if (m_read_on_open || mix_f.data())
m_data = mix_f.get_vdata(id);
test_fail(post_open())
return 0;
}
int Ccc_file::open(const string& name, Cmix_file& mix_f)
{
return open(Cmix_file::get_id(mix_f.get_game(), name), mix_f);
}
#endif
int Ccc_file::open(const string& name)
{
close();
assert(!is_open());
#ifdef NO_MIX_SUPPORT
test_fail(m_f.open_read(name));
#else
test_fail(m_f.open_read(xcc_dirs::find_file(name)));
#endif
m_offset = 0;
m_size = m_f.size();
m_p = 0;
m_is_open = true;
m_data = m_f.get_mm();
if (m_read_on_open)
m_f.close();
#ifndef NO_FT_SUPPORT
Cfname fname = to_lower_copy(name);
if (fname.get_fext() == ".mmx")
{
fname.set_ext(".map");
mix_database::add_name(game_ra2, fname.get_fname(), "-");
fname.set_ext(".pkt");
mix_database::add_name(game_ra2, fname.get_fname(), "-");
}
#endif
test_fail(post_open())
return 0;
}
const Cwin_handle& Ccc_file::h()
{
assert(is_open());
return m_f.h();
}
int Ccc_file::open(const Cwin_handle& h)
{
assert(!is_open());
m_f.open(h);
m_offset = 0;
m_size = m_f.size();
m_p = 0;
m_is_open = true;
m_data = m_f.get_mm();
if (m_read_on_open)
m_f.close();
test_fail(post_open())
return 0;
}
void Ccc_file::load(const Cvirtual_binary& d, int size)
{
m_data = d;
m_offset = 0;
m_is_open = true;
m_p = 0;
m_size = size == -1 ? d.size() : size;
post_open();
}
void Ccc_file::load(const Ccc_file& f)
{
load(f.vdata());
}
int Ccc_file::read()
{
seek(0);
Cvirtual_binary d;
if (int error = read(d.write_start(get_size()), get_size()))
return error;
m_data = d;
return 0;
}
int Ccc_file::read(void* data, int size)
{
if (get_p() < 0 || get_p() + size > get_size())
return 1;
if (get_data())
{
memcpy(data, m_data.data() + m_p, size);
skip(size);
return 0;
}
assert(is_open());
m_f.seek(m_offset + m_p);
int res = m_f.read(data, size);
if (!res)
skip(size);
return res;
}
int Ccc_file::extract(const string& name)
{
assert(is_open());
if (data())
return vdata().save(name);
seek(0);
Cfile32 f;
if (int error = f.open_write(name))
return error;
Cvirtual_binary data;
for (int size = get_size(); size; )
{
int cb_write = min(size, 1 << 20);
if (int error = read(data.write_start(cb_write), cb_write))
return error;
if (int error = f.write(data.data(), cb_write))
return error;
size -= cb_write;
}
return 0;
}
void Ccc_file::close()
{
m_data.clear();
m_f.close();
m_is_open = false;
}
#ifndef NO_MIX_SUPPORT
#ifndef NO_FT_SUPPORT
t_file_type Ccc_file::get_file_type(bool fast)
{
Cvirtual_binary data;
int size;
if (m_data.data())
{
data = m_data;
size = m_size;
}
else
{
size = min<int>(m_size, 64 << 10);
seek(0);
if (read(data.write_start(size), size))
return ft_unknown;
seek(0);
}
Caud_file aud_f;
Cbin_file bin_f;
Cbink_file bink_f;
Cbig_file big_f;
Cbmp_file bmp_f;
Ccsf_file csf_f;
Ccps_file cps_f;
Cdds_file dds_f;
Cfnt_file fnt_f;
Chva_file hva_f;
Cmix_file mix_f;
Cmix_rg_file mix_rg_f;
Cmp3_file mp3_f;
Cjpeg_file jpeg_f;
Cogg_file ogg_f;
Cpak_file pak_f;
Cpal_file pal_f;
Cpcx_file pcx_f;
Cpng_file png_f;
Criff_file riff_f;
Cshp_dune2_file shp_dune2_f;
Cshp_file shp_f;
Cshp_ts_file shp_ts_f;
Cst_file st_f;
Ctext_file text_f;
Ctga_file tga_f;
Ctmp_file tmp_f;
Ctmp_ra_file tmp_ra_f;
Ctmp_ts_file tmp_ts_f;
Cvoc_file voc_f;
Cvqa_file vqa_f;
Cvqp_file vqp_f;
Cvxl_file vxl_f;
Cw3d_file w3d_f;
Cwsa_dune2_file wsa_dune2_f;
Cwsa_file wsa_f;
Cxcc_file xcc_f;
Cxif_file xif_f;
if (aud_f.load(data, m_size), aud_f.is_valid())
return ft_aud;
if (big_f.load(data, m_size), big_f.is_valid())
return ft_big;
if (bin_f.load(data, m_size), bin_f.is_valid())
return ft_bin;
if (bink_f.load(data, m_size), bink_f.is_valid())
return ft_bink;
if (bmp_f.load(data, m_size), bmp_f.is_valid())
return ft_bmp;
if (csf_f.load(data, m_size), csf_f.is_valid())
return ft_csf;
if (cps_f.load(data, m_size), cps_f.is_valid())
return ft_cps;
if (dds_f.load(data, m_size), dds_f.is_valid())
return ft_dds;
if (fnt_f.load(data, m_size), fnt_f.is_valid())
return ft_fnt;
if (hva_f.load(data, m_size), hva_f.is_valid())
return ft_hva;
if (mp3_f.load(data, m_size), mp3_f.is_valid())
return ft_mp3;
if (jpeg_f.load(data, m_size), jpeg_f.is_valid())
return ft_jpeg;
if (ogg_f.load(data, m_size), ogg_f.is_valid())
return ft_ogg;
if (pal_f.load(data, m_size), pal_f.is_valid())
return ft_pal;
if (pcx_f.load(data, m_size), pcx_f.is_valid())
return ft_pcx;
if (png_f.load(data, m_size), png_f.is_valid())
return ft_png;
if (riff_f.load(data, m_size), riff_f.is_valid())
{
Cavi_file avi_f;
Cwav_file wav_f;
avi_f.load(data, m_size);
wav_f.load(data, m_size);
if (avi_f.is_valid())
return ft_avi;
if (wav_f.is_valid())
return ft_wav;
return ft_riff;
}
if (shp_dune2_f.load(data, m_size), shp_dune2_f.is_valid())
return ft_shp_dune2;
if (shp_f.load(data, m_size), shp_f.is_valid())
return ft_shp;
if (shp_ts_f.load(data, m_size), shp_ts_f.is_valid())
return ft_shp_ts;
if (st_f.load(data, m_size), st_f.is_valid())
return ft_st;
if (tga_f.load(data, m_size), tga_f.is_valid())
return ft_tga;
if (tmp_f.load(data, m_size), tmp_f.is_valid())
return ft_tmp;
if (tmp_ra_f.load(data, m_size), tmp_ra_f.is_valid())
return ft_tmp_ra;
if (tmp_ts_f.load(data, m_size), tmp_ts_f.is_valid())
return ft_tmp_ts;
if (voc_f.load(data, m_size), voc_f.is_valid())
return ft_voc;
if (vqa_f.load(data, m_size), vqa_f.is_valid())
return ft_vqa;
if (vqp_f.load(data, m_size), vqp_f.is_valid())
return ft_vqp;
if (vxl_f.load(data, m_size), vxl_f.is_valid())
return ft_vxl;
if (wsa_dune2_f.load(data, m_size), wsa_dune2_f.is_valid())
return ft_wsa_dune2;
if (wsa_f.load(data, m_size), wsa_f.is_valid())
return ft_wsa;
if (xcc_f.load(data, m_size), xcc_f.is_valid())
{
switch (xcc_f.get_ft())
{
case xcc_ft_lmd:
return ft_xcc_lmd;
}
return ft_xcc_unknown;
}
if (xif_f.load(data, m_size), xif_f.is_valid())
return ft_xif;
if (mix_f.load(data, m_size), mix_f.is_valid())
return ft_mix;
if (mix_rg_f.load(data, m_size), mix_rg_f.is_valid())
return ft_mix_rg;
if (pak_f.load(data, m_size), pak_f.is_valid())
return ft_pak;
if (w3d_f.load(data, m_size), w3d_f.is_valid())
return ft_w3d;
if (text_f.load(data, m_size), text_f.is_valid())
{
if (fast)
return ft_text;
Cvirtual_tfile tf;
tf.load_data(data);
Cnull_ini_reader ir;
int error = 0;
while (!error && !tf.eof())
{
error = ir.process_line(tf.read_line());
if (tf.eof())
error = 0;
}
if (!error && ir.is_valid())
{
if (!m_read_on_open && m_size != size)
{
size = m_size;
if (read(data.write_start(size), size))
return ft_unknown;
seek(0);
}
{
Cmap_td_ini_reader ir;
if (!ir.process(data) && ir.is_valid())
return ft_map_td;
}
{
Cmap_ra_ini_reader ir;
if (!ir.process(data) && ir.is_valid())
return ft_map_ra;
}
{
Cmap_ts_ini_reader ir;
ir.fast(true);
if (!ir.process(data) && ir.is_valid())
return ft_map_ts;
}
{
Cpkt_ts_ini_reader ir;
ir.fast(true);
if (!ir.process(data) && ir.is_valid())
return ft_pkt_ts;
}
{
Csound_ts_ini_reader ir;
ir.fast(true);
if (!ir.process(data) && ir.is_valid())
return ft_sound_ini_ts;
}
{
Ctheme_ts_ini_reader ir;
if (!ir.process(data) && ir.is_valid())
return ft_theme_ini_ts;
}
return ft_ini;
}
return ft_text;
}
return ft_unknown;
}
#endif
#endif

195
3rdParty/xcc/misc/cc_file.h vendored Normal file
View file

@ -0,0 +1,195 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "file32.h"
#include <virtual_binary.h>
enum t_file_type
{
ft_aud,
ft_avi,
ft_big,
ft_bin,
ft_bink,
ft_bmp,
ft_clipboard,
ft_csf,
ft_cps,
ft_csv,
ft_dds,
ft_dir,
ft_drive,
ft_fnt,
ft_html,
ft_hva,
ft_ini,
ft_jpeg,
ft_jpeg_single,
ft_map_dune2,
ft_map_td,
ft_map_ra,
ft_map_ts,
ft_map_ts_preview,
ft_map_ra2,
ft_mix,
ft_mix_rg,
ft_mng,
ft_mp3,
ft_mrf,
ft_ogg,
ft_pak,
ft_pal,
ft_pal_jasc,
ft_pcx_single,
ft_pcx,
ft_png_single,
ft_png,
ft_pkt_ts,
ft_riff,
ft_rules_ini_ts,
ft_rules_ini_ra2,
ft_shp_dune2,
ft_shp,
ft_shp_ts,
ft_sound_ini_ts,
ft_sound_ini_ra2,
ft_st,
ft_text,
ft_tga,
ft_tga_single,
ft_theme_ini_ts,
ft_theme_ini_ra2,
ft_tmp,
ft_tmp_ra,
ft_tmp_ts,
ft_voc,
ft_vpl,
ft_vqa,
ft_vqp,
ft_vxl,
ft_w3d,
ft_wav,
ft_wav_ima_adpcm,
ft_wav_pcm,
ft_wsa_dune2,
ft_wsa,
ft_xcc_lmd,
ft_xcc_unknown,
ft_xif,
ft_zip,
ft_unknown,
ft_count
};
const char* ft_name[];
class Cmix_file;
class Ccc_file
{
public:
const Cwin_handle& h();
int open(const Cwin_handle& h);
int open(unsigned int id, Cmix_file& mix_f);
int open(const string& name, Cmix_file& mix_f);
int open(const string& name);
void load(const Cvirtual_binary& d, int size = -1);
void load(const Ccc_file& f);
t_file_type get_file_type(bool fast = true);
int read();
int read(void* data, int size);
int extract(const string& name);
virtual void close();
Ccc_file(bool read_on_open);
const byte* begin() const
{
return m_data.begin();
}
const byte* end() const
{
return m_data.end();
}
const byte* data() const
{
return m_data.data();
}
long long size() const
{
return m_size;
}
const byte* get_data() const
{
return m_data.data();
}
const byte* data_end() const
{
return m_data.data_end();
}
Cvirtual_binary vdata() const
{
return m_data;
}
int get_p() const
{
return m_p;
}
long long get_size() const
{
return m_size;
}
bool is_open() const
{
return m_is_open;
}
void seek(int p)
{
m_p = p;
}
void skip(int p)
{
m_p += p;
}
virtual int post_open()
{
return 0;
}
protected:
int m_offset;
private:
Cvirtual_binary m_data;
Cfile32 m_f;
bool m_is_open = false;
int m_p;
const bool m_read_on_open;
long long m_size;
};

31
3rdParty/xcc/misc/cc_file_sh.h vendored Normal file
View file

@ -0,0 +1,31 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <cc_file_small.h>
template <class T>
class Ccc_file_sh : public Ccc_file_small
{
public:
const T& header() const
{
return *reinterpret_cast<const T*>(data());
}
};

29
3rdParty/xcc/misc/cc_file_small.h vendored Normal file
View file

@ -0,0 +1,29 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <cc_file.h>
class Ccc_file_small : public Ccc_file
{
public:
Ccc_file_small() : Ccc_file(true)
{
}
};

40
3rdParty/xcc/misc/cc_structures.cpp vendored Normal file
View file

@ -0,0 +1,40 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "cc_structures.h"
const char* game_name[] =
{
"Tiberian Dawn",
"Red Alert",
"Tiberian Sun",
"Dune 2",
"Dune 2000",
"Red Alert 2",
"Red Alert 2 Yuri's Revenge",
"Renegade",
"Generals",
"Generals Zero Hour",
"Emperor Battle for Dune",
"Nox",
"Battle for Middle Earth",
"Battle for Middle Earth 2",
"Tiberium Wars",
"Tiberian Sun Firestorm",
};

566
3rdParty/xcc/misc/cc_structures.h vendored Normal file
View file

@ -0,0 +1,566 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "palet.h"
enum t_game
{
game_td,
game_ra,
game_ts,
game_dune2,
game_dune2000,
game_ra2,
game_ra2_yr,
game_rg,
game_gr,
game_gr_zh,
game_ebfd,
game_nox,
game_bfme,
game_bfme2,
game_tw,
game_ts_fs,
game_unknown
};
const char* game_name[];
inline __int32 reverse(__int32 v)
{
_asm
{
mov eax, v
xchg al, ah
rol eax, 16
xchg al, ah
mov v, eax
}
return v;
}
#pragma pack(push, 1)
struct t_aud_header
{
unsigned __int16 samplerate;
unsigned __int32 size_in;
unsigned __int32 size_out;
__int8 flags;
__int8 compression;
};
struct t_aud_chunk_header
{
unsigned __int16 size_in;
unsigned __int16 size_out;
__int32 id;
};
const __int32 aud_chunk_id = 0x0000deaf;
struct t_audio_idx_header
{
__int32 id;
__int32 two;
__int32 c_sounds;
};
struct t_audio_idx_entry
{
char fname[16];
__int32 offset;
__int32 size;
__int32 samplerate;
__int32 flags;
__int32 chunk_size;
};
const __int32 audio_idx_id = *(__int32*)"GABA";
struct t_big_header
{
__int32 id;
__int32 size;
__int32 mc_files;
__int32 mcb_header;
int c_files() const
{
return reverse(mc_files);
}
int cb_header() const
{
return reverse(mcb_header);
}
};
struct t_big_index_entry
{
__int32 offset;
__int32 size;
};
const int big_id = 'FGIB';
const int big4_id = '4GIB';
struct t_cps_header
{
unsigned __int16 size;
__int16 unknown;
unsigned __int16 image_size;
__int16 zero;
__int16 palet_size;
};
struct t_csf_header
{
__int32 id;
__int32 flags1;
__int32 count1;
__int32 count2;
__int32 zero;
__int32 flags2;
};
const __int32 csf_file_id = 'CSF ';
const __int32 csf_label_id = 'LBL ';
const __int32 csf_string_id = 'STR ';
const __int32 csf_string_w_id = 'STRW';
struct t_fnt_header
{
unsigned __int16 size;
__int16 id1;
__int16 id2;
__int16 id3;
unsigned __int16 cx_ofs;
unsigned __int16 image_ofs;
unsigned __int16 cy_ofs;
__int16 id4;
__int8 zero;
unsigned __int8 c_chars;
__int8 cy;
__int8 cmax_x;
};
struct t_hva_header
{
char id[16];
__int32 c_frames;
__int32 c_sections;
};
using t_hva_transform_matrix = float[3][4];
struct t_jpeg_header
{
__int8 unknown[6];
__int8 id[4];
};
const char jpeg_id[] = "JFIF";
union t_mix_header
{
struct
{
__int16 c_files;
__int32 size;
};
__int32 flags;
};
const int mix_checksum = 0x00010000;
const int mix_encrypted = 0x00020000;
const int cb_mix_key = 56;
const int cb_mix_key_source = 80;
const int cb_mix_checksum = 20;
struct t_mix_index_entry
{
t_mix_index_entry() = default;
t_mix_index_entry(unsigned int id_, int offset_, int size_)
{
id = id_;
offset = offset_;
size = size_;
}
unsigned __int32 id;
__int32 offset;
__int32 size;
};
struct t_mix_rg_header
{
__int32 id;
__int32 index_offset;
__int32 tailer_offset;
__int32 zero;
};
struct t_mix_rg_index_entry
{
__int32 id;
__int32 offset;
__int32 size;
};
const int mix_rg_id = '1XIM';
struct t_iso_map_pack_entry
{
unsigned __int16 x;
unsigned __int16 y;
__int16 tile;
unsigned __int8 zero1;
unsigned __int8 zero2;
unsigned __int8 sub_tile;
unsigned __int8 z;
unsigned __int8 zero3;
};
struct t_ogg_header
{
__int8 id[4];
};
const char ogg_id[] = "OggS";
struct t_pack_section_header
{
unsigned __int16 size_in;
unsigned __int16 size_out;
};
struct t_pcx_header
{
__int8 manufacturer;
__int8 version;
__int8 encoding;
__int8 cbits_pixel;
__int16 xmin;
__int16 ymin;
__int16 xmax;
__int16 ymax;
__int16 cx_inch;
__int16 cy_inch;
__int8 colorpap[16][3];
__int8 reserved;
__int8 c_planes;
__int16 cb_line;
__int8 filler[60];
};
struct t_png_header
{
__int8 id[8];
};
const char png_id[] = "\x89PNG\r\n\x1A\n";
struct t_shp_dune2_header
{
__int16 c_images;
};
struct t_shp_dune2_image_header
{
__int16 compression;
unsigned __int8 cy;
unsigned __int16 cx;
unsigned __int8 cy2;
unsigned __int16 size_in;
unsigned __int16 size_out;
};
struct t_shp_header
{
__int16 c_images;
__int16 unknown1;
__int16 unknown2;
__int16 cx;
__int16 cy;
__int32 unknown3;
};
struct t_shp_ts_header
{
__int16 zero;
__int16 cx;
__int16 cy;
__int16 c_images;
};
struct t_shp_ts_image_header
{
__int16 x;
__int16 y;
__int16 cx;
__int16 cy;
__int32 compression;
__int32 unknown;
__int32 zero;
__int32 offset;
};
struct t_tga_header
{
byte id_size;
byte map_t;
byte image_t;
unsigned __int16 map_first;
unsigned __int16 map_size;
byte map_entry_size;
unsigned __int16 x;
unsigned __int16 y;
unsigned __int16 cx;
unsigned __int16 cy;
byte cb_pixel;
byte alpha:4;
byte horizontal:1;
byte vertical:1;
};
struct t_tmp_header
{
__int16 cx;
__int16 cy;
__int16 c_tiles;
__int16 zero1;
__int32 size;
__int32 image_offset;
__int32 zero2;
__int32 id;
__int32 index2;
__int32 index1;
};
struct t_tmp_ra_header
{
__int16 cx;
__int16 cy;
__int16 c_tiles;
__int16 zero1;
__int16 cblocks_x;
__int16 cblocks_y;
__int32 size;
__int32 image_offset;
__int32 zero2;
__int32 unknown1;
__int32 index2;
__int32 unknown2;
__int32 index1;
};
struct t_tmp_ts_header
{
__int32 cblocks_x;
__int32 cblocks_y;
__int32 cx;
__int32 cy;
};
struct t_tmp_image_header
{
__int32 x;
__int32 y;
__int32 extra_ofs;
__int32 z_ofs;
__int32 extra_z_ofs;
__int32 x_extra;
__int32 y_extra;
__int32 cx_extra;
__int32 cy_extra;
unsigned int has_extra_data: 1;
unsigned int has_z_data: 1;
unsigned int has_damaged_data: 1;
__int8 height;
__int8 terrain_type;
__int8 ramp_type;
unsigned __int8 radar_red_left;
unsigned __int8 radar_green_left;
unsigned __int8 radar_blue_left;
unsigned __int8 radar_red_right;
unsigned __int8 radar_green_right;
unsigned __int8 radar_blue_right;
__int8 pad[3];
};
struct t_voc_header
{
char id[20];
__int16 offset;
__int32 version;
};
struct t_voc_sound_data_header
{
unsigned __int8 samplerate;
__int8 compression;
};
const char voc_id[] = "Creative Voice File\x1a";
struct t_vqa_chunk_header
{
__int32 id;
__int32 size;
};
struct t_vqa_header
{
t_vqa_chunk_header file_header;
// 'FORM'
__int64 id;
// 'WVQAVQHD'
__int32 startpos;
__int16 version;
__int16 video_flags;
__int16 c_frames;
__int16 cx;
__int16 cy;
__int8 cx_block;
__int8 cy_block;
__int16 unknown3;
__int16 c_colors;
__int16 cb_max_cbp_chunk;
__int32 unknown4;
__int16 unknown5;
unsigned __int16 samplerate;
__int8 c_channels;
__int8 cbits_sample;
__int8 unknown6[14];
};
const __int32 vqa_c_mask = 0xff000000;
const __int32 vqa_t_mask = 0x00ffffff;
const __int32 vqa_file_id = *(__int32*)"FORM";
const __int64 vqa_form_id = {*(__int64*)"WVQAVQHD"};
const __int32 vqa_cbf_id = *(__int32*)"CBF\0";
const __int32 vqa_cbp_id = *(__int32*)"CBP\0";
const __int32 vqa_cpl_id = *(__int32*)"CPL\0";
const __int32 vqa_finf_id = *(__int32*)"FINF";
const __int32 vqa_sn2j_id = *(__int32*)"SN2J";
const __int32 vqa_snd_id = *(__int32*)"SND\0";
const __int32 vqa_vpt_id = *(__int32*)"VPT\0";
const __int32 vqa_vpr_id = *(__int32*)"VPR\0";
const __int32 vqa_vqfl_id = *(__int32*)"VQFL";
const __int32 vqa_vqfr_id = *(__int32*)"VQFR";
struct t_vqp_header
{
unsigned __int32 c_tables;
};
struct t_vxl_header
{
char id[16];
__int32 one;
unsigned __int32 c_section_headers;
unsigned __int32 c_section_tailers;
unsigned __int32 size;
__int16 unknown;
t_palet palet;
};
struct t_vxl_section_header
{
char id[16];
__int32 section_i;
__int32 one;
__int32 zero;
};
struct t_vxl_section_tailer
{
__int32 span_start_ofs;
__int32 span_end_ofs;
__int32 span_data_ofs;
float scale;
float transform[3][4];
float x_min_scale;
float y_min_scale;
float z_min_scale;
float x_max_scale;
float y_max_scale;
float z_max_scale;
unsigned __int8 cx;
unsigned __int8 cy;
unsigned __int8 cz;
__int8 unknown;
};
const char vxl_id[] = "Voxel Animation";
struct t_w3d_header
{
__int32 id;
__int32 m_size;
bool container() const
{
return m_size & 0x80000000;
}
int size() const
{
return m_size & ~0x80000000;
}
};
struct t_wsa_dune2_header
{
__int16 c_frames;
__int16 cx;
__int16 cy;
__int16 delta;
};
struct t_wsa_header
{
__int16 c_frames;
__int16 x;
__int16 y;
__int16 cx;
__int16 cy;
__int32 delta;
};
struct t_xcc_header
{
char id[32];
__int32 size;
__int32 type;
__int32 version;
};
const char xcc_id[] = "XCC by Olaf van der Spek\x1a\x04\x17\x27\x10\x19\x80";
struct t_xcc_lmd_header
{
__int32 game;
__int32 c_fnames;
};
#pragma pack(pop)

28
3rdParty/xcc/misc/crc.h vendored Normal file
View file

@ -0,0 +1,28 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <boost/crc.hpp>
inline int compute_crc(const void* d, int cb_d)
{
boost::crc_32_type crc;
crc.process_bytes(d, cb_d);
return crc();
}

72
3rdParty/xcc/misc/ddpf_conversion.cpp vendored Normal file
View file

@ -0,0 +1,72 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "ddpf_conversion.h"
static int get_shift(unsigned int v)
{
if (!v)
return 0;
int r = 0;
while (~v & 1)
{
r++;
v >>= 1;
}
return r;
}
static int get_size(unsigned int v)
{
int r = 0;
while (v)
{
if (v & 1)
r++;
v >>= 1;
}
return r;
}
void Cddpf_conversion::set_pf(const DDPIXELFORMAT& pf)
{
a_shift = get_shift(pf.dwRGBAlphaBitMask);
r_shift = get_shift(pf.dwRBitMask);
g_shift = get_shift(pf.dwGBitMask);
b_shift = get_shift(pf.dwBBitMask);
a_size = get_size(pf.dwRGBAlphaBitMask);
r_size = get_size(pf.dwRBitMask);
g_size = get_size(pf.dwGBitMask);
b_size = get_size(pf.dwBBitMask);
}
int Cddpf_conversion::get_color(int a, int r, int g, int b)
{
return a >> (8 - a_size) << a_shift | r >> (8 - r_size) << r_shift | g >> (8 - g_size) << g_shift | b >> (8 - b_size) << b_shift;
}
int Cddpf_conversion::get_color(int r, int g, int b)
{
return get_color(0, r, g, b);
}
int Cddpf_conversion::get_color(int v)
{
return get_color(v >> 24, v >> 16 & 0xff, v >> 8 & 0xff, v & 0xff);
}

33
3rdParty/xcc/misc/ddpf_conversion.h vendored Normal file
View file

@ -0,0 +1,33 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <ddraw.h>
class Cddpf_conversion
{
public:
int get_color(int a, int r, int g, int b);
int get_color(int r, int g, int b);
int get_color(int v);
void set_pf(const DDPIXELFORMAT& pf);
private:
int a_shift, r_shift, g_shift, b_shift;
int a_size, r_size, g_size, b_size;
};

153
3rdParty/xcc/misc/file32.cpp vendored Normal file
View file

@ -0,0 +1,153 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "file32.h"
int Cfile32::open(const Cwin_handle& h)
{
m_h = h;
m_p = 0;
return !is_open();
}
int Cfile32::open(const string& name, int access)
{
return access & GENERIC_WRITE ? open(name, access, CREATE_ALWAYS, 0) : open(name, access, OPEN_EXISTING, FILE_SHARE_READ);
}
int Cfile32::open(const string& name, int access, int creation, int share)
{
m_h = Cwin_handle(CreateFileA(name.c_str(), access, share, NULL, creation, FILE_ATTRIBUTE_NORMAL, NULL));
m_p = 0;
return !is_open();
}
FILETIME Cfile32::get_creation_time() const
{
assert(is_open());
FILETIME time;
int r = GetFileTime(h(), &time, NULL, NULL);
assert(r);
return time;
}
FILETIME Cfile32::get_last_access_time() const
{
assert(is_open());
FILETIME time;
int r = GetFileTime(h(), NULL, &time, NULL);
assert(r);
return time;
}
FILETIME Cfile32::get_last_write_time() const
{
assert(is_open());
FILETIME time;
int r = GetFileTime(h(), NULL, NULL, &time);
assert(r);
return time;
}
int Cfile32::open_read(const string& name)
{
return open(name, GENERIC_READ, OPEN_EXISTING, FILE_SHARE_READ);
}
int Cfile32::open_edit(const string& name)
{
return open(name, GENERIC_READ | GENERIC_WRITE, OPEN_ALWAYS, 0);
}
int Cfile32::open_write(const string& name)
{
return open(name, GENERIC_WRITE, CREATE_ALWAYS, 0);
}
long long Cfile32::size() const
{
assert(is_open());
LARGE_INTEGER v;
return GetFileSizeEx(h(), &v) ? v.QuadPart : -1;
}
int Cfile32::read(void* data, int size)
{
assert(is_open());
if (SetFilePointer(h(), m_p, 0, FILE_BEGIN) == -1)
return 1;
DWORD cb_read;
if (!ReadFile(h(), data, size, &cb_read, 0) || cb_read != size)
return 1;
m_p += size;
return 0;
}
int Cfile32::write(const void* data, int size)
{
assert(is_open());
if (SetFilePointer(h(), m_p, 0, FILE_BEGIN) == -1)
return 1;
DWORD cb_write;
if (!WriteFile(h(), data, size, &cb_write, 0) || cb_write != size)
return 1;
m_p += size;
return 0;
}
int Cfile32::write(data_ref v)
{
return write(v.data(), v.size());
};
int Cfile32::set_eof()
{
assert(is_open());
if (SetFilePointer(h(), m_p, 0, FILE_BEGIN) == -1)
return 1;
return !SetEndOfFile(h());
}
void Cfile32::close()
{
m_h.clear();
}
Cvirtual_binary Cfile32::get_mm()
{
if (!size())
return Cvirtual_binary();
Cwin_handle mh(CreateFileMapping(h(), NULL, PAGE_READONLY, 0, 0, NULL));
void* d = mh ? MapViewOfFile(mh, FILE_MAP_READ, 0, 0, 0) : NULL;
return d ? Cvirtual_binary(d, size(), std::shared_ptr<void>(d, UnmapViewOfFile)) : Cvirtual_binary();
}
Cvirtual_binary file32_read(const string& name)
{
Cfile32 f;
return f.open_read(name) ? Cvirtual_binary() : f.get_mm();
}
int file32_write(const string& name, const void* s, int cb_s)
{
Cfile32 f;
if (int error = f.open_write(name))
return error;
return f.write(s, cb_s);
}

83
3rdParty/xcc/misc/file32.h vendored Normal file
View file

@ -0,0 +1,83 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
#include <vartypes.h>
#include <virtual_binary.h>
#include "win_handle.h"
using namespace std;
class Cfile32
{
public:
Cvirtual_binary get_mm();
int open(const Cwin_handle& h);
int open(const string& name, int access);
int open(const string& name, int access, int creation, int share);
int open_read(const string& name);
int open_edit(const string& name);
int open_write(const string& name);
long long size() const;
FILETIME get_creation_time() const;
FILETIME get_last_access_time() const;
FILETIME get_last_write_time() const;
int read(void* data, int size);
int write(const void* data, int size);
int write(data_ref);
int set_eof();
void close();
bool eof() const
{
return m_p >= size();
}
const Cwin_handle& h() const
{
return m_h;
}
bool is_open() const
{
return h();
}
int get_p() const
{
return m_p;
}
void seek(int p)
{
m_p = p;
}
void skip(int p)
{
m_p += p;
}
private:
Cwin_handle m_h;
int m_p;
};
Cvirtual_binary file32_read(const string& name);
int file32_write(const string& name, const void* s, int cb_s);

217
3rdParty/xcc/misc/fname.cpp vendored Normal file
View file

@ -0,0 +1,217 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "fname.h"
Cfname::Cfname(const string& s)
{
*this = string_view(s);
}
string Cfname::get_fname() const
{
return title + ext;
}
string Cfname::get_ftitle() const
{
return title;
}
string Cfname::get_fext() const
{
return ext;
}
string Cfname::get_path() const
{
return path;
}
string Cfname::get_all() const
{
return path + title + ext;
}
/*
void Cfname::expand()
{
char t[MAX_PATH];
_fullpath(t, get_all().c_str(), MAX_PATH);
Cfname(<string>(t));
}
*/
Cfname GetModuleFileName(HMODULE hModule)
{
char s[MAX_PATH];
if (GetModuleFileNameA(hModule, s, MAX_PATH))
return Cfname(s);
return {};
}
string get_temp_path()
{
char temp_dir[MAX_PATH];
return GetTempPathA(MAX_PATH, temp_dir) ? temp_dir : ".\\";
}
string get_temp_fname(string path)
{
char temp_fname[MAX_PATH];
return GetTempFileNameA(path.c_str(), "XCC", 0, temp_fname) ? temp_fname : "";
}
string get_temp_fname()
{
return get_temp_fname(get_temp_path());
}
void Cfname::set_title(string_view s)
{
title = s;
}
void Cfname::set_ext(string_view s)
{
ext = s;
}
void Cfname::use_default_ext(string_view s)
{
if (ext == "")
ext = s;
}
void Cfname::set_path(string_view s)
{
path = s;
if (!path.empty() && path[path.length() - 1] != '\\')
path += '\\';
}
void Cfname::use_default_path(string_view s)
{
if (path.empty())
set_path(s);
}
void Cfname::make_path()
{
if ((title + ext).empty())
return;
path += title + ext + '\\';
title = ext = "";
}
bool Cfname::exists() const
{
HANDLE h;
WIN32_FIND_DATAA d;
h = FindFirstFileA(get_all().c_str(), &d);
if (h == INVALID_HANDLE_VALUE)
return false;
FindClose(h);
return true;
}
const Cfname& Cfname::operator=(string_view s)
{
long p1 = s.rfind('\\');
long p2 = s.rfind('.');
char t[MAX_PATH];
if (p1 != string::npos)
{
//copy last \ also
t[s.copy(t, p1 + 1)] = 0;
path = t;
}
t[s.copy(t, p2 - p1 - 1, p1 + 1)] = 0;
title = t;
if (p2 != s.npos && p1 < p2)
{
t[s.copy(t, s.npos, p2)] = 0;
ext = t;
}
return *this;
}
string operator+(const string& a, const Cfname& b)
{
return a + static_cast<string>(b);
}
int create_dir(const string& dir)
{
return !CreateDirectoryA(dir.c_str(), NULL);
}
void create_deep_dir(string dir, const string& name)
{
int a = 0;
int b;
while ((b = name.find_first_of("/\\", a)) != string::npos)
{
dir += '/' + name.substr(a, b - a);
create_dir(dir);
a = b + 1;
}
}
int copy_file(string s, string d)
{
return !CopyFileA(s.c_str(), d.c_str(), false);
}
int delete_file(string fname)
{
return !DeleteFileA(fname.c_str());
}
int move_file(string s, string d)
{
return !MoveFileA(s.c_str(), d.c_str());
}
bool fname_filter(const string& fname, const string& filter)
{
size_t i;
for (i = 0; i < filter.size(); i++)
{
char c = filter[i];
if (c == '*')
{
if (filter.find('*', i + 1) == string::npos)
{
int j = fname.length() - filter.length() + 1;
return j < 0 ? false : fname_filter(fname.substr(i + j), filter.substr(i + 1));
}
// for (int j = 0; j < min(fname.length(), filter.length()) - i; j++)
for (size_t j = 0; j < fname.size(); j++)
{
if (fname_filter(fname.substr(i + j), filter.substr(i + 1)))
return true;
}
return false;
}
if (c != '?' && c != fname[i])
return false;
}
return fname.length() == i;
}

66
3rdParty/xcc/misc/fname.h vendored Normal file
View file

@ -0,0 +1,66 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
#include <windows.h>
using namespace std;
class Cfname
{
private:
string path;
string title;
string ext;
public:
const Cfname& operator=(string_view);
bool exists() const;
void make_path();
void use_default_ext(string_view);
void use_default_path(string_view);
void set_ext(string_view);
void set_path(string_view);
void set_title(string_view);
void expand();
string get_all() const;
string get_path() const;
string get_fname() const;
string get_ftitle() const;
string get_fext() const;
Cfname() = default;
Cfname(const string&);
operator string() const
{
return get_all();
}
};
Cfname GetModuleFileName(HMODULE hModule = 0);
bool fname_filter(const string& fname, const string& filter);
int create_dir(const string& dir);
void create_deep_dir(string dir, const string& name);
int delete_file(string fname);
int copy_file(string s, string d);
int move_file(string s, string d);
string get_temp_fname(string path);
string get_temp_path();
string get_temp_fname();
string operator+(const string& a, const Cfname& b);

115
3rdParty/xcc/misc/hva_file.cpp vendored Normal file
View file

@ -0,0 +1,115 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "hva_file.h"
#include <fstream>
#include "multi_line.h"
#include "virtual_tfile.h"
bool Chva_file::is_valid() const
{
const t_hva_header& h = header();
int size = get_size();
return !(sizeof(t_hva_header) > size
|| !h.c_frames
|| !h.c_sections
|| sizeof(t_hva_header) + (48 * h.c_frames + 16) * h.c_sections != size);
}
int Chva_file::extract_as_csv(const string& name) const
{
ofstream f(name.c_str());
const int c_frames = get_c_frames();
const int c_sections = get_c_sections();
f << "Count frames;" << c_frames << endl
<< "Count sections;" << c_sections << endl
<< endl;
for (int i = 0; i < c_sections; i++)
f << get_section_id(i) << ";;;;;";
for (int j = 0; j < c_frames; j++)
{
f << endl;
for (int y = 0; y < 3; y++)
{
for (int i = 0; i < c_sections; i++)
{
for (int x = 0; x < 4; x++)
{
f << get_transform_matrix(i, j)[x + 4 * y] << ';';
}
f << ';';
}
f << endl;
}
}
return f.fail();
}
Cvirtual_binary hva_file_write(const byte* s, int cb_s)
{
Cvirtual_binary d;
const char sep = ';';
Cvirtual_tfile f;
f.load_data(Cvirtual_binary(s, cb_s));
Cmulti_line l;
l = f.read_line();
l.get_next_line(sep);
int c_frames = atoi(l.get_next_line(sep).c_str());
l = f.read_line();
l.get_next_line(sep);
int c_sections = atoi(l.get_next_line(sep).c_str());
f.read_line();
byte* w = d.write_start(64 << 10);
t_hva_header& header = *reinterpret_cast<t_hva_header*>(w);
strcpy(header.id, "NONE");
header.c_frames = c_frames;
header.c_sections = c_sections;
w += sizeof(t_hva_header);
l = f.read_line();
for (int i = 0; i < c_sections; i++)
{
strcpy(reinterpret_cast<char*>(w), l.get_next_line(sep).c_str());
w += 16;
l.get_next_line(sep);
l.get_next_line(sep);
l.get_next_line(sep);
l.get_next_line(sep);
}
float* transform_matrix = reinterpret_cast<float*>(w);
for (int j = 0; j < c_frames; j++)
{
for (int y = 0; y < 3; y++)
{
l = f.read_line();
for (int i = 0; i < c_sections; i++)
{
for (int x = 0; x < 4; x++)
{
transform_matrix[12 * (c_frames * i + j) + x + 4 * y] = atof(l.get_next_line(sep).c_str());
}
l.get_next_line(sep);
}
}
f.read_line();
}
w += 4 * 12 * c_frames * c_sections;
d.set_size(w - d.data());
return d;
}

51
3rdParty/xcc/misc/hva_file.h vendored Normal file
View file

@ -0,0 +1,51 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <cc_file_sh.h>
#include <cc_structures.h>
class Chva_file : public Ccc_file_sh<t_hva_header>
{
public:
int extract_as_csv(const string& name) const;
bool is_valid() const;
int get_c_frames() const
{
return header().c_frames;
}
int get_c_sections() const
{
return header().c_sections;
}
const char* get_section_id(int i) const
{
return reinterpret_cast<const char*>(data() + sizeof(t_hva_header) + 16 * i);
}
const float* get_transform_matrix(int i, int j) const
{
return reinterpret_cast<const float*>(data() + sizeof(t_hva_header) + 16 * get_c_sections() + (get_c_frames() * i + j) * sizeof(t_hva_transform_matrix));
}
};
Cvirtual_binary hva_file_write(const byte* s, int cb_s);

137
3rdParty/xcc/misc/id_log.cpp vendored Normal file
View file

@ -0,0 +1,137 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include <id_log.h>
#include <fstream>
#include <mix_file.h>
#include <string_conversion.h>
#include <xcc_dirs.h>
struct t_idinfo
{
string name;
string description;
};
using t_id_list = map<int, t_idinfo>;
t_id_list td_list, ra_list, ts_list, dune2_list, ra2_list;
static t_id_list& get_list(t_game game)
{
switch (game)
{
case game_ra:
return ra_list;
case game_ts:
return ts_list;
case game_dune2:
return dune2_list;
case game_ra2:
return ra2_list;
}
return td_list;
}
static void read_list(t_game game, const char*& s)
{
t_id_list& d = get_list(game);
int count = *reinterpret_cast<const int*>(s);
s += 4;
t_idinfo idinfo;
while (count--)
{
idinfo.name = s;
s += idinfo.name.length() + 1;
idinfo.description = s;
s += idinfo.description.length() + 1;
d[Cmix_file::get_id(game, idinfo.name)] = idinfo;
}
}
int mix_database::load()
{
if (!td_list.empty() || !ra_list.empty() || !ts_list.empty())
return 0;
Cvirtual_binary f;
if (f.load(xcc_dirs::get_data_dir() + "global mix database.dat") || f.size() < 16)
return 1;
const char* data = reinterpret_cast<const char*>(f.data());
read_list(game_td, data);
read_list(game_ra, data);
read_list(game_ts, data);
read_list(game_ra2, data);
if (0)
{
ofstream log_f("c:\\log.txt");
for (auto& i : ts_list)
log_f << i.second.name << '\t' << i.second.description << endl;
}
return 0;
char name[12] = "scg00ea.bin";
const char char1[] = "bgjm";
const char char2[] = "ew";
const char char3[] = "abc";
for (int i = 0; i < 2; i++)
{
if (i)
strcpy(name + 8, "ini");
for (int j = 0; j < 4; j++)
{
name[2] = char1[j];
for (int k = 0; k < 100; k++)
{
memcpy(name + 3, nwzl(2, k).c_str(), 2);
for (int l = 0; l < 2; l++)
{
name[5] = char2[l];
for (int m = 0; m < 3; m++)
{
name[6] = char3[m];
mix_database::add_name(game_td, name, "");
mix_database::add_name(game_ra, name, "");
mix_database::add_name(game_ts, name, "");
}
}
}
}
}
return 0;
}
void mix_database::add_name(t_game game, const string& name, const string& description)
{
t_idinfo idinfo;
idinfo.name = name;
idinfo.description = description;
get_list(game)[Cmix_file::get_id(game, name)] = idinfo;
}
string mix_database::get_name(t_game game, int id)
{
auto i = find_ptr(get_list(game), id);
return i ? i->name : "";
}
string mix_database::get_description(t_game game, int id)
{
auto i = find_ptr(get_list(game), id);
return i ? i->description : "";
}

30
3rdParty/xcc/misc/id_log.h vendored Normal file
View file

@ -0,0 +1,30 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <cc_structures.h>
#include <string>
namespace mix_database
{
void add_name(t_game, const std::string& name, const std::string& description);
std::string get_name(t_game, int id);
std::string get_description(t_game, int id);
int load();
};

52
3rdParty/xcc/misc/image_file.h vendored Normal file
View file

@ -0,0 +1,52 @@
/*
XCC Utilities and Library
Copyright (C) 2001 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "cc_structures.h"
#include "palet.h"
#include "video_file.h"
#include "virtual_file.h"
#include "virtual_image.h"
template <class T>
class Cimage_file : public Cvideo_file<T>
{
public:
virtual void decode(void*) const = 0;
#ifndef XCC_MINIMAL_BUILD
virtual Cvirtual_image vimage() const
{
Cvirtual_binary image;
decode(image.write_start(this->cb_image()));
return Cvirtual_image(image, this->cx(), this->cy(), this->cb_pixel(), this->palet());
}
#endif
int cf() const override
{
return 1;
}
};
#ifndef XCC_MINIMAL_BUILD
int image_file_write(Cvirtual_file&, t_file_type, const byte* image, const t_palet_entry*, int cx, int cy);
Cvirtual_file image_file_write(t_file_type, const byte* image, const t_palet_entry*, int cx, int cy);
int image_file_write(const string& name, t_file_type, const byte* image, const t_palet_entry*, int cx, int cy);
#endif

439
3rdParty/xcc/misc/mix_decode.cpp vendored Normal file
View file

@ -0,0 +1,439 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include <memory>
#include <mix_decode.h>
const static char* pubkey_str = "AihRvNoIbTn85FZRYNZRcT+i6KpU+maCsEqr3Q5q+LDB5tH7Tz2qQ38V";
const static char char2num[] =
{
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};
using word = unsigned short;
using bignum = uint32_t[64];
static struct
{
bignum key1;
bignum key2;
uint32_t len;
} pubkey;
static bignum glob1;
static uint32_t glob1_bitlen;
static uint32_t glob1_len_x2;
static uint32_t glob2[130];
static uint32_t glob1_hi[4];
static uint32_t glob1_hi_inv[4];
static uint32_t glob1_hi_bitlen;
static uint32_t glob1_hi_inv_lo;
static uint32_t glob1_hi_inv_hi;
static void init_bignum(bignum n, uint32_t val, uint32_t len)
{
memset(n, 0, len * 4);
n[0] = val;
}
static void move_key_to_big(bignum n, const char* key, uint32_t klen, uint32_t blen)
{
uint32_t sign = key[0] & 0x80 ? 0xff : 0;
int i = blen * 4;
for (; i > klen; i--)
((char *)n)[i - 1] = sign;
for (; i > 0; i--)
((char *)n)[i - 1] = key[klen - i];
}
static void key_to_bignum(bignum n, char *key, uint32_t len)
{
uint32_t keylen;
int i;
if (key[0] != 2)
return;
key++;
if (key[0] & 0x80)
{
keylen = 0;
for (i = 0; i < (key[0] & 0x7f); i++) keylen = (keylen << 8) | key[i+1];
key += (key[0] & 0x7f) + 1;
}
else
{
keylen = key[0];
key++;
}
if (keylen <= len * 4)
move_key_to_big(n, key, keylen, len);
}
static uint32_t len_bignum(bignum n, uint32_t len)
{
int i = len - 1;
while (i >= 0 && n[i] == 0)
i--;
return i + 1;
}
static uint32_t bitlen_bignum(bignum n, uint32_t len)
{
uint32_t ddlen = len_bignum(n, len);
if (ddlen == 0)
return 0;
uint32_t bitlen = ddlen * 32;
uint32_t mask = 0x80000000;
while ((mask & n[ddlen - 1]) == 0)
{
mask >>= 1;
bitlen--;
}
return bitlen;
}
static void init_pubkey()
{
init_bignum(pubkey.key2, 0x10001, 64);
char keytmp[256];
uint32_t i2 = 0;
for (uint32_t i = 0; i < strlen(pubkey_str);)
{
uint32_t tmp = char2num[pubkey_str[i++]];
tmp <<= 6; tmp |= char2num[pubkey_str[i++]];
tmp <<= 6; tmp |= char2num[pubkey_str[i++]];
tmp <<= 6; tmp |= char2num[pubkey_str[i++]];
keytmp[i2++] = (tmp >> 16) & 0xff;
keytmp[i2++] = (tmp >> 8) & 0xff;
keytmp[i2++] = tmp & 0xff;
}
key_to_bignum(pubkey.key1, keytmp, 64);
pubkey.len = bitlen_bignum(pubkey.key1, 64) - 1;
}
static uint32_t len_predata()
{
uint32_t a = (pubkey.len - 1) / 8;
return (55 / a + 1) * (a + 1);
}
static int cmp_bignum(bignum n1, bignum n2, uint32_t len)
{
n1 += len - 1;
n2 += len - 1;
while (len > 0)
{
if (*n1 < *n2) return -1;
if (*n1 > *n2) return 1;
n1--;
n2--;
len--;
}
return 0;
}
static void mov_bignum(bignum dest, bignum src, uint32_t len)
{
memmove(dest, src, len * 4);
}
static void shr_bignum(bignum n, uint32_t bits, long int len)
{
uint32_t i;
if (uint32_t i2 = bits / 32)
{
for (i = 0; i < len - i2; i++)
n[i] = n[i + i2];
for (; i < len; i++)
n[i] = 0;
bits %= 32;
}
if (!bits)
return;
for (i = 0; i < len - 1; i++)
n[i] = (n[i] >> bits) | (n[i + 1] << (32 - bits));
n[i] >>= bits;
}
static void shl_bignum(bignum n, uint32_t bits, uint32_t len)
{
uint32_t i;
if (uint32_t i2 = bits / 32)
{
for (i = len - 1; i > i2; i--)
n[i] = n[i - i2];
for (; i > 0; i--)
n[i] = 0;
bits %= 32;
}
if (!bits)
return;
for (i = len - 1; i > 0; i--)
n[i] = (n[i] << bits) | (n[i - 1] >> (32 - bits));
n[0] <<= bits;
}
static uint32_t sub_bignum(bignum dest, bignum src1, bignum src2, uint32_t carry, uint32_t len)
{
len *= 2;
while (--len != -1)
{
uint32_t i1 = *(word *)src1;
uint32_t i2 = *(word *)src2;
*(word *)dest = i1 - i2 - carry;
src1 = (uint32_t *)(((word *)src1) + 1);
src2 = (uint32_t *)(((word *)src2) + 1);
dest = (uint32_t *)(((word *)dest) + 1);
carry = ((i1 - i2 - carry) & 0x10000) ? 1 : 0;
}
return carry;
}
static void inv_bignum(bignum n1, bignum n2, uint32_t len)
{
bignum n_tmp;
init_bignum(n_tmp, 0, len);
init_bignum(n1, 0, len);
int n2_bitlen = bitlen_bignum(n2, len);
uint32_t bit = ((uint32_t)1) << (n2_bitlen % 32);
n1 += ((n2_bitlen + 32) / 32) - 1;
uint32_t n2_bytelen = ((n2_bitlen - 1) / 32) * 4;
n_tmp[n2_bytelen / 4] |= ((uint32_t)1) << ((n2_bitlen - 1) & 0x1f);
while (n2_bitlen > 0)
{
n2_bitlen--;
shl_bignum(n_tmp, 1, len);
if (cmp_bignum(n_tmp, n2, len) != -1)
{
sub_bignum(n_tmp, n_tmp, n2, 0, len);
*n1 |= bit;
}
bit >>= 1;
if (bit == 0)
{
n1--;
bit = 0x80000000;
}
}
init_bignum(n_tmp, 0, len);
}
static void inc_bignum(bignum n, uint32_t len)
{
while ((++*n == 0) && (--len > 0))
n++;
}
static void init_two_dw(bignum n, uint32_t len)
{
mov_bignum(glob1, n, len);
glob1_bitlen = bitlen_bignum(glob1, len);
glob1_len_x2 = (glob1_bitlen + 15) / 16;
mov_bignum(glob1_hi, glob1 + len_bignum(glob1, len) - 2, 2);
glob1_hi_bitlen = bitlen_bignum(glob1_hi, 2) - 32;
shr_bignum(glob1_hi, glob1_hi_bitlen, 2);
inv_bignum(glob1_hi_inv, glob1_hi, 2);
shr_bignum(glob1_hi_inv, 1, 2);
glob1_hi_bitlen = (glob1_hi_bitlen + 15) % 16 + 1;
inc_bignum(glob1_hi_inv, 2);
if (bitlen_bignum(glob1_hi_inv, 2) > 32)
{
shr_bignum(glob1_hi_inv, 1, 2);
glob1_hi_bitlen--;
}
glob1_hi_inv_lo = *(word *)glob1_hi_inv;
glob1_hi_inv_hi = *(((word *)glob1_hi_inv) + 1);
}
static void mul_bignum_word(bignum n1, bignum n2, uint32_t mul, uint32_t len)
{
uint32_t tmp = 0;
for (uint32_t i = 0; i < len; i++)
{
tmp = mul * (*(word *)n2) + *(word *)n1 + tmp;
*(word *)n1 = tmp;
n1 = (uint32_t *)(((word *)n1) + 1);
n2 = (uint32_t *)(((word *)n2) + 1);
tmp >>= 16;
}
*(word *)n1 += tmp;
}
static void mul_bignum(bignum dest, bignum src1, bignum src2, uint32_t len)
{
init_bignum(dest, 0, len * 2);
for (uint32_t i = 0; i < len * 2; i++)
{
mul_bignum_word(dest, src1, *(word *)src2, len * 2);
src2 = (uint32_t *)(((word *)src2) + 1);
dest = (uint32_t *)(((word *)dest) + 1);
}
}
static void not_bignum(bignum n, uint32_t len)
{
for (uint32_t i = 0; i < len; i++)
*(n++) = ~*n;
}
static void neg_bignum(bignum n, uint32_t len)
{
not_bignum(n, len);
inc_bignum(n, len);
}
static uint32_t get_mulword(bignum n)
{
word* wn = (word *)n;
uint32_t i = (((((((((*(wn - 1) ^ 0xffff) & 0xffff) * glob1_hi_inv_lo + 0x10000) >> 1)
+ (((*(wn-2) ^ 0xffff) * glob1_hi_inv_hi + glob1_hi_inv_hi) >> 1) + 1)
>> 16) + ((((*(wn-1) ^ 0xffff) & 0xffff) * glob1_hi_inv_hi) >> 1) +
(((*wn ^ 0xffff) * glob1_hi_inv_lo) >> 1) + 1) >> 14) + glob1_hi_inv_hi
* (*wn ^ 0xffff) * 2) >> glob1_hi_bitlen;
if (i > 0xffff)
i = 0xffff;
return i & 0xffff;
}
static void dec_bignum(bignum n, uint32_t len)
{
while ((--*n == 0xffffffff) && (--len > 0))
n++;
}
static void calc_a_bignum(bignum n1, bignum n2, bignum n3, uint32_t len)
{
mul_bignum(glob2, n2, n3, len);
glob2[len * 2] = 0;
uint32_t g2_len_x2 = len_bignum(glob2, len * 2 + 1) * 2;
if (g2_len_x2 >= glob1_len_x2)
{
inc_bignum(glob2, len * 2 + 1);
neg_bignum(glob2, len * 2 + 1);
uint32_t len_diff = g2_len_x2 + 1 - glob1_len_x2;
word* esi = ((word *)glob2) + (1 + g2_len_x2 - glob1_len_x2);
word* edi = ((word *)glob2) + (g2_len_x2 + 1);
for (; len_diff != 0; len_diff--)
{
edi--;
word tmp = get_mulword((uint32_t *)edi);
esi--;
if (tmp > 0)
{
mul_bignum_word((uint32_t *)esi, glob1, tmp, 2 * len);
if ((*edi & 0x8000) == 0)
{
if (sub_bignum((uint32_t *)esi, (uint32_t *)esi, glob1, 0, len))
(*edi)--;
}
}
}
neg_bignum(glob2, len);
dec_bignum(glob2, len);
}
mov_bignum(n1, glob2, len);
}
static void calc_a_key(bignum n1, bignum n2, bignum n3, bignum n4, uint32_t len)
{
bignum n_tmp;
init_bignum(n1, 1, len);
uint32_t n4_len = len_bignum(n4, len);
init_two_dw(n4, n4_len);
uint32_t n3_bitlen = bitlen_bignum(n3, n4_len);
uint32_t n3_len = (n3_bitlen + 31) / 32;
uint32_t bit_mask = (((uint32_t)1) << ((n3_bitlen - 1) % 32)) >> 1;
n3 += n3_len - 1;
n3_bitlen--;
mov_bignum(n1, n2, n4_len);
while (--n3_bitlen != -1)
{
if (bit_mask == 0)
{
bit_mask = 0x80000000;
n3--;
}
calc_a_bignum(n_tmp, n1, n1, n4_len);
if (*n3 & bit_mask)
calc_a_bignum(n1, n_tmp, n2, n4_len);
else
mov_bignum(n1, n_tmp, n4_len);
bit_mask >>= 1;
}
init_bignum(n_tmp, 0, n4_len);
init_bignum(glob1, 0, len);
init_bignum(glob2, 0, len);
init_bignum(glob1_hi_inv, 0, 4);
init_bignum(glob1_hi, 0, 4);
glob1_bitlen = 0;
glob1_hi_bitlen = 0;
glob1_len_x2 = 0;
glob1_hi_inv_lo = 0;
glob1_hi_inv_hi = 0;
}
static void process_predata(const byte* pre, uint32_t pre_len, byte *buf)
{
bignum n2, n3;
const uint32_t a = (pubkey.len - 1) / 8;
while (a + 1 <= pre_len)
{
init_bignum(n2, 0, 64);
memmove(n2, pre, a + 1);
calc_a_key(n3, n2, pubkey.key2, pubkey.key1, 64);
memmove(buf, n3, a);
pre_len -= a + 1;
pre += a + 1;
buf += a;
}
}
void get_blowfish_key(const byte* s, span<byte> d)
{
static bool public_key_initialized = false;
if (!public_key_initialized)
{
init_pubkey();
public_key_initialized = true;
}
byte key[256];
process_predata(s, len_predata(), key);
memcpy(d.data(), key, 56);
}

21
3rdParty/xcc/misc/mix_decode.h vendored Normal file
View file

@ -0,0 +1,21 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
void get_blowfish_key(const byte* s, span<byte> d);

424
3rdParty/xcc/misc/mix_file.cpp vendored Normal file
View file

@ -0,0 +1,424 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include <stdafx.h>
#include "mix_file.h"
#ifndef NO_FT_SUPPORT
#include "big_file.h"
#endif
#include "blowfish.h"
#include "crc.h"
#include "id_log.h"
#ifndef NO_FT_SUPPORT
#include "mix_cache.h"
#endif
#include "mix_decode.h"
#ifndef NO_FT_SUPPORT
#include "mix_rg_file.h"
#include "pak_file.h"
#endif
#include "string_conversion.h"
#include "xcc_lmd_file.h"
bool Cmix_file::m_ft_support = false;
Cmix_file::Cmix_file() :
Ccc_file(false)
{
}
bool Cmix_file::is_valid()
{
const byte* data = get_data();
if (!data)
return false;
const t_mix_header& header = *reinterpret_cast<const t_mix_header*>(data);
int size = get_size();
if (sizeof(t_mix_header) > size)
return false;
if (header.c_files && sizeof(t_mix_header) + header.c_files * sizeof(t_mix_index_entry) + header.size == size)
return true;
if (header.flags & ~(mix_encrypted | mix_checksum))
return false;
m_has_checksum = header.flags & mix_checksum;
m_is_encrypted = header.flags & mix_encrypted;
if (m_is_encrypted)
{
Cblowfish bf;
std::array<byte, cb_mix_key> key;
get_blowfish_key(data + 4, key);
bf.set_key(key);
byte e[8];
bf.decipher(data + 84, e, 8);
t_mix_header* header = reinterpret_cast<t_mix_header*>(e);
if (!header->c_files || 84 + (sizeof(t_mix_header) + header->c_files * sizeof(t_mix_index_entry) + 7 & ~7) + header->size + (m_has_checksum ? 20 : 0) != size)
return false;
}
else
{
const t_mix_header* header = reinterpret_cast<const t_mix_header*>(data + 4);
if (!header->c_files || 4 + sizeof(t_mix_header) + header->c_files * sizeof(t_mix_index_entry) + header->size + (m_has_checksum ? 20 : 0) != size)
return false;
}
return true;
}
#define test_fail(res) { int v = res; if (v) { close(); return v; }}
int Cmix_file::post_open()
{
#ifndef NO_FT_SUPPORT
bool index_read = false;
if (h())
{
Cmix_rg_file f;
if (get_data())
f.load(vdata());
else
f.open(h());
if (f.is_open() && f.is_valid())
{
m_game = game_rg;
m_is_encrypted = m_has_checksum = false;
int c_files = f.get_c_files();
m_index.resize(c_files);
for (int i = 0; i < c_files; i++)
{
string name = f.get_name(i);
mix_database::add_name(m_game, name, "-");
m_index[i] = t_mix_index_entry(get_id(get_game(), name), f.get_offset(name), f.get_size(name));
}
index_read = true;
}
else
{
Cbig_file f;
if (get_data())
f.load(vdata());
else
f.open(h());
if (f.is_open() && f.is_valid())
{
m_game = game_gr;
m_is_encrypted = m_has_checksum = false;
int c_files = f.get_c_files();
m_index.resize(c_files);
for (int i = 0; i < c_files; i++)
{
string name = f.get_name(i);
mix_database::add_name(m_game, name, "-");
m_index[i] = t_mix_index_entry(get_id(get_game(), name), f.get_offset(name), f.get_size(name));
}
index_read = true;
}
}
}
if (!index_read)
{
Cpak_file f;
if (get_data())
f.load(vdata());
else
{
int size = min<int>(get_size(), 64 << 10);
Cvirtual_binary data;
test_fail(read(data.write_start(size), size));
f.load(data, get_size());
}
if (f.is_valid())
{
m_game = game_dune2;
m_is_encrypted = m_has_checksum = false;
int c_files = f.get_c_files();
if (c_files >> 12)
test_fail(1);
m_index.resize(c_files);
for (int i = 0; i < c_files; i++)
{
string name = f.get_name(i);
mix_database::add_name(m_game, name, "-");
m_index[i] = t_mix_index_entry(get_id(get_game(), name), f.get_offset(name), f.get_size(name));
}
index_read = true;
}
}
if (!index_read)
#endif
{
t_mix_header header;
seek(0);
test_fail(read(&header, sizeof(t_mix_header)));
if (header.c_files)
{
m_game = game_td;
m_is_encrypted = m_has_checksum = false;
int c_files = header.c_files;
int cb_index = c_files * sizeof(t_mix_index_entry);
if (header.c_files >> 12 || get_size() != 6 + cb_index + header.size)
test_fail(1);
m_index.resize(c_files);
test_fail(read(&m_index[0], cb_index));
for (int i = 0; i < c_files; i++)
m_index[i].offset += 6 + cb_index;
}
else
{
m_has_checksum = header.flags & mix_checksum;
m_is_encrypted = header.flags & mix_encrypted;
bool aligned = true;
Cblowfish bf;
seek(4);
if (m_is_encrypted)
{
byte key_source[cb_mix_key_source];
read(key_source, cb_mix_key_source);
std::array<byte, cb_mix_key> key;
get_blowfish_key(key_source, key);
bf.set_key(key);
byte e[8];
read(e, 8);
bf.decipher(e, e, 8);
memcpy(&header, e, sizeof(t_mix_header));
int c_files = header.c_files;
const int cb_index = c_files * sizeof(t_mix_index_entry);
const int cb_f = cb_index + 5 & ~7;
if (get_size() != 92 + cb_f + header.size + (m_has_checksum ? 20 : 0))
test_fail(1);
if (c_files)
{
Cvirtual_binary f;
read(f.write_start(cb_f), cb_f);
bf.decipher(f.data_edit(), f.data_edit(), cb_f);
m_index.resize(c_files);
memcpy(&m_index[0], e + 6, 2);
memcpy(reinterpret_cast<byte*>(&m_index[0]) + 2, f.data(), cb_index - 2);
for (int i = 0; i < c_files; i++)
{
if (m_index[i].offset & 0xf)
aligned = false;
m_index[i].offset += 92 + cb_f;
}
}
}
else
{
read(&header, sizeof(header));
int c_files = header.c_files;
const int cb_index = c_files * sizeof(t_mix_index_entry);
if (get_size() != 4 + sizeof(t_mix_header) + cb_index + header.size + (m_has_checksum ? 20 : 0))
test_fail(1);
m_index.resize(c_files);
read(&m_index[0], cb_index);
for (int i = 0; i < c_files; i++)
{
if (m_index[i].offset & 0xf)
aligned = false;
m_index[i].offset += 4 + sizeof(t_mix_header) + cb_index;
}
}
m_game = is_encrypted() ? game_ra : game_ts;
for (int i = 0; i < get_c_files(); i++)
{
if (get_id(i) == 0x763c81dd)
{
m_game = game_ts;
break;
}
}
if (m_game == game_ra && aligned)
m_game = game_ts;
}
}
for (int i = 0; i < get_c_files(); i++)
m_id_index[get_id(i)] = i;
#ifndef NO_FT_SUPPORT
if (m_ft_support)
{
switch (m_game)
{
case game_dune2:
case game_rg:
break;
default:
int count[game_unknown] = {0};
for (int i = 0; i < get_c_files(); i++)
{
int id = get_id(i);
for (int game = game_td; game < game_unknown; game++)
count[game] += mix_database::get_name(static_cast<t_game>(game), id).empty();
}
int min = count[0];
for (int game = 0; game < game_unknown; game++)
{
if (count[game] < min)
{
m_game = static_cast<t_game>(game);
min = count[game];
}
}
}
if (vdata().size() == get_size())
{
int crc = compute_crc(&m_index[0], get_c_files() * sizeof(t_mix_index_entry));
Cvirtual_binary s = mix_cache::get_data(crc);
m_index_ft.resize(get_c_files());
if (s.size() == get_c_files() * sizeof(t_file_type))
memcpy(&m_index_ft[0], s.data(), get_c_files() * sizeof(t_file_type));
else
{
using t_block_map = multimap<int, int>;
t_block_map block_map;
for (int i = 0; i < get_c_files(); i++)
block_map.insert(t_block_map::value_type(get_offset(get_id(i)), i));
for (auto& i : block_map)
{
Ccc_file f(false);
f.open(get_id(i.second), *this);
m_index_ft[i.second] = f.get_file_type();
}
mix_cache::set_data(crc, Cvirtual_binary(&m_index_ft[0], get_c_files() * sizeof(t_file_type)));
}
for (int i = 0; i < get_c_files(); i++)
{
int id = get_id(i);
Cxcc_lmd_file f;
if (get_type(id) != ft_xcc_lmd || f.open(id, *this) || !f.is_valid())
continue;
m_game = f.get_game();
int count = f.get_c_fnames();
const char* r = f.get_fnames();
while (count--)
{
string name = r;
r += name.length() + 1;
mix_database::add_name(m_game, name, "-");
}
}
}
}
#endif
if (m_mix_expansion)
{
int c_files = get_c_files();
for (int i = 0; i < c_files; i++)
{
if (get_type(m_index[i].id) != ft_mix)
continue;
Cmix_file f;
f.open(m_index[i].id, *this);
int c_files = get_c_files();
int new_c_files = f.get_c_files();
m_index.resize(c_files + new_c_files);
for (int j = 0; j < new_c_files; j++)
{
int id = f.get_id(j);
m_index[c_files + j] = t_mix_index_entry(id, f.get_offset(id) + get_offset(m_index[i].id), f.get_size(id));
m_id_index[id] = c_files + j;
}
m_index_ft.resize(c_files + new_c_files);
memcpy(&m_index_ft[c_files], &f.m_index_ft[0], new_c_files * sizeof(t_file_type));
}
}
return 0;
}
void Cmix_file::close()
{
m_id_index.clear();
m_index_ft.clear();
m_index.clear();
Ccc_file::close();
}
string Cmix_file::get_name(int id)
{
#ifdef NO_FT_SUPPORT
return "";
#else
return mix_database::get_name(get_game(), id);
#endif
}
int Cmix_file::get_id(t_game game, string name)
{
boost::to_upper(name);
std::replace(name.begin(), name.end(), '/', '\\');
switch (game)
{
case game_ts:
case game_ra2:
case game_ra2_yr:
{
const int l = name.length();
int a = l & ~3;
if (l & 3)
{
name += static_cast<char>(l - a);
name.append(3 - (l & 3), name[a]);
}
return compute_crc(name.c_str(), name.length());
}
case game_rg:
case game_gr:
case game_gr_zh:
return compute_crc(name.c_str(), name.length());
default:
int i = 0;
unsigned int id = 0;
int l = name.length();
while (i < l)
{
unsigned int a = 0;
for (int j = 0; j < 4; j++)
{
a >>= 8;
if (i < l)
a |= static_cast<unsigned int>(name[i++]) << 24;
}
id = (id << 1 | id >> 31) + a;
}
return id;
}
}
int Cmix_file::get_index(unsigned int id) const
{
auto i = find_ptr(m_id_index, id);
return i ? *i : -1;
}
Cvirtual_binary Cmix_file::get_vdata(int id)
{
if (get_index(id) == -1)
return Cvirtual_binary();
if (get_data())
return vdata().sub_bin(get_offset(id), get_size(id));
Cvirtual_binary d;
seek(get_offset(id));
int size = get_size(id);
if (read(d.write_start(size), size))
d.clear();
return d;
}
Cvirtual_binary Cmix_file::get_vdata(const string& name)
{
return get_vdata(get_id(m_game, name));
}

115
3rdParty/xcc/misc/mix_file.h vendored Normal file
View file

@ -0,0 +1,115 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "cc_file.h"
#include "cc_structures.h"
class Cmix_file : public Ccc_file
{
public:
int post_open();
string get_name(int id);
static int get_id(t_game game, string name);
int get_index(unsigned int id) const;
using Ccc_file::get_size;
using Ccc_file::vdata;
Cvirtual_binary get_vdata(int id);
Cvirtual_binary get_vdata(const string& name);
bool is_valid();
void close();
Cmix_file();
static void enable_ft_support()
{
assert(!m_ft_support);
m_ft_support = true;
}
void enable_mix_expansion()
{
assert(!m_mix_expansion);
m_mix_expansion = true;
}
int get_c_files() const
{
return m_index.size();
}
t_game get_game() const
{
return m_game;
}
void set_game(t_game game)
{
m_game = game;
}
t_file_type get_type(int id)
{
assert(get_index(id) != -1);
return m_index_ft[get_index(id)];
}
int get_id(int index) const
{
return m_index[index].id;
}
int get_offset(unsigned int id) const
{
assert(get_index(id) != -1);
return m_index[get_index(id)].offset;
}
int get_size(unsigned int id) const
{
assert(get_index(id) != -1);
return m_index[get_index(id)].size;
}
bool has_checksum() const
{
return m_has_checksum;
}
bool is_encrypted() const
{
return m_is_encrypted;
}
const t_mix_index_entry* index() const
{
return &m_index[0];
}
private:
using t_id_index = map<int, int>;
static bool m_ft_support;
t_game m_game;
bool m_mix_expansion = false;
bool m_is_encrypted;
bool m_has_checksum;
vector<t_mix_index_entry> m_index;
vector<t_file_type> m_index_ft;
t_id_index m_id_index;
};

83
3rdParty/xcc/misc/mix_file_write.cpp vendored Normal file
View file

@ -0,0 +1,83 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "mix_file_write.h"
#include "mix_file.h"
#include "string_conversion.h"
Cmix_file_write::Cmix_file_write(t_game game)
{
m_game = game;
}
void Cmix_file_write::add_file(int id, const Cvirtual_binary d)
{
m_index[id] = d;
}
void Cmix_file_write::add_file(string name, const Cvirtual_binary d)
{
add_file(Cmix_file::get_id(m_game, name), d);
m_lmd_fw.add_fname(name);
}
void Cmix_file_write::clear()
{
m_index.clear();
}
int Cmix_file_write::write_start()
{
add_file("local mix database.dat", m_lmd_fw.write(m_game));
int r = 4 + sizeof(t_mix_header) + m_index.size() * sizeof(t_mix_index_entry);
for (auto& i : m_index)
r += i.second.size();
return r;
}
int Cmix_file_write::write(byte* d) const
{
byte* w = d;
*reinterpret_cast<__int32*>(w) = 0;
w += 4;
t_mix_header& header = *reinterpret_cast<t_mix_header*>(w);
header.c_files = m_index.size();
w += sizeof(t_mix_header);
t_mix_index_entry* index = reinterpret_cast<t_mix_index_entry*>(w);
w += m_index.size() * sizeof(t_mix_index_entry);
byte* body_start = w;
for (auto& i : m_index)
{
index->id = i.first;
index->offset = w - body_start;
index->size = i.second.size();
index++;
w += i.second.read(w);
}
header.size = w - body_start;
return w - d;
}
Cvirtual_binary Cmix_file_write::write()
{
Cvirtual_binary d;
write(d.write_start(write_start()));
return d;
}

42
3rdParty/xcc/misc/mix_file_write.h vendored Normal file
View file

@ -0,0 +1,42 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "cc_structures.h"
#include <virtual_binary.h>
#include "xcc_lmd_file_write.h"
class Cmix_file_write
{
public:
void add_file(int id, const Cvirtual_binary d);
void add_file(string name, const Cvirtual_binary d);
void clear();
Cvirtual_binary write();
Cmix_file_write(t_game game);
private:
using t_index = map<int, Cvirtual_binary>;
int write_start();
int write(byte* d) const;
t_game m_game;
t_index m_index;
Cxcc_lmd_file_write m_lmd_fw;
};

48
3rdParty/xcc/misc/null_ini_reader.h vendored Normal file
View file

@ -0,0 +1,48 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "ini_reader.h"
class Cnull_ini_reader : public Cini_reader
{
public:
int process_section_start(string_view) override
{
mc_sections++;
return 0;
}
bool process_section() const override
{
return true;
}
int process_key(string_view, string_view) override
{
return 0;
}
bool is_valid() const
{
return mc_sections;
}
private:
int mc_sections = 0;
};

50
3rdParty/xcc/misc/pal_file.cpp vendored Normal file
View file

@ -0,0 +1,50 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "pal_file.h"
#include <fstream>
bool Cpal_file::is_valid() const
{
if (get_size() != sizeof(t_palet))
return false;
const t_palet_entry* p = get_palet();
for (int i = 0; i < 256; i++)
{
if ((p[i].r | p[i].g | p[i].b) & 0xc0)
return false;
}
return true;
}
ostream& Cpal_file::extract_as_pal_jasc(ostream& os, bool shift_left) const
{
os << "JASC-PAL" << endl
<< "0100" << endl
<< "256" << endl;
t_palet palet;
if (shift_left)
convert_palet_18_to_24(get_palet(), palet);
else
memcpy(palet, get_palet(), sizeof(t_palet));
for (int i = 0; i < 256; i++)
os << static_cast<int>(palet[i].r) << ' ' << static_cast<int>(palet[i].g) << ' ' << static_cast<int>(palet[i].b) << endl;
return os;
}

39
3rdParty/xcc/misc/pal_file.h vendored Normal file
View file

@ -0,0 +1,39 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <cc_file_small.h>
#include <palet.h>
class Cpal_file : public Ccc_file_small
{
public:
ostream& extract_as_pal_jasc(ostream&, bool shift_left = true) const;
bool is_valid() const;
void decode(t_palet& palet) const
{
convert_palet_18_to_24(get_palet(), palet);
}
const t_palet_entry* get_palet() const
{
return reinterpret_cast<const t_palet_entry*>(data());
}
};

214
3rdParty/xcc/misc/palet.cpp vendored Normal file
View file

@ -0,0 +1,214 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include <climits>
#include "palet.h"
void convert_image_8_to_24(const byte* s, byte* d, int cx, int cy, const t_palet palet)
{
const byte* r = s;
byte* w = d;
int c = cx * cy;
while (c--)
{
const t_palet_entry* v = palet + *r++;
*w++ = v->r;
*w++ = v->g;
*w++ = v->b;
}
}
void create_downsample_table(const t_palet palet, byte* rp)
{
byte* rp_w = rp;
for (int b = 0; b < 0x40; b++)
{
for (int g = 0; g < 0x40; g++)
{
for (int r = 0; r < 0x40; r++)
*rp_w++ = find_color(r * 255 / 63, g * 255 / 63, b * 255 / 63, palet);
}
}
}
void convert_image_24_to_8(const byte* s, byte* d, int cx, int cy, const byte* rp)
{
const byte* r = s;
byte* w = d;
int c = cx * cy;
while (c--)
{
int red = *r++ >> 2 & 0x3f;
int green = *r++ >> 2 & 0x3f;
int blue = *r++ >> 2 & 0x3f;
*w++ = rp[red | green << 6 | blue << 12];
}
}
void convert_image_24_to_8(const byte* s, byte* d, int cx, int cy, const t_palet palet)
{
const byte* r = s;
byte* w = d;
int c = cx * cy;
while (c--)
{
int red = *r++;
int green = *r++;
int blue = *r++;
*w++ = find_color(red, green, blue, palet);
}
}
void downsample_image(const t_palet32entry* s, byte* d, int cx, int cy, const byte* rp)
{
const t_palet32entry* r = s;
byte* w = d;
int c = cx * cy;
while (c--)
{
t_palet32entry e = *r++;
*w++ = e.a < 0x80 ? 0 : rp[e.r >> 2 | (e.g & 0xfc) << 4 | (e.b & 0xfc) << 10];
}
}
void downsample_image(const t_palet32entry* s, byte* d, int cx, int cy, const t_palet palet)
{
const t_palet32entry* r = s;
byte* w = d;
int c = cx * cy;
while (c--)
{
t_palet32entry e = *r++;
if (e.a < 0x80)
*w++ = 0;
else
*w++ = find_color(e.r, e.g, e.b, palet);
}
}
void upsample_image(const byte* s, t_palet32entry* d, int cx, int cy, const t_palet palet)
{
const byte* r = s;
t_palet32entry* w = d;
int c = cx * cy;
while (c--)
{
t_palet32entry& e = *w++;
int z = *r++;
if (z)
{
const t_palet_entry* v = palet + z;
e.r = v->r;
e.g = v->g;
e.b = v->b;
e.a = 0xff;
}
else
{
e.r = 0x80;
e.g = 0x80;
e.b = 0x80;
e.a = 0;
}
}
}
void convert_palet_18_to_24(const t_palet s, t_palet d)
{
for (int i = 0; i < 256; i++)
{
d[i].r = (s[i].r & 63) * 255 / 63;
d[i].g = (s[i].g & 63) * 255 / 63;
d[i].b = (s[i].b & 63) * 255 / 63;
}
}
void convert_palet_24_to_18(const t_palet s, t_palet d)
{
for (int i = 0; i < 256; i++)
{
d[i].r = s[i].r >> 2;
d[i].g = s[i].g >> 2;
d[i].b = s[i].b >> 2;
}
}
void convert_palet_18_to_24(t_palet palet)
{
convert_palet_18_to_24(palet, palet);
}
void convert_palet_24_to_18(t_palet palet)
{
convert_palet_24_to_18(palet, palet);
}
int find_color(int r, int g, int b, const t_palet p)
{
int best_i;
int min_d = INT_MAX;
for (int i = 0; i < 256; i++)
{
int d_r = p[i].r - r;
int d_g = p[i].g - g;
int d_b = p[i].b - b;
int d = d_r * d_r + d_g * d_g + d_b * d_b;
if (d < min_d)
{
min_d = d;
best_i = i;
}
}
return best_i;
}
int find_color_t(int r, int g, int b, const t_palet p)
{
int best_i;
int min_d = INT_MAX;
for (int i = 1; i < 256; i++)
{
int d_r = p[i].r - r;
int d_g = p[i].g - g;
int d_b = p[i].b - b;
int d = d_r * d_r + d_g * d_g + d_b * d_b;
if (d < min_d)
{
min_d = d;
best_i = i;
}
}
return best_i;
}
void create_rp(const t_palet s1, const t_palet s2, byte* d)
{
d[0] = 0;
for (int i = 1; i < 256; i++)
d[i] = find_color(s1[i].r, s1[i].g, s1[i].b, s2);
}
void apply_rp(byte* d, int cb_d, const byte* rp)
{
while (cb_d--)
{
*d = rp[*d];
d++;
}
}

76
3rdParty/xcc/misc/palet.h vendored Normal file
View file

@ -0,0 +1,76 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <vartypes.h>
#pragma pack(push, 1)
struct t_palet_entry
{
byte r, g, b;
};
struct t_palet24rgb_entry
{
byte r, g, b;
};
struct t_palet24bgr_entry
{
byte b, g, r;
};
union t_palet32entry
{
struct
{
byte r, g, b, a;
};
unsigned __int32 v;
};
union t_palet32bgr_entry
{
struct
{
byte b, g, r, a;
};
unsigned __int32 v;
};
using t_palet = t_palet_entry[256];
void apply_rp(byte* d, int cb_d, const byte* rp);
void convert_image_8_to_24(const byte* s, byte* d, int cx, int cy, const t_palet palet);
void convert_image_24_to_8(const byte* s, byte* d, int cx, int cy, const byte* rp);
void convert_image_24_to_8(const byte* s, byte* d, int cx, int cy, const t_palet palet);
void convert_palet_18_to_24(const t_palet s, t_palet d);
void convert_palet_18_to_24(t_palet palet);
void convert_palet_24_to_18(const t_palet s, t_palet d);
void convert_palet_24_to_18(t_palet palet);
void create_downsample_table(const t_palet palet, byte* rp);
void create_rp(const t_palet s1, const t_palet s2, byte* d);
void downsample_image(const t_palet32entry* s, byte* d, int cx, int cy, const byte* rp);
void downsample_image(const t_palet32entry* s, byte* d, int cx, int cy, const t_palet palet);
void upsample_image(const byte* s, t_palet32entry* d, int cx, int cy, const t_palet palet);
int find_color(int r, int g, int b, const t_palet p);
int find_color_t(int r, int g, int b, const t_palet p);
#pragma pack(pop)

105
3rdParty/xcc/misc/reg_key.cpp vendored Normal file
View file

@ -0,0 +1,105 @@
/*
XCC Utilities and Library
Copyright (C) 2006 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "reg_key.h"
#include <vector>
using namespace std;
Creg_key::Creg_key(HKEY key, const string& name, REGSAM sam_desired)
{
m_h = NULL;
if (open(key, name, sam_desired) != ERROR_SUCCESS)
throw exception();
}
Creg_key::Creg_key(const Creg_key& key, const string& name, REGSAM sam_desired)
{
m_h = NULL;
if (open(key.m_h, name, sam_desired) != ERROR_SUCCESS)
throw exception();
}
Creg_key::~Creg_key()
{
close();
}
LONG Creg_key::create(HKEY key, const string& name)
{
close();
return RegCreateKeyExA(key, name.c_str(), 0, NULL, 0, KEY_ALL_ACCESS, NULL, &m_h, NULL);
}
LONG Creg_key::open(HKEY key, const string& name, REGSAM sam_desired)
{
close();
return RegOpenKeyExA(key, name.c_str(), 0, sam_desired, &m_h);
};
LONG Creg_key::open(const Creg_key& key, const string& name, REGSAM sam_desired)
{
return open(key.m_h, name, sam_desired);
};
LONG Creg_key::close()
{
if (!m_h)
return ERROR_SUCCESS;
LONG result = RegCloseKey(m_h);
m_h = NULL;
return result;
}
LONG Creg_key::query_value(const string& name, string& value)
{
DWORD cb_d = 0;
LONG result = RegQueryValueExA(m_h, name.c_str(), NULL, NULL, NULL, &cb_d);
if (result != ERROR_SUCCESS)
return result;
if (!cb_d)
{
value.erase();
return result;
}
vector<BYTE> d(cb_d);
result = RegQueryValueExA(m_h, name.c_str(), NULL, NULL, &d.front(), &cb_d);
if (result == ERROR_SUCCESS)
{
if (cb_d)
value.assign(reinterpret_cast<char*>(&d.front()), cb_d - 1);
else
value.erase();
}
return result;
}
string Creg_key::query_value(const string& name)
{
string d;
if (query_value(name, d) != ERROR_SUCCESS)
throw exception();
return d;
}
LONG Creg_key::set_value(const string& name, const string& value)
{
return RegSetValueExA(m_h, name.c_str(), 0, REG_SZ, reinterpret_cast<const BYTE*>(value.c_str()), value.size());
}

41
3rdParty/xcc/misc/reg_key.h vendored Normal file
View file

@ -0,0 +1,41 @@
/*
XCC Utilities and Library
Copyright (C) 2006 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <boost/noncopyable.hpp>
#include <string>
#include <windows.h>
class Creg_key : boost::noncopyable
{
public:
Creg_key() = default;
Creg_key(HKEY, const std::string& name, REGSAM sam_desired);
Creg_key(const Creg_key&, const std::string& name, REGSAM sam_desired);
~Creg_key();
LONG create(HKEY key, const std::string& name);
LONG open(HKEY, const std::string& name, REGSAM sam_desired);
LONG open(const Creg_key&, const std::string& name, REGSAM sam_desired);
LONG close();
LONG query_value(const std::string& name, std::string& value);
std::string query_value(const std::string& name);
LONG set_value(const std::string& name, const std::string& value);
private:
HKEY m_h = NULL;
};

1196
3rdParty/xcc/misc/shp_decode.cpp vendored Normal file

File diff suppressed because it is too large Load diff

39
3rdParty/xcc/misc/shp_decode.h vendored Normal file
View file

@ -0,0 +1,39 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <virtual_binary.h>
int decode2(const byte* s, byte* d, int cb_s, const byte* reference_palet);
int decode3(const byte* s, byte* d, int cx, int cy);
int encode3(const byte* s, byte* d, int cx, int cy);
int decode5(const byte* s, byte* d, int cb_s, int format);
int encode5(const byte* s, byte* d, int cb_s, int format);
int decode5s(const byte* s, byte* d, int cb_s);
int encode5s(const byte* s, byte* d, int cb_s);
int decode64(const byte* s, byte* d);
Cvirtual_binary decode64(data_ref);
Cvirtual_binary encode64(data_ref);
int decode40(const byte image_in[], byte image_out[]);
int decode80(const byte image_in[], byte image_out[]);
int decode80c(const byte image_in[], byte image_out[], int cb_in);
int decode80r(const byte image_in[], byte image_out[]);
int encode40(const byte* last_s, const byte* s, byte* d, int cb_s);
int encode80(const byte* s, byte* d, int cb_s);
int get_run_length(const byte* r, const byte* s_end);

668
3rdParty/xcc/misc/shp_ts_file.cpp vendored Normal file
View file

@ -0,0 +1,668 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "shp_ts_file.h"
#include "image_file.h"
#include "shp_decode.h"
#include "string_conversion.h"
#ifndef XCC_MINIMAL_BUILD
#include "xcc_log.h"
#endif
class Cshp_ts_decoder : public Cvideo_decoder
{
public:
int cb_pixel() const
{
return m_f.cb_pixel();
}
int cf() const
{
return m_f.cf();
}
int cx() const
{
return m_f.cx();
}
int cy() const
{
return m_f.cy();
}
int decode(void* d0)
{
if (m_frame_i >= cf())
return 1;
byte* d = reinterpret_cast<byte*>(d0);
Cvirtual_binary s;
const int cx = m_f.get_cx(m_frame_i);
const int cy = m_f.get_cy(m_frame_i);
const byte* r;
if (m_f.is_compressed(m_frame_i))
{
decode3(m_f.get_image(m_frame_i), s.write_start(cx * cy), cx, cy);
r = s.data();
}
else
r = m_f.get_image(m_frame_i);
memset(d, 0, cb_image());
byte* w = d + m_f.get_x(m_frame_i) + Cshp_ts_decoder::cx() * m_f.get_y(m_frame_i);
for (int y = 0; y < cy; y++)
{
memcpy(w, r, cx);
r += cx;
w += Cshp_ts_decoder::cx();
}
m_frame_i++;
return 0;
}
const t_palet_entry* palet() const
{
return m_palet;
}
int seek(int f)
{
m_frame_i = f;
return 0;
}
Cshp_ts_decoder(const Cshp_ts_file& f, const t_palet_entry* palet)
{
m_f.load(f);
m_frame_i = 0;
memcpy(m_palet, palet, sizeof(t_palet));
}
private:
Cshp_ts_file m_f;
int m_frame_i;
t_palet m_palet;
};
Cvideo_decoder* Cshp_ts_file::decoder(const t_palet_entry* palet)
{
return new Cshp_ts_decoder(*this, palet);
}
bool Cshp_ts_file::is_valid() const
{
const t_shp_ts_header& h = header();
int size = get_size();
if (sizeof(t_shp_ts_header) > size ||
h.zero ||
h.c_images < 1 || h.c_images > 10000 ||
sizeof(t_shp_ts_header) + get_cb_index() > size)
return false;
for (int i = 0; i < min(cf(), 1000); i++)
{
const t_shp_ts_image_header& image_header = *get_image_header(i);
if (!image_header.cx && !image_header.cy && !image_header.offset)
continue;
if (!image_header.cx || image_header.x + image_header.cx > h.cx ||
!image_header.cy || image_header.y + image_header.cy > h.cy ||
image_header.zero ||
image_header.offset < sizeof(t_shp_ts_header) + get_cb_index())
return false;
if (is_compressed(i))
{
if (image_header.offset > size)
return false;
}
else
{
if (image_header.offset + image_header.cx * image_header.cy > size)
return false;
}
}
return true;
}
int get_ofs(int x, int y, int cx, int cy)
{
return x + cx * y;
}
#ifndef XCC_MINIMAL_BUILD
int Cshp_ts_file::extract_as_pcx(const Cfname& name, t_file_type ft, const t_palet _palet, bool combine_shadows) const
{
t_palet palet;
convert_palet_18_to_24(_palet, palet);
int error = 0;
const int global_cx = cx();
const int global_cy = cy();
const int c_images = cf();
if (combine_shadows && ~c_images & 1)
{
bool shadow = false;
byte* image = new byte[global_cx * global_cy];
byte* d = new byte[global_cx * global_cy * c_images >> 1];
byte* w = d;
for (int i = 0; i < c_images; i++)
{
const int cx = get_cx(i);
const int cy = get_cy(i);
const byte* r;
if (is_compressed(i))
{
decode3(get_image(i), image, cx, cy);
r = image;
}
else
r = get_image(i);
if (!shadow)
{
if (i == c_images >> 1)
{
shadow = true;
w = d;
}
else
memset(w, 0, global_cx * global_cy);
}
byte* w_start = w;
w += get_x(i) + global_cx * get_y(i);
for (int y = 0; y < cy; y++)
{
if (shadow)
{
for (int x = 0; x < cx; x++)
{
if (*r++)
w[x] = 4;
}
}
else
{
memcpy(w, r, cx);
r += cx;
}
w += global_cx;
}
if (shadow)
{
Cfname t = name;
t.set_title(name.get_ftitle() + " " + nwzl(4, i - (c_images >> 1)));
error = image_file_write(t, ft, w_start, palet, global_cx, global_cy);
if (error)
break;
}
w = w_start + global_cx * global_cy;
}
delete[] d;
delete[] image;
}
else
{
byte* image = new byte[global_cx * global_cy];
byte* s = new byte[global_cx * global_cy];
for (int i = 0; i < c_images; i++)
{
const int cx = get_cx(i);
const int cy = get_cy(i);
const byte* r;
if (is_compressed(i))
{
decode3(get_image(i), image, cx, cy);
r = image;
}
else
r = get_image(i);
memset(s, 0, global_cx * global_cy);
byte* w = s + get_x(i) + global_cx * get_y(i);
for (int y = 0; y < cy; y++)
{
memcpy(w, r, cx);
r += cx;
w += global_cx;
}
// xcc_log::write_line("<tr><td>" + name.get_ftitle() + "</td><td><img src=" + name.get_fname() + "></td></tr>");
Cfname t = name;
t.set_title(name.get_ftitle() + " " + nwzl(4, i));
error = image_file_write(t, ft, s, palet, global_cx, global_cy);
if (error)
break;
}
delete[] s;
delete[] image;
}
return error;
}
Cvirtual_image Cshp_ts_file::extract_as_pcx_single(const t_palet _palet, bool combine_shadows) const
{
t_palet palet;
convert_palet_18_to_24(_palet, palet);
const int global_cx = cx();
const int global_cy = cy();
int c_images = cf();
combine_shadows &= ~c_images & 1;
if (combine_shadows)
c_images >>= 1;
const int cblocks_x = min(c_images, 1024 / global_cx);
const int cblocks_y = (c_images + cblocks_x - 1) / cblocks_x;
int cx_s = cblocks_x * global_cx;
int cy_s = cblocks_y * global_cy;
Cvirtual_binary image;
Cvirtual_binary s;
memset(s.write_start(cx_s * cy_s), 0, cx_s * cy_s);
if (combine_shadows)
{
c_images <<= 1;
bool shadow = false;
for (int i = 0; i < c_images; i++)
{
const int cx = get_cx(i);
const int cy = get_cy(i);
const byte* r;
if (is_compressed(i))
{
decode3(get_image(i), image.write_start(global_cx * global_cy), cx, cy);
r = image.data();
}
else
r = get_image(i);
if (!shadow && i == c_images >> 1)
shadow = true;
int j = i % (c_images >> 1);
byte* w = s.data_edit() + get_ofs(j % cblocks_x * global_cx + get_x(i), j / cblocks_x * global_cy + get_y(i), cx_s, cy_s);
for (int y = 0; y < cy; y++)
{
if (shadow)
{
for (int x = 0; x < cx; x++)
{
if (*r++)
w[x] = 4;
}
}
else
{
memcpy(w, r, cx);
r += cx;
}
w += cx_s;
}
}
}
else
{
for (int i = 0; i < c_images; i++)
{
const int cx = get_cx(i);
const int cy = get_cy(i);
const byte* r;
if (is_compressed(i))
{
decode3(get_image(i), image.write_start(global_cx * global_cy), cx, cy);
r = image.data();
}
else
r = get_image(i);
byte* w = s.data_edit() + get_ofs(i % cblocks_x * global_cx + get_x(i), i / cblocks_x * global_cy + get_y(i), cx_s, cy_s);
for (int y = 0; y < cy; y++)
{
memcpy(w, r, cx);
r += cx;
w += cx_s;
}
}
}
return Cvirtual_image(s, cx_s, cy_s, 1, palet);
}
void shp_split_frames(Cvirtual_image& image, int cblocks_x, int cblocks_y)
{
int cx = image.cx() / cblocks_x;
int cy = image.cy() / cblocks_y;
int cx_d = image.cx() / cblocks_x;
int cy_d = image.cy() * cblocks_x;
byte* d = new byte[cx_d * cy_d];
byte* w = d;
const byte* r_line = image.image();
for (int yb = 0; yb < cblocks_y; yb++)
{
for (int xb = 0; xb < cblocks_x; xb++)
{
const byte* r = r_line + cx * xb;
for (int y = 0; y < cy; y++)
{
memcpy(w, r, cx);
r += image.cx();
w += cx_d;
}
}
r_line += image.cx() * cy;
}
image.load(d, cx_d, cy_d, image.cb_pixel(), image.palet());
delete[] d;
}
void shp_split_shadows(Cvirtual_image& image)
{
int cx = image.cx();
int cy = image.cy();
int count = cx * cy;
byte* d = new byte[count << 1];
memcpy(d, image.image(), count);
byte* r = d;
byte* w = d + count;
while (count--)
{
byte& v = *r++;
if (v == 4)
{
v = 0;
*w++ = 1;
}
else
*w++ = 0;
}
image.load(d, cx, cy << 1, image.cb_pixel(), image.palet());
delete[] d;
}
#endif
/*
void shp_xor_decode_frames(Cvirtual_image& image, int c_frames)
{
int cx = image.cx();
int cy = image.cy() / c_frames;
int count = cx * cy * (c_frames - 1);
const byte* r = image.image();
byte* w = image.image_edit() + cx * cy;
while (count--)
{
*w++ ^= *r++;
}
}
void shp_xor_encode_frames(Cvirtual_image& image, int c_frames)
{
int cx = image.cx();
int cy = image.cy() / c_frames;
int count = cx * cy * c_frames;
byte* w = image.image_edit() + count;
count -= cx * cy;
const byte* r = image.image() + count;
while (count--)
{
*--w ^= *--r;
}
}
*/
static int get_left_margin(const byte* r, int cx)
{
int c = 0;
while (cx-- && !*r++)
c++;
return c;
}
static int get_right_margin(const byte* r, int cx)
{
int c = 0;
while (cx-- && !*--r)
c++;
return c;
}
static int encode4_line(const byte* r, byte* d, int cx)
{
const byte* s_end = r + cx;
byte* w = d;
while (r < s_end)
{
int v = *w++ = *r++;
if (!v)
{
int c = min(get_run_length(r - 1, s_end), 0xff);
r += c - 1;
*w++ = c;
}
}
return w - d;
}
static int decode4_line_size(const byte*& r, int cx)
{
int w = 0;
while (cx--)
{
w++;
if (!*r++)
{
cx -= *r++ - 1;
w++;
}
}
return w;
}
static int decode4_line(const byte* s, byte*& w, int cx)
{
const byte* r = s;
while (cx--)
{
if (!(*w++ = *r++))
cx -= (*w++ = *r++) - 1;
}
return r - s;
}
static int encode4(const byte* s, byte* d, int cx, int cy)
{
const byte* s_end = s + cx * cy;
const byte* r = s;
byte* w = d;
for (int y = 0; y < cy; y++)
{
int lm = min(get_left_margin(r, cx), 0xff);
int rm = min(get_right_margin(r + cx, cx - lm), 0xff);
*w++ = lm;
*w++ = rm;
w += encode4_line(r + lm, w, cx - lm - rm);
r += cx;
}
return w - d;
}
static int decode4_size(const byte*& r, int cx, int cy)
{
int w = 0;
for (int y = 0; y < cy; y++)
{
int lm = *r++;
int rm = *r++;
w += 2;
if (lm)
w += 2;
w += decode4_line_size(r, cx - lm - rm);
if (rm)
w += 2;
}
return w;
}
static int decode4(const byte* s, byte*& w, int cx, int cy)
{
const byte* r = s;
for (int y = 0; y < cy; y++)
{
int lm = *r++;
int rm = *r++;
byte* w_line = w;
w += 2;
if (lm)
{
*w++ = 0;
*w++ = lm;
}
r += decode4_line(r, w, cx - lm - rm);
if (rm)
{
*w++ = 0;
*w++ = rm;
}
*reinterpret_cast<unsigned __int16*>(w_line) = w - w_line;
}
return r - s;
}
struct t_shp4_header
{
unsigned __int16 cx;
unsigned __int16 cy;
unsigned __int16 c_frames;
};
struct t_shp4_frame_header
{
unsigned __int8 lm;
unsigned __int8 rm;
unsigned __int8 tm;
unsigned __int8 bm;
};
int shp_encode4(const Cshp_ts_file& f, byte* d)
{
const int global_cx = f.cx();
const int global_cy = f.cy();
const int c_frames = f.cf();
byte* w = d;
t_shp4_header& header = *reinterpret_cast<t_shp4_header*>(w);
header.cx = global_cx;
header.cy = global_cy;
header.c_frames = c_frames;
w += sizeof(t_shp4_header);
for (int i = 0; i < c_frames; i++)
{
const t_shp_ts_image_header& image_header = *f.get_image_header(i);
const int cx = image_header.cx;
const int cy = image_header.cy;
t_shp4_frame_header& frame_header = *reinterpret_cast<t_shp4_frame_header*>(w);
if (image_header.cx && image_header.cy)
{
frame_header.lm = image_header.x;
frame_header.tm = image_header.y;
}
else
{
frame_header.lm = min(global_cx, 0xff);
frame_header.tm = min(global_cy, 0xff);
}
if (global_cx - frame_header.lm - cx > 0xff
|| global_cy - frame_header.tm - cy > 0xff)
return 0;
frame_header.rm = global_cx - frame_header.lm - cx;
frame_header.bm = global_cy - frame_header.tm - cy;
w += sizeof(t_shp4_frame_header);
if (f.is_compressed(i))
{
Cvirtual_binary image;
decode3(f.get_image(i), image.write_start(cx * cy), cx, cy);
w += encode4(image.data(), w, cx, cy);
}
else
w += encode4(f.get_image(i), w, cx, cy);
}
return w - d;
}
int shp_decode4_size(const byte* s)
{
Cvirtual_binary d;
const byte* r = s;
const t_shp4_header& s_header = *reinterpret_cast<const t_shp4_header*>(r);
const int global_cx = s_header.cx;
const int global_cy = s_header.cy;
const int c_frames = s_header.c_frames;
r += sizeof(t_shp4_header);
int w = 0;
for (int i = 0; i < c_frames; i++)
{
const t_shp4_frame_header& frame_header = *reinterpret_cast<const t_shp4_frame_header*>(r);
int x = frame_header.lm;
int y = frame_header.tm;
int cx = global_cx - x - frame_header.rm;
int cy = global_cy - y - frame_header.bm;
r += sizeof(t_shp4_frame_header);
if (cy)
w += decode4_size(r, cx, cy);
w = w + 7 & ~7;
}
return w
+ sizeof(t_shp_ts_header)
+ c_frames * sizeof(t_shp_ts_image_header);
}
Cvirtual_binary shp_decode4(const byte* s, int cb_d)
{
Cvirtual_binary d;
const byte* r = s;
const t_shp4_header& s_header = *reinterpret_cast<const t_shp4_header*>(r);
const int global_cx = s_header.cx;
const int global_cy = s_header.cy;
const int c_frames = s_header.c_frames;
r += sizeof(t_shp4_header);
byte* w = d.write_start(cb_d ? cb_d : Cshp_ts_file::get_max_size(global_cx, global_cy, c_frames));
t_shp_ts_header& header = *reinterpret_cast<t_shp_ts_header*>(w);
header.zero = 0;
header.cx = global_cx;
header.cy = global_cy;
header.c_images = c_frames;
w += sizeof(t_shp_ts_header);
byte* w1 = w + c_frames * sizeof(t_shp_ts_image_header);
for (int i = 0; i < c_frames; i++)
{
const t_shp4_frame_header& frame_header = *reinterpret_cast<const t_shp4_frame_header*>(r);
int x = frame_header.lm;
int y = frame_header.tm;
int cx = global_cx - x - frame_header.rm;
int cy = global_cy - y - frame_header.bm;
r += sizeof(t_shp4_frame_header);
t_shp_ts_image_header& image_header = *reinterpret_cast<t_shp_ts_image_header*>(w);
image_header.x = x;
image_header.y = y;
image_header.cx = cx;
image_header.cy = cy;
image_header.compression = 3;
image_header.unknown = 0;
image_header.zero = 0;
image_header.offset = w1 - d.data();
w += sizeof(t_shp_ts_image_header);
if (cy)
r += decode4(r, w1, cx, cy);
else
image_header.offset = 0;
w1 = d.data_edit() + (w1 - d.data() + 7 & ~7);
}
assert(!cb_d || d.size() == w1 - d.data());
return cb_d ? d : Cvirtual_binary(d.data(), w1 - d.data());
}

117
3rdParty/xcc/misc/shp_ts_file.h vendored Normal file
View file

@ -0,0 +1,117 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "cc_structures.h"
#include "fname.h"
#include "palet.h"
#include "video_file.h"
#include "virtual_image.h"
class Cshp_ts_file : public Cvideo_file<t_shp_ts_header>
{
public:
Cvideo_decoder* decoder(const t_palet_entry*);
#ifndef XCC_MINIMAL_BUILD
int extract_as_pcx(const Cfname& name, t_file_type ft, const t_palet palet, bool combine_shadows = false) const;
Cvirtual_image extract_as_pcx_single(const t_palet _palet, bool combine_shadows = false) const;
#endif
bool is_valid() const;
int cb_pixel() const
{
return 1;
}
int cf() const
{
return header().c_images;
}
int cx() const
{
return header().cx;
}
int cy() const
{
return header().cy;
}
int get_x(int i) const
{
return get_image_header(i)->x;
}
int get_y(int i) const
{
return get_image_header(i)->y;
}
int get_cx(int i) const
{
return get_image_header(i)->cx;
}
int get_cy(int i) const
{
return get_image_header(i)->cy;
}
int get_cb_index() const
{
return sizeof(t_shp_ts_image_header) * cf();
}
bool is_compressed(int i) const
{
return get_image_header(i)->compression & 2;
}
const t_shp_ts_image_header* get_image_header(int i) const
{
return reinterpret_cast<const t_shp_ts_image_header*>(data() + sizeof(t_shp_ts_header) + sizeof(t_shp_ts_image_header) * i);
}
int get_offset(int i) const
{
return get_image_header(i)->offset;
}
const byte* get_image(int i) const
{
return data() + get_offset(i);
}
static int get_max_size(int cx, int cy, int c_images)
{
return sizeof(t_shp_ts_header) + (sizeof(t_shp_ts_image_header) + (2 * (cx + 1) * cy + 7 & ~7)) * c_images;
}
};
int shp_decode4_size(const byte* s);
Cvirtual_binary shp_decode4(const byte* s, int cb_d);
int shp_encode4(const Cshp_ts_file& f, byte* d);
#ifndef XCC_MINIMAL_BUILD
void shp_split_frames(Cvirtual_image& image, int cblocks_x, int cblocks_y);
void shp_split_shadows(Cvirtual_image& image);
void shp_xor_decode_frames(Cvirtual_image& image, int c_frames);
void shp_xor_encode_frames(Cvirtual_image& image, int c_frames);
#endif

18
3rdParty/xcc/misc/stdafx.h vendored Normal file
View file

@ -0,0 +1,18 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/

266
3rdParty/xcc/misc/string_conversion.cpp vendored Normal file
View file

@ -0,0 +1,266 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "string_conversion.h"
#include <ctime>
using namespace std;
int a2ip(const string& s)
{
int r = 0;
int l = 0;
for (int i = 0; i < 3; i++)
{
int c = s.find('.', l);
r = r << 8 | atoi(s.substr(l, c - l).c_str());
l = c + 1;
}
r = r << 8 | atoi(s.substr(l).c_str());
return r;
}
string ip2a(int v)
{
return n(v >> 24 & 0xff) + '.' + n(v >> 16 & 0xff) + '.' + n(v >> 8 & 0xff) + '.' + n(v & 0xff);
}
int get_net_mask(int v)
{
if (v & 0x80000000)
return 0xffffff00;
if (v & 0x40000000)
return 0xffff0000;
return 0xff000000;
}
int get_net_part(int v)
{
return v & get_net_mask(v);
}
bool atob(string s)
{
return s == "true" || s == "yes";
}
string btoa(bool v)
{
return v ? "yes" : "no";
}
string n(unsigned int v)
{
return to_string(v);
}
string n(int v)
{
return to_string(v);
}
string n(long long v)
{
return to_string(v);
}
string n(unsigned long long v)
{
return to_string(v);
}
string swsl(int l, string s)
{
while (s.size() < l)
s = ' ' + s;
return s;
}
string swsr(int l, string s)
{
while (s.size() < l)
s += ' ';
return s;
}
string nwzl(int l, unsigned int v)
{
string s = n(v);
while (s.size() < l)
s = '0' + s;
return s;
}
string nwsl(int l, unsigned int v)
{
return swsl(l, n(v));
}
string nh(int l, __int64 v)
{
string s;
int w;
while (l)
{
w = v & 0xf;
if (w > 9)
w += 7;
s = char(w + 48) + s;
v >>= 4;
l--;
}
return s;
}
string nwp(int l, unsigned int v)
{
string r;
string s = n(v);
while (1)
{
int l = s.size();
if (l > 3)
{
r = '.' + s.substr(l - 3, 3) + r;
s.erase(l - 3, 3);
}
else
{
r = s + r;
break;
}
}
return swsl(l, r);
}
void split_key(const string& key, string& name, string& value)
{
size_t i = key.find('=');
if (i == string::npos)
{
name = key;
value.erase();
}
else
{
name = key.substr(0, i);
value = key.substr(i + 1);
}
}
string tabs2spaces(const string& v)
{
string r;
for (size_t i = 0; i < v.size(); i++)
{
char c = v[i];
if (c == '\t')
{
do
r += ' ';
while (r.size() & 3);
}
else
r += c;
}
return r;
}
string time2a(time_t v)
{
char b[20];
const tm* date = gmtime(&v);
if (date)
sprintf(b, "%04d-%02d-%02d %02d:%02d:%02d", date->tm_year + 1900, date->tm_mon + 1, date->tm_mday, date->tm_hour, date->tm_min, date->tm_sec);
else
*b = 0;
return b;
}
string js_encode(const string& v)
{
string r;
for (size_t i = 0; i < v.size(); i++)
{
switch (v[i])
{
case '<':
r += "&lt;";
break;
case '\"':
case '\'':
case '\\':
r += '\\';
default:
r += v[i];
}
}
return r;
}
string trim_field(const string& v)
{
string r;
bool copy_white = false;
for (size_t i = 0; i < v.size(); i++)
{
if (isspace(v[i]))
copy_white = true;
else
{
if (copy_white)
{
if (!r.empty())
r += ' ';
copy_white = false;
}
r += v[i];
}
}
return r;
}
string trim_text(const string& v)
{
string r;
bool copy_white = false;
for (size_t i = 0; i < v.size(); )
{
int p = v.find('\n', i);
if (p == string::npos)
p = v.size();
string line = trim_field(v.substr(i, p - i));
if (line.empty())
copy_white = true;
else
{
if (copy_white)
{
if (!r.empty())
r += '\n';
copy_white = false;
}
r += line + '\n';
}
i = p + 1;
}
return r;
}

41
3rdParty/xcc/misc/string_conversion.h vendored Normal file
View file

@ -0,0 +1,41 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
int a2ip(const std::string&);
std::string ip2a(int);
int get_net_mask(int);
int get_net_part(int);
bool atob(std::string);
std::string btoa(bool);
std::string js_encode(const std::string&);
std::string n(long long);
std::string swsl(int l, std::string);
std::string swsr(int l, std::string);
std::string nwp(int l, unsigned int);
std::string nwsl(int l, unsigned int);
std::string nwzl(int l, unsigned int);
std::string nh(int l, long long v);
void split_key(const std::string& key, std::string& name, std::string& value);
std::string tabs2spaces(const std::string&);
std::string time2a(time_t);
std::string trim_field(const std::string&);
std::string trim_text(const std::string&);

56
3rdParty/xcc/misc/tmp_file.h vendored Normal file
View file

@ -0,0 +1,56 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <cc_file_sh.h>
#include <cc_structures.h>
class Ctmp_file : public Ccc_file_sh<t_tmp_header>
{
public:
bool is_valid() const
{
const t_tmp_header& h = header();
int size = get_size();
return !(sizeof(t_tmp_header) > size ||
h.cx != 24 ||
h.cy != 24 ||
h.c_tiles > 128 ||
h.zero1 ||
h.size != size ||
h.image_offset > size ||
h.zero2 ||
h.id != 0x0d1affff);
}
int get_c_tiles() const
{
return header().c_tiles;
}
const byte* get_image(int i) const
{
return data() + header().image_offset + 576 * get_index1()[i];
}
const byte* get_index1() const
{
return data() + header().index1;
}
};

185
3rdParty/xcc/misc/tmp_ts_file.cpp vendored Normal file
View file

@ -0,0 +1,185 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "tmp_ts_file.h"
#include "image_file.h"
void Ctmp_ts_file::get_rect(int& x, int& y, int& cx, int& cy) const
{
x = INT_MAX;
y = INT_MAX;
cx = INT_MIN;
cy = INT_MIN;
int bigy = INT_MIN;
int bigyval = 0;
for (int i = 0; i < get_c_tiles(); i++)
{
if (get_index()[i])
{
int height = get_height() - get_height(i);
int x_t = get_x(i);
int y_t = get_y(i) + (height * (get_cy() / 2));
int x2_t = x_t + get_cx();
int y2_t = y_t + get_cy();
if (has_extra_graphics(i))
{
int y_t_extra = get_y_extra(i) + (height * (get_cy() / 2));
int y2_t_extra = y_t_extra + get_cy_extra(i);
if (y_t_extra < y)
y = y_t_extra;
if (y2_t_extra > cy)
cy = y2_t_extra;
}
if (x_t < x)
x = x_t;
if (x2_t > cx)
cx = x2_t;
if (y_t < y)
y = y_t;
if (y2_t > cy)
cy = y2_t;
if (bigy < get_y(i))
{
bigy = get_y(i);
bigyval = get_y(i) + get_cy() + (get_height(i) * (get_cy() / 2));
if (has_extra_graphics(i))
bigyval -= get_y_extra(i);
}
}
}
cx -= x;
cy -= y;
if (cy < bigyval)
cy = bigyval;
}
void Ctmp_ts_file::draw(byte* d) const
{
int global_x, global_y, global_cx, global_cy;
get_rect(global_x, global_y, global_cx, global_cy);
memset(d, 0, global_cx * global_cy);
for (int i = 0; i < get_c_tiles(); i++)
{
if (get_index()[i])
{
int height = get_height() - get_height(i);
const byte* r = get_image(i);
byte* w_line = d + get_x(i) - global_x + global_cx * (get_y(i) - global_y + (height * (get_cy() / 2)));
int x = get_cx() / 2;
int cx = 0;
int y = 0;
for (; y < get_cy() / 2; y++)
{
cx += 4;
x -= 2;
memcpy(w_line + x, r, cx);
r += cx;
w_line += global_cx;
}
for (; y < get_cy(); y++)
{
cx -= 4;
x += 2;
memcpy(w_line + x, r, cx);
r += cx;
w_line += global_cx;
}
if (has_extra_graphics(i))
{
r += get_cx() * get_cy() / 2;
w_line = d + get_x_extra(i) - global_x + global_cx * (get_y_extra(i) - global_y + (height * (get_cy() / 2)));
int cx = get_cx_extra(i);
int cy = get_cy_extra(i);
for (y = 0; y < cy; y++)
{
byte* w = w_line;
for (int i = 0; i < cx; i++)
{
int v = *r++;
if (v)
*w = v;
w++;
}
w_line += global_cx;
}
}
}
}
}
int decode_tile(const byte* s, byte* d, int cx_d)
{
int cy = cx_d >> 1;
memset(d, 0, cx_d * cy);
const byte* r = s;
byte* w = d;
int x = cx_d / 2;
int cx = 0;
int y = 0;
for (; y < cy / 2; y++)
{
cx += 4;
x -= 2;
memcpy(w + x, r, cx);
r += cx;
w += cx_d;
}
for (; y < cy; y++)
{
cx -= 4;
x += 2;
memcpy(w + x, r, cx);
r += cx;
w += cx_d;
}
return w - d;
}
int encode_tile(const byte* s, byte* d, int cx_s)
{
int cy = cx_s >> 1;
const byte* r = s;
byte* w = d;
int x = cx_s / 2;
int cx = 0;
int y = 0;
for (; y < cy / 2; y++)
{
cx += 4;
x -= 2;
memcpy(w, r + x, cx);
r += cx_s;
w += cx;
}
for (; y < cy; y++)
{
cx -= 4;
x += 2;
memcpy(w, r + x, cx);
r += cx_s;
w += cx;
}
return w - d;
}
void Ctmp_ts_file::decode(void* d) const
{
draw(reinterpret_cast<byte*>(d));
}

210
3rdParty/xcc/misc/tmp_ts_file.h vendored Normal file
View file

@ -0,0 +1,210 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <cc_file_sh.h>
#include <cc_structures.h>
#include "fname.h"
#include "image_file.h"
#include "palet.h"
class Ctmp_ts_file : public Cimage_file<t_tmp_ts_header>
{
public:
void decode(void*) const;
void draw(byte* d) const;
void get_rect(int& x, int& y, int& cx, int& cy) const;
bool is_valid() const
{
const t_tmp_ts_header& h = header();
int size = get_size();
if (sizeof(t_tmp_ts_header) > size ||
!h.cblocks_x || !h.cblocks_y ||
h.cx != 48 && h.cx != 60 ||
2 * h.cy != h.cx ||
sizeof(t_tmp_ts_header) + 4 * get_c_tiles() > size)
return false;
for (int i = 0; i < min(get_c_tiles(), 64); i++)
{
if (get_index()[i])
{
const t_tmp_image_header& image_header = *get_image_header(i);
}
}
return true;
}
int cb_pixel() const
{
return 1;
}
int cx() const
{
int x, y, cx, cy;
get_rect(x, y, cx, cy);
return cx;
}
int cy() const
{
int x, y, cx, cy;
get_rect(x, y, cx, cy);
return cy;
}
int get_c_tiles() const
{
return get_cblocks_x() * get_cblocks_y();
}
int get_cblocks_x() const
{
return header().cblocks_x;
}
int get_cblocks_y() const
{
return header().cblocks_y;
}
const t_tmp_image_header* get_image_header(int i) const
{
return reinterpret_cast<const t_tmp_image_header*>(data() + get_index()[i]);
}
int get_x(int i) const
{
return get_image_header(i)->x;
}
int get_y(int i) const
{
return get_image_header(i)->y;
}
int get_cx() const
{
return header().cx;
}
int get_cy() const
{
return header().cy;
}
int get_x_extra(int i) const
{
return get_image_header(i)->x_extra;
}
int get_height() const
{
int height = 0;
for (int i = 0; i < get_c_tiles(); i++)
{
if (get_index()[i])
{
if (get_height(i) > height)
height = get_height(i);
}
}
return height;
}
int get_height(int i) const
{
return get_image_header(i)->height;
}
/*
int get_ramp_type(int i) const
{
return get_image_header(i)->ramp_type;
}
int get_terrain_type(int i) const
{
return get_image_header(i)->terrain_type;
}
*/
int get_y_extra(int i) const
{
return get_image_header(i)->y_extra;
}
int get_cx_extra(int i) const
{
return get_image_header(i)->cx_extra;
}
int get_cy_extra(int i) const
{
return get_image_header(i)->cy_extra;
}
bool has_extra_graphics(int i) const
{
return get_image_header(i)->has_extra_data;
}
int get_cb_diamond() const
{
return get_cx() * get_cy() >> 1;
}
int get_cb_extra_data(int i) const
{
return get_cx_extra(i) * get_cy_extra(i);
}
const byte* get_image(int i) const
{
return reinterpret_cast<const byte*>(get_image_header(i) + 1);
}
const byte* get_z_image(int i) const
{
int a = get_index()[i] + get_image_header(i)->z_ofs;
int b = get_image(i) + get_cb_diamond() - data();
assert(a == b);
return data() + get_index()[i] + get_image_header(i)->z_ofs;
}
const byte* get_extra_data(int i) const
{
return data() + get_index()[i] + get_image_header(i)->extra_ofs;
}
const byte* get_extra_z_data(int i) const
{
return data() + get_index()[i] + get_image_header(i)->extra_z_ofs;
}
const int* get_index() const
{
return reinterpret_cast<const int*>(data() + sizeof(t_tmp_ts_header));
}
};
int decode_tile(const byte* s, byte* d, int cx_d);
int encode_tile(const byte* s, byte* d, int cx_s);
int tmp_ts_file_write(const byte* s, byte* d, int cx, int cy);

22
3rdParty/xcc/misc/vartypes.h vendored Normal file
View file

@ -0,0 +1,22 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include <cstddef>
using byte = unsigned char;
// using std::byte;

29
3rdParty/xcc/misc/video_decoder.cpp vendored Normal file
View file

@ -0,0 +1,29 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "video_decoder.h"
Cvideo_decoder::~Cvideo_decoder()
{
}
const t_palet_entry* Cvideo_decoder::palet() const
{
return NULL;
}

44
3rdParty/xcc/misc/video_decoder.h vendored Normal file
View file

@ -0,0 +1,44 @@
/*
XCC Utilities and Library
Copyright (C) 2004 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "palet.h"
class Cvideo_decoder
{
public:
virtual int cb_pixel() const = 0;
virtual int cf() const = 0;
virtual int cx() const = 0;
virtual int cy() const = 0;
virtual int decode(void* d) = 0;
virtual const t_palet_entry* palet() const;
virtual int seek(int f) = 0;
virtual ~Cvideo_decoder();
int cb_image() const
{
return cb_pixel() * cx() * cy();
}
int cb_video() const
{
return cf() * cb_image();
}
};

20
3rdParty/xcc/misc/video_file.cpp vendored Normal file
View file

@ -0,0 +1,20 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "video_file.h"

48
3rdParty/xcc/misc/video_file.h vendored Normal file
View file

@ -0,0 +1,48 @@
/*
XCC Utilities and Library
Copyright (C) 2004 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "cc_file_sh.h"
#include "palet.h"
#include "video_decoder.h"
template <class T>
class Cvideo_file : public Ccc_file_sh<T>
{
public:
virtual int cb_pixel() const = 0;
virtual int cf() const = 0;
virtual int cx() const = 0;
virtual int cy() const = 0;
int cb_image() const
{
return cb_pixel() * cx() * cy();
}
int cb_video() const
{
return cf() * cb_image();
}
virtual const t_palet_entry* palet() const
{
return NULL;
}
};

71
3rdParty/xcc/misc/virtual_audio.cpp vendored Normal file
View file

@ -0,0 +1,71 @@
/*
XCC Utilities and Library
Copyright (C) 2001 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "virtual_audio.h"
#include "aud_file_write.h"
#include "wav_file.h"
Cvirtual_audio::Cvirtual_audio()
{
}
Cvirtual_audio::~Cvirtual_audio()
{
}
void Cvirtual_audio::load(Cvirtual_file f, int c_samples, int samplerate, int cb_sample, int c_channels)
{
mc_samples = c_samples;
m_samplerate = samplerate;
mcb_sample = cb_sample;
mc_channels = c_channels;
m_f = f;
m_f.compact();
}
Cvirtual_file Cvirtual_audio::save_as_aud() const
{
return aud_file_write(audio(), cb_audio(), c_samples(), samplerate(), c_channels());
}
int Cvirtual_audio::save_as_aud(string fname) const
{
return aud_file_write(fname, audio(), cb_audio(), c_samples(), samplerate(), c_channels());
}
Cvirtual_file Cvirtual_audio::save_as_wav_ima_adpcm() const
{
return wav_ima_adpcm_file_write(audio(), cb_audio(), c_samples(), samplerate(), c_channels());
}
int Cvirtual_audio::save_as_wav_ima_adpcm(string fname) const
{
return wav_ima_adpcm_file_write(fname, audio(), cb_audio(), c_samples(), samplerate(), c_channels());
}
Cvirtual_file Cvirtual_audio::save_as_wav_pcm() const
{
return wav_pcm_file_write(audio(), cb_audio(), samplerate(), cb_sample(), c_channels());
}
int Cvirtual_audio::save_as_wav_pcm(string fname) const
{
return wav_pcm_file_write(fname, audio(), cb_audio(), samplerate(), cb_sample(), c_channels());
}

71
3rdParty/xcc/misc/virtual_audio.h vendored Normal file
View file

@ -0,0 +1,71 @@
/*
XCC Utilities and Library
Copyright (C) 2001 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "virtual_file.h"
class Cvirtual_audio
{
public:
void load(Cvirtual_file f, int c_samples, int samplerate, int cb_sample, int c_channels);
Cvirtual_file save_as_aud() const;
int save_as_aud(string fname) const;
Cvirtual_file save_as_wav_ima_adpcm() const;
int save_as_wav_ima_adpcm(string fname) const;
Cvirtual_file save_as_wav_pcm() const;
int save_as_wav_pcm(string fname) const;
Cvirtual_audio();
~Cvirtual_audio();
const __int16* audio() const
{
return reinterpret_cast<const __int16*>(m_f.data());
}
int cb_audio() const
{
return mc_samples * mcb_sample * mc_channels;
}
int c_samples() const
{
return mc_samples;
}
int samplerate() const
{
return m_samplerate;
}
int cb_sample() const
{
return mcb_sample;
}
int c_channels() const
{
return mc_channels;
}
private:
Cvirtual_file m_f;
int mc_samples;
int m_samplerate;
int mcb_sample;
int mc_channels;
};

165
3rdParty/xcc/misc/virtual_binary.cpp vendored Normal file
View file

@ -0,0 +1,165 @@
/*
XCC Utilities and Library
Copyright (C) 2001 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include <virtual_binary.h>
#include "file32.h"
Cvirtual_binary_source::Cvirtual_binary_source(const void* d, size_t cb_d, const std::shared_ptr<const void>& source)
{
if (source)
{
m_data = const_cast<byte*>(reinterpret_cast<const byte*>(d));
m_size = cb_d;
m_source = source;
}
else
{
m_data = new byte[cb_d];
m_size = cb_d;
if (d)
memcpy(m_data, d, cb_d);
}
mc_references = 1;
}
Cvirtual_binary_source* Cvirtual_binary_source::attach()
{
if (this)
mc_references++;
return this;
}
void Cvirtual_binary_source::detach()
{
if (!this || --mc_references)
return;
if (!m_source)
delete[] m_data;
delete this;
}
Cvirtual_binary_source* Cvirtual_binary_source::pre_edit()
{
if (mc_references == 1 && !m_source)
return this;
Cvirtual_binary_source* t = new Cvirtual_binary_source(m_data, m_size, NULL);
detach();
return t;
}
Cvirtual_binary::Cvirtual_binary()
{
m_source = NULL;
}
Cvirtual_binary::Cvirtual_binary(const Cvirtual_binary& v)
{
m_source = v.m_source->attach();
}
Cvirtual_binary::Cvirtual_binary(const void* d, size_t cb_d)
{
m_source = new Cvirtual_binary_source(d, cb_d);
}
Cvirtual_binary::Cvirtual_binary(const void* d, size_t cb_d, const std::shared_ptr<void>& source)
{
m_source = new Cvirtual_binary_source(d, cb_d, source);
}
Cvirtual_binary::Cvirtual_binary(data_ref d)
{
m_source = new Cvirtual_binary_source(d.data(), d.size());
}
Cvirtual_binary::Cvirtual_binary(const string& fname, bool use_mm)
{
m_source = NULL;
load(fname, use_mm);
}
Cvirtual_binary::~Cvirtual_binary()
{
m_source->detach();
}
const Cvirtual_binary& Cvirtual_binary::operator=(const Cvirtual_binary& v)
{
if (this != &v)
{
m_source->detach();
m_source = v.m_source->attach();
}
return *this;
}
int Cvirtual_binary::save(const string& fname) const
{
return data() ? file32_write(fname, data(), size()) : 1;
}
int Cvirtual_binary::load(const string& fname, bool use_mm)
{
if (use_mm)
*this = file32_read(fname);
else
{
Cvirtual_binary d = file32_read(fname);
*this = Cvirtual_binary(d.data(), d.size());
}
return !data();
}
void Cvirtual_binary::clear()
{
m_source->detach();
m_source = NULL;
}
void Cvirtual_binary::memset(int v)
{
::memset(data_edit(), v, size());
}
size_t Cvirtual_binary::read(void* d) const
{
memcpy(d, data(), size());
return size();
}
byte* Cvirtual_binary::write_start(size_t cb_d)
{
if (data() && size() == cb_d)
return data_edit();
m_source->detach();
m_source = new Cvirtual_binary_source(NULL, cb_d);
return data_edit();
}
void Cvirtual_binary::write(const void* d, size_t cb_d)
{
memcpy(write_start(cb_d), d, cb_d);
}
Cvirtual_binary Cvirtual_binary::sub_bin(size_t offset, size_t size) const
{
assert(offset >= 0 && offset + size <= Cvirtual_binary::size());
return data() ? Cvirtual_binary(data() + offset, size, std::make_shared<Cvirtual_binary>(*this)) : *this;
}

140
3rdParty/xcc/misc/virtual_binary.h vendored Normal file
View file

@ -0,0 +1,140 @@
/*
XCC Utilities and Library
Copyright (C) 2001 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <cassert>
#include <memory>
#include <string>
#include <vartypes.h>
#include <xcc/data_ref.h>
using namespace std;
class Cvirtual_binary_source
{
public:
Cvirtual_binary_source(const void* d, size_t cb_d, const std::shared_ptr<const void>& source = NULL);
Cvirtual_binary_source* attach();
void detach();
Cvirtual_binary_source* pre_edit();
const byte* data() const
{
return m_data;
}
const byte* data_end() const
{
return data() + size();
}
byte* data_edit()
{
assert(mc_references == 1 && !m_source);
return m_data;
}
size_t size() const
{
return m_size;
}
void size(size_t v)
{
assert(mc_references == 1 && !m_source && v <= m_size);
m_size = v;
}
bool unique() const
{
return mc_references == 1;
}
private:
byte* m_data;
size_t m_size;
int mc_references;
std::shared_ptr<const void> m_source;
};
class Cvirtual_binary
{
public:
Cvirtual_binary sub_bin(size_t offset, size_t size) const;
int save(const string& fname) const;
int load(const string& fname, bool use_mm = true);
void clear();
void memset(int v);
size_t read(void* d) const;
byte* write_start(size_t cb_d);
void write(const void* d, size_t cb_d);
const Cvirtual_binary& operator=(const Cvirtual_binary& v);
Cvirtual_binary();
Cvirtual_binary(const Cvirtual_binary&);
Cvirtual_binary(data_ref);
Cvirtual_binary(const void*, size_t);
Cvirtual_binary(const void*, size_t, const std::shared_ptr<void>& source);
explicit Cvirtual_binary(const string& fname, bool use_mm = true);
~Cvirtual_binary();
const byte* data() const
{
return m_source ? m_source->data() : NULL;
}
const byte* data_end() const
{
return m_source ? m_source->data_end() : NULL;
}
const byte* begin() const
{
return data();
}
const byte* end() const
{
return data_end();
}
byte* data_edit()
{
assert(m_source);
m_source = m_source->pre_edit();
return m_source->data_edit();
}
byte* mutable_end()
{
return data_edit() + size();
}
size_t size() const
{
return m_source ? m_source->size() : 0;
}
void set_size(size_t v)
{
assert(m_source);
m_source = m_source->pre_edit();
m_source->size(v);
}
private:
Cvirtual_binary_source* m_source;
};

109
3rdParty/xcc/misc/virtual_file.cpp vendored Normal file
View file

@ -0,0 +1,109 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "virtual_file.h"
#include "file32.h"
Cvirtual_file::Cvirtual_file()
{
}
Cvirtual_file::Cvirtual_file(const Cvirtual_binary& d)
{
write(d);
}
void Cvirtual_file::clear()
{
m_data.clear();
}
void Cvirtual_file::compact()
{
if (m_data.size() == 1)
return;
Cvirtual_binary t = read();
clear();
write(t);
}
const byte* Cvirtual_file::data() const
{
if (m_data.size() != 1)
return NULL;
return m_data.begin()->data();
}
int Cvirtual_file::size() const
{
int r = 0;
for (auto& i : m_data)
r += i.size();
return r;
}
int Cvirtual_file::save(const string& fname) const
{
Cfile32 f;
int error = f.open_write(fname);
if (!error)
{
for (auto& i : m_data)
error = f.write(i);
}
return error;
}
int Cvirtual_file::load(const string& fname)
{
clear();
Cvirtual_binary t;
int error = t.load(fname);
if (!error)
write(t);
return error;
}
Cvirtual_binary Cvirtual_file::read() const
{
if (m_data.size() == 1)
return *m_data.begin();
Cvirtual_binary r;
read(r.write_start(size()));
return r;
}
int Cvirtual_file::read(void* d) const
{
byte* w = reinterpret_cast<byte*>(d);
for (auto& i : m_data)
w += i.read(w);
return w - reinterpret_cast<byte*>(d);
}
void Cvirtual_file::write(const Cvirtual_binary& d)
{
m_data.push_back(d);
}
void Cvirtual_file::write(const void* d, int cb_d)
{
write(Cvirtual_binary(d, cb_d));
}

44
3rdParty/xcc/misc/virtual_file.h vendored Normal file
View file

@ -0,0 +1,44 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <list>
#include <virtual_binary.h>
using namespace std;
class Cvirtual_file
{
public:
int save(const string& fname) const;
int load(const string& fname);
void clear();
void compact();
const byte* data() const;
int size() const;
Cvirtual_binary read() const;
int read(void* d) const;
void write(const Cvirtual_binary& d);
void write(const void* d, int cb_d);
Cvirtual_file();
Cvirtual_file(const Cvirtual_binary& d);
private:
using t_data = list<Cvirtual_binary>;
t_data m_data;
};

332
3rdParty/xcc/misc/virtual_image.cpp vendored Normal file
View file

@ -0,0 +1,332 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include <windows.h>
#include <gdiplus.h>
#include <shlwapi.h>
#ifndef XCC_MINIMAL_BUILD
#include "dds_file.h"
#include "image_file.h"
#include "jpeg_file.h"
#include "pcx_file.h"
#include "pcx_file_write.h"
#include "png_file.h"
#include "tga_file.h"
#endif
#include "virtual_image.h"
using namespace Gdiplus;
Cvirtual_image::Cvirtual_image(const Cvirtual_binary& image, int cx, int cy, int cb_pixel, const t_palet_entry* palet, bool inflate)
{
load(image, cx, cy, cb_pixel, palet, inflate);
}
Cvirtual_image::Cvirtual_image(const void* image, int cx, int cy, int cb_pixel, const t_palet_entry* palet, bool inflate)
{
load(image, cx, cy, cb_pixel, palet, inflate);
}
const Cvirtual_image& Cvirtual_image::palet(const t_palet_entry* palet, bool inflate)
{
if (palet)
{
memcpy(m_palet.write_start(sizeof(t_palet)), palet, sizeof(t_palet));
if (inflate)
convert_palet_18_to_24(reinterpret_cast<t_palet_entry*>(m_palet.data_edit()));
}
else
m_palet.clear();
return *this;
}
void Cvirtual_image::load(const Cvirtual_binary& image, int cx, int cy, int cb_pixel, const t_palet_entry* p, bool inflate)
{
assert(cb_pixel == 1 || cb_pixel == 3 || cb_pixel == 4);
m_cx = cx;
m_cy = cy;
mcb_pixel = cb_pixel;
if (image.size() == cb_image())
m_image = image;
else
m_image.write_start(cb_image());
palet(p, inflate);
}
void Cvirtual_image::load(const void* image, int cx, int cy, int cb_pixel, const t_palet_entry* p, bool inflate)
{
assert(cb_pixel == 1 || cb_pixel == 3 || cb_pixel == 4);
m_cx = cx;
m_cy = cy;
mcb_pixel = cb_pixel;
m_image.write_start(cb_image());
if (image)
memcpy(m_image.data_edit(), image, cb_image());
palet(p, inflate);
}
#ifndef XCC_MINIMAL_BUILD
int Cvirtual_image::load(const Cvirtual_binary& s)
{
Cdds_file dds_f;
Cpcx_file pcx_f;
Cpng_file png_f;
Ctga_file tga_f;
if (dds_f.load(s), dds_f.is_valid())
*this = dds_f.vimage();
else if (pcx_f.load(s), pcx_f.is_valid())
*this = pcx_f.vimage();
else if (png_f.load(s), png_f.is_valid())
return png_f.decode(*this);
else if (tga_f.load(s), tga_f.is_valid())
return tga_f.decode(*this);
else
{
IStream* is = SHCreateMemStream(s.data(), s.size());
Gdiplus::Bitmap bmp(is);
is->Release();
if (bmp.GetLastStatus() != Ok)
return 1;
PixelFormat pf = bmp.GetPixelFormat();
if (bmp.GetPixelFormat() & PixelFormatIndexed)
{
load(NULL, bmp.GetWidth(), bmp.GetHeight(), 1, NULL);
BitmapData d;
d.Stride = bmp.GetWidth();
d.Scan0 = image_edit();
bmp.LockBits(NULL, ImageLockModeRead | ImageLockModeUserInputBuf, PixelFormat8bppIndexed, &d);
bmp.UnlockBits(&d);
}
else
{
load(NULL, bmp.GetWidth(), bmp.GetHeight(), 3, NULL);
BitmapData d;
d.Stride = bmp.GetWidth() * 3;
d.Scan0 = image_edit();
bmp.LockBits(NULL, ImageLockModeRead | ImageLockModeUserInputBuf, PixelFormat24bppRGB, &d);
bmp.UnlockBits(&d);
swap_rb();
}
}
return 0;
}
int Cvirtual_image::load(const Cvirtual_file& f)
{
return load(f.read());
}
int Cvirtual_image::load(const string& fname)
{
Cvirtual_binary s;
int error = s.load(fname);
if (!error)
error = load(s);
return error;
}
int Cvirtual_image::save(Cvirtual_file& f, t_file_type ft) const
{
return image_file_write(f, ft, image(), palet(), m_cx, m_cy);
}
Cvirtual_file Cvirtual_image::save(t_file_type ft) const
{
return image_file_write(ft, image(), palet(), m_cx, m_cy);
}
int Cvirtual_image::save(const string& fname, t_file_type ft) const
{
return image_file_write(fname, ft, image(), palet(), m_cx, m_cy);
}
void Cvirtual_image::swap_rb()
{
int count = m_cx * m_cy;
t_palet_entry* r = reinterpret_cast<t_palet_entry*>(m_image.data_edit());
while (count--)
{
swap(r->r, r->b);
r++;
}
}
static void flip_frame(const byte* s, byte* d, int cx, int cy, int cb_pixel)
{
int cb_line = cx * cb_pixel;
const byte* r = s;
byte* w = d + cb_line * cy;
while (cy--)
{
w -= cb_line;
memcpy(w, r, cb_line);
r += cb_line;
}
}
void Cvirtual_image::flip()
{
Cvirtual_binary t = m_image;
flip_frame(t.data(), image_edit(), cx(), cy(), cb_pixel());
}
void Cvirtual_image::cb_pixel(int cb_pixel, const t_palet_entry* palet)
{
if (cb_pixel < mcb_pixel)
decrease_color_depth(cb_pixel, palet);
else if (cb_pixel > mcb_pixel)
increase_color_depth(cb_pixel);
}
void Cvirtual_image::decrease_color_depth(int new_cb_pixel, const t_palet_entry* palet)
{
if (new_cb_pixel == 3)
{
remove_alpha();
return;
}
assert(new_cb_pixel == 1);
int old_cb_pixel = cb_pixel();
Cvirtual_binary t = m_image;
load(NULL, cx(), cy(), new_cb_pixel, palet);
byte* w = image_edit();
int count = m_cx * m_cy;
if (old_cb_pixel == 3)
{
const t_palet_entry* r = reinterpret_cast<const t_palet_entry*>(t.data());
while (count--)
{
*w++ = find_color(r->r, r->g, r->b, palet);
r++;
}
}
else
{
assert(old_cb_pixel == 4);
const t_palet32entry* r = reinterpret_cast<const t_palet32entry*>(t.data());
while (count--)
{
*w++ = r->a < 0x80 ? find_color(r->r, r->g, r->b, palet) : 0;
r++;
}
}
}
static t_palet32entry p32e(int r, int g, int b, int a = 0)
{
t_palet32entry e;
e.r = r;
e.g = g;
e.b = b;
e.a = a;
return e;
}
static t_palet32entry p32e(t_palet_entry e)
{
return p32e(e.r, e.g, e.b);
}
static t_palet32entry p32e(const t_palet palet, int i)
{
return i ? p32e(palet[i]) : p32e(0x80, 0x80, 0x80, 0xff);
}
void Cvirtual_image::increase_color_depth(int new_cb_pixel)
{
if (cb_pixel() == 3)
{
if (new_cb_pixel == 4)
add_alpha();
return;
}
assert(cb_pixel() == 1);
Cvirtual_image t = *this;
const byte* r = t.image();
load(NULL, cx(), cy(), new_cb_pixel, NULL);
int count = m_cx * m_cy;
if (cb_pixel() == 3)
{
t_palet_entry* w = reinterpret_cast<t_palet_entry*>(image_edit());
while (count--)
*w++ = t.palet()[*r++];
}
else
{
assert(cb_pixel() == 4);
t_palet32entry* w = reinterpret_cast<t_palet32entry*>(image_edit());
while (count--)
*w++ = p32e(t.palet(), *r++);
}
}
void Cvirtual_image::add_alpha()
{
assert(cb_pixel() == 3);
Cvirtual_binary t = m_image;
load(NULL, cx(), cy(), 4, NULL);
int count = m_cx * m_cy;
const byte* r = t.data();
byte* w = image_edit();
while (count--)
{
*w++ = *r++;
*w++ = *r++;
*w++ = *r++;
*w++ = 0;
}
}
void Cvirtual_image::remove_alpha()
{
if (cb_pixel() != 4)
return;
Cvirtual_binary t = m_image;
load(NULL, cx(), cy(), 3, NULL);
int count = m_cx * m_cy;
const byte* r = t.data();
byte* w = image_edit();
while (count--)
{
*w++ = *r++;
*w++ = *r++;
*w++ = *r++;
r++;
}
}
void Cvirtual_image::increase_palet_depth()
{
assert(false);
Cvirtual_binary t = m_palet;
const t_palet_entry* s = reinterpret_cast<const t_palet_entry*>(t.data());
t_palet_entry* d = reinterpret_cast<t_palet_entry*>(t.data_edit());
for (int i = 0; i < 256; i++)
{
d[i].r = (s[i].r & 63) * 255 / 63;
d[i].g = (s[i].g & 63) * 255 / 63;
d[i].b = (s[i].b & 63) * 255 / 63;
}
}
#endif

124
3rdParty/xcc/misc/virtual_image.h vendored Normal file
View file

@ -0,0 +1,124 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "cc_file.h"
#include "palet.h"
#include "virtual_file.h"
class Cvirtual_image
{
public:
const Cvirtual_image& palet(const t_palet_entry* palet, bool inflate = false);
void remove_alpha();
void add_alpha();
void cb_pixel(int cb_pixel, const t_palet_entry* palet = NULL);
void decrease_color_depth(int cb_pixel, const t_palet_entry* palet = NULL);
void increase_color_depth(int cb_pixel);
void increase_palet_depth();
void flip();
int get_clipboard();
int set_clipboard() const;
int load();
int save() const;
void load(const Cvirtual_binary& image, int cx, int cy, int cb_pixel, const t_palet_entry* palet, bool inflate = false);
void load(const void* image, int cx, int cy, int cb_pixel, const t_palet_entry* palet, bool inflate = false);
int load(const Cvirtual_binary& s);
int load(const Cvirtual_file& f);
int load(const string& fname);
int save(Cvirtual_file& f, t_file_type ft) const;
Cvirtual_file save(t_file_type ft) const;
int save(const string& fname, t_file_type ft) const;
void swap_rb();
Cvirtual_image() = default;
Cvirtual_image(const Cvirtual_binary& image, int cx, int cy, int cb_pixel, const t_palet_entry* palet = NULL, bool inflate = false);
Cvirtual_image(const void* image, int cx, int cy, int cb_pixel, const t_palet_entry* palet = NULL, bool inflate = false);
const byte* image() const
{
return m_image.data();
}
byte* image_edit()
{
return m_image.data_edit();
}
int cx() const
{
return m_cx;
}
int cy() const
{
return m_cy;
}
int cb_pixel() const
{
return mcb_pixel;
}
const t_palet_entry* palet() const
{
return reinterpret_cast<const t_palet_entry*>(m_palet.data());
}
int cb_image() const
{
return m_cx * m_cy * mcb_pixel;
}
int ofs8(int x, int y) const
{
return x + m_cx * y;
}
int ofs24(int x, int y) const
{
return ofs8(x, y) * 3;
}
int pixel8(int x, int y) const
{
return m_image.data()[ofs8(x, y)];
}
void pixel8(int x, int y, int v)
{
m_image.data_edit()[ofs8(x, y)] = v;
}
t_palet_entry pixel24(int x, int y) const
{
return reinterpret_cast<const t_palet_entry*>(m_image.data())[ofs8(x, y)];
}
void pixel24(int x, int y, t_palet_entry v)
{
reinterpret_cast<t_palet_entry*>(m_image.data_edit())[ofs8(x, y)] = v;
}
private:
Cvirtual_binary m_image;
Cvirtual_binary m_palet;
int m_cx = 0;
int m_cy = 0;
int mcb_pixel = 0;
};

93
3rdParty/xcc/misc/virtual_tfile.cpp vendored Normal file
View file

@ -0,0 +1,93 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "virtual_tfile.h"
void Cvirtual_tfile::load_data(const Cvirtual_binary s)
{
m_data = s;
pos = 0;
}
string Cvirtual_tfile::read_line()
{
assert(data());
const int first_non_ws = pos;
int last_non_ws;
while (pos < size())
{
switch (data()[pos++])
{
case '\r':
last_non_ws = pos - 2;
if (pos < size() && data()[pos] == '\n')
pos++;
return string(data() + first_non_ws, last_non_ws - first_non_ws + 1);
case '\n':
last_non_ws = pos - 2;
return string(data() + first_non_ws, last_non_ws - first_non_ws + 1);
}
}
last_non_ws = size() - 1;
return string(data() + first_non_ws, last_non_ws - first_non_ws + 1);
}
string Cvirtual_tfile::read_line(bool remove_ws)
{
if (!remove_ws)
return read_line();
assert(data());
int first_non_ws;
int last_non_ws;
while (pos < size())
{
switch (data()[pos++])
{
case '\r':
if (pos < size() && data()[pos] == '\n')
pos++;
case '\n':
return "";
case '\t':
case ' ':
break;
default:
first_non_ws = pos - 1;
last_non_ws = pos - 2;
while (pos < size())
{
switch (data()[pos++])
{
case '\r':
if (pos < size() && data()[pos] == '\n')
pos++;
case '\n':
return string(data() + first_non_ws, last_non_ws - first_non_ws + 1);
case '\t':
case ' ':
break;
default:
last_non_ws = pos - 1;
}
}
return string(data() + first_non_ws, last_non_ws - first_non_ws + 1);
}
}
return "";
}

53
3rdParty/xcc/misc/virtual_tfile.h vendored Normal file
View file

@ -0,0 +1,53 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <vartypes.h>
#include <virtual_binary.h>
class Cvirtual_tfile
{
private:
Cvirtual_binary m_data;
int pos;
const char* data() const
{
return reinterpret_cast<const char*>(m_data.data());
}
int size() const
{
return m_data.size();
}
public:
string read_line();
string read_line(bool remove_ws);
void load_data(const Cvirtual_binary s);
bool eof() const
{
return pos >= size();
}
void seek(int ipos)
{
pos = ipos;
}
};

676
3rdParty/xcc/misc/vxl_file.cpp vendored Normal file
View file

@ -0,0 +1,676 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "vxl_file.h"
#include "file32.h"
#include "image_file.h"
#ifndef XCC_MINIMAL_BUILD
#include "multi_line.h"
#include "pcx_decode.h"
#include "pcx_file_write.h"
#endif
#include "string_conversion.h"
bool Cvxl_file::is_valid() const
{
int size = get_size();
const t_vxl_header& h = header();
if (sizeof(t_vxl_header) > size ||
strcmp(h.id, vxl_id) ||
h.one != 1 ||
h.c_section_headers != h.c_section_tailers ||
h.size != size - sizeof(t_vxl_header) - h.c_section_headers * sizeof(t_vxl_section_header) - h.c_section_tailers * sizeof(t_vxl_section_tailer) ||
h.unknown != 0x1f10)
return false;
/*
for (int i = 0; i < header.c_section_headers; i++)
{
const t_vxl_section_header& section_header = *get_section_header(i);
const t_vxl_section_tailer& section_tailer = *get_section_tailer(i);
if (section_header.one != 1 ||
section_header.zero ||
section_tailer.span_end_ofs - section_tailer.span_start_ofs != section_tailer.span_data_ofs - section_tailer.span_end_ofs)
return false;
}
*/
return true;
}
#ifndef XCC_MINIMAL_BUILD
int Cvxl_file::extract_as_pcx(const Cfname& name, t_file_type ft, const t_palet _palet) const
{
t_palet palet;
memcpy(palet, _palet, sizeof(t_palet));
convert_palet_18_to_24(palet);
const t_vxl_section_tailer& section_tailer = *get_section_tailer(0);
const int cx = section_tailer.cx;
const int cy = section_tailer.cy;
const int cz = section_tailer.cz;
Cvirtual_binary s;
for (int i = 0; i < cz; i++)
{
memset(s.write_start(cx * cy), 0, cx * cy);
int j = 0;
for (int y = 0; y < cy; y++)
{
for (int x = 0; x < cx; x++)
{
const byte* r = get_span_data(0, j);
if (r)
{
int z = 0;
while (z < cz)
{
z += *r++;
int c = *r++;
while (c--)
{
if (i == z)
s.data_edit()[x + cx * y] = *r;
r += 2;
z++;
}
r++;
}
}
j++;
}
}
Cfname t = name;
t.set_title(name.get_ftitle() + " " + nwzl(4, i));
int error = image_file_write(t, ft, s.data(), palet, cx, cy);
if (error)
return error;
}
return 0;
}
#endif
ostream& Cvxl_file::extract_as_text(ostream& os) const
{
for (int i = 0; i < get_c_section_headers(); i++)
{
const t_vxl_section_tailer& section_tailer = *get_section_tailer(i);
const int cx = section_tailer.cx;
const int cy = section_tailer.cy;
const int cz = section_tailer.cz;
int j = 0;
for (int y = 0; y < cy; y++)
{
for (int x = 0; x < cx; x++)
{
const byte* r = get_span_data(i, j);
if (r)
{
int z = 0;
while (z < cz)
{
z += *r++;
int c = *r++;
while (c--)
{
os << i << ',' << x << ',' << y << ',' << z << ',' << static_cast<int>(*r++) << ',' << static_cast<int>(*r++) << endl;
z++;
}
r++;
}
}
j++;
}
}
}
return os;
}
enum
{
vi_header,
vi_body,
vi_tailer,
vi_palet,
vi_color,
vi_surface_normal,
vi_x,
vi_y,
vi_z,
vi_cx,
vi_cy,
vi_cz,
vi_id,
vi_red,
vi_green,
vi_blue,
vi_x_min,
vi_y_min,
vi_z_min,
vi_x_max,
vi_y_max,
vi_z_max
};
#ifndef XCC_MINIMAL_BUILD
int Cvxl_file::extract_as_xif(const string& name) const
{
Cxif_key k;
Cxif_key& header = k.open_key_write(vi_header);
Cxif_key& palet = header.open_key_write(vi_palet);
int i;
for (i = 0; i < 256; i++)
{
Cxif_key& palet_entry = palet.open_key_write(i);
palet_entry.set_value_int(vi_red, get_palet()[i].r);
palet_entry.set_value_int(vi_green, get_palet()[i].g);
palet_entry.set_value_int(vi_blue, get_palet()[i].b);
}
Cxif_key& body = k.open_key_write(vi_body);
for (i = 0; i < get_c_section_headers(); i++)
{
const t_vxl_section_header& section_header = *get_section_header(i);
const t_vxl_section_tailer& section_tailer = *get_section_tailer(i);
const int cx = section_tailer.cx;
const int cy = section_tailer.cy;
const int cz = section_tailer.cz;
Cxif_key& section = body.open_key_write(i);
Cxif_key& header = section.open_key_write(vi_header);
header.set_value_string(vi_id, section_header.id);
Cxif_key& body = section.open_key_write(vi_body);
int j = 0;
for (int y = 0; y < cy; y++)
{
Cxif_key& yi = body.open_key_write(y);
for (int x = 0; x < cx; x++)
{
Cxif_key& xi = yi.open_key_write(x);
const byte* r = get_span_data(i, j);
if (r)
{
int z = 0;
while (z < cz)
{
z += *r++;
int c = *r++;
while (c--)
{
Cxif_key& zi = xi.open_key_write(z);
zi.set_value_int(vi_color, *r++);
zi.set_value_int(vi_surface_normal, *r++);
z++;
}
r++;
}
}
j++;
}
}
Cxif_key& tailer = section.open_key_write(vi_tailer);
tailer.set_value_int(vi_x_min, section_tailer.x_min_scale * 1000000);
tailer.set_value_int(vi_y_min, section_tailer.y_min_scale * 1000000);
tailer.set_value_int(vi_z_min, section_tailer.z_min_scale * 1000000);
tailer.set_value_int(vi_x_max, section_tailer.x_max_scale * 1000000);
tailer.set_value_int(vi_y_max, section_tailer.y_max_scale * 1000000);
tailer.set_value_int(vi_z_max, section_tailer.z_max_scale * 1000000);
tailer.set_value_int(vi_cx, cx);
tailer.set_value_int(vi_cy, cy);
tailer.set_value_int(vi_cz, cz);
}
return k.vdata().save(name);
}
Cvirtual_binary vxl_file_write(const Cxif_key& s)
{
Cvirtual_binary d;
byte* w = d.write_start(1 << 20);
const Cxif_key& header_key = s.open_key_read(vi_header);
const Cxif_key& body_key = s.open_key_read(vi_body);
int c_sections = body_key.c_keys();
int* span_start_list_ofs = new int[c_sections];
int* span_end_list_ofs = new int[c_sections];
int* span_data_ofs = new int[c_sections];
t_vxl_header& header = *reinterpret_cast<t_vxl_header*>(w);
strcpy(header.id, vxl_id);
header.one = 1;
header.c_section_headers = c_sections;
header.c_section_tailers = c_sections;
header.unknown = 0x1f10;
const Cxif_key& palet_key = header_key.open_key_read(vi_palet);
int i;
for (i = 0; i < 256; i++)
{
const Cxif_key& palet_entry_key = palet_key.open_key_read(i);
header.palet[i].r = palet_entry_key.get_value_int(vi_red);
header.palet[i].g = palet_entry_key.get_value_int(vi_green);
header.palet[i].b = palet_entry_key.get_value_int(vi_blue);
}
w += sizeof(t_vxl_header);
for (i = 0; i < c_sections; i++)
{
const Cxif_key& section_key = body_key.open_key_read(i);
const Cxif_key& section_header_key = section_key.open_key_read(vi_header);
t_vxl_section_header& section_header = *reinterpret_cast<t_vxl_section_header*>(w);
strcpy(section_header.id, section_header_key.get_value_string(vi_id).c_str());
section_header.section_i = i;
section_header.one = 1;
section_header.zero = 0;
w += sizeof(t_vxl_section_header);
}
byte* body_start = w;
for (i = 0; i < c_sections; i++)
{
const Cxif_key& section_key = body_key.open_key_read(i);
const Cxif_key& section_body_key = section_key.open_key_read(vi_body);
const Cxif_key& section_tailer_key = section_key.open_key_read(vi_tailer);
const int cx = section_tailer_key.get_value_int(vi_cx);
const int cy = section_tailer_key.get_value_int(vi_cy);
const int cz = section_tailer_key.get_value_int(vi_cz);
__int32* span_start_list = reinterpret_cast<__int32*>(w);
span_start_list_ofs[i] = w - body_start;
w += 4 * cx * cy;
__int32* span_end_list = reinterpret_cast<__int32*>(w);
span_end_list_ofs[i] = w - body_start;
w += 4 * cx * cy;
byte* span_data_start = w;
span_data_ofs[i] = w - body_start;
int span_i = 0;
for (int y = 0; y < cy; y++)
{
const Cxif_key& yi = section_body_key.open_key_read(y);
for (int x = 0; x < cx; x++)
{
byte* span_start = w;
const Cxif_key& xi = yi.open_key_read(x);
int z = 0;
for (auto& i : xi.m_keys)
{
int z_inc = i.first - z;
z = i.first + 1;
*w++ = z_inc;
*w++ = 1;
*w++ = i.second.get_value_int(vi_color);
*w++ = i.second.get_value_int(vi_surface_normal);
*w++ = 1;
}
if (span_start == w)
{
span_start_list[span_i] = -1;
span_end_list[span_i] = -1;
}
else
{
if (z != cz)
{
*w++ = cz - z;
*w++ = 0;
*w++ = 0;
}
span_start_list[span_i] = span_start - span_data_start;
span_end_list[span_i] = w - span_data_start - 1;
}
span_i++;
}
}
}
header.size = w - body_start;
for (i = 0; i < c_sections; i++)
{
const Cxif_key& section_key = body_key.open_key_read(i);
const Cxif_key& section_tailer_key = section_key.open_key_read(vi_tailer);
t_vxl_section_tailer& section_tailer = *reinterpret_cast<t_vxl_section_tailer*>(w);
section_tailer.span_start_ofs = span_start_list_ofs[i];
section_tailer.span_end_ofs = span_end_list_ofs[i];
section_tailer.span_data_ofs = span_data_ofs[i];
section_tailer.scale = 0;
for (int ty = 0; ty < 3; ty++)
{
for (int tx = 0; tx < 4; tx++)
section_tailer.transform[ty][tx] = 0;
}
section_tailer.x_min_scale = section_tailer_key.get_value_int(vi_x_min) / 1000000.0;
section_tailer.y_min_scale = section_tailer_key.get_value_int(vi_y_min) / 1000000.0;
section_tailer.z_min_scale = section_tailer_key.get_value_int(vi_z_min) / 1000000.0;
section_tailer.x_max_scale = section_tailer_key.get_value_int(vi_x_max) / 1000000.0;
section_tailer.y_max_scale = section_tailer_key.get_value_int(vi_y_max) / 1000000.0;
section_tailer.z_max_scale = section_tailer_key.get_value_int(vi_z_max) / 1000000.0;
section_tailer.cx = section_tailer_key.get_value_int(vi_cx);
section_tailer.cy = section_tailer_key.get_value_int(vi_cy);
section_tailer.cz = section_tailer_key.get_value_int(vi_cz);
section_tailer.unknown = 2;
w += sizeof(t_vxl_section_tailer);
}
delete[] span_data_ofs;
delete[] span_end_list_ofs;
delete[] span_start_list_ofs;
d.set_size(w - d.data());
return d;
}
Cvirtual_binary vxl_file_write(const byte* s, const byte* s_normals, int cx, int cy, int cz)
{
Cxif_key k;
Cxif_key& header = k.open_key_write(vi_header);
Cxif_key& palet = header.open_key_write(vi_palet);
for (int i = 0; i < 256; i++)
{
Cxif_key& palet_entry = palet.open_key_write(i);
palet_entry.set_value_int(vi_red, i);
palet_entry.set_value_int(vi_green, i);
palet_entry.set_value_int(vi_blue, i);
}
Cxif_key& body = k.open_key_write(vi_body);
{
Cxif_key& section = body.open_key_write(0);
Cxif_key& header = section.open_key_write(vi_header);
header.set_value_string(vi_id, "NONE");
Cxif_key& body = section.open_key_write(vi_body);
for (int y = 0; y < cy; y++)
{
Cxif_key& yi = body.open_key_write(y);
for (int x = 0; x < cx; x++)
{
Cxif_key& xi = yi.open_key_write(x);
const byte* r = s + x + cx * y;
for (int z = 0; z < cz; z++)
{
int v = *r;
if (v)
{
Cxif_key& zi = xi.open_key_write(z);
zi.set_value_int(vi_color, v);
zi.set_value_int(vi_surface_normal, s_normals ? s_normals[r - s]: -1);
}
r += cx * cy;
}
}
}
Cxif_key& tailer = section.open_key_write(vi_tailer);
tailer.set_value_int(vi_x_min, cx * -1000000 / 2);
tailer.set_value_int(vi_y_min, cy * -1000000 / 2);
tailer.set_value_int(vi_z_min, cz * -1000000 / 2);
tailer.set_value_int(vi_x_max, cx * +1000000 / 2);
tailer.set_value_int(vi_y_max, cy * +1000000 / 2);
tailer.set_value_int(vi_z_max, cz * +1000000 / 2);
tailer.set_value_int(vi_cx, cx);
tailer.set_value_int(vi_cy, cy);
tailer.set_value_int(vi_cz, cz);
}
return vxl_file_write(k);
}
struct t_voxel
{
int x;
int y;
int z;
int color;
int normal;
};
Cvirtual_binary vxl_file_write(Cvirtual_tfile s)
{
using t_list = list<t_voxel>;
t_list list;
int cs = 0;
int cx = 0;
int cy = 0;
int cz = 0;
while (!s.eof())
{
Cmulti_line l = s.read_line();
t_voxel e;
int s = l.get_next_int(',');
e.x = l.get_next_int(',');
e.y = l.get_next_int(',');
e.z = l.get_next_int(',');
e.normal = l.get_next_int(',');
e.color = l.get_next_int(',');
if (!s)
list.push_back(e);
cs = max(cs, s + 1);
cx = max(cx, e.x + 1);
cy = max(cy, e.y + 1);
cz = max(cz, e.z + 1);
}
Cvirtual_binary colors(NULL, cx * cy * cz);
Cvirtual_binary normals(NULL, cx * cy * cz);
colors.memset(0);
normals.memset(0);
for (auto& e : list)
{
int o = e.x + cx * (e.y + cy * e.z);
colors.data_edit()[o] = e.color;
normals.data_edit()[o] = e.normal;
}
return vxl_file_write(colors.data(), normals.data(), cx, cy, cz);
}
#endif
struct t_vxl4_header
{
unsigned __int32 c_sections;
};
struct t_vxl4_section_header
{
char id[16];
__int32 section_i;
float scale;
float x_min_scale;
float y_min_scale;
float z_min_scale;
float x_max_scale;
float y_max_scale;
float z_max_scale;
unsigned __int8 cx;
unsigned __int8 cy;
unsigned __int8 cz;
__int8 unknown;
};
int vxl_encode4(const Cvxl_file& f, byte* d)
{
const int c_sections = f.get_c_section_headers();
byte* w = d;
t_vxl4_header& header = *reinterpret_cast<t_vxl4_header*>(w);
header.c_sections = c_sections;
w += sizeof(t_vxl4_header);
for (int i = 0; i < c_sections; i++)
{
const t_vxl_section_header& s_section_header = *f.get_section_header(i);
const t_vxl_section_tailer& section_tailer = *f.get_section_tailer(i);
const int cx = section_tailer.cx;
const int cy = section_tailer.cy;
const int cz = section_tailer.cz;
t_vxl4_section_header& section_header = *reinterpret_cast<t_vxl4_section_header*>(w);
strcpy(section_header.id, s_section_header.id);
section_header.section_i = s_section_header.section_i;
assert(s_section_header.section_i == i);
section_header.scale = section_tailer.scale;
section_header.x_min_scale = section_tailer.x_min_scale;
section_header.y_min_scale = section_tailer.y_min_scale;
section_header.z_min_scale = section_tailer.z_min_scale;
section_header.x_max_scale = section_tailer.x_max_scale;
section_header.y_max_scale = section_tailer.y_max_scale;
section_header.z_max_scale = section_tailer.z_max_scale;
section_header.cx = section_tailer.cx;
section_header.cy = section_tailer.cy;
section_header.cz = section_tailer.cz;
section_header.unknown = section_tailer.unknown;
w += sizeof(t_vxl4_section_header);
for (int j = 0; j < f.get_c_spans(i); j++)
{
const byte* r = f.get_span_data(i, j);
if (r)
{
int z = 0;
while (z < cz)
{
int z_inc = *w++ = *r++;
if (z_inc == cz)
break;
z += z_inc;
int c = *w++ = *r++;
while (c--)
{
*w++ = *r++;
*w++ = *r++;
z++;
}
r++;
}
}
else
*w++ = cz;
}
}
return w - d;
}
int vxl_decode4_size(const byte* s)
{
const byte* r = s;
const t_vxl4_header& s_header = *reinterpret_cast<const t_vxl4_header*>(r);
const int c_sections = s_header.c_sections;
r += sizeof(t_vxl4_header);
int w = 0;
for (int i = 0; i < c_sections; i++)
{
const t_vxl4_section_header& section_header = *reinterpret_cast<const t_vxl4_section_header*>(r);
const int cx = section_header.cx;
const int cy = section_header.cy;
const int cz = section_header.cz;
w += 8 * cx * cy;
r += sizeof(t_vxl4_section_header);
for (int j = 0; j < cx * cy; j++)
{
int z = 0;
while (z < cz)
{
int z_inc = *r++;
if (z_inc == cz)
break;
z += z_inc;
int count = *r++;
r += 2 * count;
w += 2 * count + 3;
z += count;
}
}
}
return w
+ sizeof(t_vxl_header)
+ (sizeof(t_vxl_section_header) + sizeof(t_vxl_section_tailer)) * c_sections;
}
Cvirtual_binary vxl_decode4(const byte* s, int cb_d)
{
Cvirtual_binary d;
const byte* r = s;
const t_vxl4_header& s_header = *reinterpret_cast<const t_vxl4_header*>(r);
const int c_sections = s_header.c_sections;
r += sizeof(t_vxl4_header);
byte* w = d.write_start(cb_d ? cb_d : 1 << 20);
t_vxl_header& header = *reinterpret_cast<t_vxl_header*>(w);
strcpy(header.id, vxl_id);
header.one = 1;
header.c_section_headers = c_sections;
header.c_section_tailers = c_sections;
header.unknown = 0x1f10;
w += sizeof(t_vxl_header);
t_vxl_section_header* d_section_header = reinterpret_cast<t_vxl_section_header*>(w);
t_vxl_section_tailer* section_tailer = new t_vxl_section_tailer[c_sections];
w += sizeof(t_vxl_section_header) * c_sections;
byte* body_start = w;
for (int i = 0; i < c_sections; i++)
{
const t_vxl4_section_header& section_header = *reinterpret_cast<const t_vxl4_section_header*>(r);
const int cx = section_header.cx;
const int cy = section_header.cy;
const int cz = section_header.cz;
strcpy(d_section_header->id, section_header.id);
d_section_header->section_i = section_header.section_i;
d_section_header->one = 1;
d_section_header->zero = 0;
d_section_header++;
__int32* span_start_list = reinterpret_cast<__int32*>(w);
section_tailer[i].span_start_ofs = w - body_start;
w += 4 * cx * cy;
__int32* span_end_list = reinterpret_cast<__int32*>(w);
section_tailer[i].span_end_ofs = w - body_start;
w += 4 * cx * cy;
section_tailer[i].span_data_ofs = w - body_start;
section_tailer[i].scale = section_header.scale;
section_tailer[i].x_min_scale = section_header.x_min_scale;
section_tailer[i].y_min_scale = section_header.y_min_scale;
section_tailer[i].z_min_scale = section_header.z_min_scale;
section_tailer[i].x_max_scale = section_header.x_max_scale;
section_tailer[i].y_max_scale = section_header.y_max_scale;
section_tailer[i].z_max_scale = section_header.z_max_scale;
section_tailer[i].cx = section_header.cx;
section_tailer[i].cy = section_header.cy;
section_tailer[i].cz = section_header.cz;
section_tailer[i].unknown = section_header.unknown;
r += sizeof(t_vxl4_section_header);
byte* span_data_start = w;
for (int j = 0; j < cx * cy; j++)
{
byte* span_start = w;
int z = 0;
while (z < cz)
{
int z_inc = *r++;
if (z_inc == cz)
break;
z += *w++ = z_inc;
int count = *w++ = *r++;
int c = count;
while (c--)
{
*w++ = *r++;
*w++ = *r++;
z++;
}
*w++ = count;
}
if (span_start == w)
{
span_start_list[j] = -1;
span_end_list[j] = -1;
}
else
{
span_start_list[j] = span_start - span_data_start;
span_end_list[j] = w - span_data_start - 1;
}
}
}
header.size = w - body_start;
memcpy(w, section_tailer, sizeof(t_vxl_section_tailer) * c_sections);
delete[] section_tailer;
w += sizeof(t_vxl_section_tailer) * c_sections;
assert(!cb_d || d.size() == w - d.data());
return cb_d ? d : Cvirtual_binary(d.data(), w - d.data());
}

106
3rdParty/xcc/misc/vxl_file.h vendored Normal file
View file

@ -0,0 +1,106 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "cc_file_sh.h"
#include "cc_structures.h"
#include "fname.h"
#include "virtual_tfile.h"
#ifndef XCC_MINIMAL_BUILD
#include "xif_key.h"
#endif
class Cvxl_file : public Ccc_file_sh<t_vxl_header>
{
public:
#ifndef XCC_MINIMAL_BUILD
int extract_as_pcx(const Cfname& name, t_file_type ft, const t_palet _palet) const;
#endif
ostream& extract_as_text(ostream& os) const;
#ifndef XCC_MINIMAL_BUILD
int extract_as_xif(const string& name) const;
#endif
bool is_valid() const;
int get_c_section_headers() const
{
return header().c_section_headers;
}
int get_c_spans(int i) const
{
return get_section_tailer(i)->span_end_ofs - get_section_tailer(i)->span_start_ofs >> 2;
}
int get_c_section_tailers() const
{
return header().c_section_tailers;
}
const t_palet_entry* get_palet() const
{
return header().palet;
}
const byte* get_section_body() const
{
return data() + sizeof(t_vxl_header) + sizeof(t_vxl_section_header) * get_c_section_tailers();
}
const t_vxl_section_header* get_section_header(int i) const
{
return reinterpret_cast<const t_vxl_section_header*>(data() + sizeof(t_vxl_header) + sizeof(t_vxl_section_header) * i);
}
const t_vxl_section_tailer* get_section_tailer(int i) const
{
return reinterpret_cast<const t_vxl_section_tailer*>(data() + get_size() + sizeof(t_vxl_section_tailer) * (i - get_c_section_tailers()));
}
const byte* get_span_data(int i, int j) const
{
if (get_span_start_list(i)[j] == -1)
return NULL;
return get_section_body() + get_section_tailer(i)->span_data_ofs + get_span_start_list(i)[j];
}
int get_span_size(int i, int j) const
{
return get_span_end_list(i)[j] - get_span_start_list(i)[j] + 1;
}
const int* get_span_start_list(int i) const
{
return reinterpret_cast<const int*>(get_section_body() + get_section_tailer(i)->span_start_ofs);
}
const int* get_span_end_list(int i) const
{
return reinterpret_cast<const int*>(get_section_body() + get_section_tailer(i)->span_end_ofs);
}
};
int vxl_decode4_size(const byte* s);
Cvirtual_binary vxl_decode4(const byte* s, int cb_d);
int vxl_encode4(const Cvxl_file& f, byte* d);
#ifndef XCC_MINIMAL_BUILD
Cvirtual_binary vxl_file_write(const Cxif_key& s);
Cvirtual_binary vxl_file_write(const byte* s, const byte* s_normals, int cx, int cy, int cz);
Cvirtual_binary vxl_file_write(Cvirtual_tfile s);
#endif

36
3rdParty/xcc/misc/win_handle.cpp vendored Normal file
View file

@ -0,0 +1,36 @@
/*
XCC Utilities and Library
Copyright (C) 2002 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "win_handle.h"
int create_process(const std::string& exe_name, const std::string& _cmd_line, bool wait)
{
char cmd_line[256];
strcpy(cmd_line, ("\"" + exe_name + "\" " + _cmd_line).c_str());
STARTUPINFO si;
memset(&si, 0, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
PROCESS_INFORMATION pi;
int error = !CreateProcess(exe_name.c_str(), cmd_line, NULL, NULL, false, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &si, &pi);
if (!error && wait)
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return error;
}

50
3rdParty/xcc/misc/win_handle.h vendored Normal file
View file

@ -0,0 +1,50 @@
/*
XCC Utilities and Library
Copyright (C) 2002 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <memory>
#include <string>
#include <windows.h>
template<class T>
class Cwin_handle_base
{
public:
Cwin_handle_base() = default;
explicit Cwin_handle_base(T h) : m_source(h == INVALID_HANDLE_VALUE ? NULL : h, CloseHandle)
{
}
void clear()
{
m_source.reset();
}
operator T() const
{
return static_cast<T>(m_source.get());
}
private:
std::shared_ptr<void> m_source;
};
using Cwin_handle = Cwin_handle_base<HANDLE>;
int create_process(const std::string& exe_name, const std::string& _cmd_line = "", bool wait = false);

66
3rdParty/xcc/misc/xcc/data_ref.h vendored Normal file
View file

@ -0,0 +1,66 @@
/*
XCC Utilities and Library
Copyright (C) 2021 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <span>
template <class T, class U>
class data_ref_base : public std::span<T>
{
private:
using base_t = std::span<T>;
public:
data_ref_base() = default;
template<class V>
data_ref_base(const V& v, typename std::enable_if_t<std::is_class<V>::value>* = 0)
{
if (v.end() != v.begin())
assign(&*v.begin(), v.end() - v.begin() + &*v.begin());
}
template<class V>
data_ref_base(V& v, typename std::enable_if<std::is_class<V>::value>* = 0)
{
if (v.end() != v.begin())
assign(&*v.begin(), v.end() - v.begin() + &*v.begin());
}
data_ref_base(U begin, U end)
{
assign(begin, end);
}
data_ref_base(U begin, size_t size)
{
assign(begin, size);
}
void assign(U begin, U end)
{
static_cast<base_t&>(*this) = base_t(reinterpret_cast<T*>(begin), reinterpret_cast<T*>(end));
}
void assign(U begin, size_t size)
{
assign(begin, reinterpret_cast<T*>(begin) + size);
}
};
using data_ref = data_ref_base<const unsigned char, const void*>;

86
3rdParty/xcc/misc/xcc/find_ptr.h vendored Normal file
View file

@ -0,0 +1,86 @@
/*
XCC Utilities and Library
Copyright (C) 2021 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
template <class T, class U>
const typename T::value_type::second_type* find_ptr(const T& c, const U& v)
{
typename T::const_iterator i = c.find(v);
return i == c.end() ? NULL : &i->second;
}
template <class T, class U>
typename T::value_type::second_type* find_ptr(T& c, const U& v)
{
typename T::iterator i = c.find(v);
return i == c.end() ? NULL : &i->second;
}
template <class T, class U>
const typename T::value_type::second_type& find_ptr2(const T& c, const U& v)
{
static typename T::value_type::second_type z = typename T::value_type::second_type();
typename T::const_iterator i = c.find(v);
return i == c.end() ? z : i->second;
}
template <class T, class U>
typename T::value_type::second_type& find_ptr2(T& c, const U& v)
{
static typename T::value_type::second_type z = typename T::value_type::second_type();
typename T::iterator i = c.find(v);
return i == c.end() ? z : i->second;
}
template <class T, class U>
const typename T::value_type* find_ptr0(const T& c, const U& v)
{
typename T::const_iterator i = c.find(v);
return i == c.end() ? NULL : &*i;
}
template <class T, class U>
typename T::value_type::second_type& find_ref(T& c, const U& v)
{
typename T::iterator i = c.find(v);
assert(i != c.end());
return i->second;
}
template <class T, class U>
const typename T::value_type::second_type& find_ref(const T& c, const U& v)
{
typename T::const_iterator i = c.find(v);
assert(i != c.end());
return i->second;
}
template <class T, class U>
const typename T::value_type::second_type& find_ref(const T& c, const U& v, const typename T::value_type::second_type& z)
{
typename T::const_iterator i = c.find(v);
return i == c.end() ? z : i->second;
}
template <class T, class U>
typename T::value_type::second_type& find_ref(T& c, const U& v, typename T::value_type::second_type& z)
{
typename T::iterator i = c.find(v);
return i == c.end() ? z : i->second;
}

68
3rdParty/xcc/misc/xcc/string_view.h vendored Normal file
View file

@ -0,0 +1,68 @@
/*
XCC Utilities and Library
Copyright (C) 2021 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <charconv>
#include <string>
#include <string_view>
inline std::string& operator<<(std::string& a, std::string_view b)
{
return a += b;
}
template<class T>
inline std::enable_if_t<std::is_integral<T>::value, std::string&> operator<<(std::string& a, T b)
{
return a += std::to_string(b);
}
inline float to_float(std::string_view s)
{
float v;
auto res = std::from_chars(s.data(), s.data() + s.size(), v);
return res.ec == std::errc() && res.ptr == s.data() + s.size() ? v : 0;
}
inline long long to_int(std::string_view s)
{
long long v;
auto res = std::from_chars(s.data(), s.data() + s.size(), v);
return res.ec == std::errc() && res.ptr == s.data() + s.size() ? v : 0;
}
template<size_t N>
std::string_view to_string_view(const std::array<char, N>& v)
{
return std::string_view(v.data(), v.size());
}
template<size_t N>
std::string_view to_string_view(const std::array<unsigned char, N>& v)
{
return std::string_view(reinterpret_cast<const char*>(v.data()), v.size());
}
inline std::string_view read_until(std::string_view& v, char sep, bool keep_sep = false)
{
size_t i = v.find(sep);
std::string_view ret = v.substr(0, i);
v.remove_prefix(i == std::string_view::npos ? v.size() : keep_sep ? i : i + 1);
return ret;
}

417
3rdParty/xcc/misc/xcc_dirs.cpp vendored Normal file
View file

@ -0,0 +1,417 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "xcc_dirs.h"
#include <boost/algorithm/string.hpp>
#include <cassert>
#include <windows.h>
#include "reg_key.h"
#include "string_conversion.h"
#include "xcc_registry.h"
bool g_enable_log = false;
static string dune2_dir;
static string td_primary_dir;
static string td_secondary_dir;
static string cd_dir;
static string data_dir;
static string ra_dir;
static string dune2000_dir;
static string ts_dir;
static string ra2_dir;
static string nox_dir;
static string rg_dir;
static string gr_dir;
static string gr_zh_dir;
static string ebfd_dir;
static string bfme_dir;
static string tw_dir;
bool xcc_dirs::enable_log()
{
return g_enable_log;
}
string xcc_dirs::get_dir(t_game game)
{
switch (game)
{
case game_td:
return td_primary_dir;
case game_ra:
return ra_dir;
case game_ts:
case game_ts_fs:
return ts_dir;
case game_dune2:
return dune2_dir;
case game_dune2000:
return dune2000_dir;
case game_ra2:
case game_ra2_yr:
return ra2_dir;
case game_nox:
return nox_dir;
case game_rg:
return rg_dir;
case game_gr:
return gr_dir;
case game_gr_zh:
return gr_zh_dir;
case game_ebfd:
return ebfd_dir;
case game_bfme:
return bfme_dir;
case game_tw:
return tw_dir;
}
assert(false);
return "";
}
string xcc_dirs::get_exe(t_game game)
{
switch (game)
{
case game_td:
return td_primary_dir + "c&c95.exe";
case game_ra:
return ra_dir + "ra95.exe";
case game_ts:
return ts_dir + "sun.exe";
case game_dune2:
return dune2_dir + "dune2.exe";
case game_dune2000:
return dune2000_dir + "dune2000.exe";
case game_ra2:
return ra2_dir + "ra2.exe";
case game_nox:
return nox_dir + "nox.exe";
case game_ra2_yr:
return ra2_dir + "ra2md.exe";
case game_gr:
return gr_dir + "generals.exe";
case game_bfme:
return bfme_dir + "lotrbfme.exe";
}
assert(false);
return "";
}
string xcc_dirs::get_audio_mix(t_game game)
{
switch (game)
{
case game_ra2:
return "audio.mix";
case game_ra2_yr:
return "audiomd.mix";
}
assert(false);
return "";
}
string xcc_dirs::get_csf_fname(t_game game)
{
switch (game)
{
case game_ra2:
return "ra2.csf";
case game_ra2_yr:
return "ra2md.csf";
case game_gr:
case game_gr_zh:
return "data/english/generals.csf";
}
assert(false);
return "";
}
static string get_suffix(t_game game)
{
return game == game_ra2_yr ? "md" : "";
}
string xcc_dirs::get_ecache_mix(t_game game, bool dir, int i)
{
return get_ecache_mix(game, dir, nwzl(2, i));
}
string xcc_dirs::get_ecache_mix(t_game game, bool dir, const string& s)
{
string r = "ecache" + get_suffix(game) + s + ".mix";
if (dir)
r = get_dir(game) + r;
return r;
}
string xcc_dirs::get_expand_mix(t_game game, int i)
{
return get_expand_mix(game, nwzl(2, i));
}
string xcc_dirs::get_expand_mix(t_game game, const string& s)
{
return get_dir(game) + "expand" + get_suffix(game) + s + ".mix";
}
string xcc_dirs::get_language_mix(t_game game)
{
switch (game)
{
case game_ra2:
return ra2_dir + "language.mix";
case game_ra2_yr:
return ra2_dir + "langmd.mix";
case game_gr:
return gr_dir + "english.big";
case game_gr_zh:
return gr_zh_dir + "englishzh.big";
}
assert(false);
return "";
}
string xcc_dirs::get_local_mix(t_game game)
{
switch (game)
{
case game_ts:
case game_ra2:
return "local.mix";
case game_ra2_yr:
return "localmd.mix";
}
assert(false);
return "";
}
string xcc_dirs::get_main_mix(t_game game)
{
switch (game)
{
case game_ra:
return ra_dir + "redalert.mix";
case game_ts:
return ts_dir + "tibsun.mix";
case game_ra2:
return ra2_dir + "ra2.mix";
case game_ra2_yr:
return ra2_dir + "ra2md.mix";
}
assert(false);
return "";
}
static void set_path(string s, string& path)
{
boost::to_lower(s);
if (!s.empty() && s.back() != '\\')
s += '\\';
path = s;
}
void xcc_dirs::set_dir(t_game game, const string &s)
{
switch (game)
{
case game_td:
set_path(s, td_primary_dir);
break;
case game_ra:
set_path(s, ra_dir);
break;
case game_ts:
set_path(s, ts_dir);
break;
case game_dune2:
set_path(s, dune2_dir);
break;
case game_dune2000:
set_path(s, dune2000_dir);
break;
case game_ra2:
set_path(s, ra2_dir);
break;
case game_nox:
set_path(s, nox_dir);
break;
case game_rg:
set_path(s, rg_dir);
break;
case game_gr:
set_path(s, gr_dir);
break;
case game_gr_zh:
set_path(s, gr_zh_dir);
break;
case game_ebfd:
set_path(s, ebfd_dir);
break;
case game_bfme:
set_path(s, bfme_dir);
break;
case game_tw:
set_path(s, tw_dir);
break;
default:
assert(false);
}
}
void xcc_dirs::set_td_secondary_dir(const string& s)
{
set_path(s, td_secondary_dir);
}
void xcc_dirs::set_cd_dir(const string& s)
{
set_path(s, cd_dir);
}
void xcc_dirs::set_data_dir(const string& s)
{
set_path(s, data_dir);
}
void xcc_dirs::reset_cd_dir()
{
int drive_map = GetLogicalDrives();
char drive_root[] = "a:\\";
for (int i = 0; i < 26; i++)
{
if (drive_map >> i & 1 && GetDriveTypeA(drive_root) == DRIVE_CDROM)
{
set_cd_dir(drive_root);
break;
}
drive_root[0]++;
}
}
void xcc_dirs::reset_data_dir()
{
set_data_dir(GetModuleFileName().get_path());
}
static void read_dir(const string& key, const string& value, t_game game)
{
Creg_key h;
string s;
if (xcc_dirs::get_dir(game).empty()
&& ERROR_SUCCESS == h.open(HKEY_LOCAL_MACHINE, key, KEY_QUERY_VALUE)
&& ERROR_SUCCESS == h.query_value(value, s))
xcc_dirs::set_dir(game, Cfname(s).get_path());
}
void xcc_dirs::load_from_registry()
{
Creg_key kh_base;
if (!Cxcc_registry::get_base_key(kh_base))
{
string s;
if (ERROR_SUCCESS == kh_base.query_value("dune2_dir", s))
set_dir(game_dune2, s);
if (ERROR_SUCCESS == kh_base.query_value("dir1", s))
set_dir(game_td, s);
if (ERROR_SUCCESS == kh_base.query_value("dir2", s))
set_td_secondary_dir(s);
if (ERROR_SUCCESS == kh_base.query_value("ra_dir", s))
set_dir(game_ra, s);
if (ERROR_SUCCESS == kh_base.query_value("cd_dir", s))
set_cd_dir(s);
if (ERROR_SUCCESS == kh_base.query_value("data_dir", s))
set_data_dir(s);
if (ERROR_SUCCESS == kh_base.query_value("enable_log", s))
g_enable_log = true;
}
if (cd_dir.empty())
reset_cd_dir();
if (data_dir.empty())
reset_data_dir();
read_dir("Software\\Westwood\\Dune 2", "InstallPath", game_dune2);
read_dir("Software\\Westwood\\Command & Conquer Windows 95 Edition", "InstallPath", game_td);
read_dir("Software\\Westwood\\Red Alert Windows 95 Edition", "InstallPath", game_ra);
read_dir("Software\\Westwood\\Dune 2000", "InstallPath", game_dune2000);
read_dir("Software\\Westwood\\Tiberian Sun", "InstallPath", game_ts);
read_dir("Software\\Westwood\\Red Alert 2", "InstallPath", game_ra2);
read_dir("Software\\Westwood\\Nox", "InstallPath", game_nox);
read_dir("Software\\Westwood\\Renegade", "InstallPath", game_rg);
read_dir("Software\\Westwood\\Emperor", "InstallPath", game_ebfd);
/*
read_dir("Software\\Electronic Arts\\EA Games\\Generals", "InstallPath", game_gr);
read_dir("Software\\Electronic Arts\\EA Games\\Command and Conquer Generals Zero Hour", "InstallPath", game_gr_zh);
read_dir("Software\\Electronic Arts\\EA Games\\The Battle for Middle-earth", "InstallPath", game_bfme);
read_dir("Software\\Electronic Arts\\Electronic Arts\\Command and Conquer 3", "InstallPath", game_tw);
*/
}
void xcc_dirs::save_to_registry()
{
Creg_key kh_base;
if (Cxcc_registry::get_base_key(kh_base))
return;
kh_base.set_value("dune2_dir", dune2_dir);
kh_base.set_value("dir1", td_primary_dir);
kh_base.set_value("dir2", td_secondary_dir);
kh_base.set_value("ra_dir", ra_dir);
};
string xcc_dirs::find_file(Cfname s)
{
if (!s.get_path().empty() || s.exists())
return s;
s.set_path(td_primary_dir);
if (s.exists())
return s;
s.set_path(td_secondary_dir);
if (s.exists())
return s;
s.set_path(ra_dir);
if (s.exists())
return s;
s.set_path(ts_dir);
if (s.exists())
return s;
s.set_path(ra2_dir);
if (s.exists())
return s;
s.set_path(cd_dir);
return s;
}
bool xcc_dirs::is_available(t_game game)
{
return Cfname(get_exe(game)).exists();
}
const string& xcc_dirs::get_td_secondary_dir()
{
return td_secondary_dir;
}
const string& xcc_dirs::get_cd_dir()
{
return cd_dir;
}
const string& xcc_dirs::get_data_dir()
{
return data_dir;
}

52
3rdParty/xcc/misc/xcc_dirs.h vendored Normal file
View file

@ -0,0 +1,52 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "cc_structures.h"
#include "fname.h"
class xcc_dirs
{
public:
static bool enable_log();
static void load_from_registry();
static void save_to_registry();
static string find_file(Cfname s);
static bool is_available(t_game game);
static string get_audio_mix(t_game game);
static string get_csf_fname(t_game game);
static string get_dir(t_game game);
static string get_exe(t_game game);
static string get_ecache_mix(t_game game, bool dir, int i);
static string get_ecache_mix(t_game game, bool dir, const string& s);
static string get_expand_mix(t_game game, int i);
static string get_expand_mix(t_game game, const string& s);
static string get_language_mix(t_game game);
static string get_local_mix(t_game game);
static string get_main_mix(t_game game);
static void set_td_secondary_dir(const string& s);
static void set_cd_dir(const string &s);
static void set_data_dir(const string &s);
static void set_dir(t_game game, const string& s);
static void reset_cd_dir();
static void reset_data_dir();
static const string& get_td_secondary_dir();
static const string& get_cd_dir();
static const string& get_data_dir();
};

48
3rdParty/xcc/misc/xcc_file.h vendored Normal file
View file

@ -0,0 +1,48 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <cc_file_sh.h>
#include <cc_structures.h>
enum t_xcc_ft
{
xcc_ft_lmd, xcc_ft_xif, xcc_ft_unknown
};
const char* xcc_ft_name[];
class Cxcc_file : public Ccc_file_sh<t_xcc_header>
{
public:
bool is_valid() const
{
const t_xcc_header& h = header();
int size = get_size();
return !(sizeof(t_xcc_header) > size ||
strcmp(h.id, xcc_id) ||
h.size != size ||
h.version);
}
t_xcc_ft get_ft() const
{
return static_cast<t_xcc_ft>(header().type);
}
};

31
3rdParty/xcc/misc/xcc_file_sh.h vendored Normal file
View file

@ -0,0 +1,31 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "xcc_file.h"
template <class T>
class Cxcc_file_sh : public Cxcc_file
{
public:
const T& header() const
{
return *reinterpret_cast<const T*>(data() + sizeof(t_xcc_header));
}
};

45
3rdParty/xcc/misc/xcc_lmd_file.h vendored Normal file
View file

@ -0,0 +1,45 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "xcc_file_sh.h"
class Cxcc_lmd_file : public Cxcc_file_sh<t_xcc_lmd_header>
{
public:
bool is_valid() const
{
return Cxcc_file_sh<t_xcc_lmd_header>::is_valid() && get_ft() == xcc_ft_lmd;
}
t_game get_game() const
{
return static_cast<t_game>(header().game);
}
int get_c_fnames() const
{
return header().c_fnames;
}
const char* get_fnames() const
{
return reinterpret_cast<const char*>(data() + sizeof(t_xcc_header) + sizeof(t_xcc_lmd_header));
}
};

View file

@ -0,0 +1,53 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "xcc_lmd_file_write.h"
#include "cc_structures.h"
#include "xcc_file.h"
void Cxcc_lmd_file_write::add_fname(const string& fname)
{
m_index.push_back(to_lower_copy(fname));
}
Cvirtual_binary Cxcc_lmd_file_write::write(t_game game) const
{
int size = sizeof(t_xcc_header) + sizeof(t_xcc_lmd_header);
for (auto& i : m_index)
size += i.length() + 1;
Cvirtual_binary data;
byte* w = data.write_start(size);
t_xcc_header& header = *reinterpret_cast<t_xcc_header*>(w);
strcpy(header.id, xcc_id);
header.size = size;
header.type = xcc_ft_lmd;
header.version = 0;
w += sizeof(t_xcc_header);
t_xcc_lmd_header& lmd_header = *reinterpret_cast<t_xcc_lmd_header*>(w);
lmd_header.c_fnames = m_index.size();
lmd_header.game = game;
w += sizeof(t_xcc_lmd_header);
for (auto& i : m_index)
{
strcpy(reinterpret_cast<char*>(w), i.c_str());
w += i.length() + 1;
}
return data;
}

35
3rdParty/xcc/misc/xcc_lmd_file_write.h vendored Normal file
View file

@ -0,0 +1,35 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <vector>
#include "cc_structures.h"
#include <virtual_binary.h>
using namespace std;
class Cxcc_lmd_file_write
{
public:
void add_fname(const string& fname);
Cvirtual_binary write(t_game game) const;
private:
using t_index = vector<string>;
t_index m_index;
};

25
3rdParty/xcc/misc/xcc_registry.cpp vendored Normal file
View file

@ -0,0 +1,25 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "xcc_registry.h"
int Cxcc_registry::get_base_key(Creg_key& kh_base)
{
return ERROR_SUCCESS != kh_base.create(HKEY_CURRENT_USER, "Software\\XCC");
}

27
3rdParty/xcc/misc/xcc_registry.h vendored Normal file
View file

@ -0,0 +1,27 @@
/*
XCC Utilities and Library
Copyright (C) 2000 Olaf van der Spek <olafvdspek@gmail.com>
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "reg_key.h"
class Cxcc_registry
{
public:
static int get_base_key(Creg_key&);
};

View file

@ -0,0 +1,769 @@
diff --git a/Library/StdAfx.h b/Library/StdAfx.h
index f688f65..ce37391 100644
--- a/Library/StdAfx.h
+++ b/Library/StdAfx.h
@@ -35,7 +35,9 @@
#include <vector>
#include <xcc/data_ref.h>
#include <xcc/find_ptr.h>
+#ifndef XCC_MINIMAL_BUILD
#include <xcc/string_view.h>
+#endif
using namespace std;
using boost::iequals;
diff --git a/Library/XCC Library.vcxproj b/Library/XCC Library.vcxproj
index 0481daf..857d3f8 100644
--- a/Library/XCC Library.vcxproj
+++ b/Library/XCC Library.vcxproj
@@ -1,10 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="DebugMinimal|Win32">
+ <Configuration>DebugMinimal</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
+ <ProjectConfiguration Include="ReleaseMinimal|Win32">
+ <Configuration>ReleaseMinimal</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
@@ -18,18 +26,59 @@
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <OutDir>$(SolutionDir)\build\output\$(Configuration)-$(Platform)\lib\</OutDir>
+ <IntDir>$(SolutionDir)\build\intermediate\$(Configuration)-$(Platform)\$(ProjectName)\</IntDir>
<ConfigurationType>StaticLibrary</ConfigurationType>
- <UseOfMfc>Static</UseOfMfc>
+ <UseOfMfc>Dynamic</UseOfMfc>
+ <CharacterSet>MultiByte</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <PlatformToolset>v143</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseMinimal|Win32'" Label="Configuration">
+ <OutDir>$(SolutionDir)\build\output\$(Configuration)-$(Platform)\lib\</OutDir>
+ <IntDir>$(SolutionDir)\build\intermediate\$(Configuration)-$(Platform)\$(ProjectName)\</IntDir>
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseOfMfc>Dynamic</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <OutDir>$(SolutionDir)\build\output\$(Configuration)-$(Platform)\lib\</OutDir>
+ <IntDir>$(SolutionDir)\build\intermediate\$(Configuration)-$(Platform)\$(ProjectName)\</IntDir>
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseOfMfc>Dynamic</UseOfMfc>
+ <CharacterSet>MultiByte</CharacterSet>
+ <PlatformToolset>v143</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugMinimal|Win32'" Label="Configuration">
+ <OutDir>$(SolutionDir)\build\output\$(Configuration)-$(Platform)\lib\</OutDir>
+ <IntDir>$(SolutionDir)\build\intermediate\$(Configuration)-$(Platform)\$(ProjectName)\</IntDir>
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseOfMfc>Dynamic</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)'=='Release'" Label="XCC">
+ <XCC_MINIMAL_BUILD>
+ </XCC_MINIMAL_BUILD>
+ <NO_FT_SUPPORT>
+ </NO_FT_SUPPORT>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)'=='ReleaseMinimal'" Label="XCC">
+ <XCC_MINIMAL_BUILD>XCC_MINIMAL_BUILD</XCC_MINIMAL_BUILD>
+ <NO_FT_SUPPORT>NO_FT_SUPPORT</NO_FT_SUPPORT>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="XCC">
+ <XCC_MINIMAL_BUILD>
+ </XCC_MINIMAL_BUILD>
+ <NO_FT_SUPPORT>
+ </NO_FT_SUPPORT>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)'=='DebugMinimal'" Label="XCC">
+ <XCC_MINIMAL_BUILD>XCC_MINIMAL_BUILD</XCC_MINIMAL_BUILD>
+ <NO_FT_SUPPORT>NO_FT_SUPPORT</NO_FT_SUPPORT>
+ </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
@@ -37,10 +86,18 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\XCC.props" />
</ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseMinimal|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="..\XCC.props" />
+ </ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\XCC.props" />
</ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='DebugMinimal|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="..\XCC.props" />
+ </ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
@@ -51,7 +108,22 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
- <PreprocessorDefinitions>_DEBUG;WIN32;_LIB;JPEG_SUPPORT;OGG_SUPPORT;PNG_SUPPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>_DEBUG;WIN32;_LIB;$(XCC_MINIMAL_BUILD);$(NO_FT_SUPPORT);%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <ForcedIncludeFiles>stdafx.h</ForcedIncludeFiles>
+ <LanguageStandard>stdcpplatest</LanguageStandard>
+ </ClCompile>
+ <ResourceCompile>
+ <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <Culture>0x0413</Culture>
+ </ResourceCompile>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugMinimal|Win32'">
+ <ClCompile>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>_DEBUG;WIN32;_LIB;$(XCC_MINIMAL_BUILD);$(NO_FT_SUPPORT);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
@@ -65,7 +137,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
- <PreprocessorDefinitions>NDEBUG;WIN32;_LIB;JPEG_SUPPORT;OGG_SUPPORT;PNG_SUPPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>NDEBUG;WIN32;_LIB;$(XCC_MINIMAL_BUILD);$(NO_FT_SUPPORT);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
@@ -78,204 +150,293 @@
<Culture>0x0413</Culture>
</ResourceCompile>
</ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseMinimal|Win32'">
+ <ClCompile>
+ <PreprocessorDefinitions>NDEBUG;WIN32;_LIB;$(XCC_MINIMAL_BUILD);$(NO_FT_SUPPORT);%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <StringPooling>true</StringPooling>
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <ForcedIncludeFiles>stdafx.h</ForcedIncludeFiles>
+ <LanguageStandard>stdcpplatest</LanguageStandard>
+ </ClCompile>
+ <ResourceCompile>
+ <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <Culture>0x0413</Culture>
+ </ResourceCompile>
+ </ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\misc\aud_decode.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\aud_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\aud_file_write.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\audio_idx_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\avi_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\big_edit.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\big_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\big_file_write.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\blowfish.cpp">
</ClCompile>
<ClCompile Include="..\misc\bmp_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\cc_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\cc_structures.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\cps_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\csf_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\ddpf_conversion.cpp">
</ClCompile>
<ClCompile Include="..\misc\dds_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\file32.cpp">
</ClCompile>
<ClCompile Include="..\misc\fname.cpp">
</ClCompile>
<ClCompile Include="..\misc\fs_ini_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\hva_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\id_log.cpp">
</ClCompile>
<ClCompile Include="..\misc\ima_adpcm_wav_decode.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\ima_adpcm_wav_encode.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\image_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\image_tools.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\ini_reader.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
+ </ClCompile>
+ <ClCompile Include="..\misc\jpeg_file.cpp">
+ <ExcludedFromBuild Condition="'$(JPEG_SUPPORT)'==''">true</ExcludedFromBuild>
</ClCompile>
- <ClCompile Include="..\misc\jpeg_file.cpp" />
<ClCompile Include="..\misc\map_ra_ini_reader.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\map_td_ini_reader.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\map_ts_encoder.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\map_ts_ini_reader.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\mix_cache.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\mix_decode.cpp">
</ClCompile>
<ClCompile Include="..\misc\mix_edit.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\mix_file.cpp">
</ClCompile>
<ClCompile Include="..\misc\mix_file_write.cpp">
</ClCompile>
<ClCompile Include="..\misc\mix_rg_edit.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\mix_rg_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\mix_rg_file_write.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\mix_sfl.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\mp3_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\mp3_frame_header.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\multi_line.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\neat_ini_reader.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\neat_key_list.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\ogg_file.cpp">
+ <ExcludedFromBuild Condition="'$(OGG_SUPPORT)'==''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\pak_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\pal_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\palet.cpp">
</ClCompile>
<ClCompile Include="..\misc\pcx_decode.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\pcx_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\pcx_file_write.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\pkt_ts_ini_reader.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
- <ClCompile Include="..\misc\png_file.cpp" />
- <ClCompile Include="..\misc\reg_key.cpp">
+ <ClCompile Include="..\misc\png_file.cpp">
+ <ExcludedFromBuild Condition="'$(PNG_SUPPORT)'==''">true</ExcludedFromBuild>
</ClCompile>
+ <ClCompile Include="..\misc\reg_key.cpp" />
<ClCompile Include="..\misc\riff_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\rules_ts_ini_reader.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\shp_decode.cpp">
</ClCompile>
<ClCompile Include="..\misc\shp_dune2_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\shp_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\shp_images.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\shp_ts_file.cpp">
</ClCompile>
<ClCompile Include="..\misc\shp_ts_file_write.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\sound_ts_ini_reader.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\st_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="StdAfx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='DebugMinimal|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='ReleaseMinimal|Win32'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\misc\string_conversion.cpp">
</ClCompile>
<ClCompile Include="..\misc\tga_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\theme_ts_ini_reader.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\timer.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\tmp_ra.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\tmp_ts_file.cpp">
</ClCompile>
<ClCompile Include="..\misc\video_decoder.cpp">
</ClCompile>
<ClCompile Include="..\misc\virtual_audio.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
- <ClCompile Include="..\misc\virtual_binary.cpp">
- </ClCompile>
+ <ClCompile Include="..\misc\virtual_binary.cpp" />
<ClCompile Include="..\misc\virtual_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
- <ClCompile Include="..\misc\virtual_image.cpp">
- </ClCompile>
+ <ClCompile Include="..\misc\virtual_image.cpp" />
<ClCompile Include="..\misc\virtual_tfile.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\voc_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\vqa_decode.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\vqa_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\vxl_file.cpp">
</ClCompile>
<ClCompile Include="..\misc\wav_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\wav_header.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\win_handle.cpp">
</ClCompile>
<ClCompile Include="..\misc\wsa_dune2_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\wsa_file.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\xcc_apps.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
- <ClCompile Include="..\misc\xcc_dirs.cpp">
- </ClCompile>
+ <ClCompile Include="..\misc\xcc_dirs.cpp" />
<ClCompile Include="..\misc\xcc_draw.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
- <ClCompile Include="..\misc\xcc_lmd_file_write.cpp">
- </ClCompile>
+ <ClCompile Include="..\misc\xcc_lmd_file_write.cpp" />
<ClCompile Include="..\misc\xcc_log.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\xcc_mixs.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
- <ClCompile Include="..\misc\xcc_registry.cpp">
- </ClCompile>
+ <ClCompile Include="..\misc\xcc_registry.cpp" />
<ClCompile Include="..\misc\xif_key.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\xif_key_r.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\xif_value.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\xse.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\misc\XSTE.cpp">
+ <ExcludedFromBuild Condition="'$(XCC_MINIMAL_BUILD)'!=''">true</ExcludedFromBuild>
</ClCompile>
</ItemGroup>
<ItemGroup>
@@ -301,7 +462,6 @@
<ClInclude Include="..\misc\dd_window.h" />
<ClInclude Include="..\misc\ddpf_conversion.h" />
<ClInclude Include="..\misc\dds_file.h" />
- <ClInclude Include="..\misc\ETSLayout.h" />
<ClInclude Include="..\misc\extract_object.h" />
<ClInclude Include="..\misc\file32.h" />
<ClInclude Include="..\misc\fname.h" />
@@ -413,4 +573,13 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
+ <PropertyGroup>
+ <IntegratedVCPKG_ROOT>$(VcpkgRoot)</IntegratedVCPKG_ROOT>
+ </PropertyGroup>
+ <Import Project="$(VCINSTALLDIR)vcpkg\scripts\buildsystems\msbuild\vcpkg.props" Condition="'$(IntegratedVCPKG_ROOT)'=='' And Exists('$(VCINSTALLDIR)vcpkg\scripts\buildsystems\msbuild\vcpkg.props')" />
+ <Import Project="$(VCINSTALLDIR)vcpkg\scripts\buildsystems\msbuild\vcpkg.targets" Condition="'$(IntegratedVCPKG_ROOT)'=='' And Exists('$(VCINSTALLDIR)vcpkg\scripts\buildsystems\msbuild\vcpkg.targets')" />
+ <Target Name="CheckVCPKG" BeforeTargets="BeforeClCompile">
+ <Error Text="You have neither installed VCPKG in your Visual C++ installation nor do you have VCPKG integrated into MSBuild. Please update your Visual Studio 2022 installation and after updating add the VCPKG single component. More details are available in the Readme.md file." Condition="'$(VcpkgRoot)' == ''" />
+ <Warning Text="'$(VcpkgRoot)\.vcpkg-root' does not exist. Either VcpkgRoot is set to a invalid location or you may have to repair your VCPKG installation (e.g. using the Visual Studio installer)" Condition="!Exists('$(VcpkgRoot)\.vcpkg-root')" />
+ </Target>
</Project>
\ No newline at end of file
diff --git a/XCC.props b/XCC.props
index f813cc4..5970828 100644
--- a/XCC.props
+++ b/XCC.props
@@ -15,4 +15,5 @@
<AdditionalDependencies>dsound.lib;gdiplus.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
+
</Project>
diff --git a/misc/cc_file.cpp b/misc/cc_file.cpp
index 13e4976..d9e9e11 100644
--- a/misc/cc_file.cpp
+++ b/misc/cc_file.cpp
@@ -19,6 +19,7 @@
#include "stdafx.h"
#include "cc_file.h"
+#ifndef XCC_MINIMAL_BUILD
#include "aud_file.h"
#include "avi_file.h"
#include "big_file.h"
@@ -70,6 +71,11 @@
#include "xcc_file.h"
#include "xcc_lmd_file.h"
#include "xif_file.h"
+#else
+#include "mix_file.h"
+#include "xcc_dirs.h"
+#endif
+
const char* ft_name[] =
{
diff --git a/misc/image_file.h b/misc/image_file.h
index e107843..b9e9fb5 100644
--- a/misc/image_file.h
+++ b/misc/image_file.h
@@ -30,12 +30,14 @@ class Cimage_file : public Cvideo_file<T>
public:
virtual void decode(void*) const = 0;
+#ifndef XCC_MINIMAL_BUILD
virtual Cvirtual_image vimage() const
{
Cvirtual_binary image;
decode(image.write_start(this->cb_image()));
return Cvirtual_image(image, this->cx(), this->cy(), this->cb_pixel(), this->palet());
}
+#endif
int cf() const override
{
@@ -43,6 +45,8 @@ public:
}
};
+#ifndef XCC_MINIMAL_BUILD
int image_file_write(Cvirtual_file&, t_file_type, const byte* image, const t_palet_entry*, int cx, int cy);
Cvirtual_file image_file_write(t_file_type, const byte* image, const t_palet_entry*, int cx, int cy);
int image_file_write(const string& name, t_file_type, const byte* image, const t_palet_entry*, int cx, int cy);
+#endif
diff --git a/misc/mix_file.cpp b/misc/mix_file.cpp
index 8354059..874ff31 100644
--- a/misc/mix_file.cpp
+++ b/misc/mix_file.cpp
@@ -19,14 +19,20 @@
#include <stdafx.h>
#include "mix_file.h"
+#ifndef NO_FT_SUPPORT
#include "big_file.h"
+#endif
#include "blowfish.h"
#include "crc.h"
#include "id_log.h"
+#ifndef NO_FT_SUPPORT
#include "mix_cache.h"
+#endif
#include "mix_decode.h"
+#ifndef NO_FT_SUPPORT
#include "mix_rg_file.h"
#include "pak_file.h"
+#endif
#include "string_conversion.h"
#include "xcc_lmd_file.h"
diff --git a/misc/shp_ts_file.cpp b/misc/shp_ts_file.cpp
index 4950213..db60a92 100644
--- a/misc/shp_ts_file.cpp
+++ b/misc/shp_ts_file.cpp
@@ -22,7 +22,9 @@
#include "image_file.h"
#include "shp_decode.h"
#include "string_conversion.h"
+#ifndef XCC_MINIMAL_BUILD
#include "xcc_log.h"
+#endif
class Cshp_ts_decoder : public Cvideo_decoder
{
@@ -141,6 +143,7 @@ int get_ofs(int x, int y, int cx, int cy)
return x + cx * y;
}
+#ifndef XCC_MINIMAL_BUILD
int Cshp_ts_file::extract_as_pcx(const Cfname& name, t_file_type ft, const t_palet _palet, bool combine_shadows) const
{
t_palet palet;
@@ -378,6 +381,7 @@ void shp_split_shadows(Cvirtual_image& image)
image.load(d, cx, cy << 1, image.cb_pixel(), image.palet());
delete[] d;
}
+#endif
/*
void shp_xor_decode_frames(Cvirtual_image& image, int c_frames)
diff --git a/misc/shp_ts_file.h b/misc/shp_ts_file.h
index b38a053..76261cd 100644
--- a/misc/shp_ts_file.h
+++ b/misc/shp_ts_file.h
@@ -28,8 +28,10 @@ class Cshp_ts_file : public Cvideo_file<t_shp_ts_header>
{
public:
Cvideo_decoder* decoder(const t_palet_entry*);
+#ifndef XCC_MINIMAL_BUILD
int extract_as_pcx(const Cfname& name, t_file_type ft, const t_palet palet, bool combine_shadows = false) const;
Cvirtual_image extract_as_pcx_single(const t_palet _palet, bool combine_shadows = false) const;
+#endif
bool is_valid() const;
int cb_pixel() const
@@ -106,7 +108,10 @@ public:
int shp_decode4_size(const byte* s);
Cvirtual_binary shp_decode4(const byte* s, int cb_d);
int shp_encode4(const Cshp_ts_file& f, byte* d);
+
+#ifndef XCC_MINIMAL_BUILD
void shp_split_frames(Cvirtual_image& image, int cblocks_x, int cblocks_y);
void shp_split_shadows(Cvirtual_image& image);
void shp_xor_decode_frames(Cvirtual_image& image, int c_frames);
void shp_xor_encode_frames(Cvirtual_image& image, int c_frames);
+#endif
diff --git a/misc/virtual_image.cpp b/misc/virtual_image.cpp
index 5dfc3e2..456ea2d 100644
--- a/misc/virtual_image.cpp
+++ b/misc/virtual_image.cpp
@@ -21,6 +21,8 @@
#include <windows.h>
#include <gdiplus.h>
#include <shlwapi.h>
+
+#ifndef XCC_MINIMAL_BUILD
#include "dds_file.h"
#include "image_file.h"
#include "jpeg_file.h"
@@ -28,6 +30,7 @@
#include "pcx_file_write.h"
#include "png_file.h"
#include "tga_file.h"
+#endif
#include "virtual_image.h"
using namespace Gdiplus;
@@ -80,6 +83,8 @@ void Cvirtual_image::load(const void* image, int cx, int cy, int cb_pixel, const
palet(p, inflate);
}
+#ifndef XCC_MINIMAL_BUILD
+
int Cvirtual_image::load(const Cvirtual_binary& s)
{
Cdds_file dds_f;
@@ -323,3 +328,5 @@ void Cvirtual_image::increase_palet_depth()
d[i].b = (s[i].b & 63) * 255 / 63;
}
}
+
+#endif
diff --git a/misc/virtual_image.h b/misc/virtual_image.h
index 2396af8..0a2a2d6 100644
--- a/misc/virtual_image.h
+++ b/misc/virtual_image.h
@@ -121,3 +121,4 @@ private:
int m_cy = 0;
int mcb_pixel = 0;
};
+
diff --git a/misc/vxl_file.cpp b/misc/vxl_file.cpp
index 3132cdf..a629aa1 100644
--- a/misc/vxl_file.cpp
+++ b/misc/vxl_file.cpp
@@ -21,9 +21,11 @@
#include "file32.h"
#include "image_file.h"
+#ifndef XCC_MINIMAL_BUILD
#include "multi_line.h"
#include "pcx_decode.h"
#include "pcx_file_write.h"
+#endif
#include "string_conversion.h"
bool Cvxl_file::is_valid() const
@@ -51,6 +53,7 @@ bool Cvxl_file::is_valid() const
return true;
}
+#ifndef XCC_MINIMAL_BUILD
int Cvxl_file::extract_as_pcx(const Cfname& name, t_file_type ft, const t_palet _palet) const
{
t_palet palet;
@@ -98,6 +101,7 @@ int Cvxl_file::extract_as_pcx(const Cfname& name, t_file_type ft, const t_palet
}
return 0;
}
+#endif
ostream& Cvxl_file::extract_as_text(ostream& os) const
{
@@ -162,6 +166,7 @@ enum
vi_z_max
};
+#ifndef XCC_MINIMAL_BUILD
int Cvxl_file::extract_as_xif(const string& name) const
{
Cxif_key k;
@@ -458,6 +463,8 @@ Cvirtual_binary vxl_file_write(Cvirtual_tfile s)
return vxl_file_write(colors.data(), normals.data(), cx, cy, cz);
}
+#endif
+
struct t_vxl4_header
{
unsigned __int32 c_sections;
diff --git a/misc/vxl_file.h b/misc/vxl_file.h
index 395f5ac..5dd1857 100644
--- a/misc/vxl_file.h
+++ b/misc/vxl_file.h
@@ -22,14 +22,20 @@
#include "cc_structures.h"
#include "fname.h"
#include "virtual_tfile.h"
+#ifndef XCC_MINIMAL_BUILD
#include "xif_key.h"
+#endif
class Cvxl_file : public Ccc_file_sh<t_vxl_header>
{
public:
+#ifndef XCC_MINIMAL_BUILD
int extract_as_pcx(const Cfname& name, t_file_type ft, const t_palet _palet) const;
+#endif
ostream& extract_as_text(ostream& os) const;
+#ifndef XCC_MINIMAL_BUILD
int extract_as_xif(const string& name) const;
+#endif
bool is_valid() const;
int get_c_section_headers() const
@@ -93,6 +99,8 @@ public:
int vxl_decode4_size(const byte* s);
Cvirtual_binary vxl_decode4(const byte* s, int cb_d);
int vxl_encode4(const Cvxl_file& f, byte* d);
+#ifndef XCC_MINIMAL_BUILD
Cvirtual_binary vxl_file_write(const Cxif_key& s);
Cvirtual_binary vxl_file_write(const byte* s, const byte* s_normals, int cx, int cy, int cz);
Cvirtual_binary vxl_file_write(Cvirtual_tfile s);
+#endif
diff --git a/vcpkg.json b/vcpkg.json
index e0669e6..92d46dd 100644
--- a/vcpkg.json
+++ b/vcpkg.json
@@ -5,9 +5,8 @@
"boost-algorithm",
"boost-crc",
"bzip2",
- "libjpeg-turbo",
- "libpng",
- "libvorbis",
- "lzo"
- ]
+ "lzo",
+ "zlib"
+ ],
+ "builtin-baseline": "45c8b198b7647b6a68235353a00839082c910914"
}

12
3rdParty/xcc/vcpkg.json vendored Normal file
View file

@ -0,0 +1,12 @@
{
"name": "xcc",
"version-string": "0",
"dependencies": [
"boost-algorithm",
"boost-crc",
"bzip2",
"lzo",
"zlib"
],
"builtin-baseline": "45c8b198b7647b6a68235353a00839082c910914"
}

674
LICENSE.md Normal file
View file

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. 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
them 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 prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. 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.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey 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;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If 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 convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU 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 that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
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.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
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.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
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
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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 3 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, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program 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, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU 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 Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

View file

@ -0,0 +1,81 @@
/*
FinalSun/FinalAlert 2 Mission Editor
Copyright (C) 1999-2024 Electronic Arts, Inc.
Authored by Matthias Wagner
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 3 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, see <https://www.gnu.org/licenses/>.
*/
// AITriggerAddDlg.cpp: Implementierungsdatei
//
#include "stdafx.h"
#include "finalsun.h"
#include "AITriggerAddDlg.h"
#include "Variables.h"
#include "inlines.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Dialogfeld CAITriggerAddDlg
CAITriggerAddDlg::CAITriggerAddDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAITriggerAddDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAITriggerAddDlg)
m_AITrigger = _T("");
//}}AFX_DATA_INIT
}
void CAITriggerAddDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAITriggerAddDlg)
DDX_LBString(pDX, IDC_AITRIGGERS, m_AITrigger);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAITriggerAddDlg, CDialog)
//{{AFX_MSG_MAP(CAITriggerAddDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Behandlungsroutinen für Nachrichten CAITriggerAddDlg
BOOL CAITriggerAddDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CListBox* lb=(CListBox*)GetDlgItem(IDC_AITRIGGERS);
int i;
for(i=0;i<ai.sections["AITriggerTypes"].values.size();i++)
{
lb->AddString(*ai.sections["AITriggerTypes"].GetValueName(i)+ (CString)" " +GetParam(*ai.sections["AITriggerTypes"].GetValue(i), 0));
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX-Eigenschaftenseiten sollten FALSE zurückgeben
}

View file

@ -0,0 +1,66 @@
/*
FinalSun/FinalAlert 2 Mission Editor
Copyright (C) 1999-2024 Electronic Arts, Inc.
Authored by Matthias Wagner
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#if !defined(AFX_AITRIGGERADDDLG_H__19C60CA1_25D1_11D5_89B2_444553540000__INCLUDED_)
#define AFX_AITRIGGERADDDLG_H__19C60CA1_25D1_11D5_89B2_444553540000__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// AITriggerAddDlg.h : Header-Datei
//
/////////////////////////////////////////////////////////////////////////////
// Dialogfeld CAITriggerAddDlg
class CAITriggerAddDlg : public CDialog
{
// Konstruktion
public:
CAITriggerAddDlg(CWnd* pParent = NULL); // Standardkonstruktor
// Dialogfelddaten
//{{AFX_DATA(CAITriggerAddDlg)
enum { IDD = IDD_AITRIGGERADD };
CString m_AITrigger;
//}}AFX_DATA
// Überschreibungen
// Vom Klassen-Assistenten generierte virtuelle Funktionsüberschreibungen
//{{AFX_VIRTUAL(CAITriggerAddDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV-Unterstützung
//}}AFX_VIRTUAL
// Implementierung
protected:
// Generierte Nachrichtenzuordnungsfunktionen
//{{AFX_MSG(CAITriggerAddDlg)
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ fügt unmittelbar vor der vorhergehenden Zeile zusätzliche Deklarationen ein.
#endif // AFX_AITRIGGERADDDLG_H__19C60CA1_25D1_11D5_89B2_444553540000__INCLUDED_

View file

@ -0,0 +1,827 @@
/*
FinalSun/FinalAlert 2 Mission Editor
Copyright (C) 1999-2024 Electronic Arts, Inc.
Authored by Matthias Wagner
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 3 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, see <https://www.gnu.org/licenses/>.
*/
// AITriggerTypes.cpp: implementation file
//
#include "stdafx.h"
#include "FinalSun.h"
#include "AITriggerTypes.h"
#include "Mapdata.h"
#include "structs.h"
#include "variables.h"
#include "functions.h"
#include "inlines.h"
// AI trigger type enumeration
enum AITriggerEnum {
AIT_NONE = -1,
AIT_ENEMY_OWNS_X_COND_N = 0,
AIT_HOUSE_OWNS_X_COND_N,
AIT_POWER_YELLOW,
AIT_POWER_RED,
AIT_ENEMY_MONEY_COND_N,
AIT_CURTAIN_NEAR_READY,
AIT_SPHERE_NEAR_READY,
AIT_NEUTRAL_OWNS_X_COND_N,
};
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// property page CAITriggerTypes
IMPLEMENT_DYNCREATE(CAITriggerTypes, CDialog)
CAITriggerTypes::CAITriggerTypes() : CDialog(CAITriggerTypes::IDD)
{
//{{AFX_DATA_INIT(CAITriggerTypes)
m_Flag3 = _T("");
m_Flag4 = _T("");
m_Name = _T("");
m_Flag6 = _T("");
m_Flag7 = _T("");
m_Flag8 = _T("");
m_Flag9 = _T("");
m_Enabled = FALSE;
m_Condition = -1;
m_Number = 0;
m_Easy = FALSE;
m_Medium = FALSE;
m_Hard = FALSE;
m_BaseDefense = FALSE;
m_Skirmish = FALSE;
m_Flag5 = _T("");
m_MultiSide = _T("");
//}}AFX_DATA_INIT
}
CAITriggerTypes::~CAITriggerTypes()
{
}
void CAITriggerTypes::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAITriggerTypes)
DDX_Control(pDX, IDC_TEAMTYPE1, m_TeamType1);
DDX_Control(pDX, IDC_UNITTYPE, m_UnitType);
DDX_Control(pDX, IDC_TEAMTYPE2, m_TeamType2);
DDX_Control(pDX, IDC_FLAG2, m_Flag2);
DDX_Control(pDX, IDC_FLAG1, m_Flag1);
DDX_Control(pDX, IDC_DATA, m_Data);
DDX_Control(pDX, IDC_OWNER, m_Owner);
DDX_Control(pDX, IDC_FLOAT3, m_Float3);
DDX_Control(pDX, IDC_FLOAT2, m_Float2);
DDX_Control(pDX, IDC_FLOAT1, m_Float1);
DDX_Control(pDX, IDC_AITRIGGERTYPE, m_AITriggerType);
DDX_Text(pDX, IDC_FLAG4, m_Flag4);
DDX_Text(pDX, IDC_NAME, m_Name);
DDX_Check(pDX, IDC_ENABLED, m_Enabled);
DDX_CBIndex(pDX, IDC_CONDITION, m_Condition);
DDX_Text(pDX, IDC_NUMBER, m_Number);
DDV_MinMaxInt(pDX, m_Number, 0, 256);
DDX_Check(pDX, IDC_EASY, m_Easy);
DDX_Check(pDX, IDC_MEDIUM, m_Medium);
DDX_Check(pDX, IDC_HARD, m_Hard);
DDX_Check(pDX, IDC_BASEDEFENSE, m_BaseDefense);
DDX_Check(pDX, IDC_SKIRMISH, m_Skirmish);
DDX_CBString(pDX, IDC_MULTISIDE, m_MultiSide);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAITriggerTypes, CDialog)
//{{AFX_MSG_MAP(CAITriggerTypes)
ON_CBN_SELCHANGE(IDC_AITRIGGERTYPE, OnSelchangeAitriggertype)
ON_EN_CHANGE(IDC_NAME, OnChangeName)
ON_CBN_EDITCHANGE(IDC_OWNER, OnEditchangeOwner)
ON_CBN_EDITCHANGE(IDC_TEAMTYPE1, OnEditchangeTeamtype1)
ON_CBN_EDITCHANGE(IDC_TEAMTYPE2, OnEditchangeTeamtype2)
ON_CBN_EDITCHANGE(IDC_FLAG1, OnEditchangeFlag1)
ON_CBN_EDITCHANGE(IDC_FLAG2, OnEditchangeFlag2)
ON_CBN_EDITCHANGE(IDC_UNITTYPE, OnEditchangeUnittype)
ON_CBN_EDITCHANGE(IDC_DATA, OnEditchangeData)
ON_EN_CHANGE(IDC_FLOAT1, OnChangeFloat1)
ON_EN_CHANGE(IDC_FLOAT2, OnChangeFloat2)
ON_EN_CHANGE(IDC_FLOAT3, OnChangeFloat3)
ON_EN_CHANGE(IDC_FLAG4, OnChangeFlag4)
ON_BN_CLICKED(IDC_ENABLED, OnEnabled)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
ON_CBN_EDITCHANGE(IDC_AITRIGGERTYPE, OnEditchangeAitriggertype)
ON_CBN_SELCHANGE(IDC_CONDITION, OnSelchangeCondition)
ON_EN_CHANGE(IDC_NUMBER, OnChangeNumber)
ON_BN_CLICKED(IDC_EASY, OnEasy)
ON_BN_CLICKED(IDC_MEDIUM, OnMedium)
ON_BN_CLICKED(IDC_HARD, OnHard)
ON_BN_CLICKED(IDC_BASEDEFENSE, OnBasedefense)
ON_BN_CLICKED(IDC_SKIRMISH, OnSkirmish)
ON_CBN_EDITCHANGE(IDC_MULTISIDE, OnEditchangeMultiside)
ON_CBN_SELCHANGE(IDC_MULTISIDE, OnSelchangeMultiside)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// message handlers CAITriggerTypes
void ListObjects(CComboBox& cb)
{
CComboBox& m_UnitType=cb;
CIniFile& ini=Map->GetIniFile();
int i;
CString ss="InfantryTypes";
for(i=0;i<rules.sections[ss].values.size();i++)
{
CString type;
CString s;
type=*rules.sections[ss].GetValue(i);
s=type;
s+=" (";
s+=Map->GetUnitName((char*)(LPCTSTR)type);
s+=")";
m_UnitType.AddString(s);
}
for(i=0;i<ini.sections[ss].values.size();i++)
{
CString type;
CString s;
type=*ini.sections[ss].GetValue(i);
s=type;
s+=" (";
s+=Map->GetUnitName((char*)(LPCTSTR)type);
s+=")";
m_UnitType.AddString(s);
}
ss="VehicleTypes";
for(i=0;i<rules.sections[ss].values.size();i++)
{
CString type;
CString s;
type=*rules.sections[ss].GetValue(i);
s=type;
s+=" (";
s+=Map->GetUnitName((char*)(LPCTSTR)type);
s+=")";
m_UnitType.AddString(s);
}
for(i=0;i<ini.sections[ss].values.size();i++)
{
CString type;
CString s;
type=*ini.sections[ss].GetValue(i);
s=type;
s+=" (";
s+=Map->GetUnitName((char*)(LPCTSTR)type);
s+=")";
m_UnitType.AddString(s);
}
ss="AircraftTypes";
for(i=0;i<rules.sections[ss].values.size();i++)
{
CString type;
CString s;
type=*rules.sections[ss].GetValue(i);
s=type;
s+=" (";
s+=Map->GetUnitName((char*)(LPCTSTR)type);
s+=")";
m_UnitType.AddString(s);
}
for(i=0;i<ini.sections[ss].values.size();i++)
{
CString type;
CString s;
type=*ini.sections[ss].GetValue(i);
s=type;
s+=" (";
s+=Map->GetUnitName((char*)(LPCTSTR)type);
s+=")";
m_UnitType.AddString(s);
}
ss="BuildingTypes";
for(i=0;i<rules.sections[ss].values.size();i++)
{
CString type;
CString s;
type=*rules.sections[ss].GetValue(i);
s=type;
s+=" (";
s+=Map->GetUnitName((char*)(LPCTSTR)type);
s+=")";
m_UnitType.AddString(s);
}
for(i=0;i<ini.sections[ss].values.size();i++)
{
CString type;
CString s;
type=*ini.sections[ss].GetValue(i);
s=type;
s+=" (";
s+=Map->GetUnitName((char*)(LPCTSTR)type);
s+=")";
m_UnitType.AddString(s);
}
}
void CAITriggerTypes::UpdateDialog()
{
int sel=m_AITriggerType.GetCurSel();
m_AITriggerType.SetRedraw(FALSE);
while(m_AITriggerType.DeleteString(0)!=CB_ERR);
ListHouses(m_Owner,FALSE,TRUE);
m_Owner.AddString("<all>");
ListTeamTypes(m_TeamType1, TRUE);
ListTeamTypes(m_TeamType2, TRUE);
int i;
for(i=0;i<Map->GetAITriggerTypeCount();i++)
{
AITRIGGERTYPE aitt;
Map->GetAITriggerType(i, &aitt);
CString s=aitt.ID;
s+=" (";
s+=aitt.name;
s+=")";
m_AITriggerType.AddString(s);
}
m_AITriggerType.SetCurSel(0);
if(sel!=-1)
m_AITriggerType.SetCurSel(sel);
OnSelchangeAitriggertype();
m_AITriggerType.SetRedraw(TRUE);
m_AITriggerType.RedrawWindow();
}
void CAITriggerTypes::OnSelchangeAitriggertype()
{
int sel=m_AITriggerType.GetCurSel();
if(sel<0) return;
CString aitrigger;
m_AITriggerType.GetLBText(sel,aitrigger);
TruncSpace(aitrigger);
AITRIGGERTYPE aitt;
Map->GetAITriggerType(Map->GetAITriggerTypeIndex(aitrigger), &aitt);
m_Name=aitt.name;
m_TeamType1.SetWindowText(aitt.teamtype1);
m_Owner.SetWindowText(TranslateHouse(aitt.owner, TRUE));
m_Flag1.SetWindowText(aitt.techlevel);
//m_Flag2.SetWindowText(aitt.type);
int type=atoi(aitt.type)+1;
m_Flag2.SetCurSel(type);
m_UnitType.SetWindowText(aitt.unittype);
m_Data.SetWindowText(aitt.data);
m_Float1.SetWindowText(aitt.float1);
m_Float2.SetWindowText(aitt.float2);
m_Float3.SetWindowText(aitt.float3);
//m_Flag3=aitt.skirmish;
m_Skirmish=isTrue(aitt.skirmish);
m_Flag4=aitt.flag4;
//m_Flag5=aitt.multihouse;
m_MultiSide=aitt.multihouse;
m_BaseDefense=isTrue(aitt.basedefense);
m_TeamType2.SetWindowText(aitt.teamtype2);
m_Easy=isTrue(aitt.easy);
m_Medium=isTrue(aitt.medium);
m_Hard=isTrue(aitt.hard);
m_Enabled=FALSE;
CIniFile& ini=Map->GetIniFile();
if(ini.sections["AITriggerTypesEnable"].values.find((LPCTSTR)aitrigger)!=ini.sections["AITriggerTypesEnable"].values.end())
if(stricmp(ini.sections["AITriggerTypesEnable"].values[(LPCTSTR)aitrigger], "yes")==NULL)
m_Enabled=TRUE;
AITrigInfo info;
info=ConvertToAITrigInfoFromHex((char*)(LPCSTR)aitt.data);
m_Condition=info.Condition;
m_Number=info.Number;
ListObjects(m_UnitType);
UpdateData(FALSE);
}
void CAITriggerTypes::OnChangeName()
{
UpdateData();
CString value;
value=m_Name;
if(value.GetLength()==0) value=" ";
SetAITriggerParam(value, 0);
UpdateDialog();
}
void CAITriggerTypes::OnEditchangeOwner()
{
CString value;
m_Owner.GetWindowText(value);
value=TranslateHouse(value);
SetAITriggerParam(value, 2);
}
void CAITriggerTypes::OnEditchangeTeamtype1()
{
CString value;
m_TeamType1.GetWindowText(value);
TruncSpace(value);
SetAITriggerParam(value, 1);
}
void CAITriggerTypes::OnEditchangeTeamtype2()
{
CString value;
m_TeamType2.GetWindowText(value);
TruncSpace(value);
SetAITriggerParam(value, 14);
}
void CAITriggerTypes::OnEditchangeFlag1()
{
CString value;
m_Flag1.GetWindowText(value);
SetAITriggerParam(value, 3);
}
void CAITriggerTypes::OnEditchangeFlag2()
{
CString value;
m_Flag2.GetWindowText(value);
TruncSpace(value);
SetAITriggerParam(value, 4);
}
void CAITriggerTypes::OnEditchangeUnittype()
{
CString value;
m_UnitType.GetWindowText(value);
TruncSpace(value);
SetAITriggerParam(value, 5);
}
void CAITriggerTypes::OnEditchangeData()
{
/*
This function should also valid the data!
*/
CString value;
m_Data.GetWindowText(value);
TruncSpace(value);
// max 64 chars... min 64 chars too...
((char*)(LPCTSTR)value)[64]=0;
int ToInsert=64-value.GetLength();
CString nulls('0',ToInsert);
value.Insert(value.GetLength()-ToInsert, nulls);
SetAITriggerParam(value, 6);
int editsel=m_Data.GetEditSel();
UpdateDialog();
m_Data.SetEditSel(editsel,editsel+1);
}
void CAITriggerTypes::OnChangeFloat1()
{
CString value;
m_Float1.GetWindowText(value);
SetAITriggerParam(value, 7);
}
void CAITriggerTypes::OnChangeFloat2()
{
CString value;
m_Float2.GetWindowText(value);
SetAITriggerParam(value, 8);
}
void CAITriggerTypes::OnChangeFloat3()
{
CString value;
m_Float3.GetWindowText(value);
SetAITriggerParam(value, 9);
}
void CAITriggerTypes::OnChangeFlag3()
{
}
void CAITriggerTypes::OnChangeFlag4()
{
UpdateData();
CString value;
value=m_Flag4;
SetAITriggerParam(value, 11);
}
void CAITriggerTypes::OnChangeFlag5()
{
}
void CAITriggerTypes::OnChangeFlag6()
{
}
void CAITriggerTypes::OnChangeFlag7()
{
}
void CAITriggerTypes::OnChangeFlag8()
{
UpdateData();
CString value;
value=m_Flag8;
SetAITriggerParam(value, 16);
}
void CAITriggerTypes::OnChangeFlag9()
{
UpdateData();
CString value;
value=m_Flag9;
SetAITriggerParam(value, 17);
}
void CAITriggerTypes::OnEnabled()
{
// enable or disable trigger
UpdateData();
int sel=m_AITriggerType.GetCurSel();
if(sel<0) return;
CString aitrigger;
m_AITriggerType.GetLBText(sel,aitrigger);
TruncSpace(aitrigger);
CIniFile& ini=Map->GetIniFile();
if(m_Enabled)
{
// enable it
ini.sections["AITriggerTypesEnable"].values[(LPCTSTR)aitrigger]="yes";
}
else
ini.sections["AITriggerTypesEnable"].values.erase((LPCTSTR)aitrigger);
}
void CAITriggerTypes::SetAITriggerParam(const char *value, int param)
{
int sel=m_AITriggerType.GetCurSel();
if(sel<0) return;
CString aitrigger;
m_AITriggerType.GetLBText(sel,aitrigger);
TruncSpace(aitrigger);
CIniFile& ini=Map->GetIniFile();
ini.sections["AITriggerTypes"].values[aitrigger]=SetParam(ini.sections["AITriggerTypes"].values[aitrigger],param,value);
}
void CAITriggerTypes::OnAdd()
{
CString ID=GetFreeID();
CIniFile& ini=Map->GetIniFile();
CString data="New AI Trigger,";
// now try to set a teamtype
if(ini.sections["TeamTypes"].values.size()>0)
{
data+=*ini.sections["TeamTypes"].GetValue(0);
}
else
{
data+="<none>";
}
data+=",<all>,";
// the flag here... i first thought it´s an ID, but it more seems to be an value specifying the importance of the trigger
data+="1,";
// the flag 2 seems to be the type of the trigger. -1 seems to be pool
data+="0,";
// now stuff
data+="<none>,0000000000000000000000000000000000000000000000000000000000000000,50.000000,30.000000,50.000000,1,0,1,1,";
// a pool seems to need both teamtypes the same
if(ini.sections["TeamTypes"].values.size()>0)
{
data+="<none>";//*ini.sections["TeamTypes"].GetValue(0);
}
else
{
data+="<none>";
}
data+=",1,1,1";
ini.sections["AITriggerTypes"].values[ID]=data;
UpdateDialog();
// now make current id visible
int i;
for(i=0;i<m_AITriggerType.GetCount();i++)
{
CString cuString;
m_AITriggerType.GetLBText(i, cuString);
TruncSpace(cuString);
if(cuString==ID)
{
m_AITriggerType.SetCurSel(i);
OnSelchangeAitriggertype();
}
}
}
void CAITriggerTypes::OnDelete()
{
int sel=m_AITriggerType.GetCurSel();
if(sel<0) return;
CString aitrigger;
m_AITriggerType.GetLBText(sel,aitrigger);
TruncSpace(aitrigger);
CIniFile& ini=Map->GetIniFile();
ini.sections["AITriggerTypes"].values.erase(aitrigger);
ini.sections["AITriggerTypesEnable"].values.erase(aitrigger);
UpdateDialog();
}
void CAITriggerTypes::OnEditchangeAitriggertype()
{
OnSelchangeAitriggertype();
}
AITrigInfo CAITriggerTypes::ConvertToAITrigInfoFromHex(char *aitinfo)
{
int index=0;
AITrigInfo info;
char* rawdata=(char*)&info;
char hexbuff[3]="00";
char* dummy=NULL;
while(*aitinfo!='\0')
{
while(isspace((int)*aitinfo)) aitinfo++;
hexbuff[0]=*aitinfo++;
ASSERT(*aitinfo!='\0');
if(*aitinfo!='\0'){
hexbuff[1]=*aitinfo++;
} else {
hexbuff[1]='\0';
}
ASSERT(index<sizeof(AITrigInfo));
if(index>=sizeof(AITrigInfo)) break;
*rawdata++=strtol(hexbuff, &dummy, 16);
index++;
}
return info;
}
char* CAITriggerTypes::ConvertToHexFromAITrigInfo(AITrigInfo info, char* buffer)
{
unsigned char* aitinfobuffer=(unsigned char*)buffer;
/*
** Convert the AITrigInfo union data structure to ASCII format string
*/
{
int index = 0;
unsigned char *rawdata = (unsigned char *)&info;
unsigned char *aitinfobuffptr = &aitinfobuffer[0];
for (; index < sizeof(AITrigInfo); index++, rawdata++, aitinfobuffptr += 2) {
sprintf((char *)aitinfobuffptr, "%02x", *rawdata);
}
*aitinfobuffptr = '\0';
}
return (char*)aitinfobuffer;
}
void CAITriggerTypes::OnSelchangeCondition()
{
int sel=m_AITriggerType.GetCurSel();
if(sel<0) return;
UpdateData(TRUE);
AITrigInfo info;
info.Condition=(ConditionEnum)m_Condition;
info.Number=m_Number;
char buffer[65];
ConvertToHexFromAITrigInfo(info, buffer);
SetAITriggerParam(buffer, 6);
UpdateDialog();
}
void CAITriggerTypes::OnChangeNumber()
{
int sel=m_AITriggerType.GetCurSel();
if(sel<0) return;
UpdateData(TRUE);
AITrigInfo info;
memset(&info, 0, sizeof(AITrigInfo));
info.Condition=(ConditionEnum)m_Condition;
info.Number=m_Number;
char buffer[65];
ConvertToHexFromAITrigInfo(info, buffer);
//MessageBox(buffer);
//m_Data.SetWindowText(buffer);
SetAITriggerParam(buffer, 6);
UpdateDialog();
}
void CAITriggerTypes::OnEasy()
{
UpdateData();
CString value;
value="1";
if(!m_Easy) value="0";
SetAITriggerParam(value, 15);
}
void CAITriggerTypes::OnMedium()
{
UpdateData();
CString value;
value="1";
if(!m_Medium) value="0";
SetAITriggerParam(value, 16);
}
void CAITriggerTypes::OnHard()
{
UpdateData();
CString value;
value="1";
if(!m_Hard) value="0";
SetAITriggerParam(value, 17);
}
void CAITriggerTypes::OnBasedefense()
{
UpdateData();
CString value;
value="1";
if(!m_BaseDefense) value="0";
SetAITriggerParam(value, 13);
}
void CAITriggerTypes::OnSkirmish()
{
UpdateData();
CString value;
value="1";
if(!m_Skirmish) value="0";
SetAITriggerParam(value, 10);
}
void CAITriggerTypes::OnEditchangeMultiside()
{
UpdateData();
CString value;
value=m_MultiSide;
TruncSpace(value);
SetAITriggerParam(value, 12);
}
void CAITriggerTypes::OnSelchangeMultiside()
{
CString s;
CComboBox& box=*(CComboBox*)GetDlgItem(IDC_MULTISIDE);
box.GetLBText(box.GetCurSel(), s);
box.SetWindowText(s);
OnEditchangeMultiside();
}

View file

@ -0,0 +1,132 @@
/*
FinalSun/FinalAlert 2 Mission Editor
Copyright (C) 1999-2024 Electronic Arts, Inc.
Authored by Matthias Wagner
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#if !defined(AFX_AITRIGGERTYPES_H__47F0A0E0_A8DC_11D3_B63B_B4F5BEE55940__INCLUDED_)
#define AFX_AITRIGGERTYPES_H__47F0A0E0_A8DC_11D3_B63B_B4F5BEE55940__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// AITriggerTypes.h : Header file
//
#include "structs.h"
/////////////////////////////////////////////////////////////////////////////
// dialog field CAITriggerTypes
class CAITriggerTypes : public CDialog
{
DECLARE_DYNCREATE(CAITriggerTypes)
// construction
public:
char* ConvertToHexFromAITrigInfo(AITrigInfo info, char* buffer);
void SetAITriggerParam(const char* value, int param);
void UpdateDialog();
CAITriggerTypes();
~CAITriggerTypes();
// dialog field data
//{{AFX_DATA(CAITriggerTypes)
enum { IDD = IDD_AITRIGGERTYPES };
CMyComboBox m_TeamType1;
CMyComboBox m_UnitType;
CMyComboBox m_TeamType2;
CMyComboBox m_Flag2;
CMyComboBox m_Flag1;
CMyComboBox m_Data;
CMyComboBox m_Owner;
CFloatEdit m_Float3;
CFloatEdit m_Float2;
CFloatEdit m_Float1;
CMyComboBox m_AITriggerType;
CString m_Flag3;
CString m_Flag4;
CString m_Name;
CString m_Flag6;
CString m_Flag7;
CString m_Flag8;
CString m_Flag9;
BOOL m_Enabled;
int m_Condition;
int m_Number;
BOOL m_Easy;
BOOL m_Medium;
BOOL m_Hard;
BOOL m_BaseDefense;
BOOL m_Skirmish;
CString m_Flag5;
CString m_MultiSide;
//}}AFX_DATA
// overwriteables
// generated virtual overwriteables
//{{AFX_VIRTUAL(CAITriggerTypes)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// implementation
protected:
AITrigInfo ConvertToAITrigInfoFromHex(char* aitinfo);
// generated message maps
//{{AFX_MSG(CAITriggerTypes)
afx_msg void OnSelchangeAitriggertype();
afx_msg void OnChangeName();
afx_msg void OnEditchangeOwner();
afx_msg void OnEditchangeTeamtype1();
afx_msg void OnEditchangeTeamtype2();
afx_msg void OnEditchangeFlag1();
afx_msg void OnEditchangeFlag2();
afx_msg void OnEditchangeUnittype();
afx_msg void OnEditchangeData();
afx_msg void OnChangeFloat1();
afx_msg void OnChangeFloat2();
afx_msg void OnChangeFloat3();
afx_msg void OnChangeFlag3();
afx_msg void OnChangeFlag4();
afx_msg void OnChangeFlag5();
afx_msg void OnChangeFlag6();
afx_msg void OnChangeFlag7();
afx_msg void OnChangeFlag8();
afx_msg void OnChangeFlag9();
afx_msg void OnEnabled();
afx_msg void OnAdd();
afx_msg void OnDelete();
afx_msg void OnEditchangeAitriggertype();
afx_msg void OnSelchangeCondition();
afx_msg void OnChangeNumber();
afx_msg void OnEasy();
afx_msg void OnMedium();
afx_msg void OnHard();
afx_msg void OnBasedefense();
afx_msg void OnSkirmish();
afx_msg void OnEditchangeMultiside();
afx_msg void OnSelchangeMultiside();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
#endif // AFX_AITRIGGERTYPES_H__47F0A0E0_A8DC_11D3_B63B_B4F5BEE55940__INCLUDED_

View file

@ -0,0 +1,170 @@
/*
FinalSun/FinalAlert 2 Mission Editor
Copyright (C) 1999-2024 Electronic Arts, Inc.
Authored by Matthias Wagner
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 3 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, see <https://www.gnu.org/licenses/>.
*/
// AiTriggerTypesEnable.cpp: Implementierungsdatei
//
#include "stdafx.h"
#include "FinalSun.h"
#include "AiTriggerTypesEnable.h"
#include "mapdata.h"
#include "variables.h"
#include "inlines.h"
#include "aitriggeradddlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Eigenschaftenseite CAiTriggerTypesEnable
IMPLEMENT_DYNCREATE(CAiTriggerTypesEnable, CDialog)
CAiTriggerTypesEnable::CAiTriggerTypesEnable() : CDialog(CAiTriggerTypesEnable::IDD)
{
//{{AFX_DATA_INIT(CAiTriggerTypesEnable)
// HINWEIS: Der Klassen-Assistent fügt hier Elementinitialisierung ein
//}}AFX_DATA_INIT
}
CAiTriggerTypesEnable::~CAiTriggerTypesEnable()
{
}
void CAiTriggerTypesEnable::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAiTriggerTypesEnable)
DDX_Control(pDX, IDC_AITRIGGERTYPE, m_AITriggerType);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAiTriggerTypesEnable, CDialog)
//{{AFX_MSG_MAP(CAiTriggerTypesEnable)
ON_BN_CLICKED(IDC_ENABLEALL, OnEnableall)
ON_CBN_SELCHANGE(IDC_AITRIGGERTYPE, OnSelchangeAitriggertype)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
ON_BN_CLICKED(IDC_ADD, OnAdd)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Behandlungsroutinen für Nachrichten CAiTriggerTypesEnable
void CAiTriggerTypesEnable::UpdateDialog()
{
int sel=m_AITriggerType.GetCurSel();
if(sel<0) sel=0;
while(m_AITriggerType.DeleteString(0)!=CB_ERR);
CIniFile& ini=Map->GetIniFile();
int i;
for(i=0;i<ini.sections["AITriggerTypesEnable"].values.size();i++)
{
CString aitrigger=*ini.sections["AITriggerTypesEnable"].GetValueName(i);
CString str=aitrigger;
str+=" (";
if(ai.sections["AITriggerTypes"].values.find(aitrigger)!=ai.sections["AITriggerTypes"].values.end())
{
// standard ai trigger
str+=GetParam(ai.sections["AITriggerTypes"].values[aitrigger],0);
str+=" -> ";
str+=*ini.sections["AITriggerTypesEnable"].GetValue(i);
}
if(ini.sections["AITriggerTypes"].values.find(aitrigger)!=ini.sections["AITriggerTypes"].values.end())
{
str+=GetParam(ini.sections["AITriggerTypes"].values[aitrigger],0);
str+=" -> ";
str+=*ini.sections["AITriggerTypesEnable"].GetValue(i);
}
str+=")";
m_AITriggerType.AddString(str);
}
if(m_AITriggerType.SetCurSel(sel)==CB_ERR)
m_AITriggerType.SetCurSel(0);
OnSelchangeAitriggertype();
}
void CAiTriggerTypesEnable::OnEnableall()
{
// enable all standard ai triggers
CIniFile& ini=Map->GetIniFile();
int i;
for(i=0;i<ai.sections["AITriggerTypes"].values.size();i++)
{
ini.sections["AITriggerTypesEnable"].values[*ai.sections["AITriggerTypes"].GetValueName(i)]="yes";
}
UpdateDialog();
}
void CAiTriggerTypesEnable::OnSelchangeAitriggertype()
{
int sel=m_AITriggerType.GetCurSel();
if(sel<0) return;
}
void CAiTriggerTypesEnable::OnDelete()
{
int sel=m_AITriggerType.GetCurSel();
if(sel<0) return;
CString aitrigger;
m_AITriggerType.GetLBText(sel,aitrigger);
if(aitrigger.Find(" ")>=0) aitrigger.SetAt(aitrigger.Find(" "), 0);
CIniFile& ini=Map->GetIniFile();
ini.sections["AITriggerTypesEnable"].values.erase((LPCTSTR)aitrigger);
UpdateDialog();
}
void CAiTriggerTypesEnable::OnAdd()
{
//CString p=InputBox("Please enter the ID of the AITriggerType (for a list of all AITriggerType-IDs use the All-Section)","Enable AITriggerType");
CAITriggerAddDlg dlg;
if(dlg.DoModal()==IDCANCEL) return;
CString p=dlg.m_AITrigger;
TruncSpace(p);
if(p.GetLength()==0) return;
CIniFile& ini=Map->GetIniFile();
ini.sections["AITriggerTypesEnable"].values[p]="yes";
UpdateDialog();
}

View file

@ -0,0 +1,73 @@
/*
FinalSun/FinalAlert 2 Mission Editor
Copyright (C) 1999-2024 Electronic Arts, Inc.
Authored by Matthias Wagner
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#if !defined(AFX_AITRIGGERTYPESENABLE_H__5CA6D080_A4D2_11D3_B63B_808EC7AC6440__INCLUDED_)
#define AFX_AITRIGGERTYPESENABLE_H__5CA6D080_A4D2_11D3_B63B_808EC7AC6440__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// AiTriggerTypesEnable.h : Header-Datei
//
/////////////////////////////////////////////////////////////////////////////
// Dialogfeld CAiTriggerTypesEnable
class CAiTriggerTypesEnable : public CDialog
{
DECLARE_DYNCREATE(CAiTriggerTypesEnable)
// Konstruktion
public:
void UpdateDialog();
CAiTriggerTypesEnable();
~CAiTriggerTypesEnable();
// Dialogfelddaten
//{{AFX_DATA(CAiTriggerTypesEnable)
enum { IDD = IDD_AITRIGGERTYPESENABLE };
CComboBox m_AITriggerType;
//}}AFX_DATA
// Überschreibungen
// Der Klassen-Assistent generiert virtuelle Funktionsüberschreibungen
//{{AFX_VIRTUAL(CAiTriggerTypesEnable)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV-Unterstützung
//}}AFX_VIRTUAL
// Implementierung
protected:
// Generierte Nachrichtenzuordnungsfunktionen
//{{AFX_MSG(CAiTriggerTypesEnable)
afx_msg void OnEnableall();
afx_msg void OnSelchangeAitriggertype();
afx_msg void OnDelete();
afx_msg void OnAdd();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ fügt unmittelbar vor der vorhergehenden Zeile zusätzliche Deklarationen ein.
#endif // AFX_AITRIGGERTYPESENABLE_H__5CA6D080_A4D2_11D3_B63B_808EC7AC6440__INCLUDED_

166
MissionEditor/Aircraft.cpp Normal file
View file

@ -0,0 +1,166 @@
/*
FinalSun/FinalAlert 2 Mission Editor
Copyright (C) 1999-2024 Electronic Arts, Inc.
Authored by Matthias Wagner
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 3 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, see <https://www.gnu.org/licenses/>.
*/
// Aircraft.cpp: implementation file
//
#include "stdafx.h"
#include "FinalSun.h"
#include "Aircraft.h"
#include "mapdata.h"
#include "variables.h"
#include "functions.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// dialog field CAircraft
CAircraft::CAircraft(CWnd* pParent /*=NULL*/)
: CDialog(CAircraft::IDD, pParent)
{
//{{AFX_DATA_INIT(CAircraft)
m_direction = _T("");
m_house = _T("");
m_flag1 = _T("");
m_flag2 = _T("");
m_flag3 = _T("");
m_flag4 = _T("");
m_action = _T("");
m_tag = _T("");
//}}AFX_DATA_INIT
}
void CAircraft::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAircraft)
DDX_Control(pDX, IDC_STRENGTH, m_strength_ctrl);
DDX_CBString(pDX, IDC_DIRECTION, m_direction);
DDX_CBString(pDX, IDC_HOUSE, m_house);
DDX_Text(pDX, IDC_P1, m_flag1);
DDX_Text(pDX, IDC_P2, m_flag2);
DDX_Text(pDX, IDC_P3, m_flag3);
DDX_Text(pDX, IDC_P4, m_flag4);
DDX_CBString(pDX, IDC_STATE, m_action);
DDX_CBString(pDX, IDC_TAG, m_tag);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAircraft, CDialog)
//{{AFX_MSG_MAP(CAircraft)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// handlers for messages CAircraft
void CAircraft::Init(CString house, CString strength, CString direction, CString action, CString tag, CString flag1, CString flag2, CString flag3, CString flag4)
{
if(house.GetLength()==0)
{
m_house=TranslateHouse(Map->GetHouseID(0), TRUE);
}
else
m_house=TranslateHouse(house, TRUE);
m_flag1=flag1;
m_flag2=flag2;
m_flag3=flag3;
m_flag4=flag4;
m_action=action;
m_strength=strength;
m_tag=tag;
m_direction=direction;
}
BOOL CAircraft::OnInitDialog()
{
CDialog::OnInitDialog();
// init the common (!) dialog things
int i;
CComboBox* house, *tag;
house=(CComboBox*)GetDlgItem(IDC_HOUSE);
tag=(CComboBox*)GetDlgItem(IDC_TAG);
ListHouses(*house, FALSE);
ListTags(*tag, TRUE);
ListYesNo(*(CComboBox*)GetDlgItem(IDC_P3));
UpdateData(FALSE);
m_strength_ctrl.SetRange(0,256);
m_strength_ctrl.SetPos(atoi(m_strength));
UpdateStrings();
return TRUE;
}
void CAircraft::OnOK()
{
CDialog::OnOK();
m_strength=GetText(&m_strength_ctrl);
UpdateData();
m_house=TranslateHouse(m_house, FALSE);
TruncSpace(m_tag);
TruncSpace(m_flag1);
TruncSpace(m_flag2);
TruncSpace(m_flag3);
TruncSpace(m_flag4);
}
void CAircraft::UpdateStrings()
{
SetWindowText(GetLanguageStringACP("AirCap"));
GetDlgItem(IDC_LHOUSE)->SetWindowText(GetLanguageStringACP("AirHouse"));
GetDlgItem(IDC_LDESC)->SetWindowText(GetLanguageStringACP("AirDesc"));
GetDlgItem(IDC_LSTRENGTH)->SetWindowText(GetLanguageStringACP("AirStrength"));
GetDlgItem(IDC_LSTATE)->SetWindowText(GetLanguageStringACP("AirState"));
GetDlgItem(IDC_LDIRECTION)->SetWindowText(GetLanguageStringACP("AirDirection"));
GetDlgItem(IDC_LTAG)->SetWindowText(GetLanguageStringACP("AirTag"));
GetDlgItem(IDC_LP1)->SetWindowText(GetLanguageStringACP("AirP1"));
GetDlgItem(IDC_LP2)->SetWindowText(GetLanguageStringACP("AirP2"));
GetDlgItem(IDC_LP3)->SetWindowText(GetLanguageStringACP("AirP3"));
GetDlgItem(IDC_LP4)->SetWindowText(GetLanguageStringACP("AirP4"));
SetDlgItemText(IDOK, GetLanguageStringACP("OK"));
SetDlgItemText(IDCANCEL, GetLanguageStringACP("Cancel"));
}

75
MissionEditor/Aircraft.h Normal file
View file

@ -0,0 +1,75 @@
/*
FinalSun/FinalAlert 2 Mission Editor
Copyright (C) 1999-2024 Electronic Arts, Inc.
Authored by Matthias Wagner
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#if !defined(AFX_AIRCRAFT_H__15BD6160_8953_11D3_B63B_A583BFBD8C41__INCLUDED_)
#define AFX_AIRCRAFT_H__15BD6160_8953_11D3_B63B_A583BFBD8C41__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Aircraft.h : Header-Datei
//
class CAircraft : public CDialog
{
// construction
public:
void UpdateStrings();
CString m_strength;
void Init(CString house="", CString strength="256", CString direction="64", CString action="Guard", CString tag="None", CString flag1="0", CString flag2="0", CString flag3="0", CString flag4="0");
CAircraft(CWnd* pParent = NULL); // standard constructor
// dialog field data
//{{AFX_DATA(CAircraft)
enum { IDD = IDD_AIRCRAFT };
CSliderCtrl m_strength_ctrl;
CString m_direction;
CString m_house;
CString m_flag1;
CString m_flag2;
CString m_flag3;
CString m_flag4;
CString m_action;
CString m_tag;
//}}AFX_DATA
// overwriteables
// generated from class assistant
//{{AFX_VIRTUAL(CAircraft)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// implementation
protected:
// generated message maps
//{{AFX_MSG(CAircraft)
virtual BOOL OnInitDialog();
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
#endif // AFX_AIRCRAFT_H__15BD6160_8953_11D3_B63B_A583BFBD8C41__INCLUDED_

285
MissionEditor/All.cpp Normal file
View file

@ -0,0 +1,285 @@
/*
FinalSun/FinalAlert 2 Mission Editor
Copyright (C) 1999-2024 Electronic Arts, Inc.
Authored by Matthias Wagner
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 3 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, see <https://www.gnu.org/licenses/>.
*/
// All1.cpp: Implementierungsdatei
//
#include "stdafx.h"
#include "FinalSun.h"
#include "All.h"
#include "mapdata.h"
#include "variables.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CFinalSunApp theApp;
#include "ImportIni.h"
/////////////////////////////////////////////////////////////////////////////
// Dialogfeld CAll
CAll::CAll(CWnd* pParent /*=NULL*/)
: CDialog(CAll::IDD, pParent)
{
//{{AFX_DATA_INIT(CAll)
// HINWEIS: Der Klassen-Assistent fügt hier Elementinitialisierung ein
//}}AFX_DATA_INIT
}
void CAll::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAll)
DDX_Control(pDX, IDC_VALUE, m_Value);
DDX_Control(pDX, IDC_KEYS, m_Keys);
DDX_Control(pDX, IDC_INISECTION, m_IniSection);
DDX_Control(pDX, IDC_DELETESECTION, m_DeleteSection);
DDX_Control(pDX, IDC_DELETEKEY, m_DeleteKey);
DDX_Control(pDX, IDC_ADDSECTION, m_AddSection);
DDX_Control(pDX, IDC_ADDKEY, m_AddKey);
DDX_Control(pDX, IDC_SECTIONS, m_Sections);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAll, CDialog)
//{{AFX_MSG_MAP(CAll)
ON_CBN_SELCHANGE(IDC_SECTIONS, OnSelchangeSections)
ON_EN_CHANGE(IDC_VALUE, OnChangeValue)
ON_LBN_SELCHANGE(IDC_KEYS, OnSelchangeKeys)
ON_EN_UPDATE(IDC_VALUE, OnUpdateValue)
ON_BN_CLICKED(IDC_ADDSECTION, OnAddsection)
ON_BN_CLICKED(IDC_DELETESECTION, OnDeletesection)
ON_BN_CLICKED(IDC_DELETEKEY, OnDeletekey)
ON_BN_CLICKED(IDC_ADDKEY, OnAddkey)
ON_BN_CLICKED(IDC_INISECTION, OnInisection)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Behandlungsroutinen für Nachrichten CAll
void CAll::UpdateDialog()
{
//m_Sections.Clear();
while(m_Sections.DeleteString(0)!=-1);
while(m_Keys.DeleteString(0)!=-1);
CIniFile& ini=Map->GetIniFile();
m_Value.SetWindowText("");
int i;
for(i=ini.sections.size()-1;i>=0;i--)
{
const CString* name=ini.GetSectionName(i);
if(!Map->IsMapSection(*name))
m_Sections.InsertString(0, *name);
}
m_Sections.SetCurSel(1);
OnSelchangeSections();
}
void CAll::OnSelchangeSections()
{
while(m_Keys.DeleteString(0)!=CB_ERR);
CIniFile& ini=Map->GetIniFile();
CString cuSection;
m_Sections.GetWindowText(cuSection);
if(cuSection.GetLength())
{
int i;
m_Keys.SetRedraw(FALSE);
SetCursor(LoadCursor(0,IDC_WAIT));
for(i=0;i<ini.sections[cuSection].values.size();i++)
{
const CString* name=ini.sections[cuSection].GetValueName(i);
m_Keys.InsertString(-1, *name);
}
SetCursor(m_hArrowCursor);
m_Keys.SetRedraw(TRUE);
m_Keys.RedrawWindow();
}
}
void CAll::OnChangeValue()
{
CIniFile& ini=Map->GetIniFile();
CString t;
m_Value.GetWindowText(t);
CString cuSection;
m_Sections.GetWindowText(cuSection);
CString cuKey;
if(m_Keys.GetCurSel()>=0)m_Keys.GetText(m_Keys.GetCurSel(), cuKey) ;
ini.sections[cuSection].values[cuKey]=t;
}
void CAll::OnSelchangeKeys()
{
CIniFile& ini=Map->GetIniFile();
CString cuSection;
m_Sections.GetWindowText(cuSection);
CString cuKey;
m_Keys.GetText(m_Keys.GetCurSel(), cuKey) ;
m_Value.SetWindowText(ini.sections[cuSection].values[cuKey]);
}
void CAll::OnUpdateValue()
{
}
void CAll::OnAddsection()
{
CString name=InputBox("Please set the name of the new section (the section may already exist)", "Insert Section");
CIniFile& ini=Map->GetIniFile();
CIniFileSection stub=ini.sections[(LPCTSTR)name];
UpdateDialog();
}
void CAll::OnDeletesection()
{
CIniFile& ini=Map->GetIniFile();
int cusection;
cusection=m_Sections.GetCurSel();
if(cusection==-1) {
MessageBox("You cannot delete a section without choosing one.");
return;
}
CString str;
m_Sections.GetLBText(cusection, str);
if(MessageBox(CString((CString)"Are you sure you want to delete " + str + "? You should be really careful, you may not be able to use the map afterwards."), "Delete section", MB_YESNO)==IDNO) return;
ini.sections.erase(str);
UpdateDialog();
}
void CAll::OnDeletekey()
{
CIniFile& ini=Map->GetIniFile();
int cukey;
if(m_Sections.GetCurSel()<0) return;
cukey=m_Keys.GetCurSel();
if(cukey==-1) {
MessageBox("You cannot delete a key without choosing one.");
return;
}
CString str;
CString sec;
int cuSection=m_Sections.GetCurSel();
m_Sections.GetLBText(cuSection, sec);
m_Keys.GetText(cukey, str);
if(MessageBox(CString((CString)"Are you sure you want to delete " + str + "? You should be really careful, you may not be able to use the map afterwards."), "Delete key", MB_YESNO)==IDNO) return;
ini.sections[sec].values.erase(str);
UpdateDialog();
m_Sections.SetCurSel(cuSection);
OnSelchangeSections();
}
void CAll::OnAddkey()
{
CIniFile& ini=Map->GetIniFile();
int cusection;
cusection=m_Sections.GetCurSel();
if(cusection==-1) {
MessageBox("You need to specify a section first.");
return;
}
CString sec;
m_Sections.GetLBText(cusection, sec);
CString key, value;
key=InputBox("Please set the name and value for the current key here: (for example, setting a new key ""Strength"" with the value 200 can be written as ""Strength=200"". You don´t need to specify a value.)", "Create key");
if(key.Find("=")!=-1)
{
// value specified
// MW BUGFIX
value=key.Right(key.GetLength()-key.Find("=")-1);
key=key.Left(key.Find("="));
}
ini.sections[sec].values[key]=value;
UpdateDialog();
m_Sections.SetCurSel(cusection);
OnSelchangeSections();
}
void CAll::OnInisection()
{
CFileDialog dlg(FALSE, ".ini", "*.ini", OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, "INI files|*.ini|");
char cuPath[MAX_PATH];
BOOL hidePreview=FALSE;
BOOL previewPrinted=FALSE;
GetCurrentDirectory(MAX_PATH, cuPath);
dlg.m_ofn.lpstrInitialDir=cuPath;
if(theApp.m_Options.TSExe.GetLength()) dlg.m_ofn.lpstrInitialDir=(char*)(LPCTSTR)theApp.m_Options.TSExe;
if(dlg.DoModal()!=IDCANCEL)
{
CImportINI impini;
impini.m_FileName=dlg.GetPathName();
if(impini.DoModal()!=IDCANCEL)
{
UpdateDialog();
}
}
}

82
MissionEditor/All.h Normal file
View file

@ -0,0 +1,82 @@
/*
FinalSun/FinalAlert 2 Mission Editor
Copyright (C) 1999-2024 Electronic Arts, Inc.
Authored by Matthias Wagner
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#if !defined(AFX_ALL1_H__B5D522E4_69CE_11D3_99E1_C138647F2A00__INCLUDED_)
#define AFX_ALL1_H__B5D522E4_69CE_11D3_99E1_C138647F2A00__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// All1.h : Header-Datei
//
/////////////////////////////////////////////////////////////////////////////
// Dialogfeld CAll
class CAll : public CDialog
{
// Konstruktion
public:
void UpdateDialog();
CAll(CWnd* pParent = NULL); // Standardkonstruktor
// Dialogfelddaten
//{{AFX_DATA(CAll)
enum { IDD = IDD_ALL };
CEdit m_Value;
CListBox m_Keys;
CButton m_IniSection;
CButton m_DeleteSection;
CButton m_DeleteKey;
CButton m_AddSection;
CButton m_AddKey;
CComboBox m_Sections;
//}}AFX_DATA
// Überschreibungen
// Vom Klassen-Assistenten generierte virtuelle Funktionsüberschreibungen
//{{AFX_VIRTUAL(CAll)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV-Unterstützung
//}}AFX_VIRTUAL
// Implementierung
protected:
// Generierte Nachrichtenzuordnungsfunktionen
//{{AFX_MSG(CAll)
afx_msg void OnSelchangeSections();
afx_msg void OnChangeValue();
afx_msg void OnSelchangeKeys();
afx_msg void OnUpdateValue();
afx_msg void OnAddsection();
afx_msg void OnDeletesection();
afx_msg void OnDeletekey();
afx_msg void OnAddkey();
afx_msg void OnInisection();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ fügt unmittelbar vor der vorhergehenden Zeile zusätzliche Deklarationen ein.
#endif // AFX_ALL1_H__B5D522E4_69CE_11D3_99E1_C138647F2A00__INCLUDED_

View file

@ -0,0 +1,100 @@
/*
FinalSun/FinalAlert 2 Mission Editor
Copyright (C) 1999-2024 Electronic Arts, Inc.
Authored by Matthias Wagner
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 3 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, see <https://www.gnu.org/licenses/>.
*/
// BackCliffModifier.cpp: Implementierung der Klasse CBackCliffModifier.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "stdafx.h"
#include "BackCliffModifier.h"
#include <vector>
#include "variables.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Konstruktion/Destruktion
//////////////////////////////////////////////////////////////////////
CBackCliffModifier::CBackCliffModifier()
{
}
CBackCliffModifier::~CBackCliffModifier()
{
}
void CBackCliffModifier::ModifyCurrentPos(DWORD *dwPos, BOOL bBeforePlacing, BOOL bSmall)
{
if(!bBeforePlacing)
{
if(m_direction==cd_verticdiag_top) (*dwPos)+=2+0*Map->GetIsoSize();
if(m_direction==cd_verticdiag_bottom) (*dwPos)+=-2+0*Map->GetIsoSize();
}
}
void CBackCliffModifier::ModifyStartPos(DWORD *dwPos, BOOL bSmall)
{
if(m_direction==cd_verticdiag_top) (*dwPos)+=1+1*Map->GetIsoSize();
if(m_direction==cd_verticdiag_bottom) (*dwPos)+=-1+0*Map->GetIsoSize();
if(m_direction==cd_horiz_right) (*dwPos)+=0+0*Map->GetIsoSize();
if(m_direction==cd_horiz_left)
{
int ground=Map->GetFielddataAt(*dwPos)->wGround;
(*dwPos)+=0+Map->GetIsoSize();
if(ground==0xFFFF) ground=0;
if((*tiledata)[ground].wTileSet==cliffset)
{
(*dwPos)-=Map->GetIsoSize();
//ModifyStartPos(dwPos, bSmall);
}
}
if(m_direction==cd_vertic_top)
{
int ground=Map->GetFielddataAt(*dwPos)->wGround;
(*dwPos)+=1;
if(ground==0xFFFF) ground=0;
if((*tiledata)[ground].wTileSet==cliffset)
{
(*dwPos)-=1;
//ModifyStartPos(dwPos, bSmall);
}
}
}
CString CBackCliffModifier::GetDataSection()
{
if(m_bAlternative) return ("CliffBackDataAlt");
return("CliffBackData");
}

View file

@ -0,0 +1,46 @@
/*
FinalSun/FinalAlert 2 Mission Editor
Copyright (C) 1999-2024 Electronic Arts, Inc.
Authored by Matthias Wagner
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 3 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, see <https://www.gnu.org/licenses/>.
*/
// BackCliffModifier.h: Schnittstelle für die Klasse CBackCliffModifier.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_BACKCLIFFMODIFIER_H__3853D325_CD37_11D4_9C87_F2DC6A2E6849__INCLUDED_)
#define AFX_BACKCLIFFMODIFIER_H__3853D325_CD37_11D4_9C87_F2DC6A2E6849__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "CliffModifier.h"
class CBackCliffModifier : public CCliffModifier
{
public:
CBackCliffModifier();
virtual ~CBackCliffModifier();
protected:
virtual CString GetDataSection();
virtual void ModifyStartPos(DWORD* dwPos, BOOL bSmall);
virtual void ModifyCurrentPos(DWORD* dwPos, BOOL bBeforePlacing, BOOL bSmall);
};
#endif // !defined(AFX_BACKCLIFFMODIFIER_H__3853D325_CD37_11D4_9C87_F2DC6A2E6849__INCLUDED_)

346
MissionEditor/Basic.cpp Normal file
View file

@ -0,0 +1,346 @@
/*
FinalSun/FinalAlert 2 Mission Editor
Copyright (C) 1999-2024 Electronic Arts, Inc.
Authored by Matthias Wagner
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 3 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, see <https://www.gnu.org/licenses/>.
*/
// Basic.cpp: Implementierungsdatei
//
#include "stdafx.h"
#include "FinalSun.h"
#include "Basic.h"
#include "resource.h"
#include "mapdata.h"
#include "variables.h"
#include "functions.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Eigenschaftenseite CBasic
IMPLEMENT_DYNCREATE(CBasic, CPropertyPage)
CBasic::CBasic() : CDialog(CBasic::IDD)
{
//{{AFX_DATA_INIT(CBasic)
//}}AFX_DATA_INIT
}
CBasic::~CBasic()
{
}
void CBasic::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBasic)
DDX_Control(pDX, IDC_REQUIREDADDON, m_RequiredAddOn);
DDX_Control(pDX, IDC_VEINGROWTHENABLED, m_VeinGrowthEnabled);
DDX_Control(pDX, IDC_TRUCKCRATE, m_TruckCrate);
DDX_Control(pDX, IDC_TRAINCRATE, m_TrainCrate);
DDX_Control(pDX, IDC_TIBERIUMGROWTHENABLED, m_TiberiumGrowthEnabled);
DDX_Control(pDX, IDC_TIBERIUMDEATHTOVISCEROID, m_TiberiumDeathToVisceroid);
DDX_Control(pDX, IDC_SKIPSCORE, m_SkipScore);
DDX_Control(pDX, IDC_SKIPMAPSELECT, m_SkipMapSelect);
DDX_Control(pDX, IDC_ONETIMEONLY, m_OneTimeOnly);
DDX_Control(pDX, IDC_OFFICIAL, m_Official);
DDX_Control(pDX, IDC_NEXTSCENARIO, m_NextScenario);
DDX_Control(pDX, IDC_PERCENT, m_Percent);
DDX_Control(pDX, IDC_NEWINIFORMAT, m_NewINIFormat);
DDX_Control(pDX, IDC_NAME, m_Name);
DDX_Control(pDX, IDC_MULTIPLAYERONLY, m_MultiplayerOnly);
DDX_Control(pDX, IDC_INITTIME, m_InitTime);
DDX_Control(pDX, IDC_IGNOREGLOBALAITRIGGERS, m_IgnoreGlobalAITriggers);
DDX_Control(pDX, IDC_ICEGROWTHENABLED, m_IceGrowthEnabled);
DDX_Control(pDX, IDC_FREERADAR, m_FreeRadar);
DDX_Control(pDX, IDC_ENDOFGAME, m_EndOfGame);
DDX_Control(pDX, IDC_CARRYOVERCAP, m_CarryOverCap);
DDX_Control(pDX, IDC_ALTNEXTSCENARIO, m_AltNextScenario);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBasic, CDialog)
//{{AFX_MSG_MAP(CBasic)
ON_EN_CHANGE(IDC_NAME, OnChangeName)
ON_CBN_EDITCHANGE(IDC_NEXTSCENARIO, OnEditchangeNextscenario)
ON_CBN_EDITCHANGE(IDC_ALTNEXTSCENARIO, OnEditchangeAltnextscenario)
ON_EN_CHANGE(IDC_NEWINIFORMAT, OnChangeNewiniformat)
ON_EN_CHANGE(IDC_CARRYOVERCAP, OnChangeCarryovercap)
ON_CBN_EDITCHANGE(IDC_ENDOFGAME, OnEditchangeEndofgame)
ON_CBN_EDITCHANGE(IDC_SKIPSCORE, OnEditchangeSkipscore)
ON_CBN_EDITCHANGE(IDC_ONETIMEONLY, OnEditchangeOnetimeonly)
ON_CBN_EDITCHANGE(IDC_SKIPMAPSELECT, OnEditchangeSkipmapselect)
ON_CBN_EDITCHANGE(IDC_OFFICIAL, OnEditchangeOfficial)
ON_CBN_EDITCHANGE(IDC_IGNOREGLOBALAITRIGGERS, OnEditchangeIgnoreglobalaitriggers)
ON_CBN_EDITCHANGE(IDC_TRUCKCRATE, OnEditchangeTruckcrate)
ON_CBN_EDITCHANGE(IDC_TRAINCRATE, OnEditchangeTraincrate)
ON_EN_CHANGE(IDC_PERCENT, OnChangePercent)
ON_EN_CHANGE(IDC_MULTIPLAYERONLY, OnChangeMultiplayeronly)
ON_CBN_EDITCHANGE(IDC_TIBERIUMGROWTHENABLED, OnEditchangeTiberiumgrowthenabled)
ON_CBN_EDITCHANGE(IDC_VEINGROWTHENABLED, OnEditchangeVeingrowthenabled)
ON_CBN_EDITCHANGE(IDC_ICEGROWTHENABLED, OnEditchangeIcegrowthenabled)
ON_CBN_EDITCHANGE(IDC_TIBERIUMDEATHTOVISCEROID, OnEditchangeTiberiumdeathtovisceroid)
ON_CBN_EDITCHANGE(IDC_FREERADAR, OnEditchangeFreeradar)
ON_EN_CHANGE(IDC_INITTIME, OnChangeInittime)
ON_CBN_EDITCHANGE(IDC_REQUIREDADDON, OnEditchangeRequiredaddon)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Behandlungsroutinen für Nachrichten CBasic
//DEL void CBasic::OnOK()
//DEL {
//DEL // TODO: Zusätzliche Prüfung hier einfügen
//DEL
//DEL CPropertyPage::OnOK();
//DEL }
void CBasic::UpdateDialog()
{
CIniFile& ini=Map->GetIniFile();
m_AltNextScenario.SetWindowText(ini.sections["Basic"].values["AltNextScenario"]);
m_Name.SetWindowText(ini.sections["Basic"].values["Name"]);
m_CarryOverCap.SetWindowText(ini.sections["Basic"].values["CarryOverCap"]);
m_EndOfGame.SetWindowText(ini.sections["Basic"].values["EndOfGame"]);
m_FreeRadar.SetWindowText(ini.sections["Basic"].values["FreeRadar"]);
m_IceGrowthEnabled.SetWindowText(ini.sections["Basic"].values["IceGrowthEnabled"]);
m_IgnoreGlobalAITriggers.SetWindowText(ini.sections["Basic"].values["IgnoreGlobalAITriggers"]);
m_InitTime.SetWindowText(ini.sections["Basic"].values["InitTime"]);
m_MultiplayerOnly.SetWindowText(ini.sections["Basic"].values["MultiplayerOnly"]);
m_NewINIFormat.SetWindowText(ini.sections["Basic"].values["NewINIFormat"]);
m_NextScenario.SetWindowText(ini.sections["Basic"].values["NextScenario"]);
m_Official.SetWindowText(ini.sections["Basic"].values["Official"]);
m_OneTimeOnly.SetWindowText(ini.sections["Basic"].values["OneTimeOnly"]);
m_Percent.SetWindowText(ini.sections["Basic"].values["Percent"]);
m_SkipMapSelect.SetWindowText(ini.sections["Basic"].values["SkipMapSelect"]);
m_SkipScore.SetWindowText(ini.sections["Basic"].values["SkipScore"]);
m_TiberiumDeathToVisceroid.SetWindowText(ini.sections["Basic"].values["TiberiumDeathToVisceroid"]);
m_TiberiumGrowthEnabled.SetWindowText(ini.sections["Basic"].values["TiberiumGrowthEnabled"]);
m_TrainCrate.SetWindowText(ini.sections["Basic"].values["TrainCrate"]);
m_TruckCrate.SetWindowText(ini.sections["Basic"].values["TruckCrate"]);
m_VeinGrowthEnabled.SetWindowText(ini.sections["Basic"].values["VeinGrowthEnabled"]);
if(ini.sections["Basic"].values.find("RequiredAddOn")!=ini.sections["Basic"].values.end())
{
m_RequiredAddOn.SetWindowText(ini.sections["Basic"].values["RequiredAddOn"]);
}
else
m_RequiredAddOn.SetWindowText("0");
}
void CBasic::OnChangeName()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["Name"]=GetText(&m_Name);
}
void CBasic::UpdateData()
{
// MessageBox("This function ( UpdateData() ) should not be called here... please report to the author.");
errstream << "CBasic::UpdateData() called - should not be called" << endl;
errstream.flush();
}
void CBasic::OnEditchangeNextscenario()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["NextScenario"]=GetText(&m_NextScenario);
}
void CBasic::OnEditchangeAltnextscenario()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["AltNextScenario"]=GetText(&m_AltNextScenario);
}
void CBasic::OnChangeNewiniformat()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["NewINIFormat"]=GetText(&m_NewINIFormat);
}
void CBasic::OnChangeCarryovercap()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["CarryOverCap"]=GetText(&m_CarryOverCap);
}
void CBasic::OnEditchangeEndofgame()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["EndOfGame"]=GetText(&m_EndOfGame);
}
void CBasic::OnEditchangeSkipscore()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["SkipScore"]=GetText(&m_SkipScore);
}
void CBasic::OnEditchangeOnetimeonly()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["OneTimeOnly"]=GetText(&m_OneTimeOnly);
}
void CBasic::OnEditchangeSkipmapselect()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["SkipMapSelect"]=GetText(&m_SkipMapSelect);
}
void CBasic::OnEditchangeOfficial()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["Official"]=GetText(&m_Official);
}
void CBasic::OnEditchangeIgnoreglobalaitriggers()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["IgnoreGlobalAITriggers"]=GetText(&m_IgnoreGlobalAITriggers);
}
void CBasic::OnEditchangeTruckcrate()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["TruckCrate"]=GetText(&m_TruckCrate);
}
void CBasic::OnEditchangeTraincrate()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["TrainCrate"]=GetText(&m_TrainCrate);
}
void CBasic::OnChangePercent()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["Percent"]=GetText(&m_Percent);
}
void CBasic::OnChangeMultiplayeronly()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["MultiplayerOnly"]=GetText(&m_MultiplayerOnly);
}
void CBasic::OnEditchangeTiberiumgrowthenabled()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["TiberiumGrowthEnabled"]=GetText(&m_TiberiumGrowthEnabled);
}
void CBasic::OnEditchangeVeingrowthenabled()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["VeinGrowthEnabled"]=GetText(&m_VeinGrowthEnabled);
}
void CBasic::OnEditchangeIcegrowthenabled()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["IceGrowthEnabled"]=GetText(&m_IceGrowthEnabled);
}
void CBasic::OnEditchangeTiberiumdeathtovisceroid()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["TiberiumDeathToVisceroid"]=GetText(&m_TiberiumDeathToVisceroid);
}
void CBasic::OnEditchangeFreeradar()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["FreeRadar"]=GetText(&m_FreeRadar);
}
void CBasic::OnChangeInittime()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["InitTime"]=GetText(&m_InitTime);
}
void CBasic::UpdateStrings()
{
SetDlgItemText(IDC_LDESC, GetLanguageStringACP("BasicDesc"));
SetDlgItemText(IDC_LNAME, GetLanguageStringACP("BasicName"));
SetDlgItemText(IDC_LNEXTSCENARIO, GetLanguageStringACP("BasicNextScenario"));
SetDlgItemText(IDC_LALTNEXTSCENARIO, GetLanguageStringACP("BasicAltNextScenario"));
SetDlgItemText(IDC_LNEWINIFORMAT, GetLanguageStringACP("BasicNewIniFormat"));
SetDlgItemText(IDC_LCARRYOVERCAP, GetLanguageStringACP("BasicCarryOverCap"));
SetDlgItemText(IDC_LENDOFGAME, GetLanguageStringACP("BasicEndOfGame"));
SetDlgItemText(IDC_LSKIPSCORE, GetLanguageStringACP("BasicSkipScore"));
SetDlgItemText(IDC_LONETIMEONLY, GetLanguageStringACP("BasicOneTimeOnly"));
SetDlgItemText(IDC_LSKIPMAPSELECT, GetLanguageStringACP("BasicSkipMapSelect"));
SetDlgItemText(IDC_LOFFICIAL, GetLanguageStringACP("BasicOfficial"));
SetDlgItemText(IDC_LIGNOREGLOBALAITRIGGERS, GetLanguageStringACP("BasicIgnoreGlobalAITriggers"));
SetDlgItemText(IDC_LTRUCKCRATE, GetLanguageStringACP("BasicTruckCrate"));
SetDlgItemText(IDC_LTRAINCRATE, GetLanguageStringACP("BasicTrainCrate"));
SetDlgItemText(IDC_LPERCENT, GetLanguageStringACP("BasicPercent"));
SetDlgItemText(IDC_LMULTIPLAYERONLY, GetLanguageStringACP("BasicMultiplayerOnly"));
SetDlgItemText(IDC_LTIBERIUMGROWTHENABLED, GetLanguageStringACP("BasicTiberiumGrowthEnabled"));
SetDlgItemText(IDC_LVEINGROWTHENABLED, GetLanguageStringACP("BasicVeinGrowthEnabled"));
SetDlgItemText(IDC_LICEGROWTHENABLED, GetLanguageStringACP("BasicIceGrowthEnabled"));
SetDlgItemText(IDC_LTIBERIUMDEATHTOVISCEROID, GetLanguageStringACP("BasicTiberiumDeathToVisceroid"));
SetDlgItemText(IDC_LFREERADAR, GetLanguageStringACP("BasicFreeRadar"));
SetDlgItemText(IDC_LINITIME, GetLanguageStringACP("BasicInitTime"));
SetDlgItemText(IDC_LADDONNEEDED, GetLanguageStringACP("BasicAddOnNeeded"));
#ifdef RA2_MODE
GetDlgItem(IDC_LVEINGROWTHENABLED)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_VEINGROWTHENABLED)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_LTRAINCRATE)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_TRAINCRATE)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_ICEGROWTHENABLED)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_LICEGROWTHENABLED)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_TIBERIUMDEATHTOVISCEROID)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_LTIBERIUMDEATHTOVISCEROID)->ShowWindow(SW_HIDE);
#endif
SetWindowText(TranslateStringACP("Basic"));
}
void CBasic::OnEditchangeRequiredaddon()
{
CIniFile& ini=Map->GetIniFile();
ini.sections["Basic"].values["RequiredAddOn"]=GetText(&m_RequiredAddOn);
if(ini.sections["Basic"].values["RequiredAddOn"]=="0") ini.sections["Basic"].values.erase("RequiredAddOn");
}
void CBasic::PostNcDestroy()
{
// do not call PostNcDestroy as this is a member of FinalSunDlg
//CPropertyPage::PostNcDestroy();
}

115
MissionEditor/Basic.h Normal file
View file

@ -0,0 +1,115 @@
/*
FinalSun/FinalAlert 2 Mission Editor
Copyright (C) 1999-2024 Electronic Arts, Inc.
Authored by Matthias Wagner
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#if !defined(AFX_BASIC_H__C350C7AC_63C3_11D3_99E0_C30F10710B17__INCLUDED_)
#define AFX_BASIC_H__C350C7AC_63C3_11D3_99E0_C30F10710B17__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Basic.h : Header-Datei
//
/////////////////////////////////////////////////////////////////////////////
// Dialogfeld CBasic
class CBasic : public CDialog
{
DECLARE_DYNCREATE(CBasic)
// Konstruktion
public:
void UpdateStrings();
void UpdateData();
void UpdateDialog();
CBasic();
~CBasic();
// Dialogfelddaten
//{{AFX_DATA(CBasic)
enum { IDD = IDD_BASIC };
CMyComboBox m_RequiredAddOn;
CMyComboBox m_VeinGrowthEnabled;
CMyComboBox m_TruckCrate;
CMyComboBox m_TrainCrate;
CMyComboBox m_TiberiumGrowthEnabled;
CMyComboBox m_TiberiumDeathToVisceroid;
CMyComboBox m_SkipScore;
CMyComboBox m_SkipMapSelect;
CMyComboBox m_OneTimeOnly;
CMyComboBox m_Official;
CMyComboBox m_NextScenario;
CEdit m_Percent;
CEdit m_NewINIFormat;
CEdit m_Name;
CEdit m_MultiplayerOnly;
CEdit m_InitTime;
CMyComboBox m_IgnoreGlobalAITriggers;
CMyComboBox m_IceGrowthEnabled;
CMyComboBox m_FreeRadar;
CMyComboBox m_EndOfGame;
CEdit m_CarryOverCap;
CMyComboBox m_AltNextScenario;
//}}AFX_DATA
// Überschreibungen
// Der Klassen-Assistent generiert virtuelle Funktionsüberschreibungen
//{{AFX_VIRTUAL(CBasic)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV-Unterstützung
virtual void PostNcDestroy();
//}}AFX_VIRTUAL
// Implementierung
protected:
// Generierte Nachrichtenzuordnungsfunktionen
//{{AFX_MSG(CBasic)
afx_msg void OnChangeName();
afx_msg void OnEditchangeNextscenario();
afx_msg void OnEditchangeAltnextscenario();
afx_msg void OnChangeNewiniformat();
afx_msg void OnChangeCarryovercap();
afx_msg void OnEditchangeEndofgame();
afx_msg void OnEditchangeSkipscore();
afx_msg void OnEditchangeOnetimeonly();
afx_msg void OnEditchangeSkipmapselect();
afx_msg void OnEditchangeOfficial();
afx_msg void OnEditchangeIgnoreglobalaitriggers();
afx_msg void OnEditchangeTruckcrate();
afx_msg void OnEditchangeTraincrate();
afx_msg void OnChangePercent();
afx_msg void OnChangeMultiplayeronly();
afx_msg void OnEditchangeTiberiumgrowthenabled();
afx_msg void OnEditchangeVeingrowthenabled();
afx_msg void OnEditchangeIcegrowthenabled();
afx_msg void OnEditchangeTiberiumdeathtovisceroid();
afx_msg void OnEditchangeFreeradar();
afx_msg void OnChangeInittime();
afx_msg void OnEditchangeRequiredaddon();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ fügt unmittelbar vor der vorhergehenden Zeile zusätzliche Deklarationen ein.
#endif // AFX_BASIC_H__C350C7AC_63C3_11D3_99E0_C30F10710B17__INCLUDED_

View file

@ -0,0 +1,206 @@
/*
FinalSun/FinalAlert 2 Mission Editor
Copyright (C) 1999-2024 Electronic Arts, Inc.
Authored by Matthias Wagner
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 3 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, see <https://www.gnu.org/licenses/>.
*/
// Bitmap2MapConverter.cpp: Implementierung der Klasse CBitmap2MapConverter.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "stdafx.h"
#include "Bitmap2MapConverter.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Konstruktion/Destruktion
//////////////////////////////////////////////////////////////////////
CBitmap2MapConverter::CBitmap2MapConverter()
{
}
CBitmap2MapConverter::~CBitmap2MapConverter()
{
}
/*
I originally intended this tool to support different theaters,
but currently it does only support temperate. People can use
copy/paste to convert those maps though!
*/
BOOL CBitmap2MapConverter::Convert(HBITMAP hBitmap, CMapData & mapdata)
{
BITMAP bm;
GetObject(hBitmap, sizeof(BITMAP), &bm);
HBITMAP hUsed=hBitmap;
if(bm.bmWidth+bm.bmHeight>255)
{
float scalex=(float)bm.bmWidth/(float)bm.bmHeight;
int neededheight, neededwidth;
neededheight=255.0f/(scalex+1.0f);
neededwidth=255-neededheight;
hUsed=CreateCompatibleBitmap(GetDC(NULL), neededwidth, neededheight);
HDC hDC=CreateCompatibleDC(GetDC(NULL));
SelectObject(hDC, hUsed);
HDC hSrcDC=CreateCompatibleDC(GetDC(NULL));
SelectObject(hSrcDC, hBitmap);
StretchBlt(hDC, 0,0,neededwidth,neededheight, hSrcDC, 0,0,bm.bmWidth, bm.bmHeight, SRCCOPY);
DeleteDC(hDC);
DeleteDC(hSrcDC);
GetObject(hUsed, sizeof(BITMAP), &bm);
}
HDC hDC;
hDC=CreateCompatibleDC(GetDC(NULL));
SelectObject(hDC, hUsed);
srand(GetTickCount());
int i;
int e;
int theater=0;
mapdata.CreateMap(bm.bmWidth, bm.bmHeight, "TEMPERATE", 0);
int isosize=mapdata.GetIsoSize();
for(i=0;i<(*tiledata_count);i++)
if((*tiledata)[i].wTileSet==waterset) break;
int water_start=i+8; // to 12
int sandset=atoi((*tiles).sections["General"].values["SandTile"]);
int greenset=atoi((*tiles).sections["General"].values["GreenTile"]);
#ifdef RA2_MODE
sandset=atoi((*tiles).sections["General"].values["GreenTile"]);
greenset=atoi((*tiles).sections["General"].values["RoughTile"]);
#endif
for(i=0;i<(*tiledata_count);i++)
if((*tiledata)[i].wTileSet==sandset) break;
int sand_start=i;
for(i=0;i<(*tiledata_count);i++)
if((*tiledata)[i].wTileSet==greenset) break;
int green_start=i;
for(i=0;i<bm.bmWidth;i++)
{
for(e=0;e<bm.bmHeight;e++)
{
COLORREF col=GetPixel(hDC, i, bm.bmHeight-e);
int x=(i)+mapdata.GetHeight()+1;
int y=(e)+mapdata.GetWidth();
int xiso;
int yiso;
yiso=mapdata.GetIsoSize()-(y - x);
xiso=mapdata.GetIsoSize()-(x + y);
yiso-=mapdata.GetHeight();
for(x=-1;x<2;x++)
{
for(y=-1;y<2;y++)
{
DWORD dwPos=xiso+x+(yiso+y)*isosize;
if(dwPos>isosize*isosize) continue;
FIELDDATA* fd=mapdata.GetFielddataAt(dwPos);
int r=GetRValue(col);
int g=GetGValue(col);
int b=GetBValue(col);
if(g>r && g>b)
{
if(theater!=1)
{
fd->wGround=0;
fd->bSubTile=0;
}
}
if(b>g && b>r)
{
int p=rand()*4/RAND_MAX;
fd->wGround=water_start+p;
fd->bSubTile=0;
}
if(g>b+25 && r>b+25 && g>120 && r>120)
{
if(theater!=1)
{
fd->wGround=sand_start;
fd->bSubTile=0;
}
}
if(b<20 && r<20 && g>20)
{
#ifdef RA2_MODE
if(g<140) // dark only
#endif
{
fd->wGround=green_start;
fd->bSubTile=0;
}
}
}
}
}
}
mapdata.CreateShore(0,0,isosize, isosize);
for(i=0;i<isosize*isosize;i++)
{
mapdata.SmoothAllAt(i);
}
DeleteDC(hDC);
if(hUsed!=hBitmap) DeleteObject(hUsed);
return TRUE;
}

View file

@ -0,0 +1,43 @@
/*
FinalSun/FinalAlert 2 Mission Editor
Copyright (C) 1999-2024 Electronic Arts, Inc.
Authored by Matthias Wagner
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 3 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, see <https://www.gnu.org/licenses/>.
*/
// Bitmap2MapConverter.h: Schnittstelle für die Klasse CBitmap2MapConverter.
//
//////////////////////////////////////////////////////////////////////
#include "mapdata.h"
#if !defined(AFX_BITMAP2MAPCONVERTER_H__42E61B61_E18A_11D4_9C88_816E6DEF4C47__INCLUDED_)
#define AFX_BITMAP2MAPCONVERTER_H__42E61B61_E18A_11D4_9C88_816E6DEF4C47__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CBitmap2MapConverter
{
public:
BOOL Convert(HBITMAP hBitmap, CMapData& mapdata);
CBitmap2MapConverter();
virtual ~CBitmap2MapConverter();
};
#endif // !defined(AFX_BITMAP2MAPCONVERTER_H__42E61B61_E18A_11D4_9C88_816E6DEF4C47__INCLUDED_)

317
MissionEditor/Building.cpp Normal file
View file

@ -0,0 +1,317 @@
/*
FinalSun/FinalAlert 2 Mission Editor
Copyright (C) 1999-2024 Electronic Arts, Inc.
Authored by Matthias Wagner
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 3 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, see <https://www.gnu.org/licenses/>.
*/
// Building.cpp: Implementierungsdatei
//
#include "stdafx.h"
#include "FinalSun.h"
#include "Building.h"
#include "mapdata.h"
#include "variables.h"
#include "inlines.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Dialogfeld CBuilding
CBuilding::CBuilding(CWnd* pParent /*=NULL*/)
: CDialog(CBuilding::IDD, pParent)
{
//{{AFX_DATA_INIT(CBuilding)
m_direction = _T("");
m_house = _T("");
m_flag1 = _T("");
m_flag2 = _T("");
m_energy = _T("");
m_upgradecount = _T("");
m_spotlight = _T("");
m_upgrade1 = _T("");
m_upgrade2 = _T("");
m_upgrade3 = _T("");
m_flag3 = _T("");
m_flag4 = _T("");
m_tag = _T("");
//}}AFX_DATA_INIT
Init();
}
void CBuilding::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBuilding)
DDX_Control(pDX, IDC_STRENGTH, m_strength_ctrl);
DDX_CBString(pDX, IDC_DIRECTION, m_direction);
DDX_CBString(pDX, IDC_HOUSE, m_house);
DDX_Text(pDX, IDC_P1, m_flag1);
DDX_Text(pDX, IDC_P2, m_flag2);
DDX_Text(pDX, IDC_P3, m_energy);
DDX_Text(pDX, IDC_P4, m_upgradecount);
DDX_Text(pDX, IDC_P5, m_spotlight);
DDX_CBString(pDX, IDC_P6, m_upgrade1);
DDX_CBString(pDX, IDC_P7, m_upgrade2);
DDX_CBString(pDX, IDC_P8, m_upgrade3);
DDX_Text(pDX, IDC_P9, m_flag3);
DDX_Text(pDX, IDC_P10, m_flag4);
DDX_CBString(pDX, IDC_TAG, m_tag);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBuilding, CDialog)
//{{AFX_MSG_MAP(CBuilding)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Behandlungsroutinen für Nachrichten CBuilding
CString GetName(CString id)
{
CIniFile& ini=Map->GetIniFile();
if(ini.sections.find(id)!=ini.sections.end())
{
if(ini.sections[id].values.find("Name")!=ini.sections[id].values.end())
return ini.sections[id].values["Name"];
}
return rules.sections[id].values["Name"];
}
void CBuilding::OnOK()
{
CDialog::OnOK();
m_strength=GetText(&m_strength_ctrl);
UpdateData();
char d[50];
TruncSpace(m_spotlight);
itoa(atoi(m_spotlight), d, 10);
m_spotlight=d;
m_house=TranslateHouse(m_house);
TruncSpace(m_upgrade1);
TruncSpace(m_upgrade2);
TruncSpace(m_upgrade3);
TruncSpace(m_tag);
TruncSpace(m_flag1);
TruncSpace(m_flag2);
TruncSpace(m_flag3);
TruncSpace(m_flag4);
//
}
BOOL CBuilding::OnInitDialog()
{
CDialog::OnInitDialog();
CIniFile& ini=Map->GetIniFile();
int i;
CComboBox* chouse, *ctag;
chouse=(CComboBox*)GetDlgItem(IDC_HOUSE);
ctag=(CComboBox*)GetDlgItem(IDC_TAG);
ListHouses(*chouse, FALSE);
ListTags(*ctag, TRUE);
m_strength_ctrl.SetRange(0,256);
m_strength_ctrl.SetPos(atoi(m_strength));
UpdateData(FALSE);
int upgradecount=0;
if(strcmp(m_type,"GACTWR")==NULL)
upgradecount=1;
if(ini.sections.find(m_type)!=ini.sections.end())
{
if(ini.sections[m_type].values.find("Upgrades")!=ini.sections[m_type].values.end())
{
// ok we have our upgrade
upgradecount=atoi(ini.sections[m_type].values["Upgrades"]);
}
else
{
if(rules.sections[m_type].values.find("Upgrades")!=rules.sections[m_type].values.end())
upgradecount=atoi(rules.sections[m_type].values["Upgrades"]);
}
}
else
{
if(rules.sections[m_type].values.find("Upgrades")!=rules.sections[m_type].values.end())
upgradecount=atoi(rules.sections[m_type].values["Upgrades"]);
}
GetDlgItem(IDC_P5)->SendMessage(CB_SETCURSEL, atoi(m_spotlight), 0);
if(upgradecount>0)
{
for(i=0;i<rules.sections["BuildingTypes"].values.size();i++)
{
const char* unitname=*rules.sections["BuildingTypes"].GetValue(i);
// okay, first all the old units
if(ini.sections.find(unitname)!=ini.sections.end())
{
// new thing specified
if(ini.sections[unitname].values.find("PowersUpBuilding")!=ini.sections[unitname].values.end())
{
// ini file specified new PowersUpBuilding
if(_stricmp(ini.sections[unitname].values["PowersUpBuilding"], m_type)==NULL)
{
((CComboBox*)GetDlgItem(IDC_P6))->AddString(((CString)unitname+" ("+GetName(unitname)+")"));
((CComboBox*)GetDlgItem(IDC_P7))->AddString(((CString)unitname+" ("+GetName(unitname)+")"));
((CComboBox*)GetDlgItem(IDC_P8))->AddString(((CString)unitname+" ("+GetName(unitname)+")"));
}
}
}
else
{
// ini did not specify thing specified
if(rules.sections[unitname].values.find("PowersUpBuilding")!=rules.sections[unitname].values.end())
{
// rules file specified new PowersUpBuilding
if(_stricmp(rules.sections[unitname].values["PowersUpBuilding"], m_type)==NULL)
{
((CComboBox*)GetDlgItem(IDC_P6))->AddString(((CString)unitname+" ("+GetName(unitname)+")"));
((CComboBox*)GetDlgItem(IDC_P7))->AddString(((CString)unitname+" ("+GetName(unitname)+")"));
((CComboBox*)GetDlgItem(IDC_P8))->AddString(((CString)unitname+" ("+GetName(unitname)+")"));
}
}
}
}
if(ini.sections.find("BuildingTypes")!=ini.sections.end())
{
for(i=0;i<ini.sections["BuildingTypes"].values.size();i++)
{
const char* unitname=*ini.sections["BuildingTypes"].GetValue(i);
// okay, first all the old units
if(ini.sections.find(unitname)!=ini.sections.end())
{
// new thing specified
if(ini.sections[unitname].values.find("PowersUpBuilding")!=ini.sections[unitname].values.end())
{
// ini file specified new PowersUpBuilding
if(_stricmp(ini.sections[unitname].values["PowersUpBuilding"], m_type)==NULL)
{
((CComboBox*)GetDlgItem(IDC_P6))->AddString(((CString)unitname+" ("+GetName(unitname)+")"));
((CComboBox*)GetDlgItem(IDC_P7))->AddString(((CString)unitname+" ("+GetName(unitname)+")"));
((CComboBox*)GetDlgItem(IDC_P8))->AddString(((CString)unitname+" ("+GetName(unitname)+")"));
}
}
}
}
}
}
GetDlgItem(IDC_P8)->EnableWindow(TRUE);
GetDlgItem(IDC_P7)->EnableWindow(TRUE);
GetDlgItem(IDC_P6)->EnableWindow(TRUE);
GetDlgItem(IDC_P4)->EnableWindow(TRUE);
if(upgradecount<3)
GetDlgItem(IDC_P8)->EnableWindow(FALSE);
if(upgradecount<2)
GetDlgItem(IDC_P7)->EnableWindow(FALSE);
if(upgradecount<1)
{
GetDlgItem(IDC_P6)->EnableWindow(FALSE);
GetDlgItem(IDC_P4)->EnableWindow(FALSE);
}
UpdateStrings();
return TRUE;
}
void CBuilding::Init(CString house, CString strength, CString direction, CString tag, CString flag1, CString flag2, CString energy, CString upgradecount, CString spotlight, CString upgrade1, CString upgrade2, CString upgrade3, CString flag3, CString flag4)
{
CIniFile& ini=Map->GetIniFile();
if(house=="")
{
house=TranslateHouse(Map->GetHouseID(0), TRUE);
}
else
m_house=TranslateHouse(house, TRUE);
m_house=TranslateHouse(house, TRUE);
m_flag1=flag1;
m_flag2=flag2;
m_flag3=flag3;
m_flag4=flag4;
m_spotlight=spotlight;
m_energy=energy;
m_upgrade1=upgrade1;
m_upgrade2=upgrade2;
m_upgrade3=upgrade3;
m_upgradecount=upgradecount;
m_strength=strength;
m_tag=tag;
m_direction=direction;
}
void CBuilding::UpdateStrings()
{
SetWindowText(GetLanguageStringACP("StructCap"));
GetDlgItem(IDC_LHOUSE)->SetWindowText(GetLanguageStringACP("StructHouse"));
GetDlgItem(IDC_LDESC)->SetWindowText(GetLanguageStringACP("StructDesc"));
GetDlgItem(IDC_LSTRENGTH)->SetWindowText(GetLanguageStringACP("StructStrength"));
GetDlgItem(IDC_LDIRECTION)->SetWindowText(GetLanguageStringACP("StructDirection"));
GetDlgItem(IDC_LTAG)->SetWindowText(GetLanguageStringACP("StructTag"));
GetDlgItem(IDC_LAIREPAIRS)->SetWindowText(GetLanguageStringACP("StructAIRepairs"));
GetDlgItem(IDC_LENERGY)->SetWindowText(GetLanguageStringACP("StructEnergy"));
GetDlgItem(IDC_LUPGRADECOUNT)->SetWindowText(GetLanguageStringACP("StructUpgradeCount"));
GetDlgItem(IDC_LSPOTLIGHT)->SetWindowText(GetLanguageStringACP("StructSpotlight"));
GetDlgItem(IDC_LUPGRADE1)->SetWindowText(GetLanguageStringACP("StructUpgrade1"));
GetDlgItem(IDC_LUPGRADE2)->SetWindowText(GetLanguageStringACP("StructUpgrade2"));
GetDlgItem(IDC_LUPGRADE3)->SetWindowText(GetLanguageStringACP("StructUpgrade3"));
GetDlgItem(IDC_LP1)->SetWindowText(GetLanguageStringACP("StructP1"));
GetDlgItem(IDC_LP2)->SetWindowText(GetLanguageStringACP("StructP2"));
GetDlgItem(IDC_LP3)->SetWindowText(GetLanguageStringACP("StructP3"));
SetDlgItemText(IDOK, GetLanguageStringACP("OK"));
SetDlgItemText(IDCANCEL, GetLanguageStringACP("Cancel"));
}

Some files were not shown because too many files have changed in this diff Show more