resonance 1.0.1
Loading...
Searching...
No Matches
PyShell Class Reference

Host of the embedded Python interpreter, and the one object the game runs script through. More...

#include <pyshell.h>

Collaboration diagram for PyShell:

Public Member Functions

 PyShell ()
 Bring the interpreter up and prepare the script environment.
 ~PyShell ()
 Release the namespace dictionary, and then shut the interpreter down through the interpreter member.
Py::Object Eval (const HxStr &source, int nStartSymbol)
 Compile and run script text in the shared namespace.
void RunMasterInitScript ()
 Run the master script.
void ReportError (const HxStr &context, int bWithTraceback)
 Report a script failure and halt the machine.

Public Attributes

Py::Dict mDict
 Namespace every script runs in, which is the dictionary of __main__.

Detailed Description

Host of the embedded Python interpreter, and the one object the game runs script through.

The title comes from the diagnostic the constructor reports when start-up throws, while initializing PyShell. The class is not polymorphic, has no RTTI descriptor, and has no embedded __FILE__, so the title is an inference from that one string rather than a recovered identifier.

The object is twelve bytes, and GetPythonScriptHost() at 0x0050d588 reserves exactly that much for the single instance. The four bytes at +0x00 are the interpreter's lifetime, a member with no data. No routine reads or writes them, and the member's constructor and destructor bracket the dictionary at +0x04.

Constructor & Destructor Documentation

◆ PyShell()

PyShell::PyShell ( )

Bring the interpreter up and prepare the script environment.

The sequence is fixed. Py_NoSiteFlag is set, the interpreter starts, the namespace of __main__ becomes the dictionary below, import sys runs, two sys.path.append calls add gscripts and gscripts/hx under the prefix GetFreqRoot() supplies, and the game's own hx extension module registers last.

A Py::Exception thrown anywhere after the dictionary exists is caught and reported through ReportError() with the context while initializing PyShell, so a script failure at start-up halts the machine with a message rather than propagating.

Ghidra address:
NTSC-U/C: 0x005072e8
Ghidra address:
PAL: 0x005461e8

◆ ~PyShell()

PyShell::~PyShell ( )

Release the namespace dictionary, and then shut the interpreter down through the interpreter member.

Ghidra address:
NTSC-U/C: 0x0050d480
Ghidra address:
PAL: 0x0054c938

Member Function Documentation

◆ Eval()

Py::Object PyShell::Eval ( const HxStr & source,
int nStartSymbol )

Compile and run script text in the shared namespace.

Globals and locals are the same dictionary. A null result is reported through ReportError() with the source as the context, which halts the machine, so the returned handle is only ever reached on success.

Parameters
sourceThe text to run.
nStartSymbolThe grammar start symbol, Py_file_input for a statement and Py_eval_input for an expression.
Returns
A handle on the result.
Ghidra address:
NTSC-U/C: 0x00508ca8
Ghidra address:
PAL: 0x00547e08

◆ RunMasterInitScript()

void PyShell::RunMasterInitScript ( )

Run the master script.

The path is Global/GrvScript.py under the prefix GetFreqRoot() supplies. The file is opened with fopen in mode r and handed straight to PyRun_File(), so a script is read through the game's own file layer rather than through any interpreter hook. The shipped script imports os, os.path, and hx, calls hx.get_freq_root(), and runs global/defaults.py.

Ghidra address:
NTSC-U/C: 0x00508de8
Ghidra address:
PAL: 0x00547f48

◆ ReportError()

void PyShell::ReportError ( const HxStr & context,
int bWithTraceback )

Report a script failure and halt the machine.

The Python error indicator is drained into a message, the message is decorated with the context, and the machine stops. The routine never returns to its caller, because Fatal() does not return.

The receiver is unused. The routine reads only its two arguments, and it is a member rather than a free function because the call sites pass the receiver.

Parameters
contextText describing what was being attempted.
bWithTracebackNon-zero to format the traceback through hxutl.traceback_str, which also consumes the context. Zero appends the context directly instead.
Ghidra address:
NTSC-U/C: 0x00507f58
Ghidra address:
PAL: 0x00547018

Member Data Documentation

◆ mDict

Py::Dict PyShell::mDict

Namespace every script runs in, which is the dictionary of __main__.

Public because the free functions of the script layer read it directly off the singleton and the image has no accessor for it. 0x0050a868 is one such reader.

+0x04


The documentation for this class was generated from the following file: