mirror of https://github.com/sm64pc/sm64pc.git
Added load_graph_node & save_graph_node hooks
This commit is contained in:
parent
701dffa219
commit
0657d7e6e2
|
@ -200,10 +200,6 @@ void spawn_sparkle_particles(s32 n, s32 a1, s32 a2, s32 r) {
|
|||
coss(D_8035FF10 + i * separation) * a1, o, MODEL_NONE, bhvSparkleSpawn);
|
||||
}
|
||||
|
||||
if (1)
|
||||
{
|
||||
}
|
||||
|
||||
D_8035FF10 += r * 0x100;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "textures/mod-texture.h"
|
||||
#include "shaders/mod-shaders.h"
|
||||
#include "moon/achievements/achievements.h"
|
||||
#include "models/mod-model.h"
|
||||
|
||||
#include "moon/fs/moonfs.h"
|
||||
#include "moon/libs/nlohmann/json.hpp"
|
||||
|
@ -151,6 +152,7 @@ namespace MoonInternal {
|
|||
void setupModEngine( string state ){
|
||||
MoonInternal::setupTextureEngine(state);
|
||||
MoonInternal::setupAchievementEngine(state);
|
||||
MoonInternal::setupModelEngine(state);
|
||||
|
||||
if(state == "PreStartup"){
|
||||
MoonInternal::scanAddonsDirectory();
|
||||
|
|
|
@ -23,16 +23,65 @@ namespace MoonInternal {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
string hookName;
|
||||
map<string, void*> initArgs;
|
||||
map<string, void*> hookArgs;
|
||||
|
||||
/*
|
||||
#############################
|
||||
Module: Hook C++ Handle
|
||||
#############################
|
||||
*/
|
||||
|
||||
namespace MoonInternal {
|
||||
void bindHook(string name){
|
||||
hookName = name;
|
||||
}
|
||||
|
||||
void initBindHook(int length, ...){
|
||||
if(length > 0){
|
||||
va_list args;
|
||||
va_start(args, length);
|
||||
for(int i = 0; i < length; i++) {
|
||||
HookParameter currentParam = va_arg(args, struct HookParameter);
|
||||
initArgs[currentParam.name] = currentParam.parameter;
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
|
||||
bool callBindHook(int length, ...){
|
||||
if(length > 0){
|
||||
va_list args;
|
||||
va_start(args, length);
|
||||
for(int i = 0; i < length; i++) {
|
||||
HookParameter currentParam = va_arg(args, struct HookParameter);
|
||||
hookArgs[currentParam.name] = currentParam.parameter;
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
bool cancelled = MoonInternal::handleHook({
|
||||
.name = hookName,
|
||||
.baseArgs = initArgs,
|
||||
.hookedArgs = hookArgs
|
||||
});
|
||||
|
||||
hookName = "";
|
||||
initArgs.clear();
|
||||
hookArgs.clear();
|
||||
|
||||
return cancelled;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
#############################
|
||||
Module: Hook C Handle
|
||||
#############################
|
||||
*/
|
||||
|
||||
string hookName;
|
||||
map<string, void*> initArgs;
|
||||
map<string, void*> hookArgs;
|
||||
|
||||
extern "C" {
|
||||
|
||||
void moon_bind_hook(char* name){
|
||||
|
|
|
@ -11,6 +11,9 @@ struct HookParameter {
|
|||
#define HUD_DRAW "HudDraw"
|
||||
#define POST_HUD_DRAW "PostHudDraw"
|
||||
|
||||
#define SAVE_GRAPH_NODE "SaveGraphNode"
|
||||
#define LOAD_GRAPH_NODE "LoadGraphNode"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <string>
|
||||
|
@ -34,6 +37,12 @@ namespace Moon {
|
|||
void registerHookListener(HookListener listener);
|
||||
}
|
||||
|
||||
namespace MoonInternal {
|
||||
void bindHook(std::string name);
|
||||
void initBindHook(int length, ...);
|
||||
bool callBindHook(int length, ...);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void moon_bind_hook(char* name);
|
||||
|
|
|
@ -2,24 +2,40 @@
|
|||
|
||||
#include "moon/mod-engine/interfaces/file-entry.h"
|
||||
#include "moon/mod-engine/interfaces/bit-module.h"
|
||||
#include "moon/mod-engine/hooks/hook.h"
|
||||
#include "types.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include "model_ids.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
map<int, GraphNode*> loadedGraphNodes;
|
||||
|
||||
namespace MoonInternal {
|
||||
void setupModelEngine(string state) {
|
||||
if(state == "Init"){}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"{
|
||||
void bind_graph_node(int modelId, struct GraphNode *graphNode){
|
||||
MoonInternal::bindHook(SAVE_GRAPH_NODE);
|
||||
MoonInternal::initBindHook(2,
|
||||
(struct HookParameter){.name = "modelId", .parameter = (void*) &modelId},
|
||||
(struct HookParameter){.name = "graphNode", .parameter = (void*) &graphNode}
|
||||
);
|
||||
MoonInternal::callBindHook(0);
|
||||
loadedGraphNodes[modelId] = graphNode;
|
||||
// cout << "Binding model with id " << modelId << endl;
|
||||
}
|
||||
struct GraphNode * get_graph_node(int modelId){
|
||||
if(loadedGraphNodes.find(modelId) == loadedGraphNodes.end()) return NULL;
|
||||
// cout << "Loading model with id " << modelId << endl;
|
||||
MoonInternal::bindHook(LOAD_GRAPH_NODE);
|
||||
MoonInternal::initBindHook(1,
|
||||
(struct HookParameter){.name = "modelId", .parameter = (void*) &modelId}
|
||||
);
|
||||
MoonInternal::callBindHook(0);
|
||||
return loadedGraphNodes[modelId];
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ namespace Moon {
|
|||
}
|
||||
|
||||
namespace MoonInternal {
|
||||
void setupModuleEngine( std::string state );
|
||||
void setupModelEngine( std::string state );
|
||||
}
|
||||
|
||||
#else
|
||||
|
|
Loading…
Reference in New Issue