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.
C calculatorcalculator-gamescasiochesscrossy-roaddrive-madfx-cg50gamesgeometry-dashgraphing-calculatorndlessnumworksnumworks-appsnumworks-calculatornumworks-gamenumworks-gamestetristi-84-plus-ceti-nspire
Hollow Knight: Hornet's encounter in Greenpath, her arena's walls, her refight
Mason Chen8d5335f10a9a
diff --git a/games/hollowknight/src/data.bin b/games/hollowknight/src/data.binindex eed99628..6e18bb7a 100644Binary files a/games/hollowknight/src/data.bin and b/games/hollowknight/src/data.bin differdiff --git a/games/hollowknight/src/data.h b/games/hollowknight/src/data.hindex 8a376f99..bd9d8104 100644--- a/games/hollowknight/src/data.h+++ b/games/hollowknight/src/data.h@@ -495,45 +495,47 @@#define CLIP_DRIP_DRIP 435#define CLIP_DRIP_FALL 436#define CLIP_DRIP_IMPACT 437-#define CLIP_HORNETCS_IDLE 438-#define CLIP_HORNETCS_JUMP_FULL 439-#define CLIP_HORNETCS_THROW_SIDE_START 440-#define CLIP_HORNETCS_THROW_SIDE 441-#define CLIP_HORNETCS_HARPOON_SIDE 442-#define CLIP_HORNETCS_THREAD_1 443-#define CLIP_HORNETCS_POINT 444-#define CLIP_HORNETCS_EVADE_ANTIC 445-#define CLIP_HORNETCS_EVADE 446-#define CLIP_HORNETCS_SOFT_LAND 447-#define CLIP_BULLET_IDLE 448-#define CLIP_BULLET_IMPACT 449-#define CLIP_BULLET_SHOCKWAVE_SPURT 450-#define CLIP_PROP0_WATERFALL_LOOP 451-#define CLIP_PROP1_TORCH2 452-#define CLIP_PROP1_TORCH3 453-#define CLIP_VM0_FLOWER 454-#define CLIP_VM0_IDLE 455-#define CLIP_VM0_REACH 456-#define CLIP_VM0_REACH_TO_IDLE 457-#define CLIP_VM0_TALK_LEFT 458-#define CLIP_VM0_TALK_RIGHT 459-#define CLIP_VM0_TURN_LEFT 460-#define CLIP_VM0_TURN_RIGHT 461-#define CLIP_VM2_IDLE 462-#define CLIP_VM2_SIT_IDLE 463-#define CLIP_VM2_SIT_TALK 464-#define CLIP_VM2_SIT_TALK_END 465-#define CLIP_VM2_SUMMON 466-#define CLIP_VM2_TALK 467-#define CLIP_VM2_TALK_END 468-#define CLIP_VM2_TURN 469-#define SPRITE_HERO_LIGHT 2014-#define SPRITE_DIALOGUE_BACKBOARD 2015-#define SPRITE_PROMPT_SHADOW 2016-#define SPRITE_CORPSE_NAIL 2017-#define SPRITE_FK_BARREL 2018-#define SPRITE_FK_STAFF 2019-#define SPRITE_DIGIT0 2219+#define CLIP_HORNETCS_EVADE 438+#define CLIP_HORNETCS_EVADE_ANTIC 439+#define CLIP_HORNETCS_HARPOON_SIDE 440+#define CLIP_HORNETCS_IDLE 441+#define CLIP_HORNETCS_JUMP_FULL 442+#define CLIP_HORNETCS_POINT 443+#define CLIP_HORNETCS_SOFT_LAND 444+#define CLIP_HORNETCS_THREAD_1 445+#define CLIP_HORNETCS_THROW_SIDE 446+#define CLIP_HORNETCS_THROW_SIDE_START 447+#define CLIP_HORNETCS_TURN 448+#define CLIP_HORNETCS_TURNTOIDLE 449+#define CLIP_BULLET_IDLE 450+#define CLIP_BULLET_IMPACT 451+#define CLIP_BULLET_SHOCKWAVE_SPURT 452+#define CLIP_PROP0_WATERFALL_LOOP 453+#define CLIP_PROP1_TORCH2 454+#define CLIP_PROP1_TORCH3 455+#define CLIP_VM0_FLOWER 456+#define CLIP_VM0_IDLE 457+#define CLIP_VM0_REACH 458+#define CLIP_VM0_REACH_TO_IDLE 459+#define CLIP_VM0_TALK_LEFT 460+#define CLIP_VM0_TALK_RIGHT 461+#define CLIP_VM0_TURN_LEFT 462+#define CLIP_VM0_TURN_RIGHT 463+#define CLIP_VM3_IDLE 464+#define CLIP_VM3_SIT_IDLE 465+#define CLIP_VM3_SIT_TALK 466+#define CLIP_VM3_SIT_TALK_END 467+#define CLIP_VM3_SUMMON 468+#define CLIP_VM3_TALK 469+#define CLIP_VM3_TALK_END 470+#define CLIP_VM3_TURN 471+#define SPRITE_HERO_LIGHT 2017+#define SPRITE_DIALOGUE_BACKBOARD 2018+#define SPRITE_PROMPT_SHADOW 2019+#define SPRITE_CORPSE_NAIL 2020+#define SPRITE_FK_BARREL 2021+#define SPRITE_FK_STAFF 2022+#define SPRITE_DIGIT0 2222#define STYLE_DIALOGUE 0#define STYLE_PROMPT 1#define STYLE_TITLE_L 2@@ -574,20 +576,20 @@#define EK_HORNET 29#define NUM_KINDS 30#define KIND_TABLE {{0}, {EF_CRAWLER, {-1, 156, 155, -1, -1, -1, -1, -1, -1, -1, -1, 158, 159}}, {EF_BUZZER, {161, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 163, 164}}, {EF_SHADE, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}}, {EF_CLIMBER, {-1, -1, 171, 170, -1, -1, -1, -1, -1, -1, -1, 168, 169}}, {EF_BOUNCER, {-1, -1, -1, 174, -1, -1, -1, -1, -1, -1, -1, 172, 173}}, {EF_SPITTER, {-1, -1, -1, 177, 178, 176, -1, -1, -1, -1, -1, 175, -1}}, {EF_ROLLER, {181, -1, -1, 183, 182, 184, -1, -1, -1, -1, -1, 179, 180}}, {EF_BLOCKER, {191, -1, -1, 187, 192, 185, 186, 193, 194, 190, 189, -1, 188}}, {EF_HUSK, {200, 201, 202, 195, 197, 196, -1, -1, -1, -1, -1, 198, 199}}, {EF_HUSK, {208, 209, 210, 203, 205, 204, -1, -1, -1, -1, -1, 206, 207}}, {EF_HUSK, {216, 217, 218, 211, 213, 212, -1, -1, -1, -1, -1, 214, 215}}, {EF_HUSK, {224, 225, 226, 219, 221, 220, -1, -1, -1, -1, -1, 222, 223}}, {EF_LEAPER, {230, 232, 233, 227, 231, -1, -1, -1, -1, -1, -1, 228, 229}}, {EF_GUARD, {239, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 236, 237}}, {EF_FK, {261, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 259}}, {EF_FKHEAD, {281, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 279}}, {EF_HATCHER, {-1, -1, -1, 286, 285, -1, -1, -1, -1, -1, -1, 283, 284}}, {EF_HATCHLING, {-1, -1, -1, 287, -1, -1, -1, -1, -1, -1, -1, -1, -1}}, {EF_SLUG, {293, -1, -1, 291, 292, 295, 294, 288, -1, -1, -1, 289, 290}}, {EF_GFLY, {308, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}}, {EF_MOSSWALKER, {-1, 317, 318, 316, 312, 313, -1, -1, -1, -1, -1, 314, 315}}, {EF_PIGEON, {-1, -1, -1, 320, 321, 322, 319, -1, -1, -1, -1, -1, -1}}, {EF_PLANTTRAP, {324, -1, -1, 327, 326, 325, -1, -1, -1, -1, -1, 323, -1}}, {EF_SHAKER, {331, 332, 333, 328, -1, -1, -1, -1, -1, -1, -1, 329, 330}}, {EF_MOSQUITO, {338, -1, -1, 340, 339, 335, 334, -1, -1, -1, -1, 336, 337}}, {EF_FATFLY, {344, -1, -1, 341, -1, -1, -1, -1, -1, -1, -1, 342, 343}}, {EF_MOSSCHARGER, {-1, -1, -1, 345, 346, 349, 352, 351, 353, 350, -1, 347, 348}}, {EF_MOSSKNIGHT, {359, 374, 378, -1, -1, -1, -1, -1, -1, -1, -1, 354, 355}}, {EF_HORNET, {394, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 382, -1}}}-#define TXT_PROMPT_LISTEN 27-#define TXT_PROMPT_REST 28-#define TXT_PROMPT_INSPECT 29-#define TXT_PROMPT_ENTER 30-#define TXT_PROMPT_SIT 31-#define TXT_PROMPT_SHOP 32-#define TXT_PROMPT_TRAVEL 33-#define TXT_PROMPT_ASCEND 34-#define TXT_PROMPT_DESCEND 35-#define TXT_PROMPT_EXIT 36-#define TXT_PROMPT_ACCEPT 37-#define TXT_PROMPT_TRADE 38-#define TXT_PROMPT_WATCH 39-#define TXT_PROMPT_CHALLENGE 40+#define TXT_PROMPT_LISTEN 28+#define TXT_PROMPT_REST 29+#define TXT_PROMPT_INSPECT 30+#define TXT_PROMPT_ENTER 31+#define TXT_PROMPT_SIT 32+#define TXT_PROMPT_SHOP 33+#define TXT_PROMPT_TRAVEL 34+#define TXT_PROMPT_ASCEND 35+#define TXT_PROMPT_DESCEND 36+#define TXT_PROMPT_EXIT 37+#define TXT_PROMPT_ACCEPT 38+#define TXT_PROMPT_TRADE 39+#define TXT_PROMPT_WATCH 40+#define TXT_PROMPT_CHALLENGE 41#define PROMPT_SORT 884737u#define DIGIT_ADV {0.4182f, 0.4182f, 0.4182f, 0.4182f, 0.4182f, 0.4182f, 0.4182f, 0.4182f, 0.4182f, 0.4182f}#define VMOP_NOP 1@@ -674,6 +676,8 @@#define VMOP_FINDGAMEOBJECT 82#define VMOP_SETPARENT 83#define VMOP_INTOP 84+#define VMOP_ACTIVATEALLCHILDREN 85+#define VMOP_ITWEENMOVEBY 86#define VMEV_FINISHED 0#define VMEV_CONVO_FINISH 1#define VMEV_CONVO_START 2@@ -689,9 +693,16 @@#define VMEV_TAKE_DAMAGE 12#define VMEV_GET_ITEM_MSG_END 13#define VMEV_HORNET_LEAVE 14+#define VMEV_BG_CLOSE 15+#define VMEV_BG_QUICK_CLOSE 16+#define VMEV_BG_OPEN 17+#define VMEV_BG_QUICK_OPEN 18+#define VMEV_BG_DESTROY 19+#define VMEV_WAKE 20#define VMSTR_NPC_TITLE 14-#define VMSTR_VISITED 127-#define VMSTR_DISPLAY_RIGHT 128+#define VMSTR_VISITED 149+#define VMSTR_DISPLAY_RIGHT 150+#define VMSTR_HORNET_SAVER 83#define STR_ATTACK_RANGE 23#define STR_EVADE_RANGE 50#define STR_SPIT_RANGE 51@@ -719,18 +730,18 @@#define TITLE_TISO_NC 18#define TITLE_CHARM_SLUG 19#define NUM_TITLES 20-#define TITLE_TABLE {{41, 42, -1, -1}, {43, 44, 45, -1}, {46, 47, -1, 48}, {49, 50, -1, 51}, {52, 53, -1, 54}, {55, 56, -1, -1}, {57, 58, 59, -1}, {60, 61, -1, -1}, {62, 63, -1, -1}, {64, 65, -1, -1}, {66, 67, -1, -1}, {68, 69, -1, -1}, {70, 71, -1, -1}, {72, 73, -1, -1}, {74, 75, -1, 76}, {77, 78, -1, 79}, {77, 78, -1, 80}, {81, 82, 83, -1}, {81, 82, -1, -1}, {84, 85, -1, 86}}-#define SPRITE_FLEUR_TOP 2020+#define TITLE_TABLE {{42, 43, -1, -1}, {44, 45, 46, -1}, {47, 48, -1, 49}, {50, 51, -1, 52}, {53, 54, -1, 55}, {56, 57, -1, -1}, {58, 59, 60, -1}, {61, 62, -1, -1}, {63, 64, -1, -1}, {65, 66, -1, -1}, {67, 68, -1, -1}, {69, 70, -1, -1}, {71, 72, -1, -1}, {73, 74, -1, -1}, {75, 76, -1, 77}, {78, 79, -1, 80}, {78, 79, -1, 81}, {82, 83, 84, -1}, {82, 83, -1, -1}, {85, 86, -1, 87}}+#define SPRITE_FLEUR_TOP 2023#define FLEUR_TOP_RECTS {{0.781f, -0.844f, 0.953f, -0.688f}, {-1.078f, -0.984f, 1.141f, -0.531f}, {-1.281f, -1.016f, 1.313f, -0.484f}, {-1.359f, -1.016f, 1.969f, -0.141f}, {-2.141f, -1.031f, 2.531f, 0.047f}, {-2.250f, -1.078f, 2.766f, 0.266f}, {-2.797f, -1.203f, 3.094f, 0.578f}, {-2.938f, -1.219f, 3.219f, 0.859f}, {-3.203f, -1.234f, 3.469f, 1.141f}, {-3.312f, -1.234f, 3.766f, 1.281f}, {-3.547f, -1.250f, 4.000f, 1.328f}, {-3.844f, -1.250f, 4.016f, 1.328f}, {-4.016f, -1.250f, 4.031f, 1.344f}, {-4.031f, -1.250f, 4.031f, 1.344f}, {-4.047f, -1.250f, 4.031f, 1.359f}, {-4.047f, -1.250f, 4.031f, 1.359f}, {-4.047f, -1.266f, 4.031f, 1.359f}, {-4.047f, -1.266f, 4.031f, 1.359f}, {-4.062f, -1.266f, 4.047f, 1.375f}, {-4.062f, -1.266f, 4.047f, 1.375f}, {-4.062f, -1.266f, 4.047f, 1.375f}, {-4.062f, -1.266f, 4.047f, 1.375f}}#define FLEUR_FRAMES 22#define FLEUR_FPS 15.0f-#define SPRITE_FLEUR_BOT 2021+#define SPRITE_FLEUR_BOT 2024#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 2022-#define SPRITE_MSG_STOP 2023-#define SPRITE_MSG_FLEUR 2024-#define SPRITE_MSG_KEY 2025-#define SPRITE_MSG_ICON_FIREBALL 2026-#define SPRITE_GRASS_BALL 2027-#define MSG_TABLE {{87, 88, 89, 90, 91, 92}}+#define SPRITE_MSG_BG 2025+#define SPRITE_MSG_STOP 2026+#define SPRITE_MSG_FLEUR 2027+#define SPRITE_MSG_KEY 2028+#define SPRITE_MSG_ICON_FIREBALL 2029+#define SPRITE_GRASS_BALL 2030+#define MSG_TABLE {{88, 89, 90, 91, 92, 93}}#define MSG_FIREBALL 0diff --git a/games/hollowknight/src/enemy.c b/games/hollowknight/src/enemy.cindex 50f54964..d20793b6 100644--- a/games/hollowknight/src/enemy.c+++ b/games/hollowknight/src/enemy.c@@ -5306,6 +5306,14 @@ static void ho_box(Enemy *e, int b) {e->body.hx = (q[2] * c + q[3] * s) / 2, e->body.hy = (q[2] * s + q[3] * c) / 2;}+/* (put into the floor by a snap to the wall: the physics pushes her out of it, up, the least way) */+static void ho_unsink(Enemy *e, bool left) {+ float x = e->body.x + e->body.ox + (left ? 0.5f : -0.5f), top = e->body.y + e->body.oy + e->body.hy;+ float bottom = top - 2 * e->body.hy;+ PhysHit h;+ if (phys_ray(x, top, 0, -1, top - bottom, CF_TERRAIN, &h) && h.y > bottom) e->body.y += h.y - bottom + 0.01f;+}+/* SetBoxColliderTrigger: a trigger touches nothing */static void ho_trigger(Enemy *e, bool on) { e->body.mask = on ? 0 : CF_SOLID; }@@ -5895,6 +5903,7 @@ static void hornet_update(Enemy *e) {e->body.x = left ? HO_WALL_L : HO_WALL_R;ho_trigger(e, false);ho_box(e, HB_IDLE);+ ho_unsink(e, left);anim_play_from_frame(&e->anim, CLIP_HORNET_WALL_IMPACT, 0);e->c0 = left;e->st = HO_WALL;@@ -6827,4 +6836,4 @@ void enemies_debug_hit(int damage) {#endif/* her Hornet Saver (walls round her arena): ActivateAllChildren */-void enemies_hornet_saver(bool on) { (void)on; }+void enemies_hornet_saver(bool on) { vm_activate_children(VMSTR_HORNET_SAVER, on); }diff --git a/games/hollowknight/src/game.h b/games/hollowknight/src/game.hindex 5e30ac45..8800f9a5 100644--- a/games/hollowknight/src/game.h+++ b/games/hollowknight/src/game.h@@ -72,6 +72,8 @@ enum { EF_START = 1, EF_STARTLES = 2, EF_PREBATTLE = 4, EF_BATTLE = 8, EF_ARENA_/* battle gates (BG Control: their events) and arenas (Battle Control: obj.c) */enum { BG_CLOSE, BG_QUICK_CLOSE, BG_OPEN, BG_QUICK_OPEN, BG_DESTROY };void gates_event(int ev);+int gate_find(uint16_t name); /* (a gate by its name: the scripts' strings) */+void gate_event_at(int k, int ev);void arena_start(void); /* START (sent by an enemy) */void arena_enemy_died(void); /* (one it counts) */void arena_set_activated(void); /* Activated: its fight over (and saved) */@@ -278,6 +280,8 @@ void vm_enter(void);void vm_tick(void);void vm_draw(void);void vm_broadcast(int ev);+void vm_spell(float x0, float y0, float x1, float y1); /* (a spell's box: the triggers it is in) */+void vm_activate_children(uint16_t name, bool on); /* ActivateAllChildren of a script object, by name *//* 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);diff --git a/games/hollowknight/src/obj.c b/games/hollowknight/src/obj.cindex f6cbe9f7..3333bf2c 100644--- a/games/hollowknight/src/obj.c+++ b/games/hollowknight/src/obj.c@@ -373,6 +373,17 @@ static void gate_tick(Obj *o, const Ent *e) {}}+/* a gate by its name (the scripts': FindGameObject) -> its object, or -1; an event to it alone */+int gate_find(uint16_t name) {+ for (int k = 0; k < nobjs; k++)+ if (objs[k].kind == OK_BGATE && (uint16_t)ent_at(objs[k].ent)->p2 == name) return k;+ return -1;+}++void gate_event_at(int k, int ev) {+ if (k >= 0 && k < nobjs && objs[k].kind == OK_BGATE) gate_event(&objs[k], ent_at(objs[k].ent), ev);+}+void gates_event(int ev) {#ifdef HOSTif (getenv("HKOBJ")) fprintf(stderr, "gates event %d\n", ev);diff --git a/games/hollowknight/src/spell.c b/games/hollowknight/src/spell.cindex 508359c8..310ad952 100644--- a/games/hollowknight/src/spell.c+++ b/games/hollowknight/src/spell.c@@ -290,6 +290,7 @@ static void fireball_hit_things(Fireball *f) {float dir = f->right ? 0 : 180;f->hit_enemies |= enemies_spell(cx - hx, cy - hy, cx + hx, cy + hy, dir, FB_DAMAGE, FB_MAGNITUDE, f->hit_enemies);obj_spell(cx - hx, cy - hy, cx + hx, cy + hy, dir, f->hit_objs);+ vm_spell(cx - hx, cy - hy, cx + hx, cy + hy);}void fireballs_tick(void) {diff --git a/games/hollowknight/src/vm.c b/games/hollowknight/src/vm.cindex 0da0de44..61d9e944 100644--- a/games/hollowknight/src/vm.c+++ b/games/hollowknight/src/vm.c@@ -17,9 +17,12 @@#define NONE 0xFFFF#define OWNER 0xFF0Fenum { O_HERO = 0xFF00, O_HERO_LIGHT, O_DIALOGUE_MANAGER, O_DIALOGUE_TEXT, O_AREA_TITLE, O_CAMERA_PARENT, O_MAIN_CAMERA,- O_GAME_MANAGER, O_HUD_BLANKER };+ O_GAME_MANAGER, O_HUD_BLANKER, O_HORNET = 0xFF0C };+#define O_GATE 0xFD00 /* (+ k: a battle gate, obj.c's) */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 };+ OF_GONE = 32, OF_INSIDE = 64, OF_WAS_INSIDE = 128,+ OF_COND_OFF = 256, /* (not there: its condition) */+ OF_SPELL_HIT = 512, OF_SPELL_IN = 1024, OF_SPELL_WAS = 2048 }; /* (a spell in its trigger) */#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 };@@ -31,16 +34,21 @@ typedef struct {uint16_t cond, layer;int16_t order;uint16_t blend; /* (its material's: BL_*) */+ uint8_t col0, ncol; /* (the colliders it has: on as it is) */+ uint16_t pad;} ObjRec;typedef struct {float x, y, sx, sy; /* its place and scale now */Anim anim;- uint8_t flags;+ uint16_t flags;} Obj;typedef struct {int16_t obj; /* (-1: none) */float vx, vy, g; /* (one the scripts set moving: velocity, gravity scale) */+ /* (iTweenMoveBy: from, by, time so far, its time, ease; 1 going, 2 over) */+ float tx, ty, tdx, tdy, tt, ttime;+ uint8_t ease, tween;} Mover;typedef struct {@@ -174,6 +182,7 @@ static int pd_int(int i) {case 7: return g_pd.shaman;case 8: return g_pd.elderbug;case 10: return g_pd.nail_damage;+ case 11: return g_pd.hornet_greenpath;default: return 0;}}@@ -185,6 +194,7 @@ static void pd_set_int(int i, int v) {case 4: g_pd.fireball_level = (uint8_t)v; break;case 7: g_pd.shaman = (uint8_t)v; break;case 8: g_pd.elderbug = (uint8_t)v; break;+ case 11: g_pd.hornet_greenpath = (uint8_t)v; break;}}@@ -260,7 +270,8 @@ static Mover *mover(int o, bool make) {if (!make) return NULL;for (int i = 0; i < MAX_MOVERS; i++)if (vm.movers[i].obj < 0) {- vm.movers[i] = (Mover){(int16_t)o, 0, 0, 0};+ memset(&vm.movers[i], 0, sizeof vm.movers[i]);+ vm.movers[i].obj = (int16_t)o;return &vm.movers[i];}return NULL;@@ -275,6 +286,13 @@ static void anims_start(void) {}}+/* (the colliders objects have: on as they are) */+static void obj_colliders(void) {+ for (int i = 0; i < vm.nobjs; i++)+ if (vm.rec[i].ncol && !(vm.objs[i].flags & OF_COND_OFF))+ for (int c = vm.rec[i].col0; c < vm.rec[i].col0 + vm.rec[i].ncol; c++) phys_collider_enable(c, obj_active(i));+}+static void fsm_start(Fsm *f);static void obj_set_active(int o, bool on) {if (o == O_AREA_TITLE) {@@ -284,7 +302,7 @@ static void obj_set_active(int o, bool on) {if (!obj_ok(o)) return;bool was = obj_active(o);if (on) vm.objs[o].flags |= OF_ACTIVE;- else vm.objs[o].flags &= (uint8_t)~OF_ACTIVE;+ else vm.objs[o].flags &= (uint16_t)~OF_ACTIVE;if (!was && on) anims_start();/* (an FSM starts again as its object comes on: RestartOnEnable) */if (!was && on)@@ -295,6 +313,7 @@ static void obj_set_active(int o, bool on) {if (was && !on)for (int i = 0; i < vm.nfsms; i++)if (vm.fsms[i].on && !obj_active(vm.fsms[i].owner)) vm.fsms[i].on = false;+ if (was != on) obj_colliders();}static bool hero_box_in(int o) {@@ -344,6 +363,14 @@ void vm_broadcast(int ev) {}static void obj_event(int o, int ev, uint16_t fsm_name) {+ if (o >= O_GATE && o < O_GATE + 0x100) {+ if (ev >= VMEV_BG_CLOSE && ev <= VMEV_BG_DESTROY) gate_event_at(o - O_GATE, ev - VMEV_BG_CLOSE);+ return;+ }+ if (o == O_HORNET) {+ if (ev == VMEV_WAKE) enemies_hornet_wake();+ return;+ }if (o == O_DIALOGUE_MANAGER) {if (ev == VMEV_BOX_UP) dialogue_box_up();else if (ev == VMEV_BOX_DOWN) dialogue_box_down();@@ -355,7 +382,8 @@ static void obj_event(int o, int ev, uint16_t fsm_name) {/* events the game's own objects hear */static void game_event(int ev) {- if (ev == VMEV_NPC_TITLE_DOWN) title_npc_down();+ if (ev >= VMEV_BG_CLOSE && ev <= VMEV_BG_DESTROY) gates_event(ev - VMEV_BG_CLOSE);+ else if (ev == VMEV_NPC_TITLE_DOWN) title_npc_down();else if (ev == VMEV_NPC_CONVO_START) title_npc_convo_start();}@@ -597,13 +625,13 @@ static bool act(Fsm *f, const uint8_t *a, int mode) {int o = oval(f, rv(&r));bool on = val(f, rv(&r)) != 0;if (o == O_HERO) g_hero.hidden = !on;- else if (obj_ok(o)) vm.objs[o].flags = (uint8_t)(on ? vm.objs[o].flags | OF_RENDERER : vm.objs[o].flags & ~OF_RENDERER);+ else if (obj_ok(o)) vm.objs[o].flags = (uint16_t)(on ? vm.objs[o].flags | OF_RENDERER : vm.objs[o].flags & ~OF_RENDERER);return true;}case VMOP_SETCOLLIDER: {int o = oval(f, rv(&r));bool on = val(f, rv(&r)) != 0;- if (obj_ok(o)) vm.objs[o].flags = (uint8_t)(on ? vm.objs[o].flags | OF_COLLIDER : vm.objs[o].flags & ~OF_COLLIDER);+ if (obj_ok(o)) vm.objs[o].flags = (uint16_t)(on ? vm.objs[o].flags | OF_COLLIDER : vm.objs[o].flags & ~OF_COLLIDER);return true;}case VMOP_DESTROYOBJECT: {@@ -771,11 +799,11 @@ static bool act(Fsm *f, const uint8_t *a, int mode) {return !every;}case VMOP_TRIGGER2DEVENT: {- /* (the Knight against its owner's trigger: 0 entering, 1 in it, 2 leaving) */- int kind = rb(&r), ev = rb(&r);+ /* (the Knight, or a spell, against its owner's trigger: 0 entering, 1 in it, 2 leaving) */+ int kind = rb(&r), ev = rb(&r), tag = rb(&r);if (mode != M_FIXED || !obj_ok(f->owner) || !(vm.objs[f->owner].flags & OF_COLLIDER)) return false;- uint8_t fl = vm.objs[f->owner].flags;- bool in = fl & OF_INSIDE, was = fl & OF_WAS_INSIDE;+ uint16_t fl = vm.objs[f->owner].flags;+ bool in = fl & (tag ? OF_SPELL_IN : OF_INSIDE), was = fl & (tag ? OF_SPELL_WAS : OF_WAS_INSIDE);if ((kind == 0 && in && !was) || (kind == 1 && in) || (kind == 2 && !in && was)) fsm_event(f, ev);return false;}@@ -920,6 +948,11 @@ static bool act(Fsm *f, const uint8_t *a, int mode) {int found = NONE;for (int i = 0; i < vm.nobjs && found == NONE; i++)if (vm.rec[i].name == name && obj_active(i)) found = i;+ if (found == NONE) {+ /* (a battle gate: the game's) */+ int g = gate_find(name);+ if (g >= 0) found = O_GATE + g;+ }set_var(f, rb(&r), (uint32_t)found);return true;}@@ -930,17 +963,84 @@ static bool act(Fsm *f, const uint8_t *a, int mode) {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;+ vm.objs[o].flags &= (uint16_t)~OF_GONE;obj_set_active(o, true);}set_var(f, store, (uint32_t)o);return true;}+ case VMOP_ACTIVATEALLCHILDREN: {+ int o = oval(f, rv(&r));+ bool on = val(f, rv(&r)) != 0;+ for (int c = 0; c < vm.nobjs; c++)+ if (obj_ok(o) && vm.rec[c].parent == o) obj_set_active(c, on);+ return true;+ }+ case VMOP_ITWEENMOVEBY: {+ /* (by a vector, in a time, eased; over once it is there) */+ int o = oval(f, rv(&r));+ uint16_t vec = rv(&r);+ float t = fval(f, rv(&r));+ int ease = rb(&r), ev = rb(&r);+ Mover *m = mover(o, enter);+ if (enter) {+ if (!m) return true;+ obj_pos(o, &m->tx, &m->ty);+ m->tdx = has(vec) ? fval(f, vec) : 0, m->tdy = has(vec) ? fval(f, (uint16_t)(vec + 1)) : 0;+ m->tt = 0, m->ttime = t, m->ease = (uint8_t)ease, m->tween = 1;+ return false;+ }+ if (mode == M_UPDATE && (!m || m->tween != 1)) {+ if (m) m->tween = 0;+ fsm_event(f, ev);+ return true;+ }+ return false;+ }default:return true;}}+/* iTween's eases (EaseType: quad, cubic, quart, quint each in, out, in-out; sine, expo, circ; linear) */+static float ease(int type, float k) {+ int g = type / 3, w = type % 3;+ if (type >= 21) return k;+ switch (g) {+ case 0: return w == 0 ? k * k : w == 1 ? 1 - (1 - k) * (1 - k) : k < 0.5f ? 2 * k * k : 1 - 2 * (1 - k) * (1 - k);+ case 1: return w == 0 ? k * k * k : w == 1 ? 1 - (1 - k) * (1 - k) * (1 - k)+ : k < 0.5f ? 4 * k * k * k : 1 - 4 * (1 - k) * (1 - k) * (1 - k);+ case 2: return w == 0 ? k * k * k * k : w == 1 ? 1 - powf(1 - k, 4) : k < 0.5f ? 8 * powf(k, 4) : 1 - 8 * powf(1 - k, 4);+ case 3: return w == 0 ? powf(k, 5) : w == 1 ? 1 - powf(1 - k, 5) : k < 0.5f ? 16 * powf(k, 5) : 1 - 16 * powf(1 - k, 5);+ case 4: return w == 0 ? 1 - cosf(k * (float)M_PI / 2) : w == 1 ? sinf(k * (float)M_PI / 2) : (1 - cosf(k * (float)M_PI)) / 2;+ case 5:+ if (k <= 0 || k >= 1) return k;+ return w == 0 ? powf(2, 10 * (k - 1)) : w == 1 ? 1 - powf(2, -10 * k)+ : k < 0.5f ? powf(2, 20 * k - 10) / 2 : 1 - powf(2, -20 * k + 10) / 2;+ default:+ return w == 0 ? 1 - sqrtf(1 - k * k) : w == 1 ? sqrtf(1 - (k - 1) * (k - 1))+ : k < 0.5f ? (1 - sqrtf(1 - 4 * k * k)) / 2 : (1 + sqrtf(1 - (2 * k - 2) * (2 * k - 2))) / 2;+ }+}++/* ActivateAllChildren of an object the game names (Hornet's Hornet Saver) */+void vm_activate_children(uint16_t name, bool on) {+ for (int o = 0; o < vm.nobjs; o++)+ if (vm.rec[o].name == name && !(vm.objs[o].flags & OF_COND_OFF))+ for (int c = 0; c < vm.nobjs; c++)+ if (vm.rec[c].parent == o) obj_set_active(c, on);+}++/* (a spell's box: the triggers it is in, this step) */+void vm_spell(float x0, float y0, float x1, float y1) {+ for (int i = 0; i < vm.nobjs; i++) {+ const ObjRec *r = &vm.rec[i];+ float cx = vm.objs[i].x + r->bx, cy = vm.objs[i].y + r->by;+ if ((r->flags & OF_TRIGGER) && x1 > cx - r->bhx && x0 < cx + r->bhx && y1 > cy - r->bhy && y0 < cy + r->bhy)+ vm.objs[i].flags |= OF_SPELL_HIT;+ }+}+/* ---------------------------------------------------------------- states */static void enter_state(Fsm *f, int s) {const uint8_t *st = d_state(f->def, s);@@ -1018,8 +1118,8 @@ void vm_enter(void) {Obj *o = &vm.objs[i];o->x = r->x, o->y = r->y, o->sx = r->sx, o->sy = r->sy;o->flags = r->flags & (OF_ACTIVE | OF_RENDERER | OF_COLLIDER);- /* (DeactivateIfPlayerdataTrue, False) */- if (r->cond != NONE && pd_flag(r->cond & 0x7FFF) == ((r->cond & 0x8000) != 0)) o->flags &= (uint8_t)~OF_ACTIVE;+ /* (DeactivateIfPlayerdataTrue, False; or a scene loaded with the room's by a bool, not now) */+ if (r->cond != NONE && pd_flag(r->cond & 0x7FFF) == ((r->cond & 0x8000) != 0)) o->flags = OF_COND_OFF;o->anim.clip = -1, o->anim.sprite = -1;}const uint8_t *p = vm.map + 4 * nmap;@@ -1036,6 +1136,11 @@ void vm_enter(void) {}vm.nfsms = nfsms;vm.prev_keys = g_hero.keys;+ /* (what it holds within the condition's: off too) */+ for (int i = 0; i < nobjs; i++)+ for (int p = vm.rec[i].parent, k = 0; p != NONE && p < nobjs && k < 16; p = vm.rec[p].parent, k++)+ if (vm.objs[p].flags & OF_COND_OFF) vm.objs[i].flags = OF_COND_OFF;+ obj_colliders();anims_start();for (int i = 0; i < nfsms; i++)if (obj_active(vm.fsms[i].owner)) fsm_start(&vm.fsms[i]);@@ -1046,9 +1151,12 @@ void vm_tick(void) {/* the Knight in the objects' triggers */for (int i = 0; i < vm.nobjs; i++) {Obj *o = &vm.objs[i];- o->flags = (uint8_t)((o->flags & ~OF_WAS_INSIDE) | ((o->flags & OF_INSIDE) ? OF_WAS_INSIDE : 0));- bool in = (vm.rec[i].flags & OF_TRIGGER) && (o->flags & OF_COLLIDER) && obj_active(i) && hero_box_in(i);- o->flags = (uint8_t)(in ? o->flags | OF_INSIDE : o->flags & ~OF_INSIDE);+ o->flags = (uint16_t)((o->flags & ~(OF_WAS_INSIDE | OF_SPELL_WAS)) | ((o->flags & OF_INSIDE) ? OF_WAS_INSIDE : 0) |+ ((o->flags & OF_SPELL_IN) ? OF_SPELL_WAS : 0));+ bool on = (vm.rec[i].flags & OF_TRIGGER) && (o->flags & OF_COLLIDER) && obj_active(i);+ bool in = on && hero_box_in(i), spell = on && (o->flags & OF_SPELL_HIT);+ o->flags = (uint16_t)((in ? o->flags | OF_INSIDE : o->flags & ~OF_INSIDE) & ~OF_SPELL_HIT);+ o->flags = (uint16_t)(spell ? o->flags | OF_SPELL_IN : o->flags & ~OF_SPELL_IN);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);@@ -1070,6 +1178,16 @@ void vm_tick(void) {o->x += m->vx * DT;}for (int i = 0; i < vm.nfsms; i++) fsm_step(&vm.fsms[i], M_FIXED);+ /* (tweens: iTween's Update) */+ for (int k = 0; k < MAX_MOVERS; k++) {+ Mover *m = &vm.movers[k];+ if (m->obj < 0 || m->tween != 1) continue;+ m->tt += DT;+ float q = m->ttime > 0 ? m->tt / m->ttime : 1;+ if (q >= 1) q = 1, m->tween = 2;+ float e = ease(m->ease, q);+ obj_move(m->obj, m->tx + m->tdx * e, m->ty + m->tdy * e);+ }for (int i = 0; i < vm.nfsms; i++) fsm_step(&vm.fsms[i], M_UPDATE);vm.prev_keys = g_hero.keys;if (vm.title_start) {@@ -1105,7 +1223,7 @@ void vm_debug(void) {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);+ printf(" obj %d name %d flags %d active %d cols %d+%d at %.2f,%.2f clip %d sprite %d\n", i, vm.rec[i].name, vm.objs[i].flags,+ obj_active(i), vm.rec[i].col0, vm.rec[i].ncol, vm.objs[i].x, vm.objs[i].y, vm.objs[i].anim.clip, vm.objs[i].anim.sprite);}#endifdiff --git a/games/hollowknight/tests/play.c b/games/hollowknight/tests/play.cindex d8bfb01f..736d5954 100644--- a/games/hollowknight/tests/play.c+++ b/games/hollowknight/tests/play.c@@ -58,6 +58,7 @@ int main(int argc, char **argv) {if (getenv("HKHEALTH")) g_pd.health = (int8_t)atoi(getenv("HKHEALTH"));if (getenv("HKGEO")) g_pd.geo = atoi(getenv("HKGEO"));if (getenv("HKFIRE")) g_pd.fireball_level = atoi(getenv("HKFIRE"));+ if (getenv("HKHORNETGP")) g_pd.hornet_greenpath = (uint8_t)atoi(getenv("HKHORNETGP"));for (const char *f = getenv("HKFLAGS"); f && *f;) { /* (PlayerData bools on, by number: "7,8") */pd_set_flag(atoi(f), true);while (*f && *f != ',') f++;@@ -100,6 +101,9 @@ int main(int argc, char **argv) {printf("%4d keys %02x pos %.3f,%.3f v %.3f,%.3f state %d ground %d jump %d fall %d clip %d frame %d cam %.2f,%.2f\n", tick,keys, g_hero.body.x, g_hero.body.y, g_hero.body.vx, g_hero.body.vy, g_hero.state, g_hero.cs.on_ground,g_hero.cs.jumping, g_hero.cs.falling, g_hero.anim.clip, g_hero.anim.frame, g_cam_x, g_cam_y);+ if (trace && getenv("HKCONTACTS"))+ for (int c = 0; c < g_hero.body.ncontacts; c++)+ printf(" contact col %d n %.2f,%.2f\n", g_hero.body.ccol[c], g_hero.body.cnx[c], g_hero.body.cny[c]);if (trace && getenv("HKSTATS")) printf(" health %d blue %d mp %d geo %d\n", g_pd.health, g_pd.health_blue, g_pd.mp, (int)g_pd.geo);if (trace && getenv("VMDEBUG")) {extern void vm_debug(void);diff --git a/games/hollowknight/tools/coll.py b/games/hollowknight/tools/coll.pyindex 78ae9267..b4774a90 100644--- a/games/hollowknight/tools/coll.py+++ b/games/hollowknight/tools/coll.py@@ -98,13 +98,17 @@ def path_key(d):return key+# objects off in the scene whose colliders the scripts turn on (ActivateAllChildren): there, off at first+SWITCHED = {"Hornet Saver/Colliders"}++def room(d, w, h):"""-> (solid tiles of the tilemap, segments [(x0, y0, x1, y1, collider)], colliders [flags], each collider's objectid); collider 0 is the tilemap's. An object's subtree has consecutive colliders (subtree_colliders)."""segs, cols, owners = [], [CF_SOLID | CF_TERRAIN], [0]tm_edges = []for o in sorted(d["objects"], key=path_key(d)):- if not o["active"] or o["layer"] not in SOLID_LAYERS:+ if (not o["active"] and o["path"] not in SWITCHED) or o["layer"] not in SOLID_LAYERS:continueif "TileMap Render Data/" in o["path"]:for c in o["c"]:diff --git a/games/hollowknight/tools/ents.py b/games/hollowknight/tools/ents.pyindex 1c2a9aa5..fb60d4bd 100644--- a/games/hollowknight/tools/ents.py+++ b/games/hollowknight/tools/ents.py@@ -746,7 +746,10 @@ def _gate(d, o, owners):m = np.array(o["m3"]).reshape(3, 3)sx = float(np.hypot(m[0, 0], m[1, 0])) * (-1.0 if np.linalg.det(m[:2, :2]) < 0 else 1.0)sy = float(np.hypot(m[0, 1], m[1, 1]))- return rec(ENT_OBJ, OK_BGATE, (o["pos"][0], o["pos"][1], o["pos"][2], sx), (sy, pd, 0, 0), a=c0, group=cn, s0=fl)+ import vm+ # (p2: its name, as the scripts' strings number it: FindGameObject)+ return rec(ENT_OBJ, OK_BGATE, (o["pos"][0], o["pos"][1], o["pos"][2], sx), (sy, pd, vm.STR.id(o["name"]), 0), a=c0,+ group=cn, s0=fl)def room(d, rooms, strings, persist, name, sprites=None, owners=None, rec_base=0, col_base=0, group_base=0):diff --git a/games/hollowknight/tools/pack.py b/games/hollowknight/tools/pack.pyindex b111b36d..316454de 100644--- a/games/hollowknight/tools/pack.py+++ b/games/hollowknight/tools/pack.py@@ -19,6 +19,7 @@ TEXTS = text.Texts()PROMPTS = ["Listen", "Rest", "Inspect", "Enter", "Sit", "Shop", "Travel", "Ascend", "Descend", "Exit", "Accept", "Trade","Watch", "Challenge"]ROOM_DATA = {} # name -> (coll.room's, ents.room's)+ROOM_OWNERS = {} # (name, variant) -> each collider's owner: (scene, object id)def room_data(name, variant=0):@@ -34,6 +35,7 @@ def room_data(name, variant=0):recs, gr = ents.room(d, ROOMS, STRINGS, PERSIST, name, SPRITES, owners)groups = {(name, k): g for k, g in gr.items()}segs, cols, recs = list(segs), list(cols), list(recs)+ own = [(name, oid) for oid in owners]gb = max(gr.values(), default=0)spans = {}for an, flag, val, which in scene.additive(name):@@ -49,9 +51,11 @@ def room_data(name, variant=0):if (which == 1) == (variant == 0):segs += [(x0, y0, x1, y1, ci + len(cols)) for x0, y0, x1, y1, ci in asegs]cols += acols+ own += [(an, oid) for oid in aown]recs += arassert gb < ents.MAX_GROUPS, (name, gb)ROOM_DATA[(name, variant)] = ((solid, segs, cols, owners), (recs, groups), spans)+ ROOM_OWNERS[(name, variant)] = ownreturn ROOM_DATA[(name, variant)]SECTIONS = ["TEX", "PAL", "TDAT", "ROOMS", "RBLOB", "PRIOR", "SOFT", "SPR", "CLIP", "STR", "TEXT", "FONT", "PHASH",@@ -491,10 +495,10 @@ def main():if r in VARIANT_ROOMS:room_data(r, 1)clip_index = {c["id"]: i for i, c in enumerate(clips)}- vm_rooms = [vm.room_blob(r, clip_index, SPRITES) for r in ROOMS]+ vm_rooms = [vm.room_blob(r, clip_index, SPRITES, ROOM_OWNERS.get((r, 0), [])) for r in ROOMS]sheet = text.sheets()["Prompts"]vm_prompts = {s: TEXTS.id("Prompts", s.upper(), "PROMPT") for s in vm.STR.list if s.upper() in sheet}- for s in ("NPC Title", "Visited", "Display Right"):+ for s in ("NPC Title", "Visited", "Display Right", "Hornet Saver"):vm.STR.id(s)sprites += actors.unity_sprites(SPRITES.list)# the HUD's geo count: TrajanPro-Bold digits (TextMesh: size 45, character size 1, scale 0.1527)@@ -695,9 +699,9 @@ def main():f.write("#define DIGIT_ADV {%s}\n" % ", ".join("%.4ff" % a for a in digit_adv))for name, (code, _) in vm.OPS.items():f.write("#define VMOP_%s %d\n" % (name.upper(), code))- for i, e in enumerate(vm.EVENTS.list[:15]):+ for i, e in enumerate(vm.EVENTS.list[:vm.FIXED_EVENTS]):f.write("#define VMEV_%s %d\n" % (e.upper().replace(" ", "_"), i))- for name in ("NPC Title", "Visited", "Display Right"):+ for name in ("NPC Title", "Visited", "Display Right", "Hornet Saver"):f.write("#define VMSTR_%s %d\n" % (name.upper().replace(" ", "_"), vm.STR.index[name]))for name, i in str_ids.items():f.write("#define STR_%s %d\n" % (name.upper().replace(" ", "_"), i))diff --git a/games/hollowknight/tools/vm.py b/games/hollowknight/tools/vm.pyindex 34732e8d..04f9cfb1 100644--- a/games/hollowknight/tools/vm.py+++ b/games/hollowknight/tools/vm.py@@ -11,6 +11,7 @@ import unity, text, state# rooms -> the objects whose scripts run here (and all under them)ROOMS = {"Town": ["_NPCs/Elderbug"],+ "Fungus1_04": ["Hornet Infected Knight Encounter", "Hornet Saver"],"Crossroads_ShamanTemple": ["_Props/Shaman Meeting", "_Props/Shaman Trapped", "_Props/Shaman Killed Blocker","_Props/Knight Get Fireball", "Battle Scene/Reminder Cast"],}@@ -28,7 +29,7 @@ SPECIAL = {"Hero": 0xFF00, "HeroLight": 0xFF01, "DialogueManager": 0xFF02, "DialO_NONE = 0xFFFF# PlayerData ints (src/vm.c: pd_int)PD_INTS = ["MPCharge", "health", "maxHealth", "geo", "fireballLevel", "quakeLevel", "screamLevel", "shaman", "elderbug",- "permadeathMode", "nailDamage"]+ "permadeathMode", "nailDamage", "hornetGreenpath"]# PlayerData bools kept elsewhere (src/vm.c)PD_SPECIAL = {"disablePause": 0xFFF0, "hasSpell": 0xFFF1}# PlayerData bools that keep their new game value all through this part of the game@@ -61,8 +62,9 @@ STR = Strings()EVENTS = Strings()for e in ("FINISHED", "CONVO_FINISH", "CONVO START", "CONVO END", "BIG TITLE START", "BIG TITLE END", "HERO DAMAGED","NPC TITLE DOWN", "NPC CONVO START", "BOX UP", "BOX DOWN", "LEAVING SCENE", "TAKE DAMAGE", "GET ITEM MSG END",- "HORNET LEAVE"):+ "HORNET LEAVE", "BG CLOSE", "BG QUICK CLOSE", "BG OPEN", "BG QUICK OPEN", "BG DESTROY", "WAKE"):EVENTS.id(e)+FIXED_EVENTS = len(EVENTS.list) # (src/data.h: VMEV_*)# ---------------------------------------------------------------- the actions it runs: name -> (opcode, operands)# operand kinds: f i b s o value slots (u16), F I B S O V output variables (u8: 255 none), e event (u8), t event target,@@ -145,7 +147,7 @@ op("Tk2dPlayAnimationWithEvents", ("gameObject", "o"), ("clipName", "s"), ("animop("Tk2dWatchAnimationEvents", ("gameObject", "o"), ("animationTriggerEvent", "e"), ("animationCompleteEvent", "e"))op("Tk2dPlayFrame", ("gameObject", "o"), ("frame", "i"))op("Tk2dSpriteGetId", ("gameObject", "o"), ("spriteID", "I"), ("everyframe", "n"))-op("Trigger2dEvent", ("trigger", "n"), ("sendEvent", "e"))+op("Trigger2dEvent", ("trigger", "n"), ("sendEvent", "e"), ("tag", "n"))op("ListenForUp", ("wasPressed", "e"), ("isPressed", "e"))op("ListenForDown", ("wasPressed", "e"), ("isPressed", "e"))op("ListenForLeft", ("wasPressed", "e"))@@ -173,6 +175,8 @@ op("BlankerOn", ("on", "b"))op("FindGameObject", ("objectName", "s"), ("store", "O"))op("SetParent", ("gameObject", "o"))op("IntOp", ("intVariable", "I"), ("value", "i"))+op("ActivateAllChildren", ("gameObject", "o"), ("activate", "b"))+op("iTweenMoveBy", ("gameObject", "o"), ("vector", "v3"), ("time", "f"), ("easeType", "n"), ("finishEvent", "e"))# HeroController's methods the scripts call (HeroCall's method)HERO_METHODS = ["RelinquishControl", "RegainControl", "StopAnimationControl", "StartAnimationControl", "FaceLeft",@@ -181,6 +185,10 @@ HERO_METHODS = ["RelinquishControl", "RegainControl", "StopAnimationControl", "S"SetCState", "SaveGame", "AffectedByGravity", "ResetHardLandingTimer", "StopPlayingAudio"]# prefabs CreateObject makes that the scripts go on with (made beforehand, off): (file, path id)PREFAB_SPAWNS = {("sharedassets76.assets", 69)}+# the game's objects the scripts find by name that are not theirs (enemies): what they are to them+GAME_OBJECTS = {"Hornet Boss 1": 0xFF0C}+# what a trigger's Trigger2dEvent hears, by collideTag: the Knight (any), a spell+TRIGGER_TAGS = {None: 0, "": 0, "Player": 0, "Untagged": 0, "Hero Spell": 1}# the items the message shows (text.MSGS's order), by Msg Control's ItemMSG_ITEMS = {"Fireball": 0}# camera shake events@@ -194,6 +202,26 @@ class Room:self.sprites, self.texts, self.actor_of = sprites, texts, actor_ofself.by_id = {o["id"]: o for o in d["objects"]}self.by_path = {o["path"]: o for o in d["objects"]}+ for o in d["objects"]:+ o["_scene"], o["_raw"] = name, o["id"]+ # (the scenes it loads with it, the first of them: their objects there only as they are, by a PlayerData bool)+ import scene+ for an, flag, val, which in scene.additive(name):+ if which != 1:+ continue+ da = unity.scene(an)+ ids = {q["id"] for q in da["objects"]}+ k = lambda i, an=an: ("sc", an, i)+ for q in da["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"], c["_scene"], c["_raw"] = da, k, an, q["id"]+ if c["parent"] is None:+ c["_variant"] = (flag, val)+ self.by_id[c["id"]] = c+ self.by_path.setdefault(q["path"], c)self.objs, self.obj_index = [], {}self.fsms = []self.problems = []@@ -481,6 +509,9 @@ class Compiler:if n == "SetSpriteRenderer" and P.get("gameObject") == "$HUD Blanker":return self.emit("BlankerOn", {"on": P.get("active")})if n == "FindGameObject":+ if P.get("objectName") in GAME_OBJECTS:+ return self.emit("SetGameObject", {"variable": P.get("store"),+ "gameObject": ("objindex", GAME_OBJECTS[P.get("objectName")])})if P.get("objectName"):return self.emit("FindGameObject", P)return None # (by tag: the main camera)@@ -530,6 +561,8 @@ class Compiler:if evn in SHAKES:return self.emit("Shake", {"kind": SHAKES[evn]})return None+ if go == "$AudioManager":+ return None # (music)if go in ("$DialogueManager",) and evn in ("BOX UP", "BOX DOWN"):return self.emit("SendEventByName", P)return self.emit("SendEventByName" if n == "SendEventByName" else "SendEvent", P)@@ -545,12 +578,19 @@ class Compiler:if P.get("gameObject") == "$Main Camera Obj" or P.get("gameObject") == "$MainCamera":vec = P.get("vector") or [0, 0, 0]return self.emit("CameraZoom", {"z": vec[2], "time": P.get("time"), "delay": P.get("delay") or 0})- self.problem("iTweenMoveBy")- return None+ if P.get("speed") is not None or P.get("loopType") or P.get("space") or P.get("delay") or \+ (P.get("easeType") or 0) > 21:+ self.problem("iTweenMoveBy %r" % P)+ return None+ return self.emit(n, P)if n == "GetScale":return self.emit(n, P)if n == "Trigger2dEvent":- return self.emit(n, {"trigger": P.get("trigger"), "sendEvent": P.get("sendEvent")})+ if P.get("collideTag") not in TRIGGER_TAGS:+ self.problem("Trigger2dEvent tag %s" % P.get("collideTag"))+ return None+ return self.emit(n, {"trigger": P.get("trigger"), "sendEvent": P.get("sendEvent"),+ "tag": TRIGGER_TAGS[P.get("collideTag")]})if n in ("Collision2dEvent", "Collision2dEventLayer"):return self.emit("Collision2dEvent", P)if n in ("ListenForUp", "ListenForDown", "ListenForLeft", "ListenForRight", "ListenForAttack", "ListenForJump",@@ -693,13 +733,15 @@ def prepare(rooms, sprites, texts):known[lib] = a-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+OBJ = "<fffffffffHHHHHBBHHhHBBH" # 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, blend, its+# colliders (first, count)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):- """A room's VM data (src/vm.c): counts, its objects, their clip maps, its FSMs (definition, owner, name, variables)."""+def room_blob(name, clip_index, sprites, owners=()):+ """A room's VM data (src/vm.c): counts, its objects, their clip maps, its FSMs (definition, owner, name, variables).+ owners: each collider's (scene, object id): the colliders an object has, the scripts turn on and off with it."""import actors, ents, tk2drm = BUILT.get(name)if rm is None:@@ -755,6 +797,14 @@ def room_blob(name, clip_index, sprites):for bn, off_if in state.conditions(o):if bn in pdf:cond = pdf[bn] | (0x8000 if off_if else 0)+ if o.get("_variant"):+ # (a scene loaded with the room's by a PlayerData bool: there only when it has that value)+ bn, val = o["_variant"]+ assert cond == 0xFFFF, o["path"]+ cond = pdf[bn] | (0 if val else 0x8000)+ cols = [k for k, ow in enumerate(owners) if k and ow == (o.get("_scene", name), o.get("_raw", o["id"]))]+ assert cols == list(range(cols[0], cols[-1] + 1)) if cols else True, o["path"]+ assert len(cols) < 256 and (not cols or cols[-1] < 256), o["path"]layer, order = ents._sorting(o)# (its material's blend: pack.BLENDS)import scene@@ -766,7 +816,8 @@ def room_blob(name, clip_index, sprites):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, blend)+ STR.id(o["name"]), sprite, first, start, min(count, 255), fl, cond, layer, order, blend,+ cols[0] if cols else 0, len(cols), 0)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)