Summary
The gaame uses a GPhaseSystem
to split the logic into game sections. It is located under the gphase.cpp file. Please take not that all the following information is pulled from the EU version. The EU version has a few more states than the US/JP versions:
- A language selection upon first boot
- A screen refresh rate selector
- A boot video of Ubisoft's logo
Basic Components
Game Phases
In Fatal Frame 2, a Game Phase (GPhase)
represents the current action (phase) the game is currently performing. Each phase serves to handle a particular part of the game such as loading the game, menu traversal, selecting a lanaguage, and so on... A GPhase
is represented by a GPHASE_ID_ENUM
, an enum that contains all possible game phases (see list below). Those phases also have handler functions that will contain all code to perform the action!
List Of GPhases
Layers
In Fatal Frame 2, a layer (GPHASE_LAYER
) represents the game's current phase in a category. Those layers regroup a collection of GPHASE_ID_ENUM
(see Game Phases) that are related to a common section of the game. For example, some phases are related to the initialization of the game which are under the layer GAME_INIT
. Take note that the game does not use any enum definitions for those but simply int
. As such, I extracted this information based on my knowledge of the game. This might change later as I get a better understanding of the code.
The 6 Layers
States
A GPhase state (or GPHASE_ENUM
) indicates the state of the game for the current frame and is usually the value returned by GPhase state handling functions (see the following section).
List Of GPhase Status
Handler Functions
Each GPHASE
has 4 handler methods: ini_func
, pre_func
, after_func
and end_func
. The order of execution goes as follows:
ini
-> handles initialization of variables/memory allocationpre
-> handles logic before calling son- If this phase has a son -> go to step 1 for son; Otherwise continue to next step
after
-> handles logic after calling sonend
-> handles freeing allocated memory and resetting values
ini_func
and pre_func
have no arguments while after_func
and end_func
take a GPHASE_ID
as an argument and return a value of GPHASE_ENUM
. Only the pre
handler can have a nullptr
as a method. However, since this repo will not have all reversed code at the same time additionnal checks for nullptr
have been added to other handler calls.
When implementing a new GPHASE
, make sure to add your functions to the array of the appropriate xx_func
and ABSOLUTELY make sure that the function's position/index in the array is the same as the GPHASE_ID
.
Sample Of Ini, End, Pre, And After Functions
Take note that the SUPER GPHASE (GID_SUPER)
is at position 0/ is the first element just like its enum.
Structured GPhase Data
Structure Definitions
GPHASE_DAT
The GPHASE_DAT
structure contains all information related to a game phase. The layer indicates to which layer a game phase belongs to. superID
indicates the parent of that phase. son_ID
indicates the child of a game phase and son_num
indicates how many children a game phase has.
Definition Of GPHASE_DAT
GPHASE_SYS
GPHASE_SYS
is a structure that stores the current phase of the game, the next one and some execution flag. At this moment I do not know more than that.