mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-09-22 23:18:01 +03:00
Ensure _ModuleInit runs after VM reset
Fixes crash after game over in MangaGamer version of Sengoku Rance.
This commit is contained in:
+1
-1
@@ -104,9 +104,9 @@ void vm_call(int fno, int struct_page);
|
||||
int vm_time(void);
|
||||
|
||||
void hll_call(int libno, int fno);
|
||||
void link_libraries(void);
|
||||
bool library_exists(int libno);
|
||||
bool library_function_exists(int libno, int fno);
|
||||
void init_libraries(void);
|
||||
void exit_libraries(void);
|
||||
|
||||
void vm_stack_trace(void);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "vm.h"
|
||||
#include "vm/heap.h"
|
||||
#include "vm/page.h"
|
||||
#include "xsystem4.h"
|
||||
|
||||
#define HLL_MAX_ARGS 64
|
||||
|
||||
@@ -57,6 +58,7 @@ bool library_function_exists(int libno, int fno)
|
||||
static void trace_hll_call(struct ain_library *lib, struct ain_hll_function *f,
|
||||
struct hll_function *fun, union vm_value *r, void *_args)
|
||||
{
|
||||
/*
|
||||
// list of traced libraries
|
||||
if (!strcmp(lib->name, "StoatSpriteEngine") || !strcmp(lib->name, "ChipmunkSpriteEngine")) {
|
||||
// list of excluded functions
|
||||
@@ -86,16 +88,22 @@ static void trace_hll_call(struct ain_library *lib, struct ain_hll_function *f,
|
||||
}
|
||||
//else if (!strcmp(lib->name, "DrawGraph"));
|
||||
else if (!strcmp(lib->name, "SACT2")) {
|
||||
if (strncmp(f->name, "SP_", 3)) goto notrace;
|
||||
if (!strcmp(f->name, "Key_IsDown")) goto notrace;
|
||||
if (!strcmp(f->name, "Mouse_GetPos")) goto notrace;
|
||||
if (!strcmp(f->name, "SP_ExistAlpha")) goto notrace;
|
||||
if (!strcmp(f->name, "SP_IsPtInRect")) goto notrace;
|
||||
if (!strcmp(f->name, "SP_IsPtIn")) goto notrace;
|
||||
if (!strcmp(f->name, "SP_IsUsing")) goto notrace;
|
||||
if (!strcmp(f->name, "SP_SetShow")) goto notrace;
|
||||
if (!strcmp(f->name, "SP_SetPos")) goto notrace;
|
||||
if (!strcmp(f->name, "Timer_Get")) goto notrace;
|
||||
if (!strcmp(f->name, "Update")) goto notrace;
|
||||
}
|
||||
else if (!strcmp(lib->name, "SengokuRanceFont"));
|
||||
else*/ if (!strcmp(lib->name, "SengokuRanceFont")) {
|
||||
if (!strcmp(f->name, "SP_SetReduceDescender")) goto notrace;
|
||||
if (!strcmp(f->name, "SP_ClearState")) goto notrace;
|
||||
}
|
||||
else goto notrace;
|
||||
|
||||
sys_message("(%s) ", display_sjis0(ain->functions[call_stack[call_stack_ptr-1].fno].name));
|
||||
@@ -457,16 +465,32 @@ static struct hll_function *link_static_library(struct ain_library *ainlib, stru
|
||||
ERROR("Too many arguments to library function: %s", ainlib->functions[i].name);
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
static void library_run(struct static_library *lib, const char *name)
|
||||
{
|
||||
for (int i = 0; lib->functions[i].name; i++) {
|
||||
if (!strcmp(lib->functions[i].name, "_ModuleInit")) {
|
||||
if (!strcmp(lib->functions[i].name, name)) {
|
||||
((void(*)(void))lib->functions[i].fun)();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
void link_libraries(void)
|
||||
static void library_run_all(const char *name)
|
||||
{
|
||||
for (int i = 0; i < ain->nr_libraries; i++) {
|
||||
for (int j = 0; static_libraries[j]; j++) {
|
||||
if (!strcmp(ain->libraries[i].name, static_libraries[j]->name)) {
|
||||
library_run(static_libraries[j], name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void link_libraries(void)
|
||||
{
|
||||
if (libraries)
|
||||
return;
|
||||
@@ -485,24 +509,13 @@ void link_libraries(void)
|
||||
}
|
||||
}
|
||||
|
||||
void library_fini(struct static_library *lib)
|
||||
void init_libraries(void)
|
||||
{
|
||||
for (int i = 0; lib->functions[i].name; i++) {
|
||||
if (!strcmp(lib->functions[i].name, "_ModuleFini")) {
|
||||
((void(*)(void))lib->functions[i].fun)();
|
||||
break;
|
||||
}
|
||||
}
|
||||
link_libraries();
|
||||
library_run_all("_ModuleInit");
|
||||
}
|
||||
|
||||
void exit_libraries(void)
|
||||
{
|
||||
for (int i = 0; i < ain->nr_libraries; i++) {
|
||||
for (int j = 0; static_libraries[j]; j++) {
|
||||
if (!strcmp(ain->libraries[i].name, static_libraries[j]->name)) {
|
||||
library_fini(static_libraries[j]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
library_run_all("_ModuleFini");
|
||||
}
|
||||
|
||||
+33
-12
@@ -24,6 +24,7 @@
|
||||
#include "system4/fnl.h"
|
||||
#include "system4/hashtable.h"
|
||||
#include "system4/string.h"
|
||||
#include "system4/utfsjis.h"
|
||||
|
||||
#include "gfx/gfx.h"
|
||||
#include "vm/page.h"
|
||||
@@ -37,6 +38,7 @@ struct sr_text_properties {
|
||||
float home_x;
|
||||
int home_y;
|
||||
int line_space;
|
||||
int last_char;
|
||||
struct text_style ts;
|
||||
};
|
||||
|
||||
@@ -46,6 +48,7 @@ static struct sr_text_properties default_text_properties = {
|
||||
.home_x = 0.0,
|
||||
.home_y = 0,
|
||||
.line_space = 0,
|
||||
.last_char = -1,
|
||||
.ts = {
|
||||
.font_type = 0,
|
||||
.size = 16.0,
|
||||
@@ -318,16 +321,23 @@ static void SengokuRanceFont_SP_SetTextStyle(int sp_no, struct page *page)
|
||||
ts->font_size = NULL;
|
||||
}
|
||||
|
||||
static float sp_text_draw(struct sact_sprite *sp, struct text_style *ts, struct string *text, float x, int y)
|
||||
static float sp_text_draw(struct sact_sprite *sp, struct sr_text_properties *tp, struct string *text, float x, int y)
|
||||
{
|
||||
if (ts->size < 8) {
|
||||
ts->size = 8;
|
||||
if (tp->ts.size < 8) {
|
||||
tp->ts.size = 8;
|
||||
}
|
||||
|
||||
struct texture *tex = sprite_get_texture(sp);
|
||||
|
||||
// save last char code
|
||||
int last_char = -1;
|
||||
for (char *p = text->text; *p; p = sjis_skip_char(p)) {
|
||||
last_char = sjis_code(p);
|
||||
}
|
||||
tp->last_char = last_char;
|
||||
|
||||
sprite_dirty(sp);
|
||||
return x + fnl_draw_text(ts, tex, x, y, text->text);
|
||||
return x + fnl_draw_text(&tp->ts, tex, x, y, text->text);
|
||||
}
|
||||
|
||||
static void SengokuRanceFont_SP_TextDraw(int sp_no, struct string *text)
|
||||
@@ -339,7 +349,7 @@ static void SengokuRanceFont_SP_TextDraw(int sp_no, struct string *text)
|
||||
}
|
||||
|
||||
struct sr_text_properties *p = get_sp_properties(sp_no);
|
||||
p->x += sp_text_draw(sp, &p->ts, text, p->x, p->y);
|
||||
p->x += sp_text_draw(sp, p, text, p->x, p->y);
|
||||
}
|
||||
|
||||
// As far as I can tell, this just renders the text slightly higher than
|
||||
@@ -355,7 +365,7 @@ static void SengokuRanceFont_SP_TextDrawClassic(int sp_no, struct string *text)
|
||||
struct sr_text_properties *p = get_sp_properties(sp_no);
|
||||
//int y = p->y - p->ts.size * 0.1875;
|
||||
int y = p->y;
|
||||
p->x += sp_text_draw(sp, &p->ts, text, p->x, y);
|
||||
p->x += sp_text_draw(sp, p, text, p->x, y);
|
||||
}
|
||||
|
||||
HLL_WARN_UNIMPLEMENTED( , void, SengokuRanceFont, SP_TextDrawPreload, int sp_no, struct string *text);
|
||||
@@ -460,9 +470,20 @@ static float SengokuRanceFont_GetActualFontSizeRoundDown(int font_type, float fo
|
||||
return fnl_get_actual_font_size_round_down(font_type, font_size);
|
||||
}
|
||||
|
||||
//static int SengokuRanceFont_SP_GetTextLastCharCode(int spriteNumber);
|
||||
//static void SengokuRanceFont_SP_SetTextLastCharCode(int spriteNumber, int lastChar);
|
||||
//static int SengokuRanceFont_SP_GetReduceDescender(int spriteNumber);
|
||||
static int SengokuRanceFont_SP_GetTextLastCharCode(int sp_no)
|
||||
{
|
||||
return get_sp_properties(sp_no)->last_char;
|
||||
}
|
||||
|
||||
static void SengokuRanceFont_SP_SetTextLastCharCode(int sp_no, int last_char)
|
||||
{
|
||||
get_sp_properties(sp_no)->last_char = last_char;
|
||||
}
|
||||
|
||||
static int SengokuRanceFont_SP_GetReduceDescender(int sp_no)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void SengokuRanceFont_SP_SetReduceDescender(int sp_no, int reduce_descender)
|
||||
{
|
||||
@@ -564,8 +585,8 @@ HLL_LIBRARY(SengokuRanceFont,
|
||||
HLL_EXPORT(SP_GetSpaceScaleX, SengokuRanceFont_SP_GetSpaceScaleX),
|
||||
HLL_EXPORT(GetActualFontSize, SengokuRanceFont_GetActualFontSize),
|
||||
HLL_EXPORT(GetActualFontSizeRoundDown, SengokuRanceFont_GetActualFontSizeRoundDown),
|
||||
//HLL_EXPORT(SP_GetTextLastCharCode, SengokuRanceFont_SP_GetTextLastCharCode),
|
||||
//HLL_EXPORT(SP_SetTextLastCharCode, SengokuRanceFont_SP_SetTextLastCharCode),
|
||||
//HLL_EXPORT(SP_GetReduceDescender, SengokuRanceFont_SP_GetReduceDescender),
|
||||
HLL_EXPORT(SP_GetTextLastCharCode, SengokuRanceFont_SP_GetTextLastCharCode),
|
||||
HLL_EXPORT(SP_SetTextLastCharCode, SengokuRanceFont_SP_SetTextLastCharCode),
|
||||
HLL_EXPORT(SP_GetReduceDescender, SengokuRanceFont_SP_GetReduceDescender),
|
||||
HLL_EXPORT(SP_SetReduceDescender, SengokuRanceFont_SP_SetReduceDescender)
|
||||
);
|
||||
|
||||
+1
-1
@@ -284,7 +284,7 @@ static void config_init_with_ain(const char *ain_path)
|
||||
|
||||
static void ain_audit(FILE *f, struct ain *ain)
|
||||
{
|
||||
link_libraries();
|
||||
init_libraries();
|
||||
|
||||
for (size_t addr = 0; addr < ain->code_size;) {
|
||||
uint16_t opcode = LittleEndian_getW(ain->code, addr);
|
||||
|
||||
Reference in New Issue
Block a user