You've already forked Microtransactions64
mirror of
https://github.com/Print-and-Panic/Microtransactions64.git
synced 2026-01-21 10:17:19 -08:00
* buffers: refresh 15 and revert to base decomp * behavior script * color helper functions * extended bounds * egeo_layout * fixed model ids * camera conf improved * message panel ucode small * graph node * level script * mathutil updates * mathutil updates (allow unused funcs) * behaviors a - beta_fish * Add librtc and fix some data declarations * Move GRUCODE define to proper location in makefile * Refresh 15 * extra * Make ROM name smaller and change messages printed on build a bit * Fix console (lol) * Update UNF to latest master * Make ucode load from .o's (and also fix Super3D) * Fix crash with rumble + custom mario model * graph node and mathutil * removed behaviors * Ldtob documentation * _Putfld labeling * area * behavior actions * camera * debug updates * bubbles * envfx snow * farcall helpers * game init * geo misc * hud * only check if VC on render init * ingame menu * revert goddard to base decomp * insn disasm * interaction documentation * level geo * level update defines * macro special objects formatting changes * main.h documentation * map parser documentation & formatting * airborne documentation * mario actions automatic documentation * mario actions cutscene documentation * mario actions moving documentation and options * mario actions object documentation and options * mario stationary documentation * mario submerged documentation * mario misc documentation * mario step: ledge grab fixes and documentation * mario documentation * memory.h documentation * moving textures * object behaviors * object collision * fix flamethrower bug * object helpers * object list processor documentation * paintings * platform displacement * print / printf * puppycam absf * puppyprint updates and formatting changes * rendering graph node performance optimizations * rumble opt and doc * hqvm back to ultrasm64 * save file documentation and unlock defines * s2d engine * reset various files to ultrasm64 * file select * intro geo documentation * screen transition documentation * segment2.h * shadow overhaul * skybox refactor * sound init: clean up define usage + documentation * spawn object optimizations and documentation * spawn sound cleanup * sram to ultrasm64 * star select cleanup * title screen cleanup * dialogs / text * rename stomp smoke * stomp smoke -> small water splash * updated README * compilation flags * optimized file positions + support function/data sections * surface collision performance improvements * surface load optimizations * camera conf documentation * Allow easier command for opening puppyprint debug * Rearranged framebuffers & fixed puppyprint console printing * Fix shadow scaling and shifting * Fix SILHOUETTE, OBJECTS_REJ, and ucode loading, also clean up render phase system a bit. * Fixed build with BETTER_HANGING off * Clean up OBJECTS_REJ ifdefs * Fix duplicate comment & graph render layers/flags bitmask * Fixed build with BETTER_HANGING off * Fix Fast64 importing by reverting sSegmentTable change * Readded missing functions that caused build errors with Mario head enabled * Fixed clang compilation issues * Add INTER mode for geo_update_layer_transparency * Fix build warnings * bugfix: miscalculation in obj_turn_toward_object * Some puppytech fixes * Further Puppycamera fixes * Fix BUGFIX_DIALOG_TIME_STOP Fixes #136 * Fix sliding platform bparams * Add LEGACY_SHADOW_IDS define for Fast64 compatibility * Apply suggested changes * Better find_in_bounds_yaw_wdw_bob_thi ifdef * Fix build warnings for unused functions * Fixed stale reference bug from obj_mark_for_deletion change * Fixed incorrect digit for 100s #145 * Change groundpound-fix define and functionality to just disable bonking * Fixed puppyroll #134 * Adjust height value for terrain angle to kick in * fixed hi score flashing * Remove menudata backup (#131) Not considered important enough to keep * Fix fread() build warning * Add COURSE_NUM_TO_INDEX to save_file_get_star_flags check in bhv_unagi_init * Fix approach_s16 return value * Use boolean defines for oCapDoScaleVertically * Make the door lock a part of the key door model to eliminate z-fighting, also reduce z fighting on numbered doors with AUTO_LOD enabled. * Move flames to LAYER_TRANSPARENT_INTER * Resolved some compiler warnings and added FALL_THROUGH define (#168) * Address some more compiler warnings with different define toggles * Remove unnecessary fallthrough attribute * fixed geo_process_billboard floating point exception * Allow water to face any direction * Initialize focOffset so that BBH doesn't crash * Removed superfluous RDP commands when switching microcodes which would override scissor * Set OBJ_FLAG_DONT_CALC_COLL_DIST on bhvUkikiCage * Fix rumble build * Fixed UNLOCK_FPS strobing * Update src/game/object_helpers.c Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com> * Update src/game/object_helpers.c Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com> * Fix LEGACY_SHADOW_IDS id conflict * Use the vanilla default value for rotating fire bars if bparam2 is 0 * START_LEVEL safeguard * Fix some drawing distance issues caused by AUTO_COLLISION_DISTANCE * Fix rumble build * Fixed spline poll code using the wrong values for keyframes * Update readme with better credits Better credits for individual contributors * add arthur * added falco and moose * add fazana * le funny typo * added S2DEX engine to credits * silhouette + axo + ratio * remove specific callouts + add auto col distance * Update data/behavior_data.c Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com> * Update data/behavior_data.c Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com> * Update data/behavior_data.c Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com> * Revert formatting changes to match vanilla decomp * Re-implement Y buffer for find_ceil * Re-implement POWER_STARS_HEAL for normal Power Stars * Start level comment & exit course comment/collapse * utilize reonucam technique for FAST_VERTICAL_CAMERA_MOVEMENT * Fix "MAX_REFERENCED_WALLS" typo * Allow stop_and_set_height_to_floor to work at any height if Mario is teleporting (#213) * Revert stop_and_set_height_to_floor to vanilla Fixes #208 * Fixed sAudioEnabled so that it disables audio CPU processing as well * Fixed puppyprint debug RDP us calculations * Renamed sAudioEnabled to gAudioEnabled * Replaced mtxf_to_mtx_asm with an equivalent implementation that supports WORLD_SCALE * Moved extended bounds and world scale configuration to a new config_world.h file * Default all objects to non-rej (#227) Fixes #221 (Default all objects to non-rej) * Fix #221 * Fix VISUAL_DEBUG breaking/crashing when OBJECTS_REJ is disabled (#211) * Fix VISUAL_DEBUG breaking/crashing when OBJECTS_REJ is disabled * Change vtl decrement in visual_surface_display from 6 to 3 Fixes #207 * Make area in SL igloo wider to prevent a softlock (#233) Fixes #210 * Fix coin formation coins being deleted if they spawn in the middle of a floor, also fix TTM slide coin position (#232) Fixes #201 * Make UNLOCK_ALL apply to more things * Fix wrong ifdef/ifndef in bhv_invisible_objects_under_bridge_init * Change chain chomp load/unload distances depending on number of segments (#237) Fixes #192 * added WATER_PLUNGE_UPWARP define * Add reonucam patch (#239) * added reonucam patch Fixes #218 * Fix how shadows handle water/transparency/height (#228) * Fix how shadows handle water/transparency/height * Change shadow check for flying carpets from a level specific check to a oPlatformOnTrackType check Fixes #179 * added reonucam credit * delete unnecesary patches * Apply suggested changes * murdered more patches * UNLOCK_ALL unlocks the cap boxes * UNLOCK_ALL unlocks cap boxes (slightly more epic edition) * revert ceil buffer * Renamed HD_INTRO_TEXTURES define, separated intro floombas * prevent double definition of floombas * actually prevent floomba redefinition * Develop/refactor default defines (#242) * Changed default config options * Added build dir to includePaths for pngs * disable NO_SLEEP by default * Disable puppyprint by default Sorry fazana 😔 * fix typos * add comment about BETTER_REVERB console perf * disable blue coin switch retry by default * Update config_audio.h Co-authored-by: Reonu <danileon95@gmail.com> Co-authored-by: Mr-Wiseguy <68165316+Mr-Wiseguy@users.noreply.github.com> * revert air step line to vanilla to fix bitfs scaling platform issue (#247) Fixes #200 * Fix stuttering on thin slopes (#248) * Fix stuttering on thin slopes * Revert vec3f_find_ceil calls to vanilla * Rename vec3f_find_ceil to find_mario_ceil * Update src/engine/surface_collision.h Fixes #249 * Swap static and dynamic surface checks back to vanilla order (#253) * Swap static and dynamic surface checks back to vanilla order * re-enable DISABLE_ALL config Fixes #251 #252 * Fixed save and quitting while in widescreen (#257) * Fixed save and quitting while in widescreen * use define for the level * all my homies hate ifdefs * skip wall offsets < 0 (#255) Fixes #255 * #264: Document non-stop stars' issues (#267) * #264: Document non-stop stars' issues * Update include/config/config_game.h * nonstop vanilla comment * derive margin_radius from radius after capping at 200 (#266) Fixes #259 * Config cleanup/refactor (#269) * Moved puppyprint define to graphics / rearranged some debug defines for ease of access * Moved compatibility safeguards to config_safeguards.h * spacing and comment formatting * #272 Move GFX_POOL_SIZE to config_graphics.h * disable EASIER_DIALOG_TRIGGER by default * prevent redefining warnings * small ifdef typo * changed ifndef to undefs Fixes #262 Fixes #272 * Improved movement config documentation related to turning around (#271) Fixes #270 * rename CUSTOM_DEBUG, add comments (#275) * Update README.md (#277) * v2.0.0 Co-authored-by: CrashOveride95 <crashoveride953@gmail.com> Co-authored-by: Arceveti <73617174+Arceveti@users.noreply.github.com> Co-authored-by: n64 <n64> Co-authored-by: Fazana <52551480+FazanaJ@users.noreply.github.com> Co-authored-by: Mr-Wiseguy <mrwiseguyromhacking@gmail.com> Co-authored-by: aglab2 <aglab3@gmail.com> Co-authored-by: gheskett <gheskett@gmail.com> Co-authored-by: Reonu <danileon95@gmail.com> Co-authored-by: Axollyon <20480418+Axollyon@users.noreply.github.com> Co-authored-by: Mr-Wiseguy <68165316+Mr-Wiseguy@users.noreply.github.com>
309 lines
11 KiB
C
309 lines
11 KiB
C
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
#define EI_DATA 5
|
|
#define EI_NIDENT 16
|
|
|
|
#define STT_NOTYPE 0
|
|
#define STT_OBJECT 1
|
|
#define STT_FUNC 2
|
|
#define STT_SECTION 3
|
|
#define STT_FILE 4
|
|
#define STT_COMMON 5
|
|
#define STT_TLS 6
|
|
|
|
#define ELF_ST_TYPE(x) (((unsigned int) x) & 0xf)
|
|
|
|
typedef uint32_t Elf32_Addr;
|
|
typedef uint32_t Elf32_Off;
|
|
|
|
typedef struct {
|
|
unsigned char e_ident[EI_NIDENT];
|
|
uint16_t e_type;
|
|
uint16_t e_machine;
|
|
uint32_t e_version;
|
|
Elf32_Addr e_entry;
|
|
Elf32_Off e_phoff;
|
|
Elf32_Off e_shoff;
|
|
uint32_t e_flags;
|
|
uint16_t e_ehsize;
|
|
uint16_t e_phentsize;
|
|
uint16_t e_phnum;
|
|
uint16_t e_shentsize;
|
|
uint16_t e_shnum;
|
|
uint16_t e_shstrndx;
|
|
} Elf32_Ehdr;
|
|
|
|
typedef struct {
|
|
uint32_t sh_name;
|
|
uint32_t sh_type;
|
|
uint32_t sh_flags;
|
|
Elf32_Addr sh_addr;
|
|
Elf32_Off sh_offset;
|
|
uint32_t sh_size;
|
|
uint32_t sh_link;
|
|
uint32_t sh_info;
|
|
uint32_t sh_addralign;
|
|
uint32_t sh_entsize;
|
|
} Elf32_Shdr;
|
|
|
|
typedef struct {
|
|
uint32_t st_name;
|
|
Elf32_Addr st_value;
|
|
uint32_t st_size;
|
|
unsigned char st_info;
|
|
unsigned char st_other;
|
|
uint16_t st_shndx;
|
|
} Elf32_Sym;
|
|
|
|
typedef struct {
|
|
uint16_t magic; //To verify validity of the table
|
|
uint16_t vstamp; //Version stamp
|
|
uint32_t ilineMax; //Number of line number entries
|
|
uint32_t cbLine; //Number of bytes for line number entries
|
|
uint32_t cbLineOffset; //Index to start of line numbers
|
|
uint32_t idnMax; //Max index into dense numbers
|
|
uint32_t cbDnOffset; //Index to start dense numbers
|
|
uint32_t ipdMax; //Number of procedures
|
|
uint32_t cbPdOffset; //Index to procedure descriptors
|
|
uint32_t isymMax; //Number of local symbols
|
|
uint32_t cbSymOffset; //Index to start of local symbols
|
|
uint32_t ioptMax; //Maximum index into optimization entries
|
|
uint32_t cbOptOffset; //Index to start of optimization entries
|
|
uint32_t iauxMax; //Number of auxiliary symbols
|
|
uint32_t cbAuxOffset; //Index to the start of auxiliary symbols
|
|
uint32_t issMax; //Max index into local strings
|
|
uint32_t cbSsOffset; //Index to start of local strings
|
|
uint32_t issExtMax; //Max index into external strings
|
|
uint32_t cbSsExtOffset; //Index to the start of external strings
|
|
uint32_t ifdMax; //Number of file descriptors
|
|
uint32_t cbFdOffset; //Index to file descriptor
|
|
uint32_t crfd; //Number of relative file descriptors
|
|
uint32_t cbRfdOffset; //Index to relative file descriptors
|
|
uint32_t iextMax; //Maximum index into external symbols
|
|
uint32_t cbExtOffset; //Index to the start of external symbols.
|
|
} SymbolicHeader;
|
|
|
|
typedef struct {
|
|
uint32_t adr; // Memory address of start of file
|
|
uint32_t rss; // Source file name
|
|
uint32_t issBase; // Start of local strings
|
|
uint32_t cbSs; // Number of bytes in local strings
|
|
uint32_t isymBase; // Start of local symbol entries
|
|
uint32_t csym; // Count of local symbol entries
|
|
uint32_t ilineBase; // Start of line number entries
|
|
uint32_t cline; // Count of line number entries
|
|
uint32_t ioptBase; // Start of optimization symbol entries
|
|
uint32_t copt; // Count of optimization symbol entries
|
|
uint16_t ipdFirst; // Start of procedure descriptor table
|
|
uint16_t cpd; // Count of procedures descriptors
|
|
uint32_t iauxBase; // Start of auxiliary symbol entries
|
|
uint32_t caux; // Count of auxiliary symbol entries
|
|
uint32_t rfdBase; // Index into relative file descriptors
|
|
uint32_t crfd; // Relative file descriptor count
|
|
uint32_t flags;
|
|
uint32_t cbLineOffset; // Byte offset from header or file ln's
|
|
uint32_t cbLine;
|
|
} FileDescriptorTable;
|
|
|
|
typedef struct {
|
|
uint32_t iss;
|
|
uint32_t value;
|
|
uint32_t st_sc_index;
|
|
} LocalSymbolsEntry;
|
|
|
|
typedef enum {
|
|
stNil,
|
|
stGlobal,
|
|
stStatic,
|
|
stParam,
|
|
stLocal,
|
|
stLabel,
|
|
stProc,
|
|
stBlock,
|
|
stEnd,
|
|
stMember,
|
|
stTypedef,
|
|
stFile,
|
|
stStaticProc,
|
|
stConstant
|
|
} StConstants;
|
|
|
|
uint32_t u32be(uint32_t val) {
|
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
|
return __builtin_bswap32(val);
|
|
#else
|
|
return val;
|
|
#endif
|
|
}
|
|
|
|
uint16_t u16be(uint16_t val) {
|
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
|
return __builtin_bswap16(val);
|
|
#else
|
|
return val;
|
|
#endif
|
|
}
|
|
|
|
static bool elf_get_section_range(uint8_t *file, const char *searched_name, uint32_t *address, uint32_t *offset, uint32_t *size, uint32_t *section_index) {
|
|
Elf32_Ehdr *ehdr = (Elf32_Ehdr *)file;
|
|
|
|
for (int i = 0; i < u16be(ehdr->e_shnum); i++) {
|
|
if (memcmp("\x7f" "ELF", ehdr->e_ident, 4) != 0) {
|
|
fprintf(stderr, "Missing ELF magic\n");
|
|
exit(1);
|
|
}
|
|
if (ehdr->e_ident[EI_DATA] != 2) {
|
|
fprintf(stderr, "ELF file is not big-endian\n");
|
|
exit(1);
|
|
}
|
|
|
|
Elf32_Shdr *shdr = (Elf32_Shdr *)(file + u32be(ehdr->e_shoff) + i * u16be(ehdr->e_shentsize));
|
|
if (u16be(ehdr->e_shstrndx) >= u16be(ehdr->e_shnum)) {
|
|
fprintf(stderr, "Invalid ELF file\n");
|
|
exit(1);
|
|
}
|
|
Elf32_Shdr *str_shdr = (Elf32_Shdr *)(file + u32be(ehdr->e_shoff) + u16be(ehdr->e_shstrndx) * u16be(ehdr->e_shentsize));
|
|
char *name = (char *)(file + u32be(str_shdr->sh_offset) + u32be(shdr->sh_name));
|
|
if (memcmp(name, searched_name, strlen(searched_name)) == 0) {
|
|
*address = u32be(shdr->sh_addr);
|
|
*offset = u32be(shdr->sh_offset);
|
|
*size = u32be(shdr->sh_size);
|
|
*section_index = i;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
if (argc < 3) {
|
|
fprintf(stderr, "Usage: %s INFILE OUTFILE\n", argv[0]);
|
|
return 1;
|
|
}
|
|
|
|
FILE *in = fopen(argv[1], "rb");
|
|
if (in == NULL) {
|
|
perror("fopen couldn't open input file");
|
|
exit(1);
|
|
}
|
|
fseek(in, 0, SEEK_END);
|
|
size_t file_size = ftell(in);
|
|
fseek(in, 0, SEEK_SET);
|
|
uint8_t *file = malloc(file_size);
|
|
if (fread(file, 1, file_size, in) != file_size) {
|
|
fclose(in);
|
|
fprintf(stderr, "Failed to read file: %s\n", argv[1]);
|
|
exit(1);
|
|
}
|
|
fclose(in);
|
|
|
|
uint32_t data_address, data_offset, data_size, data_index;
|
|
if (!elf_get_section_range(file, ".data", &data_address, &data_offset, &data_size, &data_index)) {
|
|
fprintf(stderr, "section .data not found\n");
|
|
exit(1);
|
|
}
|
|
|
|
uint32_t rodata_address, rodata_offset, rodata_size, rodata_index;
|
|
if (elf_get_section_range(file, ".rodata", &rodata_address, &rodata_offset, &rodata_size, &rodata_index)) {
|
|
fprintf(stderr, ".rodata section found, please put everything in .data instead (non-const variables)\n");
|
|
exit(1);
|
|
}
|
|
|
|
uint32_t symtab_address, symtab_offset, symtab_size, symtab_index;
|
|
if (!elf_get_section_range(file, ".symtab", &symtab_address, &symtab_offset, &symtab_size, &symtab_index)) {
|
|
fprintf(stderr, "section .symtab not found\n");
|
|
exit(1);
|
|
}
|
|
|
|
uint32_t strtab_address, strtab_offset, strtab_size, strtab_index;
|
|
if (!elf_get_section_range(file, ".strtab", &strtab_address, &strtab_offset, &strtab_size, &strtab_index)) {
|
|
fprintf(stderr, "section .strtab not found\n");
|
|
exit(1);
|
|
}
|
|
|
|
// IDO might pad the section to the nearest 16 byte boundary,
|
|
// but the mio0 data should not include that. Therefore find
|
|
// the "real" end by finding where the last symbol ends.
|
|
uint32_t last_symbol_end = 0;
|
|
|
|
for (uint32_t i = 0; i < symtab_size / sizeof(Elf32_Sym); i++) {
|
|
Elf32_Sym *symbol = (Elf32_Sym *)(file + symtab_offset + i * sizeof(Elf32_Sym));
|
|
#if DEBUG
|
|
const char *name = "(null)";
|
|
if (symbol->st_name != 0U) {
|
|
name = (const char*)file + strtab_offset + u32be(symbol->st_name);
|
|
}
|
|
printf("%08x\t%08x\t%02x\t%02x\t%02x\t%s\n", u32be(symbol->st_value), u32be(symbol->st_size), symbol->st_info, symbol->st_other, u16be(symbol->st_shndx), name);
|
|
#endif
|
|
if (ELF_ST_TYPE(symbol->st_info) == STT_OBJECT && u16be(symbol->st_shndx) == data_index) {
|
|
uint32_t symbol_end = u32be(symbol->st_value) + u32be(symbol->st_size);
|
|
if (symbol_end > last_symbol_end) {
|
|
last_symbol_end = symbol_end;
|
|
}
|
|
}
|
|
}
|
|
|
|
uint32_t mdebug_address, mdebug_offset, mdebug_size, mdebug_index;
|
|
if (elf_get_section_range(file, ".mdebug", &mdebug_address, &mdebug_offset, &mdebug_size, &mdebug_index)) {
|
|
SymbolicHeader *symbolic_header = (SymbolicHeader *)(file + mdebug_offset);
|
|
|
|
for (uint32_t i = 0; i < u32be(symbolic_header->ifdMax); i++) {
|
|
FileDescriptorTable *fdt = (FileDescriptorTable *)(file + u32be(symbolic_header->cbFdOffset) + i * sizeof(FileDescriptorTable));
|
|
|
|
for (uint32_t j = 0; j < u32be(fdt->csym); j++) {
|
|
LocalSymbolsEntry lse;
|
|
memcpy(&lse, file + u32be(symbolic_header->cbSymOffset) + (u32be(fdt->isymBase) + j) * sizeof(LocalSymbolsEntry), sizeof(LocalSymbolsEntry));
|
|
|
|
uint32_t value = u32be(lse.value);
|
|
uint32_t st_sc_index = u32be(lse.st_sc_index);
|
|
uint32_t st = (st_sc_index >> 26);
|
|
#ifdef DEBUG
|
|
uint32_t sc = (st_sc_index >> 21) & 0x1f;
|
|
uint32_t index = st_sc_index & 0xfffff;
|
|
uint32_t iss = u32be(lse.iss);
|
|
const char *symbol_name = file + u32be(symbolic_header->cbSsOffset) + iss;
|
|
printf("%s %08x\n", symbol_name, value);
|
|
#endif
|
|
|
|
if (st == stStatic || st == stGlobal) {
|
|
// Right now just assume length 8 since it's quite much work to extract the real size
|
|
uint32_t symbol_end = value + 8;
|
|
if (symbol_end > last_symbol_end) {
|
|
last_symbol_end = symbol_end;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
printf("Last symbol end: %08x\n", last_symbol_end);
|
|
#endif
|
|
|
|
size_t new_size = last_symbol_end - data_address;
|
|
if (new_size + 16 <= data_size) {
|
|
// There seems to be more than 16 bytes padding or non-identified data, so abort and take the original size
|
|
new_size = data_size;
|
|
} else {
|
|
// Make sure we don't cut off non-zero bytes
|
|
for (size_t i = new_size; i < data_size; i++) {
|
|
if (file[data_offset + i] != 0) {
|
|
// Must be some symbol missing, so abort and take the original size
|
|
new_size = data_size;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
FILE *out = fopen(argv[2], "wb");
|
|
fwrite(file + data_offset, 1, new_size, out);
|
|
fclose(out);
|
|
|
|
free(file);
|
|
return 0;
|
|
}
|