Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua support #878

Draft
wants to merge 140 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
8ab29ad
Test implementation of lua
ihaveamac Jul 23, 2023
9905b93
Trust that lua knows what its doing with this
luigoalma Jul 23, 2023
d4d2a08
actually update top screen when Thingy is called, disable unnecessary…
ihaveamac Jul 23, 2023
a7597d0
readme
ihaveamac Jul 23, 2023
107fb48
change init for a simple test, print error on top screen too
ihaveamac Jul 23, 2023
201cbc4
Readme
ihaveamac Jul 23, 2023
20a2cc7
change init for a simple test, print error on top screen too
ihaveamac Jul 23, 2023
725fcd1
enable more lua libs, edit init.lua with string examples
ihaveamac Jul 23, 2023
b69d933
enable more lua libs, edit init.lua with string examples
ihaveamac Jul 23, 2023
fa46fc2
one more readme edit before bed
ihaveamac Jul 23, 2023
85eaca7
Readme
ihaveamac Jul 23, 2023
f2317d6
change init for a simple test, print error on top screen too
ihaveamac Jul 23, 2023
cecb455
enable more lua libs, edit init.lua with string examples
ihaveamac Jul 23, 2023
2143075
Merge branch 'lua-attempt' of github.com:ihaveamac/GM9-lua-attempt in…
ihaveamac Jul 23, 2023
406885e
make lua a proper file type, add test UI library with two functions, …
ihaveamac Jul 24, 2023
a3b7c92
remove old attempts at editing lauxlib and liolib
ihaveamac Jul 24, 2023
7fc6c95
README
ihaveamac Jul 24, 2023
50aba3a
README
ihaveamac Jul 24, 2023
cd41ea2
Merge branch 'master' of github.com:d0k3/GodMode9 into lua-attempt
ihaveamac Jul 24, 2023
16aec40
FS lib, new UI stuff
ihaveamac Jul 25, 2023
1efa7b9
consistency with "type* ptr" maybe
ihaveamac Jul 25, 2023
6d00c3e
add custom package searcher, reset package.path
ihaveamac Jul 27, 2023
b3d331f
new functions for UI including basic print output buffer, add "Lua sc…
ihaveamac Jul 28, 2023
8281e0c
build vram0.tar including subdirs of data
ihaveamac Aug 3, 2023
7106f44
move default path to GM9LUA_DEFAULT_PATH
ihaveamac Aug 3, 2023
2b24193
FS_FileGetData
ihaveamac Aug 3, 2023
0f4a4c4
testfgd, add GM9VERSION global, update README, fix indentation
ihaveamac Aug 3, 2023
7d1223d
FS_FileGetData will return a nil instead if it fails
ihaveamac Aug 3, 2023
adf43bc
it's actually luaL_pushfail
ihaveamac Aug 3, 2023
3572658
os
Gruetzig Aug 12, 2023
c4a7954
use luaL_tolstring instead of lua_tostring
ihaveamac Aug 12, 2023
b7278f6
Merge branch 'ihaveamac:lua-attempt' into lua-attempt
Gruetzig Aug 12, 2023
28e3179
fix test/remove debugging showprompt
Gruetzig Aug 12, 2023
ce71316
os.clock float attempt
Gruetzig Aug 12, 2023
01100b2
fix print for real
ihaveamac Aug 12, 2023
bbcbf75
Merge branch 'ihaveamac:lua-attempt' into lua-attempt
Gruetzig Aug 12, 2023
ba36494
fix swapped offset and size for FileGetData
ihaveamac Aug 12, 2023
4ef4529
finish OS stuff
Gruetzig Aug 12, 2023
04fc335
fix os.clock
Gruetzig Aug 12, 2023
7c9275e
shorten table in/out
Gruetzig Aug 13, 2023
c266bdf
remove .vscode dir
Gruetzig Aug 13, 2023
97bed41
Merge pull request #2 from Gruetzig/lua-attempt
ihaveamac Aug 13, 2023
a875d01
enum test
ihaveamac Aug 15, 2023
b4ce10b
support building without lua
ihaveamac Aug 16, 2023
0971a69
NO_LUA hides menu options (except when you directly select a lua file)
ihaveamac Aug 19, 2023
e1cd5eb
update UI lib to better match the ideas on #1
ihaveamac Aug 19, 2023
a5d1c63
merge in changes from master
ihaveamac Aug 23, 2023
042df82
Merge branch 'master' into lua-attempt
ihaveamac Aug 26, 2023
4c4ae78
dockermake
ihaveamac Aug 26, 2023
4c0c30e
add DrawPNG function
Gruetzig Nov 20, 2023
144434e
whoops its ShowPNG
Gruetzig Nov 20, 2023
9e1cb51
minor fixes, add DrawPNG
Gruetzig Nov 20, 2023
1692a8a
fix AskPrompt, add all showprompts mentioned in #1
Gruetzig Mar 16, 2024
c6426ce
add newly added functions to readme
Gruetzig Mar 16, 2024
cecb117
try to keep separate code and data
Wolfvak Sep 23, 2024
cffa149
Merge remote-tracking branch 'upstream/master' into dev/separate-code…
Wolfvak Sep 23, 2024
f05f49f
Merge branch 'master' of github.com:d0k3/GodMode9 into lua-attempt
ihaveamac Sep 23, 2024
dab5c9a
update lua to 5.4.7
ihaveamac Sep 30, 2024
2e8ee79
Merge branch 'dev/separate-code-data' of github.com:Wolfvak/GodMode9 …
ihaveamac Nov 19, 2024
4b3cef3
Merge branch 'lua-attempt' of github.com:ihaveamac/GM9-lua-attempt in…
ihaveamac Nov 19, 2024
ac6c165
Merge branch 'master' into lua-attempt
ihaveamac Nov 19, 2024
137f223
remove test libraries now that i want to attempt to implement in a re…
ihaveamac Nov 19, 2024
e367768
add nix flake for building
ihaveamac Nov 19, 2024
884730f
add various lua functions, some of them taken from the old attempt bu…
ihaveamac Nov 19, 2024
3c3d807
add dev shell to flake.nix
ihaveamac Nov 19, 2024
bc3a21b
remove test lua scripts in root
ihaveamac Nov 19, 2024
7ab6628
add test lua scripts in data/luascripts
ihaveamac Nov 19, 2024
0787d03
add a whole bunch more lua functions and stuff
ihaveamac Nov 20, 2024
fd1cf50
add more test lua scripts
ihaveamac Nov 20, 2024
da0a1bc
add more functions, add preload script, add test io compatibility module
ihaveamac Nov 20, 2024
a8762ca
add more functions and test scripts
ihaveamac Nov 20, 2024
fb61e7d
more functions and stuff
ihaveamac Nov 20, 2024
09d2d44
more functions and stuff
ihaveamac Nov 21, 2024
8d90636
more functions and stuff, plus a wip ctrcheck reimpl
ihaveamac Nov 22, 2024
1c9499a
yet more functions and stuff
ihaveamac Nov 23, 2024
1f58eba
even more functions and stuff
ihaveamac Nov 23, 2024
75b106a
command comparison table.ods
ihaveamac Nov 23, 2024
9c79c91
update command comparison table.ods
ihaveamac Nov 23, 2024
f121fa7
update command comparison table.ods
ihaveamac Nov 26, 2024
5dacf8e
Merge branch 'master' into real-lua-attempt
ihaveamac Nov 26, 2024
badbe94
Add files via upload
ihaveamac Nov 28, 2024
c42bcea
update command comparison table.ods
ihaveamac Nov 28, 2024
0572137
update ui.show_text to use DrawStringCenter, update ctrcheck rewrite
ihaveamac Nov 28, 2024
47717ac
Fix merge conflicts and add missing strings to source.json
ihaveamac Dec 1, 2024
8dca84b
Split up the ARM9 code (.text, .vectors) and data (.rodata, .data, .b…
Wolfvak Sep 23, 2024
76c322a
use the makefile definition
Wolfvak Dec 1, 2024
849a2a4
Merge in d0k3/GodMode9#883 and fix merge conflicts
ihaveamac Dec 2, 2024
0273326
add title module, move around some functions, update command comparis…
ihaveamac Dec 2, 2024
6316ba1
add readme for lua
ihaveamac Dec 2, 2024
6ad9a43
remove liolib.c and loslib.c
ihaveamac Dec 2, 2024
afc9d46
more functions and things, use CheckWritePermissionsLuaError in place…
ihaveamac Dec 2, 2024
7c19eec
add missing constant
ihaveamac Dec 2, 2024
8af7a1d
set CURRDIR to nil instead of "(null)" if not found
ihaveamac Dec 2, 2024
6d5b6e2
remove gm9enum (unused since the restart)
ihaveamac Dec 2, 2024
723ff05
add ui.check_key
ihaveamac Dec 3, 2024
9d9b327
split fs module to lua overlay and _fs internal module, and add a che…
ihaveamac Dec 3, 2024
f8738ef
add fs.ask_select_file and fs.ask_select_dir
ihaveamac Dec 3, 2024
3790401
add fs.key_dump, replace overwrite_all and append_all with overwrite …
ihaveamac Dec 3, 2024
2166d5e
add fs.cart_dump and sys.emu_base
ihaveamac Dec 3, 2024
722c54c
add ctrtool, update flake.lock
ihaveamac Dec 5, 2024
6e8208d
add io append mode
ihaveamac Dec 7, 2024
d4dbd9f
make sure io.open with write mode starts with an empty file, add os.r…
ihaveamac Dec 7, 2024
b40af5a
properly implement os.remove compatibility
ihaveamac Dec 9, 2024
3b57ffd
add fs.verify_with_sha_file, fix PathIsDirectory by using stat instea…
ihaveamac Dec 9, 2024
b0d0d0b
add util.running_as_module (untested)
ihaveamac Dec 11, 2024
3a915cd
move scripts over to https://github.com/ihaveamac/GM9-lua-script-expe…
ihaveamac Dec 11, 2024
b36c044
remove ods and dockermake.sh
ihaveamac Dec 11, 2024
606ea6a
remove data/scripts
ihaveamac Dec 11, 2024
b99a6bc
add lua autorun (untested)
ihaveamac Dec 11, 2024
aa52cfc
fix syntax error
ihaveamac Dec 11, 2024
fc0a438
add sys.check_embedded_backup
ihaveamac Dec 12, 2024
ff2cb91
remove accidental symlink
ihaveamac Dec 12, 2024
f355844
add sys.check_raw_rtc
ihaveamac Dec 12, 2024
702261a
fix ui.show_file_text_viewer not freeing memory or reporting an error…
ihaveamac Dec 13, 2024
256f5eb
add todo notes for ui
ihaveamac Dec 13, 2024
830392c
work-in-progress lua doc
ihaveamac Dec 13, 2024
bdf569a
formatting fix
ihaveamac Dec 13, 2024
6ef14b6
up heading level for all sections
ihaveamac Dec 13, 2024
376968f
Revert "up heading level for all sections"
ihaveamac Dec 13, 2024
11082c9
separators
ihaveamac Dec 13, 2024
87f9d15
fix name and error for fs.move
ihaveamac Dec 13, 2024
81254fa
do explicit permission checks in fs.move
ihaveamac Dec 13, 2024
f1c022a
fix error string for fs.copy
ihaveamac Dec 13, 2024
aa672a8
fix function name for fs.dir_info
ihaveamac Dec 13, 2024
e31f69c
fix error string for fs.find and fs.find_not
ihaveamac Dec 13, 2024
92f83a5
fix function name for fs.img_umount
ihaveamac Dec 13, 2024
f8447f3
partial fs doc
ihaveamac Dec 13, 2024
7cf6900
finished fs doc, string fixes for fs module
ihaveamac Dec 13, 2024
0996219
document fs.cart_dump encrypted opt, remove stat from fs.verify_with_…
ihaveamac Dec 13, 2024
3eef799
title doc
ihaveamac Dec 13, 2024
8149339
sys doc, error string updates
ihaveamac Dec 13, 2024
328751c
util doc
ihaveamac Dec 13, 2024
5c51e93
add json.lua to lua-doc
ihaveamac Dec 14, 2024
10cfae4
add fs.find_all
ihaveamac Dec 15, 2024
3599612
add 3dstool to flake
ihaveamac Dec 15, 2024
b716e46
make fs.find_all recursive actually recursive, document fs.find_all
ihaveamac Dec 15, 2024
5da469d
add "for" to comparison table
ihaveamac Dec 15, 2024
7308ddc
change fs.find to return nil if no path was found, instead of raising…
ihaveamac Dec 15, 2024
2524e77
change ui.echo to automatically word wrap (untested)
ihaveamac Dec 16, 2024
01e2b53
Revert "change ui.echo to automatically word wrap (untested)"
ihaveamac Dec 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.obj
*.elf
*.map
*.dis

# Precompiled Headers
*.gch
Expand Down Expand Up @@ -35,6 +36,7 @@

# OS leftovers
desktop.ini
.DS_Store

# Sublime files
*.sublime-*
Expand Down
20 changes: 12 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export COMMON_DIR := ../common

# Definitions for initial RAM disk
VRAM_TAR := $(OUTDIR)/vram0.tar
VRAM_DATA := data
VRAM_DATA := data/*
VRAM_FLAGS := --make-new --path-limit 99
ifeq ($(NTRBOOT),1)
VRAM_SCRIPTS := resources/gm9/scripts
VRAM_SCRIPTS := resources/gm9/scripts/*
endif

# Definitions for translation files
Expand Down Expand Up @@ -52,7 +52,7 @@ export CFLAGS := -DDBUILTS="\"$(DBUILTS)\"" -DDBUILTL="\"$(DBUILTL)\"" -DVERSIO
-fomit-frame-pointer -ffast-math -std=gnu11 -MMD -MP \
-Wno-unused-function -Wno-format-truncation -Wno-format-nonliteral $(INCLUDE) -ffunction-sections -fdata-sections
export LDFLAGS := -Tlink.ld -nostartfiles -Wl,--gc-sections,-z,max-page-size=4096
ELF := arm9/arm9.elf arm11/arm11.elf
ELF := arm9/arm9_code.elf arm9/arm9_data.elf arm11/arm11.elf

.PHONY: all firm $(VRAM_TAR) elf release clean
all: firm
Expand Down Expand Up @@ -93,7 +93,7 @@ release: clean unmarked_readme
$(VRAM_TAR): $(SPLASH) $(OVERRIDE_FONT) $(VRAM_DATA) $(VRAM_SCRIPTS)
@mkdir -p "$(@D)"
@echo "Creating $@"
@$(PY3) utils/add2tar.py $(VRAM_FLAGS) $(VRAM_TAR) $(shell find $^ -type f)
$(PY3) utils/add2tar.py $(VRAM_FLAGS) $(VRAM_TAR) $(shell ls -d -1 $^)

$(LANGUAGE_INL): $(SOURCE_JSON)
@echo "Creating $@"
Expand All @@ -104,19 +104,23 @@ $(TRF_FOLDER)/%.trf: $(JSON_FOLDER)/%.json

%.elf: .FORCE
@echo "Building $@"
@$(MAKE) --no-print-directory -C $(@D)
@$(MAKE) --no-print-directory -C $(@D) $(@F)

arm9/arm9.elf: $(VRAM_TAR) $(LANGUAGE_INL)
# Indicate a few explicit dependencies:
# The ARM9 data section depends on the VRAM drive
arm9/arm9_data.elf: $(VRAM_TAR) $(LANGUAGE_INL)
# And the code section depends on the data section being built already
arm9/arm9_code.elf: arm9/arm9_data.elf

firm: $(ELF) $(TRF_FILES)
@mkdir -p $(call dirname,"$(FIRM)") $(call dirname,"$(FIRMD)")
@echo "[FLAVOR] $(FLAVOR)"
@echo "[VERSION] $(VERSION)"
@echo "[BUILD] $(DBUILTL)"
@echo "[FIRM] $(FIRM)"
@$(PY3) -m firmtool build $(FIRM) $(FTFLAGS) -g -D $(ELF) -C NDMA XDMA
@$(PY3) -m firmtool build $(FIRM) $(FTFLAGS) -g -D $(ELF) -C NDMA NDMA XDMA
@echo "[FIRM] $(FIRMD)"
@$(PY3) -m firmtool build $(FIRMD) $(FTDFLAGS) -g -D $(ELF) -C NDMA XDMA
@$(PY3) -m firmtool build $(FIRMD) $(FTDFLAGS) -g -D $(ELF) -C NDMA NDMA XDMA

vram0: $(VRAM_TAR) .FORCE # legacy target name

Expand Down
7 changes: 5 additions & 2 deletions Makefile.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

LIBS ?=

OBJECTS := $(patsubst $(SOURCE)/%.s, $(BUILD)/%.o, \
$(patsubst $(SOURCE)/%.c, $(BUILD)/%.o, \
$(call rwildcard, $(SOURCE), *.s *.c)))
Expand All @@ -11,11 +13,12 @@ all: $(TARGET).elf

.PHONY: clean
clean:
@rm -rf $(BUILD) $(TARGET).elf $(TARGET).map
@rm -rf $(BUILD) $(TARGET).elf $(TARGET).dis $(TARGET).map

$(TARGET).elf: $(OBJECTS) $(OBJECTS_COMMON)
@mkdir -p "$(@D)"
@$(CC) $(LDFLAGS) $^ -o $@
@$(CC) $(LDFLAGS) $^ -o $@ $(LIBS)
@$(OBJDUMP) -S $@ > $@.dis

$(BUILD)/%.cmn.o: $(COMMON_DIR)/%.c
@mkdir -p "$(@D)"
Expand Down
5 changes: 5 additions & 0 deletions Makefile.common
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export OBJDUMP := arm-none-eabi-objdump

dirname = $(shell dirname $(1))

Expand Down Expand Up @@ -67,6 +68,10 @@ ifdef SD_TIMEOUT
CFLAGS += -DSD_TIMEOUT=$(SD_TIMEOUT)
endif

ifeq ($(NO_LUA),1)
CFLAGS += -DNO_LUA
endif

ifdef N_PANES
CFLAGS += -DN_PANES=$(N_PANES)
endif
Expand Down
211 changes: 14 additions & 197 deletions README.md

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion arm9/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ SOURCE := source
BUILD := build

SUBARCH := -D$(PROCESSOR) -march=armv5te -mtune=arm946e-s -mthumb -mfloat-abi=soft
INCDIRS := source source/common source/filesys source/crypto source/fatfs source/nand source/virtual source/game source/gamecart source/lodepng source/qrcodegen source/system source/utils
INCDIRS := source source/common source/filesys source/crypto source/fatfs source/nand source/virtual source/game source/gamecart source/lodepng source/lua source/qrcodegen source/system source/utils
INCLUDE := $(foreach dir,$(INCDIRS),-I"$(shell pwd)/$(dir)")

ASFLAGS += $(SUBARCH) $(INCLUDE)
CFLAGS += $(SUBARCH) $(INCLUDE) -fno-builtin-memcpy -flto
LDFLAGS += $(SUBARCH) -Wl,--use-blx,-Map,$(TARGET).map -flto
LIBS += -lm

include ../Makefile.common
include ../Makefile.build

arm9_data.elf: arm9.elf
$(OBJCOPY) -O elf32-littlearm -j .rodata* -j .data* -j .bss* $< $@

arm9_code.elf: arm9.elf
$(OBJCOPY) -O elf32-littlearm -j .text* -j .vectors* $< $@
20 changes: 13 additions & 7 deletions arm9/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ ENTRY(_start)
MEMORY
{
VECTORS (RX) : ORIGIN = 0x08000000, LENGTH = 64
AHBWRAM (RWX) : ORIGIN = 0x08000040, LENGTH = 512K - 64
CODEMEM (RX) : ORIGIN = 0x08000040, LENGTH = 512K - 64
BOOTROM (R) : ORIGIN = 0x08080000, LENGTH = 128K /* BootROM mirrors, don't touch! */
DATAMEM (RW) : ORIGIN = 0x080A0000, LENGTH = 384K
}

SECTIONS
Expand All @@ -16,32 +18,36 @@ SECTIONS
KEEP(*(.vectors));
. = ALIGN(4);
__vectors_len = ABSOLUTE(.) - __vectors_vma;
} >VECTORS AT>AHBWRAM
} >VECTORS AT>CODEMEM

.text : ALIGN(4) {
__text_s = ABSOLUTE(.);
*(.text.start);
*(.text*);
. = ALIGN(4);
__text_e = ABSOLUTE(.);
} >AHBWRAM
} >CODEMEM

.rodata : ALIGN(4) {
*(.rodata*);
. = ALIGN(4);
} >AHBWRAM
__exidx_start = .;
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
__exidx_end = .;
. = ALIGN(4);
} >DATAMEM

.data : ALIGN(4) {
*(.data*);
. = ALIGN(4);
} >AHBWRAM
} >DATAMEM

.bss : ALIGN(4) {
.bss (NOLOAD) : ALIGN(4) {
__bss_start = .;
*(.bss*);
. = ALIGN(4);
__bss_end = .;
} >AHBWRAM
} >DATAMEM

__end__ = ABSOLUTE(.);
}
4 changes: 4 additions & 0 deletions arm9/source/filesys/filetype.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "keydb.h"
#include "ctrtransfer.h"
#include "scripting.h"
#include "gm9lua.h"
#include "png.h"
#include "ui.h" // only for font file detection

Expand Down Expand Up @@ -165,6 +166,9 @@ u64 IdentifyFileType(const char* path) {
u64 type = 0;
if ((fsize < SCRIPT_MAX_SIZE) && (strcasecmp(ext, SCRIPT_EXT) == 0))
type |= TXT_SCRIPT; // should be a script (which is also generic text)
// this should check if it's compiled lua bytecode (done with luac), which is NOT text
else if ((fsize < LUASCRIPT_MAX_SIZE) && (strcasecmp(ext, LUASCRIPT_EXT) == 0))
type |= TXT_LUA;
if (fsize < STD_BUFFER_SIZE) type |= TXT_GENERIC;
return type;
} else if ((strncmp(path + 2, "/Nintendo DSiWare/", 18) == 0) &&
Expand Down
2 changes: 2 additions & 0 deletions arm9/source/filesys/filetype.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define NOIMG_NAND (1ULL<<35)
#define HDR_NAND (1ULL<<36)
#define TRANSLATION (1ULL<<37)
#define TXT_LUA (1ULL<<38)
#define TYPE_BASE 0xFFFFFFFFFFULL // 40 bit reserved for base types

// #define FLAG_FIRM (1ULL<<58) // <--- for CXIs containing FIRMs
Expand Down Expand Up @@ -77,6 +78,7 @@
#define FTYPE_KEYINIT(tp) (tp&(BIN_KEYDB))
#define FTYPE_KEYINSTALL(tp) (tp&(BIN_KEYDB))
#define FTYPE_SCRIPT(tp) (tp&(TXT_SCRIPT))
#define FTYPE_LUA(tp) (tp&(TXT_LUA))
#define FTYPE_FONT(tp) (tp&(FONT_PBM|FONT_RIFF))
#define FTYPE_TRANSLATION(tp) (tp&(TRANSLATION))
#define FTYPE_GFX(tp) (tp&(GFX_PNG))
Expand Down
1 change: 1 addition & 0 deletions arm9/source/filesys/support.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// scripts / payloads dir names
#define LANGUAGES_DIR "languages"
#define SCRIPTS_DIR "scripts"
#define LUASCRIPTS_DIR "luascripts"
#define PAYLOADS_DIR "payloads"

bool CheckSupportFile(const char* fname);
Expand Down
1 change: 1 addition & 0 deletions arm9/source/filesys/vff.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#define fvx_tell(fp) ((fp)->fptr)
#define fvx_size(fp) ((fp)->obj.objsize)
#define fvx_eof(fp) (fvx_tell(fp) == fvx_size(fp))

#define FN_ANY 0x00
#define FN_HIGHEST 0x01
Expand Down
51 changes: 49 additions & 2 deletions arm9/source/godmode.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "i2c.h"
#include "pxi.h"
#include "language.h"
#include "gm9lua.h"

#ifndef N_PANES
#define N_PANES 3
Expand Down Expand Up @@ -1198,6 +1199,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan
bool installable = (FTYPE_INSTALLABLE(filetype));
bool agbexportable = (FTYPE_AGBSAVE(filetype) && (drvtype & DRV_VIRTUAL) && (drvtype & DRV_SYSNAND));
bool agbimportable = (FTYPE_AGBSAVE(filetype) && (drvtype & DRV_VIRTUAL) && (drvtype & DRV_SYSNAND));
bool luascriptable = (FTYPE_LUA(filetype));

char cxi_path[256] = { 0 }; // special options for TMD
if ((filetype & GAME_TMD) &&
Expand All @@ -1213,7 +1215,8 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan
cxi_dumpable || tik_buildable || key_buildable || titleinfo || renamable || trimable || transferable ||
hsinjectable || restorable || xorpadable || ebackupable || ncsdfixable || extrcodeable || keyinitable ||
keyinstallable || bootable || scriptable || fontable || translationable || viewable || installable ||
agbexportable || agbimportable || cia_installable || tik_installable || tik_dumpable || cif_installable;
agbexportable || agbimportable || cia_installable || tik_installable || tik_dumpable || cif_installable ||
luascriptable;

char pathstr[UTF_BUFFER_BYTESIZE(32)];
TruncateString(pathstr, file_path, 32, 8);
Expand Down Expand Up @@ -1296,6 +1299,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan
(filetype & BIN_LEGKEY) ? buildkeydb_str :
(filetype & BIN_NCCHNFO)? STR_NCCHINFO_OPTIONS :
(filetype & TXT_SCRIPT) ? STR_EXECUTE_GM9_SCRIPT :
(filetype & TXT_LUA) ? STR_EXECUTE_LUA_SCRIPT :
(FTYPE_FONT(filetype)) ? STR_FONT_OPTIONS :
(filetype & TRANSLATION)? STR_LANGUAGE_OPTIONS :
(filetype & GFX_PNG) ? STR_VIEW_PNG_FILE :
Expand Down Expand Up @@ -1459,6 +1463,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan
int install = (installable) ? ++n_opt : -1;
int boot = (bootable) ? ++n_opt : -1;
int script = (scriptable) ? ++n_opt : -1;
int luascript = (luascriptable) ? ++n_opt : -1;
int font = (fontable) ? ++n_opt : -1;
int translation = (translationable) ? ++n_opt : -1;
int view = (viewable) ? ++n_opt : -1;
Expand Down Expand Up @@ -1496,6 +1501,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan
if (install > 0) optionstr[install-1] = STR_INSTALL_FIRM;
if (boot > 0) optionstr[boot-1] = STR_BOOT_FIRM;
if (script > 0) optionstr[script-1] = STR_EXECUTE_GM9_SCRIPT;
if (luascript > 0) optionstr[luascript-1] = STR_EXECUTE_LUA_SCRIPT;
if (view > 0) optionstr[view-1] = STR_VIEW_PNG_FILE;
if (font > 0) optionstr[font-1] = STR_SET_AS_ACTIVE_FONT;
if (translation > 0) optionstr[translation-1] = STR_SET_AS_ACTIVE_LANGUAGE;
Expand Down Expand Up @@ -2143,6 +2149,20 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan
ClearScreenF(true, true, COLOR_STD_BG);
return 0;
}
else if (user_select == luascript) { // execute lua script
#ifndef NO_LUA
if (ShowPrompt(true, "%s\n%s", pathstr, STR_WARNING_DO_NOT_RUN_UNTRUSTED_SCRIPTS))
ShowPrompt(false, "%s\n%s", pathstr, ExecuteLuaScript(file_path) ? STR_SCRIPT_EXECUTE_SUCCESS : STR_SCRIPT_EXECUTE_FAILURE);
#else
// instead of outright removing the option, i think
// having it display an error would be useful
// so the user knows their issue exactly
ShowPrompt(false, "%s", STR_LUA_NOT_INCLUDED);
#endif
GetDirContents(current_dir, current_path);
ClearScreenF(true, true, COLOR_STD_BG);
return 0;
}
else if (user_select == font) { // set font
u8* font = (u8*) malloc(0x20000); // arbitrary, should be enough by far
if (!font) return 1;
Expand Down Expand Up @@ -2492,6 +2512,7 @@ u32 GodMode(int entrypoint) {
}
}

// note: this is kinda duplicated in arm9/source/lua/gm9internalsys.c as well
// check internal clock
if (IS_UNLOCKED) { // we could actually do this on any entrypoint
DsTime dstime;
Expand Down Expand Up @@ -2919,7 +2940,7 @@ u32 GodMode(int entrypoint) {
exit_mode = (switched || (pad_state & BUTTON_LEFT)) ? GODMODE_EXIT_POWEROFF : GODMODE_EXIT_REBOOT;
break;
} else if (pad_state & (BUTTON_HOME|BUTTON_POWER)) { // Home menu
const char* optionstr[8];
const char* optionstr[9];
bool buttonhome = (pad_state & BUTTON_HOME);
u32 n_opt = 0;
int poweroff = ++n_opt;
Expand All @@ -2928,6 +2949,9 @@ u32 GodMode(int entrypoint) {
int brick = (HID_ReadState() & BUTTON_R1) ? ++n_opt : 0;
int titleman = ++n_opt;
int scripts = ++n_opt;
#ifndef NO_LUA
int luascripts = ++n_opt;
#endif
int payloads = ++n_opt;
int more = ++n_opt;
if (poweroff > 0) optionstr[poweroff - 1] = STR_POWEROFF_SYSTEM;
Expand All @@ -2936,6 +2960,9 @@ u32 GodMode(int entrypoint) {
if (language > 0) optionstr[language - 1] = STR_LANGUAGE;
if (brick > 0) optionstr[brick - 1] = STR_BRICK_MY_3DS;
if (scripts > 0) optionstr[scripts - 1] = STR_SCRIPTS;
#ifndef NO_LUA
if (luascripts > 0) optionstr[luascripts - 1] = STR_LUA_SCRIPTS;
#endif
if (payloads > 0) optionstr[payloads - 1] = STR_PAYLOADS;
if (more > 0) optionstr[more - 1] = STR_MORE;

Expand Down Expand Up @@ -3013,6 +3040,17 @@ u32 GodMode(int entrypoint) {
ClearScreenF(true, true, COLOR_STD_BG);
break;
}
#ifndef NO_LUA
} else if (user_select == luascripts) {
if (!CheckSupportDir(LUASCRIPTS_DIR)) {
ShowPrompt(false, STR_LUA_SCRIPTS_DIRECTORY_NOT_FOUND, LUASCRIPTS_DIR);
} else if (FileSelectorSupport(loadpath, STR_HOME_LUA_SCRIPTS_MENU_SELECT_SCRIPT, LUASCRIPTS_DIR, "*.lua")) {
ExecuteLuaScript(loadpath);
GetDirContents(current_dir, current_path);
ClearScreenF(true, true, COLOR_STD_BG);
break;
}
#endif
} else if (user_select == payloads) {
if (!CheckSupportDir(PAYLOADS_DIR)) ShowPrompt(false, STR_PAYLOADS_DIRECTORY_NOT_FOUND, PAYLOADS_DIR);
else if (FileSelectorSupport(loadpath, STR_HOME_PAYLOADS_MENU_SELECT_PAYLOAD, PAYLOADS_DIR, "*.firm"))
Expand Down Expand Up @@ -3096,12 +3134,21 @@ u32 ScriptRunner(int entrypoint) {
if (PathExist("V:/" VRAM0_AUTORUN_GM9)) {
ClearScreenF(true, true, COLOR_STD_BG); // clear splash
ExecuteGM9Script("V:/" VRAM0_AUTORUN_GM9);
} else if (PathExist("V:/" VRAM0_AUTORUN_LUA)) {
ClearScreenF(true, true, COLOR_STD_BG); // clear splash
ExecuteLuaScript("V:/" VRAM0_AUTORUN_LUA);
} else if (PathExist("V:/" VRAM0_SCRIPTS)) {
char loadpath[256];
char title[256];
snprintf(title, sizeof(title), STR_FLAVOR_SCRIPTS_MENU_SELECT_SCRIPT, FLAVOR);
if (FileSelector(loadpath, title, "V:/" VRAM0_SCRIPTS, "*.gm9", HIDE_EXT, false))
ExecuteGM9Script(loadpath);
} else if (PathExist("V:/" VRAM0_LUASCRIPTS)) {
char loadpath[256];
char title[256];
snprintf(title, sizeof(title), STR_FLAVOR_SCRIPTS_MENU_SELECT_SCRIPT, FLAVOR);
if (FileSelector(loadpath, title, "V:/" VRAM0_LUASCRIPTS, "*.lua", HIDE_EXT, false))
ExecuteLuaScript(loadpath);
} else ShowPrompt(false, STR_COMPILED_AS_SCRIPT_AUTORUNNER_BUT_NO_SCRIPT_DERP);

// deinit
Expand Down
Loading
Loading