diff --git a/src/main.cpp b/src/main.cpp
index c2967bd..12edd5f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -54,6 +54,7 @@
#include "patcher/hooks_patcher.h"
#include "patcher/hooks_patcher_static.h"
#include "plugin/dynamic_linking_defines.h"
+#include "myutils/mem_utils.h"
#include "myutils/mocha.h"
#include "myutils/libntfs.h"
#include "myutils/libfat.h"
@@ -135,6 +136,7 @@ extern "C" int32_t Menu_Main(int32_t argc, char **argv) {
CSettings::destroyInstance();
PluginLoader::destroyInstance();
+ MemoryUtils::init();
}
DEBUG_FUNCTION_LINE("Patch own stuff\n");
@@ -171,6 +173,7 @@ extern "C" int32_t Menu_Main(int32_t argc, char **argv) {
}
if(result == APPLICATION_CLOSE_APPLY || result == APPLICATION_CLOSE_APPLY_MEMORY) {
+ CallHook(WUPS_LOADER_HOOK_INIT_VID_MEM);
CallHook(WUPS_LOADER_HOOK_INIT_KERNEL);
CallHook(WUPS_LOADER_HOOK_INIT_FS);
CallHook(WUPS_LOADER_HOOK_INIT_OVERLAY);
diff --git a/src/mymemory/memory_mapping.cpp b/src/mymemory/memory_mapping.cpp
index 43512a4..b29a3de 100644
--- a/src/mymemory/memory_mapping.cpp
+++ b/src/mymemory/memory_mapping.cpp
@@ -76,6 +76,14 @@ uint32_t MemoryMapping::getHeapSize() {
return getAreaSizeFromPageTable(MEMORY_START_PLUGIN_HEAP,MEMORY_START_PLUGIN_HEAP_END - MEMORY_START_PLUGIN_HEAP);
}
+uint32_t MemoryMapping::getVideoMemoryAddress() {
+ return MEMORY_START_VIDEO_SPACE;
+}
+
+uint32_t MemoryMapping::getVideoMemorySize() {
+ return getAreaSizeFromPageTable(MEMORY_START_VIDEO_SPACE,MEMORY_START_VIDEO_SPACE_END - MEMORY_START_VIDEO_SPACE);
+}
+
void MemoryMapping::searchEmptyMemoryRegions() {
DEBUG_FUNCTION_LINE("Searching for empty memory.\n");
diff --git a/src/myutils/mem_utils.cpp b/src/myutils/mem_utils.cpp
new file mode 100644
index 0000000..6674412
--- /dev/null
+++ b/src/myutils/mem_utils.cpp
@@ -0,0 +1,37 @@
+/****************************************************************************
+ * Copyright (C) 2018 Maschell
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ ****************************************************************************/
+#include
+#include
+#include
+#include "dynamic_libs/os_functions.h"
+#include "mem_utils.h"
+#include "mymemory/memory_mapping.h"
+
+
+int32_t memHandle __attribute__((section(".data"))) = -1;
+
+void MemoryUtils::init(){
+ memHandle = MEMCreateExpHeapEx((void*)MemoryMapping::getVideoMemoryAddress(), MemoryMapping::getVideoMemorySize(), 0);
+}
+
+void* MemoryUtils::alloc(uint32_t size, int32_t align){
+ return MEMAllocFromExpHeapEx(memHandle,size, align);
+}
+
+void MemoryUtils::free(void * ptr){
+ MEMFreeToExpHeap(memHandle,ptr);
+}
diff --git a/src/myutils/mem_utils.h b/src/myutils/mem_utils.h
new file mode 100644
index 0000000..7a8cd9f
--- /dev/null
+++ b/src/myutils/mem_utils.h
@@ -0,0 +1,32 @@
+/****************************************************************************
+ * Copyright (C) 2018 Maschell
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ ****************************************************************************/
+#ifndef __MEMORY_UTILS_UTILS_H_
+#define __SCREEN_UTILS_H_
+
+class MemoryUtils {
+public:
+ static void init();
+
+ static void* alloc(uint32_t size, int32_t align);
+
+ static void free(void * ptr);
+private:
+ MemoryUtils() {}
+ ~MemoryUtils() {}
+
+};
+#endif
diff --git a/src/utils.cpp b/src/utils.cpp
index cc44b7e..76cedca 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -14,6 +14,7 @@
#include "common/common.h"
#include "common/retain_vars.h"
#include "myutils/overlay_helper.h"
+#include "myutils/mem_utils.h"
#include "kernel/syscalls.h"
void CallHook(wups_loader_hook_type_t hook_type) {
@@ -112,7 +113,12 @@ void CallHookEx(wups_loader_hook_type_t hook_type, int32_t plugin_index_needed)
((void (*)(wups_loader_init_kernel_args_t))((uint32_t*)func_ptr) )(args);
plugin_data->kernel_init_done = true;
}
- } else {
+ } else if(hook_type == WUPS_LOADER_HOOK_INIT_VID_MEM){
+ wups_loader_init_vid_mem_args_t args;
+ args.vid_mem_alloc_ptr = &MemoryUtils::alloc;
+ args.vid_mem_free_ptr = &MemoryUtils::free;
+ ((void (*)(wups_loader_init_vid_mem_args_t))((uint32_t*)func_ptr) )(args);
+ }else {
DEBUG_FUNCTION_LINE("ERROR: HOOK TYPE WAS NOT IMPLEMENTED %08X \n",hook_type);
}
} else {