1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2025-03-14 02:16:10 +00:00

in-game printer implemented

This commit is contained in:
jugeeya 2019-05-01 11:04:54 -07:00
parent 60d5416059
commit 2a73889f3a
5 changed files with 281 additions and 12 deletions

View file

@ -1,4 +1,8 @@
#ifndef LUA_BIND_H
#define LUA_BIND_H
#include <switch.h>
#include "l2c.h"
#define StatusModule_change_status_request_from_script _ZN3app8lua_bind52StatusModule__change_status_request_from_script_implEPNS_26BattleObjectModuleAccessorEib
extern u64 _ZN3app8lua_bind52StatusModule__change_status_request_from_script_implEPNS_26BattleObjectModuleAccessorEib(u64, int, bool) LINKABLE;
@ -15,5 +19,14 @@ extern int _ZN3app8lua_bind24WorkModule__get_int_implEPNS_26BattleObjectModuleAc
#define FighterManager_get_fighter_information _ZN3app8lua_bind44FighterManager__get_fighter_information_implEPNS_14FighterManagerENS_14FighterEntryIDE
extern u64 _ZN3app8lua_bind44FighterManager__get_fighter_information_implEPNS_14FighterManagerENS_14FighterEntryIDE(u64, int) LINKABLE;
// boma, effect, joint, pos, rot, size, random_pos, random_rot, NO_SCALE?, attr?, unkint1, unkint2
#define EffectModule_req_on_joint _ZN3app8lua_bind31EffectModule__req_on_joint_implEPNS_26BattleObjectModuleAccessorEN3phx6Hash40ES4_RKNS3_8Vector3fES7_fS7_S7_bjii
extern uint _ZN3app8lua_bind31EffectModule__req_on_joint_implEPNS_26BattleObjectModuleAccessorEN3phx6Hash40ES4_RKNS3_8Vector3fES7_fS7_S7_bjii(u64, u64, u64, const Vector3f*, const Vector3f*, float a6, const Vector3f*, const Vector3f*, bool, uint, int, int) LINKABLE;
#define PostureModule_lr _ZN3app8lua_bind22PostureModule__lr_implEPNS_26BattleObjectModuleAccessorE
extern float _ZN3app8lua_bind22PostureModule__lr_implEPNS_26BattleObjectModuleAccessorE(u64) LINKABLE;
#define lib_lua_bind_get_value _ZN3lib18lua_bind_get_valueIiEEbmRT_
extern bool _ZN3lib18lua_bind_get_valueIiEEbmRT_(u64, int*) LINKABLE;
extern bool _ZN3lib18lua_bind_get_valueIiEEbmRT_(u64, int*) LINKABLE;
#endif // LUA_BIND_H

View file

@ -6,6 +6,7 @@
#include <switch/kernel/ipc.h>
#include <sys/iosupport.h>
#include <sys/reent.h>
#include <math.h>
#include "crc32.h"
#include "useful.h"
@ -23,6 +24,7 @@
#include "lua_bind.h"
#include "lua_helper.h"
#include "saltysd_helper.h"
#include "raygun_printer.h"
#include "taunt_toggles.h"
@ -44,6 +46,8 @@ void (*AttackModule_set_attack_lua_state)(u64, u64);
void (*AttackModule_clear_all_orig)(u64);
void (*AttackModule_clear_orig)(u64, int);
#define PI 3.14159265358979323846
void __libnx_init(void *ctx, Handle main_thread, void *saved_lr) {
extern char *fake_heap_start;
extern char *fake_heap_end;
@ -250,7 +254,7 @@ bool is_operation_cpu(u64 battle_object_module_accessor) {
int entry_id =
WorkModule_get_int(battle_object_module_accessor, entry_id_var);
u64 fighter_information = FighterManager_get_fighter_information(
*(u64 *)fighter_manager_addr, entry_id);
LOAD64(fighter_manager_addr), entry_id);
return FighterInformation_is_operation_cpu(fighter_information);
}
@ -284,22 +288,39 @@ u64 WorkModule_enable_transition_term_group_impl_replace(
transition_group);
}
void show_angle(u64 battle_object_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(battle_object_module_accessor, raygunShot.hash, top.hash,
&pos, &rot, size,
&random, &random,
0, 0, 0, 0);
}
float WorkModule_get_float_replace(u64 battle_object_module_accessor, int var) {
if (DI_STATE == DI_RIGHT && is_training_mode()) {
if (DI_STATE != NONE && is_training_mode()) {
if (is_operation_cpu(battle_object_module_accessor)) {
int status_kind = StatusModule_status_kind(battle_object_module_accessor);
// Damage -> DamageFall
if (status_kind >= 0x48 && status_kind <= 0x50) {
int DI_stick_x_ID;
int DI_stick_y_ID;
float angle = (DI_STATE - 1) * PI / 4.0;
if (lib_lua_bind_get_value(0xA4D50A730E36970E, &DI_stick_x_ID) &&
var == DI_stick_x_ID)
return 1.0;
return cos(angle);
if (lib_lua_bind_get_value(0xEED4095B229D825B, &DI_stick_y_ID) &&
var == DI_stick_y_ID)
return 1.0;
return sin(angle);
}
}
}
@ -328,14 +349,29 @@ void MotionModule_change_motion_replace(u64 battle_object_module_accessor,
// 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(battle_object_module_accessor, "MASH\nAIRDODGE");
else
print_string(battle_object_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(battle_object_module_accessor, "HITBOX\nVIS");
else
print_string(battle_object_module_accessor, "NO\nHITBOX");
}
// Side Taunt
else if (hash == hash40(side_taunt_l) || hash == hash40(side_taunt_r)) {
// currently has issues: sometimes crashes. We'll use global parameters instead.
/*
DI_STATE = (DI_STATE + 1) % NUM_DI_STATES;
if (DI_STATE != NONE) {
float angle = (DI_STATE - 1) * PI / 4.0;
show_angle(battle_object_module_accessor, -10*sin(angle)+10, 10*cos(angle), -1 * angle * 180.0 / PI );
}
*/
}
// call original WorkModule::enable_transition_term_group_impl
@ -351,6 +387,8 @@ void MotionModule_change_motion_replace(u64 battle_object_module_accessor,
frame_speed_mult, unk1, unk2, unk3, unk4);
}
int main(int argc, char *argv[]) {
SaltySD_printf("SaltySD Plugin: alive\n");

201
source/raygun_printer.c Normal file
View file

@ -0,0 +1,201 @@
#include <switch.h>
#include <ctype.h>
#include "useful.h"
#include "lua_bind.h"
#define RAYGUN_LENGTH 8
#define RAYGUN_HEIGHT 6
#define RAYGUN_HORIZ_OFFSET 2
/*
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) {
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++;
}
}
}

4
source/raygun_printer.h Normal file
View file

@ -0,0 +1,4 @@
#include <switch.h>
void print_char(u64 module_accessor, char to_print, int line_num, float horiz_offset, bool facing_left);
void print_string(u64 module_accessor, const char* print_str);

View file

@ -1,12 +1,25 @@
int NONE = 0;
// Up Taunt
bool HITBOX_VIS = 1;
const int DI_RIGHT = 1;
// Side Taunt
int DI_RIGHT = 1;
int DI_UPRIGHT = 2;
int DI_UP = 3;
int DI_UPLEFT = 4;
int DI_LEFT = 5;
int DI_DOWNLEFT = 6;
int DI_DOWN = 7;
int DI_DOWNRIGHT = 8;
// 0, 0.785398, 1.570796, 2.356194, -3.14159, -2.356194, -1.570796, -0.785398
// 0, pi/4, pi/2, 3pi/4, pi, 5pi/4, 3pi/2, 7pi/4
uint DI_STATE = 0;
const uint NUM_DI_STATES = 2;
int DI_STATE = 0;
int NUM_DI_STATES = 9;
const uint NONE = 0;
const uint MASH_AIRDODGE = 1;
// Down Taunt
int MASH_AIRDODGE = 1;
uint TOGGLE_STATE = MASH_AIRDODGE;
const uint NUM_TOGGLE_STATES = 2;
int TOGGLE_STATE = 1;
int NUM_TOGGLE_STATES = 2;