SHARE
TWEET

Untitled

a guest May 23rd, 2019 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <switch.h>
  2.  
  3. #include <stdint.h>
  4.  
  5. #include "crc32.h"
  6.  
  7. #include "l2c.hpp"
  8. #include "l2c_imports.hpp"
  9. #include "acmd_wrapper.hpp"
  10. #include "const_value_table.h"
  11.  
  12. #include "const_value_table.h"
  13.  
  14. using namespace lib;
  15. using namespace app::sv_animcmd;
  16. using namespace app::lua_bind;
  17.  
  18. u64 shine_replace(L2CAgent* l2c_agent, void* variadic);
  19. u64 ivy_upsmash(L2CAgent* l2c_agent, void* variadic);
  20. u64 squirtle_utilt(L2CAgent* l2c_agent, void* variadic);
  21. u64 knee_replace(L2CAgent* l2c_agent, void* variadic);
  22.  
  23. void replace_scripts(L2CAgent* l2c_agent, u8 category, int kind) {
  24.     // fighter
  25.     if (category == BATTLE_OBJECT_CATEGORY_FIGHTER) {
  26.         // fox
  27.         if (kind == FIGHTER_KIND_FOX) {
  28.           l2c_agent->sv_set_function_hash(&shine_replace, hash40("game_speciallwstart"));
  29.           l2c_agent->sv_set_function_hash(&shine_replace, hash40("game_specialairlwstart"));
  30.         }
  31.  
  32.         // ivysaur
  33.         if (kind == FIGHTER_KIND_PFUSHIGISOU) {
  34.           l2c_agent->sv_set_function_hash(&ivy_upsmash, hash40("game_attackhi4"));
  35.         }
  36.  
  37.         // if squirtle
  38.         if (kind == FIGHTER_KIND_PZENIGAME) {
  39.           l2c_agent->sv_set_function_hash(&squirtle_utilt, hash40("game_attackhi3"));
  40.         }
  41.        
  42.         // captain
  43.         if (kind == FIGHTER_KIND_CAPTAIN) {
  44.             l2c_agent->sv_set_function_hash(&knee_replace, hash40("game_attackairf"));
  45.         }
  46.     }
  47. }
  48.  
  49. // AnimCMD replacement functions
  50. u64 shine_replace(L2CAgent* l2c_agent, void* variadic) {
  51.   ACMD acmd = ACMD(l2c_agent);
  52.  
  53.   acmd.frame(1);
  54.   if(acmd.is_excute()){
  55.     acmd.ATTACK(0, 0, hash40("top"), 2.0, 80, 32, 0, 80, 8, 0.0, 6.5, 0.0, 1.0, 1.0, ATTACK_SETOFF_KIND_OFF, ATTACK_LR_CHECK_POS, false, 0, 0.0, 0, false, false, false, false, true, COLLISION_SITUATION_MASK_G, COLLISION_CATEGORY_MASK_ALL, COLLISION_PART_MASK_ALL, false, hash40("collision_attr_elec"), ATTACK_SOUND_LEVEL_L, COLLISION_SOUND_ATTR_ELEC, ATTACK_REGION_ENERGY);
  56.     acmd.ATTACK(1, 0, hash40("top"), 2.0, 80, 32, 0, 80, 8, 0.0, 6.5, 0.0, 1.0, 1.0, ATTACK_SETOFF_KIND_OFF, ATTACK_LR_CHECK_POS, false, 0, 0.0, 0, false, false, false, false, true, COLLISION_SITUATION_MASK_A, COLLISION_CATEGORY_MASK_ALL, COLLISION_PART_MASK_ALL, false, hash40("collision_attr_elec"), ATTACK_SOUND_LEVEL_L, COLLISION_SOUND_ATTR_ELEC, ATTACK_REGION_ENERGY);
  57.     acmd.ATTACK(2, 0, hash40("top"), 2.0, 60, 32, 0, 110, 2, -10, 6.5, 0.0, 1.0, 1.0, ATTACK_SETOFF_KIND_OFF, ATTACK_LR_CHECK_POS, false, 0, 0.0, 0, false, false, false, false, true, COLLISION_SITUATION_MASK_GA, COLLISION_CATEGORY_MASK_ALL, COLLISION_PART_MASK_ALL, false, hash40("collision_attr_elec"), ATTACK_SOUND_LEVEL_L, COLLISION_SOUND_ATTR_ELEC, ATTACK_REGION_ENERGY);
  58.     acmd.ATTACK(3, 0, hash40("top"), 2.0, 60, 32, 0, 60, 2, 10, 6.5, 0.0, 1.0, 1.0, ATTACK_SETOFF_KIND_OFF, ATTACK_LR_CHECK_POS, false, 0, 0.0, 0, false, false, false, false, true, COLLISION_SITUATION_MASK_GA, COLLISION_CATEGORY_MASK_ALL, COLLISION_PART_MASK_ALL, false, hash40("collision_attr_elec"), ATTACK_SOUND_LEVEL_L, COLLISION_SOUND_ATTR_ELEC, ATTACK_REGION_ENERGY);
  59.   }
  60.  
  61.   return 0;
  62. }
  63.  
  64. u64 squirtle_utilt(L2CAgent* l2c_agent, void* variadic) {
  65.   ACMD acmd = ACMD(l2c_agent);
  66.  
  67.   acmd.frame(5);
  68.   if (acmd.is_excute()) {
  69.     acmd.ATTACK(0, 0, hash40("head"), 15.0, 88, 100, 0, 30, 10.0, 1.7, 0.7, 0.7, 1.7, 0.7, 0.7, 1.0, 1.0, ATTACK_SETOFF_KIND_ON, ATTACK_LR_CHECK_POS, false, 0, 0.0, 0, false, false, false, false, true, COLLISION_SITUATION_MASK_GA, COLLISION_CATEGORY_MASK_ALL, COLLISION_PART_MASK_ALL, false, hash40("collision_attr_fire"), ATTACK_SOUND_LEVEL_M, COLLISION_SOUND_ATTR_PUNCH, ATTACK_REGION_HEAD);
  70.     acmd.ATTACK(1, 0, hash40("hip"), 15.0, 88, 100, 0, 30, 10.0, 1.7, 1.2, 1.2, 1.7, 1.2, 1.2, 1.0, 1.0, ATTACK_SETOFF_KIND_ON, ATTACK_LR_CHECK_POS, false, 0, 0.0, 0, false, false, false, false, true, COLLISION_SITUATION_MASK_GA, COLLISION_CATEGORY_MASK_ALL, COLLISION_PART_MASK_ALL, false, hash40("collision_attr_fire"), ATTACK_SOUND_LEVEL_M, COLLISION_SOUND_ATTR_PUNCH, ATTACK_REGION_HEAD);
  71.   }
  72.  
  73.   acmd.wait(2);
  74.   if (acmd.is_excute()) {
  75.     AttackModule::clear_all(acmd.module_accessor);
  76.   }
  77.  
  78.   return 0;
  79. }
  80.  
  81. u64 ivy_upsmash(L2CAgent* l2c_agent, void* variadic) {
  82.   ACMD acmd = ACMD(l2c_agent);
  83.  
  84.   acmd.frame(8);
  85.   if (acmd.is_excute()) {
  86.     WorkModule::on_flag(acmd.module_accessor, FIGHTER_STATUS_ATTACK_FLAG_START_SMASH_HOLD);
  87.     /**
  88.      * This return statement is unusual, but for some reason
  89.      * necessary. It may have to do with smash attacks in general.
  90.     */
  91.     return 0;
  92.   }
  93.  
  94.   acmd.frame(26);
  95.   if (acmd.is_excute()) {
  96.     acmd.wrap(HIT_NODE, {L2CValue(hash40("flower")), L2CValue(HIT_STATUS_XLU)});
  97.     acmd.ATTACK(0, 0, hash40("top"), 100.0, 82, 78, 0, 78, 20.0, 0.0, 17.0, 0.0, 1.0, 1.0, ATTACK_SETOFF_KIND_ON, ATTACK_LR_CHECK_POS, false, 0, 0.0, 0, false, false, false, false, true, COLLISION_SITUATION_MASK_GA, COLLISION_CATEGORY_MASK_ALL, COLLISION_PART_MASK_ALL, false, hash40("collision_attr_death"), ATTACK_SOUND_LEVEL_L, COLLISION_SOUND_ATTR_FIRE, ATTACK_REGION_BOMB);
  98.     acmd.ATTACK(1, 0, hash40("top"), 100.0, 82, 78, 0, 78,  12.0, 0.0,  5.0, 0.0, 1.0, 1.0, ATTACK_SETOFF_KIND_ON, ATTACK_LR_CHECK_POS, false, 0, 0.0, 0, false, false, false, false, true, COLLISION_SITUATION_MASK_GA, COLLISION_CATEGORY_MASK_ALL, COLLISION_PART_MASK_ALL, false, hash40("collision_attr_death"), ATTACK_SOUND_LEVEL_L, COLLISION_SOUND_ATTR_FIRE, ATTACK_REGION_BOMB);
  99.   }
  100.  
  101.   acmd.wait(4);
  102.   if (acmd.is_excute()) {
  103.     AttackModule::clear_all(acmd.module_accessor);
  104.     HitModule::set_status_all(acmd.module_accessor, HIT_STATUS_NORMAL, 0);
  105.   }
  106.  
  107.   return 0;
  108. }
  109.  
  110. void* sv_get_status_func(u64 l2c_agentbase, int status_kind, u64 key) {
  111.   u64 unk48 = LOAD64(l2c_agentbase + 0x48);
  112.   u64 unk50 = LOAD64(l2c_agentbase + 0x50);
  113.   if ( 0x2E8BA2E8BA2E8BA3LL * ((unk50 - unk48) >> 4) > (u64)status_kind)
  114.     return *(void **)(unk48 + 0xB0LL * status_kind + (key << 32 >> 29));
  115.  
  116.   return 0;
  117. }
  118.  
  119. u64 knee_replace(L2CAgent* l2c_agent, void* variadic) {
  120.   ACMD acmd = ACMD{.l2c_agent = l2c_agent};
  121.  
  122.   acmd.frame(5);
  123. if (acmd.is_excute()) {
  124.  
  125. WorkModule::on_flag(acmd.module_accessor, /*Flag*/ FIGHTER_STATUS_ATTACK_AIR_FLAG_ENABLE_LANDING);
  126. }
  127. acmd.frame(14);
  128. if (acmd.is_excute()) {
  129.  
  130. WorkModule::set_int(acmd.module_accessor, 0, FIGHTER_CAPTAIN_STATUS_ATTACK_AIR_WORK_INT_CRITICAL_ATTACK_ID);
  131.  
  132. acmd.ATTACK(/*ID*/ 0, /*Part*/ 0, /*Bone*/ hash40("legl"), /*Damage*/ 22.0, /*Angle*/ 80, /*KBG*/ 81, /*FKB*/ 0, /*BKB*/ 30, /*Size*/ 3.0, /*X*/ 4.4, /*Y*/ -0.2, /*Z*/ -1.0, /*X2*/ 4.4, /*Y2*/ 0.3, /*Z2*/ 1.0, /*Hitlag*/ 1.2, /*SDI*/ 1.0, /*Clang/Rebound*/ ATTACK_SETOFF_KIND_ON, /*FacingRestrict*/ ATTACK_LR_CHECK_F, /*SetWeight*/ false, /*ShieldDamage*/ 0, /*Trip*/ 0.0, /*Rehit*/ 0, /*Reflectable*/ false, /*Absorbable*/ false, /*Flinchless*/ false, /*DisableHitlag*/ false, /*Direct/Indirect*/ true, /*Ground/Air*/ COLLISION_SITUATION_MASK_GA, /*Hitbits*/ COLLISION_CATEGORY_MASK_ALL, /*CollisionPart*/ COLLISION_PART_MASK_ALL, /*FriendlyFire*/ false, /*Effect*/ hash40("collision_attr_elec"), /*SFXLevel*/ ATTACK_SOUND_LEVEL_L, /*SFXType*/ COLLISION_SOUND_ATTR_KICK, /*Type*/ ATTACK_REGION_KNEE);
  133.  
  134. acmd.ATTACK(/*ID*/ 1, /*Part*/ 0, /*Bone*/ hash40("top"), /*Damage*/ 6.0, /*Angle*/ 80, /*KBG*/ 80, /*FKB*/ 0, /*BKB*/ 35, /*Size*/ 3.0, /*X*/ 0.0, /*Y*/ 6.0, /*Z*/ 0.0, /*Hitlag*/ 1.2, /*SDI*/ 1.0, /*Clang/Rebound*/ ATTACK_SETOFF_KIND_ON, /*FacingRestrict*/ ATTACK_LR_CHECK_F, /*SetWeight*/ false, /*ShieldDamage*/ 0, /*Trip*/ 0.0, /*Rehit*/ 0, /*Reflectable*/ false, /*Absorbable*/ false, /*Flinchless*/ false, /*DisableHitlag*/ false, /*Direct/Indirect*/ true, /*Ground/Air*/ COLLISION_SITUATION_MASK_GA, /*Hitbits*/ COLLISION_CATEGORY_MASK_ALL, /*CollisionPart*/ COLLISION_PART_MASK_ALL, /*FriendlyFire*/ false, /*Effect*/ hash40("collision_attr_normal"), /*SFXLevel*/ ATTACK_SOUND_LEVEL_S, /*SFXType*/ COLLISION_SOUND_ATTR_KICK, /*Type*/ ATTACK_REGION_KNEE);
  135. }
  136. acmd.wait(1);
  137. if (acmd.is_excute()) {
  138.  
  139. WorkModule::off_flag(acmd.module_accessor, /*Flag*/ FIGHTER_CAPTAIN_STATUS_ATTACK_AIR_WORK_FLAG_CRITICAL);
  140.  
  141. acmd.ATTACK(/*ID*/ 0, /*Part*/ 0, /*Bone*/ hash40("legl"), /*Damage*/ 3.0, /*Angle*/ 80, /*KBG*/ 80, /*FKB*/ 0, /*BKB*/ 35, /*Size*/ 4.7, /*X*/ 4.4, /*Y*/ -0.2, /*Z*/ -1.0, /*Hitlag*/ 1.0, /*SDI*/ 1.0, /*Clang/Rebound*/ ATTACK_SETOFF_KIND_ON, /*FacingRestrict*/ ATTACK_LR_CHECK_F, /*SetWeight*/ false, /*ShieldDamage*/ 0, /*Trip*/ 0.2, /*Rehit*/ 0, /*Reflectable*/ false, /*Absorbable*/ false, /*Flinchless*/ false, /*DisableHitlag*/ false, /*Direct/Indirect*/ true, /*Ground/Air*/ COLLISION_SITUATION_MASK_GA, /*Hitbits*/ COLLISION_CATEGORY_MASK_ALL, /*CollisionPart*/ COLLISION_PART_MASK_ALL, /*FriendlyFire*/ false, /*Effect*/ hash40("collision_attr_normal"), /*SFXLevel*/ ATTACK_SOUND_LEVEL_S, /*SFXType*/ COLLISION_SOUND_ATTR_KICK, /*Type*/ ATTACK_REGION_KNEE);
  142.  
  143. acmd.ATTACK(/*ID*/ 1, /*Part*/ 0, /*Bone*/ hash40("top"), /*Damage*/ 3.0, /*Angle*/ 80, /*KBG*/ 80, /*FKB*/ 0, /*BKB*/ 35, /*Size*/ 3.0, /*X*/ 0.0, /*Y*/ 6.0, /*Z*/ 0.0, /*Hitlag*/ 1.0, /*SDI*/ 1.0, /*Clang/Rebound*/ ATTACK_SETOFF_KIND_ON, /*FacingRestrict*/ ATTACK_LR_CHECK_F, /*SetWeight*/ false, /*ShieldDamage*/ 0, /*Trip*/ 0.2, /*Rehit*/ 0, /*Reflectable*/ false, /*Absorbable*/ false, /*Flinchless*/ false, /*DisableHitlag*/ false, /*Direct/Indirect*/ true, /*Ground/Air*/ COLLISION_SITUATION_MASK_GA, /*Hitbits*/ COLLISION_CATEGORY_MASK_ALL, /*CollisionPart*/ COLLISION_PART_MASK_ALL, /*FriendlyFire*/ false, /*Effect*/ hash40("collision_attr_normal"), /*SFXLevel*/ ATTACK_SOUND_LEVEL_S, /*SFXType*/ COLLISION_SOUND_ATTR_KICK, /*Type*/ ATTACK_REGION_KNEE);
  144. }
  145. acmd.frame(31);
  146. if (acmd.is_excute()) {
  147.  
  148. AttackModule::clear_all(acmd.module_accessor);
  149. }
  150. acmd.frame(42);
  151. if (acmd.is_excute()) {
  152.  
  153. WorkModule::off_flag(acmd.module_accessor, /*Flag*/ FIGHTER_STATUS_ATTACK_AIR_FLAG_ENABLE_LANDING);
  154. }
  155.  
  156.   return 0;
  157. }
  158.  
  159. void sv_replace_status_func(u64 l2c_agentbase, int status_kind, u64 key, void* func) {
  160.   u64 unk48 = LOAD64(l2c_agentbase + 0x48);
  161.   u64 unk50 = LOAD64(l2c_agentbase + 0x50);
  162.   if ( 0x2E8BA2E8BA2E8BA3LL * ((unk50 - unk48) >> 4) > (u64)status_kind) {
  163.     *(void **)(unk48 + 0xB0LL * status_kind + (key << 32 >> 29)) = func;
  164.   }
  165. }
  166.  
  167. u64 clear_lua_stack_replace(u64 l2c_agent) {
  168.   u64 lua_state = LOAD64(l2c_agent + 8);
  169.   if (lua_state-8 && LOAD64(lua_state-8) && LOAD64(LOAD64(lua_state - 8) + 416LL)) {
  170.     u8 battle_object_category = *(u8 *)(LOAD64(lua_state - 8) + 404LL);
  171.     int battle_object_kind = *(int *)(LOAD64(lua_state - 8) + 408LL);
  172.     replace_scripts((L2CAgent*)l2c_agent, battle_object_category, battle_object_kind);
  173.   }
  174.  
  175.   // Original clear_lua_stack:
  176.   u64 v1 = LOAD64(l2c_agent + 8);
  177.   u64 v2 = LOAD64(v1 + 16);
  178.   u64 i = LOAD64(LOAD64(v1 + 32)) + 16LL;
  179.   for (; v2 < i; v2 = LOAD64(v1 + 16)) {
  180.     LOAD64(v1 + 16) = v2 + 16;
  181.     *(u32 *)(v2 + 8) = 0;
  182.   }
  183.   LOAD64(v1 + 16) = i;
  184.   return l2c_agent;
  185. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top