Create simple data "migration" script (#548)

* setup function

* cleanup parts of calc_item_damage_enemy

* init data2c

* clean up data2c.py

* .

* rename and update script to have additional functionality

* .
This commit is contained in:
Alexander Faßbender 2021-12-12 14:53:19 +01:00 committed by GitHub
parent d9c72e432b
commit c719faf847
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 150 additions and 48 deletions

1
.gitignore vendored
View File

@ -15,6 +15,7 @@ expected/
/ver/current /ver/current
/ver/*/assets /ver/*/assets
ctx.c.m2c ctx.c.m2c
/data2c
# Build artifacts # Build artifacts
build.ninja build.ninja

View File

@ -505,7 +505,7 @@ enum SoundIDs {
SOUND_E3 = 0x000000E3, SOUND_E3 = 0x000000E3,
SOUND_E7 = 0x000000E7, SOUND_E7 = 0x000000E7,
SOUND_E9 = 0x000000E9, SOUND_E9 = 0x000000E9,
SOUND_EA = 0x000000EA, SOUND_FIRE = 0x000000EA,
SOUND_FREEZE = 0x000000EB, SOUND_FREEZE = 0x000000EB,
SOUND_10C = 0x0000010C, SOUND_10C = 0x0000010C,
SOUND_10D = 0x0000010D, SOUND_10D = 0x0000010D,
@ -576,7 +576,7 @@ enum SoundIDs {
SOUND_UNKNOWN_377 = 0x00000377, SOUND_UNKNOWN_377 = 0x00000377,
SOUND_UNKNOWN_379 = 0x00000379, SOUND_UNKNOWN_379 = 0x00000379,
SOUND_37A = 0x0000037A, SOUND_37A = 0x0000037A,
SOUND_37B = 0x0000037B, SOUND_ELECTRIC = 0x0000037B,
SOUND_GENERAL_WHISTLE = 0x00000395, SOUND_GENERAL_WHISTLE = 0x00000395,
SOUND_OPEN_SHELL = 0x000003D4, SOUND_OPEN_SHELL = 0x000003D4,
SOUND_JUMP_3E2 = 0x000003E2, SOUND_JUMP_3E2 = 0x000003E2,
@ -1513,6 +1513,7 @@ enum DamageTypes {
DAMAGE_TYPE_POW = 0x00000400, DAMAGE_TYPE_POW = 0x00000400,
DAMAGE_TYPE_QUAKE = 0x00000800, DAMAGE_TYPE_QUAKE = 0x00000800,
DAMAGE_TYPE_FEAR = 0x00001000, DAMAGE_TYPE_FEAR = 0x00001000,
DAMAGE_TYPE_2000 = 0x00002000,
DAMAGE_TYPE_4000 = 0x00004000, DAMAGE_TYPE_4000 = 0x00004000,
DAMAGE_TYPE_AIR_LIFT = 0x00008000, DAMAGE_TYPE_AIR_LIFT = 0x00008000,
DAMAGE_TYPE_SPINY_SURGE = 0x00010000, DAMAGE_TYPE_SPINY_SURGE = 0x00010000,

View File

@ -591,4 +591,7 @@ void clear_player_data(void);
void enforce_hpfp_limits(void); void enforce_hpfp_limits(void);
void func_8024EFE0(f32 x, f32 y, f32 z, s32 a, s32 b, s32 c);
void func_802664DC(f32 x, f32 y, f32 z, s32 attack, s32 a);
#endif #endif

View File

@ -1,4 +1,7 @@
#include "common.h" #include "common.h"
#include "battle/battle.h"
#include "script_api/battle.h"
#include "effects.h"
s32 calc_item_check_hit(void) { s32 calc_item_check_hit(void) {
BattleStatus* battleStatus = &gBattleStatus; BattleStatus* battleStatus = &gBattleStatus;
@ -26,7 +29,7 @@ s32 calc_item_check_hit(void) {
sfx_play_sound_at_position(0x10C, 0, walk->goalPos.x, walk->goalPos.y, walk->goalPos.z); sfx_play_sound_at_position(0x10C, 0, walk->goalPos.x, walk->goalPos.y, walk->goalPos.z);
return HIT_RESULT_IMMUNE; return HIT_RESULT_IMMUNE;
} }
if ((battleStatus->currentAttackElement & 0x80) && (actorPart->eventFlags & ACTOR_EVENT_FLAG_SPIKY_TOP)) { if ((battleStatus->currentAttackElement & DAMAGE_TYPE_JUMP) && (actorPart->eventFlags & ACTOR_EVENT_FLAG_SPIKY_TOP)) {
sfx_play_sound_at_position(0xE9, 0, walk->goalPos.x, walk->goalPos.y, walk->goalPos.z); sfx_play_sound_at_position(0xE9, 0, walk->goalPos.x, walk->goalPos.y, walk->goalPos.z);
return HIT_RESULT_LANDED_ON_SPIKE; return HIT_RESULT_LANDED_ON_SPIKE;
} }
@ -55,31 +58,31 @@ ApiStatus ItemDamageEnemy(Evt* script, s32 isInitialCall) {
a5 = *args++; a5 = *args++;
if ((a5 & 0x30) == 0x30) { if ((a5 & 0x30) == 0x30) {
battleStatus->flags1 |= 0x30; gBattleStatus.flags1 |= (BS_FLAGS1_10 | BS_FLAGS1_SP_EVT_ACTIVE);
} else if (a5 & flag) { } else if (a5 & flag) {
battleStatus->flags1 = (battleStatus->flags1 | flag) & ~0x20; gBattleStatus.flags1 = (gBattleStatus.flags1 | flag) & ~BS_FLAGS1_SP_EVT_ACTIVE;
} else if (a5 & 0x20) { } else if (a5 & 0x20) {
battleStatus->flags1 = (battleStatus->flags1 & ~flag) | 0x20; gBattleStatus.flags1 = (gBattleStatus.flags1 & ~flag) | BS_FLAGS1_SP_EVT_ACTIVE;
} else { } else {
battleStatus->flags1 = (battleStatus->flags1 & ~flag) & ~0x20; gBattleStatus.flags1 = (gBattleStatus.flags1 & ~flag) & ~BS_FLAGS1_SP_EVT_ACTIVE;
} }
if (a5 & 0x40) { if (a5 & 0x40) {
gBattleStatus.flags1 |= 0x40; gBattleStatus.flags1 |= BS_FLAGS1_40;
} else { } else {
gBattleStatus.flags1 &= ~0x40; gBattleStatus.flags1 &= ~BS_FLAGS1_40;
} }
if (a5 & 0x200) { if (a5 & 0x200) {
gBattleStatus.flags1 |= 0x200; gBattleStatus.flags1 |= BS_FLAGS1_200;
} else { } else {
gBattleStatus.flags1 &= ~0x200; gBattleStatus.flags1 &= ~BS_FLAGS1_200;
} }
if (a5 & 0x80) { if (a5 & 0x80) {
gBattleStatus.flags1 |= 0x80; gBattleStatus.flags1 |= BS_FLAGS1_80;
} else { } else {
gBattleStatus.flags1 &= ~0x80; gBattleStatus.flags1 &= ~BS_FLAGS1_80;
} }
actor = get_actor(script->owner1.actorID); actor = get_actor(script->owner1.actorID);
@ -123,31 +126,31 @@ ApiStatus ItemAfflictEnemy(Evt* script, s32 isInitialCall) {
a5 = *args++; a5 = *args++;
if ((a5 & 0x30) == 0x30) { if ((a5 & 0x30) == 0x30) {
battleStatus->flags1 |= 0x30; gBattleStatus.flags1 |= (BS_FLAGS1_10 | BS_FLAGS1_SP_EVT_ACTIVE);
} else if (a5 & flag) { } else if (a5 & flag) {
battleStatus->flags1 = (battleStatus->flags1 | flag) & ~0x20; gBattleStatus.flags1 = (gBattleStatus.flags1 | flag) & ~BS_FLAGS1_SP_EVT_ACTIVE;
} else if (a5 & 0x20) { } else if (a5 & 0x20) {
battleStatus->flags1 = (battleStatus->flags1 & ~flag) | 0x20; gBattleStatus.flags1 = (gBattleStatus.flags1 & ~flag) | BS_FLAGS1_SP_EVT_ACTIVE;
} else { } else {
battleStatus->flags1 = (battleStatus->flags1 & ~flag) & ~0x20; gBattleStatus.flags1 = (gBattleStatus.flags1 & ~flag) & ~BS_FLAGS1_SP_EVT_ACTIVE;
} }
if (a5 & 0x40) { if (a5 & 0x40) {
gBattleStatus.flags1 |= 0x40; gBattleStatus.flags1 |= BS_FLAGS1_40;
} else { } else {
gBattleStatus.flags1 &= ~0x40; gBattleStatus.flags1 &= ~BS_FLAGS1_40;
} }
if (a5 & 0x200) { if (a5 & 0x200) {
gBattleStatus.flags1 |= 0x200; gBattleStatus.flags1 |= BS_FLAGS1_200;
} else { } else {
gBattleStatus.flags1 &= ~0x200; gBattleStatus.flags1 &= ~BS_FLAGS1_200;
} }
if (a5 & 0x80) { if (a5 & 0x80) {
gBattleStatus.flags1 |= 0x80; gBattleStatus.flags1 |= BS_FLAGS1_80;
} else { } else {
gBattleStatus.flags1 &= ~0x80; gBattleStatus.flags1 &= ~BS_FLAGS1_80;
} }
actor = get_actor(script->owner1.actorID); actor = get_actor(script->owner1.actorID);
@ -190,31 +193,31 @@ ApiStatus func_80252B3C(Evt* script, s32 isInitialCall) {
a5 = *args++; a5 = *args++;
if ((a5 & 0x30) == 0x30) { if ((a5 & 0x30) == 0x30) {
battleStatus->flags1 |= 0x30; gBattleStatus.flags1 |= (BS_FLAGS1_10 | BS_FLAGS1_SP_EVT_ACTIVE);
} else if (a5 & flag) { } else if (a5 & flag) {
battleStatus->flags1 = (battleStatus->flags1 | flag) & ~0x20; gBattleStatus.flags1 = (gBattleStatus.flags1 | flag) & ~BS_FLAGS1_SP_EVT_ACTIVE;
} else if (a5 & 0x20) { } else if (a5 & 0x20) {
battleStatus->flags1 = (battleStatus->flags1 & ~flag) | 0x20; gBattleStatus.flags1 = (gBattleStatus.flags1 & ~flag) | BS_FLAGS1_SP_EVT_ACTIVE;
} else { } else {
battleStatus->flags1 = (battleStatus->flags1 & ~flag) & ~0x20; gBattleStatus.flags1 = (gBattleStatus.flags1 & ~flag) & ~BS_FLAGS1_SP_EVT_ACTIVE;
} }
if (a5 & 0x40) { if (a5 & 0x40) {
gBattleStatus.flags1 |= 0x40; gBattleStatus.flags1 |= BS_FLAGS1_40;
} else { } else {
gBattleStatus.flags1 &= ~0x40; gBattleStatus.flags1 &= ~BS_FLAGS1_40;
} }
if (a5 & 0x200) { if (a5 & 0x200) {
gBattleStatus.flags1 |= 0x200; gBattleStatus.flags1 |= BS_FLAGS1_200;
} else { } else {
gBattleStatus.flags1 &= ~0x200; gBattleStatus.flags1 &= ~BS_FLAGS1_200;
} }
if (a5 & 0x80) { if (a5 & 0x80) {
gBattleStatus.flags1 |= 0x80; gBattleStatus.flags1 |= BS_FLAGS1_80;
} else { } else {
gBattleStatus.flags1 &= ~0x80; gBattleStatus.flags1 &= ~BS_FLAGS1_80;
} }
actor = get_actor(script->owner1.actorID); actor = get_actor(script->owner1.actorID);
@ -257,31 +260,31 @@ ApiStatus ItemCheckHit(Evt* script, s32 isInitialCall) {
a5 = *args++; a5 = *args++;
if ((a5 & 0x30) == 0x30) { if ((a5 & 0x30) == 0x30) {
battleStatus->flags1 |= 0x30; gBattleStatus.flags1 |= (BS_FLAGS1_10 | BS_FLAGS1_SP_EVT_ACTIVE);
} else if (a5 & flag) { } else if (a5 & flag) {
battleStatus->flags1 = (battleStatus->flags1 | flag) & ~0x20; gBattleStatus.flags1 = (gBattleStatus.flags1 | flag) & ~BS_FLAGS1_SP_EVT_ACTIVE;
} else if (a5 & 0x20) { } else if (a5 & 0x20) {
battleStatus->flags1 = (battleStatus->flags1 & ~flag) | 0x20; gBattleStatus.flags1 = (gBattleStatus.flags1 & ~flag) | BS_FLAGS1_SP_EVT_ACTIVE;
} else { } else {
battleStatus->flags1 = (battleStatus->flags1 & ~flag) & ~0x20; gBattleStatus.flags1 = (gBattleStatus.flags1 & ~flag) & ~BS_FLAGS1_SP_EVT_ACTIVE;
} }
if (a5 & 0x40) { if (a5 & 0x40) {
gBattleStatus.flags1 |= 0x40; gBattleStatus.flags1 |= BS_FLAGS1_40;
} else { } else {
gBattleStatus.flags1 &= ~0x40; gBattleStatus.flags1 &= ~BS_FLAGS1_40;
} }
if (a5 & 0x200) { if (a5 & 0x200) {
gBattleStatus.flags1 |= 0x200; gBattleStatus.flags1 |= BS_FLAGS1_200;
} else { } else {
gBattleStatus.flags1 &= ~0x200; gBattleStatus.flags1 &= ~BS_FLAGS1_200;
} }
if (a5 & 0x80) { if (a5 & 0x80) {
gBattleStatus.flags1 |= 0x80; gBattleStatus.flags1 |= BS_FLAGS1_80;
} else { } else {
gBattleStatus.flags1 &= ~0x80; gBattleStatus.flags1 &= ~BS_FLAGS1_80;
} }
actor = get_actor(script->owner1.actorID); actor = get_actor(script->owner1.actorID);

View File

@ -72,10 +72,10 @@ void play_hit_sound(Actor* actor, f32 x, f32 y, f32 z, u32 hitSound) {
sfx_play_sound_at_position(SOUND_E2, 0, x, y, z); sfx_play_sound_at_position(SOUND_E2, 0, x, y, z);
break; break;
case ACTOR_PARTNER: case ACTOR_PARTNER:
sfx_play_sound_at_position(SOUND_EA, 0, x, y, z); sfx_play_sound_at_position(SOUND_FIRE, 0, x, y, z);
break; break;
case ACTOR_ENEMY0: case ACTOR_ENEMY0:
sfx_play_sound_at_position(SOUND_EA, 0, x, y, z); sfx_play_sound_at_position(SOUND_FIRE, 0, x, y, z);
break; break;
} }
break; break;
@ -98,10 +98,10 @@ void play_hit_sound(Actor* actor, f32 x, f32 y, f32 z, u32 hitSound) {
sfx_play_sound_at_position(SOUND_37A, 0, x, y, z); sfx_play_sound_at_position(SOUND_37A, 0, x, y, z);
break; break;
case ACTOR_PARTNER: case ACTOR_PARTNER:
sfx_play_sound_at_position(SOUND_37B, 0, x, y, z); sfx_play_sound_at_position(SOUND_ELECTRIC, 0, x, y, z);
break; break;
case ACTOR_ENEMY0: case ACTOR_ENEMY0:
sfx_play_sound_at_position(SOUND_37B, 0, x, y, z); sfx_play_sound_at_position(SOUND_ELECTRIC, 0, x, y, z);
break; break;
} }
break; break;
@ -791,7 +791,7 @@ s32 calc_enemy_damage_target(Actor* attacker) {
&& !has_enchanted_part(attacker) && !has_enchanted_part(attacker)
) { ) {
// enum mismatch? shock vs explode :raised_eyebrow: // enum mismatch? shock vs explode :raised_eyebrow:
sfx_play_sound_at_position(SOUND_37B, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z); sfx_play_sound_at_position(SOUND_ELECTRIC, 0, state->goalPos.x, state->goalPos.y, state->goalPos.z);
func_80251474(attacker); func_80251474(attacker);
dispatch_damage_event_actor_1(attacker, 1, EVENT_SHOCK_HIT); dispatch_damage_event_actor_1(attacker, 1, EVENT_SHOCK_HIT);
return HIT_RESULT_TRIGGERED_EXPLODE; return HIT_RESULT_TRIGGERED_EXPLODE;

94
tools/migrate_data_to_c.py Executable file
View File

@ -0,0 +1,94 @@
#!/usr/bin/python3
import re
import os
import argparse
data_dir = os.path.dirname(os.path.realpath(__file__)) + "/../ver/current/asm/data/"
def find_dir(query):
for root, dirs, files in os.walk(data_dir):
for f in files:
if f == query:
return os.path.join(root, f)
return None
def data_to_c(file_path):
file = open(file_path)
s = file.read()
output = ""
pattern = re.compile(r"(dlabel (D_.*)\n.(\w+) (.*))")
for (all, symbol, type, data) in re.findall(pattern, s):
if type == "word":
output += "s32 " + symbol + "[] = {" + data + "};\n\n"
elif type == "byte":
output += "s8 " + symbol + "[] = {" + data + "};\n\n"
else:
output += all + "\n\n"
file.close()
return output
def out_to_file(output, file_path):
output_dir = os.path.join(os.getcwd(), "data2c")
if not os.path.exists(output_dir):
os.mkdir(output_dir)
file_name = file_path[file_path.rfind("/"):-7]
file = open("data2c/" + file_name + ".c", "w+")
file.write(output)
file.close()
def get_all():
for root, dirs, files in os.walk(data_dir):
for f in files:
file_path = os.fspath(os.path.join(root, f))
out_to_file(data_to_c(file_path), file_path)
print("Files have been translated successfully and stored at " + os.getcwd() + "/data2c/")
def query(file, to_file):
for root, dirs, files in os.walk(data_dir):
for f in files:
if f == file:
file_path = os.fspath(os.path.join(root, f))
output = data_to_c(file_path)
if to_file is True:
out_to_file(output, file_path)
else:
print(output)
return
print("File not found: " + file)
parser = argparse.ArgumentParser(description="Tool to translate .data.s files to data arrays")
parser.add_argument("query", help="data file", nargs='?', default=None)
parser.add_argument("--all", help="translate all data files at once and output them into /data2c", action='store_true', required=False)
parser.add_argument("--to-file", help="redirect the output into a file. Can not be used in combination with --all", action='store_true', required=False)
args = parser.parse_args()
if args.query is None and args.all is False and args.to_file is False:
parser.print_help()
exit()
if args.query is not None and not args.query.endswith(".data.s"):
args.query = args.query + ".data.s"
if args.all is False:
if args.to_file is True:
query(args.query, True)
else:
query(args.query, False)
else:
get_all()