├── .clang-format ├── .github └── workflows │ ├── ci.yml │ └── pr.yml ├── .gitignore ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── data ├── fonts │ └── font.ttf ├── images │ ├── iconEmpty.png │ ├── layoutSwitchButton.png │ ├── leftArrow.png │ ├── noGameIcon.png │ ├── rightArrow.png │ └── settingsButton.png └── sounds │ ├── bgMusic.ogg │ ├── button_click.mp3 │ └── settings_click_2.mp3 ├── filelist.sh └── src ├── Application.cpp ├── Application.h ├── common └── common.h ├── entry.cpp ├── fs ├── CFile.cpp ├── CFile.hpp ├── DirList.cpp ├── DirList.h ├── FSUtils.cpp └── FSUtils.h ├── game ├── GameList.cpp └── GameList.h ├── gui ├── GameIcon.cpp ├── GameIcon.h ├── GameIconModel.h ├── GuiIconGrid.cpp ├── GuiIconGrid.h └── GuiTitleBrowser.h ├── menu ├── GameSplashScreen.cpp ├── GameSplashScreen.h ├── KeyboardHelper.cpp ├── KeyboardHelper.h ├── MainDrcButtonsFrame.h ├── MainWindow.cpp └── MainWindow.h ├── resources ├── Resources.cpp └── Resources.h ├── system └── CThread.h └── utils ├── AsyncExecutor.cpp ├── AsyncExecutor.h ├── StringTools.cpp ├── StringTools.h ├── logger.h ├── utils.c └── utils.h /.clang-format: -------------------------------------------------------------------------------- 1 | # Generated from CLion C/C++ Code Style settings 2 | BasedOnStyle: LLVM 3 | AccessModifierOffset: -4 4 | AlignAfterOpenBracket: Align 5 | AlignConsecutiveAssignments: Consecutive 6 | AlignConsecutiveMacros: AcrossEmptyLinesAndComments 7 | AlignOperands: Align 8 | AllowAllArgumentsOnNextLine: false 9 | AllowAllConstructorInitializersOnNextLine: false 10 | AllowAllParametersOfDeclarationOnNextLine: false 11 | AllowShortBlocksOnASingleLine: Always 12 | AllowShortCaseLabelsOnASingleLine: false 13 | AllowShortFunctionsOnASingleLine: All 14 | AllowShortIfStatementsOnASingleLine: Always 15 | AllowShortLambdasOnASingleLine: All 16 | AllowShortLoopsOnASingleLine: true 17 | AlwaysBreakAfterReturnType: None 18 | AlwaysBreakTemplateDeclarations: Yes 19 | BreakBeforeBraces: Custom 20 | BraceWrapping: 21 | AfterCaseLabel: false 22 | AfterClass: false 23 | AfterControlStatement: Never 24 | AfterEnum: false 25 | AfterFunction: false 26 | AfterNamespace: false 27 | AfterUnion: false 28 | BeforeCatch: false 29 | BeforeElse: false 30 | IndentBraces: false 31 | SplitEmptyFunction: false 32 | SplitEmptyRecord: true 33 | BreakBeforeBinaryOperators: None 34 | BreakBeforeTernaryOperators: true 35 | BreakConstructorInitializers: BeforeColon 36 | BreakInheritanceList: BeforeColon 37 | ColumnLimit: 0 38 | CompactNamespaces: false 39 | ContinuationIndentWidth: 8 40 | IndentCaseLabels: true 41 | IndentPPDirectives: None 42 | IndentWidth: 4 43 | KeepEmptyLinesAtTheStartOfBlocks: true 44 | MaxEmptyLinesToKeep: 2 45 | NamespaceIndentation: All 46 | ObjCSpaceAfterProperty: false 47 | ObjCSpaceBeforeProtocolList: true 48 | PointerAlignment: Right 49 | ReflowComments: false 50 | SpaceAfterCStyleCast: true 51 | SpaceAfterLogicalNot: false 52 | SpaceAfterTemplateKeyword: false 53 | SpaceBeforeAssignmentOperators: true 54 | SpaceBeforeCpp11BracedList: false 55 | SpaceBeforeCtorInitializerColon: true 56 | SpaceBeforeInheritanceColon: true 57 | SpaceBeforeParens: ControlStatements 58 | SpaceBeforeRangeBasedForLoopColon: true 59 | SpaceInEmptyParentheses: false 60 | SpacesBeforeTrailingComments: 1 61 | SpacesInAngles: false 62 | SpacesInCStyleCastParentheses: false 63 | SpacesInContainerLiterals: false 64 | SpacesInParentheses: false 65 | SpacesInSquareBrackets: false 66 | TabWidth: 4 67 | UseTab: Never 68 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI-Release 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | clang-format: 10 | runs-on: ubuntu-18.04 11 | steps: 12 | - uses: actions/checkout@v2 13 | - name: clang-format 14 | run: | 15 | docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src 16 | build-binary: 17 | runs-on: ubuntu-18.04 18 | needs: clang-format 19 | steps: 20 | - uses: actions/checkout@v2 21 | - name: build binary 22 | run: | 23 | docker build . -t builder 24 | docker run --rm -v ${PWD}:/project builder make 25 | - uses: actions/upload-artifact@master 26 | with: 27 | name: binary 28 | path: "*.rpx" 29 | deploy-binary: 30 | needs: build-binary 31 | runs-on: ubuntu-18.04 32 | steps: 33 | - name: Get environment variables 34 | id: get_repository_name 35 | run: | 36 | echo REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}' | sed -e "s/:refs//") >> $GITHUB_ENV 37 | echo DATETIME=$(echo $(date '+%Y%m%d-%H%M%S')) >> $GITHUB_ENV 38 | - uses: actions/download-artifact@master 39 | with: 40 | name: binary 41 | path: wiiu 42 | - name: zip artifact 43 | run: zip -r ${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip wiiu 44 | - name: Create Release 45 | id: create_release 46 | uses: actions/create-release@v1 47 | env: 48 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 49 | with: 50 | tag_name: ${{ env.REPOSITORY_NAME }}-${{ env.DATETIME }} 51 | release_name: Nightly-${{ env.REPOSITORY_NAME }}-${{ env.DATETIME }} 52 | draft: false 53 | prerelease: true 54 | body: | 55 | Not a stable release: 56 | ${{ github.event.head_commit.message }} 57 | - name: Upload Release Asset 58 | id: upload-release-asset 59 | uses: actions/upload-release-asset@v1 60 | env: 61 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 62 | with: 63 | upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps 64 | asset_path: ./${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip 65 | asset_name: ${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip 66 | asset_content_type: application/zip -------------------------------------------------------------------------------- /.github/workflows/pr.yml: -------------------------------------------------------------------------------- 1 | name: CI-PR 2 | 3 | on: [pull_request] 4 | 5 | jobs: 6 | clang-format: 7 | runs-on: ubuntu-18.04 8 | steps: 9 | - uses: actions/checkout@v2 10 | - name: clang-format 11 | run: | 12 | docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src 13 | build-binary: 14 | runs-on: ubuntu-18.04 15 | needs: clang-format 16 | steps: 17 | - uses: actions/checkout@v2 18 | - name: build binary 19 | run: | 20 | docker build . -t builder 21 | docker run --rm -v ${PWD}:/project builder make 22 | - uses: actions/upload-artifact@master 23 | with: 24 | name: binary 25 | path: "*.rpx" -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.cbp 2 | *.elf 3 | *.rpx 4 | build/ 5 | src/resources/filelist.h 6 | *.save-failed 7 | launchiine.layout 8 | cmake-build-debug/ 9 | .idea/ 10 | CMakeLists.txt 11 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM wiiuenv/devkitppc:20211229 2 | 3 | COPY --from=wiiuenv/libgui:20220109 /artifacts $DEVKITPRO 4 | 5 | WORKDIR project -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------- 2 | .SUFFIXES: 3 | #------------------------------------------------------------------------------- 4 | 5 | ifeq ($(strip $(DEVKITPRO)),) 6 | $(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") 7 | endif 8 | 9 | TOPDIR ?= $(CURDIR) 10 | 11 | include $(DEVKITPRO)/wut/share/wut_rules 12 | 13 | #------------------------------------------------------------------------------- 14 | # TARGET is the name of the output 15 | # BUILD is the directory where object files & intermediate files will be placed 16 | # SOURCES is a list of directories containing source code 17 | # DATA is a list of directories containing data files 18 | # INCLUDES is a list of directories containing header files 19 | #------------------------------------------------------------------------------- 20 | TARGET := men 21 | BUILD := build 22 | SOURCES := src \ 23 | src/fs \ 24 | src/game \ 25 | src/gui \ 26 | src/menu \ 27 | src/resources \ 28 | src/system \ 29 | src/utils 30 | DATA := data \ 31 | data/images \ 32 | data/sounds \ 33 | data/fonts 34 | INCLUDES := src 35 | 36 | #------------------------------------------------------------------------------- 37 | # options for code generation 38 | #------------------------------------------------------------------------------- 39 | CFLAGS := -g -Wall -O2 -ffunction-sections \ 40 | $(MACHDEP) 41 | 42 | CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ 43 | 44 | CXXFLAGS := $(CFLAGS) 45 | 46 | ASFLAGS := -g $(ARCH) 47 | LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) 48 | 49 | LIBS := -lgui -lfreetype -lgd -lpng -ljpeg -lz -lmad -lvorbisidec -logg -lbz2 -lwut 50 | 51 | #------------------------------------------------------------------------------- 52 | # list of directories containing libraries, this must be the top level 53 | # containing include and lib 54 | #------------------------------------------------------------------------------- 55 | LIBDIRS := $(PORTLIBS) $(WUT_ROOT) $(WUT_ROOT)/usr 56 | 57 | #------------------------------------------------------------------------------- 58 | # no real need to edit anything past this point unless you need to add additional 59 | # rules for different file extensions 60 | #------------------------------------------------------------------------------- 61 | ifneq ($(BUILD),$(notdir $(CURDIR))) 62 | #------------------------------------------------------------------------------- 63 | FILELIST := $(shell bash ./filelist.sh) 64 | export OUTPUT := $(CURDIR)/$(TARGET) 65 | export TOPDIR := $(CURDIR) 66 | 67 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 68 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 69 | 70 | export DEPSDIR := $(CURDIR)/$(BUILD) 71 | 72 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 73 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 74 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 75 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 76 | 77 | #------------------------------------------------------------------------------- 78 | # use CXX for linking C++ projects, CC for standard C 79 | #------------------------------------------------------------------------------- 80 | ifeq ($(strip $(CPPFILES)),) 81 | #------------------------------------------------------------------------------- 82 | export LD := $(CC) 83 | #------------------------------------------------------------------------------- 84 | else 85 | #------------------------------------------------------------------------------- 86 | export LD := $(CXX) 87 | #------------------------------------------------------------------------------- 88 | endif 89 | #------------------------------------------------------------------------------- 90 | 91 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) 92 | export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 93 | export OFILES := $(OFILES_BIN) $(OFILES_SRC) 94 | export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES))) 95 | 96 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 97 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 98 | -I$(CURDIR)/$(BUILD) -I$(PORTLIBS_PATH)/ppc/include/freetype2 99 | 100 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 101 | 102 | .PHONY: $(BUILD) clean all 103 | 104 | #------------------------------------------------------------------------------- 105 | all: $(BUILD) 106 | 107 | $(BUILD): 108 | @[ -d $@ ] || mkdir -p $@ 109 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 110 | 111 | #------------------------------------------------------------------------------- 112 | clean: 113 | @echo clean ... 114 | @rm -fr $(BUILD) $(TARGET).rpx $(TARGET).elf 115 | 116 | #------------------------------------------------------------------------------- 117 | else 118 | .PHONY: all 119 | 120 | DEPENDS := $(OFILES:.o=.d) 121 | 122 | #------------------------------------------------------------------------------- 123 | # main targets 124 | #------------------------------------------------------------------------------- 125 | all : $(OUTPUT).rpx 126 | 127 | $(OUTPUT).rpx : $(OUTPUT).elf 128 | $(OUTPUT).elf : $(OFILES) 129 | 130 | $(OFILES_SRC) : $(HFILES_BIN) 131 | 132 | #------------------------------------------------------------------------------- 133 | # you need a rule like this for each extension you use as binary data 134 | #------------------------------------------------------------------------------- 135 | %.bin.o %_bin.h : %.bin 136 | @echo $(notdir $<) 137 | @$(bin2o) 138 | 139 | %.png.o %_png.h : %.png 140 | @echo $(notdir $<) 141 | @$(bin2o) 142 | 143 | %.jpg.o %_jpg.h : %.jpg 144 | @echo $(notdir $<) 145 | @$(bin2o) 146 | 147 | %.ogg.o %_ogg.h : %.ogg 148 | @echo $(notdir $<) 149 | @$(bin2o) 150 | 151 | %.mp3.o %_mp3.h : %.mp3 152 | @echo $(notdir $<) 153 | @$(bin2o) 154 | 155 | %.ttf.o %_ttf.h : %.ttf 156 | @echo $(notdir $<) 157 | @$(bin2o) 158 | 159 | 160 | -include $(DEPENDS) 161 | 162 | #------------------------------------------------------------------------------- 163 | endif 164 | #------------------------------------------------------------------------------- 165 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Launchiine (WIP) 2 | 3 | A simple Wii U Menu replacement, still in early development and not ready for a day to day usage 4 | 5 | ## Usage (Replace Wii U Menu via Mocha Payload): 6 | ([ENVIRONMENT] is a placeholder for the actual environment name.) 7 | - Place the `men.rpx` on the sd card in the directory `sd:/wiiu/environments/[ENVIRONMENT]/`. 8 | - Load the [MochaPayload](https://github.com/wiiu-env/MochaPayload) via the [EnvironmentLoader](https://github.com/wiiu-env/EnvironmentLoader) (e.g. [Tiramisu](https://github.com/wiiu-env/Tiramisu)) 9 | - Load the Wii U Menu and launchiine should show up instead. 10 | 11 | ## Known Issues 12 | - Random crashes 13 | - The Keyboard input is implemented, but result is ignored. 14 | - nn::spm is not initalized and no quick start menu support. For the it's relying on the [AutobootModule](https://github.com/wiiu-env/AutobootModule) doing this. 15 | - No sound on splash screen. 16 | - Probably a lot more 17 | 18 | ## TODOs 19 | - Non-touch controls 20 | - Sound on splashscreen 21 | - Folder support 22 | - Preserve app order after closing/opening launchiine. 23 | - Display applets like the original Wii U Menu 24 | - Implement Account selection when no default account is set. 25 | - Implement update check/no way to update games 26 | - Properly implement nn::spm and nn:sl (external storage and quick start menu) 27 | - Fix search 28 | - Implement all the other stuff the Wii U Menu offers (Account creationg, switching between Accounts, set default account etc.) 29 | - Implement ways to launch the original Wii U Menu. 30 | 31 | ## Building 32 | Install the following dependencies: 33 | - [wut](https://github.com/devkitPro/wut) 34 | - [libgui](https://github.com/wiiu-env/libgui) 35 | 36 | Then build via `make`. 37 | 38 | ## Building using the Dockerfile 39 | 40 | It's possible to use a docker image for building. This way you don't need anything installed on your host system. 41 | 42 | ``` 43 | # Build docker image (only needed once) 44 | docker build . -t launchiine-builder 45 | 46 | # make 47 | docker run -it --rm -v ${PWD}:/project launchiine-builder make 48 | 49 | # make clean 50 | docker run -it --rm -v ${PWD}:/project launchiine-builder make clean 51 | ``` 52 | -------------------------------------------------------------------------------- /data/fonts/font.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiiu-env/launchiine/bd31cbe4f4487851e6a2aa79ad30fba5b73107d3/data/fonts/font.ttf -------------------------------------------------------------------------------- /data/images/iconEmpty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiiu-env/launchiine/bd31cbe4f4487851e6a2aa79ad30fba5b73107d3/data/images/iconEmpty.png -------------------------------------------------------------------------------- /data/images/layoutSwitchButton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiiu-env/launchiine/bd31cbe4f4487851e6a2aa79ad30fba5b73107d3/data/images/layoutSwitchButton.png -------------------------------------------------------------------------------- /data/images/leftArrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiiu-env/launchiine/bd31cbe4f4487851e6a2aa79ad30fba5b73107d3/data/images/leftArrow.png -------------------------------------------------------------------------------- /data/images/noGameIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiiu-env/launchiine/bd31cbe4f4487851e6a2aa79ad30fba5b73107d3/data/images/noGameIcon.png -------------------------------------------------------------------------------- /data/images/rightArrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiiu-env/launchiine/bd31cbe4f4487851e6a2aa79ad30fba5b73107d3/data/images/rightArrow.png -------------------------------------------------------------------------------- /data/images/settingsButton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiiu-env/launchiine/bd31cbe4f4487851e6a2aa79ad30fba5b73107d3/data/images/settingsButton.png -------------------------------------------------------------------------------- /data/sounds/bgMusic.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiiu-env/launchiine/bd31cbe4f4487851e6a2aa79ad30fba5b73107d3/data/sounds/bgMusic.ogg -------------------------------------------------------------------------------- /data/sounds/button_click.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiiu-env/launchiine/bd31cbe4f4487851e6a2aa79ad30fba5b73107d3/data/sounds/button_click.mp3 -------------------------------------------------------------------------------- /data/sounds/settings_click_2.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiiu-env/launchiine/bd31cbe4f4487851e6a2aa79ad30fba5b73107d3/data/sounds/settings_click_2.mp3 -------------------------------------------------------------------------------- /filelist.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # 3 | # Automatic resource file list generation 4 | # Created by Dimok 5 | 6 | outFile="./src/resources/filelist.h" 7 | count_old=$(cat $outFile 2>/dev/null | tr -d '\n\n' | sed 's/[^0-9]*\([0-9]*\).*/\1/') 8 | 9 | count=0 10 | if [[ $OSTYPE == darwin* ]]; 11 | then 12 | 13 | for i in $(gfind ./data/images/ ./data/sounds/ ./data/fonts/ -maxdepth 1 -type f \( ! -printf "%f\n" \) | sort -f) 14 | do 15 | files[count]=$i 16 | count=$((count+1)) 17 | done 18 | 19 | else 20 | 21 | for i in $(find ./data/images/ ./data/sounds/ ./data/fonts/ -maxdepth 1 -type f \( ! -printf "%f\n" \) | sort -f) 22 | do 23 | files[count]=$i 24 | count=$((count+1)) 25 | done 26 | 27 | fi 28 | 29 | if [ "$count_old" != "$count" ] || [ ! -f $outFile ] 30 | then 31 | 32 | echo "Generating filelist.h for $count files." >&2 33 | cat < $outFile 34 | /**************************************************************************** 35 | * Resource files. 36 | * This file is generated automatically. 37 | * Includes $count files. 38 | * 39 | * NOTE: 40 | * Any manual modification of this file will be overwriten by the generation. 41 | ****************************************************************************/ 42 | #ifndef _FILELIST_H_ 43 | #define _FILELIST_H_ 44 | 45 | typedef struct _RecourceFile 46 | { 47 | const char *filename; 48 | const unsigned char *DefaultFile; 49 | const unsigned int &DefaultFileSize; 50 | unsigned char *CustomFile; 51 | unsigned int CustomFileSize; 52 | } RecourceFile; 53 | 54 | EOF 55 | 56 | for i in ${files[@]} 57 | do 58 | filename=${i%.*} 59 | extension=${i##*.} 60 | echo '#include "'$filename'_'$extension'.h"' >> $outFile 61 | done 62 | 63 | echo '' >> $outFile 64 | echo 'static RecourceFile RecourceList[] =' >> $outFile 65 | echo '{' >> $outFile 66 | 67 | for i in ${files[@]} 68 | do 69 | filename=${i%.*} 70 | extension=${i##*.} 71 | echo -e '\t{"'$i'", '$filename'_'$extension', '$filename'_'$extension'_size, NULL, 0},' >> $outFile 72 | done 73 | 74 | echo -e '\t{NULL, NULL, 0, NULL, 0}' >> $outFile 75 | echo '};' >> $outFile 76 | 77 | echo '' >> $outFile 78 | echo '#endif' >> $outFile 79 | 80 | fi 81 | -------------------------------------------------------------------------------- /src/Application.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 Dimok 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | ****************************************************************************/ 17 | #include "Application.h" 18 | #include "common/common.h" 19 | #include "resources/Resources.h" 20 | #include "utils/AsyncExecutor.h" 21 | #include "utils/logger.h" 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | Application *Application::applicationInstance = nullptr; 35 | bool Application::exitApplication = false; 36 | bool Application::quitRequest = false; 37 | 38 | Application::Application() 39 | : CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 0, 0x800000), bgMusic(nullptr), video(nullptr), mainWindow(nullptr), fontSystem(nullptr), exitCode(0) { 40 | controller[0] = new VPadController(GuiTrigger::CHANNEL_1); 41 | controller[1] = new WPadController(GuiTrigger::CHANNEL_2); 42 | controller[2] = new WPadController(GuiTrigger::CHANNEL_3); 43 | controller[3] = new WPadController(GuiTrigger::CHANNEL_4); 44 | controller[4] = new WPadController(GuiTrigger::CHANNEL_5); 45 | 46 | //! create bgMusic 47 | bgMusic = new GuiSound(Resources::GetFile("bgMusic.ogg"), Resources::GetFileSize("bgMusic.ogg")); 48 | bgMusic->SetLoop(true); 49 | bgMusic->Play(); 50 | bgMusic->SetVolume(50); 51 | 52 | AsyncExecutor::execute([] { DEBUG_FUNCTION_LINE("Hello"); }); 53 | 54 | exitApplication = false; 55 | 56 | ProcUIInit(OSSavesDone_ReadyToRelease); 57 | } 58 | 59 | Application::~Application() { 60 | DEBUG_FUNCTION_LINE("Destroy music"); 61 | delete bgMusic; 62 | 63 | DEBUG_FUNCTION_LINE("Destroy controller"); 64 | 65 | for (auto &i : controller) { 66 | delete i; 67 | } 68 | 69 | DEBUG_FUNCTION_LINE("Clear resources"); 70 | Resources::Clear(); 71 | 72 | DEBUG_FUNCTION_LINE("Stop sound handler"); 73 | SoundHandler::DestroyInstance(); 74 | 75 | DEBUG_FUNCTION_LINE("Clear AsyncExecutor"); 76 | AsyncExecutor::destroyInstance(); 77 | 78 | ProcUIShutdown(); 79 | } 80 | 81 | int32_t Application::exec() { 82 | //! start main GX2 thread 83 | resumeThread(); 84 | //! now wait for thread to finish 85 | shutdownThread(); 86 | 87 | return exitCode; 88 | } 89 | 90 | void Application::quit(int32_t code) { 91 | exitCode = code; 92 | exitApplication = true; 93 | quitRequest = true; 94 | } 95 | 96 | void Application::fadeOut() { 97 | GuiImage fadeOut(video->getTvWidth(), video->getTvHeight(), (GX2Color){0, 0, 0, 255}); 98 | 99 | for (int32_t i = 0; i < 255; i += 10) { 100 | if (i > 255) 101 | i = 255; 102 | 103 | fadeOut.setAlpha(i / 255.0f); 104 | 105 | //! start rendering DRC 106 | video->prepareDrcRendering(); 107 | mainWindow->drawDrc(video); 108 | 109 | GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_FUNC_ALWAYS); 110 | fadeOut.draw(video); 111 | GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL); 112 | 113 | video->drcDrawDone(); 114 | 115 | //! start rendering TV 116 | video->prepareTvRendering(); 117 | 118 | mainWindow->drawTv(video); 119 | 120 | GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_FUNC_ALWAYS); 121 | fadeOut.draw(video); 122 | GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL); 123 | 124 | video->tvDrawDone(); 125 | 126 | //! as last point update the effects as it can drop elements 127 | mainWindow->updateEffects(); 128 | 129 | video->waitForVSync(); 130 | } 131 | } 132 | 133 | bool Application::procUI() { 134 | bool executeProcess = false; 135 | 136 | switch (ProcUIProcessMessages(true)) { 137 | case PROCUI_STATUS_EXITING: { 138 | DEBUG_FUNCTION_LINE("PROCUI_STATUS_EXITING"); 139 | exitCode = EXIT_SUCCESS; 140 | exitApplication = true; 141 | break; 142 | } 143 | case PROCUI_STATUS_RELEASE_FOREGROUND: { 144 | DEBUG_FUNCTION_LINE("PROCUI_STATUS_RELEASE_FOREGROUND"); 145 | if (video != nullptr) { 146 | // we can turn ofF the screen but we don't need to and it will display the last image 147 | video->tvEnable(true); 148 | video->drcEnable(true); 149 | 150 | DEBUG_FUNCTION_LINE("delete fontSystem"); 151 | delete fontSystem; 152 | fontSystem = nullptr; 153 | 154 | DEBUG_FUNCTION_LINE("delete video"); 155 | delete video; 156 | video = nullptr; 157 | 158 | DEBUG_FUNCTION_LINE("deinitialze memory"); 159 | libgui_memoryRelease(); 160 | ProcUIDrawDoneRelease(); 161 | } else { 162 | ProcUIDrawDoneRelease(); 163 | } 164 | break; 165 | } 166 | case PROCUI_STATUS_IN_FOREGROUND: { 167 | if (!quitRequest) { 168 | if (video == nullptr) { 169 | DEBUG_FUNCTION_LINE("PROCUI_STATUS_IN_FOREGROUND"); 170 | DEBUG_FUNCTION_LINE("initialze memory"); 171 | libgui_memoryInitialize(); 172 | 173 | DEBUG_FUNCTION_LINE("Initialize video"); 174 | video = new CVideo(GX2_TV_SCAN_MODE_720P, GX2_DRC_RENDER_MODE_SINGLE); 175 | DEBUG_FUNCTION_LINE("Video size %i x %i", video->getTvWidth(), video->getTvHeight()); 176 | 177 | //! setup default Font 178 | DEBUG_FUNCTION_LINE("Initialize main font system"); 179 | auto *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true); 180 | GuiText::setPresetFont(fontSystem); 181 | 182 | if (mainWindow == nullptr) { 183 | DEBUG_FUNCTION_LINE("Initialize main window"); 184 | mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight()); 185 | } 186 | } 187 | executeProcess = true; 188 | } 189 | break; 190 | } 191 | case PROCUI_STATUS_IN_BACKGROUND: 192 | default: 193 | break; 194 | } 195 | 196 | return executeProcess; 197 | } 198 | 199 | void Application::executeThread() { 200 | DEBUG_FUNCTION_LINE("Entering main loop"); 201 | 202 | //! main GX2 loop (60 Hz cycle with max priority on core 1) 203 | while (!exitApplication) { 204 | if (!procUI()) { 205 | continue; 206 | } 207 | 208 | mainWindow->lockGUI(); 209 | mainWindow->process(); 210 | 211 | //! Read out inputs 212 | for (auto &i : controller) { 213 | if (!i->update(video->getTvWidth(), video->getTvHeight())) 214 | continue; 215 | 216 | //! update controller states 217 | mainWindow->update(i); 218 | } 219 | 220 | //! start rendering DRC 221 | video->prepareDrcRendering(); 222 | mainWindow->drawDrc(video); 223 | video->drcDrawDone(); 224 | 225 | //! start rendering TV 226 | video->prepareTvRendering(); 227 | mainWindow->drawTv(video); 228 | video->tvDrawDone(); 229 | 230 | //! enable screen after first frame render 231 | if (video->getFrameCount() == 0) { 232 | video->tvEnable(true); 233 | video->drcEnable(true); 234 | } 235 | 236 | //! as last point update the effects as it can drop elements 237 | mainWindow->updateEffects(); 238 | mainWindow->unlockGUI(); 239 | 240 | video->waitForVSync(); 241 | } 242 | 243 | if (bgMusic) { 244 | bgMusic->SetVolume(0); 245 | } 246 | 247 | DEBUG_FUNCTION_LINE("delete mainWindow"); 248 | delete mainWindow; 249 | mainWindow = nullptr; 250 | 251 | DEBUG_FUNCTION_LINE("delete fontSystem"); 252 | delete fontSystem; 253 | fontSystem = nullptr; 254 | 255 | DEBUG_FUNCTION_LINE("delete video"); 256 | delete video; 257 | video = nullptr; 258 | 259 | DEBUG_FUNCTION_LINE("deinitialize memory"); 260 | libgui_memoryRelease(); 261 | } 262 | -------------------------------------------------------------------------------- /src/Application.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 Dimok 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | ****************************************************************************/ 17 | #ifndef _APPLICATION_H 18 | #define _APPLICATION_H 19 | 20 | #include "menu/MainWindow.h" 21 | #include "system/CThread.h" 22 | #include 23 | 24 | // forward declaration 25 | class FreeTypeGX; 26 | 27 | class Application : public CThread { 28 | public: 29 | static Application *instance() { 30 | if (!applicationInstance) 31 | applicationInstance = new Application(); 32 | return applicationInstance; 33 | } 34 | 35 | static void destroyInstance() { 36 | if (applicationInstance) { 37 | delete applicationInstance; 38 | applicationInstance = nullptr; 39 | } 40 | } 41 | 42 | CVideo *getVideo(void) const { 43 | return video; 44 | } 45 | 46 | MainWindow *getMainWindow(void) const { 47 | return mainWindow; 48 | } 49 | 50 | GuiSound *getBgMusic(void) const { 51 | return bgMusic; 52 | } 53 | 54 | int exec(void); 55 | 56 | void fadeOut(void); 57 | 58 | void quit(int code); 59 | 60 | private: 61 | Application(); 62 | 63 | virtual ~Application(); 64 | 65 | bool procUI(void); 66 | 67 | static Application *applicationInstance; 68 | static bool exitApplication; 69 | static bool quitRequest; 70 | 71 | void executeThread(void); 72 | 73 | GuiSound *bgMusic; 74 | CVideo *video; 75 | MainWindow *mainWindow; 76 | FreeTypeGX *fontSystem; 77 | GuiController *controller[5]{}; 78 | int exitCode; 79 | BOOL sFromHBL = FALSE; 80 | }; 81 | 82 | #endif //_APPLICATION_H 83 | -------------------------------------------------------------------------------- /src/common/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H 2 | #define COMMON_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define LAUNCHIINE_VERSION "v0.1" 9 | #define META_PATH "/meta" 10 | 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | 15 | #endif /* COMMON_H */ 16 | -------------------------------------------------------------------------------- /src/entry.cpp: -------------------------------------------------------------------------------- 1 | #include "Application.h" 2 | #include "common/common.h" 3 | #include "utils/logger.h" 4 | #include 5 | #include 6 | #include 7 | 8 | int32_t main(int32_t argc, char **argv) { 9 | bool moduleInit; 10 | bool cafeInit = false; 11 | bool udpInit = false; 12 | 13 | if (!(moduleInit = WHBLogModuleInit())) { 14 | cafeInit = WHBLogCafeInit(); 15 | udpInit = WHBLogUdpInit(); 16 | } 17 | DEBUG_FUNCTION_LINE("Starting launchiine " LAUNCHIINE_VERSION ""); 18 | 19 | DEBUG_FUNCTION_LINE("Start main application"); 20 | Application::instance()->exec(); 21 | 22 | DEBUG_FUNCTION_LINE("Main application stopped"); 23 | Application::destroyInstance(); 24 | 25 | DEBUG_FUNCTION_LINE("Peace out..."); 26 | 27 | if (cafeInit) { 28 | WHBLogCafeDeinit(); 29 | } 30 | 31 | if (udpInit) { 32 | WHBLogUdpDeinit(); 33 | } 34 | 35 | if (moduleInit) { 36 | WHBLogModuleDeinit(); 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /src/fs/CFile.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | CFile::CFile() { 9 | iFd = -1; 10 | mem_file = nullptr; 11 | filesize = 0; 12 | pos = 0; 13 | } 14 | 15 | CFile::CFile(const std::string &filepath, eOpenTypes mode) { 16 | iFd = -1; 17 | this->open(filepath, mode); 18 | } 19 | 20 | CFile::CFile(const uint8_t *mem, int32_t size) { 21 | iFd = -1; 22 | this->open(mem, size); 23 | } 24 | 25 | CFile::~CFile() { 26 | this->close(); 27 | } 28 | 29 | int32_t CFile::open(const std::string &filepath, eOpenTypes mode) { 30 | this->close(); 31 | int32_t openMode = 0; 32 | 33 | // This depend on the devoptab implementation. 34 | // see https://github.com/devkitPro/wut/blob/master/libraries/wutdevoptab/devoptab_fs_open.c#L21 fpr reference 35 | 36 | switch (mode) { 37 | default: 38 | case ReadOnly: // file must exist 39 | openMode = O_RDONLY; 40 | break; 41 | case WriteOnly: // file will be created / zerod 42 | openMode = O_TRUNC | O_CREAT | O_WRONLY; 43 | break; 44 | case ReadWrite: // file must exist 45 | openMode = O_RDWR; 46 | break; 47 | case Append: // append to file, file will be created if missing. write only 48 | openMode = O_CREAT | O_APPEND | O_WRONLY; 49 | break; 50 | } 51 | 52 | //! Using fopen works only on the first launch as expected 53 | //! on the second launch it causes issues because we don't overwrite 54 | //! the .data sections which is needed for a normal application to re-init 55 | //! this will be added with launching as RPX 56 | iFd = ::open(filepath.c_str(), openMode); 57 | if (iFd < 0) 58 | return iFd; 59 | 60 | 61 | filesize = ::lseek(iFd, 0, SEEK_END); 62 | ::lseek(iFd, 0, SEEK_SET); 63 | 64 | return 0; 65 | } 66 | 67 | int32_t CFile::open(const uint8_t *mem, int32_t size) { 68 | this->close(); 69 | 70 | mem_file = mem; 71 | filesize = size; 72 | 73 | return 0; 74 | } 75 | 76 | void CFile::close() { 77 | if (iFd >= 0) 78 | ::close(iFd); 79 | 80 | iFd = -1; 81 | mem_file = nullptr; 82 | filesize = 0; 83 | pos = 0; 84 | } 85 | 86 | int32_t CFile::read(uint8_t *ptr, size_t size) { 87 | if (iFd >= 0) { 88 | int32_t ret = ::read(iFd, ptr, size); 89 | if (ret > 0) 90 | pos += ret; 91 | return ret; 92 | } 93 | 94 | int32_t readsize = size; 95 | 96 | if (readsize > (int64_t) (filesize - pos)) 97 | readsize = filesize - pos; 98 | 99 | if (readsize <= 0) 100 | return readsize; 101 | 102 | if (mem_file != nullptr) { 103 | memcpy(ptr, mem_file + pos, readsize); 104 | pos += readsize; 105 | return readsize; 106 | } 107 | 108 | return -1; 109 | } 110 | 111 | int32_t CFile::write(const uint8_t *ptr, size_t size) { 112 | if (iFd >= 0) { 113 | size_t done = 0; 114 | while (done < size) { 115 | int32_t ret = ::write(iFd, ptr, size - done); 116 | if (ret <= 0) 117 | return ret; 118 | 119 | ptr += ret; 120 | done += ret; 121 | pos += ret; 122 | } 123 | return done; 124 | } 125 | 126 | return -1; 127 | } 128 | 129 | int32_t CFile::seek(long int offset, int32_t origin) { 130 | int32_t ret = 0; 131 | int64_t newPos = pos; 132 | 133 | if (origin == SEEK_SET) { 134 | newPos = offset; 135 | } else if (origin == SEEK_CUR) { 136 | newPos += offset; 137 | } else if (origin == SEEK_END) { 138 | newPos = filesize + offset; 139 | } 140 | 141 | if (newPos < 0) { 142 | pos = 0; 143 | } else { 144 | pos = newPos; 145 | } 146 | 147 | if (iFd >= 0) 148 | ret = ::lseek(iFd, pos, SEEK_SET); 149 | 150 | if (mem_file != nullptr) { 151 | if (pos > filesize) { 152 | pos = filesize; 153 | } 154 | } 155 | 156 | return ret; 157 | } 158 | 159 | int32_t CFile::fwrite(const char *format, ...) { 160 | char tmp[512]; 161 | tmp[0] = 0; 162 | int32_t result = -1; 163 | 164 | va_list va; 165 | va_start(va, format); 166 | if ((vsprintf(tmp, format, va) >= 0)) { 167 | result = this->write((uint8_t *) tmp, strlen(tmp)); 168 | } 169 | va_end(va); 170 | 171 | 172 | return result; 173 | } 174 | -------------------------------------------------------------------------------- /src/fs/CFile.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CFILE_HPP_ 2 | #define CFILE_HPP_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class CFile { 12 | public: 13 | enum eOpenTypes { 14 | ReadOnly, 15 | WriteOnly, 16 | ReadWrite, 17 | Append 18 | }; 19 | 20 | CFile(); 21 | 22 | CFile(const std::string &filepath, eOpenTypes mode); 23 | 24 | CFile(const uint8_t *memory, int32_t memsize); 25 | 26 | virtual ~CFile(); 27 | 28 | int32_t open(const std::string &filepath, eOpenTypes mode); 29 | 30 | int32_t open(const uint8_t *memory, int32_t memsize); 31 | 32 | BOOL isOpen() const { 33 | if (iFd >= 0) 34 | return true; 35 | 36 | if (mem_file) 37 | return true; 38 | 39 | return false; 40 | } 41 | 42 | void close(); 43 | 44 | int32_t read(uint8_t *ptr, size_t size); 45 | 46 | int32_t write(const uint8_t *ptr, size_t size); 47 | 48 | int32_t fwrite(const char *format, ...); 49 | 50 | int32_t seek(long int offset, int32_t origin); 51 | 52 | uint64_t tell() { 53 | return pos; 54 | }; 55 | 56 | uint64_t size() { 57 | return filesize; 58 | }; 59 | 60 | void rewind() { 61 | this->seek(0, SEEK_SET); 62 | }; 63 | 64 | protected: 65 | int32_t iFd; 66 | const uint8_t *mem_file; 67 | uint64_t filesize; 68 | uint64_t pos; 69 | }; 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /src/fs/DirList.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2010 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | * 24 | * DirList Class 25 | * for WiiXplorer 2010 26 | ***************************************************************************/ 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | 39 | DirList::DirList() { 40 | Flags = 0; 41 | Filter = 0; 42 | Depth = 0; 43 | } 44 | 45 | DirList::DirList(const std::string &path, const char *filter, uint32_t flags, uint32_t maxDepth) { 46 | this->LoadPath(path, filter, flags, maxDepth); 47 | this->SortList(); 48 | } 49 | 50 | DirList::~DirList() { 51 | ClearList(); 52 | } 53 | 54 | BOOL DirList::LoadPath(const std::string &folder, const char *filter, uint32_t flags, uint32_t maxDepth) { 55 | if (folder.empty()) 56 | return false; 57 | 58 | Flags = flags; 59 | Filter = filter; 60 | Depth = maxDepth; 61 | 62 | std::string folderpath(folder); 63 | uint32_t length = folderpath.size(); 64 | 65 | //! clear path of double slashes 66 | StringTools::RemoveDoubleSlashs(folderpath); 67 | 68 | //! remove last slash if exists 69 | if (length > 0 && folderpath[length - 1] == '/') 70 | folderpath.erase(length - 1); 71 | 72 | //! add root slash if missing 73 | if (folderpath.find('/') == std::string::npos) { 74 | folderpath += '/'; 75 | } 76 | 77 | return InternalLoadPath(folderpath); 78 | } 79 | 80 | BOOL DirList::InternalLoadPath(std::string &folderpath) { 81 | if (folderpath.size() < 3) 82 | return false; 83 | 84 | struct dirent *dirent = nullptr; 85 | DIR *dir = nullptr; 86 | 87 | dir = opendir(folderpath.c_str()); 88 | if (dir == nullptr) 89 | return false; 90 | 91 | while ((dirent = readdir(dir)) != 0) { 92 | BOOL isDir = dirent->d_type & DT_DIR; 93 | const char *filename = dirent->d_name; 94 | 95 | if (isDir) { 96 | if (strcmp(filename, ".") == 0 || strcmp(filename, "..") == 0) 97 | continue; 98 | 99 | if ((Flags & CheckSubfolders) && (Depth > 0)) { 100 | int32_t length = folderpath.size(); 101 | if (length > 2 && folderpath[length - 1] != '/') { 102 | folderpath += '/'; 103 | } 104 | folderpath += filename; 105 | 106 | Depth--; 107 | InternalLoadPath(folderpath); 108 | folderpath.erase(length); 109 | Depth++; 110 | } 111 | 112 | if (!(Flags & Dirs)) 113 | continue; 114 | } else if (!(Flags & Files)) { 115 | continue; 116 | } 117 | 118 | if (Filter) { 119 | char *fileext = strrchr(filename, '.'); 120 | if (!fileext) 121 | continue; 122 | 123 | if (StringTools::strtokcmp(fileext, Filter, ",") == 0) 124 | AddEntrie(folderpath, filename, isDir); 125 | } else { 126 | AddEntrie(folderpath, filename, isDir); 127 | } 128 | } 129 | closedir(dir); 130 | 131 | return true; 132 | } 133 | 134 | void DirList::AddEntrie(const std::string &filepath, const char *filename, BOOL isDir) { 135 | if (!filename) 136 | return; 137 | 138 | int32_t pos = FileInfo.size(); 139 | 140 | FileInfo.resize(pos + 1); 141 | 142 | FileInfo[pos].FilePath = (char *) malloc(filepath.size() + strlen(filename) + 2); 143 | if (!FileInfo[pos].FilePath) { 144 | FileInfo.resize(pos); 145 | return; 146 | } 147 | 148 | sprintf(FileInfo[pos].FilePath, "%s/%s", filepath.c_str(), filename); 149 | FileInfo[pos].isDir = isDir; 150 | } 151 | 152 | void DirList::ClearList() { 153 | for (uint32_t i = 0; i < FileInfo.size(); ++i) { 154 | if (FileInfo[i].FilePath) { 155 | free(FileInfo[i].FilePath); 156 | FileInfo[i].FilePath = nullptr; 157 | } 158 | } 159 | 160 | FileInfo.clear(); 161 | std::vector().swap(FileInfo); 162 | } 163 | 164 | const char *DirList::GetFilename(int32_t ind) const { 165 | if (!valid(ind)) 166 | return ""; 167 | 168 | return StringTools::FullpathToFilename(FileInfo[ind].FilePath); 169 | } 170 | 171 | static BOOL SortCallback(const DirEntry &f1, const DirEntry &f2) { 172 | if (f1.isDir && !(f2.isDir)) 173 | return true; 174 | if (!(f1.isDir) && f2.isDir) 175 | return false; 176 | 177 | if (f1.FilePath && !f2.FilePath) 178 | return true; 179 | if (!f1.FilePath) 180 | return false; 181 | 182 | if (strcasecmp(f1.FilePath, f2.FilePath) > 0) 183 | return false; 184 | 185 | return true; 186 | } 187 | 188 | void DirList::SortList() { 189 | if (FileInfo.size() > 1) 190 | std::sort(FileInfo.begin(), FileInfo.end(), SortCallback); 191 | } 192 | 193 | void DirList::SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b)) { 194 | if (FileInfo.size() > 1) 195 | std::sort(FileInfo.begin(), FileInfo.end(), SortFunc); 196 | } 197 | 198 | uint64_t DirList::GetFilesize(int32_t index) const { 199 | struct stat st; 200 | const char *path = GetFilepath(index); 201 | 202 | if (!path || stat(path, &st) != 0) 203 | return 0; 204 | 205 | return st.st_size; 206 | } 207 | 208 | int32_t DirList::GetFileIndex(const char *filename) const { 209 | if (!filename) 210 | return -1; 211 | 212 | for (uint32_t i = 0; i < FileInfo.size(); ++i) { 213 | if (strcasecmp(GetFilename(i), filename) == 0) 214 | return i; 215 | } 216 | 217 | return -1; 218 | } 219 | -------------------------------------------------------------------------------- /src/fs/DirList.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2010 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | * 24 | * DirList Class 25 | * for WiiXplorer 2010 26 | ***************************************************************************/ 27 | #ifndef ___DIRLIST_H_ 28 | #define ___DIRLIST_H_ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | typedef struct { 35 | char *FilePath; 36 | BOOL isDir; 37 | } DirEntry; 38 | 39 | class DirList { 40 | public: 41 | //!Constructor 42 | DirList(void); 43 | 44 | //!\param path Path from where to load the filelist of all files 45 | //!\param filter A fileext that needs to be filtered 46 | //!\param flags search/filter flags from the enum 47 | DirList(const std::string &path, const char *filter = nullptr, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff); 48 | 49 | //!Destructor 50 | virtual ~DirList(); 51 | 52 | //! Load all the files from a directory 53 | BOOL LoadPath(const std::string &path, const char *filter = nullptr, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff); 54 | 55 | //! Get a filename of the list 56 | //!\param list index 57 | const char *GetFilename(int32_t index) const; 58 | 59 | //! Get the a filepath of the list 60 | //!\param list index 61 | const char *GetFilepath(int32_t index) const { 62 | if (!valid(index)) 63 | return ""; 64 | else 65 | return FileInfo[index].FilePath; 66 | } 67 | 68 | //! Get the a filesize of the list 69 | //!\param list index 70 | uint64_t GetFilesize(int32_t index) const; 71 | 72 | //! Is index a dir or a file 73 | //!\param list index 74 | BOOL IsDir(int32_t index) const { 75 | if (!valid(index)) 76 | return false; 77 | return FileInfo[index].isDir; 78 | }; 79 | 80 | //! Get the filecount of the whole list 81 | int32_t GetFilecount() const { 82 | return FileInfo.size(); 83 | }; 84 | 85 | //! Sort list by filepath 86 | void SortList(); 87 | 88 | //! Custom sort command for custom sort functions definitions 89 | void SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b)); 90 | 91 | //! Get the index of the specified filename 92 | int32_t GetFileIndex(const char *filename) const; 93 | 94 | //! Enum for search/filter flags 95 | enum { 96 | Files = 0x01, 97 | Dirs = 0x02, 98 | CheckSubfolders = 0x08, 99 | }; 100 | 101 | protected: 102 | // Internal parser 103 | BOOL InternalLoadPath(std::string &path); 104 | 105 | //!Add a list entrie 106 | void AddEntrie(const std::string &filepath, const char *filename, BOOL isDir); 107 | 108 | //! Clear the list 109 | void ClearList(); 110 | 111 | //! Check if valid pos is requested 112 | inline BOOL valid(uint32_t pos) const { 113 | return (pos < FileInfo.size()); 114 | }; 115 | 116 | uint32_t Flags; 117 | uint32_t Depth; 118 | const char *Filter; 119 | std::vector FileInfo; 120 | }; 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /src/fs/FSUtils.cpp: -------------------------------------------------------------------------------- 1 | #include "fs/FSUtils.h" 2 | #include "fs/CFile.hpp" 3 | #include "utils/logger.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) { 11 | //! always initialze input 12 | *inbuffer = nullptr; 13 | if (size) 14 | *size = 0; 15 | 16 | int32_t iFd = open(filepath, O_RDONLY); 17 | if (iFd < 0) 18 | return -1; 19 | 20 | uint32_t filesize = lseek(iFd, 0, SEEK_END); 21 | lseek(iFd, 0, SEEK_SET); 22 | 23 | uint8_t *buffer = (uint8_t *) malloc(filesize); 24 | if (buffer == nullptr) { 25 | close(iFd); 26 | return -2; 27 | } 28 | 29 | uint32_t blocksize = 0x4000; 30 | uint32_t done = 0; 31 | int32_t readBytes = 0; 32 | 33 | while (done < filesize) { 34 | if (done + blocksize > filesize) { 35 | blocksize = filesize - done; 36 | } 37 | readBytes = read(iFd, buffer + done, blocksize); 38 | if (readBytes <= 0) 39 | break; 40 | done += readBytes; 41 | } 42 | 43 | close(iFd); 44 | 45 | if (done != filesize) { 46 | free(buffer); 47 | buffer = nullptr; 48 | return -3; 49 | } 50 | 51 | *inbuffer = buffer; 52 | 53 | //! sign is optional input 54 | if (size) { 55 | *size = filesize; 56 | } 57 | 58 | return filesize; 59 | } 60 | 61 | int32_t FSUtils::CheckFile(const char *filepath) { 62 | if (!filepath) 63 | return 0; 64 | 65 | struct stat filestat; 66 | 67 | char dirnoslash[strlen(filepath) + 2]; 68 | snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath); 69 | 70 | while (dirnoslash[strlen(dirnoslash) - 1] == '/') 71 | dirnoslash[strlen(dirnoslash) - 1] = '\0'; 72 | 73 | char *notRoot = strrchr(dirnoslash, '/'); 74 | if (!notRoot) { 75 | strcat(dirnoslash, "/"); 76 | } 77 | 78 | if (stat(dirnoslash, &filestat) == 0) 79 | return 1; 80 | 81 | return 0; 82 | } 83 | 84 | int32_t FSUtils::CreateSubfolder(const char *fullpath) { 85 | if (!fullpath) 86 | return 0; 87 | 88 | int32_t result = 0; 89 | 90 | char dirnoslash[strlen(fullpath) + 1]; 91 | strcpy(dirnoslash, fullpath); 92 | 93 | int32_t pos = strlen(dirnoslash) - 1; 94 | while (dirnoslash[pos] == '/') { 95 | dirnoslash[pos] = '\0'; 96 | pos--; 97 | } 98 | 99 | if (CheckFile(dirnoslash)) { 100 | return 1; 101 | } else { 102 | char parentpath[strlen(dirnoslash) + 2]; 103 | strcpy(parentpath, dirnoslash); 104 | char *ptr = strrchr(parentpath, '/'); 105 | 106 | if (!ptr) { 107 | //!Device root directory (must be with '/') 108 | strcat(parentpath, "/"); 109 | struct stat filestat; 110 | if (stat(parentpath, &filestat) == 0) 111 | return 1; 112 | 113 | return 0; 114 | } 115 | 116 | ptr++; 117 | ptr[0] = '\0'; 118 | 119 | result = CreateSubfolder(parentpath); 120 | } 121 | 122 | if (!result) 123 | return 0; 124 | 125 | if (mkdir(dirnoslash, 0777) == -1) { 126 | return 0; 127 | } 128 | 129 | return 1; 130 | } 131 | 132 | int32_t FSUtils::saveBufferToFile(const char *path, void *buffer, uint32_t size) { 133 | CFile file(path, CFile::WriteOnly); 134 | if (!file.isOpen()) { 135 | DEBUG_FUNCTION_LINE("Failed to open %s", path); 136 | return 0; 137 | } 138 | int32_t written = file.write((const uint8_t *) buffer, size); 139 | file.close(); 140 | return written; 141 | } 142 | -------------------------------------------------------------------------------- /src/fs/FSUtils.h: -------------------------------------------------------------------------------- 1 | #ifndef __FS_UTILS_H_ 2 | #define __FS_UTILS_H_ 3 | 4 | #include 5 | 6 | class FSUtils { 7 | public: 8 | static int32_t LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size); 9 | 10 | //! todo: C++ class 11 | static int32_t CreateSubfolder(const char *fullpath); 12 | 13 | static int32_t CheckFile(const char *filepath); 14 | 15 | static int32_t saveBufferToFile(const char *path, void *buffer, uint32_t size); 16 | }; 17 | 18 | #endif // __FS_UTILS_H_ 19 | -------------------------------------------------------------------------------- /src/game/GameList.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "GameList.h" 10 | #include "common/common.h" 11 | #include "utils/AsyncExecutor.h" 12 | 13 | #include "fs/FSUtils.h" 14 | #include "utils/logger.h" 15 | 16 | GameList::GameList() { 17 | } 18 | 19 | GameList::~GameList() { 20 | stopAsyncLoading = true; 21 | DCFlushRange(&stopAsyncLoading, sizeof(stopAsyncLoading)); 22 | clear(); 23 | }; 24 | 25 | void GameList::clear() { 26 | lock(); 27 | for (auto const &x : fullGameList) { 28 | if (x != nullptr) { 29 | if (x->imageData != nullptr) { 30 | AsyncExecutor::pushForDelete(x->imageData); 31 | x->imageData = nullptr; 32 | } 33 | delete x; 34 | } 35 | } 36 | fullGameList.clear(); 37 | //! Clear memory of the vector completely 38 | std::vector().swap(fullGameList); 39 | unlock(); 40 | titleListChanged(this); 41 | } 42 | 43 | gameInfo *GameList::getGameInfo(uint64_t titleId) { 44 | gameInfo *result = nullptr; 45 | lock(); 46 | for (uint32_t i = 0; i < fullGameList.size(); ++i) { 47 | if (titleId == fullGameList[i]->titleId) { 48 | result = fullGameList[i]; 49 | break; 50 | } 51 | } 52 | unlock(); 53 | return result; 54 | } 55 | 56 | int32_t GameList::readGameList() { 57 | // Clear list 58 | for (auto const &x : fullGameList) { 59 | delete x; 60 | } 61 | 62 | fullGameList.clear(); 63 | //! Clear memory of the vector completely 64 | std::vector().swap(fullGameList); 65 | 66 | int32_t cnt = 0; 67 | 68 | MCPError mcp = MCP_Open(); 69 | if (mcp < 0) { 70 | return 0; 71 | } 72 | 73 | MCPError titleCount = MCP_TitleCount(mcp); 74 | if (titleCount < 0) { 75 | MCP_Close(mcp); 76 | return 0; 77 | } 78 | 79 | std::vector titles(titleCount); 80 | uint32_t realTitleCount = 0; 81 | 82 | static const std::vector menuAppTypes{ 83 | MCP_APP_TYPE_GAME, 84 | MCP_APP_TYPE_GAME_WII, 85 | MCP_APP_TYPE_SYSTEM_APPS, 86 | MCP_APP_TYPE_SYSTEM_SETTINGS, 87 | MCP_APP_TYPE_FRIEND_LIST, 88 | MCP_APP_TYPE_MIIVERSE, 89 | MCP_APP_TYPE_ESHOP, 90 | MCP_APP_TYPE_BROWSER, 91 | MCP_APP_TYPE_DOWNLOAD_MANAGEMENT, 92 | MCP_APP_TYPE_ACCOUNT_APPS, 93 | }; 94 | 95 | for (auto appType : menuAppTypes) { 96 | uint32_t titleCountByType = 0; 97 | MCPError err = MCP_TitleListByAppType(mcp, appType, &titleCountByType, titles.data() + realTitleCount, 98 | (titles.size() - realTitleCount) * sizeof(decltype(titles)::value_type)); 99 | if (err < 0) { 100 | MCP_Close(mcp); 101 | return 0; 102 | } 103 | realTitleCount += titleCountByType; 104 | } 105 | if (realTitleCount != titles.size()) { 106 | titles.resize(realTitleCount); 107 | } 108 | 109 | for (auto title_candidate : titles) { 110 | auto *newGameInfo = new gameInfo; 111 | newGameInfo->titleId = title_candidate.titleId; 112 | newGameInfo->appType = title_candidate.appType; 113 | newGameInfo->gamePath = title_candidate.path; 114 | newGameInfo->name = ""; 115 | newGameInfo->imageData = nullptr; 116 | DCFlushRange(newGameInfo, sizeof(gameInfo)); 117 | 118 | fullGameList.push_back(newGameInfo); 119 | titleAdded(newGameInfo); 120 | cnt++; 121 | } 122 | 123 | AsyncExecutor::execute([this] { 124 | lock(); 125 | for (auto header : fullGameList) { 126 | DCFlushRange(&stopAsyncLoading, sizeof(stopAsyncLoading)); 127 | if (stopAsyncLoading) { 128 | DEBUG_FUNCTION_LINE("Stop async title loading"); 129 | break; 130 | } 131 | 132 | DEBUG_FUNCTION_LINE("Load extra infos of %016llX", header->titleId); 133 | auto *meta = (ACPMetaXml *) calloc(1, 0x4000); //TODO fix wut 134 | if (meta) { 135 | auto acp = ACPGetTitleMetaXml(header->titleId, meta); 136 | if (acp >= 0) { 137 | header->name = meta->shortname_en; 138 | } 139 | free(meta); 140 | } 141 | 142 | if (header->imageData == nullptr) { 143 | std::string filepath = "fs:" + header->gamePath + META_PATH + "/iconTex.tga"; 144 | uint8_t *buffer = nullptr; 145 | uint32_t bufferSize = 0; 146 | int iResult = FSUtils::LoadFileToMem(filepath.c_str(), &buffer, &bufferSize); 147 | if (iResult > 0) { 148 | auto *imageData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR); 149 | header->imageData = imageData; 150 | 151 | //! free original image buffer which is converted to texture now and not needed anymore 152 | free(buffer); 153 | } 154 | } 155 | DCFlushRange(header, sizeof(gameInfo)); 156 | titleUpdated(header); 157 | } 158 | unlock(); 159 | }); 160 | 161 | return cnt; 162 | } 163 | 164 | void GameList::updateTitleInfo() { 165 | for (int i = 0; i < this->size(); i++) { 166 | gameInfo *newHeader = this->at(i); 167 | 168 | bool hasChanged = false; 169 | 170 | if (newHeader->name.empty()) { 171 | auto *meta = (ACPMetaXml *) calloc(1, 0x4000); //TODO fix wut 172 | if (meta) { 173 | auto acp = ACPGetTitleMetaXml(newHeader->titleId, meta); 174 | if (acp >= 0) { 175 | newHeader->name = meta->shortname_en; 176 | hasChanged = true; 177 | } 178 | free(meta); 179 | } 180 | } 181 | 182 | if (newHeader->imageData == nullptr) { 183 | std::string filepath = "fs:" + newHeader->gamePath + META_PATH + "/iconTex.tga"; 184 | uint8_t *buffer = nullptr; 185 | uint32_t bufferSize = 0; 186 | int iResult = FSUtils::LoadFileToMem(filepath.c_str(), &buffer, &bufferSize); 187 | 188 | if (iResult > 0) { 189 | auto *imageData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR); 190 | newHeader->imageData = imageData; 191 | hasChanged = true; 192 | 193 | //! free original image buffer which is converted to texture now and not needed anymore 194 | free(buffer); 195 | } 196 | } 197 | if (hasChanged) { 198 | DCFlushRange(newHeader, sizeof(gameInfo)); 199 | titleUpdated(newHeader); 200 | } 201 | } 202 | } 203 | 204 | int32_t GameList::load() { 205 | lock(); 206 | if (fullGameList.empty()) { 207 | readGameList(); 208 | } 209 | 210 | AsyncExecutor::execute([&] { updateTitleInfo(); }); 211 | 212 | titleListChanged(this); 213 | 214 | int res = fullGameList.size(); 215 | unlock(); 216 | return res; 217 | } 218 | -------------------------------------------------------------------------------- /src/game/GameList.h: -------------------------------------------------------------------------------- 1 | #ifndef GAME_LIST_H_ 2 | #define GAME_LIST_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | typedef struct _gameInfo { 13 | uint64_t titleId; 14 | MCPAppType appType; 15 | std::string name; 16 | std::string gamePath; 17 | GuiImageData *imageData; 18 | } gameInfo; 19 | 20 | class GameList { 21 | public: 22 | GameList(); 23 | 24 | ~GameList(); 25 | 26 | int32_t size() { 27 | lock(); 28 | int32_t res = fullGameList.size(); 29 | unlock(); 30 | return res; 31 | } 32 | 33 | int32_t gameCount() { 34 | lock(); 35 | int32_t res = fullGameList.size(); 36 | unlock(); 37 | return res; 38 | } 39 | 40 | gameInfo *at(int32_t i) { 41 | return operator[](i); 42 | } 43 | 44 | gameInfo *operator[](int32_t i) { 45 | lock(); 46 | gameInfo *res = nullptr; 47 | if (i < 0 || i >= (int32_t) fullGameList.size()) { 48 | res = nullptr; 49 | } else { 50 | res = fullGameList[i]; 51 | } 52 | unlock(); 53 | return res; 54 | } 55 | 56 | gameInfo *getGameInfo(uint64_t titleId); 57 | 58 | void clear(); 59 | 60 | std::vector &getFullGameList(void) { 61 | return fullGameList; 62 | } 63 | 64 | int32_t load(); 65 | 66 | sigslot::signal1 titleListChanged; 67 | sigslot::signal1 titleUpdated; 68 | sigslot::signal1 titleAdded; 69 | 70 | void lock() { 71 | _lock.lock(); 72 | } 73 | 74 | void unlock() { 75 | _lock.unlock(); 76 | } 77 | 78 | protected: 79 | int32_t readGameList(); 80 | 81 | void updateTitleInfo(); 82 | 83 | std::vector fullGameList; 84 | 85 | std::recursive_mutex _lock; 86 | 87 | bool stopAsyncLoading = false; 88 | }; 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /src/gui/GameIcon.cpp: -------------------------------------------------------------------------------- 1 | #include "GameIcon.h" 2 | #include "Application.h" 3 | #include "GameIconModel.h" 4 | #include "utils/logger.h" 5 | #include "utils/utils.h" 6 | #include 7 | #include 8 | #include 9 | 10 | static const float cfIconMirrorScale = 1.15f; 11 | static const float cfIconMirrorAlpha = 0.45f; 12 | 13 | GameIcon::GameIcon(GuiImageData *preloadImage) 14 | : GuiImage(preloadImage) { 15 | bSelected = false; 16 | bRenderStroke = true; 17 | bRenderReflection = false; 18 | bIconLast = false; 19 | strokeFractalEnable = 1; 20 | strokeBlurBorder = 0.0f; 21 | distanceFadeout = 0.0f; 22 | rotationX = 0.0f; 23 | reflectionAlpha = 0.4f; 24 | strokeWidth = 2.35f; 25 | colorIntensity = glm::vec4(1.0f); 26 | colorIntensityMirror = colorIntensity; 27 | alphaFadeOutNorm = glm::vec4(0.0f); 28 | alphaFadeOutRefl = glm::vec4(-1.0f, 0.0f, 0.9f, 1.0f); 29 | selectionBlurOuterColorIntensity = glm::vec4(0.09411764f * 1.15f, 0.56862745f * 1.15f, 0.96862745098f * 1.15f, 1.0f); 30 | selectionBlurOuterSize = 1.65f; 31 | selectionBlurOuterBorderSize = 0.5f; 32 | selectionBlurInnerColorIntensity = glm::vec4(0.46666667f, 0.90588235f, 1.0f, 1.0f); 33 | selectionBlurInnerSize = 1.45f; 34 | selectionBlurInnerBorderSize = 0.95f; 35 | 36 | vtxCount = sizeof(cfGameIconPosVtxs) / (Shader3D::cuVertexAttrSize); 37 | 38 | //! texture and vertex coordinates 39 | posVtxs = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconPosVtxs)); 40 | texCoords = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconTexCoords)); 41 | 42 | if (posVtxs) { 43 | memcpy((float *) posVtxs, cfGameIconPosVtxs, sizeof(cfGameIconPosVtxs)); 44 | GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, (float *) posVtxs, sizeof(cfGameIconPosVtxs)); 45 | } 46 | if (texCoords) { 47 | memcpy((float *) texCoords, cfGameIconTexCoords, sizeof(cfGameIconTexCoords)); 48 | GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, (float *) texCoords, sizeof(cfGameIconTexCoords)); 49 | } 50 | 51 | //! create vertexes for the mirror frame 52 | texCoordsMirror = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconTexCoords)); 53 | 54 | if (texCoordsMirror) { 55 | for (uint32_t i = 0; i < vtxCount; i++) { 56 | texCoordsMirror[i * 2 + 0] = texCoords[i * 2 + 0] * cfIconMirrorScale - ((cfIconMirrorScale - 1.0f) - (cfIconMirrorScale - 1.0f) * 0.5f); 57 | texCoordsMirror[i * 2 + 1] = texCoords[i * 2 + 1] * cfIconMirrorScale - ((cfIconMirrorScale - 1.0f) - (cfIconMirrorScale - 1.0f) * 0.5f); 58 | } 59 | GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, texCoordsMirror, sizeof(cfGameIconTexCoords)); 60 | } 61 | 62 | //! setup stroke of the icon 63 | strokePosVtxs = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconStrokeVtxs)); 64 | if (strokePosVtxs) { 65 | memcpy(strokePosVtxs, cfGameIconStrokeVtxs, sizeof(cfGameIconStrokeVtxs)); 66 | GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, strokePosVtxs, sizeof(cfGameIconStrokeVtxs)); 67 | } 68 | strokeTexCoords = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, cuGameIconStrokeVtxCount * Shader::cuTexCoordAttrSize); 69 | if (strokeTexCoords) { 70 | for (size_t i = 0, n = 0; i < cuGameIconStrokeVtxCount; n += 2, i += 3) { 71 | strokeTexCoords[n] = (1.0f + strokePosVtxs[i]) * 0.5f; 72 | strokeTexCoords[n + 1] = 1.0f - (1.0f + strokePosVtxs[i + 1]) * 0.5f; 73 | } 74 | GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, strokeTexCoords, cuGameIconStrokeVtxCount * Shader::cuTexCoordAttrSize); 75 | } 76 | strokeColorVtxs = (uint8_t *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, cuGameIconStrokeVtxCount * Shader::cuColorAttrSize); 77 | if (strokeColorVtxs) { 78 | for (size_t i = 0; i < (cuGameIconStrokeVtxCount * Shader::cuColorAttrSize); i++) 79 | strokeColorVtxs[i] = 0xff; 80 | GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, strokeColorVtxs, cuGameIconStrokeVtxCount * Shader::cuColorAttrSize); 81 | } 82 | } 83 | 84 | GameIcon::~GameIcon() { 85 | //! remove image so it can not be drawn anymore from this point on 86 | imageData = nullptr; 87 | 88 | //! main image vertexes 89 | if (posVtxs) { 90 | free((void *) posVtxs); 91 | posVtxs = nullptr; 92 | } 93 | if (texCoords) { 94 | free((void *) texCoords); 95 | texCoords = nullptr; 96 | } 97 | //! mirror image vertexes 98 | if (texCoordsMirror) { 99 | free(texCoordsMirror); 100 | texCoordsMirror = nullptr; 101 | } 102 | //! stroke image vertexes 103 | if (strokePosVtxs) { 104 | free(strokePosVtxs); 105 | strokePosVtxs = nullptr; 106 | } 107 | if (strokeTexCoords) { 108 | free(strokeTexCoords); 109 | strokeTexCoords = nullptr; 110 | } 111 | if (strokeColorVtxs) { 112 | free(strokeColorVtxs); 113 | strokeColorVtxs = nullptr; 114 | } 115 | } 116 | 117 | bool GameIcon::checkRayIntersection(const glm::vec3 &rayOrigin, const glm::vec3 &rayDirFrac) { 118 | //! since we always face the camera we can just check the AABB intersection 119 | //! otherwise an OOB intersection would be required 120 | 121 | float currPosX = getCenterX() * Application::instance()->getVideo()->getWidthScaleFactor() * 2.0f; 122 | float currPosY = getCenterY() * Application::instance()->getVideo()->getHeightScaleFactor() * 2.0f; 123 | float currPosZ = getDepth() * Application::instance()->getVideo()->getDepthScaleFactor() * 2.0f; 124 | float currScaleX = getScaleX() * (float) getWidth() * Application::instance()->getVideo()->getWidthScaleFactor(); 125 | float currScaleY = getScaleY() * (float) getHeight() * Application::instance()->getVideo()->getHeightScaleFactor(); 126 | float currScaleZ = getScaleZ() * (float) getWidth() * Application::instance()->getVideo()->getDepthScaleFactor(); 127 | //! lb is the corner of AABB with minimal coordinates - left bottom, rt is maximal corner 128 | glm::vec3 lb(currPosX - currScaleX, currPosY - currScaleY, currPosZ - currScaleZ); 129 | glm::vec3 rt(currPosX + currScaleX, currPosY + currScaleY, currPosZ + currScaleZ); 130 | 131 | float t1 = (lb.x - rayOrigin.x) * rayDirFrac.x; 132 | float t2 = (rt.x - rayOrigin.x) * rayDirFrac.x; 133 | float t3 = (lb.y - rayOrigin.y) * rayDirFrac.y; 134 | float t4 = (rt.y - rayOrigin.y) * rayDirFrac.y; 135 | float t5 = (lb.z - rayOrigin.z) * rayDirFrac.z; 136 | float t6 = (rt.z - rayOrigin.z) * rayDirFrac.z; 137 | 138 | float tmin = std::max(std::max(std::min(t1, t2), std::min(t3, t4)), std::min(t5, t6)); 139 | float tmax = std::min(std::min(std::max(t1, t2), std::max(t3, t4)), std::max(t5, t6)); 140 | 141 | //! if tmax < 0, ray (line) is intersecting AABB, but whole AABB is behing us 142 | if (tmax < 0) { 143 | //t = tmax; 144 | return false; 145 | } 146 | 147 | //! if tmin > tmax, ray doesn't intersect AABB 148 | if (tmin > tmax) { 149 | //t = tmax; 150 | return false; 151 | } 152 | 153 | //t = tmin; 154 | return true; 155 | } 156 | 157 | void GameIcon::draw(CVideo *pVideo, const glm::mat4 &projectionMtx, const glm::mat4 &viewMtx, const glm::mat4 &modelView) { 158 | if (imageData == nullptr) { 159 | return; 160 | } 161 | //! first setup 2D GUI positions 162 | float currPosX = getCenterX() * pVideo->getWidthScaleFactor() * 2.0f; 163 | float currPosY = getCenterY() * pVideo->getHeightScaleFactor() * 2.0f; 164 | float currPosZ = getDepth() * pVideo->getDepthScaleFactor() * 2.0f; 165 | float currScaleX = getScaleX() * (float) getWidth() * pVideo->getWidthScaleFactor(); 166 | float currScaleY = getScaleY() * (float) getHeight() * pVideo->getHeightScaleFactor(); 167 | float currScaleZ = getScaleZ() * (float) getWidth() * pVideo->getDepthScaleFactor(); 168 | float strokeScaleX = pVideo->getWidthScaleFactor() * strokeWidth * 0.25f + cfIconMirrorScale; 169 | float strokeScaleY = pVideo->getHeightScaleFactor() * strokeWidth * 0.25f + cfIconMirrorScale; 170 | 171 | for (int32_t iDraw = 0; iDraw < 2; iDraw++) { 172 | glm::vec4 *alphaFadeOut; 173 | glm::mat4 m_iconView; 174 | glm::mat4 m_mirrorView; 175 | glm::mat4 m_strokeView; 176 | 177 | if (iDraw == RENDER_REFLECTION) { 178 | //! Reflection render 179 | if (!bRenderReflection) 180 | continue; 181 | m_iconView = glm::translate(modelView, glm::vec3(currPosX, -currScaleY * 2.0f - currPosY, currPosZ + cosf(DegToRad(rotationX)) * currScaleZ * 2.0f)); 182 | m_iconView = glm::rotate(m_iconView, DegToRad(rotationX), glm::vec3(1.0f, 0.0f, 0.0f)); 183 | m_iconView = glm::scale(m_iconView, glm::vec3(currScaleX, -currScaleY, currScaleZ)); 184 | 185 | colorIntensity[3] = reflectionAlpha * getAlpha(); 186 | selectionBlurOuterColorIntensity[3] = colorIntensity[3] * 0.7f; 187 | selectionBlurInnerColorIntensity[3] = colorIntensity[3] * 0.7f; 188 | alphaFadeOut = &alphaFadeOutRefl; 189 | 190 | GX2SetCullOnlyControl(GX2_FRONT_FACE_CCW, GX2_ENABLE, GX2_DISABLE); 191 | } else { 192 | //! Normal render 193 | m_iconView = glm::translate(modelView, glm::vec3(currPosX, currPosY, currPosZ)); 194 | m_iconView = glm::rotate(m_iconView, DegToRad(rotationX), glm::vec3(1.0f, 0.0f, 0.0f)); 195 | m_iconView = glm::scale(m_iconView, glm::vec3(currScaleX, currScaleY, currScaleZ)); 196 | 197 | colorIntensity[3] = getAlpha(); 198 | selectionBlurOuterColorIntensity[3] = colorIntensity[3]; 199 | selectionBlurInnerColorIntensity[3] = colorIntensity[3]; 200 | alphaFadeOut = &alphaFadeOutNorm; 201 | } 202 | 203 | m_mirrorView = glm::scale(m_iconView, glm::vec3(cfIconMirrorScale, cfIconMirrorScale, cfIconMirrorScale)); 204 | 205 | colorIntensityMirror[3] = cfIconMirrorAlpha * colorIntensity[3]; 206 | 207 | if (!bIconLast) { 208 | Shader3D::instance()->setShaders(); 209 | Shader3D::instance()->setProjectionMtx(projectionMtx); 210 | Shader3D::instance()->setViewMtx(viewMtx); 211 | Shader3D::instance()->setTextureAndSampler(imageData->getTexture(), imageData->getSampler()); 212 | Shader3D::instance()->setAlphaFadeOut(*alphaFadeOut); 213 | Shader3D::instance()->setDistanceFadeOut(distanceFadeout); 214 | 215 | //! render the real symbol 216 | Shader3D::instance()->setModelViewMtx(m_iconView); 217 | Shader3D::instance()->setColorIntensity(colorIntensity); 218 | Shader3D::instance()->setAttributeBuffer(vtxCount, posVtxs, texCoords); 219 | Shader3D::instance()->draw(GX2_PRIMITIVE_MODE_QUADS, vtxCount); 220 | } 221 | 222 | 223 | if (bSelected) { 224 | strokeFractalEnable = 0; 225 | 226 | GX2SetDepthOnlyControl(GX2_ENABLE, GX2_DISABLE, GX2_COMPARE_FUNC_LEQUAL); 227 | m_strokeView = glm::scale(m_iconView, glm::vec3(selectionBlurOuterSize, selectionBlurOuterSize, 0.0f)); 228 | ShaderFractalColor::instance()->setShaders(); 229 | ShaderFractalColor::instance()->setProjectionMtx(projectionMtx); 230 | ShaderFractalColor::instance()->setViewMtx(viewMtx); 231 | ShaderFractalColor::instance()->setModelViewMtx(m_strokeView); 232 | ShaderFractalColor::instance()->setFractalColor(strokeFractalEnable); 233 | ShaderFractalColor::instance()->setBlurBorder(selectionBlurOuterBorderSize); 234 | ShaderFractalColor::instance()->setColorIntensity(selectionBlurOuterColorIntensity); 235 | ShaderFractalColor::instance()->setAlphaFadeOut(*alphaFadeOut); 236 | ShaderFractalColor::instance()->setAttributeBuffer(); 237 | ShaderFractalColor::instance()->draw(); 238 | 239 | m_strokeView = glm::scale(m_iconView, glm::vec3(selectionBlurInnerSize, selectionBlurInnerSize, 0.0f)); 240 | ShaderFractalColor::instance()->setBlurBorder(selectionBlurInnerBorderSize); 241 | ShaderFractalColor::instance()->setColorIntensity(selectionBlurInnerColorIntensity); 242 | ShaderFractalColor::instance()->draw(); 243 | GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL); 244 | } 245 | 246 | if (iDraw == RENDER_NORMAL && bRenderStroke) { 247 | strokeFractalEnable = 1; 248 | //! now render the icon stroke 249 | //! make the stroke a little bigger than the mirror, just by the line width on each side 250 | m_strokeView = glm::scale(m_iconView, glm::vec3(strokeScaleX, strokeScaleY, cfIconMirrorScale)); 251 | 252 | ShaderFractalColor::instance()->setShaders(); 253 | ShaderFractalColor::instance()->setLineWidth(strokeWidth); 254 | ShaderFractalColor::instance()->setProjectionMtx(projectionMtx); 255 | ShaderFractalColor::instance()->setViewMtx(viewMtx); 256 | ShaderFractalColor::instance()->setModelViewMtx(m_strokeView); 257 | ShaderFractalColor::instance()->setFractalColor(strokeFractalEnable); 258 | ShaderFractalColor::instance()->setBlurBorder(strokeBlurBorder); 259 | ShaderFractalColor::instance()->setColorIntensity(colorIntensity); 260 | ShaderFractalColor::instance()->setAlphaFadeOut(*alphaFadeOut); 261 | ShaderFractalColor::instance()->setAttributeBuffer(cuGameIconStrokeVtxCount, strokePosVtxs, strokeTexCoords, strokeColorVtxs); 262 | ShaderFractalColor::instance()->draw(GX2_PRIMITIVE_MODE_LINE_STRIP, cuGameIconStrokeVtxCount); 263 | } 264 | 265 | //! render the background mirror frame 266 | Shader3D::instance()->setShaders(); 267 | Shader3D::instance()->setProjectionMtx(projectionMtx); 268 | Shader3D::instance()->setViewMtx(viewMtx); 269 | Shader3D::instance()->setTextureAndSampler(imageData->getTexture(), imageData->getSampler()); 270 | Shader3D::instance()->setAlphaFadeOut(*alphaFadeOut); 271 | Shader3D::instance()->setDistanceFadeOut(distanceFadeout); 272 | Shader3D::instance()->setModelViewMtx(m_mirrorView); 273 | Shader3D::instance()->setColorIntensity(colorIntensityMirror); 274 | Shader3D::instance()->setAttributeBuffer(vtxCount, posVtxs, texCoordsMirror); 275 | Shader3D::instance()->draw(GX2_PRIMITIVE_MODE_QUADS, vtxCount); 276 | 277 | if (bIconLast) { 278 | Shader3D::instance()->setShaders(); 279 | Shader3D::instance()->setProjectionMtx(projectionMtx); 280 | Shader3D::instance()->setViewMtx(viewMtx); 281 | Shader3D::instance()->setTextureAndSampler(imageData->getTexture(), imageData->getSampler()); 282 | Shader3D::instance()->setAlphaFadeOut(*alphaFadeOut); 283 | Shader3D::instance()->setDistanceFadeOut(distanceFadeout); 284 | 285 | //! render the real symbol 286 | Shader3D::instance()->setModelViewMtx(m_iconView); 287 | Shader3D::instance()->setColorIntensity(colorIntensity); 288 | Shader3D::instance()->setAttributeBuffer(vtxCount, posVtxs, texCoords); 289 | Shader3D::instance()->draw(GX2_PRIMITIVE_MODE_QUADS, vtxCount); 290 | } 291 | 292 | //! return back normal culling 293 | if (iDraw == RENDER_REFLECTION) { 294 | GX2SetCullOnlyControl(GX2_FRONT_FACE_CCW, GX2_DISABLE, GX2_ENABLE); 295 | } 296 | } 297 | } 298 | -------------------------------------------------------------------------------- /src/gui/GameIcon.h: -------------------------------------------------------------------------------- 1 | #ifndef _GAME_ICON_H_ 2 | #define _GAME_ICON_H_ 3 | 4 | #include 5 | #include 6 | 7 | class GameIcon : public GuiImage { 8 | public: 9 | GameIcon(GuiImageData *preloadImage); 10 | 11 | virtual ~GameIcon(); 12 | 13 | void setRotationX(float r) { 14 | rotationX = r; 15 | } 16 | 17 | void setColorIntensity(const glm::vec4 &color) { 18 | colorIntensity = color; 19 | colorIntensityMirror = colorIntensity; 20 | selectionBlurOuterColorIntensity = color * glm::vec4(0.09411764f * 1.15f, 0.56862745f * 1.15f, 0.96862745098f * 1.15f, 1.0f); 21 | selectionBlurInnerColorIntensity = color * glm::vec4(0.46666667f, 0.90588235f, 1.0f, 1.0f); 22 | } 23 | 24 | const glm::vec4 &getColorIntensity() const { 25 | return colorIntensity; 26 | } 27 | 28 | void setAlphaFadeOutNorm(const glm::vec4 &a) { 29 | alphaFadeOutNorm = a; 30 | } 31 | 32 | void setAlphaFadeOutRefl(const glm::vec4 &a) { 33 | alphaFadeOutRefl = a; 34 | } 35 | 36 | void setRenderReflection(bool enable) { 37 | bRenderReflection = enable; 38 | } 39 | 40 | void setSelected(bool enable) { 41 | bSelected = enable; 42 | } 43 | 44 | void setStrokeRender(bool enable) { 45 | bRenderStroke = enable; 46 | } 47 | 48 | void setRenderIconLast(bool enable) { 49 | bIconLast = enable; 50 | } 51 | 52 | void draw(CVideo *pVideo) { 53 | static const glm::mat4 identity(1.0f); 54 | draw(pVideo, identity, identity, identity); 55 | } 56 | 57 | void draw(CVideo *pVideo, const glm::mat4 &projection, const glm::mat4 &view, const glm::mat4 &modelView); 58 | 59 | bool checkRayIntersection(const glm::vec3 &rayOrigin, const glm::vec3 &rayDirFrac); 60 | 61 | private: 62 | enum eRenderState { 63 | RENDER_REFLECTION, 64 | RENDER_NORMAL 65 | }; 66 | 67 | bool bSelected; 68 | bool bRenderStroke; 69 | bool bRenderReflection; 70 | bool bIconLast; 71 | glm::vec4 colorIntensity; 72 | glm::vec4 colorIntensityMirror; 73 | glm::vec4 alphaFadeOutNorm; 74 | glm::vec4 alphaFadeOutRefl; 75 | 76 | float reflectionAlpha; 77 | float strokeWidth; 78 | float rotationX; 79 | float rgbReduction; 80 | float distanceFadeout; 81 | float *texCoordsMirror; 82 | float *strokePosVtxs; 83 | float *strokeTexCoords; 84 | uint8_t *strokeColorVtxs; 85 | int32_t strokeFractalEnable; 86 | float strokeBlurBorder; 87 | glm::vec4 selectionBlurOuterColorIntensity; 88 | float selectionBlurOuterSize; 89 | float selectionBlurOuterBorderSize; 90 | glm::vec4 selectionBlurInnerColorIntensity; 91 | float selectionBlurInnerSize; 92 | float selectionBlurInnerBorderSize; 93 | }; 94 | 95 | #endif // _GAME_ICON_H_ 96 | -------------------------------------------------------------------------------- /src/gui/GuiIconGrid.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 Dimok 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | ****************************************************************************/ 17 | #include "Application.h" 18 | #include "common/common.h" 19 | #include "gui/GameIcon.h" 20 | #include "utils/logger.h" 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | GuiIconGrid::GuiIconGrid(int32_t w, int32_t h, uint64_t GameIndex, bool sortByName) 29 | : GuiTitleBrowser(w, h, GameIndex), 30 | sortByName(sortByName), 31 | particleBgImage(w, h, 50, 60.0f, 90.0f, 0.6f, 1.0f), buttonClickSound(Resources::GetSound("button_click.mp3")), gameTitle((char *) nullptr, 52, glm::vec4(1.0f)), 32 | touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH), 33 | wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A), 34 | leftTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_LEFT | GuiTrigger::STICK_L_LEFT, true), 35 | rightTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_RIGHT | GuiTrigger::STICK_L_RIGHT, true), 36 | downTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_DOWN | GuiTrigger::STICK_L_DOWN, true), upTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_UP | GuiTrigger::STICK_L_UP, true), 37 | buttonATrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_A, true), buttonLTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_L, true), 38 | buttonRTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_R, true), leftButton(w, h), rightButton(w, h), downButton(w, h), upButton(w, h), launchButton(w, h), 39 | arrowRightImageData(Resources::GetImageData("rightArrow.png")), arrowLeftImageData(Resources::GetImageData("leftArrow.png")), arrowRightImage(arrowRightImageData), 40 | arrowLeftImage(arrowLeftImageData), arrowRightButton(arrowRightImage.getWidth(), arrowRightImage.getHeight()), arrowLeftButton(arrowLeftImage.getWidth(), arrowLeftImage.getHeight()), 41 | noIcon(Resources::GetFile("noGameIcon.png"), Resources::GetFileSize("noGameIcon.png"), GX2_TEX_CLAMP_MODE_MIRROR), 42 | emptyIcon(Resources::GetFile("iconEmpty.png"), Resources::GetFileSize("iconEmpty.png"), GX2_TEX_CLAMP_MODE_MIRROR), dragListener(w, h) { 43 | 44 | particleBgImage.setParent(this); 45 | setSelectedGame(GameIndex); 46 | listOffset = selectedGame / (MAX_COLS * MAX_ROWS); 47 | targetLeftPosition = -listOffset * getWidth(); 48 | currentLeftPosition = targetLeftPosition; 49 | 50 | leftButton.setTrigger(&leftTrigger); 51 | leftButton.clicked.connect(this, &GuiIconGrid::OnLeftClick); 52 | this->append(&leftButton); 53 | 54 | rightButton.setTrigger(&rightTrigger); 55 | rightButton.clicked.connect(this, &GuiIconGrid::OnRightClick); 56 | this->append(&rightButton); 57 | 58 | downButton.setTrigger(&downTrigger); 59 | downButton.clicked.connect(this, &GuiIconGrid::OnDownClick); 60 | this->append(&downButton); 61 | 62 | upButton.setTrigger(&upTrigger); 63 | upButton.clicked.connect(this, &GuiIconGrid::OnUpClick); 64 | this->append(&upButton); 65 | 66 | launchButton.setTrigger(&buttonATrigger); 67 | launchButton.setSoundClick(buttonClickSound); 68 | launchButton.clicked.connect(this, &GuiIconGrid::OnLaunchClick); 69 | this->append(&launchButton); 70 | 71 | arrowLeftButton.setImage(&arrowLeftImage); 72 | arrowLeftButton.setEffectGrow(); 73 | arrowLeftButton.setPosition(40, 0); 74 | arrowLeftButton.setAlignment(ALIGN_LEFT | ALIGN_MIDDLE); 75 | arrowLeftButton.setTrigger(&touchTrigger); 76 | arrowLeftButton.setTrigger(&wpadTouchTrigger); 77 | arrowLeftButton.setTrigger(&buttonLTrigger); 78 | arrowLeftButton.setHoldable(true); 79 | arrowLeftButton.setSoundClick(buttonClickSound); 80 | arrowLeftButton.clicked.connect(this, &GuiIconGrid::OnLeftArrowClick); 81 | arrowLeftButton.held.connect(this, &GuiIconGrid::OnLeftArrowHeld); 82 | arrowLeftButton.released.connect(this, &GuiIconGrid::OnLeftArrowReleased); 83 | 84 | append(&arrowLeftButton); 85 | 86 | arrowRightButton.setImage(&arrowRightImage); 87 | arrowRightButton.setEffectGrow(); 88 | arrowRightButton.setPosition(-40, 0); 89 | arrowRightButton.setAlignment(ALIGN_RIGHT | ALIGN_MIDDLE); 90 | arrowRightButton.setTrigger(&touchTrigger); 91 | arrowRightButton.setTrigger(&wpadTouchTrigger); 92 | arrowRightButton.setTrigger(&buttonRTrigger); 93 | arrowRightButton.setHoldable(true); 94 | arrowRightButton.setSoundClick(buttonClickSound); 95 | arrowRightButton.clicked.connect(this, &GuiIconGrid::OnRightArrowClick); 96 | arrowRightButton.held.connect(this, &GuiIconGrid::OnRightArrowHeld); 97 | arrowRightButton.released.connect(this, &GuiIconGrid::OnRightArrowReleased); 98 | append(&arrowRightButton); 99 | 100 | // at most we are rendering 2 screens at the same time 101 | for (int i = 0; i < MAX_COLS * MAX_ROWS * 2; i++) { 102 | GameIcon *image = new GameIcon(&emptyIcon); 103 | emptyIcons.push_back(image); 104 | GuiButton *button = new GuiButton(emptyIcon.getWidth(), emptyIcon.getHeight()); 105 | button->setImage(image); 106 | button->setPosition(0, 0); 107 | //button->setEffectGrow(); 108 | button->setHoldable(true); 109 | button->setTrigger(&touchTrigger); 110 | button->held.connect(this, &GuiIconGrid::OnGameButtonHeld); 111 | emptyButtons.push_back(button); 112 | } 113 | 114 | dragListener.setTrigger(&touchTrigger); 115 | dragListener.setTrigger(&wpadTouchTrigger); 116 | dragListener.dragged.connect(this, &GuiIconGrid::OnDrag); 117 | 118 | append(&dragListener); 119 | 120 | gameTitle.setPosition(0, -320); 121 | gameTitle.setBlurGlowColor(5.0f, glm::vec4(0.109804, 0.6549, 1.0f, 1.0f)); 122 | gameTitle.setMaxWidth(900, GuiText::DOTTED); 123 | gameTitle.setText(""); 124 | append(&gameTitle); 125 | } 126 | 127 | GuiIconGrid::~GuiIconGrid() { 128 | containerMutex.lock(); 129 | for (auto const &x : gameInfoContainers) { 130 | remove(x.second->button); 131 | delete x.second; 132 | } 133 | gameInfoContainers.clear(); 134 | containerMutex.unlock(); 135 | 136 | for (auto const &x : emptyButtons) { 137 | delete x; 138 | } 139 | 140 | for (auto const &x : emptyIcons) { 141 | delete x; 142 | } 143 | 144 | emptyButtons.clear(); 145 | emptyIcons.clear(); 146 | } 147 | 148 | int32_t GuiIconGrid::offsetForTitleId(uint64_t titleId) { 149 | int32_t offset = -1; 150 | positionMutex.lock(); 151 | for (uint32_t i = 0; i < position.size(); i++) { 152 | if (position.at(i) == titleId) { 153 | offset = i; 154 | break; 155 | } 156 | } 157 | positionMutex.unlock(); 158 | return offset; 159 | } 160 | 161 | void GuiIconGrid::setSelectedGame(uint64_t idx) { 162 | this->selectedGame = idx; 163 | 164 | containerMutex.lock(); 165 | GameInfoContainer *container = nullptr; 166 | for (auto const &x : gameInfoContainers) { 167 | container = x.second; 168 | if (x.first == idx) { 169 | container->image->setSelected(true); 170 | gameTitle.setText(container->info->name.c_str()); 171 | } else { 172 | container->image->setSelected(false); 173 | } 174 | } 175 | containerMutex.unlock(); 176 | 177 | int32_t offset = offsetForTitleId(getSelectedGame()); 178 | if (offset > 0) { 179 | uint32_t newPage = offset / (MAX_COLS * MAX_ROWS); 180 | if (newPage != (uint32_t) curPage) { 181 | curPage = newPage; 182 | bUpdatePositions = true; 183 | } 184 | } 185 | } 186 | 187 | uint64_t GuiIconGrid::getSelectedGame(void) { 188 | return selectedGame; 189 | } 190 | 191 | void GuiIconGrid::OnGameTitleListUpdated(GameList *gameList) { 192 | gameList->lock(); 193 | containerMutex.lock(); 194 | positionMutex.lock(); 195 | // At first delete the ones that were deleted; 196 | auto it = gameInfoContainers.begin(); 197 | while (it != gameInfoContainers.end()) { 198 | bool wasFound = false; 199 | for (int32_t i = 0; i < gameList->size(); i++) { 200 | gameInfo *info = gameList->at(i); 201 | if (info != nullptr && info->titleId == it->first) { 202 | wasFound = true; 203 | break; 204 | } 205 | } 206 | 207 | if (!wasFound) { 208 | DEBUG_FUNCTION_LINE("Removing %016llX", it->first); 209 | remove(it->second->button); 210 | delete it->second; 211 | it = gameInfoContainers.erase(it); 212 | } else { 213 | ++it; 214 | } 215 | } 216 | 217 | for (int32_t i = 0; i < gameList->size(); i++) { 218 | gameInfo *info = gameList->at(i); 219 | GameInfoContainer *container = nullptr; 220 | 221 | for (auto const &x : gameInfoContainers) { 222 | if (info->titleId == x.first) { 223 | container = x.second; 224 | break; 225 | } 226 | } 227 | if (container == nullptr) { 228 | OnGameTitleAdded(info); 229 | } 230 | } 231 | positionMutex.unlock(); 232 | containerMutex.unlock(); 233 | gameList->unlock(); 234 | setSelectedGame(0); 235 | gameSelectionChanged(this, selectedGame); 236 | curPage = 0; 237 | currentLeftPosition = 0; 238 | bUpdatePositions = true; 239 | } 240 | 241 | void GuiIconGrid::OnLeftArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { 242 | //setSelectedGame(0); 243 | curPage--; 244 | bUpdatePositions = true; 245 | } 246 | 247 | void GuiIconGrid::OnRightArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { 248 | //setSelectedGame(0); 249 | curPage++; 250 | bUpdatePositions = true; 251 | } 252 | 253 | void GuiIconGrid::OnLeftClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { 254 | int32_t offset = offsetForTitleId(getSelectedGame()); 255 | if (offset < 0) { 256 | return; 257 | } 258 | if ((offset % MAX_COLS) == 0) { 259 | offset -= ((MAX_COLS * MAX_ROWS) - MAX_COLS) + 1; 260 | } else { 261 | offset--; 262 | } 263 | if (offset < 0 || position.empty()) { 264 | return; 265 | } 266 | uint64_t newTitleId = position.at(offset); 267 | if (newTitleId > 0) { 268 | setSelectedGame(newTitleId); 269 | gameSelectionChanged(this, selectedGame); 270 | } 271 | } 272 | 273 | void GuiIconGrid::OnRightClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { 274 | int32_t offset = offsetForTitleId(getSelectedGame()); 275 | if (offset < 0) { 276 | return; 277 | } 278 | if ((offset % MAX_COLS) == MAX_COLS - 1) { 279 | offset += ((MAX_COLS * MAX_ROWS) - MAX_COLS) + 1; 280 | } else { 281 | offset++; 282 | } 283 | if ((uint32_t) offset >= position.size()) { 284 | return; 285 | } 286 | uint64_t newTitleId = position.at(offset); 287 | if (newTitleId > 0) { 288 | setSelectedGame(newTitleId); 289 | gameSelectionChanged(this, selectedGame); 290 | } 291 | } 292 | 293 | void GuiIconGrid::OnDownClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { 294 | int32_t offset = offsetForTitleId(getSelectedGame()); 295 | if (offset < 0) { 296 | return; 297 | } 298 | if (offset % (MAX_COLS * MAX_ROWS) < (MAX_COLS * MAX_ROWS) - MAX_COLS) { 299 | offset = offset + MAX_COLS; 300 | } else { 301 | return; 302 | } 303 | 304 | if ((uint32_t) offset >= position.size()) { 305 | return; 306 | } 307 | uint64_t newTitleId = position.at(offset); 308 | if (newTitleId > 0) { 309 | setSelectedGame(newTitleId); 310 | gameSelectionChanged(this, selectedGame); 311 | } 312 | } 313 | 314 | void GuiIconGrid::OnUpClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { 315 | int32_t offset = offsetForTitleId(getSelectedGame()); 316 | if (offset < 0) { 317 | return; 318 | } 319 | if (offset % (MAX_COLS * MAX_ROWS) >= MAX_COLS) { 320 | offset = offset - MAX_COLS; 321 | } else { 322 | return; 323 | } 324 | 325 | if (offset < 0) { 326 | return; 327 | } 328 | uint64_t newTitleId = position.at(offset); 329 | if (newTitleId > 0) { 330 | setSelectedGame(newTitleId); 331 | gameSelectionChanged(this, selectedGame); 332 | } 333 | } 334 | 335 | void GuiIconGrid::OnLaunchClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { 336 | //! do not auto launch when wiimote is pointing to screen and presses A 337 | if ((trigger == &buttonATrigger) && (controller->chan & (GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5)) && controller->data.validPointer) { 338 | return; 339 | } 340 | DEBUG_FUNCTION_LINE("Tried to launch %s (%016llX)", gameInfoContainers[getSelectedGame()]->info->name.c_str(), getSelectedGame()); 341 | gameLaunchClicked(this, getSelectedGame()); 342 | } 343 | 344 | 345 | void GuiIconGrid::OnLeftArrowHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { 346 | if (currentlyHeld != nullptr) { 347 | if (lArrowHeldCounter++ > 30) { 348 | OnLeftArrowClick(button, controller, trigger); 349 | lArrowHeldCounter = 0; 350 | } 351 | } else { 352 | lArrowHeldCounter = 0; 353 | } 354 | } 355 | 356 | void GuiIconGrid::OnLeftArrowReleased(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { 357 | lArrowHeldCounter = 0; 358 | } 359 | 360 | void GuiIconGrid::OnRightArrowHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { 361 | if (currentlyHeld != nullptr) { 362 | if (rArrowHeldCounter++ > 30) { 363 | DEBUG_FUNCTION_LINE("CLICK"); 364 | OnRightArrowClick(button, controller, trigger); 365 | rArrowHeldCounter = 0; 366 | } 367 | } else { 368 | rArrowHeldCounter = 0; 369 | } 370 | } 371 | 372 | void GuiIconGrid::OnRightArrowReleased(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { 373 | rArrowHeldCounter = 0; 374 | } 375 | 376 | 377 | void GuiIconGrid::OnGameButtonHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { 378 | if (currentlyHeld == nullptr) { 379 | bool found = false; 380 | // We don't want to drag empty buttons 381 | for (auto const &x : emptyButtons) { 382 | if (x == button) { 383 | found = true; 384 | break; 385 | } 386 | } 387 | if (!found) { 388 | currentlyHeld = button; 389 | } 390 | } 391 | if (currentlyHeld != nullptr && currentlyHeld != button) { 392 | dragTarget = button; 393 | } 394 | } 395 | 396 | void GuiIconGrid::OnGameButtonPointedOn(GuiButton *button, const GuiController *controller) { 397 | } 398 | 399 | void GuiIconGrid::OnGameButtonPointedOff(GuiButton *button, const GuiController *controller) { 400 | } 401 | 402 | void GuiIconGrid::OnDrag(GuiDragListener *element, const GuiController *controller, GuiTrigger *trigger, int32_t dx, int32_t dy) { 403 | if (currentlyHeld != nullptr) { 404 | currentlyHeld->setPosition(currentlyHeld->getOffsetX() + dx, currentlyHeld->getOffsetY() + dy); 405 | } 406 | // reset the target when we move. 407 | dragTarget = nullptr; 408 | } 409 | 410 | void GuiIconGrid::OnGameButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { 411 | containerMutex.lock(); 412 | for (auto const &x : gameInfoContainers) { 413 | if (x.second->button == button) { 414 | if (selectedGame == (x.second->info->titleId)) { 415 | if (gameLaunchTimer < 30) 416 | OnLaunchClick(button, controller, trigger); 417 | } else { 418 | setSelectedGame(x.second->info->titleId); 419 | gameSelectionChanged(this, selectedGame); 420 | } 421 | gameLaunchTimer = 0; 422 | break; 423 | } 424 | } 425 | containerMutex.unlock(); 426 | } 427 | 428 | void GuiIconGrid::OnGameTitleAdded(gameInfo *info) { 429 | DEBUG_FUNCTION_LINE("Adding %016llX", info->titleId); 430 | GuiImageData *imageData = &noIcon; 431 | if (info->imageData != nullptr) { 432 | imageData = info->imageData; 433 | } 434 | GameIcon *image = new GameIcon(imageData); 435 | image->setRenderReflection(false); 436 | image->setStrokeRender(false); 437 | image->setSelected(info->titleId == selectedGame); 438 | image->setRenderIconLast(true); 439 | 440 | GuiButton *button = new GuiButton(noIcon.getWidth(), noIcon.getHeight()); 441 | button->setImage(image); 442 | button->setPosition(0, 0); 443 | button->setEffectGrow(); 444 | button->setTrigger(&touchTrigger); 445 | button->setTrigger(&wpadTouchTrigger); 446 | button->setSoundClick(buttonClickSound); 447 | //button->setClickable( (idx < gameList->size()) ); 448 | //button->setSelectable( (idx < gameList->size()) ); 449 | button->clicked.connect(this, &GuiIconGrid::OnGameButtonClick); 450 | button->setHoldable(true); 451 | button->held.connect(this, &GuiIconGrid::OnGameButtonHeld); 452 | button->pointedOn.connect(this, &GuiIconGrid::OnGameButtonPointedOn); 453 | button->pointedOff.connect(this, &GuiIconGrid::OnGameButtonPointedOff); 454 | //button->dragged.connect(this, &GuiIconGrid::OnGameButtonDragged); 455 | 456 | GameInfoContainer *container = new GameInfoContainer(button, image, info); 457 | containerMutex.lock(); 458 | gameInfoContainers[info->titleId] = container; 459 | containerMutex.unlock(); 460 | this->append(button); 461 | 462 | positionMutex.lock(); 463 | bool foundFreePlace = false; 464 | for (uint32_t i = 0; i < position.size(); i++) { 465 | if (position[i] == 0) { 466 | position[i] = info->titleId; 467 | foundFreePlace = true; 468 | break; 469 | } 470 | } 471 | if (!foundFreePlace) { 472 | position.push_back(info->titleId); 473 | } 474 | positionMutex.unlock(); 475 | 476 | bUpdatePositions = true; 477 | } 478 | 479 | void GuiIconGrid::OnGameTitleUpdated(gameInfo *info) { 480 | DEBUG_FUNCTION_LINE("Updating infos of %016llX", info->titleId); 481 | GameInfoContainer *container = nullptr; 482 | containerMutex.lock(); 483 | for (auto const &x : gameInfoContainers) { 484 | if (info->titleId == x.first) { 485 | container = x.second; 486 | break; 487 | } 488 | } 489 | 490 | // keep the lock to delay the draw() until the image data is ready. 491 | if (container != nullptr) { 492 | container->updateImageData(); 493 | } 494 | 495 | containerMutex.unlock(); 496 | 497 | bUpdatePositions = true; 498 | } 499 | 500 | void GuiIconGrid::process() { 501 | if (currentlyHeld != nullptr) { 502 | if (!currentlyHeld->isStateSet(GuiElement::STATE_HELD)) { 503 | DEBUG_FUNCTION_LINE("Not held anymore"); 504 | positionMutex.lock(); 505 | if (dragTarget) { 506 | DEBUG_FUNCTION_LINE("Let's swap"); 507 | 508 | std::vector> vec; 509 | containerMutex.lock(); 510 | // copy key-value pairs from the map to the vector 511 | std::copy(gameInfoContainers.begin(), gameInfoContainers.end(), std::back_inserter>>(vec)); 512 | containerMutex.unlock(); 513 | uint64_t targetTitleId = 0; 514 | for (auto const &x : vec) { 515 | if (x.second->button == dragTarget) { 516 | targetTitleId = x.first; 517 | break; 518 | } 519 | } 520 | for (uint32_t i = 0; i < positionButtons.size(); i++) { 521 | if (positionButtons[i] == dragTarget) { 522 | if (i < position.size() && (int32_t) i != currentlyHeldPosition) { 523 | position[i] = currentlyHeldTitleId; 524 | DEBUG_FUNCTION_LINE("Set position to title id to %d", i, currentlyHeldPosition); 525 | } else { 526 | targetTitleId = currentlyHeldTitleId; 527 | } 528 | 529 | break; 530 | } 531 | } 532 | if (currentlyHeldPosition >= 0 && currentlyHeldPosition <= (int32_t) position.size()) { 533 | position[currentlyHeldPosition] = targetTitleId; 534 | } 535 | 536 | dragTarget = nullptr; 537 | } else { 538 | if (currentlyHeldPosition >= 0 && currentlyHeldPosition <= (int32_t) position.size()) { 539 | position[currentlyHeldPosition] = currentlyHeldTitleId; 540 | } 541 | } 542 | positionMutex.unlock(); 543 | currentlyHeld = nullptr; 544 | currentlyHeldTitleId = 0; 545 | 546 | currentlyHeldPosition = -1; 547 | bUpdatePositions = true; 548 | } else { 549 | //DEBUG_FUNCTION_LINE("Holding it"); 550 | bUpdatePositions = true; 551 | } 552 | } 553 | 554 | if (currentLeftPosition < targetLeftPosition) { 555 | currentLeftPosition += 35; 556 | 557 | if (currentLeftPosition > targetLeftPosition) 558 | currentLeftPosition = targetLeftPosition; 559 | 560 | bUpdatePositions = true; 561 | } else if (currentLeftPosition > targetLeftPosition) { 562 | currentLeftPosition -= 35; 563 | 564 | if (currentLeftPosition < targetLeftPosition) 565 | currentLeftPosition = targetLeftPosition; 566 | 567 | bUpdatePositions = true; 568 | } 569 | 570 | if (bUpdatePositions) { 571 | bUpdatePositions = false; 572 | updateButtonPositions(); 573 | } 574 | gameLaunchTimer++; 575 | 576 | GuiFrame::process(); 577 | } 578 | 579 | void GuiIconGrid::update(GuiController *c) { 580 | GuiFrame::update(c); 581 | } 582 | 583 | void GuiIconGrid::updateButtonPositions() { 584 | positionMutex.lock(); 585 | arrowRightButton.setState(GuiElement::STATE_DISABLED); 586 | arrowRightButton.setVisible(false); 587 | arrowLeftButton.setState(GuiElement::STATE_DISABLED); 588 | arrowLeftButton.setVisible(false); 589 | 590 | int32_t col = 0, row = 0, listOff = 0; 591 | 592 | // create an empty vector of pairs 593 | std::vector> vec; 594 | 595 | containerMutex.lock(); 596 | 597 | // copy key-value pairs from the map to the vector 598 | std::copy(gameInfoContainers.begin(), gameInfoContainers.end(), std::back_inserter>>(vec)); 599 | 600 | containerMutex.unlock(); 601 | 602 | for (auto const &x : vec) { 603 | if (x.second->button == currentlyHeld) { 604 | currentlyHeldTitleId = x.first; 605 | } 606 | remove(x.second->button); 607 | } 608 | 609 | for (auto const &x : emptyButtons) { 610 | remove(x); 611 | } 612 | 613 | if (sortByName) { 614 | std::sort(vec.begin(), vec.end(), 615 | [](const std::pair &l, const std::pair &r) { 616 | if (l.second != r.second) 617 | return l.second->info->name.compare(r.second->info->name) < 0; 618 | 619 | return l.first < r.first; 620 | }); 621 | } 622 | 623 | // TODO somehow be able to adjust the positions. 624 | 625 | //position.clear(); 626 | for (uint32_t i = 0; i < position.size(); i++) { 627 | if (position[i] == currentlyHeldTitleId) { 628 | currentlyHeldPosition = i; 629 | position[i] = 0; 630 | } 631 | } 632 | 633 | uint32_t elementSize = position.size(); 634 | uint32_t pages = (elementSize / (MAX_COLS * MAX_ROWS)) + 1; 635 | if (elementSize % (MAX_COLS * MAX_ROWS) == 0) { 636 | pages--; 637 | } 638 | 639 | uint32_t emptyIconUse = 0; 640 | 641 | if (curPage < 0) { 642 | curPage = 0; 643 | } 644 | if ((uint32_t) curPage > pages) { 645 | curPage = 0; 646 | } 647 | 648 | targetLeftPosition = -curPage * getWidth(); 649 | 650 | if ((uint32_t) curPage < (pages - 1)) { 651 | arrowRightButton.clearState(GuiElement::STATE_DISABLED); 652 | arrowRightButton.setVisible(true); 653 | bringToFront(&arrowRightButton); 654 | } 655 | if (curPage > 0) { 656 | arrowLeftButton.clearState(GuiElement::STATE_DISABLED); 657 | arrowLeftButton.setVisible(true); 658 | bringToFront(&arrowLeftButton); 659 | } 660 | 661 | uint32_t startPage = -(currentLeftPosition / getWidth()); 662 | uint32_t endPage = startPage; 663 | 664 | if (targetLeftPosition != currentLeftPosition) { 665 | for (auto const &x : vec) { 666 | x.second->button->setHoldable(false); 667 | } 668 | endPage++; 669 | if (endPage > pages) { 670 | endPage = pages; 671 | } 672 | } else { 673 | for (auto const &x : vec) { 674 | x.second->button->setHoldable(true); 675 | } 676 | } 677 | uint32_t startValue = startPage * (MAX_COLS * MAX_ROWS); 678 | 679 | positionButtons.clear(); 680 | for (uint32_t i = 0; i < startValue; i++) { 681 | positionButtons.push_back(nullptr); 682 | } 683 | 684 | for (uint32_t i = startPage * (MAX_COLS * MAX_ROWS); i < (endPage + 1) * (MAX_COLS * MAX_ROWS); i++) { 685 | listOff = i / (MAX_COLS * MAX_ROWS); 686 | GuiButton *element = nullptr; 687 | float posX = currentLeftPosition + listOff * width + (col * (noIcon.getWidth() + noIcon.getWidth() * 0.5f) - (MAX_COLS * 0.5f - 0.5f) * (noIcon.getWidth() + noIcon.getWidth() * 0.5f)); 688 | float posY = -row * (noIcon.getHeight() + noIcon.getHeight() * 0.5f) + (MAX_ROWS * 0.5f - 0.5f) * (noIcon.getHeight() + noIcon.getHeight() * 0.5f) + 30.0f; 689 | 690 | if (i < position.size()) { 691 | uint64_t titleID = position.at(i); 692 | if (titleID > 0) { 693 | GameInfoContainer *container = nullptr; 694 | containerMutex.lock(); 695 | if (gameInfoContainers.find(titleID) != gameInfoContainers.end()) { 696 | container = gameInfoContainers[titleID]; 697 | } 698 | containerMutex.unlock(); 699 | if (container != nullptr) { 700 | element = container->button; 701 | } 702 | } 703 | } 704 | 705 | if (element == nullptr) { 706 | if (emptyButtons.size() <= emptyIconUse) { 707 | break; 708 | } 709 | element = emptyButtons.at(emptyIconUse); 710 | emptyIconUse++; 711 | } 712 | positionButtons.push_back(element); 713 | element->setPosition(posX, posY); 714 | append(element); 715 | 716 | col++; 717 | if (col >= MAX_COLS) { 718 | col = 0; 719 | row++; 720 | } 721 | if (row >= MAX_ROWS) { 722 | row = 0; 723 | } 724 | } 725 | if (currentlyHeld != nullptr) { 726 | append(currentlyHeld); 727 | } 728 | if (positionButtons.size() > position.size() && targetLeftPosition == currentLeftPosition) { 729 | for (uint32_t i = 0; i < positionButtons.size() - position.size(); i++) { 730 | position.push_back(0); 731 | } 732 | } 733 | positionMutex.unlock(); 734 | } 735 | 736 | void GuiIconGrid::draw(CVideo *pVideo) { 737 | //! the BG needs to be rendered to stencil 738 | pVideo->setStencilRender(true); 739 | particleBgImage.draw(pVideo); 740 | pVideo->setStencilRender(false); 741 | 742 | containerMutex.lock(); 743 | positionMutex.lock(); 744 | GuiFrame::draw(pVideo); 745 | positionMutex.unlock(); 746 | containerMutex.unlock(); 747 | } 748 | -------------------------------------------------------------------------------- /src/gui/GuiIconGrid.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 Dimok 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | ****************************************************************************/ 17 | #pragma once 18 | 19 | #include "gui/GameIcon.h" 20 | #include "gui/GuiDragListener.h" 21 | #include "gui/GuiTitleBrowser.h" 22 | #include "utils/AsyncExecutor.h" 23 | #include "utils/logger.h" 24 | #include 25 | #include 26 | 27 | class GuiIconGrid : public GuiTitleBrowser, public sigslot::has_slots<> { 28 | public: 29 | GuiIconGrid(int32_t w, int32_t h, uint64_t selectedTitleId, bool sortByName); 30 | 31 | virtual ~GuiIconGrid(); 32 | 33 | void setSelectedGame(uint64_t idx); 34 | 35 | uint64_t getSelectedGame(void); 36 | 37 | void update(GuiController *t); 38 | 39 | void draw(CVideo *pVideo); 40 | 41 | void process(); 42 | 43 | void OnGameTitleListUpdated(GameList *list); 44 | 45 | void OnAddGameTitle(gameInfo *info); 46 | 47 | void OnGameTitleUpdated(gameInfo *info); 48 | 49 | void OnGameTitleAdded(gameInfo *info); 50 | 51 | private: 52 | static const int32_t MAX_ROWS = 3; 53 | static const int32_t MAX_COLS = 5; 54 | 55 | bool sortByName = false; 56 | 57 | GuiParticleImage particleBgImage; 58 | 59 | GuiSound *buttonClickSound; 60 | 61 | GuiText gameTitle; 62 | GuiTrigger touchTrigger; 63 | GuiTrigger wpadTouchTrigger; 64 | GuiTrigger leftTrigger; 65 | GuiTrigger rightTrigger; 66 | GuiTrigger downTrigger; 67 | GuiTrigger upTrigger; 68 | GuiTrigger buttonATrigger; 69 | GuiTrigger buttonLTrigger; 70 | GuiTrigger buttonRTrigger; 71 | GuiButton leftButton; 72 | GuiButton rightButton; 73 | GuiButton downButton; 74 | GuiButton upButton; 75 | GuiButton launchButton; 76 | 77 | GuiImageData *arrowRightImageData; 78 | GuiImageData *arrowLeftImageData; 79 | GuiImage arrowRightImage; 80 | GuiImage arrowLeftImage; 81 | GuiButton arrowRightButton; 82 | GuiButton arrowLeftButton; 83 | 84 | GuiImageData noIcon; 85 | GuiImageData emptyIcon; 86 | 87 | GuiDragListener dragListener; 88 | 89 | void OnLeftArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); 90 | 91 | void OnRightArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); 92 | 93 | void OnLeftClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); 94 | 95 | void OnRightClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); 96 | 97 | void OnDownClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); 98 | 99 | void OnUpClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); 100 | 101 | void OnLaunchClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); 102 | 103 | void OnGameButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); 104 | 105 | void OnGameButtonHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); 106 | 107 | void OnGameButtonPointedOn(GuiButton *button, const GuiController *controller); 108 | 109 | void OnGameButtonPointedOff(GuiButton *button, const GuiController *controller); 110 | 111 | void OnDrag(GuiDragListener *button, const GuiController *controller, GuiTrigger *trigger, int32_t dx, int32_t dy); 112 | 113 | void OnLeftArrowHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); 114 | 115 | void OnRightArrowHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); 116 | 117 | void OnLeftArrowReleased(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); 118 | 119 | void OnRightArrowReleased(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); 120 | 121 | void updateButtonPositions(); 122 | 123 | int32_t offsetForTitleId(uint64_t titleId); 124 | 125 | uint32_t lArrowHeldCounter = 0; 126 | uint32_t rArrowHeldCounter = 0; 127 | 128 | int32_t curPage = 0; 129 | int32_t listOffset; 130 | uint64_t selectedGame; 131 | int32_t currentLeftPosition; 132 | int32_t targetLeftPosition; 133 | uint32_t gameLaunchTimer; 134 | bool bUpdatePositions = false; 135 | GuiButton *currentlyHeld = nullptr; 136 | uint64_t currentlyHeldTitleId = 0; 137 | int32_t currentlyHeldPosition = -1; 138 | GuiButton *dragTarget = nullptr; 139 | 140 | class GameInfoContainer { 141 | public: 142 | GameInfoContainer(GuiButton *button, GameIcon *image, gameInfo *info) { 143 | this->image = image; 144 | this->info = info; 145 | this->button = button; 146 | } 147 | 148 | ~GameInfoContainer() { 149 | if (button != nullptr) { 150 | AsyncExecutor::pushForDelete(button); 151 | } 152 | if (image != nullptr) { 153 | AsyncExecutor::pushForDelete(image); 154 | } 155 | } 156 | 157 | void updateImageData() { 158 | if (image != nullptr && info != nullptr && info->imageData != nullptr) { 159 | image->setImageData(info->imageData); 160 | } 161 | } 162 | 163 | GameIcon *image; 164 | gameInfo *info; 165 | GuiButton *button; 166 | }; 167 | 168 | std::recursive_mutex positionMutex; 169 | std::recursive_mutex containerMutex; 170 | std::map gameInfoContainers; 171 | std::vector position; 172 | std::vector positionButtons; 173 | 174 | std::vector emptyIcons; 175 | std::vector emptyButtons; 176 | }; 177 | -------------------------------------------------------------------------------- /src/gui/GuiTitleBrowser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "game/GameList.h" 4 | #include 5 | #include 6 | 7 | class GuiTitleBrowser : public GuiFrame { 8 | public: 9 | GuiTitleBrowser(int32_t w, int32_t h, uint64_t GameIndex) : GuiFrame(w, h) {} 10 | 11 | virtual ~GuiTitleBrowser() {} 12 | 13 | virtual void setSelectedGame(uint64_t idx) = 0; 14 | 15 | virtual uint64_t getSelectedGame(void) = 0; 16 | 17 | virtual void OnGameTitleListUpdated(GameList *list) = 0; 18 | 19 | virtual void OnGameTitleUpdated(gameInfo *info) = 0; 20 | 21 | virtual void OnGameTitleAdded(gameInfo *info) = 0; 22 | 23 | sigslot::signal2 gameLaunchClicked; 24 | sigslot::signal2 gameSelectionChanged; 25 | }; 26 | -------------------------------------------------------------------------------- /src/menu/GameSplashScreen.cpp: -------------------------------------------------------------------------------- 1 | #include "GameSplashScreen.h" 2 | #include "common/common.h" 3 | #include "fs/FSUtils.h" 4 | #include "utils/AsyncExecutor.h" 5 | #include "utils/logger.h" 6 | 7 | GameSplashScreen::GameSplashScreen(int32_t w, int32_t h, gameInfo *info, bool onTV) : GuiFrame(w, h), 8 | bgImageColor(w, h, (GX2Color){0, 0, 0, 0}) { 9 | bgImageColor.setImageColor((GX2Color){ 10 | 79, 153, 239, 255}, 11 | 0); 12 | bgImageColor.setImageColor((GX2Color){ 13 | 79, 153, 239, 255}, 14 | 1); 15 | bgImageColor.setImageColor((GX2Color){ 16 | 59, 159, 223, 255}, 17 | 2); 18 | bgImageColor.setImageColor((GX2Color){ 19 | 59, 159, 223, 255}, 20 | 3); 21 | append(&bgImageColor); 22 | this->onTV = onTV; 23 | this->info = info; 24 | 25 | std::string filepath = "fs:" + info->gamePath + META_PATH + "/bootDRCTex.tga"; 26 | if (onTV) { 27 | filepath = "fs:" + info->gamePath + META_PATH + "/bootTVTex.tga"; 28 | } 29 | uint8_t *buffer = nullptr; 30 | uint32_t bufferSize = 0; 31 | int iResult = FSUtils::LoadFileToMem(filepath.c_str(), &buffer, &bufferSize); 32 | if (iResult > 0) { 33 | splashScreenData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR); 34 | if (splashScreenData) { 35 | bgImageColor.setImageData(splashScreenData); 36 | bgImageColor.setScale(((float) h) / splashScreenData->getHeight()); 37 | } 38 | 39 | //! free original image buffer which is converted to texture now and not needed anymore 40 | free(buffer); 41 | } 42 | this->effectFinished.connect(this, &GameSplashScreen::OnSplashScreenFadeInDone); 43 | } 44 | 45 | void GameSplashScreen::OnSplashScreenFadeInDone(GuiElement *element) { 46 | // we need to wait one more frame because the effects get calculated before drawing. 47 | launchGame = true; 48 | } 49 | 50 | void GameSplashScreen::draw(CVideo *v) { 51 | GuiFrame::draw(v); 52 | bool triggerLaunch = onTV; // Only the trigger the launch when calling for the TV. 53 | if (launchGame && frameCounter++ > 1) { 54 | launchGame = false; 55 | gameGameSplashScreenFinished(this, info, triggerLaunch); 56 | } 57 | } 58 | 59 | GameSplashScreen::~GameSplashScreen() { 60 | DEBUG_FUNCTION_LINE("Destroy me"); 61 | if (splashScreenData) { 62 | AsyncExecutor::pushForDelete(splashScreenData); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/menu/GameSplashScreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "game/GameList.h" 4 | #include 5 | #include 6 | 7 | class GameSplashScreen : public GuiFrame, public sigslot::has_slots<> { 8 | public: 9 | GameSplashScreen(int32_t w, int32_t h, gameInfo *info, bool onTV); 10 | 11 | virtual ~GameSplashScreen(); 12 | 13 | void OnSplashScreenFadeInDone(GuiElement *element); 14 | 15 | virtual void draw(CVideo *v); 16 | 17 | sigslot::signal3 gameGameSplashScreenFinished; 18 | 19 | private: 20 | GuiImage bgImageColor; 21 | GuiImageData *splashScreenData = nullptr; 22 | gameInfo *info = nullptr; 23 | bool launchGame = false; 24 | uint32_t frameCounter = 0; 25 | bool onTV = false; 26 | }; 27 | -------------------------------------------------------------------------------- /src/menu/KeyboardHelper.cpp: -------------------------------------------------------------------------------- 1 | #include "KeyboardHelper.h" 2 | #include "utils/logger.h" 3 | #include 4 | #include 5 | 6 | KeyboardHelper::KeyboardHelper() { 7 | auto *_fsClient = (FSClient *) MEMAllocFromDefaultHeap(sizeof(FSClient)); 8 | FSAddClient(_fsClient, FS_ERROR_FLAG_ALL); 9 | 10 | // Create swkbd 11 | nn::swkbd::CreateArg createArg; 12 | createArg.regionType = nn::swkbd::RegionType::Europe; 13 | createArg.workMemory = MEMAllocFromDefaultHeap(nn::swkbd::GetWorkMemorySize(0)); 14 | memset(createArg.workMemory, 0, sizeof(nn::swkbd::GetWorkMemorySize(0))); 15 | this->workMemory = createArg.workMemory; 16 | createArg.fsClient = _fsClient; 17 | this->fsClient = createArg.fsClient; 18 | DEBUG_FUNCTION_LINE("Calling create"); 19 | if (!nn::swkbd::Create(createArg)) { 20 | DEBUG_FUNCTION_LINE("Failed to create keyboard"); 21 | return; 22 | } 23 | 24 | keyboardCreated = true; 25 | } 26 | 27 | KeyboardHelper::~KeyboardHelper() { 28 | if (keyboardCreated) { 29 | nn::swkbd::Destroy(); 30 | MEMFreeToDefaultHeap(this->workMemory); 31 | this->workMemory = nullptr; 32 | 33 | FSDelClient(fsClient, FS_ERROR_FLAG_ALL); 34 | MEMFreeToDefaultHeap(this->fsClient); 35 | keyboardCreated = false; 36 | } 37 | } 38 | 39 | bool KeyboardHelper::openKeyboard() { 40 | if (keyboardCreated) { 41 | // Show the keyboard 42 | nn::swkbd::AppearArg appearArg; 43 | appearArg.keyboardArg.configArg.languageType = nn::swkbd::LanguageType::English; 44 | if (!nn::swkbd::AppearInputForm(appearArg)) { 45 | DEBUG_FUNCTION_LINE("nn::swkbd::AppearInputForm failed"); 46 | return false; 47 | } 48 | keyboardOpen = true; 49 | return true; 50 | } 51 | return false; 52 | } 53 | 54 | std::string KeyboardHelper::getResult() { 55 | return resultStr; 56 | } 57 | 58 | bool KeyboardHelper::checkResult() { 59 | if (keyboardCreated) { 60 | VPADStatus vpadStatus; 61 | if (keyboardOpen) { 62 | VPADRead(VPAD_CHAN_0, &vpadStatus, 1, nullptr); 63 | VPADGetTPCalibratedPoint(VPAD_CHAN_0, &vpadStatus.tpNormal, &vpadStatus.tpNormal); 64 | } 65 | // Update keyboard 66 | nn::swkbd::ControllerInfo controllerInfo; 67 | controllerInfo.vpad = &vpadStatus; 68 | controllerInfo.kpad[0] = nullptr; 69 | controllerInfo.kpad[1] = nullptr; 70 | controllerInfo.kpad[2] = nullptr; 71 | controllerInfo.kpad[3] = nullptr; 72 | nn::swkbd::Calc(controllerInfo); 73 | 74 | if (nn::swkbd::IsNeedCalcSubThreadFont()) { 75 | nn::swkbd::CalcSubThreadFont(); 76 | } 77 | 78 | if (nn::swkbd::IsNeedCalcSubThreadPredict()) { 79 | nn::swkbd::CalcSubThreadPredict(); 80 | } 81 | 82 | if (nn::swkbd::IsDecideOkButton(nullptr) || nn::swkbd::IsDecideCancelButton(nullptr)) { 83 | const char16_t *str = nn::swkbd::GetInputFormString(); 84 | // Quick hack to get from a char16_t str to char for our log function 85 | char logStr[128]; 86 | logStr[0] = 0; 87 | 88 | for (int i = 0; i < 128; ++i) { 89 | if (!str[i]) { 90 | logStr[i] = 0; 91 | break; 92 | } 93 | 94 | if (str[i] > 0x7F) { 95 | logStr[i] = '?'; 96 | } else { 97 | logStr[i] = str[i]; 98 | } 99 | } 100 | this->resultStr = logStr; 101 | keyboardOpen = false; 102 | nn::swkbd::DisappearInputForm(); 103 | return true; 104 | } 105 | } 106 | return false; 107 | } 108 | 109 | void KeyboardHelper::drawDRC() { 110 | nn::swkbd::DrawDRC(); 111 | } 112 | 113 | void KeyboardHelper::drawTV() { 114 | nn::swkbd::DrawTV(); 115 | } 116 | -------------------------------------------------------------------------------- /src/menu/KeyboardHelper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class KeyboardHelper { 7 | public: 8 | KeyboardHelper(); 9 | 10 | ~KeyboardHelper(); 11 | 12 | bool checkResult(); 13 | 14 | static void drawTV(); 15 | 16 | static void drawDRC(); 17 | 18 | bool openKeyboard(); 19 | 20 | bool isReady() { 21 | return keyboardCreated; 22 | } 23 | 24 | std::string getResult(); 25 | 26 | private: 27 | void *workMemory = nullptr; 28 | FSClient *fsClient = nullptr; 29 | bool keyboardOpen = false; 30 | bool keyboardCreated = false; 31 | std::string resultStr = ""; 32 | }; 33 | -------------------------------------------------------------------------------- /src/menu/MainDrcButtonsFrame.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 Dimok 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | ****************************************************************************/ 17 | #ifndef _MAIN_DRC_BUTTONS_FRAME_H_ 18 | #define _MAIN_DRC_BUTTONS_FRAME_H_ 19 | 20 | #include "gui/Gui.h" 21 | #include "resources/Resources.h" 22 | 23 | class MainDrcButtonsFrame : public GuiFrame, public sigslot::has_slots<> { 24 | public: 25 | MainDrcButtonsFrame(int32_t w, int32_t h) 26 | : GuiFrame(w, h), buttonClickSound(Resources::GetSound("settings_click_2.mp3")), screenSwitchSound(Resources::GetSound("screenSwitchSound.mp3")), 27 | switchIconData(Resources::GetImageData("layoutSwitchButton.png")), settingsIconData(Resources::GetImageData("settingsButton.png")), switchIcon(switchIconData), 28 | settingsIcon(settingsIconData), switchLayoutButton(switchIcon.getWidth(), switchIcon.getHeight()), settingsButton(settingsIcon.getWidth(), settingsIcon.getHeight()), 29 | gameListFilterButton(w, h), touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH), 30 | wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A), 31 | settingsTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_ZL, true), switchLayoutTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_ZR, true), 32 | plusTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_PLUS, true) { 33 | settingsButton.setClickable(true); 34 | settingsButton.setImage(&settingsIcon); 35 | settingsButton.setTrigger(&touchTrigger); 36 | settingsButton.setTrigger(&wpadTouchTrigger); 37 | settingsButton.setTrigger(&settingsTrigger); 38 | settingsButton.setAlignment(ALIGN_LEFT | ALIGN_BOTTOM); 39 | settingsButton.setSoundClick(buttonClickSound); 40 | settingsButton.setEffectGrow(); 41 | settingsButton.clicked.connect(this, &MainDrcButtonsFrame::OnSettingsButtonClick); 42 | append(&settingsButton); 43 | 44 | switchLayoutButton.setClickable(true); 45 | switchLayoutButton.setImage(&switchIcon); 46 | switchLayoutButton.setTrigger(&touchTrigger); 47 | switchLayoutButton.setTrigger(&wpadTouchTrigger); 48 | switchLayoutButton.setTrigger(&switchLayoutTrigger); 49 | switchLayoutButton.setAlignment(ALIGN_RIGHT | ALIGN_BOTTOM); 50 | switchLayoutButton.setSoundClick(screenSwitchSound); 51 | switchLayoutButton.setEffectGrow(); 52 | switchLayoutButton.clicked.connect(this, &MainDrcButtonsFrame::OnLayoutSwithClick); 53 | append(&switchLayoutButton); 54 | 55 | gameListFilterButton.setClickable(true); 56 | gameListFilterButton.setSoundClick(buttonClickSound); 57 | gameListFilterButton.setTrigger(&plusTrigger); 58 | gameListFilterButton.clicked.connect(this, &MainDrcButtonsFrame::OnGameListFilterButtonClicked); 59 | append(&gameListFilterButton); 60 | } 61 | 62 | virtual ~MainDrcButtonsFrame() { 63 | Resources::RemoveImageData(switchIconData); 64 | Resources::RemoveImageData(settingsIconData); 65 | Resources::RemoveSound(buttonClickSound); 66 | Resources::RemoveSound(screenSwitchSound); 67 | } 68 | 69 | sigslot::signal1 settingsButtonClicked; 70 | sigslot::signal1 layoutSwitchClicked; 71 | sigslot::signal1 gameListFilterClicked; 72 | 73 | private: 74 | void OnSettingsButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *) { 75 | settingsButtonClicked(this); 76 | } 77 | 78 | void OnLayoutSwithClick(GuiButton *button, const GuiController *controller, GuiTrigger *) { 79 | layoutSwitchClicked(this); 80 | } 81 | 82 | void OnGameListFilterButtonClicked(GuiButton *button, const GuiController *controller, GuiTrigger *) { 83 | gameListFilterClicked(this); 84 | } 85 | 86 | GuiSound *buttonClickSound; 87 | GuiSound *screenSwitchSound; 88 | GuiImageData *switchIconData; 89 | GuiImageData *settingsIconData; 90 | GuiImage switchIcon; 91 | GuiImage settingsIcon; 92 | 93 | GuiButton switchLayoutButton; 94 | GuiButton settingsButton; 95 | GuiButton gameListFilterButton; 96 | 97 | GuiTrigger touchTrigger; 98 | GuiTrigger wpadTouchTrigger; 99 | GuiTrigger settingsTrigger; 100 | GuiTrigger switchLayoutTrigger; 101 | GuiTrigger plusTrigger; 102 | }; 103 | 104 | #endif //_SETTINGS_WINDOW_H_ 105 | -------------------------------------------------------------------------------- /src/menu/MainWindow.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 Dimok 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | ****************************************************************************/ 17 | #include "MainWindow.h" 18 | #include "Application.h" 19 | #include "utils/StringTools.h" 20 | #include "utils/logger.h" 21 | 22 | #include "GameSplashScreen.h" 23 | #include "gui/GuiIconGrid.h" 24 | #include "gui/GuiTitleBrowser.h" 25 | #include "resources/Resources.h" 26 | #include "utils/AsyncExecutor.h" 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | MainWindow::MainWindow(int32_t w, int32_t h) 33 | : width(w), height(h), gameClickSound(Resources::GetSound("game_click.mp3")), mainSwitchButtonFrame(nullptr), currentTvFrame(nullptr), currentDrcFrame(nullptr) { 34 | for (int32_t i = 0; i < 4; i++) { 35 | std::string filename = StringTools::strfmt("player%i_point.png", i + 1); 36 | pointerImgData[i] = Resources::GetImageData(filename.c_str()); 37 | pointerImg[i] = new GuiImage(pointerImgData[i]); 38 | pointerImg[i]->setScale(1.5f); 39 | pointerValid[i] = false; 40 | } 41 | SetupMainView(); 42 | gameList.titleListChanged.connect(this, &MainWindow::OnGameTitleListChanged); 43 | gameList.titleUpdated.connect(this, &MainWindow::OnGameTitleUpdated); 44 | gameList.titleAdded.connect(this, &MainWindow::OnGameTitleAdded); 45 | AsyncExecutor::execute([&] { gameList.load(); }); 46 | } 47 | 48 | MainWindow::~MainWindow() { 49 | gameList.titleListChanged.disconnect(this); 50 | gameList.titleUpdated.disconnect(this); 51 | gameList.titleAdded.disconnect(this); 52 | while (!tvElements.empty()) { 53 | delete tvElements[0]; 54 | remove(tvElements[0]); 55 | } 56 | while (!drcElements.empty()) { 57 | delete drcElements[0]; 58 | remove(drcElements[0]); 59 | } 60 | for (int32_t i = 0; i < 4; i++) { 61 | delete pointerImg[i]; 62 | Resources::RemoveImageData(pointerImgData[i]); 63 | } 64 | 65 | Resources::RemoveSound(gameClickSound); 66 | } 67 | 68 | void MainWindow::updateEffects() { 69 | //! dont read behind the initial elements in case one was added 70 | uint32_t tvSize = tvElements.size(); 71 | uint32_t drcSize = drcElements.size(); 72 | 73 | for (uint32_t i = 0; (i < drcSize) && (i < drcElements.size()); ++i) { 74 | drcElements[i]->updateEffects(); 75 | } 76 | 77 | //! only update TV elements that are not updated yet because they are on DRC 78 | for (uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) { 79 | uint32_t n; 80 | for (n = 0; (n < drcSize) && (n < drcElements.size()); n++) { 81 | if (tvElements[i] == drcElements[n]) 82 | break; 83 | } 84 | if (n == drcElements.size()) { 85 | tvElements[i]->updateEffects(); 86 | } 87 | } 88 | } 89 | 90 | void MainWindow::process() { 91 | //! dont read behind the initial elements in case one was added 92 | uint32_t tvSize = tvElements.size(); 93 | uint32_t drcSize = drcElements.size(); 94 | 95 | for (uint32_t i = 0; (i < drcSize) && (i < drcElements.size()); ++i) { 96 | drcElements[i]->process(); 97 | } 98 | 99 | //! only update TV elements that are not updated yet because they are on DRC 100 | for (uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) { 101 | uint32_t n; 102 | for (n = 0; (n < drcSize) && (n < drcElements.size()); n++) { 103 | if (tvElements[i] == drcElements[n]) 104 | break; 105 | } 106 | if (n == drcElements.size()) { 107 | tvElements[i]->process(); 108 | } 109 | } 110 | 111 | if (keyboardInstance != nullptr) { 112 | if (keyboardInstance->checkResult()) { 113 | std::string result = keyboardInstance->getResult(); 114 | 115 | currentTvFrame->clearState(GuiElement::STATE_DISABLED); 116 | currentDrcFrame->clearState(GuiElement::STATE_DISABLED); 117 | mainSwitchButtonFrame->clearState(GuiElement::STATE_DISABLED); 118 | } else { 119 | } 120 | } 121 | } 122 | 123 | void MainWindow::OnGameTitleListChanged(GameList *list) { 124 | currentTvFrame->OnGameTitleListUpdated(list); 125 | if (currentTvFrame != currentDrcFrame) { 126 | currentDrcFrame->OnGameTitleListUpdated(list); 127 | } 128 | } 129 | 130 | void MainWindow::OnGameTitleUpdated(gameInfo *info) { 131 | currentTvFrame->OnGameTitleUpdated(info); 132 | if (currentTvFrame != currentDrcFrame) { 133 | currentDrcFrame->OnGameTitleUpdated(info); 134 | } 135 | } 136 | 137 | void MainWindow::OnGameTitleAdded(gameInfo *info) { 138 | currentTvFrame->OnGameTitleAdded(info); 139 | if (currentTvFrame != currentDrcFrame) { 140 | currentDrcFrame->OnGameTitleAdded(info); 141 | } 142 | } 143 | 144 | void MainWindow::update(GuiController *controller) { 145 | //! dont read behind the initial elements in case one was added 146 | //uint32_t tvSize = tvElements.size(); 147 | 148 | if (controller->chan & GuiTrigger::CHANNEL_1) { 149 | uint32_t drcSize = drcElements.size(); 150 | 151 | for (uint32_t i = 0; (i < drcSize) && (i < drcElements.size()); ++i) { 152 | drcElements[i]->update(controller); 153 | } 154 | } else { 155 | uint32_t tvSize = tvElements.size(); 156 | 157 | for (uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) { 158 | tvElements[i]->update(controller); 159 | } 160 | } 161 | 162 | // //! only update TV elements that are not updated yet because they are on DRC 163 | // for(uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) 164 | // { 165 | // uint32_t n; 166 | // for(n = 0; (n < drcSize) && (n < drcElements.size()); n++) 167 | // { 168 | // if(tvElements[i] == drcElements[n]) 169 | // break; 170 | // } 171 | // if(n == drcElements.size()) 172 | // { 173 | // tvElements[i]->update(controller); 174 | // } 175 | // } 176 | 177 | if (controller->chanIdx >= 1 && controller->chanIdx <= 4 && controller->data.validPointer) { 178 | int32_t wpadIdx = controller->chanIdx - 1; 179 | float posX = controller->data.x; 180 | float posY = controller->data.y; 181 | pointerImg[wpadIdx]->setPosition(posX, posY); 182 | pointerImg[wpadIdx]->setAngle(controller->data.pointerAngle); 183 | pointerValid[wpadIdx] = true; 184 | } 185 | } 186 | 187 | void MainWindow::drawDrc(CVideo *video) { 188 | for (uint32_t i = 0; i < drcElements.size(); ++i) { 189 | drcElements[i]->draw(video); 190 | } 191 | 192 | for (int32_t i = 0; i < 4; i++) { 193 | if (pointerValid[i]) { 194 | pointerImg[i]->setAlpha(0.5f); 195 | pointerImg[i]->draw(video); 196 | pointerImg[i]->setAlpha(1.0f); 197 | } 198 | } 199 | 200 | if (keyboardInstance != nullptr) { 201 | keyboardInstance->drawDRC(); 202 | } 203 | } 204 | 205 | void MainWindow::drawTv(CVideo *video) { 206 | for (uint32_t i = 0; i < tvElements.size(); ++i) { 207 | tvElements[i]->draw(video); 208 | } 209 | 210 | for (int32_t i = 0; i < 4; i++) { 211 | if (pointerValid[i]) { 212 | pointerImg[i]->draw(video); 213 | pointerValid[i] = false; 214 | } 215 | } 216 | if (keyboardInstance != nullptr) { 217 | keyboardInstance->drawTV(); 218 | } 219 | } 220 | 221 | void MainWindow::SetupMainView() { 222 | currentTvFrame = new GuiIconGrid(width, height, 0, true); 223 | 224 | currentTvFrame->setEffect(EFFECT_FADE, 10, 255); 225 | currentTvFrame->setState(GuiElement::STATE_DISABLED); 226 | currentTvFrame->effectFinished.connect(this, &MainWindow::OnOpenEffectFinish); 227 | 228 | appendTv(currentTvFrame); 229 | 230 | currentDrcFrame = new GuiIconGrid(width, height, 0, false); 231 | currentDrcFrame->setEffect(EFFECT_FADE, 10, 255); 232 | currentDrcFrame->setState(GuiElement::STATE_DISABLED); 233 | currentDrcFrame->effectFinished.connect(this, &MainWindow::OnOpenEffectFinish); 234 | 235 | if (currentTvFrame != currentDrcFrame) { 236 | currentDrcFrame->setEffect(EFFECT_FADE, 10, 255); 237 | currentDrcFrame->setState(GuiElement::STATE_DISABLED); 238 | currentDrcFrame->effectFinished.connect(this, &MainWindow::OnOpenEffectFinish); 239 | } 240 | 241 | //! reconnect only to DRC game selection change 242 | currentTvFrame->gameSelectionChanged.disconnect(this); 243 | currentDrcFrame->gameSelectionChanged.disconnect(this); 244 | currentTvFrame->gameLaunchClicked.disconnect(this); 245 | currentDrcFrame->gameLaunchClicked.disconnect(this); 246 | 247 | 248 | if (currentTvFrame != currentDrcFrame) { 249 | currentTvFrame->gameSelectionChanged.connect(this, &MainWindow::OnGameSelectionChange); 250 | currentTvFrame->gameLaunchClicked.connect(this, &MainWindow::OnGameLaunchSplashScreen); 251 | } 252 | 253 | currentDrcFrame->gameSelectionChanged.connect(this, &MainWindow::OnGameSelectionChange); 254 | currentDrcFrame->gameLaunchClicked.connect(this, &MainWindow::OnGameLaunchSplashScreen); 255 | 256 | mainSwitchButtonFrame = new MainDrcButtonsFrame(width, height); 257 | mainSwitchButtonFrame->settingsButtonClicked.connect(this, &MainWindow::OnSettingsButtonClicked); 258 | mainSwitchButtonFrame->layoutSwitchClicked.connect(this, &MainWindow::OnLayoutSwitchClicked); 259 | mainSwitchButtonFrame->gameListFilterClicked.connect(this, &MainWindow::OnGameListFilterButtonClicked); 260 | mainSwitchButtonFrame->setState(GuiElement::STATE_DISABLED); 261 | mainSwitchButtonFrame->setEffect(EFFECT_FADE, 10, 255); 262 | mainSwitchButtonFrame->setState(GuiElement::STATE_DISABLED); 263 | mainSwitchButtonFrame->effectFinished.connect(this, &MainWindow::OnOpenEffectFinish); 264 | 265 | appendDrc(currentDrcFrame); 266 | append(mainSwitchButtonFrame); 267 | } 268 | 269 | void MainWindow::OnLayoutSwitchClicked(GuiElement *element) { 270 | if (!currentTvFrame || !currentDrcFrame || !mainSwitchButtonFrame) { 271 | return; 272 | } 273 | 274 | if (currentTvFrame == currentDrcFrame) { 275 | return; 276 | } 277 | 278 | currentTvFrame->setState(GuiElement::STATE_DISABLED); 279 | currentTvFrame->setEffect(EFFECT_FADE, -15, 0); 280 | currentTvFrame->effectFinished.connect(this, &MainWindow::OnLayoutSwitchEffectFinish); 281 | 282 | currentDrcFrame->setState(GuiElement::STATE_DISABLED); 283 | currentDrcFrame->setEffect(EFFECT_FADE, -15, 0); 284 | 285 | mainSwitchButtonFrame->setState(GuiElement::STATE_DISABLED); 286 | } 287 | 288 | void MainWindow::OnGameListFilterButtonClicked(GuiElement *element) { 289 | if (!currentTvFrame || !currentDrcFrame || !mainSwitchButtonFrame) { 290 | return; 291 | } 292 | 293 | if (keyboardInstance == nullptr) { 294 | keyboardInstance = new KeyboardHelper(); 295 | } 296 | if (keyboardInstance->isReady()) { 297 | if (keyboardInstance->openKeyboard()) { 298 | currentTvFrame->setState(GuiElement::STATE_DISABLED); 299 | currentDrcFrame->setState(GuiElement::STATE_DISABLED); 300 | mainSwitchButtonFrame->setState(GuiElement::STATE_DISABLED); 301 | } 302 | } 303 | } 304 | 305 | void MainWindow::OnLayoutSwitchEffectFinish(GuiElement *element) { 306 | if (!currentTvFrame || !currentDrcFrame || !mainSwitchButtonFrame) 307 | return; 308 | 309 | element->effectFinished.disconnect(this); 310 | remove(currentDrcFrame); 311 | remove(currentTvFrame); 312 | 313 | GuiTitleBrowser *tmpElement = currentDrcFrame; 314 | currentDrcFrame = currentTvFrame; 315 | currentTvFrame = tmpElement; 316 | 317 | appendTv(currentTvFrame); 318 | appendDrc(currentDrcFrame); 319 | //! re-append on top 320 | append(mainSwitchButtonFrame); 321 | 322 | currentTvFrame->resetState(); 323 | currentTvFrame->setEffect(EFFECT_FADE, 15, 255); 324 | 325 | currentDrcFrame->resetState(); 326 | currentDrcFrame->setEffect(EFFECT_FADE, 15, 255); 327 | 328 | mainSwitchButtonFrame->clearState(GuiElement::STATE_DISABLED); 329 | 330 | //! reconnect only to DRC game selection change 331 | currentTvFrame->gameSelectionChanged.disconnect(this); 332 | currentDrcFrame->gameSelectionChanged.disconnect(this); 333 | currentTvFrame->gameLaunchClicked.disconnect(this); 334 | currentDrcFrame->gameLaunchClicked.disconnect(this); 335 | 336 | currentTvFrame->gameSelectionChanged.connect(this, &MainWindow::OnGameSelectionChange); 337 | currentTvFrame->gameLaunchClicked.connect(this, &MainWindow::OnGameLaunchSplashScreen); 338 | currentDrcFrame->gameSelectionChanged.connect(this, &MainWindow::OnGameSelectionChange); 339 | currentDrcFrame->gameLaunchClicked.connect(this, &MainWindow::OnGameLaunchSplashScreen); 340 | } 341 | 342 | void MainWindow::OnOpenEffectFinish(GuiElement *element) { 343 | //! once the menu is open reset its state and allow it to be "clicked/hold" 344 | element->effectFinished.disconnect(this); 345 | element->clearState(GuiElement::STATE_DISABLED); 346 | } 347 | 348 | void MainWindow::OnCloseEffectFinish(GuiElement *element) { 349 | DEBUG_FUNCTION_LINE("Remove %08X", element); 350 | //! remove element from draw list and push to delete queue 351 | remove(element); 352 | AsyncExecutor::pushForDelete(element); 353 | } 354 | 355 | void MainWindow::OnSettingsButtonClicked(GuiElement *element) { 356 | } 357 | 358 | void MainWindow::OnGameSelectionChange(GuiTitleBrowser *element, uint64_t selectedIdx) { 359 | if (!currentDrcFrame || !currentTvFrame) 360 | return; 361 | 362 | if (element == currentDrcFrame && currentDrcFrame != currentTvFrame) { 363 | currentTvFrame->setSelectedGame(selectedIdx); 364 | } else if (element == currentTvFrame && currentDrcFrame != currentTvFrame) { 365 | currentDrcFrame->setSelectedGame(selectedIdx); 366 | } 367 | } 368 | 369 | void MainWindow::OnGameLaunchSplashScreen(GuiTitleBrowser *element, uint64_t titleID) { 370 | DEBUG_FUNCTION_LINE(""); 371 | gameInfo *info = gameList.getGameInfo(titleID); 372 | if (info != nullptr) { 373 | auto *splashScreenDRC = new GameSplashScreen(width, height, info, false); 374 | splashScreenDRC->setEffect(EFFECT_FADE, 15, 255); 375 | splashScreenDRC->setState(GuiElement::STATE_DISABLED); 376 | splashScreenDRC->effectFinished.connect(this, &MainWindow::OnOpenEffectFinish); 377 | splashScreenDRC->gameGameSplashScreenFinished.connect(this, &MainWindow::OnGameLaunchSplashScreenFinished); 378 | appendDrc(splashScreenDRC); 379 | 380 | auto *splashScreenTV = new GameSplashScreen(width, height, info, true); 381 | splashScreenTV->setEffect(EFFECT_FADE, 15, 255); 382 | splashScreenTV->setState(GuiElement::STATE_DISABLED); 383 | splashScreenTV->effectFinished.connect(this, &MainWindow::OnOpenEffectFinish); 384 | splashScreenTV->gameGameSplashScreenFinished.connect(this, &MainWindow::OnGameLaunchSplashScreenFinished); 385 | appendTv(splashScreenTV); 386 | } else { 387 | DEBUG_FUNCTION_LINE("Failed to find gameInfo for titleId %016llX", titleID); 388 | } 389 | } 390 | 391 | void MainWindow::OnGameLaunchSplashScreenFinished(GuiElement *element, gameInfo *info, bool launchGame) { 392 | if (info == nullptr) { 393 | return; 394 | } 395 | if (launchGame) { 396 | OnGameLaunch(info->titleId); 397 | } 398 | if (element) { 399 | // immediately remove the splashScreen 400 | MainWindow::OnCloseEffectFinish(element); 401 | } 402 | } 403 | 404 | extern "C" int32_t SYSSwitchToBrowser(void *); 405 | extern "C" int32_t SYSSwitchToEShop(void *); 406 | extern "C" int32_t _SYSSwitchTo(uint32_t pfid); 407 | 408 | void MainWindow::OnGameLaunch(uint64_t titleId) { 409 | DEBUG_FUNCTION_LINE("Launch GAME!!"); 410 | 411 | if (titleId == 0x0005001010040000L || 412 | titleId == 0x0005001010040100L || 413 | titleId == 0x0005001010040200L) { 414 | DEBUG_FUNCTION_LINE("Skip launching the Wii U Menu"); 415 | return; 416 | } 417 | 418 | if (titleId == 0x000500301001220AL || 419 | titleId == 0x000500301001210AL || 420 | titleId == 0x000500301001200AL) { 421 | DEBUG_FUNCTION_LINE("Launching the browser"); 422 | SYSSwitchToBrowser(nullptr); 423 | return; 424 | } 425 | if (titleId == 0x000500301001400AL || 426 | titleId == 0x000500301001410AL || 427 | titleId == 0x000500301001420AL) { 428 | DEBUG_FUNCTION_LINE("Launching the Eshop"); 429 | SYSSwitchToEShop(nullptr); 430 | 431 | return; 432 | } 433 | if (titleId == 0x000500301001800AL || 434 | titleId == 0x000500301001810AL || 435 | titleId == 0x000500301001820AL) { 436 | DEBUG_FUNCTION_LINE("Launching the Download Management"); 437 | _SYSSwitchTo(12); 438 | return; 439 | } 440 | if (titleId == 0x000500301001600AL || 441 | titleId == 0x000500301001610AL || 442 | titleId == 0x000500301001620AL) { 443 | DEBUG_FUNCTION_LINE("Launching Miiverse"); 444 | _SYSSwitchTo(9); 445 | return; 446 | } 447 | if (titleId == 0x000500301001500AL || 448 | titleId == 0x000500301001510AL || 449 | titleId == 0x000500301001520AL) { 450 | DEBUG_FUNCTION_LINE("Launching Friendlist"); 451 | _SYSSwitchTo(11); 452 | return; 453 | } 454 | if (titleId == 0x000500301001300AL || 455 | titleId == 0x000500301001310AL || 456 | titleId == 0x000500301001320AL) { 457 | DEBUG_FUNCTION_LINE("Launching TVii"); 458 | _SYSSwitchTo(3); 459 | return; 460 | } 461 | 462 | MCPTitleListType titleInfo; 463 | int32_t handle = MCP_Open(); 464 | auto err = MCP_GetTitleInfo(handle, titleId, &titleInfo); 465 | MCP_Close(handle); 466 | if (err == 0) { 467 | ACPAssignTitlePatch(&titleInfo); 468 | _SYSLaunchTitleWithStdArgsInNoSplash(titleId, nullptr); 469 | return; 470 | } 471 | 472 | DEBUG_FUNCTION_LINE("Failed launch titleId %016llX", titleId); 473 | } 474 | -------------------------------------------------------------------------------- /src/menu/MainWindow.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 Dimok 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | ****************************************************************************/ 17 | #ifndef _MAIN_WINDOW_H_ 18 | #define _MAIN_WINDOW_H_ 19 | 20 | #include "KeyboardHelper.h" 21 | #include "MainDrcButtonsFrame.h" 22 | #include "game/GameList.h" 23 | #include "gui/GuiTitleBrowser.h" 24 | #include 25 | #include 26 | #include 27 | 28 | class CVideo; 29 | 30 | class MainWindow : public sigslot::has_slots<> { 31 | public: 32 | MainWindow(int32_t w, int32_t h); 33 | 34 | virtual ~MainWindow(); 35 | 36 | void appendTv(GuiElement *e) { 37 | if (!e) 38 | return; 39 | 40 | removeTv(e); 41 | tvElements.push_back(e); 42 | } 43 | 44 | void appendDrc(GuiElement *e) { 45 | if (!e) 46 | return; 47 | 48 | removeDrc(e); 49 | drcElements.push_back(e); 50 | } 51 | 52 | void append(GuiElement *e) { 53 | appendTv(e); 54 | appendDrc(e); 55 | } 56 | 57 | void insertTv(uint32_t pos, GuiElement *e) { 58 | if (!e) 59 | return; 60 | 61 | removeTv(e); 62 | tvElements.insert(tvElements.begin() + pos, e); 63 | } 64 | 65 | void insertDrc(uint32_t pos, GuiElement *e) { 66 | if (!e) 67 | return; 68 | 69 | removeDrc(e); 70 | drcElements.insert(drcElements.begin() + pos, e); 71 | } 72 | 73 | void insert(uint32_t pos, GuiElement *e) { 74 | insertTv(pos, e); 75 | insertDrc(pos, e); 76 | } 77 | 78 | void removeTv(GuiElement *e) { 79 | for (uint32_t i = 0; i < tvElements.size(); ++i) { 80 | if (e == tvElements[i]) { 81 | tvElements.erase(tvElements.begin() + i); 82 | break; 83 | } 84 | } 85 | } 86 | 87 | void removeDrc(GuiElement *e) { 88 | for (uint32_t i = 0; i < drcElements.size(); ++i) { 89 | if (e == drcElements[i]) { 90 | drcElements.erase(drcElements.begin() + i); 91 | break; 92 | } 93 | } 94 | } 95 | 96 | void remove(GuiElement *e) { 97 | removeTv(e); 98 | removeDrc(e); 99 | } 100 | 101 | void removeAll() { 102 | tvElements.clear(); 103 | drcElements.clear(); 104 | } 105 | 106 | void drawDrc(CVideo *video); 107 | 108 | void drawTv(CVideo *video); 109 | 110 | void update(GuiController *controller); 111 | 112 | void updateEffects(); 113 | 114 | void process(); 115 | 116 | void lockGUI() { 117 | guiMutex.lock(); 118 | } 119 | 120 | void unlockGUI() { 121 | guiMutex.unlock(); 122 | } 123 | 124 | private: 125 | void SetupMainView(void); 126 | 127 | void OnOpenEffectFinish(GuiElement *element); 128 | 129 | void OnCloseEffectFinish(GuiElement *element); 130 | 131 | static void OnGameLaunch(uint64_t titleId); 132 | 133 | void OnGameLaunchSplashScreenFinished(GuiElement *element, gameInfo *info, bool launchGame); 134 | 135 | void OnGameLaunchSplashScreen(GuiTitleBrowser *element, uint64_t titleId); 136 | 137 | void OnGameSelectionChange(GuiTitleBrowser *element, uint64_t titleId); 138 | 139 | void OnSettingsButtonClicked(GuiElement *element); 140 | 141 | void OnLayoutSwitchClicked(GuiElement *element); 142 | 143 | void OnLayoutSwitchEffectFinish(GuiElement *element); 144 | 145 | void OnGameListFilterButtonClicked(GuiElement *element); 146 | 147 | void OnGameTitleListChanged(GameList *list); 148 | 149 | void OnGameTitleUpdated(gameInfo *info); 150 | 151 | void OnGameTitleAdded(gameInfo *info); 152 | 153 | int32_t width, height; 154 | std::vector drcElements; 155 | std::vector tvElements; 156 | 157 | GuiSound *gameClickSound; 158 | 159 | MainDrcButtonsFrame *mainSwitchButtonFrame; 160 | 161 | GuiTitleBrowser *currentTvFrame; 162 | GuiTitleBrowser *currentDrcFrame; 163 | 164 | GuiImageData *pointerImgData[4]; 165 | GuiImage *pointerImg[4]; 166 | bool pointerValid[4]; 167 | 168 | GameList gameList; 169 | 170 | std::recursive_mutex guiMutex; 171 | KeyboardHelper *keyboardInstance = nullptr; 172 | }; 173 | 174 | #endif //_MAIN_WINDOW_H_ 175 | -------------------------------------------------------------------------------- /src/resources/Resources.cpp: -------------------------------------------------------------------------------- 1 | #include "Resources.h" 2 | #include "filelist.h" 3 | #include "fs/FSUtils.h" 4 | #include "utils/AsyncExecutor.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | Resources *Resources::instance = nullptr; 19 | 20 | void Resources::Clear() { 21 | for (int32_t i = 0; RecourceList[i].filename != nullptr; ++i) { 22 | if (RecourceList[i].CustomFile) { 23 | free(RecourceList[i].CustomFile); 24 | RecourceList[i].CustomFile = nullptr; 25 | } 26 | 27 | if (RecourceList[i].CustomFileSize != 0) 28 | RecourceList[i].CustomFileSize = 0; 29 | } 30 | 31 | if (instance) 32 | delete instance; 33 | 34 | instance = nullptr; 35 | } 36 | 37 | bool Resources::LoadFiles(const char *path) { 38 | if (!path) 39 | return false; 40 | 41 | bool result = false; 42 | Clear(); 43 | 44 | for (int32_t i = 0; RecourceList[i].filename != nullptr; ++i) { 45 | std::string fullpath(path); 46 | fullpath += "/"; 47 | fullpath += RecourceList[i].filename; 48 | 49 | uint8_t *buffer = nullptr; 50 | uint32_t filesize = 0; 51 | 52 | FSUtils::LoadFileToMem(fullpath.c_str(), &buffer, &filesize); 53 | 54 | RecourceList[i].CustomFile = buffer; 55 | RecourceList[i].CustomFileSize = (uint32_t) filesize; 56 | result |= (buffer != 0); 57 | } 58 | 59 | return result; 60 | } 61 | 62 | const uint8_t *Resources::GetFile(const char *filename) { 63 | for (int32_t i = 0; RecourceList[i].filename != nullptr; ++i) { 64 | if (strcasecmp(filename, RecourceList[i].filename) == 0) { 65 | return (RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile); 66 | } 67 | } 68 | 69 | return nullptr; 70 | } 71 | 72 | uint32_t Resources::GetFileSize(const char *filename) { 73 | for (int32_t i = 0; RecourceList[i].filename != nullptr; ++i) { 74 | if (strcasecmp(filename, RecourceList[i].filename) == 0) { 75 | return (RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize); 76 | } 77 | } 78 | return 0; 79 | } 80 | 81 | GuiImageData *Resources::GetImageData(const char *filename) { 82 | if (!instance) 83 | instance = new Resources; 84 | 85 | std::map>::iterator itr = instance->imageDataMap.find(std::string(filename)); 86 | if (itr != instance->imageDataMap.end()) { 87 | itr->second.first++; 88 | return itr->second.second; 89 | } 90 | 91 | for (int32_t i = 0; RecourceList[i].filename != nullptr; ++i) { 92 | if (strcasecmp(filename, RecourceList[i].filename) == 0) { 93 | const uint8_t *buff = RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile; 94 | const uint32_t size = RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize; 95 | 96 | if (buff == nullptr) 97 | return nullptr; 98 | 99 | GuiImageData *image = new GuiImageData(buff, size); 100 | instance->imageDataMap[std::string(filename)].first = 1; 101 | instance->imageDataMap[std::string(filename)].second = image; 102 | 103 | return image; 104 | } 105 | } 106 | 107 | return nullptr; 108 | } 109 | 110 | void Resources::RemoveImageData(GuiImageData *image) { 111 | std::map>::iterator itr; 112 | 113 | for (itr = instance->imageDataMap.begin(); itr != instance->imageDataMap.end(); itr++) { 114 | if (itr->second.second == image) { 115 | itr->second.first--; 116 | 117 | if (itr->second.first == 0) { 118 | AsyncExecutor::pushForDelete(itr->second.second); 119 | 120 | instance->imageDataMap.erase(itr); 121 | } 122 | break; 123 | } 124 | } 125 | } 126 | 127 | GuiSound *Resources::GetSound(const char *filename) { 128 | if (!instance) 129 | instance = new Resources; 130 | 131 | std::map>::iterator itr = instance->soundDataMap.find(std::string(filename)); 132 | if (itr != instance->soundDataMap.end()) { 133 | itr->second.first++; 134 | return itr->second.second; 135 | } 136 | 137 | for (int32_t i = 0; RecourceList[i].filename != nullptr; ++i) { 138 | if (strcasecmp(filename, RecourceList[i].filename) == 0) { 139 | const uint8_t *buff = RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile; 140 | const uint32_t size = RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize; 141 | 142 | if (buff == nullptr) 143 | return nullptr; 144 | 145 | GuiSound *sound = new GuiSound(buff, size); 146 | instance->soundDataMap[std::string(filename)].first = 1; 147 | instance->soundDataMap[std::string(filename)].second = sound; 148 | 149 | return sound; 150 | } 151 | } 152 | 153 | return nullptr; 154 | } 155 | 156 | void Resources::RemoveSound(GuiSound *sound) { 157 | std::map>::iterator itr; 158 | 159 | for (itr = instance->soundDataMap.begin(); itr != instance->soundDataMap.end(); itr++) { 160 | if (itr->second.second == sound) { 161 | itr->second.first--; 162 | 163 | if (itr->second.first == 0) { 164 | AsyncExecutor::pushForDelete(itr->second.second); 165 | instance->soundDataMap.erase(itr); 166 | } 167 | break; 168 | } 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /src/resources/Resources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | //! forward declaration 8 | class GuiImageData; 9 | 10 | class GuiSound; 11 | 12 | class Resources { 13 | public: 14 | static void Clear(); 15 | 16 | static bool LoadFiles(const char *path); 17 | 18 | static const uint8_t *GetFile(const char *filename); 19 | 20 | static uint32_t GetFileSize(const char *filename); 21 | 22 | static GuiImageData *GetImageData(const char *filename); 23 | 24 | static void RemoveImageData(GuiImageData *image); 25 | 26 | static GuiSound *GetSound(const char *filename); 27 | 28 | static void RemoveSound(GuiSound *sound); 29 | 30 | private: 31 | static Resources *instance; 32 | 33 | Resources() {} 34 | 35 | ~Resources() {} 36 | 37 | std::map> imageDataMap; 38 | std::map> soundDataMap; 39 | }; -------------------------------------------------------------------------------- /src/system/CThread.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 Dimok 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | ****************************************************************************/ 17 | #ifndef CTHREAD_H_ 18 | #define CTHREAD_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | class CThread { 25 | public: 26 | typedef void (*Callback)(CThread *thread, void *arg); 27 | 28 | //! constructor 29 | CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = nullptr, void *callbackArg = nullptr) 30 | : pThread(nullptr), pThreadStack(nullptr), pCallback(callback), pCallbackArg(callbackArg) { 31 | //! save attribute assignment 32 | iAttributes = iAttr; 33 | //! allocate the thread 34 | pThread = (OSThread *) memalign(8, sizeof(OSThread)); 35 | //! allocate the stack 36 | pThreadStack = (uint8_t *) memalign(0x20, iStackSize); 37 | //! create the thread 38 | if (pThread && pThreadStack) 39 | OSCreateThread(pThread, &CThread::threadCallback, 1, (char *) this, pThreadStack + iStackSize, iStackSize, iPriority, iAttributes); 40 | } 41 | 42 | //! destructor 43 | virtual ~CThread() { 44 | shutdownThread(); 45 | } 46 | 47 | static CThread *create(CThread::Callback callback, void *callbackArg, int32_t iAttr = eAttributeNone, int32_t iPriority = 16, int32_t iStackSize = 0x8000) { 48 | return (new CThread(iAttr, iPriority, iStackSize, callback, callbackArg)); 49 | } 50 | 51 | //! Get thread ID 52 | virtual void *getThread() const { 53 | return pThread; 54 | } 55 | //! Thread entry function 56 | virtual void executeThread(void) { 57 | if (pCallback) 58 | pCallback(this, pCallbackArg); 59 | } 60 | //! Suspend thread 61 | virtual void suspendThread(void) { 62 | if (isThreadSuspended()) 63 | return; 64 | if (pThread) 65 | OSSuspendThread(pThread); 66 | } 67 | //! Resume thread 68 | virtual void resumeThread(void) { 69 | if (!isThreadSuspended()) 70 | return; 71 | if (pThread) 72 | OSResumeThread(pThread); 73 | } 74 | //! Set thread priority 75 | virtual void setThreadPriority(int32_t prio) { 76 | if (pThread) 77 | OSSetThreadPriority(pThread, prio); 78 | } 79 | //! Check if thread is suspended 80 | virtual bool isThreadSuspended(void) const { 81 | if (pThread) 82 | return OSIsThreadSuspended(pThread); 83 | return false; 84 | } 85 | //! Check if thread is terminated 86 | virtual bool isThreadTerminated(void) const { 87 | if (pThread) 88 | return OSIsThreadTerminated(pThread); 89 | return false; 90 | } 91 | //! Check if thread is running 92 | virtual bool isThreadRunning(void) const { 93 | return !isThreadSuspended() && !isThreadRunning(); 94 | } 95 | //! Shutdown thread 96 | virtual void shutdownThread(void) { 97 | //! wait for thread to finish 98 | if (pThread && !(iAttributes & eAttributeDetach)) { 99 | if (isThreadSuspended()) 100 | resumeThread(); 101 | 102 | OSJoinThread(pThread, nullptr); 103 | } 104 | //! free the thread stack buffer 105 | if (pThreadStack) 106 | free(pThreadStack); 107 | if (pThread) 108 | free(pThread); 109 | 110 | pThread = nullptr; 111 | pThreadStack = nullptr; 112 | } 113 | //! Thread attributes 114 | enum eCThreadAttributes { 115 | eAttributeNone = 0x07, 116 | eAttributeAffCore0 = 0x01, 117 | eAttributeAffCore1 = 0x02, 118 | eAttributeAffCore2 = 0x04, 119 | eAttributeDetach = 0x08, 120 | eAttributePinnedAff = 0x10 121 | }; 122 | 123 | private: 124 | static int32_t threadCallback(int32_t argc, const char **argv) { 125 | //! After call to start() continue with the internal function 126 | ((CThread *) argv)->executeThread(); 127 | return 0; 128 | } 129 | int32_t iAttributes; 130 | OSThread *pThread; 131 | uint8_t *pThreadStack; 132 | Callback pCallback; 133 | void *pCallbackArg; 134 | }; 135 | 136 | #endif 137 | -------------------------------------------------------------------------------- /src/utils/AsyncExecutor.cpp: -------------------------------------------------------------------------------- 1 | #include "AsyncExecutor.h" 2 | #include "utils/logger.h" 3 | 4 | AsyncExecutor *AsyncExecutor::instance = nullptr; 5 | 6 | void AsyncExecutor::pushForDeleteInternal(GuiElement *ptr) { 7 | deleteListMutex.lock(); 8 | deleteList.push(ptr); 9 | deleteListMutex.unlock(); 10 | } 11 | 12 | AsyncExecutor::AsyncExecutor() { 13 | thread = new std::thread([&]() { 14 | while (!exitThread) { 15 | mutex.lock(); 16 | bool emptyList = elements.empty(); 17 | auto it = elements.begin(); 18 | while (it != elements.end()) { 19 | auto future = it; 20 | auto status = future->wait_for(std::chrono::seconds(0)); 21 | if (status == std::future_status::ready) { 22 | it = elements.erase(it); 23 | } else { 24 | ++it; 25 | } 26 | } 27 | if (!emptyList && elements.empty()) { 28 | DEBUG_FUNCTION_LINE("All tasks are done"); 29 | } 30 | mutex.unlock(); 31 | deleteListMutex.lock(); 32 | while (!deleteList.empty()) { 33 | GuiElement *ptr = deleteList.front(); 34 | deleteList.pop(); 35 | delete ptr; 36 | } 37 | deleteListMutex.unlock(); 38 | 39 | std::this_thread::sleep_for(std::chrono::milliseconds(16)); 40 | DCFlushRange((void *) &exitThread, sizeof(exitThread)); 41 | } 42 | }); 43 | } 44 | 45 | AsyncExecutor::~AsyncExecutor() { 46 | exitThread = true; 47 | DCFlushRange((void *) &exitThread, sizeof(exitThread)); 48 | thread->join(); 49 | } 50 | 51 | void AsyncExecutor::executeInternal(std::function func) { 52 | if (elements.size() > 10) { 53 | DEBUG_FUNCTION_LINE("Warning, many tasks running currently"); 54 | //std::this_thread::sleep_for(std::chrono::milliseconds(16)); 55 | } 56 | DEBUG_FUNCTION_LINE("Add new task"); 57 | mutex.lock(); 58 | elements.push_back(std::async(std::launch::async, func)); 59 | mutex.unlock(); 60 | } 61 | -------------------------------------------------------------------------------- /src/utils/AsyncExecutor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "utils/logger.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class AsyncExecutor { 12 | public: 13 | static void pushForDelete(GuiElement *element) { 14 | if (!instance) { 15 | instance = new AsyncExecutor(); 16 | } 17 | instance->pushForDeleteInternal(element); 18 | } 19 | 20 | static void execute(std::function func) { 21 | if (!instance) { 22 | instance = new AsyncExecutor(); 23 | } 24 | instance->executeInternal(func); 25 | } 26 | 27 | static void destroyInstance() { 28 | if (instance) { 29 | delete instance; 30 | instance = nullptr; 31 | } 32 | } 33 | 34 | private: 35 | static AsyncExecutor *instance; 36 | 37 | AsyncExecutor(); 38 | 39 | ~AsyncExecutor(); 40 | 41 | void pushForDeleteInternal(GuiElement *element); 42 | 43 | void executeInternal(std::function func); 44 | 45 | std::recursive_mutex mutex; 46 | std::thread *thread; 47 | volatile bool exitThread = false; 48 | 49 | std::vector> elements; 50 | 51 | std::recursive_mutex deleteListMutex; 52 | std::queue deleteList; 53 | }; 54 | -------------------------------------------------------------------------------- /src/utils/StringTools.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2010 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | * 24 | * for WiiXplorer 2010 25 | ***************************************************************************/ 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | 38 | BOOL StringTools::EndsWith(const std::string &a, const std::string &b) { 39 | if (b.size() > a.size()) 40 | return false; 41 | return std::equal(a.begin() + a.size() - b.size(), a.end(), b.begin()); 42 | } 43 | 44 | const char *StringTools::byte_to_binary(int32_t x) { 45 | static char b[9]; 46 | b[0] = '\0'; 47 | 48 | int32_t z; 49 | for (z = 128; z > 0; z >>= 1) { 50 | strcat(b, ((x & z) == z) ? "1" : "0"); 51 | } 52 | 53 | return b; 54 | } 55 | 56 | std::string StringTools::removeCharFromString(std::string &input, char toBeRemoved) { 57 | std::string output = input; 58 | size_t position; 59 | while (1) { 60 | position = output.find(toBeRemoved); 61 | if (position == std::string::npos) 62 | break; 63 | output.erase(position, 1); 64 | } 65 | return output; 66 | } 67 | 68 | const char *StringTools::fmt(const char *format, ...) { 69 | static char strChar[512]; 70 | strChar[0] = 0; 71 | 72 | va_list va; 73 | va_start(va, format); 74 | if ((vsprintf(strChar, format, va) >= 0)) { 75 | va_end(va); 76 | return (const char *) strChar; 77 | } 78 | va_end(va); 79 | 80 | return nullptr; 81 | } 82 | 83 | const wchar_t *StringTools::wfmt(const char *format, ...) { 84 | static char tmp[512]; 85 | static wchar_t strWChar[512]; 86 | strWChar[0] = 0; 87 | tmp[0] = 0; 88 | 89 | if (!format) 90 | return (const wchar_t *) strWChar; 91 | 92 | if (strcmp(format, "") == 0) 93 | return (const wchar_t *) strWChar; 94 | 95 | va_list va; 96 | va_start(va, format); 97 | if ((vsprintf(tmp, format, va) >= 0)) { 98 | int32_t bt; 99 | int32_t strlength = strlen(tmp); 100 | bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512); 101 | 102 | if (bt > 0) { 103 | strWChar[bt] = 0; 104 | return (const wchar_t *) strWChar; 105 | } 106 | } 107 | va_end(va); 108 | 109 | return nullptr; 110 | } 111 | 112 | int32_t StringTools::strprintf(std::string &str, const char *format, ...) { 113 | static char tmp[512]; 114 | tmp[0] = 0; 115 | int32_t result = 0; 116 | 117 | va_list va; 118 | va_start(va, format); 119 | if ((vsprintf(tmp, format, va) >= 0)) { 120 | str = tmp; 121 | result = str.size(); 122 | } 123 | va_end(va); 124 | 125 | return result; 126 | } 127 | 128 | std::string StringTools::strfmt(const char *format, ...) { 129 | std::string str; 130 | static char tmp[512]; 131 | tmp[0] = 0; 132 | 133 | va_list va; 134 | va_start(va, format); 135 | if ((vsprintf(tmp, format, va) >= 0)) { 136 | str = tmp; 137 | } 138 | va_end(va); 139 | 140 | return str; 141 | } 142 | 143 | BOOL StringTools::char2wchar_t(const char *strChar, wchar_t *dest) { 144 | if (!strChar || !dest) 145 | return false; 146 | 147 | int32_t bt; 148 | bt = mbstowcs(dest, strChar, strlen(strChar)); 149 | if (bt > 0) { 150 | dest[bt] = 0; 151 | return true; 152 | } 153 | 154 | return false; 155 | } 156 | 157 | int32_t StringTools::strtokcmp(const char *string, const char *compare, const char *separator) { 158 | if (!string || !compare) 159 | return -1; 160 | 161 | char TokCopy[512]; 162 | strncpy(TokCopy, compare, sizeof(TokCopy)); 163 | TokCopy[511] = '\0'; 164 | 165 | char *strTok = strtok(TokCopy, separator); 166 | 167 | while (strTok != nullptr) { 168 | if (strcasecmp(string, strTok) == 0) { 169 | return 0; 170 | } 171 | strTok = strtok(nullptr, separator); 172 | } 173 | 174 | return -1; 175 | } 176 | 177 | int32_t StringTools::strextcmp(const char *string, const char *extension, char seperator) { 178 | if (!string || !extension) 179 | return -1; 180 | 181 | char *ptr = strrchr(string, seperator); 182 | if (!ptr) 183 | return -1; 184 | 185 | return strcasecmp(ptr + 1, extension); 186 | } 187 | 188 | 189 | std::vector StringTools::stringSplit(const std::string &inValue, const std::string &splitter) { 190 | std::string value = inValue; 191 | std::vector result; 192 | while (true) { 193 | uint32_t index = value.find(splitter); 194 | if (index == std::string::npos) { 195 | result.push_back(value); 196 | break; 197 | } 198 | std::string first = value.substr(0, index); 199 | result.push_back(first); 200 | if (index + splitter.size() == value.length()) { 201 | result.push_back(""); 202 | break; 203 | } 204 | if (index + splitter.size() > value.length()) { 205 | break; 206 | } 207 | value = value.substr(index + splitter.size(), value.length()); 208 | } 209 | return result; 210 | } 211 | 212 | bool StringTools::findStringIC(const std::string &strHaystack, const std::string &strNeedle) { 213 | auto it = std::search( 214 | strHaystack.begin(), strHaystack.end(), 215 | strNeedle.begin(), strNeedle.end(), 216 | [](char ch1, char ch2) { return std::toupper(ch1) == std::toupper(ch2); }); 217 | return (it != strHaystack.end()); 218 | } 219 | -------------------------------------------------------------------------------- /src/utils/StringTools.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2010 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | * 24 | * for WiiXplorer 2010 25 | ***************************************************************************/ 26 | #ifndef __STRING_TOOLS_H 27 | #define __STRING_TOOLS_H 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | class StringTools { 36 | public: 37 | static BOOL EndsWith(const std::string &a, const std::string &b); 38 | 39 | static const char *byte_to_binary(int32_t x); 40 | 41 | static std::string removeCharFromString(std::string &input, char toBeRemoved); 42 | 43 | static const char *fmt(const char *format, ...); 44 | 45 | static const wchar_t *wfmt(const char *format, ...); 46 | 47 | static int32_t strprintf(std::string &str, const char *format, ...); 48 | 49 | static std::string strfmt(const char *format, ...); 50 | 51 | static BOOL char2wchar_t(const char *src, wchar_t *dest); 52 | 53 | static int32_t strtokcmp(const char *string, const char *compare, const char *separator); 54 | 55 | static int32_t strextcmp(const char *string, const char *extension, char seperator); 56 | 57 | static const char *FullpathToFilename(const char *path) { 58 | if (!path) 59 | return path; 60 | 61 | const char *ptr = path; 62 | const char *Filename = ptr; 63 | 64 | while (*ptr != '\0') { 65 | if (ptr[0] == '/' && ptr[1] != '\0') 66 | Filename = ptr + 1; 67 | 68 | ++ptr; 69 | } 70 | 71 | return Filename; 72 | } 73 | 74 | static void RemoveDoubleSlashs(std::string &str) { 75 | uint32_t length = str.size(); 76 | 77 | //! clear path of double slashes 78 | for (uint32_t i = 1; i < length; ++i) { 79 | if (str[i - 1] == '/' && str[i] == '/') { 80 | str.erase(i, 1); 81 | i--; 82 | length--; 83 | } 84 | } 85 | } 86 | 87 | static std::vector stringSplit(const std::string &value, const std::string &splitter); 88 | 89 | // https://stackoverflow.com/a/19839371 90 | static bool findStringIC(const std::string &strHaystack, const std::string &strNeedle); 91 | }; 92 | 93 | #endif /* __STRING_TOOLS_H */ 94 | -------------------------------------------------------------------------------- /src/utils/logger.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) 11 | #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) 12 | 13 | #define DEBUG_FUNCTION_LINE(FMT, ARGS...) \ 14 | do { \ 15 | WHBLogPrintf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \ 16 | } while (0) 17 | 18 | #define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) \ 19 | do { \ 20 | WHBLogWritef("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \ 21 | } while (0) 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | -------------------------------------------------------------------------------- /src/utils/utils.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | // https://gist.github.com/ccbrown/9722406 10 | void dumpHex(const void *data, size_t size) { 11 | char ascii[17]; 12 | size_t i, j; 13 | ascii[16] = '\0'; 14 | DEBUG_FUNCTION_LINE_WRITE("0x%08X (0x0000): ", data); 15 | for (i = 0; i < size; ++i) { 16 | WHBLogWritef("%02X ", ((unsigned char *) data)[i]); 17 | if (((unsigned char *) data)[i] >= ' ' && ((unsigned char *) data)[i] <= '~') { 18 | ascii[i % 16] = ((unsigned char *) data)[i]; 19 | } else { 20 | ascii[i % 16] = '.'; 21 | } 22 | if ((i + 1) % 8 == 0 || i + 1 == size) { 23 | WHBLogWritef(" "); 24 | if ((i + 1) % 16 == 0) { 25 | WHBLogWritef("| %s \n", ascii); 26 | if (i + 1 < size) { 27 | WHBLogWritef("0x%08X (0x%04X); ", data + i + 1, i + 1); 28 | } 29 | } else if (i + 1 == size) { 30 | ascii[(i + 1) % 16] = '\0'; 31 | if ((i + 1) % 16 <= 8) { 32 | WHBLogWritef(" "); 33 | } 34 | for (j = (i + 1) % 16; j < 16; ++j) { 35 | WHBLogWritef(" "); 36 | } 37 | WHBLogWritef("| %s \n", ascii); 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/utils/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef __UTILS_H_ 2 | #define __UTILS_H_ 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define LIMIT(x, min, max) \ 11 | ({ \ 12 | typeof(x) _x = x; \ 13 | typeof(min) _min = min; \ 14 | typeof(max) _max = max; \ 15 | (((_x) < (_min)) ? (_min) : ((_x) > (_max)) ? (_max) \ 16 | : (_x)); \ 17 | }) 18 | 19 | #define DegToRad(a) ((a) *0.01745329252f) 20 | #define RadToDeg(a) ((a) *57.29577951f) 21 | 22 | #define ALIGN4(x) (((x) + 3) & ~3) 23 | #define ALIGN32(x) (((x) + 31) & ~31) 24 | 25 | #define le16(i) ((((uint16_t) ((i) &0xFF)) << 8) | ((uint16_t) (((i) &0xFF00) >> 8))) 26 | #define le32(i) ((((uint32_t) le16((i) &0xFFFF)) << 16) | ((uint32_t) le16(((i) &0xFFFF0000) >> 16))) 27 | #define le64(i) ((((uint64_t) le32((i) &0xFFFFFFFFLL)) << 32) | ((uint64_t) le32(((i) &0xFFFFFFFF00000000LL) >> 32))) 28 | 29 | //Needs to have log_init() called beforehand. 30 | void dumpHex(const void *data, size_t size); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif // __UTILS_H_ 37 | --------------------------------------------------------------------------------