Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Decompilation] [th04/th05] Dialog: Script loading functions
Part of P0186, funded by [Anonymous] and Blue Bolt.
- Loading branch information
Showing
9 changed files
with
135 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "th04/formats/dialog.cpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#pragma option -zCmain_TEXT | ||
|
||
#include <stddef.h> | ||
#include "platform.h" | ||
#include "master.hpp" | ||
#include "th04/score.h" | ||
#include "th04/resident.hpp" | ||
#include "th04/formats/dialog.hpp" | ||
|
||
void pascal near dialog_load(const char *fn) | ||
{ | ||
size_t size; | ||
|
||
// While hmem_free() isn't specified to perform a NULL check, it does in | ||
// practice. So while this is *technically* fine, it's not the cleanest | ||
// solution. Fixed in TH05. | ||
hmem_free(reinterpret_cast<void __seg *>(dialog_p)); | ||
|
||
file_ropen(fn); | ||
size = file_size(); | ||
dialog_p = reinterpret_cast<unsigned char far *>(hmem_allocbyte(size)); | ||
file_read(dialog_p, size); | ||
file_close(); | ||
} | ||
|
||
void near dialog_load(void) | ||
{ | ||
#define fn dialog_fn | ||
extern char *fn; | ||
dialog_fn[3] = resident->playchar_ascii; | ||
dialog_fn[4] = resident->stage_ascii; | ||
dialog_load(dialog_fn); | ||
#undef fn | ||
} | ||
|
||
void dialog_load_yuuka5_defeat_bad(void) | ||
{ | ||
#define fn dialog_fn_yuuka5_defeat_bad | ||
extern char *fn; | ||
fn[3] = resident->playchar_ascii; | ||
dialog_load(fn); | ||
#undef fn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
// Script buffer pointer | ||
extern unsigned char far *dialog_p; | ||
|
||
// Loads a dialog script from the file with the given name. `near` in this | ||
// game, as it's only used internally. | ||
void pascal near dialog_load(const char *fn); | ||
|
||
// Loads the dialog script after defeating Stage 5 Yuuka with continues or on | ||
// Easy mode, shown before the Bad Ending. | ||
void dialog_load_yuuka5_defeat_bad(void); | ||
|
||
// Loads the dialog script for the current player character and stage. | ||
void near dialog_load(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "th05/formats/dialog.cpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma option -zCmain_TEXT | ||
|
||
#include <stddef.h> | ||
#include "platform.h" | ||
#include "master.hpp" | ||
#include "th04/common.h" | ||
#include "th04/score.h" | ||
#include "th04/main/stage/stage.hpp" | ||
#include "th05/playchar.h" | ||
#include "th05/resident.hpp" | ||
#include "th05/formats/dialog.hpp" | ||
|
||
void pascal dialog_load(const char *fn) | ||
{ | ||
size_t size; | ||
tx2_header_t header; | ||
|
||
if(dialog_p) { | ||
hmem_free(reinterpret_cast<void __seg *>(dialog_p)); | ||
} | ||
file_ropen(fn); | ||
file_read(&header, sizeof(header)); | ||
|
||
// A sanity check here would have been particularly helpful for | ||
// translators, who tend to start out by just blindly editing a .TX2 file. | ||
size = (header.offset_for[playchar + 1] - header.offset_for[playchar]); | ||
|
||
dialog_p = reinterpret_cast<unsigned char far *>(hmem_allocbyte(size)); | ||
file_seek(header.offset_for[playchar], SEEK_SET); | ||
file_read(dialog_p, size); | ||
file_close(); | ||
} | ||
|
||
void near dialog_load(void) | ||
{ | ||
#define fn dialog_fn | ||
extern char *fn; | ||
fn[4] = ('0' + stage_id); | ||
dialog_load(fn); | ||
#undef fn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,26 @@ | ||
/// TH05 in-game dialog script format | ||
/// --------------------------------- | ||
|
||
struct tx2_header_t { | ||
// The dialog script for player character N is stored between | ||
// `offset_for[N]` and `offset_for[N + 1]`. | ||
uint16_t offset_for[PLAYCHAR_COUNT + 1]; | ||
}; | ||
|
||
const uint8_t FACE_NONE = 0xFF; | ||
|
||
// Script buffer pointer | ||
extern unsigned char far *dialog_p; | ||
|
||
// Loading and freeing | ||
// ------------------- | ||
|
||
// Loads the dialog script for the current player character from the .TX2 file | ||
// with the given name. `far` in this game, as it's also called from outside | ||
// its segment. | ||
void pascal dialog_load(const char *fn); | ||
|
||
// Loads the dialog script for the current player character and stage. | ||
void near dialog_load(void); | ||
// ------------------- | ||
/// --------------------------------- |
Oops, something went wrong.