1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2025-01-20 01:10:13 +00:00

finish migration to C++

This commit is contained in:
jugeeya 2019-05-18 21:16:48 -07:00
parent ed507f70e0
commit 1b5165d211
14 changed files with 16503 additions and 382 deletions

View file

@ -29,7 +29,7 @@ include $(DEVKITPRO)/libnx/switch_rules
# - icon.jpg
# - <libnx folder>/default_icon.jpg
#---------------------------------------------------------------------------------
TARGET := my_plugin
TARGET := hitbox_visualizer
BUILD := build
SOURCES := source
DATA := data

View file

@ -1,3 +1,6 @@
#ifndef ACMD_IMPORTS_H
#define ACMD_IMPORTS_H
#include <switch.h>
namespace app::sv_animcmd
@ -6,4 +9,11 @@ namespace app::sv_animcmd
extern void is_excute(u64) asm("_ZN3app10sv_animcmd9is_excuteEP9lua_State") LINKABLE;
extern u64 ATTACK(u64) asm("_ZN3app10sv_animcmd6ATTACKEP9lua_State") LINKABLE;
extern u64 EFFECT(u64) asm("_ZN3app10sv_animcmd6EFFECTEP9lua_State") LINKABLE;
extern u64 EFFECT(u64) asm("_ZN3app10sv_animcmd6EFFECTEP9lua_State") LINKABLE;
extern u64 EFFECT_FOLLOW_NO_SCALE(u64) asm("_ZN3app10sv_animcmd22EFFECT_FOLLOW_NO_SCALEEP9lua_State") LINKABLE;
extern u64 LAST_EFFECT_SET_COLOR(u64) asm("_ZN3app10sv_animcmd21LAST_EFFECT_SET_COLOREP9lua_State") LINKABLE;
extern u64 LAST_EFFECT_SET_RATE(u64) asm("_ZN3app10sv_animcmd20LAST_EFFECT_SET_RATEEP9lua_State") LINKABLE;
}
#endif // ACMD_IMPORTS_H

View file

@ -1,3 +1,6 @@
#ifndef ACMD_WRAPPER_H
#define ACMD_WRAPPER_H
#include <switch.h>
#include "acmd_imports.hpp"
@ -75,7 +78,7 @@ struct ACMD
bool is_excute() {
app::sv_animcmd::is_excute(l2c_agent->lua_state_agent);
L2CValue is_excute;
get_lua_stack(l2c_agent, 1, &is_excute);
l2c_agent->get_lua_stack(1, &is_excute);
bool excute = is_excute.raw;
l2c_agent->clear_lua_stack();
return excute;
@ -165,4 +168,6 @@ struct ACMD
l2c_agent->clear_lua_stack();
}
};
};
#endif // ACMD_WRAPPER_H

15880
source/const_value_table.h Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,179 @@
#include "l2c.hpp"
#include "saltysd_helper.hpp"
#include "l2c_imports.hpp"
#include "acmd_imports.hpp"
#include "taunt_toggles.h"
using namespace lib;
using namespace app::lua_bind;
using namespace app::sv_animcmd;
void (*AttackModule_set_attack_lua_state)(u64, u64);
void (*AttackModule_clear_all_orig)(u64);
void (*AttackModule_clear_orig)(u64, int);
Vector3f id_colors[8] = {
{1.0f, 0.0f, 0.0f}, {0.7843f, 0.3529f, 1.0f},
{1.0f, 0.7843f, 0.7843f}, {0.0f, 1.0f, 0.8431f},
{1.0f, 0.4706f, 0.0f}, {0.7843f, 0.7059f, 0.0f},
{0.7843f, 0.0f, 1.0f}, {0.3765f, 0.2863f, 0.5294f},
};
void app_sv_animcmd_ATTACK_replace(u64 a1);
void AttackModule_clear_all_replace(u64 module_accessor);
void AttackModule_clear_replace(u64 module_accessor, int id, bool unk);
void hitbox_vis_main() {
AttackModule_set_attack_lua_state =
(void (*)(u64, u64))SaltySDCore_FindSymbol("_ZN3app10sv_animcmd6ATTACKEP9lua_State") + 0xD0 - 0x70;
SaltySD_function_replace_sym(
"_ZN3app10sv_animcmd6ATTACKEP9lua_State",
(u64)&app_sv_animcmd_ATTACK_replace);
SaltySD_function_replace_sym(
"_ZN3app8lua_bind28AttackModule__clear_all_implEPNS_26BattleObjectModuleAccessorE",
(u64)&AttackModule_clear_all_replace);
}
void AttackModule_clear_all_replace(u64 module_accessor) {
u64 attack_module = LOAD64(module_accessor + 0xA0);
u64 attack_module_clear_all = LOAD64(attack_module) + 0x50LL;
u64 (*attack_module_clear_all_impl)(u64) =
(u64(*)(u64))(LOAD64(attack_module_clear_all));
attack_module_clear_all_impl(attack_module);
if (is_training_mode()) {
// Clear graphics every time we clear all hitboxes.
// Only if we're not shielding.
int status_kind = StatusModule::status_kind(module_accessor);
if (!(status_kind >= 0x1b && status_kind <= 0x1d)) {
Hash40 shieldEffectHash = {.hash = 0xAFAE75F05LL};
EffectModule::kill_kind(module_accessor, shieldEffectHash.hash, 0, 1);
}
}
}
void push_color(L2CAgent *l2c_agent, Vector3f color) {
L2CValue red = {.type = L2C_number, .raw_float = color.x};
L2CValue green = {.type = L2C_number, .raw_float = color.y};
L2CValue blue = {.type = L2C_number, .raw_float = color.z};
l2c_agent->push_lua_stack(&red);
l2c_agent->push_lua_stack(&green);
l2c_agent->push_lua_stack(&blue);
}
void generate_hitbox_effects(L2CAgent *l2c_agent, L2CValue *id, L2CValue *bone,
L2CValue *size, L2CValue *x, L2CValue *y,
L2CValue *z, L2CValue *x2, L2CValue *y2,
L2CValue *z2) {
float sizeMult = 19.0 / 200.0;
Hash40 shieldEffectHash = {.hash = 0xAFAE75F05LL};
L2CValue shieldEffect = {.type = L2C_hash, .raw = shieldEffectHash.hash};
L2CValue xRot = {.type = L2C_number, .raw_float = 0.0};
L2CValue yRot = {.type = L2C_number, .raw_float = 0.0};
L2CValue zRot = {.type = L2C_number, .raw_float = 0.0};
L2CValue terminate = {.type = L2C_bool, .raw = 1};
L2CValue effectSize = {.type = L2C_number, .raw_float = (float)size->raw_float * sizeMult};
L2CValue rate = {.type = L2C_number, .raw_float = 8.0f};
// Extended Hitboxes if x2, y2, z2 are not L2CValue::nil
int num_effects;
if (x2->type != L2C_void && y2->type != L2C_void && z2->type != L2C_void) {
num_effects = 4;
} else {
*x2 = *x;
*y2 = *y;
*z2 = *z;
num_effects = 1;
}
for (int i = 0; i < num_effects; i++) {
// EFFECT_FOLLOW_NO_SCALE(graphic, bone, x, y, z, xrot, yrot, zrot, size,
// terminate)
L2CValue currX = {
.type = L2C_number,
.raw_float = x->raw_float + ((x2->raw_float - x->raw_float) / 3 * i)};
L2CValue currY = {
.type = L2C_number,
.raw_float = y->raw_float + ((y2->raw_float - y->raw_float) / 3 * i)};
L2CValue currZ = {
.type = L2C_number,
.raw_float = z->raw_float + ((z2->raw_float - z->raw_float) / 3 * i)};
l2c_agent->clear_lua_stack();
l2c_agent->push_lua_stack(&shieldEffect);
l2c_agent->push_lua_stack(bone);
l2c_agent->push_lua_stack(&currX);
l2c_agent->push_lua_stack(&currY);
l2c_agent->push_lua_stack(&currZ);
l2c_agent->push_lua_stack(&xRot);
l2c_agent->push_lua_stack(&yRot);
l2c_agent->push_lua_stack(&zRot);
l2c_agent->push_lua_stack(&effectSize);
l2c_agent->push_lua_stack(&terminate);
EFFECT_FOLLOW_NO_SCALE(l2c_agent->lua_state_agent);
// Set to hitbox ID color
// LAST_EFFECT_SET_COLOR(Red, Green, Blue)
l2c_agent->clear_lua_stack();
push_color(l2c_agent, id_colors[id->raw % 8]);
LAST_EFFECT_SET_COLOR(l2c_agent->lua_state_agent);
// Speed up animation by rate to remove pulsing effect
// LAST_EFFECT_SET_RATE(Rate)
l2c_agent->clear_lua_stack();
l2c_agent->push_lua_stack(&rate);
LAST_EFFECT_SET_RATE(l2c_agent->lua_state_agent);
}
}
void app_sv_animcmd_ATTACK_replace(u64 a1) {
u64 v1; // x19
u64 v2; // x9
u64 i; // x8
// Instantiate our own L2CAgent with the given lua_State
L2CAgent l2c_agent;
l2c_agent.L2CAgent_constr(a1);
// Get all necessary hitbox params
L2CValue id, bone, damage, angle, kbg, wkb, bkb, size, x, y, z, x2, y2, z2;
l2c_agent.get_lua_stack(1, &id);
l2c_agent.get_lua_stack(3, &bone);
l2c_agent.get_lua_stack(4, &damage);
l2c_agent.get_lua_stack(5, &angle);
l2c_agent.get_lua_stack(6, &kbg);
l2c_agent.get_lua_stack(7, &wkb);
l2c_agent.get_lua_stack(8, &bkb);
l2c_agent.get_lua_stack(9, &size);
l2c_agent.get_lua_stack(10, &x);
l2c_agent.get_lua_stack(11, &y);
l2c_agent.get_lua_stack(12, &z);
l2c_agent.get_lua_stack(13, &x2);
l2c_agent.get_lua_stack(14, &y2);
l2c_agent.get_lua_stack(15, &z2);
// original code: parse lua stack and call AttackModule::set_attack()
v1 = a1;
AttackModule_set_attack_lua_state(LOAD64(LOAD64(a1 - 8) + 416LL), a1);
if (HITBOX_VIS && is_training_mode()) {
// Generate hitbox effect(s)
generate_hitbox_effects(&l2c_agent, &id, &bone, &size, &x, &y, &z, &x2, &y2,
&z2);
}
// 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;
}

View file

@ -5,6 +5,8 @@
#include "l2c.hpp"
#include "lua_bind_hash.hpp"
u64 is_training_mode(void) asm("_ZN3app9smashball16is_training_modeEv") LINKABLE;
namespace lib
{
enum L2CVarType
@ -88,13 +90,19 @@ namespace lib
// which is more traditional, i.e. -1 is the top of the stack.
//__int64_t (*lib_L2CAgent_pop_lua_stack)(__int64_t, int);
u64 pop_lua_stack(int index) asm("_ZN3lib8L2CAgent13pop_lua_stackEi") LINKABLE;
void get_lua_stack(int index, lib::L2CValue* l2c_val) {
asm("mov x8, %x0" : : "r"(l2c_val) : "x8" );
pop_lua_stack(index);
}
u64 sv_set_function_hash(void* func, u64 hash) asm("_ZN3lib8L2CAgent20sv_set_function_hashEPvN3phx6Hash40E") LINKABLE;
u64 clear_lua_stack() asm("_ZN3lib8L2CAgent15clear_lua_stackEv") LINKABLE;
};
bool lua_bind_get_value(u64, int*) asm("_ZN3lib18lua_bind_get_valueIiEEbmRT_") LINKABLE;
int CONST_VALUE(const char* str) {
int lua_const(const char* str) {
int val;
if (lua_bind_get_value(lua_bind_hash_str(str), &val))
return val;

View file

@ -3,9 +3,6 @@
#include <switch.h>
#include "l2c_imports.hpp"
void get_lua_stack(lib::L2CAgent* l2c_agent, int index, lib::L2CValue* l2c_val) {
asm("mov x8, %x0" : : "r"(l2c_val) : "x8" );
l2c_agent->pop_lua_stack(index);
}
#endif // LUA_HELPER_H

View file

@ -14,13 +14,11 @@
#include "saltysd_ipc.h"
#include "saltysd_dynamic.h"
#include "l2c.hpp"
#include "saltysd_helper.hpp"
#include "l2c_imports.hpp"
#include "acmd_imports.hpp"
#include "taunt_toggles.h"
#include "script_replacement.hpp"
#include "hitbox_visualizer.hpp"
#include "training_mods.hpp"
extern "C" {
extern u32 __start__;
@ -68,309 +66,6 @@ void __attribute__((weak)) NORETURN __libnx_exit(int rc)
__nx_exit(0, orig_saved_lr);
}
u64 effect_manager_addr;
u64 fighter_manager_addr;
u64 fighter_param_accessor2_addr;
void (*AttackModule_set_attack_lua_state)(u64, u64);
void (*AttackModule_clear_all_orig)(u64);
void (*AttackModule_clear_orig)(u64, int);
#define PI 3.14159265358979323846
using namespace lib;
using namespace app::lua_bind;
Vector3f id_colors[8] = {
{1.0f, 0.0f, 0.0f}, {0.7843f, 0.3529f, 1.0f},
{1.0f, 0.7843f, 0.7843f}, {0.0f, 1.0f, 0.8431f},
{1.0f, 0.4706f, 0.0f}, {0.7843f, 0.7059f, 0.0f},
{0.7843f, 0.0f, 1.0f}, {0.3765f, 0.2863f, 0.5294f},
};
#define is_training_mode _ZN3app9smashball16is_training_modeEv
extern u64 _ZN3app9smashball16is_training_modeEv(void) LINKABLE;
void AttackModule_clear_all_replace(u64 attack_module) {
AttackModule_clear_all_orig(attack_module);
if (is_training_mode()) {
u64 module_accessor = LOAD64(attack_module + 0x8);
// Clear graphics every time we clear all hitboxes.
// Only if we're not shielding.
int status_kind = StatusModule::status_kind(module_accessor);
if (!(status_kind >= 0x1b && status_kind <= 0x1d)) {
Hash40 shieldEffectHash = {.hash = 0xAFAE75F05LL};
EffectModule::kill_kind(module_accessor, shieldEffectHash.hash, 0, 1);
}
}
}
void AttackModule_clear_replace(u64 attack_module, int id) {
AttackModule_clear_orig(attack_module, id);
// TODO: Kill effect based on hitbox ID
}
void push_color(L2CAgent *l2c_agent, Vector3f color) {
L2CValue red = {.type = L2C_number, .raw_float = color.x};
L2CValue green = {.type = L2C_number, .raw_float = color.y};
L2CValue blue = {.type = L2C_number, .raw_float = color.z};
l2c_agent->push_lua_stack(&red);
l2c_agent->push_lua_stack(&green);
l2c_agent->push_lua_stack(&blue);
}
void generate_hitbox_effects(L2CAgent *l2c_agent, L2CValue *id, L2CValue *bone,
L2CValue *size, L2CValue *x, L2CValue *y,
L2CValue *z, L2CValue *x2, L2CValue *y2,
L2CValue *z2) {
float sizeMult = 19.0 / 200.0;
Hash40 shieldEffectHash = {.hash = 0xAFAE75F05LL};
L2CValue shieldEffect = {.type = L2C_hash, .raw = shieldEffectHash.hash};
L2CValue xRot = {.type = L2C_number, .raw_float = 0.0};
L2CValue yRot = {.type = L2C_number, .raw_float = 0.0};
L2CValue zRot = {.type = L2C_number, .raw_float = 0.0};
L2CValue terminate = {.type = L2C_bool, .raw = 1};
L2CValue effectSize = {.type = L2C_number, .raw_float = (float)size->raw_float * sizeMult};
L2CValue rate = {.type = L2C_number, .raw_float = 8.0f};
// Extended Hitboxes if x2, y2, z2 are not L2CValue::nil
int num_effects;
if (x2->type != L2C_void && y2->type != L2C_void && z2->type != L2C_void) {
num_effects = 4;
} else {
*x2 = *x;
*y2 = *y;
*z2 = *z;
num_effects = 1;
}
for (int i = 0; i < num_effects; i++) {
// EFFECT_FOLLOW_NO_SCALE(graphic, bone, x, y, z, xrot, yrot, zrot, size,
// terminate)
L2CValue currX = {
.type = L2C_number,
.raw_float = x->raw_float + ((x2->raw_float - x->raw_float) / 3 * i)};
L2CValue currY = {
.type = L2C_number,
.raw_float = y->raw_float + ((y2->raw_float - y->raw_float) / 3 * i)};
L2CValue currZ = {
.type = L2C_number,
.raw_float = z->raw_float + ((z2->raw_float - z->raw_float) / 3 * i)};
l2c_agent->clear_lua_stack();
l2c_agent->push_lua_stack(&shieldEffect);
l2c_agent->push_lua_stack(bone);
l2c_agent->push_lua_stack(&currX);
l2c_agent->push_lua_stack(&currY);
l2c_agent->push_lua_stack(&currZ);
l2c_agent->push_lua_stack(&xRot);
l2c_agent->push_lua_stack(&yRot);
l2c_agent->push_lua_stack(&zRot);
l2c_agent->push_lua_stack(&effectSize);
l2c_agent->push_lua_stack(&terminate);
//app_sv_animcmd_EFFECT_FOLLOW_NO_SCALE(l2c_agent->lua_state_agent);
// Set to hitbox ID color
// LAST_EFFECT_SET_COLOR(Red, Green, Blue)
l2c_agent->clear_lua_stack();
push_color(l2c_agent, id_colors[id->raw % 8]);
//app_sv_animcmd_LAST_EFFECT_SET_COLOR(l2c_agent->lua_state_agent);
// Speed up animation by rate to remove pulsing effect
// LAST_EFFECT_SET_RATE(Rate)
l2c_agent->clear_lua_stack();
l2c_agent->push_lua_stack(&rate);
//app_sv_animcmd_LAST_EFFECT_SET_RATE(l2c_agent->lua_state_agent);
}
}
void app_sv_animcmd_ATTACK_replace(u64 a1) {
u64 v1; // x19
u64 v2; // x9
u64 i; // x8
// Instantiate our own L2CAgent with the given lua_State
L2CAgent l2c_agent;
l2c_agent.L2CAgent_constr(a1);
// Get all necessary hitbox params
L2CValue id, bone, damage, angle, kbg, wkb, bkb, size, x, y, z, x2, y2, z2;
get_lua_stack(&l2c_agent, 1, &id);
get_lua_stack(&l2c_agent, 3, &bone);
get_lua_stack(&l2c_agent, 4, &damage);
get_lua_stack(&l2c_agent, 5, &angle);
get_lua_stack(&l2c_agent, 6, &kbg);
get_lua_stack(&l2c_agent, 7, &wkb);
get_lua_stack(&l2c_agent, 8, &bkb);
get_lua_stack(&l2c_agent, 9, &size);
get_lua_stack(&l2c_agent, 10, &x);
get_lua_stack(&l2c_agent, 11, &y);
get_lua_stack(&l2c_agent, 12, &z);
get_lua_stack(&l2c_agent, 13, &x2);
get_lua_stack(&l2c_agent, 14, &y2);
get_lua_stack(&l2c_agent, 15, &z2);
// original code: parse lua stack and call AttackModule::set_attack()
v1 = a1;
AttackModule_set_attack_lua_state(LOAD64(LOAD64(a1 - 8) + 416LL), a1);
if (HITBOX_VIS && is_training_mode()) {
// Replace AttackModule::clear_all() and AttackModule::clear(int)
u64 module_accessor = LOAD64(LOAD64(a1 - 8) + 416LL);
u64 attack_module = LOAD64(module_accessor + 0xA0);
u64 attack_module_clear_all = LOAD64(attack_module) + 0x50LL;
if (AttackModule_clear_all_orig == 0) {
AttackModule_clear_all_orig =
(void (*)(u64))(LOAD64(attack_module_clear_all));
}
LOAD64(attack_module_clear_all) = (u64)AttackModule_clear_all_replace;
u64 attack_module_clear = LOAD64(attack_module) + 0x58LL;
if (AttackModule_clear_orig == 0) {
AttackModule_clear_orig =
(void (*)(u64, int))(LOAD64(attack_module_clear));
}
LOAD64(attack_module_clear) = (u64)AttackModule_clear_replace;
// Generate hitbox effect(s)
generate_hitbox_effects(&l2c_agent, &id, &bone, &size, &x, &y, &z, &x2, &y2,
&z2);
}
// 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;
}
bool is_operation_cpu(u64 module_accessor) {
// entry_id_var: 0x10000000;
int entry_id = WorkModule::get_int(module_accessor,
CONST_VALUE("FIGHTER_INSTANCE_WORK_ID_INT_ENTRY_ID"));
u64 fighter_information = FighterManager::get_fighter_information(
LOAD64(fighter_manager_addr), entry_id);
return FighterInformation::is_operation_cpu(fighter_information);
}
u64 WorkModule_enable_transition_term_group_impl_replace(u64 module_accessor,
u64 transition_group) {
if (TOGGLE_STATE == MASH_AIRDODGE && is_training_mode()) {
// 0x1F00000D for airdodge
if (transition_group == 0x1F00000D) {
if (is_operation_cpu(module_accessor)) {
int status_kind = StatusModule::status_kind(module_accessor);
int prev_status_kind = 0;//StatusModule_prev_status_kind(module_accessor, 0);
// Damage -> DamageFall
if ((status_kind >= 0x48 && status_kind <= 0x50) ||
(prev_status_kind >= 0x48 && prev_status_kind <= 0x50)) {
StatusModule::change_status_request_from_script(module_accessor, 0x22,
1);
}
}
}
}
// call original WorkModule::enable_transition_term_group_impl
u64 work_module = LOAD64(module_accessor + 0x50);
u64 enable_transition_term_group_impl = LOAD64(work_module) + 0x140LL;
u64 (*work_module_enable_transition_term_group_impl)(u64, u64) =
(u64(*)(u64, u64))(LOAD64(enable_transition_term_group_impl));
return work_module_enable_transition_term_group_impl(work_module,
transition_group);
}
void show_angle(u64 module_accessor, float y, float x, float zrot) {
Hash40 raygunShot = {.hash = 0x11e470b07fLL};
Hash40 top = {.hash = 0x031ed91fcaLL};
Vector3f pos = {.x = x, .y = y, .z = 0};
Vector3f rot = {.x = 0, .y = 90, .z = zrot};
Vector3f random = {.x = 0, .y = 0, .z = 0};
float size = 0.5;
EffectModule::req_on_joint(module_accessor, raygunShot.hash, top.hash, &pos,
&rot, size, &random, &random, 0, 0, 0, 0);
}
float WorkModule_get_float_replace(u64 module_accessor, int var) {
if (is_training_mode()) {
if (is_operation_cpu(module_accessor)) {
int status_kind = StatusModule::status_kind(module_accessor);
// Damage -> DamageFall
if (status_kind >= 0x48 && status_kind <= 0x50) {
float angle = 0;//(DI_STATE - 1) * PI / 4.0;
if (var == CONST_VALUE("FIGHTER_STATUS_DAMAGE_WORK_FLOAT_VECOR_CORRECT_STICK_X"))
return cos(angle);
if (var == CONST_VALUE("FIGHTER_STATUS_DAMAGE_WORK_FLOAT_VECOR_CORRECT_STICK_Y"))
return sin(angle);
}
}
}
// call original WorkModule::get_float_impl
u64 work_module = LOAD64(module_accessor + 0x50);
u64 get_float_impl = LOAD64(work_module) + 0x58LL;
float (*work_module_get_float_impl)(u64, int) =
(float (*)(u64, int))(LOAD64(get_float_impl));
return work_module_get_float_impl(work_module, var);
}
void MotionModule_change_motion_replace(u64 module_accessor, u64 hash,
float start_frame,
float frame_speed_mult, bool unk1,
float unk2, bool unk3, bool unk4) {
const char *down_taunt_l = "appeal_lw_l";
const char *down_taunt_r = "appeal_lw_r";
const char *up_taunt_l = "appeal_hi_l";
const char *up_taunt_r = "appeal_hi_r";
const char *side_taunt_l = "appeal_s_l";
const char *side_taunt_r = "appeal_s_r";
char buffer[16];
// Down Taunt
if (hash == hash40(down_taunt_l) || hash == hash40(down_taunt_r)) {
HITBOX_VIS = !HITBOX_VIS;
}
// Up Taunt
else if (hash == hash40(up_taunt_l) || hash == hash40(up_taunt_r)) {
TOGGLE_STATE = (TOGGLE_STATE + 1) % NUM_TOGGLE_STATES;
}
// Side Taunt
else if (hash == hash40(side_taunt_l) || hash == hash40(side_taunt_r)) {
}
// call original WorkModule::enable_transition_term_group_impl
u64 motion_module = LOAD64(module_accessor + 0x88);
u64 change_motion_impl = LOAD64(motion_module) + 0xD8LL;
void (*motion_module_change_motion_impl)(u64, u64, float, float, bool, float,
bool, bool) =
(void (*)(u64, u64, float, float, bool, float, bool, bool))(
LOAD64(change_motion_impl));
motion_module_change_motion_impl(motion_module, hash, start_frame,
frame_speed_mult, unk1, unk2, unk3, unk4);
}
int main(int argc, char *argv[])
{
SaltySD_printf("SaltySD Plugin: alive\n");
@ -380,9 +75,9 @@ int main(int argc, char *argv[])
ANCHOR_ABS = SaltySDCore_getCodeStart();
/*
Example of string replacement:
replaces the title screen's version number with the string
below.
Example of string replacement:
replaces the title screen's version number with the string
below.
*/
const char *ver = "Ver. %d.%d.%d";
@ -394,29 +89,8 @@ int main(int argc, char *argv[])
// Necessary for script replacement
SaltySD_function_replace_sym("_ZN3lib8L2CAgent15clear_lua_stackEv", (u64) &clear_lua_stack_replace);
// Add function replacements here
effect_manager_addr = SaltySDCore_FindSymbol("_ZN3lib9SingletonINS_13EffectManagerEE9instance_E");
fighter_manager_addr = SaltySDCore_FindSymbol("_ZN3lib9SingletonIN3app14FighterManagerEE9instance_E");
fighter_param_accessor2_addr = SaltySDCore_FindSymbol("_ZN3lib9SingletonIN3app21FighterParamAccessor2EE9instance_E");
AttackModule_set_attack_lua_state =
(void (*)(u64, u64))SaltySDCore_FindSymbol("_ZN3app10sv_animcmd6ATTACKEP9lua_State") + 0xD0 - 0x70;
SaltySD_function_replace_sym("_ZN3app10sv_animcmd6ATTACKEP9lua_State",
(u64)&app_sv_animcmd_ATTACK_replace);
/*
SaltySD_function_replace_sym(
"_ZN3app8lua_bind45WorkModule__enable_transition_term_group_implEPNS_26BattleObjectModuleAccessorEi",
(u64)&WorkModule_enable_transition_term_group_impl_replace);
SaltySD_function_replace_sym(
"_ZN3app8lua_bind26WorkModule__get_float_implEPNS_26BattleObjectModuleAccessorEi",
(u64)&WorkModule_get_float_replace);
SaltySD_function_replace_sym(
"_ZN3app8lua_bind32MotionModule__change_motion_implEPNS_26BattleObjectModuleAccessorEN3phx6Hash40Effbfbb",
(u64)&MotionModule_change_motion_replace);
*/
hitbox_vis_main();
training_mods_main();
__libnx_exit(0);
}

207
source/raygun_printer.hpp Normal file
View file

@ -0,0 +1,207 @@
#include <switch.h>
#include <ctype.h>
#include "useful.h"
#include "acmd_wrapper.hpp"
#define RAYGUN_LENGTH 8
#define RAYGUN_HEIGHT 6
#define RAYGUN_HORIZ_OFFSET 2
using namespace app::lua_bind;
/*
segment data list : {Z, Y, X, ZRot, Size}
segment labels :
_
|_| from top to top left, clockwise: a->f + g mid + \|/ from top mid to top left, clockwise: h->m + --two half g's: n, o
|_| /|\
*/
const float segment_dict[15][5] = {
{0,RAYGUN_HEIGHT*2,0,0,0.25}, // a
{0,RAYGUN_HEIGHT,RAYGUN_LENGTH,90,0.25}, // b
{0,0,RAYGUN_LENGTH,90,0.25}, // c
{0,0,0,0,0.25}, // d
{0,0,0,90,0.25}, //e
{0,RAYGUN_HEIGHT,0,90,0.25}, // f
{0,RAYGUN_HEIGHT,0,0,0.25}, // g mid
{0,RAYGUN_HEIGHT,RAYGUN_LENGTH/2,90,0.25}, // h
{0,RAYGUN_HEIGHT,RAYGUN_LENGTH/2,52,0.2}, // i
{0,RAYGUN_HEIGHT,RAYGUN_LENGTH/2,-52,0.2}, //j
{0,0,RAYGUN_LENGTH/2,90,0.25}, // k
{0,RAYGUN_HEIGHT/2,RAYGUN_LENGTH*3/16,52,0.2}, // l
{0,RAYGUN_HEIGHT*3/2,RAYGUN_LENGTH*3/16,-52,0.2}, // m
{0,RAYGUN_HEIGHT,0,0,0.15}, // n
{0,RAYGUN_HEIGHT,RAYGUN_LENGTH/2,0,0.15}, // o
};
/*
Segments making up each character, each index corresponding to:
'A' through 'Z', '0' through '9', ' ', '-', '+', '#' (where '#' is all segments)
*/
const char* alphabet[] = {
"abcefg",
"adefijn",
"adef",
"eflm",
"adefn",
"aefn",
"acdefo",
"bcefg",
"adhk",
"bcd",
"efnij",
"def",
"bcefim",
"bcefjm",
"abcdef",
"abefg",
"abcdefj",
"aefijn",
"acdfg",
"ahk",
"bcdef",
"efil",
"bcefjl",
"ijlm",
"ikm",
"adil",
"abcdef",
"ef",
"abdeg",
"abcdg",
"bcfg",
"acdfg",
"acdefg",
"abc",
"abcdefg",
"abcdfg",
"",
"g",
"ghk",
"abcdefhijklmno",
};
// Each index is a segment's corresponding flipped segment, for when facing left
const char segment_rev[15] = {
'a',
'f',
'e',
'd',
'c',
'b',
'g',
'h',
'm',
'l',
'k',
'j',
'i',
'o',
'n',
};
void show_segment(u64 battle_object_module_accessor, float z, float y, float x, float zrot, float size) {
Hash40 raygunShot = {.hash = 0x11e470b07fLL};
Hash40 top = {.hash = 0x031ed91fcaLL};
Vector3f pos = {.x = x, .y = y, .z = z};
Vector3f rot = {.x = 0, .y = 90, .z = zrot};
Vector3f random = {.x = 0, .y = 0, .z = 0};
EffectModule::req_on_joint(battle_object_module_accessor, raygunShot.hash, top.hash,
&pos, &rot, size,
&random, &random,
0, 0, 0, 0);
}
int alphabet_index(char to_print) {
if (to_print >= 'A' && to_print <= 'Z')
return to_print - 'A';
else if (to_print >= '0' && to_print <= '9')
return to_print - '0' + 'Z' - 'A' + 1;
else if (to_print == ' ')
return 36;
else if (to_print == '-')
return 37;
else if (to_print == '+')
return 38;
else if (to_print == '#')
return 39;
else
return -1;
}
void print_char( u64 module_accessor, char to_print, int line_num, float horiz_offset, float facing_left) {
int alph_index = alphabet_index(to_print);
if (alph_index < 0 || alph_index >= 40)
return;
const char* segment_str = alphabet[alph_index];
int num_segments = strlen(segment_str);
float lineOffset = 40 - (line_num * 16);
for (int i = 0; i < num_segments; i++) {
const float* segment;
int index = segment_str[i] - 'a';
if (facing_left == -1)
index = segment_rev[index] - 'a';
segment = segment_dict[index];
float z = segment[0];
float y = segment[1] + lineOffset;
float x = segment[2] + horiz_offset;
float zrot = segment[3];
if (facing_left == -1)
zrot *= -1;
float size = segment[4];
show_segment(module_accessor, z, y, x, zrot, size);
}
}
void print_string( u64 module_accessor, const char* print_str) {
// Delete any previous strings
Hash40 raygunShot = {.hash = 0x11e470b07fLL};
EffectModule::kill_kind(module_accessor, raygunShot.hash, 0, 1);
int line_num = 0;
float horiz_offset = 0;
int char_num = 0;
float facing_left = PostureModule::lr(module_accessor);
if (strlen(print_str) <= 8 && strchr(print_str, '\n') == NULL)
line_num = 1;
horiz_offset = 0;
char_num = 0;
for (int i = 0; i < strlen(print_str); i++) {
char curr_char = print_str[i];
if (curr_char == '\n') {
horiz_offset = 0;
char_num = 0;
line_num++;
continue;
}
print_char(module_accessor, toupper(curr_char), line_num, horiz_offset, facing_left);
char_num++;
// short characters
if (curr_char == 'D' || curr_char == '1' )
horiz_offset += facing_left * (RAYGUN_LENGTH/2 + 3);
else
horiz_offset += facing_left * (RAYGUN_LENGTH+3);
if (char_num > 8) {
horiz_offset = 0;
char_num = 0;
line_num++;
}
}
}

View file

@ -1,35 +0,0 @@
#include <switch.h>
#include "saltysd_core.h"
#include "saltysd_ipc.h"
#include "saltysd_dynamic.h"
#include "nn_ro.h"
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
SaltySD_Memcpy(addr+4, (u64) "\x20\x01\x1F\xD6", 4); // BR X9
SaltySD_Memcpy(addr+8, (u64) &new_func, 8); // .dword newaddr
return 0;
}
return -1;
}
int SaltySD_function_replace_sym(char* function_sym, u64 new_func) {
u64 addr = SaltySDCore_FindSymbol(function_sym);
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);
}

View file

@ -1,9 +1,44 @@
#ifndef SALTYSD_HELPER_H
#define SALTYSD_HELPER_H
#include <switch.h>
#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)
int SaltySD_function_replace(u64 addr, u64 new_func);
int SaltySD_function_replace_sym(char* function_sym, u64 new_func);
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
SaltySD_Memcpy(addr+4, (u64) "\x20\x01\x1F\xD6", 4); // BR X9
SaltySD_Memcpy(addr+8, (u64) &new_func, 8); // .dword newaddr
return 0;
}
return -1;
}
int SaltySD_function_replace_sym(char* function_sym, u64 new_func) {
u64 addr = SaltySDCore_FindSymbol(function_sym);
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

View file

@ -9,6 +9,8 @@
#include "acmd_wrapper.hpp"
#include "lua_helper.hpp"
#include "const_value_table.h"
#define LOAD64 *(u64 *)
using namespace lib;
@ -18,15 +20,15 @@ u64 shine_replace(L2CAgent* l2c_agent, void* variadic);
void replace_scripts(L2CAgent* l2c_agent, u8 category, uint kind) {
// fighter
if (category == CONST_VALUE("BATTLE_OBJECT_CATEGORY_FIGHTER")) {
if (category == BATTLE_OBJECT_CATEGORY_FIGHTER) {
// fox
if (kind == CONST_VALUE("FIGHTER_KIND_FOX")) {
if (kind == FIGHTER_KIND_FOX) {
l2c_agent->sv_set_function_hash(&shine_replace, hash40("game_speciallwstart"));
l2c_agent->sv_set_function_hash(&shine_replace, hash40("game_specialairlwstart"));
}
// peach
if (kind == CONST_VALUE("FIGHTER_KIND_PEACH")) {
if (kind == FIGHTER_KIND_PEACH) {
}
}
}

View file

@ -1,3 +1,6 @@
#ifndef TAUNT_TOGGLES_H
#define TAUNT_TOGGLES_H
#define NONE 0
// Up Taunt
@ -14,4 +17,6 @@ extern int DI_STATE = 0;
#define MASH_AIRDODGE 1
int TOGGLE_STATE = 1;
#define NUM_TOGGLE_STATES 2
#define NUM_TOGGLE_STATES 2
#endif // TAUNT_TOGGLES_H

154
source/training_mods.hpp Normal file
View file

@ -0,0 +1,154 @@
#include "l2c.hpp"
#include "saltysd_helper.hpp"
#include "l2c_imports.hpp"
#include "acmd_imports.hpp"
#include "taunt_toggles.h"
#include "raygun_printer.hpp"
using namespace lib;
using namespace app::lua_bind;
using namespace app::sv_animcmd;
u64 fighter_manager_addr;
u64 WorkModule_enable_transition_term_group_replace(u64 module_accessor, u64 transition_group);
float WorkModule_get_float_replace(u64 module_accessor, int var);
void MotionModule_change_motion_replace(u64 module_accessor, u64 hash,
float start_frame,
float frame_speed_mult, bool unk1,
float unk2, bool unk3, bool unk4);
void training_mods_main() {
fighter_manager_addr = SaltySDCore_FindSymbol("_ZN3lib9SingletonIN3app14FighterManagerEE9instance_E");
SaltySD_function_replace_sym(
"_ZN3app8lua_bind45WorkModule__enable_transition_term_group_implEPNS_26BattleObjectModuleAccessorEi",
(u64)&WorkModule_enable_transition_term_group_replace);
SaltySD_function_replace_sym(
"_ZN3app8lua_bind26WorkModule__get_float_implEPNS_26BattleObjectModuleAccessorEi",
(u64)&WorkModule_get_float_replace);
SaltySD_function_replace_sym(
"_ZN3app8lua_bind32MotionModule__change_motion_implEPNS_26BattleObjectModuleAccessorEN3phx6Hash40Effbfbb",
(u64)&MotionModule_change_motion_replace);
}
bool is_operation_cpu(u64 module_accessor) {
int entry_id = WorkModule::get_int(module_accessor, FIGHTER_INSTANCE_WORK_ID_INT_ENTRY_ID);
u64 fighter_information = FighterManager::get_fighter_information(
LOAD64(fighter_manager_addr), entry_id);
return FighterInformation::is_operation_cpu(fighter_information);
}
u64 WorkModule_enable_transition_term_group_replace(u64 module_accessor,
u64 transition_group) {
if (TOGGLE_STATE == MASH_AIRDODGE && is_training_mode()) {
// 0x1F00000D for airdodge
if (transition_group == 0x1F00000D) {
if (is_operation_cpu(module_accessor)) {
int status_kind = StatusModule::status_kind(module_accessor);
// Damage -> DamageFall
if (status_kind >= 0x48 && status_kind <= 0x50) {
StatusModule::change_status_request_from_script(module_accessor, 0x22, 1);
}
}
}
}
// call original WorkModule::enable_transition_term_group_impl
u64 work_module = LOAD64(module_accessor + 0x50);
u64 enable_transition_term_group_impl = LOAD64(work_module) + 0x140LL;
u64 (*work_module_enable_transition_term_group_impl)(u64, u64) =
(u64(*)(u64, u64))(LOAD64(enable_transition_term_group_impl));
return work_module_enable_transition_term_group_impl(work_module,
transition_group);
}
void show_angle(u64 module_accessor, float y, float x, float zrot) {
Hash40 raygunShot = {.hash = 0x11e470b07fLL};
Hash40 top = {.hash = 0x031ed91fcaLL};
Vector3f pos = {.x = x, .y = y, .z = 0};
Vector3f rot = {.x = 0, .y = 90, .z = zrot};
Vector3f random = {.x = 0, .y = 0, .z = 0};
float size = 0.5;
EffectModule::req_on_joint(module_accessor, raygunShot.hash, top.hash, &pos,
&rot, size, &random, &random, 0, 0, 0, 0);
}
float WorkModule_get_float_replace(u64 module_accessor, int var) {
if (is_training_mode()) {
if (is_operation_cpu(module_accessor)) {
int status_kind = StatusModule::status_kind(module_accessor);
// Damage -> DamageFall
if (status_kind >= 0x48 && status_kind <= 0x50) {
float angle = 0;//(DI_STATE - 1) * PI / 4.0;
if (var == FIGHTER_STATUS_DAMAGE_WORK_FLOAT_VECOR_CORRECT_STICK_X)
return cos(angle);
if (var == FIGHTER_STATUS_DAMAGE_WORK_FLOAT_VECOR_CORRECT_STICK_Y)
return sin(angle);
}
}
}
// call original WorkModule::get_float_impl
u64 work_module = LOAD64(module_accessor + 0x50);
u64 get_float_impl = LOAD64(work_module) + 0x58LL;
float (*work_module_get_float_impl)(u64, int) =
(float (*)(u64, int))(LOAD64(get_float_impl));
return work_module_get_float_impl(work_module, var);
}
void MotionModule_change_motion_replace(u64 module_accessor, u64 hash,
float start_frame,
float frame_speed_mult, bool unk1,
float unk2, bool unk3, bool unk4) {
const char *down_taunt_l = "appeal_lw_l";
const char *down_taunt_r = "appeal_lw_r";
const char *up_taunt_l = "appeal_hi_l";
const char *up_taunt_r = "appeal_hi_r";
const char *side_taunt_l = "appeal_s_l";
const char *side_taunt_r = "appeal_s_r";
char buffer[16];
// Down Taunt
if (hash == hash40(down_taunt_l) || hash == hash40(down_taunt_r)) {
TOGGLE_STATE = (TOGGLE_STATE + 1) % NUM_TOGGLE_STATES;
if (TOGGLE_STATE)
print_string(module_accessor, "MASH\nAIRDODGE");
else
print_string(module_accessor, "NONE");
}
// Up Taunt
else if (hash == hash40(up_taunt_l) || hash == hash40(up_taunt_r)) {
HITBOX_VIS = !HITBOX_VIS;
if (HITBOX_VIS)
print_string(module_accessor, "HITBOX\nVIS");
else
print_string(module_accessor, "NO\nHITBOX");
}
// Side Taunt
else if (hash == hash40(side_taunt_l) || hash == hash40(side_taunt_r)) {
}
// call original WorkModule::enable_transition_term_group_impl
u64 motion_module = LOAD64(module_accessor + 0x88);
u64 change_motion_impl = LOAD64(motion_module) + 0xD8LL;
void (*motion_module_change_motion_impl)(u64, u64, float, float, bool, float, bool, bool) =
(void (*)(u64, u64, float, float, bool, float, bool, bool))(
LOAD64(change_motion_impl));
motion_module_change_motion_impl(motion_module, hash, start_frame, frame_speed_mult, unk1, unk2, unk3, unk4);
}