mirror of
https://github.com/jugeeya/UltimateTrainingModpack.git
synced 2024-11-20 08:54:15 +00:00
use defined clear_lua_stack to not step on code-mod-framework reimpl
This commit is contained in:
parent
0d47295215
commit
5b4d3bb28b
5 changed files with 21 additions and 115 deletions
|
@ -38,11 +38,11 @@ struct ACMD {
|
|||
}
|
||||
|
||||
void frame(float f) {
|
||||
l2c_agent->clear_lua_stack();
|
||||
l2c_agent->_clear_lua_stack();
|
||||
L2CValue frame_val(f);
|
||||
l2c_agent->push_lua_stack(&frame_val);
|
||||
app::sv_animcmd::frame(l2c_agent->lua_state_agent, f);
|
||||
l2c_agent->clear_lua_stack();
|
||||
l2c_agent->_clear_lua_stack();
|
||||
}
|
||||
|
||||
// attempted reimplementation of sv_animcmd::frame
|
||||
|
@ -87,29 +87,29 @@ struct ACMD {
|
|||
}
|
||||
|
||||
void wait(float f) {
|
||||
l2c_agent->clear_lua_stack();
|
||||
l2c_agent->_clear_lua_stack();
|
||||
L2CValue frame_val(f);
|
||||
l2c_agent->push_lua_stack(&frame_val);
|
||||
app::sv_animcmd::wait(l2c_agent->lua_state_agent, f);
|
||||
l2c_agent->clear_lua_stack();
|
||||
l2c_agent->_clear_lua_stack();
|
||||
}
|
||||
|
||||
bool is_excute() {
|
||||
l2c_agent->clear_lua_stack();
|
||||
l2c_agent->_clear_lua_stack();
|
||||
app::sv_animcmd::is_excute(l2c_agent->lua_state_agent);
|
||||
L2CValue is_excute;
|
||||
l2c_agent->get_lua_stack(1, &is_excute);
|
||||
bool excute = (bool)(is_excute);
|
||||
l2c_agent->clear_lua_stack();
|
||||
l2c_agent->_clear_lua_stack();
|
||||
return excute;
|
||||
}
|
||||
|
||||
void wrap(u64 (*acmd_func)(u64), std::initializer_list<L2CValue> list) {
|
||||
l2c_agent->clear_lua_stack();
|
||||
l2c_agent->_clear_lua_stack();
|
||||
for (L2CValue elem : list) l2c_agent->push_lua_stack(&elem);
|
||||
|
||||
acmd_func(l2c_agent->lua_state_agent);
|
||||
l2c_agent->clear_lua_stack();
|
||||
l2c_agent->_clear_lua_stack();
|
||||
}
|
||||
|
||||
void ATTACK(u64 i1, // ID
|
||||
|
|
|
@ -227,16 +227,7 @@ void ATTACK_replace(u64 a1) {
|
|||
generate_hitbox_effects(&l2c_agent, &bone, &size, &x, &y, &z, &x2, &y2, &z2, &color);
|
||||
}
|
||||
|
||||
u64 v1, v2, i;
|
||||
v1 = a1;
|
||||
|
||||
// original code: clear_lua_stack section
|
||||
v2 = LOAD64(v1 + 16);
|
||||
for (i = **(u64 **)(v1 + 32) + 16LL; v2 < i; v2 = LOAD64(v1 + 16)) {
|
||||
LOAD64(v1 + 16) = v2 + 16;
|
||||
*(__int32_t *)(v2 + 8) = 0;
|
||||
}
|
||||
LOAD64(v1 + 16) = i;
|
||||
l2c_agent._clear_lua_stack();
|
||||
}
|
||||
|
||||
void CATCH_replace(u64 a1) {
|
||||
|
|
|
@ -127,6 +127,18 @@ namespace lib {
|
|||
|
||||
u64 sv_set_function_hash(u64 (*func)(L2CAgent*, void*), u64 hash) asm("_ZN3lib8L2CAgent20sv_set_function_hashEPvN3phx6Hash40E") LINKABLE;
|
||||
u64 clear_lua_stack() asm("_ZN3lib8L2CAgent15clear_lua_stackEv") LINKABLE;
|
||||
u64 _clear_lua_stack() {
|
||||
u64 v1, v2, i;
|
||||
v1 = this->lua_state_agent;
|
||||
|
||||
v2 = LOAD64(v1 + 16);
|
||||
for (i = **(u64 **)(v1 + 32) + 16LL; v2 < i; v2 = LOAD64(v1 + 16)) {
|
||||
LOAD64(v1 + 16) = v2 + 16;
|
||||
*(__int32_t *)(v2 + 8) = 0;
|
||||
}
|
||||
LOAD64(v1 + 16) = i;
|
||||
return (u64)this;
|
||||
}
|
||||
};
|
||||
|
||||
bool lua_bind_get_value(u64, int*) asm("_ZN3lib18lua_bind_get_valueIiEEbmRT_") LINKABLE;
|
||||
|
|
|
@ -1,82 +0,0 @@
|
|||
#ifndef NN_RO_H
|
||||
#define NN_RO_H
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
#define nn_ro_LoadModule _ZN2nn2ro10LoadModuleEPNS0_6ModuleEPKvPvmi
|
||||
extern uint64_t _ZN2nn2ro10LoadModuleEPNS0_6ModuleEPKvPvmi(void* module, void const* unk_1, void* unk_2, unsigned long unk_3, int unk_4) LINKABLE;
|
||||
|
||||
typedef unsigned char undefined;
|
||||
typedef unsigned char byte;
|
||||
typedef unsigned char dwfenc;
|
||||
typedef unsigned int dword;
|
||||
typedef long long longlong;
|
||||
typedef unsigned long long qword;
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned long ulong;
|
||||
typedef unsigned long long ulonglong;
|
||||
typedef unsigned char undefined1;
|
||||
typedef unsigned short undefined2;
|
||||
typedef unsigned int undefined3;
|
||||
typedef unsigned int undefined4;
|
||||
typedef unsigned long long undefined5;
|
||||
typedef unsigned long long undefined6;
|
||||
typedef unsigned long long undefined7;
|
||||
typedef unsigned long long undefined8;
|
||||
typedef unsigned short ushort;
|
||||
typedef unsigned short word;
|
||||
|
||||
enum module_state {module_unloaded, module_loaded};
|
||||
|
||||
typedef struct RoModule_t {
|
||||
struct RoModule_t *next;
|
||||
struct RoModule_t *prev;
|
||||
union {
|
||||
void *rel;
|
||||
void *rela;
|
||||
void *raw;
|
||||
} rela_or_rel_plt;
|
||||
union {
|
||||
void *rel;
|
||||
void *rela;
|
||||
} rela_or_rel;
|
||||
uint64_t module_base;
|
||||
void *dyanmic;
|
||||
bool is_rela;
|
||||
uint64_t rela_or_rel_plt_size;
|
||||
void (*dt_init)(void);
|
||||
void (*dt_fini)(void);
|
||||
uint32_t *hash_bucket;
|
||||
uint32_t *hash_chain;
|
||||
char *dynstr;
|
||||
void *dynsym;
|
||||
uint64_t dynstr_size;
|
||||
void **got;
|
||||
uint64_t rela_dyn_size;
|
||||
uint64_t rel_dyn_size;
|
||||
uint64_t rel_count;
|
||||
uint64_t rela_count;
|
||||
uint64_t hash_nchain_value;
|
||||
uint64_t hash_nbucket_value;
|
||||
uint64_t got_stub_ptr;
|
||||
} RoModule;
|
||||
|
||||
typedef struct Module_t {
|
||||
RoModule *module;
|
||||
enum module_state state;
|
||||
uintptr_t module_address;
|
||||
uintptr_t bss_address;
|
||||
} Module;
|
||||
|
||||
typedef struct SmashModule { /* PlaceHolder Structure */
|
||||
Module module;
|
||||
void *field_0x20;
|
||||
void *src_buffer;
|
||||
char name[256]; /* Created by retype action */
|
||||
undefined field_0x130;
|
||||
undefined field_0x131;
|
||||
undefined4 is_loaded; // bool
|
||||
} SmashModule;
|
||||
|
||||
# endif // NN_RO_H
|
|
@ -6,14 +6,11 @@
|
|||
#include "saltysd_core.h"
|
||||
#include "saltysd_ipc.h"
|
||||
#include "saltysd_dynamic.h"
|
||||
#include "nn_ro.h"
|
||||
|
||||
#define ANCHOR_REL 0x70ffffc000
|
||||
u64 ANCHOR_ABS;
|
||||
#define IMPORT(x) (x - ANCHOR_REL + ANCHOR_ABS)
|
||||
|
||||
void (*SaltySD_installed_hook)(char*, u64) = NULL;
|
||||
|
||||
int SaltySD_function_replace(u64 addr, u64 new_func) {
|
||||
if (addr) {
|
||||
SaltySD_Memcpy(addr, (u64) "\x49\x00\x00\x58", 4); // LDR X9, .+8
|
||||
|
@ -30,16 +27,4 @@ int SaltySD_function_replace_sym(char* function_sym, u64 new_func) {
|
|||
return SaltySD_function_replace(addr, new_func);
|
||||
}
|
||||
|
||||
void LoadModule(SmashModule *module, void *param_2, void *param_3, unsigned long param_4, int param_5) {
|
||||
nn_ro_LoadModule(module, param_2, param_3, param_4, param_5);
|
||||
if (SaltySD_installed_hook != NULL) {
|
||||
SaltySD_installed_hook((char*)&module->name, (u64)module->module.module->module_base);
|
||||
}
|
||||
}
|
||||
|
||||
void SaltySD_install_nro_hook(u64 LoadModule_thunk_addr, void hook_main(char*, u64)) {
|
||||
SaltySD_installed_hook = hook_main;
|
||||
SaltySD_function_replace(LoadModule_thunk_addr, (u64) LoadModule);
|
||||
}
|
||||
|
||||
#endif // SALTYSD_HELPER_H
|
||||
|
|
Loading…
Reference in a new issue