Skip to content

Commit

Permalink
Update for libnx 4.2.0
Browse files Browse the repository at this point in the history
Messily hacked together old and new files to update to libnx 4.2.0 and EdiZon-SE 3.8.25
  • Loading branch information
proferabg committed Nov 29, 2021
1 parent 1cc40d6 commit 22a30de
Show file tree
Hide file tree
Showing 16 changed files with 1,748 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
###################
#.gitignore #
###################

build/
out/
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "libs/EdiZon-SE"]
path = libs/EdiZon-SE
url = https://github.com/tomvita/EdiZon-SE.git
[submodule "libs/libtesla"]
path = libs/libtesla
url = https://github.com/WerWolv/libtesla.git
206 changes: 206 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------

ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
endif

TOPDIR ?= $(CURDIR)
include $(DEVKITPRO)/libnx/switch_rules

ifeq ($(SNAPSHOT), 1)
APP_VERSION := ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO} Snapshot
else
APP_VERSION := ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}
endif

APP_TITLE := EdiZon
APP_AUTHOR := WerWolv & proferabg
APP_VERSION := v1.0.1

TARGET := EdiZon
OUTDIR := out
BUILD := build
SOURCES_TOP := source libs/libtesla/source
SOURCES += $(foreach dir,$(SOURCES_TOP),$(shell find $(dir) -type d 2>/dev/null))
INCLUDES := include libs/EdiZon-SE/include libs/libtesla/include
#EXCLUDES := dmntcht.c
DATA := data
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
null :=
SPACE := $(null) $(null)

ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE

CFLAGS := -g -Wall -O3 -ffunction-sections \
$(ARCH) $(DEFINES) \
-DVERSION_MAJOR=${VERSION_MAJOR} \
-DVERSION_MINOR=${VERSION_MINOR} \
-DVERSION_MICRO=${VERSION_MICRO} \
-DVERSION_STRING=\"$(subst $(SPACE),\$(SPACE),${APP_VERSION})\"

CFLAGS += $(INCLUDE) -D__SWITCH__ -D__OVERLAY__ -I$(PORTLIBS)/include/freetype2 $(pkg-config --cflags --libs python3) -Wno-deprecated-declarations

CXXFLAGS := $(CFLAGS) -fexceptions -std=gnu++17

ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)

LIBS := -lnx

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(CURDIR)/libs/nxpy $(PORTLIBS) $(LIBNX)


#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------

export OUTPUT := $(CURDIR)/$(OUTDIR)/ovlEdiZon
export TOPDIR := $(CURDIR)

export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))

export DEPSDIR := $(CURDIR)/$(BUILD)


CFILES := $(filter-out $(EXCLUDES),$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))))
CPPFILES := $(filter-out $(EXCLUDES),$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))))
SFILES := $(filter-out $(EXCLUDES),$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))))
BINFILES := $(filter-out $(EXCLUDES),$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))))

#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------

export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))

export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)

export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)

ifeq ($(strip $(CONFIG_JSON)),)
jsons := $(wildcard *.json)
ifneq (,$(findstring $(TARGET).json,$(jsons)))
export APP_JSON := $(TOPDIR)/$(TARGET).json
else
ifneq (,$(findstring config.json,$(jsons)))
export APP_JSON := $(TOPDIR)/config.json
endif
endif
else
export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
endif

ifeq ($(strip $(ICON)),)
icons := $(wildcard *.jpg)
ifneq (,$(findstring $(TARGET).jpg,$(icons)))
export APP_ICON := $(TOPDIR)/$(TARGET).jpg
else
ifneq (,$(findstring icon.jpg,$(icons)))
export APP_ICON := $(TOPDIR)/icon.jpg
endif
endif
else
export APP_ICON := $(TOPDIR)/$(ICON)
endif

ifeq ($(strip $(NO_ICON)),)
export NROFLAGS += --icon=$(APP_ICON)
endif

ifeq ($(strip $(NO_NACP)),)
export NROFLAGS += --nacp=$(CURDIR)/$(OUTDIR)/ovlEdiZon.nacp
endif

ifneq ($(APP_TITLEID),)
export NACPFLAGS += --titleid=$(APP_TITLEID)
endif

ifneq ($(ROMFS),)
export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
endif

.PHONY: $(BUILD) clean all install

#---------------------------------------------------------------------------------
all: $(BUILD)

$(BUILD):
@[ -d $@ ] || mkdir -p $@ $(BUILD) $(OUTDIR)
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

#---------------------------------------------------------------------------------
clean:
@echo " RM " $(BUILD) $(OUTDIR)
@rm -fr $(BUILD) $(OUTDIR)

#---------------------------------------------------------------------------------
install: all
@echo " LFTP " $@
@lftp -e "put -O /switch/.overlays ./out/ovlEdiZon.ovl;bye" $(IP)

#---------------------------------------------------------------------------------
else
.PHONY: all

DEPENDS := $(OFILES:.o=.d)

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
all : $(OUTPUT).ovl

$(OUTPUT).ovl : $(OUTPUT).nro

$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm

$(OUTPUT).nso : $(OUTPUT).elf

$(OUTPUT).nro : $(OUTPUT).nso $(OUTPUT).nacp

$(OUTPUT).elf : $(OFILES)

$(OFILES_SRC) : $(HFILES_BIN)

#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
@echo " BIN " $@
@$(bin2o)

%.ttf.o %_ttf.h : %.ttf
@echo " BIN " $@
@$(bin2o)

-include $(DEPENDS)

#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
EdiZon-Overlay
EdiZon-Overlay by WerWolv

Updated by proferabg for libnx 4.2.0
119 changes: 119 additions & 0 deletions include/cheat.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/**
* Copyright (C) 2019 - 2020 WerWolv
*
* This file is part of EdiZon.
*
* EdiZon is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* EdiZon is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EdiZon. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <edizon.h>
//#include <helpers/dmntcht.h>
#include <helpers/util.h>
#include "cheat_engine_types.hpp"
#include "result.hpp"
#include "results.hpp"
#include "dmntcht.h"

#include <string>
#include <vector>

namespace edz::cheat {

// Work around for EResult madness
bool Succeeded(Result res);

#define EDIZON_CHEATS_DIR EDIZON_DIR "/cheats"
#define EMPTY_RESPONSE { }

class Cheat {
public:
Cheat(DmntCheatEntry cheatEntry);

std::string getName();
u32 getID();

bool toggle();
bool setState(bool state);
bool isEnabled();

private:
std::string m_name;
u32 m_id;
};

class FrozenAddress {
public:
FrozenAddress(DmntFrozenAddressEntry);
FrozenAddress(u64 address, u8 width, u64 value);
FrozenAddress(u64 address, u8 width);

u64 getAddress();
u8 getWidth();
u64 getValue();
u64 setValue(u64 value, u8 width);

bool toggle();
bool isFrozen();

private:
DmntFrozenAddressEntry m_frozenAddressEntry;
bool m_frozen;
};


class CheatManager {
public:
static Result initialize();
static void exit();

static bool isCheatServiceAvailable();

static bool forceAttach();
static bool hasCheatProcess();

static u64 getTitleID();
static u64 getProcessID();
static u64 getBuildID();

static types::Region getBaseRegion();
static types::Region getHeapRegion();
static types::Region getMainRegion();
static types::Region getAliasRegion();

//static EResultVal<std::string> getCheatFile();

//static EResultVal<u32> addCheat(DmntCheatDefinition cheatDefinition, bool enabled);
static Result removeCheat(u32 cheatID);

static std::vector<Cheat*>& getCheats();
static std::vector<FrozenAddress*>& getFrozenAddresses();

static MemoryInfo queryMemory(u64 address);
static std::vector<MemoryInfo> getMemoryRegions();

static Result readMemory(u64 address, void *buffer, size_t bufferSize);
static Result writeMemory(u64 address, const void *buffer, size_t bufferSize);

static Result reload();

private:
static inline std::vector<Cheat*> s_cheats;
static inline std::vector<FrozenAddress*> s_frozenAddresses;

static inline DmntCheatProcessMetadata s_processMetadata;
};

}
Loading

0 comments on commit 22a30de

Please sign in to comment.