Skip to content

Commit 695763a

Browse files
committed
Fix missing recomp syms
1 parent 50fe755 commit 695763a

File tree

9 files changed

+64
-28
lines changed

9 files changed

+64
-28
lines changed

include/dlls/objects/223_cannon_claw.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#ifndef _DLLS_223_H
22
#define _DLLS_223_H
33

4-
#include "common.h"
4+
#include <PR/ultratypes.h>
5+
#include "game/actor/actor.h"
56
#include "dll_def.h"
67

78
DLL_INTERFACE_BEGIN(223_cannon_claw)

include/dlls/objects/365.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef _DLLS_365_H
2+
#define _DLLS_365_H
3+
4+
#include <PR/ultratypes.h>
5+
#include "game/actor/actor.h"
6+
#include "dll_def.h"
7+
8+
typedef struct
9+
{
10+
u8 mPad[0x62];
11+
s8 m0062;
12+
} TStruct365Func0006;
13+
14+
#endif //_DLLS_365_H

src/dlls/engine/29_gplay/gplay.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#include <PR/ultratypes.h>
2-
#include "common.h"
2+
3+
#include "game/actor/actor.h"
4+
#include "sys/dll.h"
5+
#include "sys/math.h"
6+
#include "variables.h"
7+
#include "functions.h"
8+
#include "dll.h"
39

410
static const char str1[] = "gplayLoadGame error: savegame and backup failed to load.\n";
511
static const char str2[] = "gplayLoadOptions error: saveoptions failed to load.\n";
@@ -87,6 +93,7 @@ void gplay_func_110(s8 param1) {
8793
}
8894

8995
#if 1
96+
void gplay_func_198(s8 param1, u8 *param2);
9097
#pragma GLOBAL_ASM("asm/nonmatchings/dlls/engine/29_gplay/gplay_func_198.s")
9198
#else
9299
void gplay_func_198(s8 param1, u8 *param2) {

src/dlls/engine/31_flash/flash.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ static s32 osFlashReadArray(OSIoMesg *mb, s32 priority, u32 page_num, void *dram
9999
}
100100

101101
#if 1
102+
s16 flash_save_game(FlashStruct *param1, u8 param2, s32 param3, s32 param4);
102103
#pragma GLOBAL_ASM("asm/nonmatchings/dlls/engine/31_flash/flash_save_game.s")
103104
#else
104-
/*export*/ s16 _flash_save_game(FlashStruct *param1, u8 param2, s32 param3, s32 param4) {
105+
/*export*/ s16 flash_save_game(FlashStruct *param1, u8 param2, s32 param3, s32 param4) {
105106
u32 *buf;
106107
s16 i;
107108
s16 page;

src/dlls/engine/31_flash/syms.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ flash_load_game = 0x6C;
44
flash_save_game = 0x224;
55
flash_compute_checksum = 0x404;
66
osFlashInit = 0x4DC;
7-
flash_compute_checksum_func_638 = 0x638;
7+
flash_func_638 = 0x638;
88
osFlashReadStatus = 0x640;
99
osFlashReadId = 0x70C;
1010
osFlashClearStatus = 0x820;

src/dlls/objects/223_cannon_claw/cannon_claw.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include <PR/ultratypes.h>
22

3-
#include "common.h"
3+
#include "game/actor/actor.h"
4+
#include "variables.h"
5+
#include "functions.h"
46

57
static void cannon_claw_func_1B4(TActor *a0);
68

src/dlls/objects/365/365.c

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
#include <PR/ultratypes.h>
22

3-
#include "common.h"
4-
5-
typedef struct
6-
{
7-
u8 mPad[0x62];
8-
s8 m0062;
9-
} TStruct365Func0006;
3+
#include "game/actor/actor.h"
4+
#include "variables.h"
5+
#include "functions.h"
6+
#include "dlls/objects/365.h"
107

118
static s32 func_0007(TActor *arg0, TActor *arg1, TStruct365Func0006 *arg2, s32 arg3);
129

src/dlls/objects/365/syms.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
func_0007 = 0xe4;

tools/gen_recomp_syms.py

+29-16
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import argparse
22
import shutil
3+
from subprocess import check_output
34
from elftools.elf.elffile import ELFFile
45
from elftools.elf.sections import SymbolTableSection
56
from typing import TextIO
67
import math
78
import os
89
from pathlib import Path
9-
from pycparser import c_ast, parse_file, c_generator
10+
from pycparser import c_ast, c_generator, CParser
1011

1112
from dino.dll import DLL
1213
from dino.dll_analysis import get_all_dll_functions
@@ -27,7 +28,7 @@
2728

2829
# 0x8001B4F0-0x8001C8D4 is handwritten assembly that trips up recomp, split it into a bunch of
2930
# functions that don't technically exist to get recomp working. This will basically make problematic
30-
# conditional branches turn into condotional tail calls into these fake functions
31+
# conditional branches turn into conditional tail calls into these fake functions
3132
# Note: Some of the fake functions must overlap fake functions below them
3233
0x8001B4F0: { "name": "func_8001B4F0", "size": 0x200 },
3334
0x8001B6F0: { "name": "func_8001B6F0", "size": 0x510 },
@@ -152,21 +153,26 @@ def gen_core_syms(syms_toml: TextIO, datasyms_toml: TextIO):
152153

153154
datasyms_toml.write("]\n")
154155

155-
PYCPARSER_CPP_ARGS = [
156-
'-D_LANGUAGE_C',
157-
'-D_MIPS_SZLONG=32',
158-
'-DF3DEX_GBI_2',
159-
'-Iinclude'
156+
GCC_PREPROCESS_CMD = [
157+
"gcc",
158+
"-nostdinc",
159+
"-E",
160+
"-D_LANGUAGE_C",
161+
"-D_MIPS_SZLONG=32",
162+
"-DF3DEX_GBI_2",
163+
"-Iinclude"
160164
]
161165

166+
c_gen = c_generator.CGenerator()
167+
c_parser = CParser()
168+
162169
def gen_dll_recomp_header(header: TextIO,
163170
c_source_paths: list[Path],
164171
symbol_renames: "dict[str, str]"):
165172
# Parse C source
166173
includes: list[str] = []
167174
declarations: list[tuple[str, str]] = []
168-
169-
c_gen = c_generator.CGenerator()
175+
found_symbols: "set[str]" = set()
170176

171177
for c_source_path in c_source_paths:
172178
# Get includes
@@ -177,17 +183,19 @@ def gen_dll_recomp_header(header: TextIO,
177183
includes.append(line[line.index(" ") + 1:])
178184

179185
# Get declarations
180-
ast: c_ast.FileAST = parse_file(str(c_source_path), use_cpp=True,
181-
cpp_args=PYCPARSER_CPP_ARGS)
186+
preprocessed_text = check_output(GCC_PREPROCESS_CMD + [str(c_source_path)], universal_newlines=True)
187+
ast: c_ast.FileAST = c_parser.parse(preprocessed_text)
182188

183189
for child in ast:
184190
if isinstance(child, c_ast.Decl):
185191
original = child.name
192+
if original in found_symbols:
193+
continue
186194
rename = symbol_renames.get(original)
187195
if rename != None:
188196
# Turn data decl into an extern
189197
type = child.type
190-
if isinstance(type, c_ast.ArrayDecl) or isinstance(type, c_ast.PtrDecl):
198+
if isinstance(type, c_ast.ArrayDecl) or isinstance(type, c_ast.PtrDecl) or isinstance(type, c_ast.FuncDecl):
191199
type = type.type
192200
if not isinstance(type, c_ast.TypeDecl):
193201
continue
@@ -201,8 +209,11 @@ def gen_dll_recomp_header(header: TextIO,
201209
alias = "#define {} {}".format(original, rename)
202210

203211
declarations.append((decl, alias))
212+
found_symbols.add(original)
204213
elif isinstance(child, c_ast.FuncDef):
205214
original = child.decl.name
215+
if original in found_symbols:
216+
continue
206217
rename = symbol_renames.get(original)
207218
if rename != None:
208219
# Turn func def into an extern decl
@@ -217,6 +228,7 @@ def gen_dll_recomp_header(header: TextIO,
217228
alias = "#define {} {}".format(original, rename)
218229

219230
declarations.append((decl, alias))
231+
found_symbols.add(original)
220232

221233
# Write
222234
header.write("#ifndef _DLL_29_INTERNAL_H\n")
@@ -249,11 +261,13 @@ def scan_dll_elf(
249261
st_info_type = sym.entry["st_info"]["type"]
250262
st_info_bind = sym.entry["st_info"]["bind"]
251263

252-
if st_info_type != "STT_FUNC" and st_info_type != "STT_OBJECT":
264+
maybe_unref_static_func = st_info_type == "STT_NOTYPE" and st_shndx == "SHN_ABS"
265+
266+
if st_info_type != "STT_FUNC" and st_info_type != "STT_OBJECT" and not maybe_unref_static_func:
253267
continue
254268
if st_shndx == "SHN_UNDEF":
255269
continue
256-
if st_info_bind != "STB_LOCAL" and size == 0:
270+
if st_info_bind != "STB_LOCAL" and size == 0 and not maybe_unref_static_func:
257271
continue
258272
if value & 0x80000000:
259273
# External symbol reference, already covered by core syms
@@ -276,9 +290,8 @@ def scan_dll_elf(
276290

277291
vram = dll_vram + sec_offset + value
278292

279-
if st_info_type == "STT_FUNC":
293+
if st_info_type == "STT_FUNC" or maybe_unref_static_func:
280294
# Function
281-
282295
func_info = vrams_to_funcs.get(vram)
283296
if func_info == None:
284297
print("Failed to find DLL {} func {} at {:0X} ({:0X})"

0 commit comments

Comments
 (0)