1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2025-04-28 16:39:18 +00:00

formatting

This commit is contained in:
Josh Sambasivam 2019-04-11 00:35:42 -07:00
parent 1eb40592ca
commit e7bd760b91

View file

@ -26,21 +26,22 @@ u32 __nx_applet_type = AppletType_None;
static char g_heap[0x8000]; static char g_heap[0x8000];
Handle orig_main_thread; Handle orig_main_thread;
void * orig_ctx; void *orig_ctx;
void * orig_saved_lr; void *orig_saved_lr;
void (* AttackModule_clear_all_orig)(__int64_t); void (*AttackModule_clear_all_orig)(__int64_t);
void __libnx_init(void * ctx, Handle main_thread, void * saved_lr) { void __libnx_init(void *ctx, Handle main_thread, void *saved_lr)
extern char * fake_heap_start; {
extern char * fake_heap_end; extern char *fake_heap_start;
extern char *fake_heap_end;
fake_heap_start = &g_heap[0]; fake_heap_start = &g_heap[0];
fake_heap_end = &g_heap[sizeof g_heap]; fake_heap_end = &g_heap[sizeof g_heap];
orig_ctx = ctx; orig_ctx = ctx;
orig_main_thread = main_thread; orig_main_thread = main_thread;
orig_saved_lr = saved_lr; orig_saved_lr = saved_lr;
// Call constructors. // Call constructors.
void void
@ -48,7 +49,8 @@ void __libnx_init(void * ctx, Handle main_thread, void * saved_lr) {
__libc_init_array(); __libc_init_array();
} }
void __attribute__((weak)) NORETURN __libnx_exit(int rc) { void __attribute__((weak)) NORETURN __libnx_exit(int rc)
{
// Call destructors. // Call destructors.
void void
__libc_fini_array(void); __libc_fini_array(void);
@ -73,34 +75,38 @@ Vector3f id_colors[8] = {
#define is_training_mode _ZN3app9smashball16is_training_modeEv #define is_training_mode _ZN3app9smashball16is_training_modeEv
extern uint64_t _ZN3app9smashball16is_training_modeEv(void) LINKABLE; extern uint64_t _ZN3app9smashball16is_training_modeEv(void) LINKABLE;
void AttackModule_clear_all_replace(__int64_t attack_module) { void AttackModule_clear_all_replace(__int64_t attack_module)
{
AttackModule_clear_all_orig(attack_module); AttackModule_clear_all_orig(attack_module);
if (is_training_mode()) {
__int64_t battle_module_object_accessor = *(__int64_t *) (attack_module + 0x8);
// Clear graphics every time we clear all hitboxes. if (is_training_mode())
__int64_t effect_module = *(__int64_t *) (battle_module_object_accessor + 0x140); {
void (* EffectModule_kill_kind)(__int64_t, __int64_t, __int64_t, __int64_t battle_module_object_accessor = *(__int64_t *)(attack_module + 0x8);
__int64_t) =
(void (*)(__int64_t, __int64_t, __int64_t, __int64_t))(*(__int64_t *) (*(__int64_t *) (effect_module) + 0xE0LL));
Hash40 shieldEffectHash = { .hash = 0xAFAE75F05LL }; // Clear graphics every time we clear all hitboxes.
EffectModule_kill_kind(effect_module, shieldEffectHash.hash, 0, 1); __int64_t effect_module = *(__int64_t *)(battle_module_object_accessor + 0x140);
} void (*EffectModule_kill_kind)(__int64_t, __int64_t, __int64_t,
__int64_t) =
(void (*)(__int64_t, __int64_t, __int64_t, __int64_t))(*(__int64_t *)(*(__int64_t *)(effect_module) + 0xE0LL));
Hash40 shieldEffectHash = {.hash = 0xAFAE75F05LL};
EffectModule_kill_kind(effect_module, shieldEffectHash.hash, 0, 1);
}
} }
void lib_L2CAgent_push_color(__int64_t* l2c_agent, Vector3f color) { void lib_L2CAgent_push_color(__int64_t *l2c_agent, Vector3f color)
L2CValue red = { .raw_float = color.x, .type = L2C_number }; {
L2CValue green = { .raw_float = color.y, .type = L2C_number }; L2CValue red = {.raw_float = color.x, .type = L2C_number};
L2CValue blue = { .raw_float = color.z, .type = L2C_number }; L2CValue green = {.raw_float = color.y, .type = L2C_number};
L2CValue blue = {.raw_float = color.z, .type = L2C_number};
lib_L2CAgent_push_lua_stack(l2c_agent, &red); lib_L2CAgent_push_lua_stack(l2c_agent, &red);
lib_L2CAgent_push_lua_stack(l2c_agent, &green); lib_L2CAgent_push_lua_stack(l2c_agent, &green);
lib_L2CAgent_push_lua_stack(l2c_agent, &blue); lib_L2CAgent_push_lua_stack(l2c_agent, &blue);
} }
void app_sv_animcmd_ATTACK_replace(__int64_t a1) { void app_sv_animcmd_ATTACK_replace(__int64_t a1)
{
SaltySD_printf("In attack code with lua_state ptr: %llx\n", a1); SaltySD_printf("In attack code with lua_state ptr: %llx\n", a1);
__int64_t v1; // x19 __int64_t v1; // x19
@ -130,54 +136,60 @@ void app_sv_animcmd_ATTACK_replace(__int64_t a1) {
// original code: parse lua stack and call AttackModule::set_attack() // original code: parse lua stack and call AttackModule::set_attack()
v1 = a1; v1 = a1;
void (* sub_71019420D0)(__int64_t, __int64_t) = (void (*)(__int64_t, __int64_t))(IMPORT(0x71019420D0)); void (*sub_71019420D0)(__int64_t, __int64_t) = (void (*)(__int64_t, __int64_t))(IMPORT(0x71019420D0));
sub_71019420D0(*(__int64_t *) (*(__int64_t *) (a1 - 8) + 416LL), a1); sub_71019420D0(*(__int64_t *)(*(__int64_t *)(a1 - 8) + 416LL), a1);
if (is_training_mode()) { if (is_training_mode())
{
// Replace AttackModule::clear_all() // Replace AttackModule::clear_all()
__int64_t battle_module_object_accessor = *(__int64_t *) (*(__int64_t *) (a1 - 8) + 416LL); __int64_t battle_module_object_accessor = *(__int64_t *)(*(__int64_t *)(a1 - 8) + 416LL);
__int64_t attack_module = *(__int64_t *) (battle_module_object_accessor + 0xA0); __int64_t attack_module = *(__int64_t *)(battle_module_object_accessor + 0xA0);
__int64_t attack_module_clear_all = *(__int64_t *) (attack_module) + 0x50LL; __int64_t attack_module_clear_all = *(__int64_t *)(attack_module) + 0x50LL;
if (AttackModule_clear_all_orig == 0) { if (AttackModule_clear_all_orig == 0)
AttackModule_clear_all_orig = (void (*)(__int64_t))(*(__int64_t *) (attack_module_clear_all)); {
AttackModule_clear_all_orig = (void (*)(__int64_t))(*(__int64_t *)(attack_module_clear_all));
} }
*(__int64_t *) (attack_module_clear_all) = AttackModule_clear_all_replace; *(__int64_t *)(attack_module_clear_all) = AttackModule_clear_all_replace;
// Generate hitbox effect // Generate hitbox effect
// EFFECT_FOLLOW_COLOR(Graphic, Bone, Z, Y, X, ZRot, YRot, XRot, Size, unknown=0x1, Red, Green, Blue) // EFFECT_FOLLOW_COLOR(Graphic, Bone, Z, Y, X, ZRot, YRot, XRot, Size, unknown=0x1, Red, Green, Blue)
float sizeMult = 19.0 / 200.0; float sizeMult = 19.0 / 200.0;
Hash40 shieldEffectHash = { .hash = 0xAFAE75F05LL }; Hash40 shieldEffectHash = {.hash = 0xAFAE75F05LL};
L2CValue shieldEffect = { .raw = shieldEffectHash.hash, .type = L2C_hash }; L2CValue shieldEffect = {.raw = shieldEffectHash.hash, .type = L2C_hash};
L2CValue xRot = { .raw_float = (float) 0.0, .type = L2C_number }; L2CValue xRot = {.raw_float = (float)0.0, .type = L2C_number};
L2CValue yRot = { .raw_float = (float) 0.0, .type = L2C_number }; L2CValue yRot = {.raw_float = (float)0.0, .type = L2C_number};
L2CValue zRot = { .raw_float = (float) 0.0, .type = L2C_number }; L2CValue zRot = {.raw_float = (float)0.0, .type = L2C_number};
L2CValue terminate = { .raw = (int) 1, .type = L2C_integer }; L2CValue terminate = {.raw = (int)1, .type = L2C_integer};
L2CValue attribute = { .raw = 0x101C000, .type = L2C_integer }; // for EFFECT_ATTR L2CValue attribute = {.raw = 0x101C000, .type = L2C_integer}; // for EFFECT_ATTR
L2CValue l2c_true = { .raw = (bool) 1, .type = L2C_bool }; L2CValue l2c_true = {.raw = (bool)1, .type = L2C_bool};
L2CValue l2c_false = { .raw = (bool) 0, .type = L2C_bool }; L2CValue l2c_false = {.raw = (bool)0, .type = L2C_bool};
L2CValue effectSize = { .raw_float = (float) size.raw_float * sizeMult, .type = L2C_number }; L2CValue effectSize = {.raw_float = (float)size.raw_float * sizeMult, .type = L2C_number};
L2CValue rate = { .raw_float = 8.0f, .type = L2C_number }; L2CValue rate = {.raw_float = 8.0f, .type = L2C_number};
// Extended Hitboxes if x2, y2, z2 are not L2CValue::nil // Extended Hitboxes if x2, y2, z2 are not L2CValue::nil
int num_effects; int num_effects;
if (x2.type != L2C_void && y2.type != L2C_void && z2.type != L2C_void) { if (x2.type != L2C_void && y2.type != L2C_void && z2.type != L2C_void)
{
num_effects = 4; num_effects = 4;
} else { }
else
{
x2 = x; x2 = x;
y2 = y; y2 = y;
z2 = z; z2 = z;
num_effects = 1; num_effects = 1;
} }
for (int i = 0; i < num_effects; i++) { for (int i = 0; i < num_effects; i++)
{
L2CValue currX = L2CValue currX =
{ .raw_float = (float) x.raw_float + ((x2.raw_float - x.raw_float) / 3 * i), .type = L2C_number }; {.raw_float = (float)x.raw_float + ((x2.raw_float - x.raw_float) / 3 * i), .type = L2C_number};
L2CValue currY = L2CValue currY =
{ .raw_float = (float) y.raw_float + ((y2.raw_float - y.raw_float) / 3 * i), .type = L2C_number }; {.raw_float = (float)y.raw_float + ((y2.raw_float - y.raw_float) / 3 * i), .type = L2C_number};
L2CValue currZ = L2CValue currZ =
{ .raw_float = (float) z.raw_float + ((z2.raw_float - z.raw_float) / 3 * i), .type = L2C_number }; {.raw_float = (float)z.raw_float + ((z2.raw_float - z.raw_float) / 3 * i), .type = L2C_number};
lib_L2CAgent_clear_lua_stack(&l2c_agent); lib_L2CAgent_clear_lua_stack(&l2c_agent);
lib_L2CAgent_push_lua_stack(&l2c_agent, &shieldEffect); lib_L2CAgent_push_lua_stack(&l2c_agent, &shieldEffect);
@ -191,11 +203,11 @@ void app_sv_animcmd_ATTACK_replace(__int64_t a1) {
lib_L2CAgent_push_lua_stack(&l2c_agent, &effectSize); lib_L2CAgent_push_lua_stack(&l2c_agent, &effectSize);
lib_L2CAgent_push_lua_stack(&l2c_agent, &terminate); lib_L2CAgent_push_lua_stack(&l2c_agent, &terminate);
app_sv_animcmd_EFFECT_FOLLOW_NO_SCALE(l2c_agent.lua_state_agent); app_sv_animcmd_EFFECT_FOLLOW_NO_SCALE(l2c_agent.lua_state_agent);
// Set to hitbox ID color // Set to hitbox ID color
lib_L2CAgent_clear_lua_stack(&l2c_agent); lib_L2CAgent_clear_lua_stack(&l2c_agent);
lib_L2CAgent_push_color(&l2c_agent, id_colors[id.raw % 8]); lib_L2CAgent_push_color(&l2c_agent, id_colors[id.raw % 8]);
app_sv_animcmd_LAST_EFFECT_SET_COLOR(l2c_agent.lua_state_agent); app_sv_animcmd_LAST_EFFECT_SET_COLOR(l2c_agent.lua_state_agent);
// Speed up animation by rate to remove pulsing effect // Speed up animation by rate to remove pulsing effect
lib_L2CAgent_clear_lua_stack(&l2c_agent); lib_L2CAgent_clear_lua_stack(&l2c_agent);
@ -205,29 +217,32 @@ void app_sv_animcmd_ATTACK_replace(__int64_t a1) {
} }
// original code: clear_lua_stack section // original code: clear_lua_stack section
v2 = *(__int64_t *) (v1 + 16); v2 = *(__int64_t *)(v1 + 16);
for (i = **(__int64_t **) (v1 + 32) + 16LL; v2 < i; v2 = *(__int64_t *) (v1 + 16) ) { for (i = **(__int64_t **)(v1 + 32) + 16LL; v2 < i; v2 = *(__int64_t *)(v1 + 16))
*(__int64_t *) (v1 + 16) = v2 + 16; {
*(__int32_t *) (v2 + 8) = 0; *(__int64_t *)(v1 + 16) = v2 + 16;
*(__int32_t *)(v2 + 8) = 0;
} }
*(__int64_t *) (v1 + 16) = i; *(__int64_t *)(v1 + 16) = i;
} }
int main(int argc, char * argv[]) { int main(int argc, char *argv[])
{
SaltySD_printf("SaltySD Plugin: alive\n"); SaltySD_printf("SaltySD Plugin: alive\n");
// Get anchor for imports // Get anchor for imports
ANCHOR_ABS = SaltySDCore_getCodeStart(); ANCHOR_ABS = SaltySDCore_getCodeStart();
char * ver = "Ver. %d.%d.%d"; char *ver = "Ver. %d.%d.%d";
u64 dst_3 = SaltySDCore_findCode(ver, strlen(ver)); u64 dst_3 = SaltySDCore_findCode(ver, strlen(ver));
if (dst_3) { if (dst_3)
{
SaltySD_Memcpy(dst_3, "Noice v%d%d%d", 13); SaltySD_Memcpy(dst_3, "Noice v%d%d%d", 13);
} }
// Install animCMD function replacement // Install animCMD function replacement
SaltySD_function_replace_sym("_ZN3app10sv_animcmd6ATTACKEP9lua_State", SaltySD_function_replace_sym("_ZN3app10sv_animcmd6ATTACKEP9lua_State",
&app_sv_animcmd_ATTACK_replace); &app_sv_animcmd_ATTACK_replace);
__libnx_exit(0); __libnx_exit(0);
} }