WiiUIdent v1.0
18
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
name: Build
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build-binary:
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Build binary
|
||||
run: |
|
||||
docker run --rm -v ${PWD}:/project garyodernichts/wiiuident_builder make
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: WiiUIdent
|
||||
path: |
|
||||
*.wuhb
|
||||
*.rpx
|
32
Dockerfile
Normal file
@ -0,0 +1,32 @@
|
||||
FROM ghcr.io/wiiu-env/devkitppc:20230326
|
||||
|
||||
COPY --from=ghcr.io/wiiu-env/libmocha:20220903 /artifacts $DEVKITPRO
|
||||
|
||||
# build and install latest wut
|
||||
WORKDIR /
|
||||
RUN \
|
||||
mkdir wut && \
|
||||
cd wut && \
|
||||
git init . && \
|
||||
git remote add origin https://github.com/devkitPro/wut.git && \
|
||||
git fetch --depth 1 origin 451a1828f7646053b59ebacd813135e0300c67e8 && \
|
||||
git checkout FETCH_HEAD
|
||||
WORKDIR /wut
|
||||
RUN make -j$(nproc)
|
||||
RUN make install
|
||||
|
||||
# build and install latest sdl
|
||||
WORKDIR /
|
||||
RUN \
|
||||
mkdir SDL && \
|
||||
cd SDL && \
|
||||
git init . && \
|
||||
git remote add origin https://github.com/GaryOderNichts/SDL.git && \
|
||||
git fetch --depth 1 origin 687746c8c9514b5d48d5f9665a1d5fa36c5e5547 && \
|
||||
git checkout FETCH_HEAD
|
||||
WORKDIR /SDL
|
||||
RUN /opt/devkitpro/portlibs/wiiu/bin/powerpc-eabi-cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$DEVKITPRO/portlibs/wiiu
|
||||
RUN cmake --build build
|
||||
RUN cmake --install build
|
||||
|
||||
WORKDIR /project
|
339
LICENSE
Normal file
@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
41
Makefile
@ -13,9 +13,11 @@ TOPDIR ?= $(CURDIR)
|
||||
# APP_SHORTNAME sets the short name of the application
|
||||
# APP_AUTHOR sets the author of the application
|
||||
#-------------------------------------------------------------------------------
|
||||
APP_NAME := mdinfo
|
||||
APP_SHORTNAME := mdinfo
|
||||
APP_NAME := WiiUIdent
|
||||
APP_SHORTNAME := WiiUIdent
|
||||
APP_AUTHOR := GaryOderNichts
|
||||
APP_VERSION := 1.0
|
||||
DATABASE_URL := wiiu.gerbilsoft.com
|
||||
|
||||
include $(DEVKITPRO)/wut/share/wut_rules
|
||||
|
||||
@ -30,13 +32,13 @@ include $(DEVKITPRO)/wut/share/wut_rules
|
||||
# TV_SPLASH is the image displayed during bootup on the TV, leave blank to use default rule
|
||||
# DRC_SPLASH is the image displayed during bootup on the DRC, leave blank to use default rule
|
||||
#-------------------------------------------------------------------------------
|
||||
TARGET := $(notdir $(CURDIR))
|
||||
TARGET := wiiuident
|
||||
BUILD := build
|
||||
SOURCES := .
|
||||
SOURCES := source source/screens source/system
|
||||
DATA := data
|
||||
INCLUDES := include
|
||||
INCLUDES := source include
|
||||
CONTENT :=
|
||||
ICON := icon.png
|
||||
ICON := res/icon.png
|
||||
TV_SPLASH :=
|
||||
DRC_SPLASH :=
|
||||
|
||||
@ -46,14 +48,15 @@ DRC_SPLASH :=
|
||||
CFLAGS := -Wall -O2 -ffunction-sections \
|
||||
$(MACHDEP)
|
||||
|
||||
CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__
|
||||
CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -DAPP_VERSION=\"$(APP_VERSION)\" \
|
||||
-DDATABASE_URL=\"$(DATABASE_URL)\"
|
||||
|
||||
CXXFLAGS := $(CFLAGS)
|
||||
CXXFLAGS := $(CFLAGS) -std=gnu++20
|
||||
|
||||
ASFLAGS := $(ARCH)
|
||||
LDFLAGS = $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map)
|
||||
|
||||
LIBS := -lmocha -lwut
|
||||
LIBS := -lcurl -lmbedtls -lmbedcrypto -lmbedx509 -lSDL2 -lSDL2_ttf -lfreetype -lpng -lbz2 -lz -lmocha -lwut
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level
|
||||
@ -103,7 +106,7 @@ export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
-I$(CURDIR)/$(BUILD) -I$(DEVKITPRO)/portlibs/wiiu/include/SDL2
|
||||
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||
|
||||
@ -174,6 +177,24 @@ $(OFILES_SRC) : $(HFILES_BIN)
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
%.ttf.o %_ttf.h : %.ttf
|
||||
#-------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
%.bdf.o %_bdf.h : %.bdf
|
||||
#-------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
%.pem.o %_pem.h : %.pem
|
||||
#-------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
82
README.md
@ -1,14 +1,74 @@
|
||||
![](icon.png)
|
||||
# mdinfo
|
||||
![](res/banner.png)
|
||||
A Wii U Identification homebrew, which display information about console hardware components, software/hardware versions and much more.
|
||||
|
||||
Quick and simple tool to display info about IOSU's memory devices.
|
||||
Can be used to figure out what eMMC chip is built into a console.
|
||||
> :information_source: **WiiUIdent requires the [MochaPayload](https://github.com/wiiu-env/MochaPayload)!**
|
||||
> Make sure to update to [Aroma](https://aroma.foryour.cafe) or [Tiramisu](https://tiramisu.foryour.cafe), in order to use this application.
|
||||
|
||||
**Note: You need the [MochaPayload](https://github.com/wiiu-env/MochaPayload) for this to work**
|
||||
## Features
|
||||
WiiUIdent currently displays:
|
||||
|
||||
## Currently displays:
|
||||
* Manufacturer ID
|
||||
-> Shows known name and type for that ID
|
||||
* Product Revision
|
||||
* Product Name
|
||||
* CID and CSD
|
||||
- Identification
|
||||
- Model
|
||||
- Serial
|
||||
- Production Data
|
||||
- Keyset
|
||||
- Hardware
|
||||
- Type
|
||||
- Version
|
||||
- Board Type
|
||||
- SATA Device
|
||||
- DDR3 Size/Speed/Vendor
|
||||
- Region
|
||||
- Product Area
|
||||
- Game Region
|
||||
- Versions
|
||||
- System Version
|
||||
- Boot1 Version
|
||||
- MLC/SD Card information
|
||||
- Type
|
||||
- Manufacturer
|
||||
- Product Name
|
||||
- Product Revision
|
||||
- Production Date (MLC only)
|
||||
- Size
|
||||
- CID/CSD
|
||||
|
||||
## System Database
|
||||
WiiUIdent comes with an option to optionally upload system information to a database. This allows collecting various statistics about Wii U consoles.
|
||||
After submitting your data, your system information will be added to the database with a System ID, which will be displayed on the console.
|
||||
The database is publicly accessible but personally identifying information will be kept confidential.
|
||||
[The database can be found here!](https://wiiu.gerbilsoft.com/)
|
||||
|
||||
## Screenshots
|
||||
![](res/screenshot0.png)
|
||||
![](res/screenshot1.png)
|
||||
![](res/screenshot2.png)
|
||||
![](res/screenshot3.png)
|
||||
![](res/screenshot4.png)
|
||||
![](res/screenshot5.png)
|
||||
|
||||
## Building
|
||||
For building you need:
|
||||
- [wut](https://github.com/devkitPro/wut)
|
||||
- [libmocha](https://github.com/wiiu-env/libmocha)
|
||||
- [SDL2 v2.22](https://github.com/GaryOderNichts/SDL/tree/wiiu-sdl2-2.0.22)
|
||||
- wiiu-curl
|
||||
- wiiu-mbedtls
|
||||
|
||||
You can also build WiiUIdent using docker:
|
||||
```bash
|
||||
# Build docker image (only needed once)
|
||||
docker build . -t wiiuident_builder
|
||||
|
||||
# make
|
||||
docker run -it --rm -v ${PWD}:/project wiiuident_builder make
|
||||
|
||||
# make clean
|
||||
docker run -it --rm -v ${PWD}:/project wiiuident_builder make clean
|
||||
```
|
||||
A pre-built container is available as `garyodernichts/wiiuident_builder`.
|
||||
|
||||
## Additional Credits
|
||||
- [@GerbilSoft](https://github.com/GerbilSoft) for providing the System Database and the "System Information" implementation in the `recovery_menu`.
|
||||
- [FontAwesome](https://fontawesome.com/) for the icons.
|
||||
- [Terminus Font](https://terminus-font.sourceforge.net/) for the monospace font.
|
||||
|
3372
data/cacert.pem
Normal file
BIN
data/fa-solid-900.ttf
Normal file
52912
data/ter-u32b.bdf
Normal file
209
idsdb.h
@ -1,209 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// from https://kernel.googlesource.com/pub/scm/utils/mmc/mmc-utils/+/refs/heads/master/lsmmc.c
|
||||
|
||||
struct ids_database {
|
||||
char *type;
|
||||
int id;
|
||||
char *manufacturer;
|
||||
};
|
||||
|
||||
static struct ids_database unk_db = {
|
||||
.type = "unk",
|
||||
.manufacturer = "Unknown",
|
||||
};
|
||||
|
||||
static struct ids_database database[] = {
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x01,
|
||||
.manufacturer = "Panasonic",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x02,
|
||||
.manufacturer = "Toshiba/Kingston/Viking",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x03,
|
||||
.manufacturer = "SanDisk",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x08,
|
||||
.manufacturer = "Silicon Power",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x18,
|
||||
.manufacturer = "Infineon",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x1b,
|
||||
.manufacturer = "Transcend/Samsung",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x1c,
|
||||
.manufacturer = "Transcend",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x1d,
|
||||
.manufacturer = "Corsair/AData",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x1e,
|
||||
.manufacturer = "Transcend",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x1f,
|
||||
.manufacturer = "Kingston",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x27,
|
||||
.manufacturer = "Delkin/Phison",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x28,
|
||||
.manufacturer = "Lexar",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x30,
|
||||
.manufacturer = "SanDisk",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x31,
|
||||
.manufacturer = "Silicon Power",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x33,
|
||||
.manufacturer = "STMicroelectronics",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x41,
|
||||
.manufacturer = "Kingston",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x6f,
|
||||
.manufacturer = "STMicroelectronics",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x74,
|
||||
.manufacturer = "Transcend",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x76,
|
||||
.manufacturer = "Patriot",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x82,
|
||||
.manufacturer = "Gobe/Sony",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x89,
|
||||
.manufacturer = "Unknown",
|
||||
},
|
||||
{
|
||||
.type = "sd",
|
||||
.id = 0x9e,
|
||||
.manufacturer = "PNY",
|
||||
},
|
||||
{
|
||||
.type = "mmc",
|
||||
.id = 0x00,
|
||||
.manufacturer = "SanDisk",
|
||||
},
|
||||
{
|
||||
.type = "mmc",
|
||||
.id = 0x02,
|
||||
.manufacturer = "Kingston/SanDisk",
|
||||
},
|
||||
{
|
||||
.type = "mmc",
|
||||
.id = 0x03,
|
||||
.manufacturer = "Toshiba",
|
||||
},
|
||||
{
|
||||
.type = "mmc",
|
||||
.id = 0x05,
|
||||
.manufacturer = "Unknown",
|
||||
},
|
||||
{
|
||||
.type = "mmc",
|
||||
.id = 0x06,
|
||||
.manufacturer = "Unknown",
|
||||
},
|
||||
{
|
||||
.type = "mmc",
|
||||
.id = 0x11,
|
||||
.manufacturer = "Toshiba",
|
||||
},
|
||||
{
|
||||
.type = "mmc",
|
||||
.id = 0x13,
|
||||
.manufacturer = "Micron",
|
||||
},
|
||||
{
|
||||
.type = "mmc",
|
||||
.id = 0x15,
|
||||
.manufacturer = "Samsung/SanDisk/LG",
|
||||
},
|
||||
{
|
||||
.type = "mmc",
|
||||
.id = 0x37,
|
||||
.manufacturer = "KingMax",
|
||||
},
|
||||
{
|
||||
.type = "mmc",
|
||||
.id = 0x44,
|
||||
.manufacturer = "SanDisk",
|
||||
},
|
||||
{
|
||||
.type = "mmc",
|
||||
.id = 0x2c,
|
||||
.manufacturer = "Kingston",
|
||||
},
|
||||
{
|
||||
.type = "mmc",
|
||||
.id = 0x70,
|
||||
.manufacturer = "Kingston",
|
||||
},
|
||||
{
|
||||
.type = "mmc",
|
||||
.id = 0xfe,
|
||||
.manufacturer = "Micron",
|
||||
},
|
||||
{
|
||||
.type = "mmc",
|
||||
.id = 0x90,
|
||||
.manufacturer = "Hynix",
|
||||
},
|
||||
};
|
||||
|
||||
static inline struct ids_database *find_by_id(int id)
|
||||
{
|
||||
unsigned int ids_cnt = sizeof(database) / sizeof(struct ids_database);
|
||||
for (int i = 0; i < ids_cnt; ++i) {
|
||||
if (database[i].id == id) {
|
||||
return &database[i];
|
||||
}
|
||||
}
|
||||
|
||||
return &unk_db;
|
||||
}
|
136
main.c
@ -1,136 +0,0 @@
|
||||
#include <whb/proc.h>
|
||||
#include <whb/log.h>
|
||||
#include <whb/log_udp.h>
|
||||
#include <whb/log_console.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <mocha/mocha.h>
|
||||
|
||||
#include "idsdb.h"
|
||||
|
||||
struct SALDeviceParams {
|
||||
uint32_t usrptr;
|
||||
uint32_t mid_prv;
|
||||
uint32_t device_type;
|
||||
uint32_t unk[16];
|
||||
char name0[128];
|
||||
char name1[128];
|
||||
char name2[128];
|
||||
uint32_t functions[12];
|
||||
};
|
||||
|
||||
struct MDBlkDriver {
|
||||
int32_t registered;
|
||||
int32_t unk[2];
|
||||
struct SALDeviceParams params;
|
||||
int sal_handle;
|
||||
int deviceId;
|
||||
uint8_t unk2[196];
|
||||
};
|
||||
static_assert(sizeof(struct MDBlkDriver) == 724, "MDBlkDriver: wrong size");
|
||||
|
||||
#define MDBLK_DRIVER_ADDRESS 0x11c39e78
|
||||
#define MD_DEVICE_POINTERS_ADDRESS 0x10899308
|
||||
|
||||
struct MDBlkDriver blkDrivers[2] = { 0 };
|
||||
|
||||
MochaUtilsStatus iosuKernRead32(uint32_t address, uint32_t* outBuffer, int count)
|
||||
{
|
||||
MochaUtilsStatus status = MOCHA_RESULT_SUCCESS;
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
status = Mocha_IOSUKernelRead32(address + (i * 4), outBuffer + i);
|
||||
if (status != MOCHA_RESULT_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static uint32_t getDeviceAddressByID(int id)
|
||||
{
|
||||
if (id - 0x42 >= 8) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t devicePointers[8];
|
||||
if (iosuKernRead32(MD_DEVICE_POINTERS_ADDRESS, devicePointers, 8) != MOCHA_RESULT_SUCCESS) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// virtual matches physical address for IOS-FS, no need to conversion
|
||||
return devicePointers[id - 0x42];
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
WHBProcInit();
|
||||
WHBLogUdpInit();
|
||||
WHBLogConsoleInit();
|
||||
|
||||
if (Mocha_InitLibrary() == MOCHA_RESULT_SUCCESS) {
|
||||
if (iosuKernRead32(MDBLK_DRIVER_ADDRESS, (uint32_t *) blkDrivers, sizeof(blkDrivers) / 4) == MOCHA_RESULT_SUCCESS) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
struct MDBlkDriver *drv = &blkDrivers[i];
|
||||
WHBLogPrintf("** Instance %d: (%s) Type: %d **", i + 1, drv->registered ? "Attached" : "Detached", drv->params.device_type);
|
||||
if (drv->registered) {
|
||||
uint16_t mid = drv->params.mid_prv >> 16;
|
||||
uint16_t prv = drv->params.mid_prv & 0xff;
|
||||
struct ids_database *db = find_by_id(mid);
|
||||
|
||||
WHBLogPrintf("Manufacturer ID: 0x%02x, Product revision: 0x%02x", mid, prv);
|
||||
WHBLogPrintf(" -> Manufacturer: '%s' Type: '%s'", db->manufacturer, db->type);
|
||||
WHBLogPrintf("Name 0: '%s' Name 1: '%s' Name 2: '%s'", drv->params.name0, drv->params.name1, drv->params.name2);
|
||||
|
||||
uint32_t deviceAddress = getDeviceAddressByID(drv->deviceId);
|
||||
if (!deviceAddress) {
|
||||
continue;
|
||||
}
|
||||
|
||||
uint32_t cid[4];
|
||||
if (iosuKernRead32(deviceAddress + 0x58, cid, 4) != MOCHA_RESULT_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
WHBLogPrintf("CID: %08x%08x%08x%08x", cid[0], cid[1], cid[2], cid[3]);
|
||||
|
||||
if(!strcmp(db->type,"mmc")){
|
||||
uint8_t month = (uint8_t)(cid[3] >> 12) & 0xf;
|
||||
uint16_t year = (uint8_t)(cid[3] >> 8) & 0xf;
|
||||
year += 1997;
|
||||
if(year < 2005)
|
||||
year += 0x10;
|
||||
WHBLogPrintf("Mfg Date: %02u/%u", month, year);
|
||||
}
|
||||
|
||||
|
||||
uint32_t csd[4];
|
||||
if (iosuKernRead32(deviceAddress + 0x68, csd, 4) != MOCHA_RESULT_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
WHBLogPrintf("CSD: %08x%08x%08x%08x", csd[0], csd[1], csd[2], csd[3]);
|
||||
}
|
||||
|
||||
WHBLogPrintf("=================================================");
|
||||
}
|
||||
} else {
|
||||
WHBLogPrintf("Failed to read driver data");
|
||||
}
|
||||
|
||||
Mocha_DeInitLibrary();
|
||||
} else {
|
||||
WHBLogPrintf("Failed to initialize Mocha");
|
||||
}
|
||||
|
||||
while (WHBProcIsRunning()) {
|
||||
WHBLogConsoleDraw();
|
||||
}
|
||||
|
||||
WHBLogConsoleFree();
|
||||
WHBLogUdpDeinit();
|
||||
WHBProcShutdown();
|
||||
return 0;
|
||||
}
|
BIN
res/banner.png
Normal file
After Width: | Height: | Size: 979 KiB |
BIN
res/icon.png
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
res/screenshot0.png
Normal file
After Width: | Height: | Size: 277 KiB |
BIN
res/screenshot1.png
Normal file
After Width: | Height: | Size: 711 KiB |
BIN
res/screenshot2.png
Normal file
After Width: | Height: | Size: 615 KiB |
BIN
res/screenshot3.png
Normal file
After Width: | Height: | Size: 916 KiB |
BIN
res/screenshot4.png
Normal file
After Width: | Height: | Size: 292 KiB |
BIN
res/screenshot5.png
Normal file
After Width: | Height: | Size: 360 KiB |
290
source/Gfx.cpp
Normal file
@ -0,0 +1,290 @@
|
||||
#include "Gfx.hpp"
|
||||
#include "SDL_FontCache.h"
|
||||
#include <map>
|
||||
#include <cstdarg>
|
||||
|
||||
#include <coreinit/debug.h>
|
||||
#include <coreinit/memory.h>
|
||||
|
||||
#include <ter-u32b_bdf.h>
|
||||
#include <fa-solid-900_ttf.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
SDL_Window* window = nullptr;
|
||||
|
||||
SDL_Renderer* renderer = nullptr;
|
||||
|
||||
void* fontData = nullptr;
|
||||
|
||||
uint32_t fontSize = 0;
|
||||
|
||||
std::map<int, FC_Font*> fontMap;
|
||||
|
||||
FC_Font* monospaceFont = nullptr;
|
||||
|
||||
TTF_Font* iconFont = nullptr;
|
||||
|
||||
std::map<Uint16, SDL_Texture*> iconCache;
|
||||
|
||||
FC_Font* GetFontForSize(int size)
|
||||
{
|
||||
if (fontMap.contains(size)) {
|
||||
return fontMap[size];
|
||||
}
|
||||
|
||||
FC_Font* font = FC_CreateFont();
|
||||
if (!font) {
|
||||
return font;
|
||||
}
|
||||
|
||||
if (!FC_LoadFont_RW(font, renderer, SDL_RWFromMem(fontData, fontSize), 1, size, Gfx::COLOR_BLACK, TTF_STYLE_NORMAL)) {
|
||||
FC_FreeFont(font);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
fontMap.insert({size, font});
|
||||
return font;
|
||||
}
|
||||
|
||||
SDL_Texture* LoadIcon(Uint16 icon)
|
||||
{
|
||||
if (iconCache.contains(icon)) {
|
||||
return iconCache[icon];
|
||||
}
|
||||
|
||||
SDL_Surface* iconSurface = TTF_RenderGlyph_Blended(iconFont, icon, Gfx::COLOR_WHITE);
|
||||
if (!iconSurface) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, iconSurface);
|
||||
SDL_FreeSurface(iconSurface);
|
||||
if (!texture) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
iconCache.insert({icon, texture});
|
||||
return texture;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Gfx
|
||||
{
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
window = SDL_CreateWindow("WiiUIdent", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, 0);
|
||||
if (!window) {
|
||||
OSReport("SDL_CreateWindow failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
if (!renderer) {
|
||||
OSReport("SDL_CreateRenderer failed\n");
|
||||
SDL_DestroyWindow(window);
|
||||
window = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!OSGetSharedData(OS_SHAREDDATATYPE_FONT_STANDARD, 0, &fontData, &fontSize)) {
|
||||
OSReport("OSGetSharedData failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
TTF_Init();
|
||||
|
||||
monospaceFont = FC_CreateFont();
|
||||
if (!monospaceFont) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// FIXME Probably SDL bug? If we don't draw before FC_LoadFont_RW our viewport shrinks
|
||||
Gfx::DrawRectFilled(0, 0, 0, 0, COLOR_BLACK);
|
||||
|
||||
if (!FC_LoadFont_RW(monospaceFont, renderer, SDL_RWFromMem((void*)ter_u32b_bdf, ter_u32b_bdf_size), 1, 32, Gfx::COLOR_BLACK, TTF_STYLE_NORMAL)) {
|
||||
FC_FreeFont(monospaceFont);
|
||||
return false;
|
||||
}
|
||||
|
||||
// icons @256 should be large enough for our needs
|
||||
iconFont = TTF_OpenFontRW(SDL_RWFromMem((void*)fa_solid_900_ttf, fa_solid_900_ttf_size), 1, 256);
|
||||
if (!iconFont) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Shutdown()
|
||||
{
|
||||
for (const auto& [key, value] : fontMap) {
|
||||
FC_FreeFont(value);
|
||||
}
|
||||
|
||||
for (const auto& [key, value] : iconCache) {
|
||||
SDL_DestroyTexture(value);
|
||||
}
|
||||
|
||||
FC_FreeFont(monospaceFont);
|
||||
TTF_CloseFont(iconFont);
|
||||
TTF_Quit();
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
void Clear(SDL_Color color)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
|
||||
SDL_RenderClear(renderer);
|
||||
}
|
||||
|
||||
void Render()
|
||||
{
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
void DrawRectFilled(int x, int y, int w, int h, SDL_Color color)
|
||||
{
|
||||
SDL_Rect rect{x, y, w, h};
|
||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
}
|
||||
|
||||
void DrawRect(int x, int y, int w, int h, int borderSize, SDL_Color color)
|
||||
{
|
||||
DrawRectFilled(x, y, w, borderSize, color);
|
||||
DrawRectFilled(x, y + h - borderSize, w, borderSize, color);
|
||||
DrawRectFilled(x, y, borderSize, h, color);
|
||||
DrawRectFilled(x + w - borderSize, y, borderSize, h, color);
|
||||
}
|
||||
|
||||
void DrawIcon(int x, int y, int size, SDL_Color color, Uint16 icon, AlignFlags align, double angle)
|
||||
{
|
||||
SDL_Texture* iconTex = LoadIcon(icon);
|
||||
if (!iconTex) {
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_SetTextureColorMod(iconTex, color.r, color.g, color.b);
|
||||
SDL_SetTextureAlphaMod(iconTex, color.a);
|
||||
|
||||
int w, h;
|
||||
SDL_QueryTexture(iconTex, nullptr, nullptr, &w, &h);
|
||||
|
||||
SDL_Rect rect;
|
||||
rect.x = x;
|
||||
rect.y = y;
|
||||
// scale the width based on hight to keep AR
|
||||
rect.w = (int) (((float) w / h) * size);
|
||||
rect.h = size;
|
||||
|
||||
if (align & ALIGN_RIGHT) {
|
||||
rect.x -= rect.w;
|
||||
} else if (align & ALIGN_HORIZONTAL) {
|
||||
rect.x -= rect.w / 2;
|
||||
}
|
||||
|
||||
if (align & ALIGN_BOTTOM) {
|
||||
rect.y -= rect.h;
|
||||
} else if (align & ALIGN_VERTICAL) {
|
||||
rect.y -= rect.h / 2;
|
||||
}
|
||||
|
||||
// draw the icon
|
||||
if (angle) {
|
||||
SDL_RenderCopyEx(renderer, iconTex, nullptr, &rect, angle, nullptr, SDL_FLIP_NONE);
|
||||
} else {
|
||||
SDL_RenderCopy(renderer, iconTex, nullptr, &rect);
|
||||
}
|
||||
}
|
||||
|
||||
int GetIconWidth(int size, Uint16 icon)
|
||||
{
|
||||
SDL_Texture* iconTex = LoadIcon(icon);
|
||||
if (!iconTex) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w, h;
|
||||
SDL_QueryTexture(iconTex, nullptr, nullptr, &w, &h);
|
||||
|
||||
return (int) (((float) w / h) * size);
|
||||
}
|
||||
|
||||
void Print(int x, int y, int size, SDL_Color color, std::string text, AlignFlags align, bool monospace)
|
||||
{
|
||||
FC_Font* font = monospace ? monospaceFont : GetFontForSize(size);
|
||||
if (!font) {
|
||||
return;
|
||||
}
|
||||
|
||||
FC_Effect effect;
|
||||
effect.color = color;
|
||||
|
||||
// scale monospace font based on size
|
||||
if (monospace) {
|
||||
effect.scale = FC_MakeScale(size / 28.0f, size / 28.0f);
|
||||
// TODO figure out how to center this properly
|
||||
y += 5;
|
||||
} else {
|
||||
effect.scale = FC_MakeScale(1,1);
|
||||
}
|
||||
|
||||
if (align & ALIGN_LEFT) {
|
||||
effect.alignment = FC_ALIGN_LEFT;
|
||||
} else if (align & ALIGN_RIGHT) {
|
||||
effect.alignment = FC_ALIGN_RIGHT;
|
||||
} else if (align & ALIGN_HORIZONTAL) {
|
||||
effect.alignment = FC_ALIGN_CENTER;
|
||||
} else {
|
||||
// left by default
|
||||
effect.alignment = FC_ALIGN_LEFT;
|
||||
}
|
||||
|
||||
if (align & ALIGN_BOTTOM) {
|
||||
y -= GetTextHeight(size, text, monospace);
|
||||
} else if (align & ALIGN_VERTICAL) {
|
||||
y -= GetTextHeight(size, text, monospace) / 2;
|
||||
}
|
||||
|
||||
FC_DrawEffect(font, renderer, x, y, effect, "%s", text.c_str());
|
||||
}
|
||||
|
||||
int GetTextWidth(int size, std::string text, bool monospace)
|
||||
{
|
||||
FC_Font* font = monospace ? monospaceFont : GetFontForSize(size);
|
||||
if (!font) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
float scale = monospace ? (size / 28.0f) : 1.0f;
|
||||
|
||||
return FC_GetWidth(font, "%s", text.c_str()) * scale;
|
||||
}
|
||||
|
||||
int GetTextHeight(int size, std::string text, bool monospace)
|
||||
{
|
||||
// TODO this doesn't work nicely with monospace yet
|
||||
monospace = false;
|
||||
|
||||
FC_Font* font = monospace ? monospaceFont : GetFontForSize(size);
|
||||
if (!font) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
float scale = monospace ? (size / 28.0f) : 1.0f;
|
||||
|
||||
return FC_GetHeight(GetFontForSize(size), "%s", text.c_str()) * scale;
|
||||
}
|
||||
|
||||
}
|
||||
|
63
source/Gfx.hpp
Normal file
@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL.h>
|
||||
#include <string>
|
||||
|
||||
namespace Gfx
|
||||
{
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH = 1920;
|
||||
constexpr uint32_t SCREEN_HEIGHT = 1080;
|
||||
|
||||
constexpr SDL_Color COLOR_BLACK = { 0x00, 0x00, 0x00, 0xff };
|
||||
constexpr SDL_Color COLOR_WHITE = { 0xff, 0xff, 0xff, 0xff };
|
||||
constexpr SDL_Color COLOR_BACKGROUND = { 0x1b, 0x1c, 0x20, 0xff };
|
||||
constexpr SDL_Color COLOR_ALT_BACKGROUND = { 0x33, 0x34, 0x39, 0xff };
|
||||
constexpr SDL_Color COLOR_HIGHLIGHTED = { 0x00, 0x91, 0xea, 0xff };
|
||||
constexpr SDL_Color COLOR_TEXT = { 0xf8, 0xf8, 0xf8, 0xff };
|
||||
constexpr SDL_Color COLOR_ALT_TEXT = { 0xb0, 0xb0, 0xb0, 0xff };
|
||||
constexpr SDL_Color COLOR_ACCENT = { 0x32, 0xe6, 0xa6, 0xff };
|
||||
constexpr SDL_Color COLOR_ALT_ACCENT = { 0x22, 0xb3, 0x7d, 0xff };
|
||||
constexpr SDL_Color COLOR_BARS = { 0x2f, 0x3f, 0x38, 0xff };
|
||||
constexpr SDL_Color COLOR_ERROR = { 0xff, 0x33, 0x33, 0xff };
|
||||
constexpr SDL_Color COLOR_WIIU = { 0x00, 0x95, 0xc7, 0xff };
|
||||
|
||||
enum AlignFlags {
|
||||
ALIGN_LEFT = 1 << 0,
|
||||
ALIGN_RIGHT = 1 << 1,
|
||||
ALIGN_HORIZONTAL = 1 << 2,
|
||||
ALIGN_TOP = 1 << 3,
|
||||
ALIGN_BOTTOM = 1 << 4,
|
||||
ALIGN_VERTICAL = 1 << 5,
|
||||
ALIGN_CENTER = ALIGN_HORIZONTAL | ALIGN_VERTICAL,
|
||||
};
|
||||
|
||||
static constexpr inline AlignFlags operator|(AlignFlags lhs, AlignFlags rhs) {
|
||||
return static_cast<AlignFlags>(static_cast<uint32_t>(lhs) | static_cast<uint32_t>(rhs));
|
||||
}
|
||||
|
||||
bool Init();
|
||||
|
||||
void Shutdown();
|
||||
|
||||
void Clear(SDL_Color color);
|
||||
|
||||
void Render();
|
||||
|
||||
void DrawRectFilled(int x, int y, int w, int h, SDL_Color color);
|
||||
|
||||
void DrawRect(int x, int y, int w, int h, int borderSize, SDL_Color color);
|
||||
|
||||
void DrawIcon(int x, int y, int size, SDL_Color color, Uint16 icon, AlignFlags align = ALIGN_CENTER, double angle = 0.0);
|
||||
|
||||
int GetIconWidth(int size, Uint16 icon);
|
||||
|
||||
static inline int GetIconHeight(int size, Uint16 icon) { return size; }
|
||||
|
||||
void Print(int x, int y, int size, SDL_Color color, std::string text, AlignFlags align = ALIGN_LEFT | ALIGN_TOP, bool monospace = false);
|
||||
|
||||
int GetTextWidth(int size, std::string text, bool monospace = false);
|
||||
|
||||
int GetTextHeight(int size, std::string text, bool monospace = false);
|
||||
|
||||
}
|
2925
source/SDL_FontCache.c
Normal file
327
source/SDL_FontCache.h
Normal file
@ -0,0 +1,327 @@
|
||||
/*
|
||||
SDL_FontCache v0.10.0: A font cache for SDL and SDL_ttf
|
||||
by Jonathan Dearborn
|
||||
Dedicated to the memory of Florian Hufsky
|
||||
|
||||
License:
|
||||
The short:
|
||||
Use it however you'd like, but keep the copyright and license notice
|
||||
whenever these files or parts of them are distributed in uncompiled form.
|
||||
|
||||
The long:
|
||||
Copyright (c) 2019 Jonathan Dearborn
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _SDL_FONTCACHE_H__
|
||||
#define _SDL_FONTCACHE_H__
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_ttf.h"
|
||||
|
||||
#ifdef FC_USE_SDL_GPU
|
||||
#include "SDL_gpu.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// Let's pretend this exists...
|
||||
#define TTF_STYLE_OUTLINE 16
|
||||
|
||||
|
||||
|
||||
// Differences between SDL_Renderer and SDL_gpu
|
||||
#ifdef FC_USE_SDL_GPU
|
||||
#define FC_Rect GPU_Rect
|
||||
#define FC_Target GPU_Target
|
||||
#define FC_Image GPU_Image
|
||||
#define FC_Log GPU_LogError
|
||||
#else
|
||||
#define FC_Rect SDL_Rect
|
||||
#define FC_Target SDL_Renderer
|
||||
#define FC_Image SDL_Texture
|
||||
#define FC_Log SDL_Log
|
||||
#endif
|
||||
|
||||
|
||||
// SDL_FontCache types
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FC_ALIGN_LEFT,
|
||||
FC_ALIGN_CENTER,
|
||||
FC_ALIGN_RIGHT
|
||||
} FC_AlignEnum;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FC_FILTER_NEAREST,
|
||||
FC_FILTER_LINEAR
|
||||
} FC_FilterEnum;
|
||||
|
||||
typedef struct FC_Scale
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
|
||||
} FC_Scale;
|
||||
|
||||
typedef struct FC_Effect
|
||||
{
|
||||
FC_AlignEnum alignment;
|
||||
FC_Scale scale;
|
||||
SDL_Color color;
|
||||
|
||||
} FC_Effect;
|
||||
|
||||
// Opaque type
|
||||
typedef struct FC_Font FC_Font;
|
||||
|
||||
|
||||
typedef struct FC_GlyphData
|
||||
{
|
||||
SDL_Rect rect;
|
||||
int cache_level;
|
||||
|
||||
} FC_GlyphData;
|
||||
|
||||
|
||||
|
||||
|
||||
// Object creation
|
||||
|
||||
FC_Rect FC_MakeRect(float x, float y, float w, float h);
|
||||
|
||||
FC_Scale FC_MakeScale(float x, float y);
|
||||
|
||||
SDL_Color FC_MakeColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
|
||||
FC_Effect FC_MakeEffect(FC_AlignEnum alignment, FC_Scale scale, SDL_Color color);
|
||||
|
||||
FC_GlyphData FC_MakeGlyphData(int cache_level, Sint16 x, Sint16 y, Uint16 w, Uint16 h);
|
||||
|
||||
|
||||
|
||||
// Font object
|
||||
|
||||
FC_Font* FC_CreateFont(void);
|
||||
|
||||
#ifdef FC_USE_SDL_GPU
|
||||
Uint8 FC_LoadFont(FC_Font* font, const char* filename_ttf, Uint32 pointSize, SDL_Color color, int style);
|
||||
|
||||
Uint8 FC_LoadFontFromTTF(FC_Font* font, TTF_Font* ttf, SDL_Color color);
|
||||
|
||||
Uint8 FC_LoadFont_RW(FC_Font* font, SDL_RWops* file_rwops_ttf, Uint8 own_rwops, Uint32 pointSize, SDL_Color color, int style);
|
||||
#else
|
||||
Uint8 FC_LoadFont(FC_Font* font, SDL_Renderer* renderer, const char* filename_ttf, Uint32 pointSize, SDL_Color color, int style);
|
||||
|
||||
Uint8 FC_LoadFontFromTTF(FC_Font* font, SDL_Renderer* renderer, TTF_Font* ttf, SDL_Color color);
|
||||
|
||||
Uint8 FC_LoadFont_RW(FC_Font* font, SDL_Renderer* renderer, SDL_RWops* file_rwops_ttf, Uint8 own_rwops, Uint32 pointSize, SDL_Color color, int style);
|
||||
#endif
|
||||
|
||||
#ifndef FC_USE_SDL_GPU
|
||||
// note: handle SDL event types SDL_RENDER_TARGETS_RESET(>= SDL 2.0.2) and SDL_RENDER_DEVICE_RESET(>= SDL 2.0.4)
|
||||
void FC_ResetFontFromRendererReset(FC_Font* font, SDL_Renderer* renderer, Uint32 evType);
|
||||
#endif
|
||||
|
||||
void FC_ClearFont(FC_Font* font);
|
||||
|
||||
void FC_FreeFont(FC_Font* font);
|
||||
|
||||
|
||||
|
||||
// Built-in loading strings
|
||||
|
||||
char* FC_GetStringASCII(void);
|
||||
|
||||
char* FC_GetStringLatin1(void);
|
||||
|
||||
char* FC_GetStringASCII_Latin1(void);
|
||||
|
||||
|
||||
// UTF-8 to SDL_FontCache codepoint conversion
|
||||
|
||||
/*!
|
||||
Returns the Uint32 codepoint (not UTF-32) parsed from the given UTF-8 string.
|
||||
\param c A pointer to a string of proper UTF-8 character values.
|
||||
\param advance_pointer If true, the source pointer will be incremented to skip the extra bytes from multibyte codepoints.
|
||||
*/
|
||||
Uint32 FC_GetCodepointFromUTF8(const char** c, Uint8 advance_pointer);
|
||||
|
||||
/*!
|
||||
Parses the given codepoint and stores the UTF-8 bytes in 'result'. The result is NULL terminated.
|
||||
\param result A memory buffer for the UTF-8 values. Must be at least 5 bytes long.
|
||||
\param codepoint The Uint32 codepoint to parse (not UTF-32).
|
||||
*/
|
||||
void FC_GetUTF8FromCodepoint(char* result, Uint32 codepoint);
|
||||
|
||||
|
||||
// UTF-8 string operations
|
||||
|
||||
/*! Allocates a new string of 'size' bytes that is already NULL-terminated. The NULL byte counts toward the size limit, as usual. Returns NULL if size is 0. */
|
||||
char* U8_alloc(unsigned int size);
|
||||
|
||||
/*! Deallocates the given string. */
|
||||
void U8_free(char* string);
|
||||
|
||||
/*! Allocates a copy of the given string. */
|
||||
char* U8_strdup(const char* string);
|
||||
|
||||
/*! Returns the number of UTF-8 characters in the given string. */
|
||||
int U8_strlen(const char* string);
|
||||
|
||||
/*! Returns the number of bytes in the UTF-8 multibyte character pointed at by 'character'. */
|
||||
int U8_charsize(const char* character);
|
||||
|
||||