Modding Himegari
Himegari-specific facts for the generic guides. The identity block (game id, engine ABI, modules, tables, patch points) is generated in README.md.
Install and options
Section titled “Install and options”- Expected install:
games/himegari/beside the repository.Ome.Cliuses it by default, so Himegari commands need no game options. Pass--game-root DIRfor another location. - Port:
.\run-godot.cmd, with-Mod PATHfor a mod. - Driver:
py -3.11 -X utf8 tools/drive.py port start --mod PATH(nativefor AGE). Named points such asadv.next,title.startandnewgame.beginare predefined. - Registries for fragments:
py -3.11 -X utf8 tools/globals_build.py --buildandpy -3.11 -X utf8 tools/patch_points_build.py --build.
First mod values
Section titled “First mod values”The values for first-mod.md, on the opening scene SC0000.BIN:
| Step | Value |
|---|---|
| Page | The third page. Its locator reads SC0000 P003 · wait SC0000@0x8a6 · text SC0000@0x89e. |
| Site | 0x877: the reset-adv-text-layout after page 2’s wait (0x871) and end-text-line (0x874). |
| Fingerprint | sha256:029718d6c927f90f6dcb1b89851591be310b5889dd53d6c8892604ad1fc9a9f6 |
oms 1patch "SC0000.BIN" fingerprint "sha256:029718d6c927f90f6dcb1b89851591be310b5889dd53d6c8892604ad1fc9a9f6"use himegari.globalsuse himegari.adv
before site 0x877 { "[MOD] Hello from my first mod."}The finished mod is oms/examples/mods/example.sc0000-page3. example.sc0000-page4 inserts before the fourth
page (site 0x8ac) and composes with it. example.sc0000-merge replaces pages 3 and 4 (0x874 through 0x8de) and
conflicts with both.
Dialogue lines
Section titled “Dialogue lines”The prelude’s template is line(text, speaker = none, voice = none):
"――かつて、戦いがあった。" // narration魔王 "「元の台本は、一文字も書き換えられていない。」" // a speaker魔王 "「…」" (voice: 0x34e) // with a voice clipSpeakers are CNINIT’s character names (enum speaker in oms/himegari/adv.oms). Names that repeat, or that are
not identifiers such as ????, carry their id (speaker_0x10).
Data edits
Section titled “Data edits”A data file (../data-files.md) changes the unit, item and skill tables, and each stage’s
enemies, with no Lua and no script. himegari-base accepts the kind himegari.tables. It applies each file’s boot
tables at himegari.data.layered, after every layer has written them and before TUNE reads them, and a stage’s part
at himegari.stage.loaded, each time FIELD has run the stage’s loaders. This one raises the experience unit 103
gives; the comment gives the game’s own value:
# data/rewards.toml; the manifest names it with [[data]] kind = "himegari.tables", file = "rewards.toml"[unit.103]experience_reward = 40 # 30-
Tables and fields are those of
../../global-reference.md, “Tables”, by the names in itsfieldcolumn:unit(records 0 to 999),item(0 to 999),skill(0 to 299),stage_catalog(0 to 999, STINIT2’s stages),condition(0 to 29, ILINIT),element(0 to 15, AFINIT’s defense elements),character_profile(0 to 99),glossary_entry(0 to 199),magic_action(0 to 29),recipe(0 to 999, ALINIT),card(0 to 99, CDINIT2),training_action(0 to 20, TRINIT),terrain(0 to 29, LAINIT),object_type(0 to 99, OBINIT) andmap_texture(0 to 19, LAINIT’s default floor sheets). A field with a row takes its columns by the names the reference gives (stat_modifiers.max_fs), and by number only where a column has no name. Two of the reference’s tables are not ones a file writes, and the shape refuses them:class_change, the block CALCCC’s rules (CCINIT) fill for one unit at a time, andcard_list_entry, the card list CDINIT builds each time a card object is used. Their contents are those scripts’ code, which an OMS patch changes. -
Saved fields are refused:
unit.story_speaker_seen_flag,skill.acquired_flag,skill.info_revealed_flag,training_action.execution_countandtraining_action.unlock_flag. They lie below the saved prefix, so a load would bring the saved value back over the edit. -
The shape.
himegari-baseships the kind’s shape,shapes/tables.schema.json, generated from the same record map as the tables above (../data-files.md, “Shapes”). So the link,omp checkandomp buildrefuse a table, field or column the reference does not name, a saved field, an id or a column out of range and a value of the wrong kind, with the file’s line, before the game starts.omp lua-stubswrites a copy,himegari.tables.schema.json, and prints the#:schemaline that points an editor at it. Text that code page 932 cannot encode passes the shape;himegari-baserefuses it at the file’s first delivery. -
TUNE corrects the save against the edited items. It lowers each saved tuning level to the last level its item’s curve gives a bonus for (below, “Edit the boot’s tables at
data.layered”). A file that gives an item a shorter curve (item.tuning_curve_ids) lowers that item’s saved levels, and they stay lowered when the mod is removed. -
A unit keeps a copy of its definition. When a unit joins, UNITECH copies part of its definition into its saved state, which the game uses from then on. An edit to these fields reaches a unit that joins after it, not one that has joined, and what was copied while the mod was on stays in the save when the mod is removed. UNITECH takes the unit through
unit.canonical_idandunit.roster_variant_idsfirst, and makes the first join’s copies for a unit below 100 whoseunit_current_levelsis 0 (UNITECH@0x2cf,0x2e4); a form change in 配下 (SALLY’s first two actions) makes the same copies for a form used for the first time.example.unit-statsraises リリィ’s maximum HP:tools/drive/scenarios/port/himegari-unit-stats.stepsshows her saved stats take it at a new game, andhimegari-unit-stats-load-without.stepsthat a save made then keeps it without the mod.Field Saved value When unit.canonical_id,unit.roster_variant_idsthe unit a party slot holds ( party_slot_character_id)each join ( UNITECH@0x2ab) and each form change (SALLY@0x1668)unit.starting_levelunit_current_levelsthe first join ( UNITECH@0x34b) and a form’s first use (SALLY@0x16aa)unit.statsunit_current_stats, all 14 columnsthe same ( UNITECH@0x37c,SALLY@0x16db)unit.starting_skillunit_skill_idsthe same ( UNITECH@0x3a3,SALLY@0x1702); and FORT (SYSTEM4’s mode 2) gives the unit it shows each skill of the row the game has not acquired yet (skill_acquired_flags,FORT@0x3e7to0x42a, through ADDSKILL)unit.starting_equipment_item_idthe party slot’s item ( G[0x6868], unnamed), and the item itselfthe slot’s item at the first join ( UNITECH@0x338); the item, through ADDITEM, at each join that equips (UNITECH@0x27f)unit.stat_growthunit_current_statsandunit_stat_growth_fractionsthe first join, for each level it adds past the starting level ( UNITECH@0x419), and each level up (ADDEXP@0x20b). The rate is read each time, so an edit changes later levels’ growth, and the growth already added stays -
The battle entities are copies too. When FIELD places a unit, SETEN (an enemy) or SETCH (a party unit) writes its battle entity (the
entity_*arrays) from the tables: an enemy’s level from its slot’smin_level,max_levelandauto_level_scale_divisorand the unit’sstarting_level,level_capandauto_level_scale_divisor, its stats fromunit.statsandunit.stat_growth, and its routines (movement_routine_set,battle_routine_set), carried item (starting_equipment_item_id), attack (default_attack_item_id) and class title (initial_class_title); a party unit’s stats come from its saved copy above. CALCREVISE works out an entity’s effective stats and ranges from its equipment and skills (item.stat_modifiers,min_range,max_rangeandgranted_skill_id,skill.min_range_encodedandmax_range_encoded) each time the game calls it, among others when a unit is placed, levels up, or uses an item or a spell. The entities are saved, so a save made on a stage keeps them as they were placed and worked out, with the mod or without it. -
Play keeps its results, as it does without a mod: while the mod is on, an edit changes what an action gives or costs, and the result is saved.
item.essence_recovery_amountis added to the user’s side’s essence when the item is used (USEITEM@0x2fb; the player’s iscurrent_spirit);unit.summon_point_costis taken fromshared_spendable_pointsat a summon (SUMMON@0xe13);unit.essence_yieldis added tocurrent_spirit, with a change tofamiliar_alignment, when 配下 releases a unit (SALLY@0xd12,0xd49);unit.experience_rewardsets the experience a battle awards (BTL@0x366e, which ADDEXP adds throughG[0x62ccb], unnamed), and the levels and growth that follow are saved; and an item of the beaten unit’sunit.drop_itemrow is added to the inventory when the battle drops it (BTL@0x3939, through ADDITEM). The same holds for the base’s actions and the map’s cards: a synthesis takes arecipe’s ingredients andpoint_costand gives its output item (ALCHEMY@0x13d8to0x144e); atraining_actiontakes itsspirit_deltaand adds itsstat_deltas,alignment_deltaandprogress_deltato the familiar’s saved stats and counters, and gives itsawarded_skill_idandawarded_item_idon its first execution (TRAIN@0x7eeto0xdad); amagic_action’scostis taken from the spirit or the points (FIELD@0x86f0,STUDY@0x8ce,EVOLVE@0x933) and itsfacility_progress_gainadded to a facility’s progress (USEMAGIC@0x711,STUDY@0x92d); and a drawncardadds itsclear_point_bonusto the stage’s saved bonus (FIELD@0x68d5), its recoveries and damage to the unit’s resources and the spirit, its item to the inventory and itscondition_idto the unit (FIELD@0x6748to0x6998). -
A class change is copied into the save. CALCCC adds up the title-change rules that fire for a unit and copies the result into its saved state: its class title, deployment cost, stats and skills (
CALCCC@0x68to0x1b2). The rules are CCINIT’s code, not a table, so a file does not reach them. -
A condition’s turns are copied when it takes. ADDILLSUB copies the
condition’sduration_turnsfor the level reached into the unit’s battle entity (entity_condition_remaining_turns,ADDILLSUB@0x174), which is saved with the other entities; itsstat_deltasandresource_deltasare read each time they apply. -
Every other field is read where the game uses it, so an edit reaches a save made before it. These lists come from a scan of the installed scripts that follows each field’s value through a script’s locals and block copies into a cell the save keeps, and into a global it leaves for a script it calls or takes back from one, and from reading each cell it found. The scan does not follow a value left in a global for a script that runs later without being called there (another screen), so a copy made that way can be missing.
-
A stage’s enemies are the
stage_enemytable, which a file names through the stage:stage.1.enemy.2is stage 1’s enemy slot 2 (stage ids 1 to 999, of which STINIT writes 1 to 170; slots 0 to 29, and no stage gives slot 0 a unit). Its fields are the reference’s:unit_id(0 for an empty slot),min_level,max_level,auto_level_scale_divisor, the spawn (spawn_tile_xandspawn_tile_y, orspawn_object_slot),faction_id,difficulty_mask,first_clear_only,random_selection_weight, and four rows whose columns are given by name:movement_routine_set_idsandbattle_routine_set_ids(difficulty_0todifficulty_2),required_story_flags(required_flag_1torequired_flag_7) andforbidden_story_flags(forbidden_flag_1toforbidden_flag_5). None of them is saved. OMS names the slots of the stage being played (stage_enemy[2].unit_id), as the loaders leave them. This file puts another unit in stage 1’s slot 2:data/stages.toml [stage.1.enemy.2]unit_id = 810 # 200, 緑プテテット; 810 is ハルピュア -
A stage’s goals are the
stage_goaltable, one record, which a file names through the stage asstage.1.goal.0:victory_condition_1,victory_condition_2,defeat_condition_1anddefeat_condition_2, the lines AIM shows. STINIT writes them for the stage it loads. FIELD copies them into the lines the stage shows at its start (FIELD@0x308, GS0x27ato0x27d, unnamed), and a stage’s handlers (READY, ROUND) rewrite both as it goes, so the shown lines are saved: a save made on a stage keeps the lines it showed, with the mod or without it. -
A stage’s map objects are the
stage_objecttable, slots 0 to 49 (no stage writes slot 0), which a file names through the stage asstage.1.object.3:tile_x,tile_y,type_id(anobject_typeid), the two payloads, whose meaning the type gives (a chest’s item and count, a teleporter’s destination tile, a card object’s list), the reinforcement fields,difficulty_mask, the story gates anduse_story_flag_id. None of them is saved, but the save keeps two things by stage and slot, not by type: each slot’s uses (stage_object_use_counts) and its state (stage_object_runtime_state). FIELD copiesprimary_payloadinto that state for the types whose picture follows it (bases, pillars, doors and hazards) only on a fresh entry to a stage not yet cleared (FIELD@0x4d7to0x54c), so an edit to a pillar’s first owner does not reach a cleared stage, and a slot whose type an edit changes keeps the old slot’s uses and state. A player unit’s use sets the story flaguse_story_flag_idnames, which is saved (FIELD@0x5434). The stage’s floor sheets arestage.1.texture.<slot>(asset_override: a picture id, -1 for the slot’smap_texture, 0 for none), which FIELD loads after the loaders run (FIELD@0x9106). -
Terrain and object types are read where they are used: a stage’s saved terrain grid holds terrain ids, copied from MPINIT’s atlas on a fresh entry, and each
terrainandobject_typefield is read by id when the game draws, moves, fights or triggers an object, so an edit reaches a save made on a stage. One use is copied: on a fresh entry FIELD marks the tiles oflayout_class1 (every class but 0 on a fully conquered stage) in two saved tile tables,tile_faction_traversal_masksandG[0x7a6c](unnamed; DRAWOBJ shows an object only on a marked tile), so an edit to a class reaches those marks at the next fresh entry (FIELD@0x404to0x4cf). -
The names are read where they are shown, and none is saved: an item’s and a skill’s
nameandshort_description, and a stage’snameanddescription(six lines, of which SELSTAGE shows the first three before the stage is cleared and the last three after). One copy is: FIELD copies the stage’snameinto the title it shows (FIELD@0x211, GS0x278, unnamed), which a save made on a stage keeps. -
The stage part holds through the stage. FIELD runs the stage’s loaders at its start, before it places the units, and again each time it is entered again during the stage (below, “FIELD runs the loaders more than once a stage”), and the part is applied after each run. So the edit changes what the stage places, and ADDEN, which places a slot later when a stage’s handler calls it, reads the edited slot too. The placed units are saved (
entity_unit_definition_ids): a save made on the stage with the mod and loaded without it has the stage’s own table again, and the unit the edit placed is still on the field. -
Old names. No table or field has been renamed yet. When one is, the old name keeps working until
himegari-base’s next major version, anddiagnostics/lua.lognames each old name a file uses.
Patch points
Section titled “Patch points”himegari.experience.after_calculation (ADDEXP.BIN) is reached once per experience award, after the multipliers.
L[0x1] holds the amount the unit receives:
oms 1patch "ADDEXP.BIN" fingerprint "sha256:b4f38c43f2c500012be48517ce773d3c9e81c12deeb4d712cab4b99749661e1c"use himegari.globals
local int exp @ 0x1
before site himegari.experience.after_calculation { exp = exp * 2}The same in Lua (../lua.md), as oms/examples/mods/example.double-exp-lua ships it: a hook on the point
and a handler that doubles the local. It leaves the same state as the patch.
[[hooks]]point = "himegari.experience.after_calculation"handler = "double_exp.lua:on_award"function on_award(ctx) maid.vm.l[0x1] = maid.vm.l[0x1] * 2endGame names (../lua.md, “Game names”) come from himegari-base. A mod that requires it reads
require("himegari-base").g.stage_turn_limit or .table("unit_current_levels")[unit] without vm, and writes
them once its [lua] writes lists them. The names are those of ../../global-reference.md.
himegari-base declares seven game events (../lua.md, “Game events”). The experience award is raised at
the experience point:
| Event | Field | Type | Access | Cell |
|---|---|---|---|---|
himegari.experience.award |
amount |
int | rw | L[0x1], the experience the unit receives |
unit |
int | r | current_unit_id |
|
level |
int | r | unit_current_levels[current_unit_id] |
A subscriber needs no vm. oms/examples/mods/example.double-exp-event doubles every award with
event.amount = event.amount * 2, and leaves the same state as the patch above.
The other six follow the boot and each stage. Each is raised where INIT2 or FIELD has walked the chain the appends register their handlers in, so a handler runs after the base game’s and every append’s. Their fields are read-only:
| Event | Raised | Fields |
|---|---|---|
himegari.data.layered |
himegari.boot.data_layered (INIT2, before TUNE): every layer has written its tables, the appends’ included, and the boot has not used them yet |
none |
himegari.data.ready |
himegari.boot.data_ready (INIT2’s exit): every data table is built, and TUNE has corrected the save against them |
none |
himegari.stage.loaded |
himegari.stage.after_loader (FIELD): the stage’s loaders have run, and a data file’s stage part is applied |
stage (current_stage_id) |
himegari.stage.ready |
himegari.stage.after_ready_handlers: once per stage, at its start, with the units placed |
stage |
himegari.stage.round |
himegari.stage.after_round_handlers: each player turn after the first |
stage, turn (current_stage_turn) |
himegari.stage.close |
himegari.stage.after_close_handlers_won and _lost: the stage ends |
stage, result (stage_result: 1 won, 2 lost), turn |
- Edit the boot’s tables at
data.layered. An edit there lands where an append’s edit lands, and TUNE then runs over it as it runs over the appends’. TUNE lowers each saved tuning level to the last level its item’s curve gives a bonus for (item_tuning_curve_ids,item_tuning_stat_bonus_curves), and raises eachitem_inventory_countscell to the party’s items. An edit atdata.readycomes after that, so TUNE does not correct the save against it: a saved tuning level could then lie past a curve the edit shortened. The correction TUNE makes against an edit is in the save from then on, and stays when the mod is removed. - Data files are applied at
data.layered, among its handlers in load order. A handler atdata.readyruns after every data file, whatever the load order; one that should take its place among them by load order subscribes todata.layered. - The data tables are not saved (they lie above the saved range, below). A load builds the tables again and
raises
data.layeredanddata.readyagain while it restores (maid.session.restoringis true), so the handler makes its edit again. - FIELD runs the loaders more than once a stage.
field_map_continue_modeis 0 at a stage’s start: FIELD runs the loaders, places the units and walks the ready chain. Back from the camp screens (the deploy screen, for one), or at the load of a save made in the field, it is 2 or 3: FIELD runs the loaders again and raisesstage.loadedagain, but places nothing and raises nostage.ready. The loaders write their tables afresh each time, so a handler that rewrites them makes the same change each time. - The stage’s enemies are
stage_enemy_unit_id(30 slots, zero for an empty one), each with its spawn (stage_enemy_spawn_tile_xand_y, orstage_enemy_spawn_object_slot), faction, difficulty mask and replay gate.unit_boss_classis nonzero for a boss. A rewrite at the stage’s start changes what the stage places:oms/examples/mods/example.random-enemiesreplaces each ordinary enemy with one drawn from every ordinary enemy of the game, from a seed it keeps inmaid.state. stage.closecomes after the close chain, which FIELD walks for a result of 1 or 2 before it takes the stage’s SCJUMP decision. Stage 1 lost at its 50-turn limit raises it with result 2 and turn 50.
himegari-base’s helpers (../lua.md, “Game names”):
| Helper | Calls | What it does |
|---|---|---|
give_item(item, count) |
ADDITEM.BIN |
adds count (-99 to 99, 1 when nil) of item item (1 to 999) as the game does: the count stays from 0 to 99, an item gained is marked obtained, and a key item (item_category 1) sets its story flag. It puts back current_item_id and current_item_count_change, and returns item_inventory_counts[item]. |
Catalogs, scenes and saves
Section titled “Catalogs, scenes and saves”- Selectors. The install ships one append catalog (
APPEND01), so a first mod’s catalog normally gets selector 2. - Scene registry. SCJUMP decision 0 is empty in the base game and falls back to SC0000. A mod scene written into
scjump_scene_script_resource_ids[0x0]therefore plays before the opening.oms/examples/mods/example.prologuedoes this, on the skeleton of the shipped append scene$1$SC1260. Saving and loading inside it passed in the port and on native AGE (tools/drive/scenarios/himegari-mod-{save,load}-scene.steps). - Saved range. Saves keep the integer globals below
0x6241band the first 789 string globals. A table cell below that range is restored by loading a save. Check a data edit’s cells against../../global-reference.md. - Free cells. The examples use the string cells
GS[0x1400]andGS[0x1401], which no shipped script uses (oms/examples/himegari-gate6/).
Examples
Section titled “Examples”| Path | What it shows |
|---|---|
oms/examples/mods/example.sc0000-page3, -page4, -merge |
patches that compose or conflict |
oms/examples/mods/example.prologue |
a save-capable scene in an append catalog |
oms/examples/himegari-patch/SC0000.oms |
two inserted pages, with speakers |
oms/examples/himegari-gate6/ |
a boot-time script and a script called by packed id |
oms/examples/mods/example.double-exp-lua |
a Lua point hook on the experience award |
oms/examples/mods/example.double-exp-event |
a Lua subscriber of himegari.experience.award, without vm |
oms/examples/mods/example.lua-random |
math.random in a script hook on SC0000.BIN, inside a pairs loop too; tools/drive/scenarios/port/himegari-lua-random.steps checks that rand-seed 7 gives the same rolls in every run |
oms/examples/mods/example.random-enemies |
a subscriber of himegari.stage.loaded that rewrites the stage’s enemies and keeps a seed per playthrough in maid.state; tools/drive/scenarios/port/himegari-random-enemies.steps checks stage 1’s draw under rand-seed 7 |
oms/examples/mods/example.stage-enemies |
a data file that edits two stages’ enemy slots, applied at himegari.stage.loaded; example.stage-enemies-mistake is its twin with a mistake no shape can say (a unit name code page 932 cannot encode), which the link takes and the boot reports; tools/drive/scenarios/port/himegari-stage-enemies*.steps drive both, through the camp, a field save and its load with the mod and without |
oms/examples/mods/example.unit-stats |
a data file that raises リリィ’s maximum HP, which UNITECH copies into her saved stats when she joins; tools/drive/scenarios/port/himegari-unit-stats*.steps drive a new game with it and the load of its save without it |