Skip to content

The Horadric Cube: recipe match and outputs

When the player presses Transmute, the server scans the CubeMain table in row order for the first recipe whose header conditions and seven inputs fit the items in the cube. It then builds that row’s outputs (A, B, C in order): new items made through the ordinary item creation of items/uniques-sets and items/affixes with a forced quality, forced affixes and an ilvl computed from the player and input 1; copies of input 1, possibly re-based; or a special output (the cow portal, two Pandemonium stubs). If anything was produced, every item in the cube is destroyed and the outputs are placed in the cube, identified. This spec gives the match, the output construction per kind, the crafted builder (quality 8), the creation-side quality roll that the cube’s quality-0 records reach, and the order of every draw on the game seed, the unit seeds and the item seeds.

Names of functions and fields are ours. “Game seed” is Game+0xD0, “unit seed” an item unit’s Unit+0x20, “item seed” the item data’s ItemData+0x04; the primitives Step and Range are those of rng. The cube is the player’s inventory page 3. “Creation record” is the 0x84-byte ItemCreateRec that ItemCreate takes.

When Function Tag
Client packet 0x4F with button 0x18, player interaction type 4 Pkt4FButton → PktInteractButton → CubeButton [C]
The transmute: row scan, filter, player ops, match CUBE_Transmute [C]
The outputs of the matched row RecipeOutputCreate [C]
A created output of quality 8 ItemCreateByQuality case 8 → ItemBuildCrafted [C]
Output kinds 1, 2, 3 g_CubePortalFns → CUBE_CowPortalOpen, CUBE_PandemoniumPortalStub, CUBE_PandemoniumFinalePortalStub [C]
  • [I] Button 0x17 also needs interaction type 4 and ends the interaction, and a player whose type is not 4 is refused; no session logged either.
Anchor Used for
CubeMain.txt:enabled, CubeMain.txt:ladder, CubeMain.txt:min diff, CubeMain.txt:class, CubeMain.txt:version, CubeMain.txt:numinputs the row filter (§ A)
CubeMain.txt:op, CubeMain.txt:param, CubeMain.txt:value the player ops 1–14 (§ A), the item ops 15–27 and op 28 (§ B)
CubeMain.txt:input 1 … input 7 the compiled inputs (§ B)
CubeMain.txt:output, output b, output c the compiled outputs (§ E)
CubeMain.txt:lvl, CubeMain.txt:plvl, CubeMain.txt:ilvl the output ilvl (§ D)
CubeMain.txt:mod 1 … mod 5 with param, min, max, chance the property lines (§ F)
ItemStatCost.txt:ValShift value >> ValShift in the stat ops
Weapons.txt:normcode, Weapons.txt:ubercode, Weapons.txt:ultracode upg, bas/exc/eli inputs; the exc/eli output class
Weapons.txt:quest, Misc.txt:questdiffcheck op 28
Weapons.txt:level, Weapons.txt:spawnable, Weapons.txt:version the random item of a type (§ J)
ItemTypes.txt:Equiv1 type inputs and type outputs (ITEMS_UnitIsType, ITEMS_IsType)
Experience.txt:Amazon record 0 (MaxLvl), the ilvl cap (§ D)
ItemRatio.txt:Unique the creation-side roll of a quality-0 record (§ H)
MagicPrefix.txt:Name, MagicSuffix.txt:Name the forced pre=/suf= rows
Properties.txt:func1 the handler of each mod line

The record layout, the cell grammar and the survey of the stock rows are in CubeMain. What a reimplementation needs from them:

  • [C] cubemain is the only cube table the game reads: 151 records of 328 bytes, one per .txt row in order, no Expansion marker; a record holds a 20-byte header, seven 8-byte inputs and three 84-byte outputs with five 12-byte mod lines each. cubemod and cubetype are not loaded.

  • [C] Compiled input (CubeInput+0x0): flags u16, item u16, id u16 (unique or set record index

    • 1), quality u8 (1 low … 9 tmp, 0 any), qty u8. Flags: 0x001 item code, any (item 0xFFFF) or named unique/set; 0x002 item type; 0x004 nos; 0x008 sock; 0x010 eth; 0x020 noe; 0x040 named unique/set; 0x080 upg; 0x100 bas; 0x200 exc; 0x400 eli; 0x800 nru. (CubeMain § Input record, CubeMain.txt:input 1)
  • [C] Compiled output (CubeOutput+0x00): flags u16, item u16, id u16, quality u8, qty u8 (qty=N and sock=N share it, the later keyword wins), kind u8 (0xFC item code or named unique/set, 0xFD item type, 0xFE useitem, 0xFF usetype, 1 Cow Portal, 2 Pandemonium Portal, 3 Pandemonium Finale Portal), lvl/plvl/ilvl u8, pre1..3 and suf1..3 u16, five mod lines {s32 Properties row (−1 none), u16 param, s16 min, s16 max, u8 chance}. Flags: 0x001 mod, 0x002 sock=N, 0x004 eth, 0x008 named unique/set, 0x010 uns, 0x020 rem, 0x040 reg, 0x080 exc, 0x100 eli, 0x200 rep, 0x400 rch.

  • [C] Cell heads. An input head is tried as an item type first, then an item code, any, a unique or set name; an output head as useitem, usetype, an item code, an item type, a unique or set name, a portal name. So axe and key are types as inputs and items as outputs.

  • [C] A named unique or set output keeps the ilvl column: the column is compiled after the output cell and overwrites the item’s lvl that the output parser puts in the same byte. No stock row has such an output.

  • [C] Stock survey. min diff, class, param, value, every mod chance, output b and output c are blank in every stock row; op is 28 on rows 0, 1, 2, 148, 149 only; ladder is set on rows 104–122, 131, 132; rows 142–146 have enabled blank; numinputs equals the inputs’ summed qty (1 when absent) in all 151 rows.

State Type Source
cube items the player’s inventory items with page (ItemData+0x45) = 3, in inventory-list order ItemGetPage
game.expansion Game+0x70 (non-zero: expansion game) Game+0x70
game.gameType, game.ladder Game+0x6A (3 in single player), Game+0x74 Game+0x6A, Game+0x74
game.difficulty u8 Game+0x6D Game+0x6D
game.itemVersion the version the game gives a new item (≥ 100 expansion) Game+0x78
game.seed Seed at Game+0xD0 rng/seeds
game.uniqueMade the made-uniques set at Game+0x1B24 Game+0x1B24, items/uniques-sets
game quest record Game+0x10F4 → +0x0C (the game’s own quest words) GameQuestGet
player class (Unit+0x04), stat 12 (level), quest record of the current difficulty, room UnitGetClassId
local time day of month, day of week (ops 1 and 2 only) CUBE_Transmute
slots[0..2] three {unit, classId, ilvl} words filled by input 1 § C
Name Value Anchor Tag
CUBE_PAGE 3, the inventory page of the cube CubeCountItems [C]
CLAIM_SLOTS 48 entries in the claimed array; an item past the 48th is never marked claimed CubeMatchInputs [I]
MAX_TYPE_CANDIDATES 256, the random-item-of-a-type list CubePickItemOfType [I]
CRAFT_TIERS ilvl > 70 → 4, > 50 → 3, > 30 → 2, else 1 ItemBuildCrafted [C]
CRAFT_REDRAWS 252 picks per slot against a duplicate id or group ItemBuildCrafted [I]
ILVL_CAP experience record 0, class-0 column: 99 on stock data ExpMaxLevel, Experience.txt:Amazon [I]
STAT_SOCKETS, STAT_QUESTDIFF 194 item_numsockets, 356 questitemdifficulty ITEMS_GetSockets [C]
COW_LEVEL, COW_PORTAL_CLASS level 39, object class 60, pushed before the PortalObjectCreate call CUBE_CowPortalOpen, Objects.txt:Name, Levels.txt:Name, cube 6 [C]
event codes 4 after a produced transmute (the call), 20 after a refused cow portal; none when nothing is produced UnitSetEvent, cube 7 [C]
  • [C] The reproduction has no seed oracle between the match and any output: every created item, every copy and every mod line is predicted from the game seed at CUBE_Transmute. Its only boundary oracles are the cow portal’s free-spot search and portal object PortalObjectCreate, whose return values and the game seed after each are taken from the log; no item is created after them in a transmute. The spot search draws nothing (the game seed after it equals the one at CUBE_CowPortalOpen’s entry in all three openings); the portal object’s draws are the portal’s whole game-seed cost (§ L2). InvPlaceItem is used for its success or failure only. (PortalObjectCreate, InvPlaceItem, cube 55)
  • [C] The run’s inputs were builder-made items (rares with names and no affixes, magic items with one suffix, uniques at their maximal properties). They limit no statement here: the match reads class, type, quality, socket and ethereal state and stat 356; a created output reads only input 1’s class and ilvl; a copy is compared with its input list by list. (review ruling 2)
  • [C] Every chained callee is specified elsewhere and used here as specified: item creation, base stats and the property handlers, the socket setter. The 182 transmutes reproduce through those specs’ models with no oracle between the match and the output: 140 ItemCreate records, 140 ItemInitStats calls, 51 crafted builds, 301 ItemApplyProps calls and 3 ITEMS_SetSockets calls. (ItemCreate, PROP_ApplyBlockByVersion, ITEMS_SetSockets, cube 8)

All arithmetic is signed 32-bit unless a step says otherwise; ÷ truncates toward zero. Range(s, n) is one Step(s) and s.low mod n, or 0 with no step when n < 1 (signed); RNG_RangeB is this primitive.

A. The transmute and the row scan — CUBE_Transmute

Section titled “A. The transmute and the row scan — CUBE_Transmute”
A1. n: i32 ← number of cube items (page 3); a stack counts 1 [C]
if n ≤ 0: return
A2. t ← local time; dow: i32 ← t.dayOfWeek + 1 [I]; read for ops 1, 2 only
A3. for i in 0 ..< CUBEMAIN_GetCount(): [C] first fit (CUBE_Transmute, CUBEMAIN_GetRecord, all of A3a–A3h)
A3a. r ← CubeMain[i] ; record index = .txt row
if r.enabled = 0 and g_CubeAllRows = 0: continue
A3b. if game.expansion = 0 and r.version ≥ 100: continue ; u16
A3c. if game.gameType = 0 and game.ladder = 0 and r.ladder ≠ 0: continue ; [I] the skip: every run was single player
A3d. if r.minDiff > game.difficulty: continue ; unsigned bytes; [I] the skip: no stock row
A3e. if r.class ≠ 0xFF and r.class ≠ classId(player): continue ; [I] the skip: no stock row
A3f. if r.numinputs ≠ n: continue ; compared as a byte
A3g. if not PlayerOp(r, player, t, dow): continue ; A4
A3h. slots[0..2] ← {0, 0, 0}
if MatchInputs(game, r, slots): ; § B
RecipeOutputCreate(game, player, r, slots) ; § E–G
return
A4. PlayerOp(r, …): by r.op, table below; op 0 and ops 15–28 pass here [C]
A5. return ; no row matched
op the row passes when Tag
1 param ≤ day of month ≤ value [I]
2 value = dow (Sunday = 1) [I]
3 / 4 / 5 / 6 STATS_GetUnitStat(player, param) ≥ v / ≤ v / ≠ v / = v [I]
7 / 8 / 9 / 10 the same on the player’s base stat [I]
11 / 12 / 13 / 14 the same on UnitStatDelta(player, param) [I]
0, 15–28, any other no test here [C] (cube 10, 12)

Step notes:

  • A3. First fit. The first row whose filter, player op and seven inputs pass is transmuted and the scan stops; rows after it are never tested. 166 transmutes matched a row and 16 matched none, and the model predicts every row that reached the matcher and its result. [C]

  • A3b. A classic game refuses the version 100 rows. In the classic session row 60 (version 100) reached no matcher. [C]

  • A3c. Ladder rows match in single player. A ladder row is skipped only when Game+0x6A = 0 and the game is not a ladder game; single player has Game+0x6A = 3, so the 21 stock ladder rows (the rune upgrades 104–122 and the elite unique upgrades 131, 132) are matchable offline. Rows 104, 107, 111 and 122 matched and made their runes with the ladder word 0. [C]

  • A3d–A3e. No stock row sets min diff or class, so with stock data these tests always pass. [C]

  • A3f. The count is an exact count of cube items. With stock data numinputs is the inputs’ summed qty, so an extra item in the cube refuses every row. [C]

  • A4. The stat ops. v ← value >> ItemStatCost[param].ValShift (arithmetic shift). For ops 3–14 the test runs only when 0 ≤ param ≤ the stat count (DataTables+0xBD4); outside that range the row passes; a missing ItemStatCost record refuses the row. No stock row has ops 1–27; only op 28 is used (§ B). [I]

  • A4. Do not port the community readings of ops 1–4. The code passes op 1 inside the range and op 2 on equality (a guide states the refusal conditions), and ops 3/4 (7/8, 11/12, 15/16, 19/20, 23/24) on ≥ / ≤, not on > / <. [I]

  • A5. No match, no effect. Nothing in the scan or the matcher draws from any seed. In the 16 transmutes that matched no row (a count off by one, an extra item, a wrong quality, a missing gem, a version 100 row in a classic game) the game seed and the cube’s items were unchanged. [C]

B. The inputs — CubeMatchInputs and CUBE_MatchInput

Section titled “B. The inputs — CubeMatchInputs and CUBE_MatchInput”
B1. claimed[0..47] ← 0 [C]
for k in 0 ..< 7: if not MatchInput(k): return false ; stop at the first failing input
return true
MatchInput(k): [C] (CUBE_MatchInput, all of B2–B4)
B2. in ← r.input[k]
if (in.flags & 3) = 0: return true ; empty input
need: i32 ← in.qty if in.qty ≠ 0 else 1; got: i32 ← 0; exact ← true; ord: i32 ← 0
B3. for each cube item it, in inventory-list order:
ord ← ord + 1
if not ItemTest(in, it): continue ; B5
if k = 0 and not FirstInputSocketable(r, it): continue ; B6
if ord ≤ 48 and claimed[ord − 1]: continue ; [I] the 48 bound
if k = 0:
if not ItemOp(r, it): continue ; B7
FillSlots(r, it, slots) ; § C
if ord ≤ 48: claimed[ord − 1] ← 1 ; [I] the 48 bound
got ← got + 1
if ItemBaseStackable(it): exact ← false
B4. return (got = need) if exact else (got ≥ need) ; [I] the ≥

B5. ItemTest(in, it), in the code’s order; the first failing test refuses the item:

# Test Tag
a Base. Flag 0x001 with item 0xFFFF: any item. Flag 0x001 without upg: the item’s class = item. Flag 0x002: ITEMS_UnitIsType(it, item) (type equivalences count) [C]
a′ upg (0x001 with 0x080): let c be the item’s own code and i the input’s code; it passes when c = normcode and i = normcode; c = ubercode and i ∈ {normcode, ubercode}; c = ultracode and i is any of the three. So upg accepts the named base or a higher tier of it. Every stock upg input names a normal code [C] for an item of the named tier (rows 66, 73, 74, 85, 91) and of a higher tier (row 66 mgl matched a magic xmg and a magic umg, which a plain class test refuses) (Weapons.txt:normcode, Weapons.txt:ubercode, cube 15)
b Quality. When in.quality ≠ 0 the item’s quality equals it [C]
c Named unique or set (0x040): ITEMS_GetFileIndex(it) = in.id − 1 [C]
d Sockets. nos: stat 194 = 0. sock: stat 194 ≠ 0 (the socket count, not the number filled) [C]
e Ethereal. noe: not ethereal [C]
e′ eth: ethereal. No stock input has eth (0 of the 389 compiled inputs) [I] (ITEMS_IsEthereal, CubeMain.txt:input 1)
f Tier. bas: the item’s code = its normcode [C]
f′ else exc: = ubercode [C] (row 131 refused Gull dgr and Wizardspike 7dg, each passing every other test, and matched Spineripper 9dg; row 135 an exceptional rare) (Weapons.txt:ubercode, cube 17)
f″ else eli: = ultracode (one of the three is tested, in that priority). No stock input has eli [I]
g nru: the item’s runeword flag (bit 26) is clear. No stock input has nru [I] (ItemGetFlags, CubeMain.txt:input 1)
h Op 28, on every input. When r.op = 28 and the item’s base has both quest and questdiffcheck set, stat 356 ≥ game.difficulty [C]

B6. FirstInputSocketable(r, it) (input 1 only): when output A is useitem or usetype and has the sock flag, ItemMaxSockets(it) ≠ 0. [C]

B7. ItemOp(r, it) (input 1 only), with the v, range rule and missing-record refusal of A4: ops 15 / 16 / 17 / 18 item stat ≥ v / ≤ v / ≠ v / = v; 19–22 the same on the item’s base stat; 23–26 the same with UnitStatDelta; 27 ITEMS_GetFileIndex(it) ≠ value; any other op passes. No stock row has ops 15–27. [I]

[I] UnitStatDelta(unit, stat, param) is the unit’s stat minus its base stat: StatListGetStat − StatListGetBaseStat on the unit’s stat list (+0x5C; 0 with no list). Both return 0 for a stat outside the ItemStatCost range, a stat with no record, or a missing entry. StatListGetStat reads the list’s full array when the list flag 0x80000000 is set (the base array otherwise), as STATS_GetUnitStat does; StatListGetBaseStat always reads the base array. So ops 11–14 compare the player’s bonus over its base value (from items, skills and states), and ops 23–26 the magical part of input 1’s stat. Both getters apply the same ItemStatCost floor on a player or monster owner.

Step notes:

  • B3. An input claims every matching item, not qty of them, and the test is got = qty. Inputs are taken in column order, so an item that could match two inputs goes to the first. Each cube item counts 1 whatever its stack quantity. [C]

  • B4. A stackable base relaxes the count to got ≥ qty, once any claimed item has a stackable base. No stock row has two stackable inputs (6 have one) and numinputs is the summed qty on every row, so a stackable input could claim more than its qty only by leaving another input short: got ≥ qty and got = qty decide every stock transmute alike. [I]

  • B3. Because the row filter already requires the cube count to equal numinputs (A3f), and numinputs is the summed qty on every stock row (an empty qty counted 1, all 151 rows of the stock cubemain.bin), an unmatched item always refuses the row with stock data. [C] (CubeMain.txt:numinputs, cube 21)

  • B3. A row whose numinputs exceeded the inputs’ sum would let an unmatched item through; none exists. [I]

  • B5h. Op 28 is ≥, not >. Wirt’s Leg with stat 356 = 1 matched row 2 in Nightmare and 356 = 2 in Hell; 356 = 0 in Nightmare and 356 = 1 in Hell matched no row. In Normal every leg passes. The Pandemonium keys and organs have quest blank, so op 28 does not test them. [C]

  • B5. Op 28 binds, of the five op-28 rows, the inputs whose base has both quest and questdiffcheck: row 0 the Staff of Kings and the Viper Amulet (msf, vip); row 1 the Khalim Flail and Khalim’s organs (qf1, qhr, qey, qbr); row 2 Wirt’s Leg (leg, not the tome); rows 148 and 149 none. [C] (Misc.txt:questdiffcheck, CubeMain.txt:op, CubeMain § Header, cube 22)

  • B5b. On a quality mismatch with quality 9 the code makes a call whose result is unused; it has no effect. [I]

  • B6. Row 63 refuses a ring or an amulet. Its output is useitem,sock=1, so input 1 must be able to hold sockets; a rare amulet (ItemMaxSockets 0) stayed out of input 1 and no row matched. A rare short sword, cap and kite shield matched. [C]

  • B7. Input sock=N is not an input keyword: the parser knows sock alone and stops at the unknown token N, so the count is never stored or tested. No stock input cell holds sock=N (two of 389 hold sock alone, rows 15 and 141). [I]

C. What input 1 hands to the outputs — FillSlots

Section titled “C. What input 1 hands to the outputs — FillSlots”
C1. for each item it that input 1 claims, in claim order: [C] (all of C1–C2)
for s in 0 ..< 3: ; outputs A, B, C
slots[s].ilvl ← ITEMS_GetItemLevel(it)
a ← r.output[0] ; output A's kind and flags, for all three
if (a.flags & 0x001) or a.kind ∈ {0xFE, 0xFF}: slots[s].unit ← it
if a.kind = 0xFF: slots[s].classId ← classId(it)
if a.kind = 0xFE: slots[s].classId ← −1
C2. if a.kind ∈ {0xFE, 0xFF}:
if a.flags & 0x080: code ← base(it).ubercode
else if a.flags & 0x100: code ← base(it).ultracode
else: code ← none
if code ≠ blank and EXCEL_FindCode(code) = j
and (game.expansion or Items[j].version < 100): ; [I] the classic half
slots[s].classId ← j

Step notes:

  • C1. The last claimed item wins, and every slot is filled from output A’s kind and flags, so outputs B and C see the same class and ilvl as A. The nine slot words of every match were predicted. [C]
  • C1. Outputs B and C use these slots exactly as A does; no stock row has output b or output c, so a b ilvl or c ilvl is a percentage of input 1’s ilvl, not of input 2’s or 3’s. [I]
  • C2. The exc upgrade gave the three mod outputs of the run (rows 129, 130, 133) the base’s ubercode record. [C]
  • C2. The eli branch gave rows 131 and 135 the ultracode record: 9dg became 7dg (class 235), the nine slot words predicted, the copy’s class set to it and ItemInitStats re-run. [C] (cube 25)
  • C2. The version gate’s classic half (a classic game with an expansion-only upgraded base) has no stock case: the 8 rows whose output A has exc or eli (129–136) are all version 100, so a classic game refuses them at A3b first. [I]
D1. o ← r.output[s] [C] (all of D1–D2)
if o.lvl ≠ 0: v: i32 ← o.lvl
else:
v ← 0
if o.plvl ≠ 0: v ← (STATS_GetUnitStat(player, 12) × o.plvl) ÷ 100
if o.ilvl ≠ 0: v ← v + (slots[s].ilvl × o.ilvl) ÷ 100
D2. v ← max(v, 1)
D3. if v ≥ ILVL_CAP: v ← ILVL_CAP [I]

Step notes:

  • D1. Two truncating divisions, each term only when its column is non-zero; lvl overrides both. The crafted rows (plvl 50, ilvl 50), with players of level 20 to 99 and inputs of ilvl 1 to 99, reached all four crafted tiers. [C]

  • D1. The code takes a 64-bit path or divides first above 0x100000 or 0x10000, which a player level and a byte percentage never reach; for every value a stock game produces the products are exact 32-bit signed divisions. [I]

  • D1. Stock values: lvl 25, 30, 50 (the old magic recipes); plvl 75 (rings ↔ amulets); plvl/ilvl 40/40 (row 61) and 66/66 (row 62, the rare rerolls), 50/50 (crafted); ilvl 100 (magic reroll, row 60); ilvl 60 with lvl 30, where lvl wins. [C]

  • D3. The cap was not reached in the run. [I]

  • D. Only created items use v. A useitem or mod output keeps the input’s ilvl. The cube does not raise the record’s ilvl to the base’s level. [C]

E. Building one output — RecipeOutputCreate

Section titled “E. Building one output — RecipeOutputCreate”

Outputs A, B and C (row + 0x4C + 0x54·s) are built in that order, each to the end of § F before the next.

E1. strip ← (o.flags & 0x030) ≠ 0 [C] (all of E1–E6)
v ← § D
E2. if o.kind ∈ 1..3 and g_CubePortalFns[o.kind] ≠ 0:
produced ← produced or (g_CubePortalFns[o.kind](game, player) ≠ 0) ; § L
E3. if o.flags & 0x001: ; `mod`: re-base a copy of input 1
it ← ItemCopy(game, slots[s].unit, children: not strip) ; § K
cls ← max(slots[s].classId, 0) if o.kind = 0xFE ; [I] the −1 → 0 case
slots[s].classId if o.kind = 0xFF ; [I] no stock `mod` row of this kind
o.item if o.kind = 0xFC ; [I]
PickItemOfType(game, v, o.item) if o.kind = 0xFD ; [I] § J
it.classId ← cls; ItemInitStats(game, it, 0, 0) ; base stats on the copy's unit seed
E4. else if o.kind = 0xFE: ; `useitem`
it ← ItemCopy(game, slots[s].unit, children: not strip) ; § K
if o.quality = 9: TmpNames(it) ; E8; [I] the disabled rows only
E5. else if o.kind ∈ {0xFC, 0xFD, 0xFF}:
q ← o.quality; rowP1 ← o.id
if o.kind = 0xFC: cls ← o.item
if o.kind = 0xFD: cls ← PickItemOfType(game, v, o.item) ; § J, 2 game-seed draws
if o.kind = 0xFF: cls ← slots[s].classId; if o.flags & 0x040: Reg(…) ; E7; [I] `Reg`: no stock row
rec ← CreationRecord(cls, v, q, rowP1, o) ; table below
it ← ItemCreate(game, rec) ; items/uniques-sets § A onward
E6. else: no item ; kinds 0..3

The creation record of E5 (every other field 0):

Field Value Tag
source, game the player, the game [C]
ilvl (+0x0C) v of § D [C]
item index cls [C]
+0x18 4 (3 on a drop; meaning not read) [I]
+0x28, +0x2A 1, game.itemVersion (101 in the 132 logged expansion records, 2 in the 8 classic ones) [C] (ItemCreateRec+0x80, cube 29)
quality (+0x30) o.quality: mag 4, rar 6, crf 8, nor 2, …; 0 when the cell names none [C]
unique/set row + 1 o.id (0 on every stock output) [C]
forced prefixes, suffixes (+0x68, +0x74) o.pre[0..2], o.suf[0..2], u16 widened to i32 [C]
flags (+0x80) 0x08 (no socket roll), or 0x10 when sock is given with qty 0; ORed with 0x02 (no ethereal roll), or 0x04 (forced ethereal) when eth [C] for 0x08 with 0x02 (every stock created output); [I] for 0x10 and 0x04, which no stock output has

Step notes:

  • E5. A created output is an ordinary item creation. The game-seed draws, the base stats, the creation-side roll or the forced quality, the overrides, the builders, the ethereal and socket steps and the automagic pick are those of items/uniques-sets and items/affixes, entered with the record above. 140 created items reproduce, with these builders run: crafted 51, magic 44, rare 15, normal 30, low 1 (the failed low build of § H). [C]

  • E5. Forced affix ids are block-relative. pre=N and suf=N reach ITEMS_PickMagicAffix as forcedId and select row N − 1 of the prefix (suffix) block with no weighted draw (items/affixes § C, C4i): pre=331 Prismatic, 372 Garnet, 353 Cobalt, 392 Coral, 412 Jade, 191 Savage; suf=162 of Spikes, 352 of the Leech. The magic builder then picks the prefix with mustRoll 1 and the suffix with mustRoll 0 (rows 6–10: 6 of 9 items also got a suffix). 12 forced picks. [C]

  • E5. A quality-0 record (runes, gems, potions, the Token of Absolution, hst, qf2) leaves the quality to the creation-side roll, which draws on the item seed (§ H); the Normal type override then sets 2 for runes and gems, after the draws. [C]

  • E3. mod re-bases a copy. The copy gets the slot’s class (the ubercode record for the stock upgrade rows) and ItemInitStats(game, copy, 0, 0) re-runs the base stats on the copy’s unit seed: durability, defense or damage, speed and the picture are rewritten; sockets, prefixes, suffixes, the unique’s or set’s row and their lists stay; the quality builders do not run. Rows 129, 130, 133. [C]

  • E3. On an ethereal copy ItemInitStats writes the plain base values: row 129 on an ethereal Gull re-based to 9dg logged the plain damage 6–18 after the copy’s ItemInitStats; the ×3/2 (9–27) comes from the mod line’s ITEMS_MakeEthereal (F2). [C] (ItemInitStats, ITEMS_MakeEthereal, cube 38)

  • E3. A class of −1 left by the slot (a useitem,mod row whose input base has no next-tier code) becomes 0, item record 0. The stock upgrade rows require bas or exc bases, so it is not reachable. [I]

  • E4. useitem is a copy of input 1: class, quality, affixes, rare names, ilvl, flags and every stat list come back from the copy stream; 15 useitem copies. [C]

  • E3–E4. The copy takes the input’s socketed children with it unless uns is given. Row 130 (mod) on Greyform holding a standard amethyst gave a copy with its one child; row 141 (useitem,uns) on a sword with two gems and on Steel passed ItemCopy flag 0 and gave copies with no child, the input’s children destroyed with it (G2). [C] (ItemCopy, cube 32)

  • E3–E4. rem strips the children the same way; no stock output has rem. [I]

  • E7. Reg (usetype with reg, no stock row): when input 1 exists, q ← its quality, rowP1 ← its file index

    • 1 and v ← its unclamped ITEMS_GetItemLevel. If q = 7 and the row’s made bit is clear before the build, the bit is cleared again after ItemCreate, so the made set is unchanged; a bit already set stays set and the unique build may fail and fall back. This is the cube’s only write to the made-uniques set. [I]
  • E8. TmpNames (useitem with quality 9, the disabled rows only): a ← PickRareNameByVersion(it, 1), b ← PickRareNameByVersion(it, 0); with both non-zero the copy gets quality 9 and the two names; otherwise the mod lines of § F are skipped. [I]

  • E5. A named unique or set output (kind 0xFC with quality 7 or 5 and id): no stock row has one; its ilvl byte is the ilvl column (§ Inputs). [I]

F1. if strip: RemoveRuneword(it) [C]
if o.flags & 0x020: copy each socketed child of the ORIGINAL input aside ; `rem`, placed after the outputs (§ G); [I] no stock row
F2. for m in 1 ..< 6 (skipped when TmpNames failed): [C]
line ← o.mod[m]; if line.prop < 0: continue
if 1 ≤ line.chance ≤ 99: [I]
Step(it.unitSeed) ; draw on the UNIT seed
if low mod 100 > line.chance: continue ; u32
PROP_ApplyBlockByVersion(7, it, line, state 0, flags 0x40) ; handlers draw on the ITEM seed
if IsEthereal(it): ITEMS_MakeEthereal(it) ; [C]
F3. if o.flags & 0x200: [C] (all of F3–F4) ; `rep`
if stackable base and o.qty ≠ 0: stat 70 ← min(o.qty, maxStack) ; [I] the o.qty side of the min
if it.flags & 0x100: ItemRepairBroken(it) ; stat 72 ← ItemMaxDurability(it)
else if base stat 72 < stat 73: base stat 72 ← stat 73 ; [I] which stat 73
F4. if o.flags & 0x400: ItemRefillCharges(it) ; `rch`; [I] past the first stat-204 entry
F5. if (o.flags & 0x002) = 0: [C]; `qty=N`
if stackable base and o.qty ≠ 0: stat 70 ← min(o.qty, maxStack) ; [I] the o.qty side of the min
else if o.qty ≠ 0 and stat 194 = 0 and (it.flags & 0x800) = 0: [C]; `sock=N`, no draw
k ← min(ItemMaxSockets(it), o.qty)
if quality ∈ {4, 9}: k ← min(k, 3) ; [I] never binds on stock data
if quality ∈ {5, 6, 7, 8}: k ← min(k, 1) ; [I]
if k ≠ 0: it.flags ← it.flags | 0x800; ITEMS_SetSockets(it, k)

Step notes:

  • F2. The mod lines come after ItemCreate returns, so for a created output they draw on the item seed after the builder, the ethereal and socket steps and the automagic pick. Each line is one property block through the handlers of items/properties § E; 170 lines (funcs 1, 2, 8, 11, 14) reproduce slot by slot. [C]

  • F2. The chance gate applies the line with probability (chance + 1)/100 for chance 1..99, and always for 0 or ≥ 100. Every stock chance cell is blank, so stock data makes no chance draw. [I] (CubeMain.txt:mod 1 chance)

  • F2. The rune socket rows (123–126) roll sock 1..6 on every class. Their mod 1 is sock 1..6 for body armour, helm, shield and weapon alike; the count is then capped by the sock handler (ItemMaxSockets and the inventory size, no quality clamp): rolls of 6 on a gothic plate gave 4 sockets, 5 on a great helm and a kite shield 3 each, 5 on a quilted armour 2. 10 transmutes. [C]

  • F2. The ethereal base bonus is re-applied after each line when the item is ethereal: ITEMS_MakeEthereal sits inside CubeModApply, which the loop calls once per line. Row 129 on an ethereal Gull: the copy’s plain 9dg damage 6–18 (E3), then the levelreq line and MakeEthereal, damage ×3/2 (9–27) and the flag, every list predicted to the placement. [C] (CubeModApply, ITEMS_MakeEthereal, cube 38)

  • F3–F4. rep and rch on items already at full durability and with no charges change nothing; that much is reproduced. [C]

  • F3. The repair. Row 137 raised a damaged short sword’s base stat 72 from 5 to 24; on a broken one (flag 0x100, 72 = 0) ItemRepairBroken set flag 0x200, cleared 0x100 and wrote 72 = 24 (ItemMaxDurability). Each predicted at the placement. [C] (ItemRepairBroken, cube 39)

  • F3. Which maximum the repair reads is not separated: the damaged branch compares STATS_GetUnitStat(it, 73) (the evaluated stat) with STATS_GetUnitBaseStat(it, 72), the broken branch takes ItemMaxDurability, and on both logged swords (no durability modifier) the evaluated and the base maximum are the same 24. [I]

  • F4. The recharge. Row 139’s rch raised a wand’s charge entry (stat 204) from 5 to 27, predicted. [C] (ItemRefillCharges, cube 39)

  • F4. ItemRefillCharges loops over every stat-204 entry StatListGetEntries returns (loop ); the logged wand held one entry, so a refill of every entry is not separated from a refill of the first. Stock items with two to four charge entries exist (Spellsteel 4, Wisp 3). [I]

  • F5. qty and sock share a byte; the flag decides. The builder reads it as a socket count when the sock flag is set and as a stack quantity otherwise. Row 137 (useitem,rep,qty=255, no sock flag) on throwing knives at 20 set the quantity (stat 70) to 160, ITEMS_GetMaxStack, in rep and again in the qty step, with no socket call; row 63’s sock=1 is the other reading. [C] (ITEMS_GetMaxStack, cube 40)

  • F5. The qty side of min(255, max stack) is not separated: the knives’ max stack 160 is below 255. Stock data reaches it: a throwing weapon of maxstack 200 (7tk, 7bk) with Dense (stat 254 +81..120) has a max stack above 255. ITEMS_GetMaxStack is the base’s maxstack plus stat 254 (0 on the knives), capped below 511. [I]

  • F5. sock=N (row 63, useitem,sock=1): a rare short sword, cap and kite shield got one socket through ITEMS_SetSockets. [C]

  • F5. The quality clamps (magic and 9 at most 3; set, rare, unique and crafted at most 1) are read only; with N = 1 on the only stock sock=N row none of them binds, and no stock row can make a crafted item reach the setter’s crafted cap (row 63 takes a rar input; the rune socket rows use a sock mod line on nor inputs; the setter’s caps are sockets-runewords § F, whose open questions hold the crafted one). [I] (CubeMain.txt:output, review)

G1. if not produced (no output made an item and no special output returned non-zero): [C]
return ; nothing destroyed, nothing placed
G2. CubeDestroyContents(player) [C]
; every page-3 item, the originals of useitem/mod copies included
G3. UnitSetEvent(player, 4, …) [C]
G4. for each output item, in order A, B, C: [C]
set page 3; InvPlaceItem(game, player, it, …) ; ORACLE: success or failure only
; inside it: if ItemInvNonEmpty(it): ITEMS_SetFlag(it, 1, 1) ; flags bit 0
if it failed: UnitFree(it) ; [I]
else: ITEMS_SetFlag(it, 0x10) ; identified
if base(it).quest and code(it) = hst: QuestStaffMade(player)
if base(it).quest and code(it) = qf2: QuestKhalimWillMade(player)
G5. place the `rem` children the same way [I]; no stock output has `rem`

Step notes:

  • G2. The whole cube is destroyed, not only the claimed inputs; with stock data the two are the same set (A3f). The placement draws nothing; the game seed at the end of each produced transmute was predicted. [C]

  • G4. Every cube output is identified, crafted items included (their builder creates them unidentified). [C]

  • G4. The output cell. InvPlaceItem(game, player, id, 0, 0, 1, 1, 0) takes the InvPlaceAnywhere branch; for a player’s inventory InvSpotFindBySize sends an item one cell high to InvSpotFindRow and any other to InvSpotFind, the spot search of player/creation § E (E6, Inventory spot). Run on the empty 3 × 4 cube grid (inventory.txt Transmogrify Box Page 1) after G2’s destroy, it gives every logged cell: 100 placements (1 × 1 at (2, 3) 70 times, 2 × 1 at (1, 3) once, every larger size at (0, 0)), 0 mismatches. A partly filled cube is not claimed; an output never meets one, since G2 empties it. [C] (InvPlaceItem, InvPlaceAnywhere, InvSpotFindBySize, InvSpotFindRow, InvSpotFind, cube 45)

  • G3. Event 4 follows the destroy in every produced transmute (21 logged); a transmute that produces nothing makes no call (3 logged), and a refused cow portal makes its own event 20 (§ L). What UnitSetEvent does with the code is not logged. [C] (UnitSetEvent, cube 7)

  • G4. The two quest hooks. A placed hst calls QuestStaffMade, which sets the player’s quest word 10 bit 11 (0x0000 → 0x0800, QUESTRECORD_SetState(rec, 10, 11)); a placed qf2 calls QuestKhalimWillMade. Neither hook ran for the 18 other placed outputs (14 classes). [C] (QuestStaffMade, QuestKhalimWillMade, cube 43)

  • G4. What else the hooks do is seen in the log but not compared with a model: the staff’s writes the game’s quest 9 data (+0x2A = 1 and counters); the will’s reads word 18 bits 0 and 1 (results unused), writes no player bit and moves the game’s quest 16 counters. [I]

  • G5. No stock output has rem, so the second placement loop runs with a count of 0 in every stock transmute. [I]

H. The creation-side quality roll of a quality-0 record

Section titled “H. The creation-side quality roll of a quality-0 record”

ItemCreateByQuality calls ItemRollQualityCreate first; on a drop it returns the record’s quality with no draw. A cube record of quality 0 reaches its drawing body:

H1. if itemVersion ≥ 1 and rec.quality ≠ 0: return rec.quality [C] (all of H1–H4)
H2. ratio ← ITEMRATIO_Select(classId, game.difficulty, 100 if itemVersion ≥ 1 else 0)
if base.quest: return 2 ; no draw
H3. d: i32 ← 1 if ITEMS_IsType(it, 52 misc) else max(rec.ilvl − base.level, 1)
for code in 7, 6, 5, 4, 3, 2: ; table
c: i32 ← ratio[code].base − d ÷ ratio[code].divisor ; no ×128, no magic find
if c ≤ 0: return code ; no draw
if Range(item.seed, c) = 0: return code ; draw
H4. return 3 if rec.flags & 0x40 else 1 ; [I] the 3: no cube record sets 0x40

Step notes:

  • H2. The ratio columns are ItemRatio’s Unique, Rare, Set, Magic, HiQuality and Normal with their divisors; the row is chosen as in items/quality § B. [C]

  • H3. The draws count even when the result is overridden. ItemCreateByQuality keeps the record’s quality when it is non-zero, else the roll’s, then applies the type overrides; a rune or gem (Normal type) ends at 2 whatever the roll gave, after its draws. Results over 29 creations: 2 (14), 1 (9), 3 (4), 6 (2). [C]

  • H. The fallback helpers call it again. ItemFallbackNormal (and the magic helper, same shape) clears the item, sets the start seed to S and the item seed to {S, 666}, calls the roll, and only then writes the step’s quality. On a drop that call draws nothing; on a quality-0 cube record the first fallback step draws as above and discards the result. Seen once: a Token of Absolution rolled quality 1, ITEMS_BuildLow failed (not a weapon or armour), and the normal fallback drew its roll from {S, 666}. [C]

  • H1. The version-0 body (only the codes 4..2 divide, and c ≤ 0 is raised to 1) was not reached. [I]

I. The crafted builder — ItemBuildCrafted

Section titled “I. The crafted builder — ItemBuildCrafted”

Case 8 of ItemCreateByQuality clears both rare names, reads the item seed’s low word for the fallback and calls the builder: 51 crafted builds reproduced. [C] (ItemCreateByQuality, cube 47) On failure it calls ItemFallbackNormal with that value; stock data has no failing case, since the builder fails only on a rare-name pick and every spawnable base of every crafted row (161) has at least 24 rare prefixes and 14 rare suffixes that pass ITEMS_RareNameTypeOk. [I]

I1. a ← RareName(prefix); b ← RareName(suffix) [C] (ITEMS_PickRareName, all of I1–I6)
; ITEMS_PickRareName for an item of version ≥ 1 (items/affixes E2, R1–R4): one Range draw each
if a = 0 or b = 0: return false ; [I] no stock case
rareName1 ← a; rareName2 ← b
I2. tier: i32 ← 4 if rec.ilvl > 70 else 3 if rec.ilvl > 50 else 2 if rec.ilvl > 30 else 1
I3. Step(item.seed); n: u32 ← low mod 5; if n < tier: n ← tier ; draw
I4. p ← 0; s ← 0
repeat n times:
Step(item.seed); lo ← low ; the side draw, every slot
side ← suffix if p = 3 or (s ≠ 3 and (lo & 1) = 1) else prefix
t ← 0
loop:
id ← PickMagicAffix(it, needSpawnable 1, mustRoll 1, applyProps 0, side,
rec.forced<side>[side's counter], 0) ; items/affixes § C: 2 draws
if id's row and group differ from every filled slot of that side: ; id 0 against a filled slot faults (I4 note)
store id in that side's slot; advance that side's counter; break
if t > 250: store 0 in that side's slot; break ; [I] the 252-pick bound
t ← t + 1
I5. ITEMS_SetFlag(it, 0x10, 0) ; clear: created unidentified
for k in 0 ..< 3: ItemApplyProps(0, prefix[k]); ItemApplyProps(0, suffix[k]) ; empty slots skipped
I6. ITEMS_RollStaffMods(it, rec); return true

Step notes:

  • I2–I3. The count is max(low mod 5, tier). So tier 1 gives 1 affix with probability 2/5 and 2, 3, 4 with 1/5 each; tier 2 gives 2 (3/5), 3, 4 (1/5 each); tier 3 gives 3 (4/5), 4 (1/5); tier 4 always 4. 51 crafted items, counts by tier: tier 1: 2, 3, 4 (1, 2, 2 items); tier 2: 2, 3, 4 (8, 2, 4); tier 3: 3, 4 (11, 4); tier 4: 4 (17). [C]

  • I4. One side draw per slot, always, unlike the rare builder, which draws a side only while both sides are open (items/affixes § E, E4). A full side (3 affixes) forces the other. [C]

  • I4. The picks roll no properties (applyProps 0); every property comes after all picks, in the order prefix 1, suffix 1, prefix 2, suffix 2, prefix 3, suffix 3, then the staff mods. The forced ids are the record’s pre=/suf= per slot, 0 on every stock crafted row. [C]

  • I4. The duplicate test compares the picked id and its group with the filled slots of the same side. No redraw occurred in the run. [C]

  • I4. A redraw cannot be reached with stock data through a non-forced pick, because the pick’s own group test already excludes every group on the item (items/affixes § C, C4i). After 252 colliding picks the slot is written 0 and its side’s counter is not advanced, so the next slot of that side reuses it. [I]

  • I5. The recipe’s own lines come later. A crafted row’s mod 1..5 lines (three per crafted row: two for the family and one for the base) are applied by § F2 after ItemCreate returns, so they draw on the item seed after the builder, the ethereal and socket steps (both disabled by the record: § E, quality 8 has no socket roll) and the automagic pick. [C]

  • I4. A pick of 0. With mustRoll 1 the pick returns 0 only when no row is a candidate, and the builder has no test for 0: it goes straight to the duplicate loop, which skips empty slots (MAGICAFFIX_GetRecord returns NULL for id 0). (a) When the side has no filled slot, the 0 is stored in that side’s slot and the counter advanced: the slot stays empty, counts towards the side’s 3, and the property pass skips it; the build still returns true, even with every slot 0. [I]

  • I4. (b) When the side has a filled slot, the group comparison reads the NULL record of id 0 at +0x5C and the game faults; no redraw happens. Crafting at output ilvl 1 (clvl 1, input ilvl 1) on light boots (row 83) drew a second suffix of 0 against slot 0 holding suffix 730: the record read was 0 and the game ended there, its crash report giving ACCESS_VIOLATION under case 8’s call. [C] (MAGICAFFIX_GetRecord, ItemBuildCrafted, S2c piece, cube 49)

  • I4. Stock data reaches a pick of 0. The prefix and suffix groups are disjoint but one (group 0), and a side whose candidates span g ≤ 2 groups gives a pick of 0 at its (g + 1)-th affix: rows 72 and 90 on a short staff (sst, suffixes in 1 group at output ilvl 1), row 83 on light boots (lbt, 1 group at ilvl 1–3, 2 at 4–5), row 84 on light gloves (lgl, 2 groups at ilvl 1–3). Every other crafted base and ilvl has 3 or more groups per side. The crafted rows’ output ilvl is clvl × 50 ÷ 100 + ilvl × 50 ÷ 100, so only a low-level character reaches these. [C] (ItemBuildCrafted, MagicSuffix.txt:group, cube 49)

  • I4. Case (a) has no stock case: it needs a side whose first pick has no candidate, all its candidates in group 0, and no crafted row, base, output ilvl and side has that (0 of 40 194). [I]

  • I1. An item of version 0 takes PickRareNameV0 instead; not reached. [I]

J. A random item of a type — CubePickItemOfType

Section titled “J. A random item of a type — CubePickItemOfType”
J1. start: u32 ← Range(game.seed, nItems) [C] draw (RNG_RangeB, all of J1–J3)
J2. cand ← []
for j from start upward, wrapping at nItems, stopping BEFORE start − 1: ; start − 1 is never examined; [I]
if ITEMS_IsType(Items[j], type) and Items[j].spawnable
and (Items[j].version < 100 or game.itemVersion ≥ 100)
and Items[j].level ≤ ilvl ; signed
and len(cand) < 256: ; [I] the cap: no stock case
append j
J3. if cand is empty: return 0 ; item record 0, no second draw; [I] no stock case
return cand[Range(game.seed, len(cand))] ; draw

Step notes:

  • J1–J3. Both draws come before ItemCreate, on the game seed. Row 19 (pole,mag,pre=191, ilvl from lvl 50) picked a scythe (scy, record 59) from ten candidates, with the prefix Savage forced; one transmute. [C]
K1. Step(game.seed) ; SUnitCreate [C] (all of K1–K3)
K2. Step(game.seed); copy.start ← low; Init(copy.itemSeed, copy.start) ; ItemSeedInit: item seed {start, 666}
K3. restore from the copy stream: Init(copy.unitSeed, source Unit+0x28), class, quality,
file index, ilvl, affixes, rare names, flags, every stat list
K4. if children are copied: for each socketed child of the source: [C] for one child
ItemCreateFromSave(child's stream): Step(game.seed) twice; insert it into the copy ; [I] per child

Step notes:

  • K. A copy rolls on a fresh item seed. Its later draws (the mod lines, levelreq on the upgrade rows, sock) start from {start, 666} of the second game-seed step, while its unit seed restarts from the source’s saved Unit+0x28. 18 copies (15 useitem, 3 mod) had their start, item and unit seeds predicted. [C]

  • K3. The copy is a save round trip. ItemCopy serialises the item (ITEMS_Serialize, whose walk reaches ITEMS_WriteFull) and rebuilds it with ItemCreateFromSave, which calls ITEMS_ReadFull: the save writer and reader of save/d2s. The 18 logged copies came back with the source’s class, quality, affixes and lists. [C] (ItemCopy, ITEMS_Serialize, ITEMS_WriteFull, ITEMS_ReadFull, cube 52)

  • K3. A runeword’s name id comes back in prefix slot 0. The Steel copy held 20639 (0x509F) in prefix slot 0, where the source’s ItemData+0x38 held 0; § F1’s strip then cleared it. [C] (ItemRemoveRuneword, cube 36) The path: the writer saves RUNEWORD_Match’s row +0x82, not +0x38, and the reader stores the 16 bits at ItemData+0x38, as H6b logged on the loaded Steel. [I]

  • K4. A copied child costs two more game-seed steps. Row 130 on Greyform with one gem drew 4 game-seed steps for the copy, the copy’s start seed still the second step’s. [C] (ItemCopy, cube 32) That the two steps are per child is read from the copy’s child loop, which creates each child with ItemCreateFromSave, the creator the copy itself calls, then inserts it; no logged copy had two children. [I]

g_CubePortalFns holds {0, three jmp thunks} for kinds 1, 2, 3. [C]

L1. CowPortalOpen(game, player): [C] (CUBE_CowPortalOpen, all of L1)
if GameQuestGet(4, 11): refuse ; the game's own quest record
q ← the player's quest record of game.difficulty
if q.bit(4, 10): refuse
if not game.expansion: if not q.bit(26, 0): refuse ; word 40 not tested
else if not q.bit(40, 0): refuse ; word 26 not tested
L1a. if RoomGetLevelId(room(player)) ≠ 1: refuse [C]
L2. spot ← FreeSpotNear(player) [C] ORACLE, no draw
portal ← PortalObjectCreate(game, player, …, level 39, 0, class 60, 0) [C] ORACLE, draws
if either fails: refuse ; [I] no failure logged
GameQuestSet(4, 11); return 1 [C]
refuse: UnitSetEvent(player, 20, …); return 0 [C]
L3. PandemoniumPortalStub, PandemoniumFinalePortalStub: return 0 [C]

Step notes:

  • L1. Quest bits are QUESTRECORD_GetState(rec, q, s) = bit 16q + s. In expansion games the portal opened in level 1 in Normal, Nightmare and Hell, and was refused with the game’s word 4 bit 11 set (a second transmute in the same game), with the player’s word 4 bit 10 set, and with word 40 bit 0 clear; refused, the leg and the tome stayed in the cube. One cow portal per game. [C]

  • L1. The run’s quest bits and stat 356 were forced save states: they test the gates, not which quest events set those bits in a game. [C] (review ruling 3)

  • L1a. Only in the Rogue Encampment. In the Pandemonium Fortress (level 103) the tests passed up to the level test, which refused: return 0, event 20, the leg and the tome left in the cube. The three openings were in level 1. [C] (RoomGetLevelId, cube 53)

  • L1–L2. A refusal sets event 20: both logged refusals (the Pandemonium Fortress, classic word 26 clear) called UnitSetEvent(player, 20, …) from CUBE_CowPortalOpen (return). [C] (UnitSetEvent, cube 7)

  • L. The cow portal row also has op 28, so the leg must be of the current difficulty (B5h). [C]

Output Draws, in order Tag
no row matched none [C]
fixed code (0xFC) game seed: SUnitCreate step, ItemSeedInit step; unit seed: base stats; item seed from {S, 666}: the creation-side roll (§ H) when the record’s quality is 0, else none, then the builder of the (overridden) quality, the ethereal and socket steps, the automagic pick; then the mod lines [C]
item type (0xFD) game seed: Range(nItems), then Range(count) when there is a candidate (§ J); then as a fixed code [C]
usetype (0xFF) as a fixed code, with input 1’s class (upgraded by exc/eli) [C]
useitem (0xFE) game seed: two steps (§ K), then two more for a copied child (K4); then the mod lines on the copy’s fresh item seed, and sock=N (no draw) [C] with no child or one; [I] two per child past the first
mod game seed: two steps (§ K), then two more for a copied child (K4); unit seed: ItemInitStats on the copy; then the mod lines [C] with no child or one; [I] two per child past the first
Cow Portal the portal object’s game-seed draws (an oracle; 171, 173 and 171 steps in the three logged openings); the spot search draws nothing [C] (PortalObjectCreate, cube 55)
Pandemonium portals none [C]
each mod line unit seed: one step only when chance is 1..99 (never on stock data); item seed: the property handler’s draws [C] for the item-seed draws; [I] for the chance step
  • [C] Within a transmute the outputs run A, B, C, each through § F before the next, and the destroy and the placement draw nothing; the game seed at the end was predicted for every transmute. The game seed’s state at the packet is the only input outside the cube’s contents.
  • [C] A matched row with at least one produced output leaves the cube holding exactly the placed outputs, in order A, B, C, each identified; every earlier cube item is gone. Created outputs are full items as items/uniques-sets, items/affixes and items/properties build them, with the record of § E and the after-steps of § F; copies keep input 1’s identity with the § F changes.

  • [C] A transmute that matches no row leaves the cube and the game seed as they were; one whose row produces nothing (the Pandemonium rows, a refused cow portal) leaves the cube as it was.

  • [C] The cow portal output, when it opens, sets the game’s quest word 4 bit 11, so a second one in the same game is refused.

  • [I] Cube outputs are created into an inventory, so they are in no room’s unit list.

Examples 1 and 2 are the two test vectors, printed; every value is the logged one. Seeds are low:high in hex. Each row is one Step of the named seed: before is that seed’s state before the step, and the result is taken from the low word after it, which is the before of that seed’s next row (for example Step(5422ea02:0000029a) = 340b3624:2317b77a, and 0x340b3624 mod 24 = 12). The unit seed is {low, 666} of the first game-seed step, the start seed the low word of the second, the item seed {start, 666}. Affix ids are merged ids (prefix id = 747 + the prefix block row + 1); rare-name ids are merged rare ids.

Example 1: a crafted Hit Power amulet (row 70)

Section titled “Example 1: a crafted Hit Power amulet (row 70)”
  • [C] Inputs. transmute 2: expansion, Normal, a Sorceress of level 80. Cube, in list order: amu magic ilvl 41, jew magic ilvl 99, r10, gpb. Row 70 is "amul,mag", jew, r10, gpb → "usetype,crf", plvl 50, ilvl 50, mod lines gethit-skill (param 44) 5..4, thorns 3..10, howl 5..15. Rows reaching the matcher: 1, 15, 16, 17, 19, 60, 64–69 (each refused), then 70 (match). The three slots hold the amulet (class 520, ilvl 41). ilvl = 80 × 50 ÷ 100 + 41 × 50 ÷ 100 = 40 + 20 = 60, tier 3. Game seed at CUBE_Transmute 183d761c:2f3784a0.
# seed before draw range result
1 game 183d761c:2f3784a0 SUnitCreate step – low 5a9b282c: unit seed 5a9b282c:0000029a
2 game 5a9b282c:0a1c4026 ItemSeedInit step – low 5422ea02: start seed; item seed 5422ea02:0000029a; game seed now 5422ea02:25ca85e0
3 unit 5a9b282c:0000029a ItemInitStats: picture mod 3 1; unit seed now 4a06ac76:25ca85e0
4 item 5422ea02:0000029a rare name, prefix side (I1) mod 24 12 → id 168 Shadow
5 item 340b3624:2317b77a rare name, suffix side mod 14 12 → id 138 gorget
6 item 4604a12e:15b50285 crafted count (I3) mod 5, tier 3 0 → n = 3
7 item 4782eaeb:1d3439ea side (0 prefixes, 0 suffixes) & 1 1 → suffix
8 item c8d930c1:1dd3acf7 pick: roll test (mustRoll 1) & 1 0 → rolls anyway
9 item 77a8c17c:53c5b7c0 pick: suffix, 71 rows mod (W+1), W 200 57 → id 228 of Worth
10 item 53605c2c:31e8b04e side (0, 1) & 1 0 → prefix
11 item 10f05e2a:22c691d8 pick: roll test & 1 0 → rolls
12 item 9932a82a:0710aa7a pick: prefix, 77 rows mod (W+1), W 181 80 → id 1119 Garnet
13 item de1fb2cc:3fe5cd71 side (1, 1) & 1 1 → suffix
14 item c4a5246d:5ca56a29 pick: roll test & 1 0 → rolls
15 item e285c20a:5204e803 pick: suffix, 68 rows mod (W+1), W 188 180 → id 607 of Holy Bolts
16 item 17d4d9b5:5e7b15e6 P1 Garnet: res-fire (stat 39) 21..30 21 + 3 = 24
17 item c3ba6e2f:09f09e3f S1 of Worth: dmg-min (func 5; stats 21, 23, 159) 2..3 2 + 0 = 2
18 item 34bbd86a:51a30280 S2 of Holy Bolts: charged (func 19), skill 101 level 3, c = 27 mod (c − c/8) = mod 24 18 → charges 18 + 3 + 1 = 22 of 27
– – – mod 1 gethit-skill 44, 5, 4 (func 11) – no draw: stat 201 param 2820 (skill 44, level 4) = 5
19 item d5e82c12:15feaeb7 mod 2 thorns (stat 78) 3..10 3 + 1 = 4
20 item d45eb891:59380cc8 mod 3 howl (stat 112) 5..15 5 + 10 = 15
  • [C] Between the builder and the mod lines nothing draws: the amulet has no StaffMods class, the record’s flags 0x0A turn the ethereal and socket steps off, and the base names no automagic group. The property pass applies P1, S1, S2 (P2 is empty). Each slot costs three item-seed draws (side, roll test, weighted pick), the side draw included when the other side is empty (row 10).
  • [C] End state. Game seed at the end 5422ea02:25ca85e0 (the two steps only). The amulet: crafted (8), ilvl 60, start 5422ea02, unit seed 4a06ac76:25ca85e0, item seed d813a45d:5893f1c7, flags 0x00082010 (identified), prefixes {1119, 0, 0}, suffixes {228, 607, 0}, rare names {168, 138}; main list (state 0, flags 0x40): 21 = 2, 23 = 2, 39 = 24, 78 = 4, 112 = 15, 159 = 2, 201/2820 = 5, 204/6467 = 6934 (27 << 8 | 22). The four inputs are destroyed and the amulet is placed in the cube.
  • [C] Inputs. transmute 2: expansion, Normal, a Sorceress of level 80. Cube: amu magic ilvl 25, gpb, gpg, gpr. Row 60 is "any,mag", "gem4,qty=3" → "usetype,mag", ilvl 100, no mod line. Rows reaching the matcher: 1, 15, 16, 17, 19 (each refused), then 60 (match); input 2 claims the three gems. ilvl = 25 × 100 ÷ 100 = 25; the player’s level does not enter. Game seed at CUBE_Transmute 50954b25:57330aa9.
# seed before draw range result
1 game 50954b25:57330aa9 SUnitCreate step – low c4f8ae22: unit seed c4f8ae22:0000029a
2 game c4f8ae22:219c5227 ItemSeedInit step – low 59397251: item seed 59397251:0000029a; game seed now 59397251:5227bfd4
3 unit c4f8ae22:0000029a ItemInitStats: picture mod 3 1; unit seed now 379d22c4:5227bfd4
4 item 59397251:0000029a prefix pick: roll test (mustRoll 0) & 1 1 → rolls
5 item ee288aef:2536fe38 prefix pick, 49 rows mod (W+1), W 126 34 → id 1052 Snake’s
6 item a36a5823:63558390 Snake’s: mana (stat 9) 5..10 5 + 5 = 10
7 item 9ed1067f:4428c928 suffix pick: roll test (mustRoll 0) & 1 1 → rolls
8 item aae438e3:423dbc2b suffix pick, 44 rows mod (W+1), W 131 58 → id 278 of Wealth
9 item 216f32da:47470cb6 of Wealth: gold% (stat 79) 41..80 41 + 0 = 41
  • [C] The magic builder interleaves: each pick applies its row’s properties itself (applyProps 1), so the rolls follow their picks, unlike the crafted builder of Example 1. No mod line. Game seed at the end 59397251:5227bfd4. The amulet: magic (4), ilvl 25, start 59397251, unit seed 379d22c4:5227bfd4, item seed 270fce78:0df1f9f8, flags 0x00082010, prefix 1052, suffix 278; main list (state 0, flags 0x40): 9 = 2560 (10 << 8, ValShift 8), 79 = 41.

Example 3: the Savage polearm (row 19), one recorded output

Section titled “Example 3: the Savage polearm (row 19), one recorded output”
  • [C] Row 19 (kri, type gemd, type staf, type belt; output "pole,mag,pre=191", lvl 50, ilvl 60): lvl wins, so v = 50; CubePickItemOfType drew a start, found ten pole items with level ≤ 50 that are spawnable, drew one of them, and gave a scythe (scy, record 59); the magic builder took prefix Savage (block row 190) with no weighted draw.
  • First fit, and the cube count is exact. Rows are tried in table order; an extra item refuses every stock row; a stack counts as one item. [C]

  • An input takes every matching item. Do not stop at qty: claim them all, then compare. [C]

  • Input 1 drives all three outputs, with output A’s flags. Do not take input 2’s or 3’s ilvl for b ilvl or c ilvl. [I]

  • Ladder rows work offline; op 28 is ≥ the difficulty; the rune socket rows roll 1..6 for every class; the Pandemonium portals do nothing. Each contradicts a community description; keep the 1.14d behaviour. [C]

  • A quality-0 output still draws its quality roll, and its first fallback step draws it again from {S, 666}. A rune that ends at quality 2 has consumed those draws. [C]

  • Copies are not clones of the seed. useitem and mod take two game-seed steps and roll their mod lines on a new item seed; the unit seed comes back from the source’s Unit+0x28. A copied child adds two more game-seed steps. [C] Count two for each child of a copy with several: read from the child loop, not logged. [I]

  • An ethereal upgrade is plain, then ×3/2. ItemInitStats on the re-based copy writes the plain values; the mod line’s ITEMS_MakeEthereal applies the bonus. Do not apply it in the re-base. [C]

  • Crafted: a side draw every slot, and the count is raised to the tier, never lowered. [C]

  • Forced affix ids are block rows + 1, taken with no weighted draw. [C]

  • A forced row skips the level window (items/affixes § C, C4i): row 17 on a magic tower shield (output ilvl 30, alvl 19) took the forced of Spikes (suf=162, level 21). [C] (ITEMS_PickMagicAffix, cube 58)

  • That it skips only the level window, a forced row failing another C4 test being passed over, has no separating stock case: the 8 forced ids of the stock table (rows 6–10, 17–19) pass every other test. [I]

  • A crafted item at a low output ilvl can fault the game. On rows 72, 83, 84 and 90 a side with too few groups picks 0 against a filled slot and the duplicate test reads a NULL record (I4 (b)); a reimplementation that wants the 1.14d outcome must stop there, not draw again. [C] (MagicSuffix.txt:group, cube 49; the fault logged on row 83 only)

  • Nothing produced, nothing consumed. A row that matches but produces nothing (the Pandemonium rows, a refused cow portal) leaves the inputs in the cube. [C]

  • qty= and sock= share one byte: test the sock flag to know which it is. [C]