This script analyzes the assembly instructions from one frame of your game and outputs a text file with every function call the script could find. Symbols are automatically applied to the output in order to make it easier to understand the code flow of your game.

# Getting the assembly trace from your game
* Start `PCSX-Redux` with logging enabled by passing the following command line flags: `-logfile log.txt`
* Start up your game and insert a breakpoint in the first instruction of the game loop in the frame you want to analyze. Unpause the game and wait for the breakpoint to hit.
* In the drop-down menu select `Debug -> CPU -> Show Assembly`, and enable `CPU Trace`. Click on the `Resume` button.
* Once the breakpoint hits again, disable `CPU Trace` and close the emulator (`File -> Quit`).
* A log file `log.txt` should be created in the emulator directory, copy it into this `codeflow` folder.

# Getting the symbols from your Ghidra project
Open your Ghidra project, and in the drop-down menu select `Window -> Python`. Copy/paste the code from `ghidra.py` into the python interpreter. A file named `ghidra_functions.txt` will be created inside your `Ghidra` directory, simply move the created file into this `codeflow` folder.

# Running
Open the terminal and call `python main.py`. The script will look for the `ghidra_functions.txt` and `log.txt` from the current directory and create an `output.txt` file.

# Parent Call Analyzer
Once the log file has been analyzed, you can explore the call stack of a function by calling `find_parent_call.py [symbol]`, where `symbol` is the function you want to analyze its call stack. The program will print each different parent call up to the first different function it finds when comparing each call stack from the root to the top.

Example from the log.txt of this repository:

`python find_parent_call.py FUN_80019a60` outputs:
```
FUN_8007a718 -> FUN_8001c298 -> FUN_8001c2c0 -> FUN_80019f1c -> FUN_80019a60

FUN_8001daf8 -> FUN_8001dd50 -> FUN_80019a60

FUN_800798a4 -> FUN_8001c298 -> FUN_8001c2c0 -> FUN_80019f1c -> FUN_80019a60
```
Note that this isn't the entirity of the call stack generated by `FUN_80019a60`; however, the beginning of each call stack is always the same, so the program removes the repetitive code in order to have a cleaner output. For instance, this would be the full code path of each different call stack:
```
main -> FUN_80010278 -> FUN_80092b7c -> FUN_8001e898 -> FUN_80092e94 -> FUN_80093038 -> FUN_8007a718 -> FUN_8001c298 -> FUN_8001c2c0 -> FUN_80019f1c -> FUN_80019a60

main -> FUN_80010278 -> FUN_80092b7c -> FUN_8001e898 -> FUN_80092e94 -> FUN_80093038 -> FUN_8001daf8 -> FUN_8001dd50 -> FUN_80019a60

main -> FUN_80010278 -> FUN_80092b7c -> FUN_8001e898 -> FUN_80092e94 -> FUN_80093038 -> FUN_800798a4 -> FUN_8001c298 -> FUN_8001c2c0 -> FUN_80019f1c -> FUN_80019a60
```