From 216bcbc0c276524ee533f383bc76eec41238372f Mon Sep 17 00:00:00 2001 From: Shivam Dutt Date: Tue, 28 May 2019 15:36:33 -0500 Subject: [PATCH] Moved Hash40 and Vector3f structs from l2c.cpp to useful.h Moved LOAD64 macro from l2c_imports.hpp to useful.h Moved round_to and the various linear interpolation functions from useful.h to useful_visual.h More formatting fixes --- source/hitbox_visualizer.hpp | 5 +- source/l2c.hpp | 14 ------ source/l2c_imports.hpp | 15 +++--- source/main.cpp | 1 - source/raygun_printer.hpp | 58 ++++++++++++------------ source/script_replacement.hpp | 2 +- source/training_mods.hpp | 4 +- source/useful.h | 40 +++++----------- source/{useful.cpp => useful_visual.cpp} | 4 +- source/useful_visual.h | 31 +++++++++++++ 10 files changed, 88 insertions(+), 86 deletions(-) delete mode 100644 source/l2c.hpp rename source/{useful.cpp => useful_visual.cpp} (97%) create mode 100644 source/useful_visual.h diff --git a/source/hitbox_visualizer.hpp b/source/hitbox_visualizer.hpp index b61ca0d..b23c47c 100644 --- a/source/hitbox_visualizer.hpp +++ b/source/hitbox_visualizer.hpp @@ -1,12 +1,13 @@ #include -#include "l2c.hpp" +#include "useful.h" +#include "useful_visual.h" + #include "l2c_imports.hpp" #include "acmd_wrapper.hpp" #include "saltysd_helper.hpp" #include "const_value_table.h" #include "taunt_toggles.h" -#include "useful.h" using namespace lib; using namespace app::lua_bind; diff --git a/source/l2c.hpp b/source/l2c.hpp deleted file mode 100644 index 80bb242..0000000 --- a/source/l2c.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef L2C_H -#define L2C_H - -typedef struct Hash40 { - uint64_t hash : 40; -} Hash40; - -typedef struct Vector3f { - float x; - float y; - float z; -} Vector3f; - -#endif // L2C_H diff --git a/source/l2c_imports.hpp b/source/l2c_imports.hpp index c5b61f3..46f7424 100644 --- a/source/l2c_imports.hpp +++ b/source/l2c_imports.hpp @@ -5,10 +5,9 @@ #include -#include "l2c.hpp" -#include "lua_bind_hash.hpp" +#include "useful.h" -#define LOAD64 *(u64 *) +#include "lua_bind_hash.hpp" u64 is_training_mode(void) asm("_ZN3app9smashball16is_training_modeEv") LINKABLE; @@ -25,14 +24,14 @@ namespace lib { L2C_string = 8, }; - struct L2CTable_meta { + typedef struct L2CTable_meta { uint64_t a; uint64_t b; uint64_t c; uint64_t d; - }; + } L2CTable_meta; - struct L2CTable { + typedef struct L2CTable { uint32_t refcnt; uint32_t unk; @@ -41,9 +40,9 @@ namespace lib { uint64_t also_end; // L2CValue* struct L2CTable_meta meta; uint64_t unk_ptr; - }; + } L2CTable; - struct L2CInnerFunctionBase { + typedef struct L2CInnerFunctionBase { uint64_t unk; uint32_t refcnt; } L2CInnerFunctionBase; diff --git a/source/main.cpp b/source/main.cpp index 061f801..3f245c9 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -14,7 +14,6 @@ #include "saltysd_dynamic.h" #include "saltysd_helper.hpp" -#include "l2c.hpp" #include "l2c_imports.hpp" #include "acmd_imports.hpp" diff --git a/source/raygun_printer.hpp b/source/raygun_printer.hpp index a3617ee..bc7ff51 100644 --- a/source/raygun_printer.hpp +++ b/source/raygun_printer.hpp @@ -23,21 +23,21 @@ using namespace app::lua_bind; */ 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 + {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 }; /* @@ -107,12 +107,12 @@ const char segment_rev[15] = { }; 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}; + 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}; + 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, @@ -150,9 +150,9 @@ void print_char( u64 module_accessor, char to_print, int line_num, float horiz_o const float* segment; int index = segment_str[i] - 'a'; - if (facing_left == -1) + if (facing_left == -1) { index = segment_rev[index] - 'a'; - + } segment = segment_dict[index]; float z = segment[0]; @@ -170,7 +170,7 @@ void print_char( u64 module_accessor, char to_print, int line_num, float horiz_o void print_string( u64 module_accessor, const char* print_str) { // Delete any previous strings - Hash40 raygunShot = {.hash = 0x11e470b07fLL}; + Hash40 raygunShot = { .hash = 0x11e470b07fLL }; EffectModule::kill_kind(module_accessor, raygunShot.hash, 0, 1); int line_num = 0; @@ -179,8 +179,9 @@ void print_string( u64 module_accessor, const char* print_str) { float facing_left = PostureModule::lr(module_accessor); - if (strlen(print_str) <= 8 && strchr(print_str, '\n') == NULL) + if (strlen(print_str) <= 8 && strchr(print_str, '\n') == NULL) { line_num = 1; + } horiz_offset = 0; char_num = 0; for (size_t i = 0; i < strlen(print_str); i++) { @@ -196,10 +197,11 @@ void print_string( u64 module_accessor, const char* print_str) { char_num++; // short characters - if (curr_char == 'D' || curr_char == '1' ) + if (curr_char == 'D' || curr_char == '1') { horiz_offset += facing_left * (RAYGUN_LENGTH/2 + 3); - else - horiz_offset += facing_left * (RAYGUN_LENGTH+3); + } else { + horiz_offset += facing_left * (RAYGUN_LENGTH + 3); + } if (char_num > 8) { horiz_offset = 0; @@ -209,4 +211,4 @@ void print_string( u64 module_accessor, const char* print_str) { } } -#endif // RAYGUN_PRINTER_H \ No newline at end of file +#endif // RAYGUN_PRINTER_H diff --git a/source/script_replacement.hpp b/source/script_replacement.hpp index 4930c0e..479b13b 100644 --- a/source/script_replacement.hpp +++ b/source/script_replacement.hpp @@ -3,8 +3,8 @@ #include #include "crc32.h" +#include "useful.h" -#include "l2c.hpp" #include "l2c_imports.hpp" #include "acmd_wrapper.hpp" diff --git a/source/training_mods.hpp b/source/training_mods.hpp index e8bbbba..5f470a1 100644 --- a/source/training_mods.hpp +++ b/source/training_mods.hpp @@ -1,6 +1,6 @@ -#include "l2c.hpp" -#include "saltysd_helper.hpp" +#include "useful.h" #include "l2c_imports.hpp" +#include "saltysd_helper.hpp" #include "acmd_imports.hpp" #include "taunt_toggles.h" #include "raygun_printer.hpp" diff --git a/source/useful.h b/source/useful.h index 949992d..4cc628f 100644 --- a/source/useful.h +++ b/source/useful.h @@ -5,38 +5,22 @@ #include #include -#include "l2c.hpp" - #define LINKABLE __attribute__ ((weak)) -#define debug_log(...) \ - {char log_buf[0x200]; snprintf(log_buf, 0x200, __VA_ARGS__); \ - svcOutputDebugString(log_buf, strlen(log_buf));} +#define LOAD64 *(u64 *) -/** - * Rounds a number to the nearest multiple of another number. - */ -float round_to(float val, float align); +#define debug_log(...) {\ + char log_buf[0x200]; snprintf(log_buf, 0x200, __VA_ARGS__); \ + svcOutputDebugString(log_buf, strlen(log_buf)); } -/** - * Linearly interpolates between two numbers, without bounds checking. - */ -float lerp(float min, float max, float t); -float unlerp(float min, float max, float val); -/** - * Linearly interpolates between two numbers, with bounds checking. - */ -float lerp_bounded(float min, float max, float t); -float unlerp_bounded(float min, float max, float val); +typedef struct Hash40 { + uint64_t hash : 40; +} Hash40; -/** - * Linearly nterpolates between two colors, with bounds checking, accounting for gamma. - * arguments: - * - min_color (Vector3f) -- xyz maps to rgb, components are usually in the range [0.0f, 1.0f] but can go beyond to account for super-bright or super-dark colors - * - max_Color (Vector3f) -- same as minColor - * - t (float) -- how far to interpolate between the colors - * - gamma (float = 2.0f) -- used for color correction, helps avoid ugly dark colors when interpolating b/t bright colors - */ -Vector3f color_lerp(Vector3f min_color, Vector3f max_color, float t, float gamma = 2.0f); +typedef struct Vector3f { + float x; + float y; + float z; +} Vector3f; #endif // USEFUL_H diff --git a/source/useful.cpp b/source/useful_visual.cpp similarity index 97% rename from source/useful.cpp rename to source/useful_visual.cpp index 004cd25..1d8903f 100644 --- a/source/useful.cpp +++ b/source/useful_visual.cpp @@ -1,8 +1,8 @@ -#include "useful.h" +#include "useful_visual.h" #include -#include "l2c.hpp" +#include "useful.h" float round_to(float val, float align) { return roundf(val / align) * align; diff --git a/source/useful_visual.h b/source/useful_visual.h new file mode 100644 index 0000000..497b640 --- /dev/null +++ b/source/useful_visual.h @@ -0,0 +1,31 @@ +#ifndef USEFUL_VISUAL_H +#define USEFUL_VISUAL_H + +#include "useful.h" +/** + * Rounds a number to the nearest multiple of another number. + */ +float round_to(float val, float align); + +/** + * Linearly interpolates between two numbers, without bounds checking. + */ +float lerp(float min, float max, float t); +float unlerp(float min, float max, float val); +/** + * Linearly interpolates between two numbers, with bounds checking. + */ +float lerp_bounded(float min, float max, float t); +float unlerp_bounded(float min, float max, float val); + +/** + * Linearly nterpolates between two colors, with bounds checking, accounting for gamma. + * arguments: + * - min_color (Vector3f) -- xyz maps to rgb, components are usually in the range [0.0f, 1.0f] but can go beyond to account for super-bright or super-dark colors + * - max_Color (Vector3f) -- same as minColor + * - t (float) -- how far to interpolate between the colors + * - gamma (float = 2.0f) -- used for color correction, helps avoid ugly dark colors when interpolating b/t bright colors + */ +Vector3f color_lerp(Vector3f min_color, Vector3f max_color, float t, float gamma = 2.0f); + +#endif // USEFUL_VISUAL_H