Initial Commit
This commit is contained in:
		
							
								
								
									
										116
									
								
								CHANGELOG.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								CHANGELOG.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,116 @@
 | 
			
		||||
# Palladium Changelog
 | 
			
		||||
## 1.0.0
 | 
			
		||||
- Switch from C2D to LI7
 | 
			
		||||
- For the Rest See RenderD7 Changelog below
 | 
			
		||||
# RenderD7 Changelog
 | 
			
		||||
## 0.9.5
 | 
			
		||||
- Remove Npi Intro and NVID Api
 | 
			
		||||
- Replace Toasts System with Message 
 | 
			
		||||
- Added GetTime
 | 
			
		||||
- Move from Draw to Render2 Api
 | 
			
		||||
- Implement RD7Color and R7Vec2
 | 
			
		||||
- Add new Features to Color::RGBA
 | 
			
		||||
- Cleanup Code
 | 
			
		||||
- Added RenderD7 Keyboard (Overlay)
 | 
			
		||||
- Added Ftrace Overlay
 | 
			
		||||
- Moved MetrikOVL into an Overlay
 | 
			
		||||
- Removed Old Font/Text Handlers
 | 
			
		||||
- Added UI7 (New UI Api)
 | 
			
		||||
- Remove Old UI Api
 | 
			
		||||
- Rewrite of RenderD7::Image
 | 
			
		||||
- Internal Debugger/Database (IDB)
 | 
			
		||||
- Removed BitmapPrinter
 | 
			
		||||
- Added nimg and swr(render2nimg | SoftwareRender)
 | 
			
		||||
- Removed Old Error/Message Handler
 | 
			
		||||
- GetTextSize (extra buffer) + New TextShorter
 | 
			
		||||
- Require specific FLAG for MemTrack
 | 
			
		||||
- Replace all lodepng usage by stb_image
 | 
			
		||||
- Move Asset Generator into single python script
 | 
			
		||||
- Remove INI reader
 | 
			
		||||
- Python based clangformat script
 | 
			
		||||
- Move some Init code into functions to not use twice
 | 
			
		||||
- Added Font class
 | 
			
		||||
- Add LinearAllocator (for std)
 | 
			
		||||
- Fix Crash in FilsSystem
 | 
			
		||||
- Implement basic Theme System
 | 
			
		||||
- Remove 0.9.4 Security
 | 
			
		||||
- Tasks now based on std functional/thread
 | 
			
		||||
- Add Network Support (Download Files, APi Requests)
 | 
			
		||||
- Remove RD7TF
 | 
			
		||||
- Add Cia Installer
 | 
			
		||||
- Move from Init bool values to flags
 | 
			
		||||
## 0.9.4
 | 
			
		||||
- Implement new Security System To prevent from crashes
 | 
			
		||||
- Implement Functiontrace for better Timing Tests
 | 
			
		||||
- Implement MemAlloc Tracker (only size)
 | 
			
		||||
- Add some new Overlays (not functional yet)
 | 
			
		||||
- Complete Rewrite of Overlay System
 | 
			
		||||
- Fixed the FrameEnd Crash
 | 
			
		||||
- New System to get Hardware Info
 | 
			
		||||
- Removed RenderD7 Super Reselution (800px mode)
 | 
			
		||||
## 0.9.3
 | 
			
		||||
- Completly Documented Everything
 | 
			
		||||
- Fix typo in Sprite::getHeight
 | 
			
		||||
- Remove Deprecated/Useless Stuff
 | 
			
		||||
## 0.9.2
 | 
			
		||||
- Add Nvid Support(v0.0.1)
 | 
			
		||||
- Add Basic RenderD7 Splash
 | 
			
		||||
- Faster Graphics Init
 | 
			
		||||
- Fade Effects
 | 
			
		||||
- Fix Changelog Screen 
 | 
			
		||||
## 0.9.1
 | 
			
		||||
- Fix Critical bug in Spritesheet animations
 | 
			
		||||
- Fix RenderD7::Color::Hex (Major performance tweak)
 | 
			
		||||
## 0.9.0
 | 
			
		||||
- Remove Stupid try of Console
 | 
			
		||||
- Add Services list 
 | 
			
		||||
- Clean up Code
 | 
			
		||||
- Added Minimal Init for hax2.x
 | 
			
		||||
## 0.8.5
 | 
			
		||||
- Fix Deltatime
 | 
			
		||||
## 0.8.4
 | 
			
		||||
- A lot of Fixes 
 | 
			
		||||
- New Features for BitmapPrinter
 | 
			
		||||
## 0.8.3
 | 
			
		||||
- Added Overlaycount to Info
 | 
			
		||||
- Addet ResultDecoder for errors
 | 
			
		||||
## 0.8.2
 | 
			
		||||
- Fix a lot of Stuff
 | 
			
		||||
- Use c++17 std::filesystem for RenderD7::Filesystem
 | 
			
		||||
## 0.8.1
 | 
			
		||||
- Add abillity to Get Stdout as string to render it to the screen.
 | 
			
		||||
## 0.8.0
 | 
			
		||||
- Implement BitmapPrinter
 | 
			
		||||
## 0.7.3
 | 
			
		||||
- Implement Over Render Overlay Framework
 | 
			
		||||
## 0.7.2
 | 
			
		||||
- Implement MT to csv file saving
 | 
			
		||||
- Add RGB2HEX
 | 
			
		||||
## 0.7.1
 | 
			
		||||
- Add the New Overlay Handler. Its Just in code and does nothing yet
 | 
			
		||||
## 0.7.0
 | 
			
		||||
- Made Big Progress In the MT Ovl but it still crashes On a 2nd C3D_FrameEnd                                                            \
 | 
			
		||||
- Implement 800px but doesn't work that good
 | 
			
		||||
## 0.6.2
 | 
			
		||||
- Fix Crash when exiting through Home Menu.
 | 
			
		||||
## 0.6.10
 | 
			
		||||
- Rewrite Threadsystem
 | 
			
		||||
- Improve framerate
 | 
			
		||||
## 0.6.02
 | 
			
		||||
- Fix Code in lang.hpp
 | 
			
		||||
- Add Draw Text Left Function (Right since 0.7.0)
 | 
			
		||||
- Add changelog
 | 
			
		||||
## 0.6.01
 | 
			
		||||
- Add Threading system
 | 
			
		||||
## 0.6.0
 | 
			
		||||
- Better Scene Management
 | 
			
		||||
## 0.5.0
 | 
			
		||||
- Fixed some Bugs!
 | 
			
		||||
## 0.4.0 
 | 
			
		||||
- Trying to fix Filesystem and Bugs
 | 
			
		||||
## 0.3.0
 | 
			
		||||
- Recreate D7-Core into RenderD7
 | 
			
		||||
## 0.2.0
 | 
			
		||||
- Trying to create Animations of Images instead of Sheets
 | 
			
		||||
## 0.1.0
 | 
			
		||||
- Inital Release of D7-Core sprite animation plugin
 | 
			
		||||
							
								
								
									
										42
									
								
								LICENSE
									
									
									
									
									
								
							
							
						
						
									
										42
									
								
								LICENSE
									
									
									
									
									
								
							@@ -1,21 +1,21 @@
 | 
			
		||||
MIT License
 | 
			
		||||
 | 
			
		||||
Copyright (c) 2024 Tobi
 | 
			
		||||
 | 
			
		||||
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.
 | 
			
		||||
MIT License
 | 
			
		||||
 | 
			
		||||
Copyright (c) 2024 tobid7
 | 
			
		||||
 | 
			
		||||
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.
 | 
			
		||||
							
								
								
									
										64
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										64
									
								
								README.md
									
									
									
									
									
								
							@@ -1,2 +1,62 @@
 | 
			
		||||
# palladium
 | 
			
		||||
New Library for everything based on RenderD7
 | 
			
		||||
# Palladium
 | 
			
		||||
Create README ? 
 | 
			
		||||
# RenderD7 as Submodule (0.9.5+)
 | 
			
		||||
To use RenderD7 just use this command: `git submodule add https://github.com/NPI-D7/RenderD7` and add `-b v0.9.5` for example for a specific version.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
And in Your Project Makefile add this
 | 
			
		||||
```
 | 
			
		||||
# Make Sure to Change this paths if your Submodule
 | 
			
		||||
# is located somewhere else
 | 
			
		||||
RENDERD7_SRC := RenderD7/source RenderD7/external
 | 
			
		||||
RENDERD7_INC := RenderD7/include
 | 
			
		||||
# Libraries used for RenderD7
 | 
			
		||||
# if you already use -lm, -lctru etc place a # before -lm
 | 
			
		||||
RENDERD7_LIBS := -lcurl -lmbedtls -lmbedx509 -lmbedcrypto -lz -lm -lcitro2dd -lcitro3d -lctru
 | 
			
		||||
```
 | 
			
		||||
Now you need to add it to your sources and includes
 | 
			
		||||
```
 | 
			
		||||
SOURCES		:=	source $(RENDERD7_SRC)
 | 
			
		||||
INCLUDES	:=	source $(RENDERD7_INC)
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Example from rd7tf
 | 
			
		||||
### Installation (0.8.0-0.9.4) (OUTDATED)
 | 
			
		||||
Download a Package From Releses Page
 | 
			
		||||
`https://github.com/NPI-D7/RenderD7/releases/download/v0.9.4/renderd7.tar.bz2 -o renderd7.tar.bz2`
 | 
			
		||||
Then Extract it to your Libraries Path
 | 
			
		||||
`bzip2 -cd renderd7.tar.bz2 | tar -xf - -C path_to_your_libs`
 | 
			
		||||
Finally put `-lrenderd7` to the First Place and add the path_to_your_libs
 | 
			
		||||
```
 | 
			
		||||
LIBS	:= -lrenderd7 -lcurl -lstdc++ -lm -lcitro2d -lcitro3d -lctru
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
# list of directories containing libraries, this must be the top level containing
 | 
			
		||||
# include and lib
 | 
			
		||||
#---------------------------------------------------------------------------------
 | 
			
		||||
LIBDIRS	:= $(PORTLIBS) $(CTRULIB) ../path_to_your_libs
 | 
			
		||||
```
 | 
			
		||||
Make sure that `-lrenderd7` is before `-lcitro2d`, `-lcitro3d`, `-lctru`.
 | 
			
		||||
Here an example tree
 | 
			
		||||
```
 | 
			
		||||
Example-App
 | 
			
		||||
├── gfx
 | 
			
		||||
├── libs
 | 
			
		||||
│   ├── include
 | 
			
		||||
│   │   ├── rd7.hpp
 | 
			
		||||
│   │   └── renderd7
 | 
			
		||||
│   └── lib
 | 
			
		||||
│       ├── librenderd7.a
 | 
			
		||||
│       └── librenderd7d.a
 | 
			
		||||
├── Makefile
 | 
			
		||||
├── romfs
 | 
			
		||||
│   └── gfx
 | 
			
		||||
└── src
 | 
			
		||||
    └── main.cpp
 | 
			
		||||
```
 | 
			
		||||
# Credits
 | 
			
		||||
- NPI-D7
 | 
			
		||||
  - Tobi-D7 Main Dev
 | 
			
		||||
 | 
			
		||||
Some Icons are From
 | 
			
		||||
https://icons8.de/
 | 
			
		||||
See Subfolder Readmes
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										27
									
								
								clang-format.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								clang-format.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
import subprocess
 | 
			
		||||
import glob
 | 
			
		||||
from pathlib import Path
 | 
			
		||||
# Format script
 | 
			
		||||
 | 
			
		||||
def fmt_file(path):
 | 
			
		||||
        if Path(path).is_dir():
 | 
			
		||||
             return # Skip
 | 
			
		||||
        try:
 | 
			
		||||
            subprocess.run(['clang-format', '-i', path, '--style=Google'], check=True)
 | 
			
		||||
        except subprocess.CalledProcessError as e:
 | 
			
		||||
            print('Error for ' + Path(path).stem + ': ' + e)
 | 
			
		||||
 | 
			
		||||
def fmt_dir(path):
 | 
			
		||||
    sources = glob.glob(path+'/*')
 | 
			
		||||
    for file in sources:
 | 
			
		||||
        fmt_file(file)
 | 
			
		||||
 | 
			
		||||
print('Formatting...')
 | 
			
		||||
fmt_dir('source')
 | 
			
		||||
fmt_dir('include')
 | 
			
		||||
fmt_dir('include/renderd7')
 | 
			
		||||
 | 
			
		||||
# Format LE and TF as well
 | 
			
		||||
fmt_dir('rd7tf/source')
 | 
			
		||||
#fmt_dir('rd7le/source')
 | 
			
		||||
print('Done')
 | 
			
		||||
							
								
								
									
										18
									
								
								docs/javascripts/mathjax.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								docs/javascripts/mathjax.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
<div class="md-copyright">
 | 
			
		||||
  {% if config.copyright %}
 | 
			
		||||
    <div class="md-copyright__highlight">
 | 
			
		||||
      {{ config.copyright }}
 | 
			
		||||
    </div>
 | 
			
		||||
  {% endif %}
 | 
			
		||||
  {% if not config.extra.generator == false %}
 | 
			
		||||
    Made with
 | 
			
		||||
    <a href="https://doxide.org" target="_blank" rel="noopener">
 | 
			
		||||
      Doxide
 | 
			
		||||
    </a>
 | 
			
		||||
    and
 | 
			
		||||
    <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
 | 
			
		||||
      Material for MkDocs
 | 
			
		||||
    </a>
 | 
			
		||||
  {% endif %}
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										18
									
								
								docs/overrides/partials/copyright.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								docs/overrides/partials/copyright.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
<div class="md-copyright">
 | 
			
		||||
  {% if config.copyright %}
 | 
			
		||||
    <div class="md-copyright__highlight">
 | 
			
		||||
      {{ config.copyright }}
 | 
			
		||||
    </div>
 | 
			
		||||
  {% endif %}
 | 
			
		||||
  {% if not config.extra.generator == false %}
 | 
			
		||||
    Made with
 | 
			
		||||
    <a href="https://doxide.org" target="_blank" rel="noopener">
 | 
			
		||||
      Doxide
 | 
			
		||||
    </a>
 | 
			
		||||
    and
 | 
			
		||||
    <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
 | 
			
		||||
      Material for MkDocs
 | 
			
		||||
    </a>
 | 
			
		||||
  {% endif %}
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										49
									
								
								docs/stylesheets/doxide.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								docs/stylesheets/doxide.css
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,49 @@
 | 
			
		||||
:root {
 | 
			
		||||
  --md-admonition-icon--variable: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20.41 3c1.39 2.71 1.94 5.84 1.59 9-.2 3.16-1.3 6.29-3.17 9l-1.53-1c1.61-2.43 2.55-5.2 2.7-8 .34-2.8-.11-5.57-1.3-8l1.71-1M5.17 3 6.7 4C5.09 6.43 4.15 9.2 4 12c-.34 2.8.12 5.57 1.3 8l-1.69 1c-1.4-2.71-1.96-5.83-1.61-9 .2-3.16 1.3-6.29 3.17-9m6.91 7.68 2.32-3.23h2.53l-3.78 5 2.2 4.92h-2.26L11.71 14l-2.43 3.33H6.76l3.9-5.12-2.13-4.76h2.27l1.28 3.23Z"/></svg>');
 | 
			
		||||
  --md-admonition-icon--function: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15.6 5.29c-1.1-.1-2.07.71-2.17 1.82L13.18 10H16v2h-3l-.44 5.07a3.986 3.986 0 0 1-4.33 3.63 4.007 4.007 0 0 1-3.06-1.87l1.5-1.5c.24.74.9 1.31 1.73 1.38 1.1.1 2.07-.71 2.17-1.82L11 12H8v-2h3.17l.27-3.07c.19-2.2 2.13-3.83 4.33-3.63 1.31.11 2.41.84 3.06 1.87l-1.5 1.5c-.24-.74-.9-1.31-1.73-1.38Z"/></svg>');
 | 
			
		||||
  --md-admonition-icon--concept: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3.75 3.5a.25.25 0 0 0-.25.25v2.062a.75.75 0 1 1-1.5 0V3.75C2 2.783 2.783 2 3.75 2h2.062a.75.75 0 1 1 0 1.5Zm13.688-.75a.75.75 0 0 1 .75-.75h2.062c.966 0 1.75.783 1.75 1.75v2.062a.75.75 0 1 1-1.5 0V3.75a.25.25 0 0 0-.25-.25h-2.062a.75.75 0 0 1-.75-.75ZM2.75 17.438a.75.75 0 0 1 .75.75v2.062c0 .138.112.25.25.25h2.062a.75.75 0 1 1 0 1.5H3.75A1.75 1.75 0 0 1 2 20.25v-2.062a.75.75 0 0 1 .75-.75Zm18.5 0a.75.75 0 0 1 .75.75v2.062A1.75 1.75 0 0 1 20.25 22h-2.062a.75.75 0 1 1 0-1.5h2.062a.25.25 0 0 0 .25-.25v-2.062a.75.75 0 0 1 .75-.75Zm-18.5-8.25a.75.75 0 0 1 .75.75v4.124a.75.75 0 1 1-1.5 0V9.938a.75.75 0 0 1 .75-.75ZM9.188 2.75a.75.75 0 0 1 .75-.75h4.124a.75.75 0 1 1 0 1.5H9.938a.75.75 0 0 1-.75-.75Zm0 18.5a.75.75 0 0 1 .75-.75h4.124a.75.75 0 1 1 0 1.5H9.938a.75.75 0 0 1-.75-.75ZM21.25 9.188a.75.75 0 0 1 .75.75v4.124a.75.75 0 1 1-1.5 0V9.938a.75.75 0 0 1 .75-.75ZM3.75 8.25a.75.75 0 0 1 .75-.75h2a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1-.75-.75Zm5.5 0A.75.75 0 0 1 10 7.5h2A.75.75 0 0 1 12 9h-2a.75.75 0 0 1-.75-.75Zm-1-4.5A.75.75 0 0 1 9 4.5v2a.75.75 0 0 1-1.5 0v-2a.75.75 0 0 1 .75-.75Zm0 5.5A.75.75 0 0 1 9 10v2a.75.75 0 0 1-1.5 0v-2a.75.75 0 0 1 .75-.75Zm0 4.75a.75.75 0 0 1 .75.75v4a.75.75 0 0 1-1.5 0v-4a.75.75 0 0 1 .75-.75ZM14 8.25a.75.75 0 0 1 .75-.75h4a.75.75 0 0 1 0 1.5h-4a.75.75 0 0 1-.75-.75Z"/></svg>');
 | 
			
		||||
  --md-admonition-icon--macro: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="m5.41 21 .71-4h-4l.35-2h4l1.06-6h-4l.35-2h4l.71-4h2l-.71 4h6l.71-4h2l-.71 4h4l-.35 2h-4l-1.06 6h4l-.35 2h-4l-.71 4h-2l.71-4h-6l-.71 4h-2M9.53 9l-1.06 6h6l1.06-6h-6Z"/></svg>');
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.md-typeset .admonition.variable, .md-typeset details.variable,
 | 
			
		||||
.md-typeset .admonition.function, .md-typeset details.function,
 | 
			
		||||
.md-typeset .admonition.concept, .md-typeset details.concept,
 | 
			
		||||
.md-typeset .admonition.macro, .md-typeset details.macro {
 | 
			
		||||
  border-color: var(--md-default-fg-color--lighter);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.md-typeset .variable > .admonition-title, .md-typeset .variable > summary,
 | 
			
		||||
.md-typeset .function > .admonition-title, .md-typeset .function > summary,
 | 
			
		||||
.md-typeset .concept > .admonition-title, .md-typeset .concept > summary,
 | 
			
		||||
.md-typeset .macro > .admonition-title, .md-typeset .macro > summary {
 | 
			
		||||
  background-color: var(--md-default-bg-color);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.md-typeset .variable > .admonition-title::before,
 | 
			
		||||
.md-typeset .variable > summary::before {
 | 
			
		||||
  background-color: var(--md-default-fg-color--light);
 | 
			
		||||
  -webkit-mask-image: var(--md-admonition-icon--variable);
 | 
			
		||||
          mask-image: var(--md-admonition-icon--variable);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.md-typeset .function > .admonition-title::before,
 | 
			
		||||
.md-typeset .function > summary::before {
 | 
			
		||||
  background-color: var(--md-default-fg-color--light);
 | 
			
		||||
  -webkit-mask-image: var(--md-admonition-icon--function);
 | 
			
		||||
          mask-image: var(--md-admonition-icon--function);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.md-typeset .concept > .admonition-title::before,
 | 
			
		||||
.md-typeset .concept > summary::before {
 | 
			
		||||
  background-color: var(--md-default-fg-color--light);
 | 
			
		||||
  -webkit-mask-image: var(--md-admonition-icon--concept);
 | 
			
		||||
          mask-image: var(--md-admonition-icon--concept);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.md-typeset .macro > .admonition-title::before,
 | 
			
		||||
.md-typeset .macro > summary::before {
 | 
			
		||||
  background-color: var(--md-default-fg-color--light);
 | 
			
		||||
  -webkit-mask-image: var(--md-admonition-icon--macro);
 | 
			
		||||
          mask-image: var(--md-admonition-icon--macro);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										9
									
								
								doxide.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								doxide.yaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
title: Palladium
 | 
			
		||||
description: 
 | 
			
		||||
files:
 | 
			
		||||
  - "include/*.hpp"
 | 
			
		||||
  - "include/pd/*.hpp"
 | 
			
		||||
  - "include/pd/music/*.hpp"
 | 
			
		||||
  - "include/*.h"
 | 
			
		||||
  - "include/pd/*.h"
 | 
			
		||||
  - "include/pd/music/*.h"
 | 
			
		||||
							
								
								
									
										24
									
								
								include/pd.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								include/pd.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <pd/Allocator.hpp>
 | 
			
		||||
#include <pd/Error.hpp>
 | 
			
		||||
#include <pd/FileSystem.hpp>
 | 
			
		||||
#include <pd/Hid.hpp>
 | 
			
		||||
#include <pd/Image.hpp>
 | 
			
		||||
#include <pd/Installer.hpp>
 | 
			
		||||
#include <pd/Message.hpp>
 | 
			
		||||
#include <pd/Net.hpp>
 | 
			
		||||
#include <pd/Overlays.hpp>
 | 
			
		||||
#include <pd/Sound.hpp>
 | 
			
		||||
#include <pd/Timer.hpp>
 | 
			
		||||
#include <pd/UI7.hpp>
 | 
			
		||||
#include <pd/global_db.hpp>
 | 
			
		||||
#include <pd/palladium.hpp>
 | 
			
		||||
#include <pd/swr.hpp>
 | 
			
		||||
#include <pd/Texture.hpp>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
    using Render2 = R2;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace PD = Palladium;
 | 
			
		||||
							
								
								
									
										40
									
								
								include/pd/Allocator.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								include/pd/Allocator.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <3ds.h>
 | 
			
		||||
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <pd/Error.hpp>
 | 
			
		||||
 | 
			
		||||
// Write own LinearAllocator for learning
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
template <typename T>
 | 
			
		||||
class LinearAllocator : public std::allocator<T> {
 | 
			
		||||
 public:
 | 
			
		||||
  typedef size_t size_type;
 | 
			
		||||
  typedef T* pointer;
 | 
			
		||||
  typedef const T* const_pointer;
 | 
			
		||||
 | 
			
		||||
  template <typename T1>
 | 
			
		||||
  struct rebind {
 | 
			
		||||
    typedef LinearAllocator<T1> other;
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  pointer allocate(size_type n, const void* hint = nullptr) {
 | 
			
		||||
    if (n > this->max_size()) {
 | 
			
		||||
      Palladium::Error(
 | 
			
		||||
          "Linear Allocator: \nBad Alloc -> size is larger than free space!");
 | 
			
		||||
      return nullptr;
 | 
			
		||||
    }
 | 
			
		||||
    return (pointer)linearAlloc(n * sizeof(T));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void deallocate(pointer p, size_type) { linearFree((void*)p); }
 | 
			
		||||
 | 
			
		||||
  size_type max_size() { return linearSpaceFree(); }
 | 
			
		||||
 | 
			
		||||
  LinearAllocator() throw() {}
 | 
			
		||||
  LinearAllocator(const LinearAllocator<T>& a) throw() : std::allocator<T>(a) {}
 | 
			
		||||
  ~LinearAllocator() throw() {}
 | 
			
		||||
};
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										204
									
								
								include/pd/Color.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										204
									
								
								include/pd/Color.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,204 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
#include <cstring>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <pd/smart_ctor.hpp>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#define UNPACK_RGBA(col) \
 | 
			
		||||
  (unsigned char)(col >> 24), (col >> 16), (col >> 8), (col)
 | 
			
		||||
#define UNPACK_BGRA(col) \
 | 
			
		||||
  (unsigned char)(col >> 8), (col >> 16), (col >> 24), (col)
 | 
			
		||||
 | 
			
		||||
inline unsigned int RGBA8(unsigned char r, unsigned char g, unsigned char b,
 | 
			
		||||
                          unsigned char a = 255) {
 | 
			
		||||
  return (r | g << 8 | b << 16 | a << 24);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
typedef int PDColor;
 | 
			
		||||
 | 
			
		||||
// MultiColor (Less FunctionNameLen)
 | 
			
		||||
 | 
			
		||||
struct Color2 {
 | 
			
		||||
  unsigned int color0;
 | 
			
		||||
  unsigned int color1;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct Color3 {
 | 
			
		||||
  unsigned int color0;
 | 
			
		||||
  unsigned int color1;
 | 
			
		||||
  unsigned int color2;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct Color4 {
 | 
			
		||||
  unsigned int color0;
 | 
			
		||||
  unsigned int color1;
 | 
			
		||||
  unsigned int color2;
 | 
			
		||||
  unsigned int color3;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum PDColor_ {
 | 
			
		||||
  PDColor_Text,  ///< This Color Should always be used for Light Backgrounds
 | 
			
		||||
  PDColor_TextDisabled,  /// Text Disabled Color
 | 
			
		||||
  PDColor_Text2,         ///< And This want for Texts on Dark Backgrounds
 | 
			
		||||
  PDColor_Background,    ///< Your Bg Color
 | 
			
		||||
  PDColor_Header,    ///< Header Color (if the header is dark text2 is used)
 | 
			
		||||
  PDColor_Selector,  ///< Selector Color
 | 
			
		||||
  PDColor_SelectorFade,       ///< Selector FadingTo Color
 | 
			
		||||
  PDColor_List0,              ///< List Color1
 | 
			
		||||
  PDColor_List1,              ///< List Color2
 | 
			
		||||
  PDColor_MessageBackground,  ///< Message Background
 | 
			
		||||
  PDColor_Button,             ///< Button Color
 | 
			
		||||
  PDColor_ButtonHovered,      ///< Button Color if Hovered
 | 
			
		||||
  PDColor_ButtonDisabled,     ///< Button Color if disabled
 | 
			
		||||
  PDColor_ButtonActive,       ///< Button Colkor if Clicked
 | 
			
		||||
  PDColor_Checkmark,          ///< Checkbox Checkmark Color
 | 
			
		||||
  PDColor_FrameBg,            ///< Frame Background Color
 | 
			
		||||
  PDColor_FrameBgHovered,     ///< Frame Background Color if hovered
 | 
			
		||||
  PDColor_Progressbar,        ///< Progressbar Color
 | 
			
		||||
  /// NON COLOR ///
 | 
			
		||||
  PDColor_Len,  ///< Used to define the lengh of this list
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
class Theme {
 | 
			
		||||
 public:
 | 
			
		||||
  Theme() = default;
 | 
			
		||||
  ~Theme() = default;
 | 
			
		||||
 | 
			
		||||
  void Load(const std::string &path);
 | 
			
		||||
  void Default();
 | 
			
		||||
  void Save(const std::string &path);
 | 
			
		||||
 | 
			
		||||
  unsigned int Get(PDColor clr);
 | 
			
		||||
  void Set(PDColor clr, unsigned int v);
 | 
			
		||||
  void Swap(PDColor a, PDColor b);
 | 
			
		||||
  bool Undo();
 | 
			
		||||
  void UndoAll();
 | 
			
		||||
  void TextBy(PDColor bg);
 | 
			
		||||
  PDColor AutoText(PDColor bg);
 | 
			
		||||
  void ClearHistory() { changes.clear(); }
 | 
			
		||||
 | 
			
		||||
  std::vector<unsigned int> &GetTableRef() { return clr_tab; }
 | 
			
		||||
  // For Smart Pointer
 | 
			
		||||
  PD_SMART_CTOR(Theme);
 | 
			
		||||
 | 
			
		||||
  // Loader method
 | 
			
		||||
  void CopyOther(Theme::Ref theme);
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  struct change {
 | 
			
		||||
    change(PDColor a, unsigned int f, unsigned int t)
 | 
			
		||||
        : clr(a), from(f), to(t) {}
 | 
			
		||||
    change(PDColor a, PDColor b, unsigned int f, unsigned int t)
 | 
			
		||||
        : clr(a), clr2(b), from(f), to(t) {}
 | 
			
		||||
    PDColor clr;
 | 
			
		||||
    PDColor clr2 = 0;  // Used if Swap
 | 
			
		||||
    unsigned int from;
 | 
			
		||||
    unsigned int to;
 | 
			
		||||
  };
 | 
			
		||||
  // Use a vector for faster access
 | 
			
		||||
  std::vector<unsigned int> clr_tab;
 | 
			
		||||
  std::vector<change> changes;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Theme::Ref ThemeActive();
 | 
			
		||||
/// @brief Change Theme Adress
 | 
			
		||||
/// @param theme your adress
 | 
			
		||||
void ThemeSet(Theme::Ref theme);
 | 
			
		||||
namespace Color {
 | 
			
		||||
/// @brief RGBA Class
 | 
			
		||||
class RGBA {
 | 
			
		||||
 public:
 | 
			
		||||
  /// @brief Construct
 | 
			
		||||
  /// @param r
 | 
			
		||||
  /// @param g
 | 
			
		||||
  /// @param b
 | 
			
		||||
  /// @param a
 | 
			
		||||
  RGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255)
 | 
			
		||||
      : m_r(r), m_g(g), m_b(b), m_a(a) {}
 | 
			
		||||
  /// @brief Construct
 | 
			
		||||
  /// @param r
 | 
			
		||||
  /// @param g
 | 
			
		||||
  /// @param b
 | 
			
		||||
  /// @param a
 | 
			
		||||
  RGBA(float r, float g, float b, float a = 1.f)
 | 
			
		||||
      : m_r(r * 255.f), m_g(g * 255.f), m_b(b * 255.f), m_a(a * 255.f) {}
 | 
			
		||||
  RGBA(unsigned int in) {
 | 
			
		||||
#define ISIMPLEUNPAK(x, y) (((x) >> y) & 0xFF)
 | 
			
		||||
    m_r = ISIMPLEUNPAK(in, 0);
 | 
			
		||||
    m_g = ISIMPLEUNPAK(in, 8);
 | 
			
		||||
    m_b = ISIMPLEUNPAK(in, 16);
 | 
			
		||||
    m_a = ISIMPLEUNPAK(in, 24);
 | 
			
		||||
  }
 | 
			
		||||
  RGBA(PDColor in) {
 | 
			
		||||
    if (!Palladium::ThemeActive()) return;
 | 
			
		||||
    unsigned int col = Palladium::ThemeActive()->Get(in);
 | 
			
		||||
    m_r = ISIMPLEUNPAK(col, 0);
 | 
			
		||||
    m_g = ISIMPLEUNPAK(col, 8);
 | 
			
		||||
    m_b = ISIMPLEUNPAK(col, 16);
 | 
			
		||||
    m_a = ISIMPLEUNPAK(col, 24);
 | 
			
		||||
  }
 | 
			
		||||
  RGBA &changeR(unsigned char r) {
 | 
			
		||||
    m_r = r;
 | 
			
		||||
    return *this;
 | 
			
		||||
  }
 | 
			
		||||
  RGBA &changeG(unsigned char g) {
 | 
			
		||||
    m_g = g;
 | 
			
		||||
    return *this;
 | 
			
		||||
  }
 | 
			
		||||
  RGBA &changeB(unsigned char b) {
 | 
			
		||||
    m_b = b;
 | 
			
		||||
    return *this;
 | 
			
		||||
  }
 | 
			
		||||
  RGBA &changeA(unsigned char a) {
 | 
			
		||||
    m_a = a;
 | 
			
		||||
    return *this;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  RGBA &fade_to(const RGBA &color, float p) {
 | 
			
		||||
    m_a =
 | 
			
		||||
        m_a + static_cast<unsigned char>((color.m_a - m_a) * ((p + 1.0f) / 2));
 | 
			
		||||
    m_b =
 | 
			
		||||
        m_b + static_cast<unsigned char>((color.m_b - m_b) * ((p + 1.0f) / 2));
 | 
			
		||||
    m_g =
 | 
			
		||||
        m_g + static_cast<unsigned char>((color.m_g - m_g) * ((p + 1.0f) / 2));
 | 
			
		||||
    m_r =
 | 
			
		||||
        m_r + static_cast<unsigned char>((color.m_r - m_r) * ((p + 1.0f) / 2));
 | 
			
		||||
    return *this;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// @brief Get as Uint32
 | 
			
		||||
  /// @return color
 | 
			
		||||
  unsigned int toRGBA() const { return RGBA8(m_r, m_g, m_b, m_a); }
 | 
			
		||||
 | 
			
		||||
  // Just calculate the "lightness" f.e. to use Text or Text2
 | 
			
		||||
  float luminance() const {
 | 
			
		||||
    // For Reference https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
 | 
			
		||||
    return (0.3 * (m_r / 255.f) + 0.59 * (m_g / 255.f) + 0.11 * (m_b / 255.f));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  bool is_light() {
 | 
			
		||||
    // Gives us the light or dark to not
 | 
			
		||||
    // always use the below "if" statement
 | 
			
		||||
    return (luminance() >= 0.5);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  unsigned char m_r = 0, m_g = 0, m_b = 0, m_a = 0;
 | 
			
		||||
};
 | 
			
		||||
std::string RGBA2Hex(unsigned int c32);
 | 
			
		||||
/// @brief Convert RGB to Hex
 | 
			
		||||
/// @param r
 | 
			
		||||
/// @param g
 | 
			
		||||
/// @param b
 | 
			
		||||
/// @return Hex-String
 | 
			
		||||
std::string RGB2Hex(int r, int g, int b);
 | 
			
		||||
/// @brief Hex to U32
 | 
			
		||||
/// @param color
 | 
			
		||||
/// @param a
 | 
			
		||||
/// @return Color32
 | 
			
		||||
unsigned int Hex(const std::string &color, unsigned char a = 255);
 | 
			
		||||
}  // namespace Color
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										18
									
								
								include/pd/Error.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								include/pd/Error.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
void Error(const std::string& msg);
 | 
			
		||||
inline void InlineError(const std::string& msg) {
 | 
			
		||||
  std::string location = __FILE__ + std::string(":") + std::to_string(__LINE__);
 | 
			
		||||
  Error("Error: \n" + location + "\n" + msg);
 | 
			
		||||
}
 | 
			
		||||
inline void InlineAssert(bool v, const std::string& msg) {
 | 
			
		||||
  if (v == false) {
 | 
			
		||||
    std::string location =
 | 
			
		||||
        __FILE__ + std::string(":") + std::to_string(__LINE__);
 | 
			
		||||
    Error("Assert Failed:\n" + location + "\n" + msg);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										24
									
								
								include/pd/FileSystem.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								include/pd/FileSystem.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
namespace FileSystem {
 | 
			
		||||
/// @brief A Directory Entry
 | 
			
		||||
struct Entry {
 | 
			
		||||
  /// @brief Patf of The Entry
 | 
			
		||||
  std::string path;
 | 
			
		||||
  /// @brief Name of The Entry
 | 
			
		||||
  std::string name;
 | 
			
		||||
  /// @brief Directory or File
 | 
			
		||||
  bool dir = false;
 | 
			
		||||
};
 | 
			
		||||
/// @brief Gets All Entrys of A Directory into a Vector
 | 
			
		||||
/// @param path The Path of the Directory
 | 
			
		||||
/// @return The Vector of found Entrys
 | 
			
		||||
std::vector<Palladium::FileSystem::Entry> GetDirContent(std::string path);
 | 
			
		||||
std::string GetParentPath(std::string path, std::string mount_point);
 | 
			
		||||
std::vector<Entry> GetDirContentsExt(
 | 
			
		||||
    std::string &path, const std::vector<std::string> &extensions);
 | 
			
		||||
}  // namespace FileSystem
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										36
									
								
								include/pd/Font.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								include/pd/Font.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <citro2d.h>
 | 
			
		||||
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <pd/Error.hpp>
 | 
			
		||||
#include <pd/smart_ctor.hpp>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
class Font {
 | 
			
		||||
 public:
 | 
			
		||||
  Font() = default;
 | 
			
		||||
  Font(const std::string& path) { Load(path); };
 | 
			
		||||
  ~Font() { Unload(); }
 | 
			
		||||
  PD_SMART_CTOR(Font)
 | 
			
		||||
 | 
			
		||||
  void Load(const std::string& path) {
 | 
			
		||||
    std::ifstream ft(path, std::ios::in | std::ios::binary);
 | 
			
		||||
    bool io = ft.is_open();
 | 
			
		||||
    ft.close();
 | 
			
		||||
    Palladium::InlineAssert(io, "File not Found!");
 | 
			
		||||
    fnt = C2D_FontLoad(path.c_str());
 | 
			
		||||
    Palladium::InlineAssert(fnt, "Font could not be loaded!");
 | 
			
		||||
  }
 | 
			
		||||
  C2D_Font Ptr() { return fnt; }
 | 
			
		||||
  void Unload() {
 | 
			
		||||
    if (!fnt) return;
 | 
			
		||||
    C2D_FontFree(fnt);
 | 
			
		||||
    fnt = nullptr;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  C2D_Font fnt = nullptr;
 | 
			
		||||
};
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										76
									
								
								include/pd/FunctionTrace.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								include/pd/FunctionTrace.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,76 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
// Base includes
 | 
			
		||||
#include <functional>
 | 
			
		||||
#include <map>
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
// 3ds does not support std::chrono
 | 
			
		||||
#include <3ds.h>
 | 
			
		||||
 | 
			
		||||
/// @brief 3ds System Ticks per milli second
 | 
			
		||||
#define TICKS_PER_MSEC 268111.856
 | 
			
		||||
 | 
			
		||||
#define f2s(x_) #x_
 | 
			
		||||
#define scomb(x1, x2) std::string(x1 + x2)
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
namespace Ftrace {
 | 
			
		||||
/// @brief Result of FTrace
 | 
			
		||||
struct FTRes {
 | 
			
		||||
  std::string group;      ///< Group of the Trace
 | 
			
		||||
  std::string func_name;  ///< Function Name
 | 
			
		||||
 | 
			
		||||
  uint64_t time_start;  ///< when started
 | 
			
		||||
  uint64_t time_end;    ///< when stopped
 | 
			
		||||
  float time_of;        ///< stop - start (how long)
 | 
			
		||||
  float time_ofm;       ///< max time off
 | 
			
		||||
  bool is_ovl;          ///< is displayed in overlay?
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/// @brief Map of Traces
 | 
			
		||||
extern std::map<std::string, Palladium::Ftrace::FTRes> pd_traces;
 | 
			
		||||
 | 
			
		||||
/// @brief Set a Start TracePoint
 | 
			
		||||
/// @param group Set a Group Name
 | 
			
		||||
/// @param func_name Set a Function Name
 | 
			
		||||
inline void Beg(const std::string& group, const std::string& func_name) {
 | 
			
		||||
  std::string trace_id = scomb(group, func_name);
 | 
			
		||||
  auto& trace = pd_traces[trace_id];
 | 
			
		||||
  trace.group = group;
 | 
			
		||||
  trace.func_name = func_name;
 | 
			
		||||
  trace.time_start = svcGetSystemTick();
 | 
			
		||||
}
 | 
			
		||||
/// @brief Set an End TracePoint
 | 
			
		||||
/// @param group Set a Group Name
 | 
			
		||||
/// @param func_name Set a Function Name
 | 
			
		||||
inline void End(const std::string& group, const std::string& func_name) {
 | 
			
		||||
  std::string trace_id = scomb(group, func_name);
 | 
			
		||||
  auto& trace = pd_traces[trace_id];
 | 
			
		||||
  trace.time_end = svcGetSystemTick();
 | 
			
		||||
  if (trace.time_of > trace.time_ofm) trace.time_ofm = trace.time_of;
 | 
			
		||||
  trace.time_of =
 | 
			
		||||
      static_cast<float>(trace.time_end - trace.time_start) / TICKS_PER_MSEC;
 | 
			
		||||
}
 | 
			
		||||
/// @brief Trace a function execution
 | 
			
		||||
/// @param group Set a Group Name
 | 
			
		||||
/// @param name Set a Function Name
 | 
			
		||||
inline void Func(const std::string& group, const std::string& name,
 | 
			
		||||
                 std::function<void()> fun) {
 | 
			
		||||
  if (!fun) return;
 | 
			
		||||
  Beg(group, name);
 | 
			
		||||
  fun();
 | 
			
		||||
  End(group, name);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// @brief This Starts an Ftrace and
 | 
			
		||||
/// end ist when going out of scope
 | 
			
		||||
struct ScopedTrace {
 | 
			
		||||
  ScopedTrace(std::string g, std::string n) : group(g), name(n) {
 | 
			
		||||
    Ftrace::Beg(g, n);
 | 
			
		||||
  }
 | 
			
		||||
  ~ScopedTrace() { Ftrace::End(group, name); }
 | 
			
		||||
  std::string group;
 | 
			
		||||
  std::string name;
 | 
			
		||||
};
 | 
			
		||||
}  // namespace Ftrace
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										26
									
								
								include/pd/Hardware.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								include/pd/Hardware.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
namespace Hardware {
 | 
			
		||||
/// @brief Initialisize required Services
 | 
			
		||||
void Initialisize();
 | 
			
		||||
/// @brief Check if Headphones are Plugged in
 | 
			
		||||
/// @return true if headphones plugged in
 | 
			
		||||
bool IsHeadphones();
 | 
			
		||||
/// @brief Check if the 3ds Is Charging
 | 
			
		||||
/// @return true if System gets Charged
 | 
			
		||||
bool IsCharging();
 | 
			
		||||
/// @brief Check the Battery Percentage
 | 
			
		||||
/// @return Persentage as int
 | 
			
		||||
int GetBatteryPercentage();
 | 
			
		||||
/// @brief Get current State of 3d Slider
 | 
			
		||||
/// @return current 3dslider poition
 | 
			
		||||
float Get3dSliderLevel();
 | 
			
		||||
/// @brief Get Current state of Sound Slider
 | 
			
		||||
/// @return current SoundSlider state
 | 
			
		||||
float GetSoundSliderLevel();
 | 
			
		||||
/// @brief Get Current Wifi Level
 | 
			
		||||
/// @return current wifi level
 | 
			
		||||
int GetWifiLevel();
 | 
			
		||||
}  // namespace Hardware
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										42
									
								
								include/pd/Hid.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								include/pd/Hid.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,42 @@
 | 
			
		||||
// WARNING
 | 
			
		||||
// THIS IS BETA STUFF
 | 
			
		||||
// ITS MAKE LIKE EXTERNAL BUT
 | 
			
		||||
// FOR Palladium ITS INTEGRATED
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <pd/NVec.hpp>
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
namespace Hid {
 | 
			
		||||
enum Actions {
 | 
			
		||||
  Down = 0,
 | 
			
		||||
  Held = 1,
 | 
			
		||||
  Up = 2,
 | 
			
		||||
  DownRepeat = 3,
 | 
			
		||||
};
 | 
			
		||||
// Register Functions
 | 
			
		||||
// Register Current state values
 | 
			
		||||
void RegKeyDown(uint32_t &key_down);
 | 
			
		||||
void RegKeyHeld(uint32_t &key_held);
 | 
			
		||||
void RegKeyUp(uint32_t &key_up);
 | 
			
		||||
void RegKeyRepeat(uint32_t &repeat);
 | 
			
		||||
void RegTouchCoords(NVec2 &touch_pos);
 | 
			
		||||
// Not Corectly Implemented Yet
 | 
			
		||||
void RegAnalog1Movement(NVec2 &movement);
 | 
			
		||||
void RegAnalog2Movement(NVec2 &movement);
 | 
			
		||||
// Register Keys
 | 
			
		||||
void RegKeyEvent(const std::string &event, uint32_t key);
 | 
			
		||||
// KeyEvents
 | 
			
		||||
bool IsEvent(const std::string &event, Actions action);
 | 
			
		||||
NVec2 GetTouchPosition();
 | 
			
		||||
NVec2 GetLastTouchPosition();
 | 
			
		||||
NVec2 GetTouchDownPosition();
 | 
			
		||||
void Update();
 | 
			
		||||
// Lock/Unlock Input api for example for Keyboard
 | 
			
		||||
void Lock();
 | 
			
		||||
void Unlock();
 | 
			
		||||
void Clear();
 | 
			
		||||
}  // namespace Hid
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										33
									
								
								include/pd/Image.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								include/pd/Image.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <3ds.h>
 | 
			
		||||
#include <citro2d.h>
 | 
			
		||||
 | 
			
		||||
#include <pd/NVec.hpp>
 | 
			
		||||
#include <pd/nimg.hpp>
 | 
			
		||||
#include <pd/smart_ctor.hpp>
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
class Image {
 | 
			
		||||
 public:
 | 
			
		||||
  Image() = default;
 | 
			
		||||
  Image(C2D_Image img) { this->img = img; }
 | 
			
		||||
  Image(const std::string& path) { this->Load(path); }
 | 
			
		||||
  ~Image() = default;
 | 
			
		||||
  PD_SMART_CTOR(Image)
 | 
			
		||||
  void Load(const std::string& path);
 | 
			
		||||
  void From_NIMG(const nimg& image);
 | 
			
		||||
  void Delete();
 | 
			
		||||
 | 
			
		||||
  C2D_Image Get();
 | 
			
		||||
  C2D_Image& GetRef();
 | 
			
		||||
  void Set(const C2D_Image& i);
 | 
			
		||||
  NVec2 GetSize();
 | 
			
		||||
  bool Loadet();
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  bool ext = false;
 | 
			
		||||
  C2D_Image img;
 | 
			
		||||
};
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										16
									
								
								include/pd/Installer.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								include/pd/Installer.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <3ds.h> // Result
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
struct InstallerInfo {
 | 
			
		||||
  unsigned long long total;
 | 
			
		||||
  unsigned long long current;
 | 
			
		||||
  unsigned int mem_size = 0x80000;
 | 
			
		||||
  bool active = false;
 | 
			
		||||
};
 | 
			
		||||
Result InstallCia(const std::string& path, bool self);
 | 
			
		||||
void InstallSetBuffersSize(unsigned int bytes);
 | 
			
		||||
InstallerInfo InstallGetInfo();
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										125
									
								
								include/pd/LI7.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										125
									
								
								include/pd/LI7.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,125 @@
 | 
			
		||||
#include <pd/NVec.hpp>
 | 
			
		||||
#include <pd/Allocator.hpp>
 | 
			
		||||
#include <pd/Texture.hpp>
 | 
			
		||||
#include <citro3d.h>
 | 
			
		||||
 | 
			
		||||
#include <stdarg.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
class LIFont {
 | 
			
		||||
    public:
 | 
			
		||||
    struct CPI {
 | 
			
		||||
        unsigned char codepoint;
 | 
			
		||||
        NVec4 uv;
 | 
			
		||||
        Texture::Ref tex;
 | 
			
		||||
    };
 | 
			
		||||
    LIFont() = default;
 | 
			
		||||
    ~LIFont() = default;
 | 
			
		||||
    PD_SMART_CTOR(LIFont)
 | 
			
		||||
 | 
			
		||||
    void LoadTFF(const std::string path, int px_size = 32);
 | 
			
		||||
    void LoadBitmapFont(const std::string& path);
 | 
			
		||||
    void LoadSystemFont();
 | 
			
		||||
 | 
			
		||||
    int GetPixelHeight();
 | 
			
		||||
    CPI GetCodepoint();
 | 
			
		||||
 | 
			
		||||
    private:
 | 
			
		||||
    int pixel_height;
 | 
			
		||||
    unsigned char fontw[256];
 | 
			
		||||
    int charsize;
 | 
			
		||||
    std::vector<Texture::Ref> tex;
 | 
			
		||||
};
 | 
			
		||||
class LI7 {
 | 
			
		||||
 public:
 | 
			
		||||
 struct Vtx
 | 
			
		||||
{
 | 
			
		||||
    float xyz[3];
 | 
			
		||||
    float uv[2];
 | 
			
		||||
    unsigned int col;
 | 
			
		||||
};
 | 
			
		||||
/// CMD TYPES ///
 | 
			
		||||
/// 0 = SKIP
 | 
			
		||||
/// 1 = TRIANGLE
 | 
			
		||||
/// 2 = RECT
 | 
			
		||||
/////////////////
 | 
			
		||||
struct Cmd {
 | 
			
		||||
    NVec2 ppos;
 | 
			
		||||
    NVec2 pszs;
 | 
			
		||||
    NVec2 apos;
 | 
			
		||||
    NVec4 uv;
 | 
			
		||||
    int layer = 0;
 | 
			
		||||
    int cmd_type = 0;
 | 
			
		||||
    unsigned int clr = 0;
 | 
			
		||||
    Texture::Ref tex = nullptr;
 | 
			
		||||
};
 | 
			
		||||
  LI7() = default;
 | 
			
		||||
  ~LI7() = default;
 | 
			
		||||
 | 
			
		||||
  static void Init();
 | 
			
		||||
  static void Exit();
 | 
			
		||||
 | 
			
		||||
  static void OnScreen(bool bottom);
 | 
			
		||||
  static void Render(C3D_RenderTarget* top, C3D_RenderTarget* bot);
 | 
			
		||||
  static void Scale(float i) { m_scale = i; }
 | 
			
		||||
  static float Scale() { return m_scale; }
 | 
			
		||||
  static void BindTexture(Texture::Ref tex);
 | 
			
		||||
  static NVec2 ScreenSize() { return NVec2(m_width, m_height); }
 | 
			
		||||
 | 
			
		||||
  static void ColorRect(NVec2 pos, NVec2 szs, NVec4 uvs, unsigned int clr);
 | 
			
		||||
  static void Rect(NVec2 pos, NVec2 szs, NVec4 uvs);
 | 
			
		||||
  static void ColorRect(NVec2 pos, NVec2 szs, unsigned int clr);
 | 
			
		||||
  static void Rect(NVec2 pos, NVec2 szs);
 | 
			
		||||
  static void TexCutRect(NVec2 pos, NVec2 szs, NVec2 cb, NVec2 ce);
 | 
			
		||||
 | 
			
		||||
  static int DrawText(int x, int y, int z, unsigned int color, bool shadow,
 | 
			
		||||
                      int wrap, int* ySize, const char* fmt, ...);
 | 
			
		||||
 | 
			
		||||
  static int Vertices() { return m_d_vertices; }
 | 
			
		||||
  static int Drawcalls() { return m_d_drawcalls; }
 | 
			
		||||
  static int DarwCommandss() { return m_d_commands; }
 | 
			
		||||
 private:
 | 
			
		||||
  static bool CompareCommands(const Cmd& a,
 | 
			
		||||
                              const Cmd& b);
 | 
			
		||||
  static void RenderFrame(bool bottom);
 | 
			
		||||
  static int DrawTextVargs(int x, int y, int z, unsigned int color, bool shadow,
 | 
			
		||||
                           int wrap, int* ySize, const char* fmt, va_list arg);
 | 
			
		||||
 | 
			
		||||
  // Default Font Size in (px)
 | 
			
		||||
  static const float m_dffs;
 | 
			
		||||
 | 
			
		||||
  static int m_uLoc_proj;
 | 
			
		||||
  static float m_scale;
 | 
			
		||||
  static int m_width, m_height;
 | 
			
		||||
 | 
			
		||||
  static int m_d_vertices;
 | 
			
		||||
  static int m_d_drawcalls;
 | 
			
		||||
  static int m_d_commands;
 | 
			
		||||
 | 
			
		||||
  static const int m_char_height;  // Constant
 | 
			
		||||
  static float m_rot;
 | 
			
		||||
 | 
			
		||||
  // UI Stuff
 | 
			
		||||
  static std::vector<Cmd> m_top_draw_cmds;
 | 
			
		||||
  static std::vector<Cmd> m_bot_draw_cmds;
 | 
			
		||||
  static Texture::Ref m_current_texture;
 | 
			
		||||
  static std::vector<Vtx, LinearAllocator<Vtx>> m_vtx_list[2];
 | 
			
		||||
  //static Font* m_font;
 | 
			
		||||
  static std::vector<char> m_text_buffer;
 | 
			
		||||
 | 
			
		||||
  // Matrix
 | 
			
		||||
  static C3D_Mtx m_icon_model_matrix;
 | 
			
		||||
 | 
			
		||||
  // Ctx Stuff
 | 
			
		||||
  static bool m_bottom_active;
 | 
			
		||||
 | 
			
		||||
  // Shader
 | 
			
		||||
  static DVLB_s *li7_dvlb;
 | 
			
		||||
  static shaderProgram_s li7_shader;
 | 
			
		||||
  static C3D_AttrInfo li7_attr;
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										35
									
								
								include/pd/Logger.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								include/pd/Logger.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <pd/smart_ctor.hpp>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
 | 
			
		||||
/// @brief Logger base Class
 | 
			
		||||
class LoggerBase {
 | 
			
		||||
 public:
 | 
			
		||||
  /// @brief Constructor
 | 
			
		||||
  LoggerBase() = default;
 | 
			
		||||
  /// @brief Deconstructor
 | 
			
		||||
  ~LoggerBase();
 | 
			
		||||
  PD_SMART_CTOR(LoggerBase)
 | 
			
		||||
  /// @brief Init the Logger
 | 
			
		||||
  /// @param filename name[_date_time.txt]
 | 
			
		||||
  void Init(const std::string& name, bool fileless = false);
 | 
			
		||||
  /// @brief Write a String
 | 
			
		||||
  /// @param debug_text string
 | 
			
		||||
  /// @param lvl Logger LVL 0 = ERR, 1  =WARNING, >=2= Default
 | 
			
		||||
  void Write(const std::string& debug_text, int lvl = 2);
 | 
			
		||||
  void SetLvl(int lvl) { writelvl = lvl; }
 | 
			
		||||
  const std::vector<std::string>& Lines();
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  /// \param filename the name of the logfile
 | 
			
		||||
  std::string filename;
 | 
			
		||||
  std::string log_path;
 | 
			
		||||
  std::ofstream _log;
 | 
			
		||||
  int writelvl = 1;  // Only log errors/Warnings
 | 
			
		||||
  std::vector<std::string> lines;
 | 
			
		||||
};
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										24
									
								
								include/pd/Memory.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								include/pd/Memory.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <cstddef>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
namespace Memory {
 | 
			
		||||
/// @brief Metriks struct For the Internal Tracker
 | 
			
		||||
struct memory_metrics {
 | 
			
		||||
  unsigned int t_TotalAllocated = 0;  ///< Total Allocated Memory
 | 
			
		||||
  unsigned int t_TotalFreed = 0;      ///< Total Deleted Memory
 | 
			
		||||
  /// @brief Gets the Currently Allocated Memory
 | 
			
		||||
  unsigned int t_CurrentlyAllocated() { return t_TotalAllocated - t_TotalFreed; }
 | 
			
		||||
};
 | 
			
		||||
/// @brief Get Total Allocated Memory
 | 
			
		||||
/// @return Total Allocated Memory
 | 
			
		||||
size_t GetTotalAllocated();
 | 
			
		||||
/// @brief Get Total Deleted Memory
 | 
			
		||||
/// @return Total Deleted Memory
 | 
			
		||||
size_t GetTotalFreed();
 | 
			
		||||
/// @brief Get Current Allocated Memory
 | 
			
		||||
/// @return Current Allocated Memory
 | 
			
		||||
size_t GetCurrent();
 | 
			
		||||
}  // namespace Memory
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										27
									
								
								include/pd/Message.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								include/pd/Message.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
struct Message {
 | 
			
		||||
  Message(std::string t, std::string m) {
 | 
			
		||||
    title = t;
 | 
			
		||||
    message = m;
 | 
			
		||||
    animationframe = 0;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  std::string title;
 | 
			
		||||
  std::string message;
 | 
			
		||||
  int animationframe;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void ProcessMessages();
 | 
			
		||||
void PushMessage(const Message& msg);
 | 
			
		||||
inline void PushMessage(const std::string& head, const std::string& msg) {
 | 
			
		||||
  PushMessage(Message(head, msg));
 | 
			
		||||
}
 | 
			
		||||
// Config
 | 
			
		||||
void SetMessageIdleStartFrame(int frame);
 | 
			
		||||
void SetMessageTotalAnimationFrames(int total_frames);
 | 
			
		||||
void SetMessageFadeOutStartFrame(int frame);
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										104
									
								
								include/pd/NVec.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										104
									
								
								include/pd/NVec.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,104 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
struct NVec2 {
 | 
			
		||||
  // Init Funcs
 | 
			
		||||
  NVec2() : x(0), y(0) {}
 | 
			
		||||
  NVec2(float i0, float i1) : x(i0), y(i1) {}
 | 
			
		||||
  NVec2(const NVec2 &i) {
 | 
			
		||||
    x = i.x;
 | 
			
		||||
    y = i.y;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Operators
 | 
			
		||||
  // Add
 | 
			
		||||
  NVec2 &operator+=(const NVec2 &i) {
 | 
			
		||||
    x += i.x;
 | 
			
		||||
    y += i.y;
 | 
			
		||||
    return *this;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  NVec2 operator+(const NVec2 &i) const { return NVec2(x + i.x, y + i.y); }
 | 
			
		||||
 | 
			
		||||
  // Sub
 | 
			
		||||
  NVec2 &operator-=(const NVec2 &i) {
 | 
			
		||||
    x -= i.x;
 | 
			
		||||
    y -= i.y;
 | 
			
		||||
    return *this;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  NVec2 operator-(const NVec2 &i) const { return NVec2(x - i.x, y - i.y); }
 | 
			
		||||
 | 
			
		||||
  // Compare
 | 
			
		||||
  bool operator==(const NVec2 &in) const { return x == in.x && y == in.y; }
 | 
			
		||||
 | 
			
		||||
  bool operator!=(const NVec2 &in) const {
 | 
			
		||||
    // use the first comparefuncs result
 | 
			
		||||
    // and swap it lol
 | 
			
		||||
    return !(*this == in);
 | 
			
		||||
  }
 | 
			
		||||
  // Internal Values
 | 
			
		||||
  float x;
 | 
			
		||||
  float y;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct NVec4 {
 | 
			
		||||
  // Init Funcs
 | 
			
		||||
  NVec4() : x(0), y(0), z(0), w(0) {}
 | 
			
		||||
  NVec4(float i0, float i1, float i2, float i3) : x(i0), y(i1), z(i2), w(i3) {}
 | 
			
		||||
  NVec4(const NVec4 &i) {
 | 
			
		||||
    x = i.x;
 | 
			
		||||
    y = i.y;
 | 
			
		||||
    z = i.z;
 | 
			
		||||
    w = i.w;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  NVec4(const NVec2 &i0, const NVec2 &i1) {
 | 
			
		||||
    x = i0.x;
 | 
			
		||||
    y = i0.y;
 | 
			
		||||
    z = i1.x;
 | 
			
		||||
    w = i1.y;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Operators
 | 
			
		||||
  // Add
 | 
			
		||||
  NVec4 &operator+=(const NVec4 &i) {
 | 
			
		||||
    x += i.x;
 | 
			
		||||
    y += i.y;
 | 
			
		||||
    z += i.z;
 | 
			
		||||
    w += i.w;
 | 
			
		||||
    return *this;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  NVec4 operator+(const NVec4 &i) const {
 | 
			
		||||
    return NVec4(x + i.x, y + i.y, z + i.z, w + i.w);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Sub
 | 
			
		||||
  NVec4 &operator-=(const NVec4 &i) {
 | 
			
		||||
    x -= i.x;
 | 
			
		||||
    y -= i.y;
 | 
			
		||||
    z -= i.z;
 | 
			
		||||
    w -= i.w;
 | 
			
		||||
    return *this;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  NVec4 operator-(const NVec4 &i) const {
 | 
			
		||||
    return NVec4(x - i.x, y - i.y, z - i.z, w - i.w);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Compare
 | 
			
		||||
  bool operator==(const NVec4 &in) const {
 | 
			
		||||
    return x == in.x && y == in.y && z == in.z && w == in.w;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  bool operator!=(const NVec4 &in) const {
 | 
			
		||||
    // use the first comparefuncs result
 | 
			
		||||
    // and swap it lol
 | 
			
		||||
    return !(*this == in);
 | 
			
		||||
  }
 | 
			
		||||
  // Internal Values
 | 
			
		||||
  float x;
 | 
			
		||||
  float y;
 | 
			
		||||
  float z;
 | 
			
		||||
  float w;
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										42
									
								
								include/pd/Net.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								include/pd/Net.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,42 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <pd/external/json.hpp>
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
namespace Net {
 | 
			
		||||
// Define List of Errors
 | 
			
		||||
enum Error_ {
 | 
			
		||||
  Error_None,        // Function Executed Successfully
 | 
			
		||||
  Error_Memory,      // Memory  Allocation Error
 | 
			
		||||
  Error_Write,       // Unable to Write File
 | 
			
		||||
  Error_StatusCode,  // Error with Status Code
 | 
			
		||||
  Error_Git,         // Git Error
 | 
			
		||||
  Error_CtrStatus,   // 3ds Result Code
 | 
			
		||||
  Error_Curl,        // Curl Error
 | 
			
		||||
  Error_Busy,        // Another Download Taskl is already running
 | 
			
		||||
  Error_Invalid,     // Invalid Json struct
 | 
			
		||||
  Error_NoWifi,      // Console not connected to wifi
 | 
			
		||||
};
 | 
			
		||||
// Set an typedefine for Error code
 | 
			
		||||
using Error = unsigned long long;
 | 
			
		||||
// Extract Error_ from Error code
 | 
			
		||||
inline Error_ ErrorCode(Error err) {
 | 
			
		||||
  return static_cast<Error_>(static_cast<unsigned int>(err & 0xffffffff));
 | 
			
		||||
}
 | 
			
		||||
// Extract Http Status code, Curl Error Code or Ctr Result Code
 | 
			
		||||
inline int StatusCode(Error err) {
 | 
			
		||||
  Error_ c = ErrorCode(err);
 | 
			
		||||
  if (c != Error_StatusCode && c != Error_CtrStatus && c != Error_Curl)
 | 
			
		||||
    return 0;
 | 
			
		||||
  return static_cast<unsigned int>(err >> 32);
 | 
			
		||||
}
 | 
			
		||||
Error Download(const std::string& url, std::string& data);
 | 
			
		||||
Error Download2File(const std::string& url, const std::string& path);
 | 
			
		||||
Error GitDownloadRelease(const std::string& url, const std::string& asset_name,
 | 
			
		||||
                         const std::string& path, bool prerelease = false);
 | 
			
		||||
Error JsonApiRequest(const std::string& api_url, nlohmann::json& res);
 | 
			
		||||
unsigned long long GetProgressCurrent();
 | 
			
		||||
unsigned long long GetProgressTotal();
 | 
			
		||||
}  // namespace Net
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										85
									
								
								include/pd/Overlays.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								include/pd/Overlays.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,85 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <pd/Ovl.hpp>
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
typedef int PDKeyboard;
 | 
			
		||||
 | 
			
		||||
enum PDKeyboard_ {
 | 
			
		||||
  PDKeyboard_Default,
 | 
			
		||||
  PDKeyboard_Numpad,
 | 
			
		||||
  PDKeyboard_Password,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum PDKeyboardState {
 | 
			
		||||
  PDKeyboardState_None = 0,
 | 
			
		||||
  PDKeyboardState_Cancel = 1,
 | 
			
		||||
  PDKeyboardState_Confirm = 2,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
class Ovl_Ftrace : public Palladium::Ovl {
 | 
			
		||||
 public:
 | 
			
		||||
  /// @brief Constructor
 | 
			
		||||
  Ovl_Ftrace(bool* is_enabled);
 | 
			
		||||
  /// @brief Override for Draw
 | 
			
		||||
  void Draw(void) const override;
 | 
			
		||||
  /// @brief Override for Logic
 | 
			
		||||
  void Logic() override;
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  bool* i_is_enabled;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Ovl_Metrik : public Palladium::Ovl {
 | 
			
		||||
 public:
 | 
			
		||||
  /// @brief Constructor
 | 
			
		||||
  Ovl_Metrik(bool* is_enabled, bool* screen, uint32_t* mt_color,
 | 
			
		||||
             uint32_t* txt_color, float* txt_size);
 | 
			
		||||
  /// @brief Override for Draw
 | 
			
		||||
  void Draw(void) const override;
 | 
			
		||||
  /// @brief Override for Logic
 | 
			
		||||
  void Logic() override;
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  // Mutable internal values
 | 
			
		||||
  mutable std::string mt_fps;
 | 
			
		||||
  mutable std::string mt_cpu;
 | 
			
		||||
  mutable std::string mt_gpu;
 | 
			
		||||
  mutable std::string mt_cmd;
 | 
			
		||||
  mutable std::string mt_lfr;
 | 
			
		||||
  mutable std::string mt_tbs;
 | 
			
		||||
  mutable std::string mt_mem;
 | 
			
		||||
 | 
			
		||||
  // Importand Adresses
 | 
			
		||||
  bool* i_is_enabled;
 | 
			
		||||
  bool* i_screen;
 | 
			
		||||
  uint32_t* i_mt_color;
 | 
			
		||||
  uint32_t* i_txt_color;
 | 
			
		||||
  float* i_txt_size;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Ovl_Keyboard : public Palladium::Ovl {
 | 
			
		||||
 public:
 | 
			
		||||
  /// @brief Constructor
 | 
			
		||||
  /// Keyboard Type not Supported for now
 | 
			
		||||
  Ovl_Keyboard(std::string& ref, PDKeyboardState& state,
 | 
			
		||||
               const std::string& hint = "", PDKeyboard type = 0);
 | 
			
		||||
  /// @brief Deconstructor
 | 
			
		||||
  ~Ovl_Keyboard();
 | 
			
		||||
  /// @brief Override for Draw
 | 
			
		||||
  void Draw(void) const override;
 | 
			
		||||
  /// @brief Override for Logic
 | 
			
		||||
  void Logic() override;
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  mutable std::map<unsigned char, char> shared_data;
 | 
			
		||||
  // Pointer to useres String
 | 
			
		||||
  std::string* typed_text = nullptr;
 | 
			
		||||
  std::string str_bak;
 | 
			
		||||
  PDKeyboardState* state;
 | 
			
		||||
  PDKeyboard type;
 | 
			
		||||
  int mode = 0;
 | 
			
		||||
  int ft3 = 0;
 | 
			
		||||
};
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										28
									
								
								include/pd/Ovl.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								include/pd/Ovl.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <map>
 | 
			
		||||
#include <memory>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
/// @brief The Overlay Class (Used for Toasts for example)
 | 
			
		||||
class Ovl {
 | 
			
		||||
 public:
 | 
			
		||||
  /// @brief Deconstructor
 | 
			
		||||
  virtual ~Ovl() {}
 | 
			
		||||
  /// @brief Function Called to Draw this
 | 
			
		||||
  virtual void Draw() const = 0;
 | 
			
		||||
  /// @brief Logic of the Overlay
 | 
			
		||||
  virtual void Logic() = 0;
 | 
			
		||||
  /// @brief Should the overlay be killed
 | 
			
		||||
  /// @return Killed or Not
 | 
			
		||||
  inline bool IsKilled() { return this->iskilled; }
 | 
			
		||||
  /// @brief Kill The Overlay
 | 
			
		||||
  inline void Kill() { iskilled = true; }
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  /// @param iskilled For IsKilled();
 | 
			
		||||
  bool iskilled = false;
 | 
			
		||||
};
 | 
			
		||||
/// @brief Add an Overlay to the Screen
 | 
			
		||||
/// @param scene Overlay to push to Screen
 | 
			
		||||
void AddOvl(std::unique_ptr<Palladium::Ovl> scene);
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										97
									
								
								include/pd/Render2.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								include/pd/Render2.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,97 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <map>
 | 
			
		||||
#include <pd/Color.hpp>
 | 
			
		||||
#include <pd/Font.hpp>
 | 
			
		||||
#include <pd/Image.hpp>
 | 
			
		||||
#include <pd/NVec.hpp>
 | 
			
		||||
#include <pd/Sprite.hpp>
 | 
			
		||||
#include <pd/smart_ctor.hpp>
 | 
			
		||||
 | 
			
		||||
#define MAKEFLAG(x) (1 << x)
 | 
			
		||||
 | 
			
		||||
typedef unsigned int PDTextFlags;
 | 
			
		||||
 | 
			
		||||
enum PDTextFlags_ {
 | 
			
		||||
  PDTextFlags_None = 0,  //< Align is Left and Other things are disabled
 | 
			
		||||
  PDTextFlags_AlignRight = MAKEFLAG(0),
 | 
			
		||||
  PDTextFlags_AlignMid = MAKEFLAG(1),
 | 
			
		||||
  PDTextFlags_Shaddow = MAKEFLAG(2),  // TextBuf Killer lol (doubled Text)
 | 
			
		||||
  PDTextFlags_Wrap = MAKEFLAG(3),
 | 
			
		||||
  PDTextFlags_Short = MAKEFLAG(4),
 | 
			
		||||
  PDTextFlags_Scroll = MAKEFLAG(5),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum R2Screen {
 | 
			
		||||
  R2Screen_Bottom,
 | 
			
		||||
  R2Screen_Top,
 | 
			
		||||
  // TopRight,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
class R2 {
 | 
			
		||||
 public:
 | 
			
		||||
  struct R2Cmd {
 | 
			
		||||
    NVec2 pos;        //< Position
 | 
			
		||||
    NVec2 pszs;       //< Position or (TextBox) Size
 | 
			
		||||
    NVec2 ap;         //< Additional Pos
 | 
			
		||||
    unsigned int clr;  //< Color
 | 
			
		||||
    bool Screen;       //< TopScreen
 | 
			
		||||
    Image::Ref img;    //< Image Reference
 | 
			
		||||
    Sprite::Ref spr;   //< Sprite Reference
 | 
			
		||||
    // 0 = skip, 1 = rect, 2 = tri, 3 = text,
 | 
			
		||||
    // 4 = image, 5 = sprite, 6 = Line
 | 
			
		||||
    int type;            //< Command Type
 | 
			
		||||
    bool lined = false;  //< Draw Lined Rect/Tri
 | 
			
		||||
    // Text Specific
 | 
			
		||||
    PDTextFlags flags;  // Text Flags
 | 
			
		||||
    std::string text;    // Text
 | 
			
		||||
    PD_SMART_CTOR(R2Cmd)
 | 
			
		||||
  };
 | 
			
		||||
  R2() = default;
 | 
			
		||||
  ~R2() = default;
 | 
			
		||||
 | 
			
		||||
  static void Init();
 | 
			
		||||
 | 
			
		||||
  // Settings
 | 
			
		||||
  static void SetFont(Font::Ref fnt);
 | 
			
		||||
  static Font::Ref GetFont();
 | 
			
		||||
  static void DefaultFont();
 | 
			
		||||
  static void DrawNextLined();
 | 
			
		||||
  static void OnScreen(R2Screen screen);
 | 
			
		||||
  static R2Screen GetCurrentScreen();
 | 
			
		||||
  static void SetTextSize(float szs);
 | 
			
		||||
  static void DefaultTextSize();
 | 
			
		||||
  static float GetTextSize();
 | 
			
		||||
  static NVec2 GetCurrentScreenSize();
 | 
			
		||||
  // Processing
 | 
			
		||||
  static void Process();
 | 
			
		||||
  static NVec2 GetTextDimensions(const std::string& text);
 | 
			
		||||
  static std::string WrapText(const std ::string& in, int maxlen);
 | 
			
		||||
  static std::string ShortText(const std::string& in, int maxlen);
 | 
			
		||||
  // Draw Functions
 | 
			
		||||
  static void AddRect(NVec2 pos, NVec2 size, PDColor clr);
 | 
			
		||||
  static void AddRect(NVec2 pos, NVec2 size, unsigned int clr);
 | 
			
		||||
  static void AddTriangle(NVec2 pos0, NVec2 pos1, NVec2 pos2, PDColor clr);
 | 
			
		||||
  static void AddTriangle(NVec2 pos0, NVec2 pos1, NVec2 pos2,
 | 
			
		||||
                          unsigned int clr);
 | 
			
		||||
  static void AddText(NVec2 pos, const std::string& text, PDColor clr,
 | 
			
		||||
                      PDTextFlags flags = 0, NVec2 tmb = NVec2());
 | 
			
		||||
  static void AddText(NVec2 pos, const std::string& text, unsigned int clr,
 | 
			
		||||
                      PDTextFlags flags = 0, NVec2 tmb = NVec2());
 | 
			
		||||
  static void AddImage(NVec2 pos, Image::Ref img);
 | 
			
		||||
  static void AddSprite(Sprite::Ref spr);
 | 
			
		||||
  static void AddLine(NVec2 pos_a, NVec2 pos_b, PDColor clr, int t = 1);
 | 
			
		||||
  static void AddLine(NVec2 pos_a, NVec2 pos_b, unsigned int clr, int t = 1);
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  static const float default_text_size;
 | 
			
		||||
  static float text_size;
 | 
			
		||||
  static Font::Ref font;
 | 
			
		||||
  static std::map<std::string, float> ts;
 | 
			
		||||
  static std::map<std::string, int> mln;
 | 
			
		||||
  static bool next_lined;
 | 
			
		||||
  static std::vector<R2Cmd::Ref> commands;
 | 
			
		||||
  static R2Screen current_screen;
 | 
			
		||||
};
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										54
									
								
								include/pd/ResultDecoder.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								include/pd/ResultDecoder.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,54 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <3ds.h>
 | 
			
		||||
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
/// @brief Decoder for 3ds Result Codes
 | 
			
		||||
class ResultDecoder {
 | 
			
		||||
 public:
 | 
			
		||||
  /// @brief Constructor
 | 
			
		||||
  ResultDecoder() {}
 | 
			
		||||
  /// @brief Deconstructor
 | 
			
		||||
  ~ResultDecoder() {}
 | 
			
		||||
  /// @brief Load a Result into Decoder
 | 
			
		||||
  /// @param rescode Result Code
 | 
			
		||||
  void Load(Result rescode);
 | 
			
		||||
  /// @brief Load A Hex Converted Code into Decoder
 | 
			
		||||
  /// @param rescode Result-Hex Code
 | 
			
		||||
  void Load(std::string rescode);
 | 
			
		||||
  /// @brief Get Hex Code
 | 
			
		||||
  /// @return Hex-Code
 | 
			
		||||
  std::string GetCode();
 | 
			
		||||
  /// @brief Get Level Name
 | 
			
		||||
  /// @return Level Name
 | 
			
		||||
  std::string GetLevel();
 | 
			
		||||
  /// @brief Get Level Value
 | 
			
		||||
  /// @return Level Value
 | 
			
		||||
  int GetLevelInt();
 | 
			
		||||
  /// @brief Get The Mosule Name
 | 
			
		||||
  /// @return Module Name
 | 
			
		||||
  std::string GetModule();
 | 
			
		||||
  /// @brief Get The Module Value
 | 
			
		||||
  /// @return Module Value
 | 
			
		||||
  int GetModuleInt();
 | 
			
		||||
  /// @brief Get The Description
 | 
			
		||||
  /// @return Description
 | 
			
		||||
  std::string GetDescription();
 | 
			
		||||
  /// @brief Get The Description Valur
 | 
			
		||||
  /// @return Description Value
 | 
			
		||||
  int GetDescriptionInt();
 | 
			
		||||
  /// @brief Get the Summary
 | 
			
		||||
  /// @return Summary
 | 
			
		||||
  std::string GetSummary();
 | 
			
		||||
  /// @brief Get the Summary Value
 | 
			
		||||
  /// @return Summary Value
 | 
			
		||||
  int GetSummaryInt();
 | 
			
		||||
  /// @brief Write a Result log file to sd
 | 
			
		||||
  void WriteLog(void);
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  /// @param m_rescode Result code
 | 
			
		||||
  Result m_rescode;
 | 
			
		||||
};
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										35
									
								
								include/pd/Sheet.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								include/pd/Sheet.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <3ds.h>  // Result
 | 
			
		||||
#include <citro2d.h>
 | 
			
		||||
#include <citro3d.h>
 | 
			
		||||
 | 
			
		||||
#include <pd/Image.hpp>
 | 
			
		||||
#include <pd/smart_ctor.hpp>
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
/// @brief SpriteSheet Class
 | 
			
		||||
class Sheet {
 | 
			
		||||
 public:
 | 
			
		||||
  /// @brief Constructor
 | 
			
		||||
  Sheet() = default;
 | 
			
		||||
  Sheet(const std::string& path) { this->Load(path); }
 | 
			
		||||
  /// @brief Deconstructor
 | 
			
		||||
  ~Sheet() {
 | 
			
		||||
    if (spritesheet) Free();
 | 
			
		||||
  }
 | 
			
		||||
  PD_SMART_CTOR(Sheet);
 | 
			
		||||
  /// @brief Load A Spritesheet File
 | 
			
		||||
  /// @param path Path to the t3x
 | 
			
		||||
  /// @return Result Code
 | 
			
		||||
  Result Load(const std::string& path);
 | 
			
		||||
  /// @brief Unload the Sheet
 | 
			
		||||
  void Free();
 | 
			
		||||
  C2D_Image GetImage(int idx);
 | 
			
		||||
  C2D_SpriteSheet Get() { return this->spritesheet; }
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  /// \param spritesheet The Sheet
 | 
			
		||||
  C2D_SpriteSheet spritesheet;
 | 
			
		||||
};
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										35
									
								
								include/pd/Sound.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								include/pd/Sound.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <3ds.h>
 | 
			
		||||
 | 
			
		||||
#include <pd/smart_ctor.hpp>
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
/** Sound Class */
 | 
			
		||||
class Sound {
 | 
			
		||||
 public:
 | 
			
		||||
  /// \brief Construct new Soundeffect
 | 
			
		||||
  /// \param path Path to the .wav file
 | 
			
		||||
  /// \param channel the channel 1-23
 | 
			
		||||
  /// \param toloop true:loop the sound, false: don't loop
 | 
			
		||||
  Sound(const std::string &path, int channel = 1, bool toloop = false);
 | 
			
		||||
  /// @brief Deconstructor
 | 
			
		||||
  ~Sound();
 | 
			
		||||
  PD_SMART_CTOR(Sound)
 | 
			
		||||
  /// @brief Play the sound
 | 
			
		||||
  void Play();
 | 
			
		||||
  /// @brief Stop the sound
 | 
			
		||||
  void Stop();
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  /// \param dataSize Size of the filedata
 | 
			
		||||
  u32 dataSize;
 | 
			
		||||
  /// \param waveBuf For ndsp
 | 
			
		||||
  ndspWaveBuf waveBuf;
 | 
			
		||||
  /// \param data Memmory data of the sound
 | 
			
		||||
  uint8_t *data = NULL;
 | 
			
		||||
  /// \param chnl Channel of the sound
 | 
			
		||||
  int chnl;
 | 
			
		||||
};
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										71
									
								
								include/pd/Sprite.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								include/pd/Sprite.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,71 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <citro2d.h>
 | 
			
		||||
#include <citro3d.h>
 | 
			
		||||
 | 
			
		||||
#include <pd/Image.hpp>
 | 
			
		||||
#include <pd/Sheet.hpp>
 | 
			
		||||
#include <pd/smart_ctor.hpp>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
/// @brief Sprite Class
 | 
			
		||||
class Sprite {
 | 
			
		||||
 public:
 | 
			
		||||
  /// \brief Construct Sprite
 | 
			
		||||
  Sprite() = default;
 | 
			
		||||
  /// \brief Deconstruct Sprite
 | 
			
		||||
  ~Sprite() = default;
 | 
			
		||||
  PD_SMART_CTOR(Sprite)
 | 
			
		||||
  /// \brief Load a Sprite From SpriteSheet
 | 
			
		||||
  /// \param sheet the Sheet to load from.(Palladium::Sheet)
 | 
			
		||||
  /// \param index the number of the Sprite in the Sheet
 | 
			
		||||
  void FromSheet(Palladium::Sheet::Ref sheet, size_t index);
 | 
			
		||||
  /// \brief Load a Sprite From SpriteSheet
 | 
			
		||||
  /// \param img the Image to load from.(Palladium::Image)
 | 
			
		||||
  void FromImage(Palladium::Image::Ref img);
 | 
			
		||||
  /// @brief Draw the Sprite
 | 
			
		||||
  /// @return success ?
 | 
			
		||||
  bool Draw();
 | 
			
		||||
  /// @brief Set the Center Position
 | 
			
		||||
  /// @param x X Pos
 | 
			
		||||
  /// @param y Y Pos
 | 
			
		||||
  void SetCenter(float x, float y);
 | 
			
		||||
  /// @brief Set the Sprite's Position
 | 
			
		||||
  /// @param x X Pos
 | 
			
		||||
  /// @param y Y Pos
 | 
			
		||||
  void SetPos(float x, float y);
 | 
			
		||||
  /// @brief Set The Sprite's Scale
 | 
			
		||||
  /// @param x Scale on X-Axis
 | 
			
		||||
  /// @param y Scale on Y-Axis
 | 
			
		||||
  void SetScale(float x, float y);
 | 
			
		||||
  /// @brief Set the Sprite's Rotation
 | 
			
		||||
  /// @param rotation ratation
 | 
			
		||||
  void SetRotation(float rotation);
 | 
			
		||||
  /// @brief Rotate the Sprite
 | 
			
		||||
  /// @param speed Speed to Rotate
 | 
			
		||||
  void Rotate(float speed);
 | 
			
		||||
  /// @brief Get Tje Sprite's Width
 | 
			
		||||
  /// @return Width
 | 
			
		||||
  float GetWidth();
 | 
			
		||||
  /// @brief Get the Sprite's Height
 | 
			
		||||
  /// @return Height
 | 
			
		||||
  float GetHeight();
 | 
			
		||||
  /// @brief Get The Sprite's X Position
 | 
			
		||||
  /// @return X Position
 | 
			
		||||
  float GetPosX();
 | 
			
		||||
  /// @brief Get the Sprite's Y Position
 | 
			
		||||
  /// @return Y Position
 | 
			
		||||
  float GetPosY();
 | 
			
		||||
  NVec2 GetSize();
 | 
			
		||||
  NVec2 GetPos();
 | 
			
		||||
  void SetPos(NVec2 pos);
 | 
			
		||||
  void SetScale(NVec2 scale);
 | 
			
		||||
  void SetRotCenter(NVec2 percentage);
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  /// @param tint ImageTint (unused)
 | 
			
		||||
  C2D_ImageTint tint;
 | 
			
		||||
  /// @param sprite The Sprite
 | 
			
		||||
  C2D_Sprite sprite;
 | 
			
		||||
};
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										43
									
								
								include/pd/SpriteAnimation.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								include/pd/SpriteAnimation.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,43 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <citro2d.h>
 | 
			
		||||
#include <citro3d.h>
 | 
			
		||||
 | 
			
		||||
#include <pd/Sheet.hpp>
 | 
			
		||||
#include <pd/Sprite.hpp>
 | 
			
		||||
#include <pd/smart_ctor.hpp>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
/// @brief SpriteSheetAnimation Class
 | 
			
		||||
class SpriteSheetAnimation : public Palladium::Sprite {
 | 
			
		||||
 public:
 | 
			
		||||
  /// @brief Constructor
 | 
			
		||||
  SpriteSheetAnimation() = default;
 | 
			
		||||
  /// @brief Deconstructor
 | 
			
		||||
  ~SpriteSheetAnimation() = default;
 | 
			
		||||
  PD_SMART_CTOR(SpriteSheetAnimation);
 | 
			
		||||
  /// @brief Setup an Animation
 | 
			
		||||
  /// @param sheet Input Spritesheet
 | 
			
		||||
  /// @param imagecount Count of Images
 | 
			
		||||
  /// @param startimage Where to Start the Loop
 | 
			
		||||
  /// @param frame_begin Current Time (Should be 0)
 | 
			
		||||
  /// @param frame_finish Time Length
 | 
			
		||||
  void Setup(Palladium::Sheet::Ref sheet, size_t imagecount, size_t startimage,
 | 
			
		||||
             float frame_begin, float frame_finish);
 | 
			
		||||
  /// @brief Play the Animation
 | 
			
		||||
  /// @param timespeed Speed of the animation
 | 
			
		||||
  void Play(float timespeed);
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  /// @param images Count of Images
 | 
			
		||||
  size_t images;
 | 
			
		||||
  /// @param imgs Another Count of images ???
 | 
			
		||||
  size_t imgs = 0;
 | 
			
		||||
  /// @param D_totaltime Current Time
 | 
			
		||||
  float D_totaltime;
 | 
			
		||||
  /// @param sheet The Sheet of Images
 | 
			
		||||
  Palladium::Sheet::Ref sheet;
 | 
			
		||||
  /// @param time Total Time from frame_finish
 | 
			
		||||
  float time;
 | 
			
		||||
};
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										13
									
								
								include/pd/Tasks.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								include/pd/Tasks.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <functional>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
namespace Tasks {
 | 
			
		||||
/// @brief Push A Task
 | 
			
		||||
/// @param fun Function of Your Task
 | 
			
		||||
/// @return index
 | 
			
		||||
int Create(std::function<void()> fun);
 | 
			
		||||
/// @brief Destroy all Tasks
 | 
			
		||||
void DestroyAll();
 | 
			
		||||
}  // namespace Tasks
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										35
									
								
								include/pd/Texture.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								include/pd/Texture.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
#include <pd/smart_ctor.hpp>
 | 
			
		||||
#include <pd/NVec.hpp>
 | 
			
		||||
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
#include <citro3d.h>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
    class Texture {
 | 
			
		||||
        public:
 | 
			
		||||
        Texture() = default;
 | 
			
		||||
        ~Texture() = default;
 | 
			
		||||
        PD_SMART_CTOR(Texture)
 | 
			
		||||
 | 
			
		||||
        void Delete();
 | 
			
		||||
 | 
			
		||||
        void LoadFile(const std::string& path);
 | 
			
		||||
        void LoadFromMemory(const std::vector<unsigned char>& data);
 | 
			
		||||
        void LoadPixels(const std::vector<unsigned char>& data, int w, int h);
 | 
			
		||||
 | 
			
		||||
        C3D_Tex* Get() { return this->tex; }
 | 
			
		||||
        NVec2 GetTexSize() { return tex_size; }
 | 
			
		||||
        NVec2 GetSize() { return img_size; }
 | 
			
		||||
        // As the texture is a pow of 2 we need a uv 
 | 
			
		||||
        NVec4 GetUV() { return uvs; }
 | 
			
		||||
 | 
			
		||||
        private:
 | 
			
		||||
        void MakeTex(std::vector<unsigned char> &buf, int w, int h);
 | 
			
		||||
        C3D_Tex* tex;
 | 
			
		||||
        NVec2 img_size;
 | 
			
		||||
        NVec2 tex_size;
 | 
			
		||||
        NVec4 uvs;
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										29
									
								
								include/pd/ThemeEditor.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								include/pd/ThemeEditor.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <pd/palladium.hpp>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
class ThemeEditor : public Palladium::Scene {
 | 
			
		||||
 public:
 | 
			
		||||
  ThemeEditor();
 | 
			
		||||
  ~ThemeEditor();
 | 
			
		||||
 | 
			
		||||
  void Draw(void) const override;
 | 
			
		||||
  void Logic() override;
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  Theme::Ref edit_theme;
 | 
			
		||||
  // Placeholder to save active one to
 | 
			
		||||
  Theme::Ref temp_theme;
 | 
			
		||||
 | 
			
		||||
  // temp vars for samples
 | 
			
		||||
  mutable bool cm;
 | 
			
		||||
  mutable std::string inpt;
 | 
			
		||||
  mutable int menu = 0;
 | 
			
		||||
 | 
			
		||||
  // Keyboard
 | 
			
		||||
  mutable PDKeyboardState kbd_state;
 | 
			
		||||
  mutable std::string kbd_text;
 | 
			
		||||
  mutable std::vector<std::string> theme_list;
 | 
			
		||||
};
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										13
									
								
								include/pd/Time.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								include/pd/Time.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
/// @brief Format a String
 | 
			
		||||
/// @param fmt_str Format To
 | 
			
		||||
/// @param ... Additional Args
 | 
			
		||||
/// @return Formatted String
 | 
			
		||||
std::string FormatString(std::string fmt_str, ...);
 | 
			
		||||
/// @brief Get Current Time as String
 | 
			
		||||
/// @return Time-String
 | 
			
		||||
std::string GetTimeStr(void);
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										26
									
								
								include/pd/Timer.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								include/pd/Timer.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <3ds.h>
 | 
			
		||||
 | 
			
		||||
#include <pd/smart_ctor.hpp>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
class Timer {
 | 
			
		||||
 public:
 | 
			
		||||
  Timer(bool autostart = true);
 | 
			
		||||
  ~Timer() {}
 | 
			
		||||
  PD_SMART_CTOR(Timer)
 | 
			
		||||
  void Reset();
 | 
			
		||||
  void Tick();
 | 
			
		||||
  void Pause();
 | 
			
		||||
  void Resume();
 | 
			
		||||
  float Get();
 | 
			
		||||
  float GetLive();
 | 
			
		||||
  bool Running();
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  uint64_t last = 0;
 | 
			
		||||
  uint64_t current = 0;
 | 
			
		||||
  bool is_running = false;
 | 
			
		||||
};
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										102
									
								
								include/pd/UI7.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								include/pd/UI7.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,102 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <pd/Image.hpp>
 | 
			
		||||
#include <pd/NVec.hpp>
 | 
			
		||||
#include <pd/Render2.hpp>
 | 
			
		||||
#include <pd/smart_ctor.hpp>
 | 
			
		||||
 | 
			
		||||
#define UI7MAKEFLAG(x) (1 << x)
 | 
			
		||||
 | 
			
		||||
typedef int UI7MenuFlags;
 | 
			
		||||
 | 
			
		||||
enum UI7MenuFlags_ {
 | 
			
		||||
  UI7MenuFlags_None = 0,
 | 
			
		||||
  UI7MenuFlags_NoTitlebar = UI7MAKEFLAG(0),
 | 
			
		||||
  UI7MenuFlags_TitleMid = UI7MAKEFLAG(1),
 | 
			
		||||
  UI7MenuFlags_Scrolling = MAKEFLAG(2),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class DrawCmd;
 | 
			
		||||
class UI7DrawList {
 | 
			
		||||
 public:
 | 
			
		||||
  UI7DrawList() = default;
 | 
			
		||||
  ~UI7DrawList() = default;
 | 
			
		||||
 | 
			
		||||
  void AddRectangle(NVec2 pos, NVec2 szs, PDColor clr);
 | 
			
		||||
  void AddRectangle(NVec2 pos, NVec2 szs, unsigned int clr);
 | 
			
		||||
  void AddTriangle(NVec2 pos0, NVec2 pos1, NVec2 pos2, PDColor clr);
 | 
			
		||||
  void AddTriangle(NVec2 pos0, NVec2 pos1, NVec2 pos2, unsigned int clr);
 | 
			
		||||
  void AddText(NVec2 pos, const std::string &text, PDColor clr,
 | 
			
		||||
               PDTextFlags flags = 0, NVec2 box = NVec2());
 | 
			
		||||
  void AddText(NVec2 pos, const std::string &text, unsigned int clr,
 | 
			
		||||
               PDTextFlags flags = 0, NVec2 box = NVec2());
 | 
			
		||||
  void AddImage(NVec2 pos, Palladium::Image::Ref img);
 | 
			
		||||
  void AddCall(std::shared_ptr<DrawCmd> cmd);
 | 
			
		||||
 | 
			
		||||
  void Process(bool auto_clear = true);
 | 
			
		||||
  void Clear();
 | 
			
		||||
 | 
			
		||||
  PD_SMART_CTOR(UI7DrawList)
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  void AddDebugCall(std::shared_ptr<DrawCmd> cmd);
 | 
			
		||||
  std::vector<std::shared_ptr<DrawCmd>> list;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
namespace UI7 {
 | 
			
		||||
// Key functions
 | 
			
		||||
void Init();
 | 
			
		||||
void Deinit();
 | 
			
		||||
void Update();
 | 
			
		||||
float GetTime();
 | 
			
		||||
float GetDeltaTime();
 | 
			
		||||
bool &IsDebugging();
 | 
			
		||||
// Internal Function
 | 
			
		||||
// Should not be used
 | 
			
		||||
void Debug();
 | 
			
		||||
bool &DebugMenu();
 | 
			
		||||
 | 
			
		||||
bool Button(const std::string &label, NVec2 size = NVec2(0, 0));
 | 
			
		||||
void Checkbox(const std::string &label, bool &c);
 | 
			
		||||
void Label(const std::string &label, PDTextFlags flags = 0);
 | 
			
		||||
void Progressbar(float value);
 | 
			
		||||
/// @brief Draw Image in Menu
 | 
			
		||||
/// @param img Pointer f.e to Palladium::Image2
 | 
			
		||||
void Image(Palladium::Image::Ref img);
 | 
			
		||||
void BrowserList(const std::vector<std::string> &entrys, int &selection,
 | 
			
		||||
                 PDTextFlags txtflags = 0, NVec2 size = NVec2(0, 0),
 | 
			
		||||
                 int max_entrys = 13);
 | 
			
		||||
void InputText(const std::string &label, std::string &text,
 | 
			
		||||
               const std::string &hint = "");
 | 
			
		||||
bool BeginMenu(const std::string &title, NVec2 size = NVec2(0, 0),
 | 
			
		||||
               UI7MenuFlags flags = 0);
 | 
			
		||||
void EndMenu();
 | 
			
		||||
void Grid(const std::string &name, const NVec2 &size, const NVec2 &entry_size,
 | 
			
		||||
          void (*display_func)(void *, NVec2), void **data_array,
 | 
			
		||||
          size_t num_entrys);
 | 
			
		||||
void ColorSelector(const std::string &label, unsigned int &color);
 | 
			
		||||
bool BeginTree(const std::string &text);
 | 
			
		||||
void EndTree();
 | 
			
		||||
NVec2 GetCursorPos();
 | 
			
		||||
void SetCursorPos(NVec2 cp);
 | 
			
		||||
void RestoreCursor();
 | 
			
		||||
void SameLine();
 | 
			
		||||
// Internal API (For Creating Custom Objects)
 | 
			
		||||
bool InBox(NVec2 inpos, NVec2 boxpos, NVec2 boxsize);
 | 
			
		||||
void MoveCursor(NVec2 size);
 | 
			
		||||
bool HandleScrolling(NVec2 &pos, NVec2 size);
 | 
			
		||||
bool InMenu();
 | 
			
		||||
namespace Menu {
 | 
			
		||||
// All of them return the Main BG DrawList if Menu is null
 | 
			
		||||
UI7DrawList::Ref GetBackgroundList();
 | 
			
		||||
UI7DrawList::Ref GetList();
 | 
			
		||||
UI7DrawList::Ref GetForegroundList();
 | 
			
		||||
// Other Menu Specific Functions
 | 
			
		||||
float GetScrollingOffset();
 | 
			
		||||
void SetScrollingOffset(float off);
 | 
			
		||||
bool IsScrolling();
 | 
			
		||||
}  // namespace Menu
 | 
			
		||||
// DrawLists
 | 
			
		||||
UI7DrawList::Ref GetForegroundList();
 | 
			
		||||
UI7DrawList::Ref GetBackgroundList();
 | 
			
		||||
}  // namespace UI7
 | 
			
		||||
							
								
								
									
										25447
									
								
								include/pd/external/json.hpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										25447
									
								
								include/pd/external/json.hpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										8681
									
								
								include/pd/external/stb_image.h
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										8681
									
								
								include/pd/external/stb_image.h
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										2054
									
								
								include/pd/external/stb_image_write.h
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2054
									
								
								include/pd/external/stb_image_write.h
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										5636
									
								
								include/pd/external/stb_truetype.h
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										5636
									
								
								include/pd/external/stb_truetype.h
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										38
									
								
								include/pd/global_db.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								include/pd/global_db.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <pd/external/json.hpp>
 | 
			
		||||
#include <pd/palladium.hpp>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
namespace IDB {
 | 
			
		||||
void Start();
 | 
			
		||||
void Stop();
 | 
			
		||||
void Restart();
 | 
			
		||||
}  // namespace IDB
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
 | 
			
		||||
using PDFlags = int;
 | 
			
		||||
enum PDFlags_ {
 | 
			
		||||
  PDFlags_None = 0,
 | 
			
		||||
  PDFlags_MemTrack = 1 << 0,
 | 
			
		||||
  PDFlags_SceneSystem = 1 << 1,
 | 
			
		||||
  PDFlags_ShowSplash = 1 << 2,
 | 
			
		||||
  PDFlags_Default = PDFlags_SceneSystem,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Outdated HidApi (HidV2Patched)
 | 
			
		||||
extern u32 d7_hDown;
 | 
			
		||||
extern u32 d7_hHeld;
 | 
			
		||||
extern u32 d7_hUp;
 | 
			
		||||
extern u32 d7_hRepeat;  // Inofficial lol
 | 
			
		||||
extern touchPosition d7_touch;
 | 
			
		||||
 | 
			
		||||
// Modern Global Api
 | 
			
		||||
extern int pd_max_objects;
 | 
			
		||||
extern C3D_RenderTarget *pd_top;
 | 
			
		||||
extern C3D_RenderTarget *pd_top_right;
 | 
			
		||||
extern C3D_RenderTarget *pd_bottom;
 | 
			
		||||
extern PDFlags pd_flags;
 | 
			
		||||
 | 
			
		||||
// Draw2
 | 
			
		||||
extern float pd_draw2_tsm;
 | 
			
		||||
							
								
								
									
										70
									
								
								include/pd/internal_db.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								include/pd/internal_db.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,70 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <pd/Net.hpp>
 | 
			
		||||
#include <pd/external/json.hpp>
 | 
			
		||||
#include <pd/global_db.hpp>
 | 
			
		||||
#include <pd/palladium.hpp>
 | 
			
		||||
 | 
			
		||||
#define CFGVER "1"
 | 
			
		||||
#define THEMEVER "0"
 | 
			
		||||
 | 
			
		||||
#ifndef V_PDBTIME
 | 
			
		||||
#define V_PDBTIME "SUBMODULE"
 | 
			
		||||
#endif
 | 
			
		||||
#ifndef V_PDCSTRING
 | 
			
		||||
#define V_PDCSTRING "SUBMODULE"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// Base
 | 
			
		||||
extern bool pdi_do_splash;
 | 
			
		||||
extern bool pdi_enable_scene_system;
 | 
			
		||||
extern bool pdi_debugging;
 | 
			
		||||
extern bool pdi_enable_memtrack;
 | 
			
		||||
extern std::string pdi_app_name;
 | 
			
		||||
extern std::string pdi_config_path;
 | 
			
		||||
extern nlohmann::json pdi_config;
 | 
			
		||||
extern u8 pdi_console_model;
 | 
			
		||||
extern u8 pdi_system_region;
 | 
			
		||||
extern bool pdi_is_citra;
 | 
			
		||||
extern bool pdi_settings;
 | 
			
		||||
extern NVec2 pdi_hid_touch_pos;
 | 
			
		||||
extern C2D_TextBuf pdi_text_buffer;
 | 
			
		||||
extern C2D_TextBuf pdi_d2_dimbuf;
 | 
			
		||||
extern C2D_Font pdi_base_font;
 | 
			
		||||
extern bool pdi_is_ndsp;
 | 
			
		||||
extern bool pdi_running;
 | 
			
		||||
extern std::unique_ptr<Palladium::Scene> pdi_fade_scene;
 | 
			
		||||
extern std::vector<std::unique_ptr<Palladium::Ovl>> pdi_overlays;
 | 
			
		||||
extern unsigned int pdi_frames;
 | 
			
		||||
extern u64 pdi_last_time;
 | 
			
		||||
extern float pdi_framerate;
 | 
			
		||||
extern u32 pdi_mt_color;
 | 
			
		||||
extern u32 pdi_mt_txtcolor;
 | 
			
		||||
extern bool pdi_mt_screen;
 | 
			
		||||
extern float pdi_mt_txtSize;
 | 
			
		||||
extern bool pdi_metrikd;
 | 
			
		||||
extern bool pdi_ftraced;
 | 
			
		||||
extern u64 pdi_delta_time;
 | 
			
		||||
extern u64 pdi_last_tm;
 | 
			
		||||
extern float pdi_dtm;
 | 
			
		||||
extern float pdi_time;
 | 
			
		||||
extern bool pdi_fadeout;
 | 
			
		||||
extern bool pdi_fadein;
 | 
			
		||||
extern bool pdi_fadeout2;
 | 
			
		||||
extern bool pdi_fadein2;
 | 
			
		||||
extern int pdi_fadealpha;
 | 
			
		||||
extern int pdi_fadecolor;
 | 
			
		||||
extern bool pdi_wait_fade;
 | 
			
		||||
extern bool pdi_fade_exit;
 | 
			
		||||
extern bool pdi_fade_scene_wait;
 | 
			
		||||
extern bool pdi_idb_running;
 | 
			
		||||
extern bool pdi_graphics_on;
 | 
			
		||||
extern bool pdi_amdt;
 | 
			
		||||
extern void* pdi_soc_buf;
 | 
			
		||||
extern bool pdi_is_am_init;
 | 
			
		||||
extern Palladium::Theme::Ref pdi_active_theme;
 | 
			
		||||
extern bool pdi_lggrf;
 | 
			
		||||
 | 
			
		||||
// Use function for protection
 | 
			
		||||
Palladium::LoggerBase::Ref _pdi_logger();
 | 
			
		||||
Palladium::Net::Error pdi_soc_init();
 | 
			
		||||
void pdi_soc_deinit();
 | 
			
		||||
							
								
								
									
										24
									
								
								include/pd/lang.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								include/pd/lang.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
// clang-format off
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <pd/external/json.hpp>
 | 
			
		||||
// clang-format on
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
namespace Lang {
 | 
			
		||||
/// @brief Get 3ds System lang! [en] by default
 | 
			
		||||
/// @return Sytemlang as string
 | 
			
		||||
std::string GetSys();
 | 
			
		||||
/// @brief Get The Translation String
 | 
			
		||||
/// @param key Key of Translation
 | 
			
		||||
/// @return The Translated String
 | 
			
		||||
std::string Get(const std::string &key);
 | 
			
		||||
/// @brief Load A Language json
 | 
			
		||||
/// @param lang The Language Key [en], [de], etc, or getSys()
 | 
			
		||||
void Load(const std::string &lang);
 | 
			
		||||
// New funcs
 | 
			
		||||
std::string GetName();
 | 
			
		||||
std::string GetAuthor();
 | 
			
		||||
std::string GetShortcut();
 | 
			
		||||
}  // namespace Lang
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										30
									
								
								include/pd/nimg.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								include/pd/nimg.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <cstdint>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#define NPI_NIMG_ (uint32_t)0x4e494d47  // Magic: NIMG
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
struct nimg {
 | 
			
		||||
  unsigned int magic;  // Magic number defaults do NPI_NIMG_
 | 
			
		||||
  int width;
 | 
			
		||||
  int height;
 | 
			
		||||
  int format;
 | 
			
		||||
  int compression;
 | 
			
		||||
  std::vector<unsigned char> pixel_buffer;
 | 
			
		||||
 | 
			
		||||
  nimg(int w = 0, int h = 0, int fmt = 0, int cmp = 0) {
 | 
			
		||||
    magic = NPI_NIMG_;
 | 
			
		||||
    width = w;
 | 
			
		||||
    height = h;
 | 
			
		||||
    format = fmt;
 | 
			
		||||
    compression = cmp;
 | 
			
		||||
    pixel_buffer.resize((w * h) * (format ? 3 : 4));
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
nimg NIMG_Load(std::string path);
 | 
			
		||||
nimg NIMG_LoadFromMem(unsigned char* buffer, size_t bf_size);
 | 
			
		||||
void NIMG_Save(nimg image, std::string path);
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										194
									
								
								include/pd/palladium.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										194
									
								
								include/pd/palladium.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,194 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
/// c++ Includes
 | 
			
		||||
#include <cstring>
 | 
			
		||||
#include <map>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <stack>
 | 
			
		||||
#include <string>
 | 
			
		||||
/// c includes
 | 
			
		||||
#include <dirent.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
#include <time.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
/// 3ds Includes
 | 
			
		||||
#include <3ds.h>
 | 
			
		||||
#include <citro2d.h>
 | 
			
		||||
#include <citro3d.h>
 | 
			
		||||
/// Palladium Includes
 | 
			
		||||
#include <pd/Color.hpp>
 | 
			
		||||
#include <pd/FunctionTrace.hpp>
 | 
			
		||||
#include <pd/Hardware.hpp>
 | 
			
		||||
#include <pd/Logger.hpp>
 | 
			
		||||
#include <pd/Memory.hpp>
 | 
			
		||||
#include <pd/Overlays.hpp>
 | 
			
		||||
#include <pd/Ovl.hpp>
 | 
			
		||||
#include <pd/Render2.hpp>
 | 
			
		||||
#include <pd/ResultDecoder.hpp>
 | 
			
		||||
#include <pd/Sheet.hpp>
 | 
			
		||||
#include <pd/Sprite.hpp>
 | 
			
		||||
#include <pd/SpriteAnimation.hpp>
 | 
			
		||||
#include <pd/Tasks.hpp>
 | 
			
		||||
#include <pd/Time.hpp>
 | 
			
		||||
#include <pd/lang.hpp>
 | 
			
		||||
#include <pd/parameter.hpp>
 | 
			
		||||
#include <pd/stringtool.hpp>
 | 
			
		||||
#include <pd/thread.hpp>
 | 
			
		||||
 | 
			
		||||
#define PDVSTRING "1.0.0"
 | 
			
		||||
 | 
			
		||||
#define DEFAULT_CENTER 0.5f
 | 
			
		||||
 | 
			
		||||
/// @param pd_max_objects Config Param for C2D Mac objects
 | 
			
		||||
extern int pd_max_objects;
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
// Reference to Global Logger
 | 
			
		||||
LoggerBase::Ref Logger();
 | 
			
		||||
/// @brief Get Deltatime
 | 
			
		||||
/// @return Deltatime
 | 
			
		||||
float GetDeltaTime();
 | 
			
		||||
 | 
			
		||||
/// @brief Scene Class
 | 
			
		||||
class Scene {
 | 
			
		||||
 public:
 | 
			
		||||
  /// @brief Stack of the Scenes
 | 
			
		||||
  static std::stack<std::unique_ptr<Scene>> scenes;
 | 
			
		||||
  /// @brief Deconstructor
 | 
			
		||||
  virtual ~Scene() {}
 | 
			
		||||
  virtual void Logic() = 0;
 | 
			
		||||
  /// @brief Draw Func to Override
 | 
			
		||||
  virtual void Draw() const = 0;
 | 
			
		||||
  /// @brief Push a Scene to Stack
 | 
			
		||||
  /// @param scene Scene to Push
 | 
			
		||||
  /// @param fade FadeEffect (Not Correctly Implementet yet)
 | 
			
		||||
  static void Load(std::unique_ptr<Scene> scene, bool fade = false);
 | 
			
		||||
  /// @brief Go Back a Scene
 | 
			
		||||
  static void Back();
 | 
			
		||||
  /// @brief do the Draw (Called in Palladium::MainLoop())
 | 
			
		||||
  static void doDraw();
 | 
			
		||||
  static void doLogic();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/// @brief Integrated Setting Menu of Palladium
 | 
			
		||||
class RSettings : public Palladium::Scene {
 | 
			
		||||
 private:
 | 
			
		||||
  /// @brief State (Define for Menus)
 | 
			
		||||
  enum RState {
 | 
			
		||||
    RSETTINGS,  // Main Settings Menu
 | 
			
		||||
    RIDB,       // Internal Debugger
 | 
			
		||||
    ROVERLAYS,  // Overlay Settings
 | 
			
		||||
    RFTRACE,    // FTRace Menu
 | 
			
		||||
    RUI7,       // UI7 Menu
 | 
			
		||||
    RLOGS,      // Logs
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  /// @param shared_request Defines requests from Draw to Logic
 | 
			
		||||
  /// As it is not planned to make Draw non const you'll need
 | 
			
		||||
  /// A map of data or bool values that are mutable ake
 | 
			
		||||
  /// editable by const functions
 | 
			
		||||
  mutable std::map<unsigned int, unsigned int> shared_request;
 | 
			
		||||
  /// @param m_state Current menu State (Default=MainMenu aka RSETTINGS)
 | 
			
		||||
  Palladium::RSettings::RState m_state = Palladium::RSettings::RState::RSETTINGS;
 | 
			
		||||
 | 
			
		||||
  /// @brief Position in FTrace Menu
 | 
			
		||||
  int ftrace_index = 0;
 | 
			
		||||
 | 
			
		||||
  /// @param mtovlstate State of Metricks Overlay
 | 
			
		||||
  std::string mtovlstate = "false";
 | 
			
		||||
  /// @param mtscreenstate Screen the Overlay is Set to
 | 
			
		||||
  std::string mtscreenstate = "Top";
 | 
			
		||||
  std::string kbd_test;
 | 
			
		||||
  PDKeyboardState kbd_state;
 | 
			
		||||
  bool statemtold = false;
 | 
			
		||||
  bool stateftold = false;
 | 
			
		||||
  float tmp_txt;
 | 
			
		||||
 | 
			
		||||
 public:
 | 
			
		||||
  /// @brief Constructor
 | 
			
		||||
  RSettings();
 | 
			
		||||
  /// @brief Override for Draw
 | 
			
		||||
  /// @param
 | 
			
		||||
  void Draw(void) const override;
 | 
			
		||||
  /// @brief Deconstructor
 | 
			
		||||
  ~RSettings();
 | 
			
		||||
  void Logic() override;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/// @brief Show Up the Palladium-Settings Menu
 | 
			
		||||
void LoadSettings();
 | 
			
		||||
/// @brief Show Up The Theme Editor
 | 
			
		||||
void LoadThemeEditor();
 | 
			
		||||
/// @brief Get's The Programs Time running
 | 
			
		||||
/// @return Time Running
 | 
			
		||||
float GetTime();
 | 
			
		||||
/// @brief Get Framerate as Number
 | 
			
		||||
/// @return FPS
 | 
			
		||||
int GetFps();
 | 
			
		||||
 | 
			
		||||
/// @brief Get A Rendom Int
 | 
			
		||||
/// @param b From
 | 
			
		||||
/// @param e To
 | 
			
		||||
/// @return Random Int
 | 
			
		||||
int GetRandomInt(int b, int e);
 | 
			
		||||
/// @brief Fade In
 | 
			
		||||
/// @param duration Duration in Frames
 | 
			
		||||
void FadeIn();
 | 
			
		||||
/// @brief Fade Out
 | 
			
		||||
/// @param duration Duration in Frames
 | 
			
		||||
void FadeOut();
 | 
			
		||||
/// @brief Display Fade Effects
 | 
			
		||||
void FadeDisplay();
 | 
			
		||||
 | 
			
		||||
namespace Init {
 | 
			
		||||
/// @brief Init Default Palladium
 | 
			
		||||
/// @param app_name Name of Your App
 | 
			
		||||
/// @return ResCode
 | 
			
		||||
Result Main(std::string app_name = "pdGame");
 | 
			
		||||
/// @brief Init Minimal Palladium (For better Hax2.x support)
 | 
			
		||||
/// @param app_name Name of Your App
 | 
			
		||||
/// @return ResCode
 | 
			
		||||
Result Minimal(std::string app_name = "pdGame");
 | 
			
		||||
/// @brief Reload the Graphics Engine
 | 
			
		||||
/// @return ResCode
 | 
			
		||||
Result Reload();
 | 
			
		||||
/// @brief Init Graphics Only (NOT SUPPORTET use Reload)
 | 
			
		||||
void Graphics();
 | 
			
		||||
/// @brief Init Ndsp for Sounds
 | 
			
		||||
void NdspFirm();
 | 
			
		||||
}  // namespace Init
 | 
			
		||||
 | 
			
		||||
namespace FS {
 | 
			
		||||
/// @brief Check if File exists
 | 
			
		||||
/// @param path Path to the File
 | 
			
		||||
/// @return exists or not
 | 
			
		||||
bool FileExist(const std::string &path);
 | 
			
		||||
}  // namespace FS
 | 
			
		||||
 | 
			
		||||
/// @brief Check if Ndsp is Init
 | 
			
		||||
/// @return is or not
 | 
			
		||||
bool IsNdspInit();
 | 
			
		||||
/// @brief Get Current Framerate as String
 | 
			
		||||
/// @return Framerate String
 | 
			
		||||
std::string GetFramerate();
 | 
			
		||||
/// @brief MainLoop of Palladiums
 | 
			
		||||
/// @return Is Still Running or not
 | 
			
		||||
bool MainLoop();
 | 
			
		||||
/// @brief Exit App (brak the MainLoop)
 | 
			
		||||
void ExitApp();
 | 
			
		||||
 | 
			
		||||
/// @brief Clear the Citro2D TextBuffers
 | 
			
		||||
/// @param
 | 
			
		||||
void ClearTextBufs(void);
 | 
			
		||||
 | 
			
		||||
/// @brief Draw Overlays And end the Frame. DO NEVER USE C3D_FRAMEEND cause it
 | 
			
		||||
/// breaks Overlay crash Security
 | 
			
		||||
void FrameEnd();
 | 
			
		||||
 | 
			
		||||
/// @brief Returns App Working Directory path
 | 
			
		||||
/// @return AppDir Path
 | 
			
		||||
std::string GetAppDirectory();
 | 
			
		||||
/// @brief returns path to the Data Directory
 | 
			
		||||
/// @return data dir path
 | 
			
		||||
std::string GetDataDirectory();
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										134
									
								
								include/pd/parameter.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										134
									
								
								include/pd/parameter.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,134 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <tuple>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
class Parameter {
 | 
			
		||||
 private:
 | 
			
		||||
  using id = size_t;
 | 
			
		||||
 | 
			
		||||
  template <typename T>
 | 
			
		||||
  struct type {
 | 
			
		||||
    static void id() {}
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  template <typename T>
 | 
			
		||||
  static id type_id() {
 | 
			
		||||
    return reinterpret_cast<id>(&type<T>::id);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  template <typename T>
 | 
			
		||||
  using decay = typename std::decay<T>::type;
 | 
			
		||||
 | 
			
		||||
  template <typename T>
 | 
			
		||||
  using none =
 | 
			
		||||
      typename std::enable_if<!std::is_same<Parameter, T>::value>::type;
 | 
			
		||||
 | 
			
		||||
  struct base {
 | 
			
		||||
    virtual ~base() {}
 | 
			
		||||
    virtual bool is(id) const = 0;
 | 
			
		||||
    virtual base *copy() const = 0;
 | 
			
		||||
  } *p = nullptr;
 | 
			
		||||
 | 
			
		||||
  template <typename T>
 | 
			
		||||
  struct data : base, std::tuple<T> {
 | 
			
		||||
    using std::tuple<T>::tuple;
 | 
			
		||||
 | 
			
		||||
    T &get() & { return std::get<0>(*this); }
 | 
			
		||||
    T const &get() const & { return std::get<0>(*this); }
 | 
			
		||||
 | 
			
		||||
    bool is(id i) const override { return i == type_id<T>(); }
 | 
			
		||||
    base *copy() const override { return new data{get()}; }
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  template <typename T>
 | 
			
		||||
  T &stat() {
 | 
			
		||||
    return static_cast<data<T> &>(*p).get();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  template <typename T>
 | 
			
		||||
  T const &stat() const {
 | 
			
		||||
    return static_cast<data<T> const &>(*p).get();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  template <typename T>
 | 
			
		||||
  T &dyn() {
 | 
			
		||||
    return dynamic_cast<data<T> &>(*p).get();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  template <typename T>
 | 
			
		||||
  T const &dyn() const {
 | 
			
		||||
    return dynamic_cast<data<T> const &>(*p).get();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 public:
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief Default constructor
 | 
			
		||||
   */
 | 
			
		||||
  Parameter() {}
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief Destructs the Parameter
 | 
			
		||||
   */
 | 
			
		||||
  ~Parameter() { delete p; }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief Copy constructor
 | 
			
		||||
   * @param s The Parameter to copy
 | 
			
		||||
   */
 | 
			
		||||
  Parameter(Parameter &&s) : p{s.p} { s.p = nullptr; }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief Const copy constructor
 | 
			
		||||
   * @param s The Parameter to copy
 | 
			
		||||
   */
 | 
			
		||||
  Parameter(Parameter const &s) : p{s.p->copy()} {}
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief Initializes the Parameter with the given value
 | 
			
		||||
   * @param x The value to initialize the Parameter with
 | 
			
		||||
   */
 | 
			
		||||
  template <typename T, typename U = decay<T>, typename = none<U>>
 | 
			
		||||
  Parameter(T &&x) : p{new data<U>{std::forward<T>(x)}} {}
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief Overloads the assignment operator
 | 
			
		||||
   * @param s The value to set the Parameter to
 | 
			
		||||
   */
 | 
			
		||||
  Parameter &operator=(Parameter s) {
 | 
			
		||||
    swap(*this, s);
 | 
			
		||||
    return *this;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  friend void swap(Parameter &s, Parameter &r) { std::swap(s.p, r.p); }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief Clears the Parameter
 | 
			
		||||
   */
 | 
			
		||||
  void clear() {
 | 
			
		||||
    delete p;
 | 
			
		||||
    p = nullptr;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief Checks whether the Parameter is the given type
 | 
			
		||||
   * @tparam T The type to check
 | 
			
		||||
   * @return   Whether the Parameter has the given type or not
 | 
			
		||||
   */
 | 
			
		||||
  template <typename T>
 | 
			
		||||
  bool is() const {
 | 
			
		||||
    return p ? p->is(type_id<T>()) : false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief Returns the value of the Parameter
 | 
			
		||||
   * @tparam T The type of the Parameter
 | 
			
		||||
   * @return The value of the Parameter
 | 
			
		||||
   * @warning If the type of the Parameter doesn't match the type of it's stored
 | 
			
		||||
   * value, it will result in undefined behaviour.
 | 
			
		||||
   */
 | 
			
		||||
  template <typename T>
 | 
			
		||||
  T &get() & {
 | 
			
		||||
    return stat<T>();
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										10
									
								
								include/pd/smart_ctor.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								include/pd/smart_ctor.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <memory>
 | 
			
		||||
 | 
			
		||||
#define PD_SMART_CTOR(type)                                     \
 | 
			
		||||
  using Ref = std::shared_ptr<type>;                             \
 | 
			
		||||
  template <typename... args>                                    \
 | 
			
		||||
  static Ref New(args&&... cargs) {                              \
 | 
			
		||||
    return std::make_shared<type>(std::forward<args>(cargs)...); \
 | 
			
		||||
  }
 | 
			
		||||
							
								
								
									
										103
									
								
								include/pd/stringtool.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								include/pd/stringtool.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,103 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <iomanip>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <sstream>
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
/// @brief Check if A String ends with
 | 
			
		||||
/// @param name Input String
 | 
			
		||||
/// @param extensions Extensions to Check for
 | 
			
		||||
/// @return Ends with or not
 | 
			
		||||
inline bool NameIsEndingWith(const std::string &name,
 | 
			
		||||
                             const std::vector<std::string> &extensions) {
 | 
			
		||||
  if (name.substr(0, 2) == "._") return false;
 | 
			
		||||
 | 
			
		||||
  if (name.size() == 0) return false;
 | 
			
		||||
 | 
			
		||||
  if (extensions.size() == 0) return true;
 | 
			
		||||
 | 
			
		||||
  for (int i = 0; i < (int)extensions.size(); i++) {
 | 
			
		||||
    const std::string ext = extensions.at(i);
 | 
			
		||||
    if (strcasecmp(name.c_str() + name.size() - ext.size(), ext.c_str()) == 0)
 | 
			
		||||
      return true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return false;
 | 
			
		||||
}
 | 
			
		||||
/// @brief Format Milliseconds to clean string (Stolen from one of my Mc
 | 
			
		||||
/// Plugins)
 | 
			
		||||
/// @param t_time Time in ms
 | 
			
		||||
/// @return String
 | 
			
		||||
inline std::string MsTimeFmt(float t_time, bool dems = false) {
 | 
			
		||||
  std::ostringstream oss;
 | 
			
		||||
 | 
			
		||||
  if (t_time < 0.001f) {
 | 
			
		||||
    oss << std::fixed << std::setprecision(2) << t_time * 1000.0f << "ns";
 | 
			
		||||
  } else if (t_time < 1.0f) {
 | 
			
		||||
    oss << std::fixed << std::setprecision(2) << t_time << "ms";
 | 
			
		||||
  } else if (t_time < 60000.0f) {
 | 
			
		||||
    int seconds = static_cast<int>(t_time / 1000.0f);
 | 
			
		||||
    float milliseconds = t_time - (seconds * 1000.0f);
 | 
			
		||||
 | 
			
		||||
    if (seconds > 0) {
 | 
			
		||||
      oss << seconds << "s ";
 | 
			
		||||
    }
 | 
			
		||||
    if (!dems)
 | 
			
		||||
      oss << std::fixed << std::setprecision(2) << milliseconds << "ms";
 | 
			
		||||
  } else {
 | 
			
		||||
    int minutes = static_cast<int>(t_time / 60000.0f);
 | 
			
		||||
    int seconds = static_cast<int>((t_time - (minutes * 60000.0f)) / 1000.0f);
 | 
			
		||||
    float milliseconds = t_time - (minutes * 60000.0f) - (seconds * 1000.0f);
 | 
			
		||||
 | 
			
		||||
    oss << minutes << "m ";
 | 
			
		||||
    if (seconds > 0 || milliseconds > 0.0f) {
 | 
			
		||||
      oss << seconds << "s ";
 | 
			
		||||
    }
 | 
			
		||||
    if (milliseconds > 0.0f && !dems) {
 | 
			
		||||
      oss << std::fixed << std::setprecision(2) << milliseconds << "ms";
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return oss.str();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
inline std::string FormatBytes(int bytes) {
 | 
			
		||||
  char out[32];
 | 
			
		||||
 | 
			
		||||
  if (bytes == 1)
 | 
			
		||||
    snprintf(out, sizeof(out), "%d Byte", bytes);
 | 
			
		||||
 | 
			
		||||
  else if (bytes < 1024)
 | 
			
		||||
    snprintf(out, sizeof(out), "%d Bytes", bytes);
 | 
			
		||||
 | 
			
		||||
  else if (bytes < 1024 * 1024)
 | 
			
		||||
    snprintf(out, sizeof(out), "%.1f KB", (float)bytes / 1024);
 | 
			
		||||
 | 
			
		||||
  else if (bytes < 1024 * 1024 * 1024)
 | 
			
		||||
    snprintf(out, sizeof(out), "%.1f MB", (float)bytes / 1024 / 1024);
 | 
			
		||||
 | 
			
		||||
  else
 | 
			
		||||
    snprintf(out, sizeof(out), "%.1f GB", (float)bytes / 1024 / 1024 / 1024);
 | 
			
		||||
 | 
			
		||||
  return out;
 | 
			
		||||
}
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
 | 
			
		||||
template <class T>
 | 
			
		||||
T GetFileName(T const &path, T const &delims = "/\\") {
 | 
			
		||||
  return path.substr(path.find_last_of(delims) + 1);
 | 
			
		||||
}
 | 
			
		||||
template <class T>
 | 
			
		||||
T remove_ext(T const &filename) {
 | 
			
		||||
  typename T::size_type const p(filename.find_last_of('.'));
 | 
			
		||||
  return p > 0 && p != T::npos ? filename.substr(0, p) : filename;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
std::string Int_To_Hex(T i) {
 | 
			
		||||
  std::stringstream stream;
 | 
			
		||||
  stream << "0x" << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex
 | 
			
		||||
         << i;
 | 
			
		||||
  return stream.str();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										25
									
								
								include/pd/swr.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								include/pd/swr.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <pd/nimg.hpp>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
class swr {
 | 
			
		||||
 public:
 | 
			
		||||
  swr(int w, int h);
 | 
			
		||||
  swr();
 | 
			
		||||
  ~swr();
 | 
			
		||||
  nimg& get_image() { return image; }
 | 
			
		||||
  void load_file(const std::string& path);
 | 
			
		||||
  void load_nimg(const std::string& path);
 | 
			
		||||
 | 
			
		||||
  // Rendering
 | 
			
		||||
  void draw_pixel(int x, int y, unsigned int color);
 | 
			
		||||
  void draw_rect(int x, int y, int w, int h, unsigned int color, int t = 1);
 | 
			
		||||
  void draw_rect_solid(int x, int y, int w, int h, unsigned int color);
 | 
			
		||||
  void draw_line(int x1, int y1, int x2, int y2, unsigned int color, int t = 1);
 | 
			
		||||
  void flip(bool h, bool v);
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  nimg image;
 | 
			
		||||
};
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										122
									
								
								include/pd/thread.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										122
									
								
								include/pd/thread.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,122 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <3ds.h>
 | 
			
		||||
 | 
			
		||||
#include <atomic>
 | 
			
		||||
#include <functional>
 | 
			
		||||
#include <pd/parameter.hpp>
 | 
			
		||||
 | 
			
		||||
using CTRU_Thread = Thread;
 | 
			
		||||
 | 
			
		||||
#define THREAD_STACK_SIZE 0x1000
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
class Thread {
 | 
			
		||||
 public:
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief Default constructor
 | 
			
		||||
   * @note This should only be called when calling m3d::Thread::initialize()
 | 
			
		||||
   * before calling m3d::Thread::start()
 | 
			
		||||
   */
 | 
			
		||||
  Thread();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief Constructs the thread
 | 
			
		||||
   * @param t_function  The thread function
 | 
			
		||||
   * @param t_parameter The parameter to pass to the function
 | 
			
		||||
   * @param t_autostart Whether the thread should start instantly
 | 
			
		||||
   * @param t_detached  Whether the thread starts detached or not
 | 
			
		||||
   * @param t_stackSize The stacksize allocated for the thread in bytes (rounded
 | 
			
		||||
   * to multiples of 8 bytes)
 | 
			
		||||
   * @note t_function needs to be of type `void` and take one (and only one)
 | 
			
		||||
   * parameter of type m3d::Parameter
 | 
			
		||||
   * @warning If the thread priority is lower than the priority of the calling
 | 
			
		||||
   * thread, the thread will never get executed. Use
 | 
			
		||||
   * m3d::Thread::getCurrentPriority() to get the priority of the current thread
 | 
			
		||||
   */
 | 
			
		||||
  Thread(std::function<void(Palladium::Parameter)> t_function,
 | 
			
		||||
         Palladium::Parameter t_parameter = nullptr, bool t_autostart = false,
 | 
			
		||||
         bool t_detached = false,
 | 
			
		||||
         unsigned long long int t_stackSize = 4 * 1024);
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief Destructs the thread
 | 
			
		||||
   */
 | 
			
		||||
  virtual ~Thread();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief Initializes the thread
 | 
			
		||||
   * @param t_function  The thread function
 | 
			
		||||
   * @param t_parameter The parameter to pass to the function
 | 
			
		||||
   * @param t_autostart Whether the thread should start instantly
 | 
			
		||||
   * @param t_detached  Whether the thread starts detached or not
 | 
			
		||||
   * @param t_stackSize The stacksize allocated for the thread in bytes (rounded
 | 
			
		||||
   * to multiples of 8 bytes)
 | 
			
		||||
   * @note t_function needs to be of type `void` and take one (and only one)
 | 
			
		||||
   * parameter of type m3d::Parameter
 | 
			
		||||
   * @warning If the thread priority is lower than the priority of the calling
 | 
			
		||||
   * thread, the thread will never get executed. Use
 | 
			
		||||
   * m3d::Thread::getCurrentPriority() to get the priority of the current thread
 | 
			
		||||
   */
 | 
			
		||||
  void initialize(std::function<void(Palladium::Parameter)> t_function,
 | 
			
		||||
                  Palladium::Parameter t_parameter = nullptr,
 | 
			
		||||
                  bool t_autostart = false, bool t_detached = false,
 | 
			
		||||
                  unsigned long long int t_stackSize = 4 * 1024);
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief Sets the size of the stack that gets allocated for the next thread
 | 
			
		||||
   * that get's started
 | 
			
		||||
   * @param t_stackSize The allocated space in bytes (rounded to multiples of 8
 | 
			
		||||
   * bytes)
 | 
			
		||||
   */
 | 
			
		||||
  void setStackSize(unsigned long long int t_stackSize);
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief Starts the thread. To restart it, call Thread::join() before
 | 
			
		||||
   * @param t_detached Whether the thread should start detached or not
 | 
			
		||||
   */
 | 
			
		||||
  void start(bool t_detached = false);
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief Detaches the thread
 | 
			
		||||
   */
 | 
			
		||||
  void kill();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief Waits for the thread to finish
 | 
			
		||||
   * @param t_timeout The timeout in nanoseconds. Leave it for no timeout
 | 
			
		||||
   */
 | 
			
		||||
  void join(long long unsigned int t_timeout = U64_MAX);
 | 
			
		||||
 | 
			
		||||
  bool isRunning();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief Puts the thread to sleep
 | 
			
		||||
   *
 | 
			
		||||
   * This is needed if you have multiple threads running at the same time. It
 | 
			
		||||
   * doesn't affect the execution-time of the thread, it just makes it possible
 | 
			
		||||
   * for the other threads to get their chance to shine.
 | 
			
		||||
   */
 | 
			
		||||
  static void sleep();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @brief Sleeps for the given time
 | 
			
		||||
   * @param t_milliseconds The time to sleep in milliseconds
 | 
			
		||||
   */
 | 
			
		||||
  static void sleep(int t_milliseconds);
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  struct ThreadData {
 | 
			
		||||
    Palladium::Parameter m_parameter;
 | 
			
		||||
    std::function<void(Palladium::Parameter)> m_function;
 | 
			
		||||
    std::atomic<bool> *m_running;
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  static void threadFunction(void *t_arg);
 | 
			
		||||
  /* data */
 | 
			
		||||
  int m_priority, m_stackSize;
 | 
			
		||||
  bool m_started;
 | 
			
		||||
  std::atomic<bool> m_running;
 | 
			
		||||
  Palladium::Thread::ThreadData m_data;
 | 
			
		||||
  CTRU_Thread m_thread;
 | 
			
		||||
};
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										3
									
								
								intellisense/li7_shbin.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								intellisense/li7_shbin.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
extern const u8 li7_shbin_end[];
 | 
			
		||||
extern const u8 li7_shbin[];
 | 
			
		||||
extern const u32 li7_shbin_size;
 | 
			
		||||
							
								
								
									
										44
									
								
								mkdocs.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								mkdocs.yaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,44 @@
 | 
			
		||||
site_name: RenderD7 Docs
 | 
			
		||||
site_description:  
 | 
			
		||||
theme:
 | 
			
		||||
  name: material
 | 
			
		||||
  custom_dir: docs/overrides
 | 
			
		||||
  features:
 | 
			
		||||
    - navigation.indexes
 | 
			
		||||
  palette:
 | 
			
		||||
    # Palette toggle for light mode
 | 
			
		||||
    - scheme: default
 | 
			
		||||
      primary: red
 | 
			
		||||
      accent: red
 | 
			
		||||
      toggle:
 | 
			
		||||
        icon: material/brightness-7 
 | 
			
		||||
        name: Switch to dark mode
 | 
			
		||||
 | 
			
		||||
    # Palette toggle for dark mode
 | 
			
		||||
    - scheme: slate
 | 
			
		||||
      primary: red
 | 
			
		||||
      accent: red
 | 
			
		||||
      toggle:
 | 
			
		||||
        icon: material/brightness-4
 | 
			
		||||
        name: Switch to light mode
 | 
			
		||||
 | 
			
		||||
markdown_extensions:
 | 
			
		||||
  - def_list
 | 
			
		||||
  - attr_list
 | 
			
		||||
  - admonition
 | 
			
		||||
  - pymdownx.details
 | 
			
		||||
  - pymdownx.superfences
 | 
			
		||||
  - pymdownx.arithmatex:
 | 
			
		||||
      generic: true
 | 
			
		||||
  - pymdownx.emoji:
 | 
			
		||||
      emoji_index: !!python/name:materialx.emoji.twemoji
 | 
			
		||||
      emoji_generator: !!python/name:materialx.emoji.to_svg
 | 
			
		||||
plugins:
 | 
			
		||||
  - search
 | 
			
		||||
extra_css:
 | 
			
		||||
  - stylesheets/doxide.css
 | 
			
		||||
extra_javascript:
 | 
			
		||||
  - javascripts/mathjax.js
 | 
			
		||||
  - https://polyfill.io/v3/polyfill.min.js?features=es6
 | 
			
		||||
  - https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										229
									
								
								source/Color.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										229
									
								
								source/Color.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,229 @@
 | 
			
		||||
#include <filesystem>
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <map>
 | 
			
		||||
#include <pd/Color.hpp>
 | 
			
		||||
#include <pd/Message.hpp>
 | 
			
		||||
#include <pd/external/json.hpp>
 | 
			
		||||
#include <pd/internal_db.hpp>
 | 
			
		||||
 | 
			
		||||
void pdi_swap32(unsigned int& c) {
 | 
			
		||||
  c = ((c & 0xFF) << 24) | ((c & 0xFF00) << 8) | ((c & 0xFF0000) >> 8) |
 | 
			
		||||
      ((c & 0xFF000000) >> 24);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string Palladium::Color::RGBA2Hex(unsigned int c32) {
 | 
			
		||||
  pdi_swap32(c32);
 | 
			
		||||
  std::stringstream ss;
 | 
			
		||||
  ss << "#";
 | 
			
		||||
  ss << std::hex << std::setw(8) << std::setfill('0') << c32;
 | 
			
		||||
  return ss.str();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Standart Color Converter
 | 
			
		||||
static const std::map<char, int> HEX_TO_DEC = {
 | 
			
		||||
    {'0', 0},  {'1', 1},  {'2', 2},  {'3', 3},  {'4', 4},  {'5', 5},
 | 
			
		||||
    {'6', 6},  {'7', 7},  {'8', 8},  {'9', 9},  {'a', 10}, {'b', 11},
 | 
			
		||||
    {'c', 12}, {'d', 13}, {'e', 14}, {'f', 15}, {'A', 10}, {'B', 11},
 | 
			
		||||
    {'C', 12}, {'D', 13}, {'E', 14}, {'F', 15}};
 | 
			
		||||
 | 
			
		||||
unsigned int pdi_special_color_hex(const std::string& hex) {
 | 
			
		||||
  if (hex.length() < 9 || std::find_if(hex.begin() + 1, hex.end(), [](char c) {
 | 
			
		||||
                            return !std::isxdigit(c);
 | 
			
		||||
                          }) != hex.end()) {
 | 
			
		||||
    return pdi_special_color_hex("#00000000");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  int r = HEX_TO_DEC.at(hex[1]) * 16 + HEX_TO_DEC.at(hex[2]);
 | 
			
		||||
  int g = HEX_TO_DEC.at(hex[3]) * 16 + HEX_TO_DEC.at(hex[4]);
 | 
			
		||||
  int b = HEX_TO_DEC.at(hex[5]) * 16 + HEX_TO_DEC.at(hex[6]);
 | 
			
		||||
  int a = HEX_TO_DEC.at(hex[7]) * 16 + HEX_TO_DEC.at(hex[8]);
 | 
			
		||||
 | 
			
		||||
  return RGBA8(r, g, b, a);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Default Theme
 | 
			
		||||
const std::map<PDColor, unsigned int> pdi_default_theme = {
 | 
			
		||||
    {PDColor_Text, RGBA8(0, 0, 0, 255)},
 | 
			
		||||
    {PDColor_Text2, RGBA8(255, 255, 255, 255)},  // For Background change or so
 | 
			
		||||
    {PDColor_TextDisabled, RGBA8(170, 170, 170, 255)},
 | 
			
		||||
    {PDColor_Background, RGBA8(238, 238, 238, 255)},
 | 
			
		||||
    {PDColor_Header, RGBA8(17, 17, 17, 255)},
 | 
			
		||||
    {PDColor_Selector, RGBA8(34, 34, 34, 255)},
 | 
			
		||||
    {PDColor_SelectorFade, RGBA8(90, 90, 90, 255)},
 | 
			
		||||
    {PDColor_List0, RGBA8(204, 204, 204, 255)},  // List0 = % 2
 | 
			
		||||
    {PDColor_List1, RGBA8(187, 187, 187, 255)},
 | 
			
		||||
    {PDColor_MessageBackground, RGBA8(51, 51, 51, 255)},
 | 
			
		||||
    {PDColor_Button, RGBA8(17, 17, 17, 255)},
 | 
			
		||||
    {PDColor_ButtonHovered, RGBA8(34, 34, 34, 255)},
 | 
			
		||||
    {PDColor_ButtonDisabled, RGBA8(8, 8, 8, 255)},
 | 
			
		||||
    {PDColor_ButtonActive, RGBA8(42, 42, 42, 255)},
 | 
			
		||||
    {PDColor_Checkmark, RGBA8(42, 42, 42, 255)},
 | 
			
		||||
    {PDColor_FrameBg, RGBA8(85, 85, 85, 255)},
 | 
			
		||||
    {PDColor_FrameBgHovered, RGBA8(119, 119, 119, 255)},
 | 
			
		||||
    {PDColor_Progressbar, RGBA8(0, 255, 0, 255)},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void Palladium::Theme::Load(const std::string& path) {
 | 
			
		||||
  std::ifstream file(path);
 | 
			
		||||
  if (!file.is_open()) {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  nlohmann::json js;
 | 
			
		||||
  file >> js;
 | 
			
		||||
  // clang-format off
 | 
			
		||||
  if(THEMEVER != js["version"]) {
 | 
			
		||||
    file.close();
 | 
			
		||||
    return; 
 | 
			
		||||
  }
 | 
			
		||||
  this->clr_tab.clear();
 | 
			
		||||
  this->clr_tab.resize(PDColor_Len);
 | 
			
		||||
  this->clr_tab[PDColor_Text] = pdi_special_color_hex(js["PDColor_Text"].get<std::string>());
 | 
			
		||||
  this->clr_tab[PDColor_Text2] = pdi_special_color_hex(js["PDColor_Text2"].get<std::string>());
 | 
			
		||||
  this->clr_tab[PDColor_TextDisabled] = pdi_special_color_hex(js["PDColor_TextDisabled"].get<std::string>());
 | 
			
		||||
  this->clr_tab[PDColor_Background] = pdi_special_color_hex(js["PDColor_Background"].get<std::string>());
 | 
			
		||||
  this->clr_tab[PDColor_Header] = pdi_special_color_hex(js["PDColor_Header"].get<std::string>());
 | 
			
		||||
  this->clr_tab[PDColor_Selector] = pdi_special_color_hex(js["PDColor_Selector"].get<std::string>());
 | 
			
		||||
  this->clr_tab[PDColor_SelectorFade] = pdi_special_color_hex(js["PDColor_SelectorFade"].get<std::string>());
 | 
			
		||||
  this->clr_tab[PDColor_List0] = pdi_special_color_hex(js["PDColor_List0"].get<std::string>());
 | 
			
		||||
  this->clr_tab[PDColor_List1] = pdi_special_color_hex(js["PDColor_List1"].get<std::string>());
 | 
			
		||||
  this->clr_tab[PDColor_MessageBackground] =  pdi_special_color_hex(js["PDColor_MessageBackground"].get<std::string>());
 | 
			
		||||
  this->clr_tab[PDColor_Button] = pdi_special_color_hex(js["PDColor_Button"].get<std::string>());
 | 
			
		||||
  this->clr_tab[PDColor_ButtonHovered] = pdi_special_color_hex(js["PDColor_ButtonHovered"].get<std::string>());
 | 
			
		||||
  this->clr_tab[PDColor_ButtonDisabled] = pdi_special_color_hex(js["PDColor_ButtonDisabled"].get<std::string>());
 | 
			
		||||
  this->clr_tab[PDColor_ButtonActive] = pdi_special_color_hex(js["PDColor_ButtonActive"].get<std::string>());
 | 
			
		||||
  this->clr_tab[PDColor_Checkmark] = pdi_special_color_hex(js["PDColor_Checkmark"].get<std::string>());
 | 
			
		||||
  this->clr_tab[PDColor_FrameBg] = pdi_special_color_hex(js["PDColor_FrameBg"].get<std::string>());
 | 
			
		||||
  this->clr_tab[PDColor_FrameBgHovered] = pdi_special_color_hex(js["PDColor_FrameBgHovered"].get<std::string>());
 | 
			
		||||
  this->clr_tab[PDColor_Progressbar] = pdi_special_color_hex(js["PDColor_Progressbar"].get<std::string>());
 | 
			
		||||
  // clang-format on
 | 
			
		||||
  file.close();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::Theme::Default() {
 | 
			
		||||
  this->clr_tab.clear();
 | 
			
		||||
  this->clr_tab.resize(PDColor_Len);
 | 
			
		||||
  for (auto& it : pdi_default_theme) {
 | 
			
		||||
    this->clr_tab[it.first] = it.second;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::Theme::CopyOther(Theme::Ref theme) {
 | 
			
		||||
  this->clr_tab.clear();
 | 
			
		||||
  this->clr_tab.resize(PDColor_Len);
 | 
			
		||||
  for (int i = 0; i < (int)PDColor_Len; i++) {
 | 
			
		||||
    this->clr_tab[i] = theme->Get(i);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
unsigned int Palladium::Theme::Get(PDColor clr) {
 | 
			
		||||
  if (clr < 0 || clr >= PDColor_Len) return 0;
 | 
			
		||||
  return this->clr_tab[clr];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::Theme::Set(PDColor clr, unsigned int v) {
 | 
			
		||||
  if (clr < 0 || clr >= PDColor_Len) return;
 | 
			
		||||
  this->changes.push_back(change(clr, this->clr_tab[clr], v));
 | 
			
		||||
  this->clr_tab[clr] = v;
 | 
			
		||||
}
 | 
			
		||||
void Palladium::Theme::Swap(PDColor a, PDColor b) {
 | 
			
		||||
  if (a < 0 || a >= PDColor_Len || b < 0 || b >= PDColor_Len) return;
 | 
			
		||||
  auto c = this->clr_tab[a];
 | 
			
		||||
  this->clr_tab[a] = this->clr_tab[b];
 | 
			
		||||
  this->clr_tab[b] = c;
 | 
			
		||||
  this->changes.push_back(change(a, b, c, this->clr_tab[a]));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::Theme::TextBy(PDColor bg) {
 | 
			
		||||
  if (!Color::RGBA(bg).is_light()) Swap(PDColor_Text, PDColor_Text2);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
PDColor Palladium::Theme::AutoText(PDColor bg) {
 | 
			
		||||
  return Color::RGBA(bg).is_light() ? PDColor_Text : PDColor_Text2;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Palladium::Theme::Undo() {
 | 
			
		||||
  if (!this->changes.size()) return false;
 | 
			
		||||
  auto ch = this->changes[this->changes.size() - 1];
 | 
			
		||||
  this->changes.pop_back();
 | 
			
		||||
  if (ch.clr2) {
 | 
			
		||||
    this->clr_tab[ch.clr2] = ch.to;
 | 
			
		||||
    this->clr_tab[ch.clr] = ch.from;
 | 
			
		||||
  } else {
 | 
			
		||||
    this->clr_tab[ch.clr] = ch.from;
 | 
			
		||||
  }
 | 
			
		||||
  return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::Theme::UndoAll() {
 | 
			
		||||
  while (Undo()) {
 | 
			
		||||
    // Just Run Undo Until all is undone
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::Theme::Save(const std::string& path) {
 | 
			
		||||
  if (std::filesystem::path(path).filename().string() == "Palladium.theme") {
 | 
			
		||||
    if (!pdi_amdt) {
 | 
			
		||||
      Palladium::PushMessage("Theme", "Default Theme cannot\nbe overwritten!");
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  std::ofstream file(path);
 | 
			
		||||
  if (!file.is_open()) {
 | 
			
		||||
    Palladium::PushMessage("Theme", "Unable to\ncreate file!");
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  nlohmann::json js;
 | 
			
		||||
  // clang-format off
 | 
			
		||||
  js["version"] = THEMEVER;
 | 
			
		||||
  js["PDColor_Text"] = Palladium::Color::RGBA2Hex(this->clr_tab[PDColor_Text]);
 | 
			
		||||
  js["PDColor_Text2"] = Palladium::Color::RGBA2Hex(this->clr_tab[PDColor_Text2]);
 | 
			
		||||
  js["PDColor_TextDisabled"] =
 | 
			
		||||
Palladium::Color::RGBA2Hex(this->clr_tab[PDColor_TextDisabled]); js["PDColor_Background"] =
 | 
			
		||||
Palladium::Color::RGBA2Hex(this->clr_tab[PDColor_Background]); js["PDColor_Header"] =
 | 
			
		||||
Palladium::Color::RGBA2Hex(this->clr_tab[PDColor_Header]); js["PDColor_Selector"] =
 | 
			
		||||
Palladium::Color::RGBA2Hex(this->clr_tab[PDColor_Selector]); js["PDColor_SelectorFade"] =
 | 
			
		||||
Palladium::Color::RGBA2Hex(this->clr_tab[PDColor_SelectorFade]); js["PDColor_List0"] =
 | 
			
		||||
Palladium::Color::RGBA2Hex(this->clr_tab[PDColor_List0]); js["PDColor_List1"] =
 | 
			
		||||
Palladium::Color::RGBA2Hex(this->clr_tab[PDColor_List1]); js["PDColor_MessageBackground"] =
 | 
			
		||||
Palladium::Color::RGBA2Hex(this->clr_tab[PDColor_MessageBackground]); js["PDColor_Button"] =
 | 
			
		||||
Palladium::Color::RGBA2Hex(this->clr_tab[PDColor_Button]); js["PDColor_ButtonHovered"] =
 | 
			
		||||
Palladium::Color::RGBA2Hex(this->clr_tab[PDColor_ButtonHovered]);
 | 
			
		||||
  js["PDColor_ButtonDisabled"] =
 | 
			
		||||
Palladium::Color::RGBA2Hex(this->clr_tab[PDColor_ButtonDisabled]);
 | 
			
		||||
  js["PDColor_ButtonActive"] =
 | 
			
		||||
Palladium::Color::RGBA2Hex(this->clr_tab[PDColor_ButtonActive]); js["PDColor_Checkmark"] =
 | 
			
		||||
Palladium::Color::RGBA2Hex(this->clr_tab[PDColor_Checkmark]); js["PDColor_FrameBg"] =
 | 
			
		||||
Palladium::Color::RGBA2Hex(this->clr_tab[PDColor_FrameBg]); js["PDColor_FrameBgHovered"] =
 | 
			
		||||
Palladium::Color::RGBA2Hex(this->clr_tab[PDColor_FrameBgHovered]); js["PDColor_Progressbar"]
 | 
			
		||||
= Palladium::Color::RGBA2Hex(this->clr_tab[PDColor_Progressbar]);
 | 
			
		||||
  // clang-format on
 | 
			
		||||
  file << js.dump(4);
 | 
			
		||||
  file.close();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Palladium::Theme::Ref Palladium::ThemeActive() { return pdi_active_theme; }
 | 
			
		||||
 | 
			
		||||
void Palladium::ThemeSet(Palladium::Theme::Ref theme) {
 | 
			
		||||
  pdi_active_theme = theme;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
unsigned int Palladium::Color::Hex(const std::string& color, uint8_t a) {
 | 
			
		||||
  if (color.length() < 7 ||
 | 
			
		||||
      std::find_if(color.begin() + 1, color.end(),
 | 
			
		||||
                   [](char c) { return !std::isxdigit(c); }) != color.end()) {
 | 
			
		||||
    return Palladium::Color::Hex("#000000", 0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  int r = HEX_TO_DEC.at(color[1]) * 16 + HEX_TO_DEC.at(color[2]);
 | 
			
		||||
  int g = HEX_TO_DEC.at(color[3]) * 16 + HEX_TO_DEC.at(color[4]);
 | 
			
		||||
  int b = HEX_TO_DEC.at(color[5]) * 16 + HEX_TO_DEC.at(color[6]);
 | 
			
		||||
 | 
			
		||||
  return RGBA8(r, g, b, a);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string Palladium::Color::RGB2Hex(int r, int g, int b) {
 | 
			
		||||
  std::stringstream ss;
 | 
			
		||||
  ss << "#";
 | 
			
		||||
  ss << std::hex << (r << 16 | g << 8 | b);
 | 
			
		||||
  return ss.str();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										58
									
								
								source/Error.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								source/Error.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
#include <3ds.h>
 | 
			
		||||
 | 
			
		||||
#include <pd/Error.hpp>
 | 
			
		||||
#include <pd/UI7.hpp>
 | 
			
		||||
#include <pd/internal_db.hpp>
 | 
			
		||||
#include <pd/palladium.hpp>
 | 
			
		||||
 | 
			
		||||
void pdi_save_report(const std::string& msg) {
 | 
			
		||||
  auto ts = Palladium::GetTimeStr();
 | 
			
		||||
  std::ofstream f("sdmc:/Palladium/Reports/report_" + ts + ".txt");
 | 
			
		||||
  f << "Palladium Error [" << pdi_app_name << ", " << ts << "]" << std::endl;
 | 
			
		||||
  f << "Error Message: " << std::endl;
 | 
			
		||||
  f << msg << std::endl;
 | 
			
		||||
  f << "SysInfo: " << std::endl;
 | 
			
		||||
  f << "- Citra -> " << (pdi_is_citra ? "true" : "false") << std::endl;
 | 
			
		||||
  f.close();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
void Error(const std::string& msg) {
 | 
			
		||||
  pdi_save_report(msg);
 | 
			
		||||
  if (pdi_graphics_on) {
 | 
			
		||||
    while (aptMainLoop()) {
 | 
			
		||||
      hidScanInput();
 | 
			
		||||
      if (hidKeysDown() & KEY_START) break;
 | 
			
		||||
      C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
 | 
			
		||||
      Palladium::ClearTextBufs();
 | 
			
		||||
      C2D_TargetClear(pd_top, 0x00000000);
 | 
			
		||||
      C2D_TargetClear(pd_bottom, 0x00000000);
 | 
			
		||||
      Palladium::R2::OnScreen(R2Screen_Top);
 | 
			
		||||
      if (UI7::BeginMenu("Palladium - Error Manager", NVec2(),
 | 
			
		||||
                         UI7MenuFlags_TitleMid)) {
 | 
			
		||||
        UI7::Label(msg, PDTextFlags_Wrap);
 | 
			
		||||
        UI7::Label("Press Start to Exit!");
 | 
			
		||||
        UI7::EndMenu();
 | 
			
		||||
      }
 | 
			
		||||
      Palladium::R2::OnScreen(R2Screen_Bottom);
 | 
			
		||||
      UI7::Update();
 | 
			
		||||
      Palladium::R2::Process();
 | 
			
		||||
      C3D_FrameEnd(0);
 | 
			
		||||
    }
 | 
			
		||||
    exit(0);
 | 
			
		||||
  } else {
 | 
			
		||||
    gfxInitDefault();
 | 
			
		||||
    consoleInit(GFX_TOP, NULL);
 | 
			
		||||
    printf("Palladium - ERROR MANAGER\n\n%s\n", msg.c_str());
 | 
			
		||||
    printf("Report Saved in\nsdmc:/Palladium/Reports\n");
 | 
			
		||||
    printf("Press Start to Exit\n");
 | 
			
		||||
    while (aptMainLoop()) {
 | 
			
		||||
      hidScanInput();
 | 
			
		||||
      if (hidKeysDown() & KEY_START) break;
 | 
			
		||||
      gfxSwapBuffers();
 | 
			
		||||
    }
 | 
			
		||||
    gfxExit();
 | 
			
		||||
    exit(0);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										70
									
								
								source/FileSystem.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								source/FileSystem.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,70 @@
 | 
			
		||||
#include <3ds.h>
 | 
			
		||||
#include <stdarg.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
#include <cstring>
 | 
			
		||||
#include <pd/FileSystem.hpp>
 | 
			
		||||
// Debugging
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
#include <filesystem>
 | 
			
		||||
#include <pd/stringtool.hpp>
 | 
			
		||||
 | 
			
		||||
bool ___dir__predicate__(const Palladium::FileSystem::Entry &lhs,
 | 
			
		||||
                         const Palladium::FileSystem::Entry &rhs) {
 | 
			
		||||
  if (!lhs.dir && rhs.dir) return false;
 | 
			
		||||
  if (lhs.dir && !rhs.dir) return true;
 | 
			
		||||
  std::string a = lhs.name;
 | 
			
		||||
  std::string b = rhs.name;
 | 
			
		||||
  std::transform(a.begin(), a.end(), a.begin(),
 | 
			
		||||
                 [](int i) { return std::tolower(i); });
 | 
			
		||||
  std::transform(b.begin(), b.end(), b.begin(),
 | 
			
		||||
                 [](int i) { return std::tolower(i); });
 | 
			
		||||
  return a.compare(b) < 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string Palladium::FileSystem::GetParentPath(std::string path,
 | 
			
		||||
                                                std::string mount_point) {
 | 
			
		||||
  std::string tcl = path;
 | 
			
		||||
  if (path.substr(path.length() - 1, 1) != "/") {
 | 
			
		||||
    tcl += "/";
 | 
			
		||||
  }
 | 
			
		||||
  std::string res =
 | 
			
		||||
      std::filesystem::path(tcl).parent_path().parent_path().string();
 | 
			
		||||
  if (res.length() > mount_point.length()) {
 | 
			
		||||
    return res;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return mount_point;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<Palladium::FileSystem::Entry> Palladium::FileSystem::GetDirContent(
 | 
			
		||||
    std::string path) {
 | 
			
		||||
  std::vector<Palladium::FileSystem::Entry> res;
 | 
			
		||||
  for (const auto &entry :
 | 
			
		||||
       std::filesystem::directory_iterator(std::filesystem::path(path))) {
 | 
			
		||||
    res.push_back({entry.path().string(), GetFileName(entry.path().string()),
 | 
			
		||||
                   entry.is_directory()});
 | 
			
		||||
  }
 | 
			
		||||
  return res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<Palladium::FileSystem::Entry>
 | 
			
		||||
Palladium::FileSystem::GetDirContentsExt(
 | 
			
		||||
    std::string &path, const std::vector<std::string> &extensions) {
 | 
			
		||||
  std::vector<Palladium::FileSystem::Entry> res;
 | 
			
		||||
  for (auto const &it :
 | 
			
		||||
       std::filesystem::directory_iterator(std::filesystem::path(path))) {
 | 
			
		||||
    Palladium::FileSystem::Entry temp;
 | 
			
		||||
    std::string fn = it.path().string();
 | 
			
		||||
    temp.name = GetFileName(fn);
 | 
			
		||||
    temp.path = it.path().string().c_str();
 | 
			
		||||
    temp.dir = it.is_directory();
 | 
			
		||||
    if (NameIsEndingWith(GetFileName(it.path().string()), extensions) ||
 | 
			
		||||
        it.is_directory()) {
 | 
			
		||||
      res.push_back(temp);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  std::sort(res.begin(), res.end(), ___dir__predicate__);
 | 
			
		||||
  return res;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										3
									
								
								source/FunctionTrace.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								source/FunctionTrace.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
#include <pd/FunctionTrace.hpp>
 | 
			
		||||
 | 
			
		||||
std::map<std::string, Palladium::Ftrace::FTRes> Palladium::Ftrace::pd_traces;
 | 
			
		||||
							
								
								
									
										47
									
								
								source/Hardware.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								source/Hardware.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,47 @@
 | 
			
		||||
#include <pd/Hardware.hpp>
 | 
			
		||||
#include <pd/internal_db.hpp>
 | 
			
		||||
 | 
			
		||||
// Os Specific includes
 | 
			
		||||
#include <3ds.h>
 | 
			
		||||
 | 
			
		||||
void Palladium::Hardware::Initialisize() {
 | 
			
		||||
  mcuHwcInit();
 | 
			
		||||
  atexit(mcuHwcExit);
 | 
			
		||||
  ptmuInit();
 | 
			
		||||
  atexit(ptmuExit);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Palladium::Hardware::IsHeadphones() {
 | 
			
		||||
  if (pdi_is_ndsp) {
 | 
			
		||||
    bool inserted;
 | 
			
		||||
    DSP_GetHeadphoneStatus(&inserted);
 | 
			
		||||
    return inserted;
 | 
			
		||||
  } else
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Palladium::Hardware::IsCharging() {
 | 
			
		||||
  uint8_t var;
 | 
			
		||||
  PTMU_GetBatteryChargeState(&var);
 | 
			
		||||
  // Some Security Stuff
 | 
			
		||||
  if (var < 0x00 && var > 0x01) {
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
  return (var == 0x01 ? true : false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Palladium::Hardware::GetBatteryPercentage() {
 | 
			
		||||
  uint8_t percentLevel = 0;
 | 
			
		||||
  MCUHWC_GetBatteryLevel(&percentLevel);
 | 
			
		||||
  return percentLevel;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
float Palladium::Hardware::Get3dSliderLevel() { return osGet3DSliderState(); }
 | 
			
		||||
 | 
			
		||||
float Palladium::Hardware::GetSoundSliderLevel() {
 | 
			
		||||
  uint8_t percentLevel;
 | 
			
		||||
  MCUHWC_GetSoundSliderLevel(&percentLevel);
 | 
			
		||||
  return (float)percentLevel / 100;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Palladium::Hardware::GetWifiLevel() { return osGetWifiStrength(); }
 | 
			
		||||
							
								
								
									
										120
									
								
								source/Hid.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										120
									
								
								source/Hid.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,120 @@
 | 
			
		||||
#include <map>
 | 
			
		||||
#include <pd/Hid.hpp>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
class HidApi {
 | 
			
		||||
 public:
 | 
			
		||||
  HidApi() {}
 | 
			
		||||
  ~HidApi() {}
 | 
			
		||||
 | 
			
		||||
  void setKdown(uint32_t &in) { actions[Hid::Down] = ∈ }
 | 
			
		||||
  void setKheld(uint32_t &in) { actions[Hid::Held] = ∈ }
 | 
			
		||||
  void setKup(uint32_t &in) { actions[Hid::Up] = ∈ }
 | 
			
		||||
  void setKrepeat(uint32_t &in) { actions[Hid::DownRepeat] = ∈ }
 | 
			
		||||
  void setTouchCoords(NVec2 &touch_coords) { touch_pos = &touch_coords; }
 | 
			
		||||
  void setJS1Movement(NVec2 &mvmt) { js1_mv = &mvmt; }
 | 
			
		||||
  void setJS2Movement(NVec2 &mvmt) { js2_mv = &mvmt; }
 | 
			
		||||
  void bindKey(const std::string &event, uint32_t key) {
 | 
			
		||||
    key_bindings[event] = key;  // Overrides if existing
 | 
			
		||||
  }
 | 
			
		||||
  void lock(bool lock) { locked = lock; }
 | 
			
		||||
 | 
			
		||||
  void clear() {
 | 
			
		||||
    // Clears Functionality for 1 Frame
 | 
			
		||||
    last_touch_pos = NVec2();
 | 
			
		||||
    touch_pos[0] = NVec2();
 | 
			
		||||
    dtp = NVec2();
 | 
			
		||||
    backups[Hid::Down] = 0;
 | 
			
		||||
    backups[Hid::Held] = 0;
 | 
			
		||||
    backups[Hid::Up] = 0;
 | 
			
		||||
    backups[Hid::DownRepeat] = 0;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  bool isEvent(const std::string &event, Hid::Actions action) {
 | 
			
		||||
    if (locked) return false;
 | 
			
		||||
    if (key_bindings.find(event) == key_bindings.end())
 | 
			
		||||
      return false;  // Unknown Event
 | 
			
		||||
    if (backups.find(action) == backups.end())
 | 
			
		||||
      return false;  // What? NOT Alowed acrion
 | 
			
		||||
    if (backups[action] & key_bindings[event])
 | 
			
		||||
      return true;  // Action contains key as flag
 | 
			
		||||
    return false;   // Nothing to do
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  NVec2 getTouchPos() { return touch_pos[0]; }
 | 
			
		||||
  NVec2 getLastTouchPos() { return last_touch_pos; }
 | 
			
		||||
  NVec2 getTouchDownPos() { return dtp; }
 | 
			
		||||
 | 
			
		||||
  void update() {
 | 
			
		||||
    last_touch_pos = touch_pos[0];
 | 
			
		||||
    if (isEvent("touch", Hid::Down)) {
 | 
			
		||||
      dtp = touch_pos[0];
 | 
			
		||||
    }
 | 
			
		||||
    if (isEvent("touch", Hid::Up)) {
 | 
			
		||||
      dtp = NVec2();
 | 
			
		||||
    }
 | 
			
		||||
    for (const auto &it : actions) {
 | 
			
		||||
      backups[it.first] = it.second[0];
 | 
			
		||||
    }
 | 
			
		||||
    if (locked) {
 | 
			
		||||
      actions[Hid::Down][0] = 0;
 | 
			
		||||
      actions[Hid::Held][0] = 0;
 | 
			
		||||
      actions[Hid::Up][0] = 0;
 | 
			
		||||
      actions[Hid::DownRepeat][0] = 0;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  std::map<Hid::Actions, uint32_t *> actions;
 | 
			
		||||
  std::map<Hid::Actions, uint32_t> backups;
 | 
			
		||||
  NVec2 *touch_pos = nullptr;
 | 
			
		||||
  NVec2 *js1_mv = nullptr;
 | 
			
		||||
  NVec2 *js2_mv = nullptr;
 | 
			
		||||
 | 
			
		||||
  NVec2 last_touch_pos;
 | 
			
		||||
  NVec2 dtp;
 | 
			
		||||
 | 
			
		||||
  std::map<std::string, uint32_t> key_bindings;
 | 
			
		||||
  bool locked = false;
 | 
			
		||||
};
 | 
			
		||||
static HidApi hid_handler;
 | 
			
		||||
namespace Hid {
 | 
			
		||||
// Register Functions
 | 
			
		||||
// Register Current state values
 | 
			
		||||
void RegKeyDown(uint32_t &key_down) { hid_handler.setKdown(key_down); }
 | 
			
		||||
 | 
			
		||||
void RegKeyHeld(uint32_t &key_held) { hid_handler.setKheld(key_held); }
 | 
			
		||||
 | 
			
		||||
void RegKeyUp(uint32_t &key_up) { hid_handler.setKup(key_up); }
 | 
			
		||||
 | 
			
		||||
void RegKeyRepeat(uint32_t &repeat) { hid_handler.setKrepeat(repeat); }
 | 
			
		||||
 | 
			
		||||
void RegTouchCoords(NVec2 &touch_pos) {
 | 
			
		||||
  hid_handler.setTouchCoords(touch_pos);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RegAnalog1Movement(NVec2 &movement) {
 | 
			
		||||
  hid_handler.setJS1Movement(movement);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RegAnalog2Movement(NVec2 &movement) {
 | 
			
		||||
  hid_handler.setJS2Movement(movement);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Register Keys
 | 
			
		||||
void RegKeyEvent(const std::string &event, uint32_t key) {
 | 
			
		||||
  hid_handler.bindKey(event, key);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool IsEvent(const std::string &event, Actions action) {
 | 
			
		||||
  return hid_handler.isEvent(event, action);
 | 
			
		||||
}
 | 
			
		||||
NVec2 GetTouchPosition() { return hid_handler.getTouchPos(); }
 | 
			
		||||
NVec2 GetLastTouchPosition() { return hid_handler.getLastTouchPos(); }
 | 
			
		||||
NVec2 GetTouchDownPosition() { return hid_handler.getTouchDownPos(); }
 | 
			
		||||
void Update() { hid_handler.update(); }
 | 
			
		||||
void Lock() { hid_handler.lock(true); }
 | 
			
		||||
void Unlock() { hid_handler.lock(false); }
 | 
			
		||||
void Clear() { hid_handler.clear(); }
 | 
			
		||||
}  // namespace Hid
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										181
									
								
								source/Image.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										181
									
								
								source/Image.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,181 @@
 | 
			
		||||
#include <pd/external/stb_image.h>
 | 
			
		||||
 | 
			
		||||
#include <pd/Image.hpp>
 | 
			
		||||
#include <pd/internal_db.hpp>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
static u32 __pdi_gp2o__(u32 v) {
 | 
			
		||||
  v--;
 | 
			
		||||
  v |= v >> 1;
 | 
			
		||||
  v |= v >> 2;
 | 
			
		||||
  v |= v >> 4;
 | 
			
		||||
  v |= v >> 8;
 | 
			
		||||
  v |= v >> 16;
 | 
			
		||||
  v++;
 | 
			
		||||
  return (v >= 64 ? v : 64);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void __pdi_r24r32(std::vector<uint8_t> &out,
 | 
			
		||||
                          const std::vector<uint8_t> &in, const int &w,
 | 
			
		||||
                          const int &h) {
 | 
			
		||||
  // Converts RGB24 to RGBA32
 | 
			
		||||
  for (int y = 0; y < h; y++) {
 | 
			
		||||
    for (int x = 0; x < w; x++) {
 | 
			
		||||
      int src = (y * w + x) * 3;
 | 
			
		||||
      int dst = (y * w + x) * 4;
 | 
			
		||||
      out[dst + 0] = in[src + 0];
 | 
			
		||||
      out[dst + 1] = in[src + 1];
 | 
			
		||||
      out[dst + 2] = in[src + 2];
 | 
			
		||||
      out[dst + 3] = 255;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void __pdi_maketex__(C3D_Tex *tex, Tex3DS_SubTexture *sub,
 | 
			
		||||
                             std::vector<unsigned char> &buf, int w, int h) {
 | 
			
		||||
  if (!tex || !sub) {
 | 
			
		||||
    _pdi_logger()->Write("Invalid Inpit (objects have no adress!)");
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  // RGBA -> Abgr
 | 
			
		||||
  for (int y = 0; y < h; y++) {
 | 
			
		||||
    for (int x = 0; x < w; x++) {
 | 
			
		||||
      int pos = (x + y * w) * 4;
 | 
			
		||||
      auto r = buf[pos + 0];
 | 
			
		||||
      auto g = buf[pos + 1];
 | 
			
		||||
      auto b = buf[pos + 2];
 | 
			
		||||
      auto a = buf[pos + 3];
 | 
			
		||||
      buf[pos + 0] = a;
 | 
			
		||||
      buf[pos + 1] = b;
 | 
			
		||||
      buf[pos + 2] = g;
 | 
			
		||||
      buf[pos + 3] = r;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Pow2
 | 
			
		||||
  int wp2 = __pdi_gp2o__((unsigned int)w);
 | 
			
		||||
  int hp2 = __pdi_gp2o__((unsigned int)h);
 | 
			
		||||
 | 
			
		||||
  sub->width = (u16)w;
 | 
			
		||||
  sub->height = (u16)h;
 | 
			
		||||
  sub->left = 0.0f;
 | 
			
		||||
  sub->top = 1.0f;
 | 
			
		||||
  sub->right = ((float)w / (float)wp2);
 | 
			
		||||
  sub->bottom = 1.0 - ((float)h / (float)hp2);
 | 
			
		||||
 | 
			
		||||
  // Texture Setup
 | 
			
		||||
  C3D_TexInit(tex, (u16)wp2, (u16)hp2, GPU_RGBA8);
 | 
			
		||||
  C3D_TexSetFilter(tex, GPU_NEAREST, GPU_NEAREST);
 | 
			
		||||
 | 
			
		||||
  memset(tex->data, 0, tex->size);
 | 
			
		||||
 | 
			
		||||
  for (int x = 0; x < w; x++) {
 | 
			
		||||
    for (int y = 0; y < h; y++) {
 | 
			
		||||
      int dst_pos = ((((y >> 3) * (wp2 >> 3) + (x >> 3)) << 6) +
 | 
			
		||||
                     ((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) |
 | 
			
		||||
                      ((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3))) *
 | 
			
		||||
                    4;
 | 
			
		||||
      int src_pos = (y * w + x) * 4;
 | 
			
		||||
 | 
			
		||||
      memcpy(&((unsigned char *)tex->data)[dst_pos], &buf[src_pos], 4);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  C3D_TexFlush(tex);
 | 
			
		||||
  tex->border = 0x00000000;
 | 
			
		||||
  C3D_TexSetWrap(tex, GPU_CLAMP_TO_BORDER, GPU_CLAMP_TO_BORDER);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
 | 
			
		||||
void Image::Load(const std::string &path) {
 | 
			
		||||
  // Make sure to cleanup
 | 
			
		||||
  Delete();
 | 
			
		||||
  ext = false;
 | 
			
		||||
  // Setup Func and Load Data
 | 
			
		||||
  int w, h, c = 0;
 | 
			
		||||
  unsigned char *image = stbi_load(path.c_str(), &w, &h, &c, 4);
 | 
			
		||||
  if (image == nullptr) {
 | 
			
		||||
    //_pdi_logger()->Write("Failed to Load Image: " + path);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  // Size/Fmt Check
 | 
			
		||||
  if (w > 1024 || h > 1024) {
 | 
			
		||||
    // Reason: Image to Large
 | 
			
		||||
    //_pdi_logger()->Write("Image too Large!");
 | 
			
		||||
    stbi_image_free(image);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  std::vector<unsigned char> wimg;
 | 
			
		||||
  if (c == 3) {
 | 
			
		||||
    //_pdi_logger()->Write("Convert Image to RGBA");
 | 
			
		||||
    stbi_image_free(image);
 | 
			
		||||
    image = stbi_load(path.c_str(), &w, &h, &c, 3);
 | 
			
		||||
    wimg.resize(w * h * 4);
 | 
			
		||||
    __pdi_r24r32(wimg, std::vector<unsigned char>(image, image + (w * h * 3)),
 | 
			
		||||
                  w, h);
 | 
			
		||||
  } else {
 | 
			
		||||
    wimg.assign(&image[0], &image[(w * h * 4) - 1]);
 | 
			
		||||
    stbi_image_free(image);
 | 
			
		||||
  }
 | 
			
		||||
  // Create C2D_Image
 | 
			
		||||
  C3D_Tex *tex = new C3D_Tex;
 | 
			
		||||
  Tex3DS_SubTexture *subtex = new Tex3DS_SubTexture;
 | 
			
		||||
  __pdi_maketex__(tex, subtex, wimg, w, h);
 | 
			
		||||
  _pdi_logger()->Write(Palladium::FormatString("Created Texture (%d, %d)",
 | 
			
		||||
                                               tex->width, tex->height));
 | 
			
		||||
  img = {tex, subtex};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Image::From_NIMG(const nimg &image) {
 | 
			
		||||
  // Make sure to cleanup
 | 
			
		||||
  Delete();
 | 
			
		||||
  ext = false;
 | 
			
		||||
  if (image.width > 1024 || image.height > 1024) return;
 | 
			
		||||
  C3D_Tex *tex = new C3D_Tex;
 | 
			
		||||
  Tex3DS_SubTexture *subtex = new Tex3DS_SubTexture;
 | 
			
		||||
  std::vector<unsigned char> mdpb = image.pixel_buffer;
 | 
			
		||||
  __pdi_maketex__(tex, subtex, mdpb, image.width, image.height);
 | 
			
		||||
  img = {tex, subtex};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
C2D_Image Image::Get() {
 | 
			
		||||
  if (!Loadet()) {
 | 
			
		||||
    _pdi_logger()->Write("Image not Loadet!");
 | 
			
		||||
  }
 | 
			
		||||
  return img;
 | 
			
		||||
}
 | 
			
		||||
C2D_Image &Image::GetRef() {
 | 
			
		||||
  if (!Loadet()) {
 | 
			
		||||
    _pdi_logger()->Write("Image not Loadet!");
 | 
			
		||||
  }
 | 
			
		||||
  return img;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Image::Set(const C2D_Image &i) {
 | 
			
		||||
  Delete();
 | 
			
		||||
  ext = true;
 | 
			
		||||
  img = i;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
NVec2 Image::GetSize() {
 | 
			
		||||
  if (!img.subtex) return NVec2(0, 0);
 | 
			
		||||
  return NVec2(img.subtex->width, img.subtex->height);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Image::Delete() {
 | 
			
		||||
  if (ext) return;
 | 
			
		||||
  if (img.subtex != nullptr) {
 | 
			
		||||
    delete img.subtex;
 | 
			
		||||
    img.subtex = nullptr;
 | 
			
		||||
  }
 | 
			
		||||
  if (img.tex != nullptr) {
 | 
			
		||||
    C3D_TexDelete(img.tex);
 | 
			
		||||
    delete img.tex;
 | 
			
		||||
    img.tex = nullptr;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Image::Loadet() { return (img.subtex != nullptr && img.tex != nullptr); }
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										149
									
								
								source/Installer.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										149
									
								
								source/Installer.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,149 @@
 | 
			
		||||
#include <3ds.h>
 | 
			
		||||
 | 
			
		||||
#include <pd/Installer.hpp>
 | 
			
		||||
#include <pd/internal_db.hpp>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
Result DeletePrevious(u64 id, FS_MediaType mt) {
 | 
			
		||||
  if (!pdi_is_am_init) return -1;
 | 
			
		||||
  u32 num_titles = 0;
 | 
			
		||||
  Result ret = AM_GetTitleCount(mt, &num_titles);
 | 
			
		||||
  if (R_FAILED(ret)) {
 | 
			
		||||
    return ret;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  u32 read_titles = 0;
 | 
			
		||||
  auto ids = new u64[num_titles];
 | 
			
		||||
  ret = AM_GetTitleList(&read_titles, mt, num_titles, ids);
 | 
			
		||||
 | 
			
		||||
  if (R_FAILED(ret)) {
 | 
			
		||||
    delete[] ids;
 | 
			
		||||
    return ret;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  for (u32 i = 0; i < read_titles; i++) {
 | 
			
		||||
    if (ids[i] == id) {
 | 
			
		||||
      ret = AM_DeleteAppTitle(mt, id);
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  delete[] ids;
 | 
			
		||||
  if (R_FAILED(ret)) {
 | 
			
		||||
    return ret;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
FS_MediaType GetTitleDest(u64 id) {
 | 
			
		||||
  u16 platform = (u16)((id >> 48) & 0xFFFF);
 | 
			
		||||
  u16 category = (u16)((id >> 32) & 0xFFFF);
 | 
			
		||||
  u8 variation = (u8)(id & 0xFF);
 | 
			
		||||
 | 
			
		||||
  /*     DSiWare                3DS                    DSiWare, System, DLP
 | 
			
		||||
   * Application           System Title */
 | 
			
		||||
  return platform == 0x0003 || (platform == 0x0004 &&
 | 
			
		||||
                                ((category & 0x8011) != 0 ||
 | 
			
		||||
                                 (category == 0x0000 && variation == 0x02)))
 | 
			
		||||
             ? MEDIATYPE_NAND
 | 
			
		||||
             : MEDIATYPE_SD;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
InstallerInfo pdi_installer_info;
 | 
			
		||||
 | 
			
		||||
InstallerInfo InstallGetInfo() { return pdi_installer_info; }
 | 
			
		||||
 | 
			
		||||
void InstallSetBuffersSize(unsigned int bytes) {
 | 
			
		||||
  if (pdi_installer_info.active) return;
 | 
			
		||||
  if (bytes == 0) return;
 | 
			
		||||
  if (bytes >= 0x200000) bytes = 0x200000;
 | 
			
		||||
  pdi_installer_info.mem_size = bytes;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Result InstallCia(const std::string& path, bool self) {
 | 
			
		||||
  if (!pdi_is_am_init) return -1;
 | 
			
		||||
  if (pdi_installer_info.active) return -1;
 | 
			
		||||
  u32 bytes_read = 0;
 | 
			
		||||
  u32 bytes_written = 0;
 | 
			
		||||
  pdi_installer_info.current = 0;
 | 
			
		||||
  // Set 1 to avoid div0 error
 | 
			
		||||
  pdi_installer_info.total = 1;
 | 
			
		||||
  u64 size = 0;
 | 
			
		||||
  Handle cia, file;
 | 
			
		||||
  AM_TitleEntry info;
 | 
			
		||||
  Result ret = 0;
 | 
			
		||||
  FS_MediaType media = MEDIATYPE_SD;
 | 
			
		||||
 | 
			
		||||
  std::string pth;
 | 
			
		||||
  if (path[0] == '/') {
 | 
			
		||||
    pth = path;
 | 
			
		||||
  } else if (path.substr(0, 5) == "sdmc:") {
 | 
			
		||||
    pth = path.substr(5);
 | 
			
		||||
  } else {
 | 
			
		||||
    return -1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ret = FSUSER_OpenFileDirectly(&file, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, ""),
 | 
			
		||||
                                fsMakePath(PATH_ASCII, pth.c_str()),
 | 
			
		||||
                                FS_OPEN_READ, 0);
 | 
			
		||||
 | 
			
		||||
  if (R_FAILED(ret)) {
 | 
			
		||||
    return ret;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ret = AM_GetCiaFileInfo(media, &info, file);
 | 
			
		||||
 | 
			
		||||
  if (R_FAILED(ret)) {
 | 
			
		||||
    return ret;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  media = GetTitleDest(info.titleID);
 | 
			
		||||
 | 
			
		||||
  if (!self) {
 | 
			
		||||
    ret = DeletePrevious(info.titleID, media);
 | 
			
		||||
    if (R_FAILED(ret)) return ret;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ret = FSFILE_GetSize(file, &size);
 | 
			
		||||
 | 
			
		||||
  if (R_FAILED(ret)) {
 | 
			
		||||
    return ret;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ret = AM_StartCiaInstall(media, &cia);
 | 
			
		||||
 | 
			
		||||
  if (R_FAILED(ret)) {
 | 
			
		||||
    return ret;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  std::vector<unsigned char> buf(pdi_installer_info.mem_size);
 | 
			
		||||
  pdi_installer_info.total = size;
 | 
			
		||||
 | 
			
		||||
  do {
 | 
			
		||||
    FSFILE_Read(file, &bytes_read, pdi_installer_info.current, &buf[0],
 | 
			
		||||
                buf.size());
 | 
			
		||||
    FSFILE_Write(cia, &bytes_written, pdi_installer_info.current, &buf[0],
 | 
			
		||||
                 buf.size(), FS_WRITE_FLUSH);
 | 
			
		||||
    pdi_installer_info.current += bytes_read;
 | 
			
		||||
  } while (pdi_installer_info.current < pdi_installer_info.total);
 | 
			
		||||
 | 
			
		||||
  ret = AM_FinishCiaInstall(cia);
 | 
			
		||||
 | 
			
		||||
  if (R_FAILED(ret)) {
 | 
			
		||||
    return ret;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ret = FSFILE_Close(file);
 | 
			
		||||
 | 
			
		||||
  if (R_FAILED(ret)) {
 | 
			
		||||
    return ret;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (self) {
 | 
			
		||||
    aptSetChainloaderToSelf();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										326
									
								
								source/LI7.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										326
									
								
								source/LI7.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,326 @@
 | 
			
		||||
#include <pd/LI7.hpp>
 | 
			
		||||
#include <pd/Color.hpp>
 | 
			
		||||
#include <pd/palladium.hpp>
 | 
			
		||||
#include <pd/external/stb_truetype.h>
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
 | 
			
		||||
#include <li7_shbin.h>
 | 
			
		||||
 | 
			
		||||
#define DISPLAY_TRANSFER_FLAGS                                              \
 | 
			
		||||
  (GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) |                    \
 | 
			
		||||
   GX_TRANSFER_RAW_COPY(0) | GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | \
 | 
			
		||||
   GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) |                           \
 | 
			
		||||
   GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO))
 | 
			
		||||
 | 
			
		||||
#ifndef __builtin_swap_32
 | 
			
		||||
#define __builtin_swap_32(x)                                                \
 | 
			
		||||
  ((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) | (((x) & 0xff0000) >> 8) | \
 | 
			
		||||
   (((x) >> 24) & 0xff))
 | 
			
		||||
#endif
 | 
			
		||||
#define bs32(x) __builtin_swap_32(x)
 | 
			
		||||
#ifndef MAX
 | 
			
		||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
const float LI7::m_dffs = 8.f;
 | 
			
		||||
int LI7::m_uLoc_proj;
 | 
			
		||||
float LI7::m_scale = 1.0f;
 | 
			
		||||
int LI7::m_width, LI7::m_height;
 | 
			
		||||
int LI7::m_d_vertices = 0;
 | 
			
		||||
int LI7::m_d_drawcalls = 0;
 | 
			
		||||
int LI7::m_d_commands = 0;
 | 
			
		||||
const int LI7::m_char_height = 8;  // Constant
 | 
			
		||||
float LI7::m_rot = 0.f;
 | 
			
		||||
// UI Stuff
 | 
			
		||||
std::vector<LI7::Cmd> LI7::m_top_draw_cmds;
 | 
			
		||||
std::vector<LI7::Cmd> LI7::m_bot_draw_cmds;
 | 
			
		||||
Texture::Ref LI7::m_current_texture;
 | 
			
		||||
std::vector<LI7::Vtx, LinearAllocator<LI7::Vtx>> LI7::m_vtx_list[2];
 | 
			
		||||
// LI7::Font *LI7::m_font;
 | 
			
		||||
std::vector<char> LI7::m_text_buffer;
 | 
			
		||||
// Matrix
 | 
			
		||||
C3D_Mtx LI7::m_icon_model_matrix;
 | 
			
		||||
// Ctx Stuff
 | 
			
		||||
bool LI7::m_bottom_active = false;
 | 
			
		||||
// Shader
 | 
			
		||||
DVLB_s *LI7::li7_dvlb;
 | 
			
		||||
shaderProgram_s LI7::li7_shader;
 | 
			
		||||
C3D_AttrInfo LI7::li7_attr;
 | 
			
		||||
 | 
			
		||||
void LIFont::LoadTFF(const std::string path, int px_size) {
 | 
			
		||||
    // Supported Sizings (Tested [12, 16, 21, 24, 32, 48, 56, 63])
 | 
			
		||||
    this->pixel_height = px_size;
 | 
			
		||||
    if(!Palladium::FS::FileExist(path)) return;
 | 
			
		||||
    int type = px_size*16;
 | 
			
		||||
    // Load TTF
 | 
			
		||||
    stbtt_fontinfo inf;
 | 
			
		||||
    std::ifstream loader(path, std::ios::binary);
 | 
			
		||||
    if (!loader.is_open()) return;
 | 
			
		||||
    loader.seekg(0, std::ios::end);
 | 
			
		||||
    size_t len = loader.tellg();
 | 
			
		||||
    loader.seekg(0, std::ios::beg);
 | 
			
		||||
    unsigned char* buffer = new unsigned char[len];
 | 
			
		||||
    loader.read(reinterpret_cast<char*>(buffer), len);
 | 
			
		||||
    loader.close();
 | 
			
		||||
    stbtt_InitFont(&inf, buffer, 0);
 | 
			
		||||
    std::vector<unsigned char> fmap(type*type*4);
 | 
			
		||||
    float scale = stbtt_ScaleForPixelHeight(&inf, pixel_height);
 | 
			
		||||
 | 
			
		||||
    int ascent, descent, lineGap;
 | 
			
		||||
    stbtt_GetFontVMetrics(&inf, &ascent, &descent, &lineGap);
 | 
			
		||||
    int baseline = static_cast<int>(ascent * scale);
 | 
			
		||||
 | 
			
		||||
    for (int c = 0; c < 255; c++) {
 | 
			
		||||
      if (stbtt_IsGlyphEmpty(&inf, c)) continue;
 | 
			
		||||
 | 
			
		||||
      int width, height, xOffset, yOffset;
 | 
			
		||||
      unsigned char* bitmap = stbtt_GetCodepointBitmap(
 | 
			
		||||
          &inf, scale, scale, c, &width, &height, &xOffset, &yOffset);
 | 
			
		||||
      int x0, y0, x1, y1;
 | 
			
		||||
      stbtt_GetCodepointBitmapBox(&inf, c, scale, scale, &x0, &y0, &x1, &y1);
 | 
			
		||||
      this->fontw[c] = x0 + x1;
 | 
			
		||||
      int i = c % 16;
 | 
			
		||||
      int j = c / 16;
 | 
			
		||||
      int xoff = i * pixel_height;
 | 
			
		||||
      int yoff = j * pixel_height + baseline + yOffset;
 | 
			
		||||
 | 
			
		||||
      for (int y = 0; y < height; ++y) {
 | 
			
		||||
        for (int x = 0; x < width; ++x) {
 | 
			
		||||
          int map_pos = ((yoff + y) * type + (xoff + x)) * 4;
 | 
			
		||||
 | 
			
		||||
          fmap[map_pos + 0] = 255;
 | 
			
		||||
          fmap[map_pos + 1] = 255;
 | 
			
		||||
          fmap[map_pos + 2] = 255;
 | 
			
		||||
          fmap[map_pos + 3] = bitmap[x + y * width];
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      free(bitmap);
 | 
			
		||||
    }
 | 
			
		||||
    auto ftex = Texture::New();
 | 
			
		||||
    ftex->LoadPixels(fmap, type, type);
 | 
			
		||||
    this->tex.push_back(ftex);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LIFont::LoadBitmapFont(const std::string& path) {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LIFont::LoadSystemFont() {
 | 
			
		||||
    
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int LIFont::GetPixelHeight() {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
LIFont::CPI LIFont::GetCodepoint() {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LI7::Init() {
 | 
			
		||||
  m_text_buffer.resize(1024);
 | 
			
		||||
  m_vtx_list[0].reserve(2 * 4096);
 | 
			
		||||
  m_vtx_list[1].reserve(2 * 4096);
 | 
			
		||||
 | 
			
		||||
  li7_dvlb = DVLB_ParseFile((u32*)li7_shbin, li7_shbin_size);
 | 
			
		||||
  shaderProgramInit(&li7_shader);
 | 
			
		||||
  shaderProgramSetVsh(&li7_shader, &li7_dvlb->DVLE[0]);
 | 
			
		||||
  m_uLoc_proj =
 | 
			
		||||
      shaderInstanceGetUniformLocation(li7_shader.vertexShader, "projection");
 | 
			
		||||
 | 
			
		||||
  AttrInfo_Init(&li7_attr);
 | 
			
		||||
  AttrInfo_AddLoader(&li7_attr, 0, GPU_FLOAT, 3);
 | 
			
		||||
  AttrInfo_AddLoader(&li7_attr, 1, GPU_FLOAT, 2);
 | 
			
		||||
  AttrInfo_AddLoader(&li7_attr, 2, GPU_UNSIGNED_BYTE, 4);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LI7::Exit() {
 | 
			
		||||
  shaderProgramFree(&li7_shader);
 | 
			
		||||
  DVLB_Free(li7_dvlb);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LI7::OnScreen(bool bottom) {
 | 
			
		||||
    m_width = bottom ? 320 : 400;
 | 
			
		||||
    m_height = 240;
 | 
			
		||||
    m_bottom_active = bottom;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool LI7::CompareCommands(const LI7::Cmd &a,
 | 
			
		||||
                             const LI7::Cmd &b) {
 | 
			
		||||
  if (a.layer == b.layer)
 | 
			
		||||
    return a.tex < b.tex;
 | 
			
		||||
  return b.layer < a.layer;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LI7::RenderFrame(bool bottom) {
 | 
			
		||||
  m_rot += M_PI / 60.f;
 | 
			
		||||
  C3D_Mtx proj;
 | 
			
		||||
  Mtx_OrthoTilt(&proj, 0.f, (bottom ? 320 : 400), m_height, 0.f, 1.f, -1.f,
 | 
			
		||||
                false);
 | 
			
		||||
  C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, m_uLoc_proj, &proj);
 | 
			
		||||
 | 
			
		||||
  C3D_DepthTest(false, GPU_GREATER, GPU_WRITE_ALL);
 | 
			
		||||
 | 
			
		||||
  C3D_TexEnv *env = C3D_GetTexEnv(0);
 | 
			
		||||
  C3D_TexEnvInit(env);
 | 
			
		||||
  C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0, GPU_PRIMARY_COLOR, (GPU_TEVSRC)0);
 | 
			
		||||
  C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE);
 | 
			
		||||
 | 
			
		||||
  auto& active_list = m_vtx_list[bottom];
 | 
			
		||||
 | 
			
		||||
  int total_vertices = 0;
 | 
			
		||||
  m_d_drawcalls = 0;
 | 
			
		||||
  auto &draw_cmds = bottom ? m_bot_draw_cmds : m_top_draw_cmds;
 | 
			
		||||
  std::sort(draw_cmds.begin(), draw_cmds.end(), CompareCommands);
 | 
			
		||||
  m_d_commands = draw_cmds.size();
 | 
			
		||||
  size_t vtx = 0;
 | 
			
		||||
  while (draw_cmds.size() > 0) {
 | 
			
		||||
    C3D_Tex *texture = draw_cmds[draw_cmds.size() - 1].tex->Get();
 | 
			
		||||
    size_t start_vtx = vtx;
 | 
			
		||||
 | 
			
		||||
    while (draw_cmds.size() > 0 &&
 | 
			
		||||
           draw_cmds[draw_cmds.size() - 1].tex->Get() == texture) {
 | 
			
		||||
      auto c = draw_cmds[draw_cmds.size() - 1];
 | 
			
		||||
      if(c.cmd_type == 1) {
 | 
			
		||||
        active_list[vtx++] = Vtx{{c.ppos.x, c.ppos.y, 0}, {c.uv.x, c.uv.y}, c.clr};
 | 
			
		||||
        active_list[vtx++] = Vtx{{c.pszs.x, c.pszs.y, 0}, {c.uv.x, c.uv.w}, c.clr};
 | 
			
		||||
        active_list[vtx++] = Vtx{{c.apos.x, c.apos.y, 0}, {c.uv.z, c.uv.w}, c.clr};
 | 
			
		||||
      } else if (c.cmd_type == 2) {
 | 
			
		||||
        // TRI1
 | 
			
		||||
        active_list[vtx++] = Vtx{{c.ppos.x+c.pszs.x, c.ppos.y+c.pszs.y, 0}, {c.uv.z, c.uv.y}, c.clr};
 | 
			
		||||
        active_list[vtx++] = Vtx{{c.ppos.x+c.pszs.x, c.ppos.y, 0}, {c.uv.z, c.uv.w}, c.clr};
 | 
			
		||||
        active_list[vtx++] = Vtx{{c.ppos.x, c.ppos.y, 0}, {c.uv.x, c.uv.w}, c.clr};
 | 
			
		||||
        // TRI2
 | 
			
		||||
        active_list[vtx++] = Vtx{{c.ppos.x, c.ppos.y, 0}, {c.uv.x, c.uv.w}, c.clr};
 | 
			
		||||
        active_list[vtx++] = Vtx{{c.ppos.x, c.ppos.y+c.pszs.y, 0}, {c.uv.x, c.uv.y}, c.clr};
 | 
			
		||||
        active_list[vtx++] = Vtx{{c.ppos.x+c.pszs.x, c.ppos.y+c.pszs.y, 0}, {c.uv.z, c.uv.y}, c.clr};
 | 
			
		||||
      }
 | 
			
		||||
      draw_cmds.pop_back();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    C3D_TexBind(0, texture);
 | 
			
		||||
 | 
			
		||||
    C3D_BufInfo *bufinfo = C3D_GetBufInfo();
 | 
			
		||||
    BufInfo_Init(bufinfo);
 | 
			
		||||
    BufInfo_Add(bufinfo, active_list.data() + start_vtx, sizeof(Vtx), 3,
 | 
			
		||||
                0x210);
 | 
			
		||||
 | 
			
		||||
    C3D_DrawArrays(GPU_TRIANGLES, 0, vtx - start_vtx);
 | 
			
		||||
    m_d_drawcalls++;
 | 
			
		||||
    total_vertices += vtx - start_vtx;
 | 
			
		||||
  }
 | 
			
		||||
  C3D_DepthTest(true, GPU_GREATER, GPU_WRITE_ALL);
 | 
			
		||||
 | 
			
		||||
  m_d_vertices = total_vertices;
 | 
			
		||||
  m_current_texture = nullptr;
 | 
			
		||||
  m_scale = 1.f;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LI7::Render(C3D_RenderTarget* top, C3D_RenderTarget* bot) {
 | 
			
		||||
 C3D_BindProgram(&li7_shader);
 | 
			
		||||
 C3D_SetAttrInfo(&li7_attr);
 | 
			
		||||
 C3D_FrameDrawOn(top);
 | 
			
		||||
  RenderFrame(false);
 | 
			
		||||
  int d_tmp_cmds1 = m_d_commands;
 | 
			
		||||
  int d_tmp_dcls1 = m_d_drawcalls;
 | 
			
		||||
  int d_tmp_vtxs1 = m_d_vertices;
 | 
			
		||||
  C3D_FrameDrawOn(bot);
 | 
			
		||||
  RenderFrame(true);
 | 
			
		||||
  int d_tmp_cmds2 = m_d_commands;
 | 
			
		||||
  int d_tmp_dcls2 = m_d_drawcalls;
 | 
			
		||||
  int d_tmp_vtxs2 = m_d_vertices;
 | 
			
		||||
  m_d_commands = d_tmp_cmds1 + d_tmp_cmds2;
 | 
			
		||||
  m_d_drawcalls = d_tmp_dcls1 + d_tmp_dcls2;
 | 
			
		||||
  m_d_vertices = d_tmp_vtxs1 + d_tmp_vtxs2;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LI7::ColorRect(NVec2 pos, NVec2 szs, NVec4 uvs, unsigned int clr) {
 | 
			
		||||
    Cmd c;
 | 
			
		||||
    c.ppos = pos;
 | 
			
		||||
    c.pszs = szs;
 | 
			
		||||
    c.uv = uvs;
 | 
			
		||||
    c.clr = bs32(clr);
 | 
			
		||||
    c.tex = m_current_texture;
 | 
			
		||||
    c.cmd_type = 2;
 | 
			
		||||
    if(m_bottom_active) m_bot_draw_cmds.push_back(c);
 | 
			
		||||
    else m_top_draw_cmds.push_back(c);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LI7::ColorRect(NVec2 pos, NVec2 szs, unsigned int clr) {
 | 
			
		||||
    ColorRect(pos, szs, NVec4(0, 0, 1, 1), clr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LI7::Rect(NVec2 pos, NVec2 szs, NVec4 uvs) {
 | 
			
		||||
    ColorRect(pos, szs, uvs, 0xffffffff);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LI7::Rect(NVec2 pos, NVec2 szs) {
 | 
			
		||||
    ColorRect(pos, szs, NVec4(0, 0, 1, 1), 0xffffffff);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LI7::TexCutRect(NVec2 pos, NVec2 szs, NVec2 cb, NVec2 ce) {
 | 
			
		||||
  float u0 = (float)(cb.x / (float)m_current_texture->Get()->width);
 | 
			
		||||
  float v1 = (float)(((float)m_current_texture->Get()->height - cb.y) /
 | 
			
		||||
                     (float)m_current_texture->Get()->height);
 | 
			
		||||
  float u1 = (float)(ce.x / (float)m_current_texture->Get()->width);
 | 
			
		||||
  float v0 = (float)(((float)m_current_texture->Get()->height - ce.y) /
 | 
			
		||||
                     (float)m_current_texture->Get()->height);
 | 
			
		||||
  Rect(pos, szs, NVec4(u0, v0, u1, v1));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int LI7::DrawTextVargs(int x, int y, int z, unsigned int color, bool shadow,
 | 
			
		||||
                           int wrap, int* ySize, const char* fmt, va_list arg) {
 | 
			
		||||
  // FONT
 | 
			
		||||
  int len = vsnprintf(m_text_buffer.data(), m_text_buffer.size(), fmt, arg);
 | 
			
		||||
  m_text_buffer[len] = '\0';
 | 
			
		||||
  int offsetX = 0;
 | 
			
		||||
  int offsetY = 0;
 | 
			
		||||
  int maxWidth = 0;
 | 
			
		||||
  float cpm = m_dffs /1;// m_font->char_size;
 | 
			
		||||
 | 
			
		||||
  for (const auto &it : m_text_buffer) {
 | 
			
		||||
    if (it == '\0') break;
 | 
			
		||||
    bool implicitBreak = offsetX + 0/*m_font->fontWidth[(int)it]*/ >= wrap;
 | 
			
		||||
    if (it == '\n' || implicitBreak) {
 | 
			
		||||
      offsetY += /*m_font->char_size*/0 * cpm * m_scale;
 | 
			
		||||
      maxWidth = std::max(maxWidth, offsetX);
 | 
			
		||||
      offsetX = 0;
 | 
			
		||||
      if (implicitBreak) continue;
 | 
			
		||||
    } else if (it == '\t') {
 | 
			
		||||
      offsetX = ((offsetX / m_dffs) / 4 + 1) * 4 * m_dffs;
 | 
			
		||||
    } else {
 | 
			
		||||
      if (it != ' ') {
 | 
			
		||||
        int texX = (it % 16) * /*m_font->char_size*/0;
 | 
			
		||||
        int texY = (/*m_font->texture.tex.height*/0 - /*m_font->char_size*/0) -
 | 
			
		||||
                   (it / 16) * /*m_font->char_size*/0;
 | 
			
		||||
        ColorRect(NVec2(x + offsetX, y + offsetY), NVec2(m_dffs, m_dffs),
 | 
			
		||||
                      NVec4(static_cast<float>(texX) / /*m_font->texture.tex.width*/0,
 | 
			
		||||
                      static_cast<float>(texY) / /*m_font->texture.tex.height*/0,
 | 
			
		||||
                      (static_cast<float>(texX) + /*m_font->char_size*/0) /
 | 
			
		||||
                          /*m_font->texture.tex.width*/0,
 | 
			
		||||
                      (static_cast<float>(texY) + /*m_font->char_size*/0) /
 | 
			
		||||
                          /*m_font->texture.tex.height*/0),
 | 
			
		||||
                      color);
 | 
			
		||||
 | 
			
		||||
        if (shadow)
 | 
			
		||||
          ColorRect(NVec2(x + offsetX + 1, y + offsetY + 1), NVec2(m_dffs, m_dffs),
 | 
			
		||||
                        NVec4(static_cast<float>(texX) / /*m_font->texture.tex.width*/0,
 | 
			
		||||
                        static_cast<float>(texY) / /*m_font->texture.tex.height*/0,
 | 
			
		||||
                        (static_cast<float>(texX) + /*m_font->char_size*/0) /
 | 
			
		||||
                            /*m_font->texture.tex.width*/0,
 | 
			
		||||
                        (static_cast<float>(texY) + /*m_font->char_size*/0) /
 | 
			
		||||
                            /*m_font->texture.tex.height*/0),
 | 
			
		||||
                        RGBA8(10, 10, 10, 255));
 | 
			
		||||
      }
 | 
			
		||||
      offsetX += /*m_font->fontWidth[(int)it]*/0 * cpm * m_scale +
 | 
			
		||||
                 ((/*m_font->char_size*/0 * 0.2) * cpm * m_scale);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  maxWidth = std::max(maxWidth, offsetX);
 | 
			
		||||
 | 
			
		||||
  if (ySize != nullptr) *ySize = offsetY + /*m_font->char_size*/0;
 | 
			
		||||
  return maxWidth;
 | 
			
		||||
                           }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										44
									
								
								source/Logger.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								source/Logger.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,44 @@
 | 
			
		||||
#include <filesystem>
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <pd/Logger.hpp>
 | 
			
		||||
#include <pd/Time.hpp>
 | 
			
		||||
#include <pd/palladium.hpp>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
LoggerBase::~LoggerBase() {
 | 
			
		||||
  if (_log.is_open()) _log.close();
 | 
			
		||||
}
 | 
			
		||||
void LoggerBase::Init(const std::string& name, bool fileless) {
 | 
			
		||||
  if (!fileless) {
 | 
			
		||||
    std::string path_base = Palladium::GetAppDirectory() + "/logs/";
 | 
			
		||||
    if (!std::filesystem::is_directory(path_base)) {
 | 
			
		||||
      std::filesystem::create_directories(path_base);
 | 
			
		||||
    }
 | 
			
		||||
    auto ts = Palladium::GetTimeStr();
 | 
			
		||||
    std::string fn = name + ts + ".txt";
 | 
			
		||||
    this->filename = name;
 | 
			
		||||
    this->log_path = path_base + name;
 | 
			
		||||
    if (std::filesystem::exists(this->log_path)) {
 | 
			
		||||
      // Do nothing
 | 
			
		||||
    } else {
 | 
			
		||||
      _log.open(this->log_path, std::ios::out);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  this->Write("Palladium Log\n\n");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LoggerBase::Write(const std::string& debug_text, int lvl) {
 | 
			
		||||
  std::string msg = "[" + Palladium::GetTimeStr() + "]: " + debug_text;
 | 
			
		||||
  if (this->_log.is_open() && lvl <= writelvl) {
 | 
			
		||||
    this->_log << msg << std::endl;
 | 
			
		||||
  }
 | 
			
		||||
  /*while (msg.find_first_of('\n') != 0) {
 | 
			
		||||
    lines.push_back(msg.substr(0, msg.find_first_of('\n')));
 | 
			
		||||
    msg = msg.substr(msg.find_first_of('\n'));
 | 
			
		||||
  }*/
 | 
			
		||||
  lines.push_back(msg);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const std::vector<std::string>& LoggerBase::Lines() { return this->lines; }
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										56
									
								
								source/Memory.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								source/Memory.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,56 @@
 | 
			
		||||
#include <cstdlib>
 | 
			
		||||
#include <map>
 | 
			
		||||
#include <pd/Memory.hpp>
 | 
			
		||||
 | 
			
		||||
static Palladium::Memory::memory_metrics metrics;
 | 
			
		||||
 | 
			
		||||
bool pdi_enable_memtrack;
 | 
			
		||||
 | 
			
		||||
void *operator new(size_t size) {
 | 
			
		||||
  void *ptr = malloc(size);
 | 
			
		||||
  if (pdi_enable_memtrack) metrics.t_TotalAllocated += size;
 | 
			
		||||
  return ptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void operator delete(void *memory, size_t size) {
 | 
			
		||||
  if (pdi_enable_memtrack) metrics.t_TotalFreed += size;
 | 
			
		||||
  free(memory);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int allocations = 0;
 | 
			
		||||
int total_size = 0;
 | 
			
		||||
std::map<void *, size_t> sizes;
 | 
			
		||||
 | 
			
		||||
void *operator new[](size_t size) {
 | 
			
		||||
  void *ptr = malloc(size);
 | 
			
		||||
  if (pdi_enable_memtrack) {
 | 
			
		||||
    allocations++;
 | 
			
		||||
    total_size += size;
 | 
			
		||||
    sizes[ptr] = size;
 | 
			
		||||
    metrics.t_TotalAllocated += size;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return ptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void operator delete[](void *ptr) {
 | 
			
		||||
  if (pdi_enable_memtrack) {
 | 
			
		||||
    allocations--;
 | 
			
		||||
    total_size -= sizes[ptr];
 | 
			
		||||
    metrics.t_TotalFreed += sizes[ptr];
 | 
			
		||||
    sizes.erase(ptr);
 | 
			
		||||
  }
 | 
			
		||||
  free(ptr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
 | 
			
		||||
namespace Memory {
 | 
			
		||||
 | 
			
		||||
size_t GetTotalAllocated() { return metrics.t_TotalAllocated; }
 | 
			
		||||
 | 
			
		||||
size_t GetTotalFreed() { return metrics.t_TotalFreed; }
 | 
			
		||||
 | 
			
		||||
size_t GetCurrent() { return metrics.t_CurrentlyAllocated(); }
 | 
			
		||||
}  // namespace Memory
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										95
									
								
								source/Message.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								source/Message.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,95 @@
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <pd/Color.hpp>
 | 
			
		||||
#include <pd/Message.hpp>
 | 
			
		||||
#include <pd/palladium.hpp>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
extern bool pdi_debugging;
 | 
			
		||||
 | 
			
		||||
static std::vector<std::shared_ptr<Palladium::Message>> msg_lst;
 | 
			
		||||
static int fade_outs = 200;  // Start of fadeout
 | 
			
		||||
static int idles = 60;       // start of Idle
 | 
			
		||||
static int anim_len = 300;   // Full Length of Animation
 | 
			
		||||
 | 
			
		||||
NVec2 MakePos(int frame, int entry) {
 | 
			
		||||
  float fol = anim_len - fade_outs;
 | 
			
		||||
  if (frame > fade_outs)
 | 
			
		||||
    return NVec2(5, 240 - ((entry + 1) * 55) - 5 +
 | 
			
		||||
                         (float)((frame - fade_outs) / fol) * -20);
 | 
			
		||||
  if (frame > idles) return NVec2(5, 240 - ((entry + 1) * 55) - 5);
 | 
			
		||||
  return NVec2(-150 + ((float)(frame / (float)idles) * 155),
 | 
			
		||||
                240 - ((entry + 1) * 55) - 5);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
float GetDeltaTime();  // Extern from Palladium.cpp
 | 
			
		||||
 | 
			
		||||
void ProcessMessages() {
 | 
			
		||||
  float tmp_txt = R2::GetTextSize();
 | 
			
		||||
  R2::DefaultTextSize();
 | 
			
		||||
  // Draw in ovl mode
 | 
			
		||||
  R2::OnScreen(R2Screen_Top);
 | 
			
		||||
  float fol = anim_len - fade_outs;
 | 
			
		||||
  std::reverse(msg_lst.begin(), msg_lst.end());
 | 
			
		||||
  for (size_t i = 0; i < msg_lst.size(); i++) {
 | 
			
		||||
    NVec2 pos = MakePos(msg_lst[i]->animationframe, i);
 | 
			
		||||
    if ((pos.y + 150) < 0) {
 | 
			
		||||
      // Dont Render Out of Screen
 | 
			
		||||
      // And as thay aren't relevant anymore
 | 
			
		||||
      // Thay get deleted!
 | 
			
		||||
      msg_lst.erase(msg_lst.begin() + i);
 | 
			
		||||
    } else {
 | 
			
		||||
      int new_alpha = 200;
 | 
			
		||||
      if (msg_lst[i]->animationframe > fade_outs) {
 | 
			
		||||
        new_alpha =
 | 
			
		||||
            200 - (float(msg_lst[i]->animationframe - fade_outs) / fol) * 200;
 | 
			
		||||
      }
 | 
			
		||||
      // Wtf is this function lol
 | 
			
		||||
      auto bgc = Palladium::Color::RGBA(PDColor_MessageBackground)
 | 
			
		||||
                     .changeA(new_alpha)
 | 
			
		||||
                     .toRGBA();
 | 
			
		||||
      auto tc =
 | 
			
		||||
          Palladium::Color::RGBA(PDColor_Text2).changeA(new_alpha).toRGBA();
 | 
			
		||||
      R2::AddRect(pos, NVec2(150, 50), bgc);
 | 
			
		||||
      R2::AddText(pos + NVec2(5, 1), msg_lst[i]->title, tc);
 | 
			
		||||
      R2::AddText(pos + NVec2(5, 17), msg_lst[i]->message, tc);
 | 
			
		||||
      if (pdi_debugging)
 | 
			
		||||
        R2::AddText(pos + NVec2(155, 1),
 | 
			
		||||
                      std::to_string(msg_lst[i]->animationframe), tc);
 | 
			
		||||
      // Why Frameadd? because Message uses int as frame and
 | 
			
		||||
      // It seems that lower 0.5 will be rounded to 0
 | 
			
		||||
      // Why not replace int with float ?
 | 
			
		||||
      // cause of buggy positions (seen in Flappy Bird 3ds for example)
 | 
			
		||||
      float frameadd = 60.f * Palladium::GetDeltaTime();
 | 
			
		||||
      // 60fps animation * delta to not slowdown
 | 
			
		||||
      // Oh and fix for Startup lol
 | 
			
		||||
      // Todo: Only do this on AppStart
 | 
			
		||||
      if (msg_lst[i]->animationframe == 0) {
 | 
			
		||||
        msg_lst[i]->animationframe += 1;
 | 
			
		||||
      } else {
 | 
			
		||||
        msg_lst[i]->animationframe += (frameadd < 1.f ? 1.f : frameadd);
 | 
			
		||||
      }
 | 
			
		||||
      if (msg_lst[i]->animationframe > anim_len) {
 | 
			
		||||
        msg_lst.erase(msg_lst.begin() + i);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  // ReReverse ?? lol
 | 
			
		||||
  // Cause otherwise the Toasts will swap
 | 
			
		||||
  std::reverse(msg_lst.begin(), msg_lst.end());
 | 
			
		||||
  R2::SetTextSize(tmp_txt);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void PushMessage(const Message &msg) {
 | 
			
		||||
  msg_lst.push_back(std::make_shared<Palladium::Message>(msg));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SetMessageIdleStartFrame(int frame) { idles = frame; }
 | 
			
		||||
 | 
			
		||||
void SetMessageTotalAnimationFrames(int total_frames) {
 | 
			
		||||
  anim_len = total_frames;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SetMessageFadeOutStartFrame(int frame) { fade_outs = frame; }
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										245
									
								
								source/Net.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										245
									
								
								source/Net.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,245 @@
 | 
			
		||||
// TODO: Make Download2File faster on large files
 | 
			
		||||
 | 
			
		||||
#include <3ds.h>
 | 
			
		||||
#include <curl/curl.h>
 | 
			
		||||
#include <malloc.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
#include <filesystem>
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <regex>
 | 
			
		||||
#include <pd/Net.hpp>
 | 
			
		||||
#include <pd/internal_db.hpp>
 | 
			
		||||
 | 
			
		||||
static Palladium::Net::Error pdi_check_wifi() {
 | 
			
		||||
  // if (pdi_is_citra) return 0;
 | 
			
		||||
  int s = osGetWifiStrength();
 | 
			
		||||
  return (s == 0 ? Palladium::Net::Error_NoWifi : 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static size_t pdi_handle_data(char* ptr, size_t size, size_t nmemb,
 | 
			
		||||
                               void* userdata) {
 | 
			
		||||
  size_t ms = size * nmemb;
 | 
			
		||||
  ((std::string*)userdata)->append(ptr, ms);
 | 
			
		||||
  return ms;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static size_t pdi_handle_file(char* ptr, size_t size, size_t nmemb,
 | 
			
		||||
                               void* out) {
 | 
			
		||||
  size_t ms = size * nmemb;
 | 
			
		||||
  ((std::ofstream*)out)->write(reinterpret_cast<const char*>(ptr), ms);
 | 
			
		||||
  return ms;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct pdi_net_dl {
 | 
			
		||||
  unsigned long long current = 0;
 | 
			
		||||
  unsigned long long total = 1;
 | 
			
		||||
  void Reset() {
 | 
			
		||||
    current = 0;
 | 
			
		||||
    total = 1;
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static pdi_net_dl pdi_net_dl_spec;
 | 
			
		||||
 | 
			
		||||
static int pdi_handle_curl_progress(CURL* hnd, curl_off_t dltotal,
 | 
			
		||||
                                     curl_off_t dlnow, curl_off_t ultotal,
 | 
			
		||||
                                     curl_off_t ulnow) {
 | 
			
		||||
  pdi_net_dl_spec.total = dltotal;
 | 
			
		||||
  pdi_net_dl_spec.current = dlnow;
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void pdi_setup_curl_context(CURL* hnd, const std::string& url,
 | 
			
		||||
                                    void* userptr, bool mem) {
 | 
			
		||||
  std::string user_agent =
 | 
			
		||||
      pdi_app_name + "/Palladium (Version: " + std::string(PDVSTRING) +
 | 
			
		||||
      ")";
 | 
			
		||||
 | 
			
		||||
  if (!mem) {
 | 
			
		||||
    curl_easy_setopt(hnd, CURLOPT_FAILONERROR, 1L);
 | 
			
		||||
    curl_easy_setopt(hnd, CURLOPT_ACCEPT_ENCODING, "gzip");
 | 
			
		||||
    curl_easy_setopt(hnd, CURLOPT_XFERINFOFUNCTION, pdi_handle_curl_progress);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  curl_easy_setopt(hnd, CURLOPT_URL, url.c_str());
 | 
			
		||||
  curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 0L);
 | 
			
		||||
  curl_easy_setopt(hnd, CURLOPT_USERAGENT, user_agent.c_str());
 | 
			
		||||
  curl_easy_setopt(hnd, CURLOPT_WRITEDATA, userptr);
 | 
			
		||||
  curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L);
 | 
			
		||||
  curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
 | 
			
		||||
  curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2TLS);
 | 
			
		||||
  curl_easy_setopt(hnd, CURLOPT_WRITEFUNCTION,
 | 
			
		||||
                   mem ? pdi_handle_data : pdi_handle_file);
 | 
			
		||||
  curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L);
 | 
			
		||||
  curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
 | 
			
		||||
  curl_easy_setopt(hnd, CURLOPT_STDERR, stdout);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static bool pdi_curl_is_busy = false;
 | 
			
		||||
static bool pdi_apir_is_busy = false;
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
namespace Net {
 | 
			
		||||
Error Download(const std::string& url, std::string& data) {
 | 
			
		||||
  if (pdi_curl_is_busy) return Error_Busy;
 | 
			
		||||
  Error ret = pdi_check_wifi();
 | 
			
		||||
  if (ret != 0) {
 | 
			
		||||
    return ret;
 | 
			
		||||
  }
 | 
			
		||||
  pdi_curl_is_busy = true;
 | 
			
		||||
  pdi_net_dl_spec.Reset();
 | 
			
		||||
 | 
			
		||||
  auto hnd = curl_easy_init();
 | 
			
		||||
  pdi_setup_curl_context(hnd, url, &data, true);
 | 
			
		||||
 | 
			
		||||
  CURLcode curl_res = curl_easy_perform(hnd);
 | 
			
		||||
  curl_easy_cleanup(hnd);
 | 
			
		||||
 | 
			
		||||
  if (curl_res != CURLE_OK) {
 | 
			
		||||
    data.clear();
 | 
			
		||||
    pdi_curl_is_busy = false;
 | 
			
		||||
    return ((static_cast<Error>(curl_res) << 32) |
 | 
			
		||||
            static_cast<Error>(Error_Curl));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  pdi_curl_is_busy = false;
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Error Download2File(const std::string& url, const std::string& path) {
 | 
			
		||||
  if (pdi_curl_is_busy) return Error_Busy;
 | 
			
		||||
  Error ret = pdi_check_wifi();
 | 
			
		||||
  if (ret != 0) {
 | 
			
		||||
    return ret;
 | 
			
		||||
  }
 | 
			
		||||
  pdi_curl_is_busy = true;
 | 
			
		||||
  pdi_net_dl_spec.Reset();
 | 
			
		||||
  // std::filesystem::create_directories(
 | 
			
		||||
  // std::filesystem::path(path).remove_filename());
 | 
			
		||||
  std::ofstream file(path, std::ios::binary);
 | 
			
		||||
 | 
			
		||||
  if (!file.is_open()) {
 | 
			
		||||
    pdi_curl_is_busy = false;
 | 
			
		||||
    return Error_Write;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  auto hnd = curl_easy_init();
 | 
			
		||||
  pdi_setup_curl_context(hnd, url, &file, false);
 | 
			
		||||
 | 
			
		||||
  CURLcode curl_res = curl_easy_perform(hnd);
 | 
			
		||||
  curl_easy_cleanup(hnd);
 | 
			
		||||
 | 
			
		||||
  file.close();
 | 
			
		||||
  if (curl_res != CURLE_OK) {
 | 
			
		||||
    if (Palladium::FS::FileExist(path)) {
 | 
			
		||||
      std::filesystem::remove(path);
 | 
			
		||||
    }
 | 
			
		||||
    pdi_curl_is_busy = false;
 | 
			
		||||
    return ((static_cast<Error>(curl_res) << 32) |
 | 
			
		||||
            static_cast<Error>(Error_Curl));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  pdi_curl_is_busy = false;
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Error GitDownloadRelease(const std::string& url, const std::string& asset_name,
 | 
			
		||||
                         const std::string& path, bool prerelease) {
 | 
			
		||||
  if (pdi_apir_is_busy) return Error_Busy;
 | 
			
		||||
  Error ret = pdi_check_wifi();
 | 
			
		||||
  if (ret != 0) {
 | 
			
		||||
    return ret;
 | 
			
		||||
  }
 | 
			
		||||
  pdi_apir_is_busy = true;
 | 
			
		||||
  std::regex parse("github\\.com\\/(.+)\\/(.+)");
 | 
			
		||||
  std::smatch res;
 | 
			
		||||
  std::regex_search(url, res, parse);
 | 
			
		||||
 | 
			
		||||
  std::string user = res[1].str();
 | 
			
		||||
  std::string repo = res[2].str();
 | 
			
		||||
 | 
			
		||||
  std::stringstream req;
 | 
			
		||||
  req << "https://api.github.com/repos/" << user << "/" << repo
 | 
			
		||||
      << (prerelease ? "/releases" : "/releases/latest");
 | 
			
		||||
 | 
			
		||||
  std::string buf;
 | 
			
		||||
  ret = Download(req.str(), buf);
 | 
			
		||||
  if (ret) {
 | 
			
		||||
    pdi_apir_is_busy = false;
 | 
			
		||||
    return ret;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  int pret = 0;
 | 
			
		||||
  std::string freq;
 | 
			
		||||
  if (nlohmann::json::accept(buf)) {
 | 
			
		||||
    nlohmann::json api = nlohmann::json::parse(buf);
 | 
			
		||||
    if (!api.size()) pret = -1;
 | 
			
		||||
    if (pret != -1) {
 | 
			
		||||
      if (prerelease) api = api[0];
 | 
			
		||||
      if (api["assets"].is_array()) {
 | 
			
		||||
        for (const auto& asset : api["assets"]) {
 | 
			
		||||
          if (asset.is_object() && asset["name"].is_string() &&
 | 
			
		||||
              asset["browser_download_url"].is_string()) {
 | 
			
		||||
            if (std::regex_match(std::string(asset["name"]),
 | 
			
		||||
                                 std::regex(asset_name))) {
 | 
			
		||||
              freq = asset["browser_download_url"];
 | 
			
		||||
              break;
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  } else {
 | 
			
		||||
    pret = -1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (pret != 0 || freq.empty()) {
 | 
			
		||||
    pdi_apir_is_busy = false;
 | 
			
		||||
    return Error_Git;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ret = Download2File(freq, path);
 | 
			
		||||
  pdi_apir_is_busy = false;
 | 
			
		||||
  return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Error JsonApiRequest(const std::string& api_url, nlohmann::json& res) {
 | 
			
		||||
  if (pdi_apir_is_busy) return Error_Busy;
 | 
			
		||||
  Error ret = pdi_check_wifi();
 | 
			
		||||
  if (ret != 0) {
 | 
			
		||||
    return ret;
 | 
			
		||||
  }
 | 
			
		||||
  pdi_apir_is_busy = true;
 | 
			
		||||
 | 
			
		||||
  std::string buf;
 | 
			
		||||
  ret = Download(api_url, buf);
 | 
			
		||||
  if (ret) {
 | 
			
		||||
    pdi_apir_is_busy = false;
 | 
			
		||||
    return ret;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (nlohmann::json::accept(buf)) {
 | 
			
		||||
    res = nlohmann::json::parse(buf);
 | 
			
		||||
    if (!res.size()) {
 | 
			
		||||
      pdi_apir_is_busy = false;
 | 
			
		||||
      return Error_Invalid;
 | 
			
		||||
    }
 | 
			
		||||
  } else {
 | 
			
		||||
    pdi_apir_is_busy = false;
 | 
			
		||||
    return Error_Invalid;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  pdi_apir_is_busy = false;
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
unsigned long long GetProgressCurrent() { return pdi_net_dl_spec.current; }
 | 
			
		||||
unsigned long long GetProgressTotal() {
 | 
			
		||||
  // As curl sets total to 0 we need
 | 
			
		||||
  // to return a 1 as devide by zeroi will crash
 | 
			
		||||
  if (pdi_net_dl_spec.total <= 0) return 1;
 | 
			
		||||
  return pdi_net_dl_spec.total;
 | 
			
		||||
}
 | 
			
		||||
}  // namespace Net
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										497
									
								
								source/Overlays.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										497
									
								
								source/Overlays.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,497 @@
 | 
			
		||||
#include <pd/FunctionTrace.hpp>
 | 
			
		||||
#include <pd/Hid.hpp>
 | 
			
		||||
#include <pd/Overlays.hpp>
 | 
			
		||||
#include <pd/internal_db.hpp>
 | 
			
		||||
#include <pd/palladium.hpp>
 | 
			
		||||
 | 
			
		||||
///////////////////////////////
 | 
			
		||||
struct Key {
 | 
			
		||||
  std::string disp;
 | 
			
		||||
  NVec2 pos;
 | 
			
		||||
  NVec2 size;
 | 
			
		||||
  // 0 = default key
 | 
			
		||||
  // 1 = Shift
 | 
			
		||||
  // 2 = Backsp
 | 
			
		||||
  // 3 = Enter
 | 
			
		||||
  // 4 = Cancel
 | 
			
		||||
  // 5 = Confirm
 | 
			
		||||
  // 6 = Tab
 | 
			
		||||
  // 7 = Caps
 | 
			
		||||
  // 8 = Space
 | 
			
		||||
  int action = 0;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
std::vector<Key> keyboard_layout_num{
 | 
			
		||||
    // 1st row
 | 
			
		||||
    {"7", NVec2(5, 135), NVec2(36, 24), 0},
 | 
			
		||||
    {"8", NVec2(43, 135), NVec2(36, 24), 0},
 | 
			
		||||
    {"9", NVec2(81, 135), NVec2(36, 24), 0},
 | 
			
		||||
    // 2nd row
 | 
			
		||||
    {"4", NVec2(5, 161), NVec2(36, 24), 0},
 | 
			
		||||
    {"5", NVec2(43, 161), NVec2(36, 24), 0},
 | 
			
		||||
    {"6", NVec2(81, 161), NVec2(36, 24), 0},
 | 
			
		||||
    // 3rd row
 | 
			
		||||
    {"1", NVec2(5, 187), NVec2(36, 24), 0},
 | 
			
		||||
    {"2", NVec2(43, 187), NVec2(36, 24), 0},
 | 
			
		||||
    {"3", NVec2(81, 187), NVec2(36, 24), 0},
 | 
			
		||||
 | 
			
		||||
    // 4th row
 | 
			
		||||
    {"0", NVec2(5, 213), NVec2(74, 24), 0},
 | 
			
		||||
    {".", NVec2(81, 213), NVec2(36, 24), 0},
 | 
			
		||||
    // additional actions
 | 
			
		||||
    {"<---", NVec2(119, 135), NVec2(74, 24), 2},
 | 
			
		||||
    //{"", NVec2(119, 161), NVec2(74, 24), 0},
 | 
			
		||||
    {"Confirm", NVec2(119, 187), NVec2(74, 24), 5},
 | 
			
		||||
    {"Cancel", NVec2(119, 213), NVec2(74, 24), 4},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
std::vector<Key> keyboard_layout = {
 | 
			
		||||
    // 1st row
 | 
			
		||||
    {"`", NVec2(5, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"1", NVec2(25, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"2", NVec2(45, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"3", NVec2(65, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"4", NVec2(85, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"5", NVec2(105, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"6", NVec2(125, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"7", NVec2(145, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"8", NVec2(165, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"9", NVec2(185, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"0", NVec2(205, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"-", NVec2(225, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"=", NVec2(245, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"<---", NVec2(265, 137), NVec2(50, 18), 2},
 | 
			
		||||
    // 2nd row
 | 
			
		||||
    {"Tab", NVec2(5, 157), NVec2(40, 18), 6},
 | 
			
		||||
    {"q", NVec2(47, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"w", NVec2(67, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"e", NVec2(87, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"r", NVec2(107, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"t", NVec2(127, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"y", NVec2(147, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"u", NVec2(167, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"i", NVec2(187, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"o", NVec2(207, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"p", NVec2(227, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"[", NVec2(247, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"]", NVec2(267, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"\\", NVec2(287, 157), NVec2(28, 18), 0},
 | 
			
		||||
    // 3rd row
 | 
			
		||||
    {"Caps", NVec2(5, 177), NVec2(50, 18), 7},
 | 
			
		||||
    {"a", NVec2(57, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"s", NVec2(77, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"d", NVec2(97, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"f", NVec2(117, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"g", NVec2(137, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"h", NVec2(157, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"j", NVec2(177, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"k", NVec2(197, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"l", NVec2(217, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {";", NVec2(237, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"'", NVec2(257, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"Enter", NVec2(277, 177), NVec2(38, 18), 3},
 | 
			
		||||
    // 4th row
 | 
			
		||||
    {"Shift", NVec2(5, 197), NVec2(60, 18), 1},
 | 
			
		||||
    {"z", NVec2(67, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"x", NVec2(87, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"c", NVec2(107, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"v", NVec2(127, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"b", NVec2(147, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"n", NVec2(167, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"m", NVec2(187, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {",", NVec2(207, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {".", NVec2(227, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"/", NVec2(247, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"Shift", NVec2(267, 197), NVec2(48, 18), 1},
 | 
			
		||||
    // 5th row
 | 
			
		||||
    {"Cancel", NVec2(5, 217), NVec2(70, 18), 4},
 | 
			
		||||
    {"(X)", NVec2(77, 217), NVec2(23, 18), 10},
 | 
			
		||||
    {"Space", NVec2(102, 217), NVec2(108, 18), 8},
 | 
			
		||||
    {"(!)", NVec2(212, 217), NVec2(23, 18), 10},
 | 
			
		||||
    {"Confirm", NVec2(237, 217), NVec2(78, 18), 5},
 | 
			
		||||
    /*{"←", NVec2(237, 217), NVec2(18, 18)},
 | 
			
		||||
    {"→", NVec2(257, 217), NVec2(18, 18)},
 | 
			
		||||
    {"↓", NVec2(277, 217), NVec2(18, 18)},
 | 
			
		||||
    {"↑", NVec2(297, 217), NVec2(18, 18)},*/
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
std::vector<Key> keyboard_layout_caps = {
 | 
			
		||||
    // 1st row
 | 
			
		||||
    {"`", NVec2(5, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"1", NVec2(25, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"2", NVec2(45, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"3", NVec2(65, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"4", NVec2(85, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"5", NVec2(105, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"6", NVec2(125, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"7", NVec2(145, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"8", NVec2(165, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"9", NVec2(185, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"0", NVec2(205, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"-", NVec2(225, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"=", NVec2(245, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"<---", NVec2(265, 137), NVec2(50, 18), 2},
 | 
			
		||||
    // 2nd row
 | 
			
		||||
    {"Tab", NVec2(5, 157), NVec2(40, 18), 6},
 | 
			
		||||
    {"Q", NVec2(47, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"W", NVec2(67, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"E", NVec2(87, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"R", NVec2(107, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"T", NVec2(127, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"Y", NVec2(147, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"U", NVec2(167, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"I", NVec2(187, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"O", NVec2(207, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"P", NVec2(227, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"[", NVec2(247, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"]", NVec2(267, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"\\", NVec2(287, 157), NVec2(28, 18), 0},
 | 
			
		||||
    // 3rd row
 | 
			
		||||
    {"Caps", NVec2(5, 177), NVec2(50, 18), 7},
 | 
			
		||||
    {"A", NVec2(57, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"S", NVec2(77, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"D", NVec2(97, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"F", NVec2(117, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"G", NVec2(137, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"H", NVec2(157, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"J", NVec2(177, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"K", NVec2(197, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"L", NVec2(217, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {";", NVec2(237, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"'", NVec2(257, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"Enter", NVec2(277, 177), NVec2(38, 18), 3},
 | 
			
		||||
    // 4th row
 | 
			
		||||
    {"Shift", NVec2(5, 197), NVec2(60, 18), 1},
 | 
			
		||||
    {"Z", NVec2(67, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"X", NVec2(87, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"C", NVec2(107, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"V", NVec2(127, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"B", NVec2(147, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"N", NVec2(167, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"M", NVec2(187, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {",", NVec2(207, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {".", NVec2(227, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"/", NVec2(247, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"Shift", NVec2(267, 197), NVec2(48, 18), 1},
 | 
			
		||||
    // 5th row
 | 
			
		||||
    {"Cancel", NVec2(5, 217), NVec2(70, 18), 4},
 | 
			
		||||
    {"(X)", NVec2(77, 217), NVec2(23, 18), 10},
 | 
			
		||||
    {"Space", NVec2(102, 217), NVec2(108, 18), 8},
 | 
			
		||||
    {"(!)", NVec2(212, 217), NVec2(23, 18), 10},
 | 
			
		||||
    {"Confirm", NVec2(237, 217), NVec2(78, 18), 5},
 | 
			
		||||
    /*{"←", NVec2(237, 217), NVec2(18, 18)},
 | 
			
		||||
    {"→", NVec2(257, 217), NVec2(18, 18)},
 | 
			
		||||
    {"↑", NVec2(277, 217), NVec2(18, 18)},
 | 
			
		||||
    {"↓", NVec2(297, 217), NVec2(18, 18)},*/
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
std::vector<Key> keyboard_layout_shift = {
 | 
			
		||||
    // 1st row
 | 
			
		||||
    {"~", NVec2(5, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"!", NVec2(25, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"@", NVec2(45, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"#", NVec2(65, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"$", NVec2(85, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"%", NVec2(105, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"^", NVec2(125, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"&", NVec2(145, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"*", NVec2(165, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"(", NVec2(185, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {")", NVec2(205, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"_", NVec2(225, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"+", NVec2(245, 137), NVec2(18, 18), 0},
 | 
			
		||||
    {"<---", NVec2(265, 137), NVec2(50, 18), 2},
 | 
			
		||||
    // 2nd row
 | 
			
		||||
    {"Tab", NVec2(5, 157), NVec2(40, 18), 6},
 | 
			
		||||
    {"Q", NVec2(47, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"W", NVec2(67, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"E", NVec2(87, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"R", NVec2(107, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"T", NVec2(127, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"Y", NVec2(147, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"U", NVec2(167, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"I", NVec2(187, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"O", NVec2(207, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"P", NVec2(227, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"{", NVec2(247, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"}", NVec2(267, 157), NVec2(18, 18), 0},
 | 
			
		||||
    {"|", NVec2(287, 157), NVec2(28, 18), 0},
 | 
			
		||||
    // 3rd row
 | 
			
		||||
    {"Caps", NVec2(5, 177), NVec2(50, 18), 7},
 | 
			
		||||
    {"A", NVec2(57, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"S", NVec2(77, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"D", NVec2(97, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"F", NVec2(117, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"G", NVec2(137, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"H", NVec2(157, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"J", NVec2(177, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"K", NVec2(197, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"L", NVec2(217, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {":", NVec2(237, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"\"", NVec2(257, 177), NVec2(18, 18), 0},
 | 
			
		||||
    {"Enter", NVec2(277, 177), NVec2(38, 18), 3},
 | 
			
		||||
    // 4th row
 | 
			
		||||
    {"Shift", NVec2(5, 197), NVec2(60, 18), 1},
 | 
			
		||||
    {"Z", NVec2(67, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"X", NVec2(87, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"C", NVec2(107, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"V", NVec2(127, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"B", NVec2(147, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"N", NVec2(167, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"M", NVec2(187, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"<", NVec2(207, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {">", NVec2(227, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"?", NVec2(247, 197), NVec2(18, 18), 0},
 | 
			
		||||
    {"Shift", NVec2(267, 197), NVec2(48, 18), 1},
 | 
			
		||||
    // 5th row
 | 
			
		||||
    {"Cancel", NVec2(5, 217), NVec2(70, 18), 4},
 | 
			
		||||
    {"(X)", NVec2(77, 217), NVec2(23, 18), 10},
 | 
			
		||||
    {"Space", NVec2(102, 217), NVec2(108, 18), 8},
 | 
			
		||||
    {"(!)", NVec2(212, 217), NVec2(23, 18), 10},
 | 
			
		||||
    {"Confirm", NVec2(237, 217), NVec2(78, 18), 5},
 | 
			
		||||
    /*{"←", NVec2(237, 217), NVec2(18, 18)},
 | 
			
		||||
    {"→", NVec2(257, 217), NVec2(18, 18)},
 | 
			
		||||
    {"↑", NVec2(277, 217), NVec2(18, 18)},
 | 
			
		||||
    {"↓", NVec2(297, 217), NVec2(18, 18)},*/
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// From UI7
 | 
			
		||||
bool UI7_InBox(NVec2 inpos, NVec2 boxpos, NVec2 boxsize) {
 | 
			
		||||
  if ((inpos.x > boxpos.x) && (inpos.y > boxpos.y) &&
 | 
			
		||||
      (inpos.x < boxpos.x + boxsize.x) && (inpos.y < boxpos.y + boxsize.y))
 | 
			
		||||
    return true;
 | 
			
		||||
  return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
Ovl_Ftrace::Ovl_Ftrace(bool* is_enabled) { i_is_enabled = is_enabled; }
 | 
			
		||||
 | 
			
		||||
void Ovl_Ftrace::Draw(void) const {
 | 
			
		||||
  float tmp_txt = R2::GetTextSize();
 | 
			
		||||
  R2::DefaultTextSize();
 | 
			
		||||
  R2::OnScreen(R2Screen_Top);
 | 
			
		||||
  Palladium::Color::RGBA bg(PDColor_Background);
 | 
			
		||||
  bg.changeA(150);
 | 
			
		||||
  R2::AddRect(NVec2(0, 0), NVec2(400, 20), bg.toRGBA());
 | 
			
		||||
 | 
			
		||||
  std::vector<Palladium::Ftrace::FTRes> dt;
 | 
			
		||||
  for (auto const& it : Palladium::Ftrace::pd_traces)
 | 
			
		||||
    if (it.second.is_ovl && dt.size() < 10) dt.push_back(it.second);
 | 
			
		||||
  for (size_t i = 0; i < (dt.size() < 10 ? dt.size() : 10); i++) {
 | 
			
		||||
    R2::AddText(NVec2(5, 30 + i * 15), dt[i].func_name, PDColor_Text);
 | 
			
		||||
    R2::AddText(NVec2(295, 30 + i * 15), Palladium::MsTimeFmt(dt[i].time_of),
 | 
			
		||||
                  PDColor_Text);
 | 
			
		||||
  }
 | 
			
		||||
  R2::SetTextSize(tmp_txt);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Ovl_Ftrace::Logic() {
 | 
			
		||||
  if (!i_is_enabled[0]) this->Kill();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Ovl_Metrik::Ovl_Metrik(bool* is_enabled, bool* screen, uint32_t* mt_color,
 | 
			
		||||
                       uint32_t* txt_color, float* txt_size) {
 | 
			
		||||
  i_is_enabled = is_enabled;
 | 
			
		||||
  i_screen = screen;
 | 
			
		||||
  i_mt_color = mt_color;
 | 
			
		||||
  i_txt_color = txt_color;
 | 
			
		||||
  i_txt_size = txt_size;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Ovl_Metrik::Draw(void) const {
 | 
			
		||||
  float tmp_txt = R2::GetTextSize();
 | 
			
		||||
  R2::DefaultTextSize();
 | 
			
		||||
  R2::OnScreen(i_screen[0] ? R2Screen_Bottom : R2Screen_Top);
 | 
			
		||||
  std::string info =
 | 
			
		||||
      "Palladium " + std::string(PDVSTRING) + " Debug Overlay";
 | 
			
		||||
  float dim_y = R2::GetTextDimensions(info).y;
 | 
			
		||||
  float infoy = 240 - dim_y;
 | 
			
		||||
  mt_fps = "FPS: " + Palladium::GetFramerate();
 | 
			
		||||
  if (pdi_idb_running) mt_fps += " IDB -> ON";
 | 
			
		||||
  mt_cpu = "CPU: " +
 | 
			
		||||
           std::to_string(C3D_GetProcessingTime() * (Palladium::GetFps() / 10))
 | 
			
		||||
               .substr(0, 4) +
 | 
			
		||||
           "%/" + std::to_string(C3D_GetProcessingTime()).substr(0, 4) + "ms";
 | 
			
		||||
  mt_gpu = "GPU: " +
 | 
			
		||||
           std::to_string(C3D_GetDrawingTime() * (Palladium::GetFps() / 10))
 | 
			
		||||
               .substr(0, 4) +
 | 
			
		||||
           "%/" + std::to_string(C3D_GetDrawingTime()).substr(0, 4) + "ms";
 | 
			
		||||
  mt_cmd =
 | 
			
		||||
      "CMD: " + std::to_string(C3D_GetCmdBufUsage() * 100.0f).substr(0, 4) +
 | 
			
		||||
      "%";
 | 
			
		||||
  mt_lfr = "Linear: " + Palladium::FormatBytes(linearSpaceFree());
 | 
			
		||||
  mt_tbs =
 | 
			
		||||
      "TextBuf: " + std::to_string(C2D_TextBufGetNumGlyphs(pdi_text_buffer)) +
 | 
			
		||||
      "/4096";
 | 
			
		||||
  if (pdi_enable_memtrack)
 | 
			
		||||
    mt_mem = "Mem: " + Palladium::FormatBytes(Palladium::Memory::GetCurrent()) +
 | 
			
		||||
             " | " +
 | 
			
		||||
             Palladium::FormatBytes(Palladium::Memory::GetTotalAllocated()) +
 | 
			
		||||
             " | " + Palladium::FormatBytes(Palladium::Memory::GetTotalFreed());
 | 
			
		||||
  R2::AddRect(NVec2(0, 0), R2::GetTextDimensions(mt_fps),
 | 
			
		||||
                (unsigned int)i_mt_color[0]);
 | 
			
		||||
  R2::AddRect(NVec2(0, 50), R2::GetTextDimensions(mt_cpu),
 | 
			
		||||
                (unsigned int)i_mt_color[0]);
 | 
			
		||||
  R2::AddRect(NVec2(0, 50 + dim_y * 1), R2::GetTextDimensions(mt_gpu),
 | 
			
		||||
                (unsigned int)i_mt_color[0]);
 | 
			
		||||
  R2::AddRect(NVec2(0, 50 + dim_y * 2), R2::GetTextDimensions(mt_cmd),
 | 
			
		||||
                (unsigned int)i_mt_color[0]);
 | 
			
		||||
  R2::AddRect(NVec2(0, 50 + dim_y * 3), R2::GetTextDimensions(mt_lfr),
 | 
			
		||||
                (unsigned int)i_mt_color[0]);
 | 
			
		||||
  R2::AddRect(NVec2(0, 50 + dim_y * 4), R2::GetTextDimensions(mt_tbs),
 | 
			
		||||
                (unsigned int)i_mt_color[0]);
 | 
			
		||||
  if (pdi_enable_memtrack)
 | 
			
		||||
    R2::AddRect(NVec2(0, 50 + dim_y * 5), R2::GetTextDimensions(mt_mem),
 | 
			
		||||
                  (unsigned int)i_mt_color[0]);
 | 
			
		||||
  R2::AddRect(NVec2(0, infoy), R2::GetTextDimensions(info),
 | 
			
		||||
                (unsigned int)i_mt_color[0]);
 | 
			
		||||
  R2::AddText(NVec2(0, 0), mt_fps, (unsigned int)i_txt_color[0]);
 | 
			
		||||
  R2::AddText(NVec2(0, 50), mt_cpu, (unsigned int)i_txt_color[0]);
 | 
			
		||||
  R2::AddText(NVec2(0, 50 + dim_y * 1), mt_gpu,
 | 
			
		||||
                (unsigned int)i_txt_color[0]);
 | 
			
		||||
  R2::AddText(NVec2(0, 50 + dim_y * 2), mt_cmd,
 | 
			
		||||
                (unsigned int)i_txt_color[0]);
 | 
			
		||||
  R2::AddText(NVec2(0, 50 + dim_y * 3), mt_lfr,
 | 
			
		||||
                (unsigned int)i_txt_color[0]);
 | 
			
		||||
  R2::AddText(NVec2(0, 50 + dim_y * 4), mt_tbs,
 | 
			
		||||
                (unsigned int)i_txt_color[0]);
 | 
			
		||||
  if (pdi_enable_memtrack)
 | 
			
		||||
    R2::AddText(NVec2(0, 50 + dim_y * 5), mt_mem,
 | 
			
		||||
                  (unsigned int)i_txt_color[0]);
 | 
			
		||||
  R2::AddText(NVec2(0, infoy), info, (unsigned int)i_txt_color[0]);
 | 
			
		||||
 | 
			
		||||
  // Force Bottom (Debug Touchpos)
 | 
			
		||||
  R2::OnScreen(R2Screen_Bottom);
 | 
			
		||||
  if (Hid::IsEvent("touch", Hid::Held)) {
 | 
			
		||||
    R2::AddLine(NVec2(Hid::GetTouchPosition().x, 0),
 | 
			
		||||
                  NVec2(Hid::GetTouchPosition().x, 240),
 | 
			
		||||
                  Palladium::Color::Hex("#ff0000"));
 | 
			
		||||
    R2::AddLine(NVec2(0, Hid::GetTouchPosition().y),
 | 
			
		||||
                  NVec2(320, Hid::GetTouchPosition().y),
 | 
			
		||||
                  Palladium::Color::Hex("#ff0000"));
 | 
			
		||||
  }
 | 
			
		||||
  R2::SetTextSize(tmp_txt);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Ovl_Metrik::Logic() {
 | 
			
		||||
  if (!i_is_enabled[0]) this->Kill();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Ovl_Keyboard::Ovl_Keyboard(std::string& ref, PDKeyboardState& state,
 | 
			
		||||
                           const std::string& hint, PDKeyboard type) {
 | 
			
		||||
  // Blocks All Input outside of Keyboard
 | 
			
		||||
  // Doesnt work for Hidkeys down etc
 | 
			
		||||
  Palladium::Hid::Lock();
 | 
			
		||||
  typed_text = &ref;
 | 
			
		||||
  this->state = &state;
 | 
			
		||||
  this->type = type;
 | 
			
		||||
  *this->state = PDKeyboardState_None;
 | 
			
		||||
  str_bak = ref;
 | 
			
		||||
  ft3 = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Ovl_Keyboard::~Ovl_Keyboard() {
 | 
			
		||||
  // And Unlock when closing Keyboard lol
 | 
			
		||||
  Palladium::Hid::Unlock();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Ovl_Keyboard::Draw(void) const {
 | 
			
		||||
  float tmp_txt = R2::GetTextSize();
 | 
			
		||||
  R2::DefaultTextSize();
 | 
			
		||||
  if (ft3 > 5) Palladium::Hid::Unlock();
 | 
			
		||||
  auto key_table =
 | 
			
		||||
      (type == PDKeyboard_Numpad) ? keyboard_layout_num : keyboard_layout;
 | 
			
		||||
  if (mode == 1)
 | 
			
		||||
    key_table = keyboard_layout_caps;
 | 
			
		||||
  else if (mode == 2)
 | 
			
		||||
    key_table = keyboard_layout_shift;
 | 
			
		||||
  R2::OnScreen(R2Screen_Top);
 | 
			
		||||
  R2::AddRect(NVec2(0, 0), NVec2(400, 240),
 | 
			
		||||
                Palladium::Color::RGBA(PDColor_FrameBg).changeA(150).toRGBA());
 | 
			
		||||
  R2::OnScreen(R2Screen_Bottom);
 | 
			
		||||
  R2::AddRect(NVec2(0, 0), NVec2(320, 112),
 | 
			
		||||
                Palladium::Color::RGBA(PDColor_FrameBg).changeA(150).toRGBA());
 | 
			
		||||
  R2::AddRect(NVec2(0, 112), NVec2(320, 128), PDColor_FrameBg);
 | 
			
		||||
  R2::AddRect(NVec2(0, 112), NVec2(320, 20), PDColor_Header);
 | 
			
		||||
  R2::AddText(NVec2(5, 114), "> " + *typed_text,
 | 
			
		||||
                Palladium::ThemeActive()->AutoText(PDColor_Header));
 | 
			
		||||
  for (auto const& it : key_table) {
 | 
			
		||||
    NVec2 szs = it.size;
 | 
			
		||||
    NVec2 pos = it.pos;
 | 
			
		||||
    NVec2 txtdim = R2::GetTextDimensions(it.disp);
 | 
			
		||||
    PDColor btn = PDColor_Button;
 | 
			
		||||
    if (Palladium::Hid::IsEvent("cancel", Palladium::Hid::Up)) {
 | 
			
		||||
      Palladium::Hid::Clear();
 | 
			
		||||
      shared_data[0x05] = 1;
 | 
			
		||||
    }
 | 
			
		||||
    if (Palladium::Hid::IsEvent("touch", Palladium::Hid::Up) &&
 | 
			
		||||
        UI7_InBox(Palladium::Hid::GetLastTouchPosition(), pos, szs)) {
 | 
			
		||||
      if (mode == 2)  // Request Disable Shift
 | 
			
		||||
        shared_data[0x02] = 1;
 | 
			
		||||
 | 
			
		||||
      if (it.action == 0)
 | 
			
		||||
        shared_data[0x01] = it.disp[0];
 | 
			
		||||
      else if (it.action == 1)
 | 
			
		||||
        shared_data[0x02] = 1;
 | 
			
		||||
      else if (it.action == 2)
 | 
			
		||||
        shared_data[0x03] = 1;
 | 
			
		||||
      else if (it.action == 3)
 | 
			
		||||
        shared_data[0x04] = 1;
 | 
			
		||||
      else if (it.action == 4)
 | 
			
		||||
        shared_data[0x05] = 1;
 | 
			
		||||
      else if (it.action == 5)
 | 
			
		||||
        shared_data[0x06] = 1;
 | 
			
		||||
      else if (it.action == 6)
 | 
			
		||||
        shared_data[0x07] = 1;
 | 
			
		||||
      else if (it.action == 7)
 | 
			
		||||
        shared_data[0x08] = 1;
 | 
			
		||||
      else if (it.action == 8)
 | 
			
		||||
        shared_data[0x09] = 1;
 | 
			
		||||
    } else if (Palladium::Hid::IsEvent("touch", Palladium::Hid::Held) &&
 | 
			
		||||
               UI7_InBox(Palladium::Hid::GetTouchPosition(), it.pos, it.size)) {
 | 
			
		||||
      btn = PDColor_ButtonHovered;
 | 
			
		||||
      pos -= NVec2(1, 1);
 | 
			
		||||
      szs += NVec2(2, 2);
 | 
			
		||||
    }
 | 
			
		||||
    NVec2 txtpos = NVec2(pos.x + szs.x * 0.5 - txtdim.x * 0.5,
 | 
			
		||||
                           pos.y + szs.y * 0.5 - txtdim.y * 0.5);
 | 
			
		||||
    R2::AddRect(pos, szs, btn);
 | 
			
		||||
    R2::AddText(txtpos, it.disp, Palladium::ThemeActive()->AutoText(btn));
 | 
			
		||||
  }
 | 
			
		||||
  if (ft3 > 5) Palladium::Hid::Lock();
 | 
			
		||||
  R2::SetTextSize(tmp_txt);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Ovl_Keyboard::Logic() {
 | 
			
		||||
  ft3++;
 | 
			
		||||
  for (const auto& it : shared_data) {
 | 
			
		||||
    if (it.first == 0x01) {
 | 
			
		||||
      typed_text->push_back(it.second);
 | 
			
		||||
    } else if (it.first == 0x02) {
 | 
			
		||||
      // Shift
 | 
			
		||||
      mode = (mode == 2) ? 0 : 2;
 | 
			
		||||
    } else if (it.first == 0x03) {
 | 
			
		||||
      if (typed_text->length() >= 1)
 | 
			
		||||
        typed_text->erase(typed_text->begin() + typed_text->length() - 1);
 | 
			
		||||
    } else if (it.first == 0x04) {
 | 
			
		||||
      // Enter
 | 
			
		||||
    } else if (it.first == 0x05) {
 | 
			
		||||
      *typed_text = str_bak;
 | 
			
		||||
      *state = PDKeyboardState_Cancel;
 | 
			
		||||
      this->Kill();
 | 
			
		||||
    } else if (it.first == 0x06) {
 | 
			
		||||
      *state = PDKeyboardState_Confirm;
 | 
			
		||||
      this->Kill();
 | 
			
		||||
    } else if (it.first == 0x07) {
 | 
			
		||||
      // this->typed_text += '\t';  // Tab
 | 
			
		||||
    } else if (it.first == 0x08) {
 | 
			
		||||
      // Caps
 | 
			
		||||
      mode = (mode == 1) ? 0 : 1;
 | 
			
		||||
    } else if (it.first == 0x09) {
 | 
			
		||||
      typed_text->append(" ");  // Space
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  shared_data.clear();
 | 
			
		||||
}
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										378
									
								
								source/Render2.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										378
									
								
								source/Render2.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,378 @@
 | 
			
		||||
#include <citro2d.h>
 | 
			
		||||
 | 
			
		||||
#include <pd/Render2.hpp>
 | 
			
		||||
#include <pd/internal_db.hpp>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
const float R2::default_text_size = 0.5f;
 | 
			
		||||
float R2::text_size = 0.5;
 | 
			
		||||
Font::Ref R2::font;
 | 
			
		||||
std::map<std::string, float> R2::ts;
 | 
			
		||||
std::map<std::string, int> R2::mln;
 | 
			
		||||
bool R2::next_lined = false;
 | 
			
		||||
std::vector<R2::R2Cmd::Ref> R2::commands;
 | 
			
		||||
R2Screen R2::current_screen = R2Screen_Bottom;
 | 
			
		||||
 | 
			
		||||
void R2::Init() { R2::font = Font::New(); }
 | 
			
		||||
 | 
			
		||||
void R2::SetFont(Font::Ref fnt) {
 | 
			
		||||
  if (!fnt) return;
 | 
			
		||||
  R2::font = fnt;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Font::Ref R2::GetFont() { return R2::font; }
 | 
			
		||||
 | 
			
		||||
void R2::DefaultFont() { R2::font->Unload(); }
 | 
			
		||||
 | 
			
		||||
void R2::DrawNextLined() { R2::next_lined = true; }
 | 
			
		||||
 | 
			
		||||
void R2::OnScreen(R2Screen screen) {
 | 
			
		||||
  if (screen < 0 || screen > R2Screen_Top) return;
 | 
			
		||||
  R2::current_screen = screen;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void R2::SetTextSize(float szs) { text_size = szs; }
 | 
			
		||||
 | 
			
		||||
void R2::DefaultTextSize() { text_size = R2::default_text_size; }
 | 
			
		||||
 | 
			
		||||
float R2::GetTextSize() { return text_size; }
 | 
			
		||||
 | 
			
		||||
R2Screen R2::GetCurrentScreen() { return current_screen; }
 | 
			
		||||
 | 
			
		||||
NVec2 R2::GetTextDimensions(const std::string& text) {
 | 
			
		||||
  C2D_TextBufClear(pdi_d2_dimbuf);
 | 
			
		||||
  float w = 0, h = 0;
 | 
			
		||||
  C2D_Text c2dtext;
 | 
			
		||||
  C2D_TextFontParse(&c2dtext, font->Ptr(), pdi_d2_dimbuf, text.c_str());
 | 
			
		||||
  C2D_TextGetDimensions(&c2dtext, R2::text_size, R2::text_size, &w, &h);
 | 
			
		||||
  return NVec2(w, h);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string R2::WrapText(const std ::string& in, int maxlen) {
 | 
			
		||||
  std::string out;
 | 
			
		||||
  std::string line;
 | 
			
		||||
  int line_x = 0;
 | 
			
		||||
  std::istringstream istream(in);
 | 
			
		||||
  std::string temp;
 | 
			
		||||
 | 
			
		||||
  while (istream >> temp) {
 | 
			
		||||
    NVec2 dim = R2::GetTextDimensions(line + temp);
 | 
			
		||||
    if (line_x + dim.x <= maxlen) {
 | 
			
		||||
      line += temp + ' ';
 | 
			
		||||
      line_x += dim.x;
 | 
			
		||||
    } else {
 | 
			
		||||
      out += line + '\n';
 | 
			
		||||
      line = temp + ' ';
 | 
			
		||||
      line_x = dim.x;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  out += line;
 | 
			
		||||
  return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string R2::ShortText(const std::string& in, int maxlen) {
 | 
			
		||||
  auto textdim = R2::GetTextDimensions(in);
 | 
			
		||||
  if (textdim.x < (float)maxlen) return in;
 | 
			
		||||
  std::string ft = "";
 | 
			
		||||
  std::string worker = in;
 | 
			
		||||
  if (in.find_last_of('.') != in.npos) {
 | 
			
		||||
    ft = in.substr(in.find_last_of('.'));
 | 
			
		||||
    worker = in.substr(0, in.find_last_of('.'));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  maxlen -= R2::GetTextDimensions(ft).x - R2::GetTextDimensions("(...)").x;
 | 
			
		||||
  float len_mod = (float)maxlen / textdim.x;
 | 
			
		||||
  int pos = (in.length() * len_mod) / pd_draw2_tsm;
 | 
			
		||||
  std::string out;
 | 
			
		||||
 | 
			
		||||
  out = in.substr(0, pos);
 | 
			
		||||
 | 
			
		||||
  for (size_t i = pos; i < worker.length(); i++) {
 | 
			
		||||
    out += worker[i];
 | 
			
		||||
    if (R2::GetTextDimensions(out + "(...)" + ft).x > (float)maxlen) {
 | 
			
		||||
      out += "(...)";
 | 
			
		||||
      out += ft;
 | 
			
		||||
      return out;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return out;  // Impossible to reach
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
NVec2 R2::GetCurrentScreenSize() {
 | 
			
		||||
  return NVec2(R2::current_screen == R2Screen_Bottom ? 320 : 400, 240);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Main Processing of Draw Calls
 | 
			
		||||
void R2::Process() {
 | 
			
		||||
  for (auto& it : R2::commands) {
 | 
			
		||||
    if (it->type <= 0 || it->type > 6) {
 | 
			
		||||
      // Skip
 | 
			
		||||
      continue;
 | 
			
		||||
    }
 | 
			
		||||
    C2D_SceneBegin(it->Screen ? pd_top : pd_bottom);
 | 
			
		||||
    if (it->type == 1) {
 | 
			
		||||
      // Rect
 | 
			
		||||
      if (it->lined) {
 | 
			
		||||
        C2D_DrawLine(it->pos.x, it->pos.y, it->clr, it->pos.x + it->pszs.x,
 | 
			
		||||
                     it->pos.y, it->clr, 1.f, 0.5f);
 | 
			
		||||
        C2D_DrawLine(it->pos.x, it->pos.y, it->clr, it->pos.x,
 | 
			
		||||
                     it->pos.y + it->pszs.y, it->clr, 1.f, 0.5f);
 | 
			
		||||
        C2D_DrawLine(it->pos.x + it->pszs.x, it->pos.y, it->clr,
 | 
			
		||||
                     it->pos.x + it->pszs.x, it->pos.y + it->pszs.y, it->clr,
 | 
			
		||||
                     1.f, 0.5f);
 | 
			
		||||
        C2D_DrawLine(it->pos.x, it->pos.y + it->pszs.y, it->clr,
 | 
			
		||||
                     it->pos.x + it->pszs.x, it->pos.y + it->pszs.y, it->clr,
 | 
			
		||||
                     1.f, 0.5f);
 | 
			
		||||
      } else {
 | 
			
		||||
        C2D_DrawRectSolid(it->pos.x, it->pos.y, 0.5, it->pszs.x, it->pszs.y,
 | 
			
		||||
                          it->clr);
 | 
			
		||||
      }
 | 
			
		||||
    } else if (it->type == 2) {
 | 
			
		||||
      // Triangle
 | 
			
		||||
      if (it->lined) {
 | 
			
		||||
        C2D_DrawLine(it->pos.x, it->pos.y, it->clr, it->pszs.x, it->pszs.y,
 | 
			
		||||
                     it->clr, 1, 0.5f);
 | 
			
		||||
        C2D_DrawLine(it->pos.x, it->pos.y, it->clr, it->ap.x, it->ap.y, it->clr,
 | 
			
		||||
                     1, 0.5f);
 | 
			
		||||
        C2D_DrawLine(it->pszs.x, it->pszs.y, it->clr, it->ap.x, it->ap.y,
 | 
			
		||||
                     it->clr, 1, 0.5f);
 | 
			
		||||
      } else {
 | 
			
		||||
        C2D_DrawTriangle(it->pos.x, it->pos.y, it->clr, it->pszs.x, it->pszs.y,
 | 
			
		||||
                         it->clr, it->ap.x, it->ap.y, it->clr, 0.5);
 | 
			
		||||
      }
 | 
			
		||||
    } else if (it->type == 3) {
 | 
			
		||||
      // Text
 | 
			
		||||
      // little patch for a freeze
 | 
			
		||||
      if (it->text.length() < 1) continue;
 | 
			
		||||
      if (it->pszs.x == 0.0f) {
 | 
			
		||||
        it->pszs.x = it->Screen == R2Screen_Top ? 400 : 320;
 | 
			
		||||
      }
 | 
			
		||||
      if (it->pszs.y == 0.0f) {
 | 
			
		||||
        it->pszs.y = 240;
 | 
			
		||||
      }
 | 
			
		||||
      std::string edit_text = it->text;
 | 
			
		||||
      if (edit_text.substr(it->text.length() - 1) != "\n")
 | 
			
		||||
        edit_text.append("\n");  // Add \n to end if not exist
 | 
			
		||||
      int line = 0;
 | 
			
		||||
 | 
			
		||||
      if (it->flags & PDTextFlags_Wrap) {
 | 
			
		||||
        edit_text = WrapText(it->text, it->pszs.x - it->pos.x);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      while (edit_text.find('\n') != edit_text.npos) {
 | 
			
		||||
        std::string current_line = edit_text.substr(0, edit_text.find('\n'));
 | 
			
		||||
        if (it->flags & PDTextFlags_Short)
 | 
			
		||||
          current_line = R2::ShortText(current_line, it->pszs.x - it->pos.x);
 | 
			
		||||
        NVec2 newpos = it->pos;
 | 
			
		||||
        // Check Flags
 | 
			
		||||
        NVec2 dim = R2::GetTextDimensions(current_line);
 | 
			
		||||
        if (it->flags & PDTextFlags_AlignRight) newpos.x = newpos.x - dim.x;
 | 
			
		||||
        if (it->flags & PDTextFlags_AlignMid)  // Offset by inpos
 | 
			
		||||
          newpos.x = (it->pszs.x * 0.5) - (dim.x * 0.5) + it->pos.x;
 | 
			
		||||
        if (it->flags & PDTextFlags_Scroll) {  // Scroll Text
 | 
			
		||||
          // Look into Old Draw2 Code
 | 
			
		||||
          // TODO: Create Code for this
 | 
			
		||||
        }
 | 
			
		||||
        if (pdi_debugging) {
 | 
			
		||||
          R2::DrawNextLined();
 | 
			
		||||
          R2::AddRect(newpos, dim, 0xff0000ff);
 | 
			
		||||
        }
 | 
			
		||||
        C2D_Text c2dtext;
 | 
			
		||||
        C2D_TextFontParse(&c2dtext, font->Ptr(), pdi_text_buffer,
 | 
			
		||||
                          current_line.c_str());
 | 
			
		||||
        C2D_TextOptimize(&c2dtext);
 | 
			
		||||
 | 
			
		||||
        if (it->flags & PDTextFlags_Shaddow)  // performance Killer xd
 | 
			
		||||
          C2D_DrawText(&c2dtext, C2D_WithColor, newpos.x + 1 + (dim.y * line),
 | 
			
		||||
                       newpos.y + 1, 0.5, R2::text_size, R2::text_size,
 | 
			
		||||
                       Palladium::ThemeActive()->Get(PDColor_TextDisabled));
 | 
			
		||||
 | 
			
		||||
        C2D_DrawText(&c2dtext, C2D_WithColor, newpos.x,
 | 
			
		||||
                     newpos.y + (dim.y * line), 0.5, R2::text_size,
 | 
			
		||||
                     R2::text_size, it->clr);
 | 
			
		||||
        edit_text = edit_text.substr(edit_text.find('\n') + 1);
 | 
			
		||||
        line++;
 | 
			
		||||
      }
 | 
			
		||||
    } else if (it->type == 4) {
 | 
			
		||||
      if (it->img->Loadet()) {
 | 
			
		||||
        C2D_DrawImageAt(it->img->Get(), it->pos.x, it->pos.y, 0.5f);
 | 
			
		||||
      }
 | 
			
		||||
    } else if (it->type == 5) {
 | 
			
		||||
      // TODO: Move the Draw Func into this API
 | 
			
		||||
      it->spr->Draw();
 | 
			
		||||
    } else if (it->type == 6) {
 | 
			
		||||
      C2D_DrawLine(it->pos.x, it->pos.y, it->clr, it->pszs.x, it->pszs.y,
 | 
			
		||||
                   it->clr, it->ap.x, 0.5f);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  R2::commands.clear();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void R2::AddRect(NVec2 pos, NVec2 size, PDColor clr) {
 | 
			
		||||
  auto cmd = R2Cmd::New();
 | 
			
		||||
  cmd->pos = pos;
 | 
			
		||||
  cmd->pszs = size;
 | 
			
		||||
  cmd->clr = Palladium::ThemeActive()->Get(clr);
 | 
			
		||||
  cmd->type = 1;  // Rect
 | 
			
		||||
  // Just assign current screen as bottom is 0 (false)
 | 
			
		||||
  // and Top and TopRight are !0 (true)
 | 
			
		||||
  cmd->Screen = current_screen;
 | 
			
		||||
  if (R2::next_lined) {
 | 
			
		||||
    cmd->lined = true;
 | 
			
		||||
    R2::next_lined = false;
 | 
			
		||||
  }
 | 
			
		||||
  R2::commands.push_back(cmd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void R2::AddRect(NVec2 pos, NVec2 size, unsigned int clr) {
 | 
			
		||||
  auto cmd = R2Cmd::New();
 | 
			
		||||
  cmd->pos = pos;
 | 
			
		||||
  cmd->pszs = size;
 | 
			
		||||
  cmd->clr = clr;
 | 
			
		||||
  cmd->type = 1;  // Rect
 | 
			
		||||
  // Just assign current screen as bottom is 0 (false)
 | 
			
		||||
  // and Top and TopRight are !0 (true)
 | 
			
		||||
  cmd->Screen = current_screen;
 | 
			
		||||
  if (R2::next_lined) {
 | 
			
		||||
    cmd->lined = true;
 | 
			
		||||
    R2::next_lined = false;
 | 
			
		||||
  }
 | 
			
		||||
  R2::commands.push_back(cmd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void R2::AddLine(NVec2 pos_a, NVec2 pos_b, PDColor clr, int t) {
 | 
			
		||||
  auto cmd = R2Cmd::New();
 | 
			
		||||
  cmd->pos = pos_a;
 | 
			
		||||
  cmd->pszs = pos_b;
 | 
			
		||||
  cmd->ap.x = t;
 | 
			
		||||
  cmd->clr = Palladium::ThemeActive()->Get(clr);
 | 
			
		||||
  cmd->type = 6;  // Line
 | 
			
		||||
  // Just assign current screen as bottom is 0 (false)
 | 
			
		||||
  // and Top and TopRight are !0 (true)
 | 
			
		||||
  cmd->Screen = current_screen;
 | 
			
		||||
  if (R2::next_lined) {
 | 
			
		||||
    cmd->lined = true;
 | 
			
		||||
    R2::next_lined = false;
 | 
			
		||||
  }
 | 
			
		||||
  R2::commands.push_back(cmd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void R2::AddLine(NVec2 pos_a, NVec2 pos_b, unsigned int clr, int t) {
 | 
			
		||||
  auto cmd = R2Cmd::New();
 | 
			
		||||
  cmd->pos = pos_a;
 | 
			
		||||
  cmd->pszs = pos_b;
 | 
			
		||||
  cmd->ap.x = t;
 | 
			
		||||
  cmd->clr = clr;
 | 
			
		||||
  cmd->type = 6;  // Line
 | 
			
		||||
  // Just assign current screen as bottom is 0 (false)
 | 
			
		||||
  // and Top and TopRight are !0 (true)
 | 
			
		||||
  cmd->Screen = current_screen;
 | 
			
		||||
  if (R2::next_lined) {
 | 
			
		||||
    cmd->lined = true;
 | 
			
		||||
    R2::next_lined = false;
 | 
			
		||||
  }
 | 
			
		||||
  R2::commands.push_back(cmd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void R2::AddTriangle(NVec2 pos0, NVec2 pos1, NVec2 pos2, PDColor clr) {
 | 
			
		||||
  auto cmd = R2Cmd::New();
 | 
			
		||||
  cmd->pos = pos0;
 | 
			
		||||
  cmd->pszs = pos1;
 | 
			
		||||
  cmd->ap = pos2;
 | 
			
		||||
  cmd->clr = Palladium::ThemeActive()->Get(clr);
 | 
			
		||||
  cmd->type = 2;  // Triangle
 | 
			
		||||
  // Just assign current screen as bottom is 0 (false)
 | 
			
		||||
  // and Top and TopRight are !0 (true)
 | 
			
		||||
  cmd->Screen = current_screen;
 | 
			
		||||
  if (R2::next_lined) {
 | 
			
		||||
    cmd->lined = true;
 | 
			
		||||
    R2::next_lined = false;
 | 
			
		||||
  }
 | 
			
		||||
  R2::commands.push_back(cmd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void R2::AddTriangle(NVec2 pos0, NVec2 pos1, NVec2 pos2, unsigned int clr) {
 | 
			
		||||
  auto cmd = R2Cmd::New();
 | 
			
		||||
  cmd->pos = pos0;
 | 
			
		||||
  cmd->pszs = pos1;
 | 
			
		||||
  cmd->ap = pos2;
 | 
			
		||||
  cmd->clr = clr;
 | 
			
		||||
  cmd->type = 2;  // Triangle
 | 
			
		||||
  // Just assign current screen as bottom is 0 (false)
 | 
			
		||||
  // and Top and TopRight are !0 (true)
 | 
			
		||||
  cmd->Screen = current_screen;
 | 
			
		||||
  if (R2::next_lined) {
 | 
			
		||||
    cmd->lined = true;
 | 
			
		||||
    R2::next_lined = false;
 | 
			
		||||
  }
 | 
			
		||||
  R2::commands.push_back(cmd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void R2::AddText(NVec2 pos, const std::string& text, PDColor clr,
 | 
			
		||||
                 PDTextFlags flags, NVec2 tmb) {
 | 
			
		||||
  auto cmd = R2Cmd::New();
 | 
			
		||||
  cmd->pos = pos;
 | 
			
		||||
  cmd->pszs = tmb;
 | 
			
		||||
  cmd->clr = Palladium::ThemeActive()->Get(clr);
 | 
			
		||||
  cmd->flags = flags;
 | 
			
		||||
  cmd->text = text;
 | 
			
		||||
  cmd->type = 3;  // Text
 | 
			
		||||
  // Just assign current screen as bottom is 0 (false)
 | 
			
		||||
  // and Top and TopRight are !0 (true)
 | 
			
		||||
  cmd->Screen = current_screen;
 | 
			
		||||
  if (R2::next_lined) {
 | 
			
		||||
    cmd->lined = true;
 | 
			
		||||
    R2::next_lined = false;
 | 
			
		||||
  }
 | 
			
		||||
  R2::commands.push_back(cmd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void R2::AddText(NVec2 pos, const std::string& text, unsigned int clr,
 | 
			
		||||
                 PDTextFlags flags, NVec2 tmb) {
 | 
			
		||||
  auto cmd = R2Cmd::New();
 | 
			
		||||
  cmd->pos = pos;
 | 
			
		||||
  cmd->pszs = tmb;
 | 
			
		||||
  cmd->clr = clr;
 | 
			
		||||
  cmd->flags = flags;
 | 
			
		||||
  cmd->text = text;
 | 
			
		||||
  cmd->type = 3;  // Text
 | 
			
		||||
  // Just assign current screen as bottom is 0 (false)
 | 
			
		||||
  // and Top and TopRight are !0 (true)
 | 
			
		||||
  cmd->Screen = current_screen;
 | 
			
		||||
  if (R2::next_lined) {
 | 
			
		||||
    cmd->lined = true;
 | 
			
		||||
    R2::next_lined = false;
 | 
			
		||||
  }
 | 
			
		||||
  R2::commands.push_back(cmd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void R2::AddImage(NVec2 pos, Image::Ref img) {
 | 
			
		||||
  auto cmd = R2Cmd::New();
 | 
			
		||||
  cmd->pos = pos;
 | 
			
		||||
  cmd->img = img;
 | 
			
		||||
  cmd->type = 4;  // Image
 | 
			
		||||
  // Just assign current screen as bottom is 0 (false)
 | 
			
		||||
  // and Top and TopRight are !0 (true)
 | 
			
		||||
  cmd->Screen = current_screen;
 | 
			
		||||
  if (R2::next_lined) {
 | 
			
		||||
    cmd->lined = true;
 | 
			
		||||
    R2::next_lined = false;
 | 
			
		||||
  }
 | 
			
		||||
  R2::commands.push_back(cmd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void R2::AddSprite(Sprite::Ref spr) {
 | 
			
		||||
  auto cmd = R2Cmd::New();
 | 
			
		||||
  cmd->spr = spr;
 | 
			
		||||
  cmd->type = 5;  // Sprite
 | 
			
		||||
  // Just assign current screen as bottom is 0 (false)
 | 
			
		||||
  // and Top and TopRight are !0 (true)
 | 
			
		||||
  cmd->Screen = current_screen;
 | 
			
		||||
  if (R2::next_lined) {
 | 
			
		||||
    cmd->lined = true;
 | 
			
		||||
    R2::next_lined = false;
 | 
			
		||||
  }
 | 
			
		||||
  R2::commands.push_back(cmd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										460
									
								
								source/ResultDecoder.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										460
									
								
								source/ResultDecoder.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,460 @@
 | 
			
		||||
#include <filesystem>
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <map>
 | 
			
		||||
#include <pd/ResultDecoder.hpp>
 | 
			
		||||
#include <pd/internal_db.hpp>
 | 
			
		||||
#include <sstream>
 | 
			
		||||
 | 
			
		||||
static std::map<int, std::string> modules = {
 | 
			
		||||
    {0, "common"},
 | 
			
		||||
    {1, "kernel"},
 | 
			
		||||
    {2, "util"},
 | 
			
		||||
    {3, "file server"},
 | 
			
		||||
    {4, "loader server"},
 | 
			
		||||
    {5, "tcb"},
 | 
			
		||||
    {6, "os"},
 | 
			
		||||
    {7, "dbg"},
 | 
			
		||||
    {8, "dmnt"},
 | 
			
		||||
    {9, "pdn"},
 | 
			
		||||
    {10, "gsp"},
 | 
			
		||||
    {11, "i2c"},
 | 
			
		||||
    {12, "gpio"},
 | 
			
		||||
    {13, "dd"},
 | 
			
		||||
    {14, "codec"},
 | 
			
		||||
    {15, "spi"},
 | 
			
		||||
    {16, "pxi"},
 | 
			
		||||
    {17, "fs"},
 | 
			
		||||
    {18, "di"},
 | 
			
		||||
    {19, "hid"},
 | 
			
		||||
    {20, "cam"},
 | 
			
		||||
    {21, "pi"},
 | 
			
		||||
    {22, "pm"},
 | 
			
		||||
    {23, "pm_low"},
 | 
			
		||||
    {24, "fsi"},
 | 
			
		||||
    {25, "srv"},
 | 
			
		||||
    {26, "ndm"},
 | 
			
		||||
    {27, "nwm"},
 | 
			
		||||
    {28, "soc"},
 | 
			
		||||
    {29, "ldr"},
 | 
			
		||||
    {30, "acc"},
 | 
			
		||||
    {31, "romfs"},
 | 
			
		||||
    {32, "am"},
 | 
			
		||||
    {33, "hio"},
 | 
			
		||||
    {34, "updater"},
 | 
			
		||||
    {35, "mic"},
 | 
			
		||||
    {36, "fnd"},
 | 
			
		||||
    {37, "mp"},
 | 
			
		||||
    {38, "mpwl"},
 | 
			
		||||
    {39, "ac"},
 | 
			
		||||
    {40, "http"},
 | 
			
		||||
    {41, "dsp"},
 | 
			
		||||
    {42, "snd"},
 | 
			
		||||
    {43, "dlp"},
 | 
			
		||||
    {44, "hio_low"},
 | 
			
		||||
    {45, "csnd"},
 | 
			
		||||
    {46, "ssl"},
 | 
			
		||||
    {47, "am_low"},
 | 
			
		||||
    {48, "nex"},
 | 
			
		||||
    {49, "friends"},
 | 
			
		||||
    {50, "rdt"},
 | 
			
		||||
    {51, "applet"},
 | 
			
		||||
    {52, "nim"},
 | 
			
		||||
    {53, "ptm"},
 | 
			
		||||
    {54, "midi"},
 | 
			
		||||
    {55, "mc"},
 | 
			
		||||
    {56, "swc"},
 | 
			
		||||
    {57, "fatfs"},
 | 
			
		||||
    {58, "ngc"},
 | 
			
		||||
    {59, "card"},
 | 
			
		||||
    {60, "cardnor"},
 | 
			
		||||
    {61, "sdmc"},
 | 
			
		||||
    {62, "boss"},
 | 
			
		||||
    {63, "dbm"},
 | 
			
		||||
    {64, "config"},
 | 
			
		||||
    {65, "ps"},
 | 
			
		||||
    {66, "cec"},
 | 
			
		||||
    {67, "ir"},
 | 
			
		||||
    {68, "uds"},
 | 
			
		||||
    {69, "pl"},
 | 
			
		||||
    {70, "cup"},
 | 
			
		||||
    {71, "gyroscope"},
 | 
			
		||||
    {72, "mcu"},
 | 
			
		||||
    {73, "ns"},
 | 
			
		||||
    {74, "news"},
 | 
			
		||||
    {75, "ro"},
 | 
			
		||||
    {76, "gd"},
 | 
			
		||||
    {77, "card spi"},
 | 
			
		||||
    {78, "ec"},
 | 
			
		||||
    {79, "web browser"},
 | 
			
		||||
    {80, "test"},
 | 
			
		||||
    {81, "enc"},
 | 
			
		||||
    {82, "pia"},
 | 
			
		||||
    {83, "act"},
 | 
			
		||||
    {84, "vctl"},
 | 
			
		||||
    {85, "olv"},
 | 
			
		||||
    {86, "neia"},
 | 
			
		||||
    {87, "npns"},
 | 
			
		||||
    {90, "avd"},
 | 
			
		||||
    {91, "l2b"},
 | 
			
		||||
    {92, "mvd"},
 | 
			
		||||
    {93, "nfc"},
 | 
			
		||||
    {94, "uart"},
 | 
			
		||||
    {95, "spm"},
 | 
			
		||||
    {96, "qtm"},
 | 
			
		||||
    {97, "nfp"},
 | 
			
		||||
    {254, "application"},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static std::map<int, std::string> levels = {
 | 
			
		||||
    {0, "Success"},       {1, "Info"},       {25, "Status"},
 | 
			
		||||
    {26, "Temporary"},    {27, "Permanent"}, {28, "Usage"},
 | 
			
		||||
    {29, "Reinitialize"}, {30, "Reset"},     {31, "Fatal"},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static std::map<int, std::string> summaries = {
 | 
			
		||||
    {0, "Success"},
 | 
			
		||||
    {1, "Nothing happened"},
 | 
			
		||||
    {2, "Would block"},
 | 
			
		||||
    {3, "Out of resource"},
 | 
			
		||||
    {4, "Not found"},
 | 
			
		||||
    {5, "Invalid state"},
 | 
			
		||||
    {6, "Not supported"},
 | 
			
		||||
    {7, "Invalid argument"},
 | 
			
		||||
    {8, "Wrong argument"},
 | 
			
		||||
    {9, "Canceled"},
 | 
			
		||||
    {10, "Status changed"},
 | 
			
		||||
    {11, "Internal"},
 | 
			
		||||
    {63, "Invalid result value"},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static std::map<int, std::string> desccommon = {
 | 
			
		||||
    {0, "Success"},
 | 
			
		||||
    {1000, "Invalid selection"},
 | 
			
		||||
    {1001, "Too large"},
 | 
			
		||||
    {1002, "Not authorized"},
 | 
			
		||||
    {1003, "Already done"},
 | 
			
		||||
    {1004, "Invalid size"},
 | 
			
		||||
    {1005, "Invalid enum value"},
 | 
			
		||||
    {1006, "Invalid combination"},
 | 
			
		||||
    {1007, "No data"},
 | 
			
		||||
    {1008, "Busy"},
 | 
			
		||||
    {1009, "Misaligned address"},
 | 
			
		||||
    {1010, "Misaligned size"},
 | 
			
		||||
    {1011, "Out of memory"},
 | 
			
		||||
    {1012, "Not implemented"},
 | 
			
		||||
    {1013, "Invalid address"},
 | 
			
		||||
    {1014, "Invalid pointer"},
 | 
			
		||||
    {1015, "Invalid handle"},
 | 
			
		||||
    {1016, "Not initialized"},
 | 
			
		||||
    {1017, "Already initialized"},
 | 
			
		||||
    {1018, "Not found"},
 | 
			
		||||
    {1019, "Cancel requested"},
 | 
			
		||||
    {1020, "Already exists"},
 | 
			
		||||
    {1021, "Out of range"},
 | 
			
		||||
    {1022, "Timeout"},
 | 
			
		||||
    {1023, "Invalid result value"},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static std::map<int, std::string> desckernel = {
 | 
			
		||||
    {2, "Invalid memory permissions."},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static std::map<int, std::string> descos = {
 | 
			
		||||
    {10, "Not enough memory."},
 | 
			
		||||
    {26, "Session closed by remote."},
 | 
			
		||||
    {47, "Invalid command header."},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Need to Fix The Range based Values
 | 
			
		||||
static std::map<int, std::string> descfs = {
 | 
			
		||||
    {101, "Archive not mounted or mount-point not found."},
 | 
			
		||||
    {120, "Title or object not found."},
 | 
			
		||||
    {141, "Gamecard not inserted."},
 | 
			
		||||
    {230, "Invalid open flags or permissions."},
 | 
			
		||||
    {391, "NCCH hash check failed."},
 | 
			
		||||
    {302, "RSA or AES-MAC verification failed."},
 | 
			
		||||
    {395, "RomFS or Savedata hash check failed."},
 | 
			
		||||
    {630, "Command not allowed, or missing permissions."},
 | 
			
		||||
    {702, "Invalid path."},
 | 
			
		||||
    {761, "Incorrect ExeFS read size."},
 | 
			
		||||
    {100, "[Media] not found."},
 | 
			
		||||
    {180, "Exists already."},
 | 
			
		||||
    {200, "Not enough space."},
 | 
			
		||||
    {220, "Invalidated archive."},
 | 
			
		||||
    {230, "Unacceptable or write protected."},
 | 
			
		||||
    {340, "0x01"},
 | 
			
		||||
    {360, "Bad format."},
 | 
			
		||||
    {390, "Verification failure."},
 | 
			
		||||
    {400, "0x01"},
 | 
			
		||||
    {600, "Out of resources."},
 | 
			
		||||
    {630, "Access denied."},
 | 
			
		||||
    {661, "0x01"},
 | 
			
		||||
    {700, "Invalid argument."},
 | 
			
		||||
    {730, "Not initialized."},
 | 
			
		||||
    {750, "Already initialized."},
 | 
			
		||||
    {760, "Not supported."},
 | 
			
		||||
    {780, "0x01"},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static std::map<int, std::string> descsrv = {
 | 
			
		||||
    {5,
 | 
			
		||||
     "Invalid string length (service name length is zero or longer than 8 "
 | 
			
		||||
     "chars)."},
 | 
			
		||||
    {6,
 | 
			
		||||
     "Access to service denied (requested a service the application does "
 | 
			
		||||
     "not have access to)."},
 | 
			
		||||
    {7,
 | 
			
		||||
     "String size does not match contents (service name contains unexpected "
 | 
			
		||||
     "null byte)."},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static std::map<int, std::string> descnwm = {
 | 
			
		||||
    {2,
 | 
			
		||||
     "This error usually indicates the wifi chipset in the console is dying "
 | 
			
		||||
     "or dead."},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static std::map<int, std::string> descam = {
 | 
			
		||||
    {4, "Invalid ticket version."},
 | 
			
		||||
    {32, "Empty CIA."},
 | 
			
		||||
    {37, "Invalid NCCH."},
 | 
			
		||||
    {39, "Invalid title version."},
 | 
			
		||||
    {43, "Database doesn\"t exist, or it failed to open."},
 | 
			
		||||
    {44, "Trying to uninstall system-app."},
 | 
			
		||||
    {106,
 | 
			
		||||
     "Invalid signature/CIA. Usually happens when developer UNITINFO is "
 | 
			
		||||
     "enabled in Luma3DS."},
 | 
			
		||||
    {393, "Invalid database."},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static std::map<int, std::string> deschttp = {
 | 
			
		||||
    {105, "Request timed out."},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static std::map<int, std::string> descnim = {
 | 
			
		||||
    {1,
 | 
			
		||||
     "Invalid string IPC paramater (non null terminated at its indicated "
 | 
			
		||||
     "length)."},
 | 
			
		||||
    {12,
 | 
			
		||||
     "Invalid country code returned by CFG module reading config save "
 | 
			
		||||
     "0xB0000."},
 | 
			
		||||
    {13,
 | 
			
		||||
     "Zero string length console serial number or '000000000000000' "
 | 
			
		||||
     "returned by CFG's SecureInfoGetSerialNo."},
 | 
			
		||||
    {18,
 | 
			
		||||
     "General data reading error of NIM's .dat files from its system save, "
 | 
			
		||||
     "bad data or bad data lengths."},
 | 
			
		||||
    {22,
 | 
			
		||||
     "General invalid data or length of data returned from nintendo "
 | 
			
		||||
     "servers. (Only applicable for some operations)"},
 | 
			
		||||
    {25,
 | 
			
		||||
     "IntegrityVerificationSeed is waiting on servers to be synced into "
 | 
			
		||||
     "console. Can't processed with online services without sync being "
 | 
			
		||||
     "completed first over IPC request."},
 | 
			
		||||
    {26,
 | 
			
		||||
     "Unavailable/unaccessable IntegrityVerificationSeed on Nintendo "
 | 
			
		||||
     "servers. May happen if NIM is told to import "
 | 
			
		||||
     "IntegrityVerificationSeed from servers at any time other than after "
 | 
			
		||||
     "the successful System Transfer reboot."},
 | 
			
		||||
    {27,
 | 
			
		||||
     "Invalid country language code returned by CFG module reading config "
 | 
			
		||||
     "save 0xA0002."},
 | 
			
		||||
    {37,
 | 
			
		||||
     "Service is in Standby Mode. (eShop ban? General service is down? "
 | 
			
		||||
     "This caused by a server response flag on account information. "
 | 
			
		||||
     "Account is not referring to NNID.)"},
 | 
			
		||||
    {39, "HTTP Status non 200. (Only applicable for some operations)"},
 | 
			
		||||
    {40, "General XML read/write error while processing Auto Delivery XMLs."},
 | 
			
		||||
    {41,
 | 
			
		||||
     "General XML read/write error while processing Auto Delivery XMLs. "
 | 
			
		||||
     "(Stubbed virtual call was called)"},
 | 
			
		||||
    {58,
 | 
			
		||||
     "Invalid NPNS token returned by CFG module reading config save 0xF0006."},
 | 
			
		||||
    {67, "HTTP Status 404 while trying to download a game's seed."},
 | 
			
		||||
    {68, "HTTP Status 503 while trying to download a game's seed."},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static std::map<int, std::string> descmvd = {
 | 
			
		||||
    {271, "Invalid configuration."},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static std::map<int, std::string> descqtm = {
 | 
			
		||||
    {8, "Camera is already in use or busy."},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Need to Fix The Range based Values
 | 
			
		||||
static std::map<int, std::string> descapplication = {
 | 
			
		||||
    {0,
 | 
			
		||||
     "The application raised an error. Please consult the application's "
 | 
			
		||||
     "source code or ask the author for assistance with it."},
 | 
			
		||||
    {1024, "0x01"},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
void ResultDecoder::Load(Result rescode) { this->m_rescode = rescode; }
 | 
			
		||||
void ResultDecoder::Load(std::string rescode) {
 | 
			
		||||
  std::stringstream ss;
 | 
			
		||||
  ss << rescode;
 | 
			
		||||
  ss >> std::hex >> this->m_rescode;
 | 
			
		||||
}
 | 
			
		||||
std::string Palladium::ResultDecoder::GetCode() {
 | 
			
		||||
  std::stringstream ss;
 | 
			
		||||
  ss << std::hex << m_rescode;
 | 
			
		||||
  std::string reshex(ss.str());
 | 
			
		||||
  return reshex;
 | 
			
		||||
}
 | 
			
		||||
std::string ResultDecoder::GetLevel() {
 | 
			
		||||
  std::string res = levels.at(this->GetLevelInt()) + " (" +
 | 
			
		||||
                    std::to_string(this->GetLevelInt()) + ")";
 | 
			
		||||
  return res;
 | 
			
		||||
}
 | 
			
		||||
int ResultDecoder::GetLevelInt() { return R_LEVEL(m_rescode); }
 | 
			
		||||
std::string ResultDecoder::GetModule() {
 | 
			
		||||
  std::string res = modules.at(this->GetModuleInt()) + " (" +
 | 
			
		||||
                    std::to_string(this->GetModuleInt()) + ")";
 | 
			
		||||
  return res;
 | 
			
		||||
}
 | 
			
		||||
int ResultDecoder::GetModuleInt() { return R_MODULE(m_rescode); }
 | 
			
		||||
std::string ResultDecoder::GetDescription() {
 | 
			
		||||
  std::string res = "Desc Not Implemented!";
 | 
			
		||||
  switch (this->GetModuleInt()) {
 | 
			
		||||
    case 0:
 | 
			
		||||
      res = desccommon.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
            std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      break;
 | 
			
		||||
    case 1:
 | 
			
		||||
      if ((desckernel.find(this->GetDescriptionInt()) == desckernel.end())) {
 | 
			
		||||
        res = desccommon.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      } else {
 | 
			
		||||
        res = desckernel.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case 6:
 | 
			
		||||
      if ((descos.find(this->GetDescriptionInt()) == descos.end())) {
 | 
			
		||||
        res = desccommon.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      } else {
 | 
			
		||||
        res = descos.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case 17:
 | 
			
		||||
      if ((descfs.find(this->GetDescriptionInt()) == descfs.end())) {
 | 
			
		||||
        res = desccommon.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      } else {
 | 
			
		||||
        res = descfs.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case 25:
 | 
			
		||||
      if ((descsrv.find(this->GetDescriptionInt()) == descsrv.end())) {
 | 
			
		||||
        res = desccommon.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      } else {
 | 
			
		||||
        res = descsrv.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case 27:
 | 
			
		||||
      if ((descnwm.find(this->GetDescriptionInt()) == descnwm.end())) {
 | 
			
		||||
        res = desccommon.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      } else {
 | 
			
		||||
        res = descnwm.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case 32:
 | 
			
		||||
      if ((descam.find(this->GetDescriptionInt()) == descam.end())) {
 | 
			
		||||
        res = desccommon.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      } else {
 | 
			
		||||
        res = descam.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case 40:
 | 
			
		||||
      if ((deschttp.find(this->GetDescriptionInt()) == deschttp.end())) {
 | 
			
		||||
        res = desccommon.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      } else {
 | 
			
		||||
        res = deschttp.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case 52:
 | 
			
		||||
      if ((descnim.find(this->GetDescriptionInt()) == descnim.end())) {
 | 
			
		||||
        res = desccommon.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      } else {
 | 
			
		||||
        res = descnim.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case 92:
 | 
			
		||||
      if ((descmvd.find(this->GetDescriptionInt()) == descmvd.end())) {
 | 
			
		||||
        res = desccommon.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      } else {
 | 
			
		||||
        res = descmvd.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case 96:
 | 
			
		||||
      if ((descqtm.find(this->GetDescriptionInt()) == descqtm.end())) {
 | 
			
		||||
        res = desccommon.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      } else {
 | 
			
		||||
        res = descqtm.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case 254:
 | 
			
		||||
      if ((descapplication.find(this->GetDescriptionInt()) ==
 | 
			
		||||
           descapplication.end())) {
 | 
			
		||||
        res = desccommon.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      } else {
 | 
			
		||||
        res = descapplication.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
              std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
      res = desccommon.at(this->GetDescriptionInt()) + " (" +
 | 
			
		||||
            std::to_string(this->GetDescriptionInt()) + ")";
 | 
			
		||||
      break;
 | 
			
		||||
  }
 | 
			
		||||
  return res;
 | 
			
		||||
}
 | 
			
		||||
int ResultDecoder::GetDescriptionInt() { return R_DESCRIPTION(m_rescode); }
 | 
			
		||||
std::string ResultDecoder::GetSummary() {
 | 
			
		||||
  std::string res = summaries.at(this->GetSummaryInt()) + " (" +
 | 
			
		||||
                    std::to_string(this->GetSummaryInt()) + ")";
 | 
			
		||||
  return res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::ResultDecoder::WriteLog() {
 | 
			
		||||
  std::string out_path = "sdmc:/Palladium/Apps/" + pdi_app_name + "/resdec";
 | 
			
		||||
  std::filesystem::create_directories(out_path);
 | 
			
		||||
  out_path += "/err_result_" + std::to_string(time(0)) + ".log";
 | 
			
		||||
  std::ofstream out(out_path, std::ios::app);
 | 
			
		||||
  out << "+-------------------\n";
 | 
			
		||||
  out << "| Error: " << GetCode() << "\n";
 | 
			
		||||
  out << "+-------------------\n";
 | 
			
		||||
  out << "| Module: " << GetModule() << "\n";
 | 
			
		||||
  out << "+-------------------\n";
 | 
			
		||||
  out << "| Level: " << GetLevel() << "\n";
 | 
			
		||||
  out << "+-------------------\n";
 | 
			
		||||
  out << "| Summary: " << GetSummary() << "\n";
 | 
			
		||||
  out << "+-------------------\n";
 | 
			
		||||
  out << "| Description: " << GetDescription() << "\n";
 | 
			
		||||
  out << "+-------------------\n";
 | 
			
		||||
  out.close();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int ResultDecoder::GetSummaryInt() { return R_SUMMARY(m_rescode); }
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										22
									
								
								source/Sheet.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								source/Sheet.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
#include <pd/Sheet.hpp>
 | 
			
		||||
#include <pd/internal_db.hpp>
 | 
			
		||||
 | 
			
		||||
Result Palladium::Sheet::Load(const std::string& path) {
 | 
			
		||||
  if (this->spritesheet) Free();
 | 
			
		||||
  this->spritesheet = C2D_SpriteSheetLoad(path.c_str());
 | 
			
		||||
  if (!this->spritesheet) {
 | 
			
		||||
    _pdi_logger()->Write("Failed to Load Spritesheet from: " + path, 0);
 | 
			
		||||
  }
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::Sheet::Free() {
 | 
			
		||||
  if (!this->spritesheet) return;
 | 
			
		||||
  C2D_SpriteSheetFree(this->spritesheet);
 | 
			
		||||
  this->spritesheet = nullptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
C2D_Image Palladium::Sheet::GetImage(int idx) {
 | 
			
		||||
  if (!this->spritesheet) return {nullptr, nullptr};
 | 
			
		||||
  return C2D_SpriteSheetGetImage(this->spritesheet, idx);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										133
									
								
								source/Sound.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										133
									
								
								source/Sound.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,133 @@
 | 
			
		||||
#include <cstring>
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <pd/Sound.hpp>
 | 
			
		||||
#include <pd/internal_db.hpp>
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
using std::string;
 | 
			
		||||
 | 
			
		||||
// Reference: http://yannesposito.com/Scratch/en/blog/2010-10-14-Fun-with-wav/
 | 
			
		||||
typedef struct _WavHeader {
 | 
			
		||||
  char magic[4];    // "RIFF"
 | 
			
		||||
  u32 totallength;  // Total file length, minus 8.
 | 
			
		||||
  char wavefmt[8];  // Should be "WAVEfmt "
 | 
			
		||||
  u32 format;       // 16 for PCM format
 | 
			
		||||
  u16 pcm;          // 1 for PCM format
 | 
			
		||||
  u16 channels;     // Channels
 | 
			
		||||
  u32 frequency;    // Sampling frequency
 | 
			
		||||
  u32 bytes_per_second;
 | 
			
		||||
  u16 bytes_by_capture;
 | 
			
		||||
  u16 bits_per_sample;
 | 
			
		||||
  char data[4];  // "data"
 | 
			
		||||
  u32 bytes_in_data;
 | 
			
		||||
} WavHeader;
 | 
			
		||||
static_assert(sizeof(WavHeader) == 44, "WavHeader size is not 44 bytes.");
 | 
			
		||||
 | 
			
		||||
using namespace Palladium;
 | 
			
		||||
Sound::Sound(const string &path, int channel, bool toloop) {
 | 
			
		||||
  if (pdi_is_ndsp) {
 | 
			
		||||
    ndspSetOutputMode(NDSP_OUTPUT_STEREO);
 | 
			
		||||
    ndspSetOutputCount(2);  // Num of buffers
 | 
			
		||||
 | 
			
		||||
    // Reading wav file
 | 
			
		||||
    std::fstream fp(path, std::ios::in | std::ios::binary);
 | 
			
		||||
 | 
			
		||||
    if (!fp.is_open()) {
 | 
			
		||||
      _pdi_logger()->Write("Could not open WAV: " + path, 0);
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WavHeader wavHeader;
 | 
			
		||||
    fp.read(reinterpret_cast<char *>(&wavHeader), sizeof(WavHeader));
 | 
			
		||||
    size_t read = fp.tellg();
 | 
			
		||||
    if (read != sizeof(wavHeader)) {
 | 
			
		||||
      // Short read.
 | 
			
		||||
      _pdi_logger()->Write("WAV Header is too short", 0);
 | 
			
		||||
      fp.close();
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Verify the header.
 | 
			
		||||
    static const char RIFF_magic[4] = {'R', 'I', 'F', 'F'};
 | 
			
		||||
    if (memcmp(wavHeader.magic, RIFF_magic, sizeof(wavHeader.magic)) != 0) {
 | 
			
		||||
      // Incorrect magic number.
 | 
			
		||||
      _pdi_logger()->Write("Wrong Fileformat", 0);
 | 
			
		||||
      fp.close();
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (wavHeader.totallength == 0 ||
 | 
			
		||||
        (wavHeader.channels != 1 && wavHeader.channels != 2) ||
 | 
			
		||||
        (wavHeader.bits_per_sample != 8 && wavHeader.bits_per_sample != 16)) {
 | 
			
		||||
      // Unsupported WAV file.
 | 
			
		||||
      _pdi_logger()->Write("File is invalid", 0);
 | 
			
		||||
      fp.close();
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Get the file size.
 | 
			
		||||
    fp.seekg(0, std::ios::end);
 | 
			
		||||
    dataSize = fp.tellg();
 | 
			
		||||
    dataSize -= sizeof(WavHeader);
 | 
			
		||||
 | 
			
		||||
    // Allocating and reading samples
 | 
			
		||||
    data = static_cast<u8 *>(linearAlloc(dataSize));
 | 
			
		||||
    fp.seekg(44, std::ios::beg);
 | 
			
		||||
    fp.read(reinterpret_cast<char *>(data), dataSize);
 | 
			
		||||
    fp.close();
 | 
			
		||||
    dataSize /= 2;  // FIXME: 16-bit or stereo?
 | 
			
		||||
 | 
			
		||||
    // Find the right format
 | 
			
		||||
    u16 ndspFormat;
 | 
			
		||||
    if (wavHeader.bits_per_sample == 8) {
 | 
			
		||||
      ndspFormat = (wavHeader.channels == 1) ? NDSP_FORMAT_MONO_PCM8
 | 
			
		||||
                                             : NDSP_FORMAT_STEREO_PCM8;
 | 
			
		||||
    } else {
 | 
			
		||||
      ndspFormat = (wavHeader.channels == 1) ? NDSP_FORMAT_MONO_PCM16
 | 
			
		||||
                                             : NDSP_FORMAT_STEREO_PCM16;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ndspChnReset(channel);
 | 
			
		||||
    ndspChnSetInterp(channel, NDSP_INTERP_NONE);
 | 
			
		||||
    ndspChnSetRate(channel, float(wavHeader.frequency));
 | 
			
		||||
    ndspChnSetFormat(channel, ndspFormat);
 | 
			
		||||
 | 
			
		||||
    // Create and play a wav buffer
 | 
			
		||||
    memset(&waveBuf, 0, sizeof(waveBuf));
 | 
			
		||||
 | 
			
		||||
    waveBuf.data_vaddr = reinterpret_cast<u32 *>(data);
 | 
			
		||||
    waveBuf.nsamples = dataSize / (wavHeader.bits_per_sample >> 3);
 | 
			
		||||
    waveBuf.looping = toloop;
 | 
			
		||||
    waveBuf.status = NDSP_WBUF_FREE;
 | 
			
		||||
    chnl = channel;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Sound::~Sound() {
 | 
			
		||||
  if (pdi_is_ndsp) {
 | 
			
		||||
    waveBuf.data_vaddr = 0;
 | 
			
		||||
    waveBuf.nsamples = 0;
 | 
			
		||||
    waveBuf.looping = false;
 | 
			
		||||
    waveBuf.status = 0;
 | 
			
		||||
    ndspChnWaveBufClear(chnl);
 | 
			
		||||
 | 
			
		||||
    if (data) {
 | 
			
		||||
      linearFree(data);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Sound::Play() {
 | 
			
		||||
  if (pdi_is_ndsp) {
 | 
			
		||||
    if (!data) return;
 | 
			
		||||
    DSP_FlushDataCache(data, dataSize);
 | 
			
		||||
    ndspChnWaveBufAdd(chnl, &waveBuf);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Sound::Stop() {
 | 
			
		||||
  if (pdi_is_ndsp) {
 | 
			
		||||
    if (!data) return;
 | 
			
		||||
    ndspChnWaveBufClear(chnl);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										53
									
								
								source/Sprite.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								source/Sprite.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,53 @@
 | 
			
		||||
#include <pd/Sprite.hpp>
 | 
			
		||||
 | 
			
		||||
void Palladium::Sprite::FromSheet(Palladium::Sheet::Ref sheet, size_t index) {
 | 
			
		||||
  C2D_SpriteFromSheet(&this->sprite, sheet->Get(), index);
 | 
			
		||||
}
 | 
			
		||||
bool Palladium::Sprite::Draw() {
 | 
			
		||||
  // Patch Depth before draw
 | 
			
		||||
  sprite.params.depth = 0.5;
 | 
			
		||||
  return C2D_DrawSprite(&this->sprite);
 | 
			
		||||
}
 | 
			
		||||
void Palladium::Sprite::SetCenter(float x, float y) {
 | 
			
		||||
  C2D_SpriteSetCenter(&this->sprite, x, y);
 | 
			
		||||
}
 | 
			
		||||
void Palladium::Sprite::SetPos(float x, float y) {
 | 
			
		||||
  C2D_SpriteSetPos(&this->sprite, x, y);
 | 
			
		||||
}
 | 
			
		||||
void Palladium::Sprite::SetRotation(float rotation) {
 | 
			
		||||
  C2D_SpriteSetRotation(&this->sprite, rotation);
 | 
			
		||||
}
 | 
			
		||||
void Palladium::Sprite::Rotate(float speed) {
 | 
			
		||||
  C2D_SpriteRotateDegrees(&this->sprite, speed);
 | 
			
		||||
}
 | 
			
		||||
float Palladium::Sprite::GetHeight() { return GetSize().x; }
 | 
			
		||||
float Palladium::Sprite::GetWidth() { return GetSize().y; }
 | 
			
		||||
float Palladium::Sprite::GetPosX() { return GetPos().x; }
 | 
			
		||||
float Palladium::Sprite::GetPosY() { return GetPos().y; }
 | 
			
		||||
 | 
			
		||||
NVec2 Palladium::Sprite::GetPos() {
 | 
			
		||||
  return NVec2(this->sprite.params.pos.x, this->sprite.params.pos.y);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
NVec2 Palladium::Sprite::GetSize() {
 | 
			
		||||
  return NVec2(this->sprite.params.pos.w, this->sprite.params.pos.h);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::Sprite::SetPos(NVec2 pos) {
 | 
			
		||||
  C2D_SpriteSetPos(&this->sprite, pos.x, pos.y);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::Sprite::SetScale(NVec2 scale) {
 | 
			
		||||
  C2D_SpriteScale(&this->sprite, scale.x, scale.y);
 | 
			
		||||
}
 | 
			
		||||
void Palladium::Sprite::SetRotCenter(NVec2 percentage) {
 | 
			
		||||
  C2D_SpriteSetCenter(&this->sprite, percentage.x, percentage.y);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::Sprite::FromImage(Palladium::Image::Ref img) {
 | 
			
		||||
  C2D_SpriteFromImage(&this->sprite, img->Get());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::Sprite::SetScale(float x, float y) {
 | 
			
		||||
  C2D_SpriteScale(&this->sprite, x, y);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										28
									
								
								source/SpriteSheetAnimation.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								source/SpriteSheetAnimation.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
#include <pd/SpriteAnimation.hpp>
 | 
			
		||||
 | 
			
		||||
void Palladium::SpriteSheetAnimation::Setup(Palladium::Sheet::Ref sheet,
 | 
			
		||||
                                           size_t imagecount, size_t startimage,
 | 
			
		||||
                                           float frame_begin,
 | 
			
		||||
                                           float frame_finish) {
 | 
			
		||||
  D_totaltime = frame_begin;
 | 
			
		||||
 | 
			
		||||
  this->images = imagecount;
 | 
			
		||||
 | 
			
		||||
  this->sheet = sheet;
 | 
			
		||||
 | 
			
		||||
  this->time = frame_finish;
 | 
			
		||||
 | 
			
		||||
  Palladium::SpriteSheetAnimation::FromSheet(this->sheet, startimage);
 | 
			
		||||
}
 | 
			
		||||
void Palladium::SpriteSheetAnimation::Play(float timespeed) {
 | 
			
		||||
  D_totaltime += timespeed;
 | 
			
		||||
  if (D_totaltime >= time) {
 | 
			
		||||
    D_totaltime -= time;
 | 
			
		||||
    imgs++;
 | 
			
		||||
    if (imgs == images) {
 | 
			
		||||
      imgs = 0;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  Palladium::SpriteSheetAnimation::FromSheet(sheet, imgs);
 | 
			
		||||
  // Palladium::SpriteSheetAnimation::Draw();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										22
									
								
								source/Tasks.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								source/Tasks.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <pd/Tasks.hpp>
 | 
			
		||||
#include <thread>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
static std::vector<std::shared_ptr<std::thread>> threads;
 | 
			
		||||
 | 
			
		||||
int Palladium::Tasks::Create(std::function<void()> fun) {
 | 
			
		||||
  auto thrd = std::make_shared<std::thread>(fun);
 | 
			
		||||
  threads.push_back(thrd);
 | 
			
		||||
  return threads.size();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::Tasks::DestroyAll() {
 | 
			
		||||
  for (auto& it : threads) {
 | 
			
		||||
    if (it && it->joinable()) {
 | 
			
		||||
      it->join();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  // Delete Pointers
 | 
			
		||||
  threads.clear();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										177
									
								
								source/Texture.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										177
									
								
								source/Texture.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,177 @@
 | 
			
		||||
#include <pd/Texture.hpp>
 | 
			
		||||
#include <pd/external/stb_image.h>
 | 
			
		||||
#include <pd/internal_db.hpp>
 | 
			
		||||
 | 
			
		||||
#include <pd/external/stb_image_write.h>
 | 
			
		||||
 | 
			
		||||
namespace pdi {
 | 
			
		||||
static u32 GP2O(u32 v) {
 | 
			
		||||
  v--;
 | 
			
		||||
  v |= v >> 1;
 | 
			
		||||
  v |= v >> 2;
 | 
			
		||||
  v |= v >> 4;
 | 
			
		||||
  v |= v >> 8;
 | 
			
		||||
  v |= v >> 16;
 | 
			
		||||
  v++;
 | 
			
		||||
  return (v >= 64 ? v : 64);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void R24R32(std::vector<uint8_t> &out,
 | 
			
		||||
                          const std::vector<uint8_t> &in, const int &w,
 | 
			
		||||
                          const int &h) {
 | 
			
		||||
  // Converts RGB24 to RGBA32
 | 
			
		||||
  for (int y = 0; y < h; y++) {
 | 
			
		||||
    for (int x = 0; x < w; x++) {
 | 
			
		||||
      int src = (y * w + x) * 3;
 | 
			
		||||
      int dst = (y * w + x) * 4;
 | 
			
		||||
      out[dst + 0] = in[src + 0];
 | 
			
		||||
      out[dst + 1] = in[src + 1];
 | 
			
		||||
      out[dst + 2] = in[src + 2];
 | 
			
		||||
      out[dst + 3] = 255;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}}
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
void Texture::MakeTex(std::vector<unsigned char> &buf, int w, int h) {
 | 
			
		||||
  if (!tex) {
 | 
			
		||||
    _pdi_logger()->Write("Invalid Input (object has no adress!)");
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  // RGBA -> Abgr
 | 
			
		||||
  for (int y = 0; y < h; y++) {
 | 
			
		||||
    for (int x = 0; x < w; x++) {
 | 
			
		||||
      int pos = (x + y * w) * 4;
 | 
			
		||||
      auto r = buf[pos + 0];
 | 
			
		||||
      auto g = buf[pos + 1];
 | 
			
		||||
      auto b = buf[pos + 2];
 | 
			
		||||
      auto a = buf[pos + 3];
 | 
			
		||||
      buf[pos + 0] = a;
 | 
			
		||||
      buf[pos + 1] = b;
 | 
			
		||||
      buf[pos + 2] = g;
 | 
			
		||||
      buf[pos + 3] = r;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Pow2
 | 
			
		||||
  this->tex_size.x = pdi::GP2O((unsigned int)w);
 | 
			
		||||
  this->tex_size.y = pdi::GP2O((unsigned int)h);
 | 
			
		||||
 | 
			
		||||
  this->img_size.x = (u16)w;
 | 
			
		||||
  this->img_size.y = (u16)h;
 | 
			
		||||
  this->uvs.x = 0.0f;
 | 
			
		||||
  this->uvs.y = 1.0f;
 | 
			
		||||
  this->uvs.z = ((float)w / (float)this->tex_size.x);
 | 
			
		||||
  this->uvs.w = 1.0 - ((float)h / (float)this->tex_size.y);
 | 
			
		||||
 | 
			
		||||
  // Texture Setup
 | 
			
		||||
  C3D_TexInit(tex, (u16)this->tex_size.x, (u16)this->tex_size.y, GPU_RGBA8);
 | 
			
		||||
  C3D_TexSetFilter(tex, GPU_NEAREST, GPU_NEAREST);
 | 
			
		||||
 | 
			
		||||
  memset(tex->data, 0, tex->size);
 | 
			
		||||
 | 
			
		||||
  for (int x = 0; x < w; x++) {
 | 
			
		||||
    for (int y = 0; y < h; y++) {
 | 
			
		||||
      int dst_pos = ((((y >> 3) * ((int)this->tex_size.x >> 3) + (x >> 3)) << 6) +
 | 
			
		||||
                     ((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) |
 | 
			
		||||
                      ((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3))) *
 | 
			
		||||
                    4;
 | 
			
		||||
      int src_pos = (y * w + x) * 4;
 | 
			
		||||
 | 
			
		||||
      memcpy(&((unsigned char *)tex->data)[dst_pos], &buf[src_pos], 4);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  C3D_TexFlush(tex);
 | 
			
		||||
  tex->border = 0x00000000;
 | 
			
		||||
  C3D_TexSetWrap(tex, GPU_CLAMP_TO_BORDER, GPU_CLAMP_TO_BORDER);
 | 
			
		||||
}
 | 
			
		||||
void Texture::LoadFile(const std::string& path) {
 | 
			
		||||
    int w, h, c = 0;
 | 
			
		||||
  unsigned char *image = stbi_load(path.c_str(), &w, &h, &c, 4);
 | 
			
		||||
  if (image == nullptr) {
 | 
			
		||||
    //_pdi_logger()->Write("Failed to Load Image: " + path);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  // Size/Fmt Check
 | 
			
		||||
  if (w > 1024 || h > 1024) {
 | 
			
		||||
    // Reason: Image to Large
 | 
			
		||||
    //_pdi_logger()->Write("Image too Large!");
 | 
			
		||||
    stbi_image_free(image);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  std::vector<unsigned char> wimg;
 | 
			
		||||
  if (c == 3) {
 | 
			
		||||
    //_pdi_logger()->Write("Convert Image to RGBA");
 | 
			
		||||
    stbi_image_free(image);
 | 
			
		||||
    image = stbi_load(path.c_str(), &w, &h, &c, 3);
 | 
			
		||||
    wimg.resize(w * h * 4);
 | 
			
		||||
    pdi::R24R32(wimg, std::vector<unsigned char>(image, image + (w * h * 3)),
 | 
			
		||||
                  w, h);
 | 
			
		||||
  } else {
 | 
			
		||||
    wimg.assign(&image[0], &image[(w * h * 4) - 1]);
 | 
			
		||||
    stbi_image_free(image);
 | 
			
		||||
  }
 | 
			
		||||
  // Create C2D_Image
 | 
			
		||||
  tex = new C3D_Tex;
 | 
			
		||||
  MakeTex(wimg, w, h);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Texture::LoadFromMemory(const std::vector<unsigned char>& data) {
 | 
			
		||||
    int w, h, c = 0;
 | 
			
		||||
  unsigned char *image = stbi_load_from_memory(data.data(), data.size(), &w, &h, &c, 4);
 | 
			
		||||
  if (image == nullptr) {
 | 
			
		||||
    //_pdi_logger()->Write("Failed to Load Image: " + path);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  // Size/Fmt Check
 | 
			
		||||
  if (w > 1024 || h > 1024) {
 | 
			
		||||
    // Reason: Image to Large
 | 
			
		||||
    //_pdi_logger()->Write("Image too Large!");
 | 
			
		||||
    stbi_image_free(image);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  std::vector<unsigned char> wimg;
 | 
			
		||||
  if (c == 3) {
 | 
			
		||||
    //_pdi_logger()->Write("Convert Image to RGBA");
 | 
			
		||||
    stbi_image_free(image);
 | 
			
		||||
    image = stbi_load_from_memory(data.data(), data.size(), &w, &h, &c, 3);
 | 
			
		||||
    wimg.resize(w * h * 4);
 | 
			
		||||
    pdi::R24R32(wimg, std::vector<unsigned char>(image, image + (w * h * 3)),
 | 
			
		||||
                  w, h);
 | 
			
		||||
  } else {
 | 
			
		||||
    wimg.assign(&image[0], &image[(w * h * 4) - 1]);
 | 
			
		||||
    stbi_image_free(image);
 | 
			
		||||
  }
 | 
			
		||||
  // Create C2D_Image
 | 
			
		||||
  tex = new C3D_Tex;
 | 
			
		||||
  MakeTex(wimg, w, h);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Texture::LoadPixels(const std::vector<unsigned char>& data, int w, int h) {
 | 
			
		||||
    Delete();
 | 
			
		||||
    if(w*h*4 != (int)data.size()) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    if (w > 1024 || h > 1024) {
 | 
			
		||||
    // Reason: Image to Large
 | 
			
		||||
    //_pdi_logger()->Write("Image too Large!");
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  tex = new C3D_Tex;
 | 
			
		||||
  std::vector<unsigned char> wimg(data);
 | 
			
		||||
  MakeTex(wimg, w, h);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Texture::Delete() {
 | 
			
		||||
    if(tex) {
 | 
			
		||||
        delete tex;
 | 
			
		||||
        tex = nullptr;
 | 
			
		||||
        img_size = NVec2();
 | 
			
		||||
        tex_size = NVec2();
 | 
			
		||||
        uvs = NVec4();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										138
									
								
								source/ThemeEditor.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										138
									
								
								source/ThemeEditor.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,138 @@
 | 
			
		||||
#include <filesystem>
 | 
			
		||||
#include <pd/Hid.hpp>
 | 
			
		||||
#include <pd/Message.hpp>
 | 
			
		||||
#include <pd/ThemeEditor.hpp>
 | 
			
		||||
#include <pd/UI7.hpp>
 | 
			
		||||
 | 
			
		||||
std::map<PDColor, std::string> color_names = {
 | 
			
		||||
    {PDColor_Background, "Background"},
 | 
			
		||||
    {PDColor_Button, "Button"},
 | 
			
		||||
    {PDColor_ButtonActive, "ButtonActive"},
 | 
			
		||||
    {PDColor_ButtonDisabled, "ButtonDisabled"},
 | 
			
		||||
    {PDColor_ButtonHovered, "ButtonHovered"},
 | 
			
		||||
    {PDColor_Checkmark, "Checkmark"},
 | 
			
		||||
    {PDColor_FrameBg, "FrameBg"},
 | 
			
		||||
    {PDColor_FrameBgHovered, "FrameBgHovered"},
 | 
			
		||||
    {PDColor_Header, "Header"},
 | 
			
		||||
    {PDColor_List0, "List0"},
 | 
			
		||||
    {PDColor_List1, "List1"},
 | 
			
		||||
    {PDColor_MessageBackground, "Message Background"},
 | 
			
		||||
    {PDColor_Progressbar, "Progressbar"},
 | 
			
		||||
    {PDColor_Selector, "Selector"},
 | 
			
		||||
    {PDColor_SelectorFade, "SelectorFade"},
 | 
			
		||||
    {PDColor_Text2, "Text Light"},
 | 
			
		||||
    {PDColor_Text, "Text Dark"},
 | 
			
		||||
    {PDColor_TextDisabled, "Text Disabled"},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Palladium::ThemeEditor::ThemeEditor() {
 | 
			
		||||
  // Backup active Theme and create New one to edit
 | 
			
		||||
  temp_theme = Palladium::ThemeActive();
 | 
			
		||||
  edit_theme = Palladium::Theme::New();
 | 
			
		||||
  edit_theme->CopyOther(temp_theme);
 | 
			
		||||
  Palladium::ThemeSet(edit_theme);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Palladium::ThemeEditor::~ThemeEditor() {
 | 
			
		||||
  // Set Back to Acrive Theme
 | 
			
		||||
  Palladium::ThemeSet(temp_theme);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::ThemeEditor::Draw() const {
 | 
			
		||||
  Palladium::R2::OnScreen(R2Screen_Top);
 | 
			
		||||
  if (UI7::BeginMenu("Palladium -> Theme Editor")) {
 | 
			
		||||
    UI7::Label("Sample Text");
 | 
			
		||||
    UI7::Checkbox("Checkbox", cm);
 | 
			
		||||
    UI7::InputText("Input Text", inpt, "Input Text");
 | 
			
		||||
    UI7::Button("Button");
 | 
			
		||||
    UI7::Progressbar(0.5f);
 | 
			
		||||
    UI7::ColorSelector("Color Selector",
 | 
			
		||||
                       edit_theme->GetTableRef()[PDColor_Progressbar]);
 | 
			
		||||
    UI7::EndMenu();
 | 
			
		||||
  }
 | 
			
		||||
  Palladium::R2::OnScreen(R2Screen_Bottom);
 | 
			
		||||
  if (UI7::BeginMenu("Theme", NVec2(), UI7MenuFlags_Scrolling)) {
 | 
			
		||||
    if (menu == 0) {
 | 
			
		||||
      if (UI7::Button("Create New")) {
 | 
			
		||||
        menu = 1;
 | 
			
		||||
        edit_theme->Default();
 | 
			
		||||
      } else if (UI7::Button("Edit Current")) {
 | 
			
		||||
        menu = 1;
 | 
			
		||||
      } else if (UI7::Button("Select Theme")) {
 | 
			
		||||
        menu = 2;
 | 
			
		||||
        theme_list.clear();
 | 
			
		||||
        for (const auto& it : std::filesystem::directory_iterator(
 | 
			
		||||
                 Palladium::GetAppDirectory() + "/themes")) {
 | 
			
		||||
          theme_list.push_back(it.path().filename().string());
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    } else if (menu == 1) {
 | 
			
		||||
      if (UI7::Button("Go back")) {
 | 
			
		||||
        edit_theme->CopyOther(temp_theme);
 | 
			
		||||
        menu = 0;
 | 
			
		||||
      } else if (UI7::Button("Save")) {
 | 
			
		||||
        Palladium::AddOvl(std::make_unique<Ovl_Keyboard>(kbd_text, kbd_state,
 | 
			
		||||
                                                        "<name>.theme"));
 | 
			
		||||
      }
 | 
			
		||||
      for (auto& it : color_names) {
 | 
			
		||||
        UI7::ColorSelector(it.second, edit_theme->GetTableRef()[it.first]);
 | 
			
		||||
      }
 | 
			
		||||
    } else if (menu == 2) {
 | 
			
		||||
      if (UI7::Button("Go back")) {
 | 
			
		||||
        menu = 0;
 | 
			
		||||
      }
 | 
			
		||||
      for (auto& it : theme_list) {
 | 
			
		||||
        if (UI7::Button(it)) {
 | 
			
		||||
          edit_theme->Load(Palladium::GetAppDirectory() + "/themes/" + it);
 | 
			
		||||
          menu = 1;
 | 
			
		||||
        }
 | 
			
		||||
        UI7::SameLine();
 | 
			
		||||
        if (UI7::Button("Make Current")) {
 | 
			
		||||
          edit_theme->Load(Palladium::GetAppDirectory() + "/themes/" + it);
 | 
			
		||||
          temp_theme->CopyOther(edit_theme);
 | 
			
		||||
          menu = 0;
 | 
			
		||||
        }
 | 
			
		||||
        UI7::SameLine();
 | 
			
		||||
        if (UI7::Button("Delete")) {
 | 
			
		||||
          if (std::string(it) != "Palladium.theme") {
 | 
			
		||||
            std::filesystem::remove(Palladium::GetAppDirectory() + "/themes/" +
 | 
			
		||||
                                    it);
 | 
			
		||||
            theme_list.clear();
 | 
			
		||||
            for (const auto& it : std::filesystem::directory_iterator(
 | 
			
		||||
                     Palladium::GetAppDirectory() + "/themes")) {
 | 
			
		||||
              theme_list.push_back(it.path().filename().string());
 | 
			
		||||
            }
 | 
			
		||||
          } else {
 | 
			
		||||
            Palladium::PushMessage("ThemeEditor",
 | 
			
		||||
                                  "Cannot Delete\nPalladium.theme!");
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    UI7::EndMenu();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::ThemeEditor::Logic() {
 | 
			
		||||
  if (kbd_state) {
 | 
			
		||||
    if (kbd_state == PDKeyboardState_Confirm) {
 | 
			
		||||
      auto path =
 | 
			
		||||
          Palladium::GetAppDirectory() + "/themes/" + kbd_text + ".theme";
 | 
			
		||||
      kbd_text = "";
 | 
			
		||||
      if (std::filesystem::exists(path)) {
 | 
			
		||||
        // Prompt Override
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
      edit_theme->Save(path);
 | 
			
		||||
    }
 | 
			
		||||
    kbd_state = PDKeyboardState_None;
 | 
			
		||||
  }
 | 
			
		||||
  if (Hid::IsEvent("cancel", Hid::Down)) {
 | 
			
		||||
    if (menu == 0) {
 | 
			
		||||
      Palladium::Scene::Back();
 | 
			
		||||
    } else {
 | 
			
		||||
      if (menu == 1) edit_theme->CopyOther(temp_theme);
 | 
			
		||||
      menu = 0;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										30
									
								
								source/Time.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								source/Time.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
#include <stdarg.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <time.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <pd/Time.hpp>
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
std::string Palladium::FormatString(std::string fmt_str, ...) {
 | 
			
		||||
  va_list ap;
 | 
			
		||||
  char *fp = NULL;
 | 
			
		||||
  va_start(ap, fmt_str);
 | 
			
		||||
  vasprintf(&fp, fmt_str.c_str(), ap);
 | 
			
		||||
  va_end(ap);
 | 
			
		||||
  std::unique_ptr<char, decltype(free) *> formatted(fp, free);
 | 
			
		||||
  return std::string(formatted.get());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string Palladium::GetTimeStr(void) {
 | 
			
		||||
  time_t unixTime;
 | 
			
		||||
  struct tm timeStruct;
 | 
			
		||||
  time(&unixTime);
 | 
			
		||||
  localtime_r(&unixTime, &timeStruct);
 | 
			
		||||
  return FormatString("%04i-%02i-%02i_%02i-%02i-%02i",
 | 
			
		||||
                      timeStruct.tm_year + 1900, timeStruct.tm_mon + 1,
 | 
			
		||||
                      timeStruct.tm_mday, timeStruct.tm_hour, timeStruct.tm_min,
 | 
			
		||||
                      timeStruct.tm_sec);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										31
									
								
								source/Timer.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								source/Timer.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
			
		||||
#include <pd/Timer.hpp>
 | 
			
		||||
 | 
			
		||||
// Ticks per MSEC
 | 
			
		||||
#define TPMS 268111.856
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
Timer::Timer(bool autostart) {
 | 
			
		||||
  if (autostart) is_running = true;
 | 
			
		||||
  last = svcGetSystemTick();
 | 
			
		||||
  current = last;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Timer::Reset() {
 | 
			
		||||
  last = svcGetSystemTick();
 | 
			
		||||
  current = last;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Timer::Tick() {
 | 
			
		||||
  if (is_running) current = svcGetSystemTick();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Timer::Pause() { is_running = false; }
 | 
			
		||||
 | 
			
		||||
void Timer::Resume() { is_running = true; }
 | 
			
		||||
 | 
			
		||||
bool Timer::Running() { return is_running; }
 | 
			
		||||
 | 
			
		||||
float Timer::Get() { return (float)((current - last) / TPMS); }
 | 
			
		||||
 | 
			
		||||
float Timer::GetLive() { return (float)((svcGetSystemTick() - last) / TPMS); }
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										1254
									
								
								source/UI7.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1254
									
								
								source/UI7.cpp
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										291
									
								
								source/internal_db.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										291
									
								
								source/internal_db.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,291 @@
 | 
			
		||||
#include <arpa/inet.h>
 | 
			
		||||
#include <malloc.h>
 | 
			
		||||
#include <stdarg.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
#include <pd/Error.hpp>
 | 
			
		||||
#include <pd/FileSystem.hpp>
 | 
			
		||||
#include <pd/external/json.hpp>
 | 
			
		||||
#include <pd/internal_db.hpp>
 | 
			
		||||
#include <pd/palladium.hpp>
 | 
			
		||||
 | 
			
		||||
/// Base ///
 | 
			
		||||
PDFlags pd_flags = PDFlags_Default;
 | 
			
		||||
static Palladium::Thread pdi_idb_server;  // Protected
 | 
			
		||||
std::string pdi_app_name;
 | 
			
		||||
std::string pdi_config_path;
 | 
			
		||||
nlohmann::json pdi_config;
 | 
			
		||||
u8 pdi_console_model = 0;
 | 
			
		||||
u8 pdi_system_region = CFG_REGION_USA;
 | 
			
		||||
bool pdi_is_citra = false;
 | 
			
		||||
bool pdi_settings = false;
 | 
			
		||||
NVec2 pdi_hid_touch_pos;
 | 
			
		||||
C2D_TextBuf pdi_text_buffer;
 | 
			
		||||
C2D_Font pdi_base_font;
 | 
			
		||||
C2D_TextBuf pdi_d2_dimbuf;
 | 
			
		||||
bool pdi_is_ndsp = false;
 | 
			
		||||
bool pdi_running = false;
 | 
			
		||||
std::stack<std::unique_ptr<Palladium::Scene>> Palladium::Scene::scenes;
 | 
			
		||||
std::unique_ptr<Palladium::Scene> pdi_fade_scene;
 | 
			
		||||
std::vector<std::unique_ptr<Palladium::Ovl>> pdi_overlays;
 | 
			
		||||
unsigned int pdi_frames = 0;
 | 
			
		||||
u64 pdi_last_time = 0;
 | 
			
		||||
float pdi_framerate = 0.0f;
 | 
			
		||||
u32 pdi_mt_color = 0xaa000000;
 | 
			
		||||
u32 pdi_mt_txtcolor = 0xbbffffff;
 | 
			
		||||
bool pdi_mt_screen;
 | 
			
		||||
float pdi_mt_txtSize;
 | 
			
		||||
bool pdi_metrikd = false;
 | 
			
		||||
bool pdi_ftraced = false;
 | 
			
		||||
u64 pdi_delta_time;
 | 
			
		||||
u64 pdi_last_tm;
 | 
			
		||||
float pdi_dtm;
 | 
			
		||||
float pdi_time;
 | 
			
		||||
bool pdi_fadeout = false, pdi_fadein = false, pdi_fadeout2 = false,
 | 
			
		||||
     pdi_fadein2 = false;
 | 
			
		||||
int pdi_fadealpha = 0;
 | 
			
		||||
int pdi_fadecolor = 0;
 | 
			
		||||
bool pdi_wait_fade = false;
 | 
			
		||||
bool pdi_fade_exit = false;
 | 
			
		||||
bool pdi_fade_scene_wait = false;
 | 
			
		||||
bool pdi_idb_running = false;
 | 
			
		||||
bool pdi_graphics_on = false;
 | 
			
		||||
float pd_draw2_tsm = 1.2f;
 | 
			
		||||
bool pdi_amdt = false;
 | 
			
		||||
void *pdi_soc_buf = nullptr;
 | 
			
		||||
bool pdi_is_am_init = false;
 | 
			
		||||
Palladium::Theme::Ref pdi_active_theme;
 | 
			
		||||
Palladium::LoggerBase::Ref pdi_logger;
 | 
			
		||||
bool pdi_lggrf = false;
 | 
			
		||||
 | 
			
		||||
Palladium::LoggerBase::Ref _pdi_logger() {
 | 
			
		||||
  if (!pdi_logger) {
 | 
			
		||||
    Palladium::Error(
 | 
			
		||||
        "You're trying to use a Palladium Func without Init Palladium!");
 | 
			
		||||
  }
 | 
			
		||||
  return pdi_logger;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Global ///
 | 
			
		||||
// Outdated HidApi (HidV2Patched)
 | 
			
		||||
u32 d7_hDown;
 | 
			
		||||
u32 d7_hHeld;
 | 
			
		||||
u32 d7_hUp;
 | 
			
		||||
u32 d7_hRepeat;  // Inofficial lol
 | 
			
		||||
touchPosition d7_touch;
 | 
			
		||||
 | 
			
		||||
// Modern Global Api
 | 
			
		||||
int pd_max_objects = C2D_DEFAULT_MAX_OBJECTS;
 | 
			
		||||
bool pdi_do_splash = false;
 | 
			
		||||
bool pdi_enable_scene_system = true;
 | 
			
		||||
bool pdi_debugging = false;
 | 
			
		||||
C3D_RenderTarget *pd_top;
 | 
			
		||||
C3D_RenderTarget *pd_top_right;
 | 
			
		||||
C3D_RenderTarget *pd_bottom;
 | 
			
		||||
 | 
			
		||||
Palladium::Net::Error pdi_soc_init() {
 | 
			
		||||
  if (pdi_soc_buf != nullptr) {
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  pdi_soc_buf = memalign(0x1000, 0x100000);
 | 
			
		||||
  if (!pdi_soc_buf) {
 | 
			
		||||
    return Palladium::Net::Error_Memory;
 | 
			
		||||
  }
 | 
			
		||||
  Result ret = socInit((u32 *)pdi_soc_buf, 0x100000);
 | 
			
		||||
  if (R_FAILED(ret)) {
 | 
			
		||||
    free(pdi_soc_buf);
 | 
			
		||||
    return ((static_cast<Palladium::Net::Error>(ret) << 32) |
 | 
			
		||||
            static_cast<Palladium::Net::Error>(Palladium::Net::Error_CtrStatus));
 | 
			
		||||
  }
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void pdi_soc_deinit() {
 | 
			
		||||
  if (pdi_soc_buf) {
 | 
			
		||||
    socExit();
 | 
			
		||||
    free(pdi_soc_buf);
 | 
			
		||||
  }
 | 
			
		||||
  pdi_soc_buf = nullptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class Logger {
 | 
			
		||||
 public:
 | 
			
		||||
  Logger() = default;
 | 
			
		||||
  virtual ~Logger() = default;
 | 
			
		||||
 | 
			
		||||
  static void log(const std::string &prefix, const std::string &message) {
 | 
			
		||||
    std::cout << "[" << prefix << "]: " << message << std::endl;
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define pd_err(x) Logger::log("ERROR", x)
 | 
			
		||||
#define pd_wrn(x) Logger::log("WARNING", x)
 | 
			
		||||
 | 
			
		||||
class tcp_server {
 | 
			
		||||
 public:
 | 
			
		||||
  tcp_server(const std::string &ip, int port) {
 | 
			
		||||
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
 | 
			
		||||
    if (sockfd < 0) {
 | 
			
		||||
      pd_err("Unable to create socket!");
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    server.sin_family = AF_INET;
 | 
			
		||||
    server.sin_port = port;
 | 
			
		||||
    server.sin_addr.s_addr = inet_addr(ip.c_str());
 | 
			
		||||
 | 
			
		||||
    e = bind(sockfd, (struct sockaddr *)&server, sizeof(server));
 | 
			
		||||
    if (e == -1) {
 | 
			
		||||
      pd_err("Unable to bind!");
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    e = listen(sockfd, 10);
 | 
			
		||||
    if (e == 0) {
 | 
			
		||||
      printf("[+]Listening...\n");
 | 
			
		||||
    } else {
 | 
			
		||||
      pd_err("Error in Binding");
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    addr_size = sizeof(new_addr);
 | 
			
		||||
    new_sock = accept(sockfd, (struct sockaddr *)&new_addr, &addr_size);
 | 
			
		||||
    std::cout << "Connected" << std::endl;
 | 
			
		||||
  }
 | 
			
		||||
  ~tcp_server() {
 | 
			
		||||
    // Nothing here
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  bool reconnect() {
 | 
			
		||||
    close(new_sock);
 | 
			
		||||
    new_sock = accept(sockfd, (struct sockaddr *)&new_addr, &addr_size);
 | 
			
		||||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  size_t snd(void *ptr, size_t size) { return send(new_sock, ptr, size, 0); }
 | 
			
		||||
 | 
			
		||||
  size_t rec(void *ptr, size_t size) { return recv(new_sock, ptr, size, 0); }
 | 
			
		||||
 | 
			
		||||
 private:
 | 
			
		||||
  int e, sockfd, new_sock;
 | 
			
		||||
  struct sockaddr_in server, new_addr;
 | 
			
		||||
  socklen_t addr_size;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define stupid(x) &x, sizeof(x)
 | 
			
		||||
#define pdi_reacttion(x)     \
 | 
			
		||||
  {                           \
 | 
			
		||||
    int code = x;             \
 | 
			
		||||
    server.snd(stupid(code)); \
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
struct pak32 {
 | 
			
		||||
  pak32() {}
 | 
			
		||||
  pak32(const std::string &n0, float n1, unsigned char n2, unsigned char n3,
 | 
			
		||||
        bool n4, bool n5, bool n6, float n7, float n8, float n9, float n10,
 | 
			
		||||
        unsigned int n11, unsigned int n12, unsigned int n13,
 | 
			
		||||
        unsigned int n14) {
 | 
			
		||||
    magic = 0x44772277;
 | 
			
		||||
    for (int i = 0; i < 64; i++) app_name[i] = (char)0;
 | 
			
		||||
    int l = n0.length();
 | 
			
		||||
    if (l > 64) l = 64;
 | 
			
		||||
    for (int i = 0; i < l; i++) app_name[i] = n0[i];
 | 
			
		||||
    framerate = n1;
 | 
			
		||||
    console_model = n2;
 | 
			
		||||
    system_region = n3;
 | 
			
		||||
    is_citra = n4;
 | 
			
		||||
    ndsp_support = n5;
 | 
			
		||||
    in_settings = n6;
 | 
			
		||||
    deltatime = n7;
 | 
			
		||||
    rtime = n8;
 | 
			
		||||
    cpu = n9;
 | 
			
		||||
    gpu = n10;
 | 
			
		||||
    mem_alloc = n11;
 | 
			
		||||
    mem_dalloc = n12;
 | 
			
		||||
    mem_ialloc = n13;
 | 
			
		||||
    tbs = n14;
 | 
			
		||||
  }
 | 
			
		||||
  uint32_t magic;
 | 
			
		||||
  char app_name[64];
 | 
			
		||||
  float framerate;
 | 
			
		||||
  unsigned char console_model;
 | 
			
		||||
  unsigned char system_region;
 | 
			
		||||
  bool is_citra;
 | 
			
		||||
  bool ndsp_support;
 | 
			
		||||
  bool in_settings;
 | 
			
		||||
  float deltatime;
 | 
			
		||||
  float rtime;
 | 
			
		||||
  float cpu;
 | 
			
		||||
  float gpu;
 | 
			
		||||
  unsigned int mem_alloc;
 | 
			
		||||
  unsigned int mem_dalloc;
 | 
			
		||||
  unsigned int mem_ialloc;
 | 
			
		||||
  unsigned int tbs;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static bool pdi_idb_fp = false;
 | 
			
		||||
 | 
			
		||||
void KillIdbServer() {
 | 
			
		||||
  pdi_idb_fp = true;
 | 
			
		||||
  pdi_idb_server.join(100);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ServerThread(Palladium::Parameter param) {
 | 
			
		||||
  if (pdi_soc_buf == nullptr) return;
 | 
			
		||||
  pdi_idb_running = true;
 | 
			
		||||
  pdi_idb_fp = false;
 | 
			
		||||
  atexit(KillIdbServer);
 | 
			
		||||
  tcp_server server("0.0.0.0", 4727);
 | 
			
		||||
  int cmd = 0;
 | 
			
		||||
  while (!pdi_idb_fp) {
 | 
			
		||||
    size_t r = server.rec(&cmd, sizeof(int));
 | 
			
		||||
    if (r == 0) {
 | 
			
		||||
      server.reconnect();
 | 
			
		||||
    }
 | 
			
		||||
    if (cmd == 1) {
 | 
			
		||||
      pdi_reacttion(1);
 | 
			
		||||
      auto pak = pak32(
 | 
			
		||||
          pdi_app_name, pdi_framerate, pdi_console_model, pdi_system_region,
 | 
			
		||||
          pdi_is_citra, pdi_is_ndsp, pdi_settings, pdi_dtm, pdi_time,
 | 
			
		||||
          C3D_GetProcessingTime(), C3D_GetDrawingTime(),
 | 
			
		||||
          Palladium::Memory::GetTotalAllocated(),
 | 
			
		||||
          Palladium::Memory::GetTotalFreed(), Palladium::Memory::GetCurrent(),
 | 
			
		||||
          C2D_TextBufGetNumGlyphs(pdi_text_buffer));
 | 
			
		||||
      server.snd(stupid(pak));
 | 
			
		||||
    } else if (cmd == 2) {
 | 
			
		||||
      pdi_reacttion(2);
 | 
			
		||||
      std::vector<Palladium::FileSystem::Entry> el =
 | 
			
		||||
          Palladium::FileSystem::GetDirContent("sdmc:/");
 | 
			
		||||
      size_t buf = el.size() * sizeof(Palladium::FileSystem::Entry);
 | 
			
		||||
      server.snd(stupid(buf));
 | 
			
		||||
      server.snd(el.data(), buf);
 | 
			
		||||
 | 
			
		||||
    } else if (cmd == 3) {
 | 
			
		||||
      pdi_reacttion(3);
 | 
			
		||||
      Palladium::ExitApp();
 | 
			
		||||
      pdi_idb_fp = true;
 | 
			
		||||
    } else {
 | 
			
		||||
      pdi_reacttion(1234);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  pdi_idb_running = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
namespace IDB {
 | 
			
		||||
void Start() {
 | 
			
		||||
  if (pdi_idb_running) return;
 | 
			
		||||
  pdi_idb_server.initialize(ServerThread);
 | 
			
		||||
  pdi_idb_server.start(true);
 | 
			
		||||
}
 | 
			
		||||
void Stop() {
 | 
			
		||||
  if (!pdi_idb_running) return;
 | 
			
		||||
  pdi_idb_fp = true;
 | 
			
		||||
  KillIdbServer();
 | 
			
		||||
}
 | 
			
		||||
void Restart() {
 | 
			
		||||
  Stop();
 | 
			
		||||
  Start();
 | 
			
		||||
}
 | 
			
		||||
}  // namespace IDB
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										118
									
								
								source/lang.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										118
									
								
								source/lang.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,118 @@
 | 
			
		||||
#include <3ds.h>
 | 
			
		||||
 | 
			
		||||
#include <filesystem>
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <pd/lang.hpp>
 | 
			
		||||
 | 
			
		||||
static nlohmann::json appJson;
 | 
			
		||||
 | 
			
		||||
std::string Palladium::Lang::GetSys() {
 | 
			
		||||
  u8 language = 1;
 | 
			
		||||
  CFGU_GetSystemLanguage(&language);
 | 
			
		||||
 | 
			
		||||
  switch (language) {
 | 
			
		||||
    case 0:
 | 
			
		||||
      return "jp";  // Japanese
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    case 1:
 | 
			
		||||
      return "en";  // English
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    case 2:
 | 
			
		||||
      return "fr";  // French
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    case 3:
 | 
			
		||||
      return "de";  // German
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    case 4:
 | 
			
		||||
      return "it";  // Italian
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    case 5:
 | 
			
		||||
      return "es";  // Spanish
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    case 6:
 | 
			
		||||
      return "zh-CN";  // Chinese (Simplified)
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    case 7:
 | 
			
		||||
      return "ko";  // Korean
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    case 8:
 | 
			
		||||
      return "nl";  // Dutch
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    case 9:
 | 
			
		||||
      return "pt";  // Portuguese
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    case 10:
 | 
			
		||||
      return "ru";  // Russian
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    case 11:
 | 
			
		||||
      return "zh-TW";  // Chinese (Traditional)
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
      return "en";  // Fall back to English if missing
 | 
			
		||||
      break;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
std::string Palladium::Lang::Get(const std::string &key) {
 | 
			
		||||
  if (!appJson.contains("keys")) return "ERR-01";
 | 
			
		||||
  nlohmann::json js = appJson["keys"];
 | 
			
		||||
  if (!js.contains(key)) return key;
 | 
			
		||||
  return js.at(key).get<std::string>();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::Lang::Load(const std::string &lang) {
 | 
			
		||||
  std::fstream values;
 | 
			
		||||
  if (std::filesystem::exists("romfs:/lang/" + lang + "/app.json")) {
 | 
			
		||||
    values.open("romfs:/lang/" + lang + "/app.json", std::ios::in);
 | 
			
		||||
    if (values.is_open()) {
 | 
			
		||||
      appJson = nlohmann::json::parse(values);
 | 
			
		||||
    }
 | 
			
		||||
    values.close();
 | 
			
		||||
    if (appJson.is_discarded()) {
 | 
			
		||||
      appJson = {};
 | 
			
		||||
    }
 | 
			
		||||
    return;
 | 
			
		||||
  } else {
 | 
			
		||||
    values.open("romfs:/lang/en/app.json", std::ios::in);
 | 
			
		||||
    if (values.is_open()) {
 | 
			
		||||
      appJson = nlohmann::json::parse(values);
 | 
			
		||||
    }
 | 
			
		||||
    values.close();
 | 
			
		||||
    if (appJson.is_discarded()) {
 | 
			
		||||
      appJson = {};
 | 
			
		||||
    }
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string Palladium::Lang::GetName() {
 | 
			
		||||
  if (!appJson.contains("info")) return "";
 | 
			
		||||
  nlohmann::json js = appJson["info"];
 | 
			
		||||
  if (!js.contains("name")) return "Unknown";
 | 
			
		||||
  return js.at("name").get<std::string>();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string Palladium::Lang::GetAuthor() {
 | 
			
		||||
  if (!appJson.contains("info")) return "";
 | 
			
		||||
  nlohmann::json js = appJson["info"];
 | 
			
		||||
  if (!js.contains("author")) return "Unknown";
 | 
			
		||||
  return js.at("author").get<std::string>();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string Palladium::Lang::GetShortcut() {
 | 
			
		||||
  if (!appJson.contains("info")) return "";
 | 
			
		||||
  nlohmann::json js = appJson["info"];
 | 
			
		||||
  if (!js.contains("shortcut")) return "Unknown";
 | 
			
		||||
  return js.at("shortcut").get<std::string>();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										34
									
								
								source/li7.v.pica
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								source/li7.v.pica
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
; LI7 Shader
 | 
			
		||||
; Constants
 | 
			
		||||
.constf myconst(0.0, 1.0, 0.00392156862745, 0.0)
 | 
			
		||||
.alias  ones  	myconst.yyyy ; Vector full of ones
 | 
			
		||||
 | 
			
		||||
; Uniforms
 | 
			
		||||
.fvec projection[4]
 | 
			
		||||
 | 
			
		||||
; Outputs
 | 
			
		||||
.out out_position		position
 | 
			
		||||
.out out_color			color
 | 
			
		||||
.out out_uv				texcoord0
 | 
			
		||||
 | 
			
		||||
; Inputs
 | 
			
		||||
.alias in_xyz		v0
 | 
			
		||||
.alias in_uvc 		v1
 | 
			
		||||
.alias in_col	    v2
 | 
			
		||||
 | 
			
		||||
.entry vmain
 | 
			
		||||
.proc vmain
 | 
			
		||||
	mov r0.xyz, in_xyz.xyz
 | 
			
		||||
	mov r0.w, ones
 | 
			
		||||
 | 
			
		||||
	dp4 out_position.x, projection[0], r0
 | 
			
		||||
	dp4 out_position.y, projection[1], r0
 | 
			
		||||
	dp4 out_position.z, projection[2], r0
 | 
			
		||||
	dp4 out_position.w, projection[3], r0
 | 
			
		||||
 | 
			
		||||
	mov out_uv, in_uvc.xy
 | 
			
		||||
 | 
			
		||||
	mul r1, myconst.zzzz, in_col
 | 
			
		||||
	mov out_color, r1
 | 
			
		||||
	end
 | 
			
		||||
.end
 | 
			
		||||
							
								
								
									
										117
									
								
								source/nimg.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										117
									
								
								source/nimg.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,117 @@
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <pd/nimg.hpp>
 | 
			
		||||
 | 
			
		||||
// Use an Npi simplifier cause I am lazy
 | 
			
		||||
#define reca_cc(x) reinterpret_cast<const char*>(x)
 | 
			
		||||
#define reca_c(x) reinterpret_cast<char*>(x)
 | 
			
		||||
#define pak32(q, w, e, r)                                             \
 | 
			
		||||
  ((((q) & 0xff) << 0) | (((w) & 0xff) << 8) | (((e) & 0xff) << 16) | \
 | 
			
		||||
   (((r) & 0xff) << 24))
 | 
			
		||||
 | 
			
		||||
// Stupid RLE Algorithm
 | 
			
		||||
void npi_compress(std::vector<unsigned char>& ret,
 | 
			
		||||
                  const std::vector<unsigned char>& in) {
 | 
			
		||||
  unsigned char counter = 1;
 | 
			
		||||
  unsigned char tmp = in[0];
 | 
			
		||||
  for (size_t i = 1; i < in.size(); ++i) {
 | 
			
		||||
    if (tmp == in[i]) {
 | 
			
		||||
      counter++;
 | 
			
		||||
    } else {
 | 
			
		||||
      ret.push_back(counter);
 | 
			
		||||
      ret.push_back(tmp);
 | 
			
		||||
      counter = 1;
 | 
			
		||||
      tmp = in[i];
 | 
			
		||||
    }
 | 
			
		||||
    if (counter == 255) {
 | 
			
		||||
      ret.push_back(counter);
 | 
			
		||||
      ret.push_back(tmp);
 | 
			
		||||
      counter = 0;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  if (counter > 0) {
 | 
			
		||||
    ret.push_back(counter);
 | 
			
		||||
    ret.push_back(tmp);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void npi_decompress(std::vector<unsigned char>& ret,
 | 
			
		||||
                    const std::vector<unsigned char>& in) {
 | 
			
		||||
  // Size is sus
 | 
			
		||||
  if ((in.size() % 2) != 0) return;
 | 
			
		||||
  for (size_t i = 0; i < in.size(); i += 2) {
 | 
			
		||||
    int count = in[i];
 | 
			
		||||
    int value = in[i + 1];
 | 
			
		||||
    for (int c = 0; c < count; c++) {
 | 
			
		||||
      ret.push_back(value);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
nimg NIMG_Load(std::string path) {
 | 
			
		||||
  nimg res;
 | 
			
		||||
  std::ifstream fin(path, std::ios::in | std::ios::binary);
 | 
			
		||||
  // Check magic
 | 
			
		||||
  fin.read(reca_c(&res.magic), sizeof(uint32_t));
 | 
			
		||||
  if (res.magic != NPI_NIMG_) {
 | 
			
		||||
    std::cout << path << " is invalid!" << std::endl;
 | 
			
		||||
    return res;
 | 
			
		||||
  }
 | 
			
		||||
  // Read Information
 | 
			
		||||
  fin.read(reca_c(&res.width), sizeof(int));
 | 
			
		||||
  fin.read(reca_c(&res.height), sizeof(int));
 | 
			
		||||
  fin.read(reca_c(&res.format), sizeof(int));
 | 
			
		||||
  fin.read(reca_c(&res.compression), sizeof(int));
 | 
			
		||||
  // Read Pixeldata
 | 
			
		||||
  if (res.compression == 1) {
 | 
			
		||||
    std::vector<unsigned char> tb;
 | 
			
		||||
    int pb_size = 0;
 | 
			
		||||
    fin.read(reca_c(&pb_size), sizeof(int));
 | 
			
		||||
    tb.resize(pb_size);
 | 
			
		||||
    fin.read(reca_c(tb.data()), pb_size);
 | 
			
		||||
    npi_decompress(res.pixel_buffer, tb);
 | 
			
		||||
  } else {
 | 
			
		||||
    int pb_size = 0;
 | 
			
		||||
    fin.read(reca_c(&pb_size), sizeof(int));
 | 
			
		||||
    res.pixel_buffer.resize(pb_size);
 | 
			
		||||
    fin.read(reca_c(res.pixel_buffer.data()), pb_size);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Close stream
 | 
			
		||||
  fin.close();
 | 
			
		||||
  // Return the loadet imaeg
 | 
			
		||||
  return res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
nimg NIMG_LoadFromMem(unsigned char* buffer, size_t bf_size) { return nimg(); }
 | 
			
		||||
 | 
			
		||||
void NIMG_Save(nimg image, std::string path) {
 | 
			
		||||
  std::ofstream fout(path);
 | 
			
		||||
  // Write Magic
 | 
			
		||||
  fout.write(reca_cc(&image.magic), sizeof(uint32_t));
 | 
			
		||||
  // Write Information
 | 
			
		||||
  fout.write(reca_cc(&image.width), sizeof(int));
 | 
			
		||||
  fout.write(reca_cc(&image.height), sizeof(int));
 | 
			
		||||
  fout.write(reca_cc(&image.format), sizeof(int));
 | 
			
		||||
  fout.write(reca_cc(&image.compression), sizeof(int));
 | 
			
		||||
  std::vector<unsigned char> test;
 | 
			
		||||
  // Write pixels
 | 
			
		||||
  if (image.compression == 1) {
 | 
			
		||||
    std::vector<unsigned char> tb;
 | 
			
		||||
    npi_compress(tb, image.pixel_buffer);
 | 
			
		||||
    int buf_szs = tb.size();
 | 
			
		||||
    fout.write(reca_cc(&buf_szs), sizeof(int));  // buf_size
 | 
			
		||||
    fout.write(reca_cc(tb.data()),
 | 
			
		||||
               tb.size());  // buffer
 | 
			
		||||
  } else {
 | 
			
		||||
    int buf_szs = image.pixel_buffer.size();
 | 
			
		||||
    fout.write(reca_cc(&buf_szs), sizeof(int));  // buf_size
 | 
			
		||||
    fout.write(reca_cc(image.pixel_buffer.data()),
 | 
			
		||||
               image.pixel_buffer.size());  // buffer
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Close stream
 | 
			
		||||
  fout.close();
 | 
			
		||||
}
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										901
									
								
								source/palladium.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										901
									
								
								source/palladium.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,901 @@
 | 
			
		||||
#include <pd/Hid.hpp>  // Integate HidApi
 | 
			
		||||
#include <pd/Message.hpp>
 | 
			
		||||
#include <pd/Overlays.hpp>
 | 
			
		||||
#include <pd/ThemeEditor.hpp>
 | 
			
		||||
#include <pd/UI7.hpp>
 | 
			
		||||
#include <pd/palladium.hpp>
 | 
			
		||||
#include <pd/LI7.hpp>
 | 
			
		||||
 | 
			
		||||
// Config 2
 | 
			
		||||
#include <pd/external/json.hpp>
 | 
			
		||||
#include <pd/internal_db.hpp>
 | 
			
		||||
 | 
			
		||||
// C++ includes
 | 
			
		||||
#include <filesystem>
 | 
			
		||||
#include <random>
 | 
			
		||||
 | 
			
		||||
Palladium::LoggerBase::Ref pdi_glogger;
 | 
			
		||||
extern Palladium::LoggerBase::Ref pdi_logger;
 | 
			
		||||
 | 
			
		||||
static void pdi_ExitHook() {
 | 
			
		||||
  C2D_TextBufDelete(pdi_text_buffer);
 | 
			
		||||
  C2D_TextBufDelete(pdi_d2_dimbuf);
 | 
			
		||||
  romfsExit();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<std::string> string_to_lines(std::string input_str) {
 | 
			
		||||
  std::vector<std::string> lines;
 | 
			
		||||
  std::stringstream ss(input_str);
 | 
			
		||||
  std::string line;
 | 
			
		||||
  while (std::getline(ss, line)) {
 | 
			
		||||
    lines.push_back(line);
 | 
			
		||||
  }
 | 
			
		||||
  return lines;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Npifade() {
 | 
			
		||||
  if (pdi_fadein) {
 | 
			
		||||
    if (pdi_fadealpha < 255) {
 | 
			
		||||
      if ((int)pdi_fadealpha + 3 > 255) {
 | 
			
		||||
        pdi_fadealpha = 255;
 | 
			
		||||
      } else {
 | 
			
		||||
        pdi_fadealpha += 3;
 | 
			
		||||
      }
 | 
			
		||||
    } else {
 | 
			
		||||
      pdi_fadein = false;
 | 
			
		||||
    }
 | 
			
		||||
  } else if (pdi_fadeout) {
 | 
			
		||||
    if (pdi_fadealpha > 0) {
 | 
			
		||||
      if ((int)pdi_fadealpha - 3 < 0) {
 | 
			
		||||
        pdi_fadealpha = 0;
 | 
			
		||||
      } else {
 | 
			
		||||
        pdi_fadealpha -= 3;
 | 
			
		||||
      }
 | 
			
		||||
    } else {
 | 
			
		||||
      pdi_fadeout = false;
 | 
			
		||||
    }
 | 
			
		||||
  } else {
 | 
			
		||||
    if (pdi_wait_fade) pdi_wait_fade = false;
 | 
			
		||||
    if (pdi_fade_exit) pdi_running = false;
 | 
			
		||||
    if (pdi_fade_scene_wait) {
 | 
			
		||||
      Palladium::Scene::scenes.push(std::move(pdi_fade_scene));
 | 
			
		||||
      pdi_fade_scene_wait = false;
 | 
			
		||||
      Palladium::FadeIn();
 | 
			
		||||
    }
 | 
			
		||||
    // No fade
 | 
			
		||||
  }
 | 
			
		||||
  /*if (pdi_fadein || pdi_fadeout) {
 | 
			
		||||
    Palladium::R2::OnScreen(Palladium::R2Screen_Top);
 | 
			
		||||
    Palladium::R2::AddRect(NVec2(0, 0), NVec2(400, 240),
 | 
			
		||||
                            ((pdi_fadealpha << 24) | 0x00000000));
 | 
			
		||||
    Palladium::R2::OnScreen(Palladium::R2Screen_Bottom);
 | 
			
		||||
    Palladium::R2::AddRect(NVec2(0, 0), NVec2(320, 240),
 | 
			
		||||
                            ((pdi_fadealpha << 24) | 0x00000000));
 | 
			
		||||
  }*/
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void pdi_init_input() {
 | 
			
		||||
  Palladium::Hid::RegTouchCoords(pdi_hid_touch_pos);
 | 
			
		||||
  Palladium::Hid::RegKeyDown(d7_hDown);
 | 
			
		||||
  Palladium::Hid::RegKeyHeld(d7_hHeld);
 | 
			
		||||
  Palladium::Hid::RegKeyUp(d7_hUp);
 | 
			
		||||
  Palladium::Hid::RegKeyRepeat(d7_hRepeat);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("touch", KEY_TOUCH);
 | 
			
		||||
  // Default Buttons
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("confirm", KEY_A);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("cancel", KEY_B);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("spec2", KEY_X);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("spec3", KEY_Y);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("options", KEY_SELECT);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("spec1", KEY_START);
 | 
			
		||||
  // Dpad only
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("dright", KEY_DRIGHT);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("dleft", KEY_DLEFT);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("dup", KEY_DUP);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("ddown", KEY_DDOWN);
 | 
			
		||||
  // D + Cpad
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("right", KEY_RIGHT);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("left", KEY_LEFT);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("up", KEY_UP);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("down", KEY_DOWN);
 | 
			
		||||
  // Back keys
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("rt1", KEY_R);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("lt1", KEY_L);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("rt2", KEY_ZL);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("lt2", KEY_ZR);
 | 
			
		||||
  // Key by their names
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("A", KEY_A);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("B", KEY_B);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("X", KEY_X);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("Y", KEY_Y);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("L", KEY_L);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("R", KEY_R);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("ZR", KEY_ZR);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("ZL", KEY_ZL);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("START", KEY_START);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("SELECT", KEY_SELECT);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("DUP", KEY_DUP);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("DDOWN", KEY_DDOWN);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("DLEFT", KEY_DRIGHT);
 | 
			
		||||
  Palladium::Hid::RegKeyEvent("DRIGHT", KEY_DLEFT);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void pdi_init_config() {
 | 
			
		||||
  pdi_config_path = "sdmc:/Palladium/Apps/";
 | 
			
		||||
  pdi_config_path += pdi_app_name;
 | 
			
		||||
  std::filesystem::create_directories(pdi_config_path.c_str());
 | 
			
		||||
  std::filesystem::create_directories("sdmc:/Palladium/Reports");
 | 
			
		||||
  bool renew = false;
 | 
			
		||||
 | 
			
		||||
  if (Palladium::FS::FileExist(pdi_config_path + "/config.rc7")) {
 | 
			
		||||
    std::fstream cfg_ldr(pdi_config_path + "/config.rc7", std::ios::in);
 | 
			
		||||
    cfg_ldr >> pdi_config;
 | 
			
		||||
    cfg_ldr.close();
 | 
			
		||||
    std::string version = pdi_config["info"]["version"].get<std::string>();
 | 
			
		||||
    if (version != CFGVER) renew = true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (!Palladium::FS::FileExist(pdi_config_path + "/config.rc7") || renew) {
 | 
			
		||||
    if (renew) {
 | 
			
		||||
      std::fstream cfg_ldr(pdi_config_path + "/config.rc7", std::ios::in);
 | 
			
		||||
      cfg_ldr >> pdi_config;
 | 
			
		||||
      cfg_ldr.close();
 | 
			
		||||
    }
 | 
			
		||||
    pdi_config.clear();
 | 
			
		||||
    pdi_config["info"]["version"] = CFGVER;
 | 
			
		||||
    pdi_config["info"]["Palladiumver"] = PDVSTRING;
 | 
			
		||||
    pdi_config["metrik-settings"]["show"] = false;
 | 
			
		||||
    pdi_config["metrik-settings"]["Screen"] = true;
 | 
			
		||||
    pdi_config["metrik-settings"]["Text"] = "#ffffffff";
 | 
			
		||||
    pdi_config["metrik-settings"]["Bg"] = "#aa000000";
 | 
			
		||||
    pdi_config["metrik-settings"]["Size"] = 0.7f;
 | 
			
		||||
    pdi_config["internal_logger"]["nowritetxt"] = true;
 | 
			
		||||
    std::fstream cfg_wrt(pdi_config_path + "/config.rc7", std::ios::out);
 | 
			
		||||
    cfg_wrt << pdi_config.dump(4);
 | 
			
		||||
    cfg_wrt.close();
 | 
			
		||||
  }
 | 
			
		||||
  std::fstream cfg_ldr(pdi_config_path + "/config.rc7", std::ios::in);
 | 
			
		||||
  cfg_ldr >> pdi_config;
 | 
			
		||||
  cfg_ldr.close();
 | 
			
		||||
 | 
			
		||||
  pdi_metrikd = pdi_config["metrik-settings"]["show"].get<bool>();
 | 
			
		||||
  pdi_mt_txtSize = pdi_config["metrik-settings"]["Size"].get<float>();
 | 
			
		||||
  pdi_mt_screen = pdi_config["metrik-settings"]["Screen"].get<bool>();
 | 
			
		||||
  pdi_lggrf = pdi_config["internal_logger"]["nowritetxt"].get<bool>();
 | 
			
		||||
 | 
			
		||||
  if (pdi_metrikd)
 | 
			
		||||
    Palladium::AddOvl(std::make_unique<Palladium::Ovl_Metrik>(
 | 
			
		||||
        &pdi_metrikd, &pdi_mt_screen, &pdi_mt_color, &pdi_mt_txtcolor,
 | 
			
		||||
        &pdi_mt_txtSize));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void pdi_init_theme() {
 | 
			
		||||
  if (pdi_config_path == "") {
 | 
			
		||||
    pdi_config_path = "sdmc:/Palladium/Apps/";
 | 
			
		||||
    pdi_config_path += pdi_app_name;
 | 
			
		||||
  }
 | 
			
		||||
  std::string path = pdi_config_path + "/themes";
 | 
			
		||||
  std::filesystem::create_directories(path.c_str());
 | 
			
		||||
  bool renew = false;
 | 
			
		||||
 | 
			
		||||
  if (Palladium::FS::FileExist(path + "/Palladium.theme")) {
 | 
			
		||||
    std::fstream cfg_ldr(path + "/Palladium.theme", std::ios::in);
 | 
			
		||||
    nlohmann::json js;
 | 
			
		||||
    cfg_ldr >> js;
 | 
			
		||||
    cfg_ldr.close();
 | 
			
		||||
    std::string version = js["version"].get<std::string>();
 | 
			
		||||
    if (version != THEMEVER) renew = true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (!Palladium::FS::FileExist(path + "/Palladium.theme") || renew) {
 | 
			
		||||
    pdi_amdt = true;
 | 
			
		||||
    Palladium::ThemeActive()->Save(path + "/Palladium.theme");
 | 
			
		||||
    pdi_amdt = false;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Palladium::LoggerBase::Ref Palladium::Logger() {
 | 
			
		||||
  if (!pdi_glogger) {
 | 
			
		||||
    Palladium::Error("Logger Was Called before being Init!");
 | 
			
		||||
    // return schould not be reached then
 | 
			
		||||
  }
 | 
			
		||||
  return pdi_glogger;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
float Palladium::GetDeltaTime() { return (float)pdi_dtm; }
 | 
			
		||||
 | 
			
		||||
void Palladium::Init::NdspFirm() {
 | 
			
		||||
  if (access("sdmc:/3ds/dspfirm.cdc", F_OK) != -1) {
 | 
			
		||||
    ndspInit();
 | 
			
		||||
    atexit(ndspExit);
 | 
			
		||||
    pdi_is_ndsp = true;
 | 
			
		||||
  } else {
 | 
			
		||||
    Palladium::PushMessage(Palladium::Message(
 | 
			
		||||
        "Palladium", "dspfirm.cdc not found!\nUnable to play sounds!"));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::Scene::doDraw() {
 | 
			
		||||
  Ftrace::ScopedTrace st("pd-core", f2s(Scene::doDraw));
 | 
			
		||||
  if (!Palladium::Scene::scenes.empty()) Palladium::Scene::scenes.top()->Draw();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::Scene::doLogic() {
 | 
			
		||||
  Ftrace::ScopedTrace st("pd-core", f2s(Scene::doLogic));
 | 
			
		||||
  if (!Palladium::Scene::scenes.empty()) Palladium::Scene::scenes.top()->Logic();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::Scene::Load(std::unique_ptr<Scene> scene, bool fade) {
 | 
			
		||||
  if (fade) {
 | 
			
		||||
    Palladium::FadeOut();
 | 
			
		||||
    pdi_fade_scene = std::move(scene);
 | 
			
		||||
    pdi_fade_scene_wait = true;
 | 
			
		||||
  } else
 | 
			
		||||
    Scene::scenes.push(std::move(scene));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::Scene::Back() {
 | 
			
		||||
  if (Palladium::Scene::scenes.size() > 0) Palladium::Scene::scenes.pop();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void frameloop() {
 | 
			
		||||
  pdi_frames++;
 | 
			
		||||
  pdi_delta_time = osGetTime() - pdi_last_time;
 | 
			
		||||
  if (pdi_delta_time >= 1000) {
 | 
			
		||||
    pdi_framerate = pdi_frames / (pdi_delta_time / 1000.0f) + 1;
 | 
			
		||||
    pdi_frames = 0;
 | 
			
		||||
    pdi_last_time = osGetTime();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
float getframerate() { return pdi_framerate; }
 | 
			
		||||
 | 
			
		||||
std::string Palladium::GetFramerate() {
 | 
			
		||||
  return (std::to_string((int)pdi_framerate).substr(0, 2));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Palladium::MainLoop() {
 | 
			
		||||
  Palladium::Ftrace::ScopedTrace st("pd-core", f2s(MainLoop));
 | 
			
		||||
  if (!aptMainLoop()) return false;
 | 
			
		||||
  // Deltatime
 | 
			
		||||
  uint64_t currentTime = svcGetSystemTick();
 | 
			
		||||
  pdi_dtm = ((float)(currentTime / (float)TICKS_PER_MSEC) -
 | 
			
		||||
              (float)(pdi_last_tm / (float)TICKS_PER_MSEC)) /
 | 
			
		||||
             1000.f;
 | 
			
		||||
  pdi_time += pdi_dtm;
 | 
			
		||||
  pdi_last_tm = currentTime;
 | 
			
		||||
 | 
			
		||||
  hidScanInput();
 | 
			
		||||
  d7_hDown = hidKeysDown();
 | 
			
		||||
  d7_hUp = hidKeysUp();
 | 
			
		||||
  d7_hHeld = hidKeysHeld();
 | 
			
		||||
  // Inofficial
 | 
			
		||||
  d7_hRepeat = hidKeysDownRepeat();
 | 
			
		||||
  hidTouchRead(&d7_touch);
 | 
			
		||||
  Hid::Update();
 | 
			
		||||
  pdi_hid_touch_pos = NVec2(d7_touch.px, d7_touch.py);
 | 
			
		||||
 | 
			
		||||
  Palladium::ClearTextBufs();
 | 
			
		||||
  C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
 | 
			
		||||
 | 
			
		||||
  C2D_TargetClear(pd_top, C2D_Color32(0, 0, 0, 0));
 | 
			
		||||
  C2D_TargetClear(pd_bottom, C2D_Color32(0, 0, 0, 0));
 | 
			
		||||
  frameloop();
 | 
			
		||||
  if (pdi_enable_scene_system) {
 | 
			
		||||
    Palladium::Scene::doDraw();
 | 
			
		||||
    Palladium::Scene::doLogic();
 | 
			
		||||
  }
 | 
			
		||||
  return pdi_running;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::ClearTextBufs(void) { C2D_TextBufClear(pdi_text_buffer); }
 | 
			
		||||
 | 
			
		||||
void Palladium::Init::Graphics() {
 | 
			
		||||
  C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
 | 
			
		||||
  C2D_Init((size_t)pd_max_objects);
 | 
			
		||||
  C2D_Prepare();
 | 
			
		||||
  pd_top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT);
 | 
			
		||||
  pd_top_right = C2D_CreateScreenTarget(GFX_TOP, GFX_RIGHT);
 | 
			
		||||
  pd_bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT);
 | 
			
		||||
  pdi_text_buffer = C2D_TextBufNew(4096);
 | 
			
		||||
  pdi_d2_dimbuf = C2D_TextBufNew(4096);
 | 
			
		||||
  pdi_base_font = C2D_FontLoadSystem(CFG_REGION_USA);
 | 
			
		||||
  R2::Init();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Result Palladium::Init::Main(std::string app_name) {
 | 
			
		||||
  Palladium::Ftrace::ScopedTrace st("pd-core", f2s(Init::Main));
 | 
			
		||||
  pdi_app_name = app_name;
 | 
			
		||||
  pdi_logger = LoggerBase::New();
 | 
			
		||||
  pdi_glogger = LoggerBase::New();
 | 
			
		||||
 | 
			
		||||
  pdi_do_splash = (pd_flags & PDFlags_ShowSplash);
 | 
			
		||||
  pdi_enable_scene_system = (pd_flags & PDFlags_SceneSystem);
 | 
			
		||||
  pdi_enable_memtrack = (pd_flags & PDFlags_MemTrack);
 | 
			
		||||
 | 
			
		||||
  gfxInitDefault();
 | 
			
		||||
  atexit(gfxExit);
 | 
			
		||||
  // Speedup
 | 
			
		||||
  osSetSpeedupEnable(true);
 | 
			
		||||
  // consoleInit(GFX_TOP, NULL);
 | 
			
		||||
  cfguInit();
 | 
			
		||||
  atexit(cfguExit);
 | 
			
		||||
  CFGU_SecureInfoGetRegion(&pdi_system_region);
 | 
			
		||||
  CFGU_GetSystemModel(&pdi_console_model);
 | 
			
		||||
 | 
			
		||||
  aptInit();
 | 
			
		||||
  atexit(aptExit);
 | 
			
		||||
  romfsInit();
 | 
			
		||||
 | 
			
		||||
  pdi_init_config();
 | 
			
		||||
  _pdi_logger()->Init("Palladium", pdi_lggrf);
 | 
			
		||||
 | 
			
		||||
  pdi_active_theme = Theme::New();
 | 
			
		||||
  pdi_active_theme->Default();
 | 
			
		||||
 | 
			
		||||
  auto ret = pdi_soc_init();
 | 
			
		||||
  if (ret) {
 | 
			
		||||
    pdi_logger->Write("Failed to Init Soc!");
 | 
			
		||||
    Palladium::PushMessage("Palladium", "Failed to\nInit Soc!");
 | 
			
		||||
  } else {
 | 
			
		||||
    atexit(pdi_soc_deinit);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (R_SUCCEEDED(amInit())) {
 | 
			
		||||
    atexit(amExit);
 | 
			
		||||
    pdi_is_am_init = true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Hardware::Initialisize();
 | 
			
		||||
 | 
			
		||||
  C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
 | 
			
		||||
  atexit(C3D_Fini);
 | 
			
		||||
  C2D_Init((size_t)pd_max_objects);
 | 
			
		||||
  atexit(C2D_Fini);
 | 
			
		||||
  atexit(pdi_ExitHook);
 | 
			
		||||
  C2D_Prepare();
 | 
			
		||||
  pd_top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT);
 | 
			
		||||
  pd_top_right = C2D_CreateScreenTarget(GFX_TOP, GFX_RIGHT);
 | 
			
		||||
  pd_bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT);
 | 
			
		||||
  pdi_text_buffer = C2D_TextBufNew(4096);
 | 
			
		||||
  pdi_d2_dimbuf = C2D_TextBufNew(4096);
 | 
			
		||||
  pdi_base_font = C2D_FontLoadSystem(CFG_REGION_USA);
 | 
			
		||||
  R2::Init();
 | 
			
		||||
 | 
			
		||||
  pdi_graphics_on = true;
 | 
			
		||||
  pdi_last_tm = svcGetSystemTick();
 | 
			
		||||
 | 
			
		||||
  pdi_init_input();
 | 
			
		||||
  pdi_init_theme();
 | 
			
		||||
  UI7::Init();
 | 
			
		||||
  atexit(UI7::Deinit);
 | 
			
		||||
  pdi_running = true;
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Result Palladium::Init::Minimal(std::string app_name) {
 | 
			
		||||
  Palladium::Ftrace::ScopedTrace st("pd-core", f2s(Init::Minimal));
 | 
			
		||||
  pdi_app_name = app_name;
 | 
			
		||||
  pdi_logger = LoggerBase::New();
 | 
			
		||||
  pdi_glogger = LoggerBase::New();
 | 
			
		||||
 | 
			
		||||
  pdi_do_splash = (pd_flags & PDFlags_ShowSplash);
 | 
			
		||||
  pdi_enable_scene_system = (pd_flags & PDFlags_SceneSystem);
 | 
			
		||||
  pdi_enable_memtrack = (pd_flags & PDFlags_MemTrack);
 | 
			
		||||
 | 
			
		||||
  gfxInitDefault();
 | 
			
		||||
  atexit(gfxExit);
 | 
			
		||||
  romfsInit();
 | 
			
		||||
 | 
			
		||||
  pdi_init_config();
 | 
			
		||||
  _pdi_logger()->Init("Palladium", pdi_lggrf);
 | 
			
		||||
 | 
			
		||||
  pdi_active_theme = Theme::New();
 | 
			
		||||
  pdi_active_theme->Default();
 | 
			
		||||
 | 
			
		||||
  auto ret = pdi_soc_init();
 | 
			
		||||
  if (ret) {
 | 
			
		||||
    pdi_logger->Write("Failed to Init Soc!");
 | 
			
		||||
    Palladium::PushMessage("Palladium", "Failed to\nInit Soc!");
 | 
			
		||||
  } else {
 | 
			
		||||
    atexit(pdi_soc_deinit);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (R_SUCCEEDED(amInit())) {
 | 
			
		||||
    atexit(amExit);
 | 
			
		||||
    pdi_is_am_init = true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Hardware::Initialisize();
 | 
			
		||||
 | 
			
		||||
  osSetSpeedupEnable(true);
 | 
			
		||||
  C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
 | 
			
		||||
  atexit(C3D_Fini);
 | 
			
		||||
  C2D_Init((size_t)pd_max_objects);
 | 
			
		||||
  atexit(C2D_Fini);
 | 
			
		||||
  atexit(pdi_ExitHook);
 | 
			
		||||
  C2D_Prepare();
 | 
			
		||||
  pd_top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT);
 | 
			
		||||
  pd_top_right = C2D_CreateScreenTarget(GFX_TOP, GFX_RIGHT);
 | 
			
		||||
  pd_bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT);
 | 
			
		||||
  pdi_text_buffer = C2D_TextBufNew(4096);
 | 
			
		||||
  pdi_d2_dimbuf = C2D_TextBufNew(4096);
 | 
			
		||||
  pdi_base_font = C2D_FontLoadSystem(CFG_REGION_USA);
 | 
			
		||||
  R2::Init();
 | 
			
		||||
 | 
			
		||||
  pdi_graphics_on = true;
 | 
			
		||||
 | 
			
		||||
  // Check if citra
 | 
			
		||||
  s64 citracheck = 0;
 | 
			
		||||
  svcGetSystemInfo(&citracheck, 0x20000, 0);
 | 
			
		||||
  pdi_is_citra = citracheck ? true : false;
 | 
			
		||||
 | 
			
		||||
  pdi_init_input();
 | 
			
		||||
  pdi_init_theme();
 | 
			
		||||
  UI7::Init();
 | 
			
		||||
  atexit(UI7::Deinit);
 | 
			
		||||
  pdi_running = true;
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Result Palladium::Init::Reload() {
 | 
			
		||||
  pdi_graphics_on = false;
 | 
			
		||||
  C2D_TextBufDelete(pdi_text_buffer);
 | 
			
		||||
  C2D_Fini();
 | 
			
		||||
  C3D_Fini();
 | 
			
		||||
  C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
 | 
			
		||||
  C2D_Init((size_t)pd_max_objects);
 | 
			
		||||
  C2D_Prepare();
 | 
			
		||||
  pd_top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT);
 | 
			
		||||
  pd_top_right = C2D_CreateScreenTarget(GFX_TOP, GFX_RIGHT);
 | 
			
		||||
  pd_bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT);
 | 
			
		||||
  pdi_text_buffer = C2D_TextBufNew(4096);
 | 
			
		||||
  pdi_base_font = C2D_FontLoadSystem(CFG_REGION_USA);
 | 
			
		||||
  R2::Init();
 | 
			
		||||
  pdi_graphics_on = true;
 | 
			
		||||
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::ExitApp() {
 | 
			
		||||
  if (pdi_wait_fade) {
 | 
			
		||||
    pdi_fade_exit = true;
 | 
			
		||||
  } else
 | 
			
		||||
    pdi_running = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Palladium::GetRandomInt(int b, int e) {
 | 
			
		||||
  std::default_random_engine generator;
 | 
			
		||||
  std::uniform_int_distribution<int> distribution(b, e);
 | 
			
		||||
  int r = distribution(generator);
 | 
			
		||||
  return r;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Palladium::FS::FileExist(const std::string &path) {
 | 
			
		||||
  return std::filesystem::exists(path) &&
 | 
			
		||||
         std::filesystem::is_regular_file(path);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Palladium::GetFps() { return (int)pdi_framerate; }
 | 
			
		||||
 | 
			
		||||
bool Palladium::IsNdspInit() { return pdi_is_ndsp; }
 | 
			
		||||
 | 
			
		||||
void OvlHandler() {
 | 
			
		||||
  Palladium::Ftrace::ScopedTrace st("pd-core", f2s(OvlHandler));
 | 
			
		||||
  for (size_t i = 0; i < pdi_overlays.size(); i++) {
 | 
			
		||||
    pdi_overlays[i]->Draw();
 | 
			
		||||
    pdi_overlays[i]->Logic();
 | 
			
		||||
    if (pdi_overlays[i]->IsKilled())
 | 
			
		||||
      pdi_overlays.erase(pdi_overlays.begin() + i);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::FrameEnd() {
 | 
			
		||||
  Ftrace::ScopedTrace st("pd-core", f2s(FrameEnd));
 | 
			
		||||
  C3D_FrameBegin(2);
 | 
			
		||||
  if (!pdi_enable_scene_system && pdi_settings) {
 | 
			
		||||
    Palladium::Scene::doDraw();
 | 
			
		||||
    Palladium::Scene::doLogic();
 | 
			
		||||
  }
 | 
			
		||||
  UI7::Update();
 | 
			
		||||
  UI7::Debug();
 | 
			
		||||
  Palladium::ProcessMessages();
 | 
			
		||||
  OvlHandler();
 | 
			
		||||
  Npifade();
 | 
			
		||||
  R2::Process();
 | 
			
		||||
  C3D_FrameEnd(0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Palladium::RSettings::RSettings() {
 | 
			
		||||
  // Palladium Settings is designed for
 | 
			
		||||
  // System Font
 | 
			
		||||
  R2::DefaultFont();
 | 
			
		||||
  tmp_txt = R2::GetTextSize();
 | 
			
		||||
  R2::DefaultTextSize();
 | 
			
		||||
  Palladium::FadeIn();
 | 
			
		||||
  std::fstream cfg_ldr(pdi_config_path + "/config.rc7", std::ios::in);
 | 
			
		||||
  cfg_ldr >> pdi_config;
 | 
			
		||||
  cfg_ldr.close();
 | 
			
		||||
  pdi_settings = true;
 | 
			
		||||
  statemtold = pdi_metrikd;
 | 
			
		||||
  stateftold = pdi_ftraced;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Palladium::RSettings::~RSettings() { R2::SetTextSize(tmp_txt); }
 | 
			
		||||
 | 
			
		||||
std::vector<std::string> StrHelper(std::string input) {
 | 
			
		||||
  std::string ss(input);
 | 
			
		||||
  std::istringstream in(ss);
 | 
			
		||||
  std::vector<std::string> test1;
 | 
			
		||||
 | 
			
		||||
  std::copy(std::istream_iterator<std::string>(in),
 | 
			
		||||
            std::istream_iterator<std::string>(), std::back_inserter(test1));
 | 
			
		||||
  return test1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::RSettings::Draw(void) const {
 | 
			
		||||
  if (m_state == RSETTINGS) {
 | 
			
		||||
    Palladium::R2::OnScreen(R2Screen_Top);
 | 
			
		||||
    if (UI7::BeginMenu("Palladium -> Settings")) {
 | 
			
		||||
      UI7::SetCursorPos(NVec2(395, 2));
 | 
			
		||||
      UI7::Label(PDVSTRING, PDTextFlags_AlignRight);
 | 
			
		||||
      UI7::RestoreCursor();
 | 
			
		||||
      UI7::Label("Config Version: " + std::string(CFGVER));
 | 
			
		||||
      UI7::Label("App: " + pdi_app_name);
 | 
			
		||||
      UI7::Label("Palladium: " + std::string(PDVSTRING));
 | 
			
		||||
      UI7::Label("Citra: " + std::string(pdi_is_citra ? "true" : "false"));
 | 
			
		||||
      UI7::Label("Current: " + std::to_string(Palladium::Memory::GetCurrent()) +
 | 
			
		||||
                 "b");
 | 
			
		||||
      UI7::Label("Delta: " + std::to_string(Palladium::GetDeltaTime()));
 | 
			
		||||
      UI7::Label("Kbd test: " + kbd_test);
 | 
			
		||||
      UI7::EndMenu();
 | 
			
		||||
    }
 | 
			
		||||
    Palladium::R2::OnScreen(R2Screen_Bottom);
 | 
			
		||||
    if (UI7::BeginMenu("Press \uE001 to go back!")) {
 | 
			
		||||
      if (UI7::Button("FTrace")) {
 | 
			
		||||
        shared_request[0x00000001] = RFTRACE;
 | 
			
		||||
      }
 | 
			
		||||
      if (UI7::Button("UI7")) {
 | 
			
		||||
        shared_request[0x00000001] = RUI7;
 | 
			
		||||
      }
 | 
			
		||||
      if (UI7::Button("Overlays")) {
 | 
			
		||||
        shared_request[0x00000001] = ROVERLAYS;
 | 
			
		||||
      }
 | 
			
		||||
      if (UI7::Button("IDB")) {
 | 
			
		||||
        shared_request[0x00000001] = RIDB;
 | 
			
		||||
      }
 | 
			
		||||
      if (UI7::Button("ThemeEditor")) {
 | 
			
		||||
        Palladium::LoadThemeEditor();
 | 
			
		||||
      }
 | 
			
		||||
      if (UI7::Button("Logs")) {
 | 
			
		||||
        shared_request[0x00000001] = RLOGS;
 | 
			
		||||
      }
 | 
			
		||||
      UI7::SameLine();
 | 
			
		||||
      UI7::Checkbox("No File", pdi_lggrf);
 | 
			
		||||
      if (UI7::Button("Back")) {
 | 
			
		||||
        shared_request[0x00000002] = 1U;
 | 
			
		||||
      }
 | 
			
		||||
      if (UI7::Button("Keyboard")) {
 | 
			
		||||
        shared_request[0x00000003] = 1U;
 | 
			
		||||
      }
 | 
			
		||||
      UI7::EndMenu();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  } else if (m_state == RIDB) {
 | 
			
		||||
    Palladium::R2::OnScreen(R2Screen_Top);
 | 
			
		||||
    if (UI7::BeginMenu("Palladium -> Debugger")) {
 | 
			
		||||
      UI7::SetCursorPos(NVec2(395, 2));
 | 
			
		||||
      UI7::Label(PDVSTRING, PDTextFlags_AlignRight);
 | 
			
		||||
      UI7::RestoreCursor();
 | 
			
		||||
      UI7::Label("Server Running: " +
 | 
			
		||||
                 std::string(pdi_idb_running ? "true" : "false"));
 | 
			
		||||
      UI7::EndMenu();
 | 
			
		||||
    }
 | 
			
		||||
    Palladium::R2::OnScreen(R2Screen_Bottom);
 | 
			
		||||
    if (UI7::BeginMenu("Press \uE001 to go back!")) {
 | 
			
		||||
      if (UI7::Button("Start Server")) {
 | 
			
		||||
        Palladium::IDB::Start();
 | 
			
		||||
      }
 | 
			
		||||
      UI7::SameLine();
 | 
			
		||||
      if (UI7::Button("Stop Server")) {
 | 
			
		||||
        Palladium::IDB::Stop();
 | 
			
		||||
      }
 | 
			
		||||
      UI7::SameLine();
 | 
			
		||||
      if (UI7::Button("Restart Server")) {
 | 
			
		||||
        Palladium::IDB::Restart();
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      UI7::EndMenu();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  } else if (m_state == RFTRACE) {
 | 
			
		||||
    Palladium::R2::OnScreen(R2Screen_Top);
 | 
			
		||||
    // Draw Top Screen Into Background DrawList
 | 
			
		||||
    UI7::GetBackgroundList()->AddRectangle(NVec2(0, 0), NVec2(400, 240),
 | 
			
		||||
                                           PDColor_Background);
 | 
			
		||||
    UI7::GetBackgroundList()->AddRectangle(NVec2(0, 0), NVec2(400, 20),
 | 
			
		||||
                                           PDColor_Header);
 | 
			
		||||
    UI7::GetBackgroundList()->AddText(
 | 
			
		||||
        NVec2(5, 2), "Palladium -> FTrace",
 | 
			
		||||
        Palladium::ThemeActive()->AutoText(PDColor_Header));
 | 
			
		||||
    UI7::GetBackgroundList()->AddText(
 | 
			
		||||
        NVec2(395, 2), PDVSTRING,
 | 
			
		||||
        Palladium::ThemeActive()->AutoText(PDColor_Header),
 | 
			
		||||
        PDTextFlags_AlignRight);
 | 
			
		||||
    UI7::GetBackgroundList()->AddRectangle(
 | 
			
		||||
        NVec2(0, 220), NVec2(400, 20),
 | 
			
		||||
        Palladium::ThemeActive()->Get(PDColor_Header));
 | 
			
		||||
    UI7::GetBackgroundList()->AddText(
 | 
			
		||||
        NVec2(5, 222),
 | 
			
		||||
        "Traces: " + std::to_string(ftrace_index + 1) + "/" +
 | 
			
		||||
            std::to_string(Palladium::Ftrace::pd_traces.size()),
 | 
			
		||||
        Palladium::ThemeActive()->AutoText(PDColor_Header));
 | 
			
		||||
    UI7::GetBackgroundList()->AddRectangle(NVec2(0, 20), NVec2(400, 20),
 | 
			
		||||
                                           PDColor_TextDisabled);
 | 
			
		||||
    UI7::GetBackgroundList()->AddText(
 | 
			
		||||
        NVec2(5, 22),
 | 
			
		||||
        "Function:", Palladium::ThemeActive()->AutoText(PDColor_TextDisabled));
 | 
			
		||||
    UI7::GetBackgroundList()->AddText(
 | 
			
		||||
        NVec2(395, 22),
 | 
			
		||||
        "Time (ms):", Palladium::ThemeActive()->AutoText(PDColor_TextDisabled),
 | 
			
		||||
        PDTextFlags_AlignRight);
 | 
			
		||||
 | 
			
		||||
    // List Bg
 | 
			
		||||
    for (int i = 0; i < 12; i++) {
 | 
			
		||||
      if ((i % 2 == 0))
 | 
			
		||||
        UI7::GetBackgroundList()->AddRectangle(NVec2(0, 40 + (i) * 15),
 | 
			
		||||
                                               NVec2(400, 15), PDColor_List0);
 | 
			
		||||
      else
 | 
			
		||||
        UI7::GetBackgroundList()->AddRectangle(NVec2(0, 40 + (i) * 15),
 | 
			
		||||
                                               NVec2(400, 15), PDColor_List1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Palladium::Ftrace::Beg("PDft", "display_traces");
 | 
			
		||||
    int start_index = ftrace_index < 11 ? 0 : ftrace_index - 11;
 | 
			
		||||
    auto it = Palladium::Ftrace::pd_traces.begin();
 | 
			
		||||
    std::advance(it, start_index);
 | 
			
		||||
    int ix = start_index;
 | 
			
		||||
    std::string _fkey__ = "0";
 | 
			
		||||
 | 
			
		||||
    while (ix < (int)Palladium::Ftrace::pd_traces.size() &&
 | 
			
		||||
           ix < start_index + 10 && it != Palladium::Ftrace::pd_traces.end()) {
 | 
			
		||||
      if (ix == ftrace_index) {
 | 
			
		||||
        _fkey__ = it->first;
 | 
			
		||||
        UI7::GetBackgroundList()->AddRectangle(
 | 
			
		||||
            NVec2(0, 40 + (ix - start_index) * 15), NVec2(400, 15),
 | 
			
		||||
            PDColor_Selector);
 | 
			
		||||
      }
 | 
			
		||||
      auto clr = ix == ftrace_index
 | 
			
		||||
                     ? PDColor_Selector
 | 
			
		||||
                     : (ix % 2 == 0 ? PDColor_List0 : PDColor_List1);
 | 
			
		||||
      UI7::GetBackgroundList()->AddText(NVec2(5, 40 + (ix - start_index) * 15),
 | 
			
		||||
                                        it->second.func_name,
 | 
			
		||||
                                        Palladium::ThemeActive()->AutoText(clr));
 | 
			
		||||
      UI7::GetBackgroundList()->AddText(
 | 
			
		||||
          NVec2(395, 40 + (ix - start_index) * 15),
 | 
			
		||||
          Palladium::MsTimeFmt(it->second.time_of),
 | 
			
		||||
          Palladium::ThemeActive()->AutoText(clr), PDTextFlags_AlignRight);
 | 
			
		||||
      ++it;
 | 
			
		||||
      ++ix;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Palladium::Ftrace::End("PDft", "display_traces");
 | 
			
		||||
 | 
			
		||||
    Palladium::R2::OnScreen(R2Screen_Bottom);
 | 
			
		||||
    if (UI7::BeginMenu("Press \uE001 to go back!")) {
 | 
			
		||||
      auto jt = Palladium::Ftrace::pd_traces.begin();
 | 
			
		||||
      std::advance(jt, ftrace_index);
 | 
			
		||||
      UI7::Label("Group: " + jt->second.group);
 | 
			
		||||
      UI7::Label("Function: " + jt->second.func_name);
 | 
			
		||||
      UI7::Checkbox("In Overlay", jt->second.is_ovl);
 | 
			
		||||
      UI7::Label("Time: " + Palladium::MsTimeFmt(jt->second.time_of));
 | 
			
		||||
      UI7::Label("Max: " + Palladium::MsTimeFmt(jt->second.time_ofm));
 | 
			
		||||
      UI7::Label("TS: " + std::to_string(jt->second.time_start));
 | 
			
		||||
      UI7::Label("TE: " + std::to_string(jt->second.time_end));
 | 
			
		||||
      UI7::Label("SVC_Stk: " + std::to_string(svcGetSystemTick()));
 | 
			
		||||
      UI7::EndMenu();
 | 
			
		||||
    }
 | 
			
		||||
  } else if (m_state == RUI7) {
 | 
			
		||||
    Palladium::R2::OnScreen(R2Screen_Top);
 | 
			
		||||
    if (UI7::BeginMenu("Palladium -> UI7")) {
 | 
			
		||||
      UI7::SetCursorPos(NVec2(395, 2));
 | 
			
		||||
      UI7::Label(PDVSTRING, PDTextFlags_AlignRight);
 | 
			
		||||
      UI7::RestoreCursor();
 | 
			
		||||
      UI7::Label("Time: " + std::to_string(UI7::GetTime()));
 | 
			
		||||
      UI7::Label("Delta: " + std::to_string(UI7::GetDeltaTime() * 1000.f));
 | 
			
		||||
      UI7::Label("Hid Down Touch: " +
 | 
			
		||||
                 std::to_string(Hid::IsEvent("touch", Hid::Down)));
 | 
			
		||||
      UI7::Label("Hid Held Touch: " +
 | 
			
		||||
                 std::to_string(Hid::IsEvent("touch", Hid::Held)));
 | 
			
		||||
      UI7::Label("Hid Up Touch: " +
 | 
			
		||||
                 std::to_string(Hid::IsEvent("touch", Hid::Up)));
 | 
			
		||||
      UI7::Label("Touch Pos: " + std::to_string(Hid::GetTouchPosition().x) +
 | 
			
		||||
                 ", " + std::to_string(Hid::GetTouchPosition().y));
 | 
			
		||||
      UI7::Label(
 | 
			
		||||
          "Touch Last Pos: " + std::to_string(Hid::GetLastTouchPosition().x) +
 | 
			
		||||
          ", " + std::to_string(Hid::GetLastTouchPosition().y));
 | 
			
		||||
      UI7::Label(
 | 
			
		||||
          "Touch Down Pos: " + std::to_string(Hid::GetTouchDownPosition().x) +
 | 
			
		||||
          ", " + std::to_string(Hid::GetTouchDownPosition().y));
 | 
			
		||||
      UI7::EndMenu();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Palladium::R2::OnScreen(R2Screen_Bottom);
 | 
			
		||||
    if (UI7::BeginMenu("Press \uE001 to go back!", NVec2(),
 | 
			
		||||
                       UI7MenuFlags_Scrolling)) {
 | 
			
		||||
      if (UI7::Button("Go back")) {
 | 
			
		||||
        /// Request a state switch to state RSETTINGS
 | 
			
		||||
        shared_request[0x00000001] = RSETTINGS;
 | 
			
		||||
      }
 | 
			
		||||
      UI7::Checkbox("Debug", UI7::IsDebugging());
 | 
			
		||||
      UI7::Checkbox("ShowMenuInfo", UI7::DebugMenu());
 | 
			
		||||
      UI7::EndMenu();
 | 
			
		||||
    }
 | 
			
		||||
  } else if (m_state == ROVERLAYS) {
 | 
			
		||||
    Palladium::R2::OnScreen(R2Screen_Top);
 | 
			
		||||
    if (UI7::BeginMenu("Palladium -> Overlays")) {
 | 
			
		||||
      UI7::SetCursorPos(NVec2(395, 2));
 | 
			
		||||
      UI7::Label(PDVSTRING, PDTextFlags_AlignRight);
 | 
			
		||||
      UI7::RestoreCursor();
 | 
			
		||||
      UI7::Label("Metrik Overlay: " + mtovlstate);
 | 
			
		||||
      UI7::Label("Metrik Screen: " + mtscreenstate);
 | 
			
		||||
      UI7::EndMenu();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Palladium::R2::OnScreen(R2Screen_Bottom);
 | 
			
		||||
    if (UI7::BeginMenu("Press \uE001 to go back!")) {
 | 
			
		||||
      UI7::Label("Metrik:");
 | 
			
		||||
      UI7::Checkbox("Enable Overlay", pdi_metrikd);
 | 
			
		||||
      UI7::Checkbox("Bottom Screen", pdi_mt_screen);
 | 
			
		||||
      UI7::Label("FTrace:");
 | 
			
		||||
      UI7::Checkbox("Enable Overlay", pdi_ftraced);
 | 
			
		||||
      UI7::SetCursorPos(NVec2(5, 215));
 | 
			
		||||
      if (UI7::Button("Go back")) {
 | 
			
		||||
        /// Request a state switch to state RSETTINGS
 | 
			
		||||
        shared_request[0x00000001] = RSETTINGS;
 | 
			
		||||
      }
 | 
			
		||||
      UI7::EndMenu();
 | 
			
		||||
    }
 | 
			
		||||
  } else if (m_state == RLOGS) {
 | 
			
		||||
    Palladium::R2::OnScreen(R2Screen_Top);
 | 
			
		||||
    if (UI7::BeginMenu("Palladium -> Logs")) {
 | 
			
		||||
      UI7::SetCursorPos(NVec2(395, 2));
 | 
			
		||||
      UI7::Label(PDVSTRING, PDTextFlags_AlignRight);
 | 
			
		||||
      UI7::RestoreCursor();
 | 
			
		||||
      UI7::EndMenu();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Palladium::R2::OnScreen(R2Screen_Bottom);
 | 
			
		||||
    if (UI7::BeginMenu("Press \uE001 to go back!", NVec2(),
 | 
			
		||||
                       UI7MenuFlags_Scrolling)) {
 | 
			
		||||
      for (auto &it : pdi_logger->Lines()) UI7::Label(it, PDTextFlags_Wrap);
 | 
			
		||||
      UI7::EndMenu();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::RSettings::Logic() {
 | 
			
		||||
  /// Requests
 | 
			
		||||
  for (const auto &it : shared_request) {
 | 
			
		||||
    if (it.first == 0x00000001) {
 | 
			
		||||
      m_state = (RState)it.second;
 | 
			
		||||
    } else if (it.first == 0x00000002) {
 | 
			
		||||
      if (it.second) {
 | 
			
		||||
        std::fstream cfg_wrt(pdi_config_path + "/config.rc7", std::ios::out);
 | 
			
		||||
        pdi_config["metrik-settings"]["enableoverlay"] = pdi_metrikd;
 | 
			
		||||
        pdi_config["metrik-settings"]["Screen"] = pdi_mt_screen;
 | 
			
		||||
        pdi_config["internal_logger"]["nowritetxt"] = pdi_lggrf;
 | 
			
		||||
        cfg_wrt << pdi_config.dump(4);
 | 
			
		||||
        cfg_wrt.close();
 | 
			
		||||
        pdi_settings = false;
 | 
			
		||||
        Hid::Clear();
 | 
			
		||||
        Palladium::Scene::Back();
 | 
			
		||||
        // Instant break logic or it will crash
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
    } else if (it.first == 0x00000003) {
 | 
			
		||||
      if (it.second)
 | 
			
		||||
        Palladium::AddOvl(std::make_unique<Ovl_Keyboard>(kbd_test, kbd_state));
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  /// Clear if handled
 | 
			
		||||
  shared_request.clear();
 | 
			
		||||
 | 
			
		||||
  if (statemtold != pdi_metrikd && pdi_metrikd == true)
 | 
			
		||||
    Palladium::AddOvl(std::make_unique<Ovl_Metrik>(
 | 
			
		||||
        &pdi_metrikd, &pdi_mt_screen, &pdi_mt_color, &pdi_mt_txtcolor,
 | 
			
		||||
        &pdi_mt_txtSize));
 | 
			
		||||
  statemtold = pdi_metrikd;
 | 
			
		||||
  if (stateftold != pdi_ftraced && pdi_ftraced == true)
 | 
			
		||||
    Palladium::AddOvl(std::make_unique<Ovl_Ftrace>(&pdi_ftraced));
 | 
			
		||||
  stateftold = pdi_ftraced;
 | 
			
		||||
 | 
			
		||||
  if (m_state == RSETTINGS) {
 | 
			
		||||
    if (d7_hDown & KEY_B) {
 | 
			
		||||
      std::fstream cfg_wrt(pdi_config_path + "/config.rc7", std::ios::out);
 | 
			
		||||
      pdi_config["metrik-settings"]["enableoverlay"] = pdi_metrikd;
 | 
			
		||||
      pdi_config["metrik-settings"]["Screen"] = pdi_mt_screen;
 | 
			
		||||
      pdi_config["internal_logger"]["nowritetxt"] = pdi_lggrf;
 | 
			
		||||
      cfg_wrt << pdi_config.dump(4);
 | 
			
		||||
      cfg_wrt.close();
 | 
			
		||||
      pdi_settings = false;
 | 
			
		||||
      Hid::Clear();
 | 
			
		||||
      Palladium::Scene::Back();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  if (m_state == RUI7) {
 | 
			
		||||
    if (d7_hDown & KEY_B) {
 | 
			
		||||
      m_state = RSETTINGS;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  if (m_state == ROVERLAYS) {
 | 
			
		||||
    mtovlstate = pdi_metrikd ? "true" : "false";
 | 
			
		||||
    mtscreenstate = pdi_mt_screen ? "Bottom" : "Top";
 | 
			
		||||
    if (d7_hDown & KEY_B) {
 | 
			
		||||
      m_state = RSETTINGS;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  if (m_state == RIDB || m_state == RLOGS) {
 | 
			
		||||
    if (d7_hDown & KEY_B) {
 | 
			
		||||
      m_state = RSETTINGS;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  if (m_state == RFTRACE) {
 | 
			
		||||
    if (d7_hDown & KEY_DOWN) {
 | 
			
		||||
      if (ftrace_index < (int)Palladium::Ftrace::pd_traces.size() - 1)
 | 
			
		||||
        ftrace_index++;
 | 
			
		||||
    }
 | 
			
		||||
    if (d7_hDown & KEY_UP) {
 | 
			
		||||
      if (ftrace_index > 0) ftrace_index--;
 | 
			
		||||
    }
 | 
			
		||||
    if (d7_hDown & KEY_B) {
 | 
			
		||||
      m_state = RSETTINGS;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::LoadSettings() {
 | 
			
		||||
  if (!pdi_settings)
 | 
			
		||||
    Palladium::Scene::Load(std::make_unique<Palladium::RSettings>());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::LoadThemeEditor() {
 | 
			
		||||
  Palladium::Scene::Load(std::make_unique<Palladium::ThemeEditor>());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::AddOvl(std::unique_ptr<Palladium::Ovl> overlay) {
 | 
			
		||||
  pdi_overlays.push_back(std::move(overlay));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::FadeOut() {
 | 
			
		||||
  if (!pdi_wait_fade) {
 | 
			
		||||
    pdi_fadein = true;
 | 
			
		||||
    pdi_fadealpha = 0;
 | 
			
		||||
    pdi_wait_fade = true;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::FadeIn() {
 | 
			
		||||
  if (!pdi_wait_fade) {
 | 
			
		||||
    pdi_fadeout = true;
 | 
			
		||||
    pdi_fadealpha = 255;
 | 
			
		||||
    pdi_wait_fade = true;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Palladium::FadeDisplay() { Npifade(); }
 | 
			
		||||
 | 
			
		||||
float Palladium::GetTime() { return pdi_time; }
 | 
			
		||||
 | 
			
		||||
std::string Palladium::GetAppDirectory() {
 | 
			
		||||
  std::string dir = "sdmc:/Palladium/Apps/" + pdi_app_name;
 | 
			
		||||
  if (!std::filesystem::is_directory(dir))
 | 
			
		||||
    std::filesystem::create_directories(dir);
 | 
			
		||||
  return dir;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string Palladium::GetDataDirectory() {
 | 
			
		||||
  std::string dir = GetAppDirectory() + "/data";
 | 
			
		||||
  if (!std::filesystem::is_directory(dir))
 | 
			
		||||
    std::filesystem::create_directories(dir);
 | 
			
		||||
  return dir;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										6
									
								
								source/stb.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								source/stb.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
#define STB_IMAGE_IMPLEMENTATION
 | 
			
		||||
#include <pd/external/stb_image.h>
 | 
			
		||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
 | 
			
		||||
#include <pd/external/stb_image_write.h>
 | 
			
		||||
#define STB_TRUETYPE_IMPLEMENTATION
 | 
			
		||||
#include <pd/external/stb_truetype.h>
 | 
			
		||||
							
								
								
									
										94
									
								
								source/swr.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								source/swr.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,94 @@
 | 
			
		||||
#include <pd/external/stb_image.h>
 | 
			
		||||
 | 
			
		||||
#include <pd/Color.hpp>
 | 
			
		||||
#include <pd/swr.hpp>
 | 
			
		||||
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
swr::swr(int w, int h) { image = Palladium::nimg(w, h); }
 | 
			
		||||
swr::swr() { image = Palladium::nimg(1, 1); }
 | 
			
		||||
 | 
			
		||||
swr::~swr() {
 | 
			
		||||
  // Do nothing
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void swr::load_file(const std::string& path) {
 | 
			
		||||
  int w, h, c;
 | 
			
		||||
  uint8_t* dat = stbi_load(path.c_str(), &w, &h, &c, 4);
 | 
			
		||||
  image = nimg(w, h);
 | 
			
		||||
  for (int x = 0; x < w; x++) {
 | 
			
		||||
    for (int y = 0; y < h; y++) {
 | 
			
		||||
      int pos = (y * w + x) * 4;
 | 
			
		||||
      image.pixel_buffer[pos + 0] = dat[pos + 0];
 | 
			
		||||
      image.pixel_buffer[pos + 1] = dat[pos + 1];
 | 
			
		||||
      image.pixel_buffer[pos + 2] = dat[pos + 2];
 | 
			
		||||
      image.pixel_buffer[pos + 3] = dat[pos + 3];
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  stbi_image_free(dat);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void swr::load_nimg(const std::string& path) {
 | 
			
		||||
  image = Palladium::NIMG_Load(path);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void swr::draw_pixel(int x, int y, unsigned int color) {
 | 
			
		||||
  if (x > image.width || x < 0 || y > image.height || y < 0) return;
 | 
			
		||||
  Palladium::Color::RGBA splitter(color);
 | 
			
		||||
  image.pixel_buffer[((y * image.width + x) * 4) + 0] = splitter.m_r;
 | 
			
		||||
  image.pixel_buffer[((y * image.width + x) * 4) + 1] = splitter.m_g;
 | 
			
		||||
  image.pixel_buffer[((y * image.width + x) * 4) + 2] = splitter.m_b;
 | 
			
		||||
  image.pixel_buffer[((y * image.width + x) * 4) + 3] = splitter.m_a;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void swr::draw_rect(int x, int y, int w, int h, unsigned int color, int t) {
 | 
			
		||||
  draw_line(x, y, x + w, y, color, t);
 | 
			
		||||
  draw_line(x, y, x, y + h, color, t);
 | 
			
		||||
  draw_line(x, y + h, x + w, y + h, color, t);
 | 
			
		||||
  draw_line(x + w, y + h, x + w, y + h, color, t);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void swr::draw_rect_solid(int x, int y, int w, int h, unsigned int color) {
 | 
			
		||||
  for (int ix = x; ix < x + w; ix++) {
 | 
			
		||||
    for (int iy = y; iy < y + h; iy++) {
 | 
			
		||||
      draw_pixel(ix, iy, color);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void swr::draw_line(int x1, int y1, int x2, int y2, unsigned int color, int t) {
 | 
			
		||||
  for (int ix = x1; ix < x2 * t; ix++) {
 | 
			
		||||
    for (int iy = y1; iy < y2 * t; iy++) {
 | 
			
		||||
      draw_pixel(ix, iy, color);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void swr::flip(bool h, bool v) {
 | 
			
		||||
  const nimg _bak = image;
 | 
			
		||||
  if (h) {
 | 
			
		||||
    for (int x = 0; x < image.width; x++) {
 | 
			
		||||
      for (int y = 0; y < image.height; y++) {
 | 
			
		||||
        int src = (y * image.width + x) * 4;
 | 
			
		||||
        int dst = ((image.height - 1 - y) * image.width + x) * 4;
 | 
			
		||||
        image.pixel_buffer[src + 0] = _bak.pixel_buffer[dst + 3];
 | 
			
		||||
        image.pixel_buffer[src + 1] = _bak.pixel_buffer[dst + 2];
 | 
			
		||||
        image.pixel_buffer[src + 2] = _bak.pixel_buffer[dst + 1];
 | 
			
		||||
        image.pixel_buffer[src + 3] = _bak.pixel_buffer[dst + 0];
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (v) {
 | 
			
		||||
    for (int x = 0; x < image.width; x++) {
 | 
			
		||||
      for (int y = 0; y < image.height; y++) {
 | 
			
		||||
        int src = (y * image.width + x) * 4;
 | 
			
		||||
        int dst = (y * image.width + (image.width - 1 - x)) * 4;
 | 
			
		||||
        image.pixel_buffer[src + 0] = _bak.pixel_buffer[dst + 3];
 | 
			
		||||
        image.pixel_buffer[src + 1] = _bak.pixel_buffer[dst + 2];
 | 
			
		||||
        image.pixel_buffer[src + 2] = _bak.pixel_buffer[dst + 1];
 | 
			
		||||
        image.pixel_buffer[src + 3] = _bak.pixel_buffer[dst + 0];
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
							
								
								
									
										77
									
								
								source/thread.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								source/thread.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,77 @@
 | 
			
		||||
#include <pd/thread.hpp>
 | 
			
		||||
namespace Palladium {
 | 
			
		||||
Thread::Thread() : m_started(false), m_running(false) { /* do nothing */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Thread::Thread(std::function<void(Palladium::Parameter)> t_function,
 | 
			
		||||
               Palladium::Parameter t_parameter, bool t_autostart,
 | 
			
		||||
               bool t_detached, unsigned long long int t_stackSize)
 | 
			
		||||
    : m_started(false), m_running(false) {
 | 
			
		||||
  initialize(t_function, t_parameter, t_autostart, t_detached, t_stackSize);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Thread::~Thread() {
 | 
			
		||||
  join();
 | 
			
		||||
 | 
			
		||||
  if (m_started) threadFree(m_thread);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Thread::initialize(std::function<void(Palladium::Parameter)> t_function,
 | 
			
		||||
                        Palladium::Parameter t_parameter, bool t_autostart,
 | 
			
		||||
                        bool t_detached, unsigned long long int t_stackSize) {
 | 
			
		||||
  m_stackSize = t_stackSize;
 | 
			
		||||
  m_data.m_parameter = t_parameter;
 | 
			
		||||
  m_data.m_function = t_function;
 | 
			
		||||
  m_data.m_running = &m_running;
 | 
			
		||||
 | 
			
		||||
  if (t_autostart) {
 | 
			
		||||
    start(t_detached);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Thread::setStackSize(unsigned long long int t_stackSize) {
 | 
			
		||||
  m_stackSize = t_stackSize;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Thread::start(bool t_detached) {
 | 
			
		||||
  if (!m_running) {
 | 
			
		||||
    m_started = true;
 | 
			
		||||
    m_running = true;
 | 
			
		||||
    s32 prio;
 | 
			
		||||
    svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
 | 
			
		||||
    m_thread = threadCreate(threadFunction, &m_data, m_stackSize, prio + 1, -2,
 | 
			
		||||
                            t_detached);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Thread::kill() {
 | 
			
		||||
  threadDetach(m_thread);
 | 
			
		||||
  m_running = false;
 | 
			
		||||
  m_started = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Thread::join(long long unsigned int t_timeout) {
 | 
			
		||||
  if (m_running) {
 | 
			
		||||
    threadJoin(m_thread, t_timeout);
 | 
			
		||||
    threadFree(m_thread);
 | 
			
		||||
    m_running = false;
 | 
			
		||||
    m_started = false;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Thread::isRunning() { return m_running; }
 | 
			
		||||
 | 
			
		||||
void Thread::sleep() { svcSleepThread(0); }
 | 
			
		||||
 | 
			
		||||
void Thread::sleep(int t_milliseconds) {
 | 
			
		||||
  svcSleepThread(1000000 * t_milliseconds);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// private methods
 | 
			
		||||
void Thread::threadFunction(void *arg) {
 | 
			
		||||
  Palladium::Thread::ThreadData data =
 | 
			
		||||
      *static_cast<Palladium::Thread::ThreadData *>(arg);
 | 
			
		||||
  data.m_function(data.m_parameter);
 | 
			
		||||
  *data.m_running = false;
 | 
			
		||||
}
 | 
			
		||||
}  // namespace Palladium
 | 
			
		||||
		Reference in New Issue
	
	Block a user