Skip to content

Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.

Hollow Knight: the Snail Shaman and Vengeful Spirit taken

Mason Chen34b453c445b0
diff --git a/games/hollowknight/Makefile b/games/hollowknight/Makefile
index 55902f63..61b807c9 100644
--- a/games/hollowknight/Makefile
+++ b/games/hollowknight/Makefile
@@ -9,7 +9,7 @@ CC = arm-none-eabi-gcc
NWLINK ?= npx --yes -- [email protected]
STRIP ?= arm-none-eabi-strip --strip-unneeded
BUILD_DIR = output
-GAME = src/res.c src/tex.c src/room.c src/gfx.c src/phys.c src/anim.c src/hero.c src/camera.c src/game.c src/world.c src/obj.c src/enemy.c src/hud.c src/spell.c src/text.c src/npc.c src/title.c src/vm.c src/save.c src/death.c src/lzma/LzmaDec.c
+GAME = src/res.c src/tex.c src/room.c src/gfx.c src/phys.c src/anim.c src/hero.c src/camera.c src/game.c src/world.c src/obj.c src/enemy.c src/hud.c src/spell.c src/text.c src/npc.c src/title.c src/vm.c src/msg.c src/save.c src/death.c src/lzma/LzmaDec.c
SRC = $(GAME) src/plat_eadk.c src/main.c
HEADERS = $(wildcard src/*.h) ../common/epsilon_app.h ../common/epsilon_files.h
diff --git a/games/hollowknight/src/data.bin b/games/hollowknight/src/data.bin
index ba0278d0..3c807e3d 100644
Binary files a/games/hollowknight/src/data.bin and b/games/hollowknight/src/data.bin differ
diff --git a/games/hollowknight/src/data.h b/games/hollowknight/src/data.h
index 54c875cd..a3ccfc25 100644
--- a/games/hollowknight/src/data.h
+++ b/games/hollowknight/src/data.h
@@ -421,12 +421,14 @@
#define SPRITE_CORPSE_NAIL 1499
#define SPRITE_FK_BARREL 1500
#define SPRITE_FK_STAFF 1501
-#define SPRITE_DIGIT0 1696
+#define SPRITE_DIGIT0 1700
#define STYLE_DIALOGUE 0
#define STYLE_PROMPT 1
#define STYLE_TITLE_L 2
#define STYLE_TITLE_S 3
#define STYLE_TITLE_SUB 4
+#define STYLE_MSG 5
+#define STYLE_MSG_NAME 6
#define TEXT_K 1.333333f
#define FONT_PHASES 4
#define EK_CRAWLER 1
@@ -546,8 +548,11 @@
#define VMOP_HUDBLANKER 77
#define VMOP_CREATEOBJECT 78
#define VMOP_GETITEMMSG 79
-#define VMOP_SETPARENT 80
-#define VMOP_INTOP 81
+#define VMOP_BLANKER 80
+#define VMOP_BLANKERON 81
+#define VMOP_FINDGAMEOBJECT 82
+#define VMOP_SETPARENT 83
+#define VMOP_INTOP 84
#define VMEV_FINISHED 0
#define VMEV_CONVO_FINISH 1
#define VMEV_CONVO_START 2
@@ -563,8 +568,8 @@
#define VMEV_TAKE_DAMAGE 12
#define VMEV_GET_ITEM_MSG_END 13
#define VMSTR_NPC_TITLE 14
-#define VMSTR_VISITED 131
-#define VMSTR_DISPLAY_RIGHT 132
+#define VMSTR_VISITED 127
+#define VMSTR_DISPLAY_RIGHT 128
#define TITLE_KINGSPASS 0
#define TITLE_DIRTMOUTH 1
#define TITLE_CROSSROADS 2
@@ -593,3 +598,10 @@
#define FLEUR_FPS 15.0f
#define SPRITE_FLEUR_BOT 1503
#define FLEUR_BOT_RECTS {{0.000f, 0.000f, 0.016f, 0.016f}, {0.000f, 0.000f, 0.016f, 0.016f}, {0.391f, 0.406f, 0.828f, 0.844f}, {-1.063f, 0.281f, 1.516f, 1.016f}, {-1.594f, -0.047f, 2.109f, 1.031f}, {-1.984f, -0.156f, 2.375f, 1.047f}, {-2.531f, -0.438f, 2.719f, 1.172f}, {-2.688f, -0.594f, 2.766f, 1.188f}, {-2.797f, -0.797f, 3.156f, 1.219f}, {-3.078f, -0.938f, 3.219f, 1.219f}, {-3.250f, -1.156f, 3.438f, 1.219f}, {-3.250f, -1.172f, 3.828f, 1.219f}, {-3.781f, -1.188f, 4.203f, 1.234f}, {-3.984f, -1.188f, 4.344f, 1.234f}, {-4.281f, -1.203f, 4.562f, 1.234f}, {-4.406f, -1.203f, 4.641f, 1.234f}, {-4.578f, -1.219f, 4.719f, 1.234f}, {-4.656f, -1.219f, 4.719f, 1.234f}, {-4.734f, -1.219f, 4.734f, 1.234f}, {-4.750f, -1.234f, 4.734f, 1.234f}, {-4.766f, -1.234f, 4.734f, 1.250f}, {-4.766f, -1.234f, 4.734f, 1.250f}}
+#define SPRITE_MSG_BG 1504
+#define SPRITE_MSG_STOP 1505
+#define SPRITE_MSG_FLEUR 1506
+#define SPRITE_MSG_KEY 1507
+#define SPRITE_MSG_ICON_FIREBALL 1508
+#define MSG_TABLE {{87, 88, 89, 90, 91, 92}}
+#define MSG_FIREBALL 0
diff --git a/games/hollowknight/src/game.c b/games/hollowknight/src/game.c
index aac293e0..d3e26eb0 100644
--- a/games/hollowknight/src/game.c
+++ b/games/hollowknight/src/game.c
@@ -305,6 +305,7 @@ static void step(uint32_t keys) {
world_tick();
benches_tick();
vm_tick();
+ msg_tick();
titles_tick();
prompts_tick();
dialogue_tick();
@@ -329,6 +330,7 @@ void game_tick(uint32_t keys) {
void game_draw(void) {
hud_draw();
+ msg_draw();
titles_draw();
dialogue_draw();
prompts_draw();
diff --git a/games/hollowknight/src/game.h b/games/hollowknight/src/game.h
index e1937d7c..2573b0ab 100644
--- a/games/hollowknight/src/game.h
+++ b/games/hollowknight/src/game.h
@@ -267,10 +267,17 @@ void titles_hero_in_position(void);
void titles_tick(void);
void titles_draw(void);
/* the game's own scripts (vm.c): a room's, run each step, their objects drawn; events heard by all of them */
+void hero_add_mp_charge(int amount); /* (AddMPCharge) */
void vm_enter(void);
void vm_tick(void);
void vm_draw(void);
void vm_broadcast(int ev);
+/* the message as an item is taken (msg.c: MSG_*), the HUD Blanker (a white screen the scripts fade) */
+void msg_show(int item);
+bool msg_shown(void);
+void msg_tick(void);
+void msg_draw(void);
+void blanker_set(float alpha, bool on);
bool bench_respawn(const char *name); /* RESPAWN: the Knight asleep on the bench so named */
/* the Spell Control FSM (spell.c): focus, spells */
diff --git a/games/hollowknight/src/gfx.c b/games/hollowknight/src/gfx.c
index 2d573fba..96f91f2e 100644
--- a/games/hollowknight/src/gfx.c
+++ b/games/hollowknight/src/gfx.c
@@ -1103,6 +1103,16 @@ void gfx_hud_clip(int clip, float x, float y, float r) {
hud_clips[clip - 1] = (HudClip){VIEW_W / 2 + x * k, VIEW_H / 2 - y * k, r * k, 0, 0, 0, 0, false};
}
+void gfx_hud_fill(float x0, float y0, float x1, float y1, uint8_t tint) {
+ /* (a solid color: its top left, its size) */
+ Inst in;
+ memset(&in, 0, sizeof in);
+ in.ax = (int16_t)lrintf(x0 * 64), in.ay = (int16_t)lrintf(y1 * 64);
+ in.tex = TEX_NONE, in.flags = F_SOLID, in.tint = tint;
+ in.a = to_f16(x1 - x0), in.b = to_f16(y0 - y1);
+ gfx_hud(&in, 0);
+}
+
void gfx_hud_rect(int clip, float x0, float y0, float x1, float y1) {
float k = FOCAL / (HUD_Z - CAM_Z);
hud_clips[clip - 1] = (HudClip){0, 0, 0, VIEW_W / 2 + x0 * k, VIEW_H / 2 - y1 * k, VIEW_W / 2 + x1 * k, VIEW_H / 2 - y0 * k, true};
diff --git a/games/hollowknight/src/hero.c b/games/hollowknight/src/hero.c
index 56081b3e..5e760a80 100644
--- a/games/hollowknight/src/hero.c
+++ b/games/hollowknight/src/hero.c
@@ -1405,6 +1405,7 @@ static void add_mp_charge(int amount) {
}
void hero_soul_gain(void) { add_mp_charge(g_pd.mp < g_pd.max_mp ? 11 : 6); }
+void hero_add_mp_charge(int amount) { add_mp_charge(amount); }
void hero_add_geo(int amount) { g_pd.geo += amount; }
diff --git a/games/hollowknight/src/hk.h b/games/hollowknight/src/hk.h
index 6e703d91..2b2f147d 100644
--- a/games/hollowknight/src/hk.h
+++ b/games/hollowknight/src/hk.h
@@ -204,6 +204,7 @@ bool gfx_actor(const Inst *in, uint32_t group);
* height), not graded nor faded with the room (tints from HUD_TINT); clip: 0, or 1 + a circle it is drawn in */
bool gfx_hud(const Inst *in, int clip);
void gfx_hud_rect(int clip, float x0, float y0, float x1, float y1); /* (a clip that is a box, HUD units) */
+void gfx_hud_fill(float x0, float y0, float x1, float y1, uint8_t tint); /* (a box of one color) */
void gfx_hud_clip(int clip, float x, float y, float r);
uint8_t gfx_dyn_tint(int slot, uint8_t r, uint8_t g, uint8_t b, uint8_t a); /* a tint (for Inst.tint) of that color */
/* the same, flashing: its colors towards (fr, fg, fb) by amount (SpriteFlash) */
diff --git a/games/hollowknight/src/msg.c b/games/hollowknight/src/msg.c
new file mode 100644
index 00000000..91589b82
--- /dev/null
+++ b/games/hollowknight/src/msg.c
@@ -0,0 +1,138 @@
+/* The message as the Knight takes an item (UI Msg Get Item: its Msg Control FSM): a dark backdrop, the item's icon and
+ * name fade up, then how to use it (Tap or Press, the key, two lines), then the stop marker; a key sends it away.
+ * Places in HUD units from the screen's center (its prefab, made at the origin, drawn by the HUD's camera). */
+#include <math.h>
+#include "game.h"
+
+#define DT 0.02f
+#define HUD_PX (FOCAL / (-1.342f - CAM_Z))
+
+static const int16_t table[][6] = MSG_TABLE; /* (name, prefix, Tap or Press, the two lines, the key's name) */
+static const int16_t icons[] = {SPRITE_MSG_ICON_FIREBALL};
+
+enum { MS_OFF, MS_TOP_UP, MS_BOT_UP, MS_STOP_UP, MS_DETECT, MS_DOWN };
+/* (color_fader: what fades together; each its delay going up) */
+enum { F_BG, F_ICON, F_NAME, F_PREFIX, F_PRESS, F_MSG1, F_MSG2, F_BUTTON, F_STOP, F_FLEUR, NF };
+static const float up_delay[NF] = {0, 0.5f, 0.5f, 0.5f, 0, 0, 0.5f, 0, 0, 0};
+
+static struct {
+ uint8_t st, item;
+ float t;
+ float a[NF]; /* each part's alpha */
+ float t_up[NF]; /* (its UP's time: -1 none) */
+ bool down;
+ uint32_t prev_keys;
+} m;
+
+void msg_show(int item) {
+ memset(&m, 0, sizeof m);
+ m.item = (uint8_t)item;
+ for (int i = 0; i < NF; i++) m.t_up[i] = -1;
+ /* Top Up: the backdrop, the icon, the name and its prefix (and the game saved) */
+ m.t_up[F_BG] = m.t_up[F_ICON] = m.t_up[F_NAME] = m.t_up[F_PREFIX] = 0;
+ save_game();
+ m.st = MS_TOP_UP, m.t = 0;
+ m.prev_keys = g_hero.keys;
+}
+
+bool msg_shown(void) { return m.st != MS_OFF; }
+
+void msg_tick(void) {
+ if (m.st == MS_OFF) return;
+ uint32_t pressed = g_hero.keys & ~m.prev_keys;
+ m.prev_keys = g_hero.keys;
+ m.t += DT;
+ for (int i = 0; i < NF; i++) {
+ if (m.down) {
+ /* DOWN: to nothing in 1 s (the stop marker 0.15 s) */
+ m.a[i] -= DT / (i == F_STOP ? 0.15f : 1);
+ if (m.a[i] < 0) m.a[i] = 0;
+ } else if (m.t_up[i] >= 0) {
+ m.t_up[i] += DT;
+ float k = (m.t_up[i] - up_delay[i]) / 1;
+ if (k > 0) m.a[i] = k > 1 ? 1 : k;
+ }
+ }
+ switch (m.st) {
+ case MS_TOP_UP:
+ if (m.t >= 2.5f) {
+ /* the fleur (all at once), Bot Up: how to use it */
+ m.a[F_FLEUR] = 1;
+ m.t_up[F_PRESS] = m.t_up[F_MSG1] = m.t_up[F_MSG2] = m.t_up[F_BUTTON] = 0;
+ m.st = MS_BOT_UP, m.t = 0;
+ }
+ break;
+ case MS_BOT_UP:
+ if (m.t >= 3) m.a[F_STOP] = 1, m.st = MS_STOP_UP, m.t = 0;
+ break;
+ case MS_STOP_UP:
+ if (m.t >= 0.25f) m.st = MS_DETECT;
+ break;
+ case MS_DETECT:
+ if (pressed & (K_SPELL | K_JUMP | K_ATTACK)) m.down = true, m.st = MS_DOWN, m.t = 0;
+ break;
+ case MS_DOWN:
+ if (m.t >= 1) {
+ m.st = MS_OFF;
+ vm_broadcast(VMEV_GET_ITEM_MSG_END);
+ }
+ break;
+ }
+}
+
+/* a text: its lines centered on x (align 0) or ending at x (1); the first's top or middle at y -> its width (pixels) */
+static float line(int text, int style, float x, float y, int align, bool top, float a) {
+ uint32_t al = (uint32_t)(a * 255 + 0.5f);
+ if (text < 0) return 0;
+ const uint8_t *s = text_get(text), *st = font_style(style);
+ float py = VIEW_H / 2 - y * HUD_PX + (top ? font_asc(st) : (font_asc(st) - font_desc(st)) / 2), wmax = 0;
+ for (int i = 0;;) {
+ int e = i;
+ while (s[e] && s[e] != TEXT_BR) e++;
+ float w = text_width(style, s + i, e - i);
+ if (w > wmax) wmax = w;
+ if (al) gfx_text(style, VIEW_W / 2 + x * HUD_PX - (align == 0 ? w / 2 : align == 1 ? w : 0), py, s + i, e - i, al << 24 | 0xFFFFFF, 0);
+ if (!s[e]) break;
+ i = e + 1, py += font_line(st);
+ }
+ return wmax;
+}
+
+static void sprite(int sprite, float x, float y, float a, int slot) {
+ uint8_t al = (uint8_t)(a * 255 + 0.5f);
+ if (!al) return;
+ Inst in;
+ sprite_inst(sprite, x, y, 0, 1, 1, gfx_dyn_tint(slot, 255, 255, 255, al), &in);
+ gfx_hud(&in, 0);
+}
+
+/* the HUD Blanker: black over the screen (under the message), its color's alpha as the scripts set it */
+static float blank_alpha;
+static bool blank_on;
+void blanker_set(float alpha, bool on) { blank_alpha = alpha, blank_on = on; }
+
+void msg_draw(void) {
+ if (blank_on && blank_alpha > 0)
+ gfx_hud_fill(-15, -9, 15, 9, gfx_dyn_tint(27, 0, 0, 0, (uint8_t)(blank_alpha * 255 + 0.5f)));
+ if (m.st == MS_OFF) return;
+ const int16_t *t = table[m.item];
+ /* (BG: black, at 0.766 of its color's alpha) */
+ sprite(SPRITE_MSG_BG, 0, 0, m.a[F_BG] * 0.766f, 22);
+ sprite(icons[m.item], 0, 4.73f, m.a[F_ICON], 23);
+ sprite(SPRITE_MSG_FLEUR, 0, -1.48f, m.a[F_FLEUR], 24);
+ sprite(SPRITE_MSG_STOP, 0, -6.84f, m.a[F_STOP], 26);
+ line(t[0], STYLE_MSG_NAME, 0, -0.23f, 0, false, m.a[F_NAME]);
+ line(t[1], STYLE_MSG, 0, 0.84f, 0, false, m.a[F_PREFIX]);
+ line(t[2], STYLE_MSG, -8.5f + 11.1377f * 1.4407f / 2, -2.93f, 1, false, m.a[F_PRESS]);
+ line(t[3], STYLE_MSG, 0, -4.64f + 1.0253f * 1.4407f / 2, 0, true, m.a[F_MSG1]);
+ line(t[4], STYLE_MSG, 0, -6.15f + 1.7591f * 1.4407f / 2, 0, true, m.a[F_MSG2]);
+ /* the key (the calculator's, by name: its key sprite as wide as the name) */
+ float w = line(t[5], STYLE_PROMPT, 0, -2.93f, 0, false, 0) / HUD_PX + 0.5f, kx = 0.53f - 0.475f + w / 2;
+ uint8_t al = (uint8_t)(m.a[F_BUTTON] * 255 + 0.5f);
+ if (al) {
+ Inst in;
+ sprite_inst(SPRITE_MSG_KEY, kx, -2.93f, 0, w / 0.95f, 1, gfx_dyn_tint(25, 255, 255, 255, al), &in);
+ gfx_hud(&in, 0);
+ line(t[5], STYLE_PROMPT, kx, -2.93f, 0, false, m.a[F_BUTTON]);
+ }
+}
diff --git a/games/hollowknight/src/vm.c b/games/hollowknight/src/vm.c
index 32642585..0da0de44 100644
--- a/games/hollowknight/src/vm.c
+++ b/games/hollowknight/src/vm.c
@@ -20,6 +20,8 @@ enum { O_HERO = 0xFF00, O_HERO_LIGHT, O_DIALOGUE_MANAGER, O_DIALOGUE_TEXT, O_ARE
O_GAME_MANAGER, O_HUD_BLANKER };
enum { OF_ACTIVE = 1, OF_RENDERER = 2, OF_ANIMATOR = 4, OF_TRIGGER = 8, OF_COLLIDER = 16,
OF_GONE = 32, OF_INSIDE = 64, OF_WAS_INSIDE = 128 };
+#define OF_ANIM_OFF 32 /* (its record's: off once its clip is over, DeactivateAfter2dtkAnimation) */
+#define OF_STARTED 4 /* (its own: its animator started, the first time it was on) */
enum { M_ENTER, M_UPDATE, M_FIXED };
typedef struct {
@@ -28,7 +30,7 @@ typedef struct {
uint8_t nmap, flags;
uint16_t cond, layer;
int16_t order;
- uint16_t pad;
+ uint16_t blend; /* (its material's: BL_*) */
} ObjRec;
typedef struct {
@@ -62,6 +64,8 @@ static struct {
int depth;
/* the area title's variables as scripts set them (title.c starts it from them) */
bool title_npc, title_visited, title_right, title_start;
+ float blank_alpha;
+ bool blank_on;
int title;
uint32_t prev_keys;
} vm;
@@ -262,6 +266,15 @@ static Mover *mover(int o, bool make) {
return NULL;
}
+/* (an animator plays its first clip the first time its object is on) */
+static void anims_start(void) {
+ for (int i = 0; i < vm.nobjs; i++)
+ if (!(vm.objs[i].flags & OF_STARTED) && vm.rec[i].clip != NONE && obj_active(i)) {
+ vm.objs[i].flags |= OF_STARTED;
+ anim_play_from_frame(&vm.objs[i].anim, vm.rec[i].clip, 0);
+ }
+}
+
static void fsm_start(Fsm *f);
static void obj_set_active(int o, bool on) {
if (o == O_AREA_TITLE) {
@@ -272,6 +285,7 @@ static void obj_set_active(int o, bool on) {
bool was = obj_active(o);
if (on) vm.objs[o].flags |= OF_ACTIVE;
else vm.objs[o].flags &= (uint8_t)~OF_ACTIVE;
+ if (!was && on) anims_start();
/* (an FSM starts again as its object comes on: RestartOnEnable) */
if (!was && on)
for (int i = 0; i < vm.nfsms; i++) {
@@ -840,7 +854,7 @@ static bool act(Fsm *f, const uint8_t *a, int mode) {
case 6: set_var(f, store, hero_can_talk()); break;
case 7: h->prevent_cast = 0.3f; break;
case 8: h->cs.on_ground = true; break;
- case 9: break; /* (AddMPCharge sent without its amount: nothing) */
+ case 9: hero_add_mp_charge((int)a0); break;
case 10: {
/* FindGroundPoint: below a point, the Knight's place standing there */
float y = hero_ground_y(h->body.x, a0);
@@ -887,6 +901,41 @@ static bool act(Fsm *f, const uint8_t *a, int mode) {
}
return false;
}
+ case VMOP_GETITEMMSG:
+ msg_show(rb(&r));
+ return true;
+ case VMOP_BLANKER: {
+ float a = fval(f, rv(&r));
+ bool every = rb(&r);
+ vm.blank_alpha = a;
+ blanker_set(a, vm.blank_on);
+ return !every;
+ }
+ case VMOP_BLANKERON:
+ vm.blank_on = val(f, rv(&r)) != 0;
+ blanker_set(vm.blank_alpha, vm.blank_on);
+ return true;
+ case VMOP_FINDGAMEOBJECT: {
+ uint16_t name = (uint16_t)val(f, rv(&r));
+ int found = NONE;
+ for (int i = 0; i < vm.nobjs && found == NONE; i++)
+ if (vm.rec[i].name == name && obj_active(i)) found = i;
+ set_var(f, rb(&r), (uint32_t)found);
+ return true;
+ }
+ case VMOP_CREATEOBJECT: {
+ /* (a prefab made beforehand: on, where it is made) */
+ int o = oval(f, rv(&r));
+ uint16_t x = rv(&r), y = rv(&r);
+ uint8_t store = rb(&r);
+ if (obj_ok(o)) {
+ if (has(x) && has(y)) obj_move(o, fval(f, x), fval(f, y));
+ vm.objs[o].flags &= (uint8_t)~OF_GONE;
+ obj_set_active(o, true);
+ }
+ set_var(f, store, (uint32_t)o);
+ return true;
+ }
default:
return true;
}
@@ -972,7 +1021,6 @@ void vm_enter(void) {
/* (DeactivateIfPlayerdataTrue, False) */
if (r->cond != NONE && pd_flag(r->cond & 0x7FFF) == ((r->cond & 0x8000) != 0)) o->flags &= (uint8_t)~OF_ACTIVE;
o->anim.clip = -1, o->anim.sprite = -1;
- if (r->clip != NONE) anim_play(&o->anim, r->clip);
}
const uint8_t *p = vm.map + 4 * nmap;
int nvars = 0;
@@ -988,6 +1036,7 @@ void vm_enter(void) {
}
vm.nfsms = nfsms;
vm.prev_keys = g_hero.keys;
+ anims_start();
for (int i = 0; i < nfsms; i++)
if (obj_active(vm.fsms[i].owner)) fsm_start(&vm.fsms[i]);
}
@@ -1002,6 +1051,7 @@ void vm_tick(void) {
o->flags = (uint8_t)(in ? o->flags | OF_INSIDE : o->flags & ~OF_INSIDE);
o->anim.events = 0;
anim_update(&o->anim, DT);
+ if ((vm.rec[i].flags & OF_ANIM_OFF) && (o->anim.events & ANIM_DONE)) obj_set_active(i, false);
}
/* (those set moving: falling to the ground) */
for (int k = 0; k < MAX_MOVERS; k++) {
@@ -1039,6 +1089,7 @@ void vm_draw(void) {
if (sprite < 0) continue;
Inst in;
sprite_inst(sprite, o->x, o->y, r->z, o->sx, o->sy, 0, &in);
+ in.flags = (uint8_t)((in.flags & ~F_BLEND) | r->blend);
gfx_actor(&in, SORT_KEY(r->layer, r->order));
}
}
@@ -1052,5 +1103,9 @@ void vm_debug(void) {
else printf(" %d:-", i);
}
printf("\n");
+ if (getenv("VMOBJ"))
+ for (int i = 0; i < vm.nobjs; i++)
+ printf(" obj %d name %d flags %d active %d at %.2f,%.2f clip %d sprite %d\n", i, vm.rec[i].name, vm.objs[i].flags,
+ obj_active(i), vm.objs[i].x, vm.objs[i].y, vm.objs[i].anim.clip, vm.objs[i].anim.sprite);
}
#endif
diff --git a/games/hollowknight/tools/fsm.py b/games/hollowknight/tools/fsm.py
index d1af73da..d9e2fbb6 100644
--- a/games/hollowknight/tools/fsm.py
+++ b/games/hollowknight/tools/fsm.py
@@ -179,7 +179,7 @@ def decode_params(ad, data_version, names_of=None):
return {"prop": S(d.get("PropertyName", b"")), "target": named(d.get("TargetObject"), lambda d: ref(d["value"]))}
if t == "FunctionCall":
d = ad["functionCallParams"][p]
- t = S(d.get("ParameterType", b""))
+ t = S(d.get("parameterType", d.get("ParameterType", b"")))
out = {"fn": S(d.get("FunctionName", b"")), "type": t}
for key, name in (("int", "IntParameter"), ("float", "FloatParameter"), ("bool", "BoolParameter"),
("string", "StringParameter")):
diff --git a/games/hollowknight/tools/pack.py b/games/hollowknight/tools/pack.py
index d1ed05a7..117d4ea0 100644
--- a/games/hollowknight/tools/pack.py
+++ b/games/hollowknight/tools/pack.py
@@ -354,6 +354,25 @@ def main():
row.append(TEXTS.add(line, style) if line else -1)
titles.append("{%s}" % ", ".join(str(i) for i in row))
fleurs = actors.title_fleurs(SPRITES)
+ # the message as an item is taken (UI Msg Get Item, on the HUD): each item's texts, the message's sprites, the
+ # items' icons
+ msgs = []
+ for item, (name, prefix, press, m1, m2, key) in text.MSGS.items():
+ msgs.append("{%d, %d, %d, %d, %d, %d}" % (TEXTS.id("UI", name, "MSG_NAME"), TEXTS.id("Prompts", prefix, "MSG"),
+ TEXTS.id("Prompts", press, "MSG"), TEXTS.id("Prompts", m1, "MSG"),
+ TEXTS.id("Prompts", m2, "MSG"), TEXTS.add(key, "PROMPT")))
+ pmsg = unity.prefab("sharedassets6.assets", 493)
+ hud_res = actors.HUD_K / actors.K0
+ for name, path, res, ref in (("BG", "BG", 0.003, None), ("STOP", "Stop", hud_res, None),
+ ("FLEUR", "Fleur", hud_res, [4, 2086]), ("KEY", "Button", hud_res, None)):
+ # (the fleur: its animation's last frame)
+ o = next(q for q in pmsg["objects"] if q["path"] == "UI Msg Get Item/" + path)
+ sr = next(c["v"] for c in o["c"] if c["type"] == "SpriteRenderer")
+ fleurs["SPRITE_MSG_" + name] = SPRITES.id(pmsg, ref or sr["m_Sprite"], max(o["lscale"][:2]), res)
+ fleurs["SPRITE_MSG_ICON_FIREBALL"] = SPRITES.id(unity.scene("Crossroads_ShamanTemple"), [4, 44], 1.5607, hud_res)
+ fleurs["MSG_TABLE"] = "{%s}" % ", ".join(msgs)
+ for i, item in enumerate(text.MSGS):
+ fleurs["MSG_" + item] = i
for r in ROOMS:
room_data(r)
if r in VARIANT_ROOMS:
diff --git a/games/hollowknight/tools/text.py b/games/hollowknight/tools/text.py
index 72cef9ae..1ed031c9 100644
--- a/games/hollowknight/tools/text.py
+++ b/games/hollowknight/tools/text.py
@@ -89,8 +89,16 @@ STYLES = {
"TITLE_L": _style("TrajanPro-Bold", 36 * 0.4902, HUD_PX, *TRAJAN, k=1, spacing=4.69, phases=1),
"TITLE_S": _style("TrajanPro-Bold", 36 * 0.3493, HUD_PX, *TRAJAN, k=1, spacing=4.69, phases=1),
"TITLE_SUB": _style("TrajanPro-Bold", 36 * 0.1942, HUD_PX, *TRAJAN, k=1, spacing=21.06),
+ # the message as an item is taken (UI Msg Get Item: its lines, a third bigger; its item's name)
+ "MSG": _style("Perpetua", 3.73 * 1.4407, HUD_PX, 134.0625, 0, 117, 95.9375, -38.1875),
+ "MSG_NAME": _style("TrajanPro-Bold", 9.32 * 1.4407, HUD_PX, *TRAJAN, k=1, phases=1),
}
+# the items the message shows: (its name in the UI sheet, the Prompts sheet's prefix, tap or press, its two lines, the
+# calculator's key for it)
+MSGS = {"FIREBALL": ("INV_NAME_SPELL_FIREBALL1", "GET_ITEM_INTRO2", "BUTTON_DESC_TAP", "GET_FIREBALL_1", "GET_FIREBALL_2",
+ "alpha")}
+
# the titles the game shows (the Titles sheet's X_MAIN, X_SUB, X_SUPER): the areas', bosses' and characters'
TITLES = ["KINGSPASS", "DIRTMOUTH", "CROSSROADS", "EGGTEMPLE", "SHAMANTEMPLE", "GREENPATH", "BIGFLY", "FALSE_KNIGHT",
"HORNET", "ELDERBUG", "SLY", "ISELDA", "CORNIFER", "QUIRREL", "SHAMAN", "STAG", "STAG2", "TISO_C", "TISO_NC",
diff --git a/games/hollowknight/tools/vm.py b/games/hollowknight/tools/vm.py
index 350deac9..5a181dd4 100644
--- a/games/hollowknight/tools/vm.py
+++ b/games/hollowknight/tools/vm.py
@@ -17,8 +17,8 @@ ROOMS = {
# FSMs left out (what this port does not have: the dream nail, sounds...)
SKIP_FSMS = {"npc_dream_dialogue", "Dream Dialogue", "Rotate", "fade and destroy", "Shop Open Voice"}
# objects left out (effects drawn by the C code, or nothing at all; the dream nail's)
-SKIP_CLASSES = {"SpellGetOrb", "ParticleSystem"}
-SKIP_NAMES = {"Dream Dialogue", "Dream Dialogue Flower", "Flower", "Flower Give"}
+SKIP_CLASSES = {"SpellGetOrb", "ParticleSystem", "SimpleSpriteFade"}
+SKIP_NAMES = {"Dream Dialogue", "Dream Dialogue Flower", "Flower", "Flower Give", "white_light", "white_light 1"}
MAX_OBJS, MAX_FSMS, MAX_VARS = 28, 20, 256 # (src/vm.c)
# the game's own objects
@@ -165,8 +165,11 @@ op("EaseFloat", ("fromValue", "f"), ("toValue", "f"), ("floatVariable", "F"), ("
op("CameraZoom", ("z", "f"), ("time", "f"), ("delay", "f"))
op("Collision2dEvent", ("sendEvent", "e"))
op("HudBlanker", ("alpha", "f"), ("time", "f"), ("on", "n"))
-op("CreateObject", ("what", "n"), ("x", "f"), ("y", "f"), ("sx", "f"), ("storeObject", "O"))
-op("GetItemMsg", ("what", "n"))
+op("CreateObject", ("gameObject", "o"), ("x", "f"), ("y", "f"), ("storeObject", "O"))
+op("GetItemMsg", ("item", "n"))
+op("Blanker", ("alpha", "f"), ("everyFrame", "n"))
+op("BlankerOn", ("on", "b"))
+op("FindGameObject", ("objectName", "s"), ("store", "O"))
op("SetParent", ("gameObject", "o"))
op("IntOp", ("intVariable", "I"), ("value", "i"))
@@ -175,8 +178,10 @@ HERO_METHODS = ["RelinquishControl", "RegainControl", "StopAnimationControl", "S
"FaceRight", "CanTalk", "PreventCastByDialogueEnd", "SetBackOnGround", "AddMPCharge",
"FindGroundPoint", "SetBenchRespawn", "SetHazardRespawn", "RelinquishControlNotVelocity",
"SetCState", "SaveGame", "AffectedByGravity", "ResetHardLandingTimer", "StopPlayingAudio"]
-# what CreateObject makes (src/vm.c)
-CREATED = {}
+# prefabs CreateObject makes that the scripts go on with (made beforehand, off): (file, path id)
+PREFAB_SPAWNS = {("sharedassets76.assets", 69)}
+# the items the message shows (text.MSGS's order), by Msg Control's Item
+MSG_ITEMS = {"Fireball": 0}
# camera shake events
SHAKES = {"EnemyKillShake": 1, "AverageShake": 2, "BigShake": 3, "SmallShake": 4}
@@ -215,11 +220,34 @@ class Room:
self.objs.append(o)
return self.obj_index[o["id"]]
- def ref_obj(self, r):
- """["ref", file, pid] -> a VM object (this scene's objects only)"""
+ def add_prefab(self, f, pid):
+ """A prefab's objects, made beforehand (off): its root's VM object."""
+ key = ("pf", f, pid)
+ if key in self.obj_index:
+ return self.obj_index[key]
+ d2 = unity.prefab(f, pid)
+ ids = {q["id"] for q in d2["objects"]}
+ k = lambda i: ("pf", f, pid, i)
+ root = None
+ for q in d2["objects"]:
+ c = dict(q)
+ c["id"] = k(q["id"])
+ c["parent"] = k(q["parent"]) if q.get("parent") in ids else None
+ c["children"] = [k(x) for x in q.get("children", [])]
+ c["_doc"], c["_key"] = d2, k
+ self.by_id[c["id"]] = c
+ if c["parent"] is None:
+ root = c
+ root["active"] = root["self_active"] = False
+ self.add_tree(root)
+ self.obj_index[key] = self.obj_index[root["id"]]
+ return self.obj_index[root["id"]]
+
+ def ref_obj(self, r, key=None):
+ """["ref", file, pid] -> a VM object (this scene's, or this prefab's, objects only)"""
if not r or r[1] != 0:
return O_NONE
- o = self.by_id.get(r[2])
+ o = self.by_id.get(key(r[2]) if key else r[2])
if o is None:
return O_NONE
if o["id"] not in self.obj_index:
@@ -277,7 +305,7 @@ class Compiler:
if v == "Owner":
return OWNER
if isinstance(v, (list, tuple)) and v and v[0] == "ref":
- return self.rm.ref_obj(v)
+ return self.rm.ref_obj(v, self.o.get("_key"))
return O_NONE
def value(self, v, kind):
@@ -293,6 +321,8 @@ class Compiler:
self.problem("variable %s unknown" % n)
return 0xFFFF
if kind == "o":
+ if isinstance(v, tuple) and v[0] == "objindex":
+ return self.const(v[1])
return self.const(self.obj_value(v))
if kind == "s":
return self.const(STR.id(v if isinstance(v, str) else str(v)))
@@ -414,6 +444,61 @@ class Compiler:
return None
if n in ("PlayerDataBoolTest",):
return self.emit(n, P)
+ if n == "CreateUIMsgGetItem":
+ return None # (made by the SetFsmString of its Item that follows)
+ if n == "SetFsmString" and P.get("fsmName") == "Msg Control" and P.get("variableName") == "Item":
+ if P.get("setValue") not in MSG_ITEMS:
+ self.problem("item message %s" % P.get("setValue"))
+ return None
+ return self.emit("GetItemMsg", {"item": MSG_ITEMS[P.get("setValue")]})
+ if n == "EaseColor":
+ cv = P.get("colorVariable")
+ if not (isinstance(cv, str) and cv[1:] in self.slots):
+ self.problem("EaseColor to %r" % cv)
+ return None
+ slot = self.slots[cv[1:]][0] + 3
+ fv, tv = P.get("fromValue"), P.get("toValue")
+ if not isinstance(fv, (list, tuple)) or not isinstance(tv, (list, tuple)):
+ self.problem("EaseColor from %r" % fv)
+ return None
+ code, schema = OPS["EaseFloat"]
+ body = struct.pack("<HH", self.value(float(fv[3]), "f"), self.value(float(tv[3]), "f")) + bytes([slot]) + \
+ struct.pack("<H", self.value(P.get("time"), "f")) + bytes([self.event(P.get("finishEvent"))])
+ return bytes([code, len(body)]) + body
+ if n == "SetMaterialColor" and P.get("gameObject") == "$HUD Blanker":
+ c = P.get("color")
+ if isinstance(c, str) and c[1:] in self.slots:
+ a = self.slots[c[1:]][0] + 3
+ elif isinstance(c, (list, tuple)):
+ a = self.value(float(c[3]), "f")
+ else:
+ self.problem("SetMaterialColor %r" % c)
+ return None
+ code, _ = OPS["Blanker"]
+ body = struct.pack("<H", a) + bytes([int(P.get("everyFrame") or 0)])
+ return bytes([code, len(body)]) + body
+ if n == "SetSpriteRenderer" and P.get("gameObject") == "$HUD Blanker":
+ return self.emit("BlankerOn", {"on": P.get("active")})
+ if n == "FindGameObject":
+ if P.get("objectName"):
+ return self.emit("FindGameObject", P)
+ return None # (by tag: the main camera)
+ if n == "CreateObject":
+ r = P.get("gameObject")
+ if isinstance(r, (list, tuple)) and r and r[0] == "ref":
+ import ents
+ f, pid = ents._ref_file(self.o.get("_doc") or self.rm.d, [r[1], r[2]])
+ if (f, pid) in PREFAB_SPAWNS:
+ pos = P.get("position") or [None, None, None]
+ obj = self.rm.add_prefab(f, pid)
+ return self.emit("CreateObject", {"gameObject": ("objindex", obj), "x": pos[0], "y": pos[1],
+ "storeObject": P.get("storeObject")})
+ return None # (effects)
+ if n == "GetButtonDown":
+ m = {"Jump": "ListenForJump", "Attack": "ListenForAttack", "Cast": "ListenForCast"}.get(P.get("buttonName"))
+ return self.emit(m, {"wasPressed": P.get("sendEvent")}) if m else None
+ if n == "SetParent":
+ return None
if n == "CallMethodProper":
beh, m = P.get("behaviour"), P.get("methodName")
args = P.get("parameters") or []
@@ -428,7 +513,11 @@ class Compiler:
if n == "SendMessage":
fn = (P.get("functionCall") or {}).get("fn")
if fn in HERO_METHODS:
- return self.emit("HeroCall", {"method": HERO_METHODS.index(fn), "store": None, "a": 0})
+ v = (P.get("functionCall") or {}).get("value")
+ return self.emit("HeroCall", {"method": HERO_METHODS.index(fn), "store": None,
+ "a": float(v) if isinstance(v, (int, float)) and not isinstance(v, bool) else 0})
+ if fn in ("advanceTypewriter", "TimePasses", "StoryRecord_acquired", "SetActionString", "RefreshButtonIcon"):
+ return None
self.problem("SendMessage %s" % fn)
return None
if n in ("SendEventByName", "SendEvent"):
@@ -583,7 +672,7 @@ def prepare(rooms, sprites, texts):
an = _animator(o)
if not an:
continue
- lib = ents._ref_file(rm.d, an["library"])
+ lib = ents._ref_file(o.get("_doc") or rm.d, an["library"])
clips = [unity.S(c["name"]) for c in tk2d.animation(*lib)["clips"]]
want = {c for c in clips if c in names}
if 0 <= an.get("defaultClipId", 0) < len(clips):
@@ -605,7 +694,7 @@ def prepare(rooms, sprites, texts):
OBJ = "<fffffffffHHHHHBBHHhH" # x y z, sx sy, its trigger (center from its place, half size), parent, name, sprite,
# first clip, clip map, its count, flags, condition, sorting layer, order
-OF_ACTIVE, OF_RENDERER, OF_ANIMATOR, OF_TRIGGER, OF_COLLIDER = 1, 2, 4, 8, 16
+OF_ACTIVE, OF_RENDERER, OF_ANIMATOR, OF_TRIGGER, OF_COLLIDER, OF_ANIM_OFF = 1, 2, 4, 8, 16, 32
def room_blob(name, clip_index, sprites):
@@ -634,6 +723,8 @@ def room_blob(name, clip_index, sprites):
fl |= OF_COLLIDER
if box:
fl |= OF_TRIGGER
+ if any(c.get("class") == "DeactivateAfter2dtkAnimation" for c in o["c"]):
+ fl |= OF_ANIM_OFF # (off once its clip is over)
bx, by = ((box[0] + box[2]) / 2 - o["pos"][0], (box[1] + box[3]) / 2 - o["pos"][1]) if box else (0, 0)
bhx, bhy = ((box[2] - box[0]) / 2, (box[3] - box[1]) / 2) if box else (0, 0)
sprite, first, start, count = 0xFFFF, 0xFFFF, nmap, 0
@@ -643,7 +734,7 @@ def room_blob(name, clip_index, sprites):
fl |= OF_RENDERER
if an:
fl |= OF_ANIMATOR
- lib = ents._ref_file(rm.d, an["library"])
+ lib = ents._ref_file(o.get("_doc") or rm.d, an["library"])
a = LIBS[lib]
clips = [unity.S(c["name"]) for c in tk2d.animation(*lib)["clips"]]
dc = an.get("defaultClipId", 0)
@@ -658,14 +749,23 @@ def room_blob(name, clip_index, sprites):
else:
sr = next((c.get("v") for c in o["c"] if c["type"] == "SpriteRenderer" and c.get("v")), None)
if sr and sr.get("m_Sprite"):
- sprite = sprites.id(rm.d, sr["m_Sprite"], max(abs(sx), abs(sy)))
+ sprite = sprites.id(o.get("_doc") or rm.d, sr["m_Sprite"], max(abs(sx), abs(sy)))
cond = 0xFFFF
for bn, off_if in state.conditions(o):
if bn in pdf:
cond = pdf[bn] | (0x8000 if off_if else 0)
layer, order = ents._sorting(o)
+ # (its material's blend: pack.BLENDS)
+ import scene
+ blend = 0
+ if mr is not None and mr.get("m_Materials"):
+ m0 = mr["m_Materials"][0]
+ if m0 and m0[1]:
+ doc = o.get("_doc") or rm.d
+ blend = {"alpha": 0, "add": 1, "screen": 2, "linearlight": 3, "overlay": 4, "multiply": 5}[
+ scene.blend_of(unity.material(unity.ref_path(doc, m0[0]), m0[1])[1])]
objs += struct.pack(OBJ, o["pos"][0], o["pos"][1], o["pos"][2], sx, sy, bx, by, bhx, bhy, parent,
- STR.id(o["name"]), sprite, first, start, min(count, 255), fl, cond, layer, order, 0)
+ STR.id(o["name"]), sprite, first, start, min(count, 255), fl, cond, layer, order, blend)
fsms = bytearray()
for di, owner, init, fname in rm.fsms:
fsms += struct.pack("<HHHH", di, owner, fname, len(init)) + b"".join(struct.pack("<I", v) for v in init)