Skip to content
This repository was archived by the owner on Nov 7, 2019. It is now read-only.

Commit 6d2ae7b

Browse files
authored
Add new stuff
1 parent 046fab3 commit 6d2ae7b

File tree

9 files changed

+19024
-0
lines changed

9 files changed

+19024
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# ModuleMania - various useful sysmodules for CFW
2+
3+
## How do I use a sysmodule from here?
4+
5+
- The usage of every sysmodule is explained at their folder's README file.
6+
7+
## I came here looking for sys-play...
8+
9+
- Sys-play sysmodule is outdated, so I'd recommend using `xor:play` instead. Anyway, it's only release can be found on this repository: [sys-play release](https://github.com/XorTroll/ModuleMania/releases/tag/sysplay)

xor.play/Makefile

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
.SUFFIXES:
2+
3+
ifeq ($(strip $(DEVKITPRO)),)
4+
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
5+
endif
6+
7+
TOPDIR ?= $(CURDIR)
8+
include $(DEVKITPRO)/libnx/switch_rules
9+
10+
TARGET := xor.play
11+
BUILD := build
12+
SOURCES := Source
13+
DATA := data
14+
INCLUDES := Source
15+
EXEFS_SRC := exefs_src
16+
17+
KIP_NAME := xor:play
18+
KIP_HEAP := 950000
19+
KIP_TITLEID := 31200000000000AB
20+
21+
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE
22+
23+
CFLAGS := -g -Wall -Wextra -O2 -fpermissive -ffunction-sections \
24+
$(ARCH) $(DEFINES)
25+
26+
CFLAGS += $(INCLUDE) -D__SWITCH__
27+
CFLAGS += -DKIP_NAME=\"$(KIP_NAME)\" -DKIP_HEAP=0x$(KIP_HEAP) -DKIP_TITLEID=0x$(KIP_TITLEID)
28+
29+
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
30+
31+
ASFLAGS := -g $(ARCH)
32+
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
33+
34+
LIBS := -lfreetype -lSDL2_mixer -lmodplug -lmpg123 -lvorbisidec -logg -lSDL2_ttf -lSDL2_gfx -lSDL2_image -lpng -ljpeg `sdl2-config --libs` `freetype-config --libs` -lnx -lm
35+
36+
LIBDIRS := $(PORTLIBS) $(LIBNX)
37+
38+
ifneq ($(BUILD),$(notdir $(CURDIR)))
39+
40+
export OUTPUT := $(CURDIR)/$(TARGET)
41+
export TOPDIR := $(CURDIR)
42+
43+
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
44+
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
45+
46+
export DEPSDIR := $(CURDIR)/$(BUILD)
47+
48+
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
49+
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
50+
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
51+
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
52+
53+
ifeq ($(strip $(CPPFILES)),)
54+
export LD := $(CC)
55+
else
56+
export LD := $(CXX)
57+
endif
58+
59+
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
60+
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
61+
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
62+
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
63+
64+
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
65+
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
66+
-I$(CURDIR)/$(BUILD)
67+
68+
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
69+
70+
export BUILD_EXEFS_SRC := $(TOPDIR)/$(EXEFS_SRC)
71+
72+
ifeq ($(strip $(CONFIG_JSON)),)
73+
jsons := $(wildcard *.json)
74+
ifneq (,$(findstring $(TARGET).json,$(jsons)))
75+
export APP_JSON := $(TOPDIR)/$(TARGET).json
76+
else
77+
ifneq (,$(findstring config.json,$(jsons)))
78+
export APP_JSON := $(TOPDIR)/config.json
79+
endif
80+
endif
81+
else
82+
export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
83+
endif
84+
85+
.PHONY: $(BUILD) clean all
86+
87+
all: $(BUILD)
88+
89+
$(BUILD):
90+
@[ -d $@ ] || mkdir -p $@
91+
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
92+
93+
clean:
94+
@echo clean ...
95+
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).kip
96+
97+
else
98+
.PHONY: all
99+
100+
DEPENDS := $(OFILES:.o=.d)
101+
102+
all : $(OUTPUT).kip
103+
104+
$(OUTPUT).kip : $(OUTPUT).elf
105+
106+
$(OUTPUT).elf : $(OFILES)
107+
108+
$(OFILES_SRC) : $(HFILES_BIN)
109+
110+
%.bin.o %_bin.h : %.bin
111+
@echo $(notdir $<)
112+
@$(bin2o)
113+
114+
-include $(DEPENDS)
115+
116+
endif

xor.play/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# ModuleMania sysmodule - `xor:play`
2+
3+
## How do I use this sysmodule?
4+
5+
- First of all, DON'T RUN THIS KIP ALONG WITH LAYEREDFS!
6+
- Save the kip and add it to your own CFW. I guess you'll already know how to add kips to the CFW you use.
7+
- Create a file on the root of the SD card named `xor.play.json`.
8+
Add there the Title IDs and the audio files to play when that title is opened.
9+
- Here's an example with BotW and Home Menu:
10+
``` json
11+
{
12+
"0100000000001000" : "sdmc:/myaudios/play.wav",
13+
"01007EF00011E000" : "sdmc:/aud.mp3"
14+
}
15+
```
16+
- This way, when there's nothing opened and you're in Home Menu `play.wav` file would be played, and while BotW is opened `aud.mp3` would be played (even if you're on Home Menu and the app is minimized)
17+
- The number of applets which support this is unknown, be free to test it. All games should work.
18+
- Any problems you have, ask them on my Discord server ([Nintendo H&H server](https://discord.gg/Qqnndqd)), or ask them on the release GBAtemp thread of ModuleMania.

xor.play/Source/DebugTypes.hpp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
2+
#pragma once
3+
#include <switch.h>
4+
5+
struct AttachProcessInfo
6+
{
7+
u64 title_id;
8+
u64 process_id;
9+
char name[0xC];
10+
u32 flags;
11+
u64 user_exception_context_address;
12+
};
13+
14+
struct AttachThreadInfo
15+
{
16+
u64 thread_id;
17+
u64 tls_address;
18+
u64 entrypoint;
19+
};
20+
21+
enum class DebugExceptionType : u32
22+
{
23+
UndefinedInstruction = 0,
24+
InstructionAbort = 1,
25+
DataAbort = 2,
26+
AlignmentFault = 3,
27+
DebuggerAttached = 4,
28+
BreakPoint = 5,
29+
UserBreak = 6,
30+
DebuggerBreak = 7,
31+
BadSvc = 8,
32+
UnknownNine = 9,
33+
};
34+
35+
struct UndefinedInstructionInfo
36+
{
37+
u32 insn;
38+
};
39+
40+
struct DataAbortInfo
41+
{
42+
u64 address;
43+
};
44+
45+
struct AlignmentFaultInfo
46+
{
47+
u64 address;
48+
};
49+
50+
struct UserBreakInfo
51+
{
52+
u64 info_0;
53+
u64 address;
54+
u64 size;
55+
};
56+
57+
struct BadSvcInfo
58+
{
59+
u32 id;
60+
};
61+
62+
union SpecificExceptionInfo
63+
{
64+
UndefinedInstructionInfo undefined_instruction;
65+
DataAbortInfo data_abort;
66+
AlignmentFaultInfo alignment_fault;
67+
UserBreakInfo user_break;
68+
BadSvcInfo bad_svc;
69+
u64 raw;
70+
};
71+
72+
struct ExceptionInfo
73+
{
74+
DebugExceptionType type;
75+
u64 address;
76+
SpecificExceptionInfo specific;
77+
};
78+
79+
80+
enum class DebugEventType : u32
81+
{
82+
AttachProcess = 0,
83+
AttachThread = 1,
84+
ExitProcess = 2,
85+
ExitThread = 3,
86+
Exception = 4
87+
};
88+
89+
union DebugInfo
90+
{
91+
AttachProcessInfo attach_process;
92+
AttachThreadInfo attach_thread;
93+
ExceptionInfo exception;
94+
};
95+
96+
struct DebugEventInfo
97+
{
98+
DebugEventType type;
99+
u32 flags;
100+
u64 thread_id;
101+
union
102+
{
103+
DebugInfo info;
104+
u64 _[0x40/sizeof(u64)];
105+
};
106+
};

xor.play/Source/Include.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
#pragma once
3+
#include <iostream>
4+
#include <ctime>
5+
#include <cmath>
6+
#include <functional>
7+
#include <cstdio>
8+
#include <array>
9+
#include <iterator>
10+
#include <vector>
11+
#include <algorithm>
12+
#include <limits>
13+
#include <cstdint>
14+
#include <fstream>
15+
#include <unistd.h>
16+
#include <cstdlib>
17+
#include <sstream>
18+
#include <string>
19+
#include <map>
20+
#include <time.h>
21+
#include <cstring>
22+
#include <sys/types.h>
23+
#include <sys/stat.h>
24+
#include <sys/select.h>
25+
#include <dirent.h>
26+
#include <random>
27+
#include <iomanip>
28+
#include <switch.h>
29+
#include <switch/arm/atomics.h>
30+
using namespace std;

xor.play/Source/Main.cpp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
2+
#include "SysModule.hpp"
3+
#include "DebugTypes.hpp"
4+
#include <SDL2/SDL.h>
5+
#include <SDL2/SDL_mixer.h>
6+
#include "json.hpp"
7+
using namespace nlohmann;
8+
9+
struct AudioEntry
10+
{
11+
u64 TitleID;
12+
string Audio;
13+
};
14+
15+
u64 playid = 0;
16+
17+
void init()
18+
{
19+
SDL_Init(SDL_INIT_AUDIO);
20+
Mix_Init(MIX_INIT_FLAC | MIX_INIT_MOD | MIX_INIT_MP3 | MIX_INIT_OGG);
21+
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 4096);
22+
}
23+
24+
AudioEntry cur;
25+
Mix_Music *audio;
26+
bool cplay = false;
27+
28+
int main()
29+
{
30+
init();
31+
vector<AudioEntry> ents;
32+
ifstream ifs("sdmc:/xor.play.json");
33+
if(ifs.good())
34+
{
35+
json parser;
36+
ifs >> parser;
37+
for(auto i = parser.begin(); i != parser.end(); i++)
38+
{
39+
string stid = i.key();
40+
u64 tid = strtoull(stid.c_str(), NULL, 16);
41+
if(tid < 0x0100000000002000) tid = 0;
42+
string aud = i.value().get<string>();
43+
AudioEntry ent = { tid, aud };
44+
ents.push_back(ent);
45+
}
46+
}
47+
ifs.close();
48+
if(ents.empty()) return 0;
49+
while(appletMainLoop())
50+
{
51+
Result rc;
52+
u64 pid;
53+
u64 tid = 0;
54+
int count;
55+
u64* pids = new u64[256];
56+
u32 pid_count;
57+
Handle debug_handle;
58+
DebugEventInfo *d = new DebugEventInfo;
59+
svcGetProcessList(&pid_count, pids, 256);
60+
for(int i = 0; i < pid_count; i++)
61+
{
62+
if(true) // (pids[i] >= 0x70)
63+
{
64+
rc = svcDebugActiveProcess(&debug_handle, pids[i]);
65+
if(R_SUCCEEDED(rc))
66+
{
67+
pid = pids[i];
68+
while(R_SUCCEEDED(svcGetDebugEvent((u8*)d, debug_handle))) if(d->type == DebugEventType::AttachProcess) break;
69+
tid = d->info.attach_process.title_id;
70+
svcCloseHandle(debug_handle);
71+
break;
72+
}
73+
}
74+
}
75+
if(Mix_PlayingMusic() != 1) cplay = false;
76+
if(!cplay)
77+
{
78+
for(int i = 0; i < ents.size(); i++)
79+
{
80+
AudioEntry eent = ents[i];
81+
if(tid == eent.TitleID)
82+
{
83+
audio = Mix_LoadMUS(eent.Audio.c_str());
84+
Mix_PlayMusic(audio, 1);
85+
playid = tid;
86+
cplay = true;
87+
break;
88+
}
89+
}
90+
}
91+
else
92+
{
93+
if(tid != playid)
94+
{
95+
Mix_HaltMusic();
96+
Mix_FreeMusic(audio);
97+
cplay = false;
98+
}
99+
}
100+
svcSleepThread(30000000L);
101+
}
102+
Mix_CloseAudio();
103+
Mix_Quit();
104+
SDL_Quit();
105+
return 0;
106+
}

0 commit comments

Comments
 (0)