diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 5bb384d26b..657b410505 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,2 +1 @@ -open_collective: pojavlauncher patreon: pojavlauncher diff --git a/LICENSE b/LICENSE index 68a0e357f6..0a041280bd 100644 --- a/LICENSE +++ b/LICENSE @@ -1,674 +1,165 @@ - GNU GENERAL PUBLIC LICENSE + GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. 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. - - PojavLauncher - A Minecraft: Java Edition Launcher for Android and iOS - Copyright (C) 2021 Tran Hoang Khanh Duy and contributors - - 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 . - -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: - - PojavLauncher Copyright (C) 2021 Tran Hoang Khanh Duy - 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 -. - - 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 -. + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser 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 +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/README.md b/README.md index f9692faf60..7b151b66cb 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,10 @@ SolCraftLauncher is a fork of PojavLauncher with more technical added features, * It can run almost every version of Minecraft, allowing you to use .jar only installers to install modloaders such as [Forge](https://files.minecraftforge.net/) and [Fabric](http://fabricmc.net/), mods like [OptiFine](https://optifine.net) and [LabyMod](https://www.labymod.net/en), as well as hack clients like [Wurst](https://www.wurstclient.net/), and much more! -* For more details [check out our wiki](https://github.com/PojavLauncherTeam/PojavLauncher/wiki) +* For more details [check out our wiki](https://pojavlauncherteam.github.io/) ## Some notes to start with - We do not have an official TikTok account. No one from the dev team makes TikTok videos. -- The official Twitter for PojavLauncher is [@PLaunchTeam](https://twitter.com/PLaunchTeam). Any others (most notably @PojavLauncher) are fake, please report them to Twitter's moderation team. +- The official Twitter for PojavLauncher is [@PLaunchTeam](https://twitter.com/PLaunchTeam). Any others (most notably @PojavLauncher) are fake. ## Navigation - [Introduction](#introduction) diff --git a/app_pojavlauncher/build.gradle b/app_pojavlauncher/build.gradle index d7104fca8d..2d5583dcfe 100644 --- a/app_pojavlauncher/build.gradle +++ b/app_pojavlauncher/build.gradle @@ -90,7 +90,7 @@ configurations { android { namespace 'net.kdt.pojavlaunch' - compileSdk = 33 + compileSdk = 34 lintOptions { abortOnError false @@ -114,7 +114,7 @@ android { defaultConfig { applicationId "net.kdt.pojavlaunch" minSdkVersion 21 - targetSdkVersion 33 + targetSdkVersion 34 versionCode getDateSeconds() versionName getVersionName() multiDexEnabled true //important @@ -203,7 +203,7 @@ dependencies { implementation 'com.github.PojavLauncherTeam:portrait-sdp:ed33e89cbc' implementation 'com.github.PojavLauncherTeam:portrait-ssp:6c02fd739b' implementation 'com.github.Mathias-Boulay:ExtendedView:1.0.0' - implementation 'com.github.Mathias-Boulay:android_gamepad_remapper:06184ddbce' + implementation 'com.github.Mathias-Boulay:android_gamepad_remapper:2.0.3' implementation 'com.github.Mathias-Boulay:virtual-joystick-android:2e7aa25e50' // implementation 'com.intuit.sdp:sdp-android:1.0.5' diff --git a/app_pojavlauncher/src/main/AndroidManifest.xml b/app_pojavlauncher/src/main/AndroidManifest.xml index 4147e1f3a7..98628756a7 100644 --- a/app_pojavlauncher/src/main/AndroidManifest.xml +++ b/app_pojavlauncher/src/main/AndroidManifest.xml @@ -18,6 +18,8 @@ + + - - + + + + diff --git a/app_pojavlauncher/src/main/assets/components/lwjgl3/lwjgl-glfw-classes.jar b/app_pojavlauncher/src/main/assets/components/lwjgl3/lwjgl-glfw-classes.jar index dad1d35638..d7a05d5e41 100644 Binary files a/app_pojavlauncher/src/main/assets/components/lwjgl3/lwjgl-glfw-classes.jar and b/app_pojavlauncher/src/main/assets/components/lwjgl3/lwjgl-glfw-classes.jar differ diff --git a/app_pojavlauncher/src/main/assets/components/lwjgl3/version b/app_pojavlauncher/src/main/assets/components/lwjgl3/version index bf09493f2c..c3b857f256 100644 --- a/app_pojavlauncher/src/main/assets/components/lwjgl3/version +++ b/app_pojavlauncher/src/main/assets/components/lwjgl3/version @@ -1 +1 @@ -1731000005291 \ No newline at end of file +1720909595576 \ No newline at end of file diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Architecture.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Architecture.java index 6189b2872b..8716525d47 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Architecture.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Architecture.java @@ -12,6 +12,22 @@ public class Architecture { public static final int ARCH_X86 = 0x4; public static final int ARCH_X86_64 = 0x8; + /* On both 32-bit ARM and x86, the top 1GB is reserved for kernel use. */ + public static final long ADDRESS_SPACE_LIMIT_32_BIT = 0xbfffffffL; + /* + * Technically, this is supposed to be 48 bits on x86_64, but nobody's allocating + * 524288 terabytes of RAM on Pojav any time soon. + */ + public static final long ADDRESS_SPACE_LIMIT_64_BIT = 0x7fffffffffL; + + /** + * Get the highest byte accessible within the process's address space. + * @return the highest byte accessible within the process's address space. + */ + public static long getAddressSpaceLimit() { + return is64BitsDevice() ? ADDRESS_SPACE_LIMIT_64_BIT : ADDRESS_SPACE_LIMIT_32_BIT; + } + /** * Tell us if the device supports 64 bits architecture * @return If the device supports 64 bits architecture diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/EfficientAndroidLWJGLKeycode.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/EfficientAndroidLWJGLKeycode.java index c2ff62248f..5fce0dcbc4 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/EfficientAndroidLWJGLKeycode.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/EfficientAndroidLWJGLKeycode.java @@ -198,7 +198,7 @@ public static void execKeyIndex(int index){ sendKeyPress(getValueByIndex(index)); } - public static int getValueByIndex(int index) { + public static short getValueByIndex(int index) { return sLwjglKeycodes[index]; } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/ExitActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/ExitActivity.java index f488f66c49..ae39f1d1a7 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/ExitActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/ExitActivity.java @@ -4,7 +4,6 @@ import android.annotation.SuppressLint; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; @@ -21,21 +20,26 @@ public class ExitActivity extends AppCompatActivity { public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); int code = -1; + boolean isSignal = false; Bundle extras = getIntent().getExtras(); if(extras != null) { code = extras.getInt("code",-1); + isSignal = extras.getBoolean("isSignal", false); } + int message = isSignal ? R.string.mcn_signal_title : R.string.mcn_exit_title; + new AlertDialog.Builder(this) - .setMessage(getString(R.string.mcn_exit_title,code)) + .setMessage(getString(message,code)) .setPositiveButton(R.string.main_share_logs, (dialog, which) -> shareLog(this)) .setOnDismissListener(dialog -> ExitActivity.this.finish()) .show(); } - public static void showExitMessage(Context ctx, int code) { + public static void showExitMessage(Context ctx, int code, boolean isSignal) { Intent i = new Intent(ctx,ExitActivity.class); i.putExtra("code",code); + i.putExtra("isSignal", isSignal); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ctx.startActivity(i); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java index 6d559e30c7..9e7d99c97d 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java @@ -15,6 +15,7 @@ import android.widget.Toast; import androidx.activity.OnBackPressedCallback; +import androidx.appcompat.app.AlertDialog; import com.kdt.LoggerView; @@ -185,6 +186,7 @@ private void startModInstallerWithUri(Uri uri) { try { File cacheFile = new File(getCacheDir(), "mod-installer-temp"); InputStream contentStream = getContentResolver().openInputStream(uri); + if(contentStream == null) throw new IOException("Failed to open content stream"); try (FileOutputStream fileOutputStream = new FileOutputStream(cacheFile)) { IOUtils.copy(contentStream, fileOutputStream); } @@ -195,23 +197,71 @@ private void startModInstallerWithUri(Uri uri) { } } + public Runtime selectRuntime(File modFile) { + int javaVersion = getJavaVersion(modFile); + if(javaVersion == -1) { + finalErrorDialog(getString(R.string.execute_jar_failed_to_read_file)); + return null; + } + String nearestRuntime = MultiRTUtils.getNearestJreName(javaVersion); + if(nearestRuntime == null) { + finalErrorDialog(getString(R.string.multirt_nocompatiblert, javaVersion)); + return null; + } + Runtime selectedRuntime = MultiRTUtils.forceReread(nearestRuntime); + int selectedJavaVersion = Math.max(javaVersion, selectedRuntime.javaVersion); + // Don't allow versions higher than Java 17 because our caciocavallo implementation does not allow for it + if(selectedJavaVersion > 17) { + finalErrorDialog(getString(R.string.execute_jar_incompatible_runtime, selectedJavaVersion)); + return null; + } + return selectedRuntime; + } + + private File findModPath(List argList) { + int argsSize = argList.size(); + for(int i = 0; i < argsSize; i++) { + // Look for the -jar argument + if(!argList.get(i).equals("-jar")) continue; + int pathIndex = i+1; + // Check if the supposed path is out of the argument bounds + if(pathIndex >= argsSize) return null; + // Use the path as a file + return new File(argList.get(pathIndex)); + } + return null; + } + private void startModInstaller(File modFile, String javaArgs) { new Thread(() -> { - Runtime runtime = pickJreForMod(modFile); - launchJavaRuntime(runtime, modFile, javaArgs); + // Maybe replace with more advanced arg parsing logic later + List argList = javaArgs != null ? Arrays.asList(javaArgs.split(" ")) : null; + File selectedMod = modFile; + if(selectedMod == null && argList != null) { + // If modFile is not specified directly, try to extract the -jar argument from the javaArgs + selectedMod = findModPath(argList); + } + Runtime selectedRuntime; + if(selectedMod == null) { + // We were unable to find out the path to the mod. In that case, use the default runtime. + selectedRuntime = MultiRTUtils.forceReread(LauncherPreferences.PREF_DEFAULT_RUNTIME); + }else { + // Autoselect it properly in the other case. + selectedRuntime = selectRuntime(selectedMod); + // If the selection failed, just return. The autoselect function has already shown the dialog. + if(selectedRuntime == null) return; + } + launchJavaRuntime(selectedRuntime, modFile, argList); }, "JREMainThread").start(); } - private Runtime pickJreForMod(File modFile) { - String jreName = LauncherPreferences.PREF_DEFAULT_RUNTIME; - if(modFile != null) { - int javaVersion = getJavaVersion(modFile); - if(javaVersion != -1) { - String autoselectRuntime = MultiRTUtils.getNearestJreName(javaVersion); - if (autoselectRuntime != null) jreName = autoselectRuntime; - } - } - return MultiRTUtils.forceReread(jreName); + private void finalErrorDialog(CharSequence msg) { + runOnUiThread(()-> new AlertDialog.Builder(this) + .setTitle(R.string.global_error) + .setMessage(msg) + .setPositiveButton(android.R.string.ok, (d,w)->this.finish()) + .setCancelable(false) + .show()); } @Override @@ -301,21 +351,20 @@ public void toggleVirtualMouse(View v) { Toast.LENGTH_SHORT).show(); } - public void launchJavaRuntime(Runtime runtime, File modFile, String javaArgs) { + public void launchJavaRuntime(Runtime runtime, File modFile, List javaArgs) { JREUtils.redirectAndPrintJRELog(); try { List javaArgList = new ArrayList<>(); // Enable Caciocavallo Tools.getCacioJavaArgs(javaArgList,runtime.javaVersion == 8); - - if (javaArgs != null) { - javaArgList.addAll(Arrays.asList(javaArgs.split(" "))); - } else { + if(javaArgs != null) { + javaArgList.addAll(javaArgs); + } + if(modFile != null) { javaArgList.add("-jar"); javaArgList.add(modFile.getAbsolutePath()); } - if (LauncherPreferences.PREF_JAVA_SANDBOX) { Collections.reverse(javaArgList); @@ -374,7 +423,7 @@ public int getJavaVersion(File modFile) { Log.i("JavaGUILauncher", majorVersion+","+minorVersion); return classVersionToJavaVersion(majorVersion); }catch (Exception e) { - e.printStackTrace(); + Log.e("JavaVersion", "Exception thrown", e); return -1; } } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java index 4909197dbe..98aa1cc07e 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java @@ -346,7 +346,7 @@ private void runCraft(String versionId, JMinecraftVersionList.Version version) t Tools.releaseRenderersCache(); } MinecraftAccount minecraftAccount = PojavProfile.getCurrentProfileContent(this, null); - Logger.appendToLog("--------- beginning with launcher debug"); + Logger.appendToLog("--------- Starting game with Launcher Debug!"); printLauncherInfo(versionId, Tools.isValidString(minecraftProfile.javaArgs) ? minecraftProfile.javaArgs : LauncherPreferences.PREF_CUSTOM_JAVA_ARGS); JREUtils.redirectAndPrintJRELog(); LauncherProfiles.load(); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLSurface.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLSurface.java index 7ea6225126..2c460558f9 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLSurface.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLSurface.java @@ -27,6 +27,7 @@ import androidx.annotation.RequiresApi; import net.kdt.pojavlaunch.customcontrols.ControlLayout; +import net.kdt.pojavlaunch.customcontrols.gamepad.DefaultDataProvider; import net.kdt.pojavlaunch.customcontrols.gamepad.Gamepad; import net.kdt.pojavlaunch.customcontrols.mouse.AbstractTouchpad; import net.kdt.pojavlaunch.customcontrols.mouse.AndroidPointerCapture; @@ -62,7 +63,8 @@ public class MinecraftGLSurface extends View implements GrabListener { .remapLeftShoulder(true) .remapRightShoulder(true) .remapLeftTrigger(true) - .remapRightTrigger(true)); + .remapRightTrigger(true) + .remapDpad(true)); /* Resolution scaler option, allow downsizing a window */ private final float mScaleFactor = LauncherPreferences.PREF_SCALE_FACTOR/100f; @@ -202,6 +204,10 @@ public boolean onTouchEvent(MotionEvent e) { return mCurrentTouchProcessor.processTouchEvent(e); } + private void createGamepad(View contextView, InputDevice inputDevice) { + mGamepad = new Gamepad(contextView, inputDevice, DefaultDataProvider.INSTANCE, true); + } + /** * The event for mouse/joystick movements */ @@ -211,9 +217,7 @@ public boolean dispatchGenericMotionEvent(MotionEvent event) { int mouseCursorIndex = -1; if(Gamepad.isGamepadEvent(event)){ - if(mGamepad == null){ - mGamepad = new Gamepad(this, event.getDevice()); - } + if(mGamepad == null) createGamepad(this, event.getDevice()); mInputManager.handleMotionEventInput(getContext(), event, mGamepad); return true; @@ -285,9 +289,7 @@ public boolean processKeyEvent(KeyEvent event) { } if(Gamepad.isGamepadEvent(event)){ - if(mGamepad == null){ - mGamepad = new Gamepad(this, event.getDevice()); - } + if(mGamepad == null) createGamepad(this, event.getDevice()); mInputManager.handleKeyEventInput(getContext(), event, mGamepad); return true; diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java index 3bce2e602c..1ab1e1c8c3 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java @@ -50,6 +50,8 @@ import net.kdt.pojavlaunch.lifecycle.ContextExecutor; import net.kdt.pojavlaunch.lifecycle.ContextExecutorTask; import net.kdt.pojavlaunch.lifecycle.LifecycleAwareAlertDialog; +import net.kdt.pojavlaunch.memory.MemoryHoleFinder; +import net.kdt.pojavlaunch.memory.SelfMapsParser; import net.kdt.pojavlaunch.multirt.MultiRTUtils; import net.kdt.pojavlaunch.multirt.Runtime; import net.kdt.pojavlaunch.plugins.FFmpegPlugin; @@ -170,9 +172,20 @@ public static void initContextConstants(Context ctx){ public static void launchMinecraft(final AppCompatActivity activity, MinecraftAccount minecraftAccount, MinecraftProfile minecraftProfile, String versionId, int versionJavaRequirement) throws Throwable { int freeDeviceMemory = getFreeDeviceMemory(activity); + int localeString; + int freeAddressSpace = Architecture.is32BitsDevice() ? getMaxContinuousAddressSpaceSize() : -1; + Log.i("MemStat", "Free RAM: " + freeDeviceMemory + " Addressable: " + freeAddressSpace); + if(freeDeviceMemory > freeAddressSpace && freeAddressSpace != -1) { + freeDeviceMemory = freeAddressSpace; + localeString = R.string.address_memory_warning_msg; + } else { + localeString = R.string.memory_warning_msg; + } + if(LauncherPreferences.PREF_RAM_ALLOCATION > freeDeviceMemory) { + int finalDeviceMemory = freeDeviceMemory; LifecycleAwareAlertDialog.DialogCreator dialogCreator = (dialog, builder) -> - builder.setMessage(activity.getString(R.string.memory_warning_msg, freeDeviceMemory, LauncherPreferences.PREF_RAM_ALLOCATION)) + builder.setMessage(activity.getString(localeString, finalDeviceMemory, LauncherPreferences.PREF_RAM_ALLOCATION)) .setPositiveButton(android.R.string.ok, (d, w)->{}); if(LifecycleAwareAlertDialog.haltOnDialog(activity.getLifecycle(), activity, dialogCreator)) { @@ -923,6 +936,23 @@ public static int getFreeDeviceMemory(Context ctx){ return (int) (memInfo.availMem / 1048576L); } + private static int internalGetMaxContinuousAddressSpaceSize() throws Exception{ + MemoryHoleFinder memoryHoleFinder = new MemoryHoleFinder(); + new SelfMapsParser(memoryHoleFinder).run(); + long largestHole = memoryHoleFinder.getLargestHole(); + if(largestHole == -1) return -1; + else return (int)(largestHole / 1048576L); + } + + public static int getMaxContinuousAddressSpaceSize() { + try { + return internalGetMaxContinuousAddressSpaceSize(); + }catch (Exception e){ + Log.w("Tools", "Failed to find the largest uninterrupted address space"); + return -1; + } + } + public static int getDisplayFriendlyRes(int displaySideRes, float scaling){ displaySideRes *= scaling; if(displaySideRes % 2 != 0) displaySideRes --; diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/DefaultDataProvider.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/DefaultDataProvider.java new file mode 100644 index 0000000000..f16c97115e --- /dev/null +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/DefaultDataProvider.java @@ -0,0 +1,33 @@ +package net.kdt.pojavlaunch.customcontrols.gamepad; + +import net.kdt.pojavlaunch.GrabListener; + +import org.lwjgl.glfw.CallbackBridge; + +public class DefaultDataProvider implements GamepadDataProvider { + public static final DefaultDataProvider INSTANCE = new DefaultDataProvider(); + + // Cannot instantiate this class publicly + private DefaultDataProvider() {} + + @Override + public GamepadMap getGameMap() { + return GamepadMapStore.getGameMap(); + } + + + @Override + public GamepadMap getMenuMap() { + return GamepadMapStore.getMenuMap(); + } + + @Override + public boolean isGrabbing() { + return CallbackBridge.isGrabbing(); + } + + @Override + public void attachGrabListener(GrabListener grabListener) { + CallbackBridge.addGrabListener(grabListener); + } +} diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/Gamepad.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/Gamepad.java index dad6a443fd..4d3a7b135a 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/Gamepad.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/Gamepad.java @@ -19,7 +19,6 @@ import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageView; -import android.widget.Toast; import androidx.core.content.res.ResourcesCompat; import androidx.core.math.MathUtils; @@ -27,7 +26,6 @@ import net.kdt.pojavlaunch.GrabListener; import net.kdt.pojavlaunch.LwjglGlfwKeycode; import net.kdt.pojavlaunch.R; -import net.kdt.pojavlaunch.Tools; import net.kdt.pojavlaunch.prefs.LauncherPreferences; import net.kdt.pojavlaunch.utils.MCOptionUtils; @@ -75,12 +73,11 @@ public class Gamepad implements GrabListener, GamepadHandler { private double mMouseAngle; private double mMouseSensitivity = 19; - private final GamepadMap mGameMap = GamepadMap.getDefaultGameMap(); - private final GamepadMap mMenuMap = GamepadMap.getDefaultMenuMap(); - private GamepadMap mCurrentMap = mGameMap; + private GamepadMap mGameMap; + private GamepadMap mMenuMap; + private GamepadMap mCurrentMap; - // The negation is to force trigger the onGrabState - private boolean isGrabbing = !CallbackBridge.isGrabbing(); + private boolean isGrabbing; /* Choreographer with time to compute delta on ticking */ @@ -91,7 +88,9 @@ public class Gamepad implements GrabListener, GamepadHandler { @SuppressWarnings("FieldCanBeLocal") //the field is used in a WeakReference private final MCOptionUtils.MCOptionListener mGuiScaleListener = () -> notifyGUISizeChange(getMcScale()); - public Gamepad(View contextView, InputDevice inputDevice){ + private final GamepadDataProvider mMapProvider; + + public Gamepad(View contextView, InputDevice inputDevice, GamepadDataProvider mapProvider, boolean showCursor){ Settings.setDeadzoneScale(PREF_DEADZONE_SCALE); mScreenChoreographer = Choreographer.getInstance(); @@ -120,16 +119,34 @@ public void doFrame(long frameTimeNanos) { int size = (int) ((22 * getMcScale()) / mScaleFactor); mPointerImageView.setLayoutParams(new FrameLayout.LayoutParams(size, size)); + mMapProvider = mapProvider; + CallbackBridge.sendCursorPos(CallbackBridge.windowWidth/2f, CallbackBridge.windowHeight/2f); - ((ViewGroup)contextView.getParent()).addView(mPointerImageView); + + if(showCursor) { + ((ViewGroup)contextView.getParent()).addView(mPointerImageView); + } + placePointerView(CallbackBridge.physicalWidth/2, CallbackBridge.physicalHeight/2); - CallbackBridge.addGrabListener(this); + reloadGamepadMaps(); + mMapProvider.attachGrabListener(this); } - + public void reloadGamepadMaps() { + if(mGameMap != null) mGameMap.resetPressedState(); + if(mMenuMap != null) mMenuMap.resetPressedState(); + GamepadMapStore.load(); + mGameMap = mMapProvider.getGameMap(); + mMenuMap = mMapProvider.getMenuMap(); + mCurrentMap = mGameMap; + // Force state refresh + boolean currentGrab = CallbackBridge.isGrabbing(); + isGrabbing = !currentGrab; + onGrabState(currentGrab); + } public void updateJoysticks(){ updateDirectionalJoystick(); @@ -144,8 +161,8 @@ public void notifyGUISizeChange(int newSize){ } - public static void sendInput(int[] keycodes, boolean isDown){ - for(int keycode : keycodes){ + public static void sendInput(short[] keycodes, boolean isDown){ + for(short keycode : keycodes){ switch (keycode){ case GamepadMap.MOUSE_SCROLL_DOWN: if(isDown) CallbackBridge.sendScroll(0, -1); @@ -153,20 +170,23 @@ public static void sendInput(int[] keycodes, boolean isDown){ case GamepadMap.MOUSE_SCROLL_UP: if(isDown) CallbackBridge.sendScroll(0, 1); break; - - case LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_RIGHT: + case GamepadMap.MOUSE_LEFT: + sendMouseButton(LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_LEFT, isDown); + break; + case GamepadMap.MOUSE_MIDDLE: + sendMouseButton(LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_MIDDLE, isDown); + break; + case GamepadMap.MOUSE_RIGHT: sendMouseButton(LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_RIGHT, isDown); break; - case LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_LEFT: - sendMouseButton(LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_LEFT, isDown); + case GamepadMap.UNSPECIFIED: break; - default: sendKeyPress(keycode, CallbackBridge.getCurrentMods(), isDown); + CallbackBridge.setModifiers(keycode, isDown); break; } - CallbackBridge.setModifiers(keycode, isDown); } } @@ -261,32 +281,32 @@ private GamepadMap getCurrentMap(){ private static void sendDirectionalKeycode(int direction, boolean isDown, GamepadMap map){ switch (direction){ case DIRECTION_NORTH: - sendInput(map.DIRECTION_FORWARD, isDown); + map.DIRECTION_FORWARD.update(isDown); break; case DIRECTION_NORTH_EAST: - sendInput(map.DIRECTION_FORWARD, isDown); - sendInput(map.DIRECTION_RIGHT, isDown); + map.DIRECTION_FORWARD.update(isDown); + map.DIRECTION_RIGHT.update(isDown); break; case DIRECTION_EAST: - sendInput(map.DIRECTION_RIGHT, isDown); + map.DIRECTION_RIGHT.update(isDown); break; case DIRECTION_SOUTH_EAST: - sendInput(map.DIRECTION_RIGHT, isDown); - sendInput(map.DIRECTION_BACKWARD, isDown); + map.DIRECTION_RIGHT.update(isDown); + map.DIRECTION_BACKWARD.update(isDown); break; case DIRECTION_SOUTH: - sendInput(map.DIRECTION_BACKWARD, isDown); + map.DIRECTION_BACKWARD.update(isDown); break; case DIRECTION_SOUTH_WEST: - sendInput(map.DIRECTION_BACKWARD, isDown); - sendInput(map.DIRECTION_LEFT, isDown); + map.DIRECTION_BACKWARD.update(isDown); + map.DIRECTION_LEFT.update(isDown); break; case DIRECTION_WEST: - sendInput(map.DIRECTION_LEFT, isDown); + map.DIRECTION_LEFT.update(isDown); break; case DIRECTION_NORTH_WEST: - sendInput(map.DIRECTION_FORWARD, isDown); - sendInput(map.DIRECTION_LEFT, isDown); + map.DIRECTION_FORWARD.update(isDown); + map.DIRECTION_LEFT.update(isDown); break; } } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadButton.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadButton.java index a6c7cc1e79..b80324527c 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadButton.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadButton.java @@ -1,46 +1,31 @@ package net.kdt.pojavlaunch.customcontrols.gamepad; -import android.view.KeyEvent; - /** - * Simple button able to store its state and some properties + * This class corresponds to a button that does exist on the gamepad */ -public class GamepadButton { - - public int[] keycodes; +public class GamepadButton extends GamepadEmulatedButton { public boolean isToggleable = false; - private boolean mIsDown = false; private boolean mIsToggled = false; - public void update(KeyEvent event){ - boolean isKeyDown = (event.getAction() == KeyEvent.ACTION_DOWN); - update(isKeyDown); - } - public void update(boolean isKeyDown){ - if(isKeyDown != mIsDown){ - mIsDown = isKeyDown; - if(isToggleable){ - if(isKeyDown){ - mIsToggled = !mIsToggled; - Gamepad.sendInput(keycodes, mIsToggled); - } - return; - } - Gamepad.sendInput(keycodes, mIsDown); + @Override + protected void onDownStateChanged(boolean isDown) { + if(isToggleable) { + if(!isDown) return; + mIsToggled = !mIsToggled; + Gamepad.sendInput(keycodes, mIsToggled); + return; } + super.onDownStateChanged(isDown); } - public void resetButtonState(){ - if(mIsDown || mIsToggled){ + @Override + public void resetButtonState() { + if(!mIsDown && mIsToggled) { Gamepad.sendInput(keycodes, false); + mIsToggled = false; + } else { + super.resetButtonState(); } - mIsDown = false; - mIsToggled = false; } - - public boolean isDown(){ - return isToggleable ? mIsToggled : mIsDown; - } - } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadDataProvider.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadDataProvider.java new file mode 100644 index 0000000000..37dcbaab5d --- /dev/null +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadDataProvider.java @@ -0,0 +1,10 @@ +package net.kdt.pojavlaunch.customcontrols.gamepad; + +import net.kdt.pojavlaunch.GrabListener; + +public interface GamepadDataProvider { + GamepadMap getMenuMap(); + GamepadMap getGameMap(); + boolean isGrabbing(); + void attachGrabListener(GrabListener grabListener); +} diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadEmulatedButton.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadEmulatedButton.java new file mode 100644 index 0000000000..a05095b80a --- /dev/null +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadEmulatedButton.java @@ -0,0 +1,33 @@ +package net.kdt.pojavlaunch.customcontrols.gamepad; + +import android.view.KeyEvent; + +/** + * This class corresponds to a button that does not physically exist on the gamepad, but is + * emulated from other inputs on it (like WASD directional keys) + */ +public class GamepadEmulatedButton { + public short[] keycodes; + protected boolean mIsDown = false; + + public void update(KeyEvent event) { + boolean isKeyDown = (event.getAction() == KeyEvent.ACTION_DOWN); + update(isKeyDown); + } + + public void update(boolean isKeyDown){ + if(isKeyDown != mIsDown){ + mIsDown = isKeyDown; + onDownStateChanged(mIsDown); + } + } + + public void resetButtonState() { + if(mIsDown) Gamepad.sendInput(keycodes, false); + mIsDown = false; + } + + protected void onDownStateChanged(boolean isDown) { + Gamepad.sendInput(keycodes, mIsDown); + } +} diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadMap.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadMap.java index 4d7fbb1c15..c18c5dc38e 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadMap.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadMap.java @@ -4,8 +4,16 @@ public class GamepadMap { - public static final int MOUSE_SCROLL_DOWN = -1; - public static final int MOUSE_SCROLL_UP = -2; + + public static final short MOUSE_SCROLL_DOWN = -1; + public static final short MOUSE_SCROLL_UP = -2; + // Made mouse keycodes their own specials because managing special keycodes above 0 + // proved to be complicated + public static final short MOUSE_LEFT = -3; + public static final short MOUSE_MIDDLE = -4; + public static final short MOUSE_RIGHT = -5; + // Workaround, because GLFW_KEY_UNKNOWN and GLFW_MOUSE_BUTTON_LEFT are both 0 + public static final short UNSPECIFIED = -6; /* This class is just here to store the mapping @@ -14,33 +22,11 @@ public class GamepadMap { Be warned, you should define ALL keys if you want to avoid a non defined exception */ - public final GamepadButton BUTTON_A = new GamepadButton(); - public final GamepadButton BUTTON_B = new GamepadButton(); - public final GamepadButton BUTTON_X = new GamepadButton(); - public final GamepadButton BUTTON_Y = new GamepadButton(); - - public final GamepadButton BUTTON_START = new GamepadButton(); - public final GamepadButton BUTTON_SELECT = new GamepadButton(); - - public final GamepadButton TRIGGER_RIGHT = new GamepadButton(); //R2 - public final GamepadButton TRIGGER_LEFT = new GamepadButton(); //L2 - - public final GamepadButton SHOULDER_RIGHT = new GamepadButton(); //R1 - public final GamepadButton SHOULDER_LEFT = new GamepadButton(); //L1 - - public int[] DIRECTION_FORWARD; - public int[] DIRECTION_BACKWARD; - public int[] DIRECTION_RIGHT; - public int[] DIRECTION_LEFT; - - public final GamepadButton THUMBSTICK_RIGHT = new GamepadButton(); //R3 - public final GamepadButton THUMBSTICK_LEFT = new GamepadButton(); //L3 - - public final GamepadButton DPAD_UP = new GamepadButton(); - public final GamepadButton DPAD_RIGHT = new GamepadButton(); - public final GamepadButton DPAD_DOWN = new GamepadButton(); - public final GamepadButton DPAD_LEFT = new GamepadButton(); + public GamepadButton BUTTON_A, BUTTON_B, BUTTON_X, BUTTON_Y, BUTTON_START, BUTTON_SELECT, + TRIGGER_RIGHT, TRIGGER_LEFT, SHOULDER_RIGHT, SHOULDER_LEFT, THUMBSTICK_RIGHT, + THUMBSTICK_LEFT, DPAD_UP, DPAD_DOWN, DPAD_RIGHT, DPAD_LEFT; + public GamepadEmulatedButton DIRECTION_FORWARD, DIRECTION_BACKWARD, DIRECTION_RIGHT, DIRECTION_LEFT; /* * Sets all buttons to a not pressed state, sending an input if needed @@ -70,39 +56,70 @@ public void resetPressedState(){ } + private static GamepadMap createAndInitializeButtons() { + GamepadMap gamepadMap = new GamepadMap(); + gamepadMap.BUTTON_A = new GamepadButton(); + gamepadMap.BUTTON_B = new GamepadButton(); + gamepadMap.BUTTON_X = new GamepadButton(); + gamepadMap.BUTTON_Y = new GamepadButton(); + + gamepadMap.BUTTON_START = new GamepadButton(); + gamepadMap.BUTTON_SELECT = new GamepadButton(); + + gamepadMap.TRIGGER_RIGHT = new GamepadButton(); + gamepadMap.TRIGGER_LEFT = new GamepadButton(); + + gamepadMap.SHOULDER_RIGHT = new GamepadButton(); + gamepadMap.SHOULDER_LEFT = new GamepadButton(); + + gamepadMap.DIRECTION_FORWARD = new GamepadEmulatedButton(); + gamepadMap.DIRECTION_BACKWARD = new GamepadEmulatedButton(); + gamepadMap.DIRECTION_RIGHT = new GamepadEmulatedButton(); + gamepadMap.DIRECTION_LEFT = new GamepadEmulatedButton(); + + gamepadMap.THUMBSTICK_RIGHT = new GamepadButton(); + gamepadMap.THUMBSTICK_LEFT = new GamepadButton(); + + gamepadMap.DPAD_UP = new GamepadButton(); + gamepadMap.DPAD_RIGHT = new GamepadButton(); + gamepadMap.DPAD_DOWN = new GamepadButton(); + gamepadMap.DPAD_LEFT = new GamepadButton(); + return gamepadMap; + } + /* * Returns a pre-done mapping used when the mouse is grabbed by the game. */ public static GamepadMap getDefaultGameMap(){ - GamepadMap gameMap = new GamepadMap(); + GamepadMap gameMap = GamepadMap.createEmptyMap(); - gameMap.BUTTON_A.keycodes = new int[]{LwjglGlfwKeycode.GLFW_KEY_SPACE}; - gameMap.BUTTON_B.keycodes = new int[]{LwjglGlfwKeycode.GLFW_KEY_Q}; - gameMap.BUTTON_X.keycodes = new int[]{LwjglGlfwKeycode.GLFW_KEY_E}; - gameMap.BUTTON_Y.keycodes = new int[]{LwjglGlfwKeycode.GLFW_KEY_F}; + gameMap.BUTTON_A.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_SPACE; + gameMap.BUTTON_B.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_Q; + gameMap.BUTTON_X.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_E; + gameMap.BUTTON_Y.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_F; - gameMap.DIRECTION_FORWARD = new int[]{LwjglGlfwKeycode.GLFW_KEY_W}; - gameMap.DIRECTION_BACKWARD = new int[]{LwjglGlfwKeycode.GLFW_KEY_S}; - gameMap.DIRECTION_RIGHT = new int[]{LwjglGlfwKeycode.GLFW_KEY_D}; - gameMap.DIRECTION_LEFT = new int[]{LwjglGlfwKeycode.GLFW_KEY_A}; + gameMap.DIRECTION_FORWARD.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_W; + gameMap.DIRECTION_BACKWARD.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_S; + gameMap.DIRECTION_RIGHT.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_D; + gameMap.DIRECTION_LEFT.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_A; - gameMap.DPAD_UP.keycodes = new int[]{LwjglGlfwKeycode.GLFW_KEY_LEFT_SHIFT}; - gameMap.DPAD_DOWN.keycodes = new int[]{LwjglGlfwKeycode.GLFW_KEY_O}; //For mods ? - gameMap.DPAD_RIGHT.keycodes = new int[]{LwjglGlfwKeycode.GLFW_KEY_K}; //For mods ? - gameMap.DPAD_LEFT.keycodes = new int[]{LwjglGlfwKeycode.GLFW_KEY_J}; //For mods ? + gameMap.DPAD_UP.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_LEFT_SHIFT; + gameMap.DPAD_DOWN.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_O; //For mods ? + gameMap.DPAD_RIGHT.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_K; //For mods ? + gameMap.DPAD_LEFT.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_J; //For mods ? - gameMap.SHOULDER_LEFT.keycodes = new int[]{GamepadMap.MOUSE_SCROLL_UP}; - gameMap.SHOULDER_RIGHT.keycodes = new int[]{GamepadMap.MOUSE_SCROLL_DOWN}; + gameMap.SHOULDER_LEFT.keycodes[0] = GamepadMap.MOUSE_SCROLL_UP; + gameMap.SHOULDER_RIGHT.keycodes[0] = GamepadMap.MOUSE_SCROLL_DOWN; - gameMap.TRIGGER_LEFT.keycodes = new int[]{LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_RIGHT}; - gameMap.TRIGGER_RIGHT.keycodes = new int[]{LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_LEFT}; + gameMap.TRIGGER_LEFT.keycodes[0] = GamepadMap.MOUSE_RIGHT; + gameMap.TRIGGER_RIGHT.keycodes[0] = GamepadMap.MOUSE_LEFT; - gameMap.THUMBSTICK_LEFT.keycodes = new int[]{LwjglGlfwKeycode.GLFW_KEY_LEFT_CONTROL}; - gameMap.THUMBSTICK_RIGHT.keycodes = new int[]{LwjglGlfwKeycode.GLFW_KEY_LEFT_SHIFT}; + gameMap.THUMBSTICK_LEFT.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_LEFT_CONTROL; + gameMap.THUMBSTICK_RIGHT.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_LEFT_SHIFT; gameMap.THUMBSTICK_RIGHT.isToggleable = true; - gameMap.BUTTON_START.keycodes = new int[]{LwjglGlfwKeycode.GLFW_KEY_ESCAPE}; - gameMap.BUTTON_SELECT.keycodes = new int[]{LwjglGlfwKeycode.GLFW_KEY_TAB}; + gameMap.BUTTON_START.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_ESCAPE; + gameMap.BUTTON_SELECT.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_TAB; return gameMap; } @@ -111,64 +128,63 @@ public static GamepadMap getDefaultGameMap(){ * Returns a pre-done mapping used when the mouse is NOT grabbed by the game. */ public static GamepadMap getDefaultMenuMap(){ - GamepadMap menuMap = new GamepadMap(); - - menuMap.BUTTON_A.keycodes = new int[]{LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_LEFT}; - menuMap.BUTTON_B.keycodes = new int[]{LwjglGlfwKeycode.GLFW_KEY_ESCAPE}; - menuMap.BUTTON_X.keycodes = new int[]{LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_RIGHT}; - menuMap.BUTTON_Y.keycodes = new int[]{LwjglGlfwKeycode.GLFW_KEY_LEFT_SHIFT, LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_RIGHT}; //Oops, doesn't work since left shift isn't properly applied. - - menuMap.DIRECTION_FORWARD = new int[]{GamepadMap.MOUSE_SCROLL_UP, GamepadMap.MOUSE_SCROLL_UP, GamepadMap.MOUSE_SCROLL_UP, GamepadMap.MOUSE_SCROLL_UP, GamepadMap.MOUSE_SCROLL_UP}; - menuMap.DIRECTION_BACKWARD = new int[]{GamepadMap.MOUSE_SCROLL_DOWN, GamepadMap.MOUSE_SCROLL_DOWN, GamepadMap.MOUSE_SCROLL_DOWN, GamepadMap.MOUSE_SCROLL_DOWN, GamepadMap.MOUSE_SCROLL_DOWN}; - menuMap.DIRECTION_RIGHT = new int[]{}; - menuMap.DIRECTION_LEFT = new int[]{}; - - menuMap.DPAD_UP.keycodes = new int[]{}; - menuMap.DPAD_DOWN.keycodes = new int[]{LwjglGlfwKeycode.GLFW_KEY_O}; //For mods ? - menuMap.DPAD_RIGHT.keycodes = new int[]{LwjglGlfwKeycode.GLFW_KEY_K}; //For mods ? - menuMap.DPAD_LEFT.keycodes = new int[]{LwjglGlfwKeycode.GLFW_KEY_J}; //For mods ? - - menuMap.SHOULDER_LEFT.keycodes = new int[]{GamepadMap.MOUSE_SCROLL_UP}; - menuMap.SHOULDER_RIGHT.keycodes = new int[]{GamepadMap.MOUSE_SCROLL_DOWN}; - - menuMap.TRIGGER_LEFT.keycodes = new int[]{}; - menuMap.TRIGGER_RIGHT.keycodes = new int[]{}; - - menuMap.THUMBSTICK_LEFT.keycodes = new int[]{}; - menuMap.THUMBSTICK_RIGHT.keycodes = new int[]{}; - - menuMap.BUTTON_START.keycodes = new int[]{LwjglGlfwKeycode.GLFW_KEY_ESCAPE}; - menuMap.BUTTON_SELECT.keycodes = new int[]{}; + GamepadMap menuMap = GamepadMap.createEmptyMap(); + + menuMap.BUTTON_A.keycodes[0] = GamepadMap.MOUSE_LEFT; + menuMap.BUTTON_B.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_ESCAPE; + menuMap.BUTTON_X.keycodes[0] = GamepadMap.MOUSE_RIGHT; + { + short[] keycodes = menuMap.BUTTON_Y.keycodes; + keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_LEFT_SHIFT; + keycodes[1] = GamepadMap.MOUSE_RIGHT; + } + + { + short[] keycodes = menuMap.DIRECTION_FORWARD.keycodes; + keycodes[0] = keycodes[1] = keycodes[2] = keycodes[3] = GamepadMap.MOUSE_SCROLL_UP; + } + { + short[] keycodes = menuMap.DIRECTION_BACKWARD.keycodes; + keycodes[0] = keycodes[1] = keycodes[2] = keycodes[3] = GamepadMap.MOUSE_SCROLL_DOWN; + } + + menuMap.DPAD_DOWN.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_O; //For mods ? + menuMap.DPAD_RIGHT.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_K; //For mods ? + menuMap.DPAD_LEFT.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_J; //For mods ? + + menuMap.SHOULDER_LEFT.keycodes[0] = GamepadMap.MOUSE_SCROLL_UP; + menuMap.SHOULDER_RIGHT.keycodes[0] = GamepadMap.MOUSE_SCROLL_DOWN; + + menuMap.BUTTON_SELECT.keycodes[0] = LwjglGlfwKeycode.GLFW_KEY_ESCAPE; return menuMap; } /* - * Returns all GamepadButtons, does not include directional keys + * Returns all GamepadEmulatedButtons of the controller key map. */ - public GamepadButton[] getButtons(){ - return new GamepadButton[]{ BUTTON_A, BUTTON_B, BUTTON_X, BUTTON_Y, + public GamepadEmulatedButton[] getButtons(){ + return new GamepadEmulatedButton[]{ BUTTON_A, BUTTON_B, BUTTON_X, BUTTON_Y, BUTTON_SELECT, BUTTON_START, TRIGGER_LEFT, TRIGGER_RIGHT, SHOULDER_LEFT, SHOULDER_RIGHT, THUMBSTICK_LEFT, THUMBSTICK_RIGHT, - DPAD_UP, DPAD_RIGHT, DPAD_DOWN, DPAD_LEFT}; + DPAD_UP, DPAD_RIGHT, DPAD_DOWN, DPAD_LEFT, + DIRECTION_FORWARD, DIRECTION_BACKWARD, + DIRECTION_LEFT, DIRECTION_RIGHT}; } /* * Returns an pre-initialized GamepadMap with only empty keycodes */ - @SuppressWarnings("unused") public static GamepadMap getEmptyMap(){ - GamepadMap emptyMap = new GamepadMap(); - for(GamepadButton button : emptyMap.getButtons()) - button.keycodes = new int[]{}; - - emptyMap.DIRECTION_LEFT = new int[]{}; - emptyMap.DIRECTION_FORWARD = new int[]{}; - emptyMap.DIRECTION_RIGHT = new int[]{}; - emptyMap.DIRECTION_BACKWARD = new int[]{}; - + @SuppressWarnings("unused") public static GamepadMap createEmptyMap(){ + GamepadMap emptyMap = createAndInitializeButtons(); + for(GamepadEmulatedButton button : emptyMap.getButtons()) + button.keycodes = new short[] {UNSPECIFIED, UNSPECIFIED, UNSPECIFIED, UNSPECIFIED}; return emptyMap; } + public static String[] getSpecialKeycodeNames() { + return new String[] {"UNSPECIFIED", "MOUSE_RIGHT", "MOUSE_MIDDLE", "MOUSE_LEFT", "SCROLL_UP", "SCROLL_DOWN"}; + } } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadMapStore.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadMapStore.java new file mode 100644 index 0000000000..85af2404cc --- /dev/null +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadMapStore.java @@ -0,0 +1,60 @@ +package net.kdt.pojavlaunch.customcontrols.gamepad; + +import android.util.Log; + +import com.google.gson.JsonParseException; + +import net.kdt.pojavlaunch.Tools; +import net.kdt.pojavlaunch.utils.FileUtils; + +import java.io.File; +import java.io.IOException; + +public class GamepadMapStore { + private static final File STORE_FILE = new File(Tools.DIR_DATA, "gamepad_map.json"); + private static GamepadMapStore sMapStore; + private GamepadMap mInMenuMap; + private GamepadMap mInGameMap; + private static GamepadMapStore createDefault() { + GamepadMapStore mapStore = new GamepadMapStore(); + mapStore.mInGameMap = GamepadMap.getDefaultGameMap(); + mapStore.mInMenuMap = GamepadMap.getDefaultMenuMap(); + return mapStore; + } + + private static void loadIfNecessary() { + if(sMapStore == null) return; + load(); + } + + public static void load() { + GamepadMapStore mapStore = null; + if(STORE_FILE.exists() && STORE_FILE.canRead()) { + try { + String storeFileContent = Tools.read(STORE_FILE); + mapStore = Tools.GLOBAL_GSON.fromJson(storeFileContent, GamepadMapStore.class); + } catch (JsonParseException | IOException e) { + Log.w("GamepadMapStore", "Map store failed to load!", e); + } + } + if(mapStore == null) mapStore = createDefault(); + sMapStore = mapStore; + } + + public static void save() throws IOException { + if(sMapStore == null) throw new RuntimeException("Must load map store first!"); + FileUtils.ensureParentDirectory(STORE_FILE); + String jsonData = Tools.GLOBAL_GSON.toJson(sMapStore); + Tools.write(STORE_FILE.getAbsolutePath(), jsonData); + } + + public static GamepadMap getGameMap() { + loadIfNecessary(); + return sMapStore.mInGameMap; + } + + public static GamepadMap getMenuMap() { + loadIfNecessary(); + return sMapStore.mInMenuMap; + } +} diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadMapperAdapter.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadMapperAdapter.java new file mode 100644 index 0000000000..487440ffc4 --- /dev/null +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadMapperAdapter.java @@ -0,0 +1,337 @@ +package net.kdt.pojavlaunch.customcontrols.gamepad; + +import android.content.Context; +import android.graphics.Color; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.CompoundButton; +import android.widget.ImageView; +import android.widget.Spinner; + +import androidx.annotation.NonNull; +import androidx.appcompat.widget.SwitchCompat; +import androidx.recyclerview.widget.RecyclerView; + +import net.kdt.pojavlaunch.EfficientAndroidLWJGLKeycode; +import net.kdt.pojavlaunch.GrabListener; +import net.kdt.pojavlaunch.R; +import net.kdt.pojavlaunch.Tools; + +import android.widget.TextView; + +public class GamepadMapperAdapter extends RecyclerView.Adapter implements GamepadDataProvider { + private static final int BUTTON_COUNT = 20; + + private GamepadMap mSimulatedGamepadMap; + private RebinderButton[] mRebinderButtons; + private GamepadEmulatedButton[] mRealButtons; + private final ArrayAdapter mKeyAdapter; + private final int mSpecialKeycodeCount; + private GrabListener mGamepadGrabListener; + private boolean mGrabState = false; + private boolean mOldState = false; + + public GamepadMapperAdapter(Context context) { + GamepadMapStore.load(); + mKeyAdapter = new ArrayAdapter<>(context, R.layout.item_centered_textview_large); + String[] specialKeycodeNames = GamepadMap.getSpecialKeycodeNames(); + mSpecialKeycodeCount = specialKeycodeNames.length; + mKeyAdapter.addAll(specialKeycodeNames); + mKeyAdapter.addAll(EfficientAndroidLWJGLKeycode.generateKeyName()); + createRebinderMap(); + updateRealButtons(); + } + + private void createRebinderMap() { + mRebinderButtons = new RebinderButton[BUTTON_COUNT]; + mRealButtons = new GamepadEmulatedButton[BUTTON_COUNT]; + mSimulatedGamepadMap = new GamepadMap(); + int index = 0; + mSimulatedGamepadMap.BUTTON_A = mRebinderButtons[index++] = new RebinderButton(R.drawable.button_a, R.string.controller_button_a); + mSimulatedGamepadMap.BUTTON_B = mRebinderButtons[index++] = new RebinderButton(R.drawable.button_b, R.string.controller_button_b); + mSimulatedGamepadMap.BUTTON_X = mRebinderButtons[index++] = new RebinderButton(R.drawable.button_x, R.string.controller_button_x); + mSimulatedGamepadMap.BUTTON_Y = mRebinderButtons[index++] = new RebinderButton(R.drawable.button_y, R.string.controller_button_y); + mSimulatedGamepadMap.BUTTON_START = mRebinderButtons[index++] = new RebinderButton(R.drawable.button_start, R.string.controller_button_start); + mSimulatedGamepadMap.BUTTON_SELECT = mRebinderButtons[index++] = new RebinderButton(R.drawable.button_select, R.string.controller_button_select); + mSimulatedGamepadMap.TRIGGER_RIGHT = mRebinderButtons[index++] = new RebinderButton(R.drawable.trigger_right, R.string.controller_button_trigger_right); + mSimulatedGamepadMap.TRIGGER_LEFT = mRebinderButtons[index++] = new RebinderButton(R.drawable.trigger_left, R.string.controller_button_trigger_left); + mSimulatedGamepadMap.SHOULDER_RIGHT = mRebinderButtons[index++] = new RebinderButton(R.drawable.shoulder_right, R.string.controller_button_shoulder_right); + mSimulatedGamepadMap.SHOULDER_LEFT = mRebinderButtons[index++] = new RebinderButton(R.drawable.shoulder_left, R.string.controller_button_shoulder_left); + mSimulatedGamepadMap.DIRECTION_FORWARD = mRebinderButtons[index++] = new RebinderButton(R.drawable.stick_right, R.string.controller_direction_forward); + mSimulatedGamepadMap.DIRECTION_RIGHT = mRebinderButtons[index++] = new RebinderButton(R.drawable.stick_right, R.string.controller_direction_right); + mSimulatedGamepadMap.DIRECTION_LEFT = mRebinderButtons[index++] = new RebinderButton(R.drawable.stick_right, R.string.controller_direction_left); + mSimulatedGamepadMap.DIRECTION_BACKWARD = mRebinderButtons[index++] = new RebinderButton(R.drawable.stick_right, R.string.controller_direction_backward); + mSimulatedGamepadMap.THUMBSTICK_RIGHT = mRebinderButtons[index++] = new RebinderButton(R.drawable.stick_right_click, R.string.controller_stick_press_r); + mSimulatedGamepadMap.THUMBSTICK_LEFT = mRebinderButtons[index++] = new RebinderButton(R.drawable.stick_left_click, R.string.controller_stick_press_l); + mSimulatedGamepadMap.DPAD_UP = mRebinderButtons[index++] = new RebinderButton(R.drawable.dpad_up, R.string.controller_dpad_up); + mSimulatedGamepadMap.DPAD_DOWN = mRebinderButtons[index++] = new RebinderButton(R.drawable.dpad_down, R.string.controller_dpad_down); + mSimulatedGamepadMap.DPAD_RIGHT = mRebinderButtons[index++] = new RebinderButton(R.drawable.dpad_right, R.string.controller_dpad_right); + mSimulatedGamepadMap.DPAD_LEFT = mRebinderButtons[index] = new RebinderButton(R.drawable.dpad_left, R.string.controller_dpad_left); + } + + private void updateRealButtons() { + GamepadMap currentRealMap = mGrabState ? GamepadMapStore.getGameMap() : GamepadMapStore.getMenuMap(); + int index = 0; + mRealButtons[index++] = currentRealMap.BUTTON_A; + mRealButtons[index++] = currentRealMap.BUTTON_B; + mRealButtons[index++] = currentRealMap.BUTTON_X; + mRealButtons[index++] = currentRealMap.BUTTON_Y; + mRealButtons[index++] = currentRealMap.BUTTON_START; + mRealButtons[index++] = currentRealMap.BUTTON_SELECT; + mRealButtons[index++] = currentRealMap.TRIGGER_RIGHT; + mRealButtons[index++] = currentRealMap.TRIGGER_LEFT; + mRealButtons[index++] = currentRealMap.SHOULDER_RIGHT; + mRealButtons[index++] = currentRealMap.SHOULDER_LEFT; + mRealButtons[index++] = currentRealMap.DIRECTION_FORWARD; + mRealButtons[index++] = currentRealMap.DIRECTION_RIGHT; + mRealButtons[index++] = currentRealMap.DIRECTION_LEFT; + mRealButtons[index++] = currentRealMap.DIRECTION_BACKWARD; + mRealButtons[index++] = currentRealMap.THUMBSTICK_RIGHT; + mRealButtons[index++] = currentRealMap.THUMBSTICK_LEFT; + mRealButtons[index++] = currentRealMap.DPAD_UP; + mRealButtons[index++] = currentRealMap.DPAD_DOWN; + mRealButtons[index++] = currentRealMap.DPAD_RIGHT; + mRealButtons[index] = currentRealMap.DPAD_LEFT; + } + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext()); + View view = layoutInflater.inflate(R.layout.item_controller_mapping, parent, false); + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder holder, int position) { + holder.attach(position); + } + + @Override + public void onViewRecycled(@NonNull ViewHolder holder) { + super.onViewRecycled(holder); + holder.detach(); + } + + @Override + public int getItemCount() { + return mRebinderButtons.length; + } + + private void updateStickIcons() { + // Which stick is used for keyboard emulation depends on grab state, so we need + // to update the mapper UI icons accordingly + int stickIcon = mGrabState ? R.drawable.stick_left : R.drawable.stick_right; + ((RebinderButton)mSimulatedGamepadMap.DIRECTION_FORWARD).iconResourceId = stickIcon; + ((RebinderButton)mSimulatedGamepadMap.DIRECTION_BACKWARD).iconResourceId = stickIcon; + ((RebinderButton)mSimulatedGamepadMap.DIRECTION_RIGHT).iconResourceId = stickIcon; + ((RebinderButton)mSimulatedGamepadMap.DIRECTION_LEFT).iconResourceId = stickIcon; + } + + private static class RebinderButton extends GamepadButton { + public int iconResourceId; + public final int localeResourceId; + private GamepadMapperAdapter.ViewHolder mButtonHolder; + + public RebinderButton(int iconResourceId, int localeResourceId) { + this.iconResourceId = iconResourceId; + this.localeResourceId = localeResourceId; + } + + public void changeViewHolder(GamepadMapperAdapter.ViewHolder viewHolder) { + mButtonHolder = viewHolder; + if(mButtonHolder != null) mButtonHolder.setPressed(mIsDown); + } + + @Override + protected void onDownStateChanged(boolean isDown) { + if(mButtonHolder == null) return; + mButtonHolder.setPressed(isDown); + } + } + + public class ViewHolder extends RecyclerView.ViewHolder implements AdapterView.OnItemSelectedListener, View.OnClickListener, CompoundButton.OnCheckedChangeListener { + private static final int COLOR_ACTIVE_BUTTON = 0x2000FF00; + private final Context mContext; + private final ImageView mButtonIcon; + private final ImageView mExpansionIndicator; + private final Spinner[] mKeySpinners; + private final View mExpandedView; + private final SwitchCompat mToggleableSwitch; + private final TextView mKeycodeLabel; + private int mAttachedPosition = -1; + private GamepadEmulatedButton mAttachedButton; + private short[] mKeycodes; + + public ViewHolder(@NonNull View itemView) { + super(itemView); + mContext = itemView.getContext(); + mButtonIcon = itemView.findViewById(R.id.controller_mapper_button); + mExpandedView = itemView.findViewById(R.id.controller_mapper_expanded_view); + mExpansionIndicator = itemView.findViewById(R.id.controller_mapper_expand_button); + mKeycodeLabel = itemView.findViewById(R.id.controller_mapper_keycode_label); + mToggleableSwitch = itemView.findViewById(R.id.controller_mapper_toggleable_switch); + mToggleableSwitch.setOnCheckedChangeListener(this); + View defaultView = itemView.findViewById(R.id.controller_mapper_default_view); + defaultView.setOnClickListener(this); + mKeySpinners = new Spinner[4]; + mKeySpinners[0] = itemView.findViewById(R.id.controller_mapper_key_spinner1); + mKeySpinners[1] = itemView.findViewById(R.id.controller_mapper_key_spinner2); + mKeySpinners[2] = itemView.findViewById(R.id.controller_mapper_key_spinner3); + mKeySpinners[3] = itemView.findViewById(R.id.controller_mapper_key_spinner4); + for(Spinner spinner : mKeySpinners) { + spinner.setAdapter(mKeyAdapter); + spinner.setOnItemSelectedListener(this); + } + } + private void attach(int index) { + RebinderButton rebinderButton = mRebinderButtons[index]; + mExpandedView.setVisibility(View.GONE); + mButtonIcon.setImageResource(rebinderButton.iconResourceId); + String buttonName = mContext.getString(rebinderButton.localeResourceId); + mButtonIcon.setContentDescription(buttonName); + rebinderButton.changeViewHolder(this); + + GamepadEmulatedButton realButton = mRealButtons[index]; + + mAttachedButton = realButton; + + if(realButton instanceof GamepadButton) { + mToggleableSwitch.setChecked(((GamepadButton)realButton).isToggleable); + mToggleableSwitch.setVisibility(View.VISIBLE); + }else { + mToggleableSwitch.setVisibility(View.GONE); + } + + mKeycodes = realButton.keycodes; + + int spinnerIndex; + + // Populate spinners with known keycodes until we run out of keycodes + for(spinnerIndex = 0; spinnerIndex < mKeycodes.length; spinnerIndex++) { + Spinner keySpinner = mKeySpinners[spinnerIndex]; + keySpinner.setEnabled(true); + short keyCode = mKeycodes[spinnerIndex]; + int selected; + if(keyCode < 0) selected = keyCode + mSpecialKeycodeCount; + else selected = EfficientAndroidLWJGLKeycode.getIndexByValue(keyCode) + mSpecialKeycodeCount; + keySpinner.setSelection(selected); + } + // In case if there is too much spinners, disable the rest of them + for(;spinnerIndex < mKeySpinners.length; spinnerIndex++) { + mKeySpinners[spinnerIndex].setEnabled(false); + } + updateKeycodeLabel(); + + mAttachedPosition = index; + } + private void detach() { + mRebinderButtons[mAttachedPosition].changeViewHolder(null); + mAttachedPosition = -1; + mAttachedButton = null; + } + private void setPressed(boolean pressed) { + itemView.setBackgroundColor(pressed ? COLOR_ACTIVE_BUTTON : Color.TRANSPARENT); + } + + private void updateKeycodeLabel() { + StringBuilder labelBuilder = new StringBuilder(); + boolean first = true; + int unspecifiedPosition = GamepadMap.UNSPECIFIED + mSpecialKeycodeCount; + for (Spinner keySpinner : mKeySpinners) { + if (keySpinner.getSelectedItemPosition() == unspecifiedPosition) continue; + if (!first) labelBuilder.append(" + "); + else first = false; + labelBuilder.append(keySpinner.getSelectedItem().toString()); + } + if(labelBuilder.length() == 0) labelBuilder.append(mKeyAdapter.getItem(unspecifiedPosition)); + mKeycodeLabel.setText(labelBuilder.toString()); + } + + @Override + public void onItemSelected(AdapterView adapterView, View view, int selectionIndex, long selectionId) { + if(mAttachedPosition == -1) return; + int editedKeycodeIndex = -1; + for(int i = 0; i < mKeySpinners.length && i < mKeycodes.length; i++) { + if(!adapterView.equals(mKeySpinners[i])) continue; + editedKeycodeIndex = i; + break; + } + if(editedKeycodeIndex == -1) return; + int keycode_offset = selectionIndex - mSpecialKeycodeCount; + if(selectionIndex <= mSpecialKeycodeCount) mKeycodes[editedKeycodeIndex] = (short) (keycode_offset); + else mKeycodes[editedKeycodeIndex] = EfficientAndroidLWJGLKeycode.getValueByIndex(keycode_offset); + updateKeycodeLabel(); + try { + GamepadMapStore.save(); + }catch (Exception e) { + Tools.showError(adapterView.getContext(), e); + } + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } + + @Override + public void onClick(View view) { + int visibility = mExpandedView.getVisibility(); + switch (visibility) { + case View.INVISIBLE: + case View.GONE: + mExpansionIndicator.setRotation(0); + mExpandedView.setVisibility(View.VISIBLE); + break; + case View.VISIBLE: + mExpansionIndicator.setRotation(180); + mExpandedView.setVisibility(View.GONE); + } + } + + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + if(!(mAttachedButton instanceof GamepadButton)) return; + ((GamepadButton)mAttachedButton).isToggleable = checked; + try { + GamepadMapStore.save(); + }catch (Exception e) { + Tools.showError(compoundButton.getContext(), e); + } + } + } + + @Override + public GamepadMap getMenuMap() { + return mSimulatedGamepadMap; + } + + @Override + public GamepadMap getGameMap() { + return mSimulatedGamepadMap; + } + + @Override + public boolean isGrabbing() { + return mGrabState; + } + + @Override + public void attachGrabListener(GrabListener grabListener) { + mGamepadGrabListener = grabListener; + grabListener.onGrabState(mGrabState); + } + + public void setGrabState(boolean newState) { + mGrabState = newState; + if(mGamepadGrabListener != null) mGamepadGrabListener.onGrabState(newState); + if(mGrabState == mOldState) return; + updateRealButtons(); + updateStickIcons(); + notifyItemRangeChanged(0, mRebinderButtons.length); + mOldState = mGrabState; + } +} diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/HotbarView.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/HotbarView.java index 640d65fbcf..cd2ff5d1ce 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/HotbarView.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/HotbarView.java @@ -94,7 +94,8 @@ public boolean onTouchEvent(MotionEvent event) { else mDropGesture.submit(); // Determine the hotbar slot float x = event.getX(); - if(x < 0 || x > mWidth) { + // Ignore positions equal to mWidth because they would translate into an out-of-bounds hotbar index + if(x < 0 || x >= mWidth) { // If out of bounds, cancel the hotbar gesture to avoid dropping items on last hotbar slots mDropGesture.cancel(); return true; diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/GamepadMapperFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/GamepadMapperFragment.java new file mode 100644 index 0000000000..33acfed4fd --- /dev/null +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/GamepadMapperFragment.java @@ -0,0 +1,122 @@ +package net.kdt.pojavlaunch.fragments; + +import android.app.Activity; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.view.InputDevice; +import android.view.KeyEvent; +import android.view.MotionEvent; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Spinner; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import net.kdt.pojavlaunch.R; +import net.kdt.pojavlaunch.customcontrols.gamepad.Gamepad; +import net.kdt.pojavlaunch.customcontrols.gamepad.GamepadMapperAdapter; + +import fr.spse.gamepad_remapper.RemapperManager; +import fr.spse.gamepad_remapper.RemapperView; + +public class GamepadMapperFragment extends Fragment implements + View.OnKeyListener, View.OnGenericMotionListener, AdapterView.OnItemSelectedListener { + public static final String TAG = "GamepadMapperFragment"; + private final RemapperView.Builder mRemapperViewBuilder = new RemapperView.Builder(null) + .remapA(true) + .remapB(true) + .remapX(true) + .remapY(true) + .remapLeftJoystick(true) + .remapRightJoystick(true) + .remapStart(true) + .remapSelect(true) + .remapLeftShoulder(true) + .remapRightShoulder(true) + .remapLeftTrigger(true) + .remapRightTrigger(true) + .remapDpad(true); + private final Handler mExitHandler = new Handler(Looper.getMainLooper()); + private final Runnable mExitRunnable = () -> { + Activity activity = getActivity(); + if(activity == null) return; + activity.onBackPressed(); + }; + private RemapperManager mInputManager; + private GamepadMapperAdapter mMapperAdapter; + private Gamepad mGamepad; + public GamepadMapperFragment() { + super(R.layout.fragment_controller_remapper); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + RecyclerView buttonRecyclerView = view.findViewById(R.id.gamepad_remapper_recycler); + mMapperAdapter = new GamepadMapperAdapter(view.getContext()); + buttonRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); + buttonRecyclerView.setAdapter(mMapperAdapter); + buttonRecyclerView.setOnKeyListener(this); + buttonRecyclerView.setOnGenericMotionListener(this); + buttonRecyclerView.requestFocus(); + mInputManager = new RemapperManager(view.getContext(), mRemapperViewBuilder); + Spinner grabStateSpinner = view.findViewById(R.id.gamepad_remapper_mode_spinner); + ArrayAdapter mGrabStateAdapter = new ArrayAdapter<>(view.getContext(), R.layout.support_simple_spinner_dropdown_item); + mGrabStateAdapter.addAll(getString(R.string.customctrl_visibility_in_menus), getString(R.string.customctrl_visibility_ingame)); + grabStateSpinner.setAdapter(mGrabStateAdapter); + grabStateSpinner.setSelection(0); + grabStateSpinner.setOnItemSelectedListener(this); + } + + private void createGamepad(View mainView, InputDevice inputDevice) { + mGamepad = new Gamepad(mainView, inputDevice, mMapperAdapter, false) { + @Override + public void handleGamepadInput(int keycode, float value) { + if(keycode == KeyEvent.KEYCODE_BUTTON_SELECT) { + handleExitButton(value > 0.5); + } + super.handleGamepadInput(keycode, value); + } + }; + } + + private void handleExitButton(boolean isPressed) { + if(isPressed) mExitHandler.postDelayed(mExitRunnable, 400); + else mExitHandler.removeCallbacks(mExitRunnable); + } + + @Override + public boolean onKey(View view, int i, KeyEvent keyEvent) { + View mainView = getView(); + if(!Gamepad.isGamepadEvent(keyEvent) || mainView == null) return false; + if(mGamepad == null) createGamepad(mainView, keyEvent.getDevice()); + mInputManager.handleKeyEventInput(mainView.getContext(), keyEvent, mGamepad); + return true; + } + + @Override + public boolean onGenericMotion(View view, MotionEvent motionEvent) { + View mainView = getView(); + if(!Gamepad.isGamepadEvent(motionEvent) || mainView == null) return false; + if(mGamepad == null) createGamepad(mainView, motionEvent.getDevice()); + mInputManager.handleMotionEventInput(mainView.getContext(), motionEvent, mGamepad); + return true; + } + + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + boolean grab = i == 1; + mMapperAdapter.setGrabState(grab); + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } +} diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/LocalLoginFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/LocalLoginFragment.java index ecfcd999cc..1fc551b784 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/LocalLoginFragment.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/LocalLoginFragment.java @@ -1,5 +1,6 @@ package net.kdt.pojavlaunch.fragments; +import android.content.Context; import android.os.Bundle; import android.view.View; import android.widget.EditText; @@ -20,17 +21,23 @@ public class LocalLoginFragment extends Fragment { public static final String TAG = "LOCAL_LOGIN_FRAGMENT"; + private final Pattern mUsernameValidationPattern; private EditText mUsernameEditText; public LocalLoginFragment(){ super(R.layout.fragment_local_login); + mUsernameValidationPattern = Pattern.compile("^[a-zA-Z0-9_]*$"); } @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { mUsernameEditText = view.findViewById(R.id.login_edit_email); view.findViewById(R.id.login_button).setOnClickListener(v -> { - if(!checkEditText()) return; + if(!checkEditText()) { + Context context = v.getContext(); + Tools.dialog(context, context.getString(R.string.local_login_bad_username_title), context.getString(R.string.local_login_bad_username_text)); + return; + } ExtraCore.setValue(ExtraConstants.MOJANG_LOGIN_TODO, new String[]{ mUsernameEditText.getText().toString(), "" @@ -46,13 +53,11 @@ private boolean checkEditText(){ String text = mUsernameEditText.getText().toString(); - Pattern pattern = Pattern.compile("[^a-zA-Z0-9_]"); - Matcher matcher = pattern.matcher(text); - + Matcher matcher = mUsernameValidationPattern.matcher(text); return !(text.isEmpty() || text.length() < 3 || text.length() > 16 - || matcher.find() + || !matcher.find() || new File(Tools.DIR_ACCOUNT_NEW + "/" + text + ".json").exists() ); } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/MainMenuFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/MainMenuFragment.java index beea56e1d8..79a87bccd5 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/MainMenuFragment.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/MainMenuFragment.java @@ -34,6 +34,7 @@ public MainMenuFragment(){ @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { Button mNewsButton = view.findViewById(R.id.news_button); + Button mDiscordButton = view.findViewById(R.id.discord_button); Button mCustomControlButton = view.findViewById(R.id.custom_control_button); Button mInstallJarButton = view.findViewById(R.id.install_jar_button); Button mShareLogsButton = view.findViewById(R.id.share_logs_button); @@ -43,6 +44,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat mVersionSpinner = view.findViewById(R.id.mc_version_spinner); mNewsButton.setOnClickListener(v -> Tools.openURL(requireActivity(), Tools.URL_HOME)); + mDiscordButton.setOnClickListener(v -> Tools.openURL(requireActivity(), getString(R.string.discord_invite))); mCustomControlButton.setOnClickListener(v -> startActivity(new Intent(requireContext(), CustomControlsActivity.class))); mInstallJarButton.setOnClickListener(v -> runInstallerWithConfirmation(false)); mInstallJarButton.setOnLongClickListener(v->{ @@ -56,7 +58,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat mShareLogsButton.setOnClickListener((v) -> shareLog(requireContext())); mNewsButton.setOnLongClickListener((v)->{ - Tools.swapFragment(requireActivity(), SearchModFragment.class, SearchModFragment.TAG, null); + Tools.swapFragment(requireActivity(), GamepadMapperFragment.class, GamepadMapperFragment.TAG, null); return true; }); } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/ProfileEditorFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/ProfileEditorFragment.java index d0e5709626..088747b110 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/ProfileEditorFragment.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/ProfileEditorFragment.java @@ -181,7 +181,18 @@ private void loadValues(@NonNull String profile, @NonNull Context context){ private MinecraftProfile getProfile(@NonNull String profile){ MinecraftProfile minecraftProfile; if(getArguments() == null) { - minecraftProfile = new MinecraftProfile(LauncherProfiles.mainProfileJson.profiles.get(profile)); + // EDGE CASE: User leaves Pojav in background. Pojav gets terminated in the background. + // Current selected fragment and its arguments are saved. + // User returns to Pojav. Android restarts process and reinitializes fragment without + // going to the main screen. mainProfileJson and profiles left uninitialized, which + // results in a crash. + // Reload the profiles to avoid this edge case. + LauncherProfiles.load(); + MinecraftProfile originalProfile = LauncherProfiles.mainProfileJson.profiles.get(profile); + // EDGE CASE: User edits the JSON, so the profile that was edited no longer exists. + // Create a brand new profile as a fallback for this case. + if(originalProfile != null) minecraftProfile = new MinecraftProfile(originalProfile); + else minecraftProfile = MinecraftProfile.createTemplate(); mProfileKey = profile; }else{ minecraftProfile = MinecraftProfile.createTemplate(); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/memory/MemoryHoleFinder.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/memory/MemoryHoleFinder.java new file mode 100644 index 0000000000..283f6651ef --- /dev/null +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/memory/MemoryHoleFinder.java @@ -0,0 +1,22 @@ +package net.kdt.pojavlaunch.memory; + +import net.kdt.pojavlaunch.Architecture; + +public class MemoryHoleFinder implements SelfMapsParser.Callback { + private long mPreviousEnd = 0; + private long mLargestHole = -1; + private final long mAddressingLimit = Architecture.getAddressSpaceLimit(); + @Override + public boolean process(long begin, long end, String wholeLine) { + if(begin >= mAddressingLimit) begin = mAddressingLimit; + long holeSize = begin - mPreviousEnd; + if(mLargestHole < holeSize) mLargestHole = holeSize; + if(begin == mAddressingLimit) return false; + mPreviousEnd = end; + return true; + } + + public long getLargestHole() { + return mLargestHole; + } +} diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/memory/SelfMapsParser.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/memory/SelfMapsParser.java new file mode 100644 index 0000000000..6b8bab341b --- /dev/null +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/memory/SelfMapsParser.java @@ -0,0 +1,35 @@ +package net.kdt.pojavlaunch.memory; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Scanner; + +public class SelfMapsParser { + private final Callback mCallback; + public SelfMapsParser(Callback callback) { + mCallback = callback; + } + + public void run() throws IOException, NumberFormatException { + try (FileInputStream fileInputStream = new FileInputStream("/proc/self/maps")) { + Scanner scanner = new Scanner(fileInputStream); + while(scanner.hasNextLine()) { + if(!forEachLine(scanner.nextLine())) break; + } + } + } + + private boolean forEachLine(String line) throws NumberFormatException { + int firstSpaceIndex = line.indexOf(' '); + String addresses = line.substring(0, firstSpaceIndex); + String[] addressArray = addresses.split("-"); + if(addressArray.length < 2) return true; + long begin = Long.parseLong(addressArray[0], 16); + long end = Long.parseLong(addressArray[1], 16); + return mCallback.process(begin, end, line); + } + + public interface Callback { + boolean process(long startAddress, long endAddress, String wholeLine); + } +} diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/services/GameService.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/services/GameService.java index d259490f09..43ab1c0879 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/services/GameService.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/services/GameService.java @@ -1,8 +1,10 @@ package net.kdt.pojavlaunch.services; +import android.app.Notification; import android.app.PendingIntent; import android.app.Service; import android.content.Intent; +import android.content.pm.ServiceInfo; import android.os.Binder; import android.os.Build; import android.os.IBinder; @@ -43,7 +45,13 @@ public int onStartCommand(Intent intent, int flags, int startId) { .addAction(android.R.drawable.ic_menu_close_clear_cancel, getString(R.string.notification_terminate), pendingKillIntent) .setSmallIcon(R.drawable.notif_icon) .setNotificationSilent(); - startForeground(NotificationUtils.NOTIFICATION_ID_GAME_SERVICE, notificationBuilder.build()); + + Notification notification = notificationBuilder.build(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + startForeground(NotificationUtils.NOTIFICATION_ID_GAME_SERVICE, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST); + } else { + startForeground(NotificationUtils.NOTIFICATION_ID_GAME_SERVICE, notification); + } return START_NOT_STICKY; // non-sticky so android wont try restarting the game after the user uses the "Quit" button } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/services/ProgressService.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/services/ProgressService.java index fa005f0161..4678c3fb13 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/services/ProgressService.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/services/ProgressService.java @@ -1,10 +1,12 @@ package net.kdt.pojavlaunch.services; import android.annotation.SuppressLint; +import android.app.Notification; import android.app.PendingIntent; import android.app.Service; import android.content.Context; import android.content.Intent; +import android.content.pm.ServiceInfo; import android.os.Build; import android.os.IBinder; import android.os.Process; @@ -64,7 +66,12 @@ public int onStartCommand(Intent intent, int flags, int startId) { } Log.d("ProgressService", "Started!"); mNotificationBuilder.setContentText(getString(R.string.progresslayout_tasks_in_progress, ProgressKeeper.getTaskCount())); - startForeground(NotificationUtils.NOTIFICATION_ID_PROGRESS_SERVICE, mNotificationBuilder.build()); + Notification notification = mNotificationBuilder.build(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + startForeground(NotificationUtils.NOTIFICATION_ID_PROGRESS_SERVICE, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST); + } else { + startForeground(NotificationUtils.NOTIFICATION_ID_PROGRESS_SERVICE, notification); + } if(ProgressKeeper.getTaskCount() < 1) stopSelf(); else ProgressKeeper.addTaskCountListener(this, false); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java index c996107e3c..26d7ca379a 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java @@ -489,18 +489,18 @@ public static String loadGraphicsLibrary(){ case "vgpu": renderLibrary = "libvgpu.so"; break; - case "malihw_panfrost": + case "malihw_panfrost": renderLibrary = "libOSMesa_pan.so"; break; - case "virgl": - case "vulkan_zink_legacy": + case "virgl": + case "vulkan_zink_legacy": renderLibrary = "libOSMesa_znL.so"; break; case "vulkan_zink_standard": renderLibrary = "libOSMesa_std.so"; break; case "vulkan_zink": - case "adrhw_freedreno": + case "adrhw_freedreno": renderLibrary = "libOSMesa.so"; break; case "opengles3_desktopgl_angle_vulkan" : renderLibrary = "libtinywrapper.so"; break; @@ -618,6 +618,5 @@ public static int getDetectedVersion() { static { System.loadLibrary("pojavexec"); System.loadLibrary("pojavexec_awt"); - System.loadLibrary("istdio"); } } diff --git a/app_pojavlauncher/src/main/jni/Android.mk b/app_pojavlauncher/src/main/jni/Android.mk index 4790b3e844..3ac7a1f727 100644 --- a/app_pojavlauncher/src/main/jni/Android.mk +++ b/app_pojavlauncher/src/main/jni/Android.mk @@ -20,23 +20,15 @@ LOCAL_SRC_FILES := tinywrapper/main.c tinywrapper/string_utils.c LOCAL_C_INCLUDES := $(LOCAL_PATH)/tinywrapper include $(BUILD_SHARED_LIBRARY) -include $(CLEAR_VARS) -LOCAL_MODULE := angle_gles2_new -LOCAL_SRC_FILES := tinywrapper_new_angle/angle-gles/$(TARGET_ARCH_ABI)/libGLESv2_angle.so -include $(PREBUILT_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := tinywrapper_new_angle -LOCAL_SHARED_LIBRARIES := angle_gles2_new -LOCAL_SRC_FILES := tinywrapper_new_angle/main.c tinywrapper_new_angle/string_utils.c -LOCAL_C_INCLUDES := $(LOCAL_PATH)/tinywrapper_new_angle -include $(BUILD_SHARED_LIBRARY) +$(call import-module,prefab/bytehook) +LOCAL_PATH := $(HERE_PATH) include $(CLEAR_VARS) # Link GLESv2 for test LOCAL_LDLIBS := -ldl -llog -landroid # -lGLESv2 LOCAL_MODULE := pojavexec +LOCAL_SHARED_LIBRARIES := bytehook # LOCAL_CFLAGS += -DDEBUG # -DGLES_TEST LOCAL_SRC_FILES := \ @@ -51,6 +43,7 @@ LOCAL_SRC_FILES := \ input_bridge_v3.c \ jre_launcher.c \ utils.c \ + stdio_is.c \ driver_helper/nsbypass.c ifeq ($(TARGET_ARCH_ABI),arm64-v8a) @@ -67,16 +60,6 @@ LOCAL_LDFLAGS := -z global include $(BUILD_SHARED_LIBRARY) #endif -$(call import-module,prefab/bytehook) -LOCAL_PATH := $(HERE_PATH) - -include $(CLEAR_VARS) -LOCAL_MODULE := istdio -LOCAL_SHARED_LIBRARIES := bytehook -LOCAL_SRC_FILES := \ - stdio_is.c -include $(BUILD_SHARED_LIBRARY) - include $(CLEAR_VARS) LOCAL_MODULE := pojavexec_awt LOCAL_SRC_FILES := \ diff --git a/app_pojavlauncher/src/main/jni/environ/environ.h b/app_pojavlauncher/src/main/jni/environ/environ.h index c1b0fbe260..a41d61cec6 100644 --- a/app_pojavlauncher/src/main/jni/environ/environ.h +++ b/app_pojavlauncher/src/main/jni/environ/environ.h @@ -56,7 +56,7 @@ struct solcraft_environ_s { JavaVM* dalvikJavaVMPtr; JNIEnv* dalvikJNIEnvPtr_ANDROID; long showingWindow; - bool isInputReady, isCursorEntered, isUseStackQueueCall, isPumpingEvents; + bool isInputReady, isCursorEntered, isUseStackQueueCall, shouldUpdateMouse; int savedWidth, savedHeight; #define ADD_CALLBACK_WWIN(NAME) \ GLFW_invoke_##NAME##_func* GLFW_invoke_##NAME; diff --git a/app_pojavlauncher/src/main/jni/input_bridge_v3.c b/app_pojavlauncher/src/main/jni/input_bridge_v3.c index 5e13b1ad26..34af119d08 100644 --- a/app_pojavlauncher/src/main/jni/input_bridge_v3.c +++ b/app_pojavlauncher/src/main/jni/input_bridge_v3.c @@ -99,14 +99,7 @@ void handleFramebufferSizeJava(long window, int w, int h) { } void pojavPumpEvents(void* window) { - if(solcraft_environ->isPumpingEvents) return; - // prevent further calls until we exit the loop - // by spec, they will be called on the same thread so no synchronization here - solcraft_environ->isPumpingEvents = true; - - if((solcraft_environ->cLastX != solcraft_environ->cursorX || solcraft_environ->cLastY != solcraft_environ->cursorY) && solcraft_environ->GLFW_invoke_CursorPos) { - solcraft_environ->cLastX = solcraft_environ->cursorX; - solcraft_environ->cLastY = solcraft_environ->cursorY; + if(solcraft_environ->shouldUpdateMouse) { solcraft_environ->GLFW_invoke_CursorPos(window, floor(solcraft_environ->cursorX), floor(solcraft_environ->cursorY)); } @@ -148,11 +141,10 @@ void pojavPumpEvents(void* window) { } // The out target index is updated by the rewinder - solcraft_environ->isPumpingEvents = false; } -/** Setup the amount of event that will get pumped into each window */ -void pojavComputeEventTarget() { +/** Prepare the library for sending out callbacks to all windows */ +void pojavStartPumping() { size_t counter = atomic_load_explicit(&solcraft_environ->eventCounter, memory_order_acquire); size_t index = solcraft_environ->outEventIndex; @@ -163,14 +155,23 @@ void pojavComputeEventTarget() { // Only accessed by one unique thread, no need for atomic store solcraft_environ->inEventCount = counter; solcraft_environ->outTargetIndex = targetIndex; + + //PumpEvents is called for every window, so this logic should be there in order to correctly distribute events to all windows. + if((solcraft_environ->cLastX != solcraft_environ->cursorX || solcraft_environ->cLastY != solcraft_environ->cursorY) && solcraft_environ->GLFW_invoke_CursorPos) { + solcraft_environ->cLastX = solcraft_environ->cursorX; + solcraft_environ->cLastY = solcraft_environ->cursorY; + solcraft_environ->shouldUpdateMouse = true; + } } -/** Apply index offsets after events have been pumped */ -void pojavRewindEvents() { +/** Prepare the library for the next round of new events */ +void pojavStopPumping() { solcraft_environ->outEventIndex = solcraft_environ->outTargetIndex; // New events may have arrived while pumping, so remove only the difference before the start and end of execution atomic_fetch_sub_explicit(&solcraft_environ->eventCounter, solcraft_environ->inEventCount, memory_order_acquire); + // Make sure the next frame won't send mouse updates if it's unnecessary + solcraft_environ->shouldUpdateMouse = false; } JNIEXPORT void JNICALL diff --git a/app_pojavlauncher/src/main/jni/jre_launcher.c b/app_pojavlauncher/src/main/jni/jre_launcher.c index 5e53af1d4b..4b8bbf882c 100644 --- a/app_pojavlauncher/src/main/jni/jre_launcher.c +++ b/app_pojavlauncher/src/main/jni/jre_launcher.c @@ -51,25 +51,6 @@ static const char** const_appclasspath = NULL; static const jboolean const_javaw = JNI_FALSE; static const jboolean const_cpwildcard = JNI_TRUE; static const jint const_ergo_class = 0; // DEFAULT_POLICY -static struct sigaction old_sa[NSIG]; - -void (*__old_sa)(int signal, siginfo_t *info, void *reserved); -int (*JVM_handle_linux_signal)(int signo, siginfo_t* siginfo, void* ucontext, int abort_if_unrecognized); - -void android_sigaction(int signal, siginfo_t *info, void *reserved) { - printf("process killed with signal %d code %p addr %p\n", signal,info->si_code,info->si_addr); - if (JVM_handle_linux_signal == NULL) { // should not happen, but still - __old_sa = old_sa[signal].sa_sigaction; - __old_sa(signal,info,reserved); - exit(1); - } else { - // Based on https://github.com/PojavLauncherTeam/openjdk-multiarch-jdk8u/blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/os/linux/vm/os_linux.cpp#L4688-4693 - int orig_errno = errno; // Preserve errno value over signal handler. - JVM_handle_linux_signal(signal, info, reserved, true); - errno = orig_errno; - } -} -typedef jint JNI_CreateJavaVM_func(JavaVM **pvm, void **penv, void *args); typedef jint JLI_Launch_func(int argc, char ** argv, /* main argc, argc */ int jargc, const char** jargv, /* java args */ @@ -84,9 +65,80 @@ typedef jint JLI_Launch_func(int argc, char ** argv, /* main argc, argc */ jint ergo /* ergonomics class policy */ ); +struct { + sigset_t tracked_sigset; + int pipe[2]; +} abort_waiter_data; + +_Noreturn extern void nominal_exit(int code, bool is_signal); + +_Noreturn static void* abort_waiter_thread(void* extraArg) { + // Don't allow this thread to receive signals this thread is tracking. + // We should only receive them externally. + pthread_sigmask(SIG_BLOCK, &abort_waiter_data.tracked_sigset, NULL); + int signal; + // Block for reading the signal ID until it arrives + read(abort_waiter_data.pipe[0], &signal, sizeof(int)); + // Die + nominal_exit(signal, true); +} + +_Noreturn static void abort_waiter_handler(int signal) { + // Write the final signal into the pipe and block forever. + write(abort_waiter_data.pipe[1], &signal, sizeof(int)); + while(1) {} +} + +static void abort_waiter_setup() { + // Only abort on SIGABRT as the JVM either emits SIGABRT or SIGKILL (which we can't catch) + // when a fatal crash occurs. Still, keep expandability if we would want to add more + // user-friendly fatal signals in the future. + const static int tracked_signals[] = {SIGABRT}; + const static int ntracked = (sizeof(tracked_signals) / sizeof(tracked_signals[0])); + struct sigaction sigactions[ntracked]; + sigemptyset(&abort_waiter_data.tracked_sigset); + for(size_t i = 0; i < ntracked; i++) { + sigaddset(&abort_waiter_data.tracked_sigset, tracked_signals[i]); + sigactions[i].sa_handler = abort_waiter_handler; + } + if(pipe(abort_waiter_data.pipe) != 0) { + printf("Failed to set up aborter pipe: %s\n", strerror(errno)); + return; + } + pthread_t waiter_thread; int result; + if((result = pthread_create(&waiter_thread, NULL, abort_waiter_thread, NULL)) != 0) { + printf("Failed to start up waiter thread: %s", strerror(result)); + for(int i = 0; i < 2; i++) close(abort_waiter_data.pipe[i]); + return; + } + // Only set the sigactions *after* we have already set up the pipe and the thread. + for(size_t i = 0; i < ntracked; i++) { + if(sigaction(tracked_signals[i], &sigactions[i], NULL) != 0) { + // Not returning here because we may have set some handlers successfully. + // Some handling is better than no handling. + printf("Failed to set signal hander for signal %i: %s", i, strerror(errno)); + } + } +} + static jint launchJVM(int margc, char** margv) { void* libjli = dlopen("libjli.so", RTLD_LAZY | RTLD_GLOBAL); + // Unset all signal handlers to create a good slate for JVM signal detection. + struct sigaction clean_sa; + memset(&clean_sa, 0, sizeof (struct sigaction)); + for(int sigid = SIGHUP; sigid < NSIG; sigid++) { + // For some reason Android specifically checks if you set SIGSEGV to SIG_DFL. + // There's probably a good reason for that but the signal handler here is + // temporary and will be replaced by the Java VM's signal/crash handler. + // Work around the warning by using SIG_IGN for SIGSEGV + if(sigid == SIGSEGV) clean_sa.sa_handler = SIG_IGN; + else clean_sa.sa_handler = SIG_DFL; + sigaction(sigid, &clean_sa, NULL); + } + // Set up the thread that will abort the launcher with an user-facing dialog on a signal. + abort_waiter_setup(); + // Boardwalk: silence // LOGD("JLI lib = %x", (int)libjli); if (NULL == libjli) { @@ -130,35 +182,8 @@ static jint launchJVM(int margc, char** margv) { * Signature: ([Ljava/lang/String;)I */ JNIEXPORT jint JNICALL Java_com_oracle_dalvik_VMLauncher_launchJVM(JNIEnv *env, jclass clazz, jobjectArray argsArray) { -#ifdef TRY_SIG2JVM - void* libjvm = dlopen("libjvm.so", RTLD_LAZY | RTLD_GLOBAL); - if (NULL == libjvm) { - LOGE("JVM lib = NULL: %s", dlerror()); - return -1; - } - JVM_handle_linux_signal = dlsym(libjvm, "JVM_handle_linux_signal"); -#endif jint res = 0; - // int i; - //Prepare the signal trapper - struct sigaction catcher; - memset(&catcher,0,sizeof(sigaction)); - catcher.sa_sigaction = android_sigaction; - catcher.sa_flags = SA_SIGINFO|SA_RESTART; - // SA_RESETHAND; -#define CATCHSIG(X) sigaction(X, &catcher, &old_sa[X]) - CATCHSIG(SIGILL); - //CATCHSIG(SIGABRT); - CATCHSIG(SIGBUS); - CATCHSIG(SIGFPE); -#ifdef TRY_SIG2JVM - CATCHSIG(SIGSEGV); -#endif - CATCHSIG(SIGSTKFLT); - CATCHSIG(SIGPIPE); - CATCHSIG(SIGXFSZ); - //Signal trapper ready // Save dalvik JNIEnv pointer for JVM launch thread solcraft_environ->dalvikJNIEnvPtr_ANDROID = env; diff --git a/app_pojavlauncher/src/main/jni/stdio_is.c b/app_pojavlauncher/src/main/jni/stdio_is.c index 2ef90a9ceb..03bb7b1688 100644 --- a/app_pojavlauncher/src/main/jni/stdio_is.c +++ b/app_pojavlauncher/src/main/jni/stdio_is.c @@ -9,6 +9,7 @@ #include #include #include +#include // // Created by maks on 17.02.21. @@ -19,7 +20,6 @@ static volatile jclass exitTrap_exitClass; static volatile jmethodID exitTrap_staticMethod; static JavaVM *exitTrap_jvm; -static JavaVM *stdiois_jvm; static int pfd[2]; static pthread_t logger; static jmethodID logger_onEventLogged; @@ -37,19 +37,11 @@ static bool recordBuffer(char* buf, ssize_t len) { return true; } -JNIEXPORT jint JNI_OnLoad(JavaVM* vm, __attribute((unused)) void* reserved) { - stdiois_jvm = vm; - JNIEnv *env; - (*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_4); - jclass eventLogListener = (*env)->FindClass(env, "net/kdt/pojavlaunch/Logger$eventLogListener"); - logger_onEventLogged = (*env)->GetMethodID(env, eventLogListener, "onEventLogged", "(Ljava/lang/String;)V"); - return JNI_VERSION_1_4; -} - static void *logger_thread() { JNIEnv *env; jstring writeString; - (*stdiois_jvm)->AttachCurrentThread(stdiois_jvm, &env, NULL); + JavaVM* dvm = solcraft_environ->dalvikJavaVMPtr; + (*dvm)->AttachCurrentThread(dvm, &env, NULL); ssize_t rsize; char buf[2050]; while((rsize = read(pfd[0], buf, sizeof(buf)-1)) > 0) { @@ -64,7 +56,7 @@ static void *logger_thread() { (*env)->DeleteLocalRef(env, writeString); } } - (*stdiois_jvm)->DetachCurrentThread(stdiois_jvm); + (*dvm)->DetachCurrentThread(dvm); return NULL; } JNIEXPORT void JNICALL @@ -74,6 +66,10 @@ Java_net_kdt_pojavlaunch_Logger_begin(JNIEnv *env, __attribute((unused)) jclass latestlog_fd = -1; close(localfd); } + if(logger_onEventLogged == NULL) { + jclass eventLogListener = (*env)->FindClass(env, "net/kdt/pojavlaunch/Logger$eventLogListener"); + logger_onEventLogged = (*env)->GetMethodID(env, eventLogListener, "onEventLogged", "(Ljava/lang/String;)V"); + } jclass ioeClass = (*env)->FindClass(env, "java/io/IOException"); @@ -109,7 +105,7 @@ Java_net_kdt_pojavlaunch_Logger_begin(JNIEnv *env, __attribute((unused)) jclass typedef void (*exit_func)(int); -_Noreturn static void nominal_exit(int code) { +_Noreturn void nominal_exit(int code, bool is_signal) { JNIEnv *env; jint errorCode = (*exitTrap_jvm)->GetEnv(exitTrap_jvm, (void**)&env, JNI_VERSION_1_6); if(errorCode == JNI_EDETACHED) { @@ -124,7 +120,7 @@ _Noreturn static void nominal_exit(int code) { if(code != 0) { // Exit code 0 is pretty established as "eh it's fine" // so only open the GUI if the code is != 0 - (*env)->CallStaticVoidMethod(env, exitTrap_exitClass, exitTrap_staticMethod, exitTrap_ctx, code); + (*env)->CallStaticVoidMethod(env, exitTrap_exitClass, exitTrap_staticMethod, exitTrap_ctx, code, is_signal); } // Delete the reference, not gonna need 'em later anyway (*env)->DeleteGlobalRef(env, exitTrap_ctx); @@ -155,7 +151,7 @@ static void custom_exit(int code) { } exit_tripped = true; // Perform a nominal exit, as we expect. - nominal_exit(code); + nominal_exit(code, false); BYTEHOOK_POP_STACK(); } @@ -165,14 +161,14 @@ static void custom_atexit() { return; } exit_tripped = true; - nominal_exit(0); + nominal_exit(0, false); } JNIEXPORT void JNICALL Java_net_kdt_pojavlaunch_utils_JREUtils_setupExitTrap(JNIEnv *env, __attribute((unused)) jclass clazz, jobject context) { exitTrap_ctx = (*env)->NewGlobalRef(env,context); (*env)->GetJavaVM(env,&exitTrap_jvm); exitTrap_exitClass = (*env)->NewGlobalRef(env,(*env)->FindClass(env,"net/kdt/pojavlaunch/ExitActivity")); - exitTrap_staticMethod = (*env)->GetStaticMethodID(env,exitTrap_exitClass,"showExitMessage","(Landroid/content/Context;I)V"); + exitTrap_staticMethod = (*env)->GetStaticMethodID(env,exitTrap_exitClass,"showExitMessage","(Landroid/content/Context;IZ)V"); if(bytehook_init(BYTEHOOK_MODE_AUTOMATIC, false) == BYTEHOOK_STATUS_CODE_OK) { bytehook_hook_all(NULL, diff --git a/app_pojavlauncher/src/main/jniLibs/arm64-v8a/libfreetype.so b/app_pojavlauncher/src/main/jniLibs/arm64-v8a/libfreetype.so new file mode 100644 index 0000000000..4b463d9f4e Binary files /dev/null and b/app_pojavlauncher/src/main/jniLibs/arm64-v8a/libfreetype.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/arm64-v8a/libgl4es_114.so b/app_pojavlauncher/src/main/jniLibs/arm64-v8a/libgl4es_114.so old mode 100644 new mode 100755 index bc393ac846..53e7952821 Binary files a/app_pojavlauncher/src/main/jniLibs/arm64-v8a/libgl4es_114.so and b/app_pojavlauncher/src/main/jniLibs/arm64-v8a/libgl4es_114.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/arm64-v8a/liblwjgl.so b/app_pojavlauncher/src/main/jniLibs/arm64-v8a/liblwjgl.so old mode 100755 new mode 100644 index 0716643cb0..db7926eee2 Binary files a/app_pojavlauncher/src/main/jniLibs/arm64-v8a/liblwjgl.so and b/app_pojavlauncher/src/main/jniLibs/arm64-v8a/liblwjgl.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/arm64-v8a/liblwjgl_nanovg.so b/app_pojavlauncher/src/main/jniLibs/arm64-v8a/liblwjgl_nanovg.so index c78fa1565a..e882a7ecc4 100644 Binary files a/app_pojavlauncher/src/main/jniLibs/arm64-v8a/liblwjgl_nanovg.so and b/app_pojavlauncher/src/main/jniLibs/arm64-v8a/liblwjgl_nanovg.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/arm64-v8a/liblwjgl_opengl.so b/app_pojavlauncher/src/main/jniLibs/arm64-v8a/liblwjgl_opengl.so index bad44ab625..42affb5804 100644 Binary files a/app_pojavlauncher/src/main/jniLibs/arm64-v8a/liblwjgl_opengl.so and b/app_pojavlauncher/src/main/jniLibs/arm64-v8a/liblwjgl_opengl.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/arm64-v8a/liblwjgl_stb.so b/app_pojavlauncher/src/main/jniLibs/arm64-v8a/liblwjgl_stb.so index 57ee82465f..f5b7636dd9 100644 Binary files a/app_pojavlauncher/src/main/jniLibs/arm64-v8a/liblwjgl_stb.so and b/app_pojavlauncher/src/main/jniLibs/arm64-v8a/liblwjgl_stb.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/arm64-v8a/liblwjgl_tinyfd.so b/app_pojavlauncher/src/main/jniLibs/arm64-v8a/liblwjgl_tinyfd.so index 42af1df5f5..4cd5dad05a 100644 Binary files a/app_pojavlauncher/src/main/jniLibs/arm64-v8a/liblwjgl_tinyfd.so and b/app_pojavlauncher/src/main/jniLibs/arm64-v8a/liblwjgl_tinyfd.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/libfreetype.so b/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/libfreetype.so new file mode 100644 index 0000000000..861d8eed2d Binary files /dev/null and b/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/libfreetype.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/libgl4es_114.so b/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/libgl4es_114.so old mode 100644 new mode 100755 index 4a2abeb9a7..fc706fa556 Binary files a/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/libgl4es_114.so and b/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/libgl4es_114.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/liblwjgl.so b/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/liblwjgl.so old mode 100755 new mode 100644 index f62ecaa29c..f60e066e20 Binary files a/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/liblwjgl.so and b/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/liblwjgl.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/liblwjgl_nanovg.so b/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/liblwjgl_nanovg.so index aea966adab..d2a325ce0f 100644 Binary files a/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/liblwjgl_nanovg.so and b/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/liblwjgl_nanovg.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/liblwjgl_opengl.so b/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/liblwjgl_opengl.so index 44dff1b806..43a127d904 100644 Binary files a/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/liblwjgl_opengl.so and b/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/liblwjgl_opengl.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/liblwjgl_stb.so b/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/liblwjgl_stb.so index fd8ce114c9..4e9f6a09a3 100644 Binary files a/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/liblwjgl_stb.so and b/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/liblwjgl_stb.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/liblwjgl_tinyfd.so b/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/liblwjgl_tinyfd.so index d30a1539aa..9687cbb6c4 100644 Binary files a/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/liblwjgl_tinyfd.so and b/app_pojavlauncher/src/main/jniLibs/armeabi-v7a/liblwjgl_tinyfd.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/x86/libfreetype.so b/app_pojavlauncher/src/main/jniLibs/x86/libfreetype.so new file mode 100644 index 0000000000..621719e025 Binary files /dev/null and b/app_pojavlauncher/src/main/jniLibs/x86/libfreetype.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/x86/libgl4es_114.so b/app_pojavlauncher/src/main/jniLibs/x86/libgl4es_114.so old mode 100644 new mode 100755 index 9fa57bf62c..12f910e571 Binary files a/app_pojavlauncher/src/main/jniLibs/x86/libgl4es_114.so and b/app_pojavlauncher/src/main/jniLibs/x86/libgl4es_114.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/x86/liblwjgl_nanovg.so b/app_pojavlauncher/src/main/jniLibs/x86/liblwjgl_nanovg.so index 8bf786578e..7c4d675016 100644 Binary files a/app_pojavlauncher/src/main/jniLibs/x86/liblwjgl_nanovg.so and b/app_pojavlauncher/src/main/jniLibs/x86/liblwjgl_nanovg.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/x86/liblwjgl_opengl.so b/app_pojavlauncher/src/main/jniLibs/x86/liblwjgl_opengl.so index bf0f05c706..06b7487f7c 100644 Binary files a/app_pojavlauncher/src/main/jniLibs/x86/liblwjgl_opengl.so and b/app_pojavlauncher/src/main/jniLibs/x86/liblwjgl_opengl.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/x86/liblwjgl_stb.so b/app_pojavlauncher/src/main/jniLibs/x86/liblwjgl_stb.so index 7aebedf416..3b06eb6c79 100644 Binary files a/app_pojavlauncher/src/main/jniLibs/x86/liblwjgl_stb.so and b/app_pojavlauncher/src/main/jniLibs/x86/liblwjgl_stb.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/x86/liblwjgl_tinyfd.so b/app_pojavlauncher/src/main/jniLibs/x86/liblwjgl_tinyfd.so index 4c9d5eaa24..9bedb534a8 100644 Binary files a/app_pojavlauncher/src/main/jniLibs/x86/liblwjgl_tinyfd.so and b/app_pojavlauncher/src/main/jniLibs/x86/liblwjgl_tinyfd.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/x86_64/libfreetype.so b/app_pojavlauncher/src/main/jniLibs/x86_64/libfreetype.so new file mode 100644 index 0000000000..2360a1d559 Binary files /dev/null and b/app_pojavlauncher/src/main/jniLibs/x86_64/libfreetype.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/x86_64/libgl4es_114.so b/app_pojavlauncher/src/main/jniLibs/x86_64/libgl4es_114.so old mode 100644 new mode 100755 index 34e905dcc4..b21f9355d1 Binary files a/app_pojavlauncher/src/main/jniLibs/x86_64/libgl4es_114.so and b/app_pojavlauncher/src/main/jniLibs/x86_64/libgl4es_114.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/x86_64/liblwjgl.so b/app_pojavlauncher/src/main/jniLibs/x86_64/liblwjgl.so old mode 100755 new mode 100644 index 6528ee7535..cadba70357 Binary files a/app_pojavlauncher/src/main/jniLibs/x86_64/liblwjgl.so and b/app_pojavlauncher/src/main/jniLibs/x86_64/liblwjgl.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/x86_64/liblwjgl_nanovg.so b/app_pojavlauncher/src/main/jniLibs/x86_64/liblwjgl_nanovg.so index 283728cdce..5979a2b6d1 100644 Binary files a/app_pojavlauncher/src/main/jniLibs/x86_64/liblwjgl_nanovg.so and b/app_pojavlauncher/src/main/jniLibs/x86_64/liblwjgl_nanovg.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/x86_64/liblwjgl_opengl.so b/app_pojavlauncher/src/main/jniLibs/x86_64/liblwjgl_opengl.so index b863fdf785..a9fcee9a61 100644 Binary files a/app_pojavlauncher/src/main/jniLibs/x86_64/liblwjgl_opengl.so and b/app_pojavlauncher/src/main/jniLibs/x86_64/liblwjgl_opengl.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/x86_64/liblwjgl_stb.so b/app_pojavlauncher/src/main/jniLibs/x86_64/liblwjgl_stb.so index ae0d6450a1..29bfb738cd 100644 Binary files a/app_pojavlauncher/src/main/jniLibs/x86_64/liblwjgl_stb.so and b/app_pojavlauncher/src/main/jniLibs/x86_64/liblwjgl_stb.so differ diff --git a/app_pojavlauncher/src/main/jniLibs/x86_64/liblwjgl_tinyfd.so b/app_pojavlauncher/src/main/jniLibs/x86_64/liblwjgl_tinyfd.so index 500ae098f5..ba10317058 100644 Binary files a/app_pojavlauncher/src/main/jniLibs/x86_64/liblwjgl_tinyfd.so and b/app_pojavlauncher/src/main/jniLibs/x86_64/liblwjgl_tinyfd.so differ diff --git a/app_pojavlauncher/src/main/res/drawable/ic_discord.xml b/app_pojavlauncher/src/main/res/drawable/ic_discord.xml new file mode 100644 index 0000000000..ee248111df --- /dev/null +++ b/app_pojavlauncher/src/main/res/drawable/ic_discord.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app_pojavlauncher/src/main/res/layout-land/fragment_launcher.xml b/app_pojavlauncher/src/main/res/layout-land/fragment_launcher.xml index 339cc4f4bc..7881e87478 100644 --- a/app_pojavlauncher/src/main/res/layout-land/fragment_launcher.xml +++ b/app_pojavlauncher/src/main/res/layout-land/fragment_launcher.xml @@ -19,20 +19,49 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> - - + android:layout_height="wrap_content"> + + android:text="@string/mcl_tab_wiki" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toStartOf="@id/social_divider"/> + + + android:text="@string/mcl_option_customcontrol" + app:layout_constraintTop_toBottomOf="@id/news_button"/> + android:text="@string/main_install_jar_file" + app:layout_constraintTop_toBottomOf="@id/custom_control_button"/> - + android:text="@string/main_share_logs" + app:layout_constraintTop_toBottomOf="@id/install_jar_button"/> + diff --git a/app_pojavlauncher/src/main/res/layout/dialog_control_button_setting.xml b/app_pojavlauncher/src/main/res/layout/dialog_control_button_setting.xml index a3185552dd..08508c24a4 100644 --- a/app_pojavlauncher/src/main/res/layout/dialog_control_button_setting.xml +++ b/app_pojavlauncher/src/main/res/layout/dialog_control_button_setting.xml @@ -483,7 +483,7 @@ android:id="@+id/visibility_textview" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="Visibility" + android:text="@string/customctrl_visibility_title" app:layout_constraintTop_toBottomOf="@+id/editButtonOpacity_seekbar" tools:layout_editor_absoluteX="6dp" /> @@ -491,14 +491,14 @@ android:id="@+id/visibility_game_checkbox" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="In game" + android:text="@string/customctrl_visibility_ingame" app:layout_constraintTop_toBottomOf="@+id/visibility_textview" /> diff --git a/app_pojavlauncher/src/main/res/layout/fragment_controller_remapper.xml b/app_pojavlauncher/src/main/res/layout/fragment_controller_remapper.xml new file mode 100644 index 0000000000..bf5a97dbf9 --- /dev/null +++ b/app_pojavlauncher/src/main/res/layout/fragment_controller_remapper.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app_pojavlauncher/src/main/res/layout/fragment_launcher.xml b/app_pojavlauncher/src/main/res/layout/fragment_launcher.xml index c68eecd712..e5c9d03017 100644 --- a/app_pojavlauncher/src/main/res/layout/fragment_launcher.xml +++ b/app_pojavlauncher/src/main/res/layout/fragment_launcher.xml @@ -15,20 +15,48 @@ android:layout_height="0dp" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toTopOf="@id/mc_version_spinner"> - + android:layout_height="wrap_content"> + + + - /> - + \ No newline at end of file diff --git a/app_pojavlauncher/src/main/res/layout/item_controller_mapping.xml b/app_pojavlauncher/src/main/res/layout/item_controller_mapping.xml new file mode 100644 index 0000000000..84cc5f1217 --- /dev/null +++ b/app_pojavlauncher/src/main/res/layout/item_controller_mapping.xml @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app_pojavlauncher/src/main/res/values-ru/strings.xml b/app_pojavlauncher/src/main/res/values-ru/strings.xml index b13c0b6628..a0890a930d 100644 --- a/app_pojavlauncher/src/main/res/values-ru/strings.xml +++ b/app_pojavlauncher/src/main/res/values-ru/strings.xml @@ -329,4 +329,5 @@ Чтение метаданных игры… Загрузка метаданных игры (%s) Загрузка файлов… (%d/%d, %.2f МБ) + https://discord.gg/pojavlauncher-sng-962263126647144449 diff --git a/app_pojavlauncher/src/main/res/values/colors.xml b/app_pojavlauncher/src/main/res/values/colors.xml index ed07e6cbd9..3be412b377 100644 --- a/app_pojavlauncher/src/main/res/values/colors.xml +++ b/app_pojavlauncher/src/main/res/values/colors.xml @@ -5,6 +5,7 @@ #57CC33 #181818 + @color/background_overlay #464646 #242424 #232323 diff --git a/app_pojavlauncher/src/main/res/values/strings.xml b/app_pojavlauncher/src/main/res/values/strings.xml index 9a299ae125..49d86fba84 100644 --- a/app_pojavlauncher/src/main/res/values/strings.xml +++ b/app_pojavlauncher/src/main/res/values/strings.xml @@ -1,5 +1,5 @@ - + SolCraftLauncher (SolDev PojavLancher fork) SolCraftLauncher @@ -13,7 +13,7 @@ Login - "Tap the top center cog icon to open the context menu ⚙\nTap a button to customize: edit, resize, delete, or customize it's keybind." + "Touch the top center cogwheel to open the context menu ⚙\nTap a button to customize: edit, resize, remove, or change its keybind." This account will be removed! @@ -99,6 +99,7 @@ Application/Game exited with code %d, check latestlog.txt for more details. + Application/Game aborted by fatal signal %d, check latestlog.txt for more details. Are you sure want to force close? Zink (Vulkan) renderer is not supported on this device! @@ -178,6 +179,7 @@ Forward lock Absolute finger tracking The current amount of free RAM (%d) is lower than allocated RAM (%d), which may lead to crashes. Change the allocation if the game crashes. + The current amount of free addressable RAM space (%d) is lower than the allocated RAM (%d), which will lead to crashes. Change the allocation if the game crashes. Memory allocation Controls how much memory is given to Minecraft. Corrupted Java Runtime @@ -387,4 +389,39 @@ Output\nOFF Output\nON Log output: + Failed to read the .jar file + Execute .jar feature is not compatible with Java %d + A + B + X + Y + Start + Select + Left Trigger + Right Trigger + Left Shoulder + Right Shoulder + Stick Up + Stick Down + Stick Left + Stick Right + Left Thumbstick (click) + Right Thumbstick (click) + D-Pad Up + D-Pad Down + D-Pad Left + D-Pad Right + Hold + to exit + Current mode + Visibility + In-game + In menus + Expand to change keycodes + Change controller key bindings + Allows you to modify the keyboard keys bound to each controller button + Discord + https://discord.gg/pojavlauncher-724163890803638273 + Unsuitable username + The username must be between 3–16 characters long, and must only contain latin letters, arabic numerals and underscores. diff --git a/app_pojavlauncher/src/main/res/xml/pref_control.xml b/app_pojavlauncher/src/main/res/xml/pref_control.xml index 550439aeaf..f6300e7c32 100644 --- a/app_pojavlauncher/src/main/res/xml/pref_control.xml +++ b/app_pojavlauncher/src/main/res/xml/pref_control.xml @@ -132,6 +132,10 @@ + + diff --git a/jre_lwjgl3glfw/libs/lwjgl-freetype.jar b/jre_lwjgl3glfw/libs/lwjgl-freetype.jar new file mode 100644 index 0000000000..2b65c416b1 Binary files /dev/null and b/jre_lwjgl3glfw/libs/lwjgl-freetype.jar differ diff --git a/jre_lwjgl3glfw/libs/lwjgl-glfw.jar b/jre_lwjgl3glfw/libs/lwjgl-glfw.jar index 61fdc6f0e9..0cf35520bd 100644 Binary files a/jre_lwjgl3glfw/libs/lwjgl-glfw.jar and b/jre_lwjgl3glfw/libs/lwjgl-glfw.jar differ diff --git a/jre_lwjgl3glfw/libs/lwjgl-lwjglx.jar b/jre_lwjgl3glfw/libs/lwjgl-lwjglx.jar index ddadb354d4..648316323a 100644 Binary files a/jre_lwjgl3glfw/libs/lwjgl-lwjglx.jar and b/jre_lwjgl3glfw/libs/lwjgl-lwjglx.jar differ diff --git a/jre_lwjgl3glfw/libs/lwjgl-nanovg.jar b/jre_lwjgl3glfw/libs/lwjgl-nanovg.jar index c4759d5e96..1b30eef26d 100644 Binary files a/jre_lwjgl3glfw/libs/lwjgl-nanovg.jar and b/jre_lwjgl3glfw/libs/lwjgl-nanovg.jar differ diff --git a/jre_lwjgl3glfw/libs/lwjgl-openal.jar b/jre_lwjgl3glfw/libs/lwjgl-openal.jar index 665791d896..0757751aa6 100644 Binary files a/jre_lwjgl3glfw/libs/lwjgl-openal.jar and b/jre_lwjgl3glfw/libs/lwjgl-openal.jar differ diff --git a/jre_lwjgl3glfw/libs/lwjgl-opengl.jar b/jre_lwjgl3glfw/libs/lwjgl-opengl.jar index 31723fc55f..df83c5aa93 100644 Binary files a/jre_lwjgl3glfw/libs/lwjgl-opengl.jar and b/jre_lwjgl3glfw/libs/lwjgl-opengl.jar differ diff --git a/jre_lwjgl3glfw/libs/lwjgl-stb.jar b/jre_lwjgl3glfw/libs/lwjgl-stb.jar index 1cc4976ae5..f9bc3d2314 100644 Binary files a/jre_lwjgl3glfw/libs/lwjgl-stb.jar and b/jre_lwjgl3glfw/libs/lwjgl-stb.jar differ diff --git a/jre_lwjgl3glfw/libs/lwjgl-tinyfd.jar b/jre_lwjgl3glfw/libs/lwjgl-tinyfd.jar index 64ab8c3cdb..31a3ba0eff 100644 Binary files a/jre_lwjgl3glfw/libs/lwjgl-tinyfd.jar and b/jre_lwjgl3glfw/libs/lwjgl-tinyfd.jar differ diff --git a/jre_lwjgl3glfw/libs/lwjgl.jar b/jre_lwjgl3glfw/libs/lwjgl.jar index ec814a1496..fa972c65a0 100644 Binary files a/jre_lwjgl3glfw/libs/lwjgl.jar and b/jre_lwjgl3glfw/libs/lwjgl.jar differ diff --git a/jre_lwjgl3glfw/src/main/java/org/lwjgl/glfw/GLFW.java b/jre_lwjgl3glfw/src/main/java/org/lwjgl/glfw/GLFW.java index 467593b427..dde2f39baf 100644 --- a/jre_lwjgl3glfw/src/main/java/org/lwjgl/glfw/GLFW.java +++ b/jre_lwjgl3glfw/src/main/java/org/lwjgl/glfw/GLFW.java @@ -6,7 +6,6 @@ import android.util.*; -import java.lang.annotation.Native; import java.lang.reflect.*; import java.nio.*; @@ -23,8 +22,6 @@ import static org.lwjgl.system.MemoryUtil.*; import java.util.*; -import sun.misc.Unsafe; - public class GLFW { static FloatBuffer joystickData = (FloatBuffer)FloatBuffer.allocate(8).flip(); @@ -507,6 +504,7 @@ public class GLFW private static ArrayMap mGLFWWindowMap; public static boolean mGLFWIsInputReady; + private static boolean mGLFWInputPumping; public static final ByteBuffer keyDownBuffer = ByteBuffer.allocateDirect(317); public static final ByteBuffer mouseDownBuffer = ByteBuffer.allocateDirect(8); @@ -627,8 +625,8 @@ private Functions() {} SwapBuffers = apiGetFunctionAddress(GLFW, "pojavSwapBuffers"), SwapInterval = apiGetFunctionAddress(GLFW, "pojavSwapInterval"), PumpEvents = apiGetFunctionAddress(GLFW, "pojavPumpEvents"), - RewindEvents = apiGetFunctionAddress(GLFW, "pojavRewindEvents"), - SetupEvents = apiGetFunctionAddress(GLFW, "pojavComputeEventTarget"); + StopPumping = apiGetFunctionAddress(GLFW, "pojavStopPumping"), + StartPumping = apiGetFunctionAddress(GLFW, "pojavStartPumping"); } public static SharedLibrary getLibrary() { @@ -1080,9 +1078,15 @@ public static void glfwPollEvents() { mGLFWIsInputReady = true; CallbackBridge.nativeSetInputReady(true); } - callV(Functions.SetupEvents); + // During interactions with UI elements, Minecraft likes to update the screen as events related to those inputs arrive. + // This leads to calls to glfwPollEvents within glfwPollEvents, which is not good for our queue system. + // Prevent these with this code. + if(mGLFWInputPumping) return; + mGLFWInputPumping = true; + callV(Functions.StartPumping); for (Long ptr : mGLFWWindowMap.keySet()) callJV(ptr, Functions.PumpEvents); - callV(Functions.RewindEvents); + callV(Functions.StopPumping); + mGLFWInputPumping = false; } public static void internalWindowSizeChanged(long window, int w, int h) {