Added more hook events

This commit is contained in:
KiritoDev 2021-05-24 23:35:31 -05:00
parent d89c49d72c
commit e3f11cbc43
8 changed files with 150 additions and 8 deletions

View File

@ -293,6 +293,9 @@ SRC_DIRS += src/moon/mod-engine/hooks
# Moon64 SRC [Mod-Engine - Shaders Module]
SRC_DIRS += src/moon/mod-engine/shaders
# Moon64 SRC [Achievements]
SRC_DIRS += src/moon/achievements
# Moon64 LIB [RapidJSON]
SRC_DIRS += src/moon/libs/rapidjson src/moon/libs/rapidjson/error src/moon/libs/rapidjson/internal src/moon/libs/rapidjson/msinttypes

View File

@ -15,6 +15,7 @@
#include "save_file.h"
#include "print.h"
#include "pc/configfile.h"
#include "moon/mod-engine/hooks/hook.h"
#ifdef TARGET_SWITCH
#define AVOID_UTYPES
@ -473,6 +474,11 @@ void render_nx_hud(void){
* excluding the cannon reticle which detects a camera preset for it.
*/
void render_hud(void) {
moon_bind_hook(PRE_HUD_DRAW);
moon_init_hook(0);
if(moon_call_hook(0)){
return;
}
s16 hudDisplayFlags;
hudDisplayFlags = gHudDisplay.flags;
@ -484,6 +490,12 @@ void render_hud(void) {
} else {
create_dl_ortho_matrix();
moon_bind_hook(HUD_DRAW);
moon_init_hook(0);
if(moon_call_hook(0)){
return;
}
if (gCurrentArea != NULL && gCurrentArea->camera->mode == CAMERA_MODE_INSIDE_CANNON) {
render_hud_cannon_reticle();
}
@ -518,4 +530,8 @@ void render_hud(void) {
}
}
moon_bind_hook(POST_HUD_DRAW);
moon_init_hook(0);
moon_call_hook(0);
}

View File

@ -0,0 +1,83 @@
#include "achievements.h"
#include "moon/mod-engine/hooks/hook.h"
#include "moon/ui/utils/moon-draw-utils.h"
#include "moon/ui/interfaces/moon-screen.h"
#include <vector>
std::map<Achievement*, bool> entries;
namespace AchievementList {
Achievement* TRIPLE_JUMP = new Achievement("achievement.doATripleJump", "test", "Getting higher", "Do a triple jump", 0, nullptr);
};
namespace Moon {
void showAchievement(Achievement* achievement){
if(entries.find(achievement) == entries.end())
entries[achievement] = false;
}
void showAchievementById(Achievement* achievement){
}
}
int w = 0;
int h = 32;
int aId = -1;
bool launched = false;
int delay = 35;
int cgid = 0;
namespace MoonInternal{
void setupAchievementEngine(std::string status){
entries[AchievementList::TRIPLE_JUMP] = false;
if(status == "Init"){
Moon::registerHookListener({.hookName = HUD_DRAW, .callback = [](HookCall call){
cgid++;
int id = 0;
if(cgid > 90){
launched = true;
}
if(!launched) return;
for(auto &achievement : entries){
if(!achievement.second){
if(!(gGlobalTimer % delay)){
aId++;
}
switch(aId){
case 0:
if(w < 32){
w += 4;
}
break;
case 1:
if(w < 128){
w += 16;
}
delay = 60;
break;
case 2:
if(w > 0){
w -= 36;
}
break;
}
MoonDrawRectangle(GetScreenWidth(false) / 2 - w / 2, GetScreenHeight() - h - 20, w, h, {255, 255, 255, 100}, false);
if(w >= 32)
MoonDrawRectangle(GetScreenWidth(false) / 2 - w / 2, GetScreenHeight() - h - 20, 32, 32, {0, 255, 200, 100}, false);
id++;
}
}
}});
}
}
}

View File

@ -0,0 +1,37 @@
#ifndef MoonAchievements
#define MoonAchievements
#include <string>
class Achievement {
protected:
std::string id;
std::string icon;
std::string title;
std::string description;
Achievement* parent;
int points;
public:
Achievement(std::string id, std::string icon, std::string title, std::string description, int points, Achievement* parent){
this->id = id;
this->icon = icon;
this->title = title;
this->description = description;
this->parent = parent;
this->points = points;
}
};
namespace Moon {
void showAchievement(Achievement* achievement);
}
namespace MoonInternal{
void setupAchievementEngine(std::string status);
}
namespace AchievementList {
extern Achievement* TRIPLE_JUMP;
}
#endif

View File

@ -4,6 +4,7 @@
#include "interfaces/file-entry.h"
#include "textures/mod-texture.h"
#include "shaders/mod-shaders.h"
#include "moon/achievements/achievements.h"
#include "moon/fs/moonfs.h"
#include "moon/libs/nlohmann/json.hpp"
@ -149,6 +150,7 @@ namespace MoonInternal {
void setupModEngine( string state ){
MoonInternal::setupTextureEngine(state);
MoonInternal::setupAchievementEngine(state);
if(state == "PreStartup"){
MoonInternal::scanAddonsDirectory();

View File

@ -17,11 +17,9 @@ namespace Moon {
namespace MoonInternal {
bool handleHook(HookCall call){
bool cancelled = false;
for (auto& listener : listeners[string(call.name)]){
cancelled = (*listener)(call);
}
return cancelled;
for (auto& listener : listeners[string(call.name)])
(*listener)(call);
return call.cancelled;
}
}

View File

@ -6,7 +6,10 @@ struct HookParameter {
void* parameter;
};
#define TEXTURE_BIND "TextureBind"
#define TEXTURE_BIND "TextureBind"
#define PRE_HUD_DRAW "PreHudDraw"
#define HUD_DRAW "HudDraw"
#define POST_HUD_DRAW "PostHudDraw"
#ifdef __cplusplus
@ -17,9 +20,10 @@ struct HookCall {
std::string name;
std::map<std::string, void*> baseArgs;
std::map<std::string, void*> hookedArgs;
bool cancelled = false;
};
typedef bool HookFunc(HookCall call);
typedef void HookFunc(HookCall call);
struct HookListener {
std::string hookName;
HookFunc *callback;

View File

@ -42,7 +42,6 @@ void AnimatedModifier::onInit(){
(*hookTexture) = const_cast<char*>(frame->path.c_str());
}
return false;
}});
}