<?xml version='1.0' encoding='utf-8'?>
<CheatTable CheatEngineTableVersion="52">
  <CheatEntries>
    <CheatEntry>
      <ID>24</ID>
      <Description>"Select game :"</Description>
      <Color>00A5FF</Color>
      <VariableType>Auto Assembler Script</VariableType>
      <AssemblerScript>
{ Game   : 信長の野望 天下創生PK、革新PK、天道PK、大志PK、新生PK
  Author  : Black_wolf
  CheatVer:V01

  Memo: 天下創生PK Nobunaga11WPK.exe 1.0.0.0   : PE 5A570171（SizeOfImage 1546000、Steam build 2431466）
	革新PK     NOBU12PK.exe 1.0.0.1        : PE 57DA252F（SizeOfImage 102A000、Steam build 1345322）
	天道PK     NOBU13PK.exe 1.0.0.3        : PE 5A252884（SizeOfImage FC3A000、Steam build 2338456）
	創造       持ってなかった。セールの時にでも
	大志       NOBU15PK_JP.exe 1.0.0.7     : PE 5CE223D7（SizeOfImage 1D4C000、Steam build 3876132）
	大志(繁體) NOBU15PK_TC.exe 1.0.0.7     : PE 5CE22464（SizeOfImage 1B5B000、Steam build 3876132）
	新生       NOBU16PK.exe 1.0.1.35977 　 : PE 68495A9E（SizeOfImage 2653000、Steam build 18823764）

	そもそもは画面の表示倍率とマウス座標補正をCEでできるのかの技術検証だった
	別のゲームの大きなCTファイル作ったから	信長の野望も作ってみたくなって、とんでもないことに
}

[ENABLE]
{$lua}
if syntaxcheck then return end
NB.oneShot(memrec,function() NB.openConfigDropdown(24) end)
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
{$asm}
</AssemblerScript>
      <CheatEntries />
    </CheatEntry>
    <CheatEntry>
      <ID>1</ID>
      <Description>"[ATTACH / ALL OFF]"</Description>
      <Color>00A5FF</Color>
      <VariableType>Auto Assembler Script</VariableType>
      <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
NB.oneShot(memrec,function() NB.attachAndConfigure(memrec) end)
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
{$asm}
</AssemblerScript>
      <CheatEntries />
    </CheatEntry>
    <CheatEntry>
      <ID>2</ID>
      <Description>"0. Settings &amp; README"</Description>
      <Options moManualExpandCollapse="1" />
      <GroupHeader>1</GroupHeader>
      <Color>FFFF00</Color>
      <CheatEntries>
        <CheatEntry>
          <ID>3</ID>
          <Description>"Language / 言語設定"</Description>
          <Options moManualExpandCollapse="1" />
          <GroupHeader>1</GroupHeader>
          <Color>FFFF00</Color>
          <CheatEntries>
            <CheatEntry>
              <ID>4</ID>
              <Description>"English (default)"</Description>
              <Color>00A5FF</Color>
              <VariableType>Auto Assembler Script</VariableType>
              <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
NB.oneShot(memrec,function() NB.setLang('en') end)
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
{$asm}
</AssemblerScript>
              <CheatEntries />
            </CheatEntry>
            <CheatEntry>
              <ID>5</ID>
              <Description>"日本語 / Japanese"</Description>
              <Color>00A5FF</Color>
              <VariableType>Auto Assembler Script</VariableType>
              <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
NB.oneShot(memrec,function() NB.setLang('ja') end)
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
{$asm}
</AssemblerScript>
              <CheatEntries />
            </CheatEntry>
          </CheatEntries>
        </CheatEntry>
        <CheatEntry>
          <ID>20</ID>
          <Description>"Screen mode (check = launch / apply)"</Description>
          <Color>FFFF00</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.startConfiguredDisplay() end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.stopConfiguredDisplay() end)
{$asm}
</AssemblerScript>
          <CheatEntries>
            <CheatEntry>
              <ID>25</ID>
              <Description>"Display :"</Description>
              <Color>00A5FF</Color>
              <VariableType>Auto Assembler Script</VariableType>
              <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
NB.oneShot(memrec,function() NB.openConfigDropdown(25) end)
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
{$asm}
</AssemblerScript>
              <CheatEntries />
            </CheatEntry>
            <CheatEntry>
              <ID>26</ID>
              <Description>"Scale :"</Description>
              <Color>00A5FF</Color>
              <VariableType>Auto Assembler Script</VariableType>
              <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
NB.oneShot(memrec,function() NB.openConfigDropdown(26) end)
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
{$asm}
</AssemblerScript>
              <CheatEntries />
            </CheatEntry>
            <CheatEntry>
              <ID>27</ID>
              <Description>"Status"</Description>
              <GroupHeader>1</GroupHeader>
              <CheatEntries />
            </CheatEntry>
          </CheatEntries>
          <Options moManualExpandCollapse="1" />
        </CheatEntry>
        <CheatEntry>
          <ID>28</ID>
          <Description>"Controls"</Description>
          <Options moManualExpandCollapse="1" />
          <GroupHeader>1</GroupHeader>
          <Color>FFFF00</Color>
          <CheatEntries>
            <CheatEntry>
              <ID>18</ID>
              <Description>"WASD map controls (strategy / battle)"</Description>
              <Color>00A5FF</Color>
              <VariableType>Auto Assembler Script</VariableType>
              <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.feature('wasd',true) end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.feature('wasd',false) end)
{$asm}
</AssemblerScript>
              <CheatEntries />
            </CheatEntry>
            <CheatEntry>
              <ID>29</ID>
              <Description>"Extended zoom out (3x distance limit)"</Description>
              <Color>00A5FF</Color>
              <VariableType>Auto Assembler Script</VariableType>
              <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.feature('cameraZoom',true) end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.feature('cameraZoom',false) end)
{$asm}
</AssemblerScript>
              <CheatEntries />
            </CheatEntry>
          </CheatEntries>
        </CheatEntry>
        <CheatEntry>
          <ID>6</ID>
          <Description>"README"</Description>
          <Options moManualExpandCollapse="1" />
          <GroupHeader>1</GroupHeader>
          <Color>FFFF00</Color>
          <CheatEntries>
            <CheatEntry>
              <ID>7</ID>
              <Description>"1) Select game, display and scale; check Screen mode to launch/apply; then ATTACH."</Description>
              <GroupHeader>1</GroupHeader>
              <CheatEntries />
            </CheatEntry>
            <CheatEntry>
              <ID>19</ID>
              <Description>"2) Attach / All OFF connects and disables game cheats; display settings are retained."</Description>
              <GroupHeader>1</GroupHeader>
              <CheatEntries />
            </CheatEntry>
            <CheatEntry>
              <ID>17</ID>
              <Description>"3) Save before edits. All OFF does not undo committed data edits."</Description>
              <GroupHeader>1</GroupHeader>
              <CheatEntries />
            </CheatEntry>
          </CheatEntries>
        </CheatEntry>
        <CheatEntry>
          <ID>30</ID>
          <Description>"Unlock all Steam achievements"</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
NB.oneShot(memrec,function() NB.unlockSteamAchievements() end)
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
        <CheatEntry>
          <ID>12</ID>
          <Description>"Diagnostics"</Description>
          <Options moManualExpandCollapse="1" />
          <GroupHeader>1</GroupHeader>
          <Color>FFFF00</Color>
          <CheatEntries>
            <CheatEntry>
              <ID>13</ID>
              <Description>"Lua Engine (check = open)"</Description>
              <Color>00A5FF</Color>
              <VariableType>Auto Assembler Script</VariableType>
              <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.openLuaEngine() end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.closeLuaEngine() end)
{$asm}
</AssemblerScript>
              <CheatEntries />
            </CheatEntry>
            <CheatEntry>
              <ID>14</ID>
              <Description>"AOB scan self-test"</Description>
              <Color>00A5FF</Color>
              <VariableType>Auto Assembler Script</VariableType>
              <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
NB.oneShot(memrec,function() NB.scanSelfTest() end)
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
{$asm}
</AssemblerScript>
              <CheatEntries />
            </CheatEntry>
            <CheatEntry>
              <ID>15</ID>
              <Description>"Environment / connection info"</Description>
              <Color>00A5FF</Color>
              <VariableType>Auto Assembler Script</VariableType>
              <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
NB.oneShot(memrec,function() NB.envReport() end)
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
{$asm}
</AssemblerScript>
              <CheatEntries />
            </CheatEntry>
            <CheatEntry>
              <ID>16</ID>
              <Description>"Status / implementation progress"</Description>
              <Color>00A5FF</Color>
              <VariableType>Auto Assembler Script</VariableType>
              <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
NB.oneShot(memrec,function() NB.statusReport();NB.progressReport() end)
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
{$asm}
</AssemblerScript>
              <CheatEntries />
            </CheatEntry>
          </CheatEntries>
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
    <CheatEntry>
      <ID>100</ID>
      <Description>"1. Player (daimyo officer only)"</Description>
      <Options moManualExpandCollapse="1" />
      <GroupHeader>1</GroupHeader>
      <Color>FFFF00</Color>
      <CheatEntries>
        <CheatEntry>
          <ID>101</ID>
          <Description>"Unlimited commands/actions"</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.feature('actions',true) end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.feature('actions',false) end)
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
        <CheatEntry>
          <ID>102</ID>
          <Description>"Player editor (check to show)"</Description>
          <Color>FFFF00</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.openEditor(memrec,'player') end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.closeEditor(memrec) end)
{$asm}
</AssemblerScript>
          <CheatEntries />
          <Options moManualExpandCollapse="1" />
        </CheatEntry>
        <CheatEntry>
          <ID>704</ID>
          <Description>"Court editor (court / own force)"</Description>
          <Color>FFFF00</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.openCourtEditor(memrec) end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.closeEditor(memrec) end)
{$asm}
</AssemblerScript>
          <CheatEntries />
          <Options moManualExpandCollapse="1" />
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
    <CheatEntry>
      <ID>200</ID>
      <Description>"2. Battle"</Description>
      <Options moManualExpandCollapse="1" />
      <GroupHeader>1</GroupHeader>
      <Color>FFFF00</Color>
      <CheatEntries>
        <CheatEntry>
          <ID>201</ID>
          <Description>"Player invulnerability + MAX (daimyo unit)"</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.feature('playerBattle',true) end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.feature('playerBattle',false) end)
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
        <CheatEntry>
          <ID>202</ID>
          <Description>"Own units invulnerable + MAX"</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.feature('ownBattle',true) end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.feature('ownBattle',false) end)
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
        <CheatEntry>
          <ID>208</ID>
          <Description>"One-hit kill (enemy units / buildings)"</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.feature('battleOneHit',true) end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.feature('battleOneHit',false) end)
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
        <CheatEntry>
          <ID>206</ID>
          <Description>"Combat skills / tactics: no cooldown (own units)"</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.feature('battleSkills',true) end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.feature('battleSkills',false) end)
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
        <CheatEntry>
          <ID>207</ID>
          <Description>"Army movement speed MAX (own forces)"</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.feature('armySpeed',true) end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.feature('armySpeed',false) end)
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
    <CheatEntry>
      <ID>300</ID>
      <Description>"3. City"</Description>
      <Options moManualExpandCollapse="1" />
      <GroupHeader>1</GroupHeader>
      <Color>FFFF00</Color>
      <CheatEntries>
        <CheatEntry>
          <ID>301</ID>
          <Description>"Select: search city name..."</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
NB.oneShot(memrec,function() NB.search('city') end)
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
        <CheatEntry>
          <ID>302</ID>
          <Description>"Select: player's home castle"</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
NB.oneShot(memrec,function() NB.selectHomeCity() end)
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
        <CheatEntry>
          <ID>303</ID>
          <Description>"City editor (check to show)"</Description>
          <Color>FFFF00</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.openEditor(memrec,'city') end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.closeEditor(memrec) end)
{$asm}
</AssemblerScript>
          <CheatEntries />
          <Options moManualExpandCollapse="1" />
        </CheatEntry>
        <CheatEntry>
          <ID>304</ID>
          <Description>"Maximize city resources / public stats (own cities)"</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.feature('cityMax',true) end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.feature('cityMax',false) end)
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
    <CheatEntry>
      <ID>400</ID>
      <Description>"4. Officers"</Description>
      <Options moManualExpandCollapse="1" />
      <GroupHeader>1</GroupHeader>
      <Color>FFFF00</Color>
      <CheatEntries>
        <CheatEntry>
          <ID>401</ID>
          <Description>"Select: search officer name..."</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
NB.oneShot(memrec,function() NB.search('officer') end)
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
        <CheatEntry>
          <ID>402</ID>
          <Description>"Select: player daimyo"</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
NB.oneShot(memrec,function() NB.selectPlayer() end)
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
        <CheatEntry>
          <ID>403</ID>
          <Description>"Officer editor (check to show)"</Description>
          <Color>FFFF00</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.openEditor(memrec,'officer') end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.closeEditor(memrec) end)
{$asm}
</AssemblerScript>
          <CheatEntries />
          <Options moManualExpandCollapse="1" />
        </CheatEntry>
        <CheatEntry>
          <ID>404</ID>
          <Description>"Subordinate loyalty MAX"</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.feature('loyalty',true) end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.feature('loyalty',false) end)
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
    <CheatEntry>
      <ID>500</ID>
      <Description>"5. Items / treasures"</Description>
      <Options moManualExpandCollapse="1" />
      <GroupHeader>1</GroupHeader>
      <Color>FFFF00</Color>
      <CheatEntries>
        <CheatEntry>
          <ID>501</ID>
          <Description>"Assign treasures: category -&gt; multiple treasures -&gt; officer..."</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
NB.oneShot(memrec,function() NB.assignTreasure() end)
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
    <CheatEntry>
      <ID>600</ID>
      <Description>"6. Research &amp; development"</Description>
      <Options moManualExpandCollapse="1" />
      <GroupHeader>1</GroupHeader>
      <Color>FFFF00</Color>
      <CheatEntries>
        <CheatEntry>
          <ID>602</ID>
          <Description>"Instant development / investment / construction / castle building"</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.feature('instantDevelopment',true) end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.feature('instantDevelopment',false) end)
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
        <CheatEntry>
          <ID>603</ID>
          <Description>"Unlock all town types (own cities)"</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
NB.oneShot(memrec,function() NB.unlockCityDevelopment() end)
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
        <CheatEntry>
          <ID>604</ID>
          <Description>"Maximize investment (existing towns of own cities)"</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.feature('maxInvestment',true) end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.feature('maxInvestment',false) end)
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
        <CheatEntry>
          <ID>605</ID>
          <Description>"Development status (check to inspect pending orders)"</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
NB.oneShot(memrec,function() NB.reportDevelopment() end)
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
    <CheatEntry>
      <ID>700</ID>
      <Description>"7. Diplomacy, schemes &amp; personnel"</Description>
      <Options moManualExpandCollapse="1" />
      <GroupHeader>1</GroupHeader>
      <Color>FFFF00</Color>
      <CheatEntries>
        <CheatEntry>
          <ID>701</ID>
          <Description>"Guaranteed negotiation"</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.feature('negotiationSuccess',true) end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.feature('negotiationSuccess',false) end)
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
        <CheatEntry>
          <ID>702</ID>
          <Description>"Recruitment / poaching chance = 100%"</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.feature('recruitment',true) end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.feature('recruitment',false) end)
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
        <CheatEntry>
          <ID>703</ID>
          <Description>"Schemes: positive result"</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.feature('schemes',true) end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.feature('schemes',false) end)
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
        <CheatEntry>
          <ID>705</ID>
          <Description>"Instant exploration (own forces)"</Description>
          <Color>00A5FF</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end
if not NB.userRun(function() NB.feature('instantExploration',true) end) then NB.deferOff(memrec) end
{$asm}
[DISABLE]
{$lua}
if syntaxcheck then return end
NB.userRun(function() NB.feature('instantExploration',false) end)
{$asm}
</AssemblerScript>
          <CheatEntries />
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
  </CheatEntries>
  <UserdefinedSymbols />
  <LuaScript>-- Author  : Black_wolf
-- CheatVer:V01
if NB and NB.shutdown then
 local ok,e=pcall(NB.shutdown,true)
 if not ok then if NB.msg then NB.msg(tostring(e)) else print(tostring(e)) end;return end
end
NB={TAG='NOBUNAGA',TITLE="NOBUNAGA",EXE='Nobunaga11WPK.exe',MODULE='Nobunaga11WPK.exe',
 GAMEVER='2431466',BUILD={ts=0x5A570171,size=0x1546000},TICK_MS=500,lang='en',
 C_GROUP=0xFFFF00,C_SCRIPT=0x00A5FF,ID_ATTACH=1,ID_TOP0=2,OFF_VARS=0x100,OFF_PTRS=0x200,
 VARDEF={},HOOKS={},F={},PTRS={},NAMES={},game=1}
local NB=NB
NB.SIGS={root={p="83 EC 08 0F BF 49 70 81 F1 4C 4C 00 00 8D 04 24 89 0C 24 89 44 24 04 8B 44 24 04 66 C1 00 07 8B 04 24 35 B3 B3 FF FF 89 04 24 0F BF C0 50 B9 ?? ?? ?? ?? E8 68 48 01 00 83 C4 08 C3",off=0,len=6},loyalty={p="83 EC 08 8A 49 48 80 F1 4C 8D 44 24 03 88 4C 24 03 89 44 24 04 8B 44 24 04 C0 00 03 8A 44 24 03 34 B3 0F B6 C0 83 C4 08 C3",off=0,len=6},officerAccess={p="8B 44 24 04 56 33 F6 3D 41 02 00 00 7C 14 3D 20 0A 00 00 7F 0D 69 C0 B4 00 00 00 8D B4 08 50 6A FE FF",off=0,len=6},commands={p="83 EC 08 8A 49 20 80 F1 C2 8D 44 24 03 88 4C 24 03 89 44 24 04 8B 44 24 04 C0 00 03 8A 44 24 03 34 3D 0F B6 C0 83 C4 08 C3",off=0,len=6},action={p="83 EC 08 66 8B 89 86 00 00 00 66 81 F1 4C 4C 8D 04 24 66 89 0C 24 89 44 24 04 8B 44 24 04 66 C1 00 07 66 81 34 24 B3 B3 8B 04 24 C1 E8 03 83 E0 01 83 C4 08 C3 CC CC CC CC",off=0,len=6},wndTail={p="8B 01 FF 60 20 CC CC CC CC CC 56 8B F1 8B 46 5C 85 C0 74 0E 50 FF 15 70 71 77 00",off=-6,len=6},wndGlobal={p="8B 0D ?? ?? ?? ?? 8B 11 83 C4 0C FF 52 64 8B F0 8D 9B 00 00",off=0,len=6},d3dGlobal={p="00 00 00 74 4C 8B 35 ?? ?? ?? ?? 8B 46 1C 85 C0 74 3F 6A 01 E8 D7 D0 2C 00 8B",off=0,len=6},recruitChance={p="83 EC 24 53 8B 5C 24 30 55 56 89 4C 24 14 57 8B CB E8 0A 66 FD FF 8B CB 8B F0 E8 D1 64 FD FF 8B F8 8B CE 89 7C 24 10 E8",off=0,len=8,expected="83 EC 24 53 8B 5C 24 30"},townEligibility={p="8B 44 24 04 6A 6B 50 81 C1 44 D7 01 00 51 E8 FD 03 FE FF 83 C4 0C C2 04 00",off=0,len=6},specialtyInsert={p="51 55 8B 6C 24 10 56 57 8B F9 8B 77 04 8B 46 04 8A 50 0F 84 D2 B1 01 88 4C 24 0C 75 20 8A 55 00 3A 50 0C 0F 92 C1 84 C9",off=0,len=6},townDevelop={p="6A FF 68 93 4A 75 00 64 A1 00 00 00 00 50 64 89 25 00 00 00 00 81 EC 88 00 00 00 53 55 8B AC 24 A4 00 00 00 56 57 8B BC 24 A8 00 00 00 89 4C 24 4C 55 8B CF E8 27 E0 00 00 55 8B CF E8 5F E1 00",off=0,len=6},cityRecalculate={p="55 8B EC 83 E4 F8 81 EC 60 0A 00 00 53 55 56 57 8B F1 89 74 24 24 33 C0 B9 40 00 00 00 8D BC 24 70 02 00 00 F3 AB B9 40",off=0,len=6},rankSetOwner={p="83 EC 08 56 33 C0 8B F1 66 8B 46 08 57 35 95 95 FF FF 89 44 24 08 8D 44 24 08 89 44 24 0C 8B 44 24 0C 66 C1 00 07 8B 44",off=0,len=6},negotiation1={p="E8 B6 08 01 00 C7 44 24 20 0F 00 00 00 89 5C 24 1C 88 5C 24 0C 8B 96 94 00 00 00 52 8D 44 24 0C 50 68 13 06 00 00 C6 44 24 60 01 E8 9B",off=5,len=8,expected="C7 44 24 20 0F 00 00 00"},negotiation2={p="E8 8A 00 01 00 C7 44 24 20 0F 00 00 00 89 5C 24 1C 88 5C 24 0C 8B 8E 94 00 00 00 51 8D 54 24 0C 52 68 13 06 00 00 C6 44 24 64 01 E8 3F",off=5,len=8,expected="C7 44 24 20 0F 00 00 00"},negotiation3={p="E8 8A EC 00 00 C7 44 24 20 0F 00 00 00 89 5C 24 1C 88 5C 24 0C 8B 8E 94 00 00 00 51 8D 54 24 0C 52 68 13 06 00 00 C6 44 24 60 01 E8 DF",off=5,len=8,expected="C7 44 24 20 0F 00 00 00"},negotiation4={p="E8 A1 4D 01 00 C7 44 24 20 0F 00 00 00 89 5C 24 1C 88 5C 24 0C 39 9E D0 00 00 00 C6 44 24 54 01 74 2A 8B 8E B0 00 00 00 51 8B 8E AC 00",off=5,len=8,expected="C7 44 24 20 0F 00 00 00"},negotiation5={p="E8 85 F1 00 00 C7 44 24 20 0F 00 00 00 89 5C 24 1C 88 5C 24 0C 39 9E D0 00 00 00 8B 8E AC 00 00 00 C6 44 24 54 01 74 24 8B 86 B0 00 00",off=5,len=8,expected="C7 44 24 20 0F 00 00 00"},negotiation6={p="E8 55 58 01 00 C7 44 24 20 0F 00 00 00 89 5C 24 1C 88 5C 24 0C 39 9E D0 00 00 00 8B 8E AC 00 00 00 C6 44 24 58 01 74 24 8B 86 B0 00 00",off=5,len=8,expected="C7 44 24 20 0F 00 00 00"},negotiation7={p="E8 35 DB 00 00 C7 44 24 20 0F 00 00 00 89 5C 24 1C 88 5C 24 0C 39 9E D0 00 00 00 8B 8E AC 00 00 00 C6 44 24 54 01 74 24 8B 86 B0 00 00",off=5,len=8,expected="C7 44 24 20 0F 00 00 00"},negotiation8={p="E8 E5 33 01 00 C7 44 24 20 0F 00 00 00 89 5C 24 1C 88 5C 24 0C 39 9E D0 00 00 00 8B 8E AC 00 00 00 C6 44 24 54 01 74 24 8B 86 B0 00 00",off=5,len=8,expected="C7 44 24 20 0F 00 00 00"},negotiation9={p="E8 55 10 01 00 C7 44 24 20 0F 00 00 00 89 5C 24 1C 88 5C 24 0C 39 9E D0 00 00 00 8B 8E AC 00 00 00 C6 44 24 54 01 74 24 8B 86 B0 00 00",off=5,len=8,expected="C7 44 24 20 0F 00 00 00"},negotiation10={p="E8 15 F5 00 00 C7 44 24 20 0F 00 00 00 89 5C 24 1C 88 5C 24 0C 39 9E D0 00 00 00 8B 8E AC 00 00 00 C6 44 24 54 01 74 24 8B 86 B0 00 00",off=5,len=8,expected="C7 44 24 20 0F 00 00 00"},negotiation11={p="E8 05 1A 01 00 C7 44 24 20 0F 00 00 00 89 5C 24 1C 88 5C 24 0C 39 9E D0 00 00 00 8B 8E AC 00 00 00 C6 44 24 54 01 74 24 8B 86 B0 00 00",off=5,len=8,expected="C7 44 24 20 0F 00 00 00"},negotiation12={p="E8 73 FF 00 00 85 C0 74 07 8B CE E8 D8 D1 26 00 A1 40 22 8A 01 81 78 20 00 04 00 00 75 2A 6A 0A 8B CE E8 51 06 27 00 8B 10 6A 00 8B C8",off=5,len=6,expected="85 C0 74 07 8B CE"},negEnemy={p="83 C4 04 85 C0 0F 85 8B 00 00 00 6A 00 57 55 E8 1C EF FF FF 6A 00 6A 36 E8 13 60 26 00 8B 4C 24 70 83 C4 14 6A 04 6A 00 E8 F3 00 FF FF 8B 4E 04 8B 56 0C 53 51 55 52 57 8D 44 24 34 50 68 2D 06 00 00 E8 99 2E 11 00 8B 4C 24 70 51 8D 54 24 40 52 E8 6A 63 FD FF 8B 8C 24 80 00 00 00 83 C4 24",off=0,len=5,expected="83 C4 04 85 C0"},negThreat={p="8B CE E8 63 85 F5 FF 83 F8 01 74 08 85 DB 0F 84 A3 00 00 00 6A 01 6A 00 55 56 E8 6B FA FF FF 6A 00 6A 36 E8 02 FF 25 00 8B 5C 24 74 83 C4 18 6A 05 6A 00 8B CB E8 D0 C4 FE FF 8B 57 04 8B 44 24 4C 8B 4F 0C 52 50 51 55 56 8D 54 24 34 52 68 FC 05 00 00 E8 82 CD 10 00 8D 44 24 3C 56 50 E8 57",off=0,len=7,expected="8B CE E8 63 85 F5 FF"},negTribute={p="83 F8 5A 0F 8D E1 00 00 00 8B 55 04 8B 4C 24 74 52 E8 45 E2 F5 FF 85 C0 74 08 C7 44 24 78 01 00 00 00 8B CE E8 82 6D F5 FF 3B 45 04 74 44 8B CE E8 96 6E F5 FF 3B 45 0C 74 38 8B CE E8 8A 6E F5 FF 3B C7 74 2D 8B 45 0C 50 56 B9 68 D1 81 00 E8 97 B6 F6 FF 83 F8 2D 7D 19 57 56 B9 68 D1 81 00",off=0,len=9,expected="83 F8 5A 0F 8D E1 00 00 00"},negDonation={p="0F 8F 97 00 00 00 68 36 0F 00 00 B9 68 D1 81 00 E8 71 28 F7 FF 8B C8 E8 8A 97 F9 FF 3B 47 04 75 7C 6A 00 56 E8 4D FD FF FF 6A 00 6A 36 E8 04 4C 26 00 83 C4 10 6A 04 6A 00 8B CD E8 E6 EC FE FF 8B 57 04 8B 47 0C 52 50 56 8D 4C 24 1C 51 68 1C 06 00 00 E8 AE 17 11 00 8B 54 24 58 52 8D 44 24",off=0,len=6,expected="0F 8F 97 00 00 00"},negAllianceRefusal={p="85 C0 74 14 8B 55 04 52 8B CB E8 E8 59 F6 FF 83 F8 59 0F 8E 04 01 00 00 8B CE E8 78 DB F5 FF 3B 45 04 0F 84 F4 00 00 00 8B CE E8 88 DC F5 FF 3B 45 0C 75 14 8B 45 04 50 8B CB E8 B8 59 F6 FF 83 F8 59 0F 8E D4 00 00 00 8B CE E8 68 DC F5 FF 3B C7 75 14 8B 4D 04 51 8B CB E8 99 59 F6 FF 83 F8",off=0,len=8,expected="85 C0 74 14 8B 55 04 52"},negAllianceDemand={p="85 C0 0F 85 C4 02 00 00 8B 44 24 1C 85 C0 0F 86 B8 02 00 00 8B 4D 04 E8 6F 9F F6 FF 50 8B CB E8 27 56 F6 FF 83 F8 27 7E 3D 8B 4D 0C 51 56 B9 68 D1 81 00 E8 23 21 F7 FF 83 F8 23 7D 29 57 56 B9 68 D1 81 00 E8 12 21 F7 FF 83 F8 23 7D 18 8B CE E8 36 C7 F5 FF 83 F8 05 74 0C 8B 44 24 28 85 C0",off=0,len=8,expected="85 C0 0F 85 C4 02 00 00"},negRankCheck={p="68 E0 B0 41 00 51 E8 33 B4 F6 FF 8B 44 24 28 8B 54 24 40 83 C4 10 3B C7 0F 85 94 00 00 00 8B 6C 24 14 89 3A 8B 75 00 3B F5 89 6D 00 89 6D 04 74 60 F6 05 54 D0 81 00 01 8B 1E 75 42 8B 15 54 D0 81 00 83 CA 01 68 F0 5D 77 00 89 15 54 D0 81 00 89 3D 40 D0 81 00 89 3D 44 D0 81 00 89 3D 48 D0",off=0,len=5,expected="68 E0 B0 41 00"},negRankSelect={p="68 E0 B0 41 00 51 E8 7A AF F6 FF 8B 44 24 28 83 C4 10 3B C5 0F 85 92 00 00 00 8B 5C 24 14 8B 33 3B F3 89 1B 89 5B 04 74 61 F6 05 54 D0 81 00 01 8B 3E 75 42 8B 15 54 D0 81 00 83 CA 01 68 F0 5D 77 00 89 15 54 D0 81 00 89 2D 40 D0 81 00 89 2D 44 D0 81 00 89 2D 48 D0 81 00 C7 05 4C D0 81 00",off=0,len=5,expected="68 E0 B0 41 00"},negRankEligible={p="53 8B 5C 24 0C 85 DB 74 0B 8B 03 8B CB FF 50 08 85 C0 75 04 33 C0 5B C3 55 8B 6C 24 0C 85 ED 74 0C 8B 55 00 8B CD FF 52 08 85 C0 75 05 5D 33 C0 5B C3 8B CD E8 F7 AB FF FF 83 F8 17 74 EF 56 8B CD E8 FA AA FF FF 85 C0 0F 85 81 00 00 00 57 8B CB E8 0A 8B FE FF 8B C8 E8 E3 13 FF FF 8B C8 B8",off=0,len=6,expected="53 8B 5C 24 0C 85"},negRankOwner={p="83 EC 08 0F BF 49 08 81 F1 95 95 FF FF 8D 04 24 89 0C 24 89 44 24 04 8B 44 24 04 66 C1 00 07 8B 04 24 35 6A 6A 00 00 89 04 24 0F BF C0 50 B9 68 D1 81 00 E8 E8 61 00 00 83 C4 08 C3 CC CC CC CC 83 EC 08 56 33 C0 8B F1 66 8B 46 08 57 35 95 95 FF FF 89 44 24 08 8D 44 24 08 89 44 24 0C 8B 44",off=0,len=6,expected="83 EC 08 0F BF 49"},negRankGrade={p="83 EC 08 8A 49 34 80 F1 95 8D 44 24 03 88 4C 24 03 89 44 24 04 8B 44 24 04 C0 00 03 8A 44 24 03 34 6A 0F B6 C0 83 C4 08 C3 CC CC CC CC CC CC CC 83 EC 08 8A 49 34 80 F1 95 8D 44 24 03 88 4C 24 03 89 44 24 04 8B 44 24 04 C0 00 03 8A 44 24 03 34 6A 0F B6 C0 D1 E8 40 83 C4 08 C3 CC CC CC CC",off=0,len=6,expected="83 EC 08 8A 49 34"},battleSoldierSet={p="89 86 A8 00 00 00 5E C2 04 00 CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC 8B 44 24 04 89 81 C8 00 00 00 C2 04 00 CC CC",off=0,len=6,expected="89 86 A8 00 00 00"},battleSoldierAdd={p="89 86 A8 00 00 00 5F 5E 59 C2 04 00 CC CC CC CC CC CC CC CC 64 A1 00 00 00 00 6A FF 68 16 CE 75 00 50 64 89 25 00 00 00",off=0,len=6,expected="89 86 A8 00 00 00"},battleSoldierEvent={p="89 BE A8 00 00 00 5F 5E 5B 8B 4C 24 24 64 89 0D 00 00 00 00 83 C4 30 C2 04 00 8D 4C 24 18 E8 74 D3 04 00 8B CF C7 44 24",off=0,len=6,expected="89 BE A8 00 00 00"},battleSoldierDamage={p="89 BE A8 00 00 00 8B 96 A0 00 00 00 52 E8 9F 94 04 00 83 C4 04 85 FF 5F 75 0B 85 C0 74 07 8B C8 E8 1C B1 FF FF 5E C2 04",off=0,len=6,expected="89 BE A8 00 00 00"},battleMoraleSet={p="89 86 B4 00 00 00 75 15 85 C0 7F 1E 6A 01 8B CE E8 8A FE FF FF 5F 5E 83 C4 0C C2 04 00 85 C0 7E 09 6A 00 8B CE E8 75 FE",off=0,len=6,expected="89 86 B4 00 00 00"},battleFoodConsume={p="83 EC 08 33 C0 66 8B 41 0E 35 A4 A4 00 00 89 04 24 8D 04 24 89 44 24 04 8B 44 24 04 66 C1 00 07 8B 04 24 8B 54 24 0C 35 5B 5B 00 00 89 04 24 0F B7 C0 2B C2 89 44 24 0C 85 C0 C7 44 24 04 00 00 00 00 8D 44 24 0C 7F 04 8D 44 24 04 8B 10 8D 44",off=0,len=5,expected="83 EC 08 33 C0"},battleSkillSet={p="89 94 81 20 02 00 00 8B B9 74 02 00 00 8D B1 70 02 00 00 8B 4F 04 8D 44 24 10 50 51 57 8B CE E8 E6 89 01 00 6A 01 8B CE 8B D8 E8 BB F6 FF FF 89",off=0,len=7,expected="89 94 81 20 02 00 00"},battleSkillTick={p="89 94 8E 20 02 00 00 8B 00 EB 2F 3B 86 74 02 00 00 8B 38 74 23 8B 48 04 89 39 8B 10 8B 48 04 50 89 4A 04 E8 29 63 1E 00 8B 86 78 02 00 00 83 C4",off=0,len=7,expected="89 94 8E 20 02 00 00"},battleMax={p="56 8B F1 8B 8E 74 02 00 00 8B 01 3B C1 74 53 57 8B 48 08 8B 94 8E 20 02 00 00 85 D2 7E 0C 4A",off=0,len=9,expected="56 8B F1 8B 8E 74 02 00 00"},battleOneHit={p="E8 16 F6 FA FF 8B 4C 24 10 53 57 E8 9B EC FF FF 8B CB E8 14 E6 FA FF 8B F0 85 F6 0F 84 BE 01 00 00 8B 16 6A 00 6A 00 8B",off=0,len=5,expected="E8 16 F6 FA FF"},battleDamageNative={p="56 8B F1 8B 86 A8 00 00 00 85 C0 74 47 2B 44 24 08 B9 00 00 00 00 0F 98 C1 57 49 23 C8 8B F9 E8 1C 01 04 00",off=0,len=6,expected="56 8B F1 8B 86 A8"},battleBuildingHit={p="E8 46 49 FA FF 8B CE E8 1F 23 FA FF 84 C0 75 0B 8B CE E8 24 23 FA FF 84 C0 74 5B 8B 16 8B CE FF 52 44 85 C0 7F 50 33 C0",off=0,len=5,expected="E8 46 49 FA FF"},battleBuildingDamage={p="56 57 8B 7C 24 0C 85 FF 8B F1 7E 75 8B 46 18 85 C0 74 6E 53 E8 77 AB 04 00 8B C8 E8 D0 CC 03 00 6A 06 8B C8 E8 57 ED 1F 00 8B D8 8B",off=0,len=6,expected="56 57 8B 7C 24 0C"},battleBuildingVT={p="50 83 50 00 80 7D 50 00 40 36 5F 00 60 83 50 00 40 A4 50 00 C0 A1 6F 00 70 10 50 00 B0 75 54 00 D0 75 54 00 70 10 50 00 B0 90 50 00",off=0,len=4,expected="50 83 50 00"},battleAggregate={p="56 8B F1 8B 86 84 02 00 00 57 8B BE 80 02 00 00 3B F8 C7 86 BC 00 00 00 00 00 00 00 C7 86 C4 00 00 00 00 00 00 00 74 40 8B 07 50 E8 40 E3 04 00",off=0,len=6,expected="56 8B F1 8B 86 84"},battleMoraleNative={p="83 EC 0C 56 8B F1 8B 46 40 57 50 E8 B0 15 04 00 8B C8 E8 89 3D 03 00 85 C0 8B 7C 24 18 89 44 24 08 C7 44 24 0C 00 00 00 00 89 7C 24 10 8D 4C 24",off=0,len=6,expected="83 EC 0C 56 8B F1"},battleMoraleCapNative={p="8B 44 24 04 83 F8 FF 56 8B F1 74 39 50 E8 3E 01 01 00 8B 8C 86 B0 01 00 00 8B 54 24 10 83 C4 04 03 CA 79 0D 33 C9 89 8C 86 B0 01 00 00 5E C2 08",off=0,len=6,expected="8B 44 24 04 83 F8"},battleFoodNative={p="51 8B 44 24 08 85 C0 C7 04 24 00 00 00 00 8D 44 24 08 7F 03 8D 04 24 8B 00 8D 54 24 08 89 44 24 08 66 81 74 24 08 5B 5B 89 14 24 8B 04 24 66 C1 08 07 66 8B 44 24 08 66 35 A4 A4 66 89 41 0E 59",off=0,len=6,expected="51 8B 44 24 08 85"},battleUnitResolve={p="56 8B 74 24 08 83 FE FF 74 17 56 E8 20 FC FF FF 83 C4 04 85 C0 74 0A 8B 10 56 8B C8 FF 52 1C 5E C3 33 C0 5E C3 CC CC CC CC CC CC CC CC CC CC CC",off=0,len=6,expected="56 8B 74 24 08 83"},battleMainVT={p="E0 12 51 00 C0 ED 50 00 E0 ED 50 00 70 39 51 00 D0 23 51 00 C0 A1 6F 00 F0 23 51 00 F0 ED 50 00 20 EE 50 00 60 E0 50 00 D0 D9 50 00 70 3D 51 00 00 DA 50 00 E0 01 51 00 E0 87 50 00 80 C0 50 00",off=0,len=4,expected="E0 12 51 00"},battleChildVT={p="A0 52 51 00 B0 43 51 00 D0 43 51 00 90 4B 51 00 00 5B 51 00 C0 A1 6F 00 C0 4D 51 00 E0 43 51 00 10 44 51 00 60 E0 50 00 D0 D9 50 00 20 4A 51 00 00 DA 50 00 30 48 51 00 E0 87 50 00 80 C0 50 00",off=0,len=4,expected="A0 52 51 00"},battleArmyVT={p="D0 14 41 00 40 36 5F 00 60 11 41 00 F0 11 41 00 60 0B 41 00 DC 1C 7D 00 C0 2B 41 00 D0 C3 50 00 A0 28 41 00 00 29 41 00 70 19 41 00",off=0,len=4,expected="D0 14 41 00"},keyUp={p="6A 45 E8 28 65 21 00 83 C4 04 84 C0 75 46 6A 67 E8 1A 65 21 00 83 C4 04 84 C0 75 38 6A 68 E8 0C",off=0,len=2,expected="6A 45"},keyDown={p="6A 44 E8 C7 64 21 00 83 C4 04 84 C0 75 46 6A 61 E8 B9 64 21 00 83 C4 04 84 C0 75 38 6A 62 E8 AB",off=0,len=2,expected="6A 44"},keyLeft={p="6A 53 E8 66 64 21 00 83 C4 04 84 C0 75 46 6A 61 E8 58 64 21 00 83 C4 04 84 C0 75 38 6A 64 E8 4A",off=0,len=2,expected="6A 53"},keyRight={p="6A 46 E8 05 64 21 00 83 C4 04 84 C0 75 46 6A 63 E8 F7 63 21 00 83 C4 04 84 C0 75 38 6A 66 E8 E9",off=0,len=2,expected="6A 46"},keyRotateLeft={p="6A 57 E8 E8 62 21 00 83 C4 04 84 C0 75 1C 6A 25 E8 DA 62 21 00 83 C4 04 84 C0 74 1B 6A 11 E8 CC",off=0,len=2,expected="6A 57"},keyRotateRight={p="6A 52 E8 A3 62 21 00 83 C4 04 84 C0 75 1C 6A 27 E8 95 62 21 00 83 C4 04 84 C0 74 1B 6A 11 E8 87",off=0,len=2,expected="6A 52"},treasureCategories={p="28 29 78 00 20 29 78 00 18 29 78 00 10 29 78 00 08 29 78 00 00 29 78 00 F8 28 78 00",off=0,len=4},spyResult={p="8B 00 33 C9 85 C0 0F 9F C1 50 57 56 89 4C 24 74 E8 A9 EF FF FF 68 B4 00 00 00 E8 CF 41 24",off=0,len=6,expected="8B 00 33 C9 85 C0"},rumorResult={p="8B 00 33 C9 85 C0 0F 9F C1 50 57 55 89 4C 24 74 E8 68 F1 FF FF 68 B4 00 00 00 E8 9E 15 24",off=0,len=6,expected="8B 00 33 C9 85 C0"},sabotageResult={p="8B 00 33 C9 85 C0 0F 9F C1 50 57 55 89 4C 24 74 E8 78 F1 FF FF 68 B4 00 00 00 E8 BE 04 24",off=0,len=6,expected="8B 00 33 C9 85 C0"},collusionResult={p="8B 00 33 C9 85 C0 0F 9F C1 50 57 55 89 4C 24 74 E8 88 F1 FF FF 68 B4 00 00 00 E8 EE F3 23",off=0,len=6,expected="8B 00 33 C9 85 C0"},incitementResult={p="8B 00 33 C9 85 C0 0F 9F C1 50 57 55 89 4C 24 74 E8 98 F1 FF FF 68 B4 00 00 00 E8 2E E3 23",off=0,len=6,expected="8B 00 33 C9 85 C0"},cameraZoomLimits={p="00 00 50 43 00 00 6E 43 00 00 86 43 00 00 50 43 00 00 64 43 00 00 78 43 00 00 48 43 00 00 F0 41 00 00 D8 41 00 00 C8 41 00 00 B8 41 00 00 D8 41 00 00 D0 41 00 00 C8 41 00 00 34 42 00 00 48 42",off=0,len=24,expected="00 00 50 43 00 00 6E 43 00 00 86 43 00 00 50 43 00 00 64 43 00 00 78 43"},cameraFarPlane={p="00 00 FA 43 00 00 00 00 00 00 00 C0 CC CC FC 3F 00 00 20 44 0E 74 DA 3B 14 5C 7D 00",off=0,len=4,expected="00 00 FA 43"},cameraDrawGuard={p="8B 07 55 56 8B CF FF 50 0C 8B 44 24 14 8B 8B 20 C0 04 00 40 81 C7 90 00 00 00 3B C1 89 44 24 14 72 DE",off=0,len=9,expected="8B 07 55 56 8B CF FF 50 0C"},cameraCapture={p="83 EC 3C 56 8B F1 8B 06 57 FF 50 3C D9 46 44 D9 E0 8D 7E 50 D9 C0 8D 4E 5C D9 FE 51 57 8D 54 24 14 52 8D 46 04 50 D8 CA D9 5C 24 28 D9 46 48 D9",off=0,len=6,expected="83 EC 3C 56 8B F1"},cameraTerrainLOD={p="D9 41 2C D8 61 28 D8 48 30 8B 44 24 1C 99 D8 0D F0 46 78 00 83 E2 03 03 C2 C1 F8 02 D8 41 28 89 44 24 24 8B 44 24 14 99 83 E2 03 D9 9E 64 99 26",off=0,len=6,expected="D9 41 2C D8 61 28"},cameraSceneDirtyGetter={p="64 A1 00 00 00 00 8A 0D 84 01 51 01 6A FF 68 2E EC 75 00 50 B8 01 00 00 00 84 C8 64 89 25 00 00 00 00 75 25 09 05 84 01 51 01 B9 D0 FE 50 01 C7 44 24 08 00 00 00 00 E8 D4 F7 FF FF 68 60 63 77 00 E8 92 8F 1E 00 83 C4 04 8B 0C 24 B8 D0 FE 50 01 64 89 0D 00 00 00 00 83 C4 0C C3 CC CC CC CC",off=0,len=6,expected="64 A1 00 00 00 00"}}
NB.A      = NB.A or {}      -- resolved signature addresses
NB.pend   = NB.pend or {}   -- unresolved signatures
NB.hookState = NB.hookState or {}
NB.featOn = NB.featOn or {}
NB.dyn    = NB.dyn or {}    -- dynamic records {mr,en,ja}
NB.suffix = NB.suffix or {} -- record ID -&gt; text appended to its name

----------------------------------------------------------------- helpers
local function rq(a) if not a or a==0 then return nil end local v=targetIs64Bit() and readQword(a) or readInteger(a) if not v or v==0 then return nil end return v end
local function ri(a) if not a or a==0 then return nil end local v=readInteger(a) if v and v&gt;=0x80000000 then v=v-0x100000000 end return v end
function NB.T(en,ja) if NB.lang=='ja' then return ja or en end return en end
function NB.messageText(value)
 local message=tostring(value)
 while true do
  local clean=message:gsub('^%[string ".-"%]:%d+:%s*','')
  if clean==message then return message end
  message=clean
 end
end
function NB.msg(en,ja) print('['..NB.TAG..'] '..NB.messageText(NB.T(en,ja))) end
function NB.err(en,ja) error(NB.T(en,ja),0) end
local function hex(n) return string.format('%X',n) end

function NB.mod(name) return getAddressSafe(name or NB.MODULE) end
function NB.modSize(name) local ok,s=pcall(getModuleSize,name or NB.MODULE) return ok and s or nil end
function NB.base() return getAddressSafe('nbFlags') end
function NB.flag(i) return NB.base()+i end
function NB.var(o) return NB.base()+NB.OFF_VARS+o end
function NB.ptr(slot) local b=NB.base() return b and rq(b+NB.OFF_PTRS+slot*8) or nil end

----------------------------------------------------------------- one-shot / user action
function NB.userRun(fn)
  local ok,e=pcall(fn)
  if not ok then local m=tostring(e) NB.msg(m)  end
  return ok
end
function NB.oneShot(mr, fn)
  NB.userRun(fn)
  local t=createTimer(nil,false) t.Interval=150
  t.OnTimer=function(tt) tt.destroy() pcall(function() mr.Active=false end) end
  t.Enabled=true
end

----------------------------------------------------------------- attach / init
function NB.attached() return NB.pid~=nil and NB.pid==getOpenedProcessID() and NB.base()~=nil end
function NB.require()
  if not NB.attached() then
    NB.err('Not attached to '..NB.EXE..'. Run [ATTACH / ALL OFF] at the top of the table first.',
           NB.EXE..'にアタッチされていません。先にテーブル先頭の【アタッチ／一括解除】を実行してください。')
  end
end
-- state of an old process: drop it without touching the new one
function NB.forgetProcess()
  NB.hookState={} NB.featOn={} NB.A={} NB.pend={}
  NB.pid=nil
end
function NB.checkBuild()
  if not NB.BUILD then return true end
  local m=NB.mod(); local lf=ri(m+0x3C); local ts=lf and readInteger(m+lf+8)
  local sz=NB.modSize()
  if ts~=NB.BUILD.ts or (NB.BUILD.size and sz~=NB.BUILD.size) then
    NB.msg(('WARNING: different game build (timestamp %s, size %s). Made for v%s. Features whose code is not found are disabled.'):format(hex(ts or 0),hex(sz or 0),NB.GAMEVER),
           ('警告: 対応ビルドと異なります（タイムスタンプ %s、サイズ %s）。対応バージョンは v%s です。コードが見つからない機能は無効になります。'):format(hex(ts or 0),hex(sz or 0),NB.GAMEVER))
    return false
  end
  return true
end
function NB.init()
  local pid=getOpenedProcessID()
  if NB.pid==pid and NB.base() then return true end
  NB.forgetProcess()
  for _,s in ipairs({'nbFlags','nbVars','nbPtrs'}) do pcall(unregisterSymbol,s) end
  -- near the module (within 2GB) so hook code can reach [nbFlags+n] RIP-relative.
  -- AA alloc searches free blocks near the address and retries; Lua allocateMemory(size,base) retries only once.
  local mem
  if autoAssemble(('alloc(nbFlags,$1000,%X)\nregistersymbol(nbFlags)\n'):format(NB.mod())) then mem=getAddressSafe('nbFlags') end
  if not mem or mem==0 then
    pcall(unregisterSymbol,'nbFlags')
    mem=allocateMemory(0x1000)
    if not mem or mem==0 then NB.err('Memory allocation failed.','メモリ確保に失敗しました。') end
    registerSymbol('nbFlags', mem, true)
    NB.msg('WARNING: shared memory is not near '..NB.MODULE..'. Hook features may fail to assemble.',
           '警告: 共有メモリを '..NB.MODULE..' の近くに確保できませんでした。フックを使う機能は組み立てに失敗する場合があります。')
  end
  registerSymbol('nbVars',  mem+NB.OFF_VARS, true)
  registerSymbol('nbPtrs',  mem+NB.OFF_PTRS, true)
  for o,d in pairs(NB.VARDEF) do
    if d[1]=='float' then writeFloat(NB.var(o),d[2]) elseif d[1]=='qword' then writeQword(NB.var(o),d[2]) else writeInteger(NB.var(o),d[2]) end
  end
  NB.pid=pid
  NB.checkBuild()
  NB.resolveAll()
  NB.onAttach()
  NB.startTimer()
  return true
end

----------------------------------------------------------------- AOB resolver (synchronous aobscanregion)
local function aaFind(pat, s, e)
  pcall(unregisterSymbol,'nb_tmp')
  local ok=autoAssemble(('aobscanregion(nb_tmp,%s,%s,%s)\nregistersymbol(nb_tmp)\n'):format(hex(s),hex(e),pat))
  if not ok then return nil end
  local a=getAddressSafe('nb_tmp') pcall(unregisterSymbol,'nb_tmp')
  return a
end
local function aobAll(pat, s, e, maxn)
  local r={} local from=s
  while from&lt;e and #r&lt;maxn do local a=aaFind(pat,from,e) if not a then break end r[#r+1]=a from=a+1 end
  return r
end
NB.aobAll=aobAll
function NB.resolveSig(name)
  if NB.A[name] then return NB.A[name] end
  local sg=NB.SIGS[name]; if not sg then NB.err('Unknown signature: '..name,'未定義のシグネチャ: '..name) end
  local m=NB.mod(sg.mod); local sz=NB.modSize(sg.mod)
  local hits=m and sz and aobAll(sg.p,m,m+sz,2) or {}
  local a=#hits==1 and hits[1] or nil
  if not a then NB.pend[name]=true return nil end
  a=a+(sg.off or 0)
  NB.A[name]=a; NB.pend[name]=nil
  pcall(unregisterSymbol,'nbA_'..name) registerSymbol('nbA_'..name, a, true)
  return a
end
function NB.resolveAll()
  local ok,ng=0,0
  for n in pairs(NB.SIGS) do if NB.resolveSig(n) then ok=ok+1 else ng=ng+1 end end
  NB.msg(('Signatures: %d found, %d not found.'):format(ok,ng),('シグネチャ: %d件検出、%d件未検出。'):format(ok,ng))
end
function NB.pendingNames() local r={} for n in pairs(NB.pend) do r[#r+1]=n end table.sort(r) return r end

----------------------------------------------------------------- features
function NB.feature(key, on)
  local f=NB.F[key] or NB.err('Unknown feature: '..key,'未定義の機能: '..key)
  if on then
    NB.require()
    for _,h in ipairs(f.hooks or {}) do NB.hookOn(h) end
    if f.flag then writeBytes(NB.flag(f.flag),1) end
    if f.on then f.on() end
    NB.featOn[key]=true
  else
    NB.featOn[key]=nil
    if not NB.attached() then return end
    if f.flag then writeBytes(NB.flag(f.flag),0) end
    if f.off then pcall(f.off) end
    for _,h in ipairs(f.hooks or {}) do
      local used=false
      for k in pairs(NB.featOn) do for _,x in ipairs(NB.F[k].hooks or {}) do if x==h then used=true end end end
      if not used then NB.hookOff(h) end
    end
  end
end

----------------------------------------------------------------- timer (pointer slots, tasks, process watch)
function NB.tick()
  if not NB.pid then return end
  if getOpenedProcessID()~=NB.pid then return end
  local b=NB.base(); if not b then return end
  for slot,fn in pairs(NB.PTRS) do local ok,a=pcall(fn) writeQword(b+NB.OFF_PTRS+slot*8, (ok and a) or 0) end
  for k in pairs(NB.featOn) do local f=NB.F[k] if f.task then pcall(f.task) end end
  
end
function NB.startTimer()
  if NB.timer then return end
  NB.timer=createTimer(nil,false) NB.timer.Interval=NB.TICK_MS
  NB.timer.OnTimer=function() pcall(NB.tick) end
  NB.timer.Enabled=true
end

----------------------------------------------------------------- ATTACH / ALL OFF
function NB.disableAll(self)
  local ok,changed=pcall(NB.attachGame)
  if not ok then NB.msg(tostring(changed))  return end
  if changed or (NB.pid and NB.pid~=getOpenedProcessID()) then NB.forgetProcess() end
  local okI,e=pcall(NB.init) if not okI then NB.msg(tostring(e))  return end
  local al=getAddressList(); local n=0
  for i=al.Count-1,0,-1 do
    local m=al.getMemoryRecord(i)
    if NB.NAMES[m.ID] and not (NB.CONFIG_IDS and NB.CONFIG_IDS[m.ID]) and m.Active and not (self and m.ID==self.ID) then pcall(function() m.Active=false end) n=n+1 end
  end
  local r=0 for name in pairs(NB.hookState) do NB.hookOff(name) r=r+1 end
  for i=0,0xFF do writeBytes(NB.flag(i),0) end
  NB.featOn={}
  NB.msg(('Attach / All OFF: %d records deactivated, %d hooks restored.'):format(n,r),
         ('アタッチ／一括解除: %d件を無効化、%d件のフックを元に戻しました。'):format(n,r))
end

----------------------------------------------------------------- UI helpers
function NB.pick(title,names)return NB.UI.pick(title,names)end
-- dynamic records (lists built at run time)
function NB.addRec(parent, en, ja, addr, vt)
  local m=getAddressList().createMemoryRecord()
  m.Description=NB.T(en,ja) m.Type=vt or vtDword m.Address=addr m.appendToEntry(parent) m.DontSave=true
  if NB.UI then NB.UI.track(m)end
  NB.dyn[#NB.dyn+1]={mr=m,en=en,ja=ja} return m
end

----------------------------------------------------------------- language
function NB.applyLang()
  local al=getAddressList()
  for i=0,al.Count-1 do
    local m=al.getMemoryRecord(i); local n=NB.NAMES[m.ID]
    if n then local d=(NB.lang=='ja') and n[2] or n[1]
      if NB.suffix[m.ID] then d=d..' : '..NB.suffix[m.ID] end
      m.Description=d end
  end
  local keep={}
  for _,e in ipairs(NB.dyn) do if pcall(function() e.mr.Description=NB.T(e.en,e.ja) end) then keep[#keep+1]=e end end
  NB.dyn=keep
end
function NB.setLang(l) NB.lang=l NB.applyLang() end

----------------------------------------------------------------- diagnostics
-- Lua Engine window: record ID 13 is a toggle (check = open / uncheck = close)
function NB.luaEngine() local ok,f=pcall(getLuaEngine) if ok then return f end end
function NB.openLuaEngine(quiet)
  local f=NB.luaEngine()
  if f then pcall(function() f.show() end) pcall(function() f.bringToFront() end) end
  if not quiet then NB.msg('Lua Engine opened. Messages of this table are printed here.','Lua Engineを開きました。このテーブルのメッセージはここに表示されます。') end
end
function NB.closeLuaEngine()
  local f=NB.luaEngine()
  if f then pcall(function() f.hide() end) end
end
function NB.envReport()
  NB.openLuaEngine(true)
  local pid=getOpenedProcessID()
  print(('[%s] CE version      : %s'):format(NB.TAG, tostring(getCEVersion and getCEVersion())))
  print(('[%s] target process  : %s (running PID %s / opened PID %s / table PID %s)'):format(NB.TAG, NB.EXE,
        tostring(getProcessIDFromProcessName(NB.EXE)), tostring(pid), tostring(NB.pid)))
  local okx,x64=pcall(targetIs64Bit) print(('[%s] target 64-bit   : %s'):format(NB.TAG, tostring(okx and x64)))
  local m=NB.mod()
  if m then
    local lf=ri(m+0x3C); local ts=lf and readInteger(m+lf+8)
    print(('[%s] module          : %s base=%X size=%X PE-timestamp=%X'):format(NB.TAG, NB.MODULE, m, NB.modSize() or 0, ts or 0))
    if NB.BUILD then print(('[%s] expected build  : timestamp=%X size=%X (v%s)'):format(NB.TAG, NB.BUILD.ts, NB.BUILD.size or 0, NB.GAMEVER)) end
  else print(('[%s] module          : %s NOT FOUND'):format(NB.TAG, NB.MODULE)) end
  print(('[%s] shared memory   : nbFlags=%s'):format(NB.TAG, NB.base() and hex(NB.base()) or 'not allocated'))
  print(('[%s] attached        : %s'):format(NB.TAG, tostring(NB.attached())))
end
function NB.statusReport()
  NB.openLuaEngine(true)
  local l=NB.pendingNames()
  print(('[%s] unresolved signatures: %s'):format(NB.TAG, #l&gt;0 and table.concat(l,', ') or '-'))
  local h={} for n,st in pairs(NB.hookState) do h[#h+1]=('%s@%X'):format(n,st.addr) end table.sort(h)
  print(('[%s] active hooks        : %s'):format(NB.TAG, #h&gt;0 and table.concat(h,', ') or '-'))
  local f={} for k in pairs(NB.featOn) do f[#f+1]=k end table.sort(f)
  print(('[%s] features on         : %s'):format(NB.TAG, #f&gt;0 and table.concat(f,', ') or '-'))
  local al=getAddressList(); local a={}
  for i=0,al.Count-1 do local m=al.getMemoryRecord(i) if m.Active then a[#a+1]=('[%d] %s'):format(m.ID,m.Description) end end
  print(('[%s] active records      : %s'):format(NB.TAG, #a&gt;0 and table.concat(a,' / ') or '-'))
end


function NB.deferOff(mr)
 local t=createTimer(nil,false);t.Interval=50
 t.OnTimer=function(tt) tt.destroy();pcall(function() mr.Active=false end) end
 t.Enabled=true
end

-- Validated layout: x86 Nobunaga11WPK, Steam build 2431466.
-- Code addresses come from unique AOBs. Root and every object are checked by MSVC RTTI.
NB.GAMES={
 {'Tenkasousei with Power Up Kit','天下創世 with パワーアップキット','Nobunaga11WPK.exe'},
 {'Kakushin with Power Up Kit','革新 with パワーアップキット','NOBU12PK.exe'},
 {'Tendou with Power Up Kit','天道 with パワーアップキット','NOBU13PK.exe'},
 {'Taishi','大志','NOBU15.exe'},
 {'Awakening','新生','NOBU16.exe'}}
NB.layout={
 officer={offset=4,stride=0xB4,count=2016,first=577,class='CBushou',key=0xB3},
 force={offset=0x58AF0,stride=0x1C4,count=100,first=77,class='CDaimyou',key=0x4C},
 castle={offset=0x657A0,stride=0x670,count=100,first=277,class='CJoushu',key=0x3D},
 city={offset=0xA3BE0,stride=0x1DBD4,count=100,first=177,class='CRyouchi',key=0x6B},
 treasure={offset=0x8DB60,stride=0x64,count=630,first=2839,class='CKahou',key=0x53},
 castleName={offset=0xC88DF0,stride=0x30,count=255,first=4026,class='CShiroName',key=0x6C},
 world={offset=0xC84120,class='CZentai',key=0xA3}}

function NB.rol(v,n,bits)
 local mask=(1&lt;&lt;bits)-1;v=v&amp;mask
 return ((v&lt;&lt;n)|(v&gt;&gt;(bits-n)))&amp;mask
end
function NB.decode(v,key,bits)
 if v==nil then return nil end
 local k=0;for i=0,bits//8-1 do k=k|(key&lt;&lt;(i*8)) end
 return NB.rol(v~(k~((1&lt;&lt;bits)-1)),({[8]=3,[16]=7,[32]=13})[bits],bits)~k
end
function NB.encode(v,key,bits)
 local k=0;for i=0,bits//8-1 do k=k|(key&lt;&lt;(i*8)) end
 return NB.rol(v~k,bits-({[8]=3,[16]=7,[32]=13})[bits],bits)~(k~((1&lt;&lt;bits)-1))
end
function NB.number(p,key,bits)
 if not p then return nil end
 local v=bits==8 and readBytes(p,1) or bits==16 and readSmallInteger(p) or readInteger(p)
 return NB.decode(v,key,bits)
end
function NB.store(p,key,bits,value)
 local v=NB.encode(value,key,bits)
 if bits==8 then assert(writeBytes(p,v)) elseif bits==16 then assert(writeSmallInteger(p,v)) else assert(writeInteger(p,v)) end
end
function NB.class(p)
 if not p or p&lt;0x10000 then return nil end
 local vt=readInteger(p);local col=vt and readInteger(vt-4)
 local td=col and readInteger(col+12)
 local s=td and readString(td+8,100)
 return s and s:match('^%.%?AV([^@]+)@@$')
end
function NB.objectID(p)
 local v=p and readSmallInteger(p+4)
 return v and (NB.rol(v~0xA9A9,7,16)~0x5656)
end
function NB.object(kind,index)
 local l=NB.layout[kind]
 if not NB.root or not l or not index or index%1~=0 or index&lt;0 or index&gt;=l.count then return nil end
 local p=NB.root+l.offset+l.stride*index
 if NB.objectID(p)~=l.first+index or NB.class(p)~=l.class then return nil end
 return p
end
function NB.byID(kind,id)
 local l=NB.layout[kind];return id and NB.object(kind,id-l.first)
end
function NB.text(p,n,key)
 local b=readBytes(p,n,true);if not b then return '' end
 local s={};for _,v in ipairs(b) do local d=NB.decode(v,key,8);if d==0 then break end;s[#s+1]=string.char(d) end
 local raw=table.concat(s)
 return ansiToUtf8(raw)
end
function NB.officerName(p)
 if NB.class(p)~='CBushou' then return '' end
 return NB.text(p+8,9,0xB3)..NB.text(p+0x22,9,0xB3)
end
function NB.cityName(p)
 if NB.class(p)~='CRyouchi' then return '' end
 local n=NB.byID('castleName',NB.number(p+8,0x6B,16))
 return n and NB.text(n+8,11,0x6C) or NB.T('(name unavailable)','（名前取得不可）')
end
function NB.playerForceID()
 if not NB.root then return nil end
 local p=NB.root+NB.layout.world.offset
 if NB.class(p)~='CZentai' then return nil end
 return NB.number(p+0xE,0xA3,16)
end
function NB.player()
 local f=NB.byID('force',NB.playerForceID())
 return f and NB.byID('officer',NB.number(f+0xA,0x4C,16))
end
function NB.homeCity()
 local p=NB.player();local castle=p and NB.number(p+0x72,0xB3,16)
 return castle and NB.byID('city',castle-100)
end
function NB.selected(kind)
 if kind=='player' then return NB.player() end
 if kind=='officer' then return NB.byID('officer',NB.selOfficer) end
 if kind=='city' then return NB.byID('city',NB.selCity) end
end
function NB.currentBuild()
 local m=NB.mod();local pe=m and readInteger(m+0x3C)
 return pe and readInteger(m+pe+8)==NB.BUILD.ts and readInteger(m+pe+0x50)==NB.BUILD.size
end
local templateRequire=NB.require
function NB.require()
 templateRequire()
 if NB.game~=1 or not NB.currentBuild() or NB.class(NB.root)~='CNobu11Data' then
  NB.err('Unsupported game/build or invalid data root.','対応外の作品・ビルド、またはゲームデータが無効です。')
 end
end
function NB.dataReady()
 NB.require()
 if not NB.player() then NB.err('Load a playable game first.','先にプレイ中のゲームをロードしてください。') end
end
function NB.onAttach()
 -- SYNCHRONIZE handle refers to this process instance even if Windows reuses its PID.
 if not NB.lifeHandle then
  local h=executeCodeLocalEx('kernel32.OpenProcess',0x100000,0,getOpenedProcessID())
  if h and h~=0 then NB.lifeHandle=h end
 end
 if not NB.currentBuild() then NB.err('This build is not supported yet.','このビルドにはまだ対応していません。') end
 local a=NB.A.root or NB.err('Data resolver was not found.','データ検出コードが見つかりません。')
 NB.root=readInteger(a+0x2F)
 assert(NB.class(NB.root)=='CNobu11Data','CNobu11Data RTTI mismatch')
 for _,kind in ipairs({'officer','force','castle','city','treasure','castleName'}) do
  assert(NB.object(kind,0),kind..' array failed RTTI/ID validation')
 end
 assert(NB.class(NB.root+NB.layout.world.offset)=='CZentai','CZentai RTTI mismatch')
 NB.selOfficer=nil;NB.selCity=nil
 if NB.player() then NB.selOfficer=NB.objectID(NB.player()) end
 if NB.homeCity() then NB.selCity=NB.objectID(NB.homeCity()) end
 NB.refreshSuffix()
end

-- Initialization errors must not transfer state between process instances.
local originalInit=NB.init
function NB.init()
 if NB.pid==getOpenedProcessID() and NB.base() then NB.require();return true end
 local ok,e=pcall(originalInit)
 if not ok then
  -- Initialization errors must not orphan patches already installed in this process.
  if not next(NB.hookState) then NB.forgetProcess() end
  error(e,0)
 end
 NB.require()
 if not NB.root then NB.onAttach() end
 return true
end
-- Reopen the process handle even when CE retains the previous PID/symbols.
function NB.attachGame()
 if NB.game~=1 then NB.err('This operation is only available in Tenkasousei PK.','この操作は天下創世PK専用です。') end
 local pid=getProcessIDFromProcessName(NB.EXE)
 if not pid or pid==0 then NB.err('The game is not running: '..NB.EXE,'ゲームが起動していません: '..NB.EXE) end
 local previous=getOpenedProcessID()
 openProcess(pid)
 if getOpenedProcessID()~=pid then NB.err('Unable to open the selected game.','選択したゲームへの接続に失敗しました。') end
 reinitializeSymbolhandler(true)
 local base=getAddressSafe(NB.EXE)
 if not base or readSmallInteger(base)~=0x5A4D then
  NB.err('The game process could not be read.','ゲームへの接続後、メモリを読み取れませんでした。')
 end
 NB.msg(('Attached to %s (PID %d).'):format(NB.EXE,pid),('%s（PID %d）にアタッチしました。'):format(NB.EXE,pid))
 return previous~=pid
end
local forget=NB.forgetProcess
function NB.forgetProcess()
 if NB.lifeHandle then
  executeCodeLocalEx('kernel32.CloseHandle',NB.lifeHandle);NB.lifeHandle=nil
 end
 if NB.timer then NB.timer.destroy();NB.timer=nil end
 NB.root=nil;NB.selOfficer=nil;NB.selCity=nil;NB.lastLoadedForce=nil
 NB.developmentStable={}
 NB.developmentDirty={};NB.developmentReconciled={}
 NB.investmentCursor={city=0,town=0};NB.investmentSeen={}
 NB.investmentCatalog=nil;NB.investmentCatalogRoot=nil
 forget()
 if NB.editors then
  for _,e in pairs(NB.editors) do pcall(function() NB.clearChildren(e.mr) end) end
 end
 NB.editors={};NB.refreshSuffix()
end

-- Native CE custom types expose the real encoded bytes at their real addresses.
-- Value conversion enforces range limits before CE writes anything.
NB.types={}
function NB.customType(key,bits,lo,hi)
 local name=('NB11_safe2_%02X_%d_%d_%d'):format(key,bits,lo,hi)
 if NB.types[name] then return name end
 local ct=getCustomType(name)
 if not ct then
  ct=registerCustomTypeLua(name,bits//8,function(...)
   local bytes={...};local v=0
   for i=1,bits//8 do v=v|(bytes[i]&lt;&lt;((i-1)*8)) end
   return NB.decode(v,key,bits)
  end,function(value)
   local v=tonumber(value)
   -- CE suppresses Lua converter exceptions and can return undefined bytes.
   -- Conversion must therefore always succeed; UI validation is separate below.
   v=math.max(lo,math.min(hi,math.floor(v or lo)))
   local x=NB.encode(v,key,bits);local b={}
   for i=1,bits//8 do b[i]=(x&gt;&gt;((i-1)*8))&amp;255 end
   return b
  end,false,false)
 end
 assert(ct,'Cannot register custom value type: '..name)
 NB.types[name]=ct;return name
end
NB.fields={
 officer={
  {'Politics','政治',0x3E,8,0,120}, {'Leadership','統率',0x3F,8,0,120},
  {'Intellect','知略',0x41,8,0,120}, {'Culture','教養',0x40,8,0,120},
  {'Loyalty (internal 0-100)','忠誠（内部値0～100）',0x48,8,0,100},
  {'Merit','勲功',0x66,16,0,65535},
  {'Officer soldiers','武将の兵士数',0x68,16,0,65535},
  {'Birth year','誕生年',0x5E,16,1,2200},
  {'Appearance year','登場年',0x60,16,1,2200},
  {'Death year','死亡年',0x62,16,1,2200}},
 city={
  {'Money','金銭',0xC,32,0,99999,'castle'},
  {'Rice','兵糧',0x10,32,0,99999,'castle'},
  {'Soldiers','兵士',0x84,32,0,99999,'city'},
  {'Horses','軍馬',0x14,32,0,99999,'castle'},
  {'Guns','鉄砲',0x18,32,0,99999,'castle'},
  {'Cannons','大筒',0x1C,32,0,99999,'castle'},
  -- CRyouchi property IDs 49 / 4 / 5: matching getters and setters verified.
  {'Popular loyalty','民忠',0x2E,8,0,100,'city'},
  {'Public order','治安',0x0A,8,0,100,'city'},
  {'Flood control','治水',0x0B,8,0,100,'city'},
  {'Money tax (%)','金銭税率（%）',0x0D,8,0,100,'city'},
  {'Toll collection (checkpoint)','通行税（関所の設置）',0x1E,8,0,1,'city',0x10},
  {'Rice tax (%)','兵糧税率（%）',0x0C,8,0,100,'city'},
  {'Commands remaining (castle)','残り命令回数（城）',0x20,8,0,5,'castle'}}}
NB.editors={}
NB.editMeta={}
function NB.clearChildren(mr)
 -- Remove Lua references BEFORE destroying CE objects. pcall does not make
 -- accessing a destroyed native MemoryRecord safe.
 local dead={}
 for i=0,mr.Count-1 do dead[mr.Child[i].ID]=true;NB.editMeta[mr.Child[i].ID]=nil end
 local keep={}
 for _,e in ipairs(NB.dyn) do if not dead[e.mr.ID] then keep[#keep+1]=e end end
 NB.dyn=keep
 while mr.Count&gt;0 do mr.Child[0].Active=false;mr.Child[0].destroy() end
end
NB.PTRS={
 [0]=function() return NB.player() end,
 [1]=function() return NB.selected('officer') end,
 [2]=function() return NB.selected('city') end,
 [3]=function() local c=NB.selected('city');return c and NB.byID('castle',NB.objectID(c)+100) end}
function NB.refreshPointers()
 if not NB.base() then return end
 for slot,fn in pairs(NB.PTRS) do
  local ok,p=pcall(fn);writeQword(NB.base()+NB.OFF_PTRS+slot*8,ok and p or 0)
 end
end
function NB.openEditor(mr,kind)
 NB.dataReady();NB.closeEditor(mr)
 local p=NB.selected(kind)
 if not p then NB.err('Select an officer/city first.','先に武将・都市を選択してください。') end
 NB.refreshPointers()
 local fields=NB.fields[kind=='player' and 'officer' or kind]
 for _,f in ipairs(fields) do
  local slot=kind=='player' and 0 or kind=='officer' and 1 or f[7]=='castle' and 3 or 2
  local key=kind=='city' and (f[7]=='castle' and 0x3D or 0x6B) or 0xB3
  local name=f[8] and NB.customBitType(key,f[8],slot,f[3]) or NB.customType(key,f[4],f[5],f[6])
  local r=NB.addRec(mr,f[1],f[2],'nbPtrs+'..string.format('%X',slot*8),vtCustom)
  r.OffsetCount=1;r.Offset[0]=f[3];r.CustomTypeName=name
  if f[8] then r.DropDownList.Text=NB.T('0:Off\n1:On','0:徴収しない\n1:徴収する');r.DropDownReadOnly=true;r.DropDownDescriptionOnly=true;r.DisplayAsDropDownListItem=true end
  NB.editMeta[r.ID]={kind=kind,field=f,key=key}
  r.OnActivate=function(m,before)
   if before then return NB.userRun(function() NB.dataReady();assert(NB.selected(kind),'Selection unavailable') end) end
   return true
  end
 end
 NB.editors[mr.ID]={mr=mr,kind=kind}
 if kind=='city' then NB.addCitySpecialtyRow(mr) end
 if kind=='player' or kind=='officer' then NB.addOfficerRankRow(mr,kind) end
 mr.Collapsed=false;NB.refreshSuffix()
end
function NB.closeEditor(mr)
 NB.editors[mr.ID]=nil;NB.clearChildren(mr)
end
function NB.unfreezeEditors(kind)
 for _,e in pairs(NB.editors) do
  if e.kind==kind or (kind=='city' and e.kind=='city') then
   for i=0,e.mr.Count-1 do e.mr.Child[i].Active=false end
  end
 end
end
function NB.refreshSuffix()
 if not NB.NAMES then return end
 local o=NB.selected('officer');local c=NB.selected('city');local p=NB.player()
 NB.suffix[24]=nil -- selected title appears in the inline combobox
 NB.suffix[102]=p and NB.officerName(p) or NB.T('(not loaded)','（未ロード）')
 NB.suffix[403]=o and NB.officerName(o) or NB.T('(not selected)','（未選択）')
 NB.suffix[303]=c and NB.cityName(c) or NB.T('(not selected)','（未選択）')
 if NB.refreshCitySpecialtyLabels then NB.refreshCitySpecialtyLabels() end
 if NB.refreshOfficerRankLabels then NB.refreshOfficerRankLabels() end
 NB.applyLang()
end
function NB.selectPlayer()
 NB.dataReady();NB.unfreezeEditors('officer');NB.selOfficer=NB.objectID(NB.player());NB.refreshPointers();NB.refreshSuffix()
end
function NB.selectHomeCity()
 NB.dataReady();local c=NB.homeCity()
 if not c then NB.err('Home castle not found.','所属城を取得できません。') end
 NB.unfreezeEditors('city');NB.selCity=NB.objectID(c);NB.refreshPointers();NB.refreshSuffix()
end
function NB.search(kind)
 NB.dataReady()
 local q=inputQuery(NB.T('Search name','名前を検索'),NB.T('Part of name; blank lists all:','名前の一部を入力。空欄は全件表示：'),'')
 if q==nil then return end
 local hits,names={},{};local layout=NB.layout[kind]
 for i=0,layout.count-1 do
  local p=NB.object(kind,i)
  if p then
   local name=kind=='officer' and NB.officerName(p) or NB.cityName(p)
   local reading=kind=='officer' and (NB.text(p+0x11,17,0xB3)..NB.text(p+0x2B,17,0xB3)) or ''
   if name~='' and (name:find(q,1,true) or reading:find(q,1,true)) then
    hits[#hits+1]=NB.objectID(p);names[#names+1]=('%s  [ID %d]'):format(name,hits[#hits])
   end
  end
 end
 if #hits==0 then NB.msg('Not found.','見つかりません。');return end
 local i=NB.pick(NB.T('Select result','候補を選択'),names);if not i then return end
 NB.unfreezeEditors(kind)
 if kind=='officer' then NB.selOfficer=hits[i] else NB.selCity=hits[i] end
 NB.refreshPointers();NB.refreshSuffix()
end
NB.F.actions={task=function()
 NB.dataReady();local force=NB.playerForceID()
 for i=0,NB.layout.officer.count-1 do
  local p=NB.object('officer',i)
  if p and NB.number(p+0x70,0xB3,16)==force then
   -- Only bit 3 is cleared; preserve sex, injury and status bits.
   local flags=NB.number(p+0x86,0xB3,16)
   if flags and (flags&amp;8)~=0 then NB.store(p+0x86,0xB3,16,flags&amp;0xFFF7) end
  end
 end
 for i=0,NB.layout.castle.count-1 do
  local p=NB.object('castle',i)
  if p and NB.number(p+8,0x3D,16)==force and NB.number(p+0x20,0x3D,8)~=5 then
   NB.store(p+0x20,0x3D,8,5)
  end
 end
end}
NB.F.loyalty={task=function()
 NB.dataReady();local player=NB.player();local force=NB.playerForceID()
 for i=0,NB.layout.officer.count-1 do
  local p=NB.object('officer',i)
  if p and p~=player and NB.officerName(p)~='' and NB.number(p+0x70,0xB3,16)==force then
   if NB.number(p+0x48,0xB3,8)~=100 then NB.store(p+0x48,0xB3,8,100) end
  end
 end
end}
-- Run a feature once before enabling its timer and propagate errors immediately.
local templateFeature=NB.feature
function NB.feature(key,on)
 if on then NB.dataReady();local f=NB.F[key];if f.task then f.task() end end
 return templateFeature(key,on)
end
function NB.transferTreasure(item,target)
 NB.dataReady()
    local oldID=NB.number(item.p+0x40,0x53,16);local old=NB.byID('officer',oldID)
    -- Mirrors CKahou::setOwner(owner, true), including its owner cache updates.
    local oldCache=old and readInteger(old+0xA8);local newCache=readInteger(target+0xA8)
    local raw=readSmallInteger(item.p+0x40)
    local ok,e=pcall(function()
     if old then assert(writeInteger(old+0xA8,0)) end
     assert(writeInteger(target+0xA8,item.p))
     NB.store(item.p+0x40,0x53,16,NB.objectID(target))
    end)
    if not ok then
     writeSmallInteger(item.p+0x40,raw);if old then writeInteger(old+0xA8,oldCache) end;writeInteger(target+0xA8,newCache);error(e)
    end
end
function NB.assignTreasure()
 NB.dataReady()
 local target=NB.selected('officer') or NB.player()
 local categories,all={},{}
 for i=0,NB.layout.treasure.count-1 do
  local p=NB.object('treasure',i)
  if p then
   local name=NB.text(p+8,25,0x53)
   if name~='' then
    local cat=NB.number(p+0x3A,0x53,8)
    if not categories[cat] then categories[cat]={};all[#all+1]=cat end
    categories[cat][#categories[cat]+1]={p=p,name=name,id=NB.objectID(p)}
   end
  end
 end
 table.sort(all)
 local labels={};for _,cat in ipairs(all) do labels[#labels+1]=NB.treasureCategory(cat) end
 local categoryChoice,selection,recipient={},{},{}
 while true do
  local chosen,action=NB.chooseTreasureList(NB.T('Treasure category','家宝の分類'),labels,false,false,categoryChoice)
  if action~='next' then return end;categoryChoice=chosen;local cat=all[chosen[1]];local list=categories[cat]
  local names={};for _,item in ipairs(list) do names[#names+1]=item.name..' [ID '..item.id..']' end
  while true do
   local selected,step=NB.chooseTreasureList(NB.T('Select treasures','家宝を複数選択'),names,true,true,selection[cat])
   selection[cat]=selected
   if step=='cancel' then return end;if step=='back' then break end
   local destinations={NB.T('Selected officer: ','選択武将：')..NB.officerName(target),NB.T('Player daimyo: ','主人公大名：')..NB.officerName(NB.player())}
   local selectedTarget,nav=NB.chooseTreasureList(NB.T('Recipient officer','授与先の武将'),destinations,false,true,recipient,NB.T('Assign','授与'))
   recipient=selectedTarget
   if nav=='cancel' then return end
   if nav=='next' then
    local officer=selectedTarget[1]==1 and target or NB.player()
    for _,index in ipairs(selected) do NB.transferTreasure(list[index],officer) end
    NB.msg(('Assigned %d treasures.'):format(#selected),('家宝を%d件授与しました。'):format(#selected));return
   end
  end
 end
end
function NB.progressReport()
 NB.msg('Tenkasousei PK: officer/city/treasure editors; own-force commands, loyalty, construction, negotiations and battle features. Use the AOB self-test and connection report for compatibility checks.',
 '天下創世PK：武将・都市・家宝編集、自勢力の命令・忠誠・建設・交渉・戦闘機能。互換性の確認にはAOBスキャンテストと接続情報を使用してください。')
end

NB.TREASURE_EN={'Tea caddies','Tea jars','Tea kettles','Tea bowls','Vases','Tea scoops','Incense burners','Water jars','Swords','Spears','Matchlocks','Percussion guns','Pistols','Cannons','Armor','Helmets','Horses','Swordsmanship books','Agriculture books','Commerce books','Architecture books','Anecdotes','Diplomacy books','Martial arts books','Horsemanship books','Gunnery books','Knowledge books','Strategy books','Medical books','Ink paintings','Color paintings','Confectionery','Local drinks','Incense wood'}
function NB.treasureCategory(id)
 if NB.lang~='ja' and NB.TREASURE_EN[id+1] then return NB.TREASURE_EN[id+1] end
 local base=NB.A.treasureCategories;local p=base and readInteger(base+id*4)
 local s=p and readString(p,80)
 return s and ansiToUtf8(s) or NB.T('Category ','分類 ')..id
end
local originalTick=NB.tick
function NB.tick()
 if not NB.pid then return end
 -- A different CE selection suspends this session; it does not destroy hook ownership.
 if getOpenedProcessID()~=NB.pid then return end
 if NB.lifeHandle then
  local status=executeCodeLocalEx('kernel32.WaitForSingleObject',NB.lifeHandle,0)
  if status==0 then NB.forgetProcess();return end
  if status~=258 then return end -- failed/unknown query: suspend, never discard hooks
 end
 -- Symbol refresh/read failures and transient load data are not process termination.
 if not NB.currentBuild() then return end
 local a=NB.A.root
 local root=a and readInteger(a+0x2F)
 if NB.class(root)~='CNobu11Data' then return end
 if root~=NB.root then
  NB.root=root;NB.selOfficer=nil;NB.selCity=nil
  NB.developmentStable={};NB.developmentDirty={};NB.developmentReconciled={}
  NB.investmentCursor={city=0,town=0};NB.investmentSeen={}
  NB.investmentCatalog=nil;NB.investmentCatalogRoot=nil
 end
 if not NB.player() then return end
 local force=NB.playerForceID()
 if NB.lastLoadedForce~=force then
  NB.lastLoadedForce=force
  NB.selOfficer=NB.objectID(NB.player())
  local city=NB.homeCity();NB.selCity=city and NB.objectID(city) or nil
  NB.developmentStable={};NB.developmentDirty={};NB.developmentReconciled={}
  NB.investmentCursor={city=0,town=0};NB.investmentSeen={}
  NB.investmentCatalog=nil;NB.investmentCatalogRoot=nil
 end
 -- Native hooks use shared force guards: update these before resuming tasks.
 if NB.refreshGuards then NB.refreshGuards() end
 originalTick()
end
local originalLang=NB.setLang
function NB.setLang(l)
 originalLang(l);NB.refreshSuffix()
 if NB.display then NB.display.lang=l end
end
function NB.initializeUI()
 NB.applyLang()
 local al=getAddressList()
 for i=0,al.Count-1 do
  local m=al.getMemoryRecord(i)
  if NB.NAMES[m.ID] and m.Count&gt;0 then
   local inSettings=false;local parent=m
   while parent do
    if parent.ID==NB.ID_TOP0 then inSettings=true;break end
    parent=parent.Parent
   end
   m.Collapsed=not inSettings
  end
 end
 NB.previousTableLoad=onTableLoad
 NB.tableLoadHook=function(before)
  if before then NB.shutdown() end
  if NB.previousTableLoad then NB.previousTableLoad(before) end
 end
 onTableLoad=NB.tableLoadHook
end
function NB.shutdown(recordsMayBeGone)
 if NB.timer then NB.timer.destroy();NB.timer=nil end
 if NB.pid==getOpenedProcessID() then
  for key in pairs(NB.featOn) do pcall(NB.feature,key,false) end
 end
 if not recordsMayBeGone then for _,e in pairs(NB.editors) do pcall(NB.closeEditor,e.mr) end end
 if NB.display then NB.display.shutdown() end
 if onTableLoad==NB.tableLoadHook then onTableLoad=NB.previousTableLoad end
 NB.editors={};NB.dyn={};NB.editMeta={};NB.root=nil;NB.selOfficer=nil;NB.selCity=nil
 if NB.lifeHandle then executeCodeLocalEx('kernel32.CloseHandle',NB.lifeHandle);NB.lifeHandle=nil end
 forget()
end

-- City tax flags and specialty map, validated against this build's accessors.
function NB.customBitType(key,mask,slot,offset)
 local name=('NB11_bit_%02X_%02X_%d_%X'):format(key,mask,slot,offset)
 if NB.types[name] then return name end
 local ct=getCustomType(name)
 if not ct then
  ct=registerCustomTypeLua(name,1,function(byte)
   return (NB.decode(byte,key,8)&amp;mask)~=0 and 1 or 0
  end,function(value)
   local p=NB.ptr(slot)
   local raw=p and readBytes(p+offset,1)
   local old=raw and NB.decode(raw,key,8) or 0
   local bit=tonumber(value) or 0
   local merged=(old&amp;(~mask&amp;0xFF))|(bit&gt;=1 and mask or 0)
   return {NB.encode(merged,key,8)}
  end,false,false)
 end
 assert(ct,'Cannot register checkpoint value type')
 NB.types[name]=ct;return name
end
NB.SPECIALTIES={{'Gold mine','金山'},{'Silver mine','銀山'},{'Hot spring','源泉'},{'Port','港'},{'Hunting ground','狩場'},{'None','なし'}}
function NB.specialtyNodes(city)
 assert(NB.class(city)=='CRyouchi','Invalid city')
 local head=assert(readInteger(city+0x14),'Cannot read specialty map')
 assert(head&gt;=0x10000 and readBytes(head+0xF,1)==1,'Invalid specialty map header')
 local stack={assert(readInteger(head+4))};local nodes={};local seen={}
 while #stack&gt;0 do
  local p=table.remove(stack)
  if p~=head then
   assert(p&gt;=0x10000 and not seen[p],'Invalid specialty map link')
   seen[p]=true
   assert(readBytes(p+0xF,1)==0,'Invalid specialty node')
   local id=assert(readBytes(p+0xC,1));assert(id&lt;=4 and not nodes[id],'Invalid specialty ID')
   nodes[id]=p
   stack[#stack+1]=assert(readInteger(p));stack[#stack+1]=assert(readInteger(p+8))
  end
 end
 return nodes
end
function NB.citySpecialtyID(city)
 local nodes=NB.specialtyNodes(city)
 for id=0,4 do if nodes[id] and NB.number(nodes[id]+0xD,0x6B,8)==1 then return id end end
 return 5
end
function NB.refreshCitySpecialtyLabels()
 for _,editor in pairs(NB.editors) do
  if editor.kind=='city' and editor.specialty then
   local p=NB.selected('city');local ok,id=pcall(NB.citySpecialtyID,p)
   local name=ok and NB.SPECIALTIES[id+1] or {'unavailable','取得不可'}
   for _,row in ipairs(NB.dyn) do
    if row.mr==editor.specialty then
     row.en='Specialty: '..name[1]..' (select to change)'
     row.ja='特産：'..name[2]..'（一覧から変更）'
     break
    end
   end
  end
 end
end
function NB.addCitySpecialtyRow(parent)
 local r=NB.addRec(parent,'Specialty (select to change)','特産（一覧から変更）','0',vtAutoAssembler)
 r.Color=NB.C_SCRIPT
 r.Script='[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,NB.changeCitySpecialty)\n{$asm}\n[DISABLE]\n'
 NB.editors[parent.ID].specialty=r
end
function NB.changeCitySpecialty()
 NB.dataReady()
 local p=NB.selected('city');if not p then NB.err('Select a city first.','先に都市を選択してください。') end
 local labels={};for _,v in ipairs(NB.SPECIALTIES) do labels[#labels+1]=NB.T(v[1],v[2]) end
 local choice=NB.pick(NB.T('City specialty','都市の特産'),labels);if not choice then return end
 NB.dataReady();assert(NB.selected('city')==p,'City selection changed')
 NB.setCitySpecialty(p,choice-1)
 NB.refreshSuffix()
end
function NB.setCitySpecialty(p,id)
 assert(type(id)=='number' and id%1==0 and id&gt;=0 and id&lt;=5,'Invalid specialty')
 local nodes=NB.specialtyNodes(p)
 -- Use the game's std::map insertion so later save/load/destruction owns its nodes.
 if id&lt;5 and not nodes[id] then
  local fn=NB.resolveSig('specialtyInsert')
  assert(fn,'Specialty insertion code was not uniquely found')
  local buf=allocateMemory(0x20);assert(buf,'Cannot allocate specialty arguments')
  local ok,e=pcall(function()
   assert(writeBytes(buf+0x10,id,NB.encode(1,0x6B,8)))
   local result=executeMethod(0,-1,fn,{regnr=1,classinstance=p+0x10},buf,buf+0x10)
   assert(result,'Specialty insertion did not return')
  end)
  deAlloc(buf)
  if not ok then error(e,0) end
  nodes=NB.specialtyNodes(p);assert(nodes[id],'Specialty insertion failed')
 end
 for key,node in pairs(nodes) do NB.store(node+0xD,0x6B,8,key==id and 1 or 0) end
 assert(NB.citySpecialtyID(p)==id,'Specialty verification failed')
end

-- Completion mirrors the level/work/day updates in 0x459430. Only the player's
-- existing orders are processed. Money, orders, ownership and placement are kept.
NB.developmentStable={}
function NB.ownedCity(city,force)
 if NB.class(city)~='CRyouchi' then return false end
 local castle=NB.byID('castle',NB.objectID(city)+100)
 return castle and NB.number(castle+8,0x3D,16)==force
end
function NB.facilityWork(id)
 assert(id&gt;=1 and id&lt;=76,'Invalid facility definition ID')
 local p=NB.root+0xC82AA4+id*0x1C
 assert(NB.class(p)=='CShisetsu' and NB.objectID(p)==id,'Invalid facility definition')
 return assert(NB.number(p+0x1A,0x6D,8))
end
NB.developmentDirty={}
NB.developmentReconciled={}
function NB.ensureDevelopmentRecalculation(city)
 -- Reconcile production caches once even when no pending order or vacant facility remains.
 if not NB.developmentReconciled[city] then NB.developmentDirty[city]=true end
end
function NB.refreshDevelopmentCities()
 local fn=NB.resolveSig('cityRecalculate');assert(fn,'City recalculation code was not uniquely found')
 local force=NB.playerForceID()
 for city in pairs(NB.developmentDirty) do
  assert(NB.ownedCity(city,force),'City ownership changed')
  assert(executeMethod(0,-1,fn,{regnr=1,classinstance=city})~=nil,'City recalculation did not return')
  NB.developmentDirty[city]=nil
  NB.developmentReconciled[city]=true
 end
end
function NB.developmentStatus(en,ja)
 local row=getAddressList().getMemoryRecordByID(605)
 if row then NB.NAMES[605]={en,ja};row.Description=NB.T(en,ja) end
end
function NB.reportDevelopment()
 NB.dataReady()
 local force=NB.playerForceID();local towns,facilities=0,0
 for i=0,NB.layout.city.count-1 do
  local city=NB.object('city',i)
  if city and NB.ownedCity(city,force) then
   for n=0,63 do
    local p=city+0x88+n*0x1C
    if (NB.number(p,0x6B,8)&gt;&gt;4)&gt;0 or NB.number(p+1,0x6B,8)&gt;0 then towns=towns+1 end
   end
   for _,array in ipairs({{0x788,0x866},{0x4ABC,0x190}}) do
    local bytes=assert(readBytes(city+array[1],array[2]*8,true))
    for n=0,array[2]-1 do
     local flags=NB.decode(bytes[n*8+5]|(bytes[n*8+6]&lt;&lt;8),0x6B,16)
     if ((flags&gt;&gt;1)&amp;7)~=3 and (flags&gt;&gt;10)&gt;0 then facilities=facilities+1 end
    end
   end
  end
 end
 local placement=NB.lastInvestmentTown
 local en=('Pending: %d towns / %d construction records'):format(towns,facilities)
 local ja=('処理待ち：町並み%d／建設・築城%d'):format(towns,facilities)
 if placement then
  en=en..('; last investment facilities: %d -&gt; %d'):format(placement.before,placement.after)
  ja=ja..('／直近の投資施設数：%d→%d'):format(placement.before,placement.after)
 end
 NB.developmentStatus(en,ja)
 NB.msg(en..'. Reopen the city view after a change. No pending records means there is no existing order to complete; orders not yet reflected in these records require normal game progression. Placement still follows available space and town conditions.',
  ja..'。変更後は都市画面を開き直してください。処理待ち0は既存データに完了対象がない状態です。命令がまだデータに反映されていない場合はゲームを通常どおり進める必要があります。施設追加は空き場所・町並みの条件に従います。')
end
function NB.completeFacilityRecords(city,offset,count,force,filter,maxGrowth)
 local bytes=assert(readBytes(city+offset,count*8,true),'Cannot read construction records')
 local completed=0
 for i=0,count-1 do
  local n=i*8;local flags=NB.decode(bytes[n+5]|(bytes[n+6]&lt;&lt;8),0x6B,16)
  local id=NB.decode(bytes[n+3],0x6B,8)+1
  local growth=maxGrowth and id&gt;=1 and id&lt;=76 and NB.decode(bytes[n+4],0x6B,8)&lt;NB.facilityWork(id)
  if ((flags&gt;&gt;1)&amp;7)==1 and ((flags&gt;&gt;10)&gt;0 or growth) and
     (not filter or filter(NB.decode(bytes[n+3],0x6B,8)+1)) then
   local p=city+offset+n;local current=table.concat({bytes[n+1],bytes[n+2],bytes[n+3],bytes[n+4],bytes[n+5],bytes[n+6]},',')
   local previous=NB.developmentStable[p];NB.developmentStable[p]=current
   if previous==current then
    local id=NB.decode(bytes[n+3],0x6B,8)+1
    local work=NB.facilityWork(id)
    assert(NB.ownedCity(city,force),'City ownership changed')
    local now=assert(readBytes(p,6,true));local same=true
    for j=1,6 do if now[j]~=bytes[n+j] then same=false end end
    if same then
     -- Construction reaches level 1; bits 1..9 retain state/orientation/flags.
     assert(writeBytes(p+3,NB.encode(work,0x6B,8)))
     if not writeSmallInteger(p+4,NB.encode((flags&amp;0x3FE)|1,0x6B,16)) then
      writeBytes(p+3,bytes[n+4]);error('Could not finish construction')
     end
     NB.developmentStable[p]=nil;completed=completed+1;NB.developmentDirty[city]=true
    end
   end
  end
 end
 return completed
end

-- Investment capacity follows the game's 0x425440 / 0x4D8DA0 cap of 16
-- facilities per existing town. Keep its placement rules and facility choices.
function NB.investmentDefinitions()
 if NB.investmentCatalog and NB.investmentCatalogRoot==NB.root then return NB.investmentCatalog end
 local catalog={}
 for id=1,76 do
  local p=NB.root+0xC82AA4+id*0x1C
  assert(NB.class(p)=='CShisetsu' and NB.objectID(p)==id,'Invalid investment facility definition')
  catalog[id]={category=assert(NB.number(p+0x18,0x6D,8))}
 end
 NB.investmentCatalog=catalog;NB.investmentCatalogRoot=NB.root
 return catalog
end
function NB.townFacilityCounts(city)
 local definitions=NB.investmentDefinitions();local counts={}
 for town=0,63 do counts[town]=0 end
 local data=assert(readBytes(city+0x788,0x866*8,true),'Cannot read town facilities')
 for i=0,0x865 do
  local n=i*8;local flags=NB.decode(data[n+5]|(data[n+6]&lt;&lt;8),0x6B,16)
  if ((flags&gt;&gt;1)&amp;7)~=3 then
   local id=NB.decode(data[n+3],0x6B,8)+1;local def=definitions[id]
   if def and def.category&gt;5 then
    local xy=NB.decode(data[n+1]|(data[n+2]&lt;&lt;8),0x6B,16)
    local x=xy&amp;0x7F;local y=xy&gt;&gt;7
    if x&gt;=16 and x&lt;112 and y&gt;=16 and y&lt;112 then
     local town=(x-16)//12+((y-16)//12)*8
     counts[town]=counts[town]+1
    end
   end
  end
 end
 return counts
end
function NB.maximizeTownInvestment(city,town,force)
 assert(NB.ownedCity(city,force),'City ownership changed')
 local p=city+0x88+town*0x1C
 local state=assert(NB.number(p,0x6B,8));local kind=state&amp;0xF
 if kind&lt;1 or kind&gt;14 then return false end
 local counts=NB.townFacilityCounts(city);local before=counts[town]
 if before&gt;=16 then return false end
 local fn=NB.resolveSig('townDevelop');assert(fn,'Town development code was not uniquely found')
 local original=assert(readBytes(p,2,true));local current=before
 local culture=0
 for n=0,63 do
  local value=assert(NB.number(city+0x96+n*0x1C,0x6B,16))
  if value&gt;=0x8000 then value=value-0x10000 end
  culture=culture+value
 end
 culture=math.min(culture,999)
 local ok,e=pcall(function()
  -- The game's one-byte investment work budget is replenished for each
  -- bounded placement pass; the original helper still checks space and cap.
  for pass=1,16 do
   if current&gt;=16 then break end
   assert(NB.ownedCity(city,force) and (NB.number(p,0x6B,8)&amp;0xF)==kind,'Town changed')
   NB.store(p+1,0x6B,8,255)
   local result=executeMethod(0,-1,fn,{regnr=1,classinstance=NB.root},city,town,16-current,0,culture)
   assert(result~=nil,'Investment did not return')
   local after=NB.townFacilityCounts(city)[town]
   assert(after&gt;=current and after&lt;=16,'Unexpected town facility count')
   if after==current then break end
   current=after
  end
 end)
 if not ok or current==before then
  assert(writeBytes(p,original[1],original[2]))
 else
  NB.store(p,0x6B,8,kind);NB.store(p+1,0x6B,8,0)
 end
 NB.developmentStable[p]=nil
 if not ok then error(e,0) end
 NB.lastInvestmentTown={city=NB.objectID(city),town=town,before=before,after=current}
 if current&gt;before then NB.developmentDirty[city]=true end
 return current&gt;before
end
NB.investmentCursor={city=0,town=0};NB.investmentSeen={}
function NB.maximizeInvestmentTask()
 NB.dataReady()
 local force=NB.playerForceID();local definitions=NB.investmentDefinitions()
 local function townFacility(id) return definitions[id] and definitions[id].category&gt;5 end
 for i=NB.investmentCursor.city,NB.layout.city.count-1 do
  local city=NB.object('city',i)
  if city and NB.ownedCity(city,force) then
   NB.ensureDevelopmentRecalculation(city)
   NB.completeFacilityRecords(city,0x788,0x866,force,townFacility,true)
   local counts=NB.townFacilityCounts(city)
   local first=i==NB.investmentCursor.city and NB.investmentCursor.town or 0
   for town=first,63 do
    local state=NB.number(city+0x88+town*0x1C,0x6B,8);local kind=state and state&amp;0xF
    if kind and kind&gt;=1 and kind&lt;=14 and counts[town]&lt;16 then
     local key=city+0x88+town*0x1C;local stamp=kind..':'..counts[town]
     if NB.investmentSeen[key]~=stamp then
      NB.investmentSeen[key]=stamp
      local changed=NB.maximizeTownInvestment(city,town,force)
      NB.developmentStatus(changed and 'Investment: facilities added; city statistics updated' or 'Investment: no additional facility placed in the last town',
       changed and '投資：施設追加あり・都市情報を再集計' or '投資：直近の町並みには施設を追加できませんでした')
      NB.investmentSeen[key]=kind..':'..NB.townFacilityCounts(city)[town]
      NB.investmentCursor={city=i,town=town+1}
      return
     end
    end
   end
  end
 end
 NB.investmentCursor={city=0,town=0}
end
function NB.runInvestmentTask()
 local ok,e=pcall(function() NB.maximizeInvestmentTask();NB.refreshDevelopmentCities() end)
 if not ok then
  NB.featOn.maxInvestment=nil
  local row=getAddressList().getMemoryRecordByID(604)
  if row and row.Active then row.Active=false end
  NB.msg('Investment maximization stopped: '..tostring(e),'投資最大化を停止しました：'..tostring(e))
  error(e,0)
 end
end
NB.F.maxInvestment={task=NB.runInvestmentTask,off=function()
 NB.investmentCursor={city=0,town=0};NB.investmentSeen={}
 NB.developmentReconciled={}
end}
function NB.completeTown(city,index,force)
 local p=city+0x88+index*0x1C
 local state=assert(NB.number(p,0x6B,8));local skill=assert(NB.number(p+1,0x6B,8))
 local kind=state&amp;0xF
 if kind&lt;1 or kind&gt;14 or (state&gt;&gt;4)==0 and skill==0 then return false end
 local stamp=tostring(state)..':'..skill;local previous=NB.developmentStable[p]
 NB.developmentStable[p]=stamp
 if previous~=stamp then return false end
 local fn=NB.resolveSig('townDevelop');assert(fn,'Town development code was not uniquely found')
 assert(NB.ownedCity(city,force),'City ownership changed')
 if NB.number(p,0x6B,8)~=state or NB.number(p+1,0x6B,8)~=skill then return false end
 -- Japanese culture used by the original placement routine: sum town culture,
 -- capped at 999, as in CRyouchi::getJapaneseCulture (0x435190).
 local culture=0
 for n=0,63 do
  local value=assert(NB.number(city+0x96+n*0x1C,0x6B,16))
  if value&gt;=0x8000 then value=value-0x10000 end
  culture=culture+value
 end
 culture=math.min(culture,999)
 -- 16 is the game's existing facility cap per town. Placement and requirements
 -- remain handled by its original helper; a full or unsuitable town may stop early.
 local result=executeMethod(0,-1,fn,{regnr=1,classinstance=NB.root},city,index,16,0,culture)
 assert(result~=nil,'Town development did not return')
 NB.store(p,0x6B,8,kind);NB.store(p+1,0x6B,8,0)
 NB.developmentDirty[city]=true
 NB.developmentStable[p]=nil
 return true
end
function NB.completeDevelopment()
 NB.dataReady()
 local force=NB.playerForceID();local townDone=false;local count=0
 for i=0,NB.layout.city.count-1 do
  local city=NB.object('city',i)
  if city and NB.ownedCity(city,force) then
   NB.ensureDevelopmentRecalculation(city)
   if not townDone then
    for town=0,63 do if NB.completeTown(city,town,force) then townDone=true;break end end
   end
   count=count+NB.completeFacilityRecords(city,0x788,0x866,force)
   count=count+NB.completeFacilityRecords(city,0x4ABC,0x190,force)
  end
 end
 NB.lastDevelopmentCompleted=count
 NB.developmentStatus(('Completion: %d facility records / %d town order'):format(count,townDone and 1 or 0),
  ('即完了：建設・築城%d／町並み%d（今回）'):format(count,townDone and 1 or 0))
end
function NB.runDevelopmentTask()
 local ok,e=pcall(function() NB.completeDevelopment();NB.refreshDevelopmentCities() end)
 if not ok then
  NB.featOn.instantDevelopment=nil
  local row=getAddressList().getMemoryRecordByID(602)
  if row and row.Active then row.Active=false end
  NB.msg('Completion stopped: '..tostring(e),'即完了を停止しました：'..tostring(e))
  error(e,0)
 end
end
NB.F.instantDevelopment={task=NB.runDevelopmentTask,off=function() NB.developmentStable={};NB.developmentReconciled={} end}

-- CRyouchi::isTownAvailable(type) (0x430550) reads an encrypted BIT ARRAY,
-- so each byte uses the 8-bit codec, not the 16-bit codec. IDs 1..14 are real
-- town types; preserve reserved bits 0 and 15 and all adjacent bytes.
function NB.unlockCityDevelopment()
 NB.dataReady()
 assert(NB.resolveSig('townEligibility'),'Town availability code was not uniquely found')
 local force=NB.playerForceID();local cities={}
 for i=0,NB.layout.city.count-1 do
  local city=NB.object('city',i)
  if city and NB.ownedCity(city,force) then cities[#cities+1]=city end
 end
 local count=0
 for _,city in ipairs(cities) do
  assert(NB.ownedCity(city,force),'City ownership changed')
  local p=city+0x1D744
  local first=assert(readBytes(p,1));local second=assert(readBytes(p+1,1))
  local lo=NB.decode(first,0x6B,8);local hi=NB.decode(second,0x6B,8)
  if (lo&amp;0xFE)~=0xFE or (hi&amp;0x7F)~=0x7F then
   assert(writeBytes(p,NB.encode(lo|0xFE,0x6B,8)))
   if not writeBytes(p+1,NB.encode(hi|0x7F,0x6B,8)) then
    writeBytes(p,first);error('Could not unlock town development')
   end
   count=count+1
  end
 end
 NB.msg(('Unlocked all 14 town types in %d own cities.'):format(count),
  ('自勢力の都市%dか所で、14種類の町並みの開発制限を解除しました。'):format(count))
end

-- Reuse the verified editor fields and their encoded storage formats.
-- Only the requested nine resources/stats are maintained; taxes and specialities
-- are excluded. No native game calls, executable patches or allocations are used.
local targets={Money=99999,Rice=99999,Soldiers=99999,Horses=99999,Guns=99999,Cannons=99999,
 ['Popular loyalty']=100,['Public order']=100,['Flood control']=100}
local fields={}
for _,f in ipairs(NB.fields.city) do
 local value=targets[f[1]]
 if value then
  assert(not f[8] and value&gt;=f[5] and value&lt;=f[6],'Invalid city maximum field')
  fields[#fields+1]={field=f,value=value}
 end
end
assert(#fields==9,'Missing city maximum field')
function NB.maximizeOwnedCities()
 NB.dataReady()
 local root=NB.root;local force=assert(NB.playerForceID(),'Player force unavailable')
 local groups={}
 -- Validate every target address/read before the first write in this update.
 for i=0,NB.layout.city.count-1 do
  local city=NB.object('city',i)
  local castle=city and NB.byID('castle',NB.objectID(city)+100)
  if castle and NB.number(castle+8,0x3D,16)==force then
   local group={city=city,castle=castle,items={}}
   for _,spec in ipairs(fields) do
    local f=spec.field;local key=f[7]=='castle' and 0x3D or 0x6B
    local p=f[7]=='castle' and castle or city
    local old=NB.number(p+f[3],key,f[4])
    assert(old~=nil,'Cannot read city maximum target')
    group.items[#group.items+1]={address=p+f[3],key=key,bits=f[4],old=old,value=spec.value}
   end
   groups[#groups+1]=group
  end
 end
 for _,group in ipairs(groups) do
  assert(NB.root==root and NB.playerForceID()==force,'Game state changed')
  assert(NB.objectID(group.city)+100==NB.objectID(group.castle),'City/castle link changed')
  assert(NB.number(group.castle+8,0x3D,16)==force,'City ownership changed')
  for _,item in ipairs(group.items) do
   if item.old~=item.value then NB.store(item.address,item.key,item.bits,item.value) end
  end
 end
 return #groups
end
NB.F.cityMax={on=NB.maximizeOwnedCities,task=NB.maximizeOwnedCities}

-- No global RNG patch. Guard every change by actual acting officer class/force.
function NB.refreshGuards()
 NB.dataReady()
 local force=NB.playerForceID();local p=NB.player()
 assert(writeSmallInteger(NB.var(4),NB.encode(force,0xB3,16)))
 assert(writeInteger(NB.var(8),readInteger(p)))
end
local function equalBytes(a,b)
 if not a or not b or #a~=#b then return false end
 for i=1,#a do if a[i]~=b[i] then return false end end
 return true
end
local function parseBytes(s)
 local r={};for x in s:gmatch('%x%x') do r[#r+1]=tonumber(x,16) end;return r
end
local function db(b)
 local r={};for _,x in ipairs(b) do r[#r+1]=string.format('%02X',x) end;return 'db '..table.concat(r,' ')
end
-- Override the template fallback restore: unknown code is never overwritten.
-- Trampolines are deliberately retained until process exit so an executing
-- thread cannot return into freed memory during disable.
function NB.hookOn(name)
 if NB.hookState[name] then return end
 NB.refreshGuards()
 local h=assert(NB.HOOKS[name]);local sg=assert(NB.SIGS[h.sig])
 local a=NB.resolveSig(h.sig)
 if not a then NB.err('Required code was not uniquely found: '..name,'必要なコードを一意に検出できません：'..name) end
 local expected=parseBytes(sg.expected);local original=readBytes(a,sg.len,true)
 if not equalBytes(original,expected) then NB.err('Hook site is already modified: '..name,'フック箇所が既に変更されています：'..name) end
 local script=h.aa:gsub('%$SITE','nbA_'..h.sig):gsub('%$ORIG',db(original)):gsub('%$NOP',sg.len&gt;5 and ('nop '..(sg.len-5)) or '')
 local ok,info=autoAssemble(script)
 if not ok then NB.err('Hook assembly failed: '..tostring(info),'フックの組み立てに失敗：'..tostring(info)) end
 NB.hookState[name]={addr=a,orig=original,patch=readBytes(a,sg.len,true),script=script,info=info,pid=NB.pid}
end
function NB.hookOff(name)
 local st=NB.hookState[name];if not st then return end
 if NB.pid==st.pid and getOpenedProcessID()==st.pid then
  local current=readBytes(st.addr,#st.orig,true)
  if not equalBytes(current,st.orig) then
   if not equalBytes(current,st.patch) then NB.err('Unknown hook owner; restoration refused: '..name,'フックの所有者が不明なため復元しません：'..name) end
   if not autoAssemble(st.script,st.info) then NB.err('Cannot restore hook: '..name,'フックを復元できません：'..name) end
  end
 end
 NB.hookState[name]=nil
end
local guard=[[
pushfd
push eax
push edx
mov eax,$ACTOR
test eax,eax
jz fallback
mov edx,[nbVars+8]
cmp [eax],edx
jne fallback
mov dx,[nbVars+4]
cmp [eax+70],dx
jne fallback
]]
NB.HOOKS.recruitment={sig='recruitChance',aa=[[
[ENABLE]
assert($SITE,83 EC 24 53 8B 5C 24 30)
alloc(nb_recruit,$1000,$SITE)
label(fallback)
label(return)
nb_recruit:
cmp byte ptr [nbFlags+10],0
je return
]]..guard:gsub('%$ACTOR','[esp+14]')..[[
pop edx
pop eax
popfd
mov eax,64
ret 8
fallback:
pop edx
pop eax
popfd
return:
$ORIG
jmp nbA_recruitChance+8
$SITE:
jmp nb_recruit
$NOP
[DISABLE]
$SITE:
$ORIG
]]}
local schemeHooks={}
for _,name in ipairs({'spyResult','rumorResult','sabotageResult','collusionResult','incitementResult'}) do
 local block='nb_'..name
 NB.HOOKS[name]={sig=name,aa=([[
[ENABLE]
assert($SITE,8B 00 33 C9 85 C0)
alloc(%s,$1000,$SITE)
label(done)
%s:
mov eax,[eax]
pushfd
push edx
cmp byte ptr [nbFlags+11],0
je done
test edi,edi
jz done
mov edx,[nbVars+8]
cmp [edi],edx
jne done
mov dx,[nbVars+4]
cmp [edi+70],dx
jne done
test eax,eax
jg done
mov eax,1
done:
pop edx
popfd
xor ecx,ecx
test eax,eax
jmp nbA_%s+6
$SITE:
jmp %s
$NOP
[DISABLE]
$SITE:
$ORIG
]]):format(block,block,name,block)}
 schemeHooks[#schemeHooks+1]=name
end
NB.F.recruitment={hooks={'recruitment'},flag=0x10,task=NB.refreshGuards}
NB.F.schemes={hooks=schemeHooks,flag=0x11,task=NB.refreshGuards}
local feature=NB.feature
function NB.feature(key,on)
 if on then
  local ok,e=pcall(feature,key,true)
  if not ok then
   NB.featOn[key]=nil
   local f=NB.F[key]
   if NB.attached() and f.flag then writeBytes(NB.flag(f.flag),0) end
   for _,h in ipairs(f.hooks or {}) do
    local used=false
    for k in pairs(NB.featOn) do
     for _,other in ipairs(NB.F[k].hooks or {}) do if other==h then used=true end end
    end
    if not used then pcall(NB.hookOff,h) end
   end
   error(e,0)
  end
 else feature(key,false) end
end

-- CKani owner and CBushou's cached rank must agree (415C60 / 402820).
NB.layout.rank={offset=0x9E150,stride=0x38,count=350,first=3469,class='CKani',key=0x6A}
function NB.officerRank(officer)
 assert(NB.class(officer)=='CBushou','Invalid officer')
 local p=assert(readInteger(officer+0xAC))
 if p==0 then return nil end
 assert(NB.class(p)=='CKani' and NB.byID('rank',NB.objectID(p))==p,'Invalid rank cache')
 assert(NB.number(p+8,0x6A,16)==NB.objectID(officer),'Rank owner/cache mismatch')
 return p
end
function NB.setOfficerRank(officer,rank)
 NB.dataReady()
 local old=NB.officerRank(officer)
 local other
 if rank then
  assert(NB.class(rank)=='CKani' and NB.byID('rank',NB.objectID(rank))==rank,'Invalid rank')
  local owner=NB.number(rank+8,0x6A,16)
  if owner~=0xFFFF then
   other=NB.byID('officer',owner)
   local forceOwner=NB.byID('force',owner)
   assert((other and NB.officerRank(other)==rank) or forceOwner,'Rank owner/cache mismatch')
  end
 end
 local force=NB.byID('force',NB.number(officer+0x70,0xB3,16))
 local lower={}
 if rank and force then
  local grade=assert(NB.number(rank+0x34,0x6A,8));assert(grade&lt;=23,'Invalid rank grade')
  local previous=old and assert(NB.number(old+0x34,0x6A,8)) or -1
  -- Re-selecting a rank synchronizes its owner and the officer cache.
  if not old or grade&gt;previous or old==rank then
   for i=0,NB.layout.rank.count-1 do
    local title=assert(NB.object('rank',i),'Invalid rank array')
    local g=assert(NB.number(title+0x34,0x6A,8));assert(g&lt;=23,'Invalid rank grade')
    if title~=rank and g&lt;grade and NB.number(title+8,0x6A,16)==0xFFFF then
     lower[#lower+1]=title
    end
   end
  end
 end
 if old==rank and #lower==0 then return end
 local setter=assert(NB.resolveSig('rankSetOwner'),'Rank ownership setter was not uniquely found')
 -- Use the game's own ownership setter (415C60). Its writes are only the old
 -- officer cache, new officer cache, and the title owner. Snapshot all three.
 local changes={};local saved={}
 local function save(p,n)
  if saved[p] then return end
  local entry={p=p,bytes=assert(readBytes(p,n,true))}
  changes[#changes+1]=entry;saved[p]=entry
 end
 local function touch(p) assert(saved[p]).changed=true end
 save(officer+0xAC,4)
 if old then save(old+8,2) end
 if rank then save(rank+8,2) end
 for _,title in ipairs(lower) do save(title+8,2) end
 if other and other~=officer then save(other+0xAC,4) end
 local ok,e=pcall(function()
  -- Normal court promotions retain the previous title as a force-owned title
  -- (4A4C90), available for grants to subordinates.
  local oldOwner=rank and force and NB.objectID(force) or 0xFFFF
  if old~=rank then
   touch(officer+0xAC)
   if old then touch(old+8);assert(executeMethod(0,-1,setter,{regnr=1,classinstance=old},oldOwner)~=nil,'Previous rank update did not return') end
   if rank then
    touch(rank+8);if other and other~=officer then touch(other+0xAC) end
    assert(executeMethod(0,-1,setter,{regnr=1,classinstance=rank},NB.objectID(officer))~=nil,'New rank update did not return')
   end
  end
  for _,title in ipairs(lower) do
   assert(NB.number(title+8,0x6A,16)==0xFFFF,'Lower rank ownership changed')
   assert(NB.number(officer+0x70,0xB3,16)==NB.objectID(force),'Officer force changed')
   touch(title+8)
   assert(executeMethod(0,-1,setter,{regnr=1,classinstance=title},NB.objectID(force))~=nil,'Lower rank update did not return')
   assert(NB.number(title+8,0x6A,16)==NB.objectID(force),'Lower rank ownership verification failed')
  end
  assert(NB.officerRank(officer)==rank,'Rank assignment verification failed')
  if old and old~=rank then assert(NB.number(old+8,0x6A,16)==oldOwner,'Previous rank owner verification failed') end
  if other and other~=officer then assert(NB.officerRank(other)==nil,'Previous holder cache was not cleared') end
 end)
 if not ok then
  for i=#changes,1,-1 do if changes[i].changed then assert(writeBytes(changes[i].p,changes[i].bytes),'Rank rollback failed') end end
  error(e,0)
 end
end
function NB.changeOfficerRank(kind)
 NB.dataReady();local officer=assert(NB.selected(kind),'Select an officer first')
 local ranks={false};local labels={NB.T('None','なし')}
 for i=0,NB.layout.rank.count-1 do
  local p=NB.object('rank',i);local name=p and NB.text(p+0xA,13,0x6A) or ''
  if name~='' then
   local owner=NB.byID('officer',NB.number(p+8,0x6A,16))
   local force=NB.byID('force',NB.number(p+8,0x6A,16))
   local suffix=owner and NB.officerName(owner) or force and NB.T('force-owned','大名家所有')
   labels[#labels+1]=name..(suffix and ' ['..suffix..']' or '')
   ranks[#ranks+1]=p
  end
 end
 local choice=NB.pick(NB.T('Select court rank','官位を選択'),labels);if not choice then return end
 NB.dataReady();assert(NB.selected(kind)==officer,'Officer selection changed')
 NB.setOfficerRank(officer,ranks[choice] or nil);NB.refreshSuffix()
end
function NB.addOfficerRankRow(parent,kind)
 local row=NB.addRec(parent,'Court rank (select to change)','官位（一覧から変更）','0',vtAutoAssembler)
 row.Color=NB.C_SCRIPT
 row.Script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.changeOfficerRank('"..kind.."') end)\n{$asm}\n[DISABLE]\n"
 NB.editors[parent.ID].rank=row
end
function NB.refreshOfficerRankLabels()
 for _,editor in pairs(NB.editors) do
  if editor.rank then
   local officer=NB.selected(editor.kind);local ok,p=pcall(NB.officerRank,officer)
   local name=ok and (p and NB.text(p+0xA,13,0x6A) or NB.T('None','なし')) or NB.T('unavailable','取得不可')
   for _,row in ipairs(NB.dyn) do if row.mr==editor.rank then
    row.en='Court rank: '..name..' (select to change)';row.ja='官位：'..name..'（一覧から変更）';break
   end end
  end
 end
end
-- Authority belongs to CChoutei, contribution to CDaimyou, neither to the officer/city.
NB.PTRS[4]=function()
 local p=NB.root and NB.root+0x58AD4
 if NB.class(p)=='CChoutei' and NB.objectID(p)==2838 then return p end
end
NB.PTRS[5]=function() return NB.byID('force',NB.playerForceID()) end
function NB.openCourtEditor(mr)
 NB.dataReady();NB.closeEditor(mr);NB.refreshPointers()
 assert(NB.PTRS[4]() and NB.PTRS[5](),'Court/force unavailable')
 local fields={
  {'Court authority (global)','朝廷の権威（全勢力共通）',4,0xE7,8,10000},
  {'Court contribution (own force)','朝廷貢献度（自勢力）',5,0x4C,0x1A8,65535}}
 for _,f in ipairs(fields) do
  local row=NB.addRec(mr,f[1],f[2],('nbPtrs+%X'):format(f[3]*8),vtCustom)
  row.OffsetCount=1;row.Offset[0]=f[5];row.CustomTypeName=NB.customType(f[4],16,0,f[6])
  NB.editMeta[row.ID]={kind='court',field={f[1],f[2],f[5],16,0,f[6]},key=f[4]}
  row.OnActivate=function(_,before) if before then return NB.userRun(NB.dataReady) end;return true end
 end
 NB.editors[mr.ID]={mr=mr,kind='court'};mr.Collapsed=false
end

-- Restore the dialog's initial count after each completed negotiation. Never
-- patch the shared decrement globally; require a real own-force CBushou actor.
local negotiationHooks={}
for i=1,12 do
 local name='negotiation'..i;local court=i&lt;=3
 local actor=court and 0x94 or 0xB0;local remaining=court and 0xA0 or 0xB8
 local maximum=court and 0xA4 or 0xBC
 local original=i==12 and ('test eax,eax\nje nbA_'..name..'+B\nmov ecx,esi') or '$ORIG'
 local length=i==12 and 6 or 8
 NB.HOOKS[name]={sig=name,aa=([[
[ENABLE]
alloc(nb_%s,$1000,$SITE)
label(done)
nb_%s:
pushfd
push eax
push edx
cmp byte ptr [nbFlags+12],0
je done
mov eax,[esi+%X]
test eax,eax
jz done
mov edx,[nbVars+8]
cmp [eax],edx
jne done
mov dx,[nbVars+4]
cmp [eax+70],dx
jne done
mov eax,[esi+%X]
cmp eax,1
jl done
cmp eax,5
jg done
mov [esi+%X],eax
done:
pop edx
pop eax
popfd
%s
jmp nbA_%s+%X
$SITE:
jmp nb_%s
$NOP
[DISABLE]
$SITE:
$ORIG
]]):format(name,name,actor,maximum,remaining,original,name,length,name)}
 negotiationHooks[#negotiationHooks+1]=name
end
NB.F.actions.hooks=negotiationHooks;NB.F.actions.flag=0x12
local actionsTask=NB.F.actions.task
NB.F.actions.task=function() NB.refreshGuards();actionsTask() end

-- Negotiation success: dedicated call sites, native success effects retained.
-- No global RNG, owner setter, candidate cache, or whole-function return patch.
local names={}
local function hook(name,actor,original,success,length)
 local block='nb_'..name
 NB.HOOKS[name]={sig=name,aa=([[
[ENABLE]
alloc(%s,$1000,$SITE)
label(fallback)
label(return)
%s:
pushfd
push eax
push edx
cmp byte ptr [nbFlags+13],0
je fallback
mov eax,%s
test eax,eax
jz fallback
mov edx,[nbVars+8]
cmp [eax],edx
jne fallback
mov dx,[nbVars+4]
cmp [eax+70],dx
jne fallback
pop edx
pop eax
popfd
%s
jmp return
fallback:
pop edx
pop eax
popfd
%s
return:
jmp nbA_%s+%X
$SITE:
jmp %s
$NOP
[DISABLE]
$SITE:
$ORIG
]]):format(block,block,actor,success,original,name,length,block)}
 names[#names+1]=name
end
-- Random call has already advanced the RNG. Change only this local result.
hook('negEnemy','edi','$ORIG','mov eax,1\nadd esp,4\ntest eax,eax',5)
-- Threat has deterministic refusals BEFORE the final RNG. Enter native success
-- only after the target/actor checks and temporary-list construction.
hook('negThreat','ebp','mov ecx,esi\ncall Nobunaga11WPK.exe+3160',
 'jmp Nobunaga11WPK.exe+AAE35',7)
-- Tribute lists and funding checks are complete. The native no-demand path
-- transfers 500 gold, updates relations/rewards, and consumes one negotiation.
hook('negTribute','edi','cmp eax,5A\njge Nobunaga11WPK.exe+AD49F',
 'jmp Nobunaga11WPK.exe+AD7A3',9)
-- Valid actor/castle and donation funds were checked before this branch.
hook('negDonation','esi','jg Nobunaga11WPK.exe+A5F87','jmp Nobunaga11WPK.exe+A5F87',6)
-- Keep the initial validity/compatibility check. Skip refusal conditions only.
-- EBX still contains the target force; no list construction has occurred here.
hook('negAllianceRefusal','edi','test eax,eax\nje Nobunaga11WPK.exe+A65E1\nmov edx,[ebp+4]\npush edx',
 'jmp Nobunaga11WPK.exe+A68E9',8)
-- Both lists exist and the RNG call's stack cleanup has run. The native
-- no-demand acceptance path destroys both lists and applies the alliance.
hook('negAllianceDemand','edi','test eax,eax\njne Nobunaga11WPK.exe+A6C11',
 'jmp Nobunaga11WPK.exe+A6F3A',8)

-- Substitute the predicate ONLY in the court's check and selection enumerators.
-- Original 41B0E0 is not patched, so AI and unrelated callers keep their rules.
-- Both enumerators use the same predicate: no fabricated/cached rank pointer.
for _,name in ipairs({'negRankCheck','negRankSelect'}) do
 local block='nb_'..name
 NB.HOOKS[name]={sig=name,aa=([[
[ENABLE]
alloc(%s,$1000,$SITE)
label(predicate)
label(done)
label(return)
%s:
push predicate
jmp nbA_%s+5
predicate:
push esi
push ebx
mov esi,[esp+C]
mov ebx,[esp+10]
push ebx
push esi
call nbA_negRankEligible
add esp,8
test eax,eax
jnz done
cmp byte ptr [nbFlags+13],0
je done
test ebx,ebx
jz done
mov edx,[nbVars+8]
cmp [ebx],edx
jne done
mov dx,[nbVars+4]
cmp [ebx+70],dx
jne done
test esi,esi
jz done
mov edx,[nbVars+C]
cmp [esi],edx
jne done
mov ecx,esi
call nbA_negRankGrade
cmp eax,17
jae return
mov ecx,esi
call nbA_negRankOwner
test eax,eax
jne return
mov eax,1
jmp done
return:
xor eax,eax
done:
pop ebx
pop esi
ret
$SITE:
jmp %s
[DISABLE]
$SITE:
$ORIG
]]):format(block,block,name,block)}
 names[#names+1]=name
end
NB.NEGOTIATION_HOOKS=names
NB.F.negotiationSuccess={hooks=names,flag=0x13,task=function()
 NB.refreshGuards()
 local rank=assert(NB.object('rank',0),'Rank data unavailable')
 assert(NB.class(rank)=='CKani','Rank type mismatch')
 assert(writeInteger(NB.var(0xC),readInteger(rank)))
 for _,name in ipairs({'negRankEligible','negRankOwner','negRankGrade'}) do
  local site=assert(NB.resolveSig(name),'Required rank helper unavailable: '..name)
  local expected={};for b in NB.SIGS[name].expected:gmatch('%x%x') do expected[#expected+1]=tonumber(b,16) end
  local actual=assert(readBytes(site,#expected,true))
  for i,b in ipairs(expected) do assert(actual[i]==b,'Rank helper modified: '..name) end
 end
end}

-- Runtime troop data: wunit_butai aggregates living wunit_shoutai soldiers.
-- Modify proposed lower writes, not the displayed aggregate after damage.
local soldierHooks={}
local function unitGuard(child,flag)
 local text=[[
pushfd
pushad
mov edi,esi
mov edx,[nbVars+%X]
cmp [edi],edx
jne done
]]
 text=text:format(child and 0x24 or 0x20)
 if child then text=text..[[
mov eax,[edi+A0]
push eax
call nbA_battleUnitResolve
add esp,4
test eax,eax
jz done
mov edi,eax
mov edx,[nbVars+20]
cmp [edi],edx
jne done
]] end
 text=text..([[
mov edi,[edi+A4]
test edi,edi
jz done
mov edx,[nbVars+8]
cmp [edi],edx
jne done
cmp byte ptr [nbFlags+23],0
je own
cmp edi,[nbVars+30]
je allow
own:
cmp byte ptr [nbFlags+%X],0
jne force
cmp byte ptr [nbFlags+24],0
je done
force:
mov dx,[nbVars+4]
cmp [edi+70],dx
jne done
allow:
]]):format(flag)
 return text
end
local function wrap(name,body)
 return ([=[
[ENABLE]
alloc(nb_%s,$1000,$SITE)
label(done)
label(own)
label(force)
label(allow)
nb_%s:
%s
done:
popad
popfd
$ORIG
jmp nbA_%s+6
$SITE:
jmp nb_%s
$NOP
[DISABLE]
$SITE:
$ORIG
]=]):format(name,name,body,name,name)
end
for _,spec in ipairs({{'battleSoldierSet',0x1C},{'battleSoldierAdd',0x1C},{'battleSoldierEvent',0},{'battleSoldierDamage',0}}) do
 local name,slot=spec[1],spec[2]
 local body=unitGuard(true,0x20)..([[
mov eax,[esp+%X]
cmp eax,[esi+A8]
jge done
mov eax,[esi+A8]
mov [esp+%X],eax
inc dword ptr [nbVars+40]
]]):format(slot,slot)
 NB.HOOKS[name]={sig=name,aa=wrap(name,body)};soldierHooks[#soldierHooks+1]=name
end
NB.HOOKS.battleMoraleSet={sig='battleMoraleSet',aa=wrap('battleMoraleSet',unitGuard(false,0x21)..[[
// Do not preserve uninitialized / out-of-range old morale during unit creation.
cmp dword ptr [esi+B4],4B0
ja done
mov eax,[esp+1C]
cmp eax,[esi+B4]
jge done
mov eax,[esi+B4]
mov [esp+1C],eax
inc dword ptr [nbVars+44]
]])}
NB.HOOKS.battleFoodConsume={sig='battleFoodConsume',aa=[[
[ENABLE]
alloc(nb_battleFoodConsume,$1000,$SITE)
label(done)
label(own)
label(force)
label(allow)
nb_battleFoodConsume:
pushfd
pushad
cmp dword ptr [esp+28],0
jle done
mov edi,ecx
mov edx,[nbVars+28]
cmp [edi],edx
jne done
movzx eax,word ptr [edi+A]
xor ax,A4A4
rol ax,7
xor ax,5B5B
movzx eax,ax
sub eax,241
cmp eax,7DF
ja done
imul eax,B4
add eax,[nbVars+38]
add eax,4
mov edi,eax
mov edx,[nbVars+8]
cmp [edi],edx
jne done
cmp byte ptr [nbFlags+23],0
je own
cmp edi,[nbVars+30]
je allow
own:
cmp byte ptr [nbFlags+22],0
jne force
cmp byte ptr [nbFlags+24],0
je done
force:
mov dx,[nbVars+4]
cmp [edi+70],dx
jne done
allow:
mov dword ptr [esp+28],0
inc dword ptr [nbVars+48]
done:
popad
popfd
$ORIG
jmp nbA_battleFoodConsume+5
$SITE:
jmp nb_battleFoodConsume
[DISABLE]
$SITE:
$ORIG
]]}
function NB.refreshBattleGuards()
 NB.refreshGuards()
 local function vt(name,expected)
  local p=assert(NB.resolveSig(name),'Missing battle type: '..name)
  local col=readInteger(p-4);local td=col and readInteger(col+12)
  assert(td and readString(td+8,80)=='.?AV'..expected..'@@','Battle RTTI mismatch: '..name)
  return p
 end
 assert(writeInteger(NB.var(0x20),vt('battleMainVT','wunit_butai')))
 assert(writeInteger(NB.var(0x24),vt('battleChildVT','wunit_shoutai')))
 assert(writeInteger(NB.var(0x28),vt('battleArmyVT','CGunzei')))
 assert(writeInteger(NB.var(0x30),NB.player()))
 assert(writeInteger(NB.var(0x38),NB.root))
 local resolver=assert(NB.resolveSig('battleUnitResolve'),'Missing unit resolver')
 local n=0;for byte in NB.SIGS.battleUnitResolve.expected:gmatch('%x%x') do
  assert(readBytes(resolver+n,1)==tonumber(byte,16),'Unit resolver modified');n=n+1
 end
end
local all={};for _,h in ipairs(soldierHooks) do all[#all+1]=h end
all[#all+1]='battleMoraleSet';all[#all+1]='battleFoodConsume'
NB.BATTLE_HOOKS=all
NB.F.playerBattle={flag=0x23,hooks=all,task=NB.refreshBattleGuards}
NB.F.ownBattle={flag=0x24,hooks=all,task=NB.refreshBattleGuards}
-- Twenty learned-skill cooldown slots. Keep -1 (unlearned) and all other
-- eligibility checks. The setter records zero; the update loop clears existing
-- positive waits on the next tick and removes its list node normally.
NB.BATTLE_SKILL_HOOKS={}
for _,spec in ipairs({{'battleSkillSet','ecx'},{'battleSkillTick','esi'}}) do
 local name,reg=spec[1],spec[2]
 local body=([[
pushfd
pushad
cmp byte ptr [nbFlags+26],0
je done
mov edi,%s
mov edx,[nbVars+20]
cmp [edi],edx
jne done
mov edi,[edi+A4]
test edi,edi
jz done
mov edx,[nbVars+8]
cmp [edi],edx
jne done
mov dx,[nbVars+4]
cmp [edi+70],dx
jne done
cmp dword ptr [esp+14],0
jle done
mov dword ptr [esp+14],0
inc dword ptr [nbVars+4C]
]]):format(reg)
 local aa=wrap(name,body):gsub('jmp nbA_'..name..'%+6','jmp nbA_'..name..'+7')
 -- wrap's common label declarations must all be defined even for this guard.
 aa=aa:gsub('label%(own%)\n',''):gsub('label%(force%)\n',''):gsub('label%(allow%)\n','')
 NB.HOOKS[name]={sig=name,aa=aa};NB.BATTLE_SKILL_HOOKS[#NB.BATTLE_SKILL_HOOKS+1]=name
end
NB.F.battleSkills={flag=0x26,hooks=NB.BATTLE_SKILL_HOOKS,task=NB.refreshBattleGuards}

-- Fill on the game thread, from the live primary-unit update, never by scanning
-- stale heap addresses or resurrecting removed/deleted subunit handles.
NB.HOOKS.battleMax={sig='battleMax',aa=[[
[ENABLE]
alloc(nb_battleMax,$1000,$SITE)
label(done)
label(own)
label(allow)
label(loop)
label(next)
label(aggregate)
label(morale)
label(food)
label(moraleFill)
nb_battleMax:
pushfd
pushad
mov esi,ecx
mov edx,[nbVars+20]
cmp [esi],edx
jne done
mov edi,[esi+A4]
test edi,edi
jz done
mov edx,[nbVars+8]
cmp [edi],edx
jne done
cmp byte ptr [nbFlags+23],0
je own
cmp edi,[nbVars+30]
je allow
own:
cmp byte ptr [nbFlags+24],0
je done
mov dx,[nbVars+4]
cmp [edi+70],dx
jne done
allow:
mov ebx,[esi+280]
mov ebp,[esi+284]
cmp ebp,ebx
jb morale
mov eax,ebp
sub eax,ebx
cmp eax,2000
ja morale
test eax,3
jnz morale
xor edi,edi
loop:
cmp ebx,ebp
jae aggregate
mov eax,[ebx]
push eax
call nbA_battleUnitResolve
add esp,4
test eax,eax
jz next
mov edx,[nbVars+24]
cmp [eax],edx
jne next
mov edx,[esi+4]
cmp [eax+A0],edx
jne next
cmp dword ptr [eax+A8],64
jge next
mov dword ptr [eax+A8],64
inc edi
next:
add ebx,4
jmp loop
aggregate:
test edi,edi
jz morale
mov ecx,esi
call nbA_battleAggregate
inc dword ptr [nbVars+50]
morale:
mov eax,[esi+40]
cmp eax,3
ja food
shr eax,1
mov edx,[eax*4+Nobunaga11WPK.exe+1110080]
cmp edx,4B0
jge moraleFill
mov ecx,4B0
sub ecx,edx
push ecx
push dword ptr [esi+40]
mov ecx,Nobunaga11WPK.exe+110FED0
call nbA_battleMoraleCapNative
moraleFill:
mov edx,4B0
cmp [esi+B4],edx
je food
push edx
mov ecx,esi
call nbA_battleMoraleNative
inc dword ptr [nbVars+54]
food:
mov edi,[esi+A8]
test edi,edi
jz done
mov edx,[nbVars+28]
cmp [edi],edx
jne done
movzx eax,word ptr [edi+E]
xor ax,A4A4
rol ax,7
xor ax,5B5B
cmp ax,FFFF
je done
mov eax,FFFF
push eax
mov ecx,edi
call nbA_battleFoodNative
inc dword ptr [nbVars+58]
done:
popad
popfd
$ORIG
jmp nbA_battleMax+9
$SITE:
jmp nb_battleMax
$NOP
[DISABLE]
$SITE:
$ORIG
]]}
NB.BATTLE_HOOKS[#NB.BATTLE_HOOKS+1]='battleMax'
-- playerBattle and ownBattle refer to the same shared hook list.
local basicRefresh=NB.refreshBattleGuards
function NB.refreshBattleGuards()
 basicRefresh()
 for _,name in ipairs({'battleAggregate','battleMoraleNative','battleFoodNative','battleMoraleCapNative'}) do
  local p=assert(NB.resolveSig(name),'Required maximum helper missing: '..name)
  local i=0;for b in NB.SIGS[name].expected:gmatch('%x%x') do
   assert(readBytes(p+i,1)==tonumber(b,16),'Maximum helper modified: '..name);i=i+1
  end
 end
end
NB.F.playerBattle.task=NB.refreshBattleGuards
NB.F.ownBattle.task=NB.refreshBattleGuards

-- Source and target are verified live subunits at the native hostile-hit call.
-- Kill all surviving subunits of the hit enemy main unit through native damage;
-- leave native post-hit defeat, reward and retreat processing in control.
NB.HOOKS.battleOneHit={sig='battleOneHit',aa=[[
[ENABLE]
alloc(nb_battleOneHit,$1000,$SITE)
label(done)
label(loop)
label(next)
nb_battleOneHit:
pushfd
pushad
cmp byte ptr [nbFlags+27],0
je done
cmp ebp,0
jle done
mov edx,[nbVars+24]
cmp [edi],edx
jne done
cmp [ebx],edx
jne done
mov eax,[edi+A0]
push eax
call nbA_battleUnitResolve
add esp,4
test eax,eax
jz done
mov edx,[nbVars+20]
cmp [eax],edx
jne done
mov edx,[eax+A4]
test edx,edx
jz done
mov ecx,[nbVars+8]
cmp [edx],ecx
jne done
mov cx,[nbVars+4]
cmp [edx+70],cx
jne done
mov edi,[eax+40]
cmp edi,3
ja done
shr edi,1
mov eax,[ebx+A0]
push eax
call nbA_battleUnitResolve
add esp,4
test eax,eax
jz done
mov edx,[nbVars+20]
cmp [eax],edx
jne done
mov esi,eax
mov eax,[esi+40]
cmp eax,3
ja done
shr eax,1
cmp eax,edi
je done
mov ebx,[esi+280]
mov edi,[esi+284]
cmp edi,ebx
jb done
mov eax,edi
sub eax,ebx
cmp eax,2000
ja done
test eax,3
jnz done
loop:
cmp ebx,edi
jae done
mov eax,[ebx]
push eax
call nbA_battleUnitResolve
add esp,4
test eax,eax
jz next
mov edx,[nbVars+24]
cmp [eax],edx
jne next
mov edx,[esi+4]
cmp [eax+A0],edx
jne next
mov edx,[eax+A8]
test edx,edx
jle next
push edx
mov ecx,eax
call nbA_battleDamageNative
inc dword ptr [nbVars+5C]
next:
add ebx,4
jmp loop
done:
popad
popfd
call nbA_battleDamageNative
jmp nbA_battleOneHit+5
$SITE:
jmp nb_battleOneHit
[DISABLE]
$SITE:
$ORIG
]]}
NB.F.battleOneHit={flag=0x27,hooks={'battleOneHit'},task=function()
 NB.refreshBattleGuards()
 local p=assert(NB.resolveSig('battleDamageNative'),'Missing native damage routine')
 local i=0;for b in NB.SIGS.battleDamageNative.expected:gmatch('%x%x') do
  assert(readBytes(p+i,1)==tonumber(b,16),'Native damage routine modified');i=i+1
 end
end}

-- The hostile-building hit has already validated the native attack coalition.
-- Change only its positive damage argument, then run normal destruction/capture.
NB.HOOKS.battleBuildingHit={sig='battleBuildingHit',aa=[[
[ENABLE]
alloc(nb_battleBuildingHit,$1000,$SITE)
label(done)
nb_battleBuildingHit:
pushfd
pushad
cmp byte ptr [nbFlags+27],0
je done
cmp dword ptr [esp+24],0
jle done
mov edx,[nbVars+60]
cmp [esi],edx
jne done
mov edx,[nbVars+24]
cmp [ebx],edx
jne done
mov eax,[ebx+A0]
push eax
call nbA_battleUnitResolve
add esp,4
test eax,eax
jz done
mov edx,[nbVars+20]
cmp [eax],edx
jne done
mov edi,[eax+A4]
test edi,edi
jz done
mov edx,[nbVars+8]
cmp [edi],edx
jne done
mov dx,[nbVars+4]
cmp [edi+70],dx
jne done
mov edi,[eax+40]
cmp edi,3
ja done
shr edi,1
mov eax,[esi+8]
xor edx,edx
cmp eax,1
seta dl
cmp edx,edi
je done
mov eax,[esi+18]
test eax,eax
jle done
mov [esp+24],eax
inc dword ptr [nbVars+64]
done:
popad
popfd
call nbA_battleBuildingDamage
jmp nbA_battleBuildingHit+5
$SITE:
jmp nb_battleBuildingHit
[DISABLE]
$SITE:
$ORIG
]]}
NB.F.battleOneHit.hooks[#NB.F.battleOneHit.hooks+1]='battleBuildingHit'
local oneHitRefresh=NB.F.battleOneHit.task
NB.F.battleOneHit.task=function()
 oneHitRefresh()
 local vt=assert(NB.resolveSig('battleBuildingVT'),'Missing building type')
 local col=readInteger(vt-4);local td=col and readInteger(col+12)
 assert(td and readString(td+8,80)=='.?AVwbuilding@@','Building RTTI mismatch')
 assert(writeInteger(NB.var(0x60),vt))
 local p=assert(NB.resolveSig('battleBuildingDamage'),'Missing building damage routine')
 local i=0;for b in NB.SIGS.battleBuildingDamage.expected:gmatch('%x%x') do
  assert(readBytes(p+i,1)==tonumber(b,16),'Building damage routine modified');i=i+1
 end
end

-- Patch only the shared N3D_viewport_ctrl movement/rotation key queries.
-- Character input, menus, arrow keys, numpad and Ctrl+arrows are unchanged.
local keys={}
for _,row in ipairs({{'keyUp',0x57},{'keyDown',0x53},{'keyLeft',0x41},{'keyRight',0x44},{'keyRotateLeft',0x51},{'keyRotateRight',0x45}}) do
 local name,key=row[1],row[2]
 NB.HOOKS[name]={sig=name,aa=('[ENABLE]\n$SITE:\ndb 6A %02X\n[DISABLE]\n$SITE:\n$ORIG'):format(key)}
 keys[#keys+1]=name
end
NB.F.wasd={hooks=keys}

-- Native terrain registration increments the draw count before clipped tiles
-- acquire their mesh. The original draw loop dereferences such empty slots.
-- Guard the terrain-list call only; initialized tiles keep the exact native call.
NB.HOOKS.cameraDrawGuard={sig='cameraDrawGuard',aa=[[
[ENABLE]
alloc(nb_cameraDrawGuard,$1000,$SITE)
label(skip)
nb_cameraDrawGuard:
pushfd
cmp dword ptr [edi+58],0
je skip
push eax
mov eax,[edi+58]
cmp dword ptr [eax+4],0
pop eax
je skip
popfd
$ORIG
jmp nbA_cameraDrawGuard+9
skip:
inc dword ptr [nbVars+74]
popfd
jmp nbA_cameraDrawGuard+9
$SITE:
jmp nb_cameraDrawGuard
$NOP
[DISABLE]
$SITE:
$ORIG
]]}
-- Record live camera instances in reserved shared-data slots, not fixed heap addresses.
NB.HOOKS.cameraCapture={sig='cameraCapture',aa=[[
[ENABLE]
alloc(nb_cameraCapture,$1000,$SITE)
label(find)
label(save)
label(done)
nb_cameraCapture:
pushfd
push eax
push edx
inc dword ptr [nbVars+78]
mov edx,nbVars+80
mov eax,20
find:
cmp [edx],ecx
je done
cmp dword ptr [edx],0
je save
add edx,4
dec eax
jnz find
jmp done
save:
mov [edx],ecx
done:
pop edx
pop eax
popfd
$ORIG
jmp nbA_cameraCapture+6
$SITE:
jmp nb_cameraCapture
$NOP
[DISABLE]
$SITE:
$ORIG
]]}
local bytes={}
for _,v in ipairs({208,238,268,208,228,248}) do
 local s=string.pack('&lt;f',v*3)
 for i=1,4 do bytes[#bytes+1]=string.format('%02X',s:byte(i)) end
end
NB.HOOKS.cameraZoomLimits={sig='cameraZoomLimits',aa='[ENABLE]\n$SITE:\ndb '..table.concat(bytes,' ')..'\n[DISABLE]\n$SITE:\n$ORIG'}
-- The original far clip is 500; a 624..804 camera distance also needs a farther clip.
NB.HOOKS.cameraFarPlane={sig='cameraFarPlane',aa='[ENABLE]\n$SITE:\ndd (float)1500\n[DISABLE]\n$SITE:\n$ORIG'}
-- Extending the far clip must not extend the high-detail terrain radius.
-- The native threshold is near + (far-near)*quality. Keep its original far
-- reference (500 + mode delta), otherwise the 16-bit index buffer fills up.
NB.HOOKS.cameraTerrainLOD={sig='cameraTerrainLOD',aa=[[
[ENABLE]
alloc(nb_cameraTerrainLOD,$1000,$SITE)
label(normalFarOffset)
nb_cameraTerrainLOD:
fld dword ptr [ecx+2C]
fsub dword ptr [normalFarOffset]
fsub dword ptr [ecx+28]
jmp nbA_cameraTerrainLOD+6
normalFarOffset:
dd (float)1000
$SITE:
jmp nb_cameraTerrainLOD
$NOP
[DISABLE]
$SITE:
$ORIG
]]}
-- Request the same scene rebuild used by native camera input. Do not invoke
-- game functions from a CE-created thread; only update the validated dirty count.
function NB.markCameraDirty()
 local a=NB.resolveSig('cameraSceneDirtyGetter')
 if not a or readBytes(a+0x4C,1)~=0xB8 then return false end
 local manager=readInteger(a+0x4D)
 local value=manager and readInteger(manager+0x29C)
 return value and writeInteger(manager+0x29C,(value+1)&amp;0xFFFFFFFF) or false
end
NB.F.cameraZoom={hooks={'cameraDrawGuard','cameraCapture','cameraTerrainLOD','cameraZoomLimits','cameraFarPlane'},on=NB.markCameraDirty,off=function()
 -- Restore data first, return observed cameras inside every native mode's limit,
 -- then let the renderer finish its current queue before removing the guard.
 NB.hookOff('cameraFarPlane');NB.hookOff('cameraZoomLimits')
 for i=0,31 do
  local p=readInteger(NB.var(0x80+i*4))
  if p and NB.class(p)=='third_person_view_camera' then
   local d=readFloat(p+0x68)
   if d and d==d and d&gt;208 then assert(writeFloat(p+0x68,208)) end
  end
 end
 NB.markCameraDirty()
 local n=readInteger(NB.var(0x78));local deadline=getTickCount()+200
 while n and getTickCount()&lt;deadline do
  local now=readInteger(NB.var(0x78))
  if not now or ((now-n)&amp;0xFFFFFFFF)&gt;=2 then break end
  sleep(5)
 end
 -- The hook manager removes the LOD hook after this callback returns. Rebuild
 -- again on the next CE tick so the normal near-view detail is restored as well.
 if NB.cameraDirtyTimer then NB.cameraDirtyTimer.destroy() end
 local timer=createTimer(nil,false);NB.cameraDirtyTimer=timer;timer.Interval=30
 timer.OnTimer=function(t)
  t.destroy();NB.cameraDirtyTimer=nil
  if NB.pid and NB.pid==getOpenedProcessID() and NB.currentBuild() then NB.markCameraDirty() end
 end
 timer.Enabled=true
end}

-- An owned active detour replaces the AOB bytes by design. Verify its exact
-- installed patch instead of classifying it as missing or changing live code.
function NB.signatureStatus(name)
 local sg=assert(NB.SIGS[name]);local m=NB.mod(sg.mod);local size=NB.modSize(sg.mod)
 for _,st in pairs(NB.hookState or {}) do
  if st.pid==NB.pid and st.addr==NB.A[name] then
   local b=readBytes(st.addr,#st.patch,true)
   local same=b and #b==#st.patch
   if same then for i,v in ipairs(st.patch) do if b[i]~=v then same=false;break end end end
   return same and 'ACTIVE / VERIFIED' or 'PATCH MISMATCH',st.addr,same
  end
 end
 if not m or not size then return 'MODULE NOT FOUND',nil,false end
 local hits=NB.aobAll(sg.p,m,m+size,3)
 if #hits==1 then return 'OK',hits[1]+(sg.off or 0),true end
 return #hits==0 and 'NOT FOUND' or 'NOT UNIQUE',nil,false
end
function NB.scanSelfTest()
 NB.openLuaEngine(true);NB.require()
 local names={};for n in pairs(NB.SIGS) do names[#names+1]=n end;table.sort(names)
 local okn,bad=0,0
 for _,name in ipairs(names) do
  local status,p,ok=NB.signatureStatus(name)
  if ok then okn=okn+1 else bad=bad+1 end
  print(('[%s]   %-22s %-20s %s'):format(NB.TAG,name,status,p and string.format('%X',p) or ''))
 end
 NB.msg(('AOB self-test: %d verified, %d failed. Active hooks are verified against their installed bytes.'):format(okn,bad),('AOBスキャンテスト：正常 %d件、異常 %d件。有効なフックは設置済みの命令と照合しています。'):format(okn,bad))
 return okn,bad
end

function NB.makeDisplay()
 local NBDisplay
NBDisplay={revision=2,lang=NB.lang,factor=2,state='Ready - revision 2',pid=0}
local S=NBDisplay
local entry,original,windowGlobal,d3dGlobal
S.buffer=allocateSharedMemoryLocal('NBDisplayLocal_'..getTickCount(),2048)
assert(S.buffer,'Cannot allocate local observation buffer')
S.owner=assert(executeCodeLocalEx('kernel32.GetCurrentProcessId',0),'Cannot identify display controller');S.token=S.buffer &amp; 0xFFFFFFFF
local function api(n,...)
 -- CE executeCodeLocalEx needs a parameter descriptor even for zero-argument APIs.
 -- Extra register arguments are ignored by the Windows x64 zero-argument API.
 if select('#',...)==0 then return executeCodeLocalEx('user32.'..n,0) end
 return executeCodeLocalEx('user32.'..n,...)
end
local function msg(en,ja) return S.lang=='ja' and ja or en end
local function status(en,ja)
 S.state=msg(en,ja); if NB.displayStatus then NB.displayStatus(en,ja) end
 print('[N11 Scale] '..S.state)
end
local function signed(n) return n&gt;=0x80000000 and n-0x100000000 or n end
local function rect(hwnd,client)
 assert(api(client and 'GetClientRect' or 'GetWindowRect',hwnd,S.buffer)~=0,'Window rectangle unavailable')
 return signed(readIntegerLocal(S.buffer)),signed(readIntegerLocal(S.buffer+4)),signed(readIntegerLocal(S.buffer+8)),signed(readIntegerLocal(S.buffer+12))
end
local function windowPid(hwnd)
 if not hwnd or hwnd==0 then return 0 end
 api('GetWindowThreadProcessId',hwnd,S.buffer)
 return readIntegerLocal(S.buffer)
end
local function caption(hwnd)
 api('GetWindowTextW',hwnd,S.buffer,512)
 return readStringLocal(S.buffer,1024,true) or ''
end
local function findGameWindow(pid)
 local h=api('GetTopWindow',0)
 for _=1,10000 do
  if not h or h==0 then break end
  if windowPid(h)==pid then
   local title=caption(h)
   if title~='' and title~='Default IME' and title~='MSCTFIME UI' and title:find('信長',1,true) then return h,title end
  end
  h=api('GetWindow',h,2)
 end
end
local function gamePid()
 local candidates={}
 for pid,name in pairs(getProcessList()) do
  if name:lower()=='nobunaga11wpk.exe' then candidates[#candidates+1]=tonumber(pid) end
 end
 if #candidates&gt;1 then error(msg('More than one game process is running. Close the extra instances.','本体が複数起動しています。余分な本体を終了してください。')) end
 return candidates[1]
end
-- Resolve the executable of the exact running PID. No installation drive
-- or Steam library folder is assumed when checking its supported build.
local function processExePath(pid)
 local handle=executeCodeLocalEx('kernel32.OpenProcess',0x1000,0,pid)
 assert(handle and handle~=0,msg('Cannot read the game executable path.','ゲームの実行ファイルパスを取得できません。'))
 local ok,path=pcall(function()
  writeIntegerLocal(S.buffer+2044,1000)
  assert(executeCodeLocalEx('kernel32.QueryFullProcessImageNameW',handle,0,S.buffer,S.buffer+2044)~=0,
   msg('Cannot read the game executable path.','ゲームの実行ファイルパスを取得できません。'))
  local value=readStringLocal(S.buffer,2000,true)
  assert(value and value~='',msg('The executable path is empty.','実行ファイルパスが空です。'))
  return value
 end)
 executeCodeLocalEx('kernel32.CloseHandle',handle)
 if not ok then error(path,0) end
 return path
end
local function liveSettings()
 local b=getAddressSafe('Nobunaga11WPK.exe')
 if not b or not d3dGlobal then return nil end
 local sys=readInteger(d3dGlobal)
 if not sys or sys==0 then return nil end
 local dev=readInteger(sys+0x5C)
 if not dev or dev==0 then return nil end
 return sys,readInteger(sys+0x20),readInteger(sys+0x24),readInteger(sys+0x28),readInteger(sys+0x3C)
end
S.aa=[[
[ENABLE]
assert(nbDisplayEntry,$ORIGINAL)
alloc(n11DisplayBlock,512,Nobunaga11WPK.exe)
registersymbol(n11DisplayBlock)
label(body)
label(n11DisplayDims)
label(pass)
n11DisplayBlock:
db E9
dd #24
db 4E 31 31 53 43 4C 30 32
n11DisplayDims:
dd #1024 #768
dd #0
dd nbDisplayEntry+6
body:
pushfd
pushad
mov eax,[esp+2C]
cmp eax,200
jb pass
cmp eax,209
ja pass
movsx eax,word ptr [esp+34]
imul eax,400
cdq
idiv [n11DisplayDims]
and eax,FFFF
mov ebx,eax
movsx eax,word ptr [esp+36]
imul eax,300
cdq
idiv [n11DisplayDims+4]
shl eax,10
or eax,ebx
mov [esp+34],eax
pass:
popad
popfd
mov ecx,[nbWindowGlobal]
jmp nbDisplayEntry+6
nbDisplayEntry:
jmp n11DisplayBlock
nop
[DISABLE]
nbDisplayEntry:
db $ORIGINAL
unregistersymbol(n11DisplayBlock)
// Keep the tiny code/data allocations until process exit: a message may still
// be returning through this trampoline when the entry bytes are restored.
]]

local function bytes(a,n)
 local b=readBytes(a,n,true)
 if not b or #b~=n then return nil end
 return string.char(table.unpack(b))
end
local function hex(s)
 local t={};for h in s:gmatch('%x%x') do t[#t+1]=string.char(tonumber(h,16)) end
 return table.concat(t)
end
local function u32(n) return string.pack('&lt;I4',n &amp; 0xFFFFFFFF) end
local function bodyBytes(block)
 local dims=block+13;local body=block+29
 return hex('9C 60 8B 44 24 2C 3D 00 02 00 00 0F 82 3F 00 00 00 3D 09 02 00 00 0F 87 34 00 00 00 0F BF 44 24 34 69 C0 00 04 00 00 99 F7 3D')..
  u32(dims)..hex('25 FF FF 00 00 8B D8 0F BF 44 24 36 69 C0 00 03 00 00 99 F7 3D')..
  u32(dims+4)..hex('C1 E0 10 09 D8 89 44 24 34 61 9D 8B 0D')..u32(windowGlobal)..hex('E9')..u32(entry+6-body-93)
end
local function inspect(pid)
 local code=bytes(entry,6)
 if code==original then return {kind='original'} end
 if not code or code:byte(1)~=0xE9 or code:byte(6)~=0x90 then return {kind='unknown'} end
 local block=entry+5+string.unpack('&lt;i4',code,2)
 if bytes(block,13)~=string.char(0xE9)..u32(24)..'N11SCL02' then return {kind='unknown'} end
 if readInteger(block+21)~=pid or readInteger(block+25)~=entry+6 then return {kind='unknown'} end
 if bytes(block+29,93)~=bodyBytes(block) then return {kind='unknown'} end
 local w,h=readInteger(block+13),readInteger(block+17)
 if not w or not h or w&lt;320 or w&gt;16384 or h&lt;200 or h&gt;16384 then return {kind='unknown'} end
 return {kind='ours',block=block,dims=block+13,w=w,h=h}
end
local function locked(pid,fn)
 local h=executeCodeLocalEx('kernel32.CreateMutexW',0,0,{type=4,value='Local\\N11DisplayScale_v2_'..pid})
 assert(h and h~=0,'Cannot create display-control mutex')
 local wait=executeCodeLocalEx('kernel32.WaitForSingleObject',h,0)
 if wait~=0 and wait~=0x80 then
  executeCodeLocalEx('kernel32.CloseHandle',h)
  error(msg('Another Cheat Engine is updating the display. Retry.','別のCheat Engineが表示設定を変更中です。再実行してください。'))
 end
 local result={pcall(fn)}
 executeCodeLocalEx('kernel32.ReleaseMutex',h);executeCodeLocalEx('kernel32.CloseHandle',h)
 if not result[1] then error(result[2],0) end
 return table.unpack(result,2)
end
local function setSize(hwnd,w,h)
 -- An iconic window reports a zero-size client. Restore it only for an explicit
 -- apply/reset request; the background watcher skips minimized windows instead.
 if api('IsIconic',hwnd)~=0 or api('IsZoomed',hwnd)~=0 then
  api('ShowWindow',hwnd,9)
  api('UpdateWindow',hwnd)
 end
 local cw,ch
 for _=1,5 do
  local x,y; x,y,cw,ch=rect(hwnd,true)
  if cw==w and ch==h then return true end
  if cw&gt;0 and ch&gt;0 then
   local l,t,r,b=rect(hwnd,false)
   assert(api('SetWindowPos',hwnd,0,0,0,r-l+w-cw,b-t+h-ch,0x16)~=0,
    msg('Windows refused the window resize.','Windowsがウインドウサイズの変更を拒否しました。'))
  end
  api('UpdateWindow',hwnd)
 end
 local x,y; x,y,cw,ch=rect(hwnd,true)
 if cw==w and ch==h then return true end
 error(msg(('Cannot apply %d x %d: actual client is %d x %d, minimized=%s.'):format(w,h,cw,ch,tostring(api('IsIconic',hwnd)~=0)),
  ('要求%d×%dに対し、実際の表示領域は%d×%dです。最小化=%s。'):format(w,h,cw,ch,tostring(api('IsIconic',hwnd)~=0))),0)
end
local function monitorRect(hwnd)
 local monitor=api('MonitorFromWindow',hwnd,2)
 assert(monitor and monitor~=0,'Monitor unavailable')
 writeIntegerLocal(S.buffer,40)
 assert(api('GetMonitorInfoW',monitor,S.buffer)~=0,'Monitor bounds unavailable')
 return signed(readIntegerLocal(S.buffer+4)),signed(readIntegerLocal(S.buffer+8)),signed(readIntegerLocal(S.buffer+12)),signed(readIntegerLocal(S.buffer+16))
end
local function frameState(hwnd)
 local l,t,r,b=rect(hwnd,false)
 return {hwnd=hwnd,pid=windowPid(hwnd),style=api('GetWindowLongW',hwnd,-16)&amp;0xFFFFFFFF,exstyle=api('GetWindowLongW',hwnd,-20)&amp;0xFFFFFFFF,l=l,t=t,w=r-l,h=b-t}
end
local function readFrameState(block,hwnd,pid)
 if bytes(block+128,8)~='N11FRAME' or readInteger(block+160)~=pid or readInteger(block+164)~=hwnd then return nil end
 local f={hwnd=hwnd,pid=pid,style=readInteger(block+136),exstyle=readInteger(block+140),l=readInteger(block+144),t=readInteger(block+148),w=readInteger(block+152),h=readInteger(block+156)}
 if not f.w or not f.h or f.w&lt;1 or f.h&lt;1 or f.w&gt;32768 or f.h&gt;32768 then return nil end
 if f.l&gt;=0x80000000 then f.l=f.l-0x100000000 end
 if f.t&gt;=0x80000000 then f.t=f.t-0x100000000 end
 return f
end
local function saveFrameState(block,f)
 assert(writeInteger(block+136,f.style));assert(writeInteger(block+140,f.exstyle))
 for i,v in ipairs({f.l,f.t,f.w,f.h,f.pid,f.hwnd}) do assert(writeInteger(block+140+i*4,v)) end
 assert(writeBytes(block+128,{string.byte('N11FRAME',1,8)}))
end
local function restoreFrame(hwnd)
 local f=S.windowBefore
 if not f or f.hwnd~=hwnd or f.pid~=windowPid(hwnd) then return end
 api('SetWindowLongW',hwnd,-16,f.style);api('SetWindowLongW',hwnd,-20,f.exstyle)
 local order=(f.exstyle &amp; 8)~=0 and -1 or -2
 assert(api('SetWindowPos',hwnd,order,f.l,f.t,f.w,f.h,0x30)~=0,'Window frame restore failed')
 if S.block then writeBytes(S.block+128,{0,0,0,0,0,0,0,0}) end
 S.windowBefore=nil
end
local function destroyBackdrop()
 if S.backdrop then S.backdrop.destroy();S.backdrop=nil end
 S.fullscreenBounds=nil;S.fullscreenMonitor=nil
end
local function fitAspect(l,t,r,b)
 local unit=math.floor(math.min((r-l)/4,(b-t)/3))
 assert(unit&gt;=80,'Monitor is too small for fullscreen')
 local w,h=unit*4,unit*3
 local x=l+math.floor((r-l-w)/2);local y=t+math.floor((b-t-h)/2)
 return x,y,x+w,y+h
end
local function updateBackdrop(hwnd)
 local m=S.fullscreenMonitor
 if not m then return end
 if not S.backdrop then
  local f=createForm(false);f.BorderStyle='bsNone';f.Position='poDesigned';f.Color=0;f.Caption=''
  -- CE's dark theme can override Form.Color; paint true black explicitly.
  -- Use native client bounds, since LCL geometry can lag behind SetWindowPos.
  f.OnPaint=function()
   local _,_,w,h=rect(f.Handle,true);local c=f.Canvas;c.Brush.Color=0;c.fillRect(0,0,w,h)
  end
  pcall(function() f.ShowInTaskBar='stNever' end)
  S.backdrop=f
  api('SetWindowLongPtrW',f.Handle,-8,0)
  local ex=api('GetWindowLongW',f.Handle,-20)&amp;0xFFFFFFFF
  api('SetWindowLongW',f.Handle,-20,(ex &amp; ~0x00040000)|0x08000080)
 end
 -- Keep the fullscreen surface intact while CE/chat is used on another monitor.
 -- Yield to foreground applications on the same monitor, but keep black bars.
 if api('IsIconic',hwnd)~=0 or api('IsWindowVisible',hwnd)==0 then
  api('ShowWindow',S.backdrop.Handle,0);return
 end
 local front=api('GetForegroundWindow')
 local ownFront=windowPid(front)==S.pid
 local gameMonitor=api('MonitorFromWindow',hwnd,2)
 local frontMonitor=front and front~=0 and api('MonitorFromWindow',front,2) or gameMonitor
 local pin=ownFront or frontMonitor~=gameMonitor
 local topmost=(api('GetWindowLongW',hwnd,-20)&amp;8)~=0
 if pin~=topmost then
  assert(api('SetWindowPos',hwnd,pin and -1 or -2,0,0,0,0,0x13)~=0,'Fullscreen stacking failed')
 end
 if not pin and not ownFront and front and front~=0 then
  api('SetWindowPos',hwnd,front,0,0,0,0,0x13)
 end
 assert(api('SetWindowPos',S.backdrop.Handle,hwnd,m[1],m[2],m[3]-m[1],m[4]-m[2],0x50)~=0,'Black fullscreen background unavailable')
end
local function fullscreenFrame(hwnd,l,t,r,b)
 if not S.windowBefore then
  if api('IsIconic',hwnd)~=0 or api('IsZoomed',hwnd)~=0 then api('ShowWindow',hwnd,9);api('UpdateWindow',hwnd) end
  S.windowBefore=frameState(hwnd);saveFrameState(S.block,S.windowBefore)
 end
 local style=(S.windowBefore.style &amp; ~0x21CF0000)|0x80000000
 local exstyle=S.windowBefore.exstyle &amp; ~0x00000301
 api('SetWindowLongW',hwnd,-16,style);api('SetWindowLongW',hwnd,-20,exstyle)
 assert(api('SetWindowPos',hwnd,0,l,t,r-l,b-t,0x34)~=0,'Fullscreen window resize failed')
end
function S.restore(skipSize)
 destroyBackdrop()
 if S.timer then S.timer.destroy();S.timer=nil end
 if S.watch then S.watch.destroy();S.watch=nil end
 local pid,hwnd,block=S.pid,S.hwnd,S.block
 if not block or pid==0 then
  status('No display hook is owned by this table.','このテーブルで管理中の表示補正はありません。')
  return true
 end
 local removed=false;local ownsFrame=true
 if gamePid()==pid then
  if getOpenedProcessID()~=pid then openProcess(pid) end
  locked(pid,function()
   local info=inspect(pid)
   if info.kind=='original' or (info.kind=='ours' and info.block~=block) then ownsFrame=false;return end
   local owner=info.kind=='ours' and readInteger(info.block+172) or 0
   if owner~=0 and (owner~=S.owner or readInteger(info.block+176)~=S.token) then ownsFrame=false;return end
   if info.kind~='ours' then error(msg('Unknown hook: restoration was not attempted.','未知のフックのため復元しませんでした。'),0) end
   assert(writeBytes(entry,{original:byte(1,#original)}),'Cannot restore original instructions')
   removed=true
  end)
 end
 if ownsFrame and hwnd and windowPid(hwnd)==pid then restoreFrame(hwnd) end
 -- Clear ownership before resizing. A resize failure cannot recursively enter
 -- restoration, hide the original error, or leave a stale active controller.
 S.block=nil;S.dims=nil;S.pid=0;S.hwnd=nil;S.windowBefore=nil
 if removed and not skipSize and hwnd and windowPid(hwnd)==pid then
  local ok,err=pcall(setSize,hwnd,1024,768)
  if not ok then
   status('Mouse hook removed; window reset failed: '..tostring(err),
    'マウス補正は解除しました。ウインドウの復帰に失敗：'..tostring(err))
   return false,err
  end
 end
 status(removed and 'Mouse hook removed; display control released.' or 'Display control released.',
  removed and 'マウス補正を解除し、表示操作を終了しました。' or '表示操作を終了しました。')
 return true
end
function S.apply(pid)
 if getOpenedProcessID()~=pid then openProcess(pid) end
 if NB.pid and NB.pid~=pid then NB.forgetProcess() end
 if not NB.currentBuild() then return false end
 local ea=NB.resolveSig('wndTail');local ga=NB.resolveSig('wndGlobal');local da=NB.resolveSig('d3dGlobal')
 if not ea or not ga or not da then return false end
 entry=ea;windowGlobal=readInteger(ga+2);d3dGlobal=readInteger(da+7)
 if not windowGlobal or not d3dGlobal then return false end
 original=string.char(0x8B,0x0D)..string.pack('&lt;I4',windowGlobal)
 for _,sym in ipairs({'nbDisplayEntry','nbWindowGlobal'}) do pcall(unregisterSymbol,sym) end
 registerSymbol('nbDisplayEntry',entry,true);registerSymbol('nbWindowGlobal',windowGlobal,true)
 return locked(pid,function()
 openProcess(pid)
 local sys,w,h,fmt,windowed=liveSettings()
 if not sys then return false end
 if windowed==0 and S.mode==1 then
  S.pid=pid
  status('Native exclusive fullscreen is already active.','ゲーム本来の専有全画面が有効です。')
  return true
 end
 assert(w==1024 and h==768 and (fmt==21 or fmt==22) and windowed==1,
  msg('The running native exclusive mode could not be changed to windowed.','実行中の専有全画面からウインドウへの切替は未対応です。'))
 local hwnd,title=findGameWindow(pid)
 if not hwnd then return false end
 assert(md5file(processExePath(pid)):lower()=='0f9406bd9684641b4c352ffc470b4844',msg('Unsupported EXE build.','対応外のEXEです。'))
 local info=inspect(pid)
 if info.kind=='unknown' then
  error(msg('The window handler already contains an unrecognized or revision-1 hook. Restore 1x in its original CE, or restart only the game. No bytes were overwritten.',
   '既存の処理は旧版または未知のフックです。適用元のCEで1倍へ戻すか、ゲームだけを再起動してください。バイト列は上書きしていません。'))
 end
 if info.kind=='original' then
  local ok,di=autoAssemble(S.aa:gsub('%$ORIGINAL',original:gsub('.',function(c) return string.format('%02X ',c:byte()) end)))
  assert(ok,tostring(di))
  local block=getAddress('n11DisplayBlock')
  writeInteger(block+21,pid)
  unregisterSymbol('n11DisplayBlock')
  info=inspect(pid)
  assert(info.kind=='ours','New display hook did not pass full verification')
 end
 -- Adopt only our exact, fully validated v2 hook, including PID and return address.
 S.block=info.block;S.dims=info.dims;S.pid=pid;S.hwnd=hwnd
 S.windowBefore=S.windowBefore or readFrameState(S.block,hwnd,pid)
 assert(writeInteger(S.block+172,S.owner));assert(writeInteger(S.block+176,S.token))
 local tw,th=math.floor(1024*S.factor+.5),math.floor(768*S.factor+.5)
 local l,t,r,b
 if S.mode==1 then
  local ml,mt,mr,mb=monitorRect(hwnd)
  S.fullscreenMonitor={ml,mt,mr,mb}
  l,t,r,b=fitAspect(ml,mt,mr,mb);tw,th=r-l,b-t
  S.fullscreenBounds={l,t,r,b}
 end
 assert(tw&gt;=320 and th&gt;=200 and tw&lt;=16384 and th&lt;=16384,'Unsupported display dimensions')
 -- Convert each axis independently, including widescreen fullscreen clients.
 assert(writeInteger(S.dims,tw));assert(writeInteger(S.dims+4,th))
 local ok,err=pcall(function()
  if S.mode==1 then fullscreenFrame(hwnd,l,t,r,b);updateBackdrop(hwnd)
  else destroyBackdrop();restoreFrame(hwnd);setSize(hwnd,tw,th) end
 end)
 if not ok then
  local clean,cleanupError=pcall(S.restore,true)
  if not clean then err=tostring(err)..' / cleanup: '..tostring(cleanupError) end
  error(err,0)
 end
 if S.mode==1 then
  status(('Borderless fullscreen (4:3, black bars): %d x %d | internal 1024 x 768 / 32-bit | PID %d'):format(tw,th,pid),
   ('全画面（4:3・黒帯）：%d×%d｜内部1024×768・32bit｜PID %d'):format(tw,th,pid))
 else
  status(string.format('%sx: %d x %d | internal 1024 x 768 / 32-bit | PID %d | %s',S.factor,tw,th,pid,title),
   string.format('%s倍：%d×%d｜内部1024×768・32bit｜PID %d｜%s',S.factor,tw,th,pid,title))
 end
 if not S.watch then
  S.watch=createTimer(nil,false);S.watch.Interval=500
  S.watch.OnTimer=function()
   local ok,err=pcall(function()
   if windowPid(S.hwnd)~=S.pid then
    S.watch.destroy();S.watch=nil;destroyBackdrop();S.block=nil;S.dims=nil;S.pid=0;S.hwnd=nil;S.windowBefore=nil
    status('Game closed. Choose a scale and launch again.','ゲームが終了しました。倍率を選んで再起動できます。');return
   end
   -- The game can restore its original window size during movie startup/focus.
   -- Reapply only the outer window size; never reset the 1024x768 backbuffer.
   if getOpenedProcessID()==S.pid then
    local info=inspect(S.pid)
    if info.kind~='ours' or info.block~=S.block or readInteger(info.block+172)~=S.owner or readInteger(info.block+176)~=S.token then
     S.watch.destroy();S.watch=nil;destroyBackdrop();S.block=nil;S.dims=nil;S.pid=0;S.hwnd=nil;S.windowBefore=nil
     status('Display control released by another CE.','別のCEで表示補正が解除されました。');return
    end
    if S.mode==1 then updateBackdrop(S.hwnd) end
    if api('IsIconic',S.hwnd)~=0 then return end
    local _,_,cw,ch=rect(S.hwnd,true)
    if cw&gt;0 and ch&gt;0 then
     -- Shared dimensions prevent two CE instances from fighting over their old scales.
     if S.mode==1 and S.fullscreenBounds then
      local f=S.fullscreenBounds;local l,t,r,b=rect(S.hwnd,false)
      if l~=f[1] or t~=f[2] or cw~=info.w or ch~=info.h then
       assert(api('SetWindowPos',S.hwnd,0,f[1],f[2],info.w,info.h,0x14)~=0,'Fullscreen placement failed')
      end
     elseif cw~=info.w or ch~=info.h then setSize(S.hwnd,info.w,info.h) end
    end
   end
   end)
   if not ok then
    if S.watch then S.watch.destroy();S.watch=nil end
    destroyBackdrop()
    status('Display monitor stopped: '..tostring(err),'表示監視を停止しました：'..tostring(err))
   end
  end
  S.watch.Enabled=true
 end
 return true
 end)
end
local function findButton(parent,depth)
 if depth&gt;4 then return nil end
 local h=api('GetWindow',parent,5)
 for _=1,200 do
  if not h or h==0 then break end
  if caption(h)=='GAME' then return h end
  local child=findButton(h,depth+1);if child then return child end
  h=api('GetWindow',h,2)
 end
end
function S.start()
 assert(not S.timer,msg('Waiting for startup.','起動待機中です。'))
 assert(S.factor and S.factor&gt;=1 and S.factor&lt;=3,'Scale must be 1 to 3')
 local pid=gamePid()
 if pid then
  if S.pid~=0 and S.pid~=pid then S.block=nil;S.dims=nil;S.pid=0;S.windowBefore=nil end
  if S.apply(pid) then return end
 else
  NB.setScreenConfig(0,true)
  shellExecute('steam://rungameid/628140','','',1)
 end
 status('Waiting for the launcher / game (up to 90 seconds)...','ランチャー／ゲームの起動を待機しています（最大90秒）…')
 local deadline=getTickCount()+90000;local clicked=false
 S.timer=createTimer(nil,false);S.timer.Interval=50
 S.timer.OnTimer=function()
  local ok,err=pcall(function()
   if getTickCount()&gt;deadline then error(msg('Startup timed out.','起動待機がタイムアウトしました。')) end
   local p=gamePid()
   if p and S.apply(p) then S.timer.destroy();S.timer=nil;return end
   if not clicked then
    local launcherPid
    for id,name in pairs(getProcessList()) do
     if name:lower()=='nobunaga11wpk_launcher.exe' then launcherPid=tonumber(id);break end
    end
    if launcherPid then
     local root=api('GetTopWindow',0)
     for _=1,10000 do
      if not root or root==0 then break end
      if windowPid(root)==launcherPid then
       local button=findButton(root,0)
       if button then api('PostMessageW',button,0xF5,0,0);clicked=true;break end
      end
      root=api('GetWindow',root,2)
     end
    end
   end
  end)
  if not ok then
   if S.timer then S.timer.destroy();S.timer=nil end
   status('Error: '..tostring(err),'エラー：'..tostring(err))
  end
 end
 S.timer.Enabled=true
end
function S.safe(fn)
 local ok,err=pcall(fn);if not ok then status('Error: '..tostring(err),'エラー：'..tostring(err)) end
end
function S.shutdown()
 S.safe(S.restore)
 if S.buffer then deallocateSharedMemoryLocal(S.buffer);S.buffer=nil end
end


 NB.display=S
 return S
end
-- Native Windows registry APIs; writes occur only after selecting this action.
-- Save prior values in this process for diagnostics; no game restart is forced.
function NB.setScreenConfig(fullscreen,quiet)
 fullscreen=fullscreen or 0
 assert(fullscreen==0 or fullscreen==1,'Invalid display mode')
 if NB.game~=1 then NB.err('This title is not supported yet.','この作品にはまだ対応していません。') end
 local buf=allocateSharedMemoryLocal('NBRegistry_'..getTickCount(),128)
 assert(buf,'Cannot allocate registry buffer')
 local key
 local ok,e=pcall(function()
  local path=[[Software\KoeiTecmo\35th\Nobunaga11WPK\Configs]]
  local result=executeCodeLocalEx('advapi32.RegOpenKeyExW',-2147483647,{type=4,value=path},0,3,buf)
  assert(result==0,'RegOpenKeyExW: '..tostring(result))
  key=readQwordLocal(buf)
  NB.registryBefore=NB.registryBefore or {}
  for _,name in ipairs({'FULLSCREEN','VIEWMODE'}) do
   writeIntegerLocal(buf+24,4)
   local q=executeCodeLocalEx('advapi32.RegQueryValueExW',key,{type=4,value=name},0,buf+16,buf+32,buf+24)
   assert(q==0 and readIntegerLocal(buf+16)==4,'Expected existing DWORD registry value: '..name)
   if NB.registryBefore[name]==nil then NB.registryBefore[name]=readIntegerLocal(buf+32) end
  end
  for _,name in ipairs({'FULLSCREEN','VIEWMODE'}) do
   writeIntegerLocal(buf+32,name=='FULLSCREEN' and fullscreen or 0)
   assert(executeCodeLocalEx('advapi32.RegSetValueExW',key,{type=4,value=name},0,4,buf+32,4)==0,'Cannot write '..name)
  end
 end)
 if key then executeCodeLocalEx('advapi32.RegCloseKey',key) end
 deallocateSharedMemoryLocal(buf)
 if not ok then error(e,0) end
 if not quiet then NB.msg('Startup display preferences saved.','起動用の表示設定を保存しました。') end
end

-- Setup values live in Lua, so choosing them never writes target memory and
-- works before attachment. Comboboxes are embedded in the address-list tree.
NB.CONFIG_IDS={[20]=true,[24]=true,[25]=true,[26]=true,[27]=true}
NB.config={mode=0,scale=2}
NB.scaleValues={1,1.25,1.5,1.75,2,2.5,3}
NB.configControls={}
NB.uiStatus={'Choose settings, then check Screen mode.','設定を選び、画面モードをチェックしてください。'}
function NB.openConfigDropdown(id)
 local combo=NB.configControls[id]
 if combo and combo.Enabled then combo.setFocus();combo.DroppedDown=true end
end
function NB.displayStatus(en,ja)
 NB.uiStatus={en,ja};NB.suffix[27]=NB.T(en,ja);NB.applyLang()
end
function NB.stopConfiguredDisplay()
 if NB.display then NB.display.restore() end
 NB.displayStatus('Display control off.','表示操作を解除しました。')
end
function NB.startConfiguredDisplay()
 if NB.game~=1 then NB.err('Display controls are available for Tenkasousei only.','表示操作は天下創世のみ対応しています。') end
 local d=NB.display or NB.makeDisplay()
 d.lang=NB.lang;d.factor=NB.config.scale;d.mode=NB.config.mode
 if not d.timer then d.start() end
end
function NB.releaseGameSelection()
 local al=getAddressList()
 for i=al.Count-1,0,-1 do
  local m=al.getMemoryRecord(i)
  if NB.NAMES[m.ID] and not NB.CONFIG_IDS[m.ID] and m.Active then m.Active=false end
 end
 if NB.display then NB.display.shutdown();NB.display=nil end
 NB.forgetProcess()
end
function NB.changeConfig(id,index)
 if NB.uiUpdating then return end
 local screen=getAddressList().getMemoryRecordByID(20)
 if id==24 then
  if NB.game==index+1 then return end
  if screen and screen.Active then screen.Active=false end
  NB.releaseGameSelection()
  NB.game=index+1;NB.EXE=NB.GAMES[NB.game][3];NB.MODULE=NB.EXE
  if NB.applyProfileRecords then NB.applyProfileRecords() end
  NB.displayStatus(NB.game==1 and 'Choose settings, then check Screen mode.' or 'Start the selected game, then ATTACH.',
   NB.game==1 and '設定を選び、画面モードをチェックしてください。' or '選択したゲームを起動してアタッチしてください。')
 elseif id==25 then
  if NB.config.mode==index then return end
  local active=screen.Active
  if active then screen.Active=false end
  if index==1 then NB.windowedScale=NB.config.scale;NB.config.scale=1
  else NB.config.scale=NB.windowedScale or NB.config.scale end
  NB.config.mode=index
  local running=false
  if NB.game==1 then for _,name in pairs(getProcessList()) do if name:lower()=='nobunaga11wpk.exe' then running=true;break end end end
  if running then screen.Active=true
  else NB.displayStatus('Check Screen mode to launch with the selected display.','画面モードをチェックすると、選択した表示で起動します。') end
 elseif id==26 then
  NB.config.scale=NB.scaleValues[index+1]
  if screen.Active then NB.userRun(NB.startConfiguredDisplay) end
 end
 NB.refreshConfigLabels();NB.refreshSuffix()
end
function NB.refreshConfigLabels()
 if not NB.configControls[24] then return end
 NB.uiUpdating=true
 local games=NB.configControls[24];games.Items.clear()
 for i,g in ipairs(NB.GAMES) do games.Items.add(NB.T(g[1],g[2])) end
 games.ItemIndex=NB.game-1
 local mode=NB.configControls[25];mode.Items.clear()
 mode.Items.add(NB.T('Windowed (32-bit)','ウインドウ（32bit）'))
 mode.Items.add(NB.T('Fullscreen (4:3, black bars, 32-bit)','全画面（4:3・黒帯・32bit）'))
 mode.ItemIndex=NB.config.mode
 local scale=NB.configControls[26];scale.Items.clear();local selected=0
 for i,v in ipairs(NB.scaleValues) do
  scale.Items.add(NB.T(('%sx  (%d x %d)'):format(v,1024*v,768*v),('%s倍（%d×%d）'):format(v,1024*v,768*v)))
  if v==NB.config.scale then selected=i-1 end
 end
 scale.ItemIndex=selected;scale.Enabled=NB.config.mode==0 and NB.game==1
 mode.Enabled=NB.game==1
 NB.suffix[27]=NB.T(NB.uiStatus[1],NB.uiStatus[2]);NB.applyLang()
 NB.uiUpdating=false
end
function NB.layoutConfigControls()
 local al=getAddressList();local tree=al.List;local header
 for i=0,al.ControlCount-1 do local c=al.Control[i];if c.ClassName=='THeaderControl' then header=c;break end end
 local left=0
 if header then
  for i=0,header.Sections.Count-1 do local s=header.Sections[i];if i==4 then break end;if s.Visible then left=left+s.Width end end
 else left=345 end
 for id,combo in pairs(NB.configControls) do
  local node
  for i=0,tree.Items.Count-1 do local n=tree.Items[i];if n.memrec and n.memrec.ID==id then node=n;break end end
  local visible=node~=nil
  if node then local p=node.Parent;while p do if not p.Expanded then visible=false;break end;p=p.Parent end end
  local r=node and node.getDisplayRect(false)
  if r and visible then visible=r.Bottom&gt;0 and r.Top&lt;tree.Height and tree.Width&gt;left+40 end
  if visible then combo.Left=left+2;combo.Top=r.Top;combo.Width=math.max(40,math.min(tree.Width,r.Right)-left-6) end
  combo.Visible=visible
 end
end
function NB.installConfigUI()
 local tree=getAddressList().List;NB.oldItemHeight=tree.DefaultItemHeight
 for _,id in ipairs({24,25,26}) do
  local combo=createComboBox(getMainForm());combo.Parent=tree;combo.Style='csDropDownList';combo.Font.assign(tree.Font)
  combo.OnChange=function(sender) if sender.ItemIndex&gt;=0 then NB.changeConfig(id,sender.ItemIndex) end end
  NB.configControls[id]=combo;tree.DefaultItemHeight=math.max(tree.DefaultItemHeight,combo.Height)
 end
 NB.configItemHeight=tree.DefaultItemHeight
 NB.refreshConfigLabels();getAddressList().getMemoryRecordByID(20).Collapsed=false
 NB.uiTimer=createTimer(nil,false);NB.uiTimer.Interval=120
 NB.uiTimer.OnTimer=function() NB.layoutConfigControls() end;NB.uiTimer.Enabled=true;NB.layoutConfigControls()
end
function NB.destroyConfigUI()
 if NB.uiTimer then NB.uiTimer.destroy();NB.uiTimer=nil end
 for _,c in pairs(NB.configControls) do c.OnChange=nil;c.destroy() end
 NB.configControls={}
 local tree=getAddressList().List
 if NB.oldItemHeight and tree.DefaultItemHeight==NB.configItemHeight then tree.DefaultItemHeight=NB.oldItemHeight end
end
local initialize=NB.initializeUI
function NB.initializeUI() initialize();NB.installConfigUI() end
local setLanguage=NB.setLang
function NB.setLang(l) setLanguage(l);NB.refreshConfigLabels() end
local shutdown=NB.shutdown
function NB.shutdown(recordsMayBeGone) NB.destroyConfigUI();shutdown(recordsMayBeGone) end

-- Attach to an existing game also applies the selected display configuration.
function NB.attachAndConfigure(self)
 if NB.game==2 then return NB.K12.attachAndOff() end
 NB.disableAll(self)
 if not NB.attached() then return end
 local screen=getAddressList().getMemoryRecordByID(20)
 if screen.Active then
  NB.startConfiguredDisplay()
 else
  screen.Active=true
 end
end

-- Kakushin PK build 1345322: validated data editor adapter.
-- Do not reuse Nobunaga11 data layouts, encodings or hook addresses here.
NB.K12={EXE='NOBU12PK.exe',BUILD={ts=0x57DA252F,size=0x102A000},GAMEVER='1345322',pid=nil,A={}}
local K=NB.K12
K.SIGS={officerValueA={pattern="83 EC 08 53 0F B6 99 66 01 00 00 55 0F B6 A9 64 01 00 00 56 8B B1 3C 01 00 00 57 8B B9 14 01 00 00 E8 1A 13 06 00 8B C8 33 C0 85 FF 0F 94 C0 03 CD 5F C7 44 24 0C 01 00 00 00 40 0F AF C6 99 2B C2 D1 F8 03 C1 03 C3 5E 5D 89 44 24 08 83 F8 01",rva=225968},officerValueB={pattern="83 EC 08 53 0F B6 99 67 01 00 00 56 8B B1 40 01 00 00 57 8B B9 14 01 00 00 E8 E2 12 06 00 8B C8 33 C0 85 FF 0F 94 C0 03 CB 5F C7 44 24 08 01 00 00 00 40 0F AF C6 99 2B C2 D1 F8 03 C1 5E 89 44 24 08 83 F8 01 5B 8D 04 24 7C 04 8D 44 24 04 8B",rva=226064},officerValueC={pattern="83 EC 08 53 0F B6 99 68 01 00 00 56 8B B1 44 01 00 00 57 8B B9 14 01 00 00 E8 A2 12 06 00 8B C8 33 C0 85 FF 0F 94 C0 03 CB 5F C7 44 24 08 01 00 00 00 40 0F AF C6 99 2B C2 D1 F8 03 C1 5E 89 44 24 08 83 F8 01 5B 8D 04 24 7C 04 8D 44 24 04 8B",rva=226160}}
function K.buildMatches()
 local m=getAddressSafe(K.EXE);local pe=m and readInteger(m+0x3C)
 return m and readSmallInteger(m)==0x5A4D and pe and
  readSmallInteger(m+pe+4)==0x14C and readInteger(m+pe+8)==K.BUILD.ts and
  readInteger(m+pe+0x50)==K.BUILD.size
end
function K.attached() return K.pid and K.pid==getOpenedProcessID() and K.buildMatches() end
function K.disconnect()
 if K.assertNativeIdle then K.assertNativeIdle() end
 if K.stopFeatures then K.stopFeatures() end
 if K.timer then K.timer.destroy();K.timer=nil end
 if K.life then executeCodeLocalEx('kernel32.CloseHandle',K.life);K.life=nil end
 K.pid=nil;K.A={}
end
function K.scan()
 assert(K.attached(),NB.T('Attach to Kakushin PK first.','先に革新PKへアタッチしてください。'))
 local m=assert(getAddressSafe(K.EXE));local count=0;K.A={}
 for name,s in pairs(K.SIGS) do
  local hits=NB.aobAll(s.pattern,m,m+K.BUILD.size,2)
  if #hits==1 then K.A[name]=hits[1];count=count+1 end
 end
 return count
end
function K.attachAndOff()
 local processes=getProcessList();local opened=getOpenedProcessID();local pid
 for id,name in pairs(processes) do
  if name:lower()==K.EXE:lower() then
   if not pid or tonumber(id)==opened then pid=tonumber(id) end
  end
 end
 if not pid then NB.err('Kakushin PK is not running. Start it from Steam first.','革新PKが起動していません。先にSteamから起動してください。') end
 K.disconnect();openProcess(pid);pcall(reinitializeSymbolhandler,true)
 assert(getOpenedProcessID()==pid and K.buildMatches(),NB.T('Unsupported or unreadable Kakushin PK build.','対応外の革新PKビルド、またはメモリを読み取れません。'))
 K.pid=pid
 local handle=executeCodeLocalEx('kernel32.OpenProcess',0x100000,0,pid)
 if handle and handle~=0 then K.life=handle end
 local found=K.scan();if K.startData then K.startData() end;local total=0;for _ in pairs(K.SIGS) do total=total+1 end
 NB.msg(('Attached to %s (PID %d), supported Steam build %s. Signatures %d/%d.'):format(K.EXE,pid,K.GAMEVER,found,total),
  ('%s（PID %d）へアタッチ。Steam build %s。シグネチャ %d/%d。'):format(K.EXE,pid,K.GAMEVER,found,total))
 if K.life then
  K.timer=createTimer(nil,false);K.timer.Interval=500
  K.timer.OnTimer=function()
   if K.life and executeCodeLocalEx('kernel32.WaitForSingleObject',K.life,0)==0 then K.disconnect();return end
   if K.nativeBusy and K.nativeBusy() then return end
   if K.tick then
    local ok,e=pcall(K.tick)
    if not ok then
     local message=tostring(e)
     if K.tickError~=message then K.tickError=message;NB.msg(message) end
    else K.tickError=nil end
   end
  end
  K.timer.Enabled=true
 end
 return true
end
function K.report()
 NB.openLuaEngine(true)
 NB.msg(('Kakushin PK: opened PID %s / table PID %s; supported build %s; expected PE timestamp %X; SizeOfImage %X.'):format(tostring(getOpenedProcessID()),tostring(K.pid),K.GAMEVER,K.BUILD.ts,K.BUILD.size),
  ('革新PK：接続先PID %s／テーブルPID %s。対応build %s、対応PEタイムスタンプ %X、SizeOfImage %X。'):format(tostring(getOpenedProcessID()),tostring(K.pid),K.GAMEVER,K.BUILD.ts,K.BUILD.size))
 if K.attached() then
  local m=getAddressSafe(K.EXE);local pe=readInteger(m+0x3C)
  NB.msg(('Live PE timestamp %X; SizeOfImage %X.'):format(readInteger(m+pe+8),readInteger(m+pe+0x50)),
   ('実行中EXE：PEタイムスタンプ %X、SizeOfImage %X。'):format(readInteger(m+pe+8),readInteger(m+pe+0x50)))
 else NB.msg('Live build: unavailable (not attached).','実行中ビルド：取得できません（未接続）。') end
 if K.describeData then K.describeData() end
end
function K.selfTest()
 NB.openLuaEngine(true);local found=K.scan();local names={}
 for name in pairs(K.SIGS) do names[#names+1]=name end;table.sort(names)
 for _,name in ipairs(names) do NB.msg(name..': '..(K.A[name] and 'OK' or 'NOT UNIQUE / NOT FOUND')) end
 return found,#names
end

-- Kakushin PK 1345322. Pointer-vector layouts traced through native getters,
-- serializers and list-column formatters. No N11 encoded field is reused.
local K=NB.K12
K.SIGS.rootGetter={pattern='A1 EC 81 C5 00 C3 CC CC CC CC CC CC CC CC CC CC E8 0B 0E FD FF 8B 0D EC 81 C5 00',rva=0x121A60}
K.on={};K.editors={};K.sel={}
local function u(p) return p and p~=0 and readInteger(p) or nil end
function K.root()
 if not K.attached() or not K.A.rootGetter then return end
 local r=u(u(K.A.rootGetter+1))
 if not r or u(r)~=getAddressSafe(K.EXE)+0x749088 then return end
 return r
end
function K.vector(off,count)
 local r=K.root();if not r then return end
 local b,e=u(r+off+4),u(r+off+8)
 if b and b&gt;0x10000 and e and e-b==count*4 then return b end
end
function K.object(kind,index)
 local off,count,vt=0x404,1940,0x7463DC
 if kind=='city' then off,count,vt=0x444,225,0x746588 end
 local v=K.vector(off,count)
 if not v or type(index)~='number' or index&lt;0 or index&gt;=count then return end
 local p=u(v+index*4)
 if p and u(p)==getAddressSafe(K.EXE)+vt then return p end
end
function K.objects(kind)
 local count,off,vt=1940,0x404,0x7463DC
 if kind=='city' then count,off,vt=225,0x444,0x746588 end
 local v=K.vector(off,count);local out={};if not v then return out end
 local bytes=readBytes(v,count*4,true);if not bytes then return out end
 local expected=getAddressSafe(K.EXE)+vt
 for i=0,count-1 do
  local j=i*4+1;local p=bytes[j]|(bytes[j+1]&lt;&lt;8)|(bytes[j+2]&lt;&lt;16)|(bytes[j+3]&lt;&lt;24)
  if p&gt;0x10000 and u(p)==expected then out[#out+1]={id=i,p=p} end
 end
 return out
end
function K.scenario()
 local r=K.root();return r and u(r+0x588)
end
function K.force()
 local s=K.scenario();local p=s and u(s+0x204)
 if p and u(p)==getAddressSafe(K.EXE)+0x7478F4 then return p end
end
function K.ownsForce(force)
 local own=K.force()
 return force and force~=0 and own and u(force)==getAddressSafe(K.EXE)+0x7478F4 and u(force+8)==u(own+8)
end
function K.player()
 local f=K.force();local p=f and u(f+4)
 if p and u(p)==getAddressSafe(K.EXE)+0x7463DC then return p end
end
function K.homeCity()
 local p=K.player();local c=p and u(p+0xF4)
 if p and u(p+0xF0)==4 then local army=c and u(c+8);c=army and u(army+0x90) end
 if c and u(c)==getAddressSafe(K.EXE)+0x746588 then return c end
 local f=K.force();local clan=f and u(f+8);c=clan and u(clan+0x144)
 if c and u(c)==getAddressSafe(K.EXE)+0x746588 then return c end
end
function K.name(kind,p)
 if not p then return '' end
 local b=u(p+(kind=='city' and 0xDC or 0x60));if not b or b==0 then return '' end
 local function textAt(off,n)
  local s=readString(b+off,n,false);return s and ansiToUtf8(s) or ''
 end
 return kind=='city' and textAt(4,12) or textAt(4,11)..textAt(15,11)
end
function K.key()
 local r=K.root();local s=K.scenario();local f=K.force()
 local o,c=K.vector(0x404,1940),K.vector(0x444,225)
 if not r or not s or not f or not o or not c then return end
 return ('%X:%X:%X:%X:%X'):format(r,s,f,o,c)
end
function K.ready()
 assert(K.attached(),NB.T('Attach to Kakushin PK first.','先に革新PKへアタッチしてください。'))
 assert(K.key(),NB.T('Load a game first.','先にプレイ中のゲームをロードしてください。'))
end
function K.indexOf(kind,p)
 local count=kind=='city' and 225 or 1940
 local v=K.vector(kind=='city' and 0x444 or 0x404,count);if not v then return end
 for i=0,count-1 do if u(v+i*4)==p then return i end end
end
function K.selected(kind)
 if kind=='player' then return K.player() end
 return K.object(kind,K.sel[kind])
end
function K.refreshSuffix()
 NB.suffix[24]=nil
 for _,e in ipairs({{102,'player'},{403,'officer'},{303,'city'}}) do
  local p=K.selected(e[2]);NB.suffix[e[1]]=p and K.name(e[2],p) or NB.T('(not selected)','（未選択）')
 end
 NB.applyLang()
end
function K.clearEditors()
 local old=K.editors;K.editors={}
 for _,e in pairs(old) do
  e.mr.Active=false
  if e.mr.Count&gt;0 then NB.clearChildren(e.mr) end
 end
end
function K.stopFeatures()
 K.on={};K.clearEditors();K.snapshot=nil;K.sel={}
 for _,id in ipairs({101,201,202,208,206,207,304,404,602,604,701,702,703,705}) do local r=getAddressList().getMemoryRecordByID(id);if r then r.Active=false end end
end
function K.startData()
 K.snapshot=K.key()
 K.sel.officer=K.indexOf('officer',K.player())
 K.sel.city=K.indexOf('city',K.homeCity())
 K.refreshSuffix()
end
function K.select(kind,index)
 K.ready();assert(K.object(kind,index),'Selection unavailable')
 local reopen={}
 for _,e in pairs(K.editors) do if e.kind==kind then reopen[#reopen+1]=e.mr end end
 for _,m in ipairs(reopen) do K.closeEditor(m) end
 K.sel[kind]=index
 for _,m in ipairs(reopen) do K.openEditor(m,kind) end
 K.refreshSuffix()
end
function K.search(kind)
 K.ready()
 local q=inputQuery(NB.T('Search name','名前を検索'),NB.T('Part of name; blank lists all:','名前の一部を入力。空欄は全件表示：'),'')
 if q==nil then return end
 local ids,names={},{}
 for _,item in ipairs(K.objects(kind)) do
  local i,p=item.id,item.p;local name=K.name(kind,p)
  if name~='' and name:find(q,1,true) then ids[#ids+1]=i;names[#names+1]=('%s  [ID %d]'):format(name,i) end
 end
 if #ids==0 then NB.msg('Not found.','見つかりません。');return end
 local n=NB.pick(NB.T('Select result','候補を選択'),names)
 if n then K.select(kind,ids[n]) end
end
K.fields={
 officer={
  {'Leadership (base)','統率（基本値）',0x13C,1,120},
  {'Valor (base)','武勇（基本値）',0x140,1,120},
  {'Intellect (base)','知略（基本値）',0x144,1,120},
  {'Politics (base)','政治（基本値）',0x148,1,120},
  {'Loyalty','忠誠',0x154,0,100}},
 city={
  {'Money (shared by clan)','金銭（勢力共有）',0x4C,0,10000000,'force'},
  {'Rice (shared by clan)','兵糧（勢力共有）',0x50,0,10000000,'force'},
  {'Soldiers','兵士',0x40,0,500000},
  {'Horses','軍馬',0x4C,0,500000},
  {'Guns','鉄砲',0x50,0,500000},
  {'Battering rams','破城槌',0x54,0,1000},
  {'Siege towers','攻城櫓',0x58,0,1000},
  {'Cannons','大筒',0x5C,0,1000},
  {'Morale','士気',0x6C,0,100},
  {'Popular loyalty','民忠',0x68,0,100,'popular'}}}
function K.target(kind,index,f)
 local p=kind=='player' and K.player() or K.object(kind,index)
 if not p then return end
 if f[6]=='clan' then
  p=K.clan()
  if not p then return end
 elseif f[6]=='force' then
  p=u(p+0xE0)
  if not p or u(p)~=getAddressSafe(K.EXE)+0x7478F4 then return end
 elseif f[6]=='castle' then
  p=u(p+0xE8)
  if not p or u(p)~=getAddressSafe(K.EXE)+0x746368 then return end
 elseif f[6]=='popular' then
  p=u(p+0xEC);p=p and u(p+0x50)
  if not p or u(p)~=getAddressSafe(K.EXE)+0x747AB0 then return end
 end
 return p+f[3]
end
function K.closeEditor(mr)
 K.editors[mr.ID]=nil;NB.clearChildren(mr)
end
function K.addField(mr,kind,index,f)
 local token=K.key();local target=K.target(kind,index,f)
 if not target then return end
 K.typeSerial=(K.typeSerial or 0)+1
 local name=('NB12_044_'..tostring(getTickCount())..'_'..K.typeSerial..'_%d_%s_%d_%X'):format(K.pid,kind,index or 0,f[3])..'_'..(f[6] or 'self')
 -- Converter always returns defined bytes. An invalidated selection returns
 -- the currently addressed bytes unchanged, never stale frozen data.
 local ct=getCustomType(name)
 if not ct then
  ct=registerCustomTypeLua(name,4,function(a,b,c,d) local v=a|(b&lt;&lt;8)|(c&lt;&lt;16)|(d&lt;&lt;24);if f[4]&lt;0 and v&gt;=0x80000000 then v=v-0x100000000 end;return v end,
   function(value)
    local at=K.target(kind,index,f)
    if K.key()~=token or at~=target then return at and readBytes(at,4,true) or {0,0,0,0} end
    local limit=f[5]
    if f[6]=='castle' then limit=K.castleCap(K.object('city',index)) end
    local v=math.max(f[4],math.min(limit,math.floor(tonumber(value) or f[4])))
    if f[6]=='clan' then
     local ok,result=pcall(K.writeClanField,f,v)
     if not ok then NB.msg(tostring(result));return readBytes(at,4,true) or {0,0,0,0} end
     v=result
    end
    return {v&amp;255,(v&gt;&gt;8)&amp;255,(v&gt;&gt;16)&amp;255,(v&gt;&gt;24)&amp;255}
   end,false,false)
 end
 local row=NB.addRec(mr,f[1],f[2],string.format('%s+%X',K.EXE,u(K.A.rootGetter+1)-getAddressSafe(K.EXE)),vtCustom)
 local offsets
 if f[6]=='clan' then offsets={f[3],8,0x204,0x588}
 elseif kind=='player' then offsets={f[3],4,0x204,0x588}
 elseif f[6]=='force' then offsets={f[3],0xE0,index*4,0x448}
 elseif f[6]=='castle' then offsets={f[3],0xE8,index*4,0x448}
 elseif f[6]=='popular' then offsets={f[3],0x50,0xEC,index*4,0x448}
 else offsets={f[3],index*4,kind=='city' and 0x448 or 0x408} end
 row.OffsetCount=#offsets;for i,v in ipairs(offsets) do row.Offset[i-1]=v end
 row.CustomTypeName=name
 if f[8] then row.DropDownList.Text=f[8];row.DropDownReadOnly=true;row.DropDownDescriptionOnly=true;row.DisplayAsDropDownListItem=true end
 row.OnActivate=function(_,before) if before then return K.key()==token and K.target(kind,index,f)==target end;return true end
 return row
end
function K.openEditor(mr,kind)
 K.ready();K.closeEditor(mr)
 if not K.selected(kind) then NB.msg('Select an officer/city first.','先に武将・都市を選択してください。');return end
 local fields=K.fields[kind=='player' and 'officer' or kind]
 for _,f in ipairs(fields) do K.addField(mr,kind,K.sel[kind],f) end
 if kind=='player' then
  for _,f in ipairs({{'Money (shared by clan)','金銭（勢力共有）',0x4C,0,10000000},
   {'Rice (shared by clan)','兵糧（勢力共有）',0x50,0,10000000}}) do
   -- A separate clan row under the player: reuse the player's home-city owner.
   local idx=K.indexOf('city',K.homeCity());if idx then f[6]='force';K.addField(mr,'city',idx,f) end
  end
 end
 K.editors[mr.ID]={mr=mr,kind=kind};mr.Collapsed=false;K.refreshSuffix()
end
function K.feature(key,on)
 if not on then K.on[key]=nil;return end
 K.ready();assert(key=='loyalty' or key=='cityMax','Unsupported Kakushin feature')
 K.snapshot=K.key();K.on[key]=true;K.runFeatures()
end
function K.runFeatures()
 local force=K.force();if not force or K.key()~=K.snapshot then return end
 if K.on.loyalty then
  local leader=K.player()
  for _,item in ipairs(K.objects('officer')) do
   local p=item.p
   if p and p~=leader and u(p+0x10C)==7 and K.ownsForce(u(p+0x7C)) and u(p+0x154)~=100 then writeInteger(p+0x154,100) end
  end
 end
 if K.on.cityMax then
  writeInteger(force+0x4C,99999);writeInteger(force+0x50,99999)
  for _,item in ipairs(K.objects('city')) do
   local i,p=item.id,item.p
   if p and K.ownsForce(u(p+0xE0)) then
    for _,f in ipairs(K.fields.city) do
     if f[6]~='force' and f[7]~=false then
      local at=K.target('city',i,f)
      if at then
       if f[6]=='castle' then local cap=K.castleCap(p);if u(at)~=cap then K.nativeCall('cityDurabilitySet',0,p,cap) end
       else writeInteger(at,math.min(f[5],99999)) end
      end
     end
    end
   end
  end
 end
end
function K.tick()
 local key=K.key()
 if key~=K.snapshot then
  K.stopFeatures();K.startData()
  for _,id in ipairs({101,201,202,208,206,207,304,404,602,604,701,702,703,705}) do local r=getAddressList().getMemoryRecordByID(id);if r then r.Active=false end end
  return
 end
 if key then K.runFeatures() end
end
function K.describeData()
 local p,c=K.player(),K.homeCity();local f=K.force()
 NB.msg(('Player: %s; home castle: %s; money: %s; rice: %s.'):format(K.name('officer',p),K.name('city',c),tostring(f and u(f+0x4C)),tostring(f and u(f+0x50))),
  ('主人公：%s／所属城：%s／金銭：%s／兵糧：%s。'):format(K.name('officer',p),K.name('city',c),tostring(f and u(f+0x4C)),tostring(f and u(f+0x50))))
end
-- Dispatch shared UI actions without changing the N11 implementations.
local search,player,home,open,close,feature,suffix=NB.search,NB.selectPlayer,NB.selectHomeCity,NB.openEditor,NB.closeEditor,NB.feature,NB.refreshSuffix
function NB.search(kind) if NB.game==2 then return K.search(kind) end;return search(kind) end
function NB.selectPlayer() if NB.game==2 then K.ready();return K.select('officer',assert(K.indexOf('officer',K.player()))) end;return player() end
function NB.selectHomeCity() if NB.game==2 then K.ready();return K.select('city',assert(K.indexOf('city',K.homeCity()))) end;return home() end
function NB.openEditor(mr,kind) if NB.game==2 then return K.openEditor(mr,kind) end;return open(mr,kind) end
function NB.closeEditor(mr) if NB.game==2 then return K.closeEditor(mr) end;return close(mr) end
function NB.feature(key,on) if NB.game==2 then return K.feature(key,on) end;return feature(key,on) end
function NB.refreshSuffix() if NB.game==2 then return K.refreshSuffix() end;return suffix() end

-- Execute native operations on the game's window thread, never on a newly
-- injected thread. Only our private message and allocation cookie are handled.
local K=NB.K12
-- Separate CE instances must not share synchronized flag/dispatcher symbols.
K.symbolSuffix=('%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
function K.symbolAddress(name) return getAddressSafe(name..'_'..K.symbolSuffix) end
function K.assemble(script,info)
 script=script:gsub('nb12Flags','nb12Flags_'..K.symbolSuffix):gsub('nb12Native','nb12Native_'..K.symbolSuffix)
 return autoAssemble(script,info)
end
K.nativeDefs={}
K.nativeDefs['windowProc']={rva=0x1DC150,bytes={139,68,36,8,61,129,2,0,0,83,85,86,87,139,124,36}}
K.nativeDefs['treasureToOfficer']={rva=0xF7330,bytes={86,139,116,36,12,87,86,232,20,184,255,255,139,124,36,16}}
K.nativeDefs['technologyAcquire']={rva=0xFE1F0,bytes={131,236,60,85,86,139,116,36,72,51,237,59,245,15,132,94}}
K.nativeDefs['rankAward']={rva=0x10C930,bytes={100,161,0,0,0,0,106,255,104,72,225,164,0,80,100,137}}
K.nativeDefs.rankClear={rva=0x100220,bytes={139,76,36,4,86,139,113,116,133,246,116,32,87,232,222,126}}
function K.nativeAddress(name)
 local d=assert(K.nativeDefs[name],'Unknown native operation: '..tostring(name))
 assert(K.attached(),'Kakushin is not attached')
 local at=assert(getAddressSafe(K.EXE))+d.rva
 local actual=readBytes(at,#d.bytes,true)
 assert(actual and #actual==#d.bytes,'Unreadable native operation: '..name)
 for i,b in ipairs(d.bytes) do
  local patch=d.patch and K.patches and K.patches[d.patch]
  local expected=patch and patch.installed and patch.installed[i] or b
  assert(actual[i]==expected,'Native operation code mismatch: '..name)
 end
 return at
end
function K.installNative()
 if K.native then return end
 K.ready()
 local at=K.nativeAddress('windowProc')
 local script=([[
[ENABLE]
alloc(nb12Native,4096,%X)
registersymbol(nb12Native)
label(original)
label(done)
label(cancel)
label(stale)
label(invoke)
label(findOfficer)
label(officerFound)
nb12Native:
dd 0 0 0 0 0 0 0 0 0 0 0 0 0 0
align 10
nb12Native+100:
cmp dword ptr [esp+8],83C2
jne original
cmp dword ptr [esp+C],nb12Native
jne original
pushfd
pushad
cmp dword ptr [nb12Native],1
jne done
mov eax,[%X]
cmp eax,[nb12Native+20]
jne cancel
mov edx,[eax+588]
cmp edx,[nb12Native+24]
jne cancel
cmp dword ptr [nb12Native+34],1
jne invoke
// Validate on the game thread, not on an earlier CE memory snapshot.
// First find the officer in the current root's fixed object vector.
mov edi,[eax+408]
mov edx,[eax+40C]
sub edx,edi
cmp edx,1E50
jne stale
mov ecx,[nb12Native+2C]
mov edx,794
findOfficer:
cmp [edi],ecx
je officerFound
add edi,4
dec edx
jnz findOfficer
jmp stale
officerFound:
cmp dword ptr [ecx],NOBU12PK.exe+7463DC
jne stale
cmp dword ptr [ecx+10C],7
jne stale
cmp dword ptr [ecx+F0],5
jne stale
mov eax,[ecx+F4]
cmp eax,10000
jb stale
mov ecx,[nb12Native+8]
cmp [eax+C],ecx
jne stale
mov eax,[nb12Native+28]
cmp [ecx],eax
jne stale
cmp dword ptr [ecx+C],0
jle stale
cmp byte ptr [ecx+30],0
jne stale
mov eax,[ecx+1C]
cmp eax,10000
jb stale
cmp dword ptr [eax],NOBU12PK.exe+7478F4
jne stale
mov eax,[eax+8]
cmp eax,[nb12Native+30]
jne stale
invoke:
mov dword ptr [nb12Native],2
mov ebp,esp
push [nb12Native+18]
push [nb12Native+14]
push [nb12Native+10]
push [nb12Native+C]
mov ecx,[nb12Native+8]
call dword ptr [nb12Native+4]
mov esp,ebp
mov [nb12Native+1C],eax
mov dword ptr [nb12Native],3
jmp done
cancel:
mov dword ptr [nb12Native],4
jmp done
stale:
mov dword ptr [nb12Native],5
done:
popad
popfd
xor eax,eax
ret 10
original:
mov eax,[esp+8]
cmp eax,281
jmp %X
%X:
jmp nb12Native+100
nop 4
[DISABLE]
%X:
db 8B 44 24 08 3D 81 02 00 00
unregistersymbol(nb12Native)
dealloc(nb12Native)
]]):format(at,readInteger(K.A.rootGetter+1),at+9,at,at)
 local ok,info=K.assemble(script);assert(ok,tostring(info))
 K.native={script=script,info=info,pid=K.pid,buffer=assert(allocateSharedMemoryLocal('NB12NativeLocal_'..getTickCount(),4096))}
end
function K.nativeBusy()
 local n=K.native
 if not n or n.pid~=getOpenedProcessID() or not K.buildMatches() then return false end
 local q=K.symbolAddress('nb12Native');local state=q and readInteger(q)
 return state==1 or state==2
end
function K.assertNativeIdle()
 if K.nativeBusy() then NB.err('The previous game operation is still running. Wait before detaching or reloading the table.','ゲーム側の処理が実行中です。完了するまで解除・テーブル再読込を待ってください。') end
end
function K.nativeCall(name,this,...)
 K.ready();K.installNative()
 local fn=K.nativeAddress(name);local q=assert(K.symbolAddress('nb12Native'))
 local state=readInteger(q)
 K.assertNativeIdle()
 local order
 if K.nativeDefs[name].commandGuard then
  local m=getAddressSafe(K.EXE);local vt=readInteger(this)
  local allowed={[m+0x756020]=true,[m+0x7564F8]=true,[m+0x756170]=true,[m+0x756568]=true,[m+0x7561E0]=true}
  if not allowed[vt] then return nil,'stale' end
  for _,candidate in ipairs(K.orders()) do if candidate.p==this then order=candidate;break end end
  if not order then return nil,'stale' end
  order.vt=vt
 end
 local args={...};assert(#args&lt;=4,'Too many native arguments')
 writeInteger(q+4,fn);writeInteger(q+8,this or 0)
 for i=1,4 do writeInteger(q+8+i*4,args[i] or 0) end
 writeInteger(q+0x20,assert(K.root()));writeInteger(q+0x24,K.scenario() or 0)
 writeInteger(q+0x28,order and order.vt or 0);writeInteger(q+0x2C,order and order.officer or 0)
 writeInteger(q+0x30,K.clan() or 0);writeInteger(q+0x34,order and 1 or 0)
 writeInteger(q,1)
 local sent=0
 local w=executeCodeLocalEx('user32.GetTopWindow',0)
 for _=1,10000 do
  if not w or w==0 then break end
  if getWindowProcessID(w)==K.pid and executeCodeLocalEx('user32.IsWindowVisible',w)~=0 then
   executeCodeLocalEx('user32.SendMessageTimeoutW',w,0x83C2,q,0,2,2000,K.native.buffer)
   sent=sent+1
   if readInteger(q)~=1 then break end
  end
  w=getWindow(w,2)
 end
 state=readInteger(q)
 if state==5 then return nil,'stale' end
 -- Never reset/free a queued or executing operation after SendMessageTimeout.
 assert(state==3,('Game-thread operation failed (%s, %d windows, state %d)'):format(name,sent,state or -1))
 return readInteger(q+0x1C)
end
function K.removeNative()
 local n=K.native;if not n then return end
 K.assertNativeIdle()
 if n.pid==getOpenedProcessID() and K.buildMatches() then
  local q=K.symbolAddress('nb12Native');assert(not q or readInteger(q)~=2,'Native operation is busy')
  assert(K.assemble(n.script,n.info),'Cannot restore native dispatcher')
 end
 K.native=nil
end
local stop=K.stopFeatures
function K.stopFeatures() K.assertNativeIdle();stop();K.removeNative() end

local K=NB.K12
local function u(p) return p and p~=0 and readInteger(p) or nil end
K.catalogs={treasure={0x494,455,0x747984},rank={0x4B4,250,0x7479E4},tech={0x544,112,0x754428}}
function K.catalog(kind)
 K.ready();local d=assert(K.catalogs[kind]);local v=assert(K.vector(d[1],d[2]));local out={}
 local m=assert(getAddressSafe(K.EXE))
 for i=0,d[2]-1 do
  local p=u(v+i*4)
  assert(p and u(p)==m+d[3],kind..' object validation failed')
  out[#out+1]={id=i,p=p}
 end
 return out
end
function K.clan()
 local f=K.force();local c=f and u(f+8)
 if c and u(c)==getAddressSafe(K.EXE)+0x746870 then return c end
end
function K.plainName(p,n)
 local s=p and readString(p+4,n or 24,false)
 return s and ansiToUtf8(s) or ''
end
function K.treasureName(p)
 return K.plainName(u(p+4),15)
end
-- Explicit navigation; selection is retained when returning from the recipient.
function NB.chooseTreasureList(title,names,multiple,back,remember,accept)
 return NB.UI.choose(title,names,multiple,back,remember,accept)
end
K.chooseList=NB.chooseTreasureList
function K.assignTreasure()
 K.ready();local key=K.key();local items=K.catalog('treasure');local categories={};local ids={}
 for _,item in ipairs(items) do local cat=u(item.p+0x1C);if cat and cat&lt;36 then categories[cat]=true end end
 for cat in pairs(categories) do ids[#ids+1]=cat end;table.sort(ids)
 local categoryNames={}
 local en={'Tea caddy','Tea jar','Tea kettle','Tea bowl','Flower vase','Tea scoop','Incense burner','Water jar','Sword','Spear','Horse','Bow','Matchlock','Percussion gun','Pistol','Armor','Helmet','Swordsmanship book','Horsemanship book','Archery book','Gunnery book','Ninjutsu book','Cannon','Naval book','Architecture book','Agriculture book','Commerce book','Knowledge book','Strategy book','War chronicle','Medical book','Ink painting','Color painting','Sweets','Sake','Aromatic wood'}
 for _,cat in ipairs(ids) do
  local jp=readString(readInteger(getAddressSafe(K.EXE)+0x824130+cat*4),24,false)
  categoryNames[#categoryNames+1]=NB.T(en[cat+1] or tostring(cat),jp and ansiToUtf8(jp) or tostring(cat))
 end
 local categoryChoice,selection,recipient={},{},{}
 while true do
  local chosen,action=K.chooseList(NB.T('Treasure category','家宝の分類'),categoryNames,false,false,categoryChoice)
  if action~='next' then return end;categoryChoice=chosen;local cat=ids[chosen[1]]
  local candidates,names={},{}
  for _,item in ipairs(items) do if u(item.p+0x1C)==cat then candidates[#candidates+1]=item.p;names[#names+1]=K.treasureName(item.p) end end
  while true do
   local selected,step=K.chooseList(NB.T('Select treasures','家宝を複数選択'),names,true,true,selection[cat])
   selection[cat]=selected
   if step=='cancel' then return end;if step=='back' then break end
   local officers,onames={},{}
   for _,item in ipairs(K.objects('officer')) do
    if K.ownsForce(u(item.p+0x7C)) and u(item.p+0x10C)==7 then officers[#officers+1]=item.p;onames[#onames+1]=K.name('officer',item.p) end
   end
   local target,nav=K.chooseList(NB.T('Recipient officer','授与先の武将'),onames,false,true,recipient,NB.T('Assign','授与'))
   recipient=target
   if nav=='cancel' then return end
   if nav=='next' then
    local count=0
    for _,n in ipairs(selected) do
     K.ready();assert(K.key()==key,'Game data changed; reopen the treasure list')
     local treasure=candidates[n];K.nativeCall('treasureToOfficer',0,officers[target[1]],treasure)
     assert(u(treasure+0x10)==officers[target[1]],'Treasure ownership did not change');count=count+1
    end
    NB.msg(('Assigned %d treasures.'):format(count),('家宝を%d件授与しました。'):format(count));return
   end
  end
 end
end
function K.acquireAllTechnology()
 local clan=assert(K.clan());local changed=0
 for _,item in ipairs(K.catalog('tech')) do
  if u(u(clan+0x50)+item.id*4)~=1 then
   K.nativeCall('technologyAcquire',0,clan,item.p,1);changed=changed+1
  end
 end
 NB.msg(('Technologies acquired: %d.'):format(changed),('技術を%d件取得しました。'):format(changed))
end
function K.maximizeTechnology()
 local clan=assert(K.clan());local b,e=u(clan+0x158),u(clan+0x15C)
 local nb,ne=u(clan+0x168),u(clan+0x16C)
 -- Both native vectors contain 20 DWORDs. Validate both before writing either.
 assert(b and e and e-b==20*4,'Technology proficiency layout mismatch')
 assert(nb and ne and ne-nb==20*4,'Foreign technology progress layout mismatch')
 -- Native setters 4BBA00 and 4BBAD0 clamp values to 100000.
 for i=0,19 do writeInteger(b+i*4,100000);writeInteger(nb+i*4,100000) end
end
function K.chooseRank(kind,index)
 K.ready();local officer=kind=='player' and K.player() or K.object('officer',index)
 assert(officer,'Officer unavailable')
 local ranks,names={},{}
 for _,item in ipairs(K.catalog('rank')) do
  local name=K.plainName(item.p,32)
  if name~='' then ranks[#ranks+1]=item.p;names[#names+1]=name end
 end
 local selected=NB.pick(NB.T('Choose official court rank','授与する官位を選択'),names)
 if selected then
  local old=u(officer+0x74)
  if old==ranks[selected] then K.refreshRankRows();return end
  if old and old~=0 and u(old+0x38)&gt;=u(ranks[selected]+0x38) then K.nativeCall('rankClear',0,officer) end
  K.nativeCall('rankAward',0,officer,ranks[selected])
  assert(u(officer+0x74)==ranks[selected],'Court rank was not assigned to the officer')
  K.refreshRankRows()
 end
end
function K.addAction(parent,en,ja,body)
 local row=NB.addRec(parent,en,ja,'0',vtAutoAssembler)
 row.Script='[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() '..body..' end)\n{$asm}\n[DISABLE]\n'
 row.Color=NB.C_SCRIPT
 return row
end
function K.refreshRankRows()
 if not K.attached() then return end
 local key=K.key();local al=getAddressList()
 for parentID,editor in pairs(K.editors) do
  if editor.rankRowID and editor.rankKey==key then
   local row=al.getMemoryRecordByID(editor.rankRowID)
   if row and row.Parent and row.Parent.ID==parentID then
    local officer=editor.rankKind=='player' and K.player() or K.object('officer',editor.rankIndex)
    local rank=officer and u(officer+0x74)
    local name=rank and rank~=0 and K.plainName(rank,32) or nil
    local en,ja='Court rank: '..(name or 'None'),'官位：'..(name or 'なし')
    for _,entry in ipairs(NB.dyn) do if entry.mr.ID==editor.rankRowID then entry.en=en;entry.ja=ja;break end end
    row.Description=NB.T(en,ja)
   end
  end
 end
end
function K.addRankAction(mr,kind,index)
 local editor=assert(K.editors[mr.ID]);local row=K.addAction(mr,'Court rank','官位',('NB.K12.chooseRank(%q,%s)'):format(kind,tostring(index)))
 editor.rankRowID=row.ID;editor.rankKind=kind;editor.rankIndex=index;editor.rankKey=K.key()
 K.refreshRankRows()
end
local open=K.openEditor
function K.openEditor(mr,kind)
 open(mr,kind)
 if (kind=='player' or kind=='officer') and K.selected(kind) then K.addRankAction(mr,kind,K.sel[kind]) end
end
function K.openCourt(mr)
 K.ready();NB.clearChildren(mr)
 K.editors[mr.ID]={mr=mr,kind='court'}
 K.addRankAction(mr,'player');mr.Collapsed=false
end
local tick=K.tick
function K.tick() tick();K.refreshRankRows() end
local assign,court,unlock=NB.assignTreasure,NB.openCourtEditor,NB.unlockCityDevelopment
function NB.assignTreasure() if NB.game==2 then return K.assignTreasure() end;return assign() end
function NB.openCourtEditor(mr) if NB.game==2 then return K.openCourt(mr) end;return court(mr) end
function NB.unlockCityDevelopment() if NB.game==2 then return K.acquireAllTechnology() end;return unlock() end

local K=NB.K12
local function u(p) return p and p~=0 and readInteger(p) or nil end
K.patchDefs={};K.patches={}
K.patchDefs.foodSet={rva=0xDDB90,bytes={139,68,36,4,86}}
K.patchDefs.buildingHit={rva=0x154990,bytes={106,255,104,121,18,165,0}}
K.patchDefs['soldierLoss']={rva=0xDF1E0,bytes={139,68,36,4,133,192}}
K.patchDefs['moraleSet']={rva=0xA79D0,bytes={139,68,36,4,86,106,100}}
K.patchDefs['moraleDelta']={rva=0xA8000,bytes={139,68,36,4,86}}
K.patchDefs['spiritSet']={rva=0xDF1C0,bytes={139,68,36,4,86}}
K.patchDefs['skillTick']={rva=0xDF230,bytes={86,139,241,139,134,128,0,0,0}}
K.patchDefs['oneHitNormal']={rva=0x14E2E1,bytes={80,139,206,232,247,14,249,255}}
K.patchDefs['oneHitSiege']={rva=0x15849B,bytes={85,139,206,232,61,109,248,255}}
function K.armies()
 local r=K.root();if not r then return {} end
 local head,count=u(r+0x578),u(r+0x57C);local out={}
 if not head or not count or count&gt;4096 then return out end
 local n=u(head);local seen={};local vt=getAddressSafe(K.EXE)+0x754890
 for _=1,count do
  if not n or n==head or seen[n] then break end;seen[n]=true
  local p=u(n+8)
  if p and u(p)==vt and u(p+0x94) and u(p+0x94)~=0 then out[#out+1]=p end
  n=u(n)
 end
 return out
end
function K.playerArmy()
 local player=K.player()
 for _,p in ipairs(K.armies()) do
  local h=u(p+0xA4);local n=h and u(h)
  for _=1,64 do
   if not n or n==h then break end
   if u(n+8)==player then return p end;n=u(n)
  end
 end
end
function K.ensureFlags()
 if K.symbolAddress('nb12Flags') then return end
 local ok,info=K.assemble('[ENABLE]\nalloc(nb12Flags,4096)\nregistersymbol(nb12Flags)\nnb12Flags:\ndd 0 0 0 0 0\n[DISABLE]\nunregistersymbol(nb12Flags)\ndealloc(nb12Flags)')
 assert(ok,tostring(info));K.flagAllocation=info
end
function K.updateFlags()
 local b=K.symbolAddress('nb12Flags');if not b then return end
 local bits=0
 for name,bit in pairs({ownBattle=1,playerBattle=2,battleOneHit=4,battleSkills=8,actions=16,instantDevelopment=32,negotiationSuccess=64,recruitment=128,schemes=256,armySpeed=512,instantExploration=1024}) do if K.on[name] then bits=bits|bit end end
 writeInteger(b,0)
 writeInteger(b+4,K.root() or 0);writeInteger(b+8,K.force() or 0)
 writeInteger(b+12,K.playerArmy() or 0);writeInteger(b+16,K.clan() or 0)
 writeInteger(b+20,K.scenario() or 0)
 writeInteger(b,bits)
end
function K.installPatch(name,body,original)
 if K.patches[name] then
  local d=K.patchDefs[name];local expected=K.patches[name].installed
  local actual=readBytes(getAddressSafe(K.EXE)+d.rva,16,true)
  for i,b in ipairs(expected) do assert(actual and actual[i]==b,'Installed hook changed: '..name) end
  return
 end
 body=body:gsub('cmp eax,%[nb12Flags%+4%]\njne done','cmp eax,[nb12Flags+4]\njne done\nmov eax,[eax+588]\ncmp eax,[nb12Flags+14]\njne done')
 if not body:find('ownerCheck:',1,true) then body=body..'\nownerCheck:\n' end
 if not body:find('protected:',1,true) then body=body..'\nprotected:\n' end
 K.ensureFlags();local d=assert(K.patchDefs[name]);local site=getAddressSafe(K.EXE)+d.rva
 local bytes=readBytes(site,#d.bytes,true);assert(bytes,'Patch site unavailable: '..name)
 for i,b in ipairs(d.bytes) do assert(bytes[i]==b,'Patch site mismatch: '..name) end
 local db={};for _,b in ipairs(d.bytes) do db[#db+1]=('%02X'):format(b) end
 local script=('[ENABLE]\nalloc(nb12_%s,4096,%X)\nlabel(original)\nlabel(done)\nlabel(protected)\nlabel(ownerCheck)\nnb12_%s:\n%s\noriginal:\n%s\njmp %X\n%X:\njmp nb12_%s\n%s\n[DISABLE]\n%X:\ndb %s\ndealloc(nb12_%s)'):format(name,site,name,body,original,site+#d.bytes,site,name,#d.bytes&gt;5 and ('nop '..(#d.bytes-5)) or '',site,table.concat(db,' '),name)
 local ok,info=K.assemble(script);assert(ok,tostring(info));K.patches[name]={script=script,info=info,pid=K.pid,installed=readBytes(site,16,true)}
end
function K.removePatches()
 for name,p in pairs(K.patches) do
  if p.pid==getOpenedProcessID() and K.buildMatches() then assert(K.assemble(p.script,p.info),'Cannot restore '..name) end
 end
 K.patches={}
 if K.flagAllocation and K.attached() then
  assert(K.assemble('[ENABLE]\nalloc(nb12Flags,4096)\nregistersymbol(nb12Flags)\n[DISABLE]\nunregistersymbol(nb12Flags)\ndealloc(nb12Flags)',K.flagAllocation))
 end
 K.flagAllocation=nil
end
-- Entry guard: preserve registers/flags and only match the current player
-- army or armies whose force pointer equals the current player force.
function K.armyGuard(actor,mask,own)
 local selection=mask==3 and ([[test eax,1
jnz ownerCheck
cmp %s,[nb12Flags+C]
jne done
jmp protected
ownerCheck:
]]):format(actor):gsub('\n%+','\n') or 'ownerCheck:\n'
 return ([[
pushfd
push eax
mov eax,[%s]
cmp eax,%X
jne done
mov eax,[%X]
cmp eax,[nb12Flags+4]
jne done
mov eax,[nb12Flags]
test eax,%X
jz done
%s
mov eax,[%s+94]
test eax,eax
jz done
mov eax,[eax+8]
cmp eax,[nb12Flags+10]
jne done
protected:
pop eax
popfd
%s
jmp original
done:
pop eax
popfd
]]):gsub('\n%+','\n'):format(actor,getAddressSafe(K.EXE)+0x754890,readInteger(K.A.rootGetter+1),mask,selection,actor,own)
end
function K.installBattlePatches()
 local guard=K.armyGuard('ecx',3,'mov dword ptr [esp+4],0')
 K.installPatch('soldierLoss',guard,'mov eax,[esp+4]\ntest eax,eax')
 K.installPatch('moraleSet',K.armyGuard('ecx',3,'mov dword ptr [esp+4],64'),'mov eax,[esp+4]\npush esi\npush 64')
 K.installPatch('moraleDelta',K.armyGuard('ecx',3,'mov dword ptr [esp+4],0\nmov dword ptr [ecx+6C],64'),'mov eax,[esp+4]\npush esi')
end
function K.installSkillPatches()
 -- No branch that belongs to AI/enemy armies is changed.
 local body=K.armyGuard('ecx',8,'mov dword ptr [ecx+7C],3E8\nmov dword ptr [ecx+80],0')
 -- Skill guard uses player ownership independently from invulnerability bits.
 body=body:gsub('test eax,1\njz protected','test eax,8\njz done'):gsub('jmp done\nprotected:','jmp done\nprotected:')
 K.installPatch('skillTick',body,'push esi\nmov esi,ecx\nmov eax,[esi+80]')
 local setter=K.armyGuard('ecx',8,'mov dword ptr [esp+4],3E8')
 setter=setter:gsub('test eax,1\njz protected','test eax,8\njz done')
 K.installPatch('spiritSet',setter,'mov eax,[esp+4]\npush esi')
end
function K.installOneHit()
 local m=getAddressSafe(K.EXE);local root=readInteger(K.A.rootGetter+1)
 local body=([[
pushfd
push eax
test dword ptr [nb12Flags],4
jz done
mov eax,[%X]
cmp eax,[nb12Flags+4]
jne done
cmp dword ptr [edi],%X
jne done
mov eax,[edi+94]
test eax,eax
jz done
mov eax,[eax+8]
cmp eax,[nb12Flags+10]
jne done
cmp dword ptr [esi],%X
jne ownerCheck
mov eax,[esi+94]
test eax,eax
jz done
mov eax,[eax+8]
cmp eax,[nb12Flags+10]
je done
jmp protected
ownerCheck:
cmp dword ptr [esi],%X
jne done
mov eax,[esi+E0]
test eax,eax
jz done
mov eax,[eax+8]
cmp eax,[nb12Flags+10]
je done
protected:
mov eax,[esi+40]
mov [esp],eax
done:
pop eax
popfd
]]):format(root,m+0x754890,m+0x754890,m+0x746588)
 K.installPatch('oneHitNormal',body,'push eax\nmov ecx,esi\ncall '..('%X'):format(m+0xDF1E0))
 -- The siege damage register is EBP at this second call site.
 local b=body:gsub('mov %[esp%],eax','mov [esp+4],eax')
 -- EBP must survive the guard; save it in place of EAX and set only damage.
 b=b:gsub('push eax','push ebp'):gsub('pop eax','pop ebp'):gsub('mov %[esp%+4%],eax','mov [esp],eax')
 K.installPatch('oneHitSiege',b,'push ebp\nmov ecx,esi\ncall '..('%X'):format(m+0xDF1E0))
end
function K.installBuildingHit()
 local m=getAddressSafe(K.EXE);local root=readInteger(K.A.rootGetter+1)
 local body=([[pushfd
pushad
test dword ptr [nb12Flags],4
jz done
mov eax,[%X]
cmp eax,[nb12Flags+4]
jne done
mov eax,[esp+28]
test eax,eax
jz done
cmp dword ptr [eax],%X
jne done
mov eax,[eax+94]
test eax,eax
jz done
mov eax,[eax+8]
cmp eax,[nb12Flags+10]
jne done
mov esi,[esp+2C]
test esi,esi
jz done
cmp dword ptr [esi],%X
jne done
mov ecx,esi
call %X
test eax,eax
jz done
mov eax,[eax+8]
cmp eax,[nb12Flags+10]
je done
mov eax,[esi+C]
mov [esp+30],eax
done:
popad
popfd
]]):format(root,m+0x754890,m+0x746368,m+0x964B0)
 K.installPatch('buildingHit',body,'push -1\npush '..('%X'):format(m+0x651279))
end
function K.installFoodProtection()
 local root=readInteger(K.A.rootGetter+1)
 local body=([[pushfd
push eax
test dword ptr [nb12Flags],3
jz done
mov eax,[%X]
cmp eax,[nb12Flags+4]
jne done
mov eax,[ecx+8]
cmp eax,[nb12Flags+10]
jne done
mov dword ptr [esp+C],#99999
done:
pop eax
popfd
]]):format(root)
 K.installPatch('foodSet',body,'mov eax,[esp+4]\npush esi')
end
function K.runBattle()
 local own,player=K.on.ownBattle,K.on.playerBattle
 local playerUnit=K.playerArmy();local force=K.force()
 if not force then return end
 for _,p in ipairs(K.armies()) do
  if K.ownsForce(u(p+0x94)) then
   if own or (player and p==playerUnit) then writeInteger(p+0x40,99999);writeInteger(p+0x6C,100) end
   if K.on.battleSkills then writeInteger(p+0x7C,1000);writeInteger(p+0x80,0) end
  end
 end
 if own or player then writeInteger(force+0x50,99999) end
end
local feature,run,stop=K.feature,K.runFeatures,K.stopFeatures
function K.feature(key,on)
 if key=='ownBattle' or key=='playerBattle' or key=='battleOneHit' or key=='battleSkills' then
  if on then
   K.ready();K.snapshot=K.key();K.ensureFlags()
   if key=='ownBattle' or key=='playerBattle' then K.installBattlePatches();K.installFoodProtection()
   elseif key=='battleSkills' then K.installSkillPatches() else K.installOneHit();K.installBuildingHit() end
   K.on[key]=true
  else K.on[key]=nil end
  K.updateFlags();if on then K.runBattle() end
  return
 end
 return feature(key,on)
end
function K.runFeatures() run();K.updateFlags();K.runBattle() end
function K.stopFeatures() K.assertNativeIdle();local b=K.symbolAddress('nb12Flags');if b and K.attached() then writeInteger(b,0) end;K.removePatches();stop() end

local K=NB.K12
local chances={}
local function originalBytes(name) local out={};for _,b in ipairs(K.patchDefs[name].bytes) do out[#out+1]=('%02X'):format(b) end;return 'db '..table.concat(out,' ') end
K.patchDefs.chance_recruit={rva=0x307DF0,bytes={131,236,12,83,85}}
chances['recruit']={mask=128}
K.patchDefs.chance_poach={rva=0x307FA0,bytes={83,139,92,36,8}}
chances['poach']={mask=128}
K.patchDefs.chance_incite={rva=0x307870,bytes={131,236,20,87,139,124,36,32}}
chances['incite']={mask=256}
K.patchDefs.chance_mislead={rva=0x308940,bytes={106,255,104,120,80,167,0}}
chances['mislead']={mask=256}
K.patchDefs.chance_rumor={rva=0x308BC0,bytes={106,255,104,152,80,167,0}}
chances['rumor']={mask=256}
K.patchDefs.chance_ambush={rva=0x308F10,bytes={106,255,104,216,80,167,0}}
chances['ambush']={mask=256}
K.patchDefs.chance_encourage={rva=0x308E00,bytes={106,255,104,184,80,167,0}}
chances['encourage']={mask=256}
K.patchDefs.chance_alliance={rva=0x307AD0,bytes={139,68,36,12,131,192,254}}
chances['alliance']={mask=64}
K.patchDefs.chance_request={rva=0x3068F0,bytes={139,68,36,12,131,248,12}}
chances['request']={mask=64}
K.patchDefs.chance_trade={rva=0x3069A0,bytes={139,68,36,12,131,192,253}}
chances['trade']={mask=64}
K.patchDefs.chance_truce={rva=0x306A30,bytes={139,68,36,12,72}}
chances['truce']={mask=64}
K.patchDefs.chance_return={rva=0x306AD0,bytes={131,236,8,85,87}}
chances['return']={mask=64}
K.patchDefs.chance_surrender={rva=0x306C00,bytes={83,85,139,108,36,12}}
chances['surrender']={mask=64}
function K.installChance(mask)
 local m=getAddressSafe(K.EXE);local root=readInteger(K.A.rootGetter+1)
 for name,d in pairs(chances) do if d.mask==mask then
  local body=([[pushfd
push eax
push edx
test dword ptr [nb12Flags],%X
jz done
mov eax,[%X]
cmp eax,[nb12Flags+4]
jne done
mov edx,[esp+10]
test edx,edx
jz done
cmp dword ptr [edx],%X
jne done
mov eax,[edx+7C]
test eax,eax
jz done
mov eax,[eax+8]
cmp eax,[nb12Flags+10]
jne done
pop edx
pop eax
popfd
mov eax,64
ret
done:
pop edx
pop eax
popfd
]]):format(mask,root,m+0x7463DC)
  K.installPatch('chance_'..name,body,originalBytes('chance_'..name))
 end end
end
local feature=K.feature
function K.feature(key,on)
 local mask=({negotiationSuccess=64,recruitment=128,schemes=256})[key]
 if not mask then return feature(key,on) end
 if on then K.ready();K.snapshot=K.key();K.ensureFlags();K.installChance(mask);K.on[key]=true else K.on[key]=nil end
 K.updateFlags()
end

local work={}
K.patchDefs.workResearch={rva=0x1B1370,bytes={131,236,8,86,139,241}}
work.workResearch={mask=32,actor='mov edx,ecx',result=0}
K.patchDefs.workRemodel={rva=0x1B44C0,bytes={86,139,241,139,70,100}}
work.workRemodel={mask=32,actor='mov edx,ecx',result=0}
K.patchDefs.workBuild={rva=0x39FE60,bytes={106,255,104,72,203,167,0}}
work.workBuild={mask=32,actor='mov edx,[esp+10]\nsub edx,4',result=1000000}
K.patchDefs.workCastle={rva=0x3A0050,bytes={106,255,104,104,203,167,0}}
work.workCastle={mask=32,actor='mov edx,[esp+10]\nsub edx,4',result=1000000}
K.patchDefs.workRepair={rva=0x3A1280,bytes={106,255,104,136,204,167,0}}
work.workRepair={mask=32,actor='mov edx,[esp+10]\nsub edx,4',result=1000000}
K.patchDefs.commandTravel={rva=0xB1860,bytes={86,139,241,139,6}}
work.commandTravel={mask=16,actor='mov edx,ecx',result=0}
function K.installWork(mask)
 local m=getAddressSafe(K.EXE);local root=readInteger(K.A.rootGetter+1)
 for name,d in pairs(work) do if d.mask==mask then
 local body=([[pushfd
push eax
push edx
test dword ptr [nb12Flags],%X
jz done
mov eax,[%X]
cmp eax,[nb12Flags+4]
jne done
%s
test edx,edx
jz done
mov eax,[edx]
cmp eax,%X
jb done
cmp eax,%X
jae done
cmp dword ptr [eax+4],%X
jne done
mov eax,[edx+1C]
test eax,eax
jz done
mov eax,[eax+8]
cmp eax,[nb12Flags+10]
jne done
pop edx
pop eax
popfd
mov eax,%X
ret
done:
pop edx
pop eax
popfd
]]):format(mask,root,d.actor,m+0x740000,m+0x770000,m+0xB24D0,d.result)
 K.installPatch(name,body,originalBytes(name))
 end end
end
local previousFeature=K.feature
function K.feature(key,on)
 local mask=({actions=16,instantDevelopment=32})[key]
 if key=='maxInvestment' then
  if on then K.ready();K.snapshot=K.key();K.maximizeTechnology();K.on[key]=true else K.on[key]=nil end
  return
 end
 if not mask then return previousFeature(key,on) end
 if on then K.ready();K.snapshot=K.key();K.ensureFlags();K.installWork(mask);K.on[key]=true else K.on[key]=nil end
 K.updateFlags()
end
local run=K.runFeatures
function K.runFeatures()
 run()
 if K.on.maxInvestment and K.key()==K.snapshot then K.maximizeTechnology() end
end

function K.orders()
 local out,seen={},{}
 for _,v in ipairs(K.objects('officer')) do
  local p=v.p
  if K.ownsForce(readInteger(p+0x7C)) and readInteger(p+0xF0)==5 then
   local node=readInteger(p+0xF4);local cmd=node and node~=0 and readInteger(node+0xC)
   local vt=cmd and cmd~=0 and readInteger(cmd)
   local m=getAddressSafe(K.EXE)
   if vt and vt&gt;=m+0x740000 and vt&lt;m+0x770000 and readInteger(vt+4)==m+0xB24D0 and not seen[cmd] then
    seen[cmd]=true;out[#out+1]={p=cmd,officer=p,vt=vt}
   end
  end
 end
 return out
end
local report=NB.reportDevelopment
function NB.reportDevelopment()
 if NB.game~=2 then return report() end
 K.ready()
 local orders=K.orders()
 NB.msg(('Active own-force orders: %d.'):format(#orders),('自勢力の実行中命令：%d件。'):format(#orders))
 for _,v in ipairs(orders) do
  NB.msg(('%s: %X (vtable %X)'):format(K.name('officer',v.officer),v.p,v.vt))
 end
end

-- Remodeling's update has its own phase-9 gate, before the remaining-days
-- getter. Returning zero from the getter alone cannot bypass that gate.
local workPhases={
 buildPhase={rva=0x1B74E8,bytes={15,132,44,3,0,0},vt=0x756170,pass=0x1B74EE,skip=0x1B781A},
 remodelPhase={rva=0x1B4681,bytes={15,132,193,1,0,0},vt=0x756020,pass=0x1B4687,skip=0x1B4848},
 repairPhase={rva=0x1BDBCE,bytes={15,132,35,1,0,0},vt=0x7564F8,pass=0x1BDBD4,skip=0x1BDCF7},
 explorePhase={rva=0x1BE12D,bytes={15,132,23,9,0,0},vt=0x756568,pass=0x1BE133,skip=0x1BEA4A,mask=1024},
 exploreDate={rva=0x1BE153,bytes={15,133,241,8,0,0},vt=0x756568,pass=0x1BE159,skip=0x1BEA4A,mask=1024,branch='jne'}}
for name,d in pairs(workPhases) do K.patchDefs[name]=d end
function K.installWorkPhases()
 local m=getAddressSafe(K.EXE)
 for name,d in pairs(workPhases) do
 local body=([[pushfd
push eax
test dword ptr [nb12Flags],%X
jz done
mov eax,[%X]
cmp eax,[nb12Flags+4]
jne done
cmp dword ptr [esi],%X
jne done
mov eax,[esi+1C]
test eax,eax
jz done
mov eax,[eax+8]
cmp eax,[nb12Flags+10]
jne done
pop eax
popfd
jmp %X
done:
pop eax
popfd
]]):format(d.mask or 32,readInteger(K.A.rootGetter+1),m+d.vt,m+d.pass)
 K.installPatch(name,body,('%s %X'):format(d.branch or 'je',m+d.skip))
 end
end
-- Complete each normal path segment in one movement update. The existing
-- arrival branch caps displacement to that segment's endpoint; path finding,
-- collision checks, tile registration and arrival events remain native.
K.patchDefs.armySpeed={rva=0x23AA58,bytes={139,56,161,44,126,197,0}}
function K.installArmySpeed()
 local original='mov edi,[eax]\nmov eax,[NOBU12PK.exe+857E2C]'
 -- Run the original loads first. The guard preserves their EAX and flags.
 -- At this site ESI is the movement order and EBX is scratch, so preserve it
 -- while supplying the army pointer to the shared ownership guard.
 local body=original..'\npush ebx\nmov ebx,[esi+4]\n'..K.armyGuard('ebx',512,'mov edi,800')..'\noriginal:\npop ebx\n'
 -- installPatch owns the original label; remove the guard's jump/our label.
 body=body:gsub('jmp original','jmp protectedEnd'):gsub('\noriginal:','\nprotectedEnd:')
 -- Label declaration is local to this body and does not collide with others.
 body='label(protectedEnd)\n'..body
 K.installPatch('armySpeed',body,'')
end
-- Remodeling/repair completion must run on the game window thread. Its normal
-- updater can remain unscheduled even when the remaining-days getter is zero.
-- Use CCommand::update (4B1AB0), which also retires a finished command from
-- the city/manager registries. The derived work updater alone leaves it busy.
K.nativeDefs.workUpdate={commandGuard=true,rva=0xB1AB0,bytes={86,139,241,232,184,255,255,255,139,6,139,206,255,80,44,131}}
K.nativeDefs.commandMenuRefresh={rva=0x3A4CF0,bytes={131,236,24,83,85,86,139,217,87,137,92,36,20,232,206,202}}
function K.refreshCommandMenu()
 if not K.menuRefreshPending or K.menuRefreshPending~=K.key() then return end
 local m=getAddressSafe(K.EXE);local context=m+0xBED724
 local menu=readInteger(context+0xC)
 if not menu or menu==0 or readInteger(menu)~=m+0x773320 then return end
 local selector=readInteger(menu+0x70);local tab=selector and selector~=0 and readInteger(selector+0x64)
 if not tab or tab&lt;0 or tab&gt;=8 then return end
 -- Re-run the game's own enable/disable predicates for the current tab.
 -- Keep the active menu and tab, and do not force-enable invalid commands.
 K.nativeCall('commandMenuRefresh',menu,tab)
 K.menuRefreshPending=nil
end
function K.finishInstantOrders()
 if (not K.on.instantDevelopment and not K.on.instantExploration) or K.key()~=K.snapshot then return end
 local m=getAddressSafe(K.EXE);local types={}
 if K.on.instantDevelopment then types[m+0x756020]=true;types[m+0x7564F8]=true;types[m+0x756170]=true end
 if K.on.instantExploration then types[m+0x756568]=true end
 for _,order in ipairs(K.orders()) do
  local p=order.p
  if K.key()~=K.snapshot then return end
  -- Completed commands have no assigned officers. Never update them twice.
  if types[readInteger(p)] and (readInteger(p+0xC) or 0)&gt;0 and readBytes(p+0x30,1)==0 and K.ownsForce(readInteger(p+0x1C)) then
   K.nativeCall('workUpdate',p)
   K.menuRefreshPending=K.key()
  end
 end
 K.refreshCommandMenu()
end
K.patchDefs.actionUsed={rva=0x979E0,bytes={138,68,36,4,138,145,96,1,0,0}}
function K.installActionUsed()
 local m=getAddressSafe(K.EXE)
 local body=([[pushfd
push eax
test dword ptr [nb12Flags],10
jz done
cmp dword ptr [ecx],%X
jne done
mov eax,[%X]
cmp eax,[nb12Flags+4]
jne done
mov eax,[ecx+7C]
test eax,eax
jz done
mov eax,[eax+8]
cmp eax,[nb12Flags+10]
jne done
pop eax
popfd
mov dword ptr [esp+4],0
jmp original
done:
pop eax
popfd
]]):format(m+0x7463DC,readInteger(K.A.rootGetter+1))
 K.installPatch('actionUsed',body,'mov al,[esp+4]\nmov dl,[ecx+160]')
end
function K.clearActionUsed()
 if not K.on.actions or K.key()~=K.snapshot then return end
 for _,v in ipairs(K.objects('officer')) do
  if readInteger(v.p+0x10C)==7 and K.ownsForce(readInteger(v.p+0x7C)) then
   local bits=readBytes(v.p+0x160,1)
   if bits and bits&amp;2~=0 then writeBytes(v.p+0x160,bits&amp;0xFD);K.menuRefreshPending=K.key() end
  end
 end
 if K.on.actions then K.refreshCommandMenu() end
end
local movementFeature=K.feature
function K.feature(key,on)
 if key=='instantExploration' then
  if on then K.ready();K.snapshot=K.key();K.ensureFlags();K.installWorkPhases();K.on[key]=true else K.on[key]=nil end
  K.updateFlags();if on then K.finishInstantOrders() end;return
 end
 if key=='actions' and on then K.ready();K.ensureFlags();K.installActionUsed() end
 if key=='armySpeed' then
  if on then K.ready();K.snapshot=K.key();K.ensureFlags();K.installArmySpeed();K.on[key]=true else K.on[key]=nil end
  K.updateFlags();return
 end
 if key=='instantDevelopment' and on then
  -- Validate/install the phase hook before enabling the rest of this feature.
  K.ready();K.ensureFlags();K.installWorkPhases()
 end
 local result=movementFeature(key,on)
 if key=='instantDevelopment' and not on then K.menuRefreshPending=nil end
 if key=='instantDevelopment' and on then K.finishInstantOrders() end
 if key=='actions' and on then K.clearActionUsed() end
 return result
end
local updateFeatures=K.runFeatures
function K.runFeatures()
 updateFeatures();K.finishInstantOrders();K.clearActionUsed()
end

-- A zero travel duration alone leaves return commands waiting for phase 23.
-- Finish returns through CCommand::update so the native arrival and retirement
-- release their officers; never detach officers from other ongoing commands.
K.patchDefs.returnPhase={rva=0x1B7E3B,bytes={132,192,116,78,139,6}}
function K.installReturnPhase()
 local m=getAddressSafe(K.EXE)
 local body=([[pushfd
push eax
test dword ptr [nb12Flags],10
jz done
mov eax,[%X]
cmp eax,[nb12Flags+4]
jne done
cmp dword ptr [esi],%X
jne done
mov eax,[esi+1C]
test eax,eax
jz done
mov eax,[eax+8]
cmp eax,[nb12Flags+10]
jne done
pop eax
popfd
mov al,1
jmp original
done:
pop eax
popfd
]]):format(readInteger(K.A.rootGetter+1),m+0x7561E0)
 K.installPatch('returnPhase',body,('test al,al\nje %X\nmov eax,[esi]'):format(m+0x1B7E8D))
end
function K.finishReturns()
 if not K.on.actions or K.key()~=K.snapshot then return end
 local vt=getAddressSafe(K.EXE)+0x7561E0
 for _,o in ipairs(K.orders()) do
  if K.key()~=K.snapshot then return end
  if readInteger(o.p)==vt and (readInteger(o.p+12) or 0)&gt;0 and readBytes(o.p+0x30,1)==0 then
   K.nativeCall('workUpdate',o.p);K.menuRefreshPending=K.key()
  end
 end
 K.clearActionUsed()
end
local actionFeature=K.feature
function K.feature(key,on)
 if key=='actions' and on then K.ready();K.ensureFlags();K.installReturnPhase() end
 local result=actionFeature(key,on)
 if key=='actions' and on then K.finishReturns() end
 return result
end
local actionRun=K.runFeatures
function K.runFeatures() actionRun();K.finishReturns() end

local K=NB.K12
-- Native resource clamp 4C85B0: ships and siege engines have cap 1000.
for _,f in ipairs({
 {'Sekibune','関船',0x60,0,1000},
 {'Atakebune','安宅船',0x64,0,1000},
 {'Ironclads','鉄甲船',0x68,0,1000},
 {'Wounded soldiers','負傷兵',0x44,0,500000,'self',false},
 {'Castle durability','城郭耐久',0xC,0,40000,'castle'}}) do K.fields.city[#K.fields.city+1]=f end
for _,f in ipairs({
 {'Honor / obligation','義理',0x150,0,100},
 {'Merit','勲功',0x138,0,999},
 {'Stipend','俸禄',0x158,0,5000},
 {'Injury','傷病',0x114,0,2,'self',false,'0:Healthy / 健康\n1:Light injury / 軽傷\n2:Serious injury / 重傷'},
 {'Birth year','生年',0x128,1,9999},
 {'Appearance year','登場年',0x12C,1,9999},
 {'Death year','死亡年',0x130,1,9999}}) do K.fields.officer[#K.fields.officer+1]=f end
local troops={{'Infantry','足軽'},{'Cavalry','騎馬'},{'Bows','弓'},{'Guns','鉄砲'},{'Schemes','計略'},{'Siege engines','兵器'},{'Navy','水軍'},{'Castle construction','築城'},{'Domestic affairs','内政'}}
for i,t in ipairs(troops) do
 K.fields.officer[#K.fields.officer+1]={t[1]..' aptitude (base)',t[2]..'適性（基本）',0xCC+4*(i-1),0,4,'self',false,'0:D\n1:C\n2:B\n3:A\n4:S'}
 if i&lt;=6 then K.fields.officer[#K.fields.officer+1]={t[1]..' proficiency',t[2]..'熟練',0x90+4*(i-1),0,1000} end
end
K.nativeDefs.castleCap={rva=0x96030,bytes={139,73,4,133,201,116,5}}
K.nativeDefs.cityDurabilitySet={rva=0xF7450,bytes={86,139,116,36,8,86,232,213,219,252,255,131,196,4,132,192}}
K.nativeDefs.officerRecalculate={rva=0x9A3B0,bytes={131,236,8,83,85,139,217,86,141,179,100,1,0,0,87,139}}
function K.castleCap(city)
 assert(city and readInteger(city)==getAddressSafe(K.EXE)+0x746588,'Invalid city')
 local castle=readInteger(city+0xE8)
 assert(castle and castle~=0 and readInteger(castle)==getAddressSafe(K.EXE)+0x746368,'Invalid castle')
 local value=K.nativeCall('castleCap',castle)
 assert(value and value&gt;=0 and value&lt;=40000,'Invalid castle durability cap')
 return value
end
local function aptitudeKey(p)
 local bytes=readBytes(p+0xCC,36,true);return bytes and table.concat(bytes,',')
end
local open=K.openEditor
function K.openEditor(mr,kind)
 open(mr,kind)
 if kind=='officer' or kind=='player' then
  local meta=K.editors[mr.ID];local p=K.selected(kind)
  if meta and p then meta.aptitude={p=p,key=K.key(),value=aptitudeKey(p)} end
 end
end
local tick=K.tick
function K.tick()
 tick()
 for _,meta in pairs(K.editors) do
  local state=meta.aptitude
  if state and state.key==K.key() and K.selected(meta.kind)==state.p then
   local value=aptitudeKey(state.p)
   if value and value~=state.value then
    K.nativeCall('officerRecalculate',state.p)
    state.value=value
   end
  end
 end
end

-- Clan list columns FC026C/FC02A8 -&gt; credit 4B9680 / fame 4B9690.
-- Fame is derived by 4BC490: credit + 10 per eligible base + facilities,
-- clamped to 0..5000. Never edit its cached display without updating credit.
K.nativeDefs.clanCreditSet={rva=0xBC620,bytes={139,68,36,4,86,104,136,19,0,0,104,120,236,255,255,80}}
K.nativeDefs.clanRecalculate={rva=0xBC490,bytes={131,236,48,83,85,86,87,139,217,232,226,209,255,255}}
K.clanFields={
 {'Fame (shared by clan)','名声（勢力共有）',0xF8,0,5000,'clan'},
 {'Credit (fame modifier)','信用（名声の補正値）',0xF4,-5000,5000,'clan'}}
local function signed(v) if v&gt;=0x80000000 then return v-0x100000000 end;return v end
function K.writeClanField(field,value)
 K.ready();local clan=assert(K.clan(),'Clan is unavailable')
 if field[3]==0xF8 then
  K.nativeCall('clanRecalculate',clan)
  local contribution=readInteger(clan+0xF8)-signed(readInteger(clan+0xF4))
  value=math.max(-5000,math.min(5000,value-contribution))
 end
 K.nativeCall('clanCreditSet',clan,value)
 return field[3]==0xF4 and signed(readInteger(clan+0xF4)) or readInteger(clan+0xF8)
end
local parameterOpen=K.openEditor
function K.openEditor(mr,kind)
 parameterOpen(mr,kind)
 if kind=='player' and K.editors[mr.ID] then
  for _,field in ipairs(K.clanFields) do K.addField(mr,'player',nil,field) end
 end
end

do
-- Tendou PK 1.0.0.3 / Steam build 2338456.
-- Independent layouts: never resolve an N13 object using an N11/N12 offset.
NB.K13={EXE='NOBU13PK.exe',VERSION='1.0.0.3',STEAMBUILD='2338456',
 BUILD={ts=0x5A252884,size=0xFC3A000},pid=nil,sel={},on={},editors={}}
local K=NB.K13
local function u(p) return p and p&gt;=0x10000 and readInteger(p) or nil end
K.u=u
K.types={
 building={off=0x12C,count=8192,vt=0xA8FEB8},
 officer={off=0x13C,count=2600,vt=0xA8FEF4},
 clan={off=0x15C,count=66,vt=0xA90594},
 force={off=0x16C,count=100,vt=0xA91E38},
 city={off=0x17C,count=264,vt=0xA90230},
 cityName={off=0x18C,count=264,vt=0xA900EC},
 county={off=0x19C,count=568,vt=0xA8FE70},
 army={off=0x1AC,count=700,vt=0xA93350},
 buildingDef={off=0x1CC,count=59,vt=0xA907F4},
 treasure={off=0x1EC,count=453,vt=0xA91EF4},
 rank={off=0x1FC,count=250,vt=0xA91F44},
 post={off=0x24C,count=60,vt=0xA93A30},
 tactic={off=0x26C,count=72,vt=0xA931A8},
 technology={off=0x29C,count=85,vt=0xA929C8},
 town={off=0x2CC,count=364,vt=0xA939A8},
 culture={off=0x2EC,count=32,vt=0xA9054C}}
function K.base() return getAddressSafe(K.EXE) end
function K.buildMatches()
 local m=K.base();local pe=m and u(m+0x3C)
 return m and pe and readSmallInteger(m)==0x5A4D and
  u(m+pe)==0x4550 and readSmallInteger(m+pe+4)==0x14C and
  u(m+pe+8)==K.BUILD.ts and u(m+pe+0x50)==K.BUILD.size
end
function K.attached()
 return K.pid~=nil and K.pid==getOpenedProcessID() and K.buildMatches()
end
function K.isType(kind,p)
 local t=K.types[kind];local m=K.base()
 return t and m and p and u(p)==m+t.vt or false
end
function K.root()
 if not K.attached() then return end
 local m=K.base();local getter=m+0x197AF0
 -- Validate the instruction supplying the global, not just a hard-coded pointer.
 if readBytes(getter,1)~=0xA1 or readBytes(getter+5,1)~=0xC3 then return end
 local r=u(u(getter+1))
 if r and u(r)==m+0xA92800 then return r end
end
function K.vector(kind)
 local t=K.types[kind];local r=K.root();if not t or not r then return end
 local b,e=u(r+t.off),u(r+t.off+4)
 if b and e and b&gt;=0x10000 and e-b==t.count*4 then return b,t.count end
end
function K.object(kind,index)
 local b,n=K.vector(kind)
 if not b or type(index)~='number' or index%1~=0 or index&lt;0 or index&gt;=n then return end
 local p=u(b+index*4);if K.isType(kind,p) then return p end
end
function K.objects(kind)
 local b,n=K.vector(kind);local out={};if not b then return out end
 local bytes=readBytes(b,n*4,true);if not bytes then return out end
 for i=0,n-1 do
  local j=i*4+1;local p=bytes[j]|(bytes[j+1]&lt;&lt;8)|(bytes[j+2]&lt;&lt;16)|(bytes[j+3]&lt;&lt;24)
  if K.isType(kind,p) then out[#out+1]={id=i,p=p} end
 end
 return out
end
function K.indexOf(kind,p)
 if not K.isType(kind,p) then return end
 local b,n=K.vector(kind);if not b then return end
 local bytes=readBytes(b,n*4,true);if not bytes then return end
 for i=0,n-1 do
  local j=i*4+1;local value=bytes[j]|(bytes[j+1]&lt;&lt;8)|(bytes[j+2]&lt;&lt;16)|(bytes[j+3]&lt;&lt;24)
  if value==p then return i end
 end
end
function K.scenario()
 local r=K.root();local s=r and u(r+0x30C)
 if s and u(s)==K.base()+0xA93A80 then return s end
end
function K.force()
 local s=K.scenario();local p=s and u(s+0x220)
 if K.isType('force',p) and K.indexOf('force',p) then return p end
end
function K.clan()
 local f=K.force();local p=f and u(f+8)
 if K.isType('clan',p) and K.indexOf('clan',p) then return p end
end
function K.player()
 local c=K.clan();local p=c and u(c+0xBC)
 if K.isType('officer',p) and K.indexOf('officer',p) then return p end
end
function K.homeCity()
 local lord=K.player();local city
 if lord then
  local tag,where=u(lord+0x180),u(lord+0x178)
  if tag==3 then city=where
  elseif tag==4 and K.isType('army',where) then city=u(where+0x70)
  elseif tag==5 then
   local node=u(lord+0x17C)
   if where and node and node~=u(where+4) then
    local command=u(node+0x10)
    if command and command&gt;=0x10000 then city=u(command+0x20) end
   end
  end
 end
 if K.isType('city',city) then return city end
 -- The scenario slot is the selected base; use it only as an owned-base fallback.
 local scenario=K.scenario();city=scenario and u(scenario+0x228)
 if K.isType('city',city) and K.ownsForce(u(city+0x108)) then return city end
 for _,item in ipairs(K.objects('city')) do if K.ownsForce(u(item.p+0x108)) then return item.p end end
end
function K.ownsForce(p)
 local c=K.clan()
 return c and K.isType('force',p) and u(p+8)==c or false
end
function K.name(kind,p)
 if not K.isType(kind,p) then return '' end
 if kind=='city' then p=u(p+0x104);if not K.isType('cityName',p) then return '' end end
 local function text(off,len)
  local s=readString(p+off,len,false);return s and ansiToUtf8(s) or ''
 end
 if kind=='officer' then return text(4,11)..text(15,11) end
 return text(4,kind=='treasure' and 15 or 12)
end
function K.townName(p)
 if not K.isType('town',p) then return '' end
 local building=u(p+4)
 if not K.isType('building',building) then return '' end
 return K.name('buildingDef',u(building+4))
end
function K.key()
 local r,s,f=K.root(),K.scenario(),K.force()
 local o,c=K.vector('officer'),K.vector('city')
 local clan,lord=K.clan(),K.player()
 if r and s and f and o and c and clan and lord then return ('%X:%X:%X:%X:%X:%X:%X'):format(r,s,f,o,c,clan,lord) end
end
function K.ready()
 assert(K.attached(),NB.T('Attach to Tendou PK first.','先に天道PKへアタッチしてください。'))
 assert(K.key(),NB.T('Load a game first.','先にプレイ中のゲームをロードしてください。'))
end
function K.selected(kind)
 return kind=='player' and K.player() or K.object(kind,K.sel[kind])
end
K.fields={officer={
 {'Leadership (base)','統率（基本値）',0x1B8,1,120},
 {'Valor (base)','武勇（基本値）',0x1BC,1,120},
 {'Intellect (base)','知略（基本値）',0x1C0,1,120},
 {'Politics (base)','政治（基本値）',0x1C4,1,120},
 {'Loyalty','忠誠',0x1D0,0,100},
 {'Honor / obligation','義理',0x1CC,0,100},
 {'Merit','勲功',0x1B4,0,999},
 {'Stipend','俸禄',0x1D4,0,5000},
 {'Injury','傷病',0x190,0,2,'self',false,'0:Healthy / 健康\n1:Light injury / 軽傷\n2:Serious injury / 重傷'},
 {'Birth year','生年',0x1A4,1,9999},
 {'Appearance year','登場年',0x1A8,1,9999},
 {'Death year','死亡年',0x1AC,1,9999},
 {'Compatibility','相性',0x1A0,0,99}},
 city={
 {'Money (shared by district)','金銭（軍団共有）',0x48,0,10000000,'force'},
 {'Rice (shared by district)','兵糧（軍団共有）',0x4C,0,10000000,'force'},
 {'Soldiers','兵士',0x28,0,500000},
 {'Wounded soldiers','負傷兵',0x2C,0,500000,'self',false},
 {'Horses','軍馬',0x34,0,500000},
 {'Guns','鉄砲',0x38,0,500000},
 {'Battering rams','破城槌',0x3C,0,1000},
 {'Siege towers','攻城櫓',0x40,0,1000},
 {'Cannons','大筒',0x44,0,1000},
 {'Morale','士気',0x48,0,100},
 {'Spirit','闘志',0x4C,0,1000,'self',false},
 {'Castle durability','城郭耐久',0xC,0,40000,'castle'}},
 town={{'Popular loyalty','民忠',0x3C,0,100}}}
function K.target(kind,index,field)
 local p=kind=='player' and K.player() or K.object(kind,index)
 if not p then return end
 if field[6]=='force' then p=u(p+0x108);if not K.isType('force',p) then return end end
 if field[6]=='castle' then p=u(p+0x110);if not K.isType('building',p) then return end end
 return p+field[3]
end
-- Aptitudes are recalculated by 4FEB60 from 164..174 into 150..160.
-- A caller changing these must execute the native recalculation on the game thread.
K.nativeDefinitions={
 officerRecalculate={rva=0xFEB60,bytes='53 55 56 8B F1 8D 86 E4 01 00 00'},
 clanCreditSet={rva=0x122FC0,bytes='83 EC 08 8B 44 24 0C 89 04 24 3D 78 EC FF FF'},
 clanRecalculate={rva=0x122C30,bytes='83 EC 64 53 8B D9 8B 83 CC 00 00 00'},
 windowProc={rva=0x2B2070,bytes='8B 44 24 08 3D 81 02 00 00'}}

end

do
-- N13-only game-window-thread dispatcher. No remote-thread game method calls.
local K=NB.K13
K.nativeSymbol=('nb13Native_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
function K.nativeAddress(name)
 local d=assert(K.nativeDefinitions[name],'Unknown N13 operation: '..tostring(name))
 assert(K.attached(),'Tendou is not attached')
 local expected={};for h in d.bytes:gmatch('%x%x') do expected[#expected+1]=tonumber(h,16) end
 local at=K.base()+d.rva;local actual=readBytes(at,#expected,true)
 assert(actual and #actual==#expected,'Unreadable N13 operation: '..name)
 local patch=d.patch and K.patches and K.patches[d.patch]
 for i,b in ipairs(expected) do
  local wanted=patch and patch.installed[i] or b
  assert(actual[i]==wanted,'N13 operation code mismatch: '..name)
 end
 return at
end
function K.nativeBusy()
 local n=K.native
 if not n or not K.attached() or n.pid~=K.pid then return false end
 local state=readInteger(n.q)
 return state==1 or state==2
end
function K.assertNativeIdle()
 assert(not K.nativeBusy(),NB.T('The previous game operation is still running.','ゲーム側の処理が実行中です。完了までお待ちください。'))
end
function K.installNative()
 if K.native then return end
 K.ready();local at=K.nativeAddress('windowProc')
 local script=([[
[ENABLE]
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
label(done)
label(cancel)
label(stale)
label(command)
label(invoke)
@N@:
dd 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
@N@+100:
cmp dword ptr [esp+8],83C3
jne original
cmp dword ptr [esp+C],@N@
jne original
pushfd
pushad
cmp dword ptr [@N@],1
jne done
mov eax,[%X]
cmp eax,[@N@+20]
jne cancel
test eax,eax
jz cancel
mov edx,[eax+30C]
cmp edx,[@N@+24]
jne cancel
test edx,edx
jz cancel
mov edx,[edx+220]
cmp edx,[@N@+38]
jne cancel
// Resolve the current object from its vector on the game thread.
mov edx,[@N@+28]
mov edi,[eax+edx]
test edi,edi
jz stale
mov esi,[eax+edx+4]
sub esi,edi
cmp esi,[@N@+2C]
jne stale
mov ebx,[@N@+30]
shl ebx,2
cmp ebx,esi
jae stale
mov ecx,[edi+ebx]
mov edx,[@N@+34]
cmp [ecx],edx
jne stale
cmp dword ptr [@N@+3C],1
je command
cmp ecx,[@N@+8]
jne stale
jmp invoke
command:
cmp dword ptr [ecx+188],7
jne stale
cmp dword ptr [ecx+180],5
jne stale
mov eax,[ecx+178]
cmp eax,10000
jb stale
mov edx,[ecx+17C]
cmp edx,10000
jb stale
cmp edx,[eax+4]
je stale
mov ecx,[edx+10]
cmp ecx,[@N@+8]
jne stale
mov edx,[@N@+40]
cmp [ecx],edx
jne stale
cmp dword ptr [ecx+C],0
jle stale
cmp byte ptr [ecx+31],0
jne stale
mov eax,[ecx+1C]
cmp eax,10000
jb stale
cmp dword ptr [eax],NOBU13PK.exe+A91E38
jne stale
mov eax,[eax+8]
cmp eax,[@N@+44]
jne stale
invoke:
mov dword ptr [@N@],2
mov ebp,esp
push [@N@+18]
push [@N@+14]
push [@N@+10]
push [@N@+C]
call dword ptr [@N@+4]
mov esp,ebp
mov [@N@+1C],eax
mov dword ptr [@N@],3
jmp done
cancel:
mov dword ptr [@N@],4
jmp done
stale:
mov dword ptr [@N@],5
done:
popad
popfd
xor eax,eax
ret 10
original:
mov eax,[esp+8]
cmp eax,281
jmp %X
%X:
jmp @N@+100
nop 4
[DISABLE]
%X:
db 8B 44 24 08 3D 81 02 00 00
unregistersymbol(@N@)
dealloc(@N@)
]]):format(at,readInteger(K.base()+0x197AF1),at+9,at,at)
 script=script:gsub('@N@',K.nativeSymbol)
 local ok,info=autoAssemble(script);assert(ok,tostring(info))
 K.native={q=assert(getAddressSafe(K.nativeSymbol)),script=script,info=info,pid=K.pid,
  buffer=assert(allocateSharedMemoryLocal(K.nativeSymbol..'_local',4096))}
end
function K.nativeCall(name,kind,index,...)
 K.ready();local d=assert(K.nativeDefinitions[name]);assert(d.kind==kind,'N13 native target type mismatch')
 local order=kind=='command' and K.commandForOfficer(index) or nil
 local this=kind=='command' and order and order.p or K.object(kind,index)
 assert(this,'N13 native object unavailable')
 if order then assert(d.commandVT==readInteger(this)-K.base(),'Unexpected N13 command class') end
 local fn=K.nativeAddress(name);K.installNative();K.assertNativeIdle()
 local n=K.native;local q=n.q;local t=assert(K.types[order and 'officer' or kind]);local args={...}
 assert(#args&lt;=4,'Too many native arguments')
 writeInteger(q+4,fn);writeInteger(q+8,this)
 for i=1,4 do writeInteger(q+8+i*4,args[i] or 0) end
 writeInteger(q+0x20,K.root());writeInteger(q+0x24,K.scenario())
 writeInteger(q+0x28,t.off);writeInteger(q+0x2C,t.count*4)
 writeInteger(q+0x30,index);writeInteger(q+0x34,K.base()+t.vt)
 writeInteger(q+0x38,K.force())
 writeInteger(q+0x3C,order and 1 or 0);writeInteger(q+0x40,order and readInteger(this) or 0)
 writeInteger(q+0x44,order and K.clan() or 0)
 writeInteger(q,1)
 local w=executeCodeLocalEx('user32.GetTopWindow',0);local sent=0
 for _=1,10000 do
  if not w or w==0 then break end
  if getWindowProcessID(w)==K.pid and executeCodeLocalEx('user32.IsWindowVisible',w)~=0 then
   executeCodeLocalEx('user32.SendMessageTimeoutW',w,0x83C3,q,0,2,2000,n.buffer);sent=sent+1
   if readInteger(q)~=1 then break end
  end
  w=getWindow(w,2)
 end
 local state=readInteger(q)
 -- Pending operations must retain their code and data after timeout.
 assert(state==3,('N13 game operation did not complete (%s; state %s; windows %d)'):format(name,tostring(state),sent))
 return readInteger(q+0x1C)
end
function K.removeNative()
 local n=K.native;if not n then return end
 K.assertNativeIdle()
 if n.pid==getOpenedProcessID() and K.buildMatches() then
  assert(autoAssemble(n.script,n.info),'Cannot restore N13 window dispatcher')
 end
 K.native=nil
end
for name,kind in pairs({officerRecalculate='officer',
 clanCreditSet='clan',clanRecalculate='clan'}) do K.nativeDefinitions[name].kind=kind end

-- Native lifecycle entry points traced through in-game award/acquisition callers.
K.nativeDefinitions.treasureToOfficer={rva=0x158FD0,kind='officer',bytes='56 8B 74 24 0C 57 56 E8 74 A9 FF FF 8B 7C 24 10'}
K.nativeDefinitions.technologyAcquire={rva=0x1784B0,kind='clan',bytes='56 8B 74 24 08 56 E8 A5 73 FB FF 83 C4 04 84 C0'}
K.nativeDefinitions.rankAward={rva=0x165E50,kind='officer',bytes='53 56 8B 74 24 0C 33 DB 85 F6 57 8B 7C 24 14 0F'}
K.nativeDefinitions.rankClear={rva=0x165700,kind='officer',bytes='8B 4C 24 04 56 8B B1 3C 01 00 00 85 F6 74 3D 57'}
K.nativeDefinitions.rankToClan={rva=0x164A40,kind='clan',bytes='56 8B 74 24 0C 57 56 E8 84 EF FE FF 8B 7C 24 10'}
K.nativeDefinitions.buildingDurabilitySet={rva=0xFAF40,kind='building',bytes='83 EC 0C 56 57 8B F1 E8 04 FF FF FF 85 C0 8B 7C'}
K.nativeDefinitions.buildingOwner={rva=0xFA930,kind='building',bytes='56 8B F1 8B 4E 04 85 C9 74 2C E8 E1 7A 03 00 84'}
K.nativeDefinitions.officerTroopCap={rva=0xFEA80,kind='officer',bytes='83 EC 08 53 56 8B F1 8B 86 90 01 00 00 0F B6 8E'}
K.nativeDefinitions.battleDamage={rva=0x136940,kind='army',bytes='8B 44 24 04 85 C0 7D 06 33 C0 89 44 24 04 39 41',patch='battle_soldierDamage'}
K.nativeDefinitions.battleMoraleSet={rva=0x111800,kind='army',bytes='83 EC 08 8B 44 24 0C 89 04 24 85 C0 C7 44 24 0C',patch='battle_moraleSet'}
K.nativeDefinitions.battleSpiritSet={rva=0x1368C0,kind='army',bytes='83 EC 08 56 8B F1 8B 06 8B 90 F8 00 00 00 FF D2',patch='battle_spiritSet'}
K.nativeDefinitions.postAward={rva=0x163490,kind='officer',bytes='51 53 55 56 8B 74 24 14 57 8B CE E8 C0 A8 F9 FF'}
K.nativeDefinitions.postClear={rva=0x153A50,kind='officer',bytes='56 8B 74 24 08 8B CE E8 34 6F 0D 00 85 C0 74 10'}
K.nativeDefinitions.tacticSet={rva=0x101790,kind='officer',bytes='53 56 8D B1 14 01 00 00 57 8B CE E8 00 30 F4 FF'}

K.nativeDefinitions.courtContributionSet={rva=0x120960,kind='clan',bytes='83 EC 08 8B 44 24 0C 89 04 24 85 C0 C7 44 24 0C'}

K.nativeDefinitions.castleUpgrade={rva=0x1787B0,kind='city',bytes='6A FF 68 10 C2 DB 00 64 A1 00 00 00 00 50 83 EC'}

K.nativeDefinitions.cultureAcquire={rva=0x1784F0,kind='clan',bytes='56 8B 74 24 08 57 56 E8 64 73 FB FF 8B 7C 24 14'}

end

do
local K=NB.K13
local u=K.u
function K.listItems(head,max)
 local out={};local sentinel=u(head+4);local count=u(head+8)
 if not sentinel or not count or count&gt;max then return end
 local node=u(sentinel);local visited={}
 while node~=sentinel do
  if not node or visited[node] or #out&gt;=count then return end
  visited[node]=true;local p=u(node+8);if not p then return end
  out[#out+1]=p;node=u(node)
 end
 if #out==count then return out end
end
function K.hasTechnology(id)
 local c=K.clan();local p=K.object('technology',id)
 if not c or not p then return end
 local list=K.listItems(c+0x28,85);if not list then return end
 for _,owned in ipairs(list) do if owned==p then return true end end
 return false
end
function K.acquireAllTechnology()
 K.ready();local token=K.key();local count=0;local ci=assert(K.indexOf('clan',K.clan()))
 for _,item in ipairs(K.objects('technology')) do
  assert(K.key()==token,'Game data changed')
  local owned=K.hasTechnology(item.id);assert(owned~=nil,'Technology list layout mismatch')
  if not owned then
   K.nativeCall('technologyAcquire','clan',ci,K.clan(),item.p,1)
   assert(K.hasTechnology(item.id),'Technology acquisition did not complete');count=count+1
  end
 end
 NB.msg(('Technologies acquired: %d.'):format(count),('技術を%d件取得しました。'):format(count))
end
function K.writeFame(value)
 K.ready();local c=assert(K.clan());local ci=assert(K.indexOf('clan',c))
 K.nativeCall('clanRecalculate','clan',ci)
 local credit=u(c+0xCC);if credit&gt;=0x80000000 then credit=credit-0x100000000 end
 local contribution=u(c+0xD0)-credit
 local desired=math.max(-5000,math.min(5000,math.floor(value-contribution)))
 K.nativeCall('clanCreditSet','clan',ci,desired)
 return u(c+0xD0)
end
function K.awardRank(kind,index,rankID)
 K.ready();local p=kind=='player' and K.player() or K.object('officer',index)
 local oi=assert(K.indexOf('officer',p),'Officer unavailable')
 local rank=rankID==-1 and 0 or assert(K.object('rank',rankID),'Rank unavailable')
 if rank==0 then K.nativeCall('rankClear','officer',oi,p);return end
 local name=K.name('rank',rank);assert(name~='','Empty rank')
 -- The full native award releases previous ownership, updates the officer,
 -- assigns the new rank and processes associated clan effects.
 if u(p+0x13C)==rank then return end
 K.nativeCall('rankClear','officer',oi,p)
 K.nativeCall('rankAward','officer',oi,p,rank)
 assert(u(p+0x13C)==rank,'Rank award did not apply to this officer')
 local force=u(p+0x144);local clan=K.isType('force',force) and u(force+8)
 if K.isType('clan',clan) and u(clan+0xBC)==p then
  local ci=assert(K.indexOf('clan',clan));local grade=u(rank+0x38)
  for _,item in ipairs(K.objects('rank')) do
   -- Native validity predicate 53D1A0 rejects grade -1; empty slots must
   -- not be awarded. Respect both officer and clan ownership fields.
   local g=u(item.p+0x38)
   if g and g~=0xFFFFFFFF and g&lt;grade and K.name('rank',item.p)~='' and
    u(item.p+0x30)==0 and u(item.p+0x34)==0 then
    K.nativeCall('rankToClan','clan',ci,clan,item.p)
   end
  end
 end
end
function K.assignTreasure()
 K.ready();local token=K.key();local all=K.objects('treasure');local cats={};local ids={}
 for _,item in ipairs(all) do
  local flags=readBytes(item.p+0xE4,1);local category=u(item.p+0xE0)
  if flags and (flags&amp;3)~=2 and K.name('treasure',item.p)~='' and category and category&lt;36 then cats[category]=true end
 end
 for id in pairs(cats) do ids[#ids+1]=id end;table.sort(ids)
 local labels={}
 local english={'Tea caddies','Tea jars','Tea kettles','Tea bowls','Flower vases','Tea scoops','Incense burners','Water jars','Swords','Spears','Horses','Bows','Matchlock guns','Percussion guns','Pistols','Cannons','Armor','Helmets','War banners','Swordsmanship books','Horsemanship books','Archery books','Gunnery books','Ninjutsu books','Naval books','Architecture books','Agriculture books','Commerce books','Knowledge books','Strategy books','War chronicles','Medical books','Ink paintings','Color paintings','Sweets','Incense wood'}
 for _,id in ipairs(ids) do
  local ptr=u(K.base()+0xC47AD0+id*4)
  local text=ptr and readString(ptr,80,false)
  assert(text,'Unreadable treasure category')
  labels[#labels+1]=NB.T(english[id+1],ansiToUtf8(text))
 end
 local categoryChoice,remember,recipient={},{},{}
 while true do
  local chosen,action=NB.chooseTreasureList(NB.T('Treasure category','家宝の分類'),labels,false,false,categoryChoice)
  if action~='next' then return end;categoryChoice=chosen;local category=ids[chosen[1]]
  local items,names={},{}
  for _,item in ipairs(all) do
   if u(item.p+0xE0)==category and (readBytes(item.p+0xE4,1)&amp;3)~=2 and K.name('treasure',item.p)~='' then
    items[#items+1]=item;names[#names+1]=K.name('treasure',item.p)
   end
  end
  while true do
   local selected,nav=NB.chooseTreasureList(NB.T('Select treasures','家宝を複数選択'),names,true,true,remember[category])
   remember[category]=selected
   if nav=='cancel' then return end;if nav=='back' then break end
   local officers,onames={},{}
   for _,item in ipairs(K.objects('officer')) do
    if u(item.p+0x188)==7 and K.ownsForce(u(item.p+0x144)) then
     officers[#officers+1]=item;onames[#onames+1]=K.name('officer',item.p)
    end
   end
   local target,step=NB.chooseTreasureList(NB.T('Recipient officer','授与先の武将'),onames,false,true,recipient,NB.T('Assign','授与'))
   recipient=target;if step=='cancel' then return end
   if step=='next' then
    local officer=officers[target[1]];local count=0
    for _,n in ipairs(selected) do
     K.ready();assert(K.key()==token,'Game data changed; reopen the treasure list')
     assert(K.ownsForce(u(officer.p+0x144)),'Recipient is no longer in your clan')
     K.nativeCall('treasureToOfficer','officer',officer.id,officer.p,items[n].p)
     assert(u(items[n].p+0xD4)==officer.p,'Treasure ownership did not change');count=count+1
    end
    NB.msg(('Assigned %d treasures.'):format(count),('家宝を%d件授与しました。'):format(count));return
   end
  end
 end
end

function K.hasCulture(id)
 local wanted=K.object('culture',id);local clan=K.clan()
 if not wanted or not clan then return false end
 local list=K.listItems(clan+0x140,32);if not list then return end
 for _,ptr in ipairs(list) do if ptr==wanted then return true end end
 return false
end
function K.acquireAllCulture()
 K.ready();local token=K.key();local clan=assert(K.clan());local ci=assert(K.indexOf('clan',clan));local count=0
 for _,item in ipairs(K.objects('culture')) do
  local owned=K.hasCulture(item.id);assert(owned~=nil,'Culture list layout mismatch')
  if not owned then
   assert(K.key()==token,'Game data changed')
   K.nativeCall('cultureAcquire','clan',ci,clan,item.p,1)
   assert(K.hasCulture(item.id),'Culture acquisition did not apply');count=count+1
  end
 end
 NB.msg(('Acquired %d cultures.'):format(count),('文化を%d件取得しました。'):format(count))
end

end

do
local K=NB.K13
local u=K.u
local function bytes(v) return {v&amp;255,(v&gt;&gt;8)&amp;255,(v&gt;&gt;16)&amp;255,(v&gt;&gt;24)&amp;255} end
local function signed(v) return v&gt;=0x80000000 and v-0x100000000 or v end
local aptitudeNames={{'Infantry','足軽'},{'Cavalry','騎馬'},{'Bows','弓'},{'Guns','鉄砲'},{'Siege engines','兵器'}}
for i,n in ipairs(aptitudeNames) do
 K.fields.officer[#K.fields.officer+1]={n[1]..' aptitude (base)',n[2]..'適性（基本値）',0x164+(i-1)*4,0,4,'aptitude',false,'0:D\n1:C\n2:B\n3:A\n4:S'}
end
K.fields.officer[#K.fields.officer+1]={'Court rank','官位',0x13C,-1,249,'rank',false}
K.clanFields={
 {'Fame (shared by clan)','名声（勢力共有）',0xD0,0,5000,'clan'},
 {'Credit (fame modifier)','信用（名声の補正値）',0xCC,-5000,5000,'clan'}}
local target=K.target
function K.target(kind,index,field)
 if field[6]=='clan' then local p=K.clan();return p and p+field[3] end
 return target(kind,index,field)
end
function K.refreshSuffix()
 for _,entry in ipairs({{102,'player'},{403,'officer'},{303,'city'}}) do
  local p=K.selected(entry[2]);NB.suffix[entry[1]]=p and K.name(entry[2]=='player' and 'officer' or entry[2],p) or NB.T('(not selected)','（未選択）')
 end
 NB.applyLang()
end
function K.closeEditor(mr)
 K.editors[mr.ID]=nil;NB.clearChildren(mr)
end
function K.clearEditors()
 local old=K.editors;K.editors={}
 for _,e in pairs(old) do e.mr.Active=false;NB.clearChildren(e.mr) end
end
function K.addField(parent,kind,index,f)
 local token=K.key();local at=K.target(kind,index,f);if not at then return end
 K.typeSerial=(K.typeSerial or 0)+1
 local typeName=('NB13_%X_%X_%d'):format(K.pid,getTickCount(),K.typeSerial)
 local function fromBytes(a,b,c,d)
  local v=a|(b&lt;&lt;8)|(c&lt;&lt;16)|(d&lt;&lt;24)
  if f[6]=='rank' or f[6]=='post' then return v==0 and -1 or K.indexOf(f[6],v) or -1 end
  if f[6]=='bit' then return (v&amp;f[9])~=0 and 1 or 0 end
  return f[4]&lt;0 and signed(v) or v
 end
 local function toBytes(value)
  local current=K.target(kind,index,f)
  -- Never let a stale editor/frozen record write into a newly loaded scenario.
  if K.key()~=token or current~=at then return current and readBytes(current,4,true) or {0,0,0,0} end
  local v=tonumber(value);if not v or v~=v or math.abs(v)==math.huge then return readBytes(at,4,true) end
  v=math.max(f[4],math.min(f[5],math.floor(v)))
  local ok,result=pcall(function()
   if f[6]=='rank' then
    K.awardRank(kind,index,v);return u(at)
   elseif f[6]=='post' then
    K.awardPost(kind,index,v);return u(at)
   elseif f[6]=='bit' then
    return (u(at)&amp;(~f[9]))|(v~=0 and f[9] or 0)
   elseif f[6]=='aptitude' then
    writeInteger(at,v)
    local p=K.selected(kind);local oi=assert(K.indexOf('officer',p))
    K.nativeCall('officerRecalculate','officer',oi);return u(at)
   elseif f[6]=='clan' then
    if f[3]==0xD0 then return K.writeFame(v) end
    if f[3]==0x150 then K.nativeCall('courtContributionSet','clan',assert(K.indexOf('clan',K.clan())),v);return u(at) end
    K.nativeCall('clanCreditSet','clan',assert(K.indexOf('clan',K.clan())),v)
    return u(at)
   elseif f[6]=='castle' then
    local city=assert(K.object('city',index));local building=assert(u(city+0x110))
    K.nativeCall('buildingDurabilitySet','building',assert(K.indexOf('building',building)),v)
    return u(at)
   end
   return v
  end)
  if not ok then NB.msg(tostring(result):gsub('^.-:%d+: ',''));return readBytes(at,4,true) end
  return bytes(result)
 end
 registerCustomTypeLua(typeName,4,fromBytes,toBytes,false,false)
 local address=('%s+%X'):format(K.EXE,u(K.base()+0x197AF1)-K.base())
 local row=NB.addRec(parent,f[1],f[2],address,vtCustom)
 local offsets
 if f[6]=='clan' then offsets={f[3],8,0x220,0x30C}
 elseif f[6]=='force' then offsets={f[3],0x108,index*4,0x17C}
 elseif f[6]=='castle' then offsets={f[3],0x110,index*4,0x17C}
 elseif kind=='player' then offsets={f[3],0xBC,8,0x220,0x30C}
 else offsets={f[3],index*4,K.types[kind].off} end
 row.OffsetCount=#offsets;for i,v in ipairs(offsets) do row.Offset[i-1]=v end
 row.CustomTypeName=typeName
 local dropdown=f[8]
 if f[6]=='rank' or f[6]=='post' then
  local names={'-1:'..NB.T('None','なし')}
  for _,item in ipairs(K.objects(f[6])) do
   local name=K.name(f[6],item.p)
   if name~='' and (f[6]~='rank' or u(item.p+0x38)~=0xFFFFFFFF) then names[#names+1]=item.id..':'..name end
  end
  dropdown=table.concat(names,'\n')
 end
 if dropdown and dropdown:sub(1,6)=='@enum:' then
  local rva,count=dropdown:match('^@enum:(%x+):(%d+)$');assert(rva and count,'Invalid N13 enum descriptor')
  local names={}
  for i=0,tonumber(count)-1 do
   local address=u(K.base()+tonumber(rva,16)+i*4);local text=address and readString(address,80,false)
   assert(text,'N13 enum label is unreadable');names[#names+1]=i..':'..ansiToUtf8(text)
  end
  dropdown=table.concat(names,'\n')
 end
 if dropdown then row.DropDownList.Text=dropdown;row.DropDownReadOnly=true;row.DropDownDescriptionOnly=true;row.DisplayAsDropDownListItem=true end
 row.OnActivate=function(_,before) if before then return K.key()==token and K.target(kind,index,f)==at and f[6]~='rank' and f[6]~='post' and f[6]~='clan' and f[6]~='aptitude' end;return true end
 return row
end
function K.openEditor(mr,kind)
 K.ready();K.closeEditor(mr)
 local p=K.selected(kind)
 if not p then NB.msg('Select an officer/city first.','先に武将・都市を選択してください。');return end
 for _,f in ipairs(K.fields[kind=='player' and 'officer' or kind]) do K.addField(mr,kind,K.sel[kind],f) end
 if kind=='player' then
  for _,f in ipairs(K.clanFields) do K.addField(mr,kind,nil,f) end
 elseif kind=='city' then
  for _,town in ipairs(K.objects('town')) do
   if u(town.p+8)==p then
    local group=getAddressList().createMemoryRecord();group.IsGroupHeader=true
    local name=K.townName and K.townName(town.p) or ('#'..town.id)
    group.Description=NB.T('Town: ','町：')..name;group.appendToEntry(mr)
    for _,f in ipairs(K.fields.town) do K.addField(group,'town',town.id,f) end
    group.Collapsed=true
   end
  end
 end
 K.editors[mr.ID]={mr=mr,kind=kind};mr.Collapsed=false;K.refreshSuffix()
end
function K.select(kind,index)
 K.ready();assert(K.object(kind,index),'Selection unavailable')
 local reopen={};for _,e in pairs(K.editors) do if e.kind==kind then reopen[#reopen+1]=e.mr end end
 for _,mr in ipairs(reopen) do K.closeEditor(mr) end
 K.sel[kind]=index
 for _,mr in ipairs(reopen) do K.openEditor(mr,kind) end
 K.refreshSuffix()
end
function K.search(kind)
 K.ready()
 local q=inputQuery(NB.T('Search name','名前を検索'),NB.T('Part of name; blank lists all:','名前の一部を入力。空欄は全件表示：'),'')
 if q==nil then return end
 local ids,names={},{}
 for _,item in ipairs(K.objects(kind)) do
  local name=K.name(kind,item.p)
  if name~='' and name:find(q,1,true) then ids[#ids+1]=item.id;names[#names+1]=('%s [ID %d]'):format(name,item.id) end
 end
 if #ids==0 then NB.msg('Not found.','見つかりません。');return end
 local n=NB.pick(NB.T('Select result','候補を選択'),names)
 if n then K.select(kind,ids[n]) end
end

end

do
local K=NB.K13
K.patches={}
function K.patch(name,rva,expected,body,original)
 if K.patches[name] then return end
 K.ready();local at=K.base()+rva;local wanted={}
 for h in expected:gmatch('%x%x') do wanted[#wanted+1]=tonumber(h,16) end
 assert(#wanted&gt;=5,'N13 detour is too short')
 local actual=readBytes(at,#wanted,true)
 assert(actual and table.concat(actual,',')==table.concat(wanted,','),'N13 code mismatch: '..name)
 local symbol=K.nativeSymbol..'_'..name
 local script=('[ENABLE]\nalloc(%s,2048,%X)\nregistersymbol(%s)\n%s:\n%s\n%s\njmp %X\n%X:\njmp %s\n'):format(symbol,at,symbol,symbol,body,original or ('db '..expected),at+#wanted,at,symbol)
 if #wanted&gt;5 then script=script..('nop %d\n'):format(#wanted-5) end
 script=script..('[DISABLE]\n%X:\ndb %s\nunregistersymbol(%s)\ndealloc(%s)\n'):format(at,expected,symbol,symbol)
 local ok,info=autoAssemble(script);assert(ok,tostring(info))
 K.patches[name]={script=script,info=info,pid=K.pid,at=at,installed=readBytes(at,#wanted,true)}
end
function K.removePatch(name)
 local p=K.patches[name];if not p then return end
 K.assertNativeIdle()
 if p.pid==getOpenedProcessID() and K.buildMatches() then
  local actual=readBytes(p.at,#p.installed,true)
  assert(actual and table.concat(actual,',')==table.concat(p.installed,','),'N13 patch ownership changed: '..name)
  assert(autoAssemble(p.script,p.info),'Cannot restore N13 patch: '..name)
 end
 K.patches[name]=nil
end
function K.removePatches()
 local names={};for name in pairs(K.patches) do names[#names+1]=name end
 table.sort(names);for _,name in ipairs(names) do K.removePatch(name) end
end

end

do
-- Command type IDs decoded from virtual +20 and the native UI label table AE1490.
local K=NB.K13
K.commandClasses={
 immobilize={vt=0xA93B90,id=14,label='足止',update=0x11A750,tick=0x271080,finish=0x271010},
 mediation={vt=0xA93C00,id=29,label='斡旋',update=0x11A750,tick=0x2722D0,finish=0x271CF0},
 trade={vt=0xA93C78,id=4,label='売買',update=0x11A750,tick=0x272F00,finish=0x272A10},
 recruitSoldiers={vt=0xA93CE8,id=5,label='募兵',update=0x11A750,tick=0x2746B0,finish=0x273F00},
 produceHorses={vt=0xA93D60,id=6,label='生産',update=0x11A750,tick=0x274B30,finish=0x274A10},
 courtEnemy={vt=0xA93DD0,id=33,label='朝敵',update=0x11A750,tick=0x2754C0,finish=0x2750F0},
 alliance={vt=0xA93E40,id=17,label='同盟',update=0x11A750,tick=0x276E40,finish=0x276470},
 extendAlliance={vt=0xA93EB0,id=18,label='延長',update=0x11A750,tick=0x277850,finish=0x277790},
 breakAlliance={vt=0xA93F20,id=19,label='破棄',update=0x11A750,tick=0x2781F0,finish=0x277F80},
 returnCaptives={vt=0xA93F90,id=22,label='返還',update=0x11A750,tick=0x279050,finish=0x2789E0},
 poaching={vt=0xA94000,id=12,label='引抜',update=0x11A750,tick=0x279910,finish=0x279840},
 moving={vt=0xA94070,id=11,label='移動',update=0x11A750,tick=0x27A3E0,finish=0x27A350},
 request={vt=0xA940E0,id=25,label='依頼',update=0x11A750,tick=0x27ABD0,finish=0x27AF30},
 remodeling={vt=0xA94150,id=1,label='改築',update=0x11A750,tick=0x27C170,finish=0x27BF10},
 development={vt=0xA941C0,id=0,label='開発',update=0x11A750,tick=0x27CAF0,finish=0x27CEE0},
 submission={vt=0xA94230,id=23,label='勧告',update=0x11A750,tick=0x27D350,finish=0x27D290},
 donation={vt=0xA942A0,id=28,label='献上',update=0x11A750,tick=0x27D910,finish=0x27D920},
 research={vt=0xA94310,id=3,label='研究',update=0x11A750,tick=0x27E6B0,finish=0x27DB30},
 returning={vt=0xA94380,id=10,label='帰還',update=0x11A750,tick=0x27E9E0,finish=0x27E840},
 ambush={vt=0xA943F0,id=15,label='奇襲',update=0x11A750,tick=0x27F090,finish=0x27F080},
 training={vt=0xA94460,id=27,label='教練',update=0x11A750,tick=0x283700,finish=0x280D80},
 pact={vt=0xA944D0,id=24,label='盟約',update=0x11A750,tick=0x2839B0,finish=0x2837A0},
 intercession={vt=0xA94540,id=31,label='仲立',update=0x11A750,tick=0x2844E0,finish=0x2841F0},
 produceWeapons={vt=0xA945B0,id=7,label='生産',update=0x11A750,tick=0x284C40,finish=0x284B70},
 incitement={vt=0xA94620,id=13,label='扇動',update=0x11A750,tick=0x285770,finish=0x285190},
 culture={vt=0xA94690,id=26,label='振興',update=0x11A750,tick=0x2864C0,finish=0x286070},
 invitation={vt=0xA94700,id=30,label='招待',update=0x11A750,tick=0x2868E0,finish=0x286A80},
 repairs={vt=0xA94770,id=2,label='修復',update=0x11A750,tick=0x287110,finish=0x286E20},
 rally={vt=0xA947E0,id=16,label='収拾',update=0x11A750,tick=0x2878E0,finish=0x287570},
 exploration={vt=0xA94850,id=8,label='探索',update=0x11A750,tick=0x288080,finish=0x287C90},
 ceasefire={vt=0xA948C0,id=21,label='停戦',update=0x11A750,tick=0x289460,finish=0x2889C0},
 recruitment={vt=0xA94930,id=9,label='登用',update=0x11A750,tick=0x289D50,finish=0x289C50},
 reconciliation={vt=0xA949A0,id=32,label='和解',update=0x11A750,tick=0x28A3E0,finish=0x28A7C0},
 reinforcements={vt=0xA94A10,id=20,label='要請',update=0x11A750,tick=0x28AE00,finish=0x28AD90},
}

end

do
local K=NB.K13
local u=K.u
assert(K.commandClasses,'Load N13 command classes first')
function K.commandForOfficer(index)
 local officer=K.object('officer',index)
 if not officer or u(officer+0x188)~=7 or u(officer+0x180)~=5 then return end
 local owner,node=u(officer+0x178),u(officer+0x17C)
 if not owner or not node or node==u(owner+4) then return end
 local command=u(node+0x10)
 if not command or command&lt;0x10000 or not K.ownsForce(u(command+0x1C)) then return end
 local vt=u(command)
 for name,d in pairs(K.commandClasses) do
  if vt==K.base()+d.vt and u(command+0xC)&gt;0 and readBytes(command+0x31,1)==0 then
   return {p=command,officer=officer,index=index,kind=name,vt=vt}
  end
 end
end
function K.orders()
 local out,seen={},{}
 for _,officer in ipairs(K.objects('officer')) do
  if u(officer.p+0x188)==7 and K.ownsForce(u(officer.p+0x144)) then
   local order=K.commandForOfficer(officer.id)
   if order and not seen[order.p] then out[#out+1]=order;seen[order.p]=true end
  end
 end
 return out
end
function K.workEligibleAssembly(reg,kinds)
 -- Scope every bypass to this live scenario and the player's current clan.
 local m=K.base()
 local allowed={};for kind in pairs(kinds or K.instantKinds or {development=true}) do
  allowed[#allowed+1]=('cmp dword ptr [%s],%X\nje accepted'):format(reg,m+assert(K.commandClasses[kind]).vt)
 end
 table.sort(allowed)
 return ([=[
push eax
push edx
mov eax,[%X]
cmp eax,%X
jne no
cmp dword ptr [eax+30C],%X
jne no
%s
jmp no
accepted:
cmp byte ptr [%s+31],0
jne no
mov eax,[%s+1C]
cmp eax,10000
jb no
cmp dword ptr [eax],%X
jne no
mov eax,[eax+8]
cmp eax,%X
jne no
pop edx
pop eax
jmp yes
no:
pop edx
pop eax
jmp original
yes:
]=]):format(u(m+0x197AF1),assert(K.root()),assert(K.scenario()),table.concat(allowed,'\n'),reg,reg,m+K.types.force.vt,assert(K.clan()))
end
function K.installWorkPatches(kinds)
 kinds=kinds or {development=true}
 local keys={};for kind in pairs(kinds) do keys[#keys+1]=kind end;table.sort(keys)
 local key=K.key()..':'..table.concat(keys,',')
 if K.patches.workDays and K.instantPatchKey==key then return end
 if K.patches.workDays then
  local names={};for name in pairs(K.patches) do if name:sub(1,4)=='work' then names[#names+1]=name end end
  for _,name in ipairs(names) do K.removePatch(name) end
 end
 K.instantKinds=kinds;K.instantPatchKey=key
 local check=K.workEligibleAssembly('ecx')
 K.patch('workDays',0x11A300,'83 EC 08 56 8B F1',
  'label(no)\nlabel(yes)\nlabel(original)\nlabel(accepted)\n'..check..'xor eax,eax\nret\noriginal:')
 -- The command's phase gate precedes its remaining-days check. Preserve the
 -- native scheduler result for every command outside the eligible scope.
 local phases={development={0x27CB09,'E8 62 2B EB FF','esi'},remodeling={0x27C187,'E8 E4 34 EB FF','esi'},
  research={0x27E6C6,'E8 A5 0F EB FF','esi'},repairs={0x287126,'E8 45 85 EA FF','esi'},
  returning={0x27E9F6,'E8 75 0C EB FF','esi'},moving={0x27A41D,'E8 4E 52 EB FF','esi'},
  exploration={0x2880D2,'E8 99 75 EA FF','ebp'},culture={0x2864D6,'E8 95 91 EA FF','esi'}}
 for kind in pairs(kinds) do
  local d=assert(phases[kind],'Unsupported instant command: '..kind)
  K.patch('workPhase_'..kind,d[1],d[2],
   ('label(no)\nlabel(yes)\nlabel(original)\nlabel(accepted)\ncall %X\n'):format(K.base()+0x12F670)..
   K.workEligibleAssembly(d[3],{[kind]=true})..'mov eax,1\noriginal:','')
 end
 if kinds.development then
  K.patch('workAmount',0x27CC07,'E8 A4 41 F7 FF',
   ('label(no)\nlabel(yes)\nlabel(original)\nlabel(accepted)\ncall %X\n'):format(K.base()+0x1F0DB0)..
   K.workEligibleAssembly('esi',{development=true})..'mov eax,9C40\noriginal:','')
 end
 if kinds.research then
  K.patch('workResearchProgress',0x27E6F2,'E8 B9 F9 FF FF',
   ('label(no)\nlabel(yes)\nlabel(original)\nlabel(accepted)\ncall %X\n'):format(K.base()+0x27E0B0)..
   K.workEligibleAssembly('esi',{research=true})..'xor eax,eax\noriginal:','')
 end
 if kinds.culture then
  K.patch('workCultureProgress',0x28653F,'E8 AC FD FF FF',
   ('label(no)\nlabel(yes)\nlabel(original)\nlabel(accepted)\ncall %X\n'):format(K.base()+0x2862F0)..
   K.workEligibleAssembly('esi',{culture=true})..'xor eax,eax\noriginal:','')
 end
 if kinds.repairs then
  K.patch('workRepairAmount',0x286E8E,'E8 8D 94 21 00',
   ('label(no)\nlabel(yes)\nlabel(original)\nlabel(accepted)\ncall %X\n'):format(K.base()+0x4A0320)..
   K.workEligibleAssembly('edi',{repairs=true})..'mov eax,9C40\noriginal:','')
 end
 if kinds.exploration then
  K.patch('workExplorationDate',0x2880FB,'E8 30 7E EA FF',
   ('label(no)\nlabel(yes)\nlabel(original)\nlabel(accepted)\ncall %X\n'):format(K.base()+0x12FF30)..
   K.workEligibleAssembly('ebp',{exploration=true})..'xor eax,eax\noriginal:','')
 end
end
function K.completeOrder(order,kinds)
 K.ready();assert(order and K.commandClasses[order.kind],'Expected a supported order')
 K.installWorkPatches(kinds or {[order.kind]=true})
 local steps=0
 while steps&lt;32 do
  local current=K.commandForOfficer(order.index)
  if not current or current.p~=order.p or current.kind~=order.kind then break end
  K.nativeCall(order.kind..'Update','command',order.index);steps=steps+1
 end
 return steps
end
for _,kind in ipairs({'development','remodeling','research','repairs','returning','moving','exploration','culture'}) do
 K.nativeDefinitions[kind..'Update']={kind='command',commandVT=K.commandClasses[kind].vt,rva=0x11A750,
  bytes='56 8B F1 8B 06 8B 50 20 FF D2 83 F8 0A'}
end
function K.removeWorkPatches()
 local names={};for name in pairs(K.patches) do if name:sub(1,4)=='work' then names[#names+1]=name end end
 for _,name in ipairs(names) do K.removePatch(name) end
 K.instantKinds=nil;K.instantPatchKey=nil
end
function K.finishInstantOrders()
 if K.nativeBusy() or not K.key() or K.key()~=K.snapshot then return end
 local wanted={}
 if K.on.instantDevelopment then wanted.development=true;wanted.remodeling=true;wanted.research=true;wanted.repairs=true;wanted.culture=true end
 if K.on.instantExploration then wanted.exploration=true end
 if K.on.actions then wanted.moving=true;wanted.returning=true end
 if not next(wanted) then if K.patches.workDays then K.removeWorkPatches() end;return end
 K.installWorkPatches(wanted)
 for _,order in ipairs(K.orders()) do
  if wanted[order.kind] and K.key()==K.snapshot then K.completeOrder(order,wanted) end
 end
end

end

do
local K=NB.K13
local u=K.u
function K.stopFeatures()
 K.assertNativeIdle();K.on={};K.clearEditors();K.snapshot=nil;K.sel={}
 if K.removePatches then K.removePatches() end
 if K.removeBattleFlags then K.removeBattleFlags() end
 K.removeNative()
end
function K.disconnect()
 K.assertNativeIdle();K.stopFeatures()
 if K.timer then K.timer.destroy();K.timer=nil end
 if K.life then executeCodeLocalEx('kernel32.CloseHandle',K.life);K.life=nil end
 K.pid=nil
end
function K.startData()
 K.snapshot=K.key()
 K.sel.officer=K.indexOf('officer',K.player());K.sel.city=K.indexOf('city',K.homeCity())
 K.refreshSuffix()
end
function K.tick()
 if K.nativeBusy() then return end
 local token=K.key()
 if token~=K.snapshot then
  K.stopFeatures();K.startData()
  for _,id in ipairs({101,201,202,208,206,207,304,404,602,604,701,702,703,705}) do
   local mr=getAddressList().getMemoryRecordByID(id);if mr then mr.Active=false end
  end
  return
 end
 if token then K.runFeatures() end
end
function K.feature(name,on)
 if not on then K.on[name]=nil;return end
 K.ready()
 assert(name=='cityMax' or name=='loyalty' or name=='instantDevelopment' or name=='instantExploration' or name=='actions','Unknown N13 feature: '..name)
 K.snapshot=K.key();K.on[name]=true;K.runFeatures()
end
function K.runFeatures()
 if not K.key() or K.key()~=K.snapshot then return end
 if K.on.loyalty then
  local leader=K.player()
  for _,item in ipairs(K.objects('officer')) do
   if item.p~=leader and u(item.p+0x188)==7 and K.ownsForce(u(item.p+0x144)) and u(item.p+0x1D0)~=100 then
    writeInteger(item.p+0x1D0,100)
   end
  end
 end
 if K.on.cityMax then
  for _,force in ipairs(K.objects('force')) do
   if K.ownsForce(force.p) then
    if u(force.p+0x48)~=99999 then writeInteger(force.p+0x48,99999) end
    if u(force.p+0x4C)~=99999 then writeInteger(force.p+0x4C,99999) end
   end
  end
  for _,city in ipairs(K.objects('city')) do
   if K.ownsForce(u(city.p+0x108)) then
    for _,field in ipairs(K.fields.city) do
     if field[7]~=false and field[6]~='force' then
      local at=K.target('city',city.id,field)
      if at then
       if field[6]=='castle' then
        local cap=u(city.p+0x154);local building=u(city.p+0x110)
        assert(cap and cap&gt;=0 and cap&lt;=40000,'Invalid castle durability cap')
        if u(at)~=cap then K.nativeCall('buildingDurabilitySet','building',assert(K.indexOf('building',building)),cap) end
       else
        local value=math.min(field[5],99999);if u(at)~=value then writeInteger(at,value) end
       end
      end
     end
    end
   end
  end
  for _,town in ipairs(K.objects('town')) do
   local city=u(town.p+8)
   if K.isType('city',city) and K.ownsForce(u(city+0x108)) and readBytes(town.p+0x84,1)==0 and u(town.p+0x3C)~=100 then
    writeInteger(town.p+0x3C,100)
   end
  end
 end
 if K.finishInstantOrders then K.finishInstantOrders() end
end
function K.attachAndOff()
 local processes=getProcessList();local opened=getOpenedProcessID();local pid
 for id,name in pairs(processes) do
  if name:lower()==K.EXE:lower() and (not pid or tonumber(id)==opened) then pid=tonumber(id) end
 end
 assert(pid,NB.T('Start Tendou PK from Steam first.','先にSteamから天道PKを起動してください。'))
 K.disconnect();openProcess(pid);pcall(reinitializeSymbolhandler,true)
 assert(getOpenedProcessID()==pid and K.buildMatches(),NB.T('Unsupported or unreadable Tendou PK build.','対応外の天道PKビルド、またはメモリを読み取れません。'))
 K.pid=pid;K.startData()
 local handle=executeCodeLocalEx('kernel32.OpenProcess',0x100000,0,pid)
 if handle and handle~=0 then K.life=handle end
 K.timer=createTimer(nil,false);K.timer.Interval=500
 K.timer.OnTimer=function()
  if K.life and executeCodeLocalEx('kernel32.WaitForSingleObject',K.life,0)==0 then K.disconnect();return end
  if K.nativeBusy() then return end
  local ok,e=pcall(K.tick)
  if not ok then
   local text=tostring(e):gsub('^.-:%d+: ','')
   if K.tickError~=text then K.tickError=text;NB.msg(text) end
  else K.tickError=nil end
 end
 K.timer.Enabled=true
 NB.msg(('Attached to %s (PID %d). EXE version %s; Steam build %s.'):format(K.EXE,pid,K.VERSION,K.STEAMBUILD),
  ('%s（PID %d）へアタッチ。EXEバージョン %s／Steam Build %s。'):format(K.EXE,pid,K.VERSION,K.STEAMBUILD))
 return true
end
function K.report()
 NB.openLuaEngine(true)
 NB.msg(('Tendou PK: EXE version %s / Steam build %s / PID %s / PE timestamp %X / SizeOfImage %X.'):format(K.VERSION,K.STEAMBUILD,tostring(K.pid),K.BUILD.ts,K.BUILD.size),
  ('天道PK：EXEバージョン %s／Steam Build %s／PID %s／PEタイムスタンプ %X／SizeOfImage %X。'):format(K.VERSION,K.STEAMBUILD,tostring(K.pid),K.BUILD.ts,K.BUILD.size))
 if K.key() then NB.msg('Player: '..K.name('officer',K.player())..' / '..K.name('city',K.homeCity())) end
end

end

do
local K=NB.K13
K.battleSites={
 soldierDamage={rva=0x136940,bytes='8B 44 24 04 85 C0',original='db 8B 44 24 04\ndb 85 C0'},
 soldierSet={rva=0x111850,bytes='83 EC 08 8B 44 24 0C',original='db 83 EC 08\ndb 8B 44 24 0C'},
 soldierDelta={rva=0x15F730,bytes='8B 44 24 04 56',original='db 8B 44 24 04\ndb 56'},
 citySoldierDelta={rva=0x10B250,bytes='8B 44 24 04 56',original='db 8B 44 24 04\ndb 56'},
 moraleSet={rva=0x111800,bytes='83 EC 08 8B 44 24 0C',original='db 83 EC 08\ndb 8B 44 24 0C'},
 moraleDelta={rva=0x111F60,bytes='8B 44 24 04 56',original='db 8B 44 24 04\ndb 56'},
 moraleDaily={rva=0x11586B,bytes='89 46 48 E8 7D 13 02 00',original='db 89 46 48\ncall NOBU13PK.exe+136BF0'},
 moraleField1={rva=0x221FA3,bytes='89 46 48 E8 45 4C F1 FF',original='db 89 46 48\ncall NOBU13PK.exe+136BF0'},
 moraleField2={rva=0x221FFD,bytes='89 46 48 E8 EB 4B F1 FF',original='db 89 46 48\ncall NOBU13PK.exe+136BF0'},
 moraleTactic={rva=0x20EAB0,bytes='89 46 48 E8 98 46 01 00',original='db 89 46 48\ncall NOBU13PK.exe+223150'},
 riceSet={rva=0x134330,bytes='83 EC 08 8B 44 24 0C',original='db 83 EC 08\ndb 8B 44 24 0C'},
 riceDelta={rva=0x134380,bytes='83 EC 08 8B 41 4C',original='db 83 EC 08\ndb 8B 41 4C'},
 riceConsume={rva=0x1343D0,bytes='83 EC 08 8B 41 4C',original='db 83 EC 08\ndb 8B 41 4C'},
 spiritSet={rva=0x1368C0,bytes='83 EC 08 56 8B F1',original='db 83 EC 08\ndb 56\ndb 8B F1'},
 buildingCombat={rva=0x2109EC,bytes='E8 3F A6 EE FF',original='call NOBU13PK.exe+FB030'},
}

end

do
local K=NB.K13
local u=K.u
function K.ensureBattleFlags()
 if K.battleFlags then return end
 K.ready();K.nativeAddress('buildingOwner')
 local symbol=K.nativeSymbol..'_battle';local m=K.base()
 local script=([[
[ENABLE]
alloc(@F@,4096)
registersymbol(@F@)
label(done)
label(army)
label(city)
label(building)
label(checkForce)
label(enemy)
label(own)
label(roster)
label(player)
label(forceDone)
@F@:
dd 0 0 0 0 0
@F@+100:
pushad
xor eax,eax
mov edi,ecx
test edi,edi
jz done
mov edx,[%X]
cmp edx,[@F@+4]
jne done
test edx,edx
jz done
mov edx,[edx+30C]
cmp edx,[@F@+8]
jne done
mov edx,[edi]
cmp edx,%X
je army
cmp edx,%X
je city
cmp edx,%X
je building
jmp done
army:
mov edx,[edi+74]
jmp checkForce
city:
mov edx,[edi+108]
checkForce:
cmp edx,10000
jb done
cmp dword ptr [edx],%X
jne done
mov edx,[edx+8]
test edx,edx
jz done
cmp edx,[@F@+C]
jne enemy
mov eax,1
cmp dword ptr [edi],%X
jne own
mov ecx,[edi+90]
cmp ecx,10
ja own
test ecx,ecx
jz own
mov esi,[edi+8C]
cmp esi,10000
jb own
mov edx,[esi]
roster:
cmp edx,esi
je own
mov ebx,[edx+8]
cmp ebx,[@F@+10]
je player
mov edx,[edx]
dec ecx
jnz roster
jmp own
building:
call %X
test eax,eax
jz done
cmp eax,[@F@+C]
jne enemy
mov eax,1
jmp done
enemy:
mov eax,4
jmp done
own:
jmp done
player:
mov eax,3
done:
mov [esp+1C],eax
popad
ret
@F@+800:
push edx
xor eax,eax
cmp ecx,10000
jb forceDone
cmp dword ptr [ecx],%X
jne forceDone
mov edx,[%X]
cmp edx,[@F@+4]
jne forceDone
test edx,edx
jz forceDone
mov edx,[edx+30C]
cmp edx,[@F@+8]
jne forceDone
mov edx,[ecx+8]
cmp edx,[@F@+C]
sete al
forceDone:
pop edx
ret
[DISABLE]
unregistersymbol(@F@)
dealloc(@F@)
]]):format(u(m+0x197AF1),m+K.types.army.vt,m+K.types.city.vt,m+K.types.building.vt,
 m+K.types.force.vt,m+K.types.army.vt,K.nativeAddress('buildingOwner'),m+K.types.force.vt,u(m+0x197AF1))
 script=script:gsub('@F@',symbol)
 local ok,info=autoAssemble(script);assert(ok,tostring(info))
 K.battleFlags={q=assert(getAddressSafe(symbol)),symbol=symbol,script=script,info=info,pid=K.pid}
 K.updateBattleFlags()
end
function K.updateBattleFlags()
 local f=K.battleFlags;if not f or not K.attached() then return end
 writeInteger(f.q,0)
 writeInteger(f.q+4,K.root() or 0);writeInteger(f.q+8,K.scenario() or 0)
 writeInteger(f.q+0xC,K.clan() or 0);writeInteger(f.q+0x10,K.player() or 0)
 local bits=(K.on.ownBattle and 1 or 0)|(K.on.playerBattle and 2 or 0)|
  (K.on.battleOneHit and 4 or 0)|(K.on.battleSkills and 8 or 0)|(K.on.armySpeed and 16 or 0)
 writeInteger(f.q,bits)
end
function K.removeBattleFlags()
 local f=K.battleFlags;if not f then return end
 K.assertNativeIdle()
 for name in pairs(K.patches) do assert(name:sub(1,7)~='battle_','Remove N13 battle hooks before their state') end
 if f.pid==getOpenedProcessID() and K.buildMatches() then
  writeInteger(f.q,0);assert(autoAssemble(f.script,f.info),'Cannot remove N13 battle state')
 end
 K.battleFlags=nil
end
function K.battlePatch(name,body)
 local d=assert(K.battleSites[name]);K.patch('battle_'..name,d.rva,d.bytes,body,d.original)
end
function K.installBattlePatches()
 if K.patches.battle_soldierDamage then return end
 K.ensureBattleFlags();local f=K.battleFlags.symbol
 local function body(s) return s:gsub('@F@',f) end
 K.battlePatch('soldierDamage',body([[
label(enemy)
label(done)
pushfd
pushad
call @F@+100
test eax,3
jz enemy
and eax,[@F@]
test eax,eax
jz done
mov dword ptr [esp+28],0
jmp done
enemy:
cmp eax,4
jne done
test dword ptr [@F@],4
jz done
mov ecx,[esp+2C]
call @F@+100
test eax,3
jz done
mov ecx,[esp+18]
mov eax,[ecx+28]
mov [esp+28],eax
done:
popad
popfd
]]))
 local function input(code,force)
  return body(([[
label(done)
pushfd
pushad
call @F@+%s
%s
test eax,eax
jz done
%s
done:
popad
popfd
]]):format(force and '800' or '100',force and 'test dword ptr [@F@],3\njz done' or 'and eax,3\nand eax,[@F@]',code))
 end
 for _,name in ipairs({'soldierDelta','citySoldierDelta'}) do
  K.battlePatch(name,input('cmp dword ptr [esp+28],0\njge done\nmov dword ptr [esp+28],0'))
 end
 K.battlePatch('soldierSet',input('mov eax,[ecx+28]\ncmp eax,[esp+28]\njle done\nmov [esp+28],eax'))
 K.battlePatch('moraleSet',input('mov dword ptr [esp+28],64'))
 K.battlePatch('moraleDelta',input('mov eax,64\nsub eax,[ecx+48]\nmov [esp+28],eax'))
 for _,name in ipairs({'moraleDaily','moraleField1','moraleField2','moraleTactic'}) do
  K.battlePatch(name,body([[
label(done)
pushfd
push eax
push ecx
mov ecx,esi
call @F@+100
and eax,3
and eax,[@F@]
test eax,eax
jz done
mov dword ptr [esp+4],64
done:
pop ecx
pop eax
popfd
]]))
 end
 K.battlePatch('riceSet',input('mov dword ptr [esp+28],989680',true))
 K.battlePatch('riceDelta',input('mov dword ptr [ecx+4C],989680\nmov dword ptr [esp+28],0',true))
 K.battlePatch('riceConsume',input('mov dword ptr [ecx+4C],989680\nmov dword ptr [esp+28],0',true))
 K.battlePatch('spiritSet',body([[
label(done)
pushfd
pushad
test dword ptr [@F@],8
jz done
call @F@+100
test eax,3
jz done
mov dword ptr [esp+28],3E8
cmp dword ptr [ecx+FC],0
je done
mov dword ptr [esp+28],BB8
done:
popad
popfd
]]))
 K.battlePatch('buildingCombat',body([[
label(enemy)
label(done)
pushfd
pushad
call @F@+100
test eax,3
jz enemy
and eax,[@F@]
test eax,eax
jz done
mov dword ptr [esp+24],0
jmp done
enemy:
cmp eax,4
jne done
test dword ptr [@F@],4
jz done
mov ecx,edi
call @F@+100
test eax,3
jz done
mov eax,[esi+C]
mov [esp+24],eax
done:
popad
popfd
]]))
end
function K.armyOfficers(p)
 if not K.isType('army',p) then return end
 local list=K.listItems(p+0x88,16);if not list then return end
 for _,officer in ipairs(list) do if not K.isType('officer',officer) then return end end
 return list
end
function K.runBattleFeatures()
 local own,player=K.on.ownBattle,K.on.playerBattle
 if not own and not player and not K.on.battleSkills then return end
 local lord=K.player();local forces={}
 for _,item in ipairs(K.objects('army')) do
  local p=item.p;local force=u(p+0x74)
  if K.ownsForce(force) then
   local officers=K.armyOfficers(p);local include=own
   if player and officers then for _,officer in ipairs(officers) do if officer==lord then include=true end end end
   if include and officers and #officers&gt;0 and item.id&lt;500 and u(p+0x28)&gt;0 then
    local cap=0
    for _,officer in ipairs(officers) do
     local oi=assert(K.indexOf('officer',officer))
     cap=math.max(cap,K.nativeCall('officerTroopCap','officer',oi))
    end
    assert(cap&gt;0 and cap&lt;=15000,'Invalid command capacity')
    if u(p+0x28)&lt;cap then writeInteger(p+0x28,cap) end
    if u(p+0x2C)~=0 then writeInteger(p+0x2C,0) end
    if u(p+0x48)~=100 then writeInteger(p+0x48,100) end
    forces[force]=true
   end
   if K.on.battleSkills and (item.id&gt;=500 and u(p+0xFC)&gt;0 or officers and #officers&gt;0) then
    local cap=item.id&gt;=500 and 3000 or 1000
    if u(p+0x4C)~=cap then writeInteger(p+0x4C,cap) end
   end
  end
 end
 for force in pairs(forces) do if u(force+0x4C)&lt;10000000 then writeInteger(force+0x4C,10000000) end end
end
local feature=K.feature
function K.feature(name,on)
 if name=='ownBattle' or name=='playerBattle' or name=='battleOneHit' or name=='battleSkills' then
  if on then K.ready();K.installBattlePatches();K.snapshot=K.key();K.on[name]=true else K.on[name]=nil end
  K.updateBattleFlags();if on then K.runBattleFeatures() end;return
 end
 return feature(name,on)
end
local run=K.runFeatures
function K.runFeatures() run();K.updateBattleFlags();K.runBattleFeatures() end

end

do
-- Parameters linked to native list formatters and enum getters.
local K=NB.K13
local u=K.u
for _,field in ipairs({
 {'Official post','役職',0x140,-1,59,'post',false},
 {'Origin','出自',0x194,0,7,'self',false,'@enum:C47784:8'},
 {'Religion','信仰',0x198,0,3,'self',false,'@enum:C477A4:4'},
 {'Grade','格付',0x1C8,0,3,'self',false,'@enum:C47824:4'},
 {'Teaching method','指南法',0x1D8,0,4,'self',false,'@enum:C47D40:5'},
 {'Growth potential','成長力',0x1DC,0,50},
 {'Voice','声',0x18C,0,12,'self',false,'@enum:C47C7C:13'},
 {'Sex','性別',0x1E0,0,1,'bit',false,'0:Male / 男\n1:Female / 女',4}
}) do K.fields.officer[#K.fields.officer+1]=field end
function K.awardPost(kind,index,postID)
 K.ready();local p=kind=='player' and K.player() or K.object('officer',index)
 local oi=assert(K.indexOf('officer',p));local old=u(p+0x140)
 local post=postID==-1 and 0 or assert(K.object('post',postID),'Official post unavailable')
 if old==post then return end
 if old and old~=0 then K.nativeCall('postClear','officer',oi,old) end
 if post~=0 then
  K.nativeCall('postAward','officer',oi,p,post)
  assert(u(p+0x140)==post,'Official post award did not apply')
 end
end
function K.addAction(parent,en,ja,body)
 local row=NB.addRec(parent,en,ja,'0',vtAutoAssembler)
 row.Script='[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() '..body..' end)\n{$asm}\n[DISABLE]\n'
 row.Color=NB.C_SCRIPT;return row
end
function K.chooseTactic(kind,index)
 K.ready();local token=K.key();local items,names={},{}
 for _,item in ipairs(K.objects('tactic')) do
  local name=K.name('tactic',item.p)
  if name~='' then items[#items+1]=item;names[#names+1]=name end
 end
 local n=NB.pick(NB.T('Select tactic','戦法を選択'),names);if not n then return end
 assert(K.key()==token,'Game data changed')
 local p=kind=='player' and K.player() or K.object('officer',index)
 local oi=assert(K.indexOf('officer',p))
 K.nativeCall('tacticSet','officer',oi,items[n].p)
 local list=K.listItems(p+0x114,72)
 assert(list and #list==1 and list[1]==items[n].p,'Tactic change did not apply')
end
local open=K.openEditor
function K.openEditor(mr,kind)
 open(mr,kind)
 if (kind=='officer' or kind=='player') and K.editors[mr.ID] then
  K.addAction(mr,'Change tactic...','戦法を変更...',('NB.K13.chooseTactic(%q,%s)'):format(kind,tostring(K.sel[kind])))
 end
end

-- Court values belong to the clan, independently of the officer rank record.
function K.openCourt(mr)
 K.ready();K.closeEditor(mr)
 K.addField(mr,'player',nil,{'Court contribution','朝廷貢献度',0x150,0,1000,'clan',false})
 K.editors[mr.ID]={mr=mr,kind='court'};mr.Collapsed=false
end

function K.canUpgradeCastle(index)
 local city=K.object('city',index);local building=city and u(city+0x110)
 return building and K.isType('building',building) and u(building+4)==K.object('buildingDef',0) or false
end
function K.maxCastle(index)
 local city=assert(K.object('city',index),'City unavailable')
 if not K.canUpgradeCastle(index) then return end
 for _,part in ipairs({{0x118,4,4},{0x11C,2,6},{0x120,1,7}}) do
  if u(city+part[1])&lt;part[2] then K.nativeCall('castleUpgrade','city',index,city,part[3]) end
 end
 if (readBytes(city+0x149,1)&amp;1)==0 then K.nativeCall('castleUpgrade','city',index,city,8) end
end
function K.chooseCastleUpgrade(index)
 K.ready();assert(K.canUpgradeCastle(index),'This base has no main-castle upgrades');local key=K.key()
 local names={NB.T('Keep level 1','天守1段階'),NB.T('Keep level 2','天守2段階'),NB.T('Keep level 3','天守3段階'),NB.T('Maximum keep','天守最大'),NB.T('Gate level 1','城門1段階'),NB.T('Gate level 2','城門2段階'),NB.T('Wall upgrade','塀を改築'),NB.T('Second bailey','二の丸')}
 local n=NB.pick(NB.T('Castle upgrade','城郭改築'),names);if not n then return end
 assert(K.key()==key,'Game data changed')
 local city=assert(K.object('city',index));K.nativeCall('castleUpgrade','city',index,city,n)
end
local openWithParameters=K.openEditor
function K.openEditor(mr,kind)
 openWithParameters(mr,kind)
 if kind=='city' and K.editors[mr.ID] and K.canUpgradeCastle(K.sel.city) then
  K.addAction(mr,'Upgrade castle...','城郭を改築...',('NB.K13.chooseCastleUpgrade(%d)'):format(K.sel.city))
 end
end
local runWithParameters=K.runFeatures
function K.runFeatures()
 if K.on.cityMax and K.key() and K.key()==K.snapshot then
  for _,city in ipairs(K.objects('city')) do if K.ownsForce(u(city.p+0x108)) then K.maxCastle(city.id) end end
 end
 runWithParameters()
end

end

do
-- Chance overrides preserve the native result for every non-player actor.
local K=NB.K13
local chanceSites={
 {'alliance',0x276F3A,0x1F5500,'negotiationSuccess','E8 C1 E5 F7 FF'},
 {'captives',0x2791C2,0x1F5970,'negotiationSuccess','E8 A9 C7 F7 FF'},
 {'submission',0x27D44E,0x1F5B00,'negotiationSuccess','E8 AD 86 F7 FF'},
 {'ceasefire',0x28959B,0x1F5840,'negotiationSuccess','E8 A0 C2 F6 FF'},
 {'reinforcements',0x28AF58,0x1F5710,'negotiationSuccess','E8 B3 A7 F6 FF'},
 {'recruitment',0x289E18,0x1F5BC0,'recruitment','E8 A3 BD F6 FF'},
 {'poaching',0x2799A9,0x1F42A0,'recruitment','E8 F2 A8 F7 FF'},
 {'incitement',0x285835,0x1F52B0,'schemes','E8 76 FA F6 FF'},
 {'immobilize',0x27117D,0x1F3EA0,'schemes','E8 1E 2D F8 FF'},
 {'ambush',0x27F1A1,0x1F2250,'schemes','E8 AA 30 F7 FF'},
}
function K.installChancePatches()
 K.installNative();local root,scenario,clan=K.root(),K.scenario(),K.clan()
 for _,site in ipairs(chanceSites) do
  local name='chance_'..site[1]
  if K.on[site[4]] then
   local body=([[
label(done)
call %X
pushad
mov eax,[%X]
cmp eax,%X
jne done
cmp dword ptr [eax+30C],%X
jne done
mov ecx,[esp+20]
cmp ecx,10000
jb done
cmp dword ptr [ecx],%X
jne done
cmp dword ptr [ecx+188],7
jne done
mov ecx,[ecx+144]
cmp ecx,10000
jb done
cmp dword ptr [ecx],%X
jne done
cmp dword ptr [ecx+8],%X
jne done
mov dword ptr [esp+1C],64
done:
popad
]]):format(K.base()+site[3],K.base()+0xC79A10,root,scenario,K.base()+0xA8FEF4,K.base()+0xA91E38,clan)
   K.patch(name,site[2],site[5],body,'')
  else K.removePatch(name) end
 end
end
local feature=K.feature
function K.feature(name,enabled)
 if name=='negotiationSuccess' or name=='recruitment' or name=='schemes' then
  if not enabled then
   K.on[name]=nil
   if not (K.on.negotiationSuccess or K.on.recruitment or K.on.schemes) then
    local names={};for patch in pairs(K.patches) do if patch:sub(1,7)=='chance_' then names[#names+1]=patch end end
    for _,patch in ipairs(names) do K.removePatch(patch) end
    return true
   end
  end
  K.ready();K.snapshot=K.key();K.on[name]=enabled or nil;K.installChancePatches();return true
 end
 return feature(name,enabled)
end

-- Alliance extension uses a result class rather than a percentage.
-- Native success path at 677B9E accepts class 0 without hostage/money conditions.
local installChance=K.installChancePatches
function K.installChancePatches()
 installChance()
 local name='chance_extendAlliance'
 if not K.on.negotiationSuccess then K.removePatch(name);return end
 local body=([[
label(done)
call %X
pushad
mov ecx,[%X]
cmp ecx,%X
jne done
cmp dword ptr [ecx+30C],%X
jne done
mov ecx,[esp+24]
cmp ecx,10000
jb done
cmp dword ptr [ecx],%X
jne done
cmp dword ptr [ecx+8],%X
jne done
mov dword ptr [esp+1C],0
done:
popad
]]):format(K.base()+0x1F8B30,K.base()+0xC79A10,K.root(),K.scenario(),K.base()+K.types.force.vt,K.clan())
 K.patch(name,0x277907,'E8 24 12 F8 FF',body,'')
end

-- Initial alliances have a separate refusal/counteroffer class before the roll.
local installWithExtension=K.installChancePatches
function K.installChancePatches()
 installWithExtension()
 local name='chance_allianceClass'
 if not K.on.negotiationSuccess then K.removePatch(name);return end
 local body=([[
label(done)
call %X
pushad
mov ecx,[%X]
cmp ecx,%X
jne done
cmp dword ptr [ecx+30C],%X
jne done
mov ecx,[esp+20]
cmp ecx,10000
jb done
cmp dword ptr [ecx],%X
jne done
cmp dword ptr [ecx+8],%X
jne done
mov dword ptr [esp+1C],0
done:
popad
]]):format(K.base()+0x1F5E90,K.base()+0xC79A10,K.root(),K.scenario(),K.base()+K.types.force.vt,K.clan())
 K.patch(name,0x276F04,'E8 87 EF F7 FF',body,'')
end

end

do
-- Observed live coordinate writer: 699988 &lt;- 71EAFE &lt;- movement 71EC80.
-- Extend only the per-step budget; native path/arrival handling remains in charge.
local K=NB.K13
function K.installMovementPatch()
 K.installNative();K.ensureBattleFlags()
 local f=K.battleFlags.symbol
 local body=([[
label(done)
test dword ptr [%s],10
jz done
pushad
mov ecx,[esi+4]
call %s+100
test eax,1
jz skip
mov eax,[%X]
cmp eax,100
jb skip
cmp eax,10000
ja skip
mov [esp+10],eax
inc dword ptr [%s+20]
mov [%s+24],ebx
mov [%s+28],eax
skip:
popad
done:
]]):format(f,f,K.base()+0xC11B98,f,f,f)
 body='label(skip)'..string.char(10)..body
 K.patch('battle_movement',0x31EF3F,'8B 15 00 99 07 01',body,('mov edx,[%X]'):format(K.base()+0xC79900))
end
local feature=K.feature
function K.feature(name,on)
 if name=='armySpeed' then
  if on then K.ready();K.snapshot=K.key();K.installMovementPatch();K.on[name]=true else K.on[name]=nil end
  K.updateBattleFlags();return true
 end
 return feature(name,on)
end

end

-- Title-specific availability. Keep a complete schema in Lua: CE has no
-- MemoryRecord.Visible property. Setting an arbitrary Lua field does not hide rows.
-- Only the explicitly excluded display/input controls are hidden in Kakushin.
local hidden12={[20]=true,[25]=true,[26]=true,[27]=true,[28]=true,[18]=true,[29]=true}
local common={[1]=true,[2]=true,[3]=true,[4]=true,[5]=true,[6]=true,[7]=true,
 [12]=true,[13]=true,[14]=true,[15]=true,[16]=true,[17]=true,[19]=true,[24]=true}
local tips11
local savedNames={}
local extraNames
local kakushinNames={
 [501]={'Assign treasures (multiple selection)...','家宝をまとめて授与（複数選択）...'},
 [101]={'No command travel / return wait or acted status','命令の移動・帰還待ちなし／行動済みにならない'},
 [602]={'Instant research / construction / remodeling / repairs','研究・建設・改築・修復 即完了'},
 [603]={'Acquire all technologies','全技術取得'},
 [604]={'Technology proficiency MAX','技術熟練度MAX'},
 [605]={'Current orders','実行中の命令'},
 [704]={'Court rank editor','官位エディタ'}}
function NB.applyProfileRecords()
 local al=getAddressList();local wanted={}
 for _,d in ipairs(NB.RECORDS) do
  if d.id==30 then wanted[d.id]=NB.game==4 or NB.game==5
  elseif (NB.game==1 and d.id~=207 and d.id~=705) or common[d.id] or ((NB.game==2 or NB.game==3) and not hidden12[d.id]) then wanted[d.id]=true end
 end
 -- Compare the actual flattened CE tree, including order. Newly created root
 -- records otherwise remain at the bottom after a title switch.
 local expected,current={},{}
 for _,d in ipairs(NB.RECORDS) do if wanted[d.id] then expected[#expected+1]=d.id end end
 for i=0,al.Count-1 do local r=al.getMemoryRecord(i);if NB.NAMES[r.ID] then current[#current+1]=r.ID end end
 local rebuild=#expected~=#current
 for i,id in ipairs(expected) do if current[i]~=id then rebuild=true;break end end
 if rebuild then
  for i=al.Count-1,0,-1 do
   local r=al.getMemoryRecord(i)
   if NB.NAMES[r.ID] then assert(not r.Active,'Cannot rebuild an active feature');r.destroy() end
  end
 end
 for _,d in ipairs(NB.RECORDS) do
  if wanted[d.id] then
   local r=al.getMemoryRecordByID(d.id)
   if not r then
    r=al.createMemoryRecord();r.ID=d.id
    if d.group==1 then r.IsGroupHeader=true;r.Type=vtByte else r.Type=vtAutoAssembler;r.Script=d.script end
    r.Color=d.color~='' and tonumber(d.color,16) or -2147483640
    r.Options=d.manual==1 and '[moManualExpandCollapse]' or '[]'
    r.Collapsed=d.id&gt;=100
   end
   if d.parent~=0 and (not r.Parent or r.Parent.ID~=d.parent) then r.appendToEntry(assert(al.getMemoryRecordByID(d.parent))) end
   if d.group~=1 then
    local script=d.script
    if NB.game==3 and d.id==604 then script='[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.K13.acquireAllCulture() end)\n{$asm}\n[DISABLE]\n' end
    if r.Script~=script then r.Script=script end
   end
  end
 end
 extraNames=extraNames or {[206]=NB.NAMES[206],[605]=NB.NAMES[605]}
 for id,name in pairs(extraNames) do NB.NAMES[id]=name end
 tips11=tips11 or {NB.NAMES[7],NB.NAMES[19]}
 if NB.game==2 then
  NB.NAMES[7]={'1) Start Kakushin PK from Steam, select this title, then ATTACH.','1) Steamから革新PKを起動し、作品を選択してアタッチします。'}
  NB.NAMES[19]={'2) Select an officer/city, open the editor, then edit its values. Save before editing.','2) 武将・都市を選択してエディタを開き、値を編集します。編集前に保存してください。'}
 elseif NB.game==3 then
  NB.NAMES[7]={'1) Start Tendou PK from Steam, select this title, then ATTACH.','1) Steamから天道PKを起動し、作品を選択してアタッチします。'}
  NB.NAMES[19]={'2) Select an officer/city and open the editor. Save before editing.','2) 武将・都市を選択してエディタを開きます。編集前に保存してください。'}
 elseif NB.game==1 then NB.NAMES[7]=tips11[1];NB.NAMES[19]=tips11[2]
 else
  NB.NAMES[7]={'1) Start the selected game, load a scenario, then ATTACH.','1) 選択したゲームでシナリオをロードし、アタッチします。'}
  NB.NAMES[19]={'2) Select a supported title.','2) 対応する作品を選択してください。'}
 end
 for id,names in pairs(kakushinNames) do
  savedNames[id]=savedNames[id] or NB.NAMES[id]
  NB.NAMES[id]=NB.game==2 and names or savedNames[id]
 end
 if NB.game==3 then
  local names={
   [101]={'No command travel / return wait','命令の移動・帰還待ちなし'},
   [206]={'Tactic spirit always MAX (own units)','戦法の闘志MAX（自勢力）'},
   [501]={'Assign treasures (multiple selection)...','家宝をまとめて授与（複数選択）...'},
   [602]={'Instant development / research / remodeling / repairs / culture','開発・研究・改築・修復・文化振興 即完了'},
   [603]={'Acquire all technologies','全技術取得'},
   [604]={'Acquire all cultures','全文化取得'},
   [605]={'Current orders','実行中の命令'},
   [704]={'Court contribution editor','朝廷貢献度エディタ'}}
  for id,name in pairs(names) do NB.NAMES[id]=name end
 end
 NB.applyLang()
 -- Apply only after all children have been appended: CE ignores collapsing
 -- a record that has no children yet. Match GameTemplate's settings subtree.
 for i=0,al.Count-1 do
  local row=al.getMemoryRecord(i)
  if row.Count&gt;0 and not tostring(row.Options):find('moHideChildren',1,true) then
   local parent,inSettings=row,false
   while parent do if parent.ID==NB.ID_TOP0 then inSettings=true;break end;parent=parent.Parent end
   row.Collapsed=not inSettings
  end
 end
end
local initialize=NB.initializeUI
function NB.initializeUI()
 NB.applyProfileRecords();initialize();NB.applyProfileRecords()
end
local release=NB.releaseGameSelection
function NB.releaseGameSelection()
 if NB.K12 then NB.K12.disconnect() end
 release()
end
local shutdown=NB.shutdown
function NB.shutdown(recordsMayBeGone)
 if NB.K12 then NB.K12.disconnect() end
 shutdown(recordsMayBeGone)
end
local scan=NB.scanSelfTest
function NB.scanSelfTest() if NB.game==2 then return NB.K12.selfTest() end;return scan() end
local environment=NB.envReport
function NB.envReport() if NB.game==2 then return NB.K12.report() end;return environment() end
local status=NB.statusReport
function NB.statusReport() if NB.game==2 then return NB.K12.report() end;return status() end
local progress=NB.progressReport
function NB.progressReport() if NB.game==2 then return end;return progress() end

do
-- N13 dispatch is installed after the existing N11/N12 wrappers.
local K=NB.K13
local search,player,home,open,close,feature,suffix=NB.search,NB.selectPlayer,NB.selectHomeCity,NB.openEditor,NB.closeEditor,NB.feature,NB.refreshSuffix
function NB.search(kind) if NB.game==3 then return K.search(kind) end;return search(kind) end
function NB.selectPlayer() if NB.game==3 then K.ready();return K.select('officer',assert(K.indexOf('officer',K.player()))) end;return player() end
function NB.selectHomeCity() if NB.game==3 then K.ready();return K.select('city',assert(K.indexOf('city',K.homeCity()))) end;return home() end
function NB.openEditor(mr,kind) if NB.game==3 then return K.openEditor(mr,kind) end;return open(mr,kind) end
function NB.closeEditor(mr) if NB.game==3 then return K.closeEditor(mr) end;return close(mr) end
function NB.feature(name,on) if NB.game==3 then return K.feature(name,on) end;return feature(name,on) end
function NB.refreshSuffix() if NB.game==3 then return K.refreshSuffix() end;return suffix() end
local attach=NB.attachAndConfigure
function NB.attachAndConfigure(self) if NB.game==3 then NB.disableAll(self);return K.attachAndOff() end;return attach(self) end
local assign,court,unlock,orders=NB.assignTreasure,NB.openCourtEditor,NB.unlockCityDevelopment,NB.reportDevelopment
function NB.assignTreasure() if NB.game==3 then return K.assignTreasure() end;return assign() end
function NB.openCourtEditor(mr) if NB.game==3 then return K.openCourt(mr) end;return court(mr) end
function NB.unlockCityDevelopment() if NB.game==3 then return K.acquireAllTechnology() end;return unlock() end
function NB.reportDevelopment()
 if NB.game~=3 then return orders() end
 K.ready();local current=K.orders();NB.openLuaEngine(true)
 NB.msg(('Current orders: %d.'):format(#current),('実行中の命令：%d件。'):format(#current))
 for _,order in ipairs(current) do NB.msg(K.name('officer',order.officer)..': '..K.commandClasses[order.kind].label) end
end
local release=NB.releaseGameSelection
function NB.releaseGameSelection() K.disconnect();return release() end
local shutdown=NB.shutdown
function NB.shutdown(gone) K.disconnect();return shutdown(gone) end
local environment,status,progress,scan=NB.envReport,NB.statusReport,NB.progressReport,NB.scanSelfTest
function NB.envReport() if NB.game==3 then return K.report() end;return environment() end
function NB.statusReport() if NB.game==3 then return K.report() end;return status() end
function NB.progressReport() if NB.game==3 then return end;return progress() end
function NB.scanSelfTest()
 if NB.game~=3 then return scan() end
 K.ready();NB.openLuaEngine(true);local count=0
 for name in pairs(K.nativeDefinitions) do
  if name=='windowProc' and K.native then
   local at=K.base()+K.nativeDefinitions.windowProc.rva
   assert(readBytes(at,1)==0xE9,'Window dispatcher changed')
   local rel=readInteger(at+1);if rel&gt;=0x80000000 then rel=rel-0x100000000 end
   assert(at+5+rel==K.native.q+0x100,'Window dispatcher ownership changed')
  else K.nativeAddress(name) end
  count=count+1
 end
 for kind,d in pairs(K.types) do assert(#K.objects(kind)==d.count,'Object vector mismatch: '..kind) end
 NB.msg(('N13 native code and object checks passed: %d operations.'):format(count),('天道PKのコード・オブジェクト照合完了：%d処理。'):format(count))
 return count,count
end

end

do
-- Common Steam achievements; independent of game object layouts and hooks.
NB.STEAM={profiles={
 [4]={app=628890,exes={'NOBU15PK_JP.exe'},stats='STEAMUSERSTATS_INTERFACE_VERSION011',utils='SteamUtils009'},
 [5]={app=1336980,exes={'NOBU16.exe','NOBU16PK.exe','NOBU16PK_EN.exe'},stats='STEAMUSERSTATS_INTERFACE_VERSION012',utils='SteamUtils010'}}}
local A=NB.STEAM
function A.call(name,...)
 local address=assert(getAddressSafe('steam_api64.'..name),NB.T('Steam API is unavailable.','Steam APIを利用できません。'))
 local value=executeCodeEx(0,5000,address,...)
 assert(value~=nil,NB.T('Steam API call did not return.','Steam APIの応答を確認できません。'))
 return value
end
function A.context()
 local profile=assert(A.profiles[NB.game],NB.T('This title has no Steam achievement control.','この作品にはSteam実績の操作項目がありません。'))
 local found=false
 for _,exe in ipairs(profile.exes) do if getAddressSafe(exe) then found=true;break end end
 assert(found,NB.T('Attach to the selected game first.','先に選択した作品へアタッチしてください。'))
 assert(targetIs64Bit(),NB.T('Unexpected process architecture.','接続先のプロセス形式が一致しません。'))
 local client=A.call('SteamClient');assert(client and client&gt;0x10000,'Steam client unavailable')
 local user=A.call('SteamAPI_GetHSteamUser')&amp;0xFFFFFFFF
 local pipe=A.call('SteamAPI_GetHSteamPipe')&amp;0xFFFFFFFF
 assert(user&gt;0 and pipe&gt;0,NB.T('Steam user is unavailable.','Steamにログインしているユーザーを確認できません。'))
 local stats=A.call('SteamAPI_ISteamClient_GetISteamUserStats',client,user,pipe,{type=3,value=profile.stats})
 local utils=A.call('SteamAPI_ISteamClient_GetISteamUtils',client,pipe,{type=3,value=profile.utils})
 assert(stats&gt;0x10000 and utils&gt;0x10000,'Steam interfaces unavailable')
 assert((A.call('SteamAPI_ISteamUtils_GetAppID',utils)&amp;0xFFFFFFFF)==profile.app,
  NB.T('Steam App ID does not match the selected title.','SteamのApp IDが選択した作品と一致しません。'))
 return {pid=getOpenedProcessID(),game=NB.game,app=profile.app,stats=stats,utils=utils}
end
function A.valid(c)
 assert(c.pid==getOpenedProcessID() and c.game==NB.game,NB.T('Game process changed.','ゲームの接続先が変わりました。'))
 assert((A.call('SteamAPI_ISteamUtils_GetAppID',c.utils)&amp;0xFFFFFFFF)==c.app,'Steam App ID changed')
end
function A.achievements(c)
 A.valid(c)
 local count=A.call('SteamAPI_ISteamUserStats_GetNumAchievements',c.stats)&amp;0xFFFFFFFF
 assert(count&lt;=10000,'Unexpected achievement count')
 local names,seen={},{}
 for index=0,count-1 do
  A.valid(c)
  local p=A.call('SteamAPI_ISteamUserStats_GetAchievementName',c.stats,index)
  local name=p and p&gt;0x10000 and readString(p,256,false)
  assert(name and #name&gt;0 and #name&lt;256 and not seen[name],NB.T('Achievement list could not be read.','実績一覧を正しく読み取れません。'))
  seen[name]=true;names[#names+1]=name
 end
 return names
end
function A.attachSelected()
 local profile=assert(A.profiles[NB.game],'No achievement profile')
 for _,exe in ipairs(profile.exes) do if getAddressSafe(exe) then return end end
 local pid
 for _,exe in ipairs(profile.exes) do
  local candidate=getProcessIDFromProcessName(exe)
  if candidate and candidate~=0 then pid=candidate;break end
 end
 assert(pid,NB.T('Start the selected game from Steam first.','先に選択した作品をSteamから起動してください。'))
 -- Existing table hooks must be restored before changing CE's target.
 NB.releaseGameSelection();openProcess(pid)
 assert(getOpenedProcessID()==pid,'Could not attach to the selected game')
end
function A.unlockAll()
 local c=A.context();local names=A.achievements(c)
 if #names==0 then NB.msg('This game has no Steam achievements.','このゲームにはSteam実績がありません。');return {total=0,changed=0} end
 local byte=assert(allocateMemory(16));local pending={}
 local ok,result=pcall(function()
  -- Read the entire list successfully before changing any achievement.
  for _,name in ipairs(names) do
   A.valid(c);writeBytes(byte,0)
   local read=A.call('SteamAPI_ISteamUserStats_GetAchievement',c.stats,{type=3,value=name},byte)
   assert((read&amp;255)==1,NB.T('Achievement data is not ready. Try again shortly.','実績データを取得できません。少し待って再実行してください。'))
   if readBytes(byte,1)==0 then pending[#pending+1]=name end
  end
  local changed,failed=0,0
  for _,name in ipairs(pending) do
   A.valid(c)
   if (A.call('SteamAPI_ISteamUserStats_SetAchievement',c.stats,{type=3,value=name})&amp;255)==1 then changed=changed+1 else failed=failed+1 end
  end
  local stored=true
  if changed&gt;0 then A.valid(c);stored=(A.call('SteamAPI_ISteamUserStats_StoreStats',c.stats)&amp;255)==1 end
  local verified=0
  for _,name in ipairs(names) do
   A.valid(c);writeBytes(byte,0)
   local read=A.call('SteamAPI_ISteamUserStats_GetAchievement',c.stats,{type=3,value=name},byte)
   if (read&amp;255)==1 and readBytes(byte,1)==1 then verified=verified+1 end
  end
  local status={total=#names,changed=changed,failed=failed,verified=verified,storeAccepted=stored}
  A.last=status
  if not stored then
   NB.msg(('Steam unlocks: %d/%d; save request failed.'):format(verified,#names),('Steam実績：%d/%d件解除済み。保存要求は失敗しました。'):format(verified,#names))
  else
   NB.msg(('Steam unlocks: %d/%d; newly set %d, failed %d.'):format(verified,#names,changed,failed),
    ('Steam実績：%d/%d件解除済み。今回解除%d件、失敗%d件。'):format(verified,#names,changed,failed))
  end
  return status
 end)
 -- A timed-out remote call may still hold this pointer. Keep this tiny
 -- scratch allocation on failure rather than freeing an in-flight output.
 if ok then deAlloc(byte) else error(result,0) end
 return result
end
function NB.unlockSteamAchievements()
 A.attachSelected();return A.unlockAll()
end

end








-- BEGIN TAISHI PROFILE MODULES

do
local function createTaishiJP()

do
-- Taishi PK x64, FileVersion 1.0.0.7 / Steam build 3876132.
-- Independent of the x86 N11/N12/N13 object layouts and native dispatcher.
NB.K15={EXE='NOBU15PK_JP.exe',VERSION='1.0.0.7',STEAMBUILD='3876132',
 BUILD={ts=0x5CE223D7,size=0x1D4C000},sel={},editors={},on={}}
local K=NB.K15
K.types={
 officer={off=0x1A78,count=3952,stride=0x268,vt=0xBDFEC8},
 clan={off=0x95F8,count=147,stride=0x1C78,vt=0xBE0758},
 district={off=0x9A90,count=147,stride=0x1B0,vt=0xBE0840},
 city={off=0x9F28,count=350,stride=0x2B8,vt=0xBE0528},
 cityName={off=0xAA18,count=350,stride=0x38,vt=0xBE0708},
 agriculture={off=0x131A8,count=350,stride=0x170,vt=0xBE6CA0},
 market={off=0x13C98,count=782,stride=0x130,vt=0xBE6D50},
 county={off=0x15508,count=1883,stride=0x170,vt=0xBE6D00},
 facility={off=0x38AD8,count=17,stride=0xC8,vt=0xBE07A0},
 army={off=0xB508,count=700,stride=0x340,vt=0xBEAF40},
 formation={off=0x18FE0,count=700,stride=0x2C8,vt=0xBDFC50},
 treasure={off=0xD410,count=121,stride=0x70,vt=0xBE6950},
 ambitionEffect={off=0x20FD0,count=200,stride=0x408,vt=0xBE69E0},
 policy={off=0x1A8C0,count=1024,stride=0xC8,vt=0xBE6770},
 ambition={off=0x1A5C0,count=96,stride=0x110,vt=0xBE6A30},
 trait={off=0x11C40,count=200,stride=0xE8,vt=0xBE9688},
 tactic={off=0x125E8,count=241,stride=0x110,vt=0xBE96D0},
 operation={off=0x20ED0,count=32,stride=0x428,vt=0xBE6B60}}
function K.base() return getAddressSafe(K.EXE) end
function K.buildMatches()
 local m=K.base();local pe=m and readInteger(m+0x3C)
 return m and pe and readSmallInteger(m)==0x5A4D and readInteger(m+pe)==0x4550
  and readSmallInteger(m+pe+4)==0x8664 and readInteger(m+pe+8)==K.BUILD.ts
  and readInteger(m+pe+0x50)==K.BUILD.size
end
function K.attached() return K.pid~=nil and K.pid==getOpenedProcessID() and K.buildMatches() end
function K.root()
 if not K.attached() then return end
 local m=K.base();local r=readQword(m+0x11B5D18)
 if r and readQword(r)==m+0xBE6E48 then return r end
end
function K.isType(kind,p)
 local t=K.types[kind];local m=K.base()
 return t and m and p and p&gt;=0x10000 and readQword(p)==m+t.vt or false
end
function K.object(kind,index)
 local t=K.types[kind];local r=K.root()
 if not r or not t or type(index)~='number' or index%1~=0 or index&lt;0 or index&gt;=t.count then return end
 local first=readQword(r+t.off);local p=readQword(r+t.off+index*8)
 if first and p==first+index*t.stride and K.isType(kind,p) then return p end
end
function K.indexOf(kind,p)
 local t=K.types[kind];local r=K.root()
 if not t or not r or not K.isType(kind,p) then return end
 local first=readQword(r+t.off);if not first then return end
 local index=(p-first)/t.stride
 if index%1==0 and K.object(kind,index)==p then return index end
end
function K.objects(kind)
 local out={};local t=K.types[kind];local root=K.root()
 if not t or not root then return out end
 -- Validate one pointer-vector snapshot; callers still validate live write targets.
 local vector=readBytes(root+t.off,t.count*8,true)
 if not vector or #vector~=t.count*8 then return out end
 local function q(index)
  local value=0;for n=7,0,-1 do value=(value&lt;&lt;8)|vector[index*8+n+1]end;return value
 end
 local first=q(0);if first&lt;0x10000 then return out end
 local vt=K.base()+t.vt
 for i=0,t.count-1 do
  local p=q(i)
  if p==first+i*t.stride and readQword(p)==vt then out[#out+1]={id=i,p=p}end
 end
 if K.root()~=root or readQword(root+t.off)~=first then return {} end
 return out
end
function K.scenario()
 local r=K.root();local p=r and readQword(r+0x3A348)
 if p and readQword(p)==K.base()+0xBEB240 then return p end
end
function K.player()
 local s=K.scenario();local p=s and readQword(s+0xB8)
 if K.indexOf('officer',p) then return p end
end
function K.district()
 local p=K.player();local d=p and readQword(p+0xF0)
 if K.indexOf('district',d) then return d end
end
function K.clan()
 local d=K.district();local c=d and readQword(d+0x20)
 if K.indexOf('clan',c) and readQword(c+0xA0)==K.player() then return c end
end
function K.homeCity()
 local lord=K.player();if not lord then return end
 local city
 if readInteger(lord+0x108)==3 then city=readQword(lord+0x100)
 elseif K.nativeCall then city=K.nativeCall('officerResidence','officer',K.indexOf('officer',lord)) end
 if K.indexOf('city',city) then return city end
end
function K.name(kind,p)
 if not K.isType(kind,p) then return '' end
 if kind=='city' then p=K.object('cityName',K.indexOf('city',p));kind='cityName' end
 if not p then return '' end
 local n=readString(p+8,kind=='officer' and 11 or kind=='treasure' and 15 or 13,false) or ''
 if kind=='officer' then n=n..(readString(p+0x13,11,false) or '') end
 return ansiToUtf8(n)
end
function K.key()
 local root=K.root();if not root then return end
 local m=K.base();local scenario=readQword(root+0x3A348)
 if not scenario or readQword(scenario)~=m+0xBEB240 then return end
 local raw=readQword(scenario+0xB8);local player=raw;local t=K.types.officer
 if not K.isType('officer',player) then player=nil
 else
  local first=readQword(root+t.off);local index=first and (player-first)/t.stride
  if not index or index%1~=0 or index&lt;0 or index&gt;=t.count or readQword(root+t.off+index*8)~=player then player=nil end
 end
 if not player then return end
 if readQword(m+0x11B5D18)~=root or readQword(root+0x3A348)~=scenario or readQword(scenario+0xB8)~=raw then return end
 return tostring(K.pid)..':'..tostring(root)..':'..tostring(scenario)..':'..tostring(player)
end
function K.ready()
 if not K.attached() then error(NB.T('Attach to Taishi PK first.','先に大志PKへアタッチしてください。'),0) end
 if not K.clan() then error(NB.T('Load a scenario first.','先にプレイ中のゲームをロードしてください。'),0) end
end

end

do
local sites={
 {0x3FD540,0x100,'48 89 5c 24 08 48 89 6c 24 10'},
 {0x363C40,0x100,'85 ed 75 1c 83 fa 09'},
 {0x1593D0,0x100,'48 89 5c 24 10'},
 {0x12EF9A,0x100,'89 82 88 22 00 00'},
 {0x19276D,0x100,'89 82 88 22 00 00'},
 {0x1B16C5,0x100,'46 89 a4 b0 88 22 00 00'},
 {0x1BC918,0x100,'41 89 84 90 88 22 00 00'},
 {0x1BD0A3,0x100,'41 89 84 91 88 22 00 00'},
 {0x1D4B93,0x100,'43 89 84 a6 88 22 00 00'},
 {0x188B11,0x100,'01 82 88 22 00 00'},
 {0x1D3A50,0x100,'48 8b d1 45 33 c9'},
 {0x488222,0x100,'81 be 00 02 00 00 00 00 00 80'},
 {0x7BD488,0x300,'48 8b cb e8 50 f9 a9 ff'},
 {0x395463,0x100,'e8 48 d8 21 00'},
 {0x358360,0x100,'40 53 48 83 ec 20'},
 {0x486720,0x100,'4c 8b dc 56 57'},
 {0x7BD99F,0x100,'44 8b c7 33 d2'},
 {0x272762,0x100,'fe c8 88 83 96 00 00 00'},
 {0xDEC00,0x100,'48 89 74 24 18'},
 {0x33129F,0x100,'89 44 24 40 e8 18 e2 0d 00'},
 {0x331BDC,0x100,'45 33 c9 45 33 c0'},
 {0x3307B4,0x100,'39 ac 24 a0 00 00 00'},
 {0x331180,0x100,'40 55 56 57 41 54'},
 {0x331B50,0x100,'45 33 c9 45 33 c0'},
 {0x58A520,0x100,'48 83 ec 38 81 fa 0d 01 00 00'},
 {0x3D797D,0x100,'48 8b 8c 24 d8 00 00 00'},
 {0x375F0A,0x100,'8b 00 89 47 0c'},
 {0x40D769,0x100,'85 c0 7f 0f eb 03'},
 {0x40D956,0x100,'85 c0 7f 0f eb 03'},
 {0x3E03BA,0x100,'e8 01 29 1d 00'},
 {0x385255,0x100,'8b 00 89 41 54'},
 {0x3852BA,0x300,'8b 00 89 41 54'},
 {0x3898EC,0x500,'8b 00 89 41 54'},
 {0x389A37,0x700,'8b 00 89 41 54'},
 {0x31632B,0x900,'8b 00 89 41 54'},
 {0x31653A,0xB00,'8b 00 89 41 54'},
 {0x392706,0x100,'8b 05 b8 a1 c8 00'},
 {0x42814D,0x100,'43 8d 0c 80 3b c1'},
 {0x3921BC,0x100,'66 01 83 ae 00 00 00'},
 {0x3923A2,0x100,'66 41 01 47 02'},
 {0x4283A0,0x100,'89 8e dc 0d 00 00'},
 {0x428460,0x300,'89 8e dc 0d 00 00'},
 {0x442F05,0x500,'89 90 dc 0d 00 00'},
 {0x450235,0x700,'89 83 dc 0d 00 00'},
 {0x488DA2,0x900,'89 83 dc 0d 00 00'},
 {0x495E31,0xB00,'89 86 dc 0d 00 00'},
 {0x7A66FD,0xD00,'41 89 8f dc 0d 00 00'}
}
local K=NB.K15
local rawAssemble=autoAssemble
local magic='NB15HK01'
local function bytes(hex)
 local t={};for b in hex:gmatch('%x%x')do t[#t+1]=tonumber(b,16)end;return t
end
local function equal(a,b)
 if not a or #a~=#b then return false end
 for i,v in ipairs(b)do if a[i]~=v then return false end end;return true
end
local function read(at,n)return readBytes(at,n,true)end
local function put(at,b)
 assert(writeBytes(at,b)~=false,'Cannot write hook recovery data')
 assert(equal(read(at,#b),b),'Hook recovery write verification failed')
end
local function str(b)local t={};for i,v in ipairs(b)do t[i]=string.char(v)end;return table.concat(t)end
local function hash(q)
 local b=assert(read(q+0x100,0xF00),'Cannot read hook code');local h=2166136261
 for _,v in ipairs(b)do h=((h~v)*16777619)&amp;0xFFFFFFFF end;return h
end
local function asBytes(s)local t={};for i=1,#s do t[i]=s:byte(i)end;return t end
local known={};for _,s in ipairs(sites)do known[s[1]]={offset=s[2],original=bytes(s[3])}end
function K.assemble(script,info,...)
 if info~=nil then return rawAssemble(script,info,...)end
 local disable=script:match('%[DISABLE%](.*)');local patches={}
 if disable then
  for address,hex in disable:gmatch('([%x]+):%s*\n%s*db%s+([%x ]+)')do
   local at=tonumber(address,16);local original=bytes(hex)
   local def=known[at-K.base()]
   assert(def and equal(def.original,original),'Unregistered Taishi hook site')
   patches[#patches+1]={at=at,original=original}
  end
 end
 if #patches==0 then return rawAssemble(script,info,...)end
 local symbol=script:match('alloc%(([%w_]+),4096,')
 assert(symbol,'Hook recovery requires a dedicated allocation')
 local expanded,n=script:gsub('(alloc%([%w_]+,)4096(,)', '%18192%2')
 assert(n==1,'Unexpected hook allocation count')
 local ok,result=rawAssemble(expanded)
 if not ok then return ok,result end
 local saved,why=pcall(function()
  local q=assert(getAddressSafe(symbol),'Hook allocation missing')
  local payload=string.pack('&lt;I4I4I8I8I4I4',getCheatEngineProcessID(),getOpenedProcessID(),K.base(),q,hash(q),#patches)
  for _,p in ipairs(patches)do
   local installed=assert(read(p.at,#p.original));p.installed=installed
   payload=payload..string.pack('&lt;I4I4',p.at-K.base(),#p.original)..str(p.original)..str(installed)
  end
  local blob=magic..string.pack('&lt;I4',#payload)..payload
  assert(#blob&lt;=4096,'Hook recovery record exceeds reserved page')
  put(q+0x1000,asBytes(blob))
 end)
 if not saved then
  local restored=rawAssemble(script,result)
  assert(restored,'Hook metadata failed and rollback failed: '..tostring(why))
  error(why,0)
 end
 return ok,result
end
function K.recoverOrphanedHooks()
 assert(K.buildMatches(),'Unsupported executable for hook recovery')
 local base=K.base();local groups={};local count=0
 for _,s in ipairs(sites)do
  local def=known[s[1]];local actual=assert(read(base+s[1],#def.original))
  if not equal(actual,def.original)then
   assert(actual[1]==0xE9,'Unrecognized code at '..string.format('%X',s[1]))
   local rel=string.unpack('&lt;i4',str(actual):sub(2,5));local q=base+s[1]+5+rel-s[2]
   groups[q]=true
  end
 end
 local processes=getProcessList();local restore={}
 for q in pairs(groups)do
  local header=read(q+0x1000,12)
  assert(header and str(header):sub(1,8)==magic,'An unmanaged hook remains; automatic recovery was refused')
  local size=string.unpack('&lt;I4',str(header),9);assert(size&gt;=32 and size&lt;=4084,'Invalid hook recovery record')
  local payload=str(assert(read(q+0x100C,size)))
  local owner,pid,m,allocation,checksum,n,pos=string.unpack('&lt;I4I4I8I8I4I4',payload)
  assert(pid==getOpenedProcessID() and m==base and allocation==q,'Hook recovery process mismatch')
  assert(not processes[owner] and not processes[tostring(owner)],'Another running CE still owns these hooks')
  assert(n&gt;=1 and n&lt;=16 and hash(q)==checksum,'Hook recovery code verification failed')
  local seen={}
  for i=1,n do
   local rva,length;rva,length,pos=string.unpack('&lt;I4I4',payload,pos)
   local def=known[rva];assert(def and length==#def.original and not seen[rva],'Invalid hook recovery site');seen[rva]=true
   assert(pos+length*2-1&lt;=#payload,'Truncated hook recovery record')
   local original=asBytes(payload:sub(pos,pos+length-1));pos=pos+length
   local installed=asBytes(payload:sub(pos,pos+length-1));pos=pos+length
   assert(equal(original,def.original) and installed[1]==0xE9,'Hook recovery original mismatch')
   local jump=string.unpack('&lt;i4',str(installed),2)
   assert(base+rva+5+jump-def.offset==q,'Hook recovery allocation mismatch')
   assert(equal(read(base+rva,length),installed),'Hook recovery installed bytes changed')
   if rva==0x58A520 then local state=readInteger(q);assert(state~=1 and state~=2,'A game-thread operation is still pending')end
   restore[#restore+1]={at=base+rva,original=original,installed=installed}
  end
  assert(pos==#payload+1,'Unexpected hook recovery record tail')
 end
 -- Validate every group before any modification. Keep allocations alive for
 -- instructions already executing in a trampoline; the process reclaims them.
 for _,p in ipairs(restore)do assert(equal(read(p.at,#p.installed),p.installed),'Hook changed during recovery')end
 for _,p in ipairs(restore)do put(p.at,p.original);count=count+1 end
 return count
end

end

do
-- x64 Windows ABI: game methods run only on the game's window thread.
local K=NB.K15
K.nativeDefinitions={
 clanHeart={rva=0x35C450,bytes='48 89 5C 24 08 57 48 83 EC 20 48 8B DA 48 8B F9',kind='clan',argumentType='clan'},
 covertWorkTick={rva=0x428020,bytes='40 53 48 83 EC 60 48 8B 05 43 E0 C4 00 48 33 C4',kind='mission',vt=0xBA7130},
 covertWorkFinish={rva=0x3C5510,bytes='40 53 48 83 EC 20 48 8B 01 48 8B D9 FF 90 98 00',kind='mission',vt=0xBA7130},
 officerRecruitmentCheck={rva=0x395330,bytes='40 53 56 57 41 56 48 83 EC 58 48 89 54 24 38 41',kind='officer',argumentType='clan'},
 countyPopulation={rva=0x4AD590,bytes='8B 41 48 C3 CC CC CC CC CC CC CC CC CC CC CC CC',kind='county'},
 countyPopulationAdd={rva=0x3C0F70,bytes='48 83 EC 28 48 8B 05 F5 50 CB 00 48 33 C4 48 89',kind='county'},
 cityDrifters={rva=0x3504F0,bytes='48 89 5C 24 08 57 48 83 EC 20 8B FA 48 8B D9 48',kind='city'},
 policyPointsSet={rva=0x3869D0,bytes='83 FA 05 77 6B 48 83 EC 28 48 8B 05 90 F6 CE 00',kind='clan'},
 officerTraitAdd={rva=0x34E590,bytes='48 89 5C 24 08 57 48 83 EC 20 8B FA 48 8B D9 48',kind='officer'},
 officerTraitSet={rva=0x388CB0,bytes='4C 8B D1 81 FA C7 00 00 00 77 4E 41 83 F8 01 77',kind='officer'},
 officerTraitGet={rva=0x35E560,bytes='4C 8B C9 81 FA C7 00 00 00 77 29 8B C2 99 83 E2',kind='officer'},
 officerFaith={rva=0x4AF0C0,bytes='8B 81 48 02 00 00 48 C1 E8 05 83 E0 03 C3 CC CC',kind='officer'},
 officerOrigin={rva=0x4AF7D0,bytes='8B 81 48 02 00 00 48 C1 E8 07 83 E0 0F C3 CC CC',kind='officer'},
 officerGrade={rva=0x357AC0,bytes='8B 81 48 02 00 00 48 C1 E8 13 83 E0 07 C3 CC CC',kind='officer'},
 cityWorkDaily={rva=0x3920D0,bytes='40 55 56 57 41 54 48 83 EC 68 48 8B 01 48 8B F9',kind='city'},
 cityRepairDaily={rva=0x392670,bytes='48 89 5C 24 18 57 48 83 EC 20 48 8B 81 70 02 00',kind='city'},
 marketIncome={rva=0x4AD720,bytes='B8 00 10 00 00 66 85 81 D4 00 00 00 0F 85 6E B4',kind='market'},
 marketIncomeLimit={rva=0x4AD8F0,bytes='B8 00 10 00 00 66 85 81 D4 00 00 00 0F 85 3E B3',kind='market'},
 officerExperienceAdd={rva=0x3160D0,bytes='83 FA 05 7D 76 48 83 EC 28 48 8B 05 90 FF D5 00',kind='officer'},
 agriculturePopulation={rva=0x3F5460,bytes='48 89 5C 24 08 45 33 D2 4C 8B D9 45 33 C9 66 90',kind='agriculture'},
 agricultureFarmland={rva=0x4AD590,bytes='8B 41 48 C3 CC CC CC CC CC CC CC CC CC CC CC CC',kind='agriculture'},
 agricultureFarmers={rva=0x4AD5C0,bytes='8B 41 40 C3 CC CC CC CC CC CC CC CC CC CC CC CC',kind='agriculture'},
 agricultureSoldiers={rva=0x4FA260,bytes='8B 41 44 C3 CC CC CC CC CC CC CC CC CC CC CC CC',kind='agriculture'},
 agricultureAshigaru={rva=0x4AD5B0,bytes='8B 81 84 00 00 00 C3 CC CC CC CC CC CC CC CC CC',kind='agriculture'},
 agricultureFertility={rva=0x4A8510,bytes='0F B7 81 1C 01 00 00 C3 CC CC CC CC CC CC CC CC',kind='agriculture'},
 agricultureIrrigation={rva=0x4A5B20,bytes='0F B7 81 1E 01 00 00 C3 CC CC CC CC CC CC CC CC',kind='agriculture'},
 armyMoraleGet={rva=0x4ABFE0,bytes='48 8B C4 55 57 41 54 41 56 41 57 48 8D 68 A1 48',kind='army'},
 formationMoraleGet={rva=0x4ABFE0,bytes='48 8B C4 55 57 41 54 41 56 41 57 48 8D 68 A1 48',kind='formation'},
 clanWarWillAdd={rva=0x4501D0,bytes='48 89 5C 24 10 57 48 83 EC 40 48 8B 05 8F 5E C2',kind='clan'},
 districtRiceSet={rva=0x385210,bytes='48 83 EC 28 48 8B 05 55 0E CF 00 48 33 C4 48 89',kind='district'},
 districtRiceSubtract={rva=0x3899F0,bytes='48 83 EC 28 48 8B 05 75 C6 CE 00 48 33 C4 48 89',kind='district'},
 policySet={rva=0x3851C0,bytes='48 83 EC 08 81 FA FF 03 00 00 77 34 48 63 D2 48',kind='clan'},
 policyEffect={rva=0x322310,bytes='44 89 44 24 18 48 89 4C 24 08 53 41 55 41 56 48',kind='clan'},
 treasureTransfer={rva=0x420570,bytes='48 89 5C 24 18 48 89 74 24 20 57 48 83 EC 20 49',kind='officer',argumentType='treasure'},
 officerTreasureUpdate={rva=0x38DC00,bytes='48 85 C9 0F 84 0A 01 00 00 57 48 83 EC 30 48 8B',kind='officer'},
 lordTreasureUpdate={rva=0x38D9C0,bytes='48 85 C9 0F 84 2E 02 00 00 48 8B C4 55 57 41 56',kind='officer'},
 facilityLevelAdd={rva=0x3D19D0,bytes='40 55 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24',kind='county',guardByte={0x165,1}},
 officerResidence={rva=0x3A0130,bytes='48 83 EC 28 80 B9 E8 01 00 00 05 75 2F 48 8B 89',kind='officer'},
 officerLeadership={rva=0xE2D30,bytes='48 83 EC 28 48 8B 05 35 33 F9 00 48 33 C4 48 89',kind='officer'},
 officerLoyalty={rva=0x4A5D00,bytes='40 53 48 83 EC 20 48 8B D9 E8 02 D2 EB FF 85 C0',kind='officer'},
 cityDurability={rva=0x110B60,bytes='48 8B 81 70 02 00 00 33 D2 48 85 C0 74 04 8B 00',kind='city'},
 cityDurabilityMax={rva=0x110BD0,bytes='48 8B 81 70 02 00 00 33 D2 48 85 C0 74 04 8B 00',kind='city'},
 agriculturePopularity={rva=0x3FA830,bytes='48 89 5C 24 08 57 48 83 EC 20 48 8B 05 2F B8 C7',kind='agriculture'}}
function K.nativeBusy()
 local n=K.native;if not n or n.pid~=getOpenedProcessID() then return false end
 local s=readInteger(n.q);return s==1 or s==2
end
function K.installNative()
 if K.native then return end
 K.ready()
 local at=K.base()+0x58A520
 local symbol=('nb15Native_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=([[
[ENABLE]
assert(%X,48 83 EC 38 81 FA 0D 01 00 00)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
label(cancel)
label(done)
label(guarded)
label(argumentsOK)
label(missionGuard)
label(missionLoop)
label(missionFound)
label(targetValid)
@N@:
dq 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
@N@+100:
cmp edx,83D5
jne original
mov rax,@N@
cmp r8,rax
jne original
push rbx
sub rsp,40
mov rbx,@N@
cmp dword ptr [rbx],1
jne done
mov rax,[%X]
cmp rax,[rbx+40]
jne cancel
test rax,rax
jz cancel
mov rdx,[rax+3A348]
cmp rdx,[rbx+48]
jne cancel
test rdx,rdx
jz cancel
mov rdx,[rdx+B8]
cmp rdx,[rbx+50]
jne cancel
mov rdx,[rbx+58]
cmp rdx,-1
je missionGuard
mov r9,[rbx+60]
mov rcx,[rax+rdx]
test rcx,rcx
jz cancel
add rdx,rax
mov rcx,[rdx+r9*8]
cmp rcx,[rbx+10]
jne cancel
test rcx,rcx
jz cancel
mov rdx,[rcx]
cmp rdx,[rbx+68]
jne cancel
targetValid:
mov rax,[rbx+70]
test rax,rax
jz guarded
movzx edx,byte ptr [rcx+rax]
cmp edx,[rbx+78]
jne cancel
guarded:
mov r10,[rbx+80]
test r10,r10
jz argumentsOK
mov rax,[rbx+40]
add rax,r10
mov r10,[rbx+88]
mov rax,[rax+r10*8]
cmp rax,[rbx+18]
jne cancel
test rax,rax
jz cancel
mov r10,[rax]
cmp r10,[rbx+90]
jne cancel
argumentsOK:
mov dword ptr [rbx],2
mov rdx,[rbx+18]
mov r8,[rbx+20]
mov r9,[rbx+28]
call qword ptr [rbx+8]
mov [rbx+30],rax
mov dword ptr [rbx],3
jmp done
missionGuard:
mov r10,[rax+3A340]
test r10,r10
jz cancel
mov r10,[r10+18]
test r10,r10
jz cancel
mov ecx,[r10]
cmp ecx,[%X]
jae cancel
mov r10,[%X]
test r10,r10
jz cancel
mov r10,[r10+rcx*8]
mov r11,[rbx+10]
mov r9d,1000
missionLoop:
test r10,r10
jz cancel
cmp [r10],r11
je missionFound
mov r10,[r10+8]
dec r9d
jnz missionLoop
jmp cancel
missionFound:
mov rcx,r11
test rcx,rcx
jz cancel
mov rdx,[rbx+60]
cmp edx,[rcx+68]
jne cancel
cmp dword ptr [rcx+60],0
jne cancel
mov rdx,[rcx]
cmp rdx,[rbx+68]
jne cancel
mov rdx,[rcx+30]
test rdx,rdx
jz cancel
mov rdx,[rdx+20]
test rdx,rdx
jz cancel
mov r10,[rbx+50]
mov r10,[r10+F0]
test r10,r10
jz cancel
cmp rdx,[r10+20]
jne cancel
jmp targetValid
cancel:
mov dword ptr [rbx],4
done:
add rsp,40
pop rbx
xor eax,eax
ret
original:
sub rsp,38
cmp edx,10D
jmp %X
%X:
jmp @N@+100
nop 5
[DISABLE]
%X:
db 48 83 EC 38 81 FA 0D 01 00 00
unregistersymbol(@N@)
// Keep code until process exit: completion state is published before the
// dispatcher epilogue, so a timed-out sender must not free an in-flight tail.
]]):format(at,at,K.base()+0x11B5D18,K.base()+0x1981950,K.base()+0x1981920,at+10,at,at):gsub('@N@',symbol)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.native={q=assert(getAddressSafe(symbol)),script=script,info=info,pid=K.pid,
  buffer=assert(allocateSharedMemoryLocal(symbol..'_local',4096)),site=at}
 K.native.installed=assert(readBytes(at,10,true))
end
function K.nativeCall(name,kind,index,...)
 K.ready();local d=assert(K.nativeDefinitions[name],'Unknown N15 operation')
 assert(d.kind==kind,'N15 operation target mismatch')
 local p=assert(kind=='mission' and K.missionObject(index,d.vt) or K.object(kind,index),'N15 object unavailable')
 local expected={};for b in d.bytes:gmatch('%x%x') do expected[#expected+1]=tonumber(b,16) end
 local actual=readBytes(K.base()+d.rva,#expected,true);assert(actual,'Unreadable N15 method')
 for i,b in ipairs(expected) do assert(actual[i]==b,'N15 method code changed: '..name) end
 K.installNative();assert(not K.nativeBusy(),'Previous N15 operation is pending')
 local n=K.native;local q=n.q;local args={...};assert(#args&lt;=3,'Too many N15 arguments')
 writeQword(q+8,K.base()+d.rva);writeQword(q+0x10,p)
 for i=1,3 do writeQword(q+0x10+i*8,args[i] or 0) end
 writeQword(q+0x40,K.root());writeQword(q+0x48,K.scenario());writeQword(q+0x50,K.player())
 writeQword(q+0x58,kind=='mission' and -1 or K.types[kind].off);writeQword(q+0x60,index)
 writeQword(q+0x68,K.base()+(kind=='mission' and d.vt or K.types[kind].vt))
 writeQword(q+0x70,d.guardByte and d.guardByte[1] or 0);writeInteger(q+0x78,d.guardByte and d.guardByte[2] or 0)
 if d.argumentType then
  local t=assert(K.types[d.argumentType]);local argumentIndex=assert(K.indexOf(d.argumentType,args[1]),'N15 argument object unavailable')
  writeQword(q+0x80,t.off);writeQword(q+0x88,argumentIndex);writeQword(q+0x90,K.base()+t.vt)
 else writeQword(q+0x80,0) end
 writeInteger(q,1)
 local sent=0;local cached=n.window
 local function send(w)
  if getWindowProcessID(w)==K.pid and executeCodeLocalEx('user32.IsWindowVisible',w)~=0 then
   executeCodeLocalEx('user32.SendMessageTimeoutW',w,0x83D5,q,0,2,2000,n.buffer);sent=sent+1
   if readInteger(q)~=1 then n.window=w;return true end
  end
  return false
 end
 if not cached or not send(cached) then
  local w=executeCodeLocalEx('user32.GetTopWindow',0)
  for _=1,10000 do
   if not w or w==0 then break end
   if w~=cached and send(w) then break end
   w=getWindow(w,2)
  end
 end
 local state=readInteger(q)
 assert(state==3,('N15 operation failed (%s; state %s; windows %d)'):format(name,tostring(state),sent))
 return readQword(q+0x30)
end
function K.removeNative()
 local n=K.native;if not n then return end
 assert(not K.nativeBusy(),'Pending N15 operation must retain its dispatcher')
 if n.pid==getOpenedProcessID() and K.buildMatches() then
  local b=readBytes(n.site,10,true);assert(b,'Cannot read N15 dispatcher')
  for i,v in ipairs(n.installed) do assert(b[i]==v,'N15 dispatcher ownership changed') end
  assert((K.assemble or autoAssemble)(n.script,n.info),'Cannot restore N15 dispatcher')
 end
 K.native=nil
end

end

do
local K=NB.K15
K.fields={officer={},city={},district={}}
K.dropdownRecords=K.dropdownRecords or {}
function K.updateLanguage()
 local keep={}
 for _,entry in ipairs(K.dropdownRecords) do
  local row=getAddressList().getMemoryRecordByID(entry.id)
  if row then
   row.DropDownList.Text=NB.T(entry.field.choicesEn,entry.field.choicesJp)
   keep[#keep+1]=entry
  end
 end
 K.dropdownRecords=keep
end
local abilities={{'Leadership','統率'},{'Valor','武勇'},{'Intelligence','知略'},
 {'Domestic affairs','内政'},{'Foreign affairs','外政'}}
for i,n in ipairs(abilities) do
 for _,v in ipairs({{' (base)','（基本値）',0x131+i,1,255,1},
  {' growth','成長値',0x136+i,0,255,1},
  {' limit','上限',0x13B+i,1,255,1},
  {' experience','経験値',0x16E+i*2,0,10000,2}}) do
  K.fields.officer[#K.fields.officer+1]={en=n[1]..v[1],jp=n[2]..v[2],off=v[3],min=v[4],max=v[5],size=v[6]}
 end
end
for _,field in ipairs({
 {en='Birth year',jp='生年',off=0x12C,min=1,max=9999,size=2},
 {en='Appearance year',jp='登場年',off=0x12E,min=1,max=9999,size=2},
 {en='Death year',jp='没年',off=0x130,min=1,max=9999,size=2},
 {en='Required loyalty',jp='必要忠誠',off=0x24C,min=0,max=15,size=1,mask=15}
}) do K.fields.officer[#K.fields.officer+1]=field end
for _,field in ipairs({
 {en='Faith',jp='信仰',off=0x248,min=0,max=3,size=4,mask=3,shift=5,
  choicesEn='0:None\n1:Buddhism\n2:Ikko\n3:Christianity',choicesJp='0:なし\n1:仏教\n2:一向宗\n3:基督教'},
 {en='Origin',jp='出自',off=0x248,min=0,max=7,size=4,mask=15,shift=7,
  choicesEn='0:Samurai\n1:Noble\n2:Monk\n3:Merchant\n4:Pirate\n5:Ninja\n6:Swordsman\n7:Commoner',
  choicesJp='0:武士\n1:高家\n2:僧侶\n3:商人\n4:海賊\n5:忍者\n6:剣豪\n7:庶民'},
 {en='Grade',jp='格付',off=0x248,min=0,max=3,size=4,mask=7,shift=19,
  choicesEn='0:C\n1:B\n2:A\n3:S',choicesJp='0:Ｃ\n1:Ｂ\n2:Ａ\n3:Ｓ'}
}) do K.fields.officer[#K.fields.officer+1]=field end
K.fields.district={
 {en='Money',jp='金銭',off=0x50,min=0,max=10000000,size=4},
 {en='Rice',jp='兵糧',off=0x54,min=0,max=10000000,size=4},
 {en='Guns',jp='鉄砲',off=0x58,min=0,max=9999999,size=4},
 {en='Horses',jp='軍馬',off=0x5C,min=0,max=9999999,size=4}}
function K.selected(kind)
 if kind=='player' then return K.player() end
 return K.object(kind,K.sel[kind])
end
function K.closeEditor(mr)
 local dead={}
 local function collect(parent)
  for i=0,parent.Count-1 do
   local child=parent.Child[i];dead[child.ID]=true;collect(child)
  end
 end
 collect(mr)
 -- Remove nested dynamic records before CE destroys their native objects.
 -- Accessing a destroyed MemoryRecord inside pcall can still crash CE.
 if NB.dyn then
  local keep={};for _,entry in ipairs(NB.dyn) do if not dead[entry.mr.ID] then keep[#keep+1]=entry end end
  NB.dyn=keep
 end
 local keep={};for _,entry in ipairs(K.dropdownRecords) do if not dead[entry.id] then keep[#keep+1]=entry end end
 K.dropdownRecords=keep
 K.editors[mr.ID]=nil;NB.clearChildren(mr)
end
function K.refreshSuffix()
 for _,e in ipairs({{102,'player'},{403,'officer'},{303,'city'}}) do
  local p=K.selected(e[2]);NB.suffix[e[1]]=p and K.name(e[2]=='player' and 'officer' or e[2],p) or NB.T('(not selected)','（未選択）')
 end
 NB.applyLang();K.updateLanguage()
end
function K.editorType(kind,index,field,token,decode,encode)
 K.editorTypeCache=K.editorTypeCache or {}
 local parts={token,kind,tostring(index)}
 for _,key in ipairs({'off','size','min','max','mask','shift','limitOff','floorOff','computed'})do parts[#parts+1]=tostring(field[key])end
 local key=table.concat(parts,'|');local cached=K.editorTypeCache[key]
 if cached then return cached.name end
 K.typeSerial=(K.typeSerial or 0)+1
 local name=('NB15_%X_%X_%d'):format(K.pid,getTickCount(),K.typeSerial)
 local custom=assert(registerCustomTypeLua(name,field.size,decode,encode,false,false),'Custom editor type unavailable')
 pcall(function()custom.InternalOnly=true end)
 K.editorTypeCache[key]={name=name,custom=custom}
 return name
end
function K.addField(parent,kind,index,field)
 local p=assert(K.object(kind,index));local token=K.key();local at=p+field.off
 local function decode(...)
  local b={...};local v=0
  for i=1,field.size do v=v|((b[i] or 0)&lt;&lt;((i-1)*8)) end
  if field.mask then v=(v&gt;&gt;(field.shift or 0))&amp;field.mask end
  return v
 end
 local function encode(value)
  local current=K.object(kind,index)
  -- CE resolves this record's pointer chain again on every write. If a load
  -- replaced the object, return bytes from the new destination, never bytes
  -- from the captured old object (which would copy stale data into a new save).
  if K.key()~=token or current~=p then
   return current and (readBytes(current+field.off,field.size,true) or {}) or {}
  end
  local unchanged=readBytes(at,field.size,true) or {}
  local v=tonumber(value)
  if not v or v~=v or math.abs(v)==math.huge then return unchanged end
  v=math.max(field.min,math.min(field.max,math.floor(v)))
  if field.limitOff then v=math.min(v,assert(readSmallInteger(p+field.limitOff))&amp;0xFFFF) end
  if field.floorOff then v=math.max(v,assert(readSmallInteger(p+field.floorOff))&amp;0xFFFF) end
  if field.mask then
   local raw=0;for i=1,field.size do raw=raw|((unchanged[i] or 0)&lt;&lt;((i-1)*8)) end
   local shift=field.shift or 0;local mask=field.mask&lt;&lt;shift
   v=(raw&amp;(~mask))|((v&amp;field.mask)&lt;&lt;shift)
  end
  local b={};for i=1,field.size do b[i]=(v&gt;&gt;((i-1)*8))&amp;255 end
  return b
 end
 local typeName=K.editorType(kind,index,field,token,decode,encode)
 local row=NB.addRec(parent,field.en,field.jp,K.EXE..'+11B5D18',vtCustom)
 row.OffsetCount=2;row.Offset[0]=field.off;row.Offset[1]=K.types[kind].off+index*8
 row.CustomTypeName=typeName
 if field.choicesEn then
  row.DropDownList.Text=NB.T(field.choicesEn,field.choicesJp)
  row.DropDownReadOnly=true;row.DropDownDescriptionOnly=true;row.DisplayAsDropDownListItem=true
  K.dropdownRecords[#K.dropdownRecords+1]={id=row.ID,field=field}
 end
 row.OnActivate=function(_,before)
  if before then return K.key()==token and K.object(kind,index)==p end
  return true
 end
 return row
end
function K.openEditor(mr,kind)
 K.ready();K.closeEditor(mr)
 local p=K.selected(kind)
 if not p then NB.msg('Select an officer/city first.','先に武将・都市を選択してください。');return end
 local target=kind=='player' and 'officer' or kind
 local index=assert(K.indexOf(target,p))
 for _,field in ipairs(K.fields[target]) do K.addField(mr,target,index,field) end
 if kind=='player' then
  local d=assert(K.indexOf('district',K.district()))
  for _,field in ipairs(K.fields.district) do K.addField(mr,'district',d,field) end
 end
 K.editors[mr.ID]={mr=mr,kind=kind};mr.Collapsed=false;K.refreshSuffix()
end
function K.select(kind,index)
 K.ready();assert(K.object(kind,index),'N15 selection unavailable')
 local reopen={}
 for _,e in pairs(K.editors) do if e.kind==kind then reopen[#reopen+1]=e.mr end end
 for _,mr in ipairs(reopen) do K.closeEditor(mr) end
 K.sel[kind]=index
 for _,mr in ipairs(reopen) do K.openEditor(mr,kind) end
 K.refreshSuffix()
end
function K.search(kind)
 K.ready()
 local query=inputQuery(NB.T('Search name','名前を検索'),NB.T('Part of name; blank lists all:','名前の一部を入力。空欄は全件表示：'),'')
 if query==nil then return end
 local ids,names={},{}
 for _,item in ipairs(K.objects(kind)) do
  local name=K.name(kind,item.p)
  if name~='' and name:find(query,1,true) then
   ids[#ids+1]=item.id;names[#names+1]=('%s [ID %d]'):format(name,item.id)
  end
 end
 if #ids==0 then NB.msg('Not found.','見つかりません。');return end
 local n=NB.pick(NB.T('Select result','候補を選択'),names)
 if n then K.select(kind,ids[n]) end
end

end

do
local K=NB.K15
K.types.market={off=0x13C98,count=782,stride=0x130,vt=0xBE6D50}
K.fields.market={
 {en='Market income',jp='商圏収益',off=0xD6,min=0,max=10000,size=2,limitOff=0xD8},
 {en='Market income limit',jp='商圏収益上限',off=0xD8,min=0,max=10000,size=2,floorOff=0xD6},
 {en='Investment potential (before modifiers)',jp='投資の上昇余地（補正前）',off=0xDA,min=0,max=10000,size=2}}
K.fields.county={{en='Population',jp='人口',off=0x48,min=0,max=999999,size=4}}
function K.countiesForCity(city)
 if not K.indexOf('city',city) then return {} end
 local result={}
 for _,p in ipairs(K.linkedObjects(readQword(city+0xB8))) do
  local id=K.indexOf('county',p)
  if id and readQword(p+0x28)==city then result[#result+1]={id=id,p=p} end
 end
 return result
end
function K.marketIndex()
 local result={}
 for _,item in ipairs(K.objects('market')) do
  local county=readQword(item.p+0x38)
  if K.indexOf('county',county) and ((readSmallInteger(item.p+0xD4) or 0)&amp;0x1000)==0 then
   local city=readQword(county+0x28)
   if city then result[city]=result[city] or {};result[city][#result[city]+1]=item end
  end
 end
 return result
end
function K.marketsForCity(city,index)
 if not K.indexOf('city',city) then return {} end
 return (index or K.marketIndex())[city] or {}
end
-- All pointer-list reads are bounded and reject cycles before any caller writes.
function K.linkedObjects(handle)
 if not handle or handle&lt;0x10000 then return {} end
 local m=K.base();local index=readInteger(handle)
 local count=readInteger(m+0x1981950);local heads=readQword(m+0x1981920)
 if not index or not count or index&gt;=count or not heads or heads&lt;0x10000 then return {} end
 local node=readQword(heads+index*8);local result,seen={},{}
 while node and node~=0 do
  assert(node&gt;=0x10000 and not seen[node] and #result&lt;20000,'N15 object list is invalid')
  seen[node]=true
  local p=readQword(node);assert(p and p&gt;=0x10000,'N15 list item is unreadable')
  result[#result+1]=p;node=readQword(node+8)
 end
 return result
end
function K.agricultureForCity(city)
 if not K.indexOf('city',city) then return end
 for _,p in ipairs(K.linkedObjects(readQword(city+0xC8))) do
  if K.indexOf('agriculture',p) and readQword(p+0x30)==city then return p end
 end
end
K.fields.agriculture={
 {en='Farmers',jp='農民',off=0x40,min=0,max=99999,size=4},
 {en='Farmer soldiers',jp='農兵',off=0x44,min=0,max=99999,size=4},
 {en='Farmland',jp='農地',off=0x48,min=0,max=99999,size=4},
 {en='Ashigaru',jp='足軽',off=0x84,min=0,max=99999,size=4},
 {en='Popularity',jp='民忠',off=0x8A,min=0,max=100,size=2,computed='popularity'},
 {en='Fertility',jp='肥沃度',off=0x11C,min=0,max=100,size=2},
 {en='Irrigation',jp='治水',off=0x11E,min=0,max=100,size=2}}
function K.popularityModifiers(p)
 local bytes=assert(readBytes(p+0xA4,60,true),'Cannot read N15 popularity modifiers')
 local sum=0;for _,b in ipairs(bytes) do sum=sum+(b&gt;=128 and b-256 or b) end
 return sum
end
local add=K.addField
function K.addField(parent,kind,index,field)
 if field.computed~='popularity' then return add(parent,kind,index,field) end
 local p=assert(K.object(kind,index));local at=p+field.off;local token=K.key()
 local typeName=K.editorType(kind,index,field,token,function(a,b)
  local value=a|(b&lt;&lt;8);if value&gt;=32768 then value=value-65536 end
  if K.key()~=token or K.object(kind,index)~=p then return 0 end
  return math.max(0,math.min(100,value+K.popularityModifiers(p)))
 end,function(value)
  local current=K.object(kind,index)
  if K.key()~=token or current~=p then
   return current and (readBytes(current+field.off,2,true) or {0,0}) or {0,0}
  end
  local old=readBytes(at,2,true) or {0,0}
  local v=tonumber(value);if not v or v~=v or math.abs(v)==math.huge then return old end
  v=math.max(0,math.min(100,math.floor(v)))-K.popularityModifiers(p)
  assert(v&gt;=-32768 and v&lt;=32767,'N15 popularity base out of range')
  return {v&amp;255,(v&gt;&gt;8)&amp;255}
 end)
 local row=NB.addRec(parent,field.en,field.jp,K.EXE..'+11B5D18',vtCustom)
 row.OffsetCount=2;row.Offset[0]=field.off;row.Offset[1]=K.types[kind].off+index*8
 row.CustomTypeName=typeName
 row.OnActivate=function(_,before) if before then return K.key()==token and K.object(kind,index)==p end;return true end
 return row
end
local open=K.openEditor
function K.openEditor(mr,kind)
 open(mr,kind)
 if kind=='city' then
  local city=K.selected('city');local district=city and readQword(city+8)
  local districtId=K.indexOf('district',district)
  if districtId then
   for _,field in ipairs(K.fields.district) do
    local named={};for key,value in pairs(field) do named[key]=value end
    named.en='District: '..field.en;named.jp='軍団共有：'..field.jp
    K.addField(mr,'district',districtId,named)
   end
  end
  local p=K.agricultureForCity(K.selected('city'))
  if p then
   local index=assert(K.indexOf('agriculture',p))
   for _,field in ipairs(K.fields.agriculture) do K.addField(mr,'agriculture',index,field) end
  end
  for _,item in ipairs(K.marketsForCity(K.selected('city'))) do
   local name=K.name('market',item.p)
   for _,field in ipairs(K.fields.market) do
    local named={};for key,value in pairs(field) do named[key]=value end
    named.en=name..': '..field.en;named.jp=name..'：'..field.jp
    K.addField(mr,'market',item.id,named)
   end
  end
  for _,item in ipairs(K.countiesForCity(K.selected('city'))) do
   local name=K.name('county',item.p)
   local group=NB.addRec(mr,'County: '..name,'郡：'..name,'0',vtDword)
   group.IsGroupHeader=true
   group.Options='[moManualExpandCollapse]'
   for _,field in ipairs(K.fields.county) do K.addField(group,'county',item.id,field) end
   if K.addFacilityEditor then K.addFacilityEditor(group,item,mr) end
   group.Collapsed=true
  end
 end
end

end

do
local K=NB.K15
K.fields.clan={
 {en='War will',jp='戦意',off=0xDDC,min=0,max=10000,size=4},
 {en='Agriculture policy points',jp='農業施策力',off=0xDF4,min=0,max=9999,size=2},
 {en='Commerce policy points',jp='商業施策力',off=0xDF6,min=0,max=9999,size=2},
 {en='Discussion policy points',jp='論議施策力',off=0xDF8,min=0,max=9999,size=2},
 {en='Military policy points',jp='軍事施策力',off=0xDFA,min=0,max=9999,size=2},
 {en='Grand command policy points',jp='大命施策力',off=0xDFC,min=0,max=9999,size=2}}
local open=K.openEditor
function K.openEditor(mr,kind)
 open(mr,kind)
 if kind=='player' then
  local index=assert(K.indexOf('clan',K.clan()))
  for _,field in ipairs(K.fields.clan) do K.addField(mr,'clan',index,field) end
 end
end
function K.availablePolicies()
 local result={}
 for _,item in ipairs(K.objects('policy')) do
  local name=K.name('policy',item.p)
  if name~='' and name~='--' then result[#result+1]=item end
 end
 return result
end
function K.acquireAllPolicies()
 K.ready();local clan=K.clan();local index=assert(K.indexOf('clan',clan));local count=0
 for _,item in ipairs(K.availablePolicies()) do
  if readBytes(clan+0xE40+item.id,1)~=1 then
   -- Native setter invalidates the 512-entry effect cache as in normal play.
   K.nativeCall('policySet','clan',index,item.id,1)
   assert(readBytes(clan+0xE40+item.id,1)==1,'N15 policy acquisition did not apply')
   count=count+1
  end
 end
 NB.msg(('Acquired %d policies.'):format(count),('方策を%d件取得しました。'):format(count))
 return count
end

end

do
local K=NB.K15
function K.ownsOfficer(p)
 if not K.indexOf('officer',p) or readBytes(p+0x1E8,1)~=7 then return false end
 local d=readQword(p+0xF0)
 return K.indexOf('district',d)~=nil and readQword(d+0x20)==K.clan()
end
function K.giveTreasure(officer,treasure)
 K.ready();assert(K.ownsOfficer(officer),'Recipient is no longer in your clan')
 assert(K.indexOf('treasure',treasure),'N15 treasure unavailable')
 local index=assert(K.indexOf('officer',officer))
 K.nativeCall('treasureTransfer','officer',index,treasure,officer)
 assert(readQword(treasure+0x50)==officer,'N15 treasure ownership did not change')
 if officer==K.player() then K.nativeCall('lordTreasureUpdate','officer',index) end
 K.nativeCall('officerTreasureUpdate','officer',index)
end
function K.treasureCategories()
 K.ready();local token=K.key();local all=K.objects('treasure')
 local english={'Tea utensils','Weapons','Horses','Books','Paintings','Incense utensils','Western imports','Chinese imports'}
 local labels={}
 for i=0,7 do
  local p=readQword(K.base()+0x103FDC0+i*8)
  local s=p and readString(p,64,false);assert(s,'N15 treasure category is unreadable')
  labels[#labels+1]=NB.T(english[i+1],ansiToUtf8(s))
 end
 return labels,all,token
end
-- Read bounded chunks instead of resolving the root and object type for
-- every field of every officer. The live recipient is revalidated on grant.
function K.treasureRecipients()
 K.ready();local token=K.key();local root=assert(K.root());local clan=assert(K.clan());local base=K.base()
 local function vector(kind)
  local t=K.types[kind];local b=assert(readBytes(root+t.off,t.count*8,true))
  local function q(i)local v=0;for n=7,0,-1 do v=(v&lt;&lt;8)|b[i+n]end;return v end
  local first=q(1);assert(first&gt;=0x10000,'Invalid treasure recipient vector')
  for i=0,t.count-1 do assert(q(i*8+1)==first+i*t.stride,'Treasure recipient vector changed')end
  return first,t
 end
 local function q(b,off)local v=0;for n=7,0,-1 do v=(v&lt;&lt;8)|b[off+n+1]end;return v end
 local districts={};local first,typ=vector('district')
 for i=0,typ.count-1 do
  local at=first+i*typ.stride;local b=assert(readBytes(at,0x28,true))
  assert(q(b,0)==base+typ.vt,'Invalid recipient district')
  if q(b,0x20)==clan then districts[at]=true end
 end
 first,typ=vector('officer');local officers,names={},{}
 local function text(b,off,n)
  local chars={};for i=1,n do local v=b[off+i];if v==0 then break end;chars[#chars+1]=string.char(v)end
  return table.concat(chars)
 end
 for start=0,typ.count-1,32 do
  local count=math.min(32,typ.count-start);local b=assert(readBytes(first+start*typ.stride,count*typ.stride,true))
  for i=0,count-1 do
   local off=i*typ.stride;assert(q(b,off)==base+typ.vt,'Invalid recipient officer')
   if b[off+0x1E8+1]==7 and districts[q(b,off+0xF0)]then
    local id=start+i;officers[#officers+1]={id=id,p=first+id*typ.stride}
    names[#names+1]=ansiToUtf8(text(b,off+8,11)..text(b,off+0x13,11))
   end
  end
 end
 assert(K.key()==token,'Game data changed while reading recipients')
 return officers,names
end
function K.closeTreasureWizard()
 if not inMainThread()then synchronize(K.closeTreasureWizard);return end
 if K.treasureLaunchTimer then K.treasureLaunchTimer.destroy();K.treasureLaunchTimer=nil end
 local w=K.treasureWizard
 if w then w.form.close() end
end
function K.openTreasureWizard()
 if not inMainThread()then synchronize(K.openTreasureWizard);return end
 K.ready()
 if K.treasureWizard then K.treasureWizard.form.bringToFront();return end
 local labels,all,token=K.treasureCategories()
 local form=createForm(false);NB.UI.styleForm(form)
 local w={form=form,token=token,page=1,remember={},all=all,categories=labels}
 K.treasureWizard=w
 form.Name='N15TreasureWizard'
 form.ClientWidth=840;form.ClientHeight=620
 form.OnClose=function()
  if w.inGrant then w.cancelRequested=true;return caNone or 0 end
  if w.grantTimer then w.grantTimer.destroy();w.grantTimer=nil end
  if K.treasureWizard==w then K.treasureWizard=nil end
  return caFree
 end
 local hint=createLabel(form);hint.Left=12;hint.Top=12;hint.Width=816;hint.Font.Color=NB.UI.muted
 local picker=NB.UI.createList(form,{top=42,name='TreasureChoices'});local list=picker.list
 w.list=list;w.hint=hint
 local function button(name,caption,left,width)
  local b=createButton(form);b.Name=name;b.Caption=caption;b.Left=left;b.Top=466;b.Width=width;b.Height=32;return b
 end
 local allButton=button('TreasureAll',NB.T('Select shown','表示中を選択'),12,140)
 local clearButton=button('TreasureClear',NB.T('Clear selection','選択解除'),160,116)
 local back=button('TreasureBack',NB.T('Back','戻る'),338,100)
 local nextButton=button('TreasureNext',NB.T('Next','次へ'),446,110)
 nextButton.Default=true
 local cancel=button('TreasureCancel',NB.T('Cancel','キャンセル'),564,124);cancel.Cancel=true
 w.next=nextButton;w.back=back;w.cancel=cancel;w.allButton=allButton;w.clearButton=clearButton
 local function selected()return picker.selected()end
 picker.onSelectionChanged=function(n)if not w.busy then nextButton.Enabled=n&gt;0 end end
 local function layout()
  picker.layout();local width,height=form.ClientWidth,form.ClientHeight;hint.Width=width-24
  back.Left=width-362;nextButton.Left=width-254;cancel.Left=width-136
  for _,b in ipairs({allButton,clearButton,back,nextButton,cancel})do b.Top=height-46 end
 end
 form.OnResize=layout;layout()
 local function show(page,names,remember)
  w.page=page;picker.setRows(names,page==2,remember)
  back.Enabled=page&gt;1;allButton.Visible=page==2;clearButton.Visible=page==2
  form.Caption=page==1 and NB.T('Treasure category','家宝の分類') or page==2 and NB.T('Select treasures','家宝を複数選択') or NB.T('Recipient officer','授与先の武将')
  hint.Caption=page==2 and NB.T('Ctrl / Shift: select multiple treasures','Ctrl / Shiftで複数の家宝を選択できます') or NB.T('Select an entry.','項目を選択してください。')
  nextButton.Caption=page==3 and NB.T('Assign','授与') or NB.T('Next','次へ')
 end
 local function itemPage()
  w.items={};w.itemNames={}
  for _,item in ipairs(w.all)do
   if readInteger(item.p+0x68)==w.category then
    w.items[#w.items+1]=item;w.itemNames[#w.itemNames+1]=K.name('treasure',item.p)
   end
  end
  show(2,w.itemNames,w.remember[w.category])
 end
 local function guard()
  K.ready();assert(K.key()==token,NB.T('Game data changed; reopen the treasure list.','ゲームデータが変わりました。家宝一覧を開き直してください。'))
 end
 local function run(fn)
  if w.busy then return end
  local ok,why=pcall(fn)
  if not ok then hint.Caption=NB.T('Operation failed. See Lua Engine.','処理できませんでした。Lua Engineを確認してください。');NB.msg(tostring(why)) end
 end
 nextButton.OnClick=function()run(function()
  guard();local choices=selected()
  if #choices==0 then hint.Caption=NB.T('Select at least one entry.','項目を1件以上選択してください。');return end
  if w.page==1 then
   w.categoryChoice=choices;w.category=choices[1]-1;itemPage()
  elseif w.page==2 then
   w.remember[w.category]=choices
   if not w.officers then w.officers,w.officerNames=K.treasureRecipients()end
   show(3,w.officerNames,w.recipient)
  else
   w.recipient=choices;local officer=assert(w.officers[choices[1]])
   w.busy=true;nextButton.Enabled=false;back.Enabled=false
   local queue={};for _,i in ipairs(w.remember[w.category])do queue[#queue+1]=assert(w.items[i]).p end
   local done=0;local timer=createTimer(nil,false);w.grantTimer=timer;timer.Interval=25
   timer.OnTimer=function(t)
    t.Enabled=false
    if K.treasureWizard~=w then return end
    w.inGrant=true
    local ok,why=pcall(function()
     guard();K.giveTreasure(officer.p,queue[done+1]);done=done+1
    end)
    w.inGrant=false
    if w.cancelRequested then t.destroy();w.grantTimer=nil;w.busy=false;form.close();return end
    if not ok then
     t.destroy();w.grantTimer=nil;w.busy=false;nextButton.Enabled=true;back.Enabled=true
     hint.Caption=NB.T('Assignment stopped. See Lua Engine.','授与を中断しました。Lua Engineを確認してください。');NB.msg(tostring(why));return
    end
    hint.Caption=NB.T('Assigned: ','授与済み：')..done..' / '..#queue
    if done==#queue then
     t.destroy();w.grantTimer=nil;w.busy=false
     NB.msg(('Assigned %d treasures.'):format(done),('家宝を%d件授与しました。'):format(done));form.close()
    else t.Enabled=true end
   end
   timer.Enabled=true
  end
 end)end
 back.OnClick=function()run(function()
  if w.page==3 then w.recipient=selected();itemPage()
  elseif w.page==2 then w.remember[w.category]=selected();show(1,w.categories,w.categoryChoice)end
 end)end
 allButton.OnClick=picker.selectVisible
 clearButton.OnClick=picker.clearAll
 cancel.OnClick=function()form.close()end
 list.OnDblClick=function()if w.page~=2 then nextButton.OnClick()end end
 show(1,labels);form.show()
end
function K.assignTreasure()
 K.ready()
 if not inMainThread()then synchronize(K.assignTreasure);return end
 if K.treasureWizard then K.treasureWizard.form.bringToFront();return end
 if K.treasureLaunchTimer then return end
 -- AA checkbox execution must return before the interactive wizard opens.
 local timer=createTimer(nil,false);K.treasureLaunchTimer=timer;timer.Interval=1
 timer.OnTimer=function(t)
  t.destroy();K.treasureLaunchTimer=nil
  local ok,why=pcall(K.openTreasureWizard)
  if not ok then K.closeTreasureWizard();NB.msg(tostring(why))end
 end
 timer.Enabled=true
end

end

do
local K=NB.K15
function K.ownCounty(p)
 if not K.indexOf('county',p) then return false end
 local city=readQword(p+0x28)
 if not K.indexOf('city',city) then return false end
 local district=readQword(city+8)
 return K.indexOf('district',district)~=nil and readQword(district+0x20)==K.clan()
end
function K.ownedCitySet()
 local token=K.key();local clan=K.clan();local districts,owned={},{}
 for _,item in ipairs(K.objects('district'))do
  if readQword(item.p+0x20)==clan then districts[item.p]=true end
 end
 for _,item in ipairs(K.objects('city'))do
  if districts[readQword(item.p+8)]then owned[item.p]=true end
 end
 assert(K.key()==token,'City ownership data changed')
 return owned
end
function K.constructionOrders()
 K.ready();local result={}
 for _,item in ipairs(K.objects('county')) do
  if readBytes(item.p+0x165,1)==1 and K.ownCounty(item.p) then
   local facility=readQword(item.p+0x150)
   if K.indexOf('facility',facility) then
    result[#result+1]={id=item.id,p=item.p,facility=facility,
     level=readBytes(item.p+0x164,1),progress=readSmallInteger(item.p+0x160)}
   end
  end
 end
 return result
end
function K.finishConstruction()
 local orders=K.constructionOrders();local finished=0
 for _,order in ipairs(orders) do
  if readBytes(order.p+0x165,1)==1 and K.ownCounty(order.p)
    and readQword(order.p+0x150)==order.facility then
   -- The game's completion path updates levels, effects, worker assignment,
   -- event notifications and the county UI. Do not fake only its progress.
   K.nativeCall('facilityLevelAdd','county',order.id,1,0)
   assert(readBytes(order.p+0x164,1)==order.level+1,'N15 facility level did not advance')
   assert(readBytes(order.p+0x165,1)~=1,'N15 facility is still under construction')
   finished=finished+1
  end
 end
 return finished
end

end

do
local K=NB.K15
function K.makeTroopScript(at,symbol,armyVT,rootSlot,enemyCheck)
 return ([[
[ENABLE]
assert(%X,4C 8B DC 56 57 41 56 48 83 EC 50)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(done)
label(other)
label(original)
label(moraleDone)
label(siegeDefender)
label(siegeGauge)
label(protect)
@N@:
dd 0 0 0 0 0 0 0 0
@N@+100:
pushfq
push rax
push rcx
push rdx
push r8
push r9
push r10
push r11
sub rsp,88
movdqu [rsp+20],xmm0
movdqu [rsp+30],xmm1
movdqu [rsp+40],xmm2
movdqu [rsp+50],xmm3
movdqu [rsp+60],xmm4
movdqu [rsp+70],xmm5
mov rax,%X
cmp [rcx],rax
jne done
test byte ptr [rcx+200],1
jz done
cmp dword ptr [rcx+18],0
jle done
mov rax,[%X]
test rax,rax
jz done
mov rax,[rax+3A348]
test rax,rax
jz done
mov rax,[rax+B8]
test rax,rax
jz done
mov r9,rax
mov rax,[rax+F0]
test rax,rax
jz done
mov r8,[rax+20]
test r8,r8
jz done
mov rdx,[rcx+8]
test rdx,rdx
jz done
mov rdx,[rdx+20]
test rdx,rdx
jz done
cmp rdx,r8
jne other
cmp dword ptr [@N@],0
jne protect
cmp dword ptr [@N@+8],0
je done
cmp dword ptr [r9+108],4
jne done
cmp [r9+100],rcx
jne done
cmp [r9+110],rcx
jne done
protect:
// +204 is the deployed total. +208 is the farmer-soldier share, calculated
// by native 488760 from the agriculture's farmer/ashigaru ratio.
mov eax,[rcx+204]
test eax,eax
jle done
cmp eax,1869F
ja done
mov [rcx+18],eax
mov dword ptr [rcx+1C],0
// Siege UI uses the side gauge, not the clan's war-will value.
// Keep each own army at its existing morale cap; the shared side gauge uses
// the largest cap of participating armies (matching the native UI divisor).
mov eax,[rcx+2AC]
test eax,eax
jle moraleDone
cmp eax,2710
ja moraleDone
mov [rcx+2A8],eax
mov rdx,[rcx+330]
test rdx,rdx
jz moraleDone
cmp qword ptr [rcx+298],0
je siegeDefender
add rdx,10
jmp siegeGauge
siegeDefender:
add rdx,28
siegeGauge:
cmp [rdx+10],eax
jge moraleDone
mov [rdx+10],eax
moraleDone:
inc dword ptr [@N@+10]
jmp done
other:
cmp dword ptr [@N@+4],0
je done
cmp dword ptr [rcx+1C],0
jle done
mov rcx,rdx
mov rdx,r8
call %X
test eax,eax
jz done
mov r11,[rsp+B0]
mov eax,[r11+18]
mov [r11+1C],eax
inc dword ptr [@N@+14]
done:
movdqu xmm0,[rsp+20]
movdqu xmm1,[rsp+30]
movdqu xmm2,[rsp+40]
movdqu xmm3,[rsp+50]
movdqu xmm4,[rsp+60]
movdqu xmm5,[rsp+70]
add rsp,88
pop r11
pop r10
pop r9
pop r8
pop rdx
pop rcx
pop rax
popfq
original:
mov r11,rsp
push rsi
push rdi
jmp %X
%X:
jmp @N@+100
[DISABLE]
%X:
db 4C 8B DC 56 57
unregistersymbol(@N@)
// Retain this small allocation until process exit: an in-flight hook must not
// return into freed code when a feature is disabled while the game is running.
]]):format(at,at,armyVT,rootSlot,enemyCheck,at+5,at,at):gsub('@N@',symbol)
end
function K.installTroopHook()
 if K.troopHook then return end
 K.ready();local m=K.base();local at=m+0x486720
 local symbol=('nb15Troops_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeTroopScript(at,symbol,m+0xBEAF40,m+0x11B5D18,m+0x39DDC0)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.troopHook={q=assert(getAddressSafe(symbol)),script=script,info=info,pid=K.pid,at=at}
 K.troopHook.installed=readBytes(at,5,true)
end
function K.removeTroopHook()
 local h=K.troopHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local b=assert(readBytes(h.at,5,true))
  for i,v in ipairs(h.installed) do assert(b[i]==v,'N15 troop hook ownership changed') end
  writeInteger(h.q,0);writeInteger(h.q+4,0);writeInteger(h.q+8,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'N15 troop hook restoration failed')
 end
 K.troopHook=nil
end
function K.troopFeature(name,on)
 if on then K.installTroopHook() end
 local h=K.troopHook
 if h then writeInteger(h.q+(name=='battleOneHit' and 4 or 0),on and 1 or 0) end
end

end

do
local K=NB.K15
-- Setter, subtraction and signed-add paths all converge on the same 5-byte
-- store. Guard each path so consumption cannot bypass a timer between frames.
K.foodStoreSites={0x385255,0x3852BA,0x3898EC,0x389A37,0x31632B,0x31653A}
function K.installFoodHook()
 if K.foodHook then return end
 K.ready();local m=K.base()
 local symbol=('nb15Food_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local enable={'[ENABLE]',('alloc(%s,4096,%X)'):format(symbol,m+K.foodStoreSites[1]),
  'registersymbol('..symbol..')',symbol..':','dd 0'}
 local disable={'[DISABLE]'};local installed={}
 for i,rva in ipairs(K.foodStoreSites) do
  local at=m+rva;local code=('%s+%X'):format(symbol,0x100+(i-1)*0x200)
  local original,done='foodOriginal'..i,'foodMax'..i
  enable[#enable+1]=([[
assert(%X,8B 00 89 41 54)
label(%s)
label(%s)
%s:
pushfq
push rax
push r10
push r11
cmp dword ptr [%s],0
je %s
mov rax,%X
cmp [rcx],rax
jne %s
mov r11,[rcx+20]
test r11,r11
jz %s
mov r10,[%X]
test r10,r10
jz %s
mov r10,[r10+3A348]
test r10,r10
jz %s
mov r10,[r10+B8]
test r10,r10
jz %s
mov r10,[r10+F0]
test r10,r10
jz %s
cmp r11,[r10+20]
je %s
%s:
pop r11
pop r10
pop rax
popfq
mov eax,[rax]
mov [rcx+54],eax
jmp %X
%s:
mov dword ptr [rcx+54],989680
pop r11
pop r10
pop rax
popfq
mov eax,989680
jmp %X
%X:
jmp %s
]]):format(at,original,done,code,symbol,original,m+0xBE0840,original,original,
   m+0x11B5D18,original,original,original,original,done,original,at+5,done,at+5,at,code)
  disable[#disable+1]=('%X:\ndb 8B 00 89 41 54'):format(at)
 end
 disable[#disable+1]='unregistersymbol('..symbol..')'
 local script=table.concat(enable,'\n')..'\n'..table.concat(disable,'\n')
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 for _,rva in ipairs(K.foodStoreSites) do installed[rva]=readBytes(m+rva,5,true) end
 K.foodHook={q=assert(getAddressSafe(symbol)),pid=K.pid,script=script,info=info,installed=installed}
end
function K.removeFoodHook()
 local h=K.foodHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  for rva,expected in pairs(h.installed) do
   local b=assert(readBytes(K.base()+rva,5,true))
   for i,v in ipairs(expected) do assert(b[i]==v,'N15 food hook ownership changed') end
  end
  writeInteger(h.q,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'N15 food hook restoration failed')
 end
 K.foodHook=nil
end
function K.foodFeature(on)
 if on then K.installFoodHook() end
 if K.foodHook then writeInteger(K.foodHook.q,on and 1 or 0) end
end

end

do
local K=NB.K15
K.warWillSites={
 {0x4283A0,'rsi','ecx','89 8E DC 0D 00 00'},
 {0x428460,'rsi','ecx','89 8E DC 0D 00 00'},
 {0x442F05,'rax','edx','89 90 DC 0D 00 00'},
 {0x450235,'rbx','eax','89 83 DC 0D 00 00'},
 {0x488DA2,'rbx','eax','89 83 DC 0D 00 00'},
 {0x495E31,'rsi','eax','89 86 DC 0D 00 00'},
 {0x7A66FD,'r15','ecx','41 89 8F DC 0D 00 00'}}
function K.installWarWillHook()
 if K.warWillHook then return end
 K.ready();local m=K.base()
 local symbol=('nb15Will_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local enable={'[ENABLE]',('alloc(%s,4096,%X)'):format(symbol,m+0x450235),
  'registersymbol('..symbol..')',symbol..':','dd 0'}
 local disable={'[DISABLE]'};local installed={}
 for i,s in ipairs(K.warWillSites) do
  local at=m+s[1];local length=0;for _ in s[4]:gmatch('%x%x') do length=length+1 end
  local code=('%s+%X'):format(symbol,0x100+(i-1)*0x200)
  local original,force='willOriginal'..i,'willMax'..i
  enable[#enable+1]=([[
assert(%X,%s)
label(%s)
label(%s)
%s:
pushfq
push rax
push r10
push r11
cmp dword ptr [%s],0
je %s
mov r11,%s
mov rax,%X
cmp [r11],rax
jne %s
mov r10,[%X]
test r10,r10
jz %s
mov r10,[r10+3A348]
test r10,r10
jz %s
mov r10,[r10+B8]
test r10,r10
jz %s
mov r10,[r10+F0]
test r10,r10
jz %s
cmp r11,[r10+20]
je %s
%s:
pop r11
pop r10
pop rax
popfq
mov [%s+DDC],%s
jmp %X
%s:
pop r11
pop r10
pop rax
popfq
mov %s,2710
mov [%s+DDC],%s
jmp %X
%X:
jmp %s
nop %d
]]):format(at,s[4],original,force,code,symbol,original,s[2],m+0xBE0758,original,
   m+0x11B5D18,original,original,original,original,force,original,s[2],s[3],at+length,
   force,s[3],s[2],s[3],at+length,at,code,length-5)
  disable[#disable+1]=('%X:\ndb %s'):format(at,s[4])
 end
 disable[#disable+1]='unregistersymbol('..symbol..')'
 local script=table.concat(enable,'\n')..'\n'..table.concat(disable,'\n')
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 for _,s in ipairs(K.warWillSites) do
  local n=0;for _ in s[4]:gmatch('%x%x') do n=n+1 end
  installed[s[1]]=readBytes(m+s[1],n,true)
 end
 K.warWillHook={q=assert(getAddressSafe(symbol)),pid=K.pid,script=script,info=info,installed=installed}
end
function K.removeWarWillHook()
 local h=K.warWillHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  for rva,expected in pairs(h.installed) do
   local b=assert(readBytes(K.base()+rva,#expected,true))
   for i,v in ipairs(expected) do assert(b[i]==v,'N15 war-will hook ownership changed') end
  end
  writeInteger(h.q,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'N15 war-will hook restoration failed')
 end
 K.warWillHook=nil
end
function K.warWillFeature(on)
 if on then K.installWarWillHook() end
 if K.warWillHook then writeInteger(K.warWillHook.q,on and 1 or 0) end
end

end

do
local K=NB.K15
function K.installLoyaltyHook()
 if K.loyaltyHook then return end
 K.ready();local m=K.base();local at=m+0xDEC00
 local symbol=('nb15Loyalty_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=([[
[ENABLE]
assert(%X,48 89 74 24 18 57 48 83 EC 40)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
label(forced)
@N@:
dd 0
@N@+100:
pushfq
push rax
push r10
push r11
cmp dword ptr [@N@],0
je original
test rcx,rcx
jz original
mov rax,%X
cmp [rcx],rax
jne original
cmp byte ptr [rcx+1E8],7
jne original
mov r10,[rcx+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
cmp [r10+A0],rcx
je original
mov r11,[%X]
test r11,r11
jz original
mov r11,[r11+3A348]
test r11,r11
jz original
mov r11,[r11+B8]
test r11,r11
jz original
mov r11,[r11+F0]
test r11,r11
jz original
cmp [r11+20],r10
je forced
original:
pop r11
pop r10
pop rax
popfq
mov [rsp+18],rsi
jmp %X
forced:
pop r11
pop r10
pop rax
popfq
mov eax,14
ret
%X:
jmp @N@+100
[DISABLE]
%X:
db 48 89 74 24 18
unregistersymbol(@N@)
// Retain code until process exit for in-flight calls.
]]):format(at,at,m+0xBDFEC8,m+0x11B5D18,at+5,at,at):gsub('@N@',symbol)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.loyaltyHook={q=assert(getAddressSafe(symbol)),script=script,info=info,pid=K.pid,at=at}
 K.loyaltyHook.installed=assert(readBytes(at,5,true))
end
function K.loyaltyFeature(on)
 if on then K.installLoyaltyHook() end
 if K.loyaltyHook then writeInteger(K.loyaltyHook.q,on and 1 or 0) end
end
function K.removeLoyaltyHook()
 local h=K.loyaltyHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.at,5,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N15 loyalty hook ownership changed') end
  writeInteger(h.q,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 loyalty hook')
 end
 K.loyaltyHook=nil
end

end

do
local K=NB.K15
function K.installSiegeHook()
 if K.siegeHook then return end
 K.ready();local m=K.base();local at=m+0x375F0A
 local symbol=('nb15Siege_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=([[
[ENABLE]
assert(%X,8B 00 89 47 0C C7 44 24 20 C2 D6 00 00)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(done)
label(scan)
label(next)
label(hit)
@N@:
dd 0 0 0 0
@N@+100:
mov eax,[rax]
pushfq
push rax
push rcx
push rdx
push r8
push r9
push r10
push r11
cmp dword ptr [@N@],0
je done
mov r10,%X
cmp [r13],r10
jne done
cmp dword ptr [rdi+C],0
jle done
mov r8,[%X]
test r8,r8
jz done
mov r8,[r8+3A348]
test r8,r8
jz done
mov r8,[r8+B8]
test r8,r8
jz done
mov r8,[r8+F0]
test r8,r8
jz done
mov r8,[r8+20]
test r8,r8
jz done
mov r10,[rdi+18]
test r10,r10
jz done
mov edx,[r10]
cmp edx,[%X]
jae done
mov r10,[%X]
test r10,r10
jz done
mov r10,[r10+rdx*8]
mov ecx,40
scan:
test r10,r10
jz done
test ecx,ecx
jz done
dec ecx
mov r11,[r10]
test r11,r11
jz next
mov rdx,%X
cmp [r11],rdx
jne next
test byte ptr [r11+200],1
jz next
mov r11,[r11+8]
test r11,r11
jz next
mov rdx,%X
cmp [r11],rdx
jne next
cmp [r11+20],r8
je hit
next:
mov r10,[r10+8]
jmp scan
hit:
mov r14d,[rdi+C]
mov qword ptr [rsp+30],0
inc dword ptr [@N@+8]
done:
pop r11
pop r10
pop r9
pop r8
pop rdx
pop rcx
pop rax
popfq
mov [rdi+C],eax
jmp %X
%X:
jmp @N@+100
[DISABLE]
%X:
db 8B 00 89 47 0C
unregistersymbol(@N@)
// Keep allocation alive until process exit for any in-flight call.
]]):format(at,at,m+0xBE0528,m+0x11B5D18,m+0x1981950,m+0x1981920,
 m+0xBEAF40,m+0xBE0840,at+5,at,at):gsub('@N@',symbol)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.siegeHook={q=assert(getAddressSafe(symbol)),script=script,info=info,pid=K.pid,at=at}
 K.siegeHook.installed=assert(readBytes(at,5,true))
end
function K.siegeOneHit(on)
 if on then K.installSiegeHook() end
 if K.siegeHook then writeInteger(K.siegeHook.q,on and 1 or 0) end
end
function K.removeSiegeHook()
 local h=K.siegeHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.at,5,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N15 siege hook ownership changed') end
  writeInteger(h.q,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 siege hook')
 end
 K.siegeHook=nil
end

end

do
local K=NB.K15
-- The decisive-battle UI renders friendly/enemy gauges in side order 0/1
-- (native 7D45F0). Keep this separate from the campaign army/siege layout.
-- +288..+298 are three officer pointers; +2A0 is their count (175526),
-- not the soldier count. The count guard excludes empty tactical units.
function K.makeTacticalMoraleScript(at,symbol,rootSlot)
 return ([=[
[ENABLE]
assert(%X,48 89 5C 24 10 55 48 8B EC)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
label(scope)
label(protect)
@N@:
dd 0 0 0 0
@N@+100:
pushfq
push rax
push r10
cmp dword ptr [@N@],0
jne scope
cmp dword ptr [@N@+C],0
je original
scope:
mov eax,[rcx+30]
cmp eax,[@N@+4]
jne original
cmp dword ptr [rcx+2A0],0
jle original
cmp dword ptr [rcx+2A0],3
ja original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov rax,r10
mov r10,[r10+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
cmp [rcx+40],r10
jne original
cmp dword ptr [@N@],0
jne protect
cmp [rcx+288],rax
je protect
cmp dword ptr [rcx+2A0],2
jl original
cmp [rcx+290],rax
je protect
cmp dword ptr [rcx+2A0],3
jl original
cmp [rcx+298],rax
jne original
protect:
mov eax,[rcx+2B4]
test eax,eax
jle original
sub eax,[rcx+2A8]
mov edx,eax
inc dword ptr [@N@+8]
original:
pop r10
pop rax
popfq
mov [rsp+10],rbx
jmp %X
%X:
jmp @N@+100
[DISABLE]
%X:
db 48 89 5C 24 10
unregistersymbol(@N@)
// Keep trampoline memory until process exit for in-flight native calls.
]=]):format(at,at,rootSlot,at+5,at,at):gsub('@N@',symbol)
end
function K.installTacticalMoraleHook()
 if K.tacticalMoraleHook then return end
 K.ready();local at=K.base()+0x1593D0
 local symbol=('nb15TacticalMorale_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeTacticalMoraleScript(at,symbol,K.base()+0x11B5D18)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.tacticalMoraleHook={q=assert(getAddressSafe(symbol)),at=at,script=script,info=info,pid=K.pid}
 K.tacticalMoraleHook.installed=assert(readBytes(at,5,true))
end
function K.tacticalMoraleFeature(on)
 if on then K.installTacticalMoraleHook() end
 if K.tacticalMoraleHook then writeInteger(K.tacticalMoraleHook.q,on and 1 or 0) end
end
function K.removeTacticalMoraleHook()
 local h=K.tacticalMoraleHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.at,5,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N15 tactical morale hook ownership changed') end
  writeInteger(h.q,0)
  writeInteger(h.q+0xC,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 tactical morale hook')
 end
 K.tacticalMoraleHook=nil
end

end

do
local K=NB.K15
K.tacticalGaugeSites={
 {rva=0x12EF9A,bytes='89 82 88 22 00 00',original='mov [rdx+2288],eax',address='rdx+2288',source='eax'},
 {rva=0x19276D,bytes='89 82 88 22 00 00',original='mov [rdx+2288],eax',address='rdx+2288',source='eax'},
 {rva=0x1B16C5,bytes='46 89 A4 B0 88 22 00 00',original='mov [rax+r14*4+2288],r12d',address='rax+r14*4+2288',source='r12d'},
 {rva=0x1BC918,bytes='41 89 84 90 88 22 00 00',original='mov [r8+rdx*4+2288],eax',address='r8+rdx*4+2288',source='eax'},
 {rva=0x1BD0A3,bytes='41 89 84 91 88 22 00 00',original='mov [r9+rdx*4+2288],eax',address='r9+rdx*4+2288',source='eax'},
 {rva=0x1D4B93,bytes='43 89 84 A6 88 22 00 00',original='mov [r14+r12*4+2288],eax',address='r14+r12*4+2288',source='eax'},
 {rva=0x188B11,bytes='01 82 88 22 00 00',original='add [rdx+2288],eax',address='rdx+2288'}}
function K.makeTacticalGaugeScript(site,at,friendly,symbol)
 local count=0;for _ in site.bytes:gmatch('%x%x') do count=count+1 end
 local script=([=[
[ENABLE]
assert(%X,%s)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(done)
@N@:
dd 0 0 0 0
@N@+100:
%s
pushfq
push r10
push r11
cmp dword ptr [@N@],0
je done
lea r11,[%s]
mov r10,%X
cmp r11,r10
jne done
mov dword ptr [r11],2710
%s
inc dword ptr [@N@+8]
done:
pop r11
pop r10
popfq
jmp %X
%X:
jmp @N@+100
%s
[DISABLE]
%X:
db %s
unregistersymbol(@N@)
// Keep trampoline memory until process exit for in-flight native calls.
]=]):format(at,site.bytes,at,site.original,site.address,friendly,
 site.source and ('mov '..site.source..',2710') or '',at+count,at,
 count&gt;5 and ('nop '..(count-5)) or '',at,site.bytes)
 return script:gsub('@N@',symbol),count
end
function K.installTacticalGaugeHook()
 if K.tacticalGaugeHook then return end
 K.ready();local m=K.base()
 for _,site in ipairs(K.tacticalGaugeSites) do
  local expected={};for b in site.bytes:gmatch('%x%x') do expected[#expected+1]=tonumber(b,16) end
  local actual=assert(readBytes(m+site.rva,#expected,true))
  for i,b in ipairs(expected) do assert(actual[i]==b,'N15 tactical gauge code changed') end
 end
 K.tacticalGaugeHook={pid=K.pid,records={}}
 local ok,err=pcall(function()
  for _,site in ipairs(K.tacticalGaugeSites) do
   local symbol=('nb15TacticalGauge_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
   local script,size=K.makeTacticalGaugeScript(site,m+site.rva,m+0x11564A0+0x2348,symbol)
   local success,info=(K.assemble or autoAssemble)(script);assert(success,tostring(info))
   local h={q=assert(getAddressSafe(symbol)),at=m+site.rva,script=script,info=info,size=size}
   h.installed=assert(readBytes(h.at,size,true))
   table.insert(K.tacticalGaugeHook.records,h)
  end
 end)
 if not ok then pcall(K.removeTacticalGaugeHook);error(err) end
end
function K.tacticalGaugeFeature(on)
 if on then K.installTacticalGaugeHook() end
 if K.tacticalGaugeHook then
  for _,h in ipairs(K.tacticalGaugeHook.records) do writeInteger(h.q,on and 1 or 0) end
 end
end
function K.removeTacticalGaugeHook()
 local all=K.tacticalGaugeHook;if not all then return end
 if all.pid==getOpenedProcessID() and K.buildMatches() then
  for _,h in ipairs(all.records) do
   local actual=assert(readBytes(h.at,h.size,true))
   for i,b in ipairs(h.installed) do assert(actual[i]==b,'N15 tactical gauge hook ownership changed') end
  end
  for _,h in ipairs(all.records) do writeInteger(h.q,0) end
  for _,h in ipairs(all.records) do assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 tactical gauge hook') end
 end
 K.tacticalGaugeHook=nil
end

end

do
local K=NB.K15
-- Change the native per-tick travel budget; path traversal and spatial-index
-- updates remain in 487F60. Never teleport by writing world coordinates.
function K.makeMovementScript(at,symbol,rootSlot,armyVT,districtVT)
 return ([=[
[ENABLE]
assert(%X,81 BE 00 02 00 00 00 00 00 80)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 4 0 0
@N@+100:
pushfq
push r10
push r11
cmp dword ptr [@N@],0
je original
test eax,eax
jle original
mov r10,%X
cmp [rsi],r10
jne original
test byte ptr [rsi+200],1
jz original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
mov r11,%X
cmp [r10],r11
jne original
mov r10,[r10+20]
test r10,r10
jz original
mov r11,[rsi+8]
test r11,r11
jz original
push r10
mov r10,%X
cmp [r11],r10
pop r10
jne original
cmp [r11+20],r10
jne original
mov r10d,[@N@+4]
cmp r10d,1
jb original
cmp r10d,A
ja original
imul r10,rax
cmp r10,7FFFFFFF
ja original
mov eax,r10d
inc dword ptr [@N@+8]
original:
pop r11
pop r10
popfq
cmp dword ptr [rsi+200],80000000
jmp %X
%X:
jmp @N@+100
nop 5
[DISABLE]
%X:
db 81 BE 00 02 00 00 00 00 00 80
unregistersymbol(@N@)
// Retain trampoline memory until process exit for in-flight native calls.
]=]):format(at,at,armyVT,rootSlot,districtVT,districtVT,at+10,at,at):gsub('@N@',symbol)
end
function K.installMovementHook()
 if K.movementHook then return end
 K.ready();local m=K.base();local at=m+0x488222
 local symbol=('nb15Movement_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeMovementScript(at,symbol,m+0x11B5D18,m+0xBEAF40,m+0xBE0840)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.movementHook={q=assert(getAddressSafe(symbol)),at=at,script=script,info=info,pid=K.pid,
  installed=assert(readBytes(at,10,true))}
end
function K.movementFeature(on,multiplier)
 if on then
  multiplier=tonumber(multiplier) or 4
  assert(multiplier%1==0 and multiplier&gt;=1 and multiplier&lt;=10,'N15 movement multiplier must be 1..10')
  K.installMovementHook();writeInteger(K.movementHook.q+4,multiplier)
 end
 if K.movementHook then writeInteger(K.movementHook.q,on and 1 or 0) end
end
function K.removeMovementHook()
 local h=K.movementHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.at,10,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N15 movement hook ownership changed') end
  writeInteger(h.q,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 movement hook')
 end
 K.movementHook=nil
end

end

do
local K=NB.K15
function K.castleParts(city)
 if not K.indexOf('city',city) then return {} end
 local handle=readQword(city+0x270);if not handle or handle==0 then return {} end
 local index=assert(readInteger(handle));local m=K.base()
 local count=assert(readInteger(m+0x10834B0));local heads=readQword(m+0x1083480)
 assert(index&gt;=0 and index&lt;count and heads and heads&gt;=0x10000,'N15 castle list unavailable')
 local node=readQword(heads+index*8);local result,seen={},{}
 while node and node~=0 do
  assert(node&gt;=0x10000 and not seen[node] and #result&lt;4096,'N15 castle list is invalid')
  seen[node]=true
  local maximum=assert(readInteger(node+8));local current=assert(readInteger(node+0xC))
  local flags=assert(readSmallInteger(node+0xA4));local kind=assert(readInteger(node+0xA8))
  assert(maximum&gt;=0 and current&gt;=0 and current&lt;=maximum,'N15 castle durability is invalid')
  result[#result+1]={p=node,max=maximum,current=current,flags=flags,kind=kind}
  node=readQword(node+0x118)
 end
 return result
end
function K.installRepairHook()
 if K.repairHook then return end
 K.ready();local m=K.base();local at=m+0x392706
 local symbol=('nb15Repair_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=([=[
[ENABLE]
assert(%X,8B 05 B8 A1 C8 00)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dq 0 0
@N@+100:
mov eax,[%X]
pushfq
push r10
push r11
cmp dword ptr [@N@],0
je original
cmp rdi,[@N@+8]
jne original
mov r10,%X
cmp [rdi],r10
jne original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
mov r11,[rdi+8]
test r11,r11
jz original
mov r10,[r10+20]
test r10,r10
jz original
cmp [r11+20],r10
jne original
mov eax,ecx
original:
pop r11
pop r10
popfq
jmp %X
%X:
jmp @N@+100
nop
[DISABLE]
%X:
db 8B 05 B8 A1 C8 00
unregistersymbol(@N@)
// Retain trampoline memory until process exit for in-flight native calls.
]=]):format(at,at,m+0x101C8C4,m+0xBE0528,m+0x11B5D18,at+6,at,at):gsub('@N@',symbol)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.repairHook={q=assert(getAddressSafe(symbol)),at=at,script=script,info=info,pid=K.pid,
  installed=assert(readBytes(at,6,true))}
end
function K.removeRepairHook()
 local h=K.repairHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local actual=assert(readBytes(h.at,6,true))
  for i,v in ipairs(h.installed) do assert(actual[i]==v,'N15 repair hook ownership changed') end
  writeInteger(h.q,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 repair hook')
 end
 K.repairHook=nil
end
function K.repairCity(index)
 K.ready();local city=assert(K.object('city',index))
 local d=readQword(city+8)
 assert(K.indexOf('district',d) and readQword(d+0x20)==K.clan(),'Select a player-owned city')
 K.castleParts(city) -- Validate the entire linked structure before native traversal.
 K.installRepairHook();local h=K.repairHook
 writeQword(h.q+8,city);writeInteger(h.q,1)
 local ok,err=pcall(K.nativeCall,'cityRepairDaily','city',index,0,0)
 if not K.nativeBusy() then writeInteger(h.q,0) end
 if not ok then error(err,0) end
 return K.nativeCall('cityDurability','city',index)
end

end

do
local K=NB.K15
K.castleWorkSites={
 {rva=0x3921BC,bytes='66 01 83 AE 00 00 00',progress='[rbx+AE]',original='add word ptr [rbx+AE],ax',size=7},
 {rva=0x3923A2,bytes='66 41 01 47 02',progress='[r15+2]',original='add word ptr [r15+2],ax',size=5}}
function K.makeCastleWorkScript(site,at,symbol,rootSlot,cityVT)
 return ([=[
[ENABLE]
assert(%X,%s)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0 0 0
@N@+100:
pushfq
push r10
push r11
cmp dword ptr [@N@],0
je original
mov r10,%X
cmp [rdi],r10
jne original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
mov r11,[rdi+8]
test r11,r11
jz original
cmp [r11+20],r10
jne original
mov ax,si
sub ax,word ptr %s
inc dword ptr [@N@+4]
original:
pop r11
pop r10
popfq
%s
jmp %X
%X:
jmp @N@+100
%s
[DISABLE]
%X:
db %s
unregistersymbol(@N@)
// Retain trampoline memory until process exit for in-flight native calls.
]=]):format(at,site.bytes,at,cityVT,rootSlot,site.progress,site.original,at+site.size,at,
 site.size&gt;5 and ('nop '..(site.size-5)) or '',at,site.bytes):gsub('@N@',symbol)
end
function K.installCastleWorkHook()
 if K.castleWorkHook then return end
 K.ready();local m=K.base()
 for _,s in ipairs(K.castleWorkSites) do
  local b=assert(readBytes(m+s.rva,s.size,true));local i=0
  for value in s.bytes:gmatch('%x%x') do i=i+1;assert(b[i]==tonumber(value,16),'N15 castle work code changed') end
 end
 K.castleWorkHook={pid=K.pid,records={}}
 local ok,err=pcall(function()
  for _,s in ipairs(K.castleWorkSites) do
   local symbol=('nb15CastleWork_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
   local at=m+s.rva;local script=K.makeCastleWorkScript(s,at,symbol,m+0x11B5D18,m+0xBE0528)
   local success,info=(K.assemble or autoAssemble)(script);assert(success,tostring(info))
   local h={q=assert(getAddressSafe(symbol)),at=at,size=s.size,script=script,info=info}
   h.installed=assert(readBytes(at,s.size,true));table.insert(K.castleWorkHook.records,h)
  end
 end)
 if not ok then pcall(K.removeCastleWorkHook);error(err,0) end
end
function K.castleWorkFeature(on)
 if on then K.installCastleWorkHook() end
 if K.castleWorkHook then for _,h in ipairs(K.castleWorkHook.records) do writeInteger(h.q,on and 1 or 0) end end
end
function K.removeCastleWorkHook()
 local all=K.castleWorkHook;if not all then return end
 if all.pid==getOpenedProcessID() and K.buildMatches() then
  for _,h in ipairs(all.records) do
   local b=assert(readBytes(h.at,h.size,true))
   for i,v in ipairs(h.installed) do assert(b[i]==v,'N15 castle work hook ownership changed') end
  end
  for _,h in ipairs(all.records) do writeInteger(h.q,0) end
  for _,h in ipairs(all.records) do assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 castle work hook') end
 end
 K.castleWorkHook=nil
end
function K.castleWorkPending(city)
 for _,part in ipairs(K.castleParts(city)) do
  if (part.flags&amp;0x80)==0 then
   if part.kind==1 then return true end
   if part.kind==2 then
    local definition=readQword(part.p)
    if definition and definition&gt;=0x10000 then
     local n=assert(readSmallInteger(definition+0xE))&amp;0xFFFF
     assert(n&lt;=2,'N15 castle work slot layout changed')
     for i=0,n-1 do if readBytes(part.p+0x48+i*0x30,1)==1 then return true end end
    end
   end
  end
 end
 return false
end
function K.finishCastleWork()
 K.ready();local count=0
 K.castleWorkFeature(true)
 for _,item in ipairs(K.objects('city')) do
  local d=readQword(item.p+8)
  if K.indexOf('district',d) and readQword(d+0x20)==K.clan() and K.castleWorkPending(item.p) then
   K.nativeCall('cityWorkDaily','city',item.id,0,0);count=count+1
  end
 end
 return count
end

end

do
local K=NB.K15
function K.officerHasTrait(officer,id)
 assert(id&gt;=0 and id&lt;200 and id%1==0)
 local bits=assert(readInteger(officer+0x144+(id//32)*4))
 return (bits&amp;(1&lt;&lt;(id%32)))~=0
end
function K.editOfficerTraits(kind)
 K.ready();local p=assert(K.selected(kind),'Select an officer first')
 local index=assert(K.indexOf('officer',p));local token=K.key()
 local categoryChoice,remember={},{}
 while true do
  local chosen,nav=NB.chooseTreasureList(NB.T('Traits and battle skills','特性・戦法'),
   {NB.T('Personal traits','個性・特性'),NB.T('Battle skills','合戦特技・戦法')},false,false,categoryChoice)
  if nav~='next' then return end
  categoryChoice=chosen;local category=chosen[1]
  local items,names,initial={},{},{}
  for _,item in ipairs(K.objects('trait')) do
   if (category==1 and item.id&lt;90) or (category==2 and item.id&gt;=90) then
    local name=K.name('trait',item.p)
    if name~='' then
     items[#items+1]=item;names[#names+1]=name
     if K.officerHasTrait(p,item.id) then initial[#initial+1]=#items end
    end
   end
  end
  local selected,step=NB.chooseTreasureList(NB.T('Select traits to keep','保持する特性を複数選択'),
   names,true,true,remember[category] or initial,NB.T('Apply','適用'))
  remember[category]=selected
  if step=='cancel' then return end
  if step=='next' then
   assert(K.key()==token and K.object('officer',index)==p,'Game data changed; reopen the officer editor')
   local keep={};for _,n in ipairs(selected) do keep[items[n].id]=true end
   for _,item in ipairs(items) do
    if not keep[item.id] and K.officerHasTrait(p,item.id) then
     K.nativeCall('officerTraitSet','officer',index,item.id,0)
    end
   end
   for _,item in ipairs(items) do
    if keep[item.id] then K.nativeCall('officerTraitAdd','officer',index,item.id) end
   end
   return
  end
 end
end
local open=K.openEditor
function K.openEditor(mr,kind)
 open(mr,kind)
 if kind~='player' and kind~='officer' then return end
 local token=K.key();local p=K.selected(kind)
 local row=NB.addRec(mr,'Edit traits and battle skills...','特性・戦法を編集...','0',vtAutoAssembler)
 row.Script='[ENABLE]\n[DISABLE]'
 row.OnActivate=function(_,before)
  if before then
   local ok,err=pcall(function()
    assert(K.key()==token and K.selected(kind)==p,'Game data changed; reopen the officer editor')
    K.editOfficerTraits(kind)
   end)
   if not ok then NB.msg(tostring(err):gsub('^.-:%d+: ','')) end
   return false
  end
  return true
 end
end

end

do
local K=NB.K15
-- Native 1D3A50 applies pending casualties (+2B8), updates strength (+2BC)
-- and its render mirror, records casualties, then enters normal unit cleanup.
-- +2A0 is officer count; it must never be used as soldier strength.
function K.makeTacticalStrengthScript(at,symbol,rootSlot)
 return ([=[
[ENABLE]
assert(%X,48 8B D1 45 33 C9)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
label(other)
label(protect)
@N@:
dd 0 0 0 0 0
@N@+100:
pushfq
push rax
push r10
cmp dword ptr [rcx+2A0],0
jle original
cmp dword ptr [rcx+2A0],3
ja original
cmp dword ptr [rcx+2BC],0
jle original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov rax,r10
mov r10,[r10+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
cmp [rcx+40],r10
jne other
cmp dword ptr [@N@],0
jne protect
cmp dword ptr [@N@+10],0
je original
cmp [rcx+288],rax
je protect
cmp dword ptr [rcx+2A0],2
jl original
cmp [rcx+290],rax
je protect
cmp dword ptr [rcx+2A0],3
jl original
cmp [rcx+298],rax
jne original
protect:
cmp dword ptr [rcx+30],0
jne original
mov eax,[rcx+2C8]
cmp eax,[rcx+2BC]
jl original
mov [rcx+2BC],eax
mov dword ptr [rcx+2B8],0
inc dword ptr [@N@+8]
jmp original
other:
cmp dword ptr [@N@+4],0
je original
cmp dword ptr [rcx+30],1
jne original
cmp dword ptr [rcx+2B8],0
jle original
mov eax,[rcx+2BC]
mov [rcx+2B8],eax
inc dword ptr [@N@+C]
original:
pop r10
pop rax
popfq
mov rdx,rcx
xor r9d,r9d
jmp %X
%X:
jmp @N@+100
nop
[DISABLE]
%X:
db 48 8B D1 45 33 C9
unregistersymbol(@N@)
// Retain trampoline memory until process exit for in-flight native calls.
]=]):format(at,at,rootSlot,at+6,at,at):gsub('@N@',symbol)
end
function K.installTacticalStrengthHook()
 if K.tacticalStrengthHook then return end
 K.ready();local at=K.base()+0x1D3A50
 local symbol=('nb15TacticalStrength_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeTacticalStrengthScript(at,symbol,K.base()+0x11B5D18)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.tacticalStrengthHook={q=assert(getAddressSafe(symbol)),at=at,script=script,info=info,pid=K.pid,
  installed=assert(readBytes(at,6,true))}
end
function K.tacticalStrengthFeature(name,on)
 assert(name=='invincible' or name=='oneHit','Unknown N15 tactical strength feature')
 if on then K.installTacticalStrengthHook() end
 if K.tacticalStrengthHook then writeInteger(K.tacticalStrengthHook.q+(name=='oneHit' and 4 or 0),on and 1 or 0) end
end
function K.removeTacticalStrengthHook()
 local h=K.tacticalStrengthHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.at,6,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N15 tactical strength hook ownership changed') end
  writeInteger(h.q,0);writeInteger(h.q+4,0)
  writeInteger(h.q+0x10,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 tactical strength hook')
 end
 K.tacticalStrengthHook=nil
end

end

do
local K=NB.K15
-- Replace only the recruitment probability comparison. The surrounding native
-- eligibility, family/grudge checks and eventual ownership transfer stay intact.
function K.makeRecruitmentScript(at,symbol,rootSlot,comparison,expected)
 return ([=[
[ENABLE]
assert(%X,%s)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0 0 0
@N@+100:
call %X
pushfq
push r10
cmp dword ptr [@N@],0
je original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
// Native saves the recipient clan at [rsp+38]. RSI holds a probability here.
// Two pushes in this trampoline move that saved argument to [rsp+48].
cmp r10,[rsp+48]
jne original
mov eax,1
inc dword ptr [@N@+4]
original:
pop r10
popfq
jmp %X
%X:
jmp @N@+100
[DISABLE]
%X:
db %s
unregistersymbol(@N@)
// Retain trampoline memory until process exit for in-flight native calls.
]=]):format(at,expected,at,comparison,rootSlot,at+5,at,at,expected):gsub('@N@',symbol)
end
function K.installRecruitmentHook()
 if K.recruitmentHook then return end
 K.ready();local m=K.base();local at=m+0x395463
 local symbol=('nb15Recruitment_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeRecruitmentScript(at,symbol,m+0x11B5D18,m+0x5B2CB0,'E8 48 D8 21 00')
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.recruitmentHook={q=assert(getAddressSafe(symbol)),at=at,script=script,info=info,pid=K.pid,
  installed=assert(readBytes(at,5,true))}
end
function K.recruitmentFeature(on)
 if on then K.installRecruitmentHook() end
 if K.recruitmentHook then writeInteger(K.recruitmentHook.q,on and 1 or 0) end
end
function K.removeRecruitmentHook()
 local h=K.recruitmentHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.at,5,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N15 recruitment hook ownership changed') end
  writeInteger(h.q,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 recruitment hook')
 end
 K.recruitmentHook=nil
end

end

do
local K=NB.K15
K.battleHookGroups={
 playerBattle={
  {'troopHook','installTroopHook','removeTroopHook'},
  {'tacticalMoraleHook','installTacticalMoraleHook','removeTacticalMoraleHook'},
  {'tacticalStrengthHook','installTacticalStrengthHook','removeTacticalStrengthHook'}},
 invincible={
  {'troopHook','installTroopHook','removeTroopHook'},
  {'foodHook','installFoodHook','removeFoodHook'},
  {'warWillHook','installWarWillHook','removeWarWillHook'},
  {'tacticalMoraleHook','installTacticalMoraleHook','removeTacticalMoraleHook'},
  {'tacticalStrengthHook','installTacticalStrengthHook','removeTacticalStrengthHook'}},
 oneHit={
  {'troopHook','installTroopHook','removeTroopHook'},
  {'siegeHook','installSiegeHook','removeSiegeHook'},
  {'tacticalStrengthHook','installTacticalStrengthHook','removeTacticalStrengthHook'}}}
function K.prepareBattleFeature(name)
 K.ready();local group=assert(K.battleHookGroups[name],'Unknown N15 battle feature')
 local created={}
 local ok,err=pcall(function()
  for _,entry in ipairs(group) do
   local h=K[entry[1]]
   assert(not h or h.pid==K.pid,'N15 battle hook belongs to a different process')
   if not h then created[#created+1]=entry end
   assert(K[entry[2]],'Missing N15 battle module')()
  end
 end)
 if not ok then
  local errors={}
  for i=#created,1,-1 do
   local entry=created[i]
   if K[entry[1]] then
    local restored,why=pcall(K[entry[3]])
    if not restored then errors[#errors+1]=tostring(why) end
   end
  end
  if #errors&gt;0 then error(tostring(err)..'; rollback: '..table.concat(errors,'; '),0) end
  error(err,0)
 end
 return created
end
function K.invincibleFeature(on)
 if on then K.prepareBattleFeature('invincible') end
 K.troopFeature('invincible',on)
 K.foodFeature(on);K.warWillFeature(on)
 K.tacticalMoraleFeature(on);K.tacticalStrengthFeature('invincible',on)
 K.on.battleInvincible=on or nil
end
function K.oneHitFeature(on)
 if on then K.prepareBattleFeature('oneHit') end
 K.troopFeature('battleOneHit',on)
 K.siegeOneHit(on);K.tacticalStrengthFeature('oneHit',on)
 K.on.battleOneHit=on or nil
end
function K.playerBattleFeature(on)
 if on then K.prepareBattleFeature('playerBattle') end
 for _,entry in ipairs({{'troopHook',8},{'tacticalMoraleHook',0xC},{'tacticalStrengthHook',0x10}}) do
  local h=K[entry[1]];if h then writeInteger(h.q+entry[2],on and 1 or 0) end
 end
 K.on.playerBattle=on or nil
end

end

do
local K=NB.K15
-- Keep the native opinion update, target test, reports and command cleanup.
-- Change only the amount applied at the goodwill update call site.
function K.makeGoodwillScript(at,symbol,rootSlot)
 return ([=[
[ENABLE]
assert(%X,44 8B C7 33 D2)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
label(deltaOK)
@N@:
dd 0 0 0 0
@N@+100:
mov r8d,edi
push r10
cmp dword ptr [@N@],0
je original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
cmp r10,r12
jne original
// EBX is the native current opinion, [original rsp+58] is the chosen goal.
// Only this one push changes that stack offset to 60.
mov r8d,[rsp+60]
sub r8d,ebx
jge deltaOK
xor r8d,r8d
deltaOK:
// Positive progress lets the native target-reached branch finish the mission,
// even if its goal had already been reached before this update.
mov edi,1
mov [rbp+20],edi
inc dword ptr [@N@+4]
original:
pop r10
xor edx,edx
jmp %X
%X:
jmp @N@+100
[DISABLE]
%X:
db 44 8B C7 33 D2
unregistersymbol(@N@)
// Keep allocation alive until process exit for in-flight calls.
]=]):format(at,at,rootSlot,at+5,at,at):gsub('@N@',symbol)
end
function K.installGoodwillHook()
 if K.goodwillHook then return end
 K.ready();local m=K.base();local at=m+0x7BD99F
 local symbol=('nb15Goodwill_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeGoodwillScript(at,symbol,m+0x11B5D18)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.goodwillHook={q=assert(getAddressSafe(symbol)),at=at,script=script,info=info,pid=K.pid,
  installed=assert(readBytes(at,5,true))}
end
function K.goodwillFeature(on)
 if on then K.installGoodwillHook() end
 if K.goodwillHook then writeInteger(K.goodwillHook.q,on and 1 or 0) end
end
function K.removeGoodwillHook()
 local h=K.goodwillHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.at,5,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N15 goodwill hook ownership changed') end
  writeInteger(h.q,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 goodwill hook')
 end
 K.goodwillHook=nil
end

end

do
local K=NB.K15
-- The native goodwill callback runs through the guarded asynchronous request.
-- Limit that invocation to one player command; ordinary monthly processing
-- retains its original command iteration.
function K.makeGoodwillScheduleScript(filter,symbol,rootSlot,callback,validation,skip,filterBytes)
 return ([=[
[ENABLE]
assert(%X,%s)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(filterOriginal)
label(filterSkip)
@N@:
// enabled, forced-callback flag, queue command, ID, root, scenario, player, clan
dq 0 0 0 0 0 0 0 0
@N@+300:
cmp dword ptr [@N@+8],0
je filterOriginal
cmp dword ptr [@N@],0
je filterSkip
cmp rbx,[@N@+10]
jne filterSkip
push r10
mov r10,[%X]
cmp r10,[@N@+20]
jne @N@+500
test r10,r10
jz @N@+500
mov r10,[r10+3A348]
cmp r10,[@N@+28]
jne @N@+500
test r10,r10
jz @N@+500
mov r10,[r10+B8]
cmp r10,[@N@+30]
jne @N@+500
test r10,r10
jz @N@+500
mov r10,[r10+F0]
test r10,r10
jz @N@+500
mov r10,[r10+20]
cmp r10,[@N@+38]
jne @N@+500
test r10,r10
jz @N@+500
mov r10,[rbx+30]
test r10,r10
jz @N@+500
mov r10,[r10+20]
cmp r10,[@N@+38]
jne @N@+500
mov r10,[@N@+18]
cmp r10d,[rbx+68]
jne @N@+500
cmp dword ptr [rbx+60],0
jne @N@+500
pop r10
filterOriginal:
mov rcx,rbx
call %X
jmp %X
@N@+500:
pop r10
filterSkip:
jmp %X
%X:
jmp @N@+300
nop 3
@N@+600:
// RCX is the guarded player clan, not an event-manager object. The native
// goodwill callback ignores this argument.
sub rsp,28
mov dword ptr [@N@+8],1
inc dword ptr [@N@+44]
call %X
mov qword ptr [@N@+10],0
mov dword ptr [@N@+8],0
add rsp,28
ret
[DISABLE]
%X:
db %s
unregistersymbol(@N@)
// Keep allocation until process exit for in-flight game callbacks.
]=]):format(filter,filterBytes,filter,rootSlot,
 validation,filter+8,skip,filter,callback,filter,filterBytes):gsub('@N@',symbol)
end
function K.installGoodwillScheduleHook()
 if K.goodwillScheduleHook then return end
 K.ready();local m=K.base();local filter=m+0x7BD488
 local symbol=('nb15GoodwillSchedule_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeGoodwillScheduleScript(filter,symbol,m+0x11B5D18,
  m+0x7BD340,m+0x25CDE0,m+0x7BE0E7,'48 8B CB E8 50 F9 A9 FF')
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.goodwillScheduleHook={q=assert(getAddressSafe(symbol)),script=script,info=info,pid=K.pid,
  sites={{at=filter,bytes=assert(readBytes(filter,8,true))}}}
end
function K.goodwillOrders()
 K.ready();local root=K.root();local manager=readQword(root+0x3A340)
 local handle=manager and readQword(manager+0x18)
 local index=handle and readInteger(handle)
 local m=K.base();local count=readInteger(m+0x1981950)
 if not index or not count or index&lt;0 or index&gt;=count then return {} end
 local heads=readQword(m+0x1981920);local node=heads and readQword(heads+index*8)
 local result,seen={},{};local clan=K.clan()
 for _=1,4096 do
  if not node or node==0 then return result end
  assert(not seen[node],'N15 command list contains a cycle');seen[node]=true
  local p=readQword(node)
  if p and readQword(p)==m+0xBA6090 and readInteger(p+0x60)==0 and readInteger(p+0x68)~=-1 then
   local d=readQword(p+0x30)
   if K.indexOf('district',d) and readQword(d+0x20)==clan then
    result[#result+1]={p=p,id=readInteger(p+0x68),target=readBytes(p+0x88,1),goal=readSmallInteger(p+0x8A)}
   end
  end
  node=readQword(node+8)
 end
 error('N15 command list exceeded its bound',0)
end
function K.refreshGoodwillQueue()
 if K.pollGoodwillEvent and not K.pollGoodwillEvent() then return end
 local h=K.goodwillScheduleHook
 if not h or h.pid~=getOpenedProcessID() or readInteger(h.q)~=1 or readInteger(h.q+8)~=0 then return end
 if not K.attached() or not K.clan() then writeQword(h.q+0x10,0);return end
 if K.nativeBusy() then return end
 local orders=K.goodwillOrders();local first;local q=h.q
 local attempted=K.goodwillAttempted or {};K.goodwillAttempted=attempted
 for _,item in ipairs(orders) do
  item.key=K.key()..':'..item.id..':'..readInteger(item.p+0x70)..':'..item.target..':'..item.goal
  if not attempted[item.key] then first=item;break end
 end
 -- Publish the pointer last; the game's event thread sees complete guards.
 writeQword(q+0x10,0)
 if not first then return end
 writeQword(q+0x18,first.id);writeQword(q+0x20,K.root());writeQword(q+0x28,K.scenario())
 writeQword(q+0x30,K.player());writeQword(q+0x38,K.clan());writeQword(q+0x10,first.p)
 K.goodwillLast=first
 if K.postGoodwillEvent then K.postGoodwillEvent() end
end
function K.removeGoodwillScheduleHook()
 local h=K.goodwillScheduleHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  assert(readInteger(h.q+8)==0,'N15 goodwill callback is still running')
  for _,site in ipairs(h.sites) do
   local actual=assert(readBytes(site.at,#site.bytes,true))
   for i,v in ipairs(site.bytes) do assert(actual[i]==v,'N15 goodwill schedule hook ownership changed') end
  end
  writeInteger(h.q,0);writeQword(h.q+0x10,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 goodwill schedule hook')
 end
 K.goodwillScheduleHook=nil
end
function K.goodwillInstantFeature(on)
 if not on then
  if K.goodwillScheduleHook then writeInteger(K.goodwillScheduleHook.q,0) end
  K.goodwillFeature(false)
  if K.goodwillPending and K.native and readInteger(K.native.q)==1 then writeInteger(K.native.q,4) end
  if K.pollGoodwillEvent then K.pollGoodwillEvent() end
  if not K.goodwillPending and K.goodwillTimer then K.goodwillTimer.destroy();K.goodwillTimer=nil end
  return
 end
 K.ready()
 if not K.goodwillTimer then K.goodwillAttempted={} end
 local hadGain=K.goodwillHook~=nil
 local ok,why=pcall(function()
  K.installGoodwillHook();K.installGoodwillScheduleHook()
 end)
 if not ok then
  if not hadGain and K.goodwillHook then K.removeGoodwillHook() end
  error(why,0)
 end
 K.goodwillFeature(true);writeInteger(K.goodwillScheduleHook.q,1)
 K.refreshGoodwillQueue()
 if K.goodwillTimer then return end
 local timer=createTimer(nil,false);K.goodwillTimer=timer;timer.Interval=500
 timer.OnTimer=function(t)
  if K.pid~=getOpenedProcessID() then t.Enabled=false;return end
  local success,reason=pcall(K.refreshGoodwillQueue)
  if not success then
   t.Enabled=false
   if K.goodwillScheduleHook then writeInteger(K.goodwillScheduleHook.q,0) end
   K.goodwillFeature(false)
   if K.reportFeatureFailure then K.reportFeatureFailure('goodwill',reason) else NB.msg(tostring(reason)) end
  end
  if K.goodwillScheduleHook and readInteger(K.goodwillScheduleHook.q)==0 and not K.goodwillPending then
   t.destroy();K.goodwillTimer=nil
  end
 end
 timer.Enabled=true
end
function K.removeGoodwillInstant()
 K.goodwillInstantFeature(false)
 K.removeGoodwillScheduleHook();K.removeGoodwillHook()
end

end

do
local K=NB.K15
-- Post a guarded request to the existing window-thread dispatcher. Never wait
-- synchronously for a game callback which may display an in-game report.
function K.pollGoodwillEvent()
 local pending=K.goodwillPending;if not pending then return true end
 if pending.pid~=getOpenedProcessID() then return false end
 local state=readInteger(pending.q)
 if state==1 or state==2 then return false end
 assert(state==3 or state==4,'N15 goodwill request state is unreadable')
 K.goodwillPending=nil
 if pending.record then pending.record.requestState=state end
 if K.native and K.native.q==pending.q then K.removeNative() end
 return true
end
function K.postGoodwillEvent()
 local h=K.goodwillScheduleHook
 if not h or K.goodwillPending or K.nativeBusy() or readInteger(h.q)~=1 or readQword(h.q+0x10)==0 then return end
 K.ready();assert(h.pid==K.pid,'N15 goodwill queue belongs to a different process')
 local code=assert(readBytes(h.q+0x600,4,true))
 assert(code[1]==0x48 and code[2]==0x83 and code[3]==0xEC and code[4]==0x28,'N15 goodwill callback entry changed')
 local clan=assert(K.clan());local id=assert(K.indexOf('clan',clan))
 K.installNative();assert(not K.nativeBusy(),'N15 native request is pending')
 local n=K.native;local q=n.q
 writeQword(q+8,h.q+0x600);writeQword(q+0x10,clan)
 writeQword(q+0x18,0);writeQword(q+0x20,0);writeQword(q+0x28,0)
 writeQword(q+0x40,K.root());writeQword(q+0x48,K.scenario());writeQword(q+0x50,K.player())
 writeQword(q+0x58,K.types.clan.off);writeQword(q+0x60,id);writeQword(q+0x68,K.base()+K.types.clan.vt)
 writeQword(q+0x70,0);writeInteger(q+0x78,0);writeQword(q+0x80,0)
 local w=executeCodeLocalEx('user32.GetTopWindow',0);local selected
 for _=1,10000 do
  if not w or w==0 then break end
  if getWindowProcessID(w)==K.pid and executeCodeLocalEx('user32.IsWindowVisible',w)~=0 then selected=w;break end
  w=getWindow(w,2)
 end
 assert(selected,'N15 game window is unavailable')
 local record=K.goodwillLast
 if record and record.p==readQword(h.q+0x10) then
  K.goodwillAttempted=K.goodwillAttempted or {};K.goodwillAttempted[record.key]=true
 else record=nil end
 K.goodwillPending={q=q,pid=K.pid,command=readQword(h.q+0x10),id=readQword(h.q+0x18),record=record}
 writeInteger(q,1)
 local posted=executeCodeLocalEx('user32.PostMessageW',selected,0x83D5,q,0)
 if not posted or posted==0 then
  writeInteger(q,4);K.pollGoodwillEvent();error('N15 goodwill request could not be posted',0)
 end
end

end

do
local K=NB.K15
function K.missionObjects(vtable)
 K.ready();local r=K.root();local manager=readQword(r+0x3A340)
 local result={};local clan=K.clan();local m=K.base()
 for _,p in ipairs(K.linkedObjects(manager and readQword(manager+0x18))) do
  local vt=readQword(p)
  if (not vtable or vt==m+vtable) and readInteger(p+0x60)==0 then
   local id=readInteger(p+0x68);local district=readQword(p+0x30)
   if id and id&lt;0xA41 and id&gt;=0 and K.indexOf('district',district) and readQword(district+0x20)==clan then
    result[#result+1]={p=p,id=id,vt=vt-m,district=district}
   end
  end
 end
 return result
end
function K.missionObject(id,vtable)
 if type(id)~='number' or id%1~=0 then return end
 for _,item in ipairs(K.missionObjects(vtable)) do if item.id==id then return item.p end end
end

end

do
local K=NB.K15
-- Reports may remain open for user input. Publish one guarded request and
-- return immediately; never mistake a visible report for a failed operation.
function K.postMissionOperation(name,id)
 K.ready();assert(not K.nativeBusy(),'A native operation is pending')
 local d=assert(K.nativeDefinitions[name]);assert(d.kind=='mission')
 local p=assert(K.missionObject(id,d.vt),'Mission unavailable')
 local expected={};for b in d.bytes:gmatch('%x%x') do expected[#expected+1]=tonumber(b,16) end
 local actual=assert(readBytes(K.base()+d.rva,#expected,true))
 for i,b in ipairs(expected) do assert(actual[i]==b,'Mission method changed') end
 local w=executeCodeLocalEx('user32.GetTopWindow',0);local selected
 for _=1,10000 do
  if not w or w==0 then break end
  if getWindowProcessID(w)==K.pid and executeCodeLocalEx('user32.IsWindowVisible',w)~=0 then selected=w;break end
  w=getWindow(w,2)
 end
 assert(selected,'Game window unavailable')
 K.installNative();local q=K.native.q
 writeQword(q+8,K.base()+d.rva);writeQword(q+0x10,p)
 writeQword(q+0x18,0);writeQword(q+0x20,0);writeQword(q+0x28,0)
 writeQword(q+0x40,K.root());writeQword(q+0x48,K.scenario());writeQword(q+0x50,K.player())
 writeQword(q+0x58,-1);writeQword(q+0x60,id);writeQword(q+0x68,K.base()+d.vt)
 writeQword(q+0x70,0);writeInteger(q+0x78,0);writeQword(q+0x80,0)
 writeInteger(q,1)
 local posted=executeCodeLocalEx('user32.PostMessageW',selected,0x83D5,q,0)
 if not posted or posted==0 then writeInteger(q,4);error('Mission request could not be posted',0) end
 return {q=q,pid=K.pid,p=p,id=id,name=name}
end

end

do
local K=NB.K15
-- Preserve candidate eligibility and weighted selection. Replace the random
-- draw with 1 only for the player's source district, so an eligible positive
-- weight is chosen instead of the failure portion of the draw range.
function K.makeCovertChanceScript(at,symbol,rootSlot,random,districtVT,expected)
 return ([=[
[ENABLE]
assert(%X,%s)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0 0 0
@N@+100:
call %X
pushfq
push r10
cmp dword ptr [@N@],0
je original
test r15,r15
jz original
mov r10,%X
cmp [r15],r10
jne original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
cmp r10,[r15+20]
jne original
mov eax,1
inc dword ptr [@N@+4]
original:
pop r10
popfq
jmp %X
%X:
jmp @N@+100
[DISABLE]
%X:
db %s
unregistersymbol(@N@)
// Keep allocation alive until process exit for in-flight native calls.
]=]):format(at,expected,at,random,districtVT,rootSlot,at+5,at,at,expected):gsub('@N@',symbol)
end
function K.installCovertChanceHook()
 if K.covertChanceHook then return end
 K.ready();local m=K.base();local at=m+0x3E03BA
 local symbol=('nb15CovertChance_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeCovertChanceScript(at,symbol,m+0x11B5D18,m+0x5B2CC0,m+0xBE0840,'E8 01 29 1D 00')
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.covertChanceHook={q=assert(getAddressSafe(symbol)),at=at,script=script,info=info,pid=K.pid,
  installed=assert(readBytes(at,5,true))}
end
function K.covertChanceFeature(on)
 if on then K.installCovertChanceHook();K.installCovertWeightHooks() end
 if K.covertChanceHook then writeInteger(K.covertChanceHook.q,on and 1 or 0) end
 for _,h in ipairs(K.covertWeightHooks or {}) do writeInteger(h.q,on and 1 or 0) end
end
function K.removeCovertChanceHook()
 for i=#(K.covertWeightHooks or {}),1,-1 do
  local h=K.covertWeightHooks[i]
  if h.pid==getOpenedProcessID() and K.buildMatches() then
   local actual=assert(readBytes(h.at,6,true))
   for j,v in ipairs(h.installed) do assert(actual[j]==v,'N15 covert weight hook ownership changed') end
   writeInteger(h.q,0);assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 covert weight hook')
  end
  table.remove(K.covertWeightHooks,i)
 end
 local h=K.covertChanceHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.at,5,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N15 covert chance hook ownership changed') end
  writeInteger(h.q,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 covert chance hook')
 end
 K.covertChanceHook=nil
end
function K.makeCovertWeightScript(at,symbol,rootSlot,caller,officerVT)
 return ([=[
[ENABLE]
assert(%X,85 C0 7F 0F EB 03)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0 0 0
@N@+100:
push r10
cmp dword ptr [@N@],0
je original
test eax,eax
jg original
// 40D420's 7 pushes and 70-byte local frame place its return address at
// original rsp+A8 and its caller's saved RSI (source officer) at rsp+98.
// This one trampoline push moves those offsets to B0 and A0 respectively.
mov r10,%X
cmp [rsp+B0],r10
jne original
mov r10,[rsp+A0]
test r10,r10
jz original
push rax
mov rax,%X
cmp [r10],rax
pop rax
jne original
mov r10,[r10+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
push r10
mov r10,[%X]
test r10,r10
jz @N@+400
mov r10,[r10+3A348]
test r10,r10
jz @N@+400
mov r10,[r10+B8]
test r10,r10
jz @N@+400
mov r10,[r10+F0]
test r10,r10
jz @N@+400
mov r10,[r10+20]
test r10,r10
jz @N@+400
cmp r10,[rsp]
jne @N@+400
mov eax,1
inc dword ptr [@N@+4]
jmp @N@+400
@N@+400:
pop r10
original:
pop r10
test eax,eax
jg %X
jmp %X
%X:
jmp @N@+100
nop
[DISABLE]
%X:
db 85 C0 7F 0F EB 03
unregistersymbol(@N@)
// Keep allocation until process exit for in-flight native calls.
]=]):format(at,at,caller,officerVT,rootSlot,at+0x13,at+9,at,at):gsub('@N@',symbol)
end
function K.installCovertWeightHooks()
 if K.covertWeightHooks and #K.covertWeightHooks==2 then return end
 K.ready();assert(not K.covertWeightHooks or #K.covertWeightHooks==0,'N15 covert weight hook group is incomplete')
 K.covertWeightHooks={};local m=K.base()
 local ok,why=pcall(function()
  for _,rva in ipairs({0x40D769,0x40D956}) do
   local at=m+rva;local symbol=('nb15CovertWeight_%X_%X'):format(getTickCount(),rva)
   local script=K.makeCovertWeightScript(at,symbol,m+0x11B5D18,m+0x3E01AF,m+0xBDFEC8)
   local success,info=(K.assemble or autoAssemble)(script);assert(success,tostring(info))
   K.covertWeightHooks[#K.covertWeightHooks+1]={q=assert(getAddressSafe(symbol)),at=at,script=script,info=info,pid=K.pid,
    installed=assert(readBytes(at,6,true))}
  end
 end)
 if not ok then
  for i=#K.covertWeightHooks,1,-1 do
   local h=K.covertWeightHooks[i];assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot roll back N15 covert weight hook')
   table.remove(K.covertWeightHooks,i)
  end
  error(why,0)
 end
end

end

do
local K=NB.K15
function K.makeCovertDayScript(at,symbol,rootSlot,districtVT)
 return ([=[
[ENABLE]
assert(%X,43 8D 0C 80 3B C1)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0
dq 0
@N@+100:
lea ecx,[r8+r8*4]
push r10
cmp dword ptr [@N@],0
je original
cmp rdi,[@N@+8]
jne original
test rsi,rsi
jz original
mov r10,%X
cmp [rsi],r10
jne original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
cmp r10,[rsi+20]
jne original
mov eax,ecx
inc dword ptr [@N@+4]
original:
pop r10
cmp eax,ecx
jmp %X
%X:
jmp @N@+100
nop
[DISABLE]
%X:
db 43 8D 0C 80 3B C1
unregistersymbol(@N@)
// Retain trampoline memory until process exit.
]=]):format(at,at,districtVT,rootSlot,at+6,at,at):gsub('@N@',symbol)
end
function K.installCovertDayHook()
 if K.covertDayHook then return end
 K.ready();local m=K.base();local at=m+0x42814D
 local symbol=('nb15CovertDay_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeCovertDayScript(at,symbol,m+0x11B5D18,m+0xBE0840)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.covertDayHook={q=assert(getAddressSafe(symbol)),at=at,script=script,info=info,pid=K.pid,
  installed=assert(readBytes(at,6,true))}
end
function K.removeCovertDayHook()
 local h=K.covertDayHook;if not h then return end
 assert(not K.nativeBusy(),'Pending native work must retain its day hook')
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.at,6,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N15 covert day hook ownership changed') end
  writeInteger(h.q,0);writeQword(h.q+8,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 covert day hook')
 end
 K.covertDayHook=nil
end
function K.covertPledges(targetClan,sourceDistrict)
 local result={};local clanId=assert(K.indexOf('clan',targetClan))
 local districtId=assert(K.indexOf('district',sourceDistrict));local r=K.root()
 local first=readQword(r+0x38D60)
 for i=0,699 do
  local p=readQword(r+0x38D60+i*8)
  assert(p==first+i*0x28 and readQword(p)==K.base()+0xBE6EF8,'N15 contact record layout changed')
  if readBytes(p+0xA,1)==clanId and readBytes(p+0xB,1)==districtId then
   local officerId=readSmallInteger(p+8)
   if K.object('officer',officerId) then result[#result+1]={id=i,p=p,officer=officerId,kind=readBytes(p+0xC,1)} end
  end
 end
 return result
end

end

do
local K=NB.K15
local function context(c)
 K.ready()
 assert(K.pid==c.pid and K.root()==c.root and K.scenario()==c.scenario and K.player()==c.player,
  'Work context changed')
 local p=assert(K.missionObject(c.id,0xBA7130),'Work command ended or changed')
 assert(p==c.p and readQword(p+0x88)==c.target and readQword(p+0x30)==c.district,
  'Work target changed')
 return p
end
local function release(c)
 assert(not K.nativeBusy(),'Pending work must retain its hooks')
 if K.covertDayHook then writeInteger(K.covertDayHook.q,0);writeQword(K.covertDayHook.q+8,0) end
 K.covertChanceFeature(c.chanceWasOn)
 if not c.hadDay then K.removeCovertDayHook() end
 if not c.hadChance then K.removeCovertChanceHook() end
end
function K.pollCovertWork()
 local c=K.covertPending;if not c then return true end
 assert(c.pid==getOpenedProcessID(),'Work process changed')
 local state=readInteger(c.request.q)
 if state==1 or state==2 then return false end
 -- Keep ownership on failure, so the normal release path can inspect it.
 assert(state==3,'Work request was rejected')
 if c.stage=='finish' then
  K.ready()
  assert(K.root()==c.root and K.scenario()==c.scenario and K.player()==c.player,'Work context changed')
  assert(not K.missionObject(c.id,0xBA7130),'Work command remains active')
  c.after=K.covertPledges(c.target,c.district)
  c.dateUnchanged=readInteger(c.scenario+0xB0)==c.date
  release(c);K.covertPending=nil;K.covertLast=c
  return true
 end
 context(c)
 assert(readQword(c.request.q+0x30)==1,'Work update did not succeed')
 c.completed=c.completed+1
 if c.completed&lt;c.attempts and not c.stopRequested then
  c.request=K.postMissionOperation('covertWorkTick',c.id)
 else
  local after=K.covertPledges(c.target,c.district)
  if #after&lt;=#c.before then
   release(c);K.covertPending=nil
   if c.stopRequested then return true end
   error('No new contact was registered; work command was retained',0)
  end
  c.stage='finish';c.request=K.postMissionOperation('covertWorkFinish',c.id)
 end
 return false
end
function K.covertInstantFeature(on)
 if not on then
  if K.covertScanTimer then K.covertScanTimer.destroy();K.covertScanTimer=nil end
  if K.covertPending then K.covertPending.stopRequested=true end
  K.on.covertInstant=nil
  return
 end
 K.ready();if K.covertScanTimer then return end
 K.covertAttempted={};K.on.covertInstant=true
 local timer=createTimer(nil,false);timer.Interval=500;K.covertScanTimer=timer
 timer.OnTimer=function(t)
  if K.pid~=getOpenedProcessID() then t.Enabled=false;return end
  if K.covertPending or K.nativeBusy() then return end
  local ok,err=pcall(function()
   K.ready()
   for _,item in ipairs(K.missionObjects(0xBA7130)) do
    local key=K.key()..':'..item.id..':'..readInteger(item.p+0x70)..':'..readQword(item.p+0x88)
    if not K.covertAttempted[key] then
     -- An error must not trigger the same report repeatedly on every timer.
     K.covertAttempted[key]=true;K.startCovertWork(item.id);break
    end
   end
  end)
  if not ok then
   t.Enabled=false;K.on.covertInstant=nil
   if K.reportFeatureFailure then K.reportFeatureFailure('covertInstant',err) else NB.msg(tostring(err)) end
  end
 end
 timer.Enabled=true
end
function K.startCovertWork(id)
 K.ready();assert(not K.covertPending and not K.nativeBusy(),'A native operation is pending')
 local p=assert(K.missionObject(id,0xBA7130),'Work command unavailable')
 local target=assert(readQword(p+0x88));local district=assert(readQword(p+0x30))
 assert(K.indexOf('clan',target) and K.indexOf('district',district),'Work context changed')
 local months=assert(readInteger(p+0x9C));assert(months&gt;=1 and months&lt;=12,'Work duration outside validated bound')
 local c={id=id,p=p,target=target,district=district,pid=K.pid,root=K.root(),scenario=K.scenario(),player=K.player(),
  date=readInteger(K.scenario()+0xB0),before=K.covertPledges(target,district),attempts=months,completed=0,stage='tick',
  hadDay=K.covertDayHook~=nil,hadChance=K.covertChanceHook~=nil,
  chanceWasOn=K.covertChanceHook and readInteger(K.covertChanceHook.q)==1 or false}
 K.installCovertDayHook();K.covertChanceFeature(true)
 writeQword(K.covertDayHook.q+8,p);writeInteger(K.covertDayHook.q,1)
 local ok,request=pcall(K.postMissionOperation,'covertWorkTick',id)
 if not ok then if not K.nativeBusy() then release(c) end;error(request,0) end
 c.request=request;K.covertPending=c
 if not K.covertTimer then
  local timer=createTimer(nil,false);K.covertTimer=timer;timer.Interval=250
  timer.OnTimer=function(t)
   local success,done=pcall(K.pollCovertWork)
   if not success then
    t.Enabled=false
    -- An executing callback keeps its code and payload until it returns.
    if not K.nativeBusy() and K.covertPending then
     pcall(release,K.covertPending);K.covertPending=nil
    end
    NB.msg(tostring(done));return
   end
   if done then t.destroy();K.covertTimer=nil end
  end
 end
 K.covertTimer.Enabled=true
 return c
end

end

do
local K=NB.K15
-- Change the final chance only after the game's target / pledge eligibility
-- checks have passed. Keep native RNG consumption, costs and result handling.
function K.makeCovertProposalScript(at,symbol,rootSlot,clanVT)
 return ([=[
[ENABLE]
assert(%X,48 8B 8C 24 D8 00 00 00)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0 0 0
@N@+100:
pushfq
push r10
push r11
cmp dword ptr [@N@],0
je original
mov r10,[rsp+68]
test r10,r10
jz original
mov r11,%X
cmp [r10],r11
jne original
mov r11,[%X]
test r11,r11
jz original
mov r11,[r11+3A348]
test r11,r11
jz original
mov r11,[r11+B8]
test r11,r11
jz original
mov r11,[r11+F0]
test r11,r11
jz original
mov r11,[r11+20]
cmp r10,r11
jne original
mov esi,64
inc dword ptr [@N@+4]
original:
pop r11
pop r10
popfq
mov rcx,[rsp+D8]
jmp %X
%X:
jmp @N@+100
nop 3
[DISABLE]
%X:
db 48 8B 8C 24 D8 00 00 00
unregistersymbol(@N@)
// Retain the trampoline until process exit for an in-flight caller.
]=]):format(at,at,clanVT,rootSlot,at+8,at,at):gsub('@N@',symbol)
end
function K.installCovertProposalHook()
 if K.covertProposalHook then return end
 K.ready();local m=K.base();local at=m+0x3D797D
 local symbol=('nb15CovertProposal_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeCovertProposalScript(at,symbol,m+0x11B5D18,m+0xBE0758)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.covertProposalHook={q=assert(getAddressSafe(symbol)),at=at,script=script,info=info,pid=K.pid,
  installed=assert(readBytes(at,8,true))}
end
function K.covertProposalFeature(on)
 if on then K.installCovertProposalHook() end
 if K.covertProposalHook then writeInteger(K.covertProposalHook.q,on and 1 or 0) end
end
function K.removeCovertProposalHook()
 local h=K.covertProposalHook;if not h then return end
 assert(not K.nativeBusy(),'Pending game operation must retain its hooks')
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.at,8,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N15 covert proposal hook ownership changed') end
  writeInteger(h.q,0);assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 covert proposal hook')
 end
 K.covertProposalHook=nil
end

end

do
local K=NB.K15
function K.ownCity(city)
 if not K.indexOf('city',city) then return false end
 local district=readQword(city+8)
 return K.indexOf('district',district)~=nil and readQword(district+0x20)==K.clan()
end
function K.cityMaxTick()
 K.ready();assert(not K.nativeBusy(),'A game operation is pending')
 local token=K.key();local changed=0
 local function put(kind,id,p,off,value,word)
  local current=word and readSmallInteger(p+off) or readInteger(p+off)
  if current~=value then
   assert(K.key()==token and K.object(kind,id)==p,'City data changed')
   assert((word and writeSmallInteger or writeInteger)(p+off,value),'Cannot update city resource')
   changed=changed+1
  end
 end
 for _,item in ipairs(K.objects('district')) do
  if readQword(item.p+0x20)==K.clan() then
   for _,field in ipairs(K.fields.district) do put('district',item.id,item.p,field.off,field.max,false) end
  end
 end
 local markets=K.marketIndex();local owned=K.ownedCitySet()
 for _,item in ipairs(K.objects('city')) do
  if owned[item.p] and K.ownCity(item.p) then
   local ag=K.agricultureForCity(item.p)
   local ai=K.indexOf('agriculture',ag)
   if ai then
    -- Farmers and farmer soldiers share the available farmland. Do not
    -- fabricate extra deployed farmer soldiers when replenishing a city.
    local farmers=assert(readInteger(ag+0x40));local soldiers=assert(readInteger(ag+0x44))
    local farmland=assert(readInteger(ag+0x48))
    assert(farmers&gt;=0 and soldiers&gt;=0 and farmers+soldiers&lt;=farmland,'Agriculture population exceeds available farmland')
    put('agriculture',ai,ag,0x48,math.max(99999,farmland),false)
    put('agriculture',ai,ag,0x84,99999,false)
    put('agriculture',ai,ag,0x11C,100,true)
    put('agriculture',ai,ag,0x11E,100,true)
    local popularityBase=100-K.popularityModifiers(ag)
    assert(popularityBase&gt;=-32768 and popularityBase&lt;=32767,'Popularity modifiers exceed the validated bound')
    put('agriculture',ai,ag,0x8A,popularityBase,true)
   end
   for _,market in ipairs(K.marketsForCity(item.p,markets)) do
    put('market',market.id,market.p,0xD8,10000,true)
    put('market',market.id,market.p,0xD6,10000,true)
   end
   local damaged=false
   for _,part in ipairs(K.castleParts(item.p)) do
    if (part.flags&amp;0x80)==0 and part.current&lt;part.max then damaged=true;break end
   end
   if damaged then
    assert(K.key()==token and K.ownCity(item.p),'City owner changed')
    K.repairCity(item.id);changed=changed+1
   end
  end
 end
 for _,item in ipairs(K.objects('county')) do
  if owned[readQword(item.p+0x28)] and K.ownCounty(item.p) then put('county',item.id,item.p,0x48,999999,false) end
 end
 -- At most one completed facility per tick; game-thread invalidation follows
 -- its level update. Construction and assigned workers are left to their orders.
 changed=changed+K.facilityMaxTick()
 return changed
end
function K.maxPolicyPoints()
 K.ready();local clan=assert(K.clan());local id=assert(K.indexOf('clan',clan))
 for kind=0,4 do
  if readSmallInteger(clan+0xDF4+kind*2)~=9999 then
   K.nativeCall('policyPointsSet','clan',id,kind,9999)
  end
 end
end

end

do
local K=NB.K15
-- Use the predicate's own seventh argument to skip willingness only for
-- resource proposals. Native stock, live-clan and gun-availability checks stay.
function K.makeResourceNegotiationScript(at,symbol,rootSlot,clanVT,offerVT)
 return ([=[
[ENABLE]
assert(%X,40 55 56 57 41 54)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0
@N@+100:
pushfq
push rax
push r10
push r11
cmp dword ptr [@N@],0
je original
test rcx,rcx
jz original
test rdx,rdx
jz original
test r8,r8
jz original
mov rax,%X
cmp [rcx],rax
jne original
cmp [rdx],rax
jne original
mov rax,%X
cmp [r8],rax
jne original
movzx eax,word ptr [r8+8]
dec eax
cmp eax,3
ja original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
cmp [r10+20],rcx
jne original
mov dword ptr [rsp+58],1
inc dword ptr [@N@+4]
original:
pop r11
pop r10
pop rax
popfq
push rbp
push rsi
push rdi
push r12
jmp %X
%X:
jmp @N@+100
nop
[DISABLE]
%X:
db 40 55 56 57 41 54
unregistersymbol(@N@)
// Keep the trampoline allocated for any in-flight predicate return.
]=]):format(at,at,clanVT,offerVT,rootSlot,at+6,at,at):gsub('@N@',symbol)
end
function K.installResourceNegotiationHook()
 if K.resourceNegotiationHook then return end
 K.ready();local m=K.base();local at=m+0x331180
 local symbol=('nb15ResourceNegotiation_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeResourceNegotiationScript(at,symbol,m+0x11B5D18,m+0xBE0758,m+0xBE8D28)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.resourceNegotiationHook={q=assert(getAddressSafe(symbol)),at=at,pid=K.pid,script=script,info=info,
  installed=assert(readBytes(at,6,true))}
end
function K.resourceNegotiationFeature(on)
 if on then K.installResourceNegotiationHook() end
 if K.resourceNegotiationHook then writeInteger(K.resourceNegotiationHook.q,on and 1 or 0) end
end
function K.removeResourceNegotiationHook()
 local h=K.resourceNegotiationHook;if not h then return end
 assert(not K.nativeBusy(),'A pending predicate must retain its hook')
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local actual=assert(readBytes(h.at,6,true))
  for i,v in ipairs(h.installed) do assert(actual[i]==v,'Resource negotiation hook ownership changed') end
  writeInteger(h.q,0);assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore resource negotiation hook')
 end
 K.resourceNegotiationHook=nil
end
function K.makeTradeNegotiationScript(at,symbol,rootSlot)
 return ([=[
[ENABLE]
assert(%X,45 33 C9 45 33 C0)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0
@N@+100:
xor r9d,r9d
xor r8d,r8d
pushfq
push r10
push r11
cmp dword ptr [@N@],0
je original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
mov r11,[rsp+70]
test r11,r11
jz original
cmp [r10+20],r11
jne original
mov r9d,1
inc dword ptr [@N@+4]
original:
pop r11
pop r10
popfq
jmp %X
%X:
jmp @N@+100
nop
[DISABLE]
%X:
db 45 33 C9 45 33 C0
unregistersymbol(@N@)
]=]):format(at,at,rootSlot,at+6,at,at):gsub('@N@',symbol)
end
function K.installTradeNegotiationHook()
 if K.tradeNegotiationHook then return end
 K.ready();local m=K.base();local at=m+0x331B50
 local symbol=('nb15TradeNegotiation_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeTradeNegotiationScript(at,symbol,m+0x11B5D18)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.tradeNegotiationHook={q=assert(getAddressSafe(symbol)),at=at,pid=K.pid,script=script,info=info,
  installed=assert(readBytes(at,6,true))}
end
function K.tradeNegotiationFeature(on)
 if on then K.installTradeNegotiationHook() end
 if K.tradeNegotiationHook then writeInteger(K.tradeNegotiationHook.q,on and 1 or 0) end
end
function K.removeTradeNegotiationHook()
 local h=K.tradeNegotiationHook;if not h then return end
 assert(not K.nativeBusy(),'A pending predicate must retain its hook')
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local actual=assert(readBytes(h.at,6,true))
  for i,v in ipairs(h.installed) do assert(actual[i]==v,'Trade negotiation hook ownership changed') end
  writeInteger(h.q,0);assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore trade negotiation hook')
 end
 K.tradeNegotiationHook=nil
end

end

do
local K=NB.K15
-- These hooks adjust only willingness decisions inside the native transaction
-- predicate. They never rebuild a UI controller or manufacture a proposal.
function K.makeDiplomacyFrameScript(at,symbol,rootSlot,bytes,sourceOffset,replay,accepted,extra)
 local length=0;for _ in bytes:gmatch('%x%x') do length=length+1 end
 local script=([=[
[ENABLE]
assert(%X,%s)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0
@N@+100:
pushfq
push r10
push r11
cmp dword ptr [@N@],0
je original
%s
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
mov r11,[rsp+%X]
cmp r10,r11
jne original
inc dword ptr [@N@+4]
pop r11
pop r10
popfq
%s
jmp %X
original:
pop r11
pop r10
popfq
%s
jmp %X
%X:
jmp @N@+100
%s
[DISABLE]
%X:
db %s
unregistersymbol(@N@)
]=]):format(at,bytes,at,extra or '',rootSlot,sourceOffset+0x18,accepted,at+length,
 replay,at+length,at,length&gt;5 and ('nop '..(length-5)) or '',at,bytes)
 return script:gsub('@N@',symbol)
end
K.negotiationSites={
 {key='opinion',rva=0x33129F,length=9,source=0x58,
  bytes='89 44 24 40 E8 18 E2 0D 00',
  replay=function(m)return ('mov [rsp+40],eax\ncall %X'):format(m+0x40F4C0)end,
  accepted=function(m)return ('mov eax,64\nmov [rsp+40],eax\ncall %X'):format(m+0x40F4C0)end},
 {key='alliance',rva=0x331BDC,length=6,source=0x58,bytes='45 33 C9 45 33 C0',
  replay=function()return 'xor r9d,r9d\nxor r8d,r8d'end,
  accepted=function()return 'xor r8d,r8d\nmov r9d,1'end},
 {key='submission',rva=0x3307B4,length=7,source=0xD8,bytes='39 AC 24 A0 00 00 00',
  replay=function()return 'cmp [rsp+A0],ebp'end,
  accepted=function(m)return ('jmp %X'):format(m+0x330850)end,
  extra=function(m)return ([=[
cmp edi,-1
jne original
mov r10,[rsp+90]
mov r11,%X
cmp r10,r11
je callerOK
mov r11,%X
cmp r10,r11
jne original
callerOK:
]=]):format(m+0x331B81,m+0x331BCD)end}}
function K.installNegotiationDecisionHooks()
 K.ready();K.negotiationDecisionHooks=K.negotiationDecisionHooks or {}
 local m=K.base()
 for _,site in ipairs(K.negotiationSites) do
  if not K.negotiationDecisionHooks[site.key] then
   local symbol=('nb15Diplomacy_%s_%X_%X'):format(site.key,getTickCount(),math.random(0x100000,0x7FFFFF))
   local extra=site.extra and ('label(callerOK)\n'..site.extra(m)) or ''
   local script=K.makeDiplomacyFrameScript(m+site.rva,symbol,m+0x11B5D18,site.bytes,site.source,
    site.replay(m),site.accepted(m),extra)
   local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
   K.negotiationDecisionHooks[site.key]={q=assert(getAddressSafe(symbol)),script=script,info=info,
    at=m+site.rva,pid=K.pid,installed=assert(readBytes(m+site.rva,site.length,true))}
  end
 end
end
function K.removeNegotiationDecisionHooks()
 assert(not K.nativeBusy(),'A pending negotiation must retain its decision hooks')
 for name,h in pairs(K.negotiationDecisionHooks or {}) do
  if h.pid==getOpenedProcessID() and K.buildMatches() then
   local actual=assert(readBytes(h.at,#h.installed,true))
   for i,b in ipairs(h.installed) do assert(actual[i]==b,'Negotiation decision hook ownership changed') end
   writeInteger(h.q,0);assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore negotiation decision hook')
  end
  K.negotiationDecisionHooks[name]=nil
 end
end
function K.negotiationSuccessFeature(on)
 if not on then
  K.resourceNegotiationFeature(false);K.tradeNegotiationFeature(false)
  for _,h in pairs(K.negotiationDecisionHooks or {}) do writeInteger(h.q,0) end
  return
 end
 K.ready()
 local ok,why=pcall(function()
  K.installResourceNegotiationHook();K.installTradeNegotiationHook();K.installNegotiationDecisionHooks()
 end)
 if not ok then
  K.negotiationSuccessFeature(false)
  error(why,0)
 end
 K.resourceNegotiationFeature(true);K.tradeNegotiationFeature(true)
 for _,h in pairs(K.negotiationDecisionHooks) do writeInteger(h.q,1) end
end

end

do
local K=NB.K15
K.types.role={off=0x38140,count=307,stride=0x48,vt=0xBEB188}
K.nativeDefinitions.courtRankAward={rva=0x390DC0,
 bytes='40 53 57 41 54 41 55 41 56 41 57 48 83 EC 58',kind='role',argumentType='clan'}
function K.rankName(role)
 assert(K.indexOf('role',role),'Rank is unavailable')
 return ansiToUtf8(readString(role+8,0x24,false) or '')
end
function K.rankOf(officer,kind)
 assert(K.indexOf('officer',officer),'Officer is unavailable')
 local id=readSmallInteger(officer+(kind==0 and 0x1F4 or 0x1F2))
 if id and id&gt;=32768 then id=id-65536 end
 local role=id and K.object('role',id)
 if role and readBytes(role+0x2C,1)==kind then return id,role end
 return -1
end
function K.installRoleAwardWrapper()
 if K.roleAwardWrapper then return end
 K.ready();local at=K.base()+0x392F40
 local expected={0x40,0x53,0x56,0x57,0x41,0x54,0x41,0x55,0x41,0x56,0x41,0x57}
 local bytes=assert(readBytes(at,#expected,true))
 for i,b in ipairs(expected) do assert(bytes[i]==b,'Role award method changed') end
 local symbol=('nb15RoleAward_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=([=[
[ENABLE]
alloc(@N@,4096,%X)
registersymbol(@N@)
@N@:
sub rsp,28
mov qword ptr [rsp+20],0
mov rax,%X
call rax
add rsp,28
ret
[DISABLE]
unregistersymbol(@N@)
// Keep the small wrapper allocation until process exit.
]=]):format(at,at):gsub('@N@',symbol)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 local q=assert(getAddressSafe(symbol))
 K.roleAwardWrapper={q=q,pid=K.pid,script=script,info=info}
 K.nativeDefinitions.roleAward={rva=q-K.base(),bytes='48 83 EC 28 48 C7 44 24 20 00 00 00 00',kind='role',argumentType='clan'}
end
function K.removeRoleAwardWrapper()
 local h=K.roleAwardWrapper;if not h then return end
 assert(not K.nativeBusy(),'A pending award must retain its wrapper')
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot unregister role award wrapper')
 end
 K.roleAwardWrapper=nil;K.nativeDefinitions.roleAward=nil
end
function K.awardRank(officerIndex,roleIndex)
 K.ready();local officer=assert(K.object('officer',officerIndex),'Officer is unavailable')
 local role=assert(K.object('role',roleIndex),'Rank is unavailable')
 local kind=readBytes(role+0x2C,1);assert(kind==0 or kind==1,'Invalid rank category')
 local district=readQword(officer+0xF0)
 assert(K.indexOf('district',district),'Officer is not serving a clan')
 local clan=readQword(district+0x20);assert(K.indexOf('clan',clan),'Officer clan is unavailable')
 local token=K.key()
 if kind==1 then K.installRoleAwardWrapper() end
 -- Native award updates previous holder, recipient, clan ownership, acquired
 -- rank bitset and game notifications. A bare officer-field write omits these.
 K.nativeCall(kind==0 and 'courtRankAward' or 'roleAward','role',roleIndex,clan,0,officer)
 assert(K.key()==token,'Game data changed during the award')
 assert(readQword(role+0x30)==officer,'Rank holder was not updated')
 assert(readQword(role+0x38)==clan,'Rank clan ownership was not updated')
 assert(K.rankOf(officer,kind)==roleIndex,'Officer rank was not updated')
 local bits=assert(readInteger(clan+0xC48+math.floor(roleIndex/32)*4))
 assert((bits&amp;(1&lt;&lt;(roleIndex%32)))~=0,'Clan rank record was not updated')
 if K.refreshRankRows then K.refreshRankRows() end
end
function K.chooseRank(officerIndex,kind)
 K.ready();local token=K.key();local ids,names={},{}
 for _,item in ipairs(K.objects('role')) do
  if readBytes(item.p+0x2C,1)==kind then
   local name=K.rankName(item.p)
   if name~='' then ids[#ids+1]=item.id;names[#names+1]=name end
  end
 end
 local n=NB.pick(NB.T(kind==0 and 'Award court rank' or 'Award office',kind==0 and '官位を授与' or '役職を授与'),names)
 if not n then return end
 assert(K.key()==token,'Game data changed; reopen the rank list')
 K.awardRank(officerIndex,ids[n])
end
K.rankRows=K.rankRows or {}
local function labels(officer,category)
 local id,role=K.rankOf(officer,category)
 local name=role and K.rankName(role)
 return (category==0 and 'Court rank' or 'Office')..': '..(name or 'None'),
  (category==0 and '官位' or '役職')..'：'..(name or 'なし')
end
function K.refreshRankRows()
 for id,entry in pairs(K.rankRows) do
  local row=getAddressList().getMemoryRecordByID(id)
  local officer=K.object('officer',entry.index)
  if not row then K.rankRows[id]=nil
  elseif officer and K.key()==entry.token then
   local en,jp=labels(officer,entry.kind)
   for _,d in ipairs(NB.dyn or {}) do
    if d.mr==row then d.en=en;d.ja=jp;break end
   end
   row.Description=NB.T(en,jp)
  end
 end
end
local close=K.closeEditor
function K.closeEditor(mr)
 for id in pairs(K.rankRows) do
  local row=getAddressList().getMemoryRecordByID(id)
  if not row or row.Parent==mr then K.rankRows[id]=nil end
 end
 return close(mr)
end
local open=K.openEditor
function K.openEditor(mr,kind)
 open(mr,kind)
 if kind~='officer' and kind~='player' then return end
 local officer=K.selected(kind);if not officer then return end
 local index=assert(K.indexOf('officer',officer));local token=K.key()
 for category=0,1 do
  local categoryId=category
  local en,jp=labels(officer,categoryId)
  local row=NB.addRec(mr,en,jp,'',vtAutoAssembler)
  row.Script='[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.K15.chooseRank('..index..','..categoryId..') end)\n{$asm}\n[DISABLE]\n'
  row.OnActivate=function(_,before)
   if before then return K.key()==token and K.object('officer',index)==officer end
   return true
  end
  K.rankRows[row.ID]={index=index,kind=categoryId,token=token}
 end
end

end

do
local K=NB.K15
K.nativeDefinitions.commerceActionsRefill={rva=0x4010B0,
 bytes='40 53 48 83 EC 20 48 8B D9 E8 02 76 FF FF',kind='district'}
function K.makeCommerceActionsScript(at,symbol,rootSlot,districtVT)
 return ([=[
[ENABLE]
assert(%X,FE C8 88 83 96 00 00 00)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
label(store)
@N@:
dd 0 0
@N@+100:
pushfq
push r10
push r11
cmp dword ptr [@N@],0
je original
test rbx,rbx
jz original
mov r10,%X
cmp [rbx],r10
jne original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
cmp [rbx+20],r10
jne original
inc dword ptr [@N@+4]
pop r11
pop r10
popfq
jmp store
original:
pop r11
pop r10
popfq
dec al
store:
mov [rbx+96],al
jmp %X
%X:
jmp @N@+100
nop 3
[DISABLE]
%X:
db FE C8 88 83 96 00 00 00
unregistersymbol(@N@)
]=]):format(at,at,districtVT,rootSlot,at+8,at,at):gsub('@N@',symbol)
end
function K.installCommerceActionsHook()
 if K.commerceActionsHook then return end
 K.ready();local m=K.base();local at=m+0x272762
 local symbol=('nb15CommerceActions_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeCommerceActionsScript(at,symbol,m+0x11B5D18,m+K.types.district.vt)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.commerceActionsHook={q=assert(getAddressSafe(symbol)),at=at,pid=K.pid,script=script,info=info,
  installed=assert(readBytes(at,8,true))}
end
function K.commerceActionsFeature(on)
 if on then
  K.installCommerceActionsHook()
  for _,item in ipairs(K.objects('district')) do
   if readQword(item.p+0x20)==K.clan() then K.nativeCall('commerceActionsRefill','district',item.id) end
  end
 end
 if K.commerceActionsHook then writeInteger(K.commerceActionsHook.q,on and 1 or 0) end
end
function K.removeCommerceActionsHook()
 local h=K.commerceActionsHook;if not h then return end
 assert(not K.nativeBusy(),'A pending action must retain its hook')
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local actual=assert(readBytes(h.at,8,true))
  for i,b in ipairs(h.installed) do assert(actual[i]==b,'Commerce action hook ownership changed') end
  writeInteger(h.q,0);assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore commerce action hook')
 end
 K.commerceActionsHook=nil
end
local open=K.openEditor
function K.openEditor(mr,kind)
 open(mr,kind)
 if kind~='player' then return end
 local id=assert(K.indexOf('district',K.district()))
 for _,field in ipairs({
  {en='Commerce actions remaining',jp='商業の残り行動数',off=0x96,min=0,max=99,size=1},
  {en='Additional commerce actions',jp='商業の追加行動数',off=0x99,min=0,max=99,size=1}}) do
  K.addField(mr,'district',id,field)
 end
end

end

do
local K=NB.K15
-- Agriculture has shared annual supplies, not the commerce action byte.
function K.farmOwnGuard(rootSlot,agricultureVT,cityVT,districtVT,source)
 local code=([=[
test %s,%s
jz original
mov rax,%X
cmp [%s],rax
jne original
mov r11,[%X]
test r11,r11
jz original
mov r11,[r11+3A348]
test r11,r11
jz original
mov r11,[r11+B8]
test r11,r11
jz original
mov r11,[r11+F0]
test r11,r11
jz original
mov rax,%X
cmp [r11],rax
jne original
mov r11,[r11+20]
test r11,r11
jz original
]=]):format(source,source,source=='rcx' and agricultureVT or districtVT,source,rootSlot,districtVT)
 if source=='rcx' then
  code=code..([=[
mov r10,[rcx+30]
test r10,r10
jz original
mov rax,%X
cmp [r10],rax
jne original
mov r10,[r10+8]
test r10,r10
jz original
mov rax,%X
cmp [r10],rax
jne original
cmp [r10+20],r11
jne original
]=]):format(cityVT,districtVT)
 else
  code=code..'cmp [r14+20],r11\njne original\n'
 end
 return code
end
function K.makeFarmCostScript(at,symbol,rootSlot,agricultureVT,cityVT,districtVT)
 return ([=[
[ENABLE]
assert(%X,48 89 5C 24 08 48 89 6C 24 10)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0
@N@+100:
pushfq
push rax
push r10
push r11
cmp dword ptr [@N@],0
je original
%s
test r8,r8
jz original
test r9,r9
jz original
mov rax,[rsp+48]
test rax,rax
jz original
mov dword ptr [r8],0
mov dword ptr [r9],0
mov dword ptr [rax],0
inc dword ptr [@N@+4]
pop r11
pop r10
pop rax
popfq
ret
original:
pop r11
pop r10
pop rax
popfq
mov [rsp+8],rbx
mov [rsp+10],rbp
jmp %X
%X:
jmp @N@+100
nop 5
[DISABLE]
%X:
db 48 89 5C 24 08 48 89 6C 24 10
unregistersymbol(@N@)
]=]):format(at,at,K.farmOwnGuard(rootSlot,agricultureVT,cityVT,districtVT,'rcx'),at+10,at,at):gsub('@N@',symbol)
end
function K.makeFarmSeasonScript(at,symbol,rootSlot,agricultureVT,cityVT,districtVT)
 return ([=[
[ENABLE]
assert(%X,85 ED 75 1C 83 FA 09)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0
@N@+100:
pushfq
push rax
push r10
push r11
cmp dword ptr [@N@],0
je original
%s
inc dword ptr [@N@+4]
pop r11
pop r10
pop rax
popfq
jmp %X
original:
pop r11
pop r10
pop rax
popfq
test ebp,ebp
jne %X
cmp edx,9
jmp %X
%X:
jmp @N@+100
nop 2
[DISABLE]
%X:
db 85 ED 75 1C 83 FA 09
unregistersymbol(@N@)
]=]):format(at,at,K.farmOwnGuard(rootSlot,agricultureVT,cityVT,districtVT,'r14'),at+0x49,at+0x20,at+7,at,at):gsub('@N@',symbol)
end
function K.installFarmActionsHooks()
 if K.farmActionsHooks then return end
 K.ready();local m=K.base();local hooks={}
 K.farmActionsHooks=hooks
 for _,site in ipairs({{rva=0x3FD540,size=10,make=K.makeFarmCostScript},{rva=0x363C40,size=7,make=K.makeFarmSeasonScript}})do
  local symbol=('nb15Farm_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
  local at=m+site.rva
  local script=site.make(at,symbol,m+0x11B5D18,m+K.types.agriculture.vt,m+K.types.city.vt,m+K.types.district.vt)
  local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
  hooks[#hooks+1]={q=assert(getAddressSafe(symbol)),at=at,pid=K.pid,script=script,info=info,size=site.size,installed=assert(readBytes(at,site.size,true))}
 end
end
function K.farmActionsFeature(on)
 if on then K.installFarmActionsHooks();assert(#K.farmActionsHooks==2,'Agriculture hooks incomplete')end
 for _,h in ipairs(K.farmActionsHooks or {})do assert(writeInteger(h.q,on and 1 or 0))end
 if on then
  local clan=assert(K.clan());assert(K.indexOf('clan',clan))
  -- A zero stock remains usable with zero cost; restore one unit for display.
  for _,offset in ipairs({0x1653,0x1654})do if readBytes(clan+offset,1)==0 then assert(writeBytes(clan+offset,1))end end
  if readSmallInteger(clan+0x1656)==0 then assert(writeSmallInteger(clan+0x1656,1))end
 end
end
function K.removeFarmActionsHooks()
 local hooks=K.farmActionsHooks;if not hooks then return end
 assert(not K.nativeBusy(),'A pending operation must retain its hooks')
 for _,h in ipairs(hooks)do
  if h.pid==getOpenedProcessID() and K.buildMatches()then
   local bytes=assert(readBytes(h.at,h.size,true))
   for i,b in ipairs(h.installed)do assert(bytes[i]==b,'Agriculture hook ownership changed')end
   assert(writeInteger(h.q,0));assert((K.assemble or autoAssemble)(h.script,h.info))
  end
 end
 K.farmActionsHooks=nil
end
local open=K.openEditor
function K.openEditor(mr,kind)
 open(mr,kind);if kind~='player' then return end
 local id=assert(K.indexOf('clan',K.clan()))
 for _,field in ipairs({
  {en='Agriculture labor',jp='農業の労力',off=0x1656,min=0,max=99,size=2},
  {en='Agriculture fertilizer',jp='農業の肥料',off=0x1653,min=0,max=99,size=1},
  {en='Agriculture good seeds',jp='農業の良種',off=0x1654,min=0,max=99,size=1}})do K.addField(mr,'clan',id,field)end
end

end

do
local K=NB.K15
-- 3D19D0 is a work-completion routine: its player report dereferences the
-- assigned officer even when nil. Completed facilities must not call it.
function K.installFacilityLevelWrapper()
 if K.facilityLevelWrapper then return end
 K.ready()
 local symbol=('nb15FacilityLevel_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=([=[
[ENABLE]
alloc(@N@,4096,%X)
registersymbol(@N@)
label(done)
label(limit)
@N@:
push rbx
sub rsp,20
mov rbx,rcx
movzx eax,byte ptr [rbx+165]
sub eax,2
cmp eax,1
ja done
mov rcx,[rbx+150]
test rcx,rcx
jz done
movzx eax,byte ptr [rcx+27]
cmp eax,A
jbe limit
mov eax,A
limit:
cmp edx,1
jl done
cmp edx,eax
jg done
mov [rbx+164],dl
mov rax,%X
call rax
test rax,rax
jz done
mov rcx,rax
movzx edx,word ptr [rbx+D8]
mov rax,%X
call rax
done:
add rsp,20
pop rbx
ret
[DISABLE]
unregistersymbol(@N@)
// Retain allocation until process exit: never free an in-flight callback.
]=]):format(K.base(),K.base()+0x1EE3D0,K.base()+0x6CE760):gsub('@N@',symbol)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 local q=assert(getAddressSafe(symbol))
 K.facilityLevelWrapper={q=q,pid=K.pid,script=script,info=info}
 K.nativeDefinitions.facilityLevelChange={rva=q-K.base(),bytes='53 48 83 EC 20',kind='county'}
end
function K.removeFacilityLevelWrapper()
 local h=K.facilityLevelWrapper;if not h then return end
 assert(not K.nativeBusy(),'A pending facility operation must retain its wrapper')
 if h.pid==getOpenedProcessID() and K.buildMatches() then assert((K.assemble or autoAssemble)(h.script,h.info)) end
 K.facilityLevelWrapper=nil;K.nativeDefinitions.facilityLevelChange=nil
end
function K.facilityInfo(index)
 local county=K.object('county',index);if not county then return end
 local facility=readQword(county+0x150)
 if not K.indexOf('facility',facility) then return end
 local level=readBytes(county+0x164,1);local state=readBytes(county+0x165,1)
 local limit=math.min(10,assert(readBytes(facility+0x27,1)))
 if not level or level&lt;1 or level&gt;10 or limit&lt;1 then return end
 return {p=county,facility=facility,level=level,state=state,limit=limit}
end
function K.setFacilityLevel(index,value)
 K.ready();local info=assert(K.facilityInfo(index),'Facility is unavailable')
 assert(info.state==2 or info.state==3,'Finish facility construction before changing its level')
 assert(type(value)=='number' and value%1==0 and value&gt;=1 and value&lt;=info.limit,'Facility level is outside its native limit')
 if value==info.level then return end
 local worker=readQword(info.p+0x158)
 assert(worker==0 or K.indexOf('officer',worker),'Facility worker context is invalid')
 local token=K.key()
 K.installFacilityLevelWrapper()
 K.nativeCall('facilityLevelChange','county',index,value)
 assert(K.key()==token and K.object('county',index)==info.p,'Facility context changed')
 assert(readBytes(info.p+0x164,1)==value,'Facility level did not change')
 assert(readQword(info.p+0x158)==worker and readBytes(info.p+0x165,1)==info.state,'Facility assignment changed')
 if K.refreshFacilityRows then K.refreshFacilityRows() end
end
function K.facilityMaxTick()
 K.ready();local owned=K.ownedCitySet()
 for _,item in ipairs(K.objects('county')) do
  local state=readBytes(item.p+0x165,1);local level=readBytes(item.p+0x164,1)
  if (state==2 or state==3) and level and level&lt;10 and owned[readQword(item.p+0x28)] then
   local info=K.facilityInfo(item.id)
   if info and (info.state==2 or info.state==3) and info.level&lt;info.limit and K.ownCounty(item.p) then
    K.setFacilityLevel(item.id,info.limit)
    return 1
   end
  end
 end
 return 0
end
K.facilityRows=K.facilityRows or {}
local function labels(info)
 return ('Facility level: %d / %d'):format(info.level,info.limit),
  ('施設レベル：%d / %d'):format(info.level,info.limit)
end
function K.refreshFacilityRows()
 for id,entry in pairs(K.facilityRows) do
  local row=getAddressList().getMemoryRecordByID(id)
  if not row then K.facilityRows[id]=nil
  elseif K.key()==entry.token then
   local info=K.facilityInfo(entry.index)
   if info then
    local en,jp=labels(info)
    for _,d in ipairs(NB.dyn or {}) do if d.mr==row then d.en=en;d.ja=jp;break end end
    row.Description=NB.T(en,jp)
   end
  end
 end
end
function K.chooseFacilityLevel(index)
 K.ready();local token=K.key();local info=assert(K.facilityInfo(index),'Facility is unavailable')
 local names={};for i=1,info.limit do names[i]=tostring(i) end
 local n=NB.pick(NB.T('Facility level','施設レベル'),names)
 if not n then return end
 assert(K.key()==token,'Game data changed; reopen the facility editor')
 K.setFacilityLevel(index,n)
end
function K.addFacilityEditor(parent,item,owner)
 local info=K.facilityInfo(item.id);if not info then return end
 local en,jp=labels(info);local row=NB.addRec(parent,en,jp,'',vtAutoAssembler)
 row.Script='[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.K15.chooseFacilityLevel('..item.id..') end)\n{$asm}\n[DISABLE]\n'
 local token=K.key();local p=item.p
 row.OnActivate=function(_,before)
  if before then return K.key()==token and K.object('county',item.id)==p end
  return true
 end
 K.facilityRows[row.ID]={index=item.id,owner=owner,token=token}
end
local close=K.closeEditor
function K.closeEditor(mr)
 for id,entry in pairs(K.facilityRows) do if entry.owner==mr then K.facilityRows[id]=nil end end
 return close(mr)
end

end

do
local K=NB.K15
K.commerceClasses={
 [0xBA6BD0]={rva=0x20ACD0,name='commerceExpand',bytes='40 57 48 83 EC 20 48 8B 01 48 8B F9 FF 90'},
 [0xBA6D28]={rva=0x20AA30,name='commerceMonopoly',bytes='40 56 48 83 EC 20 48 8B 01 48 8B F1 FF 90'},
 [0xBA6E80]={rva=0x20ADD0,name='commerceInvest',bytes='40 56 48 83 EC 20 48 8B 01 48 8B F1 FF 90'},
 [0xBA6FD8]={rva=0x20AB80,name='commerceOther',bytes='40 56 48 83 EC 20 48 8B 01 48 8B F1 FF 90'}}
for vt,entry in pairs(K.commerceClasses) do
 -- Use the native runner, which also deregisters an ended command. Calling
 -- only virtual update +90 leaves a completed order on the active list.
 K.nativeDefinitions[entry.name]={rva=0x3A5950,bytes='40 53 48 83 EC 20 48 8B D9 E8 A2 10 FF FF',kind='mission',vt=vt}
 K.nativeDefinitions[entry.name..'Market']={rva=0x39FE30,bytes='48 8B 41 28 BA FF FF FF FF 48 85 C0',kind='mission',vt=vt}
end
function K.marketForCommerce(item)
 local entry=assert(K.commerceClasses[item.vt],'Not a commerce command')
 local market=K.nativeCall(entry.name..'Market','mission',item.id)
 assert(K.indexOf('market',market),'Commerce market is unavailable')
 return market
end
function K.makeCommerceElapsedScript(at,symbol,rootSlot,module)
 return ([=[
[ENABLE]
assert(%X,40 53 48 83 EC 20)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
label(classOK)
@N@:
dd 0 0
@N@+100:
pushfq
push r10
push r11
cmp dword ptr [@N@],0
je original
test rcx,rcx
jz original
mov r10,%X
cmp [rcx],r10
je classOK
mov r10,%X
cmp [rcx],r10
je classOK
mov r10,%X
cmp [rcx],r10
je classOK
mov r10,%X
cmp [rcx],r10
jne original
classOK:
cmp dword ptr [rcx+60],0
jne original
mov r11,[rcx+30]
test r11,r11
jz original
mov r10,%X
cmp [r11],r10
jne original
mov r11,[r11+20]
test r11,r11
jz original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
cmp [r10+20],r11
jne original
inc dword ptr [@N@+4]
pop r11
pop r10
popfq
mov eax,7FFF
ret
original:
pop r11
pop r10
popfq
push rbx
sub rsp,20
jmp %X
%X:
jmp @N@+100
nop
[DISABLE]
%X:
db 40 53 48 83 EC 20
unregistersymbol(@N@)
]=]):format(at,at,module+0xBA6BD0,module+0xBA6D28,module+0xBA6E80,module+0xBA6FD8,
 module+K.types.district.vt,rootSlot,at+6,at,at):gsub('@N@',symbol)
end
function K.installCommerceElapsedHook()
 if K.commerceElapsedHook then return end
 K.ready();local m=K.base();local at=m+0x358360
 local symbol=('nb15CommerceElapsed_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeCommerceElapsedScript(at,symbol,m+0x11B5D18,m)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.commerceElapsedHook={q=assert(getAddressSafe(symbol)),at=at,pid=K.pid,script=script,info=info,
  installed=assert(readBytes(at,6,true))}
end
function K.removeCommerceElapsedHook()
 local h=K.commerceElapsedHook;if not h then return end
 assert(not K.nativeBusy(),'A pending commerce operation must retain its elapsed hook')
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local actual=assert(readBytes(h.at,6,true))
  for i,b in ipairs(h.installed) do assert(actual[i]==b,'Commerce elapsed hook ownership changed') end
  writeInteger(h.q,0);assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore commerce elapsed hook')
 end
 K.commerceElapsedHook=nil
end
function K.finishCommerce()
 K.ready();assert(not K.nativeBusy(),'Operation pending')
 for _,item in ipairs(K.missionObjects()) do
  local entry=K.commerceClasses[item.vt]
  if entry then
   K.marketForCommerce(item)
   local token=K.key()
   K.installCommerceElapsedHook();writeInteger(K.commerceElapsedHook.q,1)
   K.nativeCall(entry.name,'mission',item.id)
   assert(K.key()==token,'Game data changed during commerce completion')
   assert(not K.missionObject(item.id,item.vt),'Commerce command has not finished')
   return 1
  end
 end
 return 0
end
function K.commerceInstantFeature(on)
 if not on then
  K.periodic('commerceInstant',false)
  if K.commerceElapsedHook then writeInteger(K.commerceElapsedHook.q,0) end
  return
 end
 K.periodic('commerceInstant',true,K.finishCommerce)
end

end

do
local K=NB.K15
-- Only game 4 dispatches here. Older games retain their original lifecycle.
K.timers=K.timers or {}
function K.reportFeatureFailure(name,why)
 NB.msg(tostring(why))
 local id=({cityMax=304,instantDevelopment=602,goodwill=15001,covertInstant=15002,
  maxInvestment=15005,commerceInstant=15006})[name]
 local row=id and getAddressList().getMemoryRecordByID(id)
 if row and row.Active then NB.deferOff(row) end
end
function K.periodic(name,on,callback)
 if K.timers[name] then K.timers[name].destroy();K.timers[name]=nil end
 K.on[name]=nil
 if not on then return end
 K.ready();assert(not K.nativeBusy(),'A game operation is pending');callback();K.on[name]=true
 local timer=createTimer(nil,false);timer.Interval=500;K.timers[name]=timer;local running=false
 timer.OnTimer=function(t)
  if running then return end
  if getOpenedProcessID()~=K.pid then t.Enabled=false;return end
  if K.nativeBusy() then return end
  t.Enabled=false;running=true
  local ok,why=pcall(callback)
  running=false
  if not ok then K.on[name]=nil;K.reportFeatureFailure(name,why)
  elseif K.timers[name]==t and K.on[name] then t.Enabled=true end
 end
 timer.Enabled=true
end
function K.instantDevelopment(on)
 if not on then
  K.periodic('instantDevelopment',false)
  K.castleWorkFeature(false)
  return
 end
 K.periodic('instantDevelopment',true,function()
  K.finishConstruction();K.finishCastleWork()
  for _,city in ipairs(K.objects('city')) do
   if K.ownCity(city.p) then
    local damaged=false
    for _,part in ipairs(K.castleParts(city.p)) do
     if (part.flags&amp;0x80)==0 and part.current&lt;part.max then damaged=true;break end
    end
    if damaged then K.repairCity(city.id) end
   end
  end
 end)
end
function K.economyActionsFeature(on)
 if on then
  local ok,why=pcall(function()K.commerceActionsFeature(true);K.farmActionsFeature(true)end)
  if not ok then
   pcall(K.farmActionsFeature,false);pcall(K.commerceActionsFeature,false)
   error(why,0)
  end
 else
  local farmOK,farmError=pcall(K.farmActionsFeature,false)
  local commerceOK,commerceError=pcall(K.commerceActionsFeature,false)
  assert(farmOK,farmError);assert(commerceOK,commerceError)
 end
end
function K.feature(name,on)
 local handlers={actions=K.economyActionsFeature,ownBattle=K.invincibleFeature,playerBattle=K.playerBattleFeature,battleOneHit=K.oneHitFeature,
  battleSkills=K.tacticalGaugeFeature,armySpeed=K.movementFeature,loyalty=K.loyaltyFeature,
  recruitment=K.recruitmentFeature,goodwill=K.goodwillInstantFeature,
  covertInstant=K.covertInstantFeature,covertProposal=K.covertProposalFeature,covertChance=K.covertChanceFeature,
  instantDevelopment=K.instantDevelopment,negotiationSuccess=K.negotiationSuccessFeature,
  commerceInstant=K.commerceInstantFeature,
  maxInvestment=function(v) K.periodic('maxInvestment',v,K.facilityMaxTick) end,
  cityMax=function(v) K.periodic('cityMax',v,K.cityMaxTick) end}
 local handler=assert(handlers[name],'Unknown Taishi feature: '..tostring(name))
 if on then K.ready() end
 handler(on);K.on[name]=on or nil
end
function K.allOff()
 -- Pending native calls may be waiting for a report. Keep ownership until
 -- the game returns instead of detaching its dispatcher under a live call.
 assert(not K.nativeBusy() and not K.covertPending and not K.goodwillPending,
  NB.T('Close the current in-game report before All OFF.','ゲーム内の報告を閉じてから一括解除してください。'))
 if K.closeTreasureWizard then K.closeTreasureWizard()end
 for name,timer in pairs(K.timers) do timer.destroy();K.timers[name]=nil end
 K.covertInstantFeature(false);K.goodwillInstantFeature(false)
 for _,name in ipairs({'actions','ownBattle','playerBattle','battleOneHit','battleSkills','armySpeed','loyalty','recruitment',
   'covertProposal','instantDevelopment','cityMax','negotiationSuccess','maxInvestment','commerceInstant'}) do K.feature(name,false) end
 for _,remove in ipairs({'removeGoodwillInstant','removeCovertProposalHook','removeCovertDayHook',
  'removeCovertChanceHook','removeRecruitmentHook','removeMovementHook','removeTacticalGaugeHook',
  'removeTacticalStrengthHook','removeTacticalMoraleHook','removeSiegeHook','removeWarWillHook',
  'removeFoodHook','removeTroopHook','removeLoyaltyHook','removeCastleWorkHook','removeRepairHook',
  'removeResourceNegotiationHook','removeTradeNegotiationHook','removeNegotiationDecisionHooks',
  'removeNegotiationAccessHook','removeRoleAwardWrapper','removeFacilityLevelWrapper','removeCommerceActionsHook','removeFarmActionsHooks','removeCommerceElapsedHook','removeNative'}) do if K[remove] then K[remove]() end end
 K.on={}
end
function K.attachAndOff()
 if K.attached() then K.allOff();return end
 local pid=getProcessIDFromProcessName(K.EXE)
 assert(pid and pid~=0,NB.T('Start Taishi PK first.','先に大志PKを起動してください。'))
 if K.pid and K.pid~=pid then K.forgetEndedSession() end
 openProcess(pid);K.pid=getOpenedProcessID()
 assert(K.pid==pid and K.buildMatches(),NB.T('Unsupported Taishi executable.','対応していない大志のEXEです。'))
 if K.recoverOrphanedHooks then
  local ok,why=pcall(K.recoverOrphanedHooks)
  if not ok then K.pid=nil;error(why,0)end
 end
 NB.msg(('Attached to %s (PID %d), version %s, Steam build %s.'):format(K.EXE,pid,K.VERSION,K.STEAMBUILD),
  ('%s（PID %d）へアタッチ。バージョン%s、Steam build %s。'):format(K.EXE,pid,K.VERSION,K.STEAMBUILD))
end
function K.forgetEndedSession()
 local processes=getProcessList()
 assert(not K.pid or (not processes[K.pid] and not processes[tostring(K.pid)]),
  NB.T('The previous game process is still running. Release its features first.',
   '以前のゲームプロセスが動作中です。そのプロセスの機能を先に解除してください。'))
 if K.closeTreasureWizard then K.closeTreasureWizard()end
 -- The old process has ended: its allocations no longer exist. Do not try
 -- to unpatch or write their flags into the restarted process.
 for name,t in pairs(K.timers) do t.destroy();K.timers[name]=nil end
 for _,name in ipairs({'goodwillTimer','covertTimer','covertScanTimer'}) do
  if K[name] then K[name].destroy();K[name]=nil end
 end
 local editors={};for _,e in pairs(K.editors) do editors[#editors+1]=e.mr end
 for _,mr in ipairs(editors) do K.closeEditor(mr) end
 local clear={}
 for name,value in pairs(K) do
  if type(value)=='table' and (name:match('Hook$') or name:match('Hooks$')) then clear[#clear+1]=name end
 end
 for _,name in ipairs(clear) do K[name]=nil end
 for _,name in ipairs({'native','roleAwardWrapper','facilityLevelWrapper','goodwillPending','covertPending',
  'goodwillLast','goodwillAttempted','covertAttempted'}) do K[name]=nil end
 K.nativeDefinitions.roleAward=nil
 K.nativeDefinitions.facilityLevelChange=nil
 K.on={};K.sel={};K.editors={};K.dropdownRecords={};K.rankRows={};K.facilityRows={};K.pid=nil
end
function K.disconnect()
 if K.closeTreasureWizard then K.closeTreasureWizard()end
 if K.attached() then K.allOff() end
 local ids={};for id in pairs(K.editors) do ids[#ids+1]=id end
 for _,id in ipairs(ids) do
  local row=getAddressList().getMemoryRecordByID(id)
  if row then K.closeEditor(row) end
 end
 K.editors={};K.dropdownRecords={}
 K.pid=nil;K.sel={}
end
function K.report()
 NB.msg(('Taishi PK: EXE %s; version %s; Steam build %s; PE %08X; SizeOfImage %X; PID %s.'):format(
  K.EXE,K.VERSION,K.STEAMBUILD,K.BUILD.ts,K.BUILD.size,tostring(K.pid)))
end

end
return NB.K15
end
local function createTaishiTC()

do
-- Taishi PK x64, FileVersion 1.0.0.7 / Steam build 3876132.
-- Independent of the x86 N11/N12/N13 object layouts and native dispatcher.
NB.K15={EXE='NOBU15PK_TC.exe',VERSION='1.0.0.7',STEAMBUILD='3876132',
 BUILD={ts=0x5CE22464,size=0x1B5B000},sel={},editors={},on={}}
local K=NB.K15
local cp950={[0xA140]=0x3000,[0xA141]=0xFF0C,[0xA142]=0x3001,[0xA143]=0x3002,[0xA144]=0xFF0E,[0xA145]=0x2027,[0xA146]=0xFF1B,[0xA147]=0xFF1A,[0xA148]=0xFF1F,[0xA149]=0xFF01,[0xA14A]=0xFE30,[0xA14B]=0x2026,[0xA14C]=0x2025,[0xA14D]=0xFE50,[0xA14E]=0xFE51,[0xA14F]=0xFE52,[0xA150]=0xB7,[0xA151]=0xFE54,[0xA152]=0xFE55,[0xA153]=0xFE56,[0xA154]=0xFE57,[0xA155]=0xFF5C,[0xA156]=0x2013,[0xA157]=0xFE31,[0xA158]=0x2014,[0xA159]=0xFE33,[0xA15A]=0x2574,[0xA15B]=0xFE34,[0xA15C]=0xFE4F,[0xA15D]=0xFF08,[0xA15E]=0xFF09,[0xA15F]=0xFE35,[0xA160]=0xFE36,[0xA161]=0xFF5B,[0xA162]=0xFF5D,[0xA163]=0xFE37,[0xA164]=0xFE38,[0xA165]=0x3014,[0xA166]=0x3015,[0xA167]=0xFE39,[0xA168]=0xFE3A,[0xA169]=0x3010,[0xA16A]=0x3011,[0xA16B]=0xFE3B,[0xA16C]=0xFE3C,[0xA16D]=0x300A,[0xA16E]=0x300B,[0xA16F]=0xFE3D,[0xA170]=0xFE3E,[0xA171]=0x3008,[0xA172]=0x3009,[0xA173]=0xFE3F,[0xA174]=0xFE40,[0xA175]=0x300C,[0xA176]=0x300D,[0xA177]=0xFE41,[0xA178]=0xFE42,[0xA179]=0x300E,[0xA17A]=0x300F,[0xA17B]=0xFE43,[0xA17C]=0xFE44,[0xA17D]=0xFE59,[0xA17E]=0xFE5A,[0xA1A1]=0xFE5B,[0xA1A2]=0xFE5C,[0xA1A3]=0x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221F,[0xA1E9]=0x22BF,[0xA1EA]=0x33D2,[0xA1EB]=0x33D1,[0xA1EC]=0x222B,[0xA1ED]=0x222E,[0xA1EE]=0x2235,[0xA1EF]=0x2234,[0xA1F0]=0x2640,[0xA1F1]=0x2642,[0xA1F2]=0x2295,[0xA1F3]=0x2299,[0xA1F4]=0x2191,[0xA1F5]=0x2193,[0xA1F6]=0x2190,[0xA1F7]=0x2192,[0xA1F8]=0x2196,[0xA1F9]=0x2197,[0xA1FA]=0x2199,[0xA1FB]=0x2198,[0xA1FC]=0x2225,[0xA1FD]=0x2223,[0xA1FE]=0xFF0F,[0xA240]=0xFF3C,[0xA241]=0x2215,[0xA242]=0xFE68,[0xA243]=0xFF04,[0xA244]=0xFFE5,[0xA245]=0x3012,[0xA246]=0xFFE0,[0xA247]=0xFFE1,[0xA248]=0xFF05,[0xA249]=0xFF20,[0xA24A]=0x2103,[0xA24B]=0x2109,[0xA24C]=0xFE69,[0xA24D]=0xFE6A,[0xA24E]=0xFE6B,[0xA24F]=0x33D5,[0xA250]=0x339C,[0xA251]=0x339D,[0xA252]=0x339E,[0xA253]=0x33CE,[0xA254]=0x33A1,[0xA255]=0x338E,[0xA256]=0x338F,[0xA257]=0x33C4,[0xA258]=0xB0,[0xA259]=0x5159,[0xA25A]=0x515B,[0xA25B]=0x515E,[0xA25C]=0x515D,[0xA25D]=0x5161,[0xA25E]=0x5163,[0xA25F]=0x55E7,[0xA260]=0x74E9,[0xA261]=0x7CCE,[0xA262]=0x2581,[0xA263]=0x2582,[0xA264]=0x2583,[0xA265]=0x2584,[0xA266]=0x2585,[0xA267]=0x2586,[0xA268]=0x2587,[0xA269]=0x2588,[0xA26A]=0x258F,[0xA26B]=0x258E,[0xA26C]=0x258D,[0xA26D]=0x258C,[0xA26E]=0x258B,[0xA26F]=0x258A,[0xA270]=0x2589,[0xA271]=0x253C,[0xA272]=0x2534,[0xA273]=0x252C,[0xA274]=0x2524,[0xA275]=0x251C,[0xA276]=0x2594,[0xA277]=0x2500,[0xA278]=0x2502,[0xA279]=0x2595,[0xA27A]=0x250C,[0xA27B]=0x2510,[0xA27C]=0x2514,[0xA27D]=0x2518,[0xA27E]=0x256D,[0xA2A1]=0x256E,[0xA2A2]=0x2570,[0xA2A3]=0x256F,[0xA2A4]=0x2550,[0xA2A5]=0x255E,[0xA2A6]=0x256A,[0xA2A7]=0x2561,[0xA2A8]=0x25E2,[0xA2A9]=0x25E3,[0xA2AA]=0x25E5,[0xA2AB]=0x25E4,[0xA2AC]=0x2571,[0xA2AD]=0x2572,[0xA2AE]=0x2573,[0xA2AF]=0xFF10,[0xA2B0]=0xFF11,[0xA2B1]=0xFF12,[0xA2B2]=0xFF13,[0xA2B3]=0xFF14,[0xA2B4]=0xFF15,[0xA2B5]=0xFF16,[0xA2B6]=0xFF17,[0xA2B7]=0xFF18,[0xA2B8]=0xFF19,[0xA2B9]=0x2160,[0xA2BA]=0x2161,[0xA2BB]=0x2162,[0xA2BC]=0x2163,[0xA2BD]=0x2164,[0xA2BE]=0x2165,[0xA2BF]=0x2166,[0xA2C0]=0x2167,[0xA2C1]=0x2168,[0xA2C2]=0x2169,[0xA2C3]=0x3021,[0xA2C4]=0x3022,[0xA2C5]=0x3023,[0xA2C6]=0x3024,[0xA2C7]=0x3025,[0xA2C8]=0x3026,[0xA2C9]=0x3027,[0xA2CA]=0x3028,[0xA2CB]=0x3029,[0xA2CC]=0x5341,[0xA2CD]=0x5344,[0xA2CE]=0x5345,[0xA2CF]=0xFF21,[0xA2D0]=0xFF22,[0xA2D1]=0xFF23,[0xA2D2]=0xFF24,[0xA2D3]=0xFF25,[0xA2D4]=0xFF26,[0xA2D5]=0xFF27,[0xA2D6]=0xFF28,[0xA2D7]=0xFF29,[0xA2D8]=0xFF2A,[0xA2D9]=0xFF2B,[0xA2DA]=0xFF2C,[0xA2DB]=0xFF2D,[0xA2DC]=0xFF2E,[0xA2DD]=0xFF2F,[0xA2DE]=0xFF30,[0xA2DF]=0xFF31,[0xA2E0]=0xFF32,[0xA2E1]=0xFF33,[0xA2E2]=0xFF34,[0xA2E3]=0xFF35,[0xA2E4]=0xFF36,[0xA2E5]=0xFF37,[0xA2E6]=0xFF38,[0xA2E7]=0xFF39,[0xA2E8]=0xFF3A,[0xA2E9]=0xFF41,[0xA2EA]=0xFF42,[0xA2EB]=0xFF43,[0xA2EC]=0xFF44,[0xA2ED]=0xFF45,[0xA2EE]=0xFF46,[0xA2EF]=0xFF47,[0xA2F0]=0xFF48,[0xA2F1]=0xFF49,[0xA2F2]=0xFF4A,[0xA2F3]=0xFF4B,[0xA2F4]=0xFF4C,[0xA2F5]=0xFF4D,[0xA2F6]=0xFF4E,[0xA2F7]=0xFF4F,[0xA2F8]=0xFF50,[0xA2F9]=0xFF51,[0xA2FA]=0xFF52,[0xA2FB]=0xFF53,[0xA2FC]=0xFF54,[0xA2FD]=0xFF55,[0xA2FE]=0xFF56,[0xA340]=0xFF57,[0xA341]=0xFF58,[0xA342]=0xFF59,[0xA343]=0xFF5A,[0xA344]=0x391,[0xA345]=0x392,[0xA346]=0x393,[0xA347]=0x394,[0xA348]=0x395,[0xA349]=0x396,[0xA34A]=0x397,[0xA34B]=0x398,[0xA34C]=0x399,[0xA34D]=0x39A,[0xA34E]=0x39B,[0xA34F]=0x39C,[0xA350]=0x39D,[0xA351]=0x39E,[0xA352]=0x39F,[0xA353]=0x3A0,[0xA354]=0x3A1,[0xA355]=0x3A3,[0xA356]=0x3A4,[0xA357]=0x3A5,[0xA358]=0x3A6,[0xA359]=0x3A7,[0xA35A]=0x3A8,[0xA35B]=0x3A9,[0xA35C]=0x3B1,[0xA35D]=0x3B2,[0xA35E]=0x3B3,[0xA35F]=0x3B4,[0xA360]=0x3B5,[0xA361]=0x3B6,[0xA362]=0x3B7,[0xA363]=0x3B8,[0xA364]=0x3B9,[0xA365]=0x3BA,[0xA366]=0x3BB,[0xA367]=0x3BC,[0xA368]=0x3BD,[0xA369]=0x3BE,[0xA36A]=0x3BF,[0xA36B]=0x3C0,[0xA36C]=0x3C1,[0xA36D]=0x3C3,[0xA36E]=0x3C4,[0xA36F]=0x3C5,[0xA370]=0x3C6,[0xA371]=0x3C7,[0xA372]=0x3C8,[0xA373]=0x3C9,[0xA374]=0x3105,[0xA375]=0x3106,[0xA376]=0x3107,[0xA377]=0x3108,[0xA378]=0x3109,[0xA379]=0x310A,[0xA37A]=0x310B,[0xA37B]=0x310C,[0xA37C]=0x310D,[0xA37D]=0x310E,[0xA37E]=0x310F,[0xA3A1]=0x3110,[0xA3A2]=0x3111,[0xA3A3]=0x3112,[0xA3A4]=0x3113,[0xA3A5]=0x3114,[0xA3A6]=0x3115,[0xA3A7]=0x3116,[0xA3A8]=0x3117,[0xA3A9]=0x3118,[0xA3AA]=0x3119,[0xA3AB]=0x311A,[0xA3AC]=0x311B,[0xA3AD]=0x311C,[0xA3AE]=0x311D,[0xA3AF]=0x311E,[0xA3B0]=0x311F,[0xA3B1]=0x3120,[0xA3B2]=0x3121,[0xA3B3]=0x3122,[0xA3B4]=0x3123,[0xA3B5]=0x3124,[0xA3B6]=0x3125,[0xA3B7]=0x3126,[0xA3B8]=0x3127,[0xA3B9]=0x3128,[0xA3BA]=0x3129,[0xA3BB]=0x2D9,[0xA3BC]=0x2C9,[0xA3BD]=0x2CA,[0xA3BE]=0x2C7,[0xA3BF]=0x2CB,[0xA3E1]=0x20AC,[0xA440]=0x4E00,[0xA441]=0x4E59,[0xA442]=0x4E01,[0xA443]=0x4E03,[0xA444]=0x4E43,[0xA445]=0x4E5D,[0xA446]=0x4E86,[0xA447]=0x4E8C,[0xA448]=0x4EBA,[0xA449]=0x513F,[0xA44A]=0x5165,[0xA44B]=0x516B,[0xA44C]=0x51E0,[0xA44D]=0x5200,[0xA44E]=0x5201,[0xA44F]=0x529B,[0xA450]=0x5315,[0xA451]=0x5341,[0xA452]=0x535C,[0xA453]=0x53C8,[0xA454]=0x4E09,[0xA455]=0x4E0B,[0xA456]=0x4E08,[0xA457]=0x4E0A,[0xA458]=0x4E2B,[0xA459]=0x4E38,[0xA45A]=0x51E1,[0xA45B]=0x4E45,[0xA45C]=0x4E48,[0xA45D]=0x4E5F,[0xA45E]=0x4E5E,[0xA45F]=0x4E8E,[0xA460]=0x4EA1,[0xA461]=0x5140,[0xA462]=0x5203,[0xA463]=0x52FA,[0xA464]=0x5343,[0xA465]=0x53C9,[0xA466]=0x53E3,[0xA467]=0x571F,[0xA468]=0x58EB,[0xA469]=0x5915,[0xA46A]=0x5927,[0xA46B]=0x5973,[0xA46C]=0x5B50,[0xA46D]=0x5B51,[0xA46E]=0x5B53,[0xA46F]=0x5BF8,[0xA470]=0x5C0F,[0xA471]=0x5C22,[0xA472]=0x5C38,[0xA473]=0x5C71,[0xA474]=0x5DDD,[0xA475]=0x5DE5,[0xA476]=0x5DF1,[0xA477]=0x5DF2,[0xA478]=0x5DF3,[0xA479]=0x5DFE,[0xA47A]=0x5E72,[0xA47B]=0x5EFE,[0xA47C]=0x5F0B,[0xA47D]=0x5F13,[0xA47E]=0x624D,[0xA4A1]=0x4E11,[0xA4A2]=0x4E10,[0xA4A3]=0x4E0D,[0xA4A4]=0x4E2D,[0xA4A5]=0x4E30,[0xA4A6]=0x4E39,[0xA4A7]=0x4E4B,[0xA4A8]=0x5C39,[0xA4A9]=0x4E88,[0xA4AA]=0x4E91,[0xA4AB]=0x4E95,[0xA4AC]=0x4E92,[0xA4AD]=0x4E94,[0xA4AE]=0x4EA2,[0xA4AF]=0x4EC1,[0xA4B0]=0x4EC0,[0xA4B1]=0x4EC3,[0xA4B2]=0x4EC6,[0xA4B3]=0x4EC7,[0xA4B4]=0x4ECD,[0xA4B5]=0x4ECA,[0xA4B6]=0x4ECB,[0xA4B7]=0x4EC4,[0xA4B8]=0x5143,[0xA4B9]=0x5141,[0xA4BA]=0x5167,[0xA4BB]=0x516D,[0xA4BC]=0x516E,[0xA4BD]=0x516C,[0xA4BE]=0x5197,[0xA4BF]=0x51F6,[0xA4C0]=0x5206,[0xA4C1]=0x5207,[0xA4C2]=0x5208,[0xA4C3]=0x52FB,[0xA4C4]=0x52FE,[0xA4C5]=0x52FF,[0xA4C6]=0x5316,[0xA4C7]=0x5339,[0xA4C8]=0x5348,[0xA4C9]=0x5347,[0xA4CA]=0x5345,[0xA4CB]=0x535E,[0xA4CC]=0x5384,[0xA4CD]=0x53CB,[0xA4CE]=0x53CA,[0xA4CF]=0x53CD,[0xA4D0]=0x58EC,[0xA4D1]=0x5929,[0xA4D2]=0x592B,[0xA4D3]=0x592A,[0xA4D4]=0x592D,[0xA4D5]=0x5B54,[0xA4D6]=0x5C11,[0xA4D7]=0x5C24,[0xA4D8]=0x5C3A,[0xA4D9]=0x5C6F,[0xA4DA]=0x5DF4,[0xA4DB]=0x5E7B,[0xA4DC]=0x5EFF,[0xA4DD]=0x5F14,[0xA4DE]=0x5F15,[0xA4DF]=0x5FC3,[0xA4E0]=0x6208,[0xA4E1]=0x6236,[0xA4E2]=0x624B,[0xA4E3]=0x624E,[0xA4E4]=0x652F,[0xA4E5]=0x6587,[0xA4E6]=0x6597,[0xA4E7]=0x65A4,[0xA4E8]=0x65B9,[0xA4E9]=0x65E5,[0xA4EA]=0x66F0,[0xA4EB]=0x6708,[0xA4EC]=0x6728,[0xA4ED]=0x6B20,[0xA4EE]=0x6B62,[0xA4EF]=0x6B79,[0xA4F0]=0x6BCB,[0xA4F1]=0x6BD4,[0xA4F2]=0x6BDB,[0xA4F3]=0x6C0F,[0xA4F4]=0x6C34,[0xA4F5]=0x706B,[0xA4F6]=0x722A,[0xA4F7]=0x7236,[0xA4F8]=0x723B,[0xA4F9]=0x7247,[0xA4FA]=0x7259,[0xA4FB]=0x725B,[0xA4FC]=0x72AC,[0xA4FD]=0x738B,[0xA4FE]=0x4E19,[0xA540]=0x4E16,[0xA541]=0x4E15,[0xA542]=0x4E14,[0xA543]=0x4E18,[0xA544]=0x4E3B,[0xA545]=0x4E4D,[0xA546]=0x4E4F,[0xA547]=0x4E4E,[0xA548]=0x4EE5,[0xA549]=0x4ED8,[0xA54A]=0x4ED4,[0xA54B]=0x4ED5,[0xA54C]=0x4ED6,[0xA54D]=0x4ED7,[0xA54E]=0x4EE3,[0xA54F]=0x4EE4,[0xA550]=0x4ED9,[0xA551]=0x4EDE,[0xA552]=0x5145,[0xA553]=0x5144,[0xA554]=0x5189,[0xA555]=0x518A,[0xA556]=0x51AC,[0xA557]=0x51F9,[0xA558]=0x51FA,[0xA559]=0x51F8,[0xA55A]=0x520A,[0xA55B]=0x52A0,[0xA55C]=0x529F,[0xA55D]=0x5305,[0xA55E]=0x5306,[0xA55F]=0x5317,[0xA560]=0x531D,[0xA561]=0x4EDF,[0xA562]=0x534A,[0xA563]=0x5349,[0xA564]=0x5361,[0xA565]=0x5360,[0xA566]=0x536F,[0xA567]=0x536E,[0xA568]=0x53BB,[0xA569]=0x53EF,[0xA56A]=0x53E4,[0xA56B]=0x53F3,[0xA56C]=0x53EC,[0xA56D]=0x53EE,[0xA56E]=0x53E9,[0xA56F]=0x53E8,[0xA570]=0x53FC,[0xA571]=0x53F8,[0xA572]=0x53F5,[0xA573]=0x53EB,[0xA574]=0x53E6,[0xA575]=0x53EA,[0xA576]=0x53F2,[0xA577]=0x53F1,[0xA578]=0x53F0,[0xA579]=0x53E5,[0xA57A]=0x53ED,[0xA57B]=0x53FB,[0xA57C]=0x56DB,[0xA57D]=0x56DA,[0xA57E]=0x5916,[0xA5A1]=0x592E,[0xA5A2]=0x5931,[0xA5A3]=0x5974,[0xA5A4]=0x5976,[0xA5A5]=0x5B55,[0xA5A6]=0x5B83,[0xA5A7]=0x5C3C,[0xA5A8]=0x5DE8,[0xA5A9]=0x5DE7,[0xA5AA]=0x5DE6,[0xA5AB]=0x5E02,[0xA5AC]=0x5E03,[0xA5AD]=0x5E73,[0xA5AE]=0x5E7C,[0xA5AF]=0x5F01,[0xA5B0]=0x5F18,[0xA5B1]=0x5F17,[0xA5B2]=0x5FC5,[0xA5B3]=0x620A,[0xA5B4]=0x6253,[0xA5B5]=0x6254,[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A]=0x5149,[0xA5FB]=0x5147,[0xA5FC]=0x5146,[0xA5FD]=0x5148,[0xA5FE]=0x5168,[0xA640]=0x5171,[0xA641]=0x518D,[0xA642]=0x51B0,[0xA643]=0x5217,[0xA644]=0x5211,[0xA645]=0x5212,[0xA646]=0x520E,[0xA647]=0x5216,[0xA648]=0x52A3,[0xA649]=0x5308,[0xA64A]=0x5321,[0xA64B]=0x5320,[0xA64C]=0x5370,[0xA64D]=0x5371,[0xA64E]=0x5409,[0xA64F]=0x540F,[0xA650]=0x540C,[0xA651]=0x540A,[0xA652]=0x5410,[0xA653]=0x5401,[0xA654]=0x540B,[0xA655]=0x5404,[0xA656]=0x5411,[0xA657]=0x540D,[0xA658]=0x5408,[0xA659]=0x5403,[0xA65A]=0x540E,[0xA65B]=0x5406,[0xA65C]=0x5412,[0xA65D]=0x56E0,[0xA65E]=0x56DE,[0xA65F]=0x56DD,[0xA660]=0x5733,[0xA661]=0x5730,[0xA662]=0x5728,[0xA663]=0x572D,[0xA664]=0x572C,[0xA665]=0x572F,[0xA666]=0x5729,[0xA667]=0x5919,[0xA668]=0x591A,[0xA669]=0x5937,[0xA66A]=0x5938,[0xA66B]=0x5984,[0xA66C]=0x5978,[0xA66D]=0x5983,[0xA66E]=0x597D,[0xA66F]=0x5979,[0xA670]=0x5982,[0xA671]=0x5981,[0xA672]=0x5B57,[0xA673]=0x5B58,[0xA674]=0x5B87,[0xA675]=0x5B88,[0xA676]=0x5B85,[0xA677]=0x5B89,[0xA678]=0x5BFA,[0xA679]=0x5C16,[0xA67A]=0x5C79,[0xA67B]=0x5DDE,[0xA67C]=0x5E06,[0xA67D]=0x5E76,[0xA67E]=0x5E74,[0xA6A1]=0x5F0F,[0xA6A2]=0x5F1B,[0xA6A3]=0x5FD9,[0xA6A4]=0x5FD6,[0xA6A5]=0x620E,[0xA6A6]=0x620C,[0xA6A7]=0x620D,[0xA6A8]=0x6210,[0xA6A9]=0x6263,[0xA6AA]=0x625B,[0xA6AB]=0x6258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F1]=0x4F34,[0xA6F2]=0x4F5B,[0xA6F3]=0x4F55,[0xA6F4]=0x4F30,[0xA6F5]=0x4F50,[0xA6F6]=0x4F51,[0xA6F7]=0x4F3D,[0xA6F8]=0x4F3A,[0xA6F9]=0x4F38,[0xA6FA]=0x4F43,[0xA6FB]=0x4F54,[0xA6FC]=0x4F3C,[0xA6FD]=0x4F46,[0xA6FE]=0x4F63,[0xA740]=0x4F5C,[0xA741]=0x4F60,[0xA742]=0x4F2F,[0xA743]=0x4F4E,[0xA744]=0x4F36,[0xA745]=0x4F59,[0xA746]=0x4F5D,[0xA747]=0x4F48,[0xA748]=0x4F5A,[0xA749]=0x514C,[0xA74A]=0x514B,[0xA74B]=0x514D,[0xA74C]=0x5175,[0xA74D]=0x51B6,[0xA74E]=0x51B7,[0xA74F]=0x5225,[0xA750]=0x5224,[0xA751]=0x5229,[0xA752]=0x522A,[0xA753]=0x5228,[0xA754]=0x52AB,[0xA755]=0x52A9,[0xA756]=0x52AA,[0xA757]=0x52AC,[0xA758]=0x5323,[0xA759]=0x5373,[0xA75A]=0x5375,[0xA75B]=0x541D,[0xA75C]=0x542D,[0xA75D]=0x541E,[0xA75E]=0x543E,[0xA75F]=0x5426,[0xA760]=0x544E,[0xA761]=0x5427,[0xA762]=0x5446,[0xA763]=0x5443,[0xA764]=0x5433,[0xA765]=0x5448,[0xA766]=0x5442,[0xA767]=0x541B,[0xA768]=0x5429,[0xA769]=0x544A,[0xA76A]=0x5439,[0xA76B]=0x543B,[0xA76C]=0x5438,[0xA76D]=0x542E,[0xA76E]=0x5435,[0xA76F]=0x5436,[0xA770]=0x5420,[0xA771]=0x543C,[0xA772]=0x5440,[0xA773]=0x5431,[0xA774]=0x542B,[0xA775]=0x541F,[0xA776]=0x542C,[0xA777]=0x56EA,[0xA778]=0x56F0,[0xA779]=0x56E4,[0xA77A]=0x56EB,[0xA77B]=0x574A,[0xA77C]=0x5751,[0xA77D]=0x5740,[0xA77E]=0x574D,[0xA7A1]=0x5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7E6]=0x6273,[0xA7E7]=0x6292,[0xA7E8]=0x626F,[0xA7E9]=0x6298,[0xA7EA]=0x626E,[0xA7EB]=0x6295,[0xA7EC]=0x6293,[0xA7ED]=0x6291,[0xA7EE]=0x6286,[0xA7EF]=0x6539,[0xA7F0]=0x653B,[0xA7F1]=0x6538,[0xA7F2]=0x65F1,[0xA7F3]=0x66F4,[0xA7F4]=0x675F,[0xA7F5]=0x674E,[0xA7F6]=0x674F,[0xA7F7]=0x6750,[0xA7F8]=0x6751,[0xA7F9]=0x675C,[0xA7FA]=0x6756,[0xA7FB]=0x675E,[0xA7FC]=0x6749,[0xA7FD]=0x6746,[0xA7FE]=0x6760,[0xA840]=0x6753,[0xA841]=0x6757,[0xA842]=0x6B65,[0xA843]=0x6BCF,[0xA844]=0x6C42,[0xA845]=0x6C5E,[0xA846]=0x6C99,[0xA847]=0x6C81,[0xA848]=0x6C88,[0xA849]=0x6C89,[0xA84A]=0x6C85,[0xA84B]=0x6C9B,[0xA84C]=0x6C6A,[0xA84D]=0x6C7A,[0xA84E]=0x6C90,[0xA84F]=0x6C70,[0xA850]=0x6C8C,[0xA851]=0x6C68,[0xA852]=0x6C96,[0xA853]=0x6C92,[0xA854]=0x6C7D,[0xA855]=0x6C83,[0xA856]=0x6C72,[0xA857]=0x6C7E,[0xA858]=0x6C74,[0xA859]=0x6C86,[0xA85A]=0x6C76,[0xA85B]=0x6C8D,[0xA85C]=0x6C94,[0xA85D]=0x6C98,[0xA85E]=0x6C82,[0xA85F]=0x7076,[0xA860]=0x707C,[0xA861]=0x707D,[0xA862]=0x7078,[0xA863]=0x7262,[0xA864]=0x7261,[0xA865]=0x7260,[0xA866]=0x72C4,[0xA867]=0x72C2,[0xA868]=0x7396,[0xA869]=0x752C,[0xA86A]=0x752B,[0xA86B]=0x7537,[0xA86C]=0x7538,[0xA86D]=0x7682,[0xA86E]=0x76EF,[0xA86F]=0x77E3,[0xA870]=0x79C1,[0xA871]=0x79C0,[0xA872]=0x79BF,[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xA8DA]=0x4F96,[0xA8DB]=0x4F7E,[0xA8DC]=0x4F8F,[0xA8DD]=0x4F91,[0xA8DE]=0x4F7A,[0xA8DF]=0x5154,[0xA8E0]=0x5152,[0xA8E1]=0x5155,[0xA8E2]=0x5169,[0xA8E3]=0x5177,[0xA8E4]=0x5176,[0xA8E5]=0x5178,[0xA8E6]=0x51BD,[0xA8E7]=0x51FD,[0xA8E8]=0x523B,[0xA8E9]=0x5238,[0xA8EA]=0x5237,[0xA8EB]=0x523A,[0xA8EC]=0x5230,[0xA8ED]=0x522E,[0xA8EE]=0x5236,[0xA8EF]=0x5241,[0xA8F0]=0x52BE,[0xA8F1]=0x52BB,[0xA8F2]=0x5352,[0xA8F3]=0x5354,[0xA8F4]=0x5353,[0xA8F5]=0x5351,[0xA8F6]=0x5366,[0xA8F7]=0x5377,[0xA8F8]=0x5378,[0xA8F9]=0x5379,[0xA8FA]=0x53D6,[0xA8FB]=0x53D4,[0xA8FC]=0x53D7,[0xA8FD]=0x5473,[0xA8FE]=0x5475,[0xA940]=0x5496,[0xA941]=0x5478,[0xA942]=0x5495,[0xA943]=0x5480,[0xA944]=0x547B,[0xA945]=0x5477,[0xA946]=0x5484,[0xA947]=0x5492,[0xA948]=0x5486,[0xA949]=0x547C,[0xA94A]=0x5490,[0xA94B]=0x5471,[0xA94C]=0x5476,[0xA94D]=0x548C,[0xA94E]=0x549A,[0xA94F]=0x5462,[0xA950]=0x5468,[0xA951]=0x548B,[0xA952]=0x547D,[0xA953]=0x548E,[0xA954]=0x56FA,[0xA955]=0x5783,[0xA956]=0x5777,[0xA957]=0x576A,[0xA958]=0x5769,[0xA959]=0x5761,[0xA95A]=0x5766,[0xA95B]=0x5764,[0xA95C]=0x577C,[0xA95D]=0x591C,[0xA95E]=0x5949,[0xA95F]=0x5947,[0xA960]=0x5948,[0xA961]=0x5944,[0xA962]=0x5954,[0xA963]=0x59BE,[0xA964]=0x59BB,[0xA965]=0x59D4,[0xA966]=0x59B9,[0xA967]=0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=0x6215,[0xA9D0]=0x623F,[0xA9D1]=0x623E,[0xA9D2]=0x6240,[0xA9D3]=0x627F,[0xA9D4]=0x62C9,[0xA9D5]=0x62CC,[0xA9D6]=0x62C4,[0xA9D7]=0x62BF,[0xA9D8]=0x62C2,[0xA9D9]=0x62B9,[0xA9DA]=0x62D2,[0xA9DB]=0x62DB,[0xA9DC]=0x62AB,[0xA9DD]=0x62D3,[0xA9DE]=0x62D4,[0xA9DF]=0x62CB,[0xA9E0]=0x62C8,[0xA9E1]=0x62A8,[0xA9E2]=0x62BD,[0xA9E3]=0x62BC,[0xA9E4]=0x62D0,[0xA9E5]=0x62D9,[0xA9E6]=0x62C7,[0xA9E7]=0x62CD,[0xA9E8]=0x62B5,[0xA9E9]=0x62DA,[0xA9EA]=0x62B1,[0xA9EB]=0x62D8,[0xA9EC]=0x62D6,[0xA9ED]=0x62D7,[0xA9EE]=0x62C6,[0xA9EF]=0x62AC,[0xA9F0]=0x62CE,[0xA9F1]=0x653E,[0xA9F2]=0x65A7,[0xA9F3]=0x65BC,[0xA9F4]=0x65FA,[0xA9F5]=0x6614,[0xA9F6]=0x6613,[0xA9F7]=0x660C,[0xA9F8]=0x6606,[0xA9F9]=0x6602,[0xA9FA]=0x660E,[0xA9FB]=0x6600,[0xA9FC]=0x660F,[0xA9FD]=0x6615,[0xA9FE]=0x660A,[0xAA40]=0x6607,[0xAA41]=0x670D,[0xAA42]=0x670B,[0xAA43]=0x676D,[0xAA44]=0x678B,[0xAA45]=0x6795,[0xAA46]=0x6771,[0xAA47]=0x679C,[0xAA48]=0x6773,[0xAA49]=0x6777,[0xAA4A]=0x6787,[0xAA4B]=0x679D,[0xAA4C]=0x6797,[0xAA4D]=0x676F,[0xAA4E]=0x6770,[0xAA4F]=0x677F,[0xAA50]=0x6789,[0xAA51]=0x677E,[0xAA52]=0x6790,[0xAA53]=0x6775,[0xAA54]=0x679A,[0xAA55]=0x6793,[0xAA56]=0x677C,[0xAA57]=0x676A,[0xAA58]=0x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0xAB47]=0x4EAE,[0xAB48]=0x4FE1,[0xAB49]=0x4FB5,[0xAB4A]=0x4FAF,[0xAB4B]=0x4FBF,[0xAB4C]=0x4FE0,[0xAB4D]=0x4FD1,[0xAB4E]=0x4FCF,[0xAB4F]=0x4FDD,[0xAB50]=0x4FC3,[0xAB51]=0x4FB6,[0xAB52]=0x4FD8,[0xAB53]=0x4FDF,[0xAB54]=0x4FCA,[0xAB55]=0x4FD7,[0xAB56]=0x4FAE,[0xAB57]=0x4FD0,[0xAB58]=0x4FC4,[0xAB59]=0x4FC2,[0xAB5A]=0x4FDA,[0xAB5B]=0x4FCE,[0xAB5C]=0x4FDE,[0xAB5D]=0x4FB7,[0xAB5E]=0x5157,[0xAB5F]=0x5192,[0xAB60]=0x5191,[0xAB61]=0x51A0,[0xAB62]=0x524E,[0xAB63]=0x5243,[0xAB64]=0x524A,[0xAB65]=0x524D,[0xAB66]=0x524C,[0xAB67]=0x524B,[0xAB68]=0x5247,[0xAB69]=0x52C7,[0xAB6A]=0x52C9,[0xAB6B]=0x52C3,[0xAB6C]=0x52C1,[0xAB6D]=0x530D,[0xAB6E]=0x5357,[0xAB6F]=0x537B,[0xAB70]=0x539A,[0xAB71]=0x53DB,[0xAB72]=0x54AC,[0xAB73]=0x54C0,[0xAB74]=0x54A8,[0xAB75]=0x54CE,[0xAB76]=0x54C9,[0xAB77]=0x54B8,[0xAB78]=0x54A6,[0xAB79]=0x54B3,[0xAB7A]=0x54C7,[0xAB7B]=0x54C2,[0xAB7C]=0x54BD,[0xAB7D]=0x54AA,[0xAB7E]=0x54C1,[0xABA1]=0x54C4,[0xABA2]=0x54C8,[0xABA3]=0x54AF,[0xABA4]=0x54AB,[0xABA5]=0x54B1,[0xABA6]=0x54BB,[0xABA7]=0x54A9,[0xABA8]=0x54A7,[0xABA9]=0x54BF,[0xABAA]=0x56FF,[0xABAB]=0x5782,[0xABAC]=0x578B,[0xABAD]=0x57A0,[0xABAE]=0x57A3,[0xABAF]=0x57A2,[0xABB0]=0x57CE,[0xABB1]=0x57AE,[0xABB2]=0x5793,[0xABB3]=0x5955,[0xABB4]=0x5951,[0xABB5]=0x594F,[0xABB6]=0x594E,[0xABB7]=0x5950,[0xABB8]=0x59DC,[0xABB9]=0x59D8,[0xABBA]=0x59FF,[0xABBB]=0x59E3,[0xABBC]=0x59E8,[0xABBD]=0x5A03,[0xABBE]=0x59E5,[0xABBF]=0x59EA,[0xABC0]=0x59DA,[0xABC1]=0x59E6,[0xABC2]=0x5A01,[0xABC3]=0x59FB,[0xABC4]=0x5B69,[0xABC5]=0x5BA3,[0xABC6]=0x5BA6,[0xABC7]=0x5BA4,[0xABC8]=0x5BA2,[0xABC9]=0x5BA5,[0xABCA]=0x5C01,[0xABCB]=0x5C4E,[0xABCC]=0x5C4F,[0xABCD]=0x5C4D,[0xABCE]=0x5C4B,[0xABCF]=0x5CD9,[0xABD0]=0x5CD2,[0xABD1]=0x5DF7,[0xABD2]=0x5E1D,[0xABD3]=0x5E25,[0xABD4]=0x5E1F,[0xABD5]=0x5E7D,[0xABD6]=0x5EA0,[0xABD7]=0x5EA6,[0xABD8]=0x5EFA,[0xABD9]=0x5F08,[0xABDA]=0x5F2D,[0xABDB]=0x5F65,[0xABDC]=0x5F88,[0xABDD]=0x5F85,[0xABDE]=0x5F8A,[0xABDF]=0x5F8B,[0xABE0]=0x5F87,[0xABE1]=0x5F8C,[0xABE2]=0x5F89,[0xABE3]=0x6012,[0xABE4]=0x601D,[0xABE5]=0x6020,[0xABE6]=0x6025,[0xABE7]=0x600E,[0xABE8]=0x6028,[0xABE9]=0x604D,[0xABEA]=0x6070,[0xABEB]=0x6068,[0xABEC]=0x6062,[0xABED]=0x6046,[0xABEE]=0x6043,[0xABEF]=0x606C,[0xABF0]=0x606B,[0xABF1]=0x606A,[0xABF2]=0x6064,[0xABF3]=0x6241,[0xABF4]=0x62DC,[0xABF5]=0x6316,[0xABF6]=0x6309,[0xABF7]=0x62FC,[0xABF8]=0x62ED,[0xABF9]=0x6301,[0xABFA]=0x62EE,[0xABFB]=0x62FD,[0xABFC]=0x6307,[0xABFD]=0x62F1,[0xABFE]=0x62F7,[0xAC40]=0x62EF,[0xAC41]=0x62EC,[0xAC42]=0x62FE,[0xAC43]=0x62F4,[0xAC44]=0x6311,[0xAC45]=0x6302,[0xAC46]=0x653F,[0xAC47]=0x6545,[0xAC48]=0x65AB,[0xAC49]=0x65BD,[0xAC4A]=0x65E2,[0xAC4B]=0x6625,[0xAC4C]=0x662D,[0xAC4D]=0x6620,[0xAC4E]=0x6627,[0xAC4F]=0x662F,[0xAC50]=0x661F,[0xAC51]=0x6628,[0xAC52]=0x6631,[0xAC53]=0x6624,[0xAC54]=0x66F7,[0xAC55]=0x67FF,[0xAC56]=0x67D3,[0xAC57]=0x67F1,[0xAC58]=0x67D4,[0xAC59]=0x67D0,[0xAC5A]=0x67EC,[0xAC5B]=0x67B6,[0xAC5C]=0x67AF,[0xAC5D]=0x67F5,[0xAC5E]=0x67E9,[0xAC5F]=0x67EF,[0xAC60]=0x67C4,[0xAC61]=0x67D1,[0xAC62]=0x67B4,[0xAC63]=0x67DA,[0xAC64]=0x67E5,[0xAC65]=0x67B8,[0xAC66]=0x67CF,[0xAC67]=0x67DE,[0xAC68]=0x67F3,[0xAC69]=0x67B0,[0xAC6A]=0x67D9,[0xAC6B]=0x67E2,[0xAC6C]=0x67DD,[0xAC6D]=0x67D2,[0xAC6E]=0x6B6A,[0xAC6F]=0x6B83,[0xAC70]=0x6B86,[0xAC71]=0x6BB5,[0xAC72]=0x6BD2,[0xAC73]=0x6BD7,[0xAC74]=0x6C1F,[0xAC75]=0x6CC9,[0xAC76]=0x6D0B,[0xAC77]=0x6D32,[0xAC78]=0x6D2A,[0xAC79]=0x6D41,[0xAC7A]=0x6D25,[0xAC7B]=0x6D0C,[0xAC7C]=0x6D31,[0xAC7D]=0x6D1E,[0xAC7E]=0x6D17,[0xACA1]=0x6D3B,[0xACA2]=0x6D3D,[0xACA3]=0x6D3E,[0xACA4]=0x6D36,[0xACA5]=0x6D1B,[0xACA6]=0x6CF5,[0xACA7]=0x6D39,[0xACA8]=0x6D27,[0xACA9]=0x6D38,[0xACAA]=0x6D29,[0xACAB]=0x6D2E,[0xACAC]=0x6D35,[0xACAD]=0x6D0E,[0xACAE]=0x6D2B,[0xACAF]=0x70AB,[0xACB0]=0x70BA,[0xACB1]=0x70B3,[0xACB2]=0x70AC,[0xACB3]=0x70AF,[0xACB4]=0x70AD,[0xACB5]=0x70B8,[0xACB6]=0x70AE,[0xACB7]=0x70A4,[0xACB8]=0x7230,[0xACB9]=0x7272,[0xACBA]=0x726F,[0xACBB]=0x7274,[0xACBC]=0x72E9,[0xACBD]=0x72E0,[0xACBE]=0x72E1,[0xACBF]=0x73B7,[0xACC0]=0x73CA,[0xACC1]=0x73BB,[0xACC2]=0x73B2,[0xACC3]=0x73CD,[0xACC4]=0x73C0,[0xACC5]=0x73B3,[0xACC6]=0x751A,[0xACC7]=0x752D,[0xACC8]=0x754F,[0xACC9]=0x754C,[0xACCA]=0x754E,[0xACCB]=0x754B,[0xACCC]=0x75AB,[0xACCD]=0x75A4,[0xACCE]=0x75A5,[0xACCF]=0x75A2,[0xACD0]=0x75A3,[0xACD1]=0x7678,[0xACD2]=0x7686,[0xACD3]=0x7687,[0xACD4]=0x7688,[0xACD5]=0x76C8,[0xACD6]=0x76C6,[0xACD7]=0x76C3,[0xACD8]=0x76C5,[0xACD9]=0x7701,[0xACDA]=0x76F9,[0xACDB]=0x76F8,[0xACDC]=0x7709,[0xACDD]=0x770B,[0xACDE]=0x76FE,[0xACDF]=0x76FC,[0xACE0]=0x7707,[0xACE1]=0x77DC,[0xACE2]=0x7802,[0xACE3]=0x7814,[0xACE4]=0x780C,[0xACE5]=0x780D,[0xACE6]=0x7946,[0xACE7]=0x7949,[0xACE8]=0x7948,[0xACE9]=0x7947,[0xACEA]=0x79B9,[0xACEB]=0x79BA,[0xACEC]=0x79D1,[0xACED]=0x79D2,[0xACEE]=0x79CB,[0xACEF]=0x7A7F,[0xACF0]=0x7A81,[0xACF1]=0x7AFF,[0xACF2]=0x7AFD,[0xACF3]=0x7C7D,[0xACF4]=0x7D02,[0xACF5]=0x7D05,[0xACF6]=0x7D00,[0xACF7]=0x7D09,[0xACF8]=0x7D07,[0xACF9]=0x7D04,[0xACFA]=0x7D06,[0xACFB]=0x7F38,[0xACFC]=0x7F8E,[0xACFD]=0x7FBF,[0xACFE]=0x8004,[0xAD40]=0x8010,[0xAD41]=0x800D,[0xAD42]=0x8011,[0xAD43]=0x8036,[0xAD44]=0x80D6,[0xAD45]=0x80E5,[0xAD46]=0x80DA,[0xAD47]=0x80C3,[0xAD48]=0x80C4,[0xAD49]=0x80CC,[0xAD4A]=0x80E1,[0xAD4B]=0x80DB,[0xAD4C]=0x80CE,[0xAD4D]=0x80DE,[0xAD4E]=0x80E4,[0xAD4F]=0x80DD,[0xAD50]=0x81F4,[0xAD51]=0x8222,[0xAD52]=0x82E7,[0xAD53]=0x8303,[0xAD54]=0x8305,[0xAD55]=0x82E3,[0xAD56]=0x82DB,[0xAD57]=0x82E6,[0xAD58]=0x8304,[0xAD59]=0x82E5,[0xAD5A]=0x8302,[0xAD5B]=0x8309,[0xAD5C]=0x82D2,[0xAD5D]=0x82D7,[0xAD5E]=0x82F1,[0xAD5F]=0x8301,[0xAD60]=0x82DC,[0xAD61]=0x82D4,[0xAD62]=0x82D1,[0xAD63]=0x82DE,[0xAD64]=0x82D3,[0xAD65]=0x82DF,[0xAD66]=0x82EF,[0xAD67]=0x8306,[0xAD68]=0x8650,[0xAD69]=0x8679,[0xAD6A]=0x867B,[0xAD6B]=0x867A,[0xAD6C]=0x884D,[0xAD6D]=0x886B,[0xAD6E]=0x8981,[0xAD6F]=0x89D4,[0xAD70]=0x8A08,[0xAD71]=0x8A02,[0xAD72]=0x8A03,[0xAD73]=0x8C9E,[0xAD74]=0x8CA0,[0xAD75]=0x8D74,[0xAD76]=0x8D73,[0xAD77]=0x8DB4,[0xAD78]=0x8ECD,[0xAD79]=0x8ECC,[0xAD7A]=0x8FF0,[0xAD7B]=0x8FE6,[0xAD7C]=0x8FE2,[0xAD7D]=0x8FEA,[0xAD7E]=0x8FE5,[0xADA1]=0x8FED,[0xADA2]=0x8FEB,[0xADA3]=0x8FE4,[0xADA4]=0x8FE8,[0xADA5]=0x90CA,[0xADA6]=0x90CE,[0xADA7]=0x90C1,[0xADA8]=0x90C3,[0xADA9]=0x914B,[0xADAA]=0x914A,[0xADAB]=0x91CD,[0xADAC]=0x9582,[0xADAD]=0x9650,[0xADAE]=0x964B,[0xADAF]=0x964C,[0xADB0]=0x964D,[0xADB1]=0x9762,[0xADB2]=0x9769,[0xADB3]=0x97CB,[0xADB4]=0x97ED,[0xADB5]=0x97F3,[0xADB6]=0x9801,[0xADB7]=0x98A8,[0xADB8]=0x98DB,[0xADB9]=0x98DF,[0xADBA]=0x9996,[0xADBB]=0x9999,[0xADBC]=0x4E58,[0xADBD]=0x4EB3,[0xADBE]=0x500C,[0xADBF]=0x500D,[0xADC0]=0x5023,[0xADC1]=0x4FEF,[0xADC2]=0x5026,[0xADC3]=0x5025,[0xADC4]=0x4FF8,[0xADC5]=0x5029,[0xADC6]=0x5016,[0xADC7]=0x5006,[0xADC8]=0x503C,[0xADC9]=0x501F,[0xADCA]=0x501A,[0xADCB]=0x5012,[0xADCC]=0x5011,[0xADCD]=0x4FFA,[0xADCE]=0x5000,[0xADCF]=0x5014,[0xADD0]=0x5028,[0xADD1]=0x4FF1,[0xADD2]=0x5021,[0xADD3]=0x500B,[0xADD4]=0x5019,[0xADD5]=0x5018,[0xADD6]=0x4FF3,[0xADD7]=0x4FEE,[0xADD8]=0x502D,[0xADD9]=0x502A,[0xADDA]=0x4FFE,[0xADDB]=0x502B,[0xADDC]=0x5009,[0xADDD]=0x517C,[0xADDE]=0x51A4,[0xADDF]=0x51A5,[0xADE0]=0x51A2,[0xADE1]=0x51CD,[0xADE2]=0x51CC,[0xADE3]=0x51C6,[0xADE4]=0x51CB,[0xADE5]=0x5256,[0xADE6]=0x525C,[0xADE7]=0x5254,[0xADE8]=0x525B,[0xADE9]=0x525D,[0xADEA]=0x532A,[0xADEB]=0x537F,[0xADEC]=0x539F,[0xADED]=0x539D,[0xADEE]=0x53DF,[0xADEF]=0x54E8,[0xADF0]=0x5510,[0xADF1]=0x5501,[0xADF2]=0x5537,[0xADF3]=0x54FC,[0xADF4]=0x54E5,[0xADF5]=0x54F2,[0xADF6]=0x5506,[0xADF7]=0x54FA,[0xADF8]=0x5514,[0xADF9]=0x54E9,[0xADFA]=0x54ED,[0xADFB]=0x54E1,[0xADFC]=0x5509,[0xADFD]=0x54EE,[0xADFE]=0x54EA,[0xAE40]=0x54E6,[0xAE41]=0x5527,[0xAE42]=0x5507,[0xAE43]=0x54FD,[0xAE44]=0x550F,[0xAE45]=0x5703,[0xAE46]=0x5704,[0xAE47]=0x57C2,[0xAE48]=0x57D4,[0xAE49]=0x57CB,[0xAE4A]=0x57C3,[0xAE4B]=0x5809,[0xAE4C]=0x590F,[0xAE4D]=0x5957,[0xAE4E]=0x5958,[0xAE4F]=0x595A,[0xAE50]=0x5A11,[0xAE51]=0x5A18,[0xAE52]=0x5A1C,[0xAE53]=0x5A1F,[0xAE54]=0x5A1B,[0xAE55]=0x5A13,[0xAE56]=0x59EC,[0xAE57]=0x5A20,[0xAE58]=0x5A23,[0xAE59]=0x5A29,[0xAE5A]=0x5A25,[0xAE5B]=0x5A0C,[0xAE5C]=0x5A09,[0xAE5D]=0x5B6B,[0xAE5E]=0x5C58,[0xAE5F]=0x5BB0,[0xAE60]=0x5BB3,[0xAE61]=0x5BB6,[0xAE62]=0x5BB4,[0xAE63]=0x5BAE,[0xAE64]=0x5BB5,[0xAE65]=0x5BB9,[0xAE66]=0x5BB8,[0xAE67]=0x5C04,[0xAE68]=0x5C51,[0xAE69]=0x5C55,[0xAE6A]=0x5C50,[0xAE6B]=0x5CED,[0xAE6C]=0x5CFD,[0xAE6D]=0x5CFB,[0xAE6E]=0x5CEA,[0xAE6F]=0x5CE8,[0xAE70]=0x5CF0,[0xAE71]=0x5CF6,[0xAE72]=0x5D01,[0xAE73]=0x5CF4,[0xAE74]=0x5DEE,[0xAE75]=0x5E2D,[0xAE76]=0x5E2B,[0xAE77]=0x5EAB,[0xAE78]=0x5EAD,[0xAE79]=0x5EA7,[0xAE7A]=0x5F31,[0xAE7B]=0x5F92,[0xAE7C]=0x5F91,[0xAE7D]=0x5F90,[0xAE7E]=0x6059,[0xAEA1]=0x6063,[0xAEA2]=0x6065,[0xAEA3]=0x6050,[0xAEA4]=0x6055,[0xAEA5]=0x606D,[0xAEA6]=0x6069,[0xAEA7]=0x606F,[0xAEA8]=0x6084,[0xAEA9]=0x609F,[0xAEAA]=0x609A,[0xAEAB]=0x608D,[0xAEAC]=0x6094,[0xAEAD]=0x608C,[0xAEAE]=0x6085,[0xAEAF]=0x6096,[0xAEB0]=0x6247,[0xAEB1]=0x62F3,[0xAEB2]=0x6308,[0xAEB3]=0x62FF,[0xAEB4]=0x634E,[0xAEB5]=0x633E,[0xAEB6]=0x632F,[0xAEB7]=0x6355,[0xAEB8]=0x6342,[0xAEB9]=0x6346,[0xAEBA]=0x634F,[0xAEBB]=0x6349,[0xAEBC]=0x633A,[0xAEBD]=0x6350,[0xAEBE]=0x633D,[0xAEBF]=0x632A,[0xAEC0]=0x632B,[0xAEC1]=0x6328,[0xAEC2]=0x634D,[0xAEC3]=0x634C,[0xAEC4]=0x6548,[0xAEC5]=0x6549,[0xAEC6]=0x6599,[0xAEC7]=0x65C1,[0xAEC8]=0x65C5,[0xAEC9]=0x6642,[0xAECA]=0x6649,[0xAECB]=0x664F,[0xAECC]=0x6643,[0xAECD]=0x6652,[0xAECE]=0x664C,[0xAECF]=0x6645,[0xAED0]=0x6641,[0xAED1]=0x66F8,[0xAED2]=0x6714,[0xAED3]=0x6715,[0xAED4]=0x6717,[0xAED5]=0x6821,[0xAED6]=0x6838,[0xAED7]=0x6848,[0xAED8]=0x6846,[0xAED9]=0x6853,[0xAEDA]=0x6839,[0xAEDB]=0x6842,[0xAEDC]=0x6854,[0xAEDD]=0x6829,[0xAEDE]=0x68B3,[0xAEDF]=0x6817,[0xAEE0]=0x684C,[0xAEE1]=0x6851,[0xAEE2]=0x683D,[0xAEE3]=0x67F4,[0xAEE4]=0x6850,[0xAEE5]=0x6840,[0xAEE6]=0x683C,[0xAEE7]=0x6843,[0xAEE8]=0x682A,[0xAEE9]=0x6845,[0xAEEA]=0x6813,[0xAEEB]=0x6818,[0xAEEC]=0x6841,[0xAEED]=0x6B8A,[0xAEEE]=0x6B89,[0xAEEF]=0x6BB7,[0xAEF0]=0x6C23,[0xAEF1]=0x6C27,[0xAEF2]=0x6C28,[0xAEF3]=0x6C26,[0xAEF4]=0x6C24,[0xAEF5]=0x6CF0,[0xAEF6]=0x6D6A,[0xAEF7]=0x6D95,[0xAEF8]=0x6D88,[0xAEF9]=0x6D87,[0xAEFA]=0x6D66,[0xAEFB]=0x6D78,[0xAEFC]=0x6D77,[0xAEFD]=0x6D59,[0xAEFE]=0x6D93,[0xAF40]=0x6D6C,[0xAF41]=0x6D89,[0xAF42]=0x6D6E,[0xAF43]=0x6D5A,[0xAF44]=0x6D74,[0xAF45]=0x6D69,[0xAF46]=0x6D8C,[0xAF47]=0x6D8A,[0xAF48]=0x6D79,[0xAF49]=0x6D85,[0xAF4A]=0x6D65,[0xAF4B]=0x6D94,[0xAF4C]=0x70CA,[0xAF4D]=0x70D8,[0xAF4E]=0x70E4,[0xAF4F]=0x70D9,[0xAF50]=0x70C8,[0xAF51]=0x70CF,[0xAF52]=0x7239,[0xAF53]=0x7279,[0xAF54]=0x72FC,[0xAF55]=0x72F9,[0xAF56]=0x72FD,[0xAF57]=0x72F8,[0xAF58]=0x72F7,[0xAF59]=0x7386,[0xAF5A]=0x73ED,[0xAF5B]=0x7409,[0xAF5C]=0x73EE,[0xAF5D]=0x73E0,[0xAF5E]=0x73EA,[0xAF5F]=0x73DE,[0xAF60]=0x7554,[0xAF61]=0x755D,[0xAF62]=0x755C,[0xAF63]=0x755A,[0xAF64]=0x7559,[0xAF65]=0x75BE,[0xAF66]=0x75C5,[0xAF67]=0x75C7,[0xAF68]=0x75B2,[0xAF69]=0x75B3,[0xAF6A]=0x75BD,[0xAF6B]=0x75BC,[0xAF6C]=0x75B9,[0xAF6D]=0x75C2,[0xAF6E]=0x75B8,[0xAF6F]=0x768B,[0xAF70]=0x76B0,[0xAF71]=0x76CA,[0xAF72]=0x76CD,[0xAF73]=0x76CE,[0xAF74]=0x7729,[0xAF75]=0x771F,[0xAF76]=0x7720,[0xAF77]=0x7728,[0xAF78]=0x77E9,[0xAF79]=0x7830,[0xAF7A]=0x7827,[0xAF7B]=0x7838,[0xAF7C]=0x781D,[0xAF7D]=0x7834,[0xAF7E]=0x7837,[0xAFA1]=0x7825,[0xAFA2]=0x782D,[0xAFA3]=0x7820,[0xAFA4]=0x781F,[0xAFA5]=0x7832,[0xAFA6]=0x7955,[0xAFA7]=0x7950,[0xAFA8]=0x7960,[0xAFA9]=0x795F,[0xAFAA]=0x7956,[0xAFAB]=0x795E,[0xAFAC]=0x795D,[0xAFAD]=0x7957,[0xAFAE]=0x795A,[0xAFAF]=0x79E4,[0xAFB0]=0x79E3,[0xAFB1]=0x79E7,[0xAFB2]=0x79DF,[0xAFB3]=0x79E6,[0xAFB4]=0x79E9,[0xAFB5]=0x79D8,[0xAFB6]=0x7A84,[0xAFB7]=0x7A88,[0xAFB8]=0x7AD9,[0xAFB9]=0x7B06,[0xAFBA]=0x7B11,[0xAFBB]=0x7C89,[0xAFBC]=0x7D21,[0xAFBD]=0x7D17,[0xAFBE]=0x7D0B,[0xAFBF]=0x7D0A,[0xAFC0]=0x7D20,[0xAFC1]=0x7D22,[0xAFC2]=0x7D14,[0xAFC3]=0x7D10,[0xAFC4]=0x7D15,[0xAFC5]=0x7D1A,[0xAFC6]=0x7D1C,[0xAFC7]=0x7D0D,[0xAFC8]=0x7D19,[0xAFC9]=0x7D1B,[0xAFCA]=0x7F3A,[0xAFCB]=0x7F5F,[0xAFCC]=0x7F94,[0xAFCD]=0x7FC5,[0xAFCE]=0x7FC1,[0xAFCF]=0x8006,[0xAFD0]=0x8018,[0xAFD1]=0x8015,[0xAFD2]=0x8019,[0xAFD3]=0x8017,[0xAFD4]=0x803D,[0xAFD5]=0x803F,[0xAFD6]=0x80F1,[0xAFD7]=0x8102,[0xAFD8]=0x80F0,[0xAFD9]=0x8105,[0xAFDA]=0x80ED,[0xAFDB]=0x80F4,[0xAFDC]=0x8106,[0xAFDD]=0x80F8,[0xAFDE]=0x80F3,[0xAFDF]=0x8108,[0xAFE0]=0x80FD,[0xAFE1]=0x810A,[0xAFE2]=0x80FC,[0xAFE3]=0x80EF,[0xAFE4]=0x81ED,[0xAFE5]=0x81EC,[0xAFE6]=0x8200,[0xAFE7]=0x8210,[0xAFE8]=0x822A,[0xAFE9]=0x822B,[0xAFEA]=0x8228,[0xAFEB]=0x822C,[0xAFEC]=0x82BB,[0xAFED]=0x832B,[0xAFEE]=0x8352,[0xAFEF]=0x8354,[0xAFF0]=0x834A,[0xAFF1]=0x8338,[0xAFF2]=0x8350,[0xAFF3]=0x8349,[0xAFF4]=0x8335,[0xAFF5]=0x8334,[0xAFF6]=0x834F,[0xAFF7]=0x8332,[0xAFF8]=0x8339,[0xAFF9]=0x8336,[0xAFFA]=0x8317,[0xAFFB]=0x8340,[0xAFFC]=0x8331,[0xAFFD]=0x8328,[0xAFFE]=0x8343,[0xB040]=0x8654,[0xB041]=0x868A,[0xB042]=0x86AA,[0xB043]=0x8693,[0xB044]=0x86A4,[0xB045]=0x86A9,[0xB046]=0x868C,[0xB047]=0x86A3,[0xB048]=0x869C,[0xB049]=0x8870,[0xB04A]=0x8877,[0xB04B]=0x8881,[0xB04C]=0x8882,[0xB04D]=0x887D,[0xB04E]=0x8879,[0xB04F]=0x8A18,[0xB050]=0x8A10,[0xB051]=0x8A0E,[0xB052]=0x8A0C,[0xB053]=0x8A15,[0xB054]=0x8A0A,[0xB055]=0x8A17,[0xB056]=0x8A13,[0xB057]=0x8A16,[0xB058]=0x8A0F,[0xB059]=0x8A11,[0xB05A]=0x8C48,[0xB05B]=0x8C7A,[0xB05C]=0x8C79,[0xB05D]=0x8CA1,[0xB05E]=0x8CA2,[0xB05F]=0x8D77,[0xB060]=0x8EAC,[0xB061]=0x8ED2,[0xB062]=0x8ED4,[0xB063]=0x8ECF,[0xB064]=0x8FB1,[0xB065]=0x9001,[0xB066]=0x9006,[0xB067]=0x8FF7,[0xB068]=0x9000,[0xB069]=0x8FFA,[0xB06A]=0x8FF4,[0xB06B]=0x9003,[0xB06C]=0x8FFD,[0xB06D]=0x9005,[0xB06E]=0x8FF8,[0xB06F]=0x9095,[0xB070]=0x90E1,[0xB071]=0x90DD,[0xB072]=0x90E2,[0xB073]=0x9152,[0xB074]=0x914D,[0xB075]=0x914C,[0xB076]=0x91D8,[0xB077]=0x91DD,[0xB078]=0x91D7,[0xB079]=0x91DC,[0xB07A]=0x91D9,[0xB07B]=0x9583,[0xB07C]=0x9662,[0xB07D]=0x9663,[0xB07E]=0x9661,[0xB0A1]=0x965B,[0xB0A2]=0x965D,[0xB0A3]=0x9664,[0xB0A4]=0x9658,[0xB0A5]=0x965E,[0xB0A6]=0x96BB,[0xB0A7]=0x98E2,[0xB0A8]=0x99AC,[0xB0A9]=0x9AA8,[0xB0AA]=0x9AD8,[0xB0AB]=0x9B25,[0xB0AC]=0x9B32,[0xB0AD]=0x9B3C,[0xB0AE]=0x4E7E,[0xB0AF]=0x507A,[0xB0B0]=0x507D,[0xB0B1]=0x505C,[0xB0B2]=0x5047,[0xB0B3]=0x5043,[0xB0B4]=0x504C,[0xB0B5]=0x505A,[0xB0B6]=0x5049,[0xB0B7]=0x5065,[0xB0B8]=0x5076,[0xB0B9]=0x504E,[0xB0BA]=0x5055,[0xB0BB]=0x5075,[0xB0BC]=0x5074,[0xB0BD]=0x5077,[0xB0BE]=0x504F,[0xB0BF]=0x500F,[0xB0C0]=0x506F,[0xB0C1]=0x506D,[0xB0C2]=0x515C,[0xB0C3]=0x5195,[0xB0C4]=0x51F0,[0xB0C5]=0x526A,[0xB0C6]=0x526F,[0xB0C7]=0x52D2,[0xB0C8]=0x52D9,[0xB0C9]=0x52D8,[0xB0CA]=0x52D5,[0xB0CB]=0x5310,[0xB0CC]=0x530F,[0xB0CD]=0x5319,[0xB0CE]=0x533F,[0xB0CF]=0x5340,[0xB0D0]=0x533E,[0xB0D1]=0x53C3,[0xB0D2]=0x66FC,[0xB0D3]=0x5546,[0xB0D4]=0x556A,[0xB0D5]=0x5566,[0xB0D6]=0x5544,[0xB0D7]=0x555E,[0xB0D8]=0x5561,[0xB0D9]=0x5543,[0xB0DA]=0x554A,[0xB0DB]=0x5531,[0xB0DC]=0x5556,[0xB0DD]=0x554F,[0xB0DE]=0x5555,[0xB0DF]=0x552F,[0xB0E0]=0x5564,[0xB0E1]=0x5538,[0xB0E2]=0x552E,[0xB0E3]=0x555C,[0xB0E4]=0x552C,[0xB0E5]=0x5563,[0xB0E6]=0x5533,[0xB0E7]=0x5541,[0xB0E8]=0x5557,[0xB0E9]=0x5708,[0xB0EA]=0x570B,[0xB0EB]=0x5709,[0xB0EC]=0x57DF,[0xB0ED]=0x5805,[0xB0EE]=0x580A,[0xB0EF]=0x5806,[0xB0F0]=0x57E0,[0xB0F1]=0x57E4,[0xB0F2]=0x57FA,[0xB0F3]=0x5802,[0xB0F4]=0x5835,[0xB0F5]=0x57F7,[0xB0F6]=0x57F9,[0xB0F7]=0x5920,[0xB0F8]=0x5962,[0xB0F9]=0x5A36,[0xB0FA]=0x5A41,[0xB0FB]=0x5A49,[0xB0FC]=0x5A66,[0xB0FD]=0x5A6A,[0xB0FE]=0x5A40,[0xB140]=0x5A3C,[0xB141]=0x5A62,[0xB142]=0x5A5A,[0xB143]=0x5A46,[0xB144]=0x5A4A,[0xB145]=0x5B70,[0xB146]=0x5BC7,[0xB147]=0x5BC5,[0xB148]=0x5BC4,[0xB149]=0x5BC2,[0xB14A]=0x5BBF,[0xB14B]=0x5BC6,[0xB14C]=0x5C09,[0xB14D]=0x5C08,[0xB14E]=0x5C07,[0xB14F]=0x5C60,[0xB150]=0x5C5C,[0xB151]=0x5C5D,[0xB152]=0x5D07,[0xB153]=0x5D06,[0xB154]=0x5D0E,[0xB155]=0x5D1B,[0xB156]=0x5D16,[0xB157]=0x5D22,[0xB158]=0x5D11,[0xB159]=0x5D29,[0xB15A]=0x5D14,[0xB15B]=0x5D19,[0xB15C]=0x5D24,[0xB15D]=0x5D27,[0xB15E]=0x5D17,[0xB15F]=0x5DE2,[0xB160]=0x5E38,[0xB161]=0x5E36,[0xB162]=0x5E33,[0xB163]=0x5E37,[0xB164]=0x5EB7,[0xB165]=0x5EB8,[0xB166]=0x5EB6,[0xB167]=0x5EB5,[0xB168]=0x5EBE,[0xB169]=0x5F35,[0xB16A]=0x5F37,[0xB16B]=0x5F57,[0xB16C]=0x5F6C,[0xB16D]=0x5F69,[0xB16E]=0x5F6B,[0xB16F]=0x5F97,[0xB170]=0x5F99,[0xB171]=0x5F9E,[0xB172]=0x5F98,[0xB173]=0x5FA1,[0xB174]=0x5FA0,[0xB175]=0x5F9C,[0xB176]=0x607F,[0xB177]=0x60A3,[0xB178]=0x6089,[0xB179]=0x60A0,[0xB17A]=0x60A8,[0xB17B]=0x60CB,[0xB17C]=0x60B4,[0xB17D]=0x60E6,[0xB17E]=0x60BD,[0xB1A1]=0x60C5,[0xB1A2]=0x60BB,[0xB1A3]=0x60B5,[0xB1A4]=0x60DC,[0xB1A5]=0x60BC,[0xB1A6]=0x60D8,[0xB1A7]=0x60D5,[0xB1A8]=0x60C6,[0xB1A9]=0x60DF,[0xB1AA]=0x60B8,[0xB1AB]=0x60DA,[0xB1AC]=0x60C7,[0xB1AD]=0x621A,[0xB1AE]=0x621B,[0xB1AF]=0x6248,[0xB1B0]=0x63A0,[0xB1B1]=0x63A7,[0xB1B2]=0x6372,[0xB1B3]=0x6396,[0xB1B4]=0x63A2,[0xB1B5]=0x63A5,[0xB1B6]=0x6377,[0xB1B7]=0x6367,[0xB1B8]=0x6398,[0xB1B9]=0x63AA,[0xB1BA]=0x6371,[0xB1BB]=0x63A9,[0xB1BC]=0x6389,[0xB1BD]=0x6383,[0xB1BE]=0x639B,[0xB1BF]=0x636B,[0xB1C0]=0x63A8,[0xB1C1]=0x6384,[0xB1C2]=0x6388,[0xB1C3]=0x6399,[0xB1C4]=0x63A1,[0xB1C5]=0x63AC,[0xB1C6]=0x6392,[0xB1C7]=0x638F,[0xB1C8]=0x6380,[0xB1C9]=0x637B,[0xB1CA]=0x6369,[0xB1CB]=0x6368,[0xB1CC]=0x637A,[0xB1CD]=0x655D,[0xB1CE]=0x6556,[0xB1CF]=0x6551,[0xB1D0]=0x6559,[0xB1D1]=0x6557,[0xB1D2]=0x555F,[0xB1D3]=0x654F,[0xB1D4]=0x6558,[0xB1D5]=0x6555,[0xB1D6]=0x6554,[0xB1D7]=0x659C,[0xB1D8]=0x659B,[0xB1D9]=0x65AC,[0xB1DA]=0x65CF,[0xB1DB]=0x65CB,[0xB1DC]=0x65CC,[0xB1DD]=0x65CE,[0xB1DE]=0x665D,[0xB1DF]=0x665A,[0xB1E0]=0x6664,[0xB1E1]=0x6668,[0xB1E2]=0x6666,[0xB1E3]=0x665E,[0xB1E4]=0x66F9,[0xB1E5]=0x52D7,[0xB1E6]=0x671B,[0xB1E7]=0x6881,[0xB1E8]=0x68AF,[0xB1E9]=0x68A2,[0xB1EA]=0x6893,[0xB1EB]=0x68B5,[0xB1EC]=0x687F,[0xB1ED]=0x6876,[0xB1EE]=0x68B1,[0xB1EF]=0x68A7,[0xB1F0]=0x6897,[0xB1F1]=0x68B0,[0xB1F2]=0x6883,[0xB1F3]=0x68C4,[0xB1F4]=0x68AD,[0xB1F5]=0x6886,[0xB1F6]=0x6885,[0xB1F7]=0x6894,[0xB1F8]=0x689D,[0xB1F9]=0x68A8,[0xB1FA]=0x689F,[0xB1FB]=0x68A1,[0xB1FC]=0x6882,[0xB1FD]=0x6B32,[0xB1FE]=0x6BBA,[0xB240]=0x6BEB,[0xB241]=0x6BEC,[0xB242]=0x6C2B,[0xB243]=0x6D8E,[0xB244]=0x6DBC,[0xB245]=0x6DF3,[0xB246]=0x6DD9,[0xB247]=0x6DB2,[0xB248]=0x6DE1,[0xB249]=0x6DCC,[0xB24A]=0x6DE4,[0xB24B]=0x6DFB,[0xB24C]=0x6DFA,[0xB24D]=0x6E05,[0xB24E]=0x6DC7,[0xB24F]=0x6DCB,[0xB250]=0x6DAF,[0xB251]=0x6DD1,[0xB252]=0x6DAE,[0xB253]=0x6DDE,[0xB254]=0x6DF9,[0xB255]=0x6DB8,[0xB256]=0x6DF7,[0xB257]=0x6DF5,[0xB258]=0x6DC5,[0xB259]=0x6DD2,[0xB25A]=0x6E1A,[0xB25B]=0x6DB5,[0xB25C]=0x6DDA,[0xB25D]=0x6DEB,[0xB25E]=0x6DD8,[0xB25F]=0x6DEA,[0xB260]=0x6DF1,[0xB261]=0x6DEE,[0xB262]=0x6DE8,[0xB263]=0x6DC6,[0xB264]=0x6DC4,[0xB265]=0x6DAA,[0xB266]=0x6DEC,[0xB267]=0x6DBF,[0xB268]=0x6DE6,[0xB269]=0x70F9,[0xB26A]=0x7109,[0xB26B]=0x710A,[0xB26C]=0x70FD,[0xB26D]=0x70EF,[0xB26E]=0x723D,[0xB26F]=0x727D,[0xB270]=0x7281,[0xB271]=0x731C,[0xB272]=0x731B,[0xB273]=0x7316,[0xB274]=0x7313,[0xB275]=0x7319,[0xB276]=0x7387,[0xB277]=0x7405,[0xB278]=0x740A,[0xB279]=0x7403,[0xB27A]=0x7406,[0xB27B]=0x73FE,[0xB27C]=0x740D,[0xB27D]=0x74E0,[0xB27E]=0x74F6,[0xB2A1]=0x74F7,[0xB2A2]=0x751C,[0xB2A3]=0x7522,[0xB2A4]=0x7565,[0xB2A5]=0x7566,[0xB2A6]=0x7562,[0xB2A7]=0x7570,[0xB2A8]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8236,[0xB2EE]=0x8239,[0xB2EF]=0x838E,[0xB2F0]=0x839E,[0xB2F1]=0x8398,[0xB2F2]=0x8378,[0xB2F3]=0x83A2,[0xB2F4]=0x8396,[0xB2F5]=0x83BD,[0xB2F6]=0x83AB,[0xB2F7]=0x8392,[0xB2F8]=0x838A,[0xB2F9]=0x8393,[0xB2FA]=0x8389,[0xB2FB]=0x83A0,[0xB2FC]=0x8377,[0xB2FD]=0x837B,[0xB2FE]=0x837C,[0xB340]=0x8386,[0xB341]=0x83A7,[0xB342]=0x8655,[0xB343]=0x5F6A,[0xB344]=0x86C7,[0xB345]=0x86C0,[0xB346]=0x86B6,[0xB347]=0x86C4,[0xB348]=0x86B5,[0xB349]=0x86C6,[0xB34A]=0x86CB,[0xB34B]=0x86B1,[0xB34C]=0x86AF,[0xB34D]=0x86C9,[0xB34E]=0x8853,[0xB34F]=0x889E,[0xB350]=0x8888,[0xB351]=0x88AB,[0xB352]=0x8892,[0xB353]=0x8896,[0xB354]=0x888D,[0xB355]=0x888B,[0xB356]=0x8993,[0xB357]=0x898F,[0xB358]=0x8A2A,[0xB359]=0x8A1D,[0xB35A]=0x8A23,[0xB35B]=0x8A25,[0xB35C]=0x8A31,[0xB35D]=0x8A2D,[0xB35E]=0x8A1F,[0xB35F]=0x8A1B,[0xB360]=0x8A22,[0xB361]=0x8C49,[0xB362]=0x8C5A,[0xB363]=0x8CA9,[0xB364]=0x8CAC,[0xB365]=0x8CAB,[0xB366]=0x8CA8,[0xB367]=0x8CAA,[0xB368]=0x8CA7,[0xB369]=0x8D67,[0xB36A]=0x8D66,[0xB36B]=0x8DBE,[0xB36C]=0x8DBA,[0xB36D]=0x8EDB,[0xB36E]=0x8EDF,[0xB36F]=0x9019,[0xB370]=0x900D,[0xB371]=0x901A,[0xB372]=0x9017,[0xB373]=0x9023,[0xB374]=0x901F,[0xB375]=0x901D,[0xB376]=0x9010,[0xB377]=0x9015,[0xB378]=0x901E,[0xB379]=0x9020,[0xB37A]=0x900F,[0xB37B]=0x9022,[0xB37C]=0x9016,[0xB37D]=0x901B,[0xB37E]=0x9014,[0xB3A1]=0x90E8,[0xB3A2]=0x90ED,[0xB3A3]=0x90FD,[0xB3A4]=0x9157,[0xB3A5]=0x91CE,[0xB3A6]=0x91F5,[0xB3A7]=0x91E6,[0xB3A8]=0x91E3,[0xB3A9]=0x91E7,[0xB3AA]=0x91ED,[0xB3AB]=0x91E9,[0xB3AC]=0x9589,[0xB3AD]=0x966A,[0xB3AE]=0x9675,[0xB3AF]=0x9673,[0xB3B0]=0x9678,[0xB3B1]=0x9670,[0xB3B2]=0x9674,[0xB3B3]=0x9676,[0xB3B4]=0x9677,[0xB3B5]=0x966C,[0xB3B6]=0x96C0,[0xB3B7]=0x96EA,[0xB3B8]=0x96E9,[0xB3B9]=0x7AE0,[0xB3BA]=0x7ADF,[0xB3BB]=0x9802,[0xB3BC]=0x9803,[0xB3BD]=0x9B5A,[0xB3BE]=0x9CE5,[0xB3BF]=0x9E75,[0xB3C0]=0x9E7F,[0xB3C1]=0x9EA5,[0xB3C2]=0x9EBB,[0xB3C3]=0x50A2,[0xB3C4]=0x508D,[0xB3C5]=0x5085,[0xB3C6]=0x5099,[0xB3C7]=0x5091,[0xB3C8]=0x5080,[0xB3C9]=0x5096,[0xB3CA]=0x5098,[0xB3CB]=0x509A,[0xB3CC]=0x6700,[0xB3CD]=0x51F1,[0xB3CE]=0x5272,[0xB3CF]=0x5274,[0xB3D0]=0x5275,[0xB3D1]=0x5269,[0xB3D2]=0x52DE,[0xB3D3]=0x52DD,[0xB3D4]=0x52DB,[0xB3D5]=0x535A,[0xB3D6]=0x53A5,[0xB3D7]=0x557B,[0xB3D8]=0x5580,[0xB3D9]=0x55A7,[0xB3DA]=0x557C,[0xB3DB]=0x558A,[0xB3DC]=0x559D,[0xB3DD]=0x5598,[0xB3DE]=0x5582,[0xB3DF]=0x559C,[0xB3E0]=0x55AA,[0xB3E1]=0x5594,[0xB3E2]=0x5587,[0xB3E3]=0x558B,[0xB3E4]=0x5583,[0xB3E5]=0x55B3,[0xB3E6]=0x55AE,[0xB3E7]=0x559F,[0xB3E8]=0x553E,[0xB3E9]=0x55B2,[0xB3EA]=0x559A,[0xB3EB]=0x55BB,[0xB3EC]=0x55AC,[0xB3ED]=0x55B1,[0xB3EE]=0x557E,[0xB3EF]=0x5589,[0xB3F0]=0x55AB,[0xB3F1]=0x5599,[0xB3F2]=0x570D,[0xB3F3]=0x582F,[0xB3F4]=0x582A,[0xB3F5]=0x5834,[0xB3F6]=0x5824,[0xB3F7]=0x5830,[0xB3F8]=0x5831,[0xB3F9]=0x5821,[0xB3FA]=0x581D,[0xB3FB]=0x5820,[0xB3FC]=0x58F9,[0xB3FD]=0x58FA,[0xB3FE]=0x5960,[0xB440]=0x5A77,[0xB441]=0x5A9A,[0xB442]=0x5A7F,[0xB443]=0x5A92,[0xB444]=0x5A9B,[0xB445]=0x5AA7,[0xB446]=0x5B73,[0xB447]=0x5B71,[0xB448]=0x5BD2,[0xB449]=0x5BCC,[0xB44A]=0x5BD3,[0xB44B]=0x5BD0,[0xB44C]=0x5C0A,[0xB44D]=0x5C0B,[0xB44E]=0x5C31,[0xB44F]=0x5D4C,[0xB450]=0x5D50,[0xB451]=0x5D34,[0xB452]=0x5D47,[0xB453]=0x5DFD,[0xB454]=0x5E45,[0xB455]=0x5E3D,[0xB456]=0x5E40,[0xB457]=0x5E43,[0xB458]=0x5E7E,[0xB459]=0x5ECA,[0xB45A]=0x5EC1,[0xB45B]=0x5EC2,[0xB45C]=0x5EC4,[0xB45D]=0x5F3C,[0xB45E]=0x5F6D,[0xB45F]=0x5FA9,[0xB460]=0x5FAA,[0xB461]=0x5FA8,[0xB462]=0x60D1,[0xB463]=0x60E1,[0xB464]=0x60B2,[0xB465]=0x60B6,[0xB466]=0x60E0,[0xB467]=0x611C,[0xB468]=0x6123,[0xB469]=0x60FA,[0xB46A]=0x6115,[0xB46B]=0x60F0,[0xB46C]=0x60FB,[0xB46D]=0x60F4,[0xB46E]=0x6168,[0xB46F]=0x60F1,[0xB470]=0x610E,[0xB471]=0x60F6,[0xB472]=0x6109,[0xB473]=0x6100,[0xB474]=0x6112,[0xB475]=0x621F,[0xB476]=0x6249,[0xB477]=0x63A3,[0xB478]=0x638C,[0xB479]=0x63CF,[0xB47A]=0x63C0,[0xB47B]=0x63E9,[0xB47C]=0x63C9,[0xB47D]=0x63C6,[0xB47E]=0x63CD,[0xB4A1]=0x63D2,[0xB4A2]=0x63E3,[0xB4A3]=0x63D0,[0xB4A4]=0x63E1,[0xB4A5]=0x63D6,[0xB4A6]=0x63ED,[0xB4A7]=0x63EE,[0xB4A8]=0x6376,[0xB4A9]=0x63F4,[0xB4AA]=0x63EA,[0xB4AB]=0x63DB,[0xB4AC]=0x6452,[0xB4AD]=0x63DA,[0xB4AE]=0x63F9,[0xB4AF]=0x655E,[0xB4B0]=0x6566,[0xB4B1]=0x6562,[0xB4B2]=0x6563,[0xB4B3]=0x6591,[0xB4B4]=0x6590,[0xB4B5]=0x65AF,[0xB4B6]=0x666E,[0xB4B7]=0x6670,[0xB4B8]=0x6674,[0xB4B9]=0x6676,[0xB4BA]=0x666F,[0xB4BB]=0x6691,[0xB4BC]=0x667A,[0xB4BD]=0x667E,[0xB4BE]=0x6677,[0xB4BF]=0x66FE,[0xB4C0]=0x66FF,[0xB4C1]=0x671F,[0xB4C2]=0x671D,[0xB4C3]=0x68FA,[0xB4C4]=0x68D5,[0xB4C5]=0x68E0,[0xB4C6]=0x68D8,[0xB4C7]=0x68D7,[0xB4C8]=0x6905,[0xB4C9]=0x68DF,[0xB4CA]=0x68F5,[0xB4CB]=0x68EE,[0xB4CC]=0x68E7,[0xB4CD]=0x68F9,[0xB4CE]=0x68D2,[0xB4CF]=0x68F2,[0xB4D0]=0x68E3,[0xB4D1]=0x68CB,[0xB4D2]=0x68CD,[0xB4D3]=0x690D,[0xB4D4]=0x6912,[0xB4D5]=0x690E,[0xB4D6]=0x68C9,[0xB4D7]=0x68DA,[0xB4D8]=0x696E,[0xB4D9]=0x68FB,[0xB4DA]=0x6B3E,[0xB4DB]=0x6B3A,[0xB4DC]=0x6B3D,[0xB4DD]=0x6B98,[0xB4DE]=0x6B96,[0xB4DF]=0x6BBC,[0xB4E0]=0x6BEF,[0xB4E1]=0x6C2E,[0xB4E2]=0x6C2F,[0xB4E3]=0x6C2C,[0xB4E4]=0x6E2F,[0xB4E5]=0x6E38,[0xB4E6]=0x6E54,[0xB4E7]=0x6E21,[0xB4E8]=0x6E32,[0xB4E9]=0x6E67,[0xB4EA]=0x6E4A,[0xB4EB]=0x6E20,[0xB4EC]=0x6E25,[0xB4ED]=0x6E23,[0xB4EE]=0x6E1B,[0xB4EF]=0x6E5B,[0xB4F0]=0x6E58,[0xB4F1]=0x6E24,[0xB4F2]=0x6E56,[0xB4F3]=0x6E6E,[0xB4F4]=0x6E2D,[0xB4F5]=0x6E26,[0xB4F6]=0x6E6F,[0xB4F7]=0x6E34,[0xB4F8]=0x6E4D,[0xB4F9]=0x6E3A,[0xB4FA]=0x6E2C,[0xB4FB]=0x6E43,[0xB4FC]=0x6E1D,[0xB4FD]=0x6E3E,[0xB4FE]=0x6ECB,[0xB540]=0x6E89,[0xB541]=0x6E19,[0xB542]=0x6E4E,[0xB543]=0x6E63,[0xB544]=0x6E44,[0xB545]=0x6E72,[0xB546]=0x6E69,[0xB547]=0x6E5F,[0xB548]=0x7119,[0xB549]=0x711A,[0xB54A]=0x7126,[0xB54B]=0x7130,[0xB54C]=0x7121,[0xB54D]=0x7136,[0xB54E]=0x716E,[0xB54F]=0x711C,[0xB550]=0x724C,[0xB551]=0x7284,[0xB552]=0x7280,[0xB553]=0x7336,[0xB554]=0x7325,[0xB555]=0x7334,[0xB556]=0x7329,[0xB557]=0x743A,[0xB558]=0x742A,[0xB559]=0x7433,[0xB55A]=0x7422,[0xB55B]=0x7425,[0xB55C]=0x7435,[0xB55D]=0x7436,[0xB55E]=0x7434,[0xB55F]=0x742F,[0xB560]=0x741B,[0xB561]=0x7426,[0xB562]=0x7428,[0xB563]=0x7525,[0xB564]=0x7526,[0xB565]=0x756B,[0xB566]=0x756A,[0xB567]=0x75E2,[0xB568]=0x75DB,[0xB569]=0x75E3,[0xB56A]=0x75D9,[0xB56B]=0x75D8,[0xB56C]=0x75DE,[0xB56D]=0x75E0,[0xB56E]=0x767B,[0xB56F]=0x767C,[0xB570]=0x7696,[0xB571]=0x7693,[0xB572]=0x76B4,[0xB573]=0x76DC,[0xB574]=0x774F,[0xB575]=0x77ED,[0xB576]=0x785D,[0xB577]=0x786C,[0xB578]=0x786F,[0xB579]=0x7A0D,[0xB57A]=0x7A08,[0xB57B]=0x7A0B,[0xB57C]=0x7A05,[0xB57D]=0x7A00,[0xB57E]=0x7A98,[0xB5A1]=0x7A97,[0xB5A2]=0x7A96,[0xB5A3]=0x7AE5,[0xB5A4]=0x7AE3,[0xB5A5]=0x7B49,[0xB5A6]=0x7B56,[0xB5A7]=0x7B46,[0xB5A8]=0x7B50,[0xB5A9]=0x7B52,[0xB5AA]=0x7B54,[0xB5AB]=0x7B4D,[0xB5AC]=0x7B4B,[0xB5AD]=0x7B4F,[0xB5AE]=0x7B51,[0xB5AF]=0x7C9F,[0xB5B0]=0x7CA5,[0xB5B1]=0x7D5E,[0xB5B2]=0x7D50,[0xB5B3]=0x7D68,[0xB5B4]=0x7D55,[0xB5B5]=0x7D2B,[0xB5B6]=0x7D6E,[0xB5B7]=0x7D72,[0xB5B8]=0x7D61,[0xB5B9]=0x7D66,[0xB5BA]=0x7D62,[0xB5BB]=0x7D70,[0xB5BC]=0x7D73,[0xB5BD]=0x5584,[0xB5BE]=0x7FD4,[0xB5BF]=0x7FD5,[0xB5C0]=0x800B,[0xB5C1]=0x8052,[0xB5C2]=0x8085,[0xB5C3]=0x8155,[0xB5C4]=0x8154,[0xB5C5]=0x814B,[0xB5C6]=0x8151,[0xB5C7]=0x814E,[0xB5C8]=0x8139,[0xB5C9]=0x8146,[0xB5CA]=0x813E,[0xB5CB]=0x814C,[0xB5CC]=0x8153,[0xB5CD]=0x8174,[0xB5CE]=0x8212,[0xB5CF]=0x821C,[0xB5D0]=0x83E9,[0xB5D1]=0x8403,[0xB5D2]=0x83F8,[0xB5D3]=0x840D,[0xB5D4]=0x83E0,[0xB5D5]=0x83C5,[0xB5D6]=0x840B,[0xB5D7]=0x83C1,[0xB5D8]=0x83EF,[0xB5D9]=0x83F1,[0xB5DA]=0x83F4,[0xB5DB]=0x8457,[0xB5DC]=0x840A,[0xB5DD]=0x83F0,[0xB5DE]=0x840C,[0xB5DF]=0x83CC,[0xB5E0]=0x83FD,[0xB5E1]=0x83F2,[0xB5E2]=0x83CA,[0xB5E3]=0x8438,[0xB5E4]=0x840E,[0xB5E5]=0x8404,[0xB5E6]=0x83DC,[0xB5E7]=0x8407,[0xB5E8]=0x83D4,[0xB5E9]=0x83DF,[0xB5EA]=0x865B,[0xB5EB]=0x86DF,[0xB5EC]=0x86D9,[0xB5ED]=0x86ED,[0xB5EE]=0x86D4,[0xB5EF]=0x86DB,[0xB5F0]=0x86E4,[0xB5F1]=0x86D0,[0xB5F2]=0x86DE,[0xB5F3]=0x8857,[0xB5F4]=0x88C1,[0xB5F5]=0x88C2,[0xB5F6]=0x88B1,[0xB5F7]=0x8983,[0xB5F8]=0x8996,[0xB5F9]=0x8A3B,[0xB5FA]=0x8A60,[0xB5FB]=0x8A55,[0xB5FC]=0x8A5E,[0xB5FD]=0x8A3C,[0xB5FE]=0x8A41,[0xB640]=0x8A54,[0xB641]=0x8A5B,[0xB642]=0x8A50,[0xB643]=0x8A46,[0xB644]=0x8A34,[0xB645]=0x8A3A,[0xB646]=0x8A36,[0xB647]=0x8A56,[0xB648]=0x8C61,[0xB649]=0x8C82,[0xB64A]=0x8CAF,[0xB64B]=0x8CBC,[0xB64C]=0x8CB3,[0xB64D]=0x8CBD,[0xB64E]=0x8CC1,[0xB64F]=0x8CBB,[0xB650]=0x8CC0,[0xB651]=0x8CB4,[0xB652]=0x8CB7,[0xB653]=0x8CB6,[0xB654]=0x8CBF,[0xB655]=0x8CB8,[0xB656]=0x8D8A,[0xB657]=0x8D85,[0xB658]=0x8D81,[0xB659]=0x8DCE,[0xB65A]=0x8DDD,[0xB65B]=0x8DCB,[0xB65C]=0x8DDA,[0xB65D]=0x8DD1,[0xB65E]=0x8DCC,[0xB65F]=0x8DDB,[0xB660]=0x8DC6,[0xB661]=0x8EFB,[0xB662]=0x8EF8,[0xB663]=0x8EFC,[0xB664]=0x8F9C,[0xB665]=0x902E,[0xB666]=0x9035,[0xB667]=0x9031,[0xB668]=0x9038,[0xB669]=0x9032,[0xB66A]=0x9036,[0xB66B]=0x9102,[0xB66C]=0x90F5,[0xB66D]=0x9109,[0xB66E]=0x90FE,[0xB66F]=0x9163,[0xB670]=0x9165,[0xB671]=0x91CF,[0xB672]=0x9214,[0xB673]=0x9215,[0xB674]=0x9223,[0xB675]=0x9209,[0xB676]=0x921E,[0xB677]=0x920D,[0xB678]=0x9210,[0xB679]=0x9207,[0xB67A]=0x9211,[0xB67B]=0x9594,[0xB67C]=0x958F,[0xB67D]=0x958B,[0xB67E]=0x9591,[0xB6A1]=0x9593,[0xB6A2]=0x9592,[0xB6A3]=0x958E,[0xB6A4]=0x968A,[0xB6A5]=0x968E,[0xB6A6]=0x968B,[0xB6A7]=0x967D,[0xB6A8]=0x9685,[0xB6A9]=0x9686,[0xB6AA]=0x968D,[0xB6AB]=0x9672,[0xB6AC]=0x9684,[0xB6AD]=0x96C1,[0xB6AE]=0x96C5,[0xB6AF]=0x96C4,[0xB6B0]=0x96C6,[0xB6B1]=0x96C7,[0xB6B2]=0x96EF,[0xB6B3]=0x96F2,[0xB6B4]=0x97CC,[0xB6B5]=0x9805,[0xB6B6]=0x9806,[0xB6B7]=0x9808,[0xB6B8]=0x98E7,[0xB6B9]=0x98EA,[0xB6BA]=0x98EF,[0xB6BB]=0x98E9,[0xB6BC]=0x98F2,[0xB6BD]=0x98ED,[0xB6BE]=0x99AE,[0xB6BF]=0x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B746]=0x5E79,[0xB747]=0x5EC9,[0xB748]=0x5EC8,[0xB749]=0x5F12,[0xB74A]=0x5F59,[0xB74B]=0x5FAC,[0xB74C]=0x5FAE,[0xB74D]=0x611A,[0xB74E]=0x610F,[0xB74F]=0x6148,[0xB750]=0x611F,[0xB751]=0x60F3,[0xB752]=0x611B,[0xB753]=0x60F9,[0xB754]=0x6101,[0xB755]=0x6108,[0xB756]=0x614E,[0xB757]=0x614C,[0xB758]=0x6144,[0xB759]=0x614D,[0xB75A]=0x613E,[0xB75B]=0x6134,[0xB75C]=0x6127,[0xB75D]=0x610D,[0xB75E]=0x6106,[0xB75F]=0x6137,[0xB760]=0x6221,[0xB761]=0x6222,[0xB762]=0x6413,[0xB763]=0x643E,[0xB764]=0x641E,[0xB765]=0x642A,[0xB766]=0x642D,[0xB767]=0x643D,[0xB768]=0x642C,[0xB769]=0x640F,[0xB76A]=0x641C,[0xB76B]=0x6414,[0xB76C]=0x640D,[0xB76D]=0x6436,[0xB76E]=0x6416,[0xB76F]=0x6417,[0xB770]=0x6406,[0xB771]=0x656C,[0xB772]=0x659F,[0xB773]=0x65B0,[0xB774]=0x6697,[0xB775]=0x6689,[0xB776]=0x6687,[0xB777]=0x6688,[0xB778]=0x6696,[0xB779]=0x6684,[0xB77A]=0x6698,[0xB77B]=0x668D,[0xB77C]=0x6703,[0xB77D]=0x6994,[0xB77E]=0x696D,[0xB7A1]=0x695A,[0xB7A2]=0x6977,[0xB7A3]=0x6960,[0xB7A4]=0x6954,[0xB7A5]=0x6975,[0xB7A6]=0x6930,[0xB7A7]=0x6982,[0xB7A8]=0x694A,[0xB7A9]=0x6968,[0xB7AA]=0x696B,[0xB7AB]=0x695E,[0xB7AC]=0x6953,[0xB7AD]=0x6979,[0xB7AE]=0x6986,[0xB7AF]=0x695D,[0xB7B0]=0x6963,[0xB7B1]=0x695B,[0xB7B2]=0x6B47,[0xB7B3]=0x6B72,[0xB7B4]=0x6BC0,[0xB7B5]=0x6BBF,[0xB7B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x776B,[0xB7FC]=0x7766,[0xB7FD]=0x775E,[0xB7FE]=0x7763,[0xB840]=0x7779,[0xB841]=0x776A,[0xB842]=0x776C,[0xB843]=0x775C,[0xB844]=0x7765,[0xB845]=0x7768,[0xB846]=0x7762,[0xB847]=0x77EE,[0xB848]=0x788E,[0xB849]=0x78B0,[0xB84A]=0x7897,[0xB84B]=0x7898,[0xB84C]=0x788C,[0xB84D]=0x7889,[0xB84E]=0x787C,[0xB84F]=0x7891,[0xB850]=0x7893,[0xB851]=0x787F,[0xB852]=0x797A,[0xB853]=0x797F,[0xB854]=0x7981,[0xB855]=0x842C,[0xB856]=0x79BD,[0xB857]=0x7A1C,[0xB858]=0x7A1A,[0xB859]=0x7A20,[0xB85A]=0x7A14,[0xB85B]=0x7A1F,[0xB85C]=0x7A1E,[0xB85D]=0x7A9F,[0xB85E]=0x7AA0,[0xB85F]=0x7B77,[0xB860]=0x7BC0,[0xB861]=0x7B60,[0xB862]=0x7B6E,[0xB863]=0x7B67,[0xB864]=0x7CB1,[0xB865]=0x7CB3,[0xB866]=0x7CB5,[0xB867]=0x7D93,[0xB868]=0x7D79,[0xB869]=0x7D91,[0xB86A]=0x7D81,[0xB86B]=0x7D8F,[0xB86C]=0x7D5B,[0xB86D]=0x7F6E,[0xB86E]=0x7F69,[0xB86F]=0x7F6A,[0xB870]=0x7F72,[0xB871]=0x7FA9,[0xB872]=0x7FA8,[0xB873]=0x7FA4,[0xB874]=0x8056,[0xB875]=0x8058,[0xB876]=0x8086,[0xB877]=0x8084,[0xB878]=0x8171,[0xB879]=0x8170,[0xB87A]=0x8178,[0xB87B]=0x8165,[0xB87C]=0x816E,[0xB87D]=0x8173,[0xB87E]=0x816B,[0xB8A1]=0x8179,[0xB8A2]=0x817A,[0xB8A3]=0x8166,[0xB8A4]=0x8205,[0xB8A5]=0x8247,[0xB8A6]=0x8482,[0xB8A7]=0x8477,[0xB8A8]=0x843D,[0xB8A9]=0x8431,[0xB8AA]=0x8475,[0xB8AB]=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]=0x8CC5,[0xB8F1]=0x8DE1,[0xB8F2]=0x8DDF,[0xB8F3]=0x8DE8,[0xB8F4]=0x8DEF,[0xB8F5]=0x8DF3,[0xB8F6]=0x8DFA,[0xB8F7]=0x8DEA,[0xB8F8]=0x8DE4,[0xB8F9]=0x8DE6,[0xB8FA]=0x8EB2,[0xB8FB]=0x8F03,[0xB8FC]=0x8F09,[0xB8FD]=0x8EFE,[0xB8FE]=0x8F0A,[0xB940]=0x8F9F,[0xB941]=0x8FB2,[0xB942]=0x904B,[0xB943]=0x904A,[0xB944]=0x9053,[0xB945]=0x9042,[0xB946]=0x9054,[0xB947]=0x903C,[0xB948]=0x9055,[0xB949]=0x9050,[0xB94A]=0x9047,[0xB94B]=0x904F,[0xB94C]=0x904E,[0xB94D]=0x904D,[0xB94E]=0x9051,[0xB94F]=0x903E,[0xB950]=0x9041,[0xB951]=0x9112,[0xB952]=0x9117,[0xB953]=0x916C,[0xB954]=0x916A,[0xB955]=0x9169,[0xB956]=0x91C9,[0xB957]=0x9237,[0xB958]=0x9257,[0xB959]=0x9238,[0xB95A]=0x923D,[0xB95B]=0x9240,[0xB95C]=0x923E,[0xB95D]=0x925B,[0xB95E]=0x924B,[0xB95F]=0x9264,[0xB960]=0x9251,[0xB961]=0x9234,[0xB962]=0x9249,[0xB963]=0x924D,[0xB964]=0x9245,[0xB965]=0x9239,[0xB966]=0x923F,[0xB967]=0x925A,[0xB968]=0x9598,[0xB969]=0x9698,[0xB96A]=0x9694,[0xB96B]=0x9695,[0xB96C]=0x96CD,[0xB96D]=0x96CB,[0xB96E]=0x96C9,[0xB96F]=0x96CA,[0xB970]=0x96F7,[0xB971]=0x96FB,[0xB972]=0x96F9,[0xB973]=0x96F6,[0xB974]=0x9756,[0xB975]=0x9774,[0xB976]=0x9776,[0xB977]=0x9810,[0xB978]=0x9811,[0xB979]=0x9813,[0xB97A]=0x980A,[0xB97B]=0x9812,[0xB97C]=0x980C,[0xB97D]=0x98FC,[0xB97E]=0x98F4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0x5BDE,[0xB9E7]=0x5BE7,[0xB9E8]=0x5BE1,[0xB9E9]=0x5BE5,[0xB9EA]=0x5BE6,[0xB9EB]=0x5BE8,[0xB9EC]=0x5BE2,[0xB9ED]=0x5BE4,[0xB9EE]=0x5BDF,[0xB9EF]=0x5C0D,[0xB9F0]=0x5C62,[0xB9F1]=0x5D84,[0xB9F2]=0x5D87,[0xB9F3]=0x5E5B,[0xB9F4]=0x5E63,[0xB9F5]=0x5E55,[0xB9F6]=0x5E57,[0xB9F7]=0x5E54,[0xB9F8]=0x5ED3,[0xB9F9]=0x5ED6,[0xB9FA]=0x5F0A,[0xB9FB]=0x5F46,[0xB9FC]=0x5F70,[0xB9FD]=0x5FB9,[0xB9FE]=0x6147,[0xBA40]=0x613F,[0xBA41]=0x614B,[0xBA42]=0x6177,[0xBA43]=0x6162,[0xBA44]=0x6163,[0xBA45]=0x615F,[0xBA46]=0x615A,[0xBA47]=0x6158,[0xBA48]=0x6175,[0xBA49]=0x622A,[0xBA4A]=0x6487,[0xBA4B]=0x6458,[0xBA4C]=0x6454,[0xBA4D]=0x64A4,[0xBA4E]=0x6478,[0xBA4F]=0x645F,[0xBA50]=0x647A,[0xBA51]=0x6451,[0xBA52]=0x6467,[0xBA53]=0x6434,[0xBA54]=0x646D,[0xBA55]=0x647B,[0xBA56]=0x6572,[0xBA57]=0x65A1,[0xBA58]=0x65D7,[0xBA59]=0x65D6,[0xBA5A]=0x66A2,[0xBA5B]=0x66A8,[0xBA5C]=0x669D,[0xBA5D]=0x699C,[0xBA5E]=0x69A8,[0xBA5F]=0x6995,[0xBA60]=0x69C1,[0xBA61]=0x69AE,[0xBA62]=0x69D3,[0xBA63]=0x69CB,[0xBA64]=0x699B,[0xBA65]=0x69B7,[0xBA66]=0x69BB,[0xBA67]=0x69AB,[0xBA68]=0x69B4,[0xBA69]=0x69D0,[0xBA6A]=0x69CD,[0xBA6B]=0x69AD,[0xBA6C]=0x69CC,[0xBA6D]=0x69A6,[0xBA6E]=0x69C3,[0xBA6F]=0x69A3,[0xBA70]=0x6B49,[0xBA71]=0x6B4C,[0xBA72]=0x6C33,[0xBA73]=0x6F33,[0xBA74]=0x6F14,[0xBA75]=0x6EFE,[0xBA76]=0x6F13,[0xBA77]=0x6EF4,[0xBA78]=0x6F29,[0xBA79]=0x6F3E,[0xBA7A]=0x6F20,[0xBA7B]=0x6F2C,[0xBA7C]=0x6F0F,[0xBA7D]=0x6F02,[0xBA7E]=0x6F22,[0xBAA1]=0x6EFF,[0xBAA2]=0x6EEF,[0xBAA3]=0x6F06,[0xBAA4]=0x6F31,[0xBAA5]=0x6F38,[0xBAA6]=0x6F32,[0xBAA7]=0x6F23,[0xBAA8]=0x6F15,[0xBAA9]=0x6F2B,[0xBAAA]=0x6F2F,[0xBAAB]=0x6F88,[0xBAAC]=0x6F2A,[0xBAAD]=0x6EEC,[0xBAAE]=0x6F01,[0xBAAF]=0x6EF2,[0xBAB0]=0x6ECC,[0xBAB1]=0x6EF7,[0xBAB2]=0x7194,[0xBAB3]=0x7199,[0xBAB4]=0x717D,[0xBAB5]=0x718A,[0xBAB6]=0x7184,[0xBAB7]=0x7192,[0xBAB8]=0x723E,[0xBAB9]=0x7292,[0xBABA]=0x7296,[0xBABB]=0x7344,[0xBABC]=0x7350,[0xBABD]=0x7464,[0xBABE]=0x7463,[0xBABF]=0x746A,[0xBAC0]=0x7470,[0xBAC1]=0x746D,[0xBAC2]=0x7504,[0xBAC3]=0x7591,[0xBAC4]=0x7627,[0xBAC5]=0x760D,[0xBAC6]=0x760B,[0xBAC7]=0x7609,[0xBAC8]=0x7613,[0xBAC9]=0x76E1,[0xBACA]=0x76E3,[0xBACB]=0x7784,[0xBACC]=0x777D,[0xBACD]=0x777F,[0xBACE]=0x7761,[0xBACF]=0x78C1,[0xBAD0]=0x789F,[0xBAD1]=0x78A7,[0xBAD2]=0x78B3,[0xBAD3]=0x78A9,[0xBAD4]=0x78A3,[0xBAD5]=0x798E,[0xBAD6]=0x798F,[0xBAD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5]=0x9177,[0xBBC6]=0x9174,[0xBBC7]=0x9278,[0xBBC8]=0x9280,[0xBBC9]=0x9285,[0xBBCA]=0x9298,[0xBBCB]=0x9296,[0xBBCC]=0x927B,[0xBBCD]=0x9293,[0xBBCE]=0x929C,[0xBBCF]=0x92A8,[0xBBD0]=0x927C,[0xBBD1]=0x9291,[0xBBD2]=0x95A1,[0xBBD3]=0x95A8,[0xBBD4]=0x95A9,[0xBBD5]=0x95A3,[0xBBD6]=0x95A5,[0xBBD7]=0x95A4,[0xBBD8]=0x9699,[0xBBD9]=0x969C,[0xBBDA]=0x969B,[0xBBDB]=0x96CC,[0xBBDC]=0x96D2,[0xBBDD]=0x9700,[0xBBDE]=0x977C,[0xBBDF]=0x9785,[0xBBE0]=0x97F6,[0xBBE1]=0x9817,[0xBBE2]=0x9818,[0xBBE3]=0x98AF,[0xBBE4]=0x98B1,[0xBBE5]=0x9903,[0xBBE6]=0x9905,[0xBBE7]=0x990C,[0xBBE8]=0x9909,[0xBBE9]=0x99C1,[0xBBEA]=0x9AAF,[0xBBEB]=0x9AB0,[0xBBEC]=0x9AE6,[0xBBED]=0x9B41,[0xBBEE]=0x9B42,[0xBBEF]=0x9CF4,[0xBBF0]=0x9CF6,[0xBBF1]=0x9CF3,[0xBBF2]=0x9EBC,[0xBBF3]=0x9F3B,[0xBBF4]=0x9F4A,[0xBBF5]=0x5104,[0xBBF6]=0x5100,[0xBBF7]=0x50FB,[0xBBF8]=0x50F5,[0xBBF9]=0x50F9,[0xBBFA]=0x5102,[0xBBFB]=0x5108,[0xBBFC]=0x5109,[0xBBFD]=0x5105,[0xBBFE]=0x51DC,[0xBC40]=0x5287,[0xBC41]=0x5288,[0xBC42]=0x5289,[0xBC43]=0x528D,[0xBC44]=0x528A,[0xBC45]=0x52F0,[0xBC46]=0x53B2,[0xBC47]=0x562E,[0xBC48]=0x563B,[0xBC49]=0x5639,[0xBC4A]=0x5632,[0xBC4B]=0x563F,[0xBC4C]=0x5634,[0xBC4D]=0x5629,[0xBC4E]=0x5653,[0xBC4F]=0x564E,[0xBC50]=0x5657,[0xBC51]=0x5674,[0xBC52]=0x5636,[0xBC53]=0x562F,[0xBC54]=0x5630,[0xBC55]=0x5880,[0xBC56]=0x589F,[0xBC57]=0x589E,[0xBC58]=0x58B3,[0xBC59]=0x589C,[0xBC5A]=0x58AE,[0xBC5B]=0x58A9,[0xBC5C]=0x58A6,[0xBC5D]=0x596D,[0xBC5E]=0x5B09,[0xBC5F]=0x5AFB,[0xBC60]=0x5B0B,[0xBC61]=0x5AF5,[0xBC62]=0x5B0C,[0xBC63]=0x5B08,[0xBC64]=0x5BEE,[0xBC65]=0x5BEC,[0xBC66]=0x5BE9,[0xBC67]=0x5BEB,[0xBC68]=0x5C64,[0xBC69]=0x5C65,[0xBC6A]=0x5D9D,[0xBC6B]=0x5D94,[0xBC6C]=0x5E62,[0xBC6D]=0x5E5F,[0xBC6E]=0x5E61,[0xBC6F]=0x5EE2,[0xBC70]=0x5EDA,[0xBC71]=0x5EDF,[0xBC72]=0x5EDD,[0xBC73]=0x5EE3,[0xBC74]=0x5EE0,[0xBC75]=0x5F48,[0xBC76]=0x5F71,[0xBC77]=0x5FB7,[0xBC78]=0x5FB5,[0xBC79]=0x6176,[0xBC7A]=0x6167,[0xBC7B]=0x616E,[0xBC7C]=0x615D,[0xBC7D]=0x6155,[0xBC7E]=0x6182,[0xBCA1]=0x617C,[0xBCA2]=0x6170,[0xBCA3]=0x616B,[0xBCA4]=0x617E,[0xBCA5]=0x61A7,[0xBCA6]=0x6190,[0xBCA7]=0x61AB,[0xBCA8]=0x618E,[0xBCA9]=0x61AC,[0xBCAA]=0x619A,[0xBCAB]=0x61A4,[0xBCAC]=0x6194,[0xBCAD]=0x61AE,[0xBCAE]=0x622E,[0xBCAF]=0x6469,[0xBCB0]=0x646F,[0xBCB1]=0x6479,[0xBCB2]=0x649E,[0xBCB3]=0x64B2,[0xBCB4]=0x6488,[0xBCB5]=0x6490,[0xBCB6]=0x64B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CEA,[0xBDE9]=0x8CE1,[0xBDEA]=0x8D6D,[0xBDEB]=0x8D9F,[0xBDEC]=0x8DA3,[0xBDED]=0x8E2B,[0xBDEE]=0x8E10,[0xBDEF]=0x8E1D,[0xBDF0]=0x8E22,[0xBDF1]=0x8E0F,[0xBDF2]=0x8E29,[0xBDF3]=0x8E1F,[0xBDF4]=0x8E21,[0xBDF5]=0x8E1E,[0xBDF6]=0x8EBA,[0xBDF7]=0x8F1D,[0xBDF8]=0x8F1B,[0xBDF9]=0x8F1F,[0xBDFA]=0x8F29,[0xBDFB]=0x8F26,[0xBDFC]=0x8F2A,[0xBDFD]=0x8F1C,[0xBDFE]=0x8F1E,[0xBE40]=0x8F25,[0xBE41]=0x9069,[0xBE42]=0x906E,[0xBE43]=0x9068,[0xBE44]=0x906D,[0xBE45]=0x9077,[0xBE46]=0x9130,[0xBE47]=0x912D,[0xBE48]=0x9127,[0xBE49]=0x9131,[0xBE4A]=0x9187,[0xBE4B]=0x9189,[0xBE4C]=0x918B,[0xBE4D]=0x9183,[0xBE4E]=0x92C5,[0xBE4F]=0x92BB,[0xBE50]=0x92B7,[0xBE51]=0x92EA,[0xBE52]=0x92AC,[0xBE53]=0x92E4,[0xBE54]=0x92C1,[0xBE55]=0x92B3,[0xBE56]=0x92BC,[0xBE57]=0x92D2,[0xBE58]=0x92C7,[0xBE59]=0x92F0,[0xBE5A]=0x92B2,[0xBE5B]=0x95AD,[0xBE5C]=0x95B1,[0xBE5D]=0x9704,[0xBE5E]=0x9706,[0xBE5F]=0x9707,[0xBE60]=0x9709,[0xBE61]=0x9760,[0xBE62]=0x978D,[0xBE63]=0x978B,[0xBE64]=0x978F,[0xBE65]=0x9821,[0xBE66]=0x982B,[0xBE67]=0x981C,[0xBE68]=0x98B3,[0xBE69]=0x990A,[0xBE6A]=0x9913,[0xBE6B]=0x9912,[0xBE6C]=0x9918,[0xBE6D]=0x99DD,[0xBE6E]=0x99D0,[0xBE6F]=0x99DF,[0xBE70]=0x99DB,[0xBE71]=0x99D1,[0xBE72]=0x99D5,[0xBE73]=0x99D2,[0xBE74]=0x99D9,[0xBE75]=0x9AB7,[0xBE76]=0x9AEE,[0xBE77]=0x9AEF,[0xBE78]=0x9B27,[0xBE79]=0x9B45,[0xBE7A]=0x9B44,[0xBE7B]=0x9B77,[0xBE7C]=0x9B6F,[0xBE7D]=0x9D06,[0xBE7E]=0x9D09,[0xBEA1]=0x9D03,[0xBEA2]=0x9EA9,[0xBEA3]=0x9EBE,[0xBEA4]=0x9ECE,[0xBEA5]=0x58A8,[0xBEA6]=0x9F52,[0xBEA7]=0x5112,[0xBEA8]=0x5118,[0xBEA9]=0x5114,[0xBEAA]=0x5110,[0xBEAB]=0x5115,[0xBEAC]=0x5180,[0xBEAD]=0x51AA,[0xBEAE]=0x51DD,[0xBEAF]=0x5291,[0xBEB0]=0x5293,[0xBEB1]=0x52F3,[0xBEB2]=0x5659,[0xBEB3]=0x566B,[0xBEB4]=0x5679,[0xBEB5]=0x5669,[0xBEB6]=0x5664,[0xBEB7]=0x5678,[0xBEB8]=0x566A,[0xBEB9]=0x5668,[0xBEBA]=0x5665,[0xBEBB]=0x5671,[0xBEBC]=0x566F,[0xBEBD]=0x566C,[0xBEBE]=0x5662,[0xBEBF]=0x5676,[0xBEC0]=0x58C1,[0xBEC1]=0x58BE,[0xBEC2]=0x58C7,[0xBEC3]=0x58C5,[0xBEC4]=0x596E,[0xBEC5]=0x5B1D,[0xBEC6]=0x5B34,[0xBEC7]=0x5B78,[0xBEC8]=0x5BF0,[0xBEC9]=0x5C0E,[0xBECA]=0x5F4A,[0xBECB]=0x61B2,[0xBECC]=0x6191,[0xBECD]=0x61A9,[0xBECE]=0x618A,[0xBECF]=0x61CD,[0xBED0]=0x61B6,[0xBED1]=0x61BE,[0xBED2]=0x61CA,[0xBED3]=0x61C8,[0xBED4]=0x6230,[0xBED5]=0x64C5,[0xBED6]=0x64C1,[0xBED7]=0x64CB,[0xBED8]=0x64BB,[0xBED9]=0x64B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0x8932,[0xBFC8]=0x8925,[0xBFC9]=0x892B,[0xBFCA]=0x8921,[0xBFCB]=0x89AA,[0xBFCC]=0x89A6,[0xBFCD]=0x8AE6,[0xBFCE]=0x8AFA,[0xBFCF]=0x8AEB,[0xBFD0]=0x8AF1,[0xBFD1]=0x8B00,[0xBFD2]=0x8ADC,[0xBFD3]=0x8AE7,[0xBFD4]=0x8AEE,[0xBFD5]=0x8AFE,[0xBFD6]=0x8B01,[0xBFD7]=0x8B02,[0xBFD8]=0x8AF7,[0xBFD9]=0x8AED,[0xBFDA]=0x8AF3,[0xBFDB]=0x8AF6,[0xBFDC]=0x8AFC,[0xBFDD]=0x8C6B,[0xBFDE]=0x8C6D,[0xBFDF]=0x8C93,[0xBFE0]=0x8CF4,[0xBFE1]=0x8E44,[0xBFE2]=0x8E31,[0xBFE3]=0x8E34,[0xBFE4]=0x8E42,[0xBFE5]=0x8E39,[0xBFE6]=0x8E35,[0xBFE7]=0x8F3B,[0xBFE8]=0x8F2F,[0xBFE9]=0x8F38,[0xBFEA]=0x8F33,[0xBFEB]=0x8FA8,[0xBFEC]=0x8FA6,[0xBFED]=0x9075,[0xBFEE]=0x9074,[0xBFEF]=0x9078,[0xBFF0]=0x9072,[0xBFF1]=0x907C,[0xBFF2]=0x907A,[0xBFF3]=0x9134,[0xBFF4]=0x9192,[0xBFF5]=0x9320,[0xBFF6]=0x9336,[0xBFF7]=0x92F8,[0xBFF8]=0x9333,[0xBFF9]=0x932F,[0xBFFA]=0x9322,[0xBFFB]=0x92FC,[0xBFFC]=0x932B,[0xBFFD]=0x9304,[0xBFFE]=0x931A,[0xC040]=0x9310,[0xC041]=0x9326,[0xC042]=0x9321,[0xC043]=0x9315,[0xC044]=0x932E,[0xC045]=0x9319,[0xC046]=0x95BB,[0xC047]=0x96A7,[0xC048]=0x96A8,[0xC049]=0x96AA,[0xC04A]=0x96D5,[0xC04B]=0x970E,[0xC04C]=0x9711,[0xC04D]=0x9716,[0xC04E]=0x970D,[0xC04F]=0x9713,[0xC050]=0x970F,[0xC051]=0x975B,[0xC052]=0x975C,[0xC053]=0x9766,[0xC054]=0x9798,[0xC055]=0x9830,[0xC056]=0x9838,[0xC057]=0x983B,[0xC058]=0x9837,[0xC059]=0x982D,[0xC05A]=0x9839,[0xC05B]=0x9824,[0xC05C]=0x9910,[0xC05D]=0x9928,[0xC05E]=0x991E,[0xC05F]=0x991B,[0xC060]=0x9921,[0xC061]=0x991A,[0xC062]=0x99ED,[0xC063]=0x99E2,[0xC064]=0x99F1,[0xC065]=0x9AB8,[0xC066]=0x9ABC,[0xC067]=0x9AFB,[0xC068]=0x9AED,[0xC069]=0x9B28,[0xC06A]=0x9B91,[0xC06B]=0x9D15,[0xC06C]=0x9D23,[0xC06D]=0x9D26,[0xC06E]=0x9D28,[0xC06F]=0x9D12,[0xC070]=0x9D1B,[0xC071]=0x9ED8,[0xC072]=0x9ED4,[0xC073]=0x9F8D,[0xC074]=0x9F9C,[0xC075]=0x512A,[0xC076]=0x511F,[0xC077]=0x5121,[0xC078]=0x5132,[0xC079]=0x52F5,[0xC07A]=0x568E,[0xC07B]=0x5680,[0xC07C]=0x5690,[0xC07D]=0x5685,[0xC07E]=0x5687,[0xC0A1]=0x568F,[0xC0A2]=0x58D5,[0xC0A3]=0x58D3,[0xC0A4]=0x58D1,[0xC0A5]=0x58CE,[0xC0A6]=0x5B30,[0xC0A7]=0x5B2A,[0xC0A8]=0x5B24,[0xC0A9]=0x5B7A,[0xC0AA]=0x5C37,[0xC0AB]=0x5C68,[0xC0AC]=0x5DBC,[0xC0AD]=0x5DBA,[0xC0AE]=0x5DBD,[0xC0AF]=0x5DB8,[0xC0B0]=0x5E6B,[0xC0B1]=0x5F4C,[0xC0B2]=0x5FBD,[0xC0B3]=0x61C9,[0xC0B4]=0x61C2,[0xC0B5]=0x61C7,[0xC0B6]=0x61E6,[0xC0B7]=0x61CB,[0xC0B8]=0x6232,[0xC0B9]=0x6234,[0xC0BA]=0x64CE,[0xC0BB]=0x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0xC140]=0x77A7,[0xC141]=0x77AD,[0xC142]=0x77EF,[0xC143]=0x78F7,[0xC144]=0x78FA,[0xC145]=0x78F4,[0xC146]=0x78EF,[0xC147]=0x7901,[0xC148]=0x79A7,[0xC149]=0x79AA,[0xC14A]=0x7A57,[0xC14B]=0x7ABF,[0xC14C]=0x7C07,[0xC14D]=0x7C0D,[0xC14E]=0x7BFE,[0xC14F]=0x7BF7,[0xC150]=0x7C0C,[0xC151]=0x7BE0,[0xC152]=0x7CE0,[0xC153]=0x7CDC,[0xC154]=0x7CDE,[0xC155]=0x7CE2,[0xC156]=0x7CDF,[0xC157]=0x7CD9,[0xC158]=0x7CDD,[0xC159]=0x7E2E,[0xC15A]=0x7E3E,[0xC15B]=0x7E46,[0xC15C]=0x7E37,[0xC15D]=0x7E32,[0xC15E]=0x7E43,[0xC15F]=0x7E2B,[0xC160]=0x7E3D,[0xC161]=0x7E31,[0xC162]=0x7E45,[0xC163]=0x7E41,[0xC164]=0x7E34,[0xC165]=0x7E39,[0xC166]=0x7E48,[0xC167]=0x7E35,[0xC168]=0x7E3F,[0xC169]=0x7E2F,[0xC16A]=0x7F44,[0xC16B]=0x7FF3,[0xC16C]=0x7FFC,[0xC16D]=0x8071,[0xC16E]=0x8072,[0xC16F]=0x8070,[0xC170]=0x806F,[0xC171]=0x8073,[0xC172]=0x81C6,[0xC173]=0x81C3,[0xC174]=0x81BA,[0xC175]=0x81C2,[0xC176]=0x81C0,[0xC177]=0x81BF,[0xC178]=0x81BD,[0xC179]=0x81C9,[0xC17A]=0x81BE,[0xC17B]=0x81E8,[0xC17C]=0x8209,[0xC17D]=0x8271,[0xC17E]=0x85AA,[0xC1A1]=0x8584,[0xC1A2]=0x857E,[0xC1A3]=0x859C,[0xC1A4]=0x8591,[0xC1A5]=0x8594,[0xC1A6]=0x85AF,[0xC1A7]=0x859B,[0xC1A8]=0x8587,[0xC1A9]=0x85A8,[0xC1AA]=0x858A,[0xC1AB]=0x8667,[0xC1AC]=0x87C0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0xC1F2]=0x95C8,[0xC1F3]=0x95C6,[0xC1F4]=0x96B1,[0xC1F5]=0x96B8,[0xC1F6]=0x96D6,[0xC1F7]=0x971C,[0xC1F8]=0x971E,[0xC1F9]=0x97A0,[0xC1FA]=0x97D3,[0xC1FB]=0x9846,[0xC1FC]=0x98B6,[0xC1FD]=0x9935,[0xC1FE]=0x9A01,[0xC240]=0x99FF,[0xC241]=0x9BAE,[0xC242]=0x9BAB,[0xC243]=0x9BAA,[0xC244]=0x9BAD,[0xC245]=0x9D3B,[0xC246]=0x9D3F,[0xC247]=0x9E8B,[0xC248]=0x9ECF,[0xC249]=0x9EDE,[0xC24A]=0x9EDC,[0xC24B]=0x9EDD,[0xC24C]=0x9EDB,[0xC24D]=0x9F3E,[0xC24E]=0x9F4B,[0xC24F]=0x53E2,[0xC250]=0x5695,[0xC251]=0x56AE,[0xC252]=0x58D9,[0xC253]=0x58D8,[0xC254]=0x5B38,[0xC255]=0x5F5D,[0xC256]=0x61E3,[0xC257]=0x6233,[0xC258]=0x64F4,[0xC259]=0x64F2,[0xC25A]=0x64FE,[0xC25B]=0x6506,[0xC25C]=0x64FA,[0xC25D]=0x64FB,[0xC25E]=0x64F7,[0xC25F]=0x65B7,[0xC260]=0x66DC,[0xC261]=0x6726,[0xC262]=0x6AB3,[0xC263]=0x6AAC,[0xC264]=0x6AC3,[0xC265]=0x6ABB,[0xC266]=0x6AB8,[0xC267]=0x6AC2,[0xC268]=0x6AAE,[0xC269]=0x6AAF,[0xC26A]=0x6B5F,[0xC26B]=0x6B78,[0xC26C]=0x6BAF,[0xC26D]=0x7009,[0xC26E]=0x700B,[0xC26F]=0x6FFE,[0xC270]=0x7006,[0xC271]=0x6FFA,[0xC272]=0x7011,[0xC273]=0x700F,[0xC274]=0x71FB,[0xC275]=0x71FC,[0xC276]=0x71FE,[0xC277]=0x71F8,[0xC278]=0x7377,[0xC279]=0x7375,[0xC27A]=0x74A7,[0xC27B]=0x74BF,[0xC27C]=0x7515,[0xC27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E3]=0x9083,[0xC2E4]=0x9088,[0xC2E5]=0x91AB,[0xC2E6]=0x91AC,[0xC2E7]=0x91D0,[0xC2E8]=0x9394,[0xC2E9]=0x938A,[0xC2EA]=0x9396,[0xC2EB]=0x93A2,[0xC2EC]=0x93B3,[0xC2ED]=0x93AE,[0xC2EE]=0x93AC,[0xC2EF]=0x93B0,[0xC2F0]=0x9398,[0xC2F1]=0x939A,[0xC2F2]=0x9397,[0xC2F3]=0x95D4,[0xC2F4]=0x95D6,[0xC2F5]=0x95D0,[0xC2F6]=0x95D5,[0xC2F7]=0x96E2,[0xC2F8]=0x96DC,[0xC2F9]=0x96D9,[0xC2FA]=0x96DB,[0xC2FB]=0x96DE,[0xC2FC]=0x9724,[0xC2FD]=0x97A3,[0xC2FE]=0x97A6,[0xC340]=0x97AD,[0xC341]=0x97F9,[0xC342]=0x984D,[0xC343]=0x984F,[0xC344]=0x984C,[0xC345]=0x984E,[0xC346]=0x9853,[0xC347]=0x98BA,[0xC348]=0x993E,[0xC349]=0x993F,[0xC34A]=0x993D,[0xC34B]=0x992E,[0xC34C]=0x99A5,[0xC34D]=0x9A0E,[0xC34E]=0x9AC1,[0xC34F]=0x9B03,[0xC350]=0x9B06,[0xC351]=0x9B4F,[0xC352]=0x9B4E,[0xC353]=0x9B4D,[0xC354]=0x9BCA,[0xC355]=0x9BC9,[0xC356]=0x9BFD,[0xC357]=0x9BC8,[0xC358]=0x9BC0,[0xC359]=0x9D51,[0xC35A]=0x9D5D,[0xC35B]=0x9D60,[0xC35C]=0x9EE0,[0xC35D]=0x9F15,[0xC35E]=0x9F2C,[0xC35F]=0x5133,[0xC360]=0x56A5,[0xC361]=0x58DE,[0xC362]=0x58DF,[0xC363]=0x58E2,[0xC364]=0x5BF5,[0xC365]=0x9F90,[0xC366]=0x5EEC,[0xC367]=0x61F2,[0xC368]=0x61F7,[0xC369]=0x61F6,[0xC36A]=0x61F5,[0xC36B]=0x6500,[0xC36C]=0x650F,[0xC36D]=0x66E0,[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]=0x8B46,[0xC3D7]=0x8B59,[0xC3D8]=0x8D08,[0xC3D9]=0x8D0A,[0xC3DA]=0x8E7C,[0xC3DB]=0x8E72,[0xC3DC]=0x8E87,[0xC3DD]=0x8E76,[0xC3DE]=0x8E6C,[0xC3DF]=0x8E7A,[0xC3E0]=0x8E74,[0xC3E1]=0x8F54,[0xC3E2]=0x8F4E,[0xC3E3]=0x8FAD,[0xC3E4]=0x908A,[0xC3E5]=0x908B,[0xC3E6]=0x91B1,[0xC3E7]=0x91AE,[0xC3E8]=0x93E1,[0xC3E9]=0x93D1,[0xC3EA]=0x93DF,[0xC3EB]=0x93C3,[0xC3EC]=0x93C8,[0xC3ED]=0x93DC,[0xC3EE]=0x93DD,[0xC3EF]=0x93D6,[0xC3F0]=0x93E2,[0xC3F1]=0x93CD,[0xC3F2]=0x93D8,[0xC3F3]=0x93E4,[0xC3F4]=0x93D7,[0xC3F5]=0x93E8,[0xC3F6]=0x95DC,[0xC3F7]=0x96B4,[0xC3F8]=0x96E3,[0xC3F9]=0x972A,[0xC3FA]=0x9727,[0xC3FB]=0x9761,[0xC3FC]=0x97DC,[0xC3FD]=0x97FB,[0xC3FE]=0x985E,[0xC440]=0x9858,[0xC441]=0x985B,[0xC442]=0x98BC,[0xC443]=0x9945,[0xC444]=0x9949,[0xC445]=0x9A16,[0xC446]=0x9A19,[0xC447]=0x9B0D,[0xC448]=0x9BE8,[0xC449]=0x9BE7,[0xC44A]=0x9BD6,[0xC44B]=0x9BDB,[0xC44C]=0x9D89,[0xC44D]=0x9D61,[0xC44E]=0x9D72,[0xC44F]=0x9D6A,[0xC450]=0x9D6C,[0xC451]=0x9E92,[0xC452]=0x9E97,[0xC453]=0x9E93,[0xC454]=0x9EB4,[0xC455]=0x52F8,[0xC456]=0x56A8,[0xC457]=0x56B7,[0xC458]=0x56B6,[0xC459]=0x56B4,[0xC45A]=0x56BC,[0xC45B]=0x58E4,[0xC45C]=0x5B40,[0xC45D]=0x5B43,[0xC45E]=0x5B7D,[0xC45F]=0x5BF6,[0xC460]=0x5DC9,[0xC461]=0x61F8,[0xC462]=0x61FA,[0xC463]=0x6518,[0xC464]=0x6514,[0xC465]=0x6519,[0xC466]=0x66E6,[0xC467]=0x6727,[0xC468]=0x6AEC,[0xC469]=0x703E,[0xC46A]=0x7030,[0xC46B]=0x7032,[0xC46C]=0x7210,[0xC46D]=0x737B,[0xC46E]=0x74CF,[0xC46F]=0x7662,[0xC470]=0x7665,[0xC471]=0x7926,[0xC472]=0x792A,[0xC473]=0x792C,[0xC474]=0x792B,[0xC475]=0x7AC7,[0xC476]=0x7AF6,[0xC477]=0x7C4C,[0xC478]=0x7C43,[0xC479]=0x7C4D,[0xC47A]=0x7CEF,[0xC47B]=0x7CF0,[0xC47C]=0x8FAE,[0xC47D]=0x7E7D,[0xC47E]=0x7E7C,[0xC4A1]=0x7E82,[0xC4A2]=0x7F4C,[0xC4A3]=0x8000,[0xC4A4]=0x81DA,[0xC4A5]=0x8266,[0xC4A6]=0x85FB,[0xC4A7]=0x85F9,[0xC4A8]=0x8611,[0xC4A9]=0x85FA,[0xC4AA]=0x8606,[0xC4AB]=0x860B,[0xC4AC]=0x8607,[0xC4AD]=0x860A,[0xC4AE]=0x8814,[0xC4AF]=0x8815,[0xC4B0]=0x8964,[0xC4B1]=0x89BA,[0xC4B2]=0x89F8,[0xC4B3]=0x8B70,[0xC4B4]=0x8B6C,[0xC4B5]=0x8B66,[0xC4B6]=0x8B6F,[0xC4B7]=0x8B5F,[0xC4B8]=0x8B6B,[0xC4B9]=0x8D0F,[0xC4BA]=0x8D0D,[0xC4BB]=0x8E89,[0xC4BC]=0x8E81,[0xC4BD]=0x8E85,[0xC4BE]=0x8E82,[0xC4BF]=0x91B4,[0xC4C0]=0x91CB,[0xC4C1]=0x9418,[0xC4C2]=0x9403,[0xC4C3]=0x93FD,[0xC4C4]=0x95E1,[0xC4C5]=0x9730,[0xC4C6]=0x98C4,[0xC4C7]=0x9952,[0xC4C8]=0x9951,[0xC4C9]=0x99A8,[0xC4CA]=0x9A2B,[0xC4CB]=0x9A30,[0xC4CC]=0x9A37,[0xC4CD]=0x9A35,[0xC4CE]=0x9C13,[0xC4CF]=0x9C0D,[0xC4D0]=0x9E79,[0xC4D1]=0x9EB5,[0xC4D2]=0x9EE8,[0xC4D3]=0x9F2F,[0xC4D4]=0x9F5F,[0xC4D5]=0x9F63,[0xC4D6]=0x9F61,[0xC4D7]=0x5137,[0xC4D8]=0x5138,[0xC4D9]=0x56C1,[0xC4DA]=0x56C0,[0xC4DB]=0x56C2,[0xC4DC]=0x5914,[0xC4DD]=0x5C6C,[0xC4DE]=0x5DCD,[0xC4DF]=0x61FC,[0xC4E0]=0x61FE,[0xC4E1]=0x651D,[0xC4E2]=0x651C,[0xC4E3]=0x6595,[0xC4E4]=0x66E9,[0xC4E5]=0x6AFB,[0xC4E6]=0x6B04,[0xC4E7]=0x6AFA,[0xC4E8]=0x6BB2,[0xC4E9]=0x704C,[0xC4EA]=0x721B,[0xC4EB]=0x72A7,[0xC4EC]=0x74D6,[0xC4ED]=0x74D4,[0xC4EE]=0x7669,[0xC4EF]=0x77D3,[0xC4F0]=0x7C50,[0xC4F1]=0x7E8F,[0xC4F2]=0x7E8C,[0xC4F3]=0x7FBC,[0xC4F4]=0x8617,[0xC4F5]=0x862D,[0xC4F6]=0x861A,[0xC4F7]=0x8823,[0xC4F8]=0x8822,[0xC4F9]=0x8821,[0xC4FA]=0x881F,[0xC4FB]=0x896A,[0xC4FC]=0x896C,[0xC4FD]=0x89BD,[0xC4FE]=0x8B74,[0xC540]=0x8B77,[0xC541]=0x8B7D,[0xC542]=0x8D13,[0xC543]=0x8E8A,[0xC544]=0x8E8D,[0xC545]=0x8E8B,[0xC546]=0x8F5F,[0xC547]=0x8FAF,[0xC548]=0x91BA,[0xC549]=0x942E,[0xC54A]=0x9433,[0xC54B]=0x9435,[0xC54C]=0x943A,[0xC54D]=0x9438,[0xC54E]=0x9432,[0xC54F]=0x942B,[0xC550]=0x95E2,[0xC551]=0x9738,[0xC552]=0x9739,[0xC553]=0x9732,[0xC554]=0x97FF,[0xC555]=0x9867,[0xC556]=0x9865,[0xC557]=0x9957,[0xC558]=0x9A45,[0xC559]=0x9A43,[0xC55A]=0x9A40,[0xC55B]=0x9A3E,[0xC55C]=0x9ACF,[0xC55D]=0x9B54,[0xC55E]=0x9B51,[0xC55F]=0x9C2D,[0xC560]=0x9C25,[0xC561]=0x9DAF,[0xC562]=0x9DB4,[0xC563]=0x9DC2,[0xC564]=0x9DB8,[0xC565]=0x9E9D,[0xC566]=0x9EEF,[0xC567]=0x9F19,[0xC568]=0x9F5C,[0xC569]=0x9F66,[0xC56A]=0x9F67,[0xC56B]=0x513C,[0xC56C]=0x513B,[0xC56D]=0x56C8,[0xC56E]=0x56CA,[0xC56F]=0x56C9,[0xC570]=0x5B7F,[0xC571]=0x5DD4,[0xC572]=0x5DD2,[0xC573]=0x5F4E,[0xC574]=0x61FF,[0xC575]=0x6524,[0xC576]=0x6B0A,[0xC577]=0x6B61,[0xC578]=0x7051,[0xC579]=0x7058,[0xC57A]=0x7380,[0xC57B]=0x74E4,[0xC57C]=0x758A,[0xC57D]=0x766E,[0xC57E]=0x766C,[0xC5A1]=0x79B3,[0xC5A2]=0x7C60,[0xC5A3]=0x7C5F,[0xC5A4]=0x807E,[0xC5A5]=0x807D,[0xC5A6]=0x81DF,[0xC5A7]=0x8972,[0xC5A8]=0x896F,[0xC5A9]=0x89FC,[0xC5AA]=0x8B80,[0xC5AB]=0x8D16,[0xC5AC]=0x8D17,[0xC5AD]=0x8E91,[0xC5AE]=0x8E93,[0xC5AF]=0x8F61,[0xC5B0]=0x9148,[0xC5B1]=0x9444,[0xC5B2]=0x9451,[0xC5B3]=0x9452,[0xC5B4]=0x973D,[0xC5B5]=0x973E,[0xC5B6]=0x97C3,[0xC5B7]=0x97C1,[0xC5B8]=0x986B,[0xC5B9]=0x9955,[0xC5BA]=0x9A55,[0xC5BB]=0x9A4D,[0xC5BC]=0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0x8D1B,[0xC643]=0x91C0,[0xC644]=0x946A,[0xC645]=0x9742,[0xC646]=0x9748,[0xC647]=0x9744,[0xC648]=0x97C6,[0xC649]=0x9870,[0xC64A]=0x9A5F,[0xC64B]=0x9B22,[0xC64C]=0x9B58,[0xC64D]=0x9C5F,[0xC64E]=0x9DF9,[0xC64F]=0x9DFA,[0xC650]=0x9E7C,[0xC651]=0x9E7D,[0xC652]=0x9F07,[0xC653]=0x9F77,[0xC654]=0x9F72,[0xC655]=0x5EF3,[0xC656]=0x6B16,[0xC657]=0x7063,[0xC658]=0x7C6C,[0xC659]=0x7C6E,[0xC65A]=0x883B,[0xC65B]=0x89C0,[0xC65C]=0x8EA1,[0xC65D]=0x91C1,[0xC65E]=0x9472,[0xC65F]=0x9470,[0xC660]=0x9871,[0xC661]=0x995E,[0xC662]=0x9AD6,[0xC663]=0x9B23,[0xC664]=0x9ECC,[0xC665]=0x7064,[0xC666]=0x77DA,[0xC667]=0x8B9A,[0xC668]=0x9477,[0xC669]=0x97C9,[0xC66A]=0x9A62,[0xC66B]=0x9A65,[0xC66C]=0x7E9C,[0xC66D]=0x8B9C,[0xC66E]=0x8EAA,[0xC66F]=0x91C5,[0xC670]=0x947D,[0xC671]=0x947E,[0xC672]=0x947C,[0xC673]=0x9C77,[0xC674]=0x9C78,[0xC675]=0x9EF7,[0xC676]=0x8C54,[0xC677]=0x947F,[0xC678]=0x9E1A,[0xC679]=0x7228,[0xC67A]=0x9A6A,[0xC67B]=0x9B31,[0xC67C]=0x9E1B,[0xC67D]=0x9E1E,[0xC67E]=0x7C72,[0xC6A1]=0x30FE,[0xC6A2]=0x309D,[0xC6A3]=0x309E,[0xC6A4]=0x3005,[0xC6A5]=0x3041,[0xC6A6]=0x3042,[0xC6A7]=0x3043,[0xC6A8]=0x3044,[0xC6A9]=0x3045,[0xC6AA]=0x3046,[0xC6AB]=0x3047,[0xC6AC]=0x3048,[0xC6AD]=0x3049,[0xC6AE]=0x304A,[0xC6AF]=0x304B,[0xC6B0]=0x304C,[0xC6B1]=0x304D,[0xC6B2]=0x304E,[0xC6B3]=0x304F,[0xC6B4]=0x3050,[0xC6B5]=0x3051,[0xC6B6]=0x3052,[0xC6B7]=0x3053,[0xC6B8]=0x3054,[0xC6B9]=0x3055,[0xC6BA]=0x3056,[0xC6BB]=0x3057,[0xC6BC]=0x3058,[0xC6BD]=0x3059,[0xC6BE]=0x305A,[0xC6BF]=0x305B,[0xC6C0]=0x305C,[0xC6C1]=0x305D,[0xC6C2]=0x305E,[0xC6C3]=0x305F,[0xC6C4]=0x3060,[0xC6C5]=0x3061,[0xC6C6]=0x3062,[0xC6C7]=0x3063,[0xC6C8]=0x3064,[0xC6C9]=0x3065,[0xC6CA]=0x3066,[0xC6CB]=0x3067,[0xC6CC]=0x3068,[0xC6CD]=0x3069,[0xC6CE]=0x306A,[0xC6CF]=0x306B,[0xC6D0]=0x306C,[0xC6D1]=0x306D,[0xC6D2]=0x306E,[0xC6D3]=0x306F,[0xC6D4]=0x3070,[0xC6D5]=0x3071,[0xC6D6]=0x3072,[0xC6D7]=0x3073,[0xC6D8]=0x3074,[0xC6D9]=0x3075,[0xC6DA]=0x3076,[0xC6DB]=0x3077,[0xC6DC]=0x3078,[0xC6DD]=0x3079,[0xC6DE]=0x307A,[0xC6DF]=0x307B,[0xC6E0]=0x307C,[0xC6E1]=0x307D,[0xC6E2]=0x307E,[0xC6E3]=0x307F,[0xC6E4]=0x3080,[0xC6E5]=0x3081,[0xC6E6]=0x3082,[0xC6E7]=0x3083,[0xC6E8]=0x3084,[0xC6E9]=0x3085,[0xC6EA]=0x3086,[0xC6EB]=0x3087,[0xC6EC]=0x3088,[0xC6ED]=0x3089,[0xC6EE]=0x308A,[0xC6EF]=0x308B,[0xC6F0]=0x308C,[0xC6F1]=0x308D,[0xC6F2]=0x308E,[0xC6F3]=0x308F,[0xC6F4]=0x3090,[0xC6F5]=0x3091,[0xC6F6]=0x3092,[0xC6F7]=0x3093,[0xC6F8]=0x30A1,[0xC6F9]=0x30A2,[0xC6FA]=0x30A3,[0xC6FB]=0x30A4,[0xC6FC]=0x30A5,[0xC6FD]=0x30A6,[0xC6FE]=0x30A7,[0xC740]=0x30A8,[0xC741]=0x30A9,[0xC742]=0x30AA,[0xC743]=0x30AB,[0xC744]=0x30AC,[0xC745]=0x30AD,[0xC746]=0x30AE,[0xC747]=0x30AF,[0xC748]=0x30B0,[0xC749]=0x30B1,[0xC74A]=0x30B2,[0xC74B]=0x30B3,[0xC74C]=0x30B4,[0xC74D]=0x30B5,[0xC74E]=0x30B6,[0xC74F]=0x30B7,[0xC750]=0x30B8,[0xC751]=0x30B9,[0xC752]=0x30BA,[0xC753]=0x30BB,[0xC754]=0x30BC,[0xC755]=0x30BD,[0xC756]=0x30BE,[0xC757]=0x30BF,[0xC758]=0x30C0,[0xC759]=0x30C1,[0xC75A]=0x30C2,[0xC75B]=0x30C3,[0xC75C]=0x30C4,[0xC75D]=0x30C5,[0xC75E]=0x30C6,[0xC75F]=0x30C7,[0xC760]=0x30C8,[0xC761]=0x30C9,[0xC762]=0x30CA,[0xC763]=0x30CB,[0xC764]=0x30CC,[0xC765]=0x30CD,[0xC766]=0x30CE,[0xC767]=0x30CF,[0xC768]=0x30D0,[0xC769]=0x30D1,[0xC76A]=0x30D2,[0xC76B]=0x30D3,[0xC76C]=0x30D4,[0xC76D]=0x30D5,[0xC76E]=0x30D6,[0xC76F]=0x30D7,[0xC770]=0x30D8,[0xC771]=0x30D9,[0xC772]=0x30DA,[0xC773]=0x30DB,[0xC774]=0x30DC,[0xC775]=0x30DD,[0xC776]=0x30DE,[0xC777]=0x30DF,[0xC778]=0x30E0,[0xC779]=0x30E1,[0xC77A]=0x30E2,[0xC77B]=0x30E3,[0xC77C]=0x30E4,[0xC77D]=0x30E5,[0xC77E]=0x30E6,[0xC7A1]=0x30E7,[0xC7A2]=0x30E8,[0xC7A3]=0x30E9,[0xC7A4]=0x30EA,[0xC7A5]=0x30EB,[0xC7A6]=0x30EC,[0xC7A7]=0x30ED,[0xC7A8]=0x30EE,[0xC7A9]=0x30EF,[0xC7AA]=0x30F0,[0xC7AB]=0x30F1,[0xC7AC]=0x30F2,[0xC7AD]=0x30F3,[0xC7AE]=0x30F4,[0xC7AF]=0x30F5,[0xC7B0]=0x30F6,[0xC7B1]=0x414,[0xC7B2]=0x415,[0xC7B3]=0x401,[0xC7B4]=0x416,[0xC7B5]=0x417,[0xC7B6]=0x418,[0xC7B7]=0x419,[0xC7B8]=0x41A,[0xC7B9]=0x41B,[0xC7BA]=0x41C,[0xC7BB]=0x423,[0xC7BC]=0x424,[0xC7BD]=0x425,[0xC7BE]=0x426,[0xC7BF]=0x427,[0xC7C0]=0x428,[0xC7C1]=0x429,[0xC7C2]=0x42A,[0xC7C3]=0x42B,[0xC7C4]=0x42C,[0xC7C5]=0x42D,[0xC7C6]=0x42E,[0xC7C7]=0x42F,[0xC7C8]=0x430,[0xC7C9]=0x431,[0xC7CA]=0x432,[0xC7CB]=0x433,[0xC7CC]=0x434,[0xC7CD]=0x435,[0xC7CE]=0x451,[0xC7CF]=0x436,[0xC7D0]=0x437,[0xC7D1]=0x438,[0xC7D2]=0x439,[0xC7D3]=0x43A,[0xC7D4]=0x43B,[0xC7D5]=0x43C,[0xC7D6]=0x43D,[0xC7D7]=0x43E,[0xC7D8]=0x43F,[0xC7D9]=0x440,[0xC7DA]=0x441,[0xC7DB]=0x442,[0xC7DC]=0x443,[0xC7DD]=0x444,[0xC7DE]=0x445,[0xC7DF]=0x446,[0xC7E0]=0x447,[0xC7E1]=0x448,[0xC7E2]=0x449,[0xC7E3]=0x44A,[0xC7E4]=0x44B,[0xC7E5]=0x44C,[0xC7E6]=0x44D,[0xC7E7]=0x44E,[0xC7E8]=0x44F,[0xC7E9]=0x2460,[0xC7EA]=0x2461,[0xC7EB]=0x2462,[0xC7EC]=0x2463,[0xC7ED]=0x2464,[0xC7EE]=0x2465,[0xC7EF]=0x2466,[0xC7F0]=0x2467,[0xC7F1]=0x2468,[0xC7F2]=0x2469,[0xC7F3]=0x2474,[0xC7F4]=0x2475,[0xC7F5]=0x2476,[0xC7F6]=0x2477,[0xC7F7]=0x2478,[0xC7F8]=0x2479,[0xC7F9]=0x247A,[0xC7FA]=0x247B,[0xC7FB]=0x247C,[0xC7FC]=0x247D,[0xC940]=0x4E42,[0xC941]=0x4E5C,[0xC942]=0x51F5,[0xC943]=0x531A,[0xC944]=0x5382,[0xC945]=0x4E07,[0xC946]=0x4E0C,[0xC947]=0x4E47,[0xC948]=0x4E8D,[0xC949]=0x56D7,[0xC94A]=0xFA0C,[0xC94B]=0x5C6E,[0xC94C]=0x5F73,[0xC94D]=0x4E0F,[0xC94E]=0x5187,[0xC94F]=0x4E0E,[0xC950]=0x4E2E,[0xC951]=0x4E93,[0xC952]=0x4EC2,[0xC953]=0x4EC9,[0xC954]=0x4EC8,[0xC955]=0x5198,[0xC956]=0x52FC,[0xC957]=0x536C,[0xC958]=0x53B9,[0xC959]=0x5720,[0xC95A]=0x5903,[0xC95B]=0x592C,[0xC95C]=0x5C10,[0xC95D]=0x5DFF,[0xC95E]=0x65E1,[0xC95F]=0x6BB3,[0xC960]=0x6BCC,[0xC961]=0x6C14,[0xC962]=0x723F,[0xC963]=0x4E31,[0xC964]=0x4E3C,[0xC965]=0x4EE8,[0xC966]=0x4EDC,[0xC967]=0x4EE9,[0xC968]=0x4EE1,[0xC969]=0x4EDD,[0xC96A]=0x4EDA,[0xC96B]=0x520C,[0xC96C]=0x531C,[0xC96D]=0x534C,[0xC96E]=0x5722,[0xC96F]=0x5723,[0xC970]=0x5917,[0xC971]=0x592F,[0xC972]=0x5B81,[0xC973]=0x5B84,[0xC974]=0x5C12,[0xC975]=0x5C3B,[0xC976]=0x5C74,[0xC977]=0x5C73,[0xC978]=0x5E04,[0xC979]=0x5E80,[0xC97A]=0x5E82,[0xC97B]=0x5FC9,[0xC97C]=0x6209,[0xC97D]=0x6250,[0xC97E]=0x6C15,[0xC9A1]=0x6C36,[0xC9A2]=0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]=0x6266,[0xC9E8]=0x6262,[0xC9E9]=0x6259,[0xC9EA]=0x6260,[0xC9EB]=0x625A,[0xC9EC]=0x6265,[0xC9ED]=0x65EF,[0xC9EE]=0x65EE,[0xC9EF]=0x673E,[0xC9F0]=0x6739,[0xC9F1]=0x6738,[0xC9F2]=0x673B,[0xC9F3]=0x673A,[0xC9F4]=0x673F,[0xC9F5]=0x673C,[0xC9F6]=0x6733,[0xC9F7]=0x6C18,[0xC9F8]=0x6C46,[0xC9F9]=0x6C52,[0xC9FA]=0x6C5C,[0xC9FB]=0x6C4F,[0xC9FC]=0x6C4A,[0xC9FD]=0x6C54,[0xC9FE]=0x6C4B,[0xCA40]=0x6C4C,[0xCA41]=0x7071,[0xCA42]=0x725E,[0xCA43]=0x72B4,[0xCA44]=0x72B5,[0xCA45]=0x738E,[0xCA46]=0x752A,[0xCA47]=0x767F,[0xCA48]=0x7A75,[0xCA49]=0x7F51,[0xCA4A]=0x8278,[0xCA4B]=0x827C,[0xCA4C]=0x8280,[0xCA4D]=0x827D,[0xCA4E]=0x827F,[0xCA4F]=0x864D,[0xCA50]=0x897E,[0xCA51]=0x9099,[0xCA52]=0x9097,[0xCA53]=0x9098,[0xCA54]=0x909B,[0xCA55]=0x9094,[0xCA56]=0x9622,[0xCA57]=0x9624,[0xCA58]=0x9620,[0xCA59]=0x9623,[0xCA5A]=0x4F56,[0xCA5B]=0x4F3B,[0xCA5C]=0x4F62,[0xCA5D]=0x4F49,[0xCA5E]=0x4F53,[0xCA5F]=0x4F64,[0xCA60]=0x4F3E,[0xCA61]=0x4F67,[0xCA62]=0x4F52,[0xCA63]=0x4F5F,[0xCA64]=0x4F41,[0xCA65]=0x4F58,[0xCA66]=0x4F2D,[0xCA67]=0x4F33,[0xCA68]=0x4F3F,[0xCA69]=0x4F61,[0xCA6A]=0x518F,[0xCA6B]=0x51B9,[0xCA6C]=0x521C,[0xCA6D]=0x521E,[0xCA6E]=0x5221,[0xCA6F]=0x52AD,[0xCA70]=0x52AE,[0xCA71]=0x5309,[0xCA72]=0x5363,[0xCA73]=0x5372,[0xCA74]=0x538E,[0xCA75]=0x538F,[0xCA76]=0x5430,[0xCA77]=0x5437,[0xCA78]=0x542A,[0xCA79]=0x5454,[0xCA7A]=0x5445,[0xCA7B]=0x5419,[0xCA7C]=0x541C,[0xCA7D]=0x5425,[0xCA7E]=0x5418,[0xCAA1]=0x543D,[0xCAA2]=0x544F,[0xCAA3]=0x5441,[0xCAA4]=0x5428,[0xCAA5]=0x5424,[0xCAA6]=0x5447,[0xCAA7]=0x56EE,[0xCAA8]=0x56E7,[0xCAA9]=0x56E5,[0xCAAA]=0x5741,[0xCAAB]=0x5745,[0xCAAC]=0x574C,[0xCAAD]=0x5749,[0xCAAE]=0x574B,[0xCAAF]=0x5752,[0xCAB0]=0x5906,[0xCAB1]=0x5940,[0xCAB2]=0x59A6,[0xCAB3]=0x5998,[0xCAB4]=0x59A0,[0xCAB5]=0x5997,[0xCAB6]=0x598E,[0xCAB7]=0x59A2,[0xCAB8]=0x5990,[0xCAB9]=0x598F,[0xCABA]=0x59A7,[0xCABB]=0x59A1,[0xCABC]=0x5B8E,[0xCABD]=0x5B92,[0xCABE]=0x5C28,[0xCABF]=0x5C2A,[0xCAC0]=0x5C8D,[0xCAC1]=0x5C8F,[0xCAC2]=0x5C88,[0xCAC3]=0x5C8B,[0xCAC4]=0x5C89,[0xCAC5]=0x5C92,[0xCAC6]=0x5C8A,[0xCAC7]=0x5C86,[0xCAC8]=0x5C93,[0xCAC9]=0x5C95,[0xCACA]=0x5DE0,[0xCACB]=0x5E0A,[0xCACC]=0x5E0E,[0xCACD]=0x5E8B,[0xCACE]=0x5E89,[0xCACF]=0x5E8C,[0xCAD0]=0x5E88,[0xCAD1]=0x5E8D,[0xCAD2]=0x5F05,[0xCAD3]=0x5F1D,[0xCAD4]=0x5F78,[0xCAD5]=0x5F76,[0xCAD6]=0x5FD2,[0xCAD7]=0x5FD1,[0xCAD8]=0x5FD0,[0xCAD9]=0x5FED,[0xCADA]=0x5FE8,[0xCADB]=0x5FEE,[0xCADC]=0x5FF3,[0xCADD]=0x5FE1,[0xCADE]=0x5FE4,[0xCADF]=0x5FE3,[0xCAE0]=0x5FFA,[0xCAE1]=0x5FEF,[0xCAE2]=0x5FF7,[0xCAE3]=0x5FFB,[0xCAE4]=0x6000,[0xCAE5]=0x5FF4,[0xCAE6]=0x623A,[0xCAE7]=0x6283,[0xCAE8]=0x628C,[0xCAE9]=0x628E,[0xCAEA]=0x628F,[0xCAEB]=0x6294,[0xCAEC]=0x6287,[0xCAED]=0x6271,[0xCAEE]=0x627B,[0xCAEF]=0x627A,[0xCAF0]=0x6270,[0xCAF1]=0x6281,[0xCAF2]=0x6288,[0xCAF3]=0x6277,[0xCAF4]=0x627D,[0xCAF5]=0x6272,[0xCAF6]=0x6274,[0xCAF7]=0x6537,[0xCAF8]=0x65F0,[0xCAF9]=0x65F4,[0xCAFA]=0x65F3,[0xCAFB]=0x65F2,[0xCAFC]=0x65F5,[0xCAFD]=0x6745,[0xCAFE]=0x6747,[0xCB40]=0x6759,[0xCB41]=0x6755,[0xCB42]=0x674C,[0xCB43]=0x6748,[0xCB44]=0x675D,[0xCB45]=0x674D,[0xCB46]=0x675A,[0xCB47]=0x674B,[0xCB48]=0x6BD0,[0xCB49]=0x6C19,[0xCB4A]=0x6C1A,[0xCB4B]=0x6C78,[0xCB4C]=0x6C67,[0xCB4D]=0x6C6B,[0xCB4E]=0x6C84,[0xCB4F]=0x6C8B,[0xCB50]=0x6C8F,[0xCB51]=0x6C71,[0xCB52]=0x6C6F,[0xCB53]=0x6C69,[0xCB54]=0x6C9A,[0xCB55]=0x6C6D,[0xCB56]=0x6C87,[0xCB57]=0x6C95,[0xCB58]=0x6C9C,[0xCB59]=0x6C66,[0xCB5A]=0x6C73,[0xCB5B]=0x6C65,[0xCB5C]=0x6C7B,[0xCB5D]=0x6C8E,[0xCB5E]=0x7074,[0xCB5F]=0x707A,[0xCB60]=0x7263,[0xCB61]=0x72BF,[0xCB62]=0x72BD,[0xCB63]=0x72C3,[0xCB64]=0x72C6,[0xCB65]=0x72C1,[0xCB66]=0x72BA,[0xCB67]=0x72C5,[0xCB68]=0x7395,[0xCB69]=0x7397,[0xCB6A]=0x7393,[0xCB6B]=0x7394,[0xCB6C]=0x7392,[0xCB6D]=0x753A,[0xCB6E]=0x7539,[0xCB6F]=0x7594,[0xCB70]=0x7595,[0xCB71]=0x7681,[0xCB72]=0x793D,[0xCB73]=0x8034,[0xCB74]=0x8095,[0xCB75]=0x8099,[0xCB76]=0x8090,[0xCB77]=0x8092,[0xCB78]=0x809C,[0xCB79]=0x8290,[0xCB7A]=0x828F,[0xCB7B]=0x8285,[0xCB7C]=0x828E,[0xCB7D]=0x8291,[0xCB7E]=0x8293,[0xCBA1]=0x828A,[0xCBA2]=0x8283,[0xCBA3]=0x8284,[0xCBA4]=0x8C78,[0xCBA5]=0x8FC9,[0xCBA6]=0x8FBF,[0xCBA7]=0x909F,[0xCBA8]=0x90A1,[0xCBA9]=0x90A5,[0xCBAA]=0x909E,[0xCBAB]=0x90A7,[0xCBAC]=0x90A0,[0xCBAD]=0x9630,[0xCBAE]=0x9628,[0xCBAF]=0x962F,[0xCBB0]=0x962D,[0xCBB1]=0x4E33,[0xCBB2]=0x4F98,[0xCBB3]=0x4F7C,[0xCBB4]=0x4F85,[0xCBB5]=0x4F7D,[0xCBB6]=0x4F80,[0xCBB7]=0x4F87,[0xCBB8]=0x4F76,[0xCBB9]=0x4F74,[0xCBBA]=0x4F89,[0xCBBB]=0x4F84,[0xCBBC]=0x4F77,[0xCBBD]=0x4F4C,[0xCBBE]=0x4F97,[0xCBBF]=0x4F6A,[0xCBC0]=0x4F9A,[0xCBC1]=0x4F79,[0xCBC2]=0x4F81,[0xCBC3]=0x4F78,[0xCBC4]=0x4F90,[0xCBC5]=0x4F9C,[0xCBC6]=0x4F94,[0xCBC7]=0x4F9E,[0xCBC8]=0x4F92,[0xCBC9]=0x4F82,[0xCBCA]=0x4F95,[0xCBCB]=0x4F6B,[0xCBCC]=0x4F6E,[0xCBCD]=0x519E,[0xCBCE]=0x51BC,[0xCBCF]=0x51BE,[0xCBD0]=0x5235,[0xCBD1]=0x5232,[0xCBD2]=0x5233,[0xCBD3]=0x5246,[0xCBD4]=0x5231,[0xCBD5]=0x52BC,[0xCBD6]=0x530A,[0xCBD7]=0x530B,[0xCBD8]=0x533C,[0xCBD9]=0x5392,[0xCBDA]=0x5394,[0xCBDB]=0x5487,[0xCBDC]=0x547F,[0xCBDD]=0x5481,[0xCBDE]=0x5491,[0xCBDF]=0x5482,[0xCBE0]=0x5488,[0xCBE1]=0x546B,[0xCBE2]=0x547A,[0xCBE3]=0x547E,[0xCBE4]=0x5465,[0xCBE5]=0x546C,[0xCBE6]=0x5474,[0xCBE7]=0x5466,[0xCBE8]=0x548D,[0xCBE9]=0x546F,[0xCBEA]=0x5461,[0xCBEB]=0x5460,[0xCBEC]=0x5498,[0xCBED]=0x5463,[0xCBEE]=0x5467,[0xCBEF]=0x5464,[0xCBF0]=0x56F7,[0xCBF1]=0x56F9,[0xCBF2]=0x576F,[0xCBF3]=0x5772,[0xCBF4]=0x576D,[0xCBF5]=0x576B,[0xCBF6]=0x5771,[0xCBF7]=0x5770,[0xCBF8]=0x5776,[0xCBF9]=0x5780,[0xCBFA]=0x5775,[0xCBFB]=0x577B,[0xCBFC]=0x5773,[0xCBFD]=0x5774,[0xCBFE]=0x5762,[0xCC40]=0x5768,[0xCC41]=0x577D,[0xCC42]=0x590C,[0xCC43]=0x5945,[0xCC44]=0x59B5,[0xCC45]=0x59BA,[0xCC46]=0x59CF,[0xCC47]=0x59CE,[0xCC48]=0x59B2,[0xCC49]=0x59CC,[0xCC4A]=0x59C1,[0xCC4B]=0x59B6,[0xCC4C]=0x59BC,[0xCC4D]=0x59C3,[0xCC4E]=0x59D6,[0xCC4F]=0x59B1,[0xCC50]=0x59BD,[0xCC51]=0x59C0,[0xCC52]=0x59C8,[0xCC53]=0x59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D42]=0x6CB4,[0xCD43]=0x6C8A,[0xCD44]=0x6C9D,[0xCD45]=0x6C80,[0xCD46]=0x6CDE,[0xCD47]=0x6CC0,[0xCD48]=0x6D30,[0xCD49]=0x6CCD,[0xCD4A]=0x6CC7,[0xCD4B]=0x6CB0,[0xCD4C]=0x6CF9,[0xCD4D]=0x6CCF,[0xCD4E]=0x6CE9,[0xCD4F]=0x6CD1,[0xCD50]=0x7094,[0xCD51]=0x7098,[0xCD52]=0x7085,[0xCD53]=0x7093,[0xCD54]=0x7086,[0xCD55]=0x7084,[0xCD56]=0x7091,[0xCD57]=0x7096,[0xCD58]=0x7082,[0xCD59]=0x709A,[0xCD5A]=0x7083,[0xCD5B]=0x726A,[0xCD5C]=0x72D6,[0xCD5D]=0x72CB,[0xCD5E]=0x72D8,[0xCD5F]=0x72C9,[0xCD60]=0x72DC,[0xCD61]=0x72D2,[0xCD62]=0x72D4,[0xCD63]=0x72DA,[0xCD64]=0x72CC,[0xCD65]=0x72D1,[0xCD66]=0x73A4,[0xCD67]=0x73A1,[0xCD68]=0x73AD,[0xCD69]=0x73A6,[0xCD6A]=0x73A2,[0xCD6B]=0x73A0,[0xCD6C]=0x73AC,[0xCD6D]=0x739D,[0xCD6E]=0x74DD,[0xCD6F]=0x74E8,[0xCD70]=0x753F,[0xCD71]=0x7540,[0xCD72]=0x753E,[0xCD73]=0x758C,[0xCD74]=0x7598,[0xCD75]=0x76AF,[0xCD76]=0x76F3,[0xCD77]=0x76F1,[0xCD78]=0x76F0,[0xCD79]=0x76F5,[0xCD7A]=0x77F8,[0xCD7B]=0x77FC,[0xCD7C]=0x77F9,[0xCD7D]=0x77FB,[0xCD7E]=0x77FA,[0xCDA1]=0x77F7,[0xCDA2]=0x7942,[0xCDA3]=0x793F,[0xCDA4]=0x79C5,[0xCDA5]=0x7A78,[0xCDA6]=0x7A7B,[0xCDA7]=0x7AFB,[0xCDA8]=0x7C75,[0xCDA9]=0x7CFD,[0xCDAA]=0x8035,[0xCDAB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xCDEF]=0x4FEC,[0xCDF0]=0x5244,[0xCDF1]=0x5249,[0xCDF2]=0x52C0,[0xCDF3]=0x52C2,[0xCDF4]=0x533D,[0xCDF5]=0x537C,[0xCDF6]=0x5397,[0xCDF7]=0x5396,[0xCDF8]=0x5399,[0xCDF9]=0x5398,[0xCDFA]=0x54BA,[0xCDFB]=0x54A1,[0xCDFC]=0x54AD,[0xCDFD]=0x54A5,[0xCDFE]=0x54CF,[0xCE40]=0x54C3,[0xCE41]=0x830D,[0xCE42]=0x54B7,[0xCE43]=0x54AE,[0xCE44]=0x54D6,[0xCE45]=0x54B6,[0xCE46]=0x54C5,[0xCE47]=0x54C6,[0xCE48]=0x54A0,[0xCE49]=0x5470,[0xCE4A]=0x54BC,[0xCE4B]=0x54A2,[0xCE4C]=0x54BE,[0xCE4D]=0x5472,[0xCE4E]=0x54DE,[0xCE4F]=0x54B0,[0xCE50]=0x57B5,[0xCE51]=0x579E,[0xCE52]=0x579F,[0xCE53]=0x57A4,[0xCE54]=0x578C,[0xCE55]=0x5797,[0xCE56]=0x579D,[0xCE57]=0x579B,[0xCE58]=0x5794,[0xCE59]=0x5798,[0xCE5A]=0x578F,[0xCE5B]=0x5799,[0xCE5C]=0x57A5,[0xCE5D]=0x579A,[0xCE5E]=0x5795,[0xCE5F]=0x58F4,[0xCE60]=0x590D,[0xCE61]=0x5953,[0xCE62]=0x59E1,[0xCE63]=0x59DE,[0xCE64]=0x59EE,[0xCE65]=0x5A00,[0xCE66]=0x59F1,[0xCE67]=0x59DD,[0xCE68]=0x59FA,[0xCE69]=0x59FD,[0xCE6A]=0x59FC,[0xCE6B]=0x59F6,[0xCE6C]=0x59E4,[0xCE6D]=0x59F2,[0xCE6E]=0x59F7,[0xCE6F]=0x59DB,[0xCE70]=0x59E9,[0xCE71]=0x59F3,[0xCE72]=0x59F5,[0xCE73]=0x59E0,[0xCE74]=0x59FE,[0xCE75]=0x59F4,[0xCE76]=0x59ED,[0xCE77]=0x5BA8,[0xCE78]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F6,[0xCEE0]=0x6300,[0xCEE1]=0x6313,[0xCEE2]=0x6314,[0xCEE3]=0x62FA,[0xCEE4]=0x6315,[0xCEE5]=0x62FB,[0xCEE6]=0x62F0,[0xCEE7]=0x6541,[0xCEE8]=0x6543,[0xCEE9]=0x65AA,[0xCEEA]=0x65BF,[0xCEEB]=0x6636,[0xCEEC]=0x6621,[0xCEED]=0x6632,[0xCEEE]=0x6635,[0xCEEF]=0x661C,[0xCEF0]=0x6626,[0xCEF1]=0x6622,[0xCEF2]=0x6633,[0xCEF3]=0x662B,[0xCEF4]=0x663A,[0xCEF5]=0x661D,[0xCEF6]=0x6634,[0xCEF7]=0x6639,[0xCEF8]=0x662E,[0xCEF9]=0x670F,[0xCEFA]=0x6710,[0xCEFB]=0x67C1,[0xCEFC]=0x67F2,[0xCEFD]=0x67C8,[0xCEFE]=0x67BA,[0xCF40]=0x67DC,[0xCF41]=0x67BB,[0xCF42]=0x67F8,[0xCF43]=0x67D8,[0xCF44]=0x67C0,[0xCF45]=0x67B7,[0xCF46]=0x67C5,[0xCF47]=0x67EB,[0xCF48]=0x67E4,[0xCF49]=0x67DF,[0xCF4A]=0x67B5,[0xCF4B]=0x67CD,[0xCF4C]=0x67B3,[0xCF4D]=0x67F7,[0xCF4E]=0x67F6,[0xCF4F]=0x67EE,[0xCF50]=0x67E3,[0xCF51]=0x67C2,[0xCF52]=0x67B9,[0xCF53]=0x67CE,[0xCF54]=0x67E7,[0xCF55]=0x67F0,[0xCF56]=0x67B2,[0xCF57]=0x67FC,[0xCF58]=0x67C6,[0xCF59]=0x67ED,[0xCF5A]=0x67CC,[0xCF5B]=0x67AE,[0xCF5C]=0x67E6,[0xCF5D]=0x67DB,[0xCF5E]=0x67FA,[0xCF5F]=0x67C9,[0xCF60]=0x67CA,[0xCF61]=0x67C3,[0xCF62]=0x67EA,[0xCF63]=0x67CB,[0xCF64]=0x6B28,[0xCF65]=0x6B82,[0xCF66]=0x6B84,[0xCF67]=0x6BB6,[0xCF68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xCFCF]=0x73EB,[0xCFD0]=0x73BF,[0xCFD1]=0x73C7,[0xCFD2]=0x73BE,[0xCFD3]=0x73C3,[0xCFD4]=0x73C6,[0xCFD5]=0x73B8,[0xCFD6]=0x73CB,[0xCFD7]=0x74EC,[0xCFD8]=0x74EE,[0xCFD9]=0x752E,[0xCFDA]=0x7547,[0xCFDB]=0x7548,[0xCFDC]=0x75A7,[0xCFDD]=0x75AA,[0xCFDE]=0x7679,[0xCFDF]=0x76C4,[0xCFE0]=0x7708,[0xCFE1]=0x7703,[0xCFE2]=0x7704,[0xCFE3]=0x7705,[0xCFE4]=0x770A,[0xCFE5]=0x76F7,[0xCFE6]=0x76FB,[0xCFE7]=0x76FA,[0xCFE8]=0x77E7,[0xCFE9]=0x77E8,[0xCFEA]=0x7806,[0xCFEB]=0x7811,[0xCFEC]=0x7812,[0xCFED]=0x7805,[0xCFEE]=0x7810,[0xCFEF]=0x780F,[0xCFF0]=0x780E,[0xCFF1]=0x7809,[0xCFF2]=0x7803,[0xCFF3]=0x7813,[0xCFF4]=0x794A,[0xCFF5]=0x794C,[0xCFF6]=0x794B,[0xCFF7]=0x7945,[0xCFF8]=0x7944,[0xCFF9]=0x79D5,[0xCFFA]=0x79CD,[0xCFFB]=0x79CF,[0xCFFC]=0x79D6,[0xCFFD]=0x79CE,[0xCFFE]=0x7A80,[0xD040]=0x7A7E,[0xD041]=0x7AD1,[0xD042]=0x7B00,[0xD043]=0x7B01,[0xD044]=0x7C7A,[0xD045]=0x7C78,[0xD046]=0x7C79,[0xD047]=0x7C7F,[0xD048]=0x7C80,[0xD049]=0x7C81,[0xD04A]=0x7D03,[0xD04B]=0x7D08,[0xD04C]=0x7D01,[0xD04D]=0x7F58,[0xD04E]=0x7F91,[0xD04F]=0x7F8D,[0xD050]=0x7FBE,[0xD051]=0x8007,[0xD052]=0x800E,[0xD053]=0x800F,[0xD054]=0x8014,[0xD055]=0x8037,[0xD056]=0x80D8,[0xD057]=0x80C7,[0xD058]=0x80E0,[0xD059]=0x80D1,[0xD05A]=0x80C8,[0xD05B]=0x80C2,[0xD05C]=0x80D0,[0xD05D]=0x80C5,[0xD05E]=0x80E3,[0xD05F]=0x80D9,[0xD060]=0x80DC,[0xD061]=0x80CA,[0xD062]=0x80D5,[0xD063]=0x80C9,[0xD064]=0x80CF,[0xD065]=0x80D7,[0xD066]=0x80E6,[0xD067]=0x80CD,[0xD068]=0x81FF,[0xD069]=0x8221,[0xD06A]=0x8294,[0xD06B]=0x82D9,[0xD06C]=0x82FE,[0xD06D]=0x82F9,[0xD06E]=0x8307,[0xD06F]=0x82E8,[0xD070]=0x8300,[0xD071]=0x82D5,[0xD072]=0x833A,[0xD073]=0x82EB,[0xD074]=0x82D6,[0xD075]=0x82F4,[0xD076]=0x82EC,[0xD077]=0x82E1,[0xD078]=0x82F2,[0xD079]=0x82F5,[0xD07A]=0x830C,[0xD07B]=0x82FB,[0xD07C]=0x82F6,[0xD07D]=0x82F0,[0xD07E]=0x82EA,[0xD0A1]=0x82E4,[0xD0A2]=0x82E0,[0xD0A3]=0x82FA,[0xD0A4]=0x82F3,[0xD0A5]=0x82ED,[0xD0A6]=0x8677,[0xD0A7]=0x8674,[0xD0A8]=0x867C,[0xD0A9]=0x8673,[0xD0AA]=0x8841,[0xD0AB]=0x884E,[0xD0AC]=0x8867,[0xD0AD]=0x886A,[0xD0AE]=0x8869,[0xD0AF]=0x89D3,[0xD0B0]=0x8A04,[0xD0B1]=0x8A07,[0xD0B2]=0x8D72,[0xD0B3]=0x8FE3,[0xD0B4]=0x8FE1,[0xD0B5]=0x8FEE,[0xD0B6]=0x8FE0,[0xD0B7]=0x90F1,[0xD0B8]=0x90BD,[0xD0B9]=0x90BF,[0xD0BA]=0x90D5,[0xD0BB]=0x90C5,[0xD0BC]=0x90BE,[0xD0BD]=0x90C7,[0xD0BE]=0x90CB,[0xD0BF]=0x90C8,[0xD0C0]=0x91D4,[0xD0C1]=0x91D3,[0xD0C2]=0x9654,[0xD0C3]=0x964F,[0xD0C4]=0x9651,[0xD0C5]=0x9653,[0xD0C6]=0x964A,[0xD0C7]=0x964E,[0xD0C8]=0x501E,[0xD0C9]=0x5005,[0xD0CA]=0x5007,[0xD0CB]=0x5013,[0xD0CC]=0x5022,[0xD0CD]=0x5030,[0xD0CE]=0x501B,[0xD0CF]=0x4FF5,[0xD0D0]=0x4FF4,[0xD0D1]=0x5033,[0xD0D2]=0x5037,[0xD0D3]=0x502C,[0xD0D4]=0x4FF6,[0xD0D5]=0x4FF7,[0xD0D6]=0x5017,[0xD0D7]=0x501C,[0xD0D8]=0x5020,[0xD0D9]=0x5027,[0xD0DA]=0x5035,[0xD0DB]=0x502F,[0xD0DC]=0x5031,[0xD0DD]=0x500E,[0xD0DE]=0x515A,[0xD0DF]=0x5194,[0xD0E0]=0x5193,[0xD0E1]=0x51CA,[0xD0E2]=0x51C4,[0xD0E3]=0x51C5,[0xD0E4]=0x51C8,[0xD0E5]=0x51CE,[0xD0E6]=0x5261,[0xD0E7]=0x525A,[0xD0E8]=0x5252,[0xD0E9]=0x525E,[0xD0EA]=0x525F,[0xD0EB]=0x5255,[0xD0EC]=0x5262,[0xD0ED]=0x52CD,[0xD0EE]=0x530E,[0xD0EF]=0x539E,[0xD0F0]=0x5526,[0xD0F1]=0x54E2,[0xD0F2]=0x5517,[0xD0F3]=0x5512,[0xD0F4]=0x54E7,[0xD0F5]=0x54F3,[0xD0F6]=0x54E4,[0xD0F7]=0x551A,[0xD0F8]=0x54FF,[0xD0F9]=0x5504,[0xD0FA]=0x5508,[0xD0FB]=0x54EB,[0xD0FC]=0x5511,[0xD0FD]=0x5505,[0xD0FE]=0x54F1,[0xD140]=0x550A,[0xD141]=0x54FB,[0xD142]=0x54F7,[0xD143]=0x54F8,[0xD144]=0x54E0,[0xD145]=0x550E,[0xD146]=0x5503,[0xD147]=0x550B,[0xD148]=0x5701,[0xD149]=0x5702,[0xD14A]=0x57CC,[0xD14B]=0x5832,[0xD14C]=0x57D5,[0xD14D]=0x57D2,[0xD14E]=0x57BA,[0xD14F]=0x57C6,[0xD150]=0x57BD,[0xD151]=0x57BC,[0xD152]=0x57B8,[0xD153]=0x57B6,[0xD154]=0x57BF,[0xD155]=0x57C7,[0xD156]=0x57D0,[0xD157]=0x57B9,[0xD158]=0x57C1,[0xD159]=0x590E,[0xD15A]=0x594A,[0xD15B]=0x5A19,[0xD15C]=0x5A16,[0xD15D]=0x5A2D,[0xD15E]=0x5A2E,[0xD15F]=0x5A15,[0xD160]=0x5A0F,[0xD161]=0x5A17,[0xD162]=0x5A0A,[0xD163]=0x5A1E,[0xD164]=0x5A33,[0xD165]=0x5B6C,[0xD166]=0x5BA7,[0xD167]=0x5BAD,[0xD168]=0x5BAC,[0xD169]=0x5C03,[0xD16A]=0x5C56,[0xD16B]=0x5C54,[0xD16C]=0x5CEC,[0xD16D]=0x5CFF,[0xD16E]=0x5CEE,[0xD16F]=0x5CF1,[0xD170]=0x5CF7,[0xD171]=0x5D00,[0xD172]=0x5CF9,[0xD173]=0x5E29,[0xD174]=0x5E28,[0xD175]=0x5EA8,[0xD176]=0x5EAE,[0xD177]=0x5EAA,[0xD178]=0x5EAC,[0xD179]=0x5F33,[0xD17A]=0x5F30,[0xD17B]=0x5F67,[0xD17C]=0x605D,[0xD17D]=0x605A,[0xD17E]=0x6067,[0xD1A1]=0x6041,[0xD1A2]=0x60A2,[0xD1A3]=0x6088,[0xD1A4]=0x6080,[0xD1A5]=0x6092,[0xD1A6]=0x6081,[0xD1A7]=0x609D,[0xD1A8]=0x6083,[0xD1A9]=0x6095,[0xD1AA]=0x609B,[0xD1AB]=0x6097,[0xD1AC]=0x6087,[0xD1AD]=0x609C,[0xD1AE]=0x608E,[0xD1AF]=0x6219,[0xD1B0]=0x6246,[0xD1B1]=0x62F2,[0xD1B2]=0x6310,[0xD1B3]=0x6356,[0xD1B4]=0x632C,[0xD1B5]=0x6344,[0xD1B6]=0x6345,[0xD1B7]=0x6336,[0xD1B8]=0x6343,[0xD1B9]=0x63E4,[0xD1BA]=0x6339,[0xD1BB]=0x634B,[0xD1BC]=0x634A,[0xD1BD]=0x633C,[0xD1BE]=0x6329,[0xD1BF]=0x6341,[0xD1C0]=0x6334,[0xD1C1]=0x6358,[0xD1C2]=0x6354,[0xD1C3]=0x6359,[0xD1C4]=0x632D,[0xD1C5]=0x6347,[0xD1C6]=0x6333,[0xD1C7]=0x635A,[0xD1C8]=0x6351,[0xD1C9]=0x6338,[0xD1CA]=0x6357,[0xD1CB]=0x6340,[0xD1CC]=0x6348,[0xD1CD]=0x654A,[0xD1CE]=0x6546,[0xD1CF]=0x65C6,[0xD1D0]=0x65C3,[0xD1D1]=0x65C4,[0xD1D2]=0x65C2,[0xD1D3]=0x664A,[0xD1D4]=0x665F,[0xD1D5]=0x6647,[0xD1D6]=0x6651,[0xD1D7]=0x6712,[0xD1D8]=0x6713,[0xD1D9]=0x681F,[0xD1DA]=0x681A,[0xD1DB]=0x6849,[0xD1DC]=0x6832,[0xD1DD]=0x6833,[0xD1DE]=0x683B,[0xD1DF]=0x684B,[0xD1E0]=0x684F,[0xD1E1]=0x6816,[0xD1E2]=0x6831,[0xD1E3]=0x681C,[0xD1E4]=0x6835,[0xD1E5]=0x682B,[0xD1E6]=0x682D,[0xD1E7]=0x682F,[0xD1E8]=0x684E,[0xD1E9]=0x6844,[0xD1EA]=0x6834,[0xD1EB]=0x681D,[0xD1EC]=0x6812,[0xD1ED]=0x6814,[0xD1EE]=0x6826,[0xD1EF]=0x6828,[0xD1F0]=0x682E,[0xD1F1]=0x684D,[0xD1F2]=0x683A,[0xD1F3]=0x6825,[0xD1F4]=0x6820,[0xD1F5]=0x6B2C,[0xD1F6]=0x6B2F,[0xD1F7]=0x6B2D,[0xD1F8]=0x6B31,[0xD1F9]=0x6B34,[0xD1FA]=0x6B6D,[0xD1FB]=0x8082,[0xD1FC]=0x6B88,[0xD1FD]=0x6BE6,[0xD1FE]=0x6BE4,[0xD240]=0x6BE8,[0xD241]=0x6BE3,[0xD242]=0x6BE2,[0xD243]=0x6BE7,[0xD244]=0x6C25,[0xD245]=0x6D7A,[0xD246]=0x6D63,[0xD247]=0x6D64,[0xD248]=0x6D76,[0xD249]=0x6D0D,[0xD24A]=0x6D61,[0xD24B]=0x6D92,[0xD24C]=0x6D58,[0xD24D]=0x6D62,[0xD24E]=0x6D6D,[0xD24F]=0x6D6F,[0xD250]=0x6D91,[0xD251]=0x6D8D,[0xD252]=0x6DEF,[0xD253]=0x6D7F,[0xD254]=0x6D86,[0xD255]=0x6D5E,[0xD256]=0x6D67,[0xD257]=0x6D60,[0xD258]=0x6D97,[0xD259]=0x6D70,[0xD25A]=0x6D7C,[0xD25B]=0x6D5F,[0xD25C]=0x6D82,[0xD25D]=0x6D98,[0xD25E]=0x6D2F,[0xD25F]=0x6D68,[0xD260]=0x6D8B,[0xD261]=0x6D7E,[0xD262]=0x6D80,[0xD263]=0x6D84,[0xD264]=0x6D16,[0xD265]=0x6D83,[0xD266]=0x6D7B,[0xD267]=0x6D7D,[0xD268]=0x6D75,[0xD269]=0x6D90,[0xD26A]=0x70DC,[0xD26B]=0x70D3,[0xD26C]=0x70D1,[0xD26D]=0x70DD,[0xD26E]=0x70CB,[0xD26F]=0x7F39,[0xD270]=0x70E2,[0xD271]=0x70D7,[0xD272]=0x70D2,[0xD273]=0x70DE,[0xD274]=0x70E0,[0xD275]=0x70D4,[0xD276]=0x70CD,[0xD277]=0x70C5,[0xD278]=0x70C6,[0xD279]=0x70C7,[0xD27A]=0x70DA,[0xD27B]=0x70CE,[0xD27C]=0x70E1,[0xD27D]=0x7242,[0xD27E]=0x7278,[0xD2A1]=0x7277,[0xD2A2]=0x7276,[0xD2A3]=0x7300,[0xD2A4]=0x72FA,[0xD2A5]=0x72F4,[0xD2A6]=0x72FE,[0xD2A7]=0x72F6,[0xD2A8]=0x72F3,[0xD2A9]=0x72FB,[0xD2AA]=0x7301,[0xD2AB]=0x73D3,[0xD2AC]=0x73D9,[0xD2AD]=0x73E5,[0xD2AE]=0x73D6,[0xD2AF]=0x73BC,[0xD2B0]=0x73E7,[0xD2B1]=0x73E3,[0xD2B2]=0x73E9,[0xD2B3]=0x73DC,[0xD2B4]=0x73D2,[0xD2B5]=0x73DB,[0xD2B6]=0x73D4,[0xD2B7]=0x73DD,[0xD2B8]=0x73DA,[0xD2B9]=0x73D7,[0xD2BA]=0x73D8,[0xD2BB]=0x73E8,[0xD2BC]=0x74DE,[0xD2BD]=0x74DF,[0xD2BE]=0x74F4,[0xD2BF]=0x74F5,[0xD2C0]=0x7521,[0xD2C1]=0x755B,[0xD2C2]=0x755F,[0xD2C3]=0x75B0,[0xD2C4]=0x75C1,[0xD2C5]=0x75BB,[0xD2C6]=0x75C4,[0xD2C7]=0x75C0,[0xD2C8]=0x75BF,[0xD2C9]=0x75B6,[0xD2CA]=0x75BA,[0xD2CB]=0x768A,[0xD2CC]=0x76C9,[0xD2CD]=0x771D,[0xD2CE]=0x771B,[0xD2CF]=0x7710,[0xD2D0]=0x7713,[0xD2D1]=0x7712,[0xD2D2]=0x7723,[0xD2D3]=0x7711,[0xD2D4]=0x7715,[0xD2D5]=0x7719,[0xD2D6]=0x771A,[0xD2D7]=0x7722,[0xD2D8]=0x7727,[0xD2D9]=0x7823,[0xD2DA]=0x782C,[0xD2DB]=0x7822,[0xD2DC]=0x7835,[0xD2DD]=0x782F,[0xD2DE]=0x7828,[0xD2DF]=0x782E,[0xD2E0]=0x782B,[0xD2E1]=0x7821,[0xD2E2]=0x7829,[0xD2E3]=0x7833,[0xD2E4]=0x782A,[0xD2E5]=0x7831,[0xD2E6]=0x7954,[0xD2E7]=0x795B,[0xD2E8]=0x794F,[0xD2E9]=0x795C,[0xD2EA]=0x7953,[0xD2EB]=0x7952,[0xD2EC]=0x7951,[0xD2ED]=0x79EB,[0xD2EE]=0x79EC,[0xD2EF]=0x79E0,[0xD2F0]=0x79EE,[0xD2F1]=0x79ED,[0xD2F2]=0x79EA,[0xD2F3]=0x79DC,[0xD2F4]=0x79DE,[0xD2F5]=0x79DD,[0xD2F6]=0x7A86,[0xD2F7]=0x7A89,[0xD2F8]=0x7A85,[0xD2F9]=0x7A8B,[0xD2FA]=0x7A8C,[0xD2FB]=0x7A8A,[0xD2FC]=0x7A87,[0xD2FD]=0x7AD8,[0xD2FE]=0x7B10,[0xD340]=0x7B04,[0xD341]=0x7B13,[0xD342]=0x7B05,[0xD343]=0x7B0F,[0xD344]=0x7B08,[0xD345]=0x7B0A,[0xD346]=0x7B0E,[0xD347]=0x7B09,[0xD348]=0x7B12,[0xD349]=0x7C84,[0xD34A]=0x7C91,[0xD34B]=0x7C8A,[0xD34C]=0x7C8C,[0xD34D]=0x7C88,[0xD34E]=0x7C8D,[0xD34F]=0x7C85,[0xD350]=0x7D1E,[0xD351]=0x7D1D,[0xD352]=0x7D11,[0xD353]=0x7D0E,[0xD354]=0x7D18,[0xD355]=0x7D16,[0xD356]=0x7D13,[0xD357]=0x7D1F,[0xD358]=0x7D12,[0xD359]=0x7D0F,[0xD35A]=0x7D0C,[0xD35B]=0x7F5C,[0xD35C]=0x7F61,[0xD35D]=0x7F5E,[0xD35E]=0x7F60,[0xD35F]=0x7F5D,[0xD360]=0x7F5B,[0xD361]=0x7F96,[0xD362]=0x7F92,[0xD363]=0x7FC3,[0xD364]=0x7FC2,[0xD365]=0x7FC0,[0xD366]=0x8016,[0xD367]=0x803E,[0xD368]=0x8039,[0xD369]=0x80FA,[0xD36A]=0x80F2,[0xD36B]=0x80F9,[0xD36C]=0x80F5,[0xD36D]=0x8101,[0xD36E]=0x80FB,[0xD36F]=0x8100,[0xD370]=0x8201,[0xD371]=0x822F,[0xD372]=0x8225,[0xD373]=0x8333,[0xD374]=0x832D,[0xD375]=0x8344,[0xD376]=0x8319,[0xD377]=0x8351,[0xD378]=0x8325,[0xD379]=0x8356,[0xD37A]=0x833F,[0xD37B]=0x8341,[0xD37C]=0x8326,[0xD37D]=0x831C,[0xD37E]=0x8322,[0xD3A1]=0x8342,[0xD3A2]=0x834E,[0xD3A3]=0x831B,[0xD3A4]=0x832A,[0xD3A5]=0x8308,[0xD3A6]=0x833C,[0xD3A7]=0x834D,[0xD3A8]=0x8316,[0xD3A9]=0x8324,[0xD3AA]=0x8320,[0xD3AB]=0x8337,[0xD3AC]=0x832F,[0xD3AD]=0x8329,[0xD3AE]=0x8347,[0xD3AF]=0x8345,[0xD3B0]=0x834C,[0xD3B1]=0x8353,[0xD3B2]=0x831E,[0xD3B3]=0x832C,[0xD3B4]=0x834B,[0xD3B5]=0x8327,[0xD3B6]=0x8348,[0xD3B7]=0x8653,[0xD3B8]=0x8652,[0xD3B9]=0x86A2,[0xD3BA]=0x86A8,[0xD3BB]=0x8696,[0xD3BC]=0x868D,[0xD3BD]=0x8691,[0xD3BE]=0x869E,[0xD3BF]=0x8687,[0xD3C0]=0x8697,[0xD3C1]=0x8686,[0xD3C2]=0x868B,[0xD3C3]=0x869A,[0xD3C4]=0x8685,[0xD3C5]=0x86A5,[0xD3C6]=0x8699,[0xD3C7]=0x86A1,[0xD3C8]=0x86A7,[0xD3C9]=0x8695,[0xD3CA]=0x8698,[0xD3CB]=0x868E,[0xD3CC]=0x869D,[0xD3CD]=0x8690,[0xD3CE]=0x8694,[0xD3CF]=0x8843,[0xD3D0]=0x8844,[0xD3D1]=0x886D,[0xD3D2]=0x8875,[0xD3D3]=0x8876,[0xD3D4]=0x8872,[0xD3D5]=0x8880,[0xD3D6]=0x8871,[0xD3D7]=0x887F,[0xD3D8]=0x886F,[0xD3D9]=0x8883,[0xD3DA]=0x887E,[0xD3DB]=0x8874,[0xD3DC]=0x887C,[0xD3DD]=0x8A12,[0xD3DE]=0x8C47,[0xD3DF]=0x8C57,[0xD3E0]=0x8C7B,[0xD3E1]=0x8CA4,[0xD3E2]=0x8CA3,[0xD3E3]=0x8D76,[0xD3E4]=0x8D78,[0xD3E5]=0x8DB5,[0xD3E6]=0x8DB7,[0xD3E7]=0x8DB6,[0xD3E8]=0x8ED1,[0xD3E9]=0x8ED3,[0xD3EA]=0x8FFE,[0xD3EB]=0x8FF5,[0xD3EC]=0x9002,[0xD3ED]=0x8FFF,[0xD3EE]=0x8FFB,[0xD3EF]=0x9004,[0xD3F0]=0x8FFC,[0xD3F1]=0x8FF6,[0xD3F2]=0x90D6,[0xD3F3]=0x90E0,[0xD3F4]=0x90D9,[0xD3F5]=0x90DA,[0xD3F6]=0x90E3,[0xD3F7]=0x90DF,[0xD3F8]=0x90E5,[0xD3F9]=0x90D8,[0xD3FA]=0x90DB,[0xD3FB]=0x90D7,[0xD3FC]=0x90DC,[0xD3FD]=0x90E4,[0xD3FE]=0x9150,[0xD440]=0x914E,[0xD441]=0x914F,[0xD442]=0x91D5,[0xD443]=0x91E2,[0xD444]=0x91DA,[0xD445]=0x965C,[0xD446]=0x965F,[0xD447]=0x96BC,[0xD448]=0x98E3,[0xD449]=0x9ADF,[0xD44A]=0x9B2F,[0xD44B]=0x4E7F,[0xD44C]=0x5070,[0xD44D]=0x506A,[0xD44E]=0x5061,[0xD44F]=0x505E,[0xD450]=0x5060,[0xD451]=0x5053,[0xD452]=0x504B,[0xD453]=0x505D,[0xD454]=0x5072,[0xD455]=0x5048,[0xD456]=0x504D,[0xD457]=0x5041,[0xD458]=0x505B,[0xD459]=0x504A,[0xD45A]=0x5062,[0xD45B]=0x5015,[0xD45C]=0x5045,[0xD45D]=0x505F,[0xD45E]=0x5069,[0xD45F]=0x506B,[0xD460]=0x5063,[0xD461]=0x5064,[0xD462]=0x5046,[0xD463]=0x5040,[0xD464]=0x506E,[0xD465]=0x5073,[0xD466]=0x5057,[0xD467]=0x5051,[0xD468]=0x51D0,[0xD469]=0x526B,[0xD46A]=0x526D,[0xD46B]=0x526C,[0xD46C]=0x526E,[0xD46D]=0x52D6,[0xD46E]=0x52D3,[0xD46F]=0x532D,[0xD470]=0x539C,[0xD471]=0x5575,[0xD472]=0x5576,[0xD473]=0x553C,[0xD474]=0x554D,[0xD475]=0x5550,[0xD476]=0x5534,[0xD477]=0x552A,[0xD478]=0x5551,[0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=0x5A5B,[0xD4E2]=0x5A48,[0xD4E3]=0x5A8E,[0xD4E4]=0x5A3E,[0xD4E5]=0x5A4D,[0xD4E6]=0x5A39,[0xD4E7]=0x5A4C,[0xD4E8]=0x5A70,[0xD4E9]=0x5A69,[0xD4EA]=0x5A47,[0xD4EB]=0x5A51,[0xD4EC]=0x5A56,[0xD4ED]=0x5A42,[0xD4EE]=0x5A5C,[0xD4EF]=0x5B72,[0xD4F0]=0x5B6E,[0xD4F1]=0x5BC1,[0xD4F2]=0x5BC0,[0xD4F3]=0x5C59,[0xD4F4]=0x5D1E,[0xD4F5]=0x5D0B,[0xD4F6]=0x5D1D,[0xD4F7]=0x5D1A,[0xD4F8]=0x5D20,[0xD4F9]=0x5D0C,[0xD4FA]=0x5D28,[0xD4FB]=0x5D0D,[0xD4FC]=0x5D26,[0xD4FD]=0x5D25,[0xD4FE]=0x5D0F,[0xD540]=0x5D30,[0xD541]=0x5D12,[0xD542]=0x5D23,[0xD543]=0x5D1F,[0xD544]=0x5D2E,[0xD545]=0x5E3E,[0xD546]=0x5E34,[0xD547]=0x5EB1,[0xD548]=0x5EB4,[0xD549]=0x5EB9,[0xD54A]=0x5EB2,[0xD54B]=0x5EB3,[0xD54C]=0x5F36,[0xD54D]=0x5F38,[0xD54E]=0x5F9B,[0xD54F]=0x5F96,[0xD550]=0x5F9F,[0xD551]=0x608A,[0xD552]=0x6090,[0xD553]=0x6086,[0xD554]=0x60BE,[0xD555]=0x60B0,[0xD556]=0x60BA,[0xD557]=0x60D3,[0xD558]=0x60D4,[0xD559]=0x60CF,[0xD55A]=0x60E4,[0xD55B]=0x60D9,[0xD55C]=0x60DD,[0xD55D]=0x60C8,[0xD55E]=0x60B1,[0xD55F]=0x60DB,[0xD560]=0x60B7,[0xD561]=0x60CA,[0xD562]=0x60BF,[0xD563]=0x60C3,[0xD564]=0x60CD,[0xD565]=0x60C0,[0xD566]=0x6332,[0xD567]=0x6365,[0xD568]=0x638A,[0xD569]=0x6382,[0xD56A]=0x637D,[0xD56B]=0x63BD,[0xD56C]=0x639E,[0xD56D]=0x63AD,[0xD56E]=0x639D,[0xD56F]=0x6397,[0xD570]=0x63AB,[0xD571]=0x638E,[0xD572]=0x636F,[0xD573]=0x6387,[0xD574]=0x6390,[0xD575]=0x636E,[0xD576]=0x63AF,[0xD577]=0x6375,[0xD578]=0x639C,[0xD579]=0x636D,[0xD57A]=0x63AE,[0xD57B]=0x637C,[0xD57C]=0x63A4,[0xD57D]=0x633B,[0xD57E]=0x639F,[0xD5A1]=0x6378,[0xD5A2]=0x6385,[0xD5A3]=0x6381,[0xD5A4]=0x6391,[0xD5A5]=0x638D,[0xD5A6]=0x6370,[0xD5A7]=0x6553,[0xD5A8]=0x65CD,[0xD5A9]=0x6665,[0xD5AA]=0x6661,[0xD5AB]=0x665B,[0xD5AC]=0x6659,[0xD5AD]=0x665C,[0xD5AE]=0x6662,[0xD5AF]=0x6718,[0xD5B0]=0x6879,[0xD5B1]=0x6887,[0xD5B2]=0x6890,[0xD5B3]=0x689C,[0xD5B4]=0x686D,[0xD5B5]=0x686E,[0xD5B6]=0x68AE,[0xD5B7]=0x68AB,[0xD5B8]=0x6956,[0xD5B9]=0x686F,[0xD5BA]=0x68A3,[0xD5BB]=0x68AC,[0xD5BC]=0x68A9,[0xD5BD]=0x6875,[0xD5BE]=0x6874,[0xD5BF]=0x68B2,[0xD5C0]=0x688F,[0xD5C1]=0x6877,[0xD5C2]=0x6892,[0xD5C3]=0x687C,[0xD5C4]=0x686B,[0xD5C5]=0x6872,[0xD5C6]=0x68AA,[0xD5C7]=0x6880,[0xD5C8]=0x6871,[0xD5C9]=0x687E,[0xD5CA]=0x689B,[0xD5CB]=0x6896,[0xD5CC]=0x688B,[0xD5CD]=0x68A0,[0xD5CE]=0x6889,[0xD5CF]=0x68A4,[0xD5D0]=0x6878,[0xD5D1]=0x687B,[0xD5D2]=0x6891,[0xD5D3]=0x688C,[0xD5D4]=0x688A,[0xD5D5]=0x687D,[0xD5D6]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xD65D]=0x727B,[0xD65E]=0x727C,[0xD65F]=0x727F,[0xD660]=0x731D,[0xD661]=0x7317,[0xD662]=0x7307,[0xD663]=0x7311,[0xD664]=0x7318,[0xD665]=0x730A,[0xD666]=0x7308,[0xD667]=0x72FF,[0xD668]=0x730F,[0xD669]=0x731E,[0xD66A]=0x7388,[0xD66B]=0x73F6,[0xD66C]=0x73F8,[0xD66D]=0x73F5,[0xD66E]=0x7404,[0xD66F]=0x7401,[0xD670]=0x73FD,[0xD671]=0x7407,[0xD672]=0x7400,[0xD673]=0x73FA,[0xD674]=0x73FC,[0xD675]=0x73FF,[0xD676]=0x740C,[0xD677]=0x740B,[0xD678]=0x73F4,[0xD679]=0x7408,[0xD67A]=0x7564,[0xD67B]=0x7563,[0xD67C]=0x75CE,[0xD67D]=0x75D2,[0xD67E]=0x75CF,[0xD6A1]=0x75CB,[0xD6A2]=0x75CC,[0xD6A3]=0x75D1,[0xD6A4]=0x75D0,[0xD6A5]=0x768F,[0xD6A6]=0x7689,[0xD6A7]=0x76D3,[0xD6A8]=0x7739,[0xD6A9]=0x772F,[0xD6AA]=0x772D,[0xD6AB]=0x7731,[0xD6AC]=0x7732,[0xD6AD]=0x7734,[0xD6AE]=0x7733,[0xD6AF]=0x773D,[0xD6B0]=0x7725,[0xD6B1]=0x773B,[0xD6B2]=0x7735,[0xD6B3]=0x7848,[0xD6B4]=0x7852,[0xD6B5]=0x7849,[0xD6B6]=0x784D,[0xD6B7]=0x784A,[0xD6B8]=0x784C,[0xD6B9]=0x7826,[0xD6BA]=0x7845,[0xD6BB]=0x7850,[0xD6BC]=0x7964,[0xD6BD]=0x7967,[0xD6BE]=0x7969,[0xD6BF]=0x796A,[0xD6C0]=0x7963,[0xD6C1]=0x796B,[0xD6C2]=0x7961,[0xD6C3]=0x79BB,[0xD6C4]=0x79FA,[0xD6C5]=0x79F8,[0xD6C6]=0x79F6,[0xD6C7]=0x79F7,[0xD6C8]=0x7A8F,[0xD6C9]=0x7A94,[0xD6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[0xD751]=0x8122,[0xD752]=0x8211,[0xD753]=0x8238,[0xD754]=0x8233,[0xD755]=0x823A,[0xD756]=0x8234,[0xD757]=0x8232,[0xD758]=0x8274,[0xD759]=0x8390,[0xD75A]=0x83A3,[0xD75B]=0x83A8,[0xD75C]=0x838D,[0xD75D]=0x837A,[0xD75E]=0x8373,[0xD75F]=0x83A4,[0xD760]=0x8374,[0xD761]=0x838F,[0xD762]=0x8381,[0xD763]=0x8395,[0xD764]=0x8399,[0xD765]=0x8375,[0xD766]=0x8394,[0xD767]=0x83A9,[0xD768]=0x837D,[0xD769]=0x8383,[0xD76A]=0x838C,[0xD76B]=0x839D,[0xD76C]=0x839B,[0xD76D]=0x83AA,[0xD76E]=0x838B,[0xD76F]=0x837E,[0xD770]=0x83A5,[0xD771]=0x83AF,[0xD772]=0x8388,[0xD773]=0x8397,[0xD774]=0x83B0,[0xD775]=0x837F,[0xD776]=0x83A6,[0xD777]=0x8387,[0xD778]=0x83AE,[0xD779]=0x8376,[0xD77A]=0x839A,[0xD77B]=0x8659,[0xD77C]=0x8656,[0xD77D]=0x86BF,[0xD77E]=0x86B7,[0xD7A1]=0x86C2,[0xD7A2]=0x86C1,[0xD7A3]=0x86C5,[0xD7A4]=0x86BA,[0xD7A5]=0x86B0,[0xD7A6]=0x86C8,[0xD7A7]=0x86B9,[0xD7A8]=0x86B3,[0xD7A9]=0x86B8,[0xD7AA]=0x86CC,[0xD7AB]=0x86B4,[0xD7AC]=0x86BB,[0xD7AD]=0x86BC,[0xD7AE]=0x86C3,[0xD7AF]=0x86BD,[0xD7B0]=0x86BE,[0xD7B1]=0x8852,[0xD7B2]=0x8889,[0xD7B3]=0x8895,[0xD7B4]=0x88A8,[0xD7B5]=0x88A2,[0xD7B6]=0x88AA,[0xD7B7]=0x889A,[0xD7B8]=0x8891,[0xD7B9]=0x88A1,[0xD7BA]=0x889F,[0xD7BB]=0x8898,[0xD7BC]=0x88A7,[0xD7BD]=0x8899,[0xD7BE]=0x889B,[0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957A,[0xD845]=0x9586,[0xD846]=0x9588,[0xD847]=0x967C,[0xD848]=0x966D,[0xD849]=0x966B,[0xD84A]=0x9671,[0xD84B]=0x966F,[0xD84C]=0x96BF,[0xD84D]=0x976A,[0xD84E]=0x9804,[0xD84F]=0x98E5,[0xD850]=0x9997,[0xD851]=0x509B,[0xD852]=0x5095,[0xD853]=0x5094,[0xD854]=0x509E,[0xD855]=0x508B,[0xD856]=0x50A3,[0xD857]=0x5083,[0xD858]=0x508C,[0xD859]=0x508E,[0xD85A]=0x509D,[0xD85B]=0x5068,[0xD85C]=0x509C,[0xD85D]=0x5092,[0xD85E]=0x5082,[0xD85F]=0x5087,[0xD860]=0x515F,[0xD861]=0x51D4,[0xD862]=0x5312,[0xD863]=0x5311,[0xD864]=0x53A4,[0xD865]=0x53A7,[0xD866]=0x5591,[0xD867]=0x55A8,[0xD868]=0x55A5,[0xD869]=0x55AD,[0xD86A]=0x5577,[0xD86B]=0x5645,[0xD86C]=0x55A2,[0xD86D]=0x5593,[0xD86E]=0x5588,[0xD86F]=0x558F,[0xD870]=0x55B5,[0xD871]=0x5581,[0xD872]=0x55A3,[0xD873]=0x5592,[0xD874]=0x55A4,[0xD875]=0x557D,[0xD876]=0x558C,[0xD877]=0x55A6,[0xD878]=0x557F,[0xD879]=0x5595,[0xD87A]=0x55A1,[0xD87B]=0x558E,[0xD87C]=0x570C,[0xD87D]=0x5829,[0xD87E]=0x5837,[0xD8A1]=0x5819,[0xD8A2]=0x581E,[0xD8A3]=0x5827,[0xD8A4]=0x5823,[0xD8A5]=0x5828,[0xD8A6]=0x57F5,[0xD8A7]=0x5848,[0xD8A8]=0x5825,[0xD8A9]=0x581C,[0xD8AA]=0x581B,[0xD8AB]=0x5833,[0xD8AC]=0x583F,[0xD8AD]=0x5836,[0xD8AE]=0x582E,[0xD8AF]=0x5839,[0xD8B0]=0x5838,[0xD8B1]=0x582D,[0xD8B2]=0x582C,[0xD8B3]=0x583B,[0xD8B4]=0x5961,[0xD8B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8F7]=0x5FAB,[0xD8F8]=0x60C9,[0xD8F9]=0x60B9,[0xD8FA]=0x60CC,[0xD8FB]=0x60E2,[0xD8FC]=0x60CE,[0xD8FD]=0x60C4,[0xD8FE]=0x6114,[0xD940]=0x60F2,[0xD941]=0x610A,[0xD942]=0x6116,[0xD943]=0x6105,[0xD944]=0x60F5,[0xD945]=0x6113,[0xD946]=0x60F8,[0xD947]=0x60FC,[0xD948]=0x60FE,[0xD949]=0x60C1,[0xD94A]=0x6103,[0xD94B]=0x6118,[0xD94C]=0x611D,[0xD94D]=0x6110,[0xD94E]=0x60FF,[0xD94F]=0x6104,[0xD950]=0x610B,[0xD951]=0x624A,[0xD952]=0x6394,[0xD953]=0x63B1,[0xD954]=0x63B0,[0xD955]=0x63CE,[0xD956]=0x63E5,[0xD957]=0x63E8,[0xD958]=0x63EF,[0xD959]=0x63C3,[0xD95A]=0x649D,[0xD95B]=0x63F3,[0xD95C]=0x63CA,[0xD95D]=0x63E0,[0xD95E]=0x63F6,[0xD95F]=0x63D5,[0xD960]=0x63F2,[0xD961]=0x63F5,[0xD962]=0x6461,[0xD963]=0x63DF,[0xD964]=0x63BE,[0xD965]=0x63DD,[0xD966]=0x63DC,[0xD967]=0x63C4,[0xD968]=0x63D8,[0xD969]=0x63D3,[0xD96A]=0x63C2,[0xD96B]=0x63C7,[0xD96C]=0x63CC,[0xD96D]=0x63CB,[0xD96E]=0x63C8,[0xD96F]=0x63F0,[0xD970]=0x63D7,[0xD971]=0x63D9,[0xD972]=0x6532,[0xD973]=0x6567,[0xD974]=0x656A,[0xD975]=0x6564,[0xD976]=0x655C,[0xD977]=0x6568,[0xD978]=0x6565,[0xD979]=0x658C,[0xD97A]=0x659D,[0xD97B]=0x659E,[0xD97C]=0x65AE,[0xD97D]=0x65D0,[0xD97E]=0x65D2,[0xD9A1]=0x667C,[0xD9A2]=0x666C,[0xD9A3]=0x667B,[0xD9A4]=0x6680,[0xD9A5]=0x6671,[0xD9A6]=0x6679,[0xD9A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C]=0x6E88,[0xD9ED]=0x6E3C,[0xD9EE]=0x6E3D,[0xD9EF]=0x6E45,[0xD9F0]=0x6E62,[0xD9F1]=0x6E2B,[0xD9F2]=0x6E3F,[0xD9F3]=0x6E41,[0xD9F4]=0x6E5D,[0xD9F5]=0x6E73,[0xD9F6]=0x6E1C,[0xD9F7]=0x6E33,[0xD9F8]=0x6E4B,[0xD9F9]=0x6E40,[0xD9FA]=0x6E51,[0xD9FB]=0x6E3B,[0xD9FC]=0x6E03,[0xD9FD]=0x6E2E,[0xD9FE]=0x6E5E,[0xDA40]=0x6E68,[0xDA41]=0x6E5C,[0xDA42]=0x6E61,[0xDA43]=0x6E31,[0xDA44]=0x6E28,[0xDA45]=0x6E60,[0xDA46]=0x6E71,[0xDA47]=0x6E6B,[0xDA48]=0x6E39,[0xDA49]=0x6E22,[0xDA4A]=0x6E30,[0xDA4B]=0x6E53,[0xDA4C]=0x6E65,[0xDA4D]=0x6E27,[0xDA4E]=0x6E78,[0xDA4F]=0x6E64,[0xDA50]=0x6E77,[0xDA51]=0x6E55,[0xDA52]=0x6E79,[0xDA53]=0x6E52,[0xDA54]=0x6E66,[0xDA55]=0x6E35,[0xDA56]=0x6E36,[0xDA57]=0x6E5A,[0xDA58]=0x7120,[0xDA59]=0x711E,[0xDA5A]=0x712F,[0xDA5B]=0x70FB,[0xDA5C]=0x712E,[0xDA5D]=0x7131,[0xDA5E]=0x7123,[0xDA5F]=0x7125,[0xDA60]=0x7122,[0xDA61]=0x7132,[0xDA62]=0x711F,[0xDA63]=0x7128,[0xDA64]=0x713A,[0xDA65]=0x711B,[0xDA66]=0x724B,[0xDA67]=0x725A,[0xDA68]=0x7288,[0xDA69]=0x7289,[0xDA6A]=0x7286,[0xDA6B]=0x7285,[0xDA6C]=0x728B,[0xDA6D]=0x7312,[0xDA6E]=0x730B,[0xDA6F]=0x7330,[0xDA70]=0x7322,[0xDA71]=0x7331,[0xDA72]=0x7333,[0xDA73]=0x7327,[0xDA74]=0x7332,[0xDA75]=0x732D,[0xDA76]=0x7326,[0xDA77]=0x7323,[0xDA78]=0x7335,[0xDA79]=0x730C,[0xDA7A]=0x742E,[0xDA7B]=0x742C,[0xDA7C]=0x7430,[0xDA7D]=0x742B,[0xDA7E]=0x7416,[0xDAA1]=0x741A,[0xDAA2]=0x7421,[0xDAA3]=0x742D,[0xDAA4]=0x7431,[0xDAA5]=0x7424,[0xDAA6]=0x7423,[0xDAA7]=0x741D,[0xDAA8]=0x7429,[0xDAA9]=0x7420,[0xDAAA]=0x7432,[0xDAAB]=0x74FB,[0xDAAC]=0x752F,[0xDAAD]=0x756F,[0xDAAE]=0x756C,[0xDAAF]=0x75E7,[0xDAB0]=0x75DA,[0xDAB1]=0x75E1,[0xDAB2]=0x75E6,[0xDAB3]=0x75DD,[0xDAB4]=0x75DF,[0xDAB5]=0x75E4,[0xDAB6]=0x75D7,[0xDAB7]=0x7695,[0xDAB8]=0x7692,[0xDAB9]=0x76DA,[0xDABA]=0x7746,[0xDABB]=0x7747,[0xDABC]=0x7744,[0xDABD]=0x774D,[0xDABE]=0x7745,[0xDABF]=0x774A,[0xDAC0]=0x774E,[0xDAC1]=0x774B,[0xDAC2]=0x774C,[0xDAC3]=0x77DE,[0xDAC4]=0x77EC,[0xDAC5]=0x7860,[0xDAC6]=0x7864,[0xDAC7]=0x7865,[0xDAC8]=0x785C,[0xDAC9]=0x786D,[0xDACA]=0x7871,[0xDACB]=0x786A,[0xDACC]=0x786E,[0xDACD]=0x7870,[0xDACE]=0x7869,[0xDACF]=0x7868,[0xDAD0]=0x785E,[0xDAD1]=0x7862,[0xDAD2]=0x7974,[0xDAD3]=0x7973,[0xDAD4]=0x7972,[0xDAD5]=0x7970,[0xDAD6]=0x7A02,[0xDAD7]=0x7A0A,[0xDAD8]=0x7A03,[0xDAD9]=0x7A0C,[0xDADA]=0x7A04,[0xDADB]=0x7A99,[0xDADC]=0x7AE6,[0xDADD]=0x7AE4,[0xDADE]=0x7B4A,[0xDADF]=0x7B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[0xDC53]=0x90FF,[0xDC54]=0x90FC,[0xDC55]=0x9108,[0xDC56]=0x90F9,[0xDC57]=0x90FB,[0xDC58]=0x9101,[0xDC59]=0x9100,[0xDC5A]=0x9107,[0xDC5B]=0x9105,[0xDC5C]=0x9103,[0xDC5D]=0x9161,[0xDC5E]=0x9164,[0xDC5F]=0x915F,[0xDC60]=0x9162,[0xDC61]=0x9160,[0xDC62]=0x9201,[0xDC63]=0x920A,[0xDC64]=0x9225,[0xDC65]=0x9203,[0xDC66]=0x921A,[0xDC67]=0x9226,[0xDC68]=0x920F,[0xDC69]=0x920C,[0xDC6A]=0x9200,[0xDC6B]=0x9212,[0xDC6C]=0x91FF,[0xDC6D]=0x91FD,[0xDC6E]=0x9206,[0xDC6F]=0x9204,[0xDC70]=0x9227,[0xDC71]=0x9202,[0xDC72]=0x921C,[0xDC73]=0x9224,[0xDC74]=0x9219,[0xDC75]=0x9217,[0xDC76]=0x9205,[0xDC77]=0x9216,[0xDC78]=0x957B,[0xDC79]=0x958D,[0xDC7A]=0x958C,[0xDC7B]=0x9590,[0xDC7C]=0x9687,[0xDC7D]=0x967E,[0xDC7E]=0x9688,[0xDCA1]=0x9689,[0xDCA2]=0x9683,[0xDCA3]=0x9680,[0xDCA4]=0x96C2,[0xDCA5]=0x96C8,[0xDCA6]=0x96C3,[0xDCA7]=0x96F1,[0xDCA8]=0x96F0,[0xDCA9]=0x976C,[0xDCAA]=0x9770,[0xDCAB]=0x976E,[0xDCAC]=0x9807,[0xDCAD]=0x98A9,[0xDCAE]=0x98EB,[0xDCAF]=0x9CE6,[0xDCB0]=0x9EF9,[0xDCB1]=0x4E83,[0xDCB2]=0x4E84,[0xDCB3]=0x4EB6,[0xDCB4]=0x50BD,[0xDCB5]=0x50BF,[0xDCB6]=0x50C6,[0xDCB7]=0x50AE,[0xDCB8]=0x50C4,[0xDCB9]=0x50CA,[0xDCBA]=0x50B4,[0xDCBB]=0x50C8,[0xDCBC]=0x50C2,[0xDCBD]=0x50B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4,[0xDD44]=0x5AB6,[0xDD45]=0x5ACD,[0xDD46]=0x5AB9,[0xDD47]=0x5A90,[0xDD48]=0x5BD6,[0xDD49]=0x5BD8,[0xDD4A]=0x5BD9,[0xDD4B]=0x5C1F,[0xDD4C]=0x5C33,[0xDD4D]=0x5D71,[0xDD4E]=0x5D63,[0xDD4F]=0x5D4A,[0xDD50]=0x5D65,[0xDD51]=0x5D72,[0xDD52]=0x5D6C,[0xDD53]=0x5D5E,[0xDD54]=0x5D68,[0xDD55]=0x5D67,[0xDD56]=0x5D62,[0xDD57]=0x5DF0,[0xDD58]=0x5E4F,[0xDD59]=0x5E4E,[0xDD5A]=0x5E4A,[0xDD5B]=0x5E4D,[0xDD5C]=0x5E4B,[0xDD5D]=0x5EC5,[0xDD5E]=0x5ECC,[0xDD5F]=0x5EC6,[0xDD60]=0x5ECB,[0xDD61]=0x5EC7,[0xDD62]=0x5F40,[0xDD63]=0x5FAF,[0xDD64]=0x5FAD,[0xDD65]=0x60F7,[0xDD66]=0x6149,[0xDD67]=0x614A,[0xDD68]=0x612B,[0xDD69]=0x6145,[0xDD6A]=0x6136,[0xDD6B]=0x6132,[0xDD6C]=0x612E,[0xDD6D]=0x6146,[0xDD6E]=0x612F,[0xDD6F]=0x614F,[0xDD70]=0x6129,[0xDD71]=0x6140,[0xDD72]=0x6220,[0xDD73]=0x9168,[0xDD74]=0x6223,[0xDD75]=0x6225,[0xDD76]=0x6224,[0xDD77]=0x63C5,[0xDD78]=0x63F1,[0xDD79]=0x63EB,[0xDD7A]=0x6410,[0xDD7B]=0x6412,[0xDD7C]=0x6409,[0xDD7D]=0x6420,[0xDD7E]=0x6424,[0xDDA1]=0x6433,[0xDDA2]=0x6443,[0xDDA3]=0x641F,[0xDDA4]=0x6415,[0xDDA5]=0x6418,[0xDDA6]=0x6439,[0xDDA7]=0x6437,[0xDDA8]=0x6422,[0xDDA9]=0x6423,[0xDDAA]=0x640C,[0xDDAB]=0x6426,[0xDDAC]=0x6430,[0xDDAD]=0x6428,[0xDDAE]=0x6441,[0xDDAF]=0x6435,[0xDDB0]=0x642F,[0xDDB1]=0x640A,[0xDDB2]=0x641A,[0xDDB3]=0x6440,[0xDDB4]=0x6425,[0xDDB5]=0x6427,[0xDDB6]=0x640B,[0xDDB7]=0x63E7,[0xDDB8]=0x641B,[0xDDB9]=0x642E,[0xDDBA]=0x6421,[0xDDBB]=0x640E,[0xDDBC]=0x656F,[0xDDBD]=0x6592,[0xDDBE]=0x65D3,[0xDDBF]=0x6686,[0xDDC0]=0x668C,[0xDDC1]=0x6695,[0xDDC2]=0x6690,[0xDDC3]=0x668B,[0xDDC4]=0x668A,[0xDDC5]=0x6699,[0xDDC6]=0x6694,[0xDDC7]=0x6678,[0xDDC8]=0x6720,[0xDDC9]=0x6966,[0xDDCA]=0x695F,[0xDDCB]=0x6938,[0xDDCC]=0x694E,[0xDDCD]=0x6962,[0xDDCE]=0x6971,[0xDDCF]=0x693F,[0xDDD0]=0x6945,[0xDDD1]=0x696A,[0xDDD2]=0x6939,[0xDDD3]=0x6942,[0xDDD4]=0x6957,[0xDDD5]=0x6959,[0xDDD6]=0x697A,[0xDDD7]=0x6948,[0xDDD8]=0x6949,[0xDDD9]=0x6935,[0xDDDA]=0x696C,[0xDDDB]=0x6933,[0xDDDC]=0x693D,[0xDDDD]=0x6965,[0xDDDE]=0x68F0,[0xDDDF]=0x6978,[0xDDE0]=0x6934,[0xDDE1]=0x6969,[0xDDE2]=0x6940,[0xDDE3]=0x696F,[0xDDE4]=0x6944,[0xDDE5]=0x6976,[0xDDE6]=0x6958,[0xDDE7]=0x6941,[0xDDE8]=0x6974,[0xDDE9]=0x694C,[0xDDEA]=0x693B,[0xDDEB]=0x694B,[0xDDEC]=0x6937,[0xDDED]=0x695C,[0xDDEE]=0x694F,[0xDDEF]=0x6951,[0xDDF0]=0x6932,[0xDDF1]=0x6952,[0xDDF2]=0x692F,[0xDDF3]=0x697B,[0xDDF4]=0x693C,[0xDDF5]=0x6B46,[0x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]=0x715F,[0xDE7D]=0x7150,[0xDE7E]=0x7153,[0xDEA1]=0x7144,[0xDEA2]=0x714D,[0xDEA3]=0x715A,[0xDEA4]=0x724F,[0xDEA5]=0x728D,[0xDEA6]=0x728C,[0xDEA7]=0x7291,[0xDEA8]=0x7290,[0xDEA9]=0x728E,[0xDEAA]=0x733C,[0xDEAB]=0x7342,[0xDEAC]=0x733B,[0xDEAD]=0x733A,[0xDEAE]=0x7340,[0xDEAF]=0x734A,[0xDEB0]=0x7349,[0xDEB1]=0x7444,[0xDEB2]=0x744A,[0xDEB3]=0x744B,[0xDEB4]=0x7452,[0xDEB5]=0x7451,[0xDEB6]=0x7457,[0xDEB7]=0x7440,[0xDEB8]=0x744F,[0xDEB9]=0x7450,[0xDEBA]=0x744E,[0xDEBB]=0x7442,[0xDEBC]=0x7446,[0xDEBD]=0x744D,[0xDEBE]=0x7454,[0xDEBF]=0x74E1,[0xDEC0]=0x74FF,[0xDEC1]=0x74FE,[0xDEC2]=0x74FD,[0xDEC3]=0x751D,[0xDEC4]=0x7579,[0xDEC5]=0x7577,[0xDEC6]=0x6983,[0xDEC7]=0x75EF,[0xDEC8]=0x760F,[0xDEC9]=0x7603,[0xDECA]=0x75F7,[0xDECB]=0x75FE,[0xDECC]=0x75FC,[0xDECD]=0x75F9,[0xDECE]=0x75F8,[0xDECF]=0x7610,[0xDED0]=0x75FB,[0xDED1]=0x75F6,[0xDED2]=0x75ED,[0xDED3]=0x75F5,[0xDED4]=0x75FD,[0xDED5]=0x7699,[0xDED6]=0x76B5,[0xDED7]=0x76DD,[0xDED8]=0x7755,[0xDED9]=0x775F,[0xDEDA]=0x7760,[0xDEDB]=0x7752,[0xDEDC]=0x7756,[0xDEDD]=0x775A,[0xDEDE]=0x7769,[0xDEDF]=0x7767,[0xDEE0]=0x7754,[0xDEE1]=0x7759,[0xDEE2]=0x776D,[0xDEE3]=0x77E0,[0xDEE4]=0x7887,[0xDEE5]=0x789A,[0xDEE6]=0x7894,[0xDEE7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6E]=0x7FA7,[0xDF6F]=0x7FDB,[0xDF70]=0x7FDC,[0xDF71]=0x8021,[0xDF72]=0x8164,[0xDF73]=0x8160,[0xDF74]=0x8177,[0xDF75]=0x815C,[0xDF76]=0x8169,[0xDF77]=0x815B,[0xDF78]=0x8162,[0xDF79]=0x8172,[0xDF7A]=0x6721,[0xDF7B]=0x815E,[0xDF7C]=0x8176,[0xDF7D]=0x8167,[0xDF7E]=0x816F,[0xDFA1]=0x8144,[0xDFA2]=0x8161,[0xDFA3]=0x821D,[0xDFA4]=0x8249,[0xDFA5]=0x8244,[0xDFA6]=0x8240,[0xDFA7]=0x8242,[0xDFA8]=0x8245,[0xDFA9]=0x84F1,[0xDFAA]=0x843F,[0xDFAB]=0x8456,[0xDFAC]=0x8476,[0xDFAD]=0x8479,[0xDFAE]=0x848F,[0xDFAF]=0x848D,[0xDFB0]=0x8465,[0xDFB1]=0x8451,[0xDFB2]=0x8440,[0xDFB3]=0x8486,[0xDFB4]=0x8467,[0xDFB5]=0x8430,[0xDFB6]=0x844D,[0xDFB7]=0x847D,[0xDFB8]=0x845A,[0xDFB9]=0x8459,[0xDFBA]=0x8474,[0xDFBB]=0x8473,[0xDFBC]=0x845D,[0xDFBD]=0x8507,[0xDFBE]=0x845E,[0xDFBF]=0x8437,[0xDFC0]=0x843A,[0xDFC1]=0x8434,[0xDFC2]=0x847A,[0xDFC3]=0x8443,[0xDFC4]=0x8478,[0xDFC5]=0x8432,[0xDFC6]=0x8445,[0xDFC7]=0x8429,[0xDFC8]=0x83D9,[0xDFC9]=0x844B,[0xDFCA]=0x842F,[0xDFCB]=0x8442,[0xDFCC]=0x842D,[0xDFCD]=0x845F,[0xDFCE]=0x8470,[0xDFCF]=0x8439,[0xDFD0]=0x844E,[0xDFD1]=0x844C,[0xDFD2]=0x8452,[0xDFD3]=0x846F,[0xDFD4]=0x84C5,[0xDFD5]=0x848E,[0xDFD6]=0x843B,[0xDFD7]=0x8447,[0xDFD8]=0x8436,[0xDFD9]=0x8433,[0xDFDA]=0x8468,[0xDFDB]=0x847E,[0xDFDC]=0x8444,[0xDFDD]=0x842B,[0xDFDE]=0x8460,[0xDFDF]=0x8454,[0xDFE0]=0x846E,[0xDFE1]=0x8450,[0xDFE2]=0x870B,[0xDFE3]=0x8704,[0xDFE4]=0x86F7,[0xDFE5]=0x870C,[0xDFE6]=0x86FA,[0xDFE7]=0x86D6,[0xDFE8]=0x86F5,[0xDFE9]=0x874D,[0xDFEA]=0x86F8,[0xDFEB]=0x870E,[0xDFEC]=0x8709,[0xDFED]=0x8701,[0xDFEE]=0x86F6,[0xDFEF]=0x870D,[0xDFF0]=0x8705,[0xDFF1]=0x88D6,[0xDFF2]=0x88CB,[0xDFF3]=0x88CD,[0xDFF4]=0x88CE,[0xDFF5]=0x88DE,[0xDFF6]=0x88DB,[0xDFF7]=0x88DA,[0xDFF8]=0x88CC,[0xDFF9]=0x88D0,[0xDFFA]=0x8985,[0xDFFB]=0x899B,[0xDFFC]=0x89DF,[0xDFFD]=0x89E5,[0xDFFE]=0x89E4,[0xE040]=0x89E1,[0xE041]=0x89E0,[0xE042]=0x89E2,[0xE043]=0x89DC,[0xE044]=0x89E6,[0xE045]=0x8A76,[0xE046]=0x8A86,[0xE047]=0x8A7F,[0xE048]=0x8A61,[0xE049]=0x8A3F,[0xE04A]=0x8A77,[0xE04B]=0x8A82,[0xE04C]=0x8A84,[0xE04D]=0x8A75,[0xE04E]=0x8A83,[0xE04F]=0x8A81,[0xE050]=0x8A74,[0xE051]=0x8A7A,[0xE052]=0x8C3C,[0xE053]=0x8C4B,[0xE054]=0x8C4A,[0xE055]=0x8C65,[0xE056]=0x8C64,[0xE057]=0x8C66,[0xE058]=0x8C86,[0xE059]=0x8C84,[0xE05A]=0x8C85,[0xE05B]=0x8CCC,[0xE05C]=0x8D68,[0xE05D]=0x8D69,[0xE05E]=0x8D91,[0xE05F]=0x8D8C,[0xE060]=0x8D8E,[0xE061]=0x8D8F,[0xE062]=0x8D8D,[0xE063]=0x8D93,[0xE064]=0x8D94,[0xE065]=0x8D90,[0xE066]=0x8D92,[0xE067]=0x8DF0,[0xE068]=0x8DE0,[0xE069]=0x8DEC,[0xE06A]=0x8DF1,[0xE06B]=0x8DEE,[0xE06C]=0x8DD0,[0xE06D]=0x8DE9,[0xE06E]=0x8DE3,[0xE06F]=0x8DE2,[0xE070]=0x8DE7,[0xE071]=0x8DF2,[0xE072]=0x8DEB,[0xE073]=0x8DF4,[0xE074]=0x8F06,[0xE075]=0x8EFF,[0xE076]=0x8F01,[0xE077]=0x8F00,[0xE078]=0x8F05,[0xE079]=0x8F07,[0xE07A]=0x8F08,[0xE07B]=0x8F02,[0xE07C]=0x8F0B,[0xE07D]=0x9052,[0xE07E]=0x903F,[0xE0A1]=0x9044,[0xE0A2]=0x9049,[0xE0A3]=0x903D,[0xE0A4]=0x9110,[0xE0A5]=0x910D,[0xE0A6]=0x910F,[0xE0A7]=0x9111,[0xE0A8]=0x9116,[0xE0A9]=0x9114,[0xE0AA]=0x910B,[0xE0AB]=0x910E,[0xE0AC]=0x916E,[0xE0AD]=0x916F,[0xE0AE]=0x9248,[0xE0AF]=0x9252,[0xE0B0]=0x9230,[0xE0B1]=0x923A,[0xE0B2]=0x9266,[0xE0B3]=0x9233,[0xE0B4]=0x9265,[0xE0B5]=0x925E,[0xE0B6]=0x9283,[0xE0B7]=0x922E,[0xE0B8]=0x924A,[0xE0B9]=0x9246,[0xE0BA]=0x926D,[0xE0BB]=0x926C,[0xE0BC]=0x924F,[0xE0BD]=0x9260,[0xE0BE]=0x9267,[0xE0BF]=0x926F,[0xE0C0]=0x9236,[0xE0C1]=0x9261,[0xE0C2]=0x9270,[0xE0C3]=0x9231,[0xE0C4]=0x9254,[0xE0C5]=0x9263,[0xE0C6]=0x9250,[0xE0C7]=0x9272,[0xE0C8]=0x924E,[0xE0C9]=0x9253,[0xE0CA]=0x924C,[0xE0CB]=0x9256,[0xE0CC]=0x9232,[0xE0CD]=0x959F,[0xE0CE]=0x959C,[0xE0CF]=0x959E,[0xE0D0]=0x959B,[0xE0D1]=0x9692,[0xE0D2]=0x9693,[0xE0D3]=0x9691,[0xE0D4]=0x9697,[0xE0D5]=0x96CE,[0xE0D6]=0x96FA,[0xE0D7]=0x96FD,[0xE0D8]=0x96F8,[0xE0D9]=0x96F5,[0xE0DA]=0x9773,[0xE0DB]=0x9777,[0xE0DC]=0x9778,[0xE0DD]=0x9772,[0xE0DE]=0x980F,[0xE0DF]=0x980D,[0xE0E0]=0x980E,[0xE0E1]=0x98AC,[0xE0E2]=0x98F6,[0xE0E3]=0x98F9,[0xE0E4]=0x99AF,[0xE0E5]=0x99B2,[0xE0E6]=0x99B0,[0xE0E7]=0x99B5,[0xE0E8]=0x9AAD,[0xE0E9]=0x9AAB,[0xE0EA]=0x9B5B,[0xE0EB]=0x9CEA,[0xE0EC]=0x9CED,[0xE0ED]=0x9CE7,[0xE0EE]=0x9E80,[0xE0EF]=0x9EFD,[0xE0F0]=0x50E6,[0xE0F1]=0x50D4,[0xE0F2]=0x50D7,[0xE0F3]=0x50E8,[0xE0F4]=0x50F3,[0xE0F5]=0x50DB,[0xE0F6]=0x50EA,[0xE0F7]=0x50DD,[0xE0F8]=0x50E4,[0xE0F9]=0x50D3,[0xE0FA]=0x50EC,[0xE0FB]=0x50F0,[0xE0FC]=0x50EF,[0xE0FD]=0x50E3,[0xE0FE]=0x50E0,[0xE140]=0x51D8,[0xE141]=0x5280,[0xE142]=0x5281,[0xE143]=0x52E9,[0xE144]=0x52EB,[0xE145]=0x5330,[0xE146]=0x53AC,[0xE147]=0x5627,[0xE148]=0x5615,[0xE149]=0x560C,[0xE14A]=0x5612,[0xE14B]=0x55FC,[0xE14C]=0x560F,[0xE14D]=0x561C,[0xE14E]=0x5601,[0xE14F]=0x5613,[0xE150]=0x5602,[0xE151]=0x55FA,[0xE152]=0x561D,[0xE153]=0x5604,[0xE154]=0x55FF,[0xE155]=0x55F9,[0xE156]=0x5889,[0xE157]=0x587C,[0xE158]=0x5890,[0xE159]=0x5898,[0xE15A]=0x5886,[0xE15B]=0x5881,[0xE15C]=0x587F,[0xE15D]=0x5874,[0xE15E]=0x588B,[0xE15F]=0x587A,[0xE160]=0x5887,[0xE161]=0x5891,[0xE162]=0x588E,[0xE163]=0x5876,[0xE164]=0x5882,[0xE165]=0x5888,[0xE166]=0x587B,[0xE167]=0x5894,[0xE168]=0x588F,[0xE169]=0x58FE,[0xE16A]=0x596B,[0xE16B]=0x5ADC,[0xE16C]=0x5AEE,[0xE16D]=0x5AE5,[0xE16E]=0x5AD5,[0xE16F]=0x5AEA,[0xE170]=0x5ADA,[0xE171]=0x5AED,[0xE172]=0x5AEB,[0xE173]=0x5AF3,[0xE174]=0x5AE2,[0xE175]=0x5AE0,[0xE176]=0x5ADB,[0xE177]=0x5AEC,[0xE178]=0x5ADE,[0xE179]=0x5ADD,[0xE17A]=0x5AD9,[0xE17B]=0x5AE8,[0xE17C]=0x5ADF,[0xE17D]=0x5B77,[0xE17E]=0x5BE0,[0xE1A1]=0x5BE3,[0xE1A2]=0x5C63,[0xE1A3]=0x5D82,[0xE1A4]=0x5D80,[0xE1A5]=0x5D7D,[0xE1A6]=0x5D86,[0xE1A7]=0x5D7A,[0xE1A8]=0x5D81,[0xE1A9]=0x5D77,[0xE1AA]=0x5D8A,[0xE1AB]=0x5D89,[0xE1AC]=0x5D88,[0xE1AD]=0x5D7E,[0xE1AE]=0x5D7C,[0xE1AF]=0x5D8D,[0xE1B0]=0x5D79,[0xE1B1]=0x5D7F,[0xE1B2]=0x5E58,[0xE1B3]=0x5E59,[0xE1B4]=0x5E53,[0xE1B5]=0x5ED8,[0xE1B6]=0x5ED1,[0xE1B7]=0x5ED7,[0xE1B8]=0x5ECE,[0xE1B9]=0x5EDC,[0xE1BA]=0x5ED5,[0xE1BB]=0x5ED9,[0xE1BC]=0x5ED2,[0xE1BD]=0x5ED4,[0xE1BE]=0x5F44,[0xE1BF]=0x5F43,[0xE1C0]=0x5F6F,[0xE1C1]=0x5FB6,[0xE1C2]=0x612C,[0xE1C3]=0x6128,[0xE1C4]=0x6141,[0xE1C5]=0x615E,[0xE1C6]=0x6171,[0xE1C7]=0x6173,[0xE1C8]=0x6152,[0xE1C9]=0x6153,[0xE1CA]=0x6172,[0xE1CB]=0x616C,[0xE1CC]=0x6180,[0xE1CD]=0x6174,[0xE1CE]=0x6154,[0xE1CF]=0x617A,[0xE1D0]=0x615B,[0xE1D1]=0x6165,[0xE1D2]=0x613B,[0xE1D3]=0x616A,[0xE1D4]=0x6161,[0xE1D5]=0x6156,[0xE1D6]=0x6229,[0xE1D7]=0x6227,[0xE1D8]=0x622B,[0xE1D9]=0x642B,[0xE1DA]=0x644D,[0xE1DB]=0x645B,[0xE1DC]=0x645D,[0xE1DD]=0x6474,[0xE1DE]=0x6476,[0xE1DF]=0x6472,[0xE1E0]=0x6473,[0xE1E1]=0x647D,[0xE1E2]=0x6475,[0xE1E3]=0x6466,[0xE1E4]=0x64A6,[0xE1E5]=0x644E,[0xE1E6]=0x6482,[0xE1E7]=0x645E,[0xE1E8]=0x645C,[0xE1E9]=0x644B,[0xE1EA]=0x6453,[0xE1EB]=0x6460,[0xE1EC]=0x6450,[0xE1ED]=0x647F,[0xE1EE]=0x643F,[0xE1EF]=0x646C,[0xE1F0]=0x646B,[0xE1F1]=0x6459,[0xE1F2]=0x6465,[0xE1F3]=0x6477,[0xE1F4]=0x6573,[0xE1F5]=0x65A0,[0xE1F6]=0x66A1,[0xE1F7]=0x66A0,[0xE1F8]=0x669F,[0xE1F9]=0x6705,[0xE1FA]=0x6704,[0xE1FB]=0x6722,[0xE1FC]=0x69B1,[0xE1FD]=0x69B6,[0xE1FE]=0x69C9,[0xE240]=0x69A0,[0xE241]=0x69CE,[0xE242]=0x6996,[0xE243]=0x69B0,[0xE244]=0x69AC,[0xE245]=0x69BC,[0xE246]=0x6991,[0xE247]=0x6999,[0xE248]=0x698E,[0xE249]=0x69A7,[0xE24A]=0x698D,[0xE24B]=0x69A9,[0xE24C]=0x69BE,[0xE24D]=0x69AF,[0xE24E]=0x69BF,[0xE24F]=0x69C4,[0xE250]=0x69BD,[0xE251]=0x69A4,[0xE252]=0x69D4,[0xE253]=0x69B9,[0xE254]=0x69CA,[0xE255]=0x699A,[0xE256]=0x69CF,[0xE257]=0x69B3,[0xE258]=0x6993,[0xE259]=0x69AA,[0xE25A]=0x69A1,[0xE25B]=0x699E,[0xE25C]=0x69D9,[0xE25D]=0x6997,[0xE25E]=0x6990,[0xE25F]=0x69C2,[0xE260]=0x69B5,[0xE261]=0x69A5,[0xE262]=0x69C6,[0xE263]=0x6B4A,[0xE264]=0x6B4D,[0xE265]=0x6B4B,[0xE266]=0x6B9E,[0xE267]=0x6B9F,[0xE268]=0x6BA0,[0xE269]=0x6BC3,[0xE26A]=0x6BC4,[0xE26B]=0x6BFE,[0xE26C]=0x6ECE,[0xE26D]=0x6EF5,[0xE26E]=0x6EF1,[0xE26F]=0x6F03,[0xE270]=0x6F25,[0xE271]=0x6EF8,[0xE272]=0x6F37,[0xE273]=0x6EFB,[0xE274]=0x6F2E,[0xE275]=0x6F09,[0xE276]=0x6F4E,[0xE277]=0x6F19,[0xE278]=0x6F1A,[0xE279]=0x6F27,[0xE27A]=0x6F18,[0xE27B]=0x6F3B,[0xE27C]=0x6F12,[0xE27D]=0x6EED,[0xE27E]=0x6F0A,[0xE2A1]=0x6F36,[0xE2A2]=0x6F73,[0xE2A3]=0x6EF9,[0xE2A4]=0x6EEE,[0xE2A5]=0x6F2D,[0xE2A6]=0x6F40,[0xE2A7]=0x6F30,[0xE2A8]=0x6F3C,[0xE2A9]=0x6F35,[0xE2AA]=0x6EEB,[0xE2AB]=0x6F07,[0xE2AC]=0x6F0E,[0xE2AD]=0x6F43,[0xE2AE]=0x6F05,[0xE2AF]=0x6EFD,[0xE2B0]=0x6EF6,[0xE2B1]=0x6F39,[0xE2B2]=0x6F1C,[0xE2B3]=0x6EFC,[0xE2B4]=0x6F3A,[0xE2B5]=0x6F1F,[0xE2B6]=0x6F0D,[0xE2B7]=0x6F1E,[0xE2B8]=0x6F08,[0xE2B9]=0x6F21,[0xE2BA]=0x7187,[0xE2BB]=0x7190,[0xE2BC]=0x7189,[0xE2BD]=0x7180,[0xE2BE]=0x7185,[0xE2BF]=0x7182,[0xE2C0]=0x718F,[0xE2C1]=0x717B,[0xE2C2]=0x7186,[0xE2C3]=0x7181,[0xE2C4]=0x7197,[0xE2C5]=0x7244,[0xE2C6]=0x7253,[0xE2C7]=0x7297,[0xE2C8]=0x7295,[0xE2C9]=0x7293,[0xE2CA]=0x7343,[0xE2CB]=0x734D,[0xE2CC]=0x7351,[0xE2CD]=0x734C,[0xE2CE]=0x7462,[0xE2CF]=0x7473,[0xE2D0]=0x7471,[0xE2D1]=0x7475,[0xE2D2]=0x7472,[0xE2D3]=0x7467,[0xE2D4]=0x746E,[0xE2D5]=0x7500,[0xE2D6]=0x7502,[0xE2D7]=0x7503,[0xE2D8]=0x757D,[0xE2D9]=0x7590,[0xE2DA]=0x7616,[0xE2DB]=0x7608,[0xE2DC]=0x760C,[0xE2DD]=0x7615,[0xE2DE]=0x7611,[0xE2DF]=0x760A,[0xE2E0]=0x7614,[0xE2E1]=0x76B8,[0xE2E2]=0x7781,[0xE2E3]=0x777C,[0xE2E4]=0x7785,[0xE2E5]=0x7782,[0xE2E6]=0x776E,[0xE2E7]=0x7780,[0xE2E8]=0x776F,[0xE2E9]=0x777E,[0xE2EA]=0x7783,[0xE2EB]=0x78B2,[0xE2EC]=0x78AA,[0xE2ED]=0x78B4,[0xE2EE]=0x78AD,[0xE2EF]=0x78A8,[0xE2F0]=0x787E,[0xE2F1]=0x78AB,[0xE2F2]=0x789E,[0xE2F3]=0x78A5,[0xE2F4]=0x78A0,[0xE2F5]=0x78AC,[0xE2F6]=0x78A2,[0xE2F7]=0x78A4,[0xE2F8]=0x7998,[0xE2F9]=0x798A,[0xE2FA]=0x798B,[0xE2FB]=0x7996,[0xE2FC]=0x7995,[0xE2FD]=0x7994,[0xE2FE]=0x7993,[0xE340]=0x7997,[0xE341]=0x7988,[0xE342]=0x7992,[0xE343]=0x7990,[0xE344]=0x7A2B,[0xE345]=0x7A4A,[0xE346]=0x7A30,[0xE347]=0x7A2F,[0xE348]=0x7A28,[0xE349]=0x7A26,[0xE34A]=0x7AA8,[0xE34B]=0x7AAB,[0xE34C]=0x7AAC,[0xE34D]=0x7AEE,[0xE34E]=0x7B88,[0xE34F]=0x7B9C,[0xE350]=0x7B8A,[0xE351]=0x7B91,[0xE352]=0x7B90,[0xE353]=0x7B96,[0xE354]=0x7B8D,[0xE355]=0x7B8C,[0xE356]=0x7B9B,[0xE357]=0x7B8E,[0xE358]=0x7B85,[0xE359]=0x7B98,[0xE35A]=0x5284,[0xE35B]=0x7B99,[0xE35C]=0x7BA4,[0xE35D]=0x7B82,[0xE35E]=0x7CBB,[0xE35F]=0x7CBF,[0xE360]=0x7CBC,[0xE361]=0x7CBA,[0xE362]=0x7DA7,[0xE363]=0x7DB7,[0xE364]=0x7DC2,[0xE365]=0x7DA3,[0xE366]=0x7DAA,[0xE367]=0x7DC1,[0xE368]=0x7DC0,[0xE369]=0x7DC5,[0xE36A]=0x7D9D,[0xE36B]=0x7DCE,[0xE36C]=0x7DC4,[0xE36D]=0x7DC6,[0xE36E]=0x7DCB,[0xE36F]=0x7DCC,[0xE370]=0x7DAF,[0xE371]=0x7DB9,[0xE372]=0x7D96,[0xE373]=0x7DBC,[0xE374]=0x7D9F,[0xE375]=0x7DA6,[0xE376]=0x7DAE,[0xE377]=0x7DA9,[0xE378]=0x7DA1,[0xE379]=0x7DC9,[0xE37A]=0x7F73,[0xE37B]=0x7FE2,[0xE37C]=0x7FE3,[0xE37D]=0x7FE5,[0xE37E]=0x7FDE,[0xE3A1]=0x8024,[0xE3A2]=0x805D,[0xE3A3]=0x805C,[0xE3A4]=0x8189,[0xE3A5]=0x8186,[0xE3A6]=0x8183,[0xE3A7]=0x8187,[0xE3A8]=0x818D,[0xE3A9]=0x818C,[0xE3AA]=0x818B,[0xE3AB]=0x8215,[0xE3AC]=0x8497,[0xE3AD]=0x84A4,[0xE3AE]=0x84A1,[0xE3AF]=0x849F,[0xE3B0]=0x84BA,[0xE3B1]=0x84CE,[0xE3B2]=0x84C2,[0xE3B3]=0x84AC,[0xE3B4]=0x84AE,[0xE3B5]=0x84AB,[0xE3B6]=0x84B9,[0xE3B7]=0x84B4,[0xE3B8]=0x84C1,[0xE3B9]=0x84CD,[0xE3BA]=0x84AA,[0xE3BB]=0x849A,[0xE3BC]=0x84B1,[0xE3BD]=0x84D0,[0xE3BE]=0x849D,[0xE3BF]=0x84A7,[0xE3C0]=0x84BB,[0xE3C1]=0x84A2,[0xE3C2]=0x8494,[0xE3C3]=0x84C7,[0xE3C4]=0x84CC,[0xE3C5]=0x849B,[0xE3C6]=0x84A9,[0xE3C7]=0x84AF,[0xE3C8]=0x84A8,[0xE3C9]=0x84D6,[0xE3CA]=0x8498,[0xE3CB]=0x84B6,[0xE3CC]=0x84CF,[0xE3CD]=0x84A0,[0xE3CE]=0x84D7,[0xE3CF]=0x84D4,[0xE3D0]=0x84D2,[0xE3D1]=0x84DB,[0xE3D2]=0x84B0,[0xE3D3]=0x8491,[0xE3D4]=0x8661,[0xE3D5]=0x8733,[0xE3D6]=0x8723,[0xE3D7]=0x8728,[0xE3D8]=0x876B,[0xE3D9]=0x8740,[0xE3DA]=0x872E,[0xE3DB]=0x871E,[0xE3DC]=0x8721,[0xE3DD]=0x8719,[0xE3DE]=0x871B,[0xE3DF]=0x8743,[0xE3E0]=0x872C,[0xE3E1]=0x8741,[0xE3E2]=0x873E,[0xE3E3]=0x8746,[0xE3E4]=0x8720,[0xE3E5]=0x8732,[0xE3E6]=0x872A,[0xE3E7]=0x872D,[0xE3E8]=0x873C,[0xE3E9]=0x8712,[0xE3EA]=0x873A,[0xE3EB]=0x8731,[0xE3EC]=0x8735,[0xE3ED]=0x8742,[0xE3EE]=0x8726,[0xE3EF]=0x8727,[0xE3F0]=0x8738,[0xE3F1]=0x8724,[0xE3F2]=0x871A,[0xE3F3]=0x8730,[0xE3F4]=0x8711,[0xE3F5]=0x88F7,[0xE3F6]=0x88E7,[0xE3F7]=0x88F1,[0xE3F8]=0x88F2,[0xE3F9]=0x88FA,[0xE3FA]=0x88FE,[0xE3FB]=0x88EE,[0xE3FC]=0x88FC,[0xE3FD]=0x88F6,[0xE3FE]=0x88FB,[0xE440]=0x88F0,[0xE441]=0x88EC,[0xE442]=0x88EB,[0xE443]=0x899D,[0xE444]=0x89A1,[0xE445]=0x899F,[0xE446]=0x899E,[0xE447]=0x89E9,[0xE448]=0x89EB,[0xE449]=0x89E8,[0xE44A]=0x8AAB,[0xE44B]=0x8A99,[0xE44C]=0x8A8B,[0xE44D]=0x8A92,[0xE44E]=0x8A8F,[0xE44F]=0x8A96,[0xE450]=0x8C3D,[0xE451]=0x8C68,[0xE452]=0x8C69,[0xE453]=0x8CD5,[0xE454]=0x8CCF,[0xE455]=0x8CD7,[0xE456]=0x8D96,[0xE457]=0x8E09,[0xE458]=0x8E02,[0xE459]=0x8DFF,[0xE45A]=0x8E0D,[0xE45B]=0x8DFD,[0xE45C]=0x8E0A,[0xE45D]=0x8E03,[0xE45E]=0x8E07,[0xE45F]=0x8E06,[0xE460]=0x8E05,[0xE461]=0x8DFE,[0xE462]=0x8E00,[0xE463]=0x8E04,[0xE464]=0x8F10,[0xE465]=0x8F11,[0xE466]=0x8F0E,[0xE467]=0x8F0D,[0xE468]=0x9123,[0xE469]=0x911C,[0xE46A]=0x9120,[0xE46B]=0x9122,[0xE46C]=0x911F,[0xE46D]=0x911D,[0xE46E]=0x911A,[0xE46F]=0x9124,[0xE470]=0x9121,[0xE471]=0x911B,[0xE472]=0x917A,[0xE473]=0x9172,[0xE474]=0x9179,[0xE475]=0x9173,[0xE476]=0x92A5,[0xE477]=0x92A4,[0xE478]=0x9276,[0xE479]=0x929B,[0xE47A]=0x927A,[0xE47B]=0x92A0,[0xE47C]=0x9294,[0xE47D]=0x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7,[0xE4E6]=0x50FF,[0xE4E7]=0x5103,[0xE4E8]=0x5130,[0xE4E9]=0x50F8,[0xE4EA]=0x5106,[0xE4EB]=0x5107,[0xE4EC]=0x50F6,[0xE4ED]=0x50FE,[0xE4EE]=0x510B,[0xE4EF]=0x510C,[0xE4F0]=0x50FD,[0xE4F1]=0x510A,[0xE4F2]=0x528B,[0xE4F3]=0x528C,[0xE4F4]=0x52F1,[0xE4F5]=0x52EF,[0xE4F6]=0x5648,[0xE4F7]=0x5642,[0xE4F8]=0x564C,[0xE4F9]=0x5635,[0xE4FA]=0x5641,[0xE4FB]=0x564A,[0xE4FC]=0x5649,[0xE4FD]=0x5646,[0xE4FE]=0x5658,[0xE540]=0x565A,[0xE541]=0x5640,[0xE542]=0x5633,[0xE543]=0x563D,[0xE544]=0x562C,[0xE545]=0x563E,[0xE546]=0x5638,[0xE547]=0x562A,[0xE548]=0x563A,[0xE549]=0x571A,[0xE54A]=0x58AB,[0xE54B]=0x589D,[0xE54C]=0x58B1,[0xE54D]=0x58A0,[0xE54E]=0x58A3,[0xE54F]=0x58AF,[0xE550]=0x58AC,[0xE551]=0x58A5,[0xE552]=0x58A1,[0xE553]=0x58FF,[0xE554]=0x5AFF,[0xE555]=0x5AF4,[0xE556]=0x5AFD,[0xE557]=0x5AF7,[0xE558]=0x5AF6,[0xE559]=0x5B03,[0xE55A]=0x5AF8,[0xE55B]=0x5B02,[0xE55C]=0x5AF9,[0xE55D]=0x5B01,[0xE55E]=0x5B07,[0xE55F]=0x5B05,[0xE560]=0x5B0F,[0xE561]=0x5C67,[0xE562]=0x5D99,[0xE563]=0x5D97,[0xE564]=0x5D9F,[0xE565]=0x5D92,[0xE566]=0x5DA2,[0xE567]=0x5D93,[0xE568]=0x5D95,[0xE569]=0x5DA0,[0xE56A]=0x5D9C,[0xE56B]=0x5DA1,[0xE56C]=0x5D9A,[0xE56D]=0x5D9E,[0xE56E]=0x5E69,[0xE56F]=0x5E5D,[0xE570]=0x5E60,[0xE571]=0x5E5C,[0xE572]=0x7DF3,[0xE573]=0x5EDB,[0xE574]=0x5EDE,[0xE575]=0x5EE1,[0xE576]=0x5F49,[0xE577]=0x5FB2,[0xE578]=0x618B,[0xE579]=0x6183,[0xE57A]=0x6179,[0xE57B]=0x61B1,[0xE57C]=0x61B0,[0xE57D]=0x61A2,[0xE57E]=0x6189,[0xE5A1]=0x619B,[0xE5A2]=0x6193,[0xE5A3]=0x61AF,[0xE5A4]=0x61AD,[0xE5A5]=0x619F,[0xE5A6]=0x6192,[0xE5A7]=0x61AA,[0xE5A8]=0x61A1,[0xE5A9]=0x618D,[0xE5AA]=0x6166,[0xE5AB]=0x61B3,[0xE5AC]=0x622D,[0xE5AD]=0x646E,[0xE5AE]=0x6470,[0xE5AF]=0x6496,[0xE5B0]=0x64A0,[0xE5B1]=0x6485,[0xE5B2]=0x6497,[0xE5B3]=0x649C,[0xE5B4]=0x648F,[0xE5B5]=0x648B,[0xE5B6]=0x648A,[0xE5B7]=0x648C,[0xE5B8]=0x64A3,[0xE5B9]=0x649F,[0xE5BA]=0x6468,[0xE5BB]=0x64B1,[0xE5BC]=0x6498,[0xE5BD]=0x6576,[0xE5BE]=0x657A,[0xE5BF]=0x6579,[0xE5C0]=0x657B,[0xE5C1]=0x65B2,[0xE5C2]=0x65B3,[0xE5C3]=0x66B5,[0xE5C4]=0x66B0,[0xE5C5]=0x66A9,[0xE5C6]=0x66B2,[0xE5C7]=0x66B7,[0xE5C8]=0x66AA,[0xE5C9]=0x66AF,[0xE5CA]=0x6A00,[0xE5CB]=0x6A06,[0xE5CC]=0x6A17,[0xE5CD]=0x69E5,[0xE5CE]=0x69F8,[0xE5CF]=0x6A15,[0xE5D0]=0x69F1,[0xE5D1]=0x69E4,[0xE5D2]=0x6A20,[0xE5D3]=0x69FF,[0xE5D4]=0x69EC,[0xE5D5]=0x69E2,[0xE5D6]=0x6A1B,[0xE5D7]=0x6A1D,[0xE5D8]=0x69FE,[0xE5D9]=0x6A27,[0xE5DA]=0x69F2,[0xE5DB]=0x69EE,[0xE5DC]=0x6A14,[0xE5DD]=0x69F7,[0xE5DE]=0x69E7,[0xE5DF]=0x6A40,[0xE5E0]=0x6A08,[0xE5E1]=0x69E6,[0xE5E2]=0x69FB,[0xE5E3]=0x6A0D,[0xE5E4]=0x69FC,[0xE5E5]=0x69EB,[0xE5E6]=0x6A09,[0xE5E7]=0x6A04,[0xE5E8]=0x6A18,[0xE5E9]=0x6A25,[0xE5EA]=0x6A0F,[0xE5EB]=0x69F6,[0xE5EC]=0x6A26,[0xE5ED]=0x6A07,[0xE5EE]=0x69F4,[0xE5EF]=0x6A16,[0xE5F0]=0x6B51,[0xE5F1]=0x6BA5,[0xE5F2]=0x6BA3,[0xE5F3]=0x6BA2,[0xE5F4]=0x6BA6,[0xE5F5]=0x6C01,[0xE5F6]=0x6C00,[0xE5F7]=0x6BFF,[0xE5F8]=0x6C02,[0xE5F9]=0x6F41,[0xE5FA]=0x6F26,[0xE5FB]=0x6F7E,[0xE5FC]=0x6F87,[0xE5FD]=0x6FC6,[0xE5FE]=0x6F92,[0xE640]=0x6F8D,[0xE641]=0x6F89,[0xE642]=0x6F8C,[0xE643]=0x6F62,[0xE644]=0x6F4F,[0xE645]=0x6F85,[0xE646]=0x6F5A,[0xE647]=0x6F96,[0xE648]=0x6F76,[0xE649]=0x6F6C,[0xE64A]=0x6F82,[0xE64B]=0x6F55,[0xE64C]=0x6F72,[0xE64D]=0x6F52,[0xE64E]=0x6F50,[0xE64F]=0x6F57,[0xE650]=0x6F94,[0xE651]=0x6F93,[0xE652]=0x6F5D,[0xE653]=0x6F00,[0xE654]=0x6F61,[0xE655]=0x6F6B,[0xE656]=0x6F7D,[0xE657]=0x6F67,[0xE658]=0x6F90,[0xE659]=0x6F53,[0xE65A]=0x6F8B,[0xE65B]=0x6F69,[0xE65C]=0x6F7F,[0xE65D]=0x6F95,[0xE65E]=0x6F63,[0xE65F]=0x6F77,[0xE660]=0x6F6A,[0xE661]=0x6F7B,[0xE662]=0x71B2,[0xE663]=0x71AF,[0xE664]=0x719B,[0xE665]=0x71B0,[0xE666]=0x71A0,[0xE667]=0x719A,[0xE668]=0x71A9,[0xE669]=0x71B5,[0xE66A]=0x719D,[0xE66B]=0x71A5,[0xE66C]=0x719E,[0xE66D]=0x71A4,[0xE66E]=0x71A1,[0xE66F]=0x71AA,[0xE670]=0x719C,[0xE671]=0x71A7,[0xE672]=0x71B3,[0xE673]=0x7298,[0xE674]=0x729A,[0xE675]=0x7358,[0xE676]=0x7352,[0xE677]=0x735E,[0xE678]=0x735F,[0xE679]=0x7360,[0xE67A]=0x735D,[0xE67B]=0x735B,[0xE67C]=0x7361,[0xE67D]=0x735A,[0xE67E]=0x7359,[0xE6A1]=0x7362,[0xE6A2]=0x7487,[0xE6A3]=0x7489,[0xE6A4]=0x748A,[0xE6A5]=0x7486,[0xE6A6]=0x7481,[0xE6A7]=0x747D,[0xE6A8]=0x7485,[0xE6A9]=0x7488,[0xE6AA]=0x747C,[0xE6AB]=0x7479,[0xE6AC]=0x7508,[0xE6AD]=0x7507,[0xE6AE]=0x757E,[0xE6AF]=0x7625,[0xE6B0]=0x761E,[0xE6B1]=0x7619,[0xE6B2]=0x761D,[0xE6B3]=0x761C,[0xE6B4]=0x7623,[0xE6B5]=0x761A,[0xE6B6]=0x7628,[0xE6B7]=0x761B,[0xE6B8]=0x769C,[0xE6B9]=0x769D,[0xE6BA]=0x769E,[0xE6BB]=0x769B,[0xE6BC]=0x778D,[0xE6BD]=0x778F,[0xE6BE]=0x7789,[0xE6BF]=0x7788,[0xE6C0]=0x78CD,[0xE6C1]=0x78BB,[0xE6C2]=0x78CF,[0xE6C3]=0x78CC,[0xE6C4]=0x78D1,[0xE6C5]=0x78CE,[0xE6C6]=0x78D4,[0xE6C7]=0x78C8,[0xE6C8]=0x78C3,[0xE6C9]=0x78C4,[0xE6CA]=0x78C9,[0xE6CB]=0x799A,[0xE6CC]=0x79A1,[0xE6CD]=0x79A0,[0xE6CE]=0x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850A,[0xE756]=0x8527,[0xE757]=0x851C,[0xE758]=0x84FB,[0xE759]=0x852B,[0xE75A]=0x84FA,[0xE75B]=0x8508,[0xE75C]=0x850C,[0xE75D]=0x84F4,[0xE75E]=0x852A,[0xE75F]=0x84F2,[0xE760]=0x8515,[0xE761]=0x84F7,[0xE762]=0x84EB,[0xE763]=0x84F3,[0xE764]=0x84FC,[0xE765]=0x8512,[0xE766]=0x84EA,[0xE767]=0x84E9,[0xE768]=0x8516,[0xE769]=0x84FE,[0xE76A]=0x8528,[0xE76B]=0x851D,[0xE76C]=0x852E,[0xE76D]=0x8502,[0xE76E]=0x84FD,[0xE76F]=0x851E,[0xE770]=0x84F6,[0xE771]=0x8531,[0xE772]=0x8526,[0xE773]=0x84E7,[0xE774]=0x84E8,[0xE775]=0x84F0,[0xE776]=0x84EF,[0xE777]=0x84F9,[0xE778]=0x8518,[0xE779]=0x8520,[0xE77A]=0x8530,[0xE77B]=0x850B,[0xE77C]=0x8519,[0xE77D]=0x852F,[0xE77E]=0x8662,[0xE7A1]=0x8756,[0xE7A2]=0x8763,[0xE7A3]=0x8764,[0xE7A4]=0x8777,[0xE7A5]=0x87E1,[0xE7A6]=0x8773,[0xE7A7]=0x8758,[0xE7A8]=0x8754,[0xE7A9]=0x875B,[0xE7AA]=0x8752,[0xE7AB]=0x8761,[0xE7AC]=0x875A,[0xE7AD]=0x8751,[0xE7AE]=0x875E,[0xE7AF]=0x876D,[0xE7B0]=0x876A,[0xE7B1]=0x8750,[0xE7B2]=0x874E,[0xE7B3]=0x875F,[0xE7B4]=0x875D,[0xE7B5]=0x876F,[0xE7B6]=0x876C,[0xE7B7]=0x877A,[0xE7B8]=0x876E,[0xE7B9]=0x875C,[0xE7BA]=0x8765,[0xE7BB]=0x874F,[0xE7BC]=0x877B,[0xE7BD]=0x8775,[0xE7BE]=0x8762,[0xE7BF]=0x8767,[0xE7C0]=0x8769,[0xE7C1]=0x885A,[0xE7C2]=0x8905,[0xE7C3]=0x890C,[0x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,[0xE849]=0x8F18,[0xE84A]=0x8F1A,[0xE84B]=0x8F20,[0xE84C]=0x8F23,[0xE84D]=0x8F16,[0xE84E]=0x8F17,[0xE84F]=0x9073,[0xE850]=0x9070,[0xE851]=0x906F,[0xE852]=0x9067,[0xE853]=0x906B,[0xE854]=0x912F,[0xE855]=0x912B,[0xE856]=0x9129,[0xE857]=0x912A,[0xE858]=0x9132,[0xE859]=0x9126,[0xE85A]=0x912E,[0xE85B]=0x9185,[0xE85C]=0x9186,[0xE85D]=0x918A,[0xE85E]=0x9181,[0xE85F]=0x9182,[0xE860]=0x9184,[0xE861]=0x9180,[0xE862]=0x92D0,[0xE863]=0x92C3,[0xE864]=0x92C4,[0xE865]=0x92C0,[0xE866]=0x92D9,[0xE867]=0x92B6,[0xE868]=0x92CF,[0xE869]=0x92F1,[0xE86A]=0x92DF,[0xE86B]=0x92D8,[0xE86C]=0x92E9,[0xE86D]=0x92D7,[0xE86E]=0x92DD,[0xE86F]=0x92CC,[0xE870]=0x92EF,[0xE871]=0x92C2,[0xE872]=0x92E8,[0xE873]=0x92CA,[0xE874]=0x92C8,[0xE875]=0x92CE,[0xE876]=0x92E6,[0xE877]=0x92CD,[0xE878]=0x92D5,[0xE879]=0x92C9,[0xE87A]=0x92E0,[0xE87B]=0x92DE,[0xE87C]=0x92E7,[0xE87D]=0x92D1,[0xE87E]=0x92D3,[0xE8A1]=0x92B5,[0xE8A2]=0x92E1,[0xE8A3]=0x92C6,[0xE8A4]=0x92B4,[0xE8A5]=0x957C,[0xE8A6]=0x95AC,[0xE8A7]=0x95AB,[0xE8A8]=0x95AE,[0xE8A9]=0x95B0,[0xE8AA]=0x96A4,[0xE8AB]=0x96A2,[0xE8AC]=0x96D3,[0xE8AD]=0x9705,[0xE8AE]=0x9708,[0xE8AF]=0x9702,[0xE8B0]=0x975A,[0xE8B1]=0x978A,[0xE8B2]=0x978E,[0xE8B3]=0x9788,[0xE8B4]=0x97D0,[0xE8B5]=0x97CF,[0xE8B6]=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xE8FB]=0x53E1,[0xE8FC]=0x5670,[0xE8FD]=0x5660,[0xE8FE]=0x566E,[0xE940]=0x5673,[0xE941]=0x5666,[0xE942]=0x5663,[0xE943]=0x566D,[0xE944]=0x5672,[0xE945]=0x565E,[0xE946]=0x5677,[0xE947]=0x571C,[0xE948]=0x571B,[0xE949]=0x58C8,[0xE94A]=0x58BD,[0xE94B]=0x58C9,[0xE94C]=0x58BF,[0xE94D]=0x58BA,[0xE94E]=0x58C2,[0xE94F]=0x58BC,[0xE950]=0x58C6,[0xE951]=0x5B17,[0xE952]=0x5B19,[0xE953]=0x5B1B,[0xE954]=0x5B21,[0xE955]=0x5B14,[0xE956]=0x5B13,[0xE957]=0x5B10,[0xE958]=0x5B16,[0xE959]=0x5B28,[0xE95A]=0x5B1A,[0xE95B]=0x5B20,[0xE95C]=0x5B1E,[0xE95D]=0x5BEF,[0xE95E]=0x5DAC,[0xE95F]=0x5DB1,[0xE960]=0x5DA9,[0xE961]=0x5DA7,[0xE962]=0x5DB5,[0xE963]=0x5DB0,[0xE964]=0x5DAE,[0xE965]=0x5DAA,[0xE966]=0x5DA8,[0xE967]=0x5DB2,[0xE968]=0x5DAD,[0xE969]=0x5DAF,[0xE96A]=0x5DB4,[0xE96B]=0x5E67,[0xE96C]=0x5E68,[0xE96D]=0x5E66,[0xE96E]=0x5E6F,[0xE96F]=0x5EE9,[0xE970]=0x5EE7,[0xE971]=0x5EE6,[0xE972]=0x5EE8,[0xE973]=0x5EE5,[0xE974]=0x5F4B,[0xE975]=0x5FBC,[0xE976]=0x619D,[0xE977]=0x61A8,[0xE978]=0x6196,[0xE979]=0x61C5,[0xE97A]=0x61B4,[0xE97B]=0x61C6,[0xE97C]=0x61C1,[0xE97D]=0x61CC,[0xE97E]=0x61BA,[0xE9A1]=0x61BF,[0xE9A2]=0x61B8,[0xE9A3]=0x618C,[0xE9A4]=0x64D7,[0xE9A5]=0x64D6,[0xE9A6]=0x64D0,[0xE9A7]=0x64CF,[0xE9A8]=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FA3,[0xE9EC]=0x6FC7,[0xE9ED]=0x6FBC,[0xE9EE]=0x6FCE,[0xE9EF]=0x6FC8,[0xE9F0]=0x6F5E,[0xE9F1]=0x6FC4,[0xE9F2]=0x6FBD,[0xE9F3]=0x6F9E,[0xE9F4]=0x6FCA,[0xE9F5]=0x6FA8,[0xE9F6]=0x7004,[0xE9F7]=0x6FA5,[0xE9F8]=0x6FAE,[0xE9F9]=0x6FBA,[0xE9FA]=0x6FAC,[0xE9FB]=0x6FAA,[0xE9FC]=0x6FCF,[0xE9FD]=0x6FBF,[0xE9FE]=0x6FB8,[0xEA40]=0x6FA2,[0xEA41]=0x6FC9,[0xEA42]=0x6FAB,[0xEA43]=0x6FCD,[0xEA44]=0x6FAF,[0xEA45]=0x6FB2,[0xEA46]=0x6FB0,[0xEA47]=0x71C5,[0xEA48]=0x71C2,[0xEA49]=0x71BF,[0xEA4A]=0x71B8,[0xEA4B]=0x71D6,[0xEA4C]=0x71C0,[0xEA4D]=0x71C1,[0xEA4E]=0x71CB,[0xEA4F]=0x71D4,[0xEA50]=0x71CA,[0xEA51]=0x71C7,[0xEA52]=0x71CF,[0xEA53]=0x71BD,[0xEA54]=0x71D8,[0xEA55]=0x71BC,[0xEA56]=0x71C6,[0xEA57]=0x71DA,[0xEA58]=0x71DB,[0xEA59]=0x729D,[0xEA5A]=0x729E,[0xEA5B]=0x7369,[0xEA5C]=0x7366,[0xEA5D]=0x7367,[0xEA5E]=0x736C,[0xEA5F]=0x7365,[0xEA60]=0x736B,[0xEA61]=0x736A,[0xEA62]=0x747F,[0xEA63]=0x749A,[0xEA64]=0x74A0,[0xEA65]=0x7494,[0xEA66]=0x7492,[0xEA67]=0x7495,[0xEA68]=0x74A1,[0xEA69]=0x750B,[0xEA6A]=0x7580,[0xEA6B]=0x762F,[0xEA6C]=0x762D,[0xEA6D]=0x7631,[0xEA6E]=0x763D,[0xEA6F]=0x7633,[0xEA70]=0x763C,[0xEA71]=0x7635,[0xEA72]=0x7632,[0x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xEAD9]=0x7E0F,[0xEADA]=0x7E16,[0xEADB]=0x7E0D,[0xEADC]=0x7E14,[0xEADD]=0x7E25,[0xEADE]=0x7E24,[0xEADF]=0x7F43,[0xEAE0]=0x7F7B,[0xEAE1]=0x7F7C,[0xEAE2]=0x7F7A,[0xEAE3]=0x7FB1,[0xEAE4]=0x7FEF,[0xEAE5]=0x802A,[0xEAE6]=0x8029,[0xEAE7]=0x806C,[0xEAE8]=0x81B1,[0xEAE9]=0x81A6,[0xEAEA]=0x81AE,[0xEAEB]=0x81B9,[0xEAEC]=0x81B5,[0xEAED]=0x81AB,[0xEAEE]=0x81B0,[0xEAEF]=0x81AC,[0xEAF0]=0x81B4,[0xEAF1]=0x81B2,[0xEAF2]=0x81B7,[0xEAF3]=0x81A7,[0xEAF4]=0x81F2,[0xEAF5]=0x8255,[0xEAF6]=0x8256,[0xEAF7]=0x8257,[0xEAF8]=0x8556,[0xEAF9]=0x8545,[0xEAFA]=0x856B,[0xEAFB]=0x854D,[0xEAFC]=0x8553,[0xEAFD]=0x8561,[0xEAFE]=0x8558,[0xEB40]=0x8540,[0xEB41]=0x8546,[0xEB42]=0x8564,[0xEB43]=0x8541,[0xEB44]=0x8562,[0xEB45]=0x8544,[0xEB46]=0x8551,[0xEB47]=0x8547,[0xEB48]=0x8563,[0xEB49]=0x853E,[0xEB4A]=0x855B,[0xEB4B]=0x8571,[0xEB4C]=0x854E,[0xEB4D]=0x856E,[0xEB4E]=0x8575,[0xEB4F]=0x8555,[0xEB50]=0x8567,[0xEB51]=0x8560,[0xEB52]=0x858C,[0xEB53]=0x8566,[0xEB54]=0x855D,[0xEB55]=0x8554,[0xEB56]=0x8565,[0xEB57]=0x856C,[0xEB58]=0x8663,[0xEB59]=0x8665,[0xEB5A]=0x8664,[0xEB5B]=0x879B,[0xEB5C]=0x878F,[0xEB5D]=0x8797,[0xEB5E]=0x8793,[0xEB5F]=0x8792,[0xEB60]=0x8788,[0xEB61]=0x8781,[0xEB62]=0x8796,[0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EBCA]=0x8F2E,[0xEBCB]=0x8F35,[0xEBCC]=0x8F32,[0xEBCD]=0x8F39,[0xEBCE]=0x8F37,[0xEBCF]=0x8F34,[0xEBD0]=0x9076,[0xEBD1]=0x9079,[0xEBD2]=0x907B,[0xEBD3]=0x9086,[0xEBD4]=0x90FA,[0xEBD5]=0x9133,[0xEBD6]=0x9135,[0xEBD7]=0x9136,[0xEBD8]=0x9193,[0xEBD9]=0x9190,[0xEBDA]=0x9191,[0xEBDB]=0x918D,[0xEBDC]=0x918F,[0xEBDD]=0x9327,[0xEBDE]=0x931E,[0xEBDF]=0x9308,[0xEBE0]=0x931F,[0xEBE1]=0x9306,[0xEBE2]=0x930F,[0xEBE3]=0x937A,[0xEBE4]=0x9338,[0xEBE5]=0x933C,[0xEBE6]=0x931B,[0xEBE7]=0x9323,[0xEBE8]=0x9312,[0xEBE9]=0x9301,[0xEBEA]=0x9346,[0xEBEB]=0x932D,[0xEBEC]=0x930E,[0xEBED]=0x930D,[0xEBEE]=0x92CB,[0xEBEF]=0x931D,[0xEBF0]=0x92FA,[0xEBF1]=0x9325,[0xEBF2]=0x9313,[0xEBF3]=0x92F9,[0xEBF4]=0x92F7,[0xEBF5]=0x9334,[0xEBF6]=0x9302,[0xEBF7]=0x9324,[0xEBF8]=0x92FF,[0xEBF9]=0x9329,[0xEBFA]=0x9339,[0xEBFB]=0x9335,[0xEBFC]=0x932A,[0xEBFD]=0x9314,[0xEBFE]=0x930C,[0xEC40]=0x930B,[0xEC41]=0x92FE,[0xEC42]=0x9309,[0xEC43]=0x9300,[0xEC44]=0x92FB,[0xEC45]=0x9316,[0xEC46]=0x95BC,[0xEC47]=0x95CD,[0xEC48]=0x95BE,[0xEC49]=0x95B9,[0xEC4A]=0x95BA,[0xEC4B]=0x95B6,[0xEC4C]=0x95BF,[0xEC4D]=0x95B5,[0xEC4E]=0x95BD,[0xEC4F]=0x96A9,[0xEC50]=0x96D4,[0xEC51]=0x970B,[0xEC52]=0x9712,[0xEC53]=0x9710,[0xEC54]=0x9799,[0xEC55]=0x9797,[0xEC56]=0x9794,[0xEC57]=0x97F0,[0xEC58]=0x97F8,[0xEC59]=0x9835,[0xEC5A]=0x982F,[0xEC5B]=0x9832,[0xEC5C]=0x9924,[0xEC5D]=0x991F,[0xEC5E]=0x9927,[0xEC5F]=0x9929,[0xEC60]=0x999E,[0xEC61]=0x99EE,[0xEC62]=0x99EC,[0xEC63]=0x99E5,[0xEC64]=0x99E4,[0xEC65]=0x99F0,[0xEC66]=0x99E3,[0xEC67]=0x99EA,[0xEC68]=0x99E9,[0xEC69]=0x99E7,[0xEC6A]=0x9AB9,[0xEC6B]=0x9ABF,[0xEC6C]=0x9AB4,[0xEC6D]=0x9ABB,[0xEC6E]=0x9AF6,[0xEC6F]=0x9AFA,[0xEC70]=0x9AF9,[0xEC71]=0x9AF7,[0xEC72]=0x9B33,[0xEC73]=0x9B80,[0xEC74]=0x9B85,[0xEC75]=0x9B87,[0xEC76]=0x9B7C,[0xEC77]=0x9B7E,[0xEC78]=0x9B7B,[0xEC79]=0x9B82,[0xEC7A]=0x9B93,[0xEC7B]=0x9B92,[0xEC7C]=0x9B90,[0xEC7D]=0x9B7A,[0xEC7E]=0x9B95,[0xECA1]=0x9B7D,[0xECA2]=0x9B88,[0xECA3]=0x9D25,[0xECA4]=0x9D17,[0xECA5]=0x9D20,[0xECA6]=0x9D1E,[0xECA7]=0x9D14,[0xECA8]=0x9D29,[0xECA9]=0x9D1D,[0xECAA]=0x9D18,[0xECAB]=0x9D22,[0xECAC]=0x9D10,[0xECAD]=0x9D19,[0xECAE]=0x9D1F,[0xECAF]=0x9E88,[0xECB0]=0x9E86,[0xECB1]=0x9E87,[0xECB2]=0x9EAE,[0xECB3]=0x9EAD,[0xECB4]=0x9ED5,[0xECB5]=0x9ED6,[0xECB6]=0x9EFA,[0xECB7]=0x9F12,[0xECB8]=0x9F3D,[0xECB9]=0x5126,[0xECBA]=0x5125,[0xECBB]=0x5122,[0xECBC]=0x5124,[0xECBD]=0x5120,[0xECBE]=0x5129,[0xECBF]=0x52F4,[0xECC0]=0x5693,[0xECC1]=0x568C,[0xECC2]=0x568D,[0xECC3]=0x5686,[0xECC4]=0x5684,[0xECC5]=0x5683,[0xECC6]=0x567E,[0xECC7]=0x5682,[0xECC8]=0x567F,[0xECC9]=0x5681,[0xECCA]=0x58D6,[0xECCB]=0x58D4,[0xECCC]=0x58CF,[0xECCD]=0x58D2,[0xECCE]=0x5B2D,[0xECCF]=0x5B25,[0xECD0]=0x5B32,[0xECD1]=0x5B23,[0xECD2]=0x5B2C,[0xECD3]=0x5B27,[0xECD4]=0x5B26,[0xECD5]=0x5B2F,[0xECD6]=0x5B2E,[0xECD7]=0x5B7B,[0xECD8]=0x5BF1,[0xECD9]=0x5BF2,[0xECDA]=0x5DB7,[0xECDB]=0x5E6C,[0xECDC]=0x5E6A,[0xECDD]=0x5FBE,[0xECDE]=0x5FBB,[0xECDF]=0x61C3,[0xECE0]=0x61B5,[0xECE1]=0x61BC,[0xECE2]=0x61E7,[0xECE3]=0x61E0,[0xECE4]=0x61E5,[0xECE5]=0x61E4,[0xECE6]=0x61E8,[0xECE7]=0x61DE,[0xECE8]=0x64EF,[0xECE9]=0x64E9,[0xECEA]=0x64E3,[0xECEB]=0x64EB,[0xECEC]=0x64E4,[0xECED]=0x64E8,[0xECEE]=0x6581,[0xECEF]=0x6580,[0xECF0]=0x65B6,[0xECF1]=0x65DA,[0xECF2]=0x66D2,[0xECF3]=0x6A8D,[0xECF4]=0x6A96,[0xECF5]=0x6A81,[0xECF6]=0x6AA5,[0xECF7]=0x6A89,[0xECF8]=0x6A9F,[0xECF9]=0x6A9B,[0xECFA]=0x6AA1,[0xECFB]=0x6A9E,[0xECFC]=0x6A87,[0xECFD]=0x6A93,[0xECFE]=0x6A8E,[0xED40]=0x6A95,[0xED41]=0x6A83,[0xED42]=0x6AA8,[0xED43]=0x6AA4,[0xED44]=0x6A91,[0xED45]=0x6A7F,[0xED46]=0x6AA6,[0xED47]=0x6A9A,[0xED48]=0x6A85,[0xED49]=0x6A8C,[0xED4A]=0x6A92,[0xED4B]=0x6B5B,[0xED4C]=0x6BAD,[0xED4D]=0x6C09,[0xED4E]=0x6FCC,[0xED4F]=0x6FA9,[0xED50]=0x6FF4,[0xED51]=0x6FD4,[0xED52]=0x6FE3,[0xED53]=0x6FDC,[0xED54]=0x6FED,[0xED55]=0x6FE7,[0xED56]=0x6FE6,[0xED57]=0x6FDE,[0xED58]=0x6FF2,[0xED59]=0x6FDD,[0xED5A]=0x6FE2,[0xED5B]=0x6FE8,[0xED5C]=0x71E1,[0xED5D]=0x71F1,[0xED5E]=0x71E8,[0xED5F]=0x71F2,[0xED60]=0x71E4,[0xED61]=0x71F0,[0xED62]=0x71E2,[0xED63]=0x7373,[0xED64]=0x736E,[0xED65]=0x736F,[0xED66]=0x7497,[0xED67]=0x74B2,[0xED68]=0x74AB,[0xED69]=0x7490,[0xED6A]=0x74AA,[0xED6B]=0x74AD,[0xED6C]=0x74B1,[0xED6D]=0x74A5,[0xED6E]=0x74AF,[0xED6F]=0x7510,[0xED70]=0x7511,[0xED71]=0x7512,[0xED72]=0x750F,[0xED73]=0x7584,[0xED74]=0x7643,[0xED75]=0x7648,[0xED76]=0x7649,[0xED77]=0x7647,[0xED78]=0x76A4,[0xED79]=0x76E9,[0xED7A]=0x77B5,[0xED7B]=0x77AB,[0xED7C]=0x77B2,[0xED7D]=0x77B7,[0xED7E]=0x77B6,[0xEDA1]=0x77B4,[0xEDA2]=0x77B1,[0xEDA3]=0x77A8,[0xEDA4]=0x77F0,[0xEDA5]=0x78F3,[0xEDA6]=0x78FD,[0xEDA7]=0x7902,[0xEDA8]=0x78FB,[0xEDA9]=0x78FC,[0xEDAA]=0x78F2,[0xEDAB]=0x7905,[0xEDAC]=0x78F9,[0xEDAD]=0x78FE,[0xEDAE]=0x7904,[0xEDAF]=0x79AB,[0xEDB0]=0x79A8,[0xEDB1]=0x7A5C,[0xEDB2]=0x7A5B,[0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0xEDF6]=0x85A7,[0xEDF7]=0x8595,[0xEDF8]=0x85A0,[0xEDF9]=0x858B,[0xEDFA]=0x85A3,[0xEDFB]=0x857B,[0xEDFC]=0x85A4,[0xEDFD]=0x859A,[0xEDFE]=0x859E,[0xEE40]=0x8577,[0xEE41]=0x857C,[0xEE42]=0x8589,[0xEE43]=0x85A1,[0xEE44]=0x857A,[0xEE45]=0x8578,[0xEE46]=0x8557,[0xEE47]=0x858E,[0xEE48]=0x8596,[0xEE49]=0x8586,[0xEE4A]=0x858D,[0xEE4B]=0x8599,[0xEE4C]=0x859D,[0xEE4D]=0x8581,[0xEE4E]=0x85A2,[0xEE4F]=0x8582,[0xEE50]=0x8588,[0xEE51]=0x8585,[0xEE52]=0x8579,[0xEE53]=0x8576,[0xEE54]=0x8598,[0xEE55]=0x8590,[0xEE56]=0x859F,[0xEE57]=0x8668,[0xEE58]=0x87BE,[0xEE59]=0x87AA,[0xEE5A]=0x87AD,[0xEE5B]=0x87C5,[0xEE5C]=0x87B0,[0xEE5D]=0x87AC,[0xEE5E]=0x87B9,[0xEE5F]=0x87B5,[0xEE60]=0x87BC,[0xEE61]=0x87AE,[0xEE62]=0x87C9,[0xEE63]=0x87C3,[0xEE64]=0x87C2,[0xEE65]=0x87CC,[0xEE66]=0x87B7,[0xEE67]=0x87AF,[0xEE68]=0x87C4,[0xEE69]=0x87CA,[0xEE6A]=0x87B4,[0xEE6B]=0x87B6,[0xEE6C]=0x87BF,[0xEE6D]=0x87B8,[0xEE6E]=0x87BD,[0xEE6F]=0x87DE,[0xEE70]=0x87B2,[0xEE71]=0x8935,[0xEE72]=0x8933,[0xEE73]=0x893C,[0xEE74]=0x893E,[0xEE75]=0x8941,[0xEE76]=0x8952,[0xEE77]=0x8937,[0xEE78]=0x8942,[0xEE79]=0x89AD,[0xEE7A]=0x89AF,[0xEE7B]=0x89AE,[0xEE7C]=0x89F2,[0xEE7D]=0x89F3,[0xEE7E]=0x8B1E,[0xEEA1]=0x8B18,[0xEEA2]=0x8B16,[0xEEA3]=0x8B11,[0xEEA4]=0x8B05,[0xEEA5]=0x8B0B,[0xEEA6]=0x8B22,[0xEEA7]=0x8B0F,[0xEEA8]=0x8B12,[0xEEA9]=0x8B15,[0xEEAA]=0x8B07,[0xEEAB]=0x8B0D,[0xEEAC]=0x8B08,[0xEEAD]=0x8B06,[0xEEAE]=0x8B1C,[0xEEAF]=0x8B13,[0xEEB0]=0x8B1A,[0xEEB1]=0x8C4F,[0xEEB2]=0x8C70,[0xEEB3]=0x8C72,[0xEEB4]=0x8C71,[0xEEB5]=0x8C6F,[0xEEB6]=0x8C95,[0xEEB7]=0x8C94,[0xEEB8]=0x8CF9,[0xEEB9]=0x8D6F,[0xEEBA]=0x8E4E,[0xEEBB]=0x8E4D,[0xEEBC]=0x8E53,[0xEEBD]=0x8E50,[0xEEBE]=0x8E4C,[0xEEBF]=0x8E47,[0xEEC0]=0x8F43,[0xEEC1]=0x8F40,[0xEEC2]=0x9085,[0xEEC3]=0x907E,[0xEEC4]=0x9138,[0xEEC5]=0x919A,[0xEEC6]=0x91A2,[0xEEC7]=0x919B,[0xEEC8]=0x9199,[0xEEC9]=0x919F,[0xEECA]=0x91A1,[0xEECB]=0x919D,[0xEECC]=0x91A0,[0xEECD]=0x93A1,[0xEECE]=0x9383,[0xEECF]=0x93AF,[0xEED0]=0x9364,[0xEED1]=0x9356,[0xEED2]=0x9347,[0xEED3]=0x937C,[0xEED4]=0x9358,[0xEED5]=0x935C,[0xEED6]=0x9376,[0xEED7]=0x9349,[0xEED8]=0x9350,[0xEED9]=0x9351,[0xEEDA]=0x9360,[0xEEDB]=0x936D,[0xEEDC]=0x938F,[0xEEDD]=0x934C,[0xEEDE]=0x936A,[0xEEDF]=0x9379,[0xEEE0]=0x9357,[0xEEE1]=0x9355,[0xEEE2]=0x9352,[0xEEE3]=0x934F,[0xEEE4]=0x9371,[0xEEE5]=0x9377,[0xEEE6]=0x937B,[0xEEE7]=0x9361,[0xEEE8]=0x935E,[0xEEE9]=0x9363,[0xEEEA]=0x9367,[0xEEEB]=0x9380,[0xEEEC]=0x934E,[0xEEED]=0x9359,[0xEEEE]=0x95C7,[0xEEEF]=0x95C0,[0xEEF0]=0x95C9,[0xEEF1]=0x95C3,[0xEEF2]=0x95C5,[0xEEF3]=0x95B7,[0xEEF4]=0x96AE,[0xEEF5]=0x96B0,[0xEEF6]=0x96AC,[0xEEF7]=0x9720,[0xEEF8]=0x971F,[0xEEF9]=0x9718,[0xEEFA]=0x971D,[0xEEFB]=0x9719,[0xEEFC]=0x979A,[0xEEFD]=0x97A1,[0xEEFE]=0x979C,[0xEF40]=0x979E,[0xEF41]=0x979D,[0xEF42]=0x97D5,[0xEF43]=0x97D4,[0xEF44]=0x97F1,[0xEF45]=0x9841,[0xEF46]=0x9844,[0xEF47]=0x984A,[0xEF48]=0x9849,[0xEF49]=0x9845,[0xEF4A]=0x9843,[0xEF4B]=0x9925,[0xEF4C]=0x992B,[0xEF4D]=0x992C,[0xEF4E]=0x992A,[0xEF4F]=0x9933,[0xEF50]=0x9932,[0xEF51]=0x992F,[0xEF52]=0x992D,[0xEF53]=0x9931,[0xEF54]=0x9930,[0xEF55]=0x9998,[0xEF56]=0x99A3,[0xEF57]=0x99A1,[0xEF58]=0x9A02,[0xEF59]=0x99FA,[0xEF5A]=0x99F4,[0xEF5B]=0x99F7,[0xEF5C]=0x99F9,[0xEF5D]=0x99F8,[0xEF5E]=0x99F6,[0xEF5F]=0x99FB,[0xEF60]=0x99FD,[0xEF61]=0x99FE,[0xEF62]=0x99FC,[0xEF63]=0x9A03,[0xEF64]=0x9ABE,[0xEF65]=0x9AFE,[0xEF66]=0x9AFD,[0xEF67]=0x9B01,[0xEF68]=0x9AFC,[0xEF69]=0x9B48,[0xEF6A]=0x9B9A,[0xEF6B]=0x9BA8,[0xEF6C]=0x9B9E,[0xEF6D]=0x9B9B,[0xEF6E]=0x9BA6,[0xEF6F]=0x9BA1,[0xEF70]=0x9BA5,[0xEF71]=0x9B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[0xEFD8]=0x6594,[0xEFD9]=0x65DB,[0xEFDA]=0x66DA,[0xEFDB]=0x66DB,[0xEFDC]=0x66D8,[0xEFDD]=0x6AC5,[0xEFDE]=0x6AB9,[0xEFDF]=0x6ABD,[0xEFE0]=0x6AE1,[0xEFE1]=0x6AC6,[0xEFE2]=0x6ABA,[0xEFE3]=0x6AB6,[0xEFE4]=0x6AB7,[0xEFE5]=0x6AC7,[0xEFE6]=0x6AB4,[0xEFE7]=0x6AAD,[0xEFE8]=0x6B5E,[0xEFE9]=0x6BC9,[0xEFEA]=0x6C0B,[0xEFEB]=0x7007,[0xEFEC]=0x700C,[0xEFED]=0x700D,[0xEFEE]=0x7001,[0xEFEF]=0x7005,[0xEFF0]=0x7014,[0xEFF1]=0x700E,[0xEFF2]=0x6FFF,[0xEFF3]=0x7000,[0xEFF4]=0x6FFB,[0xEFF5]=0x7026,[0xEFF6]=0x6FFC,[0xEFF7]=0x6FF7,[0xEFF8]=0x700A,[0xEFF9]=0x7201,[0xEFFA]=0x71FF,[0xEFFB]=0x71F9,[0xEFFC]=0x7203,[0xEFFD]=0x71FD,[0xEFFE]=0x7376,[0xF040]=0x74B8,[0xF041]=0x74C0,[0xF042]=0x74B5,[0xF043]=0x74C1,[0xF044]=0x74BE,[0xF045]=0x74B6,[0xF046]=0x74BB,[0xF047]=0x74C2,[0xF048]=0x7514,[0xF049]=0x7513,[0xF04A]=0x765C,[0xF04B]=0x7664,[0xF04C]=0x7659,[0xF04D]=0x7650,[0xF04E]=0x7653,[0xF04F]=0x7657,[0xF050]=0x765A,[0xF051]=0x76A6,[0xF052]=0x76BD,[0xF053]=0x76EC,[0xF054]=0x77C2,[0xF055]=0x77BA,[0xF056]=0x78FF,[0xF057]=0x790C,[0xF058]=0x7913,[0xF059]=0x7914,[0xF05A]=0x7909,[0xF05B]=0x7910,[0xF05C]=0x7912,[0xF05D]=0x7911,[0xF05E]=0x79AD,[0xF05F]=0x79AC,[0xF060]=0x7A5F,[0xF061]=0x7C1C,[0xF062]=0x7C29,[0xF063]=0x7C19,[0xF064]=0x7C20,[0xF065]=0x7C1F,[0xF066]=0x7C2D,[0xF067]=0x7C1D,[0xF068]=0x7C26,[0xF069]=0x7C28,[0xF06A]=0x7C22,[0xF06B]=0x7C25,[0xF06C]=0x7C30,[0xF06D]=0x7E5C,[0xF06E]=0x7E50,[0xF06F]=0x7E56,[0xF070]=0x7E63,[0xF071]=0x7E58,[0xF072]=0x7E62,[0xF073]=0x7E5F,[0xF074]=0x7E51,[0xF075]=0x7E60,[0xF076]=0x7E57,[0xF077]=0x7E53,[0xF078]=0x7FB5,[0xF079]=0x7FB3,[0xF07A]=0x7FF7,[0xF07B]=0x7FF8,[0xF07C]=0x8075,[0xF07D]=0x81D1,[0xF07E]=0x81D2,[0xF0A1]=0x81D0,[0xF0A2]=0x825F,[0xF0A3]=0x825E,[0xF0A4]=0x85B4,[0xF0A5]=0x85C6,[0xF0A6]=0x85C0,[0xF0A7]=0x85C3,[0xF0A8]=0x85C2,[0xF0A9]=0x85B3,[0xF0AA]=0x85B5,[0xF0AB]=0x85BD,[0xF0AC]=0x85C7,[0xF0AD]=0x85C4,[0xF0AE]=0x85BF,[0xF0AF]=0x85CB,[0xF0B0]=0x85CE,[0xF0B1]=0x85C8,[0xF0B2]=0x85C5,[0xF0B3]=0x85B1,[0xF0B4]=0x85B6,[0xF0B5]=0x85D2,[0xF0B6]=0x8624,[0xF0B7]=0x85B8,[0xF0B8]=0x85B7,[0xF0B9]=0x85BE,[0xF0BA]=0x8669,[0xF0BB]=0x87E7,[0xF0BC]=0x87E6,[0xF0BD]=0x87E2,[0xF0BE]=0x87DB,[0xF0BF]=0x87EB,[0xF0C0]=0x87EA,[0xF0C1]=0x87E5,[0xF0C2]=0x87DF,[0xF0C3]=0x87F3,[0xF0C4]=0x87E4,[0xF0C5]=0x87D4,[0xF0C6]=0x87DC,[0xF0C7]=0x87D3,[0xF0C8]=0x87ED,[0xF0C9]=0x87D8,[0xF0CA]=0x87E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[0xF152]=0x91AA,[0xF153]=0x93B5,[0xF154]=0x938C,[0xF155]=0x9392,[0xF156]=0x93B7,[0xF157]=0x939B,[0xF158]=0x939D,[0xF159]=0x9389,[0xF15A]=0x93A7,[0xF15B]=0x938E,[0xF15C]=0x93AA,[0xF15D]=0x939E,[0xF15E]=0x93A6,[0xF15F]=0x9395,[0xF160]=0x9388,[0xF161]=0x9399,[0xF162]=0x939F,[0xF163]=0x938D,[0xF164]=0x93B1,[0xF165]=0x9391,[0xF166]=0x93B2,[0xF167]=0x93A4,[0xF168]=0x93A8,[0xF169]=0x93B4,[0xF16A]=0x93A3,[0xF16B]=0x93A5,[0xF16C]=0x95D2,[0xF16D]=0x95D3,[0xF16E]=0x95D1,[0xF16F]=0x96B3,[0xF170]=0x96D7,[0xF171]=0x96DA,[0xF172]=0x5DC2,[0xF173]=0x96DF,[0xF174]=0x96D8,[0xF175]=0x96DD,[0xF176]=0x9723,[0xF177]=0x9722,[0xF178]=0x9725,[0xF179]=0x97AC,[0xF17A]=0x97AE,[0xF17B]=0x97A8,[0xF17C]=0x97AB,[0xF17D]=0x97A4,[0xF17E]=0x97AA,[0xF1A1]=0x97A2,[0xF1A2]=0x97A5,[0xF1A3]=0x97D7,[0xF1A4]=0x97D9,[0xF1A5]=0x97D6,[0xF1A6]=0x97D8,[0xF1A7]=0x97FA,[0xF1A8]=0x9850,[0xF1A9]=0x9851,[0xF1AA]=0x9852,[0xF1AB]=0x98B8,[0xF1AC]=0x9941,[0xF1AD]=0x993C,[0xF1AE]=0x993A,[0xF1AF]=0x9A0F,[0xF1B0]=0x9A0B,[0xF1B1]=0x9A09,[0xF1B2]=0x9A0D,[0xF1B3]=0x9A04,[0xF1B4]=0x9A11,[0xF1B5]=0x9A0A,[0xF1B6]=0x9A05,[0xF1B7]=0x9A07,[0xF1B8]=0x9A06,[0xF1B9]=0x9AC0,[0xF1BA]=0x9ADC,[0xF1BB]=0x9B08,[0xF1BC]=0x9B04,[0xF1BD]=0x9B05,[0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x61FB,[0xF242]=0x6507,[0xF243]=0x6510,[0xF244]=0x650D,[0xF245]=0x6509,[0xF246]=0x650C,[0xF247]=0x650E,[0xF248]=0x6584,[0xF249]=0x65DE,[0xF24A]=0x65DD,[0xF24B]=0x66DE,[0xF24C]=0x6AE7,[0xF24D]=0x6AE0,[0xF24E]=0x6ACC,[0xF24F]=0x6AD1,[0xF250]=0x6AD9,[0xF251]=0x6ACB,[0xF252]=0x6ADF,[0xF253]=0x6ADC,[0xF254]=0x6AD0,[0xF255]=0x6AEB,[0xF256]=0x6ACF,[0xF257]=0x6ACD,[0xF258]=0x6ADE,[0xF259]=0x6B60,[0xF25A]=0x6BB0,[0xF25B]=0x6C0C,[0xF25C]=0x7019,[0xF25D]=0x7027,[0xF25E]=0x7020,[0xF25F]=0x7016,[0xF260]=0x702B,[0xF261]=0x7021,[0xF262]=0x7022,[0xF263]=0x7023,[0xF264]=0x7029,[0xF265]=0x7017,[0xF266]=0x7024,[0xF267]=0x701C,[0xF268]=0x702A,[0xF269]=0x720C,[0xF26A]=0x720A,[0xF26B]=0x7207,[0xF26C]=0x7202,[0xF26D]=0x7205,[0xF26E]=0x72A5,[0xF26F]=0x72A6,[0xF270]=0x72A4,[0xF271]=0x72A3,[0xF272]=0x72A1,[0xF273]=0x74CB,[0xF274]=0x74C5,[0xF275]=0x74B7,[0xF276]=0x74C3,[0xF277]=0x7516,[0xF278]=0x7660,[0xF279]=0x77C9,[0xF27A]=0x77CA,[0xF27B]=0x77C4,[0xF27C]=0x77F1,[0xF27D]=0x791D,[0xF27E]=0x791B,[0xF2A1]=0x7921,[0xF2A2]=0x791C,[0xF2A3]=0x7917,[0xF2A4]=0x791E,[0xF2A5]=0x79B0,[0xF2A6]=0x7A67,[0xF2A7]=0x7A68,[0xF2A8]=0x7C33,[0xF2A9]=0x7C3C,[0xF2AA]=0x7C39,[0xF2AB]=0x7C2C,[0xF2AC]=0x7C3B,[0xF2AD]=0x7CEC,[0xF2AE]=0x7CEA,[0xF2A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89B6,[0xF2F5]=0x89F6,[0xF2F6]=0x8B50,[0xF2F7]=0x8B48,[0xF2F8]=0x8B4A,[0xF2F9]=0x8B40,[0xF2FA]=0x8B53,[0xF2FB]=0x8B56,[0xF2FC]=0x8B54,[0xF2FD]=0x8B4B,[0xF2FE]=0x8B55,[0xF340]=0x8B51,[0xF341]=0x8B42,[0xF342]=0x8B52,[0xF343]=0x8B57,[0xF344]=0x8C43,[0xF345]=0x8C77,[0xF346]=0x8C76,[0xF347]=0x8C9A,[0xF348]=0x8D06,[0xF349]=0x8D07,[0xF34A]=0x8D09,[0xF34B]=0x8DAC,[0xF34C]=0x8DAA,[0xF34D]=0x8DAD,[0xF34E]=0x8DAB,[0xF34F]=0x8E6D,[0xF350]=0x8E78,[0xF351]=0x8E73,[0xF352]=0x8E6A,[0xF353]=0x8E6F,[0xF354]=0x8E7B,[0xF355]=0x8EC2,[0xF356]=0x8F52,[0xF357]=0x8F51,[0xF358]=0x8F4F,[0xF359]=0x8F50,[0xF35A]=0x8F53,[0xF35B]=0x8FB4,[0xF35C]=0x9140,[0xF35D]=0x913F,[0xF35E]=0x91B0,[0xF35F]=0x91AD,[0xF360]=0x93DE,[0xF361]=0x93C7,[0xF362]=0x93CF,[0xF363]=0x93C2,[0xF364]=0x93DA,[0xF365]=0x93D0,[0xF366]=0x93F9,[0xF367]=0x93EC,[0xF368]=0x93CC,[0xF369]=0x93D9,[0xF36A]=0x93A9,[0xF36B]=0x93E6,[0xF36C]=0x93CA,[0xF36D]=0x93D4,[0xF36E]=0x93EE,[0xF36F]=0x93E3,[0xF370]=0x93D5,[0xF371]=0x93C4,[0xF372]=0x93CE,[0xF373]=0x93C0,[0xF374]=0x93D2,[0xF375]=0x93E7,[0xF376]=0x957D,[0xF377]=0x95DA,[0xF378]=0x95DB,[0xF379]=0x96E1,[0xF37A]=0x9729,[0xF37B]=0x972B,[0xF37C]=0x972C,[0xF37D]=0x9728,[0xF37E]=0x9726,[0xF3A1]=0x97B3,[0xF3A2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0xF3E5]=0x9D74,[0xF3E6]=0x9D75,[0xF3E7]=0x9D70,[0xF3E8]=0x9D69,[0xF3E9]=0x9D85,[0xF3EA]=0x9D73,[0xF3EB]=0x9D7B,[0xF3EC]=0x9D82,[0xF3ED]=0x9D6F,[0xF3EE]=0x9D79,[0xF3EF]=0x9D7F,[0xF3F0]=0x9D87,[0xF3F1]=0x9D68,[0xF3F2]=0x9E94,[0xF3F3]=0x9E91,[0xF3F4]=0x9EC0,[0xF3F5]=0x9EFC,[0xF3F6]=0x9F2D,[0xF3F7]=0x9F40,[0xF3F8]=0x9F41,[0xF3F9]=0x9F4D,[0xF3FA]=0x9F56,[0xF3FB]=0x9F57,[0xF3FC]=0x9F58,[0xF3FD]=0x5337,[0xF3FE]=0x56B2,[0xF440]=0x56B5,[0xF441]=0x56B3,[0xF442]=0x58E3,[0xF443]=0x5B45,[0xF444]=0x5DC6,[0xF445]=0x5DC7,[0xF446]=0x5EEE,[0xF447]=0x5EEF,[0xF448]=0x5FC0,[0xF449]=0x5FC1,[0xF44A]=0x61F9,[0xF44B]=0x6517,[0xF44C]=0x6516,[0xF44D]=0x6515,[0xF44E]=0x6513,[0xF44F]=0x65DF,[0xF450]=0x66E8,[0xF451]=0x66E3,[0xF452]=0x66E4,[0xF453]=0x6AF3,[0xF454]=0x6AF0,[0xF455]=0x6AEA,[0xF456]=0x6AE8,[0xF457]=0x6AF9,[0xF458]=0x6AF1,[0xF459]=0x6AEE,[0xF45A]=0x6AEF,[0xF45B]=0x703C,[0xF45C]=0x7035,[0xF45D]=0x702F,[0xF45E]=0x7037,[0xF45F]=0x7034,[0xF460]=0x7031,[0xF461]=0x7042,[0xF462]=0x7038,[0xF463]=0x703F,[0xF464]=0x703A,[0xF465]=0x7039,[0xF466]=0x7040,[0xF467]=0x703B,[0xF468]=0x7033,[0xF469]=0x7041,[0xF46A]=0x7213,[0xF46B]=0x7214,[0xF46C]=0x72A8,[0xF46D]=0x737D,[0xF46E]=0x737C,[0xF46F]=0x74BA,[0xF470]=0x76AB,[0xF471]=0x76AA,[0xF472]=0x76BE,[0xF473]=0x76ED,[0xF474]=0x77CC,[0xF475]=0x77CE,[0xF476]=0x77CF,[0xF477]=0x77CD,[0xF478]=0x77F2,[0xF479]=0x7925,[0xF47A]=0x7923,[0xF47B]=0x7927,[0xF47C]=0x7928,[0xF47D]=0x7924,[0xF47E]=0x7929,[0xF4A1]=0x79B2,[0xF4A2]=0x7A6E,[0xF4A3]=0x7A6C,[0xF4A4]=0x7A6D,[0xF4A5]=0x7AF7,[0xF4A6]=0x7C49,[0xF4A7]=0x7C48,[0xF4A8]=0x7C4A,[0xF4A9]=0x7C47,[0xF4AA]=0x7C45,[0xF4AB]=0x7CEE,[0xF4AC]=0x7E7B,[0xF4AD]=0x7E7E,[0xF4AE]=0x7E81,[0xF4AF]=0x7E80,[0xF4B0]=0x7FBA,[0xF4B1]=0x7FFF,[0xF4B2]=0x8079,[0xF4B3]=0x81DB,[0xF4B4]=0x81D9,[0xF4B5]=0x820B,[0xF4B6]=0x8268,[0xF4B7]=0x8269,[0xF4B8]=0x8622,[0xF4B9]=0x85FF,[0xF4BA]=0x8601,[0xF4BB]=0x85FE,[0xF4BC]=0x861B,[0xF4BD]=0x8600,[0xF4BE]=0x85F6,[0xF4BF]=0x8604,[0xF4C0]=0x8609,[0xF4C1]=0x8605,[0xF4C2]=0x860C,[0xF4C3]=0x85FD,[0xF4C4]=0x8819,[0xF4C5]=0x8810,[0xF4C6]=0x8811,[0xF4C7]=0x8817,[0xF4C8]=0x8813,[0xF4C9]=0x8816,[0xF4CA]=0x8963,[0xF4CB]=0x8966,[0xF4CC]=0x89B9,[0xF4CD]=0x89F7,[0xF4CE]=0x8B60,[0xF4CF]=0x8B6A,[0xF4D0]=0x8B5D,[0xF4D1]=0x8B68,[0xF4D2]=0x8B63,[0xF4D3]=0x8B65,[0xF4D4]=0x8B67,[0xF4D5]=0x8B6D,[0xF4D6]=0x8DAE,[0xF4D7]=0x8E86,[0xF4D8]=0x8E88,[0xF4D9]=0x8E84,[0xF4DA]=0x8F59,[0xF4DB]=0x8F56,[0xF4DC]=0x8F57,[0xF4DD]=0x8F55,[0xF4DE]=0x8F58,[0xF4DF]=0x8F5A,[0xF4E0]=0x908D,[0xF4E1]=0x9143,[0xF4E2]=0x9141,[0xF4E3]=0x91B7,[0xF4E4]=0x91B5,[0xF4E5]=0x91B2,[0xF4E6]=0x91B3,[0xF4E7]=0x940B,[0xF4E8]=0x9413,[0xF4E9]=0x93FB,[0xF4EA]=0x9420,[0xF4EB]=0x940F,[0xF4EC]=0x9414,[0xF4ED]=0x93FE,[0xF4EE]=0x9415,[0xF4EF]=0x9410,[0xF4F0]=0x9428,[0xF4F1]=0x9419,[0xF4F2]=0x940D,[0xF4F3]=0x93F5,[0xF4F4]=0x9400,[0xF4F5]=0x93F7,[0xF4F6]=0x9407,[0xF4F7]=0x940E,[0xF4F8]=0x9416,[0xF4F9]=0x9412,[0xF4FA]=0x93FA,[0xF4FB]=0x9409,[0xF4FC]=0x93F8,[0xF4FD]=0x940A,[0xF4FE]=0x93FF,[0xF540]=0x93FC,[0xF541]=0x940C,[0xF542]=0x93F6,[0xF543]=0x9411,[0xF544]=0x9406,[0xF545]=0x95DE,[0xF546]=0x95E0,[0xF547]=0x95DF,[0xF548]=0x972E,[0xF549]=0x972F,[0xF54A]=0x97B9,[0xF54B]=0x97BB,[0xF54C]=0x97FD,[0xF54D]=0x97FE,[0xF54E]=0x9860,[0xF54F]=0x9862,[0xF550]=0x9863,[0xF551]=0x985F,[0xF552]=0x98C1,[0xF553]=0x98C2,[0xF554]=0x9950,[0xF555]=0x994E,[0xF556]=0x9959,[0xF557]=0x994C,[0xF558]=0x994B,[0xF559]=0x9953,[0xF55A]=0x9A32,[0xF55B]=0x9A34,[0xF55C]=0x9A31,[0xF55D]=0x9A2C,[0xF55E]=0x9A2A,[0xF55F]=0x9A36,[0xF560]=0x9A29,[0xF561]=0x9A2E,[0xF562]=0x9A38,[0xF563]=0x9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DCF,[0xF5CB]=0x5EF1,[0xF5CC]=0x61FD,[0xF5CD]=0x651B,[0xF5CE]=0x6B02,[0xF5CF]=0x6AFC,[0xF5D0]=0x6B03,[0xF5D1]=0x6AF8,[0xF5D2]=0x6B00,[0xF5D3]=0x7043,[0xF5D4]=0x7044,[0xF5D5]=0x704A,[0xF5D6]=0x7048,[0xF5D7]=0x7049,[0xF5D8]=0x7045,[0xF5D9]=0x7046,[0xF5DA]=0x721D,[0xF5DB]=0x721A,[0xF5DC]=0x7219,[0xF5DD]=0x737E,[0xF5DE]=0x7517,[0xF5DF]=0x766A,[0xF5E0]=0x77D0,[0xF5E1]=0x792D,[0xF5E2]=0x7931,[0xF5E3]=0x792F,[0xF5E4]=0x7C54,[0xF5E5]=0x7C53,[0xF5E6]=0x7CF2,[0xF5E7]=0x7E8A,[0xF5E8]=0x7E87,[0xF5E9]=0x7E88,[0xF5EA]=0x7E8B,[0xF5EB]=0x7E86,[0xF5EC]=0x7E8D,[0xF5ED]=0x7F4D,[0xF5EE]=0x7FBB,[0xF5EF]=0x8030,[0xF5F0]=0x81DD,[0xF5F1]=0x8618,[0xF5F2]=0x862A,[0xF5F3]=0x8626,[0xF5F4]=0x861F,[0xF5F5]=0x8623,[0xF5F6]=0x861C,[0xF5F7]=0x8619,[0xF5F8]=0x8627,[0xF5F9]=0x862E,[0xF5FA]=0x8621,[0xF5FB]=0x8620,[0xF5FC]=0x8629,[0xF5FD]=0x861E,[0xF5FE]=0x8625,[0xF640]=0x8829,[0xF641]=0x881D,[0xF642]=0x881B,[0xF643]=0x8820,[0xF644]=0x8824,[0xF645]=0x881C,[0xF646]=0x882B,[0xF647]=0x884A,[0xF648]=0x896D,[0xF649]=0x8969,[0xF64A]=0x896E,[0xF64B]=0x896B,[0xF64C]=0x89FA,[0xF64D]=0x8B79,[0xF64E]=0x8B78,[0xF64F]=0x8B45,[0xF650]=0x8B7A,[0xF651]=0x8B7B,[0xF652]=0x8D10,[0xF653]=0x8D14,[0xF654]=0x8DAF,[0xF655]=0x8E8E,[0xF656]=0x8E8C,[0xF657]=0x8F5E,[0xF658]=0x8F5B,[0xF659]=0x8F5D,[0xF65A]=0x9146,[0xF65B]=0x9144,[0xF65C]=0x9145,[0xF65D]=0x91B9,[0xF65E]=0x943F,[0xF65F]=0x943B,[0xF660]=0x9436,[0xF661]=0x9429,[0xF662]=0x943D,[0xF663]=0x943C,[0xF664]=0x9430,[0xF665]=0x9439,[0xF666]=0x942A,[0xF667]=0x9437,[0xF668]=0x942C,[0xF669]=0x9440,[0xF66A]=0x9431,[0xF66B]=0x95E5,[0xF66C]=0x95E4,[0xF66D]=0x95E3,[0xF66E]=0x9735,[0xF66F]=0x973A,[0xF670]=0x97BF,[0xF671]=0x97E1,[0xF672]=0x9864,[0xF673]=0x98C9,[0xF674]=0x98C6,[0xF675]=0x98C0,[0xF676]=0x9958,[0xF677]=0x9956,[0xF678]=0x9A39,[0xF679]=0x9A3D,[0xF67A]=0x9A46,[0xF67B]=0x9A44,[0xF67C]=0x9A42,[0xF67D]=0x9A41,[0xF67E]=0x9A3A,[0xF6A1]=0x9A3F,[0xF6A2]=0x9ACD,[0xF6A3]=0x9B15,[0xF6A4]=0x9B17,[0xF6A5]=0x9B18,[0xF6A6]=0x9B16,[0xF6A7]=0x9B3A,[0xF6A8]=0x9B52,[0xF6A9]=0x9C2B,[0xF6AA]=0x9C1D,[0xF6AB]=0x9C1C,[0xF6AC]=0x9C2C,[0xF6AD]=0x9C23,[0xF6AE]=0x9C28,[0xF6AF]=0x9C29,[0xF6B0]=0x9C24,[0xF6B1]=0x9C21,[0xF6B2]=0x9DB7,[0xF6B3]=0x9DB6,[0xF6B4]=0x9DBC,[0xF6B5]=0x9DC1,[0xF6B6]=0x9DC7,[0xF6B7]=0x9DCA,[0xF6B8]=0x9DCF,[0xF6B9]=0x9DBE,[0xF6BA]=0x9DC5,[0xF6BB]=0x9DC3,[0xF6BC]=0x9DBB,[0xF6BD]=0x9DB5,[0xF6BE]=0x9DC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0x7F4F,[0xF744]=0x7F87,[0xF745]=0x81DE,[0xF746]=0x826B,[0xF747]=0x8634,[0xF748]=0x8635,[0xF749]=0x8633,[0xF74A]=0x862C,[0xF74B]=0x8632,[0xF74C]=0x8636,[0xF74D]=0x882C,[0xF74E]=0x8828,[0xF74F]=0x8826,[0xF750]=0x882A,[0xF751]=0x8825,[0xF752]=0x8971,[0xF753]=0x89BF,[0xF754]=0x89BE,[0xF755]=0x89FB,[0xF756]=0x8B7E,[0xF757]=0x8B84,[0xF758]=0x8B82,[0xF759]=0x8B86,[0xF75A]=0x8B85,[0xF75B]=0x8B7F,[0xF75C]=0x8D15,[0xF75D]=0x8E95,[0xF75E]=0x8E94,[0xF75F]=0x8E9A,[0xF760]=0x8E92,[0xF761]=0x8E90,[0xF762]=0x8E96,[0xF763]=0x8E97,[0xF764]=0x8F60,[0xF765]=0x8F62,[0xF766]=0x9147,[0xF767]=0x944C,[0xF768]=0x9450,[0xF769]=0x944A,[0xF76A]=0x944B,[0xF76B]=0x944F,[0xF76C]=0x9447,[0xF76D]=0x9445,[0xF76E]=0x9448,[0xF76F]=0x9449,[0xF770]=0x9446,[0xF771]=0x973F,[0xF772]=0x97E3,[0xF773]=0x986A,[0xF774]=0x9869,[0xF775]=0x98CB,[0xF776]=0x9954,[0xF777]=0x995B,[0xF778]=0x9A4E,[0xF779]=0x9A53,[0xF77A]=0x9A54,[0xF77B]=0x9A4C,[0xF77C]=0x9A4F,[0xF77D]=0x9A48,[0xF77E]=0x9A4A,[0xF7A1]=0x9A49,[0xF7A2]=0x9A52,[0xF7A3]=0x9A50,[0xF7A4]=0x9AD0,[0xF7A5]=0x9B19,[0xF7A6]=0x9B2B,[0xF7A7]=0x9B3B,[0xF7A8]=0x9B56,[0xF7A9]=0x9B55,[0xF7AA]=0x9C46,[0xF7AB]=0x9C48,[0xF7AC]=0x9C3F,[0xF7AD]=0x9C44,[0xF7AE]=0x9C39,[0xF7AF]=0x9C33,[0xF7B0]=0x9C41,[0xF7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F5]=0x863B,[0xF7F6]=0x863E,[0xF7F7]=0x8830,[0xF7F8]=0x8832,[0xF7F9]=0x882E,[0xF7FA]=0x8833,[0xF7FB]=0x8976,[0xF7FC]=0x8974,[0xF7FD]=0x8973,[0xF7FE]=0x89FE,[0xF840]=0x8B8C,[0xF841]=0x8B8E,[0xF842]=0x8B8B,[0xF843]=0x8B88,[0xF844]=0x8C45,[0xF845]=0x8D19,[0xF846]=0x8E98,[0xF847]=0x8F64,[0xF848]=0x8F63,[0xF849]=0x91BC,[0xF84A]=0x9462,[0xF84B]=0x9455,[0xF84C]=0x945D,[0xF84D]=0x9457,[0xF84E]=0x945E,[0xF84F]=0x97C4,[0xF850]=0x97C5,[0xF851]=0x9800,[0xF852]=0x9A56,[0xF853]=0x9A59,[0xF854]=0x9B1E,[0xF855]=0x9B1F,[0xF856]=0x9B20,[0xF857]=0x9C52,[0xF858]=0x9C58,[0xF859]=0x9C50,[0xF85A]=0x9C4A,[0xF85B]=0x9C4D,[0xF85C]=0x9C4B,[0xF85D]=0x9C55,[0xF85E]=0x9C59,[0xF85F]=0x9C4C,[0xF860]=0x9C4E,[0xF861]=0x9DFB,[0xF862]=0x9DF7,[0xF863]=0x9DEF,[0xF864]=0x9DE3,[0xF865]=0x9DEB,[0xF866]=0x9DF8,[0xF867]=0x9DE4,[0xF868]=0x9DF6,[0xF869]=0x9DE1,[0xF86A]=0x9DEE,[0xF86B]=0x9DE6,[0xF86C]=0x9DF2,[0xF86D]=0x9DF0,[0xF86E]=0x9DE2,[0xF86F]=0x9DEC,[0xF870]=0x9DF4,[0xF871]=0x9DF3,[0xF872]=0x9DE8,[0xF873]=0x9DED,[0xF874]=0x9EC2,[0xF875]=0x9ED0,[0xF876]=0x9EF2,[0xF877]=0x9EF3,[0xF878]=0x9F06,[0xF879]=0x9F1C,[0xF87A]=0x9F38,[0xF87B]=0x9F37,[0xF87C]=0x9F36,[0xF87D]=0x9F43,[0xF87E]=0x9F4F,[0xF8A1]=0x9F71,[0x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DFD,[0xF8E7]=0x9E04,[0xF8E8]=0x9EA0,[0xF8E9]=0x9F1E,[0xF8EA]=0x9F46,[0xF8EB]=0x9F74,[0xF8EC]=0x9F75,[0xF8ED]=0x9F76,[0xF8EE]=0x56D4,[0xF8EF]=0x652E,[0xF8F0]=0x65B8,[0xF8F1]=0x6B18,[0xF8F2]=0x6B19,[0xF8F3]=0x6B17,[0xF8F4]=0x6B1A,[0xF8F5]=0x7062,[0xF8F6]=0x7226,[0xF8F7]=0x72AA,[0xF8F8]=0x77D8,[0xF8F9]=0x77D9,[0xF8FA]=0x7939,[0xF8FB]=0x7C69,[0xF8FC]=0x7C6B,[0xF8FD]=0x7CF6,[0xF8FE]=0x7E9A,[0xF940]=0x7E98,[0xF941]=0x7E9B,[0xF942]=0x7E99,[0xF943]=0x81E0,[0xF944]=0x81E1,[0xF945]=0x8646,[0xF946]=0x8647,[0xF947]=0x8648,[0xF948]=0x8979,[0xF949]=0x897A,[0xF94A]=0x897C,[0xF94B]=0x897B,[0xF94C]=0x89FF,[0xF94D]=0x8B98,[0xF94E]=0x8B99,[0xF94F]=0x8EA5,[0xF950]=0x8EA4,[0xF951]=0x8EA3,[0xF952]=0x946E,[0xF953]=0x946D,[0xF954]=0x946F,[0xF955]=0x9471,[0xF956]=0x9473,[0xF957]=0x9749,[0xF958]=0x9872,[0xF959]=0x995F,[0xF95A]=0x9C68,[0xF95B]=0x9C6E,[0xF95C]=0x9C6D,[0xF95D]=0x9E0B,[0xF95E]=0x9E0D,[0xF95F]=0x9E10,[0xF960]=0x9E0F,[0xF961]=0x9E12,[0xF962]=0x9E11,[0xF963]=0x9EA1,[0xF964]=0x9EF5,[0xF965]=0x9F09,[0xF966]=0x9F47,[0xF967]=0x9F78,[0xF968]=0x9F7B,[0xF969]=0x9F7A,[0xF96A]=0x9F79,[0xF96B]=0x571E,[0xF96C]=0x7066,[0xF96D]=0x7C6F,[0xF96E]=0x883C,[0xF96F]=0x8DB2,[0xF970]=0x8EA6,[0xF971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58BB,[0xF9DA]=0x6052,[0xF9DB]=0x7CA7,[0xF9DC]=0x5AFA,[0xF9DD]=0x2554,[0xF9DE]=0x2566,[0xF9DF]=0x2557,[0xF9E0]=0x2560,[0xF9E1]=0x256C,[0xF9E2]=0x2563,[0xF9E3]=0x255A,[0xF9E4]=0x2569,[0xF9E5]=0x255D,[0xF9E6]=0x2552,[0xF9E7]=0x2564,[0xF9E8]=0x2555,[0xF9E9]=0x255E,[0xF9EA]=0x256A,[0xF9EB]=0x2561,[0xF9EC]=0x2558,[0xF9ED]=0x2567,[0xF9EE]=0x255B,[0xF9EF]=0x2553,[0xF9F0]=0x2565,[0xF9F1]=0x2556,[0xF9F2]=0x255F,[0xF9F3]=0x256B,[0xF9F4]=0x2562,[0xF9F5]=0x2559,[0xF9F6]=0x2568,[0xF9F7]=0x255C,[0xF9F8]=0x2551,[0xF9F9]=0x2550,[0xF9FA]=0x256D,[0xF9FB]=0x256E,[0xF9FC]=0x2570,[0xF9FD]=0x256F,[0xF9FE]=0x2593}
function K.decodeText(s)
 local out={};local i=1
 while i&lt;=#s do local a=s:byte(i);if a&lt;128 then out[#out+1]=string.char(a);i=i+1 else local b=s:byte(i+1);local cp=b and cp950[a*256+b];out[#out+1]=utf8.char(cp or 0xFFFD);i=i+(b and 2 or 1)end end
 return table.concat(out)
end

K.types={
 officer={off=0x1A78,count=3952,stride=0x268,vt=0xA4F440},
 clan={off=0x95F8,count=147,stride=0x1C78,vt=0xA4FCE0},
 district={off=0x9A90,count=147,stride=0x1B0,vt=0xA4FDC8},
 city={off=0x9F28,count=350,stride=0x2B8,vt=0xA4FAB0},
 cityName={off=0xAA18,count=350,stride=0x38,vt=0xA4FC90},
 agriculture={off=0x131A8,count=350,stride=0x170,vt=0xA56238},
 market={off=0x13C98,count=782,stride=0x130,vt=0xA562E8},
 county={off=0x15508,count=1883,stride=0x170,vt=0xA56298},
 facility={off=0x38AD8,count=17,stride=0xC8,vt=0xA4FD28},
 army={off=0xB508,count=700,stride=0x340,vt=0xA5A290},
 formation={off=0x18FE0,count=700,stride=0x2C8,vt=0xA4F1C8},
 treasure={off=0xD410,count=121,stride=0x70,vt=0xA55EE8},
 ambitionEffect={off=0x20FD0,count=200,stride=0x408,vt=0xA55F78},
 policy={off=0x1A8C0,count=1024,stride=0xC8,vt=0xA55D08},
 ambition={off=0x1A5C0,count=96,stride=0x110,vt=0xA55FC8},
 trait={off=0x11C40,count=200,stride=0xE8,vt=0xA58BF0},
 tactic={off=0x125E8,count=241,stride=0x110,vt=0xA58C38},
 operation={off=0x20ED0,count=32,stride=0x428,vt=0xA560F8}}
function K.base() return getAddressSafe(K.EXE) end
function K.buildMatches()
 local m=K.base();local pe=m and readInteger(m+0x3C)
 return m and pe and readSmallInteger(m)==0x5A4D and readInteger(m+pe)==0x4550
  and readSmallInteger(m+pe+4)==0x8664 and readInteger(m+pe+8)==K.BUILD.ts
  and readInteger(m+pe+0x50)==K.BUILD.size
end
function K.attached() return K.pid~=nil and K.pid==getOpenedProcessID() and K.buildMatches() end
function K.root()
 if not K.attached() then return end
 local m=K.base();local r=readQword(m+0xFE1038)
 if r and readQword(r)==m+0xA563E0 then return r end
end
function K.isType(kind,p)
 local t=K.types[kind];local m=K.base()
 return t and m and p and p&gt;=0x10000 and readQword(p)==m+t.vt or false
end
function K.object(kind,index)
 local t=K.types[kind];local r=K.root()
 if not r or not t or type(index)~='number' or index%1~=0 or index&lt;0 or index&gt;=t.count then return end
 local first=readQword(r+t.off);local p=readQword(r+t.off+index*8)
 if first and p==first+index*t.stride and K.isType(kind,p) then return p end
end
function K.indexOf(kind,p)
 local t=K.types[kind];local r=K.root()
 if not t or not r or not K.isType(kind,p) then return end
 local first=readQword(r+t.off);if not first then return end
 local index=(p-first)/t.stride
 if index%1==0 and K.object(kind,index)==p then return index end
end
function K.objects(kind)
 local out={};local t=K.types[kind];local root=K.root()
 if not t or not root then return out end
 -- Validate one pointer-vector snapshot; callers still validate live write targets.
 local vector=readBytes(root+t.off,t.count*8,true)
 if not vector or #vector~=t.count*8 then return out end
 local function q(index)
  local value=0;for n=7,0,-1 do value=(value&lt;&lt;8)|vector[index*8+n+1]end;return value
 end
 local first=q(0);if first&lt;0x10000 then return out end
 local vt=K.base()+t.vt
 for i=0,t.count-1 do
  local p=q(i)
  if p==first+i*t.stride and readQword(p)==vt then out[#out+1]={id=i,p=p}end
 end
 if K.root()~=root or readQword(root+t.off)~=first then return {} end
 return out
end
function K.scenario()
 local r=K.root();local p=r and readQword(r+0x3A348)
 if p and readQword(p)==K.base()+0xA5A590 then return p end
end
function K.player()
 local s=K.scenario();local p=s and readQword(s+0xB8)
 if K.indexOf('officer',p) then return p end
end
function K.district()
 local p=K.player();local d=p and readQword(p+0xF0)
 if K.indexOf('district',d) then return d end
end
function K.clan()
 local d=K.district();local c=d and readQword(d+0x20)
 if K.indexOf('clan',c) and readQword(c+0xA0)==K.player() then return c end
end
function K.homeCity()
 local lord=K.player();if not lord then return end
 local city
 if readInteger(lord+0x108)==3 then city=readQword(lord+0x100)
 elseif K.nativeCall then city=K.nativeCall('officerResidence','officer',K.indexOf('officer',lord)) end
 if K.indexOf('city',city) then return city end
end
function K.name(kind,p)
 if not K.isType(kind,p) then return '' end
 if kind=='city' then p=K.object('cityName',K.indexOf('city',p));kind='cityName' end
 if not p then return '' end
 local n=readString(p+8,kind=='officer' and 11 or kind=='treasure' and 15 or 13,false) or ''
 if kind=='officer' then n=n..(readString(p+0x13,11,false) or '') end
 return K.decodeText(n)
end
function K.key()
 local root=K.root();if not root then return end
 local m=K.base();local scenario=readQword(root+0x3A348)
 if not scenario or readQword(scenario)~=m+0xA5A590 then return end
 local raw=readQword(scenario+0xB8);local player=raw;local t=K.types.officer
 if not K.isType('officer',player) then player=nil
 else
  local first=readQword(root+t.off);local index=first and (player-first)/t.stride
  if not index or index%1~=0 or index&lt;0 or index&gt;=t.count or readQword(root+t.off+index*8)~=player then player=nil end
 end
 if not player then return end
 if readQword(m+0xFE1038)~=root or readQword(root+0x3A348)~=scenario or readQword(scenario+0xB8)~=raw then return end
 return tostring(K.pid)..':'..tostring(root)..':'..tostring(scenario)..':'..tostring(player)
end
function K.ready()
 if not K.attached() then error(NB.T('Attach to Taishi PK first.','先に大志PKへアタッチしてください。'),0) end
 if not K.clan() then error(NB.T('Load a scenario first.','先にプレイ中のゲームをロードしてください。'),0) end
end

end

do
local sites={
 {0xC1FCD,0x100,'48 89 74 24 18'},
 {0x1043EB,0x100,'41 89 84 90 88 22 00 00'},
 {0x123C10,0x100,'44 8B 81 A8 02 00 00'},
 {0x146DA8,0x100,'01 02 48 8D 52 04'},
 {0x14E33D,0x100,'41 89 84 90 88 22 00 00'},
 {0x164FC5,0x100,'46 89 84 B8 88 22 00 00'},
 {0x16BFF0,0x100,'41 89 84 95 88 22 00 00'},
 {0x16C53D,0x100,'41 89 84 90 88 22 00 00'},
 {0x17C6A4,0x100,'48 8B D1 8B 89 BC 02 00 00'},
 {0x17D39F,0x100,'43 89 84 B5 88 22 00 00'},
 {0x2088EB,0x100,'FE C8 88 83 96 00 00 00'},
 {0x293912,0x100,'8B 00 89 41 54'},
 {0x2A75B2,0x100,'39 BC 24 A0 00 00 00'},
 {0x2A7E00,0x100,'48 8B C4 55 56'},
 {0x2A7EFC,0x100,'89 44 24 44 89 7C 24 38'},
 {0x2A8BBE,0x100,'45 33 C9 45 33 C0'},
 {0x2A8C4E,0x100,'45 33 C9 45 33 C0'},
 {0x2C5D3C,0x100,'40 53 48 83 EC 20'},
 {0x2CEC50,0x100,'45 85 FF 75 1E 83 FA 09'},
 {0x2DCBF4,0x100,'8B 00 89 47 0C'},
 {0x2E6991,0x300,'8B 00 89 41 54'},
 {0x2E69EE,0x500,'8B 00 89 41 54'},
 {0x2EA0CB,0x700,'8B 00 89 41 54'},
 {0x2F009B,0x100,'66 01 83 AE 00 00 00'},
 {0x2F01FD,0x100,'66 01 45 02 66 39 7D 02'},
 {0x2F04B9,0x100,'8B 05 65 53 B5 00'},
 {0x2F26F8,0x100,'E8 FF 8B 1B 00'},
 {0x328F85,0x100,'48 8B 4D 68 48 85 C9'},
 {0x32FF33,0x100,'E8 CC B3 17 00'},
 {0x347CA8,0x100,'48 89 5C 24 08 48 89 6C 24 10'},
 {0x3556D1,0x100,'85 C0 7F 06 44 39 75 68'},
 {0x3558B1,0x100,'85 C0 7F 06 44 39 75 68'},
 {0x367DA8,0x100,'43 8D 0C 80 3B C1'},
 {0x367F70,0x100,'89 8E DC 0D 00 00'},
 {0x36802F,0x300,'89 8E DC 0D 00 00'},
 {0x37D270,0x500,'89 81 DC 0D 00 00'},
 {0x387BA4,0x700,'89 83 DC 0D 00 00'},
 {0x3B0618,0x100,'48 8B C4 55 56'},
 {0x3B1B90,0x100,'41 81 BE 00 02 00 00 00 00 00 80'},
 {0x3B2352,0x900,'89 83 DC 0D 00 00'},
 {0x3BDFDE,0xB00,'89 86 DC 0D 00 00'},
 {0x487BE4,0x100,'48 83 EC 38 81 FA 0D 01 00 00'},
 {0x64D0F3,0xD00,'41 89 8F DC 0D 00 00'},
 {0x6605AD,0x300,'48 8B CB E8 17 BD C6 FF'},
 {0x660AE7,0x100,'44 8B 45 28 33 D2'}
}
local K=NB.K15
local rawAssemble=autoAssemble
local magic='NB15TC01'
local function bytes(hex)
 local t={};for b in hex:gmatch('%x%x')do t[#t+1]=tonumber(b,16)end;return t
end
local function equal(a,b)
 if not a or #a~=#b then return false end
 for i,v in ipairs(b)do if a[i]~=v then return false end end;return true
end
local function read(at,n)return readBytes(at,n,true)end
local function put(at,b)
 assert(writeBytes(at,b)~=false,'Cannot write hook recovery data')
 assert(equal(read(at,#b),b),'Hook recovery write verification failed')
end
local function str(b)local t={};for i,v in ipairs(b)do t[i]=string.char(v)end;return table.concat(t)end
local function hash(q)
 local b=assert(read(q+0x100,0xF00),'Cannot read hook code');local h=2166136261
 for _,v in ipairs(b)do h=((h~v)*16777619)&amp;0xFFFFFFFF end;return h
end
local function asBytes(s)local t={};for i=1,#s do t[i]=s:byte(i)end;return t end
local known={};for _,s in ipairs(sites)do known[s[1]]={offset=s[2],original=bytes(s[3])}end
function K.assemble(script,info,...)
 if info~=nil then return rawAssemble(script,info,...)end
 local disable=script:match('%[DISABLE%](.*)');local patches={}
 if disable then
  for address,hex in disable:gmatch('([%x]+):%s*\n%s*db%s+([%x ]+)')do
   local at=tonumber(address,16);local original=bytes(hex)
   local def=known[at-K.base()]
   assert(def and equal(def.original,original),'Unregistered Taishi hook site')
   patches[#patches+1]={at=at,original=original}
  end
 end
 if #patches==0 then return rawAssemble(script,info,...)end
 local symbol=script:match('alloc%(([%w_]+),4096,')
 assert(symbol,'Hook recovery requires a dedicated allocation')
 local expanded,n=script:gsub('(alloc%([%w_]+,)4096(,)', '%18192%2')
 assert(n==1,'Unexpected hook allocation count')
 local ok,result=rawAssemble(expanded)
 if not ok then return ok,result end
 local saved,why=pcall(function()
  local q=assert(getAddressSafe(symbol),'Hook allocation missing')
  local payload=string.pack('&lt;I4I4I8I8I4I4',getCheatEngineProcessID(),getOpenedProcessID(),K.base(),q,hash(q),#patches)
  for _,p in ipairs(patches)do
   local installed=assert(read(p.at,#p.original));p.installed=installed
   payload=payload..string.pack('&lt;I4I4',p.at-K.base(),#p.original)..str(p.original)..str(installed)
  end
  local blob=magic..string.pack('&lt;I4',#payload)..payload
  assert(#blob&lt;=4096,'Hook recovery record exceeds reserved page')
  put(q+0x1000,asBytes(blob))
 end)
 if not saved then
  local restored=rawAssemble(script,result)
  assert(restored,'Hook metadata failed and rollback failed: '..tostring(why))
  error(why,0)
 end
 return ok,result
end
function K.recoverOrphanedHooks()
 assert(K.buildMatches(),'Unsupported executable for hook recovery')
 local base=K.base();local groups={};local count=0
 for _,s in ipairs(sites)do
  local def=known[s[1]];local actual=assert(read(base+s[1],#def.original))
  if not equal(actual,def.original)then
   assert(actual[1]==0xE9,'Unrecognized code at '..string.format('%X',s[1]))
   local rel=string.unpack('&lt;i4',str(actual):sub(2,5));local q=base+s[1]+5+rel-s[2]
   groups[q]=true
  end
 end
 local processes=getProcessList();local restore={}
 for q in pairs(groups)do
  local header=read(q+0x1000,12)
  assert(header and str(header):sub(1,8)==magic,'An unmanaged hook remains; automatic recovery was refused')
  local size=string.unpack('&lt;I4',str(header),9);assert(size&gt;=32 and size&lt;=4084,'Invalid hook recovery record')
  local payload=str(assert(read(q+0x100C,size)))
  local owner,pid,m,allocation,checksum,n,pos=string.unpack('&lt;I4I4I8I8I4I4',payload)
  assert(pid==getOpenedProcessID() and m==base and allocation==q,'Hook recovery process mismatch')
  assert(not processes[owner] and not processes[tostring(owner)],'Another running CE still owns these hooks')
  assert(n&gt;=1 and n&lt;=16 and hash(q)==checksum,'Hook recovery code verification failed')
  local seen={}
  for i=1,n do
   local rva,length;rva,length,pos=string.unpack('&lt;I4I4',payload,pos)
   local def=known[rva];assert(def and length==#def.original and not seen[rva],'Invalid hook recovery site');seen[rva]=true
   assert(pos+length*2-1&lt;=#payload,'Truncated hook recovery record')
   local original=asBytes(payload:sub(pos,pos+length-1));pos=pos+length
   local installed=asBytes(payload:sub(pos,pos+length-1));pos=pos+length
   assert(equal(original,def.original) and installed[1]==0xE9,'Hook recovery original mismatch')
   local jump=string.unpack('&lt;i4',str(installed),2)
   assert(base+rva+5+jump-def.offset==q,'Hook recovery allocation mismatch')
   assert(equal(read(base+rva,length),installed),'Hook recovery installed bytes changed')
   if rva==0x487BE4 then local state=readInteger(q);assert(state~=1 and state~=2,'A game-thread operation is still pending')end
   restore[#restore+1]={at=base+rva,original=original,installed=installed}
  end
  assert(pos==#payload+1,'Unexpected hook recovery record tail')
 end
 -- Validate every group before any modification. Keep allocations alive for
 -- instructions already executing in a trampoline; the process reclaims them.
 for _,p in ipairs(restore)do assert(equal(read(p.at,#p.installed),p.installed),'Hook changed during recovery')end
 for _,p in ipairs(restore)do put(p.at,p.original);count=count+1 end
 return count
end

end

do
-- x64 Windows ABI: game methods run only on the game's window thread.
local K=NB.K15
K.nativeDefinitions={
 clanHeart={rva=0x2C900C,bytes='48 83 EC 28 48 85 C9 75 07 33 C0 48 83 C4 28 C3',kind='clan',argumentType='clan'},
 covertWorkTick={rva=0x367CB8,bytes='48 89 5C 24 10 48 89 6C 24 18 56 57 41 56 48 83',kind='mission',vt=0xA166A8},
 covertWorkFinish={rva=0x3198C4,bytes='40 53 48 83 EC 20 48 8B 01 48 8B D9 FF 90 98 00',kind='mission',vt=0xA166A8},
 officerRecruitmentCheck={rva=0x2F25DC,bytes='48 89 5C 24 18 48 89 6C 24 20 56 57 41 56 48 83',kind='officer',argumentType='clan'},
 countyPopulation={rva=0x1A4600,bytes='8B 41 48 C3 48 89 5C 24 10 48 89 6C 24 18 48 89',kind='county'},
 countyPopulationAdd={rva=0x3163C8,bytes='4C 8B DC 48 83 EC 28 48 8B 05 BA AF B8 00 48 33',kind='county'},
 cityDrifters={rva=0x2BFC78,bytes='48 89 5C 24 08 57 48 83 EC 20 8B FA 48 8B D9 E8',kind='city'},
 policyPointsSet={rva=0x2E7A94,bytes='48 83 EC 28 48 8B 05 F1 98 BB 00 48 33 C4 48 89',kind='clan'},
 officerTraitAdd={rva=0x2BE700,bytes='48 89 5C 24 08 57 48 83 EC 20 8B FA 48 8B D9 E8',kind='officer'},
 officerTraitSet={rva=0x2E9584,bytes='48 89 5C 24 08 4D 63 D8 48 8B D9 81 FA C7 00 00',kind='officer'},
 officerTraitGet={rva=0x2CA78C,bytes='4C 8B C9 81 FA C7 00 00 00 77 29 8B C2 99 83 E2',kind='officer'},
 officerFaith={rva=0x3D3C74,bytes='8B 81 48 02 00 00 48 C1 E8 05 83 E0 03 C3 CC CC',kind='officer'},
 officerOrigin={rva=0x3D42F4,bytes='8B 81 48 02 00 00 48 C1 E8 07 83 E0 0F C3 CC CC',kind='officer'},
 officerGrade={rva=0x2C55E0,bytes='8B 81 48 02 00 00 48 C1 E8 13 83 E0 07 C3 CC CC',kind='officer'},
 cityWorkDaily={rva=0x2EFFC4,bytes='48 89 5C 24 10 55 56 57 41 54 41 55 41 56 41 57',kind='city'},
 cityRepairDaily={rva=0x2F0444,bytes='48 89 5C 24 08 57 48 83 EC 20 48 8B 81 70 02 00',kind='city'},
 marketIncome={rva=0x3D2884,bytes='B8 00 10 00 00 66 85 81 D4 00 00 00 0F 85 F6 9C',kind='market'},
 marketIncomeLimit={rva=0x3D2A20,bytes='B8 00 10 00 00 66 85 81 D4 00 00 00 0F 85 DA 9B',kind='market'},
 officerExperienceAdd={rva=0x293438,bytes='83 FA 05 7D 74 4C 8B DC 48 83 EC 28 48 8B 05 45',kind='officer'},
 agriculturePopulation={rva=0x341774,bytes='48 89 5C 24 08 45 33 D2 4C 8B D9 45 33 C0 33 D2',kind='agriculture'},
 agricultureFarmland={rva=0x1A4600,bytes='8B 41 48 C3 48 89 5C 24 10 48 89 6C 24 18 48 89',kind='agriculture'},
 agricultureFarmers={rva=0xECB01,bytes='8B 41 40 C3 CC CC CC 48 8B 81 70 02 00 00 33 D2',kind='agriculture'},
 agricultureSoldiers={rva=0x40C2F8,bytes='8B 41 44 C3 8B 41 30 C3 48 8B 81 28 03 00 00 48',kind='agriculture'},
 agricultureAshigaru={rva=0x4110FE,bytes='8B 81 84 00 00 00 C3 0F BE 81 DF 01 00 00 C3 CC',kind='agriculture'},
 agricultureFertility={rva=0x3CE1A8,bytes='0F B7 81 1C 01 00 00 C3 4C 8B DC 53 48 83 EC 60',kind='agriculture'},
 agricultureIrrigation={rva=0x3CBE50,bytes='0F B7 81 1E 01 00 00 C3 4C 8B DC 53 48 83 EC 60',kind='agriculture'},
 armyMoraleGet={rva=0x3D14D4,bytes='48 8B C4 55 57 41 54 41 56 41 57 48 8D 68 A1 48',kind='army'},
 formationMoraleGet={rva=0x3D14D4,bytes='48 8B C4 55 57 41 54 41 56 41 57 48 8D 68 A1 48',kind='formation'},
 clanWarWillAdd={rva=0x387B3C,bytes='48 89 5C 24 10 57 48 83 EC 40 48 8B 05 43 98 B1',kind='clan'},
 districtRiceSet={rva=0x2E6950,bytes='48 83 EC 28 48 8B 05 35 AA BB 00 48 33 C4 48 89',kind='district'},
 districtRiceSubtract={rva=0x2EA084,bytes='48 83 EC 28 48 8B 05 01 73 BB 00 48 33 C4 48 89',kind='district'},
 policySet={rva=0x2E690C,bytes='48 89 7C 24 08 4C 8B C9 81 FA FF 03 00 00 77 2B',kind='clan'},
 policyEffect={rva=0x29C880,bytes='48 89 5C 24 08 44 89 44 24 18 55 56 57 41 54 41',kind='clan'},
 treasureTransfer={rva=0x361D04,bytes='48 89 5C 24 08 48 89 74 24 10 57 48 83 EC 20 48',kind='officer',argumentType='treasure'},
 officerTreasureUpdate={rva=0x2ECBA4,bytes='48 8B C4 48 89 58 08 48 89 68 10 48 89 70 18 57',kind='officer'},
 lordTreasureUpdate={rva=0x2ECA20,bytes='48 8B C4 55 48 8D A8 A8 FD FF FF 48 81 EC 50 03',kind='officer'},
 facilityLevelAdd={rva=0x323954,bytes='48 8B C4 55 56 57 41 54 41 55 41 56 41 57 48 8D',kind='county',guardByte={0x165,1}},
 officerResidence={rva=0x2FAFCC,bytes='48 83 EC 28 80 B9 E8 01 00 00 05 75 2F 48 8B 89',kind='officer'},
 officerLeadership={rva=0xC1AB0,bytes='40 53 48 83 EC 20 48 8B 05 D3 F8 DD 00 48 33 C4',kind='officer'},
 officerLoyalty={rva=0x3CBFA4,bytes='40 53 48 83 EC 20 48 8B D9 E8 36 22 F0 FF 33 D2',kind='officer'},
 cityDurability={rva=0x3D4C38,bytes='48 8B 81 70 02 00 00 33 D2 48 85 C0 74 04 8B 00',kind='city'},
 cityDurabilityMax={rva=0xECB08,bytes='48 8B 81 70 02 00 00 33 D2 48 85 C0 74 04 8B 00',kind='city'},
 agriculturePopularity={rva=0x345BD0,bytes='48 83 EC 28 48 8B 05 B5 B7 B5 00 48 33 C4 48 89',kind='agriculture'}}
function K.nativeBusy()
 local n=K.native;if not n or n.pid~=getOpenedProcessID() then return false end
 local s=readInteger(n.q);return s==1 or s==2
end
function K.installNative()
 if K.native then return end
 K.ready()
 local at=K.base()+0x487BE4
 local symbol=('nb15Native_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=([[
[ENABLE]
assert(%X,48 83 EC 38 81 FA 0D 01 00 00)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
label(cancel)
label(done)
label(guarded)
label(argumentsOK)
label(missionGuard)
label(missionLoop)
label(missionFound)
label(targetValid)
@N@:
dq 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
@N@+100:
cmp edx,83D5
jne original
mov rax,@N@
cmp r8,rax
jne original
push rbx
sub rsp,40
mov rbx,@N@
cmp dword ptr [rbx],1
jne done
mov rax,[%X]
cmp rax,[rbx+40]
jne cancel
test rax,rax
jz cancel
mov rdx,[rax+3A348]
cmp rdx,[rbx+48]
jne cancel
test rdx,rdx
jz cancel
mov rdx,[rdx+B8]
cmp rdx,[rbx+50]
jne cancel
mov rdx,[rbx+58]
cmp rdx,-1
je missionGuard
mov r9,[rbx+60]
mov rcx,[rax+rdx]
test rcx,rcx
jz cancel
add rdx,rax
mov rcx,[rdx+r9*8]
cmp rcx,[rbx+10]
jne cancel
test rcx,rcx
jz cancel
mov rdx,[rcx]
cmp rdx,[rbx+68]
jne cancel
targetValid:
mov rax,[rbx+70]
test rax,rax
jz guarded
movzx edx,byte ptr [rcx+rax]
cmp edx,[rbx+78]
jne cancel
guarded:
mov r10,[rbx+80]
test r10,r10
jz argumentsOK
mov rax,[rbx+40]
add rax,r10
mov r10,[rbx+88]
mov rax,[rax+r10*8]
cmp rax,[rbx+18]
jne cancel
test rax,rax
jz cancel
mov r10,[rax]
cmp r10,[rbx+90]
jne cancel
argumentsOK:
mov dword ptr [rbx],2
mov rdx,[rbx+18]
mov r8,[rbx+20]
mov r9,[rbx+28]
call qword ptr [rbx+8]
mov [rbx+30],rax
mov dword ptr [rbx],3
jmp done
missionGuard:
mov r10,[rax+3A340]
test r10,r10
jz cancel
mov r10,[r10+18]
test r10,r10
jz cancel
mov ecx,[r10]
cmp ecx,[%X]
jae cancel
mov r10,[%X]
test r10,r10
jz cancel
mov r10,[r10+rcx*8]
mov r11,[rbx+10]
mov r9d,1000
missionLoop:
test r10,r10
jz cancel
cmp [r10],r11
je missionFound
mov r10,[r10+8]
dec r9d
jnz missionLoop
jmp cancel
missionFound:
mov rcx,r11
test rcx,rcx
jz cancel
mov rdx,[rbx+60]
cmp edx,[rcx+68]
jne cancel
cmp dword ptr [rcx+60],0
jne cancel
mov rdx,[rcx]
cmp rdx,[rbx+68]
jne cancel
mov rdx,[rcx+30]
test rdx,rdx
jz cancel
mov rdx,[rdx+20]
test rdx,rdx
jz cancel
mov r10,[rbx+50]
mov r10,[r10+F0]
test r10,r10
jz cancel
cmp rdx,[r10+20]
jne cancel
jmp targetValid
cancel:
mov dword ptr [rbx],4
done:
add rsp,40
pop rbx
xor eax,eax
ret
original:
sub rsp,38
cmp edx,10D
jmp %X
%X:
jmp @N@+100
nop 5
[DISABLE]
%X:
db 48 83 EC 38 81 FA 0D 01 00 00
unregistersymbol(@N@)
// Keep code until process exit: completion state is published before the
// dispatcher epilogue, so a timed-out sender must not free an in-flight tail.
]]):format(at,at,K.base()+0xFE1038,K.base()+0x17ACD00,K.base()+0x17ACCD0,at+10,at,at):gsub('@N@',symbol)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.native={q=assert(getAddressSafe(symbol)),script=script,info=info,pid=K.pid,
  buffer=assert(allocateSharedMemoryLocal(symbol..'_local',4096)),site=at}
 K.native.installed=assert(readBytes(at,10,true))
end
function K.nativeCall(name,kind,index,...)
 K.ready();local d=assert(K.nativeDefinitions[name],'Unknown N15 operation')
 assert(d.kind==kind,'N15 operation target mismatch')
 local p=assert(kind=='mission' and K.missionObject(index,d.vt) or K.object(kind,index),'N15 object unavailable')
 local expected={};for b in d.bytes:gmatch('%x%x') do expected[#expected+1]=tonumber(b,16) end
 local actual=readBytes(K.base()+d.rva,#expected,true);assert(actual,'Unreadable N15 method')
 for i,b in ipairs(expected) do assert(actual[i]==b,'N15 method code changed: '..name) end
 K.installNative();assert(not K.nativeBusy(),'Previous N15 operation is pending')
 local n=K.native;local q=n.q;local args={...};assert(#args&lt;=3,'Too many N15 arguments')
 writeQword(q+8,K.base()+d.rva);writeQword(q+0x10,p)
 for i=1,3 do writeQword(q+0x10+i*8,args[i] or 0) end
 writeQword(q+0x40,K.root());writeQword(q+0x48,K.scenario());writeQword(q+0x50,K.player())
 writeQword(q+0x58,kind=='mission' and -1 or K.types[kind].off);writeQword(q+0x60,index)
 writeQword(q+0x68,K.base()+(kind=='mission' and d.vt or K.types[kind].vt))
 writeQword(q+0x70,d.guardByte and d.guardByte[1] or 0);writeInteger(q+0x78,d.guardByte and d.guardByte[2] or 0)
 if d.argumentType then
  local t=assert(K.types[d.argumentType]);local argumentIndex=assert(K.indexOf(d.argumentType,args[1]),'N15 argument object unavailable')
  writeQword(q+0x80,t.off);writeQword(q+0x88,argumentIndex);writeQword(q+0x90,K.base()+t.vt)
 else writeQword(q+0x80,0) end
 writeInteger(q,1)
 local sent=0;local cached=n.window
 local function send(w)
  if getWindowProcessID(w)==K.pid and executeCodeLocalEx('user32.IsWindowVisible',w)~=0 then
   executeCodeLocalEx('user32.SendMessageTimeoutW',w,0x83D5,q,0,2,2000,n.buffer);sent=sent+1
   if readInteger(q)~=1 then n.window=w;return true end
  end
  return false
 end
 if not cached or not send(cached) then
  local w=executeCodeLocalEx('user32.GetTopWindow',0)
  for _=1,10000 do
   if not w or w==0 then break end
   if w~=cached and send(w) then break end
   w=getWindow(w,2)
  end
 end
 local state=readInteger(q)
 assert(state==3,('N15 operation failed (%s; state %s; windows %d)'):format(name,tostring(state),sent))
 return readQword(q+0x30)
end
function K.removeNative()
 local n=K.native;if not n then return end
 assert(not K.nativeBusy(),'Pending N15 operation must retain its dispatcher')
 if n.pid==getOpenedProcessID() and K.buildMatches() then
  local b=readBytes(n.site,10,true);assert(b,'Cannot read N15 dispatcher')
  for i,v in ipairs(n.installed) do assert(b[i]==v,'N15 dispatcher ownership changed') end
  assert((K.assemble or autoAssemble)(n.script,n.info),'Cannot restore N15 dispatcher')
 end
 K.native=nil
end

end

do
local K=NB.K15
K.fields={officer={},city={},district={}}
K.dropdownRecords=K.dropdownRecords or {}
function K.updateLanguage()
 local keep={}
 for _,entry in ipairs(K.dropdownRecords) do
  local row=getAddressList().getMemoryRecordByID(entry.id)
  if row then
   row.DropDownList.Text=NB.T(entry.field.choicesEn,entry.field.choicesJp)
   keep[#keep+1]=entry
  end
 end
 K.dropdownRecords=keep
end
local abilities={{'Leadership','統率'},{'Valor','武勇'},{'Intelligence','知略'},
 {'Domestic affairs','内政'},{'Foreign affairs','外政'}}
for i,n in ipairs(abilities) do
 for _,v in ipairs({{' (base)','（基本値）',0x131+i,1,255,1},
  {' growth','成長値',0x136+i,0,255,1},
  {' limit','上限',0x13B+i,1,255,1},
  {' experience','経験値',0x16E+i*2,0,10000,2}}) do
  K.fields.officer[#K.fields.officer+1]={en=n[1]..v[1],jp=n[2]..v[2],off=v[3],min=v[4],max=v[5],size=v[6]}
 end
end
for _,field in ipairs({
 {en='Birth year',jp='生年',off=0x12C,min=1,max=9999,size=2},
 {en='Appearance year',jp='登場年',off=0x12E,min=1,max=9999,size=2},
 {en='Death year',jp='没年',off=0x130,min=1,max=9999,size=2},
 {en='Required loyalty',jp='必要忠誠',off=0x24C,min=0,max=15,size=1,mask=15}
}) do K.fields.officer[#K.fields.officer+1]=field end
for _,field in ipairs({
 {en='Faith',jp='信仰',off=0x248,min=0,max=3,size=4,mask=3,shift=5,
  choicesEn='0:None\n1:Buddhism\n2:Ikko\n3:Christianity',choicesJp='0:なし\n1:仏教\n2:一向宗\n3:基督教'},
 {en='Origin',jp='出自',off=0x248,min=0,max=7,size=4,mask=15,shift=7,
  choicesEn='0:Samurai\n1:Noble\n2:Monk\n3:Merchant\n4:Pirate\n5:Ninja\n6:Swordsman\n7:Commoner',
  choicesJp='0:武士\n1:高家\n2:僧侶\n3:商人\n4:海賊\n5:忍者\n6:剣豪\n7:庶民'},
 {en='Grade',jp='格付',off=0x248,min=0,max=3,size=4,mask=7,shift=19,
  choicesEn='0:C\n1:B\n2:A\n3:S',choicesJp='0:Ｃ\n1:Ｂ\n2:Ａ\n3:Ｓ'}
}) do K.fields.officer[#K.fields.officer+1]=field end
K.fields.district={
 {en='Money',jp='金銭',off=0x50,min=0,max=10000000,size=4},
 {en='Rice',jp='兵糧',off=0x54,min=0,max=10000000,size=4},
 {en='Guns',jp='鉄砲',off=0x58,min=0,max=9999999,size=4},
 {en='Horses',jp='軍馬',off=0x5C,min=0,max=9999999,size=4}}
function K.selected(kind)
 if kind=='player' then return K.player() end
 return K.object(kind,K.sel[kind])
end
function K.closeEditor(mr)
 local dead={}
 local function collect(parent)
  for i=0,parent.Count-1 do
   local child=parent.Child[i];dead[child.ID]=true;collect(child)
  end
 end
 collect(mr)
 -- Remove nested dynamic records before CE destroys their native objects.
 -- Accessing a destroyed MemoryRecord inside pcall can still crash CE.
 if NB.dyn then
  local keep={};for _,entry in ipairs(NB.dyn) do if not dead[entry.mr.ID] then keep[#keep+1]=entry end end
  NB.dyn=keep
 end
 local keep={};for _,entry in ipairs(K.dropdownRecords) do if not dead[entry.id] then keep[#keep+1]=entry end end
 K.dropdownRecords=keep
 K.editors[mr.ID]=nil;NB.clearChildren(mr)
end
function K.refreshSuffix()
 for _,e in ipairs({{102,'player'},{403,'officer'},{303,'city'}}) do
  local p=K.selected(e[2]);NB.suffix[e[1]]=p and K.name(e[2]=='player' and 'officer' or e[2],p) or NB.T('(not selected)','（未選択）')
 end
 NB.applyLang();K.updateLanguage()
end
function K.editorType(kind,index,field,token,decode,encode)
 K.editorTypeCache=K.editorTypeCache or {}
 local parts={token,kind,tostring(index)}
 for _,key in ipairs({'off','size','min','max','mask','shift','limitOff','floorOff','computed'})do parts[#parts+1]=tostring(field[key])end
 local key=table.concat(parts,'|');local cached=K.editorTypeCache[key]
 if cached then return cached.name end
 K.typeSerial=(K.typeSerial or 0)+1
 local name=('NB15_%X_%X_%d'):format(K.pid,getTickCount(),K.typeSerial)
 local custom=assert(registerCustomTypeLua(name,field.size,decode,encode,false,false),'Custom editor type unavailable')
 pcall(function()custom.InternalOnly=true end)
 K.editorTypeCache[key]={name=name,custom=custom}
 return name
end
function K.addField(parent,kind,index,field)
 local p=assert(K.object(kind,index));local token=K.key();local at=p+field.off
 local function decode(...)
  local b={...};local v=0
  for i=1,field.size do v=v|((b[i] or 0)&lt;&lt;((i-1)*8)) end
  if field.mask then v=(v&gt;&gt;(field.shift or 0))&amp;field.mask end
  return v
 end
 local function encode(value)
  local current=K.object(kind,index)
  -- CE resolves this record's pointer chain again on every write. If a load
  -- replaced the object, return bytes from the new destination, never bytes
  -- from the captured old object (which would copy stale data into a new save).
  if K.key()~=token or current~=p then
   return current and (readBytes(current+field.off,field.size,true) or {}) or {}
  end
  local unchanged=readBytes(at,field.size,true) or {}
  local v=tonumber(value)
  if not v or v~=v or math.abs(v)==math.huge then return unchanged end
  v=math.max(field.min,math.min(field.max,math.floor(v)))
  if field.limitOff then v=math.min(v,assert(readSmallInteger(p+field.limitOff))&amp;0xFFFF) end
  if field.floorOff then v=math.max(v,assert(readSmallInteger(p+field.floorOff))&amp;0xFFFF) end
  if field.mask then
   local raw=0;for i=1,field.size do raw=raw|((unchanged[i] or 0)&lt;&lt;((i-1)*8)) end
   local shift=field.shift or 0;local mask=field.mask&lt;&lt;shift
   v=(raw&amp;(~mask))|((v&amp;field.mask)&lt;&lt;shift)
  end
  local b={};for i=1,field.size do b[i]=(v&gt;&gt;((i-1)*8))&amp;255 end
  return b
 end
 local typeName=K.editorType(kind,index,field,token,decode,encode)
 local row=NB.addRec(parent,field.en,field.jp,K.EXE..'+FE1038',vtCustom)
 row.OffsetCount=2;row.Offset[0]=field.off;row.Offset[1]=K.types[kind].off+index*8
 row.CustomTypeName=typeName
 if field.choicesEn then
  row.DropDownList.Text=NB.T(field.choicesEn,field.choicesJp)
  row.DropDownReadOnly=true;row.DropDownDescriptionOnly=true;row.DisplayAsDropDownListItem=true
  K.dropdownRecords[#K.dropdownRecords+1]={id=row.ID,field=field}
 end
 row.OnActivate=function(_,before)
  if before then return K.key()==token and K.object(kind,index)==p end
  return true
 end
 return row
end
function K.openEditor(mr,kind)
 K.ready();K.closeEditor(mr)
 local p=K.selected(kind)
 if not p then NB.msg('Select an officer/city first.','先に武将・都市を選択してください。');return end
 local target=kind=='player' and 'officer' or kind
 local index=assert(K.indexOf(target,p))
 for _,field in ipairs(K.fields[target]) do K.addField(mr,target,index,field) end
 if kind=='player' then
  local d=assert(K.indexOf('district',K.district()))
  for _,field in ipairs(K.fields.district) do K.addField(mr,'district',d,field) end
 end
 K.editors[mr.ID]={mr=mr,kind=kind};mr.Collapsed=false;K.refreshSuffix()
end
function K.select(kind,index)
 K.ready();assert(K.object(kind,index),'N15 selection unavailable')
 local reopen={}
 for _,e in pairs(K.editors) do if e.kind==kind then reopen[#reopen+1]=e.mr end end
 for _,mr in ipairs(reopen) do K.closeEditor(mr) end
 K.sel[kind]=index
 for _,mr in ipairs(reopen) do K.openEditor(mr,kind) end
 K.refreshSuffix()
end
function K.search(kind)
 K.ready()
 local query=inputQuery(NB.T('Search name','名前を検索'),NB.T('Part of name; blank lists all:','名前の一部を入力。空欄は全件表示：'),'')
 if query==nil then return end
 local ids,names={},{}
 for _,item in ipairs(K.objects(kind)) do
  local name=K.name(kind,item.p)
  if name~='' and name:find(query,1,true) then
   ids[#ids+1]=item.id;names[#names+1]=('%s [ID %d]'):format(name,item.id)
  end
 end
 if #ids==0 then NB.msg('Not found.','見つかりません。');return end
 local n=NB.pick(NB.T('Select result','候補を選択'),names)
 if n then K.select(kind,ids[n]) end
end

end

do
local K=NB.K15
K.types.market={off=0x13C98,count=782,stride=0x130,vt=0xA562E8}
K.fields.market={
 {en='Market income',jp='商圏収益',off=0xD6,min=0,max=10000,size=2,limitOff=0xD8},
 {en='Market income limit',jp='商圏収益上限',off=0xD8,min=0,max=10000,size=2,floorOff=0xD6},
 {en='Investment potential (before modifiers)',jp='投資の上昇余地（補正前）',off=0xDA,min=0,max=10000,size=2}}
K.fields.county={{en='Population',jp='人口',off=0x48,min=0,max=999999,size=4}}
function K.countiesForCity(city)
 if not K.indexOf('city',city) then return {} end
 local result={}
 for _,p in ipairs(K.linkedObjects(readQword(city+0xB8))) do
  local id=K.indexOf('county',p)
  if id and readQword(p+0x28)==city then result[#result+1]={id=id,p=p} end
 end
 return result
end
function K.marketIndex()
 local result={}
 for _,item in ipairs(K.objects('market')) do
  local county=readQword(item.p+0x38)
  if K.indexOf('county',county) and ((readSmallInteger(item.p+0xD4) or 0)&amp;0x1000)==0 then
   local city=readQword(county+0x28)
   if city then result[city]=result[city] or {};result[city][#result[city]+1]=item end
  end
 end
 return result
end
function K.marketsForCity(city,index)
 if not K.indexOf('city',city) then return {} end
 return (index or K.marketIndex())[city] or {}
end
-- All pointer-list reads are bounded and reject cycles before any caller writes.
function K.linkedObjects(handle)
 if not handle or handle&lt;0x10000 then return {} end
 local m=K.base();local index=readInteger(handle)
 local count=readInteger(m+0x17ACD00);local heads=readQword(m+0x17ACCD0)
 if not index or not count or index&gt;=count or not heads or heads&lt;0x10000 then return {} end
 local node=readQword(heads+index*8);local result,seen={},{}
 while node and node~=0 do
  assert(node&gt;=0x10000 and not seen[node] and #result&lt;20000,'N15 object list is invalid')
  seen[node]=true
  local p=readQword(node);assert(p and p&gt;=0x10000,'N15 list item is unreadable')
  result[#result+1]=p;node=readQword(node+8)
 end
 return result
end
function K.agricultureForCity(city)
 if not K.indexOf('city',city) then return end
 for _,p in ipairs(K.linkedObjects(readQword(city+0xC8))) do
  if K.indexOf('agriculture',p) and readQword(p+0x30)==city then return p end
 end
end
K.fields.agriculture={
 {en='Farmers',jp='農民',off=0x40,min=0,max=99999,size=4},
 {en='Farmer soldiers',jp='農兵',off=0x44,min=0,max=99999,size=4},
 {en='Farmland',jp='農地',off=0x48,min=0,max=99999,size=4},
 {en='Ashigaru',jp='足軽',off=0x84,min=0,max=99999,size=4},
 {en='Popularity',jp='民忠',off=0x8A,min=0,max=100,size=2,computed='popularity'},
 {en='Fertility',jp='肥沃度',off=0x11C,min=0,max=100,size=2},
 {en='Irrigation',jp='治水',off=0x11E,min=0,max=100,size=2}}
function K.popularityModifiers(p)
 local bytes=assert(readBytes(p+0xA4,60,true),'Cannot read N15 popularity modifiers')
 local sum=0;for _,b in ipairs(bytes) do sum=sum+(b&gt;=128 and b-256 or b) end
 return sum
end
local add=K.addField
function K.addField(parent,kind,index,field)
 if field.computed~='popularity' then return add(parent,kind,index,field) end
 local p=assert(K.object(kind,index));local at=p+field.off;local token=K.key()
 local typeName=K.editorType(kind,index,field,token,function(a,b)
  local value=a|(b&lt;&lt;8);if value&gt;=32768 then value=value-65536 end
  if K.key()~=token or K.object(kind,index)~=p then return 0 end
  return math.max(0,math.min(100,value+K.popularityModifiers(p)))
 end,function(value)
  local current=K.object(kind,index)
  if K.key()~=token or current~=p then
   return current and (readBytes(current+field.off,2,true) or {0,0}) or {0,0}
  end
  local old=readBytes(at,2,true) or {0,0}
  local v=tonumber(value);if not v or v~=v or math.abs(v)==math.huge then return old end
  v=math.max(0,math.min(100,math.floor(v)))-K.popularityModifiers(p)
  assert(v&gt;=-32768 and v&lt;=32767,'N15 popularity base out of range')
  return {v&amp;255,(v&gt;&gt;8)&amp;255}
 end)
 local row=NB.addRec(parent,field.en,field.jp,K.EXE..'+FE1038',vtCustom)
 row.OffsetCount=2;row.Offset[0]=field.off;row.Offset[1]=K.types[kind].off+index*8
 row.CustomTypeName=typeName
 row.OnActivate=function(_,before) if before then return K.key()==token and K.object(kind,index)==p end;return true end
 return row
end
local open=K.openEditor
function K.openEditor(mr,kind)
 open(mr,kind)
 if kind=='city' then
  local city=K.selected('city');local district=city and readQword(city+8)
  local districtId=K.indexOf('district',district)
  if districtId then
   for _,field in ipairs(K.fields.district) do
    local named={};for key,value in pairs(field) do named[key]=value end
    named.en='District: '..field.en;named.jp='軍団共有：'..field.jp
    K.addField(mr,'district',districtId,named)
   end
  end
  local p=K.agricultureForCity(K.selected('city'))
  if p then
   local index=assert(K.indexOf('agriculture',p))
   for _,field in ipairs(K.fields.agriculture) do K.addField(mr,'agriculture',index,field) end
  end
  for _,item in ipairs(K.marketsForCity(K.selected('city'))) do
   local name=K.name('market',item.p)
   for _,field in ipairs(K.fields.market) do
    local named={};for key,value in pairs(field) do named[key]=value end
    named.en=name..': '..field.en;named.jp=name..'：'..field.jp
    K.addField(mr,'market',item.id,named)
   end
  end
  for _,item in ipairs(K.countiesForCity(K.selected('city'))) do
   local name=K.name('county',item.p)
   local group=NB.addRec(mr,'County: '..name,'郡：'..name,'0',vtDword)
   group.IsGroupHeader=true
   group.Options='[moManualExpandCollapse]'
   for _,field in ipairs(K.fields.county) do K.addField(group,'county',item.id,field) end
   if K.addFacilityEditor then K.addFacilityEditor(group,item,mr) end
   group.Collapsed=true
  end
 end
end

end

do
local K=NB.K15
K.fields.clan={
 {en='War will',jp='戦意',off=0xDDC,min=0,max=10000,size=4},
 {en='Agriculture policy points',jp='農業施策力',off=0xDF4,min=0,max=9999,size=2},
 {en='Commerce policy points',jp='商業施策力',off=0xDF6,min=0,max=9999,size=2},
 {en='Discussion policy points',jp='論議施策力',off=0xDF8,min=0,max=9999,size=2},
 {en='Military policy points',jp='軍事施策力',off=0xDFA,min=0,max=9999,size=2},
 {en='Grand command policy points',jp='大命施策力',off=0xDFC,min=0,max=9999,size=2}}
local open=K.openEditor
function K.openEditor(mr,kind)
 open(mr,kind)
 if kind=='player' then
  local index=assert(K.indexOf('clan',K.clan()))
  for _,field in ipairs(K.fields.clan) do K.addField(mr,'clan',index,field) end
 end
end
function K.availablePolicies()
 local result={}
 for _,item in ipairs(K.objects('policy')) do
  local name=K.name('policy',item.p)
  if name~='' and name~='--' then result[#result+1]=item end
 end
 return result
end
function K.acquireAllPolicies()
 K.ready();local clan=K.clan();local index=assert(K.indexOf('clan',clan));local count=0
 for _,item in ipairs(K.availablePolicies()) do
  if readBytes(clan+0xE40+item.id,1)~=1 then
   -- Native setter invalidates the 512-entry effect cache as in normal play.
   K.nativeCall('policySet','clan',index,item.id,1)
   assert(readBytes(clan+0xE40+item.id,1)==1,'N15 policy acquisition did not apply')
   count=count+1
  end
 end
 NB.msg(('Acquired %d policies.'):format(count),('方策を%d件取得しました。'):format(count))
 return count
end

end

do
local K=NB.K15
function K.ownsOfficer(p)
 if not K.indexOf('officer',p) or readBytes(p+0x1E8,1)~=7 then return false end
 local d=readQword(p+0xF0)
 return K.indexOf('district',d)~=nil and readQword(d+0x20)==K.clan()
end
function K.giveTreasure(officer,treasure)
 K.ready();assert(K.ownsOfficer(officer),'Recipient is no longer in your clan')
 assert(K.indexOf('treasure',treasure),'N15 treasure unavailable')
 local index=assert(K.indexOf('officer',officer))
 K.nativeCall('treasureTransfer','officer',index,treasure,officer)
 assert(readQword(treasure+0x50)==officer,'N15 treasure ownership did not change')
 if officer==K.player() then K.nativeCall('lordTreasureUpdate','officer',index) end
 K.nativeCall('officerTreasureUpdate','officer',index)
end
function K.treasureCategories()
 K.ready();local token=K.key();local all=K.objects('treasure')
 local english={'Tea utensils','Weapons','Horses','Books','Paintings','Incense utensils','Western imports','Chinese imports'}
 local labels={}
 for i=0,7 do
  local p=readQword(K.base()+0xE6B120+i*8)
  local s=p and readString(p,64,false);assert(s,'N15 treasure category is unreadable')
  labels[#labels+1]=NB.T(english[i+1],K.decodeText(s))
 end
 return labels,all,token
end
-- Read bounded chunks instead of resolving the root and object type for
-- every field of every officer. The live recipient is revalidated on grant.
function K.treasureRecipients()
 K.ready();local token=K.key();local root=assert(K.root());local clan=assert(K.clan());local base=K.base()
 local function vector(kind)
  local t=K.types[kind];local b=assert(readBytes(root+t.off,t.count*8,true))
  local function q(i)local v=0;for n=7,0,-1 do v=(v&lt;&lt;8)|b[i+n]end;return v end
  local first=q(1);assert(first&gt;=0x10000,'Invalid treasure recipient vector')
  for i=0,t.count-1 do assert(q(i*8+1)==first+i*t.stride,'Treasure recipient vector changed')end
  return first,t
 end
 local function q(b,off)local v=0;for n=7,0,-1 do v=(v&lt;&lt;8)|b[off+n+1]end;return v end
 local districts={};local first,typ=vector('district')
 for i=0,typ.count-1 do
  local at=first+i*typ.stride;local b=assert(readBytes(at,0x28,true))
  assert(q(b,0)==base+typ.vt,'Invalid recipient district')
  if q(b,0x20)==clan then districts[at]=true end
 end
 first,typ=vector('officer');local officers,names={},{}
 local function text(b,off,n)
  local chars={};for i=1,n do local v=b[off+i];if v==0 then break end;chars[#chars+1]=string.char(v)end
  return table.concat(chars)
 end
 for start=0,typ.count-1,32 do
  local count=math.min(32,typ.count-start);local b=assert(readBytes(first+start*typ.stride,count*typ.stride,true))
  for i=0,count-1 do
   local off=i*typ.stride;assert(q(b,off)==base+typ.vt,'Invalid recipient officer')
   if b[off+0x1E8+1]==7 and districts[q(b,off+0xF0)]then
    local id=start+i;officers[#officers+1]={id=id,p=first+id*typ.stride}
    names[#names+1]=K.decodeText(text(b,off+8,11)..text(b,off+0x13,11))
   end
  end
 end
 assert(K.key()==token,'Game data changed while reading recipients')
 return officers,names
end
function K.closeTreasureWizard()
 if not inMainThread()then synchronize(K.closeTreasureWizard);return end
 if K.treasureLaunchTimer then K.treasureLaunchTimer.destroy();K.treasureLaunchTimer=nil end
 local w=K.treasureWizard
 if w then w.form.close() end
end
function K.openTreasureWizard()
 if not inMainThread()then synchronize(K.openTreasureWizard);return end
 K.ready()
 if K.treasureWizard then K.treasureWizard.form.bringToFront();return end
 local labels,all,token=K.treasureCategories()
 local form=createForm(false);NB.UI.styleForm(form)
 local w={form=form,token=token,page=1,remember={},all=all,categories=labels}
 K.treasureWizard=w
 form.Name='N15TreasureWizard'
 form.ClientWidth=840;form.ClientHeight=620
 form.OnClose=function()
  if w.inGrant then w.cancelRequested=true;return caNone or 0 end
  if w.grantTimer then w.grantTimer.destroy();w.grantTimer=nil end
  if K.treasureWizard==w then K.treasureWizard=nil end
  return caFree
 end
 local hint=createLabel(form);hint.Left=12;hint.Top=12;hint.Width=816;hint.Font.Color=NB.UI.muted
 local picker=NB.UI.createList(form,{top=42,name='TreasureChoices'});local list=picker.list
 w.list=list;w.hint=hint
 local function button(name,caption,left,width)
  local b=createButton(form);b.Name=name;b.Caption=caption;b.Left=left;b.Top=466;b.Width=width;b.Height=32;return b
 end
 local allButton=button('TreasureAll',NB.T('Select shown','表示中を選択'),12,140)
 local clearButton=button('TreasureClear',NB.T('Clear selection','選択解除'),160,116)
 local back=button('TreasureBack',NB.T('Back','戻る'),338,100)
 local nextButton=button('TreasureNext',NB.T('Next','次へ'),446,110)
 nextButton.Default=true
 local cancel=button('TreasureCancel',NB.T('Cancel','キャンセル'),564,124);cancel.Cancel=true
 w.next=nextButton;w.back=back;w.cancel=cancel;w.allButton=allButton;w.clearButton=clearButton
 local function selected()return picker.selected()end
 picker.onSelectionChanged=function(n)if not w.busy then nextButton.Enabled=n&gt;0 end end
 local function layout()
  picker.layout();local width,height=form.ClientWidth,form.ClientHeight;hint.Width=width-24
  back.Left=width-362;nextButton.Left=width-254;cancel.Left=width-136
  for _,b in ipairs({allButton,clearButton,back,nextButton,cancel})do b.Top=height-46 end
 end
 form.OnResize=layout;layout()
 local function show(page,names,remember)
  w.page=page;picker.setRows(names,page==2,remember)
  back.Enabled=page&gt;1;allButton.Visible=page==2;clearButton.Visible=page==2
  form.Caption=page==1 and NB.T('Treasure category','家宝の分類') or page==2 and NB.T('Select treasures','家宝を複数選択') or NB.T('Recipient officer','授与先の武将')
  hint.Caption=page==2 and NB.T('Ctrl / Shift: select multiple treasures','Ctrl / Shiftで複数の家宝を選択できます') or NB.T('Select an entry.','項目を選択してください。')
  nextButton.Caption=page==3 and NB.T('Assign','授与') or NB.T('Next','次へ')
 end
 local function itemPage()
  w.items={};w.itemNames={}
  for _,item in ipairs(w.all)do
   if readInteger(item.p+0x68)==w.category then
    w.items[#w.items+1]=item;w.itemNames[#w.itemNames+1]=K.name('treasure',item.p)
   end
  end
  show(2,w.itemNames,w.remember[w.category])
 end
 local function guard()
  K.ready();assert(K.key()==token,NB.T('Game data changed; reopen the treasure list.','ゲームデータが変わりました。家宝一覧を開き直してください。'))
 end
 local function run(fn)
  if w.busy then return end
  local ok,why=pcall(fn)
  if not ok then hint.Caption=NB.T('Operation failed. See Lua Engine.','処理できませんでした。Lua Engineを確認してください。');NB.msg(tostring(why)) end
 end
 nextButton.OnClick=function()run(function()
  guard();local choices=selected()
  if #choices==0 then hint.Caption=NB.T('Select at least one entry.','項目を1件以上選択してください。');return end
  if w.page==1 then
   w.categoryChoice=choices;w.category=choices[1]-1;itemPage()
  elseif w.page==2 then
   w.remember[w.category]=choices
   if not w.officers then w.officers,w.officerNames=K.treasureRecipients()end
   show(3,w.officerNames,w.recipient)
  else
   w.recipient=choices;local officer=assert(w.officers[choices[1]])
   w.busy=true;nextButton.Enabled=false;back.Enabled=false
   local queue={};for _,i in ipairs(w.remember[w.category])do queue[#queue+1]=assert(w.items[i]).p end
   local done=0;local timer=createTimer(nil,false);w.grantTimer=timer;timer.Interval=25
   timer.OnTimer=function(t)
    t.Enabled=false
    if K.treasureWizard~=w then return end
    w.inGrant=true
    local ok,why=pcall(function()
     guard();K.giveTreasure(officer.p,queue[done+1]);done=done+1
    end)
    w.inGrant=false
    if w.cancelRequested then t.destroy();w.grantTimer=nil;w.busy=false;form.close();return end
    if not ok then
     t.destroy();w.grantTimer=nil;w.busy=false;nextButton.Enabled=true;back.Enabled=true
     hint.Caption=NB.T('Assignment stopped. See Lua Engine.','授与を中断しました。Lua Engineを確認してください。');NB.msg(tostring(why));return
    end
    hint.Caption=NB.T('Assigned: ','授与済み：')..done..' / '..#queue
    if done==#queue then
     t.destroy();w.grantTimer=nil;w.busy=false
     NB.msg(('Assigned %d treasures.'):format(done),('家宝を%d件授与しました。'):format(done));form.close()
    else t.Enabled=true end
   end
   timer.Enabled=true
  end
 end)end
 back.OnClick=function()run(function()
  if w.page==3 then w.recipient=selected();itemPage()
  elseif w.page==2 then w.remember[w.category]=selected();show(1,w.categories,w.categoryChoice)end
 end)end
 allButton.OnClick=picker.selectVisible
 clearButton.OnClick=picker.clearAll
 cancel.OnClick=function()form.close()end
 list.OnDblClick=function()if w.page~=2 then nextButton.OnClick()end end
 show(1,labels);form.show()
end
function K.assignTreasure()
 K.ready()
 if not inMainThread()then synchronize(K.assignTreasure);return end
 if K.treasureWizard then K.treasureWizard.form.bringToFront();return end
 if K.treasureLaunchTimer then return end
 -- AA checkbox execution must return before the interactive wizard opens.
 local timer=createTimer(nil,false);K.treasureLaunchTimer=timer;timer.Interval=1
 timer.OnTimer=function(t)
  t.destroy();K.treasureLaunchTimer=nil
  local ok,why=pcall(K.openTreasureWizard)
  if not ok then K.closeTreasureWizard();NB.msg(tostring(why))end
 end
 timer.Enabled=true
end

end

do
local K=NB.K15
function K.ownCounty(p)
 if not K.indexOf('county',p) then return false end
 local city=readQword(p+0x28)
 if not K.indexOf('city',city) then return false end
 local district=readQword(city+8)
 return K.indexOf('district',district)~=nil and readQword(district+0x20)==K.clan()
end
function K.ownedCitySet()
 local token=K.key();local clan=K.clan();local districts,owned={},{}
 for _,item in ipairs(K.objects('district'))do
  if readQword(item.p+0x20)==clan then districts[item.p]=true end
 end
 for _,item in ipairs(K.objects('city'))do
  if districts[readQword(item.p+8)]then owned[item.p]=true end
 end
 assert(K.key()==token,'City ownership data changed')
 return owned
end
function K.constructionOrders()
 K.ready();local result={}
 for _,item in ipairs(K.objects('county')) do
  if readBytes(item.p+0x165,1)==1 and K.ownCounty(item.p) then
   local facility=readQword(item.p+0x150)
   if K.indexOf('facility',facility) then
    result[#result+1]={id=item.id,p=item.p,facility=facility,
     level=readBytes(item.p+0x164,1),progress=readSmallInteger(item.p+0x160)}
   end
  end
 end
 return result
end
function K.finishConstruction()
 local orders=K.constructionOrders();local finished=0
 for _,order in ipairs(orders) do
  if readBytes(order.p+0x165,1)==1 and K.ownCounty(order.p)
    and readQword(order.p+0x150)==order.facility then
   -- The game's completion path updates levels, effects, worker assignment,
   -- event notifications and the county UI. Do not fake only its progress.
   K.nativeCall('facilityLevelAdd','county',order.id,1,0)
   assert(readBytes(order.p+0x164,1)==order.level+1,'N15 facility level did not advance')
   assert(readBytes(order.p+0x165,1)~=1,'N15 facility is still under construction')
   finished=finished+1
  end
 end
 return finished
end

end

do
local K=NB.K15
function K.makeTroopScript(at,symbol,armyVT,rootSlot,enemyCheck)
 return ([[
[ENABLE]
assert(%X,48 8B C4 55 56 57 41 55 41 57 48)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(done)
label(other)
label(original)
label(moraleDone)
label(siegeDefender)
label(siegeGauge)
label(protect)
@N@:
dd 0 0 0 0 0 0 0 0
@N@+100:
pushfq
push rax
push rcx
push rdx
push r8
push r9
push r10
push r11
sub rsp,88
movdqu [rsp+20],xmm0
movdqu [rsp+30],xmm1
movdqu [rsp+40],xmm2
movdqu [rsp+50],xmm3
movdqu [rsp+60],xmm4
movdqu [rsp+70],xmm5
mov rax,%X
cmp [rcx],rax
jne done
test byte ptr [rcx+200],1
jz done
cmp dword ptr [rcx+18],0
jle done
mov rax,[%X]
test rax,rax
jz done
mov rax,[rax+3A348]
test rax,rax
jz done
mov rax,[rax+B8]
test rax,rax
jz done
mov r9,rax
mov rax,[rax+F0]
test rax,rax
jz done
mov r8,[rax+20]
test r8,r8
jz done
mov rdx,[rcx+8]
test rdx,rdx
jz done
mov rdx,[rdx+20]
test rdx,rdx
jz done
cmp rdx,r8
jne other
cmp dword ptr [@N@],0
jne protect
cmp dword ptr [@N@+8],0
je done
cmp dword ptr [r9+108],4
jne done
cmp [r9+100],rcx
jne done
cmp [r9+110],rcx
jne done
protect:
// +204 is the deployed total. +208 is the farmer-soldier share, calculated
// by native 488760 from the agriculture's farmer/ashigaru ratio.
mov eax,[rcx+204]
test eax,eax
jle done
cmp eax,1869F
ja done
mov [rcx+18],eax
mov dword ptr [rcx+1C],0
// Siege UI uses the side gauge, not the clan's war-will value.
// Keep each own army at its existing morale cap; the shared side gauge uses
// the largest cap of participating armies (matching the native UI divisor).
mov eax,[rcx+2AC]
test eax,eax
jle moraleDone
cmp eax,2710
ja moraleDone
mov [rcx+2A8],eax
mov rdx,[rcx+330]
test rdx,rdx
jz moraleDone
cmp qword ptr [rcx+298],0
je siegeDefender
add rdx,10
jmp siegeGauge
siegeDefender:
add rdx,28
siegeGauge:
cmp [rdx+10],eax
jge moraleDone
mov [rdx+10],eax
moraleDone:
inc dword ptr [@N@+10]
jmp done
other:
cmp dword ptr [@N@+4],0
je done
cmp dword ptr [rcx+1C],0
jle done
mov rcx,rdx
mov rdx,r8
call %X
test eax,eax
jz done
mov r11,[rsp+B0]
mov eax,[r11+18]
mov [r11+1C],eax
inc dword ptr [@N@+14]
done:
movdqu xmm0,[rsp+20]
movdqu xmm1,[rsp+30]
movdqu xmm2,[rsp+40]
movdqu xmm3,[rsp+50]
movdqu xmm4,[rsp+60]
movdqu xmm5,[rsp+70]
add rsp,88
pop r11
pop r10
pop r9
pop r8
pop rdx
pop rcx
pop rax
popfq
original:
mov rax,rsp
push rbp
push rsi
jmp %X
%X:
jmp @N@+100
[DISABLE]
%X:
db 48 8B C4 55 56
unregistersymbol(@N@)
// Retain this small allocation until process exit: an in-flight hook must not
// return into freed code when a feature is disabled while the game is running.
]]):format(at,at,armyVT,rootSlot,enemyCheck,at+5,at,at):gsub('@N@',symbol)
end
function K.installTroopHook()
 if K.troopHook then return end
 K.ready();local m=K.base();local at=m+0x3B0618
 local symbol=('nb15Troops_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeTroopScript(at,symbol,m+0xA5A290,m+0xFE1038,m+0x2F8E50)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.troopHook={q=assert(getAddressSafe(symbol)),script=script,info=info,pid=K.pid,at=at}
 K.troopHook.installed=readBytes(at,5,true)
end
function K.removeTroopHook()
 local h=K.troopHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local b=assert(readBytes(h.at,5,true))
  for i,v in ipairs(h.installed) do assert(b[i]==v,'N15 troop hook ownership changed') end
  writeInteger(h.q,0);writeInteger(h.q+4,0);writeInteger(h.q+8,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'N15 troop hook restoration failed')
 end
 K.troopHook=nil
end
function K.troopFeature(name,on)
 if on then K.installTroopHook() end
 local h=K.troopHook
 if h then writeInteger(h.q+(name=='battleOneHit' and 4 or 0),on and 1 or 0) end
end

end

do
local K=NB.K15
-- Setter, subtraction and signed-add paths all converge on the same 5-byte
-- store. Guard each path so consumption cannot bypass a timer between frames.
K.foodStoreSites={0x293912,0x2E6991,0x2E69EE,0x2EA0CB}
function K.installFoodHook()
 if K.foodHook then return end
 K.ready();local m=K.base()
 local symbol=('nb15Food_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local enable={'[ENABLE]',('alloc(%s,4096,%X)'):format(symbol,m+K.foodStoreSites[1]),
  'registersymbol('..symbol..')',symbol..':','dd 0'}
 local disable={'[DISABLE]'};local installed={}
 for i,rva in ipairs(K.foodStoreSites) do
  local at=m+rva;local code=('%s+%X'):format(symbol,0x100+(i-1)*0x200)
  local original,done='foodOriginal'..i,'foodMax'..i
  enable[#enable+1]=([[
assert(%X,8B 00 89 41 54)
label(%s)
label(%s)
%s:
pushfq
push rax
push r10
push r11
cmp dword ptr [%s],0
je %s
mov rax,%X
cmp [rcx],rax
jne %s
mov r11,[rcx+20]
test r11,r11
jz %s
mov r10,[%X]
test r10,r10
jz %s
mov r10,[r10+3A348]
test r10,r10
jz %s
mov r10,[r10+B8]
test r10,r10
jz %s
mov r10,[r10+F0]
test r10,r10
jz %s
cmp r11,[r10+20]
je %s
%s:
pop r11
pop r10
pop rax
popfq
mov eax,[rax]
mov [rcx+54],eax
jmp %X
%s:
mov dword ptr [rcx+54],989680
pop r11
pop r10
pop rax
popfq
mov eax,989680
jmp %X
%X:
jmp %s
]]):format(at,original,done,code,symbol,original,m+0xA4FDC8,original,original,
   m+0xFE1038,original,original,original,original,done,original,at+5,done,at+5,at,code)
  disable[#disable+1]=('%X:\ndb 8B 00 89 41 54'):format(at)
 end
 disable[#disable+1]='unregistersymbol('..symbol..')'
 local script=table.concat(enable,'\n')..'\n'..table.concat(disable,'\n')
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 for _,rva in ipairs(K.foodStoreSites) do installed[rva]=readBytes(m+rva,5,true) end
 K.foodHook={q=assert(getAddressSafe(symbol)),pid=K.pid,script=script,info=info,installed=installed}
end
function K.removeFoodHook()
 local h=K.foodHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  for rva,expected in pairs(h.installed) do
   local b=assert(readBytes(K.base()+rva,5,true))
   for i,v in ipairs(expected) do assert(b[i]==v,'N15 food hook ownership changed') end
  end
  writeInteger(h.q,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'N15 food hook restoration failed')
 end
 K.foodHook=nil
end
function K.foodFeature(on)
 if on then K.installFoodHook() end
 if K.foodHook then writeInteger(K.foodHook.q,on and 1 or 0) end
end

end

do
local K=NB.K15
K.warWillSites={
 {0x367F70,'rsi','ecx','89 8E DC 0D 00 00'},
 {0x36802F,'rsi','ecx','89 8E DC 0D 00 00'},
 {0x37D270,'rcx','eax','89 81 DC 0D 00 00'},
 {0x387BA4,'rbx','eax','89 83 DC 0D 00 00'},
 {0x3B2352,'rbx','eax','89 83 DC 0D 00 00'},
 {0x3BDFDE,'rsi','eax','89 86 DC 0D 00 00'},
 {0x64D0F3,'r15','ecx','41 89 8F DC 0D 00 00'}}
function K.installWarWillHook()
 if K.warWillHook then return end
 K.ready();local m=K.base()
 local symbol=('nb15Will_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local enable={'[ENABLE]',('alloc(%s,4096,%X)'):format(symbol,m+0x387BA4),
  'registersymbol('..symbol..')',symbol..':','dd 0'}
 local disable={'[DISABLE]'};local installed={}
 for i,s in ipairs(K.warWillSites) do
  local at=m+s[1];local length=0;for _ in s[4]:gmatch('%x%x') do length=length+1 end
  local code=('%s+%X'):format(symbol,0x100+(i-1)*0x200)
  local original,force='willOriginal'..i,'willMax'..i
  enable[#enable+1]=([[
assert(%X,%s)
label(%s)
label(%s)
%s:
pushfq
push rax
push r10
push r11
cmp dword ptr [%s],0
je %s
mov r11,%s
mov rax,%X
cmp [r11],rax
jne %s
mov r10,[%X]
test r10,r10
jz %s
mov r10,[r10+3A348]
test r10,r10
jz %s
mov r10,[r10+B8]
test r10,r10
jz %s
mov r10,[r10+F0]
test r10,r10
jz %s
cmp r11,[r10+20]
je %s
%s:
pop r11
pop r10
pop rax
popfq
mov [%s+DDC],%s
jmp %X
%s:
pop r11
pop r10
pop rax
popfq
mov %s,2710
mov [%s+DDC],%s
jmp %X
%X:
jmp %s
nop %d
]]):format(at,s[4],original,force,code,symbol,original,s[2],m+0xA4FCE0,original,
   m+0xFE1038,original,original,original,original,force,original,s[2],s[3],at+length,
   force,s[3],s[2],s[3],at+length,at,code,length-5)
  disable[#disable+1]=('%X:\ndb %s'):format(at,s[4])
 end
 disable[#disable+1]='unregistersymbol('..symbol..')'
 local script=table.concat(enable,'\n')..'\n'..table.concat(disable,'\n')
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 for _,s in ipairs(K.warWillSites) do
  local n=0;for _ in s[4]:gmatch('%x%x') do n=n+1 end
  installed[s[1]]=readBytes(m+s[1],n,true)
 end
 K.warWillHook={q=assert(getAddressSafe(symbol)),pid=K.pid,script=script,info=info,installed=installed}
end
function K.removeWarWillHook()
 local h=K.warWillHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  for rva,expected in pairs(h.installed) do
   local b=assert(readBytes(K.base()+rva,#expected,true))
   for i,v in ipairs(expected) do assert(b[i]==v,'N15 war-will hook ownership changed') end
  end
  writeInteger(h.q,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'N15 war-will hook restoration failed')
 end
 K.warWillHook=nil
end
function K.warWillFeature(on)
 if on then K.installWarWillHook() end
 if K.warWillHook then writeInteger(K.warWillHook.q,on and 1 or 0) end
end

end

do
local K=NB.K15
function K.installLoyaltyHook()
 if K.loyaltyHook then return end
 K.ready();local m=K.base();local at=m+0xC1FCD
 local symbol=('nb15Loyalty_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=([[
[ENABLE]
assert(%X,48 89 74 24 18 57 48 83 EC 40)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
label(forced)
@N@:
dd 0
@N@+100:
pushfq
push rax
push r10
push r11
cmp dword ptr [@N@],0
je original
test rcx,rcx
jz original
mov rax,%X
cmp [rcx],rax
jne original
cmp byte ptr [rcx+1E8],7
jne original
mov r10,[rcx+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
cmp [r10+A0],rcx
je original
mov r11,[%X]
test r11,r11
jz original
mov r11,[r11+3A348]
test r11,r11
jz original
mov r11,[r11+B8]
test r11,r11
jz original
mov r11,[r11+F0]
test r11,r11
jz original
cmp [r11+20],r10
je forced
original:
pop r11
pop r10
pop rax
popfq
mov [rsp+18],rsi
jmp %X
forced:
pop r11
pop r10
pop rax
popfq
mov eax,14
ret
%X:
jmp @N@+100
[DISABLE]
%X:
db 48 89 74 24 18
unregistersymbol(@N@)
// Retain code until process exit for in-flight calls.
]]):format(at,at,m+0xA4F440,m+0xFE1038,at+5,at,at):gsub('@N@',symbol)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.loyaltyHook={q=assert(getAddressSafe(symbol)),script=script,info=info,pid=K.pid,at=at}
 K.loyaltyHook.installed=assert(readBytes(at,5,true))
end
function K.loyaltyFeature(on)
 if on then K.installLoyaltyHook() end
 if K.loyaltyHook then writeInteger(K.loyaltyHook.q,on and 1 or 0) end
end
function K.removeLoyaltyHook()
 local h=K.loyaltyHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.at,5,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N15 loyalty hook ownership changed') end
  writeInteger(h.q,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 loyalty hook')
 end
 K.loyaltyHook=nil
end

end

do
local K=NB.K15
function K.installSiegeHook()
 if K.siegeHook then return end
 K.ready();local m=K.base();local at=m+0x2DCBF4
 local symbol=('nb15Siege_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=([[
[ENABLE]
assert(%X,8B 00 89 47 0C C7 44 24 20 C2 D6 00 00)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(done)
label(scan)
label(next)
label(hit)
@N@:
dd 0 0 0 0
@N@+100:
mov eax,[rax]
pushfq
push rax
push rcx
push rdx
push r8
push r9
push r10
push r11
cmp dword ptr [@N@],0
je done
mov r10,%X
cmp [r12],r10
jne done
cmp dword ptr [rdi+C],0
jle done
mov r8,[%X]
test r8,r8
jz done
mov r8,[r8+3A348]
test r8,r8
jz done
mov r8,[r8+B8]
test r8,r8
jz done
mov r8,[r8+F0]
test r8,r8
jz done
mov r8,[r8+20]
test r8,r8
jz done
mov r10,[rdi+18]
test r10,r10
jz done
mov edx,[r10]
cmp edx,[%X]
jae done
mov r10,[%X]
test r10,r10
jz done
mov r10,[r10+rdx*8]
mov ecx,40
scan:
test r10,r10
jz done
test ecx,ecx
jz done
dec ecx
mov r11,[r10]
test r11,r11
jz next
mov rdx,%X
cmp [r11],rdx
jne next
test byte ptr [r11+200],1
jz next
mov r11,[r11+8]
test r11,r11
jz next
mov rdx,%X
cmp [r11],rdx
jne next
cmp [r11+20],r8
je hit
next:
mov r10,[r10+8]
jmp scan
hit:
mov esi,[rdi+C]
mov qword ptr [rsp+30],0
inc dword ptr [@N@+8]
done:
pop r11
pop r10
pop r9
pop r8
pop rdx
pop rcx
pop rax
popfq
mov [rdi+C],eax
jmp %X
%X:
jmp @N@+100
[DISABLE]
%X:
db 8B 00 89 47 0C
unregistersymbol(@N@)
// Keep allocation alive until process exit for any in-flight call.
]]):format(at,at,m+0xA4FAB0,m+0xFE1038,m+0x17ACD00,m+0x17ACCD0,
 m+0xA5A290,m+0xA4FDC8,at+5,at,at):gsub('@N@',symbol)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.siegeHook={q=assert(getAddressSafe(symbol)),script=script,info=info,pid=K.pid,at=at}
 K.siegeHook.installed=assert(readBytes(at,5,true))
end
function K.siegeOneHit(on)
 if on then K.installSiegeHook() end
 if K.siegeHook then writeInteger(K.siegeHook.q,on and 1 or 0) end
end
function K.removeSiegeHook()
 local h=K.siegeHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.at,5,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N15 siege hook ownership changed') end
  writeInteger(h.q,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 siege hook')
 end
 K.siegeHook=nil
end

end

do
local K=NB.K15
-- The decisive-battle UI renders friendly/enemy gauges in side order 0/1
-- (native 7D45F0). Keep this separate from the campaign army/siege layout.
-- +288..+298 are three officer pointers; +2A0 is their count (175526),
-- not the soldier count. The count guard excludes empty tactical units.
function K.makeTacticalMoraleScript(at,symbol,rootSlot)
 return ([=[
[ENABLE]
assert(%X,44 8B 81 A8 02 00 00)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
label(scope)
label(protect)
@N@:
dd 0 0 0 0
@N@+100:
pushfq
push rax
push r10
cmp dword ptr [@N@],0
jne scope
cmp dword ptr [@N@+C],0
je original
scope:
mov eax,[rcx+30]
cmp eax,[@N@+4]
jne original
cmp dword ptr [rcx+2A0],0
jle original
cmp dword ptr [rcx+2A0],3
ja original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov rax,r10
mov r10,[r10+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
cmp [rcx+40],r10
jne original
cmp dword ptr [@N@],0
jne protect
cmp [rcx+288],rax
je protect
cmp dword ptr [rcx+2A0],2
jl original
cmp [rcx+290],rax
je protect
cmp dword ptr [rcx+2A0],3
jl original
cmp [rcx+298],rax
jne original
protect:
mov eax,[rcx+2B4]
test eax,eax
jle original
sub eax,[rcx+2A8]
mov edx,eax
inc dword ptr [@N@+8]
original:
pop r10
pop rax
popfq
mov r8d,[rcx+2A8]
jmp %X
%X:
jmp @N@+100
nop 2
[DISABLE]
%X:
db 44 8B 81 A8 02 00 00
unregistersymbol(@N@)
// Keep trampoline memory until process exit for in-flight native calls.
]=]):format(at,at,rootSlot,at+7,at,at):gsub('@N@',symbol)
end
function K.installTacticalMoraleHook()
 if K.tacticalMoraleHook then return end
 K.ready();local at=K.base()+0x123C10
 local symbol=('nb15TacticalMorale_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeTacticalMoraleScript(at,symbol,K.base()+0xFE1038)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.tacticalMoraleHook={q=assert(getAddressSafe(symbol)),at=at,script=script,info=info,pid=K.pid}
 K.tacticalMoraleHook.installed=assert(readBytes(at,7,true))
end
function K.tacticalMoraleFeature(on)
 if on then K.installTacticalMoraleHook() end
 if K.tacticalMoraleHook then writeInteger(K.tacticalMoraleHook.q,on and 1 or 0) end
end
function K.removeTacticalMoraleHook()
 local h=K.tacticalMoraleHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.at,7,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N15 tactical morale hook ownership changed') end
  writeInteger(h.q,0)
  writeInteger(h.q+0xC,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 tactical morale hook')
 end
 K.tacticalMoraleHook=nil
end

end

do
local K=NB.K15
K.tacticalGaugeSites={
 {rva=0x1043EB,bytes='41 89 84 90 88 22 00 00',original='mov [r8+rdx*4+2288],eax',address='r8+rdx*4+2288',source='eax'},
 {rva=0x14E33D,bytes='41 89 84 90 88 22 00 00',original='mov [r8+rdx*4+2288],eax',address='r8+rdx*4+2288',source='eax'},
 {rva=0x164FC5,bytes='46 89 84 B8 88 22 00 00',original='mov [rax+r15*4+2288],r8d',address='rax+r15*4+2288',source='r8d'},
 {rva=0x16BFF0,bytes='41 89 84 95 88 22 00 00',original='mov [r13+rdx*4+2288],eax',address='r13+rdx*4+2288',source='eax'},
 {rva=0x16C53D,bytes='41 89 84 90 88 22 00 00',original='mov [r8+rdx*4+2288],eax',address='r8+rdx*4+2288',source='eax'},
 {rva=0x17D39F,bytes='43 89 84 B5 88 22 00 00',original='mov [r13+r14*4+2288],eax',address='r13+r14*4+2288',source='eax'},
 {rva=0x146DA8,bytes='01 02 48 8D 52 04',original='add dword ptr [rdx],eax\nlea rdx,[rdx+4]',address='rdx-4'}}
function K.makeTacticalGaugeScript(site,at,friendly,symbol)
 local count=0;for _ in site.bytes:gmatch('%x%x') do count=count+1 end
 local script=([=[
[ENABLE]
assert(%X,%s)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(done)
@N@:
dd 0 0 0 0
@N@+100:
%s
pushfq
push r10
push r11
cmp dword ptr [@N@],0
je done
lea r11,[%s]
mov r10,%X
cmp r11,r10
jne done
mov dword ptr [r11],2710
%s
inc dword ptr [@N@+8]
done:
pop r11
pop r10
popfq
jmp %X
%X:
jmp @N@+100
%s
[DISABLE]
%X:
db %s
unregistersymbol(@N@)
// Keep trampoline memory until process exit for in-flight native calls.
]=]):format(at,site.bytes,at,site.original,site.address,friendly,
 site.source and ('mov '..site.source..',2710') or '',at+count,at,
 count&gt;5 and ('nop '..(count-5)) or '',at,site.bytes)
 return script:gsub('@N@',symbol),count
end
function K.installTacticalGaugeHook()
 if K.tacticalGaugeHook then return end
 K.ready();local m=K.base()
 for _,site in ipairs(K.tacticalGaugeSites) do
  local expected={};for b in site.bytes:gmatch('%x%x') do expected[#expected+1]=tonumber(b,16) end
  local actual=assert(readBytes(m+site.rva,#expected,true))
  for i,b in ipairs(expected) do assert(actual[i]==b,'N15 tactical gauge code changed') end
 end
 K.tacticalGaugeHook={pid=K.pid,records={}}
 local ok,err=pcall(function()
  for _,site in ipairs(K.tacticalGaugeSites) do
   local symbol=('nb15TacticalGauge_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
   local script,size=K.makeTacticalGaugeScript(site,m+site.rva,m+0xF817C0+0x2348,symbol)
   local success,info=(K.assemble or autoAssemble)(script);assert(success,tostring(info))
   local h={q=assert(getAddressSafe(symbol)),at=m+site.rva,script=script,info=info,size=size}
   h.installed=assert(readBytes(h.at,size,true))
   table.insert(K.tacticalGaugeHook.records,h)
  end
 end)
 if not ok then pcall(K.removeTacticalGaugeHook);error(err) end
end
function K.tacticalGaugeFeature(on)
 if on then K.installTacticalGaugeHook() end
 if K.tacticalGaugeHook then
  for _,h in ipairs(K.tacticalGaugeHook.records) do writeInteger(h.q,on and 1 or 0) end
 end
end
function K.removeTacticalGaugeHook()
 local all=K.tacticalGaugeHook;if not all then return end
 if all.pid==getOpenedProcessID() and K.buildMatches() then
  for _,h in ipairs(all.records) do
   local actual=assert(readBytes(h.at,h.size,true))
   for i,b in ipairs(h.installed) do assert(actual[i]==b,'N15 tactical gauge hook ownership changed') end
  end
  for _,h in ipairs(all.records) do writeInteger(h.q,0) end
  for _,h in ipairs(all.records) do assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 tactical gauge hook') end
 end
 K.tacticalGaugeHook=nil
end

end

do
local K=NB.K15
-- Change the native per-tick travel budget; path traversal and spatial-index
-- updates remain in 487F60. Never teleport by writing world coordinates.
function K.makeMovementScript(at,symbol,rootSlot,armyVT,districtVT)
 return ([=[
[ENABLE]
assert(%X,41 81 BE 00 02 00 00 00 00 00 80)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 4 0 0
@N@+100:
pushfq
push r10
push r11
cmp dword ptr [@N@],0
je original
test eax,eax
jle original
mov r10,%X
cmp [r14],r10
jne original
test byte ptr [r14+200],1
jz original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
mov r11,%X
cmp [r10],r11
jne original
mov r10,[r10+20]
test r10,r10
jz original
mov r11,[r14+8]
test r11,r11
jz original
push r10
mov r10,%X
cmp [r11],r10
pop r10
jne original
cmp [r11+20],r10
jne original
mov r10d,[@N@+4]
cmp r10d,1
jb original
cmp r10d,A
ja original
imul r10,rax
cmp r10,7FFFFFFF
ja original
mov eax,r10d
inc dword ptr [@N@+8]
original:
pop r11
pop r10
popfq
cmp dword ptr [r14+200],80000000
jmp %X
%X:
jmp @N@+100
nop 6
[DISABLE]
%X:
db 41 81 BE 00 02 00 00 00 00 00 80
unregistersymbol(@N@)
// Retain trampoline memory until process exit for in-flight native calls.
]=]):format(at,at,armyVT,rootSlot,districtVT,districtVT,at+11,at,at):gsub('@N@',symbol)
end
function K.installMovementHook()
 if K.movementHook then return end
 K.ready();local m=K.base();local at=m+0x3B1B90
 local symbol=('nb15Movement_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeMovementScript(at,symbol,m+0xFE1038,m+0xA5A290,m+0xA4FDC8)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.movementHook={q=assert(getAddressSafe(symbol)),at=at,script=script,info=info,pid=K.pid,
  installed=assert(readBytes(at,11,true))}
end
function K.movementFeature(on,multiplier)
 if on then
  multiplier=tonumber(multiplier) or 4
  assert(multiplier%1==0 and multiplier&gt;=1 and multiplier&lt;=10,'N15 movement multiplier must be 1..10')
  K.installMovementHook();writeInteger(K.movementHook.q+4,multiplier)
 end
 if K.movementHook then writeInteger(K.movementHook.q,on and 1 or 0) end
end
function K.removeMovementHook()
 local h=K.movementHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.at,11,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N15 movement hook ownership changed') end
  writeInteger(h.q,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 movement hook')
 end
 K.movementHook=nil
end

end

do
local K=NB.K15
function K.castleParts(city)
 if not K.indexOf('city',city) then return {} end
 local handle=readQword(city+0x270);if not handle or handle==0 then return {} end
 local index=assert(readInteger(handle));local m=K.base()
 local count=assert(readInteger(m+0xEAE7D0));local heads=readQword(m+0xEAE7A0)
 assert(index&gt;=0 and index&lt;count and heads and heads&gt;=0x10000,'N15 castle list unavailable')
 local node=readQword(heads+index*8);local result,seen={},{}
 while node and node~=0 do
  assert(node&gt;=0x10000 and not seen[node] and #result&lt;4096,'N15 castle list is invalid')
  seen[node]=true
  local maximum=assert(readInteger(node+8));local current=assert(readInteger(node+0xC))
  local flags=assert(readSmallInteger(node+0xA4));local kind=assert(readInteger(node+0xA8))
  assert(maximum&gt;=0 and current&gt;=0 and current&lt;=maximum,'N15 castle durability is invalid')
  result[#result+1]={p=node,max=maximum,current=current,flags=flags,kind=kind}
  node=readQword(node+0x118)
 end
 return result
end
function K.installRepairHook()
 if K.repairHook then return end
 K.ready();local m=K.base();local at=m+0x2F04B9
 local symbol=('nb15Repair_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=([=[
[ENABLE]
assert(%X,8B 05 65 53 B5 00)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dq 0 0
@N@+100:
mov eax,[%X]
pushfq
push r10
push r11
cmp dword ptr [@N@],0
je original
cmp rdi,[@N@+8]
jne original
mov r10,%X
cmp [rdi],r10
jne original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
mov r11,[rdi+8]
test r11,r11
jz original
mov r10,[r10+20]
test r10,r10
jz original
cmp [r11+20],r10
jne original
mov eax,ecx
original:
pop r11
pop r10
popfq
jmp %X
%X:
jmp @N@+100
nop
[DISABLE]
%X:
db 8B 05 65 53 B5 00
unregistersymbol(@N@)
// Retain trampoline memory until process exit for in-flight native calls.
]=]):format(at,at,m+0xE45824,m+0xA4FAB0,m+0xFE1038,at+6,at,at):gsub('@N@',symbol)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.repairHook={q=assert(getAddressSafe(symbol)),at=at,script=script,info=info,pid=K.pid,
  installed=assert(readBytes(at,6,true))}
end
function K.removeRepairHook()
 local h=K.repairHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local actual=assert(readBytes(h.at,6,true))
  for i,v in ipairs(h.installed) do assert(actual[i]==v,'N15 repair hook ownership changed') end
  writeInteger(h.q,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 repair hook')
 end
 K.repairHook=nil
end
function K.repairCity(index)
 K.ready();local city=assert(K.object('city',index))
 local d=readQword(city+8)
 assert(K.indexOf('district',d) and readQword(d+0x20)==K.clan(),'Select a player-owned city')
 K.castleParts(city) -- Validate the entire linked structure before native traversal.
 K.installRepairHook();local h=K.repairHook
 writeQword(h.q+8,city);writeInteger(h.q,1)
 local ok,err=pcall(K.nativeCall,'cityRepairDaily','city',index,0,0)
 if not K.nativeBusy() then writeInteger(h.q,0) end
 if not ok then error(err,0) end
 return K.nativeCall('cityDurability','city',index)
end

end

do
local K=NB.K15
K.castleWorkSites={
 {rva=0x2F009B,bytes='66 01 83 AE 00 00 00',progress='[rbx+AE]',original='add word ptr [rbx+AE],ax',size=7},
 {rva=0x2F01FD,bytes='66 01 45 02 66 39 7D 02',progress='[rbp+2]',original='add word ptr [rbp+2],ax\ncmp word ptr [rbp+2],di',size=8}}
function K.makeCastleWorkScript(site,at,symbol,rootSlot,cityVT)
 return ([=[
[ENABLE]
assert(%X,%s)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0 0 0
@N@+100:
pushfq
push r10
push r11
cmp dword ptr [@N@],0
je original
mov r10,%X
cmp [r14],r10
jne original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
mov r11,[r14+8]
test r11,r11
jz original
cmp [r11+20],r10
jne original
mov ax,di
sub ax,word ptr %s
inc dword ptr [@N@+4]
original:
pop r11
pop r10
popfq
%s
jmp %X
%X:
jmp @N@+100
%s
[DISABLE]
%X:
db %s
unregistersymbol(@N@)
// Retain trampoline memory until process exit for in-flight native calls.
]=]):format(at,site.bytes,at,cityVT,rootSlot,site.progress,site.original,at+site.size,at,
 site.size&gt;5 and ('nop '..(site.size-5)) or '',at,site.bytes):gsub('@N@',symbol)
end
function K.installCastleWorkHook()
 if K.castleWorkHook then return end
 K.ready();local m=K.base()
 for _,s in ipairs(K.castleWorkSites) do
  local b=assert(readBytes(m+s.rva,s.size,true));local i=0
  for value in s.bytes:gmatch('%x%x') do i=i+1;assert(b[i]==tonumber(value,16),'N15 castle work code changed') end
 end
 K.castleWorkHook={pid=K.pid,records={}}
 local ok,err=pcall(function()
  for _,s in ipairs(K.castleWorkSites) do
   local symbol=('nb15CastleWork_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
   local at=m+s.rva;local script=K.makeCastleWorkScript(s,at,symbol,m+0xFE1038,m+0xA4FAB0)
   local success,info=(K.assemble or autoAssemble)(script);assert(success,tostring(info))
   local h={q=assert(getAddressSafe(symbol)),at=at,size=s.size,script=script,info=info}
   h.installed=assert(readBytes(at,s.size,true));table.insert(K.castleWorkHook.records,h)
  end
 end)
 if not ok then pcall(K.removeCastleWorkHook);error(err,0) end
end
function K.castleWorkFeature(on)
 if on then K.installCastleWorkHook() end
 if K.castleWorkHook then for _,h in ipairs(K.castleWorkHook.records) do writeInteger(h.q,on and 1 or 0) end end
end
function K.removeCastleWorkHook()
 local all=K.castleWorkHook;if not all then return end
 if all.pid==getOpenedProcessID() and K.buildMatches() then
  for _,h in ipairs(all.records) do
   local b=assert(readBytes(h.at,h.size,true))
   for i,v in ipairs(h.installed) do assert(b[i]==v,'N15 castle work hook ownership changed') end
  end
  for _,h in ipairs(all.records) do writeInteger(h.q,0) end
  for _,h in ipairs(all.records) do assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 castle work hook') end
 end
 K.castleWorkHook=nil
end
function K.castleWorkPending(city)
 for _,part in ipairs(K.castleParts(city)) do
  if (part.flags&amp;0x80)==0 then
   if part.kind==1 then return true end
   if part.kind==2 then
    local definition=readQword(part.p)
    if definition and definition&gt;=0x10000 then
     local n=assert(readSmallInteger(definition+0xE))&amp;0xFFFF
     assert(n&lt;=2,'N15 castle work slot layout changed')
     for i=0,n-1 do if readBytes(part.p+0x48+i*0x30,1)==1 then return true end end
    end
   end
  end
 end
 return false
end
function K.finishCastleWork()
 K.ready();local count=0
 K.castleWorkFeature(true)
 for _,item in ipairs(K.objects('city')) do
  local d=readQword(item.p+8)
  if K.indexOf('district',d) and readQword(d+0x20)==K.clan() and K.castleWorkPending(item.p) then
   K.nativeCall('cityWorkDaily','city',item.id,0,0);count=count+1
  end
 end
 return count
end

end

do
local K=NB.K15
function K.officerHasTrait(officer,id)
 assert(id&gt;=0 and id&lt;200 and id%1==0)
 local bits=assert(readInteger(officer+0x144+(id//32)*4))
 return (bits&amp;(1&lt;&lt;(id%32)))~=0
end
function K.editOfficerTraits(kind)
 K.ready();local p=assert(K.selected(kind),'Select an officer first')
 local index=assert(K.indexOf('officer',p));local token=K.key()
 local categoryChoice,remember={},{}
 while true do
  local chosen,nav=NB.chooseTreasureList(NB.T('Traits and battle skills','特性・戦法'),
   {NB.T('Personal traits','個性・特性'),NB.T('Battle skills','合戦特技・戦法')},false,false,categoryChoice)
  if nav~='next' then return end
  categoryChoice=chosen;local category=chosen[1]
  local items,names,initial={},{},{}
  for _,item in ipairs(K.objects('trait')) do
   if (category==1 and item.id&lt;90) or (category==2 and item.id&gt;=90) then
    local name=K.name('trait',item.p)
    if name~='' then
     items[#items+1]=item;names[#names+1]=name
     if K.officerHasTrait(p,item.id) then initial[#initial+1]=#items end
    end
   end
  end
  local selected,step=NB.chooseTreasureList(NB.T('Select traits to keep','保持する特性を複数選択'),
   names,true,true,remember[category] or initial,NB.T('Apply','適用'))
  remember[category]=selected
  if step=='cancel' then return end
  if step=='next' then
   assert(K.key()==token and K.object('officer',index)==p,'Game data changed; reopen the officer editor')
   local keep={};for _,n in ipairs(selected) do keep[items[n].id]=true end
   for _,item in ipairs(items) do
    if not keep[item.id] and K.officerHasTrait(p,item.id) then
     K.nativeCall('officerTraitSet','officer',index,item.id,0)
    end
   end
   for _,item in ipairs(items) do
    if keep[item.id] then K.nativeCall('officerTraitAdd','officer',index,item.id) end
   end
   return
  end
 end
end
local open=K.openEditor
function K.openEditor(mr,kind)
 open(mr,kind)
 if kind~='player' and kind~='officer' then return end
 local token=K.key();local p=K.selected(kind)
 local row=NB.addRec(mr,'Edit traits and battle skills...','特性・戦法を編集...','0',vtAutoAssembler)
 row.Script='[ENABLE]\n[DISABLE]'
 row.OnActivate=function(_,before)
  if before then
   local ok,err=pcall(function()
    assert(K.key()==token and K.selected(kind)==p,'Game data changed; reopen the officer editor')
    K.editOfficerTraits(kind)
   end)
   if not ok then NB.msg(tostring(err):gsub('^.-:%d+: ','')) end
   return false
  end
  return true
 end
end

end

do
local K=NB.K15
-- Native 1D3A50 applies pending casualties (+2B8), updates strength (+2BC)
-- and its render mirror, records casualties, then enters normal unit cleanup.
-- +2A0 is officer count; it must never be used as soldier strength.
function K.makeTacticalStrengthScript(at,symbol,rootSlot)
 return ([=[
[ENABLE]
assert(%X,48 8B D1 8B 89 BC 02 00 00)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
label(other)
label(protect)
@N@:
dd 0 0 0 0 0
@N@+100:
pushfq
push rax
push r10
cmp dword ptr [rcx+2A0],0
jle original
cmp dword ptr [rcx+2A0],3
ja original
cmp dword ptr [rcx+2BC],0
jle original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov rax,r10
mov r10,[r10+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
cmp [rcx+40],r10
jne other
cmp dword ptr [@N@],0
jne protect
cmp dword ptr [@N@+10],0
je original
cmp [rcx+288],rax
je protect
cmp dword ptr [rcx+2A0],2
jl original
cmp [rcx+290],rax
je protect
cmp dword ptr [rcx+2A0],3
jl original
cmp [rcx+298],rax
jne original
protect:
cmp dword ptr [rcx+30],0
jne original
mov eax,[rcx+2C8]
cmp eax,[rcx+2BC]
jl original
mov [rcx+2BC],eax
mov dword ptr [rcx+2B8],0
inc dword ptr [@N@+8]
jmp original
other:
cmp dword ptr [@N@+4],0
je original
cmp dword ptr [rcx+30],1
jne original
cmp dword ptr [rcx+2B8],0
jle original
mov eax,[rcx+2BC]
mov [rcx+2B8],eax
inc dword ptr [@N@+C]
original:
pop r10
pop rax
popfq
mov rdx,rcx
mov ecx,[rcx+2BC]
jmp %X
%X:
jmp @N@+100
nop 4
[DISABLE]
%X:
db 48 8B D1 8B 89 BC 02 00 00
unregistersymbol(@N@)
// Retain trampoline memory until process exit for in-flight native calls.
]=]):format(at,at,rootSlot,at+9,at,at):gsub('@N@',symbol)
end
function K.installTacticalStrengthHook()
 if K.tacticalStrengthHook then return end
 K.ready();local at=K.base()+0x17C6A4
 local symbol=('nb15TacticalStrength_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeTacticalStrengthScript(at,symbol,K.base()+0xFE1038)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.tacticalStrengthHook={q=assert(getAddressSafe(symbol)),at=at,script=script,info=info,pid=K.pid,
  installed=assert(readBytes(at,9,true))}
end
function K.tacticalStrengthFeature(name,on)
 assert(name=='invincible' or name=='oneHit','Unknown N15 tactical strength feature')
 if on then K.installTacticalStrengthHook() end
 if K.tacticalStrengthHook then writeInteger(K.tacticalStrengthHook.q+(name=='oneHit' and 4 or 0),on and 1 or 0) end
end
function K.removeTacticalStrengthHook()
 local h=K.tacticalStrengthHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.at,9,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N15 tactical strength hook ownership changed') end
  writeInteger(h.q,0);writeInteger(h.q+4,0)
  writeInteger(h.q+0x10,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 tactical strength hook')
 end
 K.tacticalStrengthHook=nil
end

end

do
local K=NB.K15
-- Replace only the recruitment probability comparison. The surrounding native
-- eligibility, family/grudge checks and eventual ownership transfer stay intact.
function K.makeRecruitmentScript(at,symbol,rootSlot,comparison,expected)
 return ([=[
[ENABLE]
assert(%X,%s)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0 0 0
@N@+100:
call %X
pushfq
push r10
cmp dword ptr [@N@],0
je original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
// Native saves the recipient clan at [rsp+38]. RSI holds a probability here.
// Two pushes in this trampoline move that saved argument to [rsp+48].
cmp r10,r14
jne original
mov eax,1
inc dword ptr [@N@+4]
original:
pop r10
popfq
jmp %X
%X:
jmp @N@+100
[DISABLE]
%X:
db %s
unregistersymbol(@N@)
// Retain trampoline memory until process exit for in-flight native calls.
]=]):format(at,expected,at,comparison,rootSlot,at+5,at,at,expected):gsub('@N@',symbol)
end
function K.installRecruitmentHook()
 if K.recruitmentHook then return end
 K.ready();local m=K.base();local at=m+0x2F26F8
 local symbol=('nb15Recruitment_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeRecruitmentScript(at,symbol,m+0xFE1038,m+0x4AB2FC,'E8 FF 8B 1B 00')
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.recruitmentHook={q=assert(getAddressSafe(symbol)),at=at,script=script,info=info,pid=K.pid,
  installed=assert(readBytes(at,5,true))}
end
function K.recruitmentFeature(on)
 if on then K.installRecruitmentHook() end
 if K.recruitmentHook then writeInteger(K.recruitmentHook.q,on and 1 or 0) end
end
function K.removeRecruitmentHook()
 local h=K.recruitmentHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.at,5,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N15 recruitment hook ownership changed') end
  writeInteger(h.q,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 recruitment hook')
 end
 K.recruitmentHook=nil
end

end

do
local K=NB.K15
K.battleHookGroups={
 playerBattle={
  {'troopHook','installTroopHook','removeTroopHook'},
  {'tacticalMoraleHook','installTacticalMoraleHook','removeTacticalMoraleHook'},
  {'tacticalStrengthHook','installTacticalStrengthHook','removeTacticalStrengthHook'}},
 invincible={
  {'troopHook','installTroopHook','removeTroopHook'},
  {'foodHook','installFoodHook','removeFoodHook'},
  {'warWillHook','installWarWillHook','removeWarWillHook'},
  {'tacticalMoraleHook','installTacticalMoraleHook','removeTacticalMoraleHook'},
  {'tacticalStrengthHook','installTacticalStrengthHook','removeTacticalStrengthHook'}},
 oneHit={
  {'troopHook','installTroopHook','removeTroopHook'},
  {'siegeHook','installSiegeHook','removeSiegeHook'},
  {'tacticalStrengthHook','installTacticalStrengthHook','removeTacticalStrengthHook'}}}
function K.prepareBattleFeature(name)
 K.ready();local group=assert(K.battleHookGroups[name],'Unknown N15 battle feature')
 local created={}
 local ok,err=pcall(function()
  for _,entry in ipairs(group) do
   local h=K[entry[1]]
   assert(not h or h.pid==K.pid,'N15 battle hook belongs to a different process')
   if not h then created[#created+1]=entry end
   assert(K[entry[2]],'Missing N15 battle module')()
  end
 end)
 if not ok then
  local errors={}
  for i=#created,1,-1 do
   local entry=created[i]
   if K[entry[1]] then
    local restored,why=pcall(K[entry[3]])
    if not restored then errors[#errors+1]=tostring(why) end
   end
  end
  if #errors&gt;0 then error(tostring(err)..'; rollback: '..table.concat(errors,'; '),0) end
  error(err,0)
 end
 return created
end
function K.invincibleFeature(on)
 if on then K.prepareBattleFeature('invincible') end
 K.troopFeature('invincible',on)
 K.foodFeature(on);K.warWillFeature(on)
 K.tacticalMoraleFeature(on);K.tacticalStrengthFeature('invincible',on)
 K.on.battleInvincible=on or nil
end
function K.oneHitFeature(on)
 if on then K.prepareBattleFeature('oneHit') end
 K.troopFeature('battleOneHit',on)
 K.siegeOneHit(on);K.tacticalStrengthFeature('oneHit',on)
 K.on.battleOneHit=on or nil
end
function K.playerBattleFeature(on)
 if on then K.prepareBattleFeature('playerBattle') end
 for _,entry in ipairs({{'troopHook',8},{'tacticalMoraleHook',0xC},{'tacticalStrengthHook',0x10}}) do
  local h=K[entry[1]];if h then writeInteger(h.q+entry[2],on and 1 or 0) end
 end
 K.on.playerBattle=on or nil
end

end

do
local K=NB.K15
-- Keep the native opinion update, target test, reports and command cleanup.
-- Change only the amount applied at the goodwill update call site.
function K.makeGoodwillScript(at,symbol,rootSlot)
 return ([=[
[ENABLE]
assert(%X,44 8B 45 28 33 D2)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
label(deltaOK)
@N@:
dd 0 0 0 0
@N@+100:
mov r8d,[rbp+28]
push r10
cmp dword ptr [@N@],0
je original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
cmp r10,r15
jne original
// EBX is the native current opinion, [original rsp+58] is the chosen goal.
// Only this one push changes that stack offset to 60.
mov r8d,[rsp+68]
sub r8d,ebx
jge deltaOK
xor r8d,r8d
deltaOK:
// Positive progress lets the native target-reached branch finish the mission,
// even if its goal had already been reached before this update.
mov dword ptr [rbp+28],1
inc dword ptr [@N@+4]
original:
pop r10
xor edx,edx
jmp %X
%X:
jmp @N@+100
nop
[DISABLE]
%X:
db 44 8B 45 28 33 D2
unregistersymbol(@N@)
// Keep allocation alive until process exit for in-flight calls.
]=]):format(at,at,rootSlot,at+6,at,at):gsub('@N@',symbol)
end
function K.installGoodwillHook()
 if K.goodwillHook then return end
 K.ready();local m=K.base();local at=m+0x660AE7
 local symbol=('nb15Goodwill_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeGoodwillScript(at,symbol,m+0xFE1038)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.goodwillHook={q=assert(getAddressSafe(symbol)),at=at,script=script,info=info,pid=K.pid,
  installed=assert(readBytes(at,6,true))}
end
function K.goodwillFeature(on)
 if on then K.installGoodwillHook() end
 if K.goodwillHook then writeInteger(K.goodwillHook.q,on and 1 or 0) end
end
function K.removeGoodwillHook()
 local h=K.goodwillHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.at,6,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N15 goodwill hook ownership changed') end
  writeInteger(h.q,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 goodwill hook')
 end
 K.goodwillHook=nil
end

end

do
local K=NB.K15
-- The native goodwill callback runs through the guarded asynchronous request.
-- Limit that invocation to one player command; ordinary monthly processing
-- retains its original command iteration.
function K.makeGoodwillScheduleScript(filter,symbol,rootSlot,callback,validation,skip,filterBytes)
 return ([=[
[ENABLE]
assert(%X,%s)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(filterOriginal)
label(filterSkip)
@N@:
// enabled, forced-callback flag, queue command, ID, root, scenario, player, clan
dq 0 0 0 0 0 0 0 0
@N@+300:
cmp dword ptr [@N@+8],0
je filterOriginal
cmp dword ptr [@N@],0
je filterSkip
cmp rbx,[@N@+10]
jne filterSkip
push r10
mov r10,[%X]
cmp r10,[@N@+20]
jne @N@+500
test r10,r10
jz @N@+500
mov r10,[r10+3A348]
cmp r10,[@N@+28]
jne @N@+500
test r10,r10
jz @N@+500
mov r10,[r10+B8]
cmp r10,[@N@+30]
jne @N@+500
test r10,r10
jz @N@+500
mov r10,[r10+F0]
test r10,r10
jz @N@+500
mov r10,[r10+20]
cmp r10,[@N@+38]
jne @N@+500
test r10,r10
jz @N@+500
mov r10,[rbx+30]
test r10,r10
jz @N@+500
mov r10,[r10+20]
cmp r10,[@N@+38]
jne @N@+500
mov r10,[@N@+18]
cmp r10d,[rbx+68]
jne @N@+500
cmp dword ptr [rbx+60],0
jne @N@+500
pop r10
filterOriginal:
mov rcx,rbx
call %X
jmp %X
@N@+500:
pop r10
filterSkip:
jmp %X
%X:
jmp @N@+300
nop 3
@N@+600:
// RCX is the guarded player clan, not an event-manager object. The native
// goodwill callback ignores this argument.
sub rsp,28
mov dword ptr [@N@+8],1
inc dword ptr [@N@+44]
call %X
mov qword ptr [@N@+10],0
mov dword ptr [@N@+8],0
add rsp,28
ret
[DISABLE]
%X:
db %s
unregistersymbol(@N@)
// Keep allocation until process exit for in-flight game callbacks.
]=]):format(filter,filterBytes,filter,rootSlot,
 validation,filter+8,skip,filter,callback,filter,filterBytes):gsub('@N@',symbol)
end
function K.installGoodwillScheduleHook()
 if K.goodwillScheduleHook then return end
 K.ready();local m=K.base();local filter=m+0x6605AD
 local symbol=('nb15GoodwillSchedule_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeGoodwillScheduleScript(filter,symbol,m+0xFE1038,
  m+0x6604B0,m+0x2CC2CC,m+0x6611A6,'48 8B CB E8 17 BD C6 FF')
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.goodwillScheduleHook={q=assert(getAddressSafe(symbol)),script=script,info=info,pid=K.pid,
  sites={{at=filter,bytes=assert(readBytes(filter,8,true))}}}
end
function K.goodwillOrders()
 K.ready();local root=K.root();local manager=readQword(root+0x3A340)
 local handle=manager and readQword(manager+0x18)
 local index=handle and readInteger(handle)
 local m=K.base();local count=readInteger(m+0x17ACD00)
 if not index or not count or index&lt;0 or index&gt;=count then return {} end
 local heads=readQword(m+0x17ACCD0);local node=heads and readQword(heads+index*8)
 local result,seen={},{};local clan=K.clan()
 for _=1,4096 do
  if not node or node==0 then return result end
  assert(not seen[node],'N15 command list contains a cycle');seen[node]=true
  local p=readQword(node)
  if p and readQword(p)==m+0xA15608 and readInteger(p+0x60)==0 and readInteger(p+0x68)~=-1 then
   local d=readQword(p+0x30)
   if K.indexOf('district',d) and readQword(d+0x20)==clan then
    result[#result+1]={p=p,id=readInteger(p+0x68),target=readBytes(p+0x88,1),goal=readSmallInteger(p+0x8A)}
   end
  end
  node=readQword(node+8)
 end
 error('N15 command list exceeded its bound',0)
end
function K.refreshGoodwillQueue()
 if K.pollGoodwillEvent and not K.pollGoodwillEvent() then return end
 local h=K.goodwillScheduleHook
 if not h or h.pid~=getOpenedProcessID() or readInteger(h.q)~=1 or readInteger(h.q+8)~=0 then return end
 if not K.attached() or not K.clan() then writeQword(h.q+0x10,0);return end
 if K.nativeBusy() then return end
 local orders=K.goodwillOrders();local first;local q=h.q
 local attempted=K.goodwillAttempted or {};K.goodwillAttempted=attempted
 for _,item in ipairs(orders) do
  item.key=K.key()..':'..item.id..':'..readInteger(item.p+0x70)..':'..item.target..':'..item.goal
  if not attempted[item.key] then first=item;break end
 end
 -- Publish the pointer last; the game's event thread sees complete guards.
 writeQword(q+0x10,0)
 if not first then return end
 writeQword(q+0x18,first.id);writeQword(q+0x20,K.root());writeQword(q+0x28,K.scenario())
 writeQword(q+0x30,K.player());writeQword(q+0x38,K.clan());writeQword(q+0x10,first.p)
 K.goodwillLast=first
 if K.postGoodwillEvent then K.postGoodwillEvent() end
end
function K.removeGoodwillScheduleHook()
 local h=K.goodwillScheduleHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  assert(readInteger(h.q+8)==0,'N15 goodwill callback is still running')
  for _,site in ipairs(h.sites) do
   local actual=assert(readBytes(site.at,#site.bytes,true))
   for i,v in ipairs(site.bytes) do assert(actual[i]==v,'N15 goodwill schedule hook ownership changed') end
  end
  writeInteger(h.q,0);writeQword(h.q+0x10,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 goodwill schedule hook')
 end
 K.goodwillScheduleHook=nil
end
function K.goodwillInstantFeature(on)
 if not on then
  if K.goodwillScheduleHook then writeInteger(K.goodwillScheduleHook.q,0) end
  K.goodwillFeature(false)
  if K.goodwillPending and K.native and readInteger(K.native.q)==1 then writeInteger(K.native.q,4) end
  if K.pollGoodwillEvent then K.pollGoodwillEvent() end
  if not K.goodwillPending and K.goodwillTimer then K.goodwillTimer.destroy();K.goodwillTimer=nil end
  return
 end
 K.ready()
 if not K.goodwillTimer then K.goodwillAttempted={} end
 local hadGain=K.goodwillHook~=nil
 local ok,why=pcall(function()
  K.installGoodwillHook();K.installGoodwillScheduleHook()
 end)
 if not ok then
  if not hadGain and K.goodwillHook then K.removeGoodwillHook() end
  error(why,0)
 end
 K.goodwillFeature(true);writeInteger(K.goodwillScheduleHook.q,1)
 K.refreshGoodwillQueue()
 if K.goodwillTimer then return end
 local timer=createTimer(nil,false);K.goodwillTimer=timer;timer.Interval=500
 timer.OnTimer=function(t)
  if K.pid~=getOpenedProcessID() then t.Enabled=false;return end
  local success,reason=pcall(K.refreshGoodwillQueue)
  if not success then
   t.Enabled=false
   if K.goodwillScheduleHook then writeInteger(K.goodwillScheduleHook.q,0) end
   K.goodwillFeature(false)
   if K.reportFeatureFailure then K.reportFeatureFailure('goodwill',reason) else NB.msg(tostring(reason)) end
  end
  if K.goodwillScheduleHook and readInteger(K.goodwillScheduleHook.q)==0 and not K.goodwillPending then
   t.destroy();K.goodwillTimer=nil
  end
 end
 timer.Enabled=true
end
function K.removeGoodwillInstant()
 K.goodwillInstantFeature(false)
 K.removeGoodwillScheduleHook();K.removeGoodwillHook()
end

end

do
local K=NB.K15
-- Post a guarded request to the existing window-thread dispatcher. Never wait
-- synchronously for a game callback which may display an in-game report.
function K.pollGoodwillEvent()
 local pending=K.goodwillPending;if not pending then return true end
 if pending.pid~=getOpenedProcessID() then return false end
 local state=readInteger(pending.q)
 if state==1 or state==2 then return false end
 assert(state==3 or state==4,'N15 goodwill request state is unreadable')
 K.goodwillPending=nil
 if pending.record then pending.record.requestState=state end
 if K.native and K.native.q==pending.q then K.removeNative() end
 return true
end
function K.postGoodwillEvent()
 local h=K.goodwillScheduleHook
 if not h or K.goodwillPending or K.nativeBusy() or readInteger(h.q)~=1 or readQword(h.q+0x10)==0 then return end
 K.ready();assert(h.pid==K.pid,'N15 goodwill queue belongs to a different process')
 local code=assert(readBytes(h.q+0x600,4,true))
 assert(code[1]==0x48 and code[2]==0x83 and code[3]==0xEC and code[4]==0x28,'N15 goodwill callback entry changed')
 local clan=assert(K.clan());local id=assert(K.indexOf('clan',clan))
 K.installNative();assert(not K.nativeBusy(),'N15 native request is pending')
 local n=K.native;local q=n.q
 writeQword(q+8,h.q+0x600);writeQword(q+0x10,clan)
 writeQword(q+0x18,0);writeQword(q+0x20,0);writeQword(q+0x28,0)
 writeQword(q+0x40,K.root());writeQword(q+0x48,K.scenario());writeQword(q+0x50,K.player())
 writeQword(q+0x58,K.types.clan.off);writeQword(q+0x60,id);writeQword(q+0x68,K.base()+K.types.clan.vt)
 writeQword(q+0x70,0);writeInteger(q+0x78,0);writeQword(q+0x80,0)
 local w=executeCodeLocalEx('user32.GetTopWindow',0);local selected
 for _=1,10000 do
  if not w or w==0 then break end
  if getWindowProcessID(w)==K.pid and executeCodeLocalEx('user32.IsWindowVisible',w)~=0 then selected=w;break end
  w=getWindow(w,2)
 end
 assert(selected,'N15 game window is unavailable')
 local record=K.goodwillLast
 if record and record.p==readQword(h.q+0x10) then
  K.goodwillAttempted=K.goodwillAttempted or {};K.goodwillAttempted[record.key]=true
 else record=nil end
 K.goodwillPending={q=q,pid=K.pid,command=readQword(h.q+0x10),id=readQword(h.q+0x18),record=record}
 writeInteger(q,1)
 local posted=executeCodeLocalEx('user32.PostMessageW',selected,0x83D5,q,0)
 if not posted or posted==0 then
  writeInteger(q,4);K.pollGoodwillEvent();error('N15 goodwill request could not be posted',0)
 end
end

end

do
local K=NB.K15
function K.missionObjects(vtable)
 K.ready();local r=K.root();local manager=readQword(r+0x3A340)
 local result={};local clan=K.clan();local m=K.base()
 for _,p in ipairs(K.linkedObjects(manager and readQword(manager+0x18))) do
  local vt=readQword(p)
  if (not vtable or vt==m+vtable) and readInteger(p+0x60)==0 then
   local id=readInteger(p+0x68);local district=readQword(p+0x30)
   if id and id&lt;0xA41 and id&gt;=0 and K.indexOf('district',district) and readQword(district+0x20)==clan then
    result[#result+1]={p=p,id=id,vt=vt-m,district=district}
   end
  end
 end
 return result
end
function K.missionObject(id,vtable)
 if type(id)~='number' or id%1~=0 then return end
 for _,item in ipairs(K.missionObjects(vtable)) do if item.id==id then return item.p end end
end

end

do
local K=NB.K15
-- Reports may remain open for user input. Publish one guarded request and
-- return immediately; never mistake a visible report for a failed operation.
function K.postMissionOperation(name,id)
 K.ready();assert(not K.nativeBusy(),'A native operation is pending')
 local d=assert(K.nativeDefinitions[name]);assert(d.kind=='mission')
 local p=assert(K.missionObject(id,d.vt),'Mission unavailable')
 local expected={};for b in d.bytes:gmatch('%x%x') do expected[#expected+1]=tonumber(b,16) end
 local actual=assert(readBytes(K.base()+d.rva,#expected,true))
 for i,b in ipairs(expected) do assert(actual[i]==b,'Mission method changed') end
 local w=executeCodeLocalEx('user32.GetTopWindow',0);local selected
 for _=1,10000 do
  if not w or w==0 then break end
  if getWindowProcessID(w)==K.pid and executeCodeLocalEx('user32.IsWindowVisible',w)~=0 then selected=w;break end
  w=getWindow(w,2)
 end
 assert(selected,'Game window unavailable')
 K.installNative();local q=K.native.q
 writeQword(q+8,K.base()+d.rva);writeQword(q+0x10,p)
 writeQword(q+0x18,0);writeQword(q+0x20,0);writeQword(q+0x28,0)
 writeQword(q+0x40,K.root());writeQword(q+0x48,K.scenario());writeQword(q+0x50,K.player())
 writeQword(q+0x58,-1);writeQword(q+0x60,id);writeQword(q+0x68,K.base()+d.vt)
 writeQword(q+0x70,0);writeInteger(q+0x78,0);writeQword(q+0x80,0)
 writeInteger(q,1)
 local posted=executeCodeLocalEx('user32.PostMessageW',selected,0x83D5,q,0)
 if not posted or posted==0 then writeInteger(q,4);error('Mission request could not be posted',0) end
 return {q=q,pid=K.pid,p=p,id=id,name=name}
end

end

do
local K=NB.K15
-- Preserve candidate eligibility and weighted selection. Replace the random
-- draw with 1 only for the player's source district, so an eligible positive
-- weight is chosen instead of the failure portion of the draw range.
function K.makeCovertChanceScript(at,symbol,rootSlot,random,districtVT,expected)
 return ([=[
[ENABLE]
assert(%X,%s)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0 0 0
@N@+100:
call %X
pushfq
push r10
cmp dword ptr [@N@],0
je original
test r15,r15
jz original
mov r10,%X
cmp [r15],r10
jne original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
cmp r10,[r15+20]
jne original
mov eax,1
inc dword ptr [@N@+4]
original:
pop r10
popfq
jmp %X
%X:
jmp @N@+100
[DISABLE]
%X:
db %s
unregistersymbol(@N@)
// Keep allocation alive until process exit for in-flight native calls.
]=]):format(at,expected,at,random,districtVT,rootSlot,at+5,at,at,expected):gsub('@N@',symbol)
end
function K.installCovertChanceHook()
 if K.covertChanceHook then return end
 K.ready();local m=K.base();local at=m+0x32FF33
 local symbol=('nb15CovertChance_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeCovertChanceScript(at,symbol,m+0xFE1038,m+0x4AB304,m+0xA4FDC8,'E8 CC B3 17 00')
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.covertChanceHook={q=assert(getAddressSafe(symbol)),at=at,script=script,info=info,pid=K.pid,
  installed=assert(readBytes(at,5,true))}
end
function K.covertChanceFeature(on)
 if on then K.installCovertChanceHook();K.installCovertWeightHooks() end
 if K.covertChanceHook then writeInteger(K.covertChanceHook.q,on and 1 or 0) end
 for _,h in ipairs(K.covertWeightHooks or {}) do writeInteger(h.q,on and 1 or 0) end
end
function K.removeCovertChanceHook()
 for i=#(K.covertWeightHooks or {}),1,-1 do
  local h=K.covertWeightHooks[i]
  if h.pid==getOpenedProcessID() and K.buildMatches() then
   local actual=assert(readBytes(h.at,8,true))
   for j,v in ipairs(h.installed) do assert(actual[j]==v,'N15 covert weight hook ownership changed') end
   writeInteger(h.q,0);assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 covert weight hook')
  end
  table.remove(K.covertWeightHooks,i)
 end
 local h=K.covertChanceHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.at,5,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N15 covert chance hook ownership changed') end
  writeInteger(h.q,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 covert chance hook')
 end
 K.covertChanceHook=nil
end
function K.makeCovertWeightScript(at,symbol,rootSlot,caller,officerVT)
 return ([=[
[ENABLE]
assert(%X,85 C0 7F 06 44 39 75 68)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0 0 0
@N@+100:
push r10
cmp dword ptr [@N@],0
je original
test eax,eax
jg original
// 40D420's 7 pushes and 70-byte local frame place its return address at
// original rsp+A8 and its caller's saved RSI (source officer) at rsp+98.
// This one trampoline push moves those offsets to B0 and A0 respectively.
mov r10,%X
cmp [rsp+B0],r10
jne original
mov r10,[rsp+A0]
test r10,r10
jz original
push rax
mov rax,%X
cmp [r10],rax
pop rax
jne original
mov r10,[r10+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
push r10
mov r10,[%X]
test r10,r10
jz @N@+400
mov r10,[r10+3A348]
test r10,r10
jz @N@+400
mov r10,[r10+B8]
test r10,r10
jz @N@+400
mov r10,[r10+F0]
test r10,r10
jz @N@+400
mov r10,[r10+20]
test r10,r10
jz @N@+400
cmp r10,[rsp]
jne @N@+400
mov eax,1
inc dword ptr [@N@+4]
jmp @N@+400
@N@+400:
pop r10
original:
pop r10
test eax,eax
jg %X
cmp dword ptr [rbp+68],r14d
jmp %X
%X:
jmp @N@+100
nop 3
[DISABLE]
%X:
db 85 C0 7F 06 44 39 75 68
unregistersymbol(@N@)
// Keep allocation until process exit for in-flight native calls.
]=]):format(at,at,caller,officerVT,rootSlot,at+0xA,at+8,at,at):gsub('@N@',symbol)
end
function K.installCovertWeightHooks()
 if K.covertWeightHooks and #K.covertWeightHooks==2 then return end
 K.ready();assert(not K.covertWeightHooks or #K.covertWeightHooks==0,'N15 covert weight hook group is incomplete')
 K.covertWeightHooks={};local m=K.base()
 local ok,why=pcall(function()
  for _,rva in ipairs({0x3556D1,0x3558B1}) do
   local at=m+rva;local symbol=('nb15CovertWeight_%X_%X'):format(getTickCount(),rva)
   local script=K.makeCovertWeightScript(at,symbol,m+0xFE1038,m+0x32FD2D,m+0xA4F440)
   local success,info=(K.assemble or autoAssemble)(script);assert(success,tostring(info))
   K.covertWeightHooks[#K.covertWeightHooks+1]={q=assert(getAddressSafe(symbol)),at=at,script=script,info=info,pid=K.pid,
    installed=assert(readBytes(at,8,true))}
  end
 end)
 if not ok then
  for i=#K.covertWeightHooks,1,-1 do
   local h=K.covertWeightHooks[i];assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot roll back N15 covert weight hook')
   table.remove(K.covertWeightHooks,i)
  end
  error(why,0)
 end
end

end

do
local K=NB.K15
function K.makeCovertDayScript(at,symbol,rootSlot,districtVT)
 return ([=[
[ENABLE]
assert(%X,43 8D 0C 80 3B C1)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0
dq 0
@N@+100:
lea ecx,[r8+r8*4]
push r10
cmp dword ptr [@N@],0
je original
cmp rdi,[@N@+8]
jne original
test rsi,rsi
jz original
mov r10,%X
cmp [rsi],r10
jne original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
cmp r10,[rsi+20]
jne original
mov eax,ecx
inc dword ptr [@N@+4]
original:
pop r10
cmp eax,ecx
jmp %X
%X:
jmp @N@+100
nop
[DISABLE]
%X:
db 43 8D 0C 80 3B C1
unregistersymbol(@N@)
// Retain trampoline memory until process exit.
]=]):format(at,at,districtVT,rootSlot,at+6,at,at):gsub('@N@',symbol)
end
function K.installCovertDayHook()
 if K.covertDayHook then return end
 K.ready();local m=K.base();local at=m+0x367DA8
 local symbol=('nb15CovertDay_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeCovertDayScript(at,symbol,m+0xFE1038,m+0xA4FDC8)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.covertDayHook={q=assert(getAddressSafe(symbol)),at=at,script=script,info=info,pid=K.pid,
  installed=assert(readBytes(at,6,true))}
end
function K.removeCovertDayHook()
 local h=K.covertDayHook;if not h then return end
 assert(not K.nativeBusy(),'Pending native work must retain its day hook')
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.at,6,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N15 covert day hook ownership changed') end
  writeInteger(h.q,0);writeQword(h.q+8,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 covert day hook')
 end
 K.covertDayHook=nil
end
function K.covertPledges(targetClan,sourceDistrict)
 local result={};local clanId=assert(K.indexOf('clan',targetClan))
 local districtId=assert(K.indexOf('district',sourceDistrict));local r=K.root()
 local first=readQword(r+0x38D60)
 for i=0,699 do
  local p=readQword(r+0x38D60+i*8)
  assert(p==first+i*0x28 and readQword(p)==K.base()+0xA56490,'N15 contact record layout changed')
  if readBytes(p+0xA,1)==clanId and readBytes(p+0xB,1)==districtId then
   local officerId=readSmallInteger(p+8)
   if K.object('officer',officerId) then result[#result+1]={id=i,p=p,officer=officerId,kind=readBytes(p+0xC,1)} end
  end
 end
 return result
end

end

do
local K=NB.K15
local function context(c)
 K.ready()
 assert(K.pid==c.pid and K.root()==c.root and K.scenario()==c.scenario and K.player()==c.player,
  'Work context changed')
 local p=assert(K.missionObject(c.id,0xA166A8),'Work command ended or changed')
 assert(p==c.p and readQword(p+0x88)==c.target and readQword(p+0x30)==c.district,
  'Work target changed')
 return p
end
local function release(c)
 assert(not K.nativeBusy(),'Pending work must retain its hooks')
 if K.covertDayHook then writeInteger(K.covertDayHook.q,0);writeQword(K.covertDayHook.q+8,0) end
 K.covertChanceFeature(c.chanceWasOn)
 if not c.hadDay then K.removeCovertDayHook() end
 if not c.hadChance then K.removeCovertChanceHook() end
end
function K.pollCovertWork()
 local c=K.covertPending;if not c then return true end
 assert(c.pid==getOpenedProcessID(),'Work process changed')
 local state=readInteger(c.request.q)
 if state==1 or state==2 then return false end
 -- Keep ownership on failure, so the normal release path can inspect it.
 assert(state==3,'Work request was rejected')
 if c.stage=='finish' then
  K.ready()
  assert(K.root()==c.root and K.scenario()==c.scenario and K.player()==c.player,'Work context changed')
  assert(not K.missionObject(c.id,0xA166A8),'Work command remains active')
  c.after=K.covertPledges(c.target,c.district)
  c.dateUnchanged=readInteger(c.scenario+0xB0)==c.date
  release(c);K.covertPending=nil;K.covertLast=c
  return true
 end
 context(c)
 assert(readQword(c.request.q+0x30)==1,'Work update did not succeed')
 c.completed=c.completed+1
 if c.completed&lt;c.attempts and not c.stopRequested then
  c.request=K.postMissionOperation('covertWorkTick',c.id)
 else
  local after=K.covertPledges(c.target,c.district)
  if #after&lt;=#c.before then
   release(c);K.covertPending=nil
   if c.stopRequested then return true end
   error('No new contact was registered; work command was retained',0)
  end
  c.stage='finish';c.request=K.postMissionOperation('covertWorkFinish',c.id)
 end
 return false
end
function K.covertInstantFeature(on)
 if not on then
  if K.covertScanTimer then K.covertScanTimer.destroy();K.covertScanTimer=nil end
  if K.covertPending then K.covertPending.stopRequested=true end
  K.on.covertInstant=nil
  return
 end
 K.ready();if K.covertScanTimer then return end
 K.covertAttempted={};K.on.covertInstant=true
 local timer=createTimer(nil,false);timer.Interval=500;K.covertScanTimer=timer
 timer.OnTimer=function(t)
  if K.pid~=getOpenedProcessID() then t.Enabled=false;return end
  if K.covertPending or K.nativeBusy() then return end
  local ok,err=pcall(function()
   K.ready()
   for _,item in ipairs(K.missionObjects(0xA166A8)) do
    local key=K.key()..':'..item.id..':'..readInteger(item.p+0x70)..':'..readQword(item.p+0x88)
    if not K.covertAttempted[key] then
     -- An error must not trigger the same report repeatedly on every timer.
     K.covertAttempted[key]=true;K.startCovertWork(item.id);break
    end
   end
  end)
  if not ok then
   t.Enabled=false;K.on.covertInstant=nil
   if K.reportFeatureFailure then K.reportFeatureFailure('covertInstant',err) else NB.msg(tostring(err)) end
  end
 end
 timer.Enabled=true
end
function K.startCovertWork(id)
 K.ready();assert(not K.covertPending and not K.nativeBusy(),'A native operation is pending')
 local p=assert(K.missionObject(id,0xA166A8),'Work command unavailable')
 local target=assert(readQword(p+0x88));local district=assert(readQword(p+0x30))
 assert(K.indexOf('clan',target) and K.indexOf('district',district),'Work context changed')
 local months=assert(readInteger(p+0x9C));assert(months&gt;=1 and months&lt;=12,'Work duration outside validated bound')
 local c={id=id,p=p,target=target,district=district,pid=K.pid,root=K.root(),scenario=K.scenario(),player=K.player(),
  date=readInteger(K.scenario()+0xB0),before=K.covertPledges(target,district),attempts=months,completed=0,stage='tick',
  hadDay=K.covertDayHook~=nil,hadChance=K.covertChanceHook~=nil,
  chanceWasOn=K.covertChanceHook and readInteger(K.covertChanceHook.q)==1 or false}
 K.installCovertDayHook();K.covertChanceFeature(true)
 writeQword(K.covertDayHook.q+8,p);writeInteger(K.covertDayHook.q,1)
 local ok,request=pcall(K.postMissionOperation,'covertWorkTick',id)
 if not ok then if not K.nativeBusy() then release(c) end;error(request,0) end
 c.request=request;K.covertPending=c
 if not K.covertTimer then
  local timer=createTimer(nil,false);K.covertTimer=timer;timer.Interval=250
  timer.OnTimer=function(t)
   local success,done=pcall(K.pollCovertWork)
   if not success then
    t.Enabled=false
    -- An executing callback keeps its code and payload until it returns.
    if not K.nativeBusy() and K.covertPending then
     pcall(release,K.covertPending);K.covertPending=nil
    end
    NB.msg(tostring(done));return
   end
   if done then t.destroy();K.covertTimer=nil end
  end
 end
 K.covertTimer.Enabled=true
 return c
end

end

do
local K=NB.K15
-- Change the final chance only after the game's target / pledge eligibility
-- checks have passed. Keep native RNG consumption, costs and result handling.
function K.makeCovertProposalScript(at,symbol,rootSlot,clanVT)
 return ([=[
[ENABLE]
assert(%X,48 8B 4D 68 48 85 C9)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0 0 0
@N@+100:
pushfq
push r10
push r11
cmp dword ptr [@N@],0
je original
mov r10,[rbp-20]
test r10,r10
jz original
mov r11,%X
cmp [r10],r11
jne original
mov r11,[%X]
test r11,r11
jz original
mov r11,[r11+3A348]
test r11,r11
jz original
mov r11,[r11+B8]
test r11,r11
jz original
mov r11,[r11+F0]
test r11,r11
jz original
mov r11,[r11+20]
cmp r10,r11
jne original
mov edi,64
inc dword ptr [@N@+4]
original:
pop r11
pop r10
popfq
mov rcx,[rbp+68]
test rcx,rcx
jmp %X
%X:
jmp @N@+100
nop 2
[DISABLE]
%X:
db 48 8B 4D 68 48 85 C9
unregistersymbol(@N@)
// Retain the trampoline until process exit for an in-flight caller.
]=]):format(at,at,clanVT,rootSlot,at+7,at,at):gsub('@N@',symbol)
end
function K.installCovertProposalHook()
 if K.covertProposalHook then return end
 K.ready();local m=K.base();local at=m+0x328F85
 local symbol=('nb15CovertProposal_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeCovertProposalScript(at,symbol,m+0xFE1038,m+0xA4FCE0)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.covertProposalHook={q=assert(getAddressSafe(symbol)),at=at,script=script,info=info,pid=K.pid,
  installed=assert(readBytes(at,7,true))}
end
function K.covertProposalFeature(on)
 if on then K.installCovertProposalHook() end
 if K.covertProposalHook then writeInteger(K.covertProposalHook.q,on and 1 or 0) end
end
function K.removeCovertProposalHook()
 local h=K.covertProposalHook;if not h then return end
 assert(not K.nativeBusy(),'Pending game operation must retain its hooks')
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.at,7,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N15 covert proposal hook ownership changed') end
  writeInteger(h.q,0);assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N15 covert proposal hook')
 end
 K.covertProposalHook=nil
end

end

do
local K=NB.K15
function K.ownCity(city)
 if not K.indexOf('city',city) then return false end
 local district=readQword(city+8)
 return K.indexOf('district',district)~=nil and readQword(district+0x20)==K.clan()
end
function K.cityMaxTick()
 K.ready();assert(not K.nativeBusy(),'A game operation is pending')
 local token=K.key();local changed=0
 local function put(kind,id,p,off,value,word)
  local current=word and readSmallInteger(p+off) or readInteger(p+off)
  if current~=value then
   assert(K.key()==token and K.object(kind,id)==p,'City data changed')
   assert((word and writeSmallInteger or writeInteger)(p+off,value),'Cannot update city resource')
   changed=changed+1
  end
 end
 for _,item in ipairs(K.objects('district')) do
  if readQword(item.p+0x20)==K.clan() then
   for _,field in ipairs(K.fields.district) do put('district',item.id,item.p,field.off,field.max,false) end
  end
 end
 local markets=K.marketIndex();local owned=K.ownedCitySet()
 for _,item in ipairs(K.objects('city')) do
  if owned[item.p] and K.ownCity(item.p) then
   local ag=K.agricultureForCity(item.p)
   local ai=K.indexOf('agriculture',ag)
   if ai then
    -- Farmers and farmer soldiers share the available farmland. Do not
    -- fabricate extra deployed farmer soldiers when replenishing a city.
    local farmers=assert(readInteger(ag+0x40));local soldiers=assert(readInteger(ag+0x44))
    local farmland=assert(readInteger(ag+0x48))
    assert(farmers&gt;=0 and soldiers&gt;=0 and farmers+soldiers&lt;=farmland,'Agriculture population exceeds available farmland')
    put('agriculture',ai,ag,0x48,math.max(99999,farmland),false)
    put('agriculture',ai,ag,0x84,99999,false)
    put('agriculture',ai,ag,0x11C,100,true)
    put('agriculture',ai,ag,0x11E,100,true)
    local popularityBase=100-K.popularityModifiers(ag)
    assert(popularityBase&gt;=-32768 and popularityBase&lt;=32767,'Popularity modifiers exceed the validated bound')
    put('agriculture',ai,ag,0x8A,popularityBase,true)
   end
   for _,market in ipairs(K.marketsForCity(item.p,markets)) do
    put('market',market.id,market.p,0xD8,10000,true)
    put('market',market.id,market.p,0xD6,10000,true)
   end
   local damaged=false
   for _,part in ipairs(K.castleParts(item.p)) do
    if (part.flags&amp;0x80)==0 and part.current&lt;part.max then damaged=true;break end
   end
   if damaged then
    assert(K.key()==token and K.ownCity(item.p),'City owner changed')
    K.repairCity(item.id);changed=changed+1
   end
  end
 end
 for _,item in ipairs(K.objects('county')) do
  if owned[readQword(item.p+0x28)] and K.ownCounty(item.p) then put('county',item.id,item.p,0x48,999999,false) end
 end
 -- At most one completed facility per tick; game-thread invalidation follows
 -- its level update. Construction and assigned workers are left to their orders.
 changed=changed+K.facilityMaxTick()
 return changed
end
function K.maxPolicyPoints()
 K.ready();local clan=assert(K.clan());local id=assert(K.indexOf('clan',clan))
 for kind=0,4 do
  if readSmallInteger(clan+0xDF4+kind*2)~=9999 then
   K.nativeCall('policyPointsSet','clan',id,kind,9999)
  end
 end
end

end

do
local K=NB.K15
-- Use the predicate's own seventh argument to skip willingness only for
-- resource proposals. Native stock, live-clan and gun-availability checks stay.
function K.makeResourceNegotiationScript(at,symbol,rootSlot,clanVT,offerVT)
 return ([=[
[ENABLE]
assert(%X,48 8B C4 55 56)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0
@N@+100:
pushfq
push rax
push r10
push r11
cmp dword ptr [@N@],0
je original
test rcx,rcx
jz original
test rdx,rdx
jz original
test r8,r8
jz original
mov rax,%X
cmp [rcx],rax
jne original
cmp [rdx],rax
jne original
mov rax,%X
cmp [r8],rax
jne original
movzx eax,word ptr [r8+8]
dec eax
cmp eax,3
ja original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
cmp [r10+20],rcx
jne original
mov dword ptr [rsp+58],1
inc dword ptr [@N@+4]
original:
pop r11
pop r10
pop rax
popfq
mov rax,rsp
push rbp
push rsi
jmp %X
%X:
jmp @N@+100
[DISABLE]
%X:
db 48 8B C4 55 56
unregistersymbol(@N@)
// Keep the trampoline allocated for any in-flight predicate return.
]=]):format(at,at,clanVT,offerVT,rootSlot,at+5,at,at):gsub('@N@',symbol)
end
function K.installResourceNegotiationHook()
 if K.resourceNegotiationHook then return end
 K.ready();local m=K.base();local at=m+0x2A7E00
 local symbol=('nb15ResourceNegotiation_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeResourceNegotiationScript(at,symbol,m+0xFE1038,m+0xA4FCE0,m+0xA582C8)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.resourceNegotiationHook={q=assert(getAddressSafe(symbol)),at=at,pid=K.pid,script=script,info=info,
  installed=assert(readBytes(at,5,true))}
end
function K.resourceNegotiationFeature(on)
 if on then K.installResourceNegotiationHook() end
 if K.resourceNegotiationHook then writeInteger(K.resourceNegotiationHook.q,on and 1 or 0) end
end
function K.removeResourceNegotiationHook()
 local h=K.resourceNegotiationHook;if not h then return end
 assert(not K.nativeBusy(),'A pending predicate must retain its hook')
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local actual=assert(readBytes(h.at,5,true))
  for i,v in ipairs(h.installed) do assert(actual[i]==v,'Resource negotiation hook ownership changed') end
  writeInteger(h.q,0);assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore resource negotiation hook')
 end
 K.resourceNegotiationHook=nil
end
function K.makeTradeNegotiationScript(at,symbol,rootSlot)
 return ([=[
[ENABLE]
assert(%X,45 33 C9 45 33 C0)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0
@N@+100:
xor r9d,r9d
xor r8d,r8d
pushfq
push r10
push r11
cmp dword ptr [@N@],0
je original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
mov r11,[rbp-71]
test r11,r11
jz original
cmp [r10+20],r11
jne original
mov r9d,1
inc dword ptr [@N@+4]
original:
pop r11
pop r10
popfq
jmp %X
%X:
jmp @N@+100
nop
[DISABLE]
%X:
db 45 33 C9 45 33 C0
unregistersymbol(@N@)
]=]):format(at,at,rootSlot,at+6,at,at):gsub('@N@',symbol)
end
function K.installTradeNegotiationHook()
 if K.tradeNegotiationHook then return end
 K.ready();local m=K.base();local at=m+0x2A8BBE
 local symbol=('nb15TradeNegotiation_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeTradeNegotiationScript(at,symbol,m+0xFE1038)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.tradeNegotiationHook={q=assert(getAddressSafe(symbol)),at=at,pid=K.pid,script=script,info=info,
  installed=assert(readBytes(at,6,true))}
end
function K.tradeNegotiationFeature(on)
 if on then K.installTradeNegotiationHook() end
 if K.tradeNegotiationHook then writeInteger(K.tradeNegotiationHook.q,on and 1 or 0) end
end
function K.removeTradeNegotiationHook()
 local h=K.tradeNegotiationHook;if not h then return end
 assert(not K.nativeBusy(),'A pending predicate must retain its hook')
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local actual=assert(readBytes(h.at,6,true))
  for i,v in ipairs(h.installed) do assert(actual[i]==v,'Trade negotiation hook ownership changed') end
  writeInteger(h.q,0);assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore trade negotiation hook')
 end
 K.tradeNegotiationHook=nil
end

end

do
local K=NB.K15
-- These hooks adjust only willingness decisions inside the native transaction
-- predicate. They never rebuild a UI controller or manufacture a proposal.
function K.makeDiplomacyFrameScript(at,symbol,rootSlot,bytes,sourceOffset,replay,accepted,extra)
 local length=0;for _ in bytes:gmatch('%x%x') do length=length+1 end
 local script=([=[
[ENABLE]
assert(%X,%s)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0
@N@+100:
pushfq
push r10
push r11
cmp dword ptr [@N@],0
je original
%s
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
mov r11,%s
cmp r10,r11
jne original
inc dword ptr [@N@+4]
pop r11
pop r10
popfq
%s
jmp %X
original:
pop r11
pop r10
popfq
%s
jmp %X
%X:
jmp @N@+100
%s
[DISABLE]
%X:
db %s
unregistersymbol(@N@)
]=]):format(at,bytes,at,extra or '',rootSlot,sourceOffset,accepted,at+length,
 replay,at+length,at,length&gt;5 and ('nop '..(length-5)) or '',at,bytes)
 return script:gsub('@N@',symbol)
end
K.negotiationSites={
 {key='opinion',rva=0x2A7EFC,length=8,source='[rbp-71]',bytes='89 44 24 44 89 7C 24 38',
 replay=function()return 'mov [rsp+44],eax\nmov [rsp+38],edi'end,
 accepted=function()return 'mov eax,64\nmov [rsp+44],eax\nmov [rsp+38],edi'end},
 {key='alliance',rva=0x2A8C4E,length=6,source='[rbp-71]',bytes='45 33 C9 45 33 C0',
 replay=function()return 'xor r9d,r9d\nxor r8d,r8d'end,
 accepted=function()return 'xor r8d,r8d\nmov r9d,1'end},
 {key='submission',rva=0x2A75B2,length=7,source='[rsp+108]',bytes='39 BC 24 A0 00 00 00',
 replay=function()return 'cmp [rsp+A0],edi'end,
 accepted=function(m)return ('jmp %X'):format(m+0x2A7653)end,
 extra=function(m)return ([=[
cmp esi,-1
jne original
mov r10,[rsp+90]
mov r11,%X
cmp r10,r11
je callerOK
mov r11,%X
cmp r10,r11
jne original
callerOK:
]=]):format(m+0x2A8C30,m+0x2A8C0A)end}}
function K.installNegotiationDecisionHooks()
 K.ready();K.negotiationDecisionHooks=K.negotiationDecisionHooks or {}
 local m=K.base()
 for _,site in ipairs(K.negotiationSites) do
  if not K.negotiationDecisionHooks[site.key] then
   local symbol=('nb15Diplomacy_%s_%X_%X'):format(site.key,getTickCount(),math.random(0x100000,0x7FFFFF))
   local extra=site.extra and ('label(callerOK)\n'..site.extra(m)) or ''
   local script=K.makeDiplomacyFrameScript(m+site.rva,symbol,m+0xFE1038,site.bytes,site.source,
    site.replay(m),site.accepted(m),extra)
   local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
   K.negotiationDecisionHooks[site.key]={q=assert(getAddressSafe(symbol)),script=script,info=info,
    at=m+site.rva,pid=K.pid,installed=assert(readBytes(m+site.rva,site.length,true))}
  end
 end
end
function K.removeNegotiationDecisionHooks()
 assert(not K.nativeBusy(),'A pending negotiation must retain its decision hooks')
 for name,h in pairs(K.negotiationDecisionHooks or {}) do
  if h.pid==getOpenedProcessID() and K.buildMatches() then
   local actual=assert(readBytes(h.at,#h.installed,true))
   for i,b in ipairs(h.installed) do assert(actual[i]==b,'Negotiation decision hook ownership changed') end
   writeInteger(h.q,0);assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore negotiation decision hook')
  end
  K.negotiationDecisionHooks[name]=nil
 end
end
function K.negotiationSuccessFeature(on)
 if not on then
  K.resourceNegotiationFeature(false);K.tradeNegotiationFeature(false)
  for _,h in pairs(K.negotiationDecisionHooks or {}) do writeInteger(h.q,0) end
  return
 end
 K.ready()
 local ok,why=pcall(function()
  K.installResourceNegotiationHook();K.installTradeNegotiationHook();K.installNegotiationDecisionHooks()
 end)
 if not ok then
  K.negotiationSuccessFeature(false)
  error(why,0)
 end
 K.resourceNegotiationFeature(true);K.tradeNegotiationFeature(true)
 for _,h in pairs(K.negotiationDecisionHooks) do writeInteger(h.q,1) end
end

end

do
local K=NB.K15
K.types.role={off=0x38140,count=307,stride=0x48,vt=0xA5A4D8}
K.nativeDefinitions.courtRankAward={rva=0x2EF29C,
 bytes='40 53 55 56 57 41 56 48 83 EC 40 48 8B 05 E2',kind='role',argumentType='clan'}
function K.rankName(role)
 assert(K.indexOf('role',role),'Rank is unavailable')
 return K.decodeText(readString(role+8,0x24,false) or '')
end
function K.rankOf(officer,kind)
 assert(K.indexOf('officer',officer),'Officer is unavailable')
 local id=readSmallInteger(officer+(kind==0 and 0x1F4 or 0x1F2))
 if id and id&gt;=32768 then id=id-65536 end
 local role=id and K.object('role',id)
 if role and readBytes(role+0x2C,1)==kind then return id,role end
 return -1
end
function K.installRoleAwardWrapper()
 if K.roleAwardWrapper then return end
 K.ready();local at=K.base()+0x2F0BDC
 local expected={0x40,0x53,0x55,0x56,0x57,0x41,0x56,0x41,0x57,0x48,0x83,0xEC}
 local bytes=assert(readBytes(at,#expected,true))
 for i,b in ipairs(expected) do assert(bytes[i]==b,'Role award method changed') end
 local symbol=('nb15RoleAward_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=([=[
[ENABLE]
alloc(@N@,4096,%X)
registersymbol(@N@)
@N@:
sub rsp,28
mov qword ptr [rsp+20],0
mov rax,%X
call rax
add rsp,28
ret
[DISABLE]
unregistersymbol(@N@)
// Keep the small wrapper allocation until process exit.
]=]):format(at,at):gsub('@N@',symbol)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 local q=assert(getAddressSafe(symbol))
 K.roleAwardWrapper={q=q,pid=K.pid,script=script,info=info}
 K.nativeDefinitions.roleAward={rva=q-K.base(),bytes='48 83 EC 28 48 C7 44 24 20 00 00 00 00',kind='role',argumentType='clan'}
end
function K.removeRoleAwardWrapper()
 local h=K.roleAwardWrapper;if not h then return end
 assert(not K.nativeBusy(),'A pending award must retain its wrapper')
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot unregister role award wrapper')
 end
 K.roleAwardWrapper=nil;K.nativeDefinitions.roleAward=nil
end
function K.awardRank(officerIndex,roleIndex)
 K.ready();local officer=assert(K.object('officer',officerIndex),'Officer is unavailable')
 local role=assert(K.object('role',roleIndex),'Rank is unavailable')
 local kind=readBytes(role+0x2C,1);assert(kind==0 or kind==1,'Invalid rank category')
 local district=readQword(officer+0xF0)
 assert(K.indexOf('district',district),'Officer is not serving a clan')
 local clan=readQword(district+0x20);assert(K.indexOf('clan',clan),'Officer clan is unavailable')
 local token=K.key()
 if kind==1 then K.installRoleAwardWrapper() end
 -- Native award updates previous holder, recipient, clan ownership, acquired
 -- rank bitset and game notifications. A bare officer-field write omits these.
 K.nativeCall(kind==0 and 'courtRankAward' or 'roleAward','role',roleIndex,clan,0,officer)
 assert(K.key()==token,'Game data changed during the award')
 assert(readQword(role+0x30)==officer,'Rank holder was not updated')
 assert(readQword(role+0x38)==clan,'Rank clan ownership was not updated')
 assert(K.rankOf(officer,kind)==roleIndex,'Officer rank was not updated')
 local bits=assert(readInteger(clan+0xC48+math.floor(roleIndex/32)*4))
 assert((bits&amp;(1&lt;&lt;(roleIndex%32)))~=0,'Clan rank record was not updated')
 if K.refreshRankRows then K.refreshRankRows() end
end
function K.chooseRank(officerIndex,kind)
 K.ready();local token=K.key();local ids,names={},{}
 for _,item in ipairs(K.objects('role')) do
  if readBytes(item.p+0x2C,1)==kind then
   local name=K.rankName(item.p)
   if name~='' then ids[#ids+1]=item.id;names[#names+1]=name end
  end
 end
 local n=NB.pick(NB.T(kind==0 and 'Award court rank' or 'Award office',kind==0 and '官位を授与' or '役職を授与'),names)
 if not n then return end
 assert(K.key()==token,'Game data changed; reopen the rank list')
 K.awardRank(officerIndex,ids[n])
end
K.rankRows=K.rankRows or {}
local function labels(officer,category)
 local id,role=K.rankOf(officer,category)
 local name=role and K.rankName(role)
 return (category==0 and 'Court rank' or 'Office')..': '..(name or 'None'),
  (category==0 and '官位' or '役職')..'：'..(name or 'なし')
end
function K.refreshRankRows()
 for id,entry in pairs(K.rankRows) do
  local row=getAddressList().getMemoryRecordByID(id)
  local officer=K.object('officer',entry.index)
  if not row then K.rankRows[id]=nil
  elseif officer and K.key()==entry.token then
   local en,jp=labels(officer,entry.kind)
   for _,d in ipairs(NB.dyn or {}) do
    if d.mr==row then d.en=en;d.ja=jp;break end
   end
   row.Description=NB.T(en,jp)
  end
 end
end
local close=K.closeEditor
function K.closeEditor(mr)
 for id in pairs(K.rankRows) do
  local row=getAddressList().getMemoryRecordByID(id)
  if not row or row.Parent==mr then K.rankRows[id]=nil end
 end
 return close(mr)
end
local open=K.openEditor
function K.openEditor(mr,kind)
 open(mr,kind)
 if kind~='officer' and kind~='player' then return end
 local officer=K.selected(kind);if not officer then return end
 local index=assert(K.indexOf('officer',officer));local token=K.key()
 for category=0,1 do
  local categoryId=category
  local en,jp=labels(officer,categoryId)
  local row=NB.addRec(mr,en,jp,'',vtAutoAssembler)
  row.Script='[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.K15.chooseRank('..index..','..categoryId..') end)\n{$asm}\n[DISABLE]\n'
  row.OnActivate=function(_,before)
   if before then return K.key()==token and K.object('officer',index)==officer end
   return true
  end
  K.rankRows[row.ID]={index=index,kind=categoryId,token=token}
 end
end

end

do
local K=NB.K15
K.nativeDefinitions.commerceActionsRefill={rva=0x34B300,
 bytes='40 53 48 83 EC 20 48 8B D9 E8 6E 8E FF FF',kind='district'}
function K.makeCommerceActionsScript(at,symbol,rootSlot,districtVT)
 return ([=[
[ENABLE]
assert(%X,FE C8 88 83 96 00 00 00)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
label(store)
@N@:
dd 0 0
@N@+100:
pushfq
push r10
push r11
cmp dword ptr [@N@],0
je original
test rbx,rbx
jz original
mov r10,%X
cmp [rbx],r10
jne original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
mov r10,[r10+20]
test r10,r10
jz original
cmp [rbx+20],r10
jne original
inc dword ptr [@N@+4]
pop r11
pop r10
popfq
jmp store
original:
pop r11
pop r10
popfq
dec al
store:
mov [rbx+96],al
jmp %X
%X:
jmp @N@+100
nop 3
[DISABLE]
%X:
db FE C8 88 83 96 00 00 00
unregistersymbol(@N@)
]=]):format(at,at,districtVT,rootSlot,at+8,at,at):gsub('@N@',symbol)
end
function K.installCommerceActionsHook()
 if K.commerceActionsHook then return end
 K.ready();local m=K.base();local at=m+0x2088EB
 local symbol=('nb15CommerceActions_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeCommerceActionsScript(at,symbol,m+0xFE1038,m+K.types.district.vt)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.commerceActionsHook={q=assert(getAddressSafe(symbol)),at=at,pid=K.pid,script=script,info=info,
  installed=assert(readBytes(at,8,true))}
end
function K.commerceActionsFeature(on)
 if on then
  K.installCommerceActionsHook()
  for _,item in ipairs(K.objects('district')) do
   if readQword(item.p+0x20)==K.clan() then K.nativeCall('commerceActionsRefill','district',item.id) end
  end
 end
 if K.commerceActionsHook then writeInteger(K.commerceActionsHook.q,on and 1 or 0) end
end
function K.removeCommerceActionsHook()
 local h=K.commerceActionsHook;if not h then return end
 assert(not K.nativeBusy(),'A pending action must retain its hook')
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local actual=assert(readBytes(h.at,8,true))
  for i,b in ipairs(h.installed) do assert(actual[i]==b,'Commerce action hook ownership changed') end
  writeInteger(h.q,0);assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore commerce action hook')
 end
 K.commerceActionsHook=nil
end
local open=K.openEditor
function K.openEditor(mr,kind)
 open(mr,kind)
 if kind~='player' then return end
 local id=assert(K.indexOf('district',K.district()))
 for _,field in ipairs({
  {en='Commerce actions remaining',jp='商業の残り行動数',off=0x96,min=0,max=99,size=1},
  {en='Additional commerce actions',jp='商業の追加行動数',off=0x99,min=0,max=99,size=1}}) do
  K.addField(mr,'district',id,field)
 end
end

end

do
local K=NB.K15
-- Agriculture has shared annual supplies, not the commerce action byte.
function K.farmOwnGuard(rootSlot,agricultureVT,cityVT,districtVT,source)
 local code=([=[
test %s,%s
jz original
mov rax,%X
cmp [%s],rax
jne original
mov r11,[%X]
test r11,r11
jz original
mov r11,[r11+3A348]
test r11,r11
jz original
mov r11,[r11+B8]
test r11,r11
jz original
mov r11,[r11+F0]
test r11,r11
jz original
mov rax,%X
cmp [r11],rax
jne original
mov r11,[r11+20]
test r11,r11
jz original
]=]):format(source,source,source=='rcx' and agricultureVT or districtVT,source,rootSlot,districtVT)
 if source=='rcx' then
  code=code..([=[
mov r10,[rcx+30]
test r10,r10
jz original
mov rax,%X
cmp [r10],rax
jne original
mov r10,[r10+8]
test r10,r10
jz original
mov rax,%X
cmp [r10],rax
jne original
cmp [r10+20],r11
jne original
]=]):format(cityVT,districtVT)
 else
  code=code..'cmp [r13+20],r11\njne original\n'
 end
 return code
end
function K.makeFarmCostScript(at,symbol,rootSlot,agricultureVT,cityVT,districtVT)
 return ([=[
[ENABLE]
assert(%X,48 89 5C 24 08 48 89 6C 24 10)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0
@N@+100:
pushfq
push rax
push r10
push r11
cmp dword ptr [@N@],0
je original
%s
test r8,r8
jz original
test r9,r9
jz original
mov rax,[rsp+48]
test rax,rax
jz original
mov dword ptr [r8],0
mov dword ptr [r9],0
mov dword ptr [rax],0
inc dword ptr [@N@+4]
pop r11
pop r10
pop rax
popfq
ret
original:
pop r11
pop r10
pop rax
popfq
mov [rsp+8],rbx
mov [rsp+10],rbp
jmp %X
%X:
jmp @N@+100
nop 5
[DISABLE]
%X:
db 48 89 5C 24 08 48 89 6C 24 10
unregistersymbol(@N@)
]=]):format(at,at,K.farmOwnGuard(rootSlot,agricultureVT,cityVT,districtVT,'rcx'),at+10,at,at):gsub('@N@',symbol)
end
function K.makeFarmSeasonScript(at,symbol,rootSlot,agricultureVT,cityVT,districtVT)
 return ([=[
[ENABLE]
assert(%X,45 85 FF 75 1E 83 FA 09)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
@N@:
dd 0 0
@N@+100:
pushfq
push rax
push r10
push r11
cmp dword ptr [@N@],0
je original
%s
inc dword ptr [@N@+4]
pop r11
pop r10
pop rax
popfq
jmp %X
original:
pop r11
pop r10
pop rax
popfq
test r15d,r15d
jne %X
cmp edx,9
jmp %X
%X:
jmp @N@+100
nop 3
[DISABLE]
%X:
db 45 85 FF 75 1E 83 FA 09
unregistersymbol(@N@)
]=]):format(at,at,K.farmOwnGuard(rootSlot,agricultureVT,cityVT,districtVT,'r13'),at+0x4F,at+0x23,at+8,at,at):gsub('@N@',symbol)
end
function K.installFarmActionsHooks()
 if K.farmActionsHooks then return end
 K.ready();local m=K.base();local hooks={}
 K.farmActionsHooks=hooks
 for _,site in ipairs({{rva=0x347CA8,size=10,make=K.makeFarmCostScript},{rva=0x2CEC50,size=8,make=K.makeFarmSeasonScript}})do
  local symbol=('nb15Farm_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
  local at=m+site.rva
  local script=site.make(at,symbol,m+0xFE1038,m+K.types.agriculture.vt,m+K.types.city.vt,m+K.types.district.vt)
  local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
  hooks[#hooks+1]={q=assert(getAddressSafe(symbol)),at=at,pid=K.pid,script=script,info=info,size=site.size,installed=assert(readBytes(at,site.size,true))}
 end
end
function K.farmActionsFeature(on)
 if on then K.installFarmActionsHooks();assert(#K.farmActionsHooks==2,'Agriculture hooks incomplete')end
 for _,h in ipairs(K.farmActionsHooks or {})do assert(writeInteger(h.q,on and 1 or 0))end
 if on then
  local clan=assert(K.clan());assert(K.indexOf('clan',clan))
  -- A zero stock remains usable with zero cost; restore one unit for display.
  for _,offset in ipairs({0x1653,0x1654})do if readBytes(clan+offset,1)==0 then assert(writeBytes(clan+offset,1))end end
  if readSmallInteger(clan+0x1656)==0 then assert(writeSmallInteger(clan+0x1656,1))end
 end
end
function K.removeFarmActionsHooks()
 local hooks=K.farmActionsHooks;if not hooks then return end
 assert(not K.nativeBusy(),'A pending operation must retain its hooks')
 for _,h in ipairs(hooks)do
  if h.pid==getOpenedProcessID() and K.buildMatches()then
   local bytes=assert(readBytes(h.at,h.size,true))
   for i,b in ipairs(h.installed)do assert(bytes[i]==b,'Agriculture hook ownership changed')end
   assert(writeInteger(h.q,0));assert((K.assemble or autoAssemble)(h.script,h.info))
  end
 end
 K.farmActionsHooks=nil
end
local open=K.openEditor
function K.openEditor(mr,kind)
 open(mr,kind);if kind~='player' then return end
 local id=assert(K.indexOf('clan',K.clan()))
 for _,field in ipairs({
  {en='Agriculture labor',jp='農業の労力',off=0x1656,min=0,max=99,size=2},
  {en='Agriculture fertilizer',jp='農業の肥料',off=0x1653,min=0,max=99,size=1},
  {en='Agriculture good seeds',jp='農業の良種',off=0x1654,min=0,max=99,size=1}})do K.addField(mr,'clan',id,field)end
end

end

do
local K=NB.K15
-- 3D19D0 is a work-completion routine: its player report dereferences the
-- assigned officer even when nil. Completed facilities must not call it.
function K.installFacilityLevelWrapper()
 if K.facilityLevelWrapper then return end
 K.ready()
 local symbol=('nb15FacilityLevel_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=([=[
[ENABLE]
alloc(@N@,4096,%X)
registersymbol(@N@)
label(done)
label(limit)
@N@:
push rbx
sub rsp,20
mov rbx,rcx
movzx eax,byte ptr [rbx+165]
sub eax,2
cmp eax,1
ja done
mov rcx,[rbx+150]
test rcx,rcx
jz done
movzx eax,byte ptr [rcx+27]
cmp eax,A
jbe limit
mov eax,A
limit:
cmp edx,1
jl done
cmp edx,eax
jg done
mov [rbx+164],dl
mov rax,%X
call rax
test rax,rax
jz done
mov rcx,rax
movzx edx,word ptr [rbx+D8]
mov rax,%X
call rax
done:
add rsp,20
pop rbx
ret
[DISABLE]
unregistersymbol(@N@)
// Retain allocation until process exit: never free an in-flight callback.
]=]):format(K.base(),K.base()+0x192724,K.base()+0x595488):gsub('@N@',symbol)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 local q=assert(getAddressSafe(symbol))
 K.facilityLevelWrapper={q=q,pid=K.pid,script=script,info=info}
 K.nativeDefinitions.facilityLevelChange={rva=q-K.base(),bytes='53 48 83 EC 20',kind='county'}
end
function K.removeFacilityLevelWrapper()
 local h=K.facilityLevelWrapper;if not h then return end
 assert(not K.nativeBusy(),'A pending facility operation must retain its wrapper')
 if h.pid==getOpenedProcessID() and K.buildMatches() then assert((K.assemble or autoAssemble)(h.script,h.info)) end
 K.facilityLevelWrapper=nil;K.nativeDefinitions.facilityLevelChange=nil
end
function K.facilityInfo(index)
 local county=K.object('county',index);if not county then return end
 local facility=readQword(county+0x150)
 if not K.indexOf('facility',facility) then return end
 local level=readBytes(county+0x164,1);local state=readBytes(county+0x165,1)
 local limit=math.min(10,assert(readBytes(facility+0x27,1)))
 if not level or level&lt;1 or level&gt;10 or limit&lt;1 then return end
 return {p=county,facility=facility,level=level,state=state,limit=limit}
end
function K.setFacilityLevel(index,value)
 K.ready();local info=assert(K.facilityInfo(index),'Facility is unavailable')
 assert(info.state==2 or info.state==3,'Finish facility construction before changing its level')
 assert(type(value)=='number' and value%1==0 and value&gt;=1 and value&lt;=info.limit,'Facility level is outside its native limit')
 if value==info.level then return end
 local worker=readQword(info.p+0x158)
 assert(worker==0 or K.indexOf('officer',worker),'Facility worker context is invalid')
 local token=K.key()
 K.installFacilityLevelWrapper()
 K.nativeCall('facilityLevelChange','county',index,value)
 assert(K.key()==token and K.object('county',index)==info.p,'Facility context changed')
 assert(readBytes(info.p+0x164,1)==value,'Facility level did not change')
 assert(readQword(info.p+0x158)==worker and readBytes(info.p+0x165,1)==info.state,'Facility assignment changed')
 if K.refreshFacilityRows then K.refreshFacilityRows() end
end
function K.facilityMaxTick()
 K.ready();local owned=K.ownedCitySet()
 for _,item in ipairs(K.objects('county')) do
  local state=readBytes(item.p+0x165,1);local level=readBytes(item.p+0x164,1)
  if (state==2 or state==3) and level and level&lt;10 and owned[readQword(item.p+0x28)] then
   local info=K.facilityInfo(item.id)
   if info and (info.state==2 or info.state==3) and info.level&lt;info.limit and K.ownCounty(item.p) then
    K.setFacilityLevel(item.id,info.limit)
    return 1
   end
  end
 end
 return 0
end
K.facilityRows=K.facilityRows or {}
local function labels(info)
 return ('Facility level: %d / %d'):format(info.level,info.limit),
  ('施設レベル：%d / %d'):format(info.level,info.limit)
end
function K.refreshFacilityRows()
 for id,entry in pairs(K.facilityRows) do
  local row=getAddressList().getMemoryRecordByID(id)
  if not row then K.facilityRows[id]=nil
  elseif K.key()==entry.token then
   local info=K.facilityInfo(entry.index)
   if info then
    local en,jp=labels(info)
    for _,d in ipairs(NB.dyn or {}) do if d.mr==row then d.en=en;d.ja=jp;break end end
    row.Description=NB.T(en,jp)
   end
  end
 end
end
function K.chooseFacilityLevel(index)
 K.ready();local token=K.key();local info=assert(K.facilityInfo(index),'Facility is unavailable')
 local names={};for i=1,info.limit do names[i]=tostring(i) end
 local n=NB.pick(NB.T('Facility level','施設レベル'),names)
 if not n then return end
 assert(K.key()==token,'Game data changed; reopen the facility editor')
 K.setFacilityLevel(index,n)
end
function K.addFacilityEditor(parent,item,owner)
 local info=K.facilityInfo(item.id);if not info then return end
 local en,jp=labels(info);local row=NB.addRec(parent,en,jp,'',vtAutoAssembler)
 row.Script='[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.K15.chooseFacilityLevel('..item.id..') end)\n{$asm}\n[DISABLE]\n'
 local token=K.key();local p=item.p
 row.OnActivate=function(_,before)
  if before then return K.key()==token and K.object('county',item.id)==p end
  return true
 end
 K.facilityRows[row.ID]={index=item.id,owner=owner,token=token}
end
local close=K.closeEditor
function K.closeEditor(mr)
 for id,entry in pairs(K.facilityRows) do if entry.owner==mr then K.facilityRows[id]=nil end end
 return close(mr)
end

end

do
local K=NB.K15
K.commerceClasses={
 [0xA16148]={rva=0x1AA844,name='commerceExpand',bytes='48 89 5C 24 08 48 89 74 24 10 57 48 83 EC'},
 [0xA162A0]={rva=0x1AA5DC,name='commerceMonopoly',bytes='48 89 5C 24 08 48 89 6C 24 10 48 89 74 24'},
 [0xA163F8]={rva=0x1AA934,name='commerceInvest',bytes='48 89 5C 24 08 48 89 6C 24 10 48 89 74 24'},
 [0xA16550]={rva=0x1AA710,name='commerceOther',bytes='48 89 5C 24 08 48 89 6C 24 10 48 89 74 24'}}
for vt,entry in pairs(K.commerceClasses) do
 -- Use the native runner, which also deregisters an ended command. Calling
 -- only virtual update +90 leaves a completed order on the active list.
 K.nativeDefinitions[entry.name]={rva=0x2FF430,bytes='40 53 48 83 EC 20 48 8B D9 E8 86 40 FF FF',kind='mission',vt=vt}
 K.nativeDefinitions[entry.name..'Market']={rva=0x2FADB4,bytes='40 53 48 83 EC 20 48 8B D9 E8 02 C0',kind='mission',vt=vt}
end
function K.marketForCommerce(item)
 local entry=assert(K.commerceClasses[item.vt],'Not a commerce command')
 local market=K.nativeCall(entry.name..'Market','mission',item.id)
 assert(K.indexOf('market',market),'Commerce market is unavailable')
 return market
end
function K.makeCommerceElapsedScript(at,symbol,rootSlot,module)
 return ([=[
[ENABLE]
assert(%X,40 53 48 83 EC 20)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
label(classOK)
@N@:
dd 0 0
@N@+100:
pushfq
push r10
push r11
cmp dword ptr [@N@],0
je original
test rcx,rcx
jz original
mov r10,%X
cmp [rcx],r10
je classOK
mov r10,%X
cmp [rcx],r10
je classOK
mov r10,%X
cmp [rcx],r10
je classOK
mov r10,%X
cmp [rcx],r10
jne original
classOK:
cmp dword ptr [rcx+60],0
jne original
mov r11,[rcx+30]
test r11,r11
jz original
mov r10,%X
cmp [r11],r10
jne original
mov r11,[r11+20]
test r11,r11
jz original
mov r10,[%X]
test r10,r10
jz original
mov r10,[r10+3A348]
test r10,r10
jz original
mov r10,[r10+B8]
test r10,r10
jz original
mov r10,[r10+F0]
test r10,r10
jz original
cmp [r10+20],r11
jne original
inc dword ptr [@N@+4]
pop r11
pop r10
popfq
mov eax,7FFF
ret
original:
pop r11
pop r10
popfq
push rbx
sub rsp,20
jmp %X
%X:
jmp @N@+100
nop
[DISABLE]
%X:
db 40 53 48 83 EC 20
unregistersymbol(@N@)
]=]):format(at,at,module+0xA16148,module+0xA162A0,module+0xA163F8,module+0xA16550,
 module+K.types.district.vt,rootSlot,at+6,at,at):gsub('@N@',symbol)
end
function K.installCommerceElapsedHook()
 if K.commerceElapsedHook then return end
 K.ready();local m=K.base();local at=m+0x2C5D3C
 local symbol=('nb15CommerceElapsed_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.makeCommerceElapsedScript(at,symbol,m+0xFE1038,m)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.commerceElapsedHook={q=assert(getAddressSafe(symbol)),at=at,pid=K.pid,script=script,info=info,
  installed=assert(readBytes(at,6,true))}
end
function K.removeCommerceElapsedHook()
 local h=K.commerceElapsedHook;if not h then return end
 assert(not K.nativeBusy(),'A pending commerce operation must retain its elapsed hook')
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local actual=assert(readBytes(h.at,6,true))
  for i,b in ipairs(h.installed) do assert(actual[i]==b,'Commerce elapsed hook ownership changed') end
  writeInteger(h.q,0);assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore commerce elapsed hook')
 end
 K.commerceElapsedHook=nil
end
function K.finishCommerce()
 K.ready();assert(not K.nativeBusy(),'Operation pending')
 for _,item in ipairs(K.missionObjects()) do
  local entry=K.commerceClasses[item.vt]
  if entry then
   K.marketForCommerce(item)
   local token=K.key()
   K.installCommerceElapsedHook();writeInteger(K.commerceElapsedHook.q,1)
   K.nativeCall(entry.name,'mission',item.id)
   assert(K.key()==token,'Game data changed during commerce completion')
   assert(not K.missionObject(item.id,item.vt),'Commerce command has not finished')
   return 1
  end
 end
 return 0
end
function K.commerceInstantFeature(on)
 if not on then
  K.periodic('commerceInstant',false)
  if K.commerceElapsedHook then writeInteger(K.commerceElapsedHook.q,0) end
  return
 end
 K.periodic('commerceInstant',true,K.finishCommerce)
end

end

do
local K=NB.K15
-- Only game 4 dispatches here. Older games retain their original lifecycle.
K.timers=K.timers or {}
function K.reportFeatureFailure(name,why)
 NB.msg(tostring(why))
 local id=({cityMax=304,instantDevelopment=602,goodwill=15001,covertInstant=15002,
  maxInvestment=15005,commerceInstant=15006})[name]
 local row=id and getAddressList().getMemoryRecordByID(id)
 if row and row.Active then NB.deferOff(row) end
end
function K.periodic(name,on,callback)
 if K.timers[name] then K.timers[name].destroy();K.timers[name]=nil end
 K.on[name]=nil
 if not on then return end
 K.ready();assert(not K.nativeBusy(),'A game operation is pending');callback();K.on[name]=true
 local timer=createTimer(nil,false);timer.Interval=500;K.timers[name]=timer;local running=false
 timer.OnTimer=function(t)
  if running then return end
  if getOpenedProcessID()~=K.pid then t.Enabled=false;return end
  if K.nativeBusy() then return end
  t.Enabled=false;running=true
  local ok,why=pcall(callback)
  running=false
  if not ok then K.on[name]=nil;K.reportFeatureFailure(name,why)
  elseif K.timers[name]==t and K.on[name] then t.Enabled=true end
 end
 timer.Enabled=true
end
function K.instantDevelopment(on)
 if not on then
  K.periodic('instantDevelopment',false)
  K.castleWorkFeature(false)
  return
 end
 K.periodic('instantDevelopment',true,function()
  K.finishConstruction();K.finishCastleWork()
  for _,city in ipairs(K.objects('city')) do
   if K.ownCity(city.p) then
    local damaged=false
    for _,part in ipairs(K.castleParts(city.p)) do
     if (part.flags&amp;0x80)==0 and part.current&lt;part.max then damaged=true;break end
    end
    if damaged then K.repairCity(city.id) end
   end
  end
 end)
end
function K.economyActionsFeature(on)
 if on then
  local ok,why=pcall(function()K.commerceActionsFeature(true);K.farmActionsFeature(true)end)
  if not ok then
   pcall(K.farmActionsFeature,false);pcall(K.commerceActionsFeature,false)
   error(why,0)
  end
 else
  local farmOK,farmError=pcall(K.farmActionsFeature,false)
  local commerceOK,commerceError=pcall(K.commerceActionsFeature,false)
  assert(farmOK,farmError);assert(commerceOK,commerceError)
 end
end
function K.feature(name,on)
 local handlers={actions=K.economyActionsFeature,ownBattle=K.invincibleFeature,playerBattle=K.playerBattleFeature,battleOneHit=K.oneHitFeature,
  battleSkills=K.tacticalGaugeFeature,armySpeed=K.movementFeature,loyalty=K.loyaltyFeature,
  recruitment=K.recruitmentFeature,goodwill=K.goodwillInstantFeature,
  covertInstant=K.covertInstantFeature,covertProposal=K.covertProposalFeature,covertChance=K.covertChanceFeature,
  instantDevelopment=K.instantDevelopment,negotiationSuccess=K.negotiationSuccessFeature,
  commerceInstant=K.commerceInstantFeature,
  maxInvestment=function(v) K.periodic('maxInvestment',v,K.facilityMaxTick) end,
  cityMax=function(v) K.periodic('cityMax',v,K.cityMaxTick) end}
 local handler=assert(handlers[name],'Unknown Taishi feature: '..tostring(name))
 if on then K.ready() end
 handler(on);K.on[name]=on or nil
end
function K.allOff()
 -- Pending native calls may be waiting for a report. Keep ownership until
 -- the game returns instead of detaching its dispatcher under a live call.
 assert(not K.nativeBusy() and not K.covertPending and not K.goodwillPending,
  NB.T('Close the current in-game report before All OFF.','ゲーム内の報告を閉じてから一括解除してください。'))
 if K.closeTreasureWizard then K.closeTreasureWizard()end
 for name,timer in pairs(K.timers) do timer.destroy();K.timers[name]=nil end
 K.covertInstantFeature(false);K.goodwillInstantFeature(false)
 for _,name in ipairs({'actions','ownBattle','playerBattle','battleOneHit','battleSkills','armySpeed','loyalty','recruitment',
   'covertProposal','instantDevelopment','cityMax','negotiationSuccess','maxInvestment','commerceInstant'}) do K.feature(name,false) end
 for _,remove in ipairs({'removeGoodwillInstant','removeCovertProposalHook','removeCovertDayHook',
  'removeCovertChanceHook','removeRecruitmentHook','removeMovementHook','removeTacticalGaugeHook',
  'removeTacticalStrengthHook','removeTacticalMoraleHook','removeSiegeHook','removeWarWillHook',
  'removeFoodHook','removeTroopHook','removeLoyaltyHook','removeCastleWorkHook','removeRepairHook',
  'removeResourceNegotiationHook','removeTradeNegotiationHook','removeNegotiationDecisionHooks',
  'removeNegotiationAccessHook','removeRoleAwardWrapper','removeFacilityLevelWrapper','removeCommerceActionsHook','removeFarmActionsHooks','removeCommerceElapsedHook','removeNative'}) do if K[remove] then K[remove]() end end
 K.on={}
end
function K.attachAndOff()
 if K.attached() then K.allOff();return end
 local pid=getProcessIDFromProcessName(K.EXE)
 assert(pid and pid~=0,NB.T('Start Taishi PK first.','先に大志PKを起動してください。'))
 if K.pid and K.pid~=pid then K.forgetEndedSession() end
 openProcess(pid);K.pid=getOpenedProcessID()
 assert(K.pid==pid and K.buildMatches(),NB.T('Unsupported Taishi executable.','対応していない大志のEXEです。'))
 if K.recoverOrphanedHooks then
  local ok,why=pcall(K.recoverOrphanedHooks)
  if not ok then K.pid=nil;error(why,0)end
 end
 NB.msg(('Attached to %s (PID %d), version %s, Steam build %s.'):format(K.EXE,pid,K.VERSION,K.STEAMBUILD),
  ('%s（PID %d）へアタッチ。バージョン%s、Steam build %s。'):format(K.EXE,pid,K.VERSION,K.STEAMBUILD))
end
function K.forgetEndedSession()
 local processes=getProcessList()
 assert(not K.pid or (not processes[K.pid] and not processes[tostring(K.pid)]),
  NB.T('The previous game process is still running. Release its features first.',
   '以前のゲームプロセスが動作中です。そのプロセスの機能を先に解除してください。'))
 if K.closeTreasureWizard then K.closeTreasureWizard()end
 -- The old process has ended: its allocations no longer exist. Do not try
 -- to unpatch or write their flags into the restarted process.
 for name,t in pairs(K.timers) do t.destroy();K.timers[name]=nil end
 for _,name in ipairs({'goodwillTimer','covertTimer','covertScanTimer'}) do
  if K[name] then K[name].destroy();K[name]=nil end
 end
 local editors={};for _,e in pairs(K.editors) do editors[#editors+1]=e.mr end
 for _,mr in ipairs(editors) do K.closeEditor(mr) end
 local clear={}
 for name,value in pairs(K) do
  if type(value)=='table' and (name:match('Hook$') or name:match('Hooks$')) then clear[#clear+1]=name end
 end
 for _,name in ipairs(clear) do K[name]=nil end
 for _,name in ipairs({'native','roleAwardWrapper','facilityLevelWrapper','goodwillPending','covertPending',
  'goodwillLast','goodwillAttempted','covertAttempted'}) do K[name]=nil end
 K.nativeDefinitions.roleAward=nil
 K.nativeDefinitions.facilityLevelChange=nil
 K.on={};K.sel={};K.editors={};K.dropdownRecords={};K.rankRows={};K.facilityRows={};K.pid=nil
end
function K.disconnect()
 if K.closeTreasureWizard then K.closeTreasureWizard()end
 if K.attached() then K.allOff() end
 local ids={};for id in pairs(K.editors) do ids[#ids+1]=id end
 for _,id in ipairs(ids) do
  local row=getAddressList().getMemoryRecordByID(id)
  if row then K.closeEditor(row) end
 end
 K.editors={};K.dropdownRecords={}
 K.pid=nil;K.sel={}
end
function K.report()
 NB.msg(('Taishi PK: EXE %s; version %s; Steam build %s; PE %08X; SizeOfImage %X; PID %s.'):format(
  K.EXE,K.VERSION,K.STEAMBUILD,K.BUILD.ts,K.BUILD.size,tostring(K.pid)))
end

end
return NB.K15
end


if NB.STEAM and NB.STEAM.profiles[4]then NB.STEAM.profiles[4].exes={'NOBU15PK_JP.exe','NOBU15PK_TC.exe'}end

NB.K15Variants={JP=createTaishiJP()}

local function taishiInstance(region)

 local all=NB.K15Variants

 if not all[region] then

  local current=NB.K15

  local ok,value=pcall(createTaishiTC)

  NB.K15=current

  assert(ok,value)

  all[region]=value

 end

 return all[region]

end

function NB.selectTaishiExecutable()

 local region,pid='JP',getProcessIDFromProcessName('NOBU15PK_JP.exe')

 if not pid or pid==0 then region='TC';pid=getProcessIDFromProcessName('NOBU15PK_TC.exe')end

 assert(pid and pid~=0,NB.T('Start Taishi PK (JP or TC) first.','先に大志PK（日本語版／繁体字版）を起動してください。'))

 local current=NB.K15

 if current.pid and (current.EXE~=('NOBU15PK_'..region..'.exe')or current.pid~=pid)then

  current.forgetEndedSession()

 end

 local selected=taishiInstance(region)

 NB.K15=selected;NB.EXE=selected.EXE;NB.MODULE=selected.EXE

 return selected,pid

end


do
local K=setmetatable({},{__index=function(_,key)return NB.K15[key]end,__newindex=function(_,key,value)NB.K15[key]=value end})
NB.GAMES[4]={'Taishi with Power Up Kit','大志 with パワーアップキット',K.EXE}
local search,player,home,open,close,feature,suffix=NB.search,NB.selectPlayer,NB.selectHomeCity,NB.openEditor,NB.closeEditor,NB.feature,NB.refreshSuffix
function NB.search(kind) if NB.game==4 then return K.search(kind) end;return search(kind) end
function NB.selectPlayer() if NB.game==4 then K.ready();return K.select('officer',assert(K.indexOf('officer',K.player()))) end;return player() end
function NB.selectHomeCity() if NB.game==4 then K.ready();return K.select('city',assert(K.indexOf('city',K.homeCity()))) end;return home() end
function NB.openEditor(mr,kind) if NB.game==4 then return K.openEditor(mr,kind) end;return open(mr,kind) end
function NB.closeEditor(mr) if NB.game==4 then return K.closeEditor(mr) end;return close(mr) end
function NB.feature(name,on) if NB.game==4 then return K.feature(name,on) end;return feature(name,on) end
function NB.refreshSuffix() if NB.game==4 then return K.refreshSuffix() end;return suffix() end
local attach=NB.attachAndConfigure
function NB.attachAndConfigure(self)
 if NB.game~=4 then return attach(self) end
 if not K.attached()then NB.selectTaishiExecutable()end
 K.attachAndOff()
 local al=getAddressList()
 for i=al.Count-1,0,-1 do
  local row=al.getMemoryRecord(i)
  if NB.NAMES[row.ID] and not NB.CONFIG_IDS[row.ID] and row.Active and row~=self then row.Active=false end
 end
end
local assign,unlock,orders=NB.assignTreasure,NB.unlockCityDevelopment,NB.reportDevelopment
function NB.assignTreasure() if NB.game==4 then return K.assignTreasure() end;return assign() end
function NB.unlockCityDevelopment() if NB.game==4 then return K.acquireAllPolicies() end;return unlock() end
function NB.reportDevelopment()
 if NB.game~=4 then return orders() end
 K.ready();local all=K.missionObjects();NB.openLuaEngine(true)
 NB.msg(('Current orders: %d.'):format(#all),('実行中の命令：%d件。'):format(#all))
 for _,item in ipairs(all) do NB.msg(('ID %d; class %X'):format(item.id,item.vt)) end
end
local release=NB.releaseGameSelection
function NB.releaseGameSelection()
 if K.pid then K.disconnect() end
 return release()
end
local shutdown=NB.shutdown
function NB.shutdown(gone)
 if K.pid then K.disconnect() end
 return shutdown(gone)
end
local environment,status,progress,scan=NB.envReport,NB.statusReport,NB.progressReport,NB.scanSelfTest
function NB.envReport() if NB.game==4 then return K.report() end;return environment() end
function NB.statusReport() if NB.game==4 then return K.report() end;return status() end
function NB.progressReport() if NB.game==4 then return end;return progress() end
function NB.scanSelfTest()
 if NB.game~=4 then return scan() end
 K.ready();local count=0
 for kind,t in pairs(K.types) do
  assert(#K.objects(kind)==t.count,'Object layout mismatch: '..kind);count=count+1
 end
 NB.msg(('Taishi object checks passed: %d arrays.'):format(count),('大志PKのオブジェクト照合完了：%d配列。'):format(count))
 return count,count
end

end

do
local K=NB.K15
local baseProfile=NB.applyProfileRecords
local baseNames
local function script(code,off)
 local enable=off and 'if not NB.userRun(function() '..code..' end) then NB.deferOff(memrec) end' or 'NB.oneShot(memrec,function() '..code..' end)'
 return '[ENABLE]\n{$lua}\nif syntaxcheck then return end\n'..enable..'\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\n'..
  (off and 'NB.userRun(function() '..off..' end)\n' or '')..'{$asm}\n'
end
local names={
 [800]={'8. Other','8. その他'},
 [7]={'1) Start Taishi PK, select this title, then ATTACH.','1) 大志PKを起動し、作品を選択してアタッチします。'},
 [19]={'2) Select an officer/city and open its editor.','2) 武将・都市を選択してエディタを開きます。'},
 [101]={'Unlimited commerce / agriculture actions','商業・農業の行動無限'},
 [206]={'Battle tactic gauge always MAX (own side)','決戦の戦法ゲージMAX（自勢力）'},
 [501]={'Assign treasures (multiple selection)...','家宝をまとめて授与（複数選択）...'},
 [602]={'Instant construction / castle works / repairs','建設・城郭工事・修復 即完了'},
 [603]={'Acquire all policies','全方策取得'},
 [604]={'Policy points MAX','施策力MAX'},
 [605]={'Current orders','実行中の命令'},
 [15001]={'Instant goodwill missions','親善 即完了'},
 [15002]={'Instant covert work missions','工作 即完了'},
 [15003]={'Secret pact success chance = 100%','密約の成功率100%'},
 [15004]={'Covert work success chance = 100%','工作の成功率100%'},
 [15006]={'Instant commerce orders','商業の命令 即完了'}}
local wanted={}
for _,id in ipairs({24,1,2,3,4,5,6,7,19,17,12,13,14,15,16,100,101,102,
 200,201,202,208,206,207,300,301,302,303,304,400,401,402,403,404,500,501,
 600,602,603,604,605,700,701,702}) do wanted[id]=true end
local extra={
 {id=15001,parent=700,name='goodwill'},
 {id=15002,parent=700,name='covertInstant'},
 {id=15003,parent=700,name='covertProposal'},
 {id=15004,parent=700,name='covertChance'},
 {id=15006,parent=600,name='commerceInstant'}}
function NB.applyProfileRecords()
 if not baseNames then
  baseNames={};for id,name in pairs(NB.NAMES) do baseNames[id]=name end
 end
 for id,name in pairs(baseNames) do NB.NAMES[id]=name end
 if NB.game~=4 then return baseProfile() end
 local definitions={}
 for _,d in ipairs(NB.RECORDS) do
  if wanted[d.id] then
   local copy={};for key,v in pairs(d) do copy[key]=v end
   if copy.id==604 then copy.script=script('NB.K15.maxPolicyPoints()') end
   definitions[#definitions+1]=copy
  end
 end
 for _,d in ipairs(extra) do
  definitions[#definitions+1]={id=d.id,parent=d.parent,group=0,manual=0,color='00A5FF',
   script=script("NB.feature('"..d.name.."',true)","NB.feature('"..d.name.."',false)")}
 end
 definitions[#definitions+1]={id=800,parent=0,group=1,manual=1,color='FFFF00',script=''}
 for _,d in ipairs(NB.RECORDS) do
  if d.id==30 then
   local copy={};for key,v in pairs(d)do copy[key]=v end
   copy.parent=800;definitions[#definitions+1]=copy;break
  end
 end
 for id,name in pairs(names) do NB.NAMES[id]=name end
 local al=getAddressList();local expected={}
 for _,d in ipairs(definitions) do expected[#expected+1]=d.id end
 local current={}
 for i=0,al.Count-1 do local row=al.getMemoryRecord(i);if NB.NAMES[row.ID] then current[#current+1]=row.ID end end
 local rebuild=#current~=#expected
 for i,id in ipairs(expected) do if current[i]~=id then rebuild=true;break end end
 if rebuild then
  for i=al.Count-1,0,-1 do
   local row=al.getMemoryRecord(i)
   if NB.NAMES[row.ID] then assert(not row.Active,'Cannot rebuild an active feature');row.destroy() end
  end
 end
 for _,d in ipairs(definitions) do
  local row=al.getMemoryRecordByID(d.id)
  if not row then
   row=al.createMemoryRecord();row.ID=d.id
   if d.group==1 then row.IsGroupHeader=true;row.Type=vtByte else row.Type=vtAutoAssembler;row.Script=d.script end
   row.Color=d.color~='' and tonumber(d.color,16) or -2147483640
   row.Options=d.manual==1 and '[moManualExpandCollapse]' or '[]'
  end
  if d.parent~=0 and (not row.Parent or row.Parent.ID~=d.parent) then row.appendToEntry(assert(al.getMemoryRecordByID(d.parent))) end
 end
 NB.applyLang()
 for i=0,al.Count-1 do
  local row=al.getMemoryRecord(i)
  if row.Count&gt;0 then
   local p=row;local setting=false
   while p do if p.ID==NB.ID_TOP0 then setting=true;break end;p=p.Parent end
   row.Collapsed=not setting
  end
 end
end

end

end

-- END TAISHI PROFILE MODULES

-- BEGIN AWAKENING PROFILE MODULES

do
NB.K16=NB.K16 or {on={},hooks={},timers={}}
local K=NB.K16
K.exe='NOBU16PK.exe'
K.types={
 officer={off=0xE8,count=6133,stride=0x270,vt=0x13C39B0},
 clan={off=0xC090,count=188,stride=0x670,vt=0x13C3AC0},
 district={off=0xC670,count=350,stride=0x120,vt=0x13C3B08},
 city={off=0xD170,count=350,stride=0x658,vt=0x13C3A78},
 army={off=0xDC60,count=710,stride=0x388,vt=0x13D0E58},
 treasure={off=0xF470,count=200,stride=0x48,vt=0x13D0628},
 county={off=0x10980,count=1883,stride=0x2C0,vt=0x13D0700},
 facility={off=0x2BCB0,count=50,stride=0x80,vt=0x13D19D0}}
function K.base() return getAddressSafe(K.exe) end
function K.root()
 local b=K.base();if not b then return nil end
 local pe=readInteger(b+0x3C)
 if not pe or pe&lt;0x40 or pe&gt;=0x1000 or readInteger(b+pe)~=0x4550
  or readInteger(b+pe+8)~=0x68495A9E or readInteger(b+pe+0x50)~=0x2653000 then return nil end
 local r=readQword(b+0x213CB08)
 if not r or r&lt;0x10000 or readQword(r)~=b+0x13D07E8 then return nil end
 return r
end
function K.object(kind,index)
 local t=K.types[kind];local r=K.root()
 if not t or not r or type(index)~='number' or index%1~=0 or index&lt;0 or index&gt;=t.count then return nil end
 local first=readQword(r+t.off);local p=readQword(r+t.off+index*8)
 if not first or not p or p~=first+index*t.stride or readQword(p)~=K.base()+t.vt then return nil end
 return p
end
function K.indexOf(kind,p)
 local t=K.types[kind];local r=K.root()
 if not t or not r or not p then return nil end
 local first=readQword(r+t.off);if not first then return nil end
 local i=(p-first)/t.stride
 if K.object(kind,i)==p then return i end
end
function K.scenario()
 local r=K.root();if not r then return nil end
 local s=readQword(r+0x1B260)
 if s and s&gt;=0x10000 and readQword(s)==K.base()+0x13D1070 then return s end
end
function K.player()
 local s=K.scenario();if not s then return nil end
 local p=readQword(s+0x1047E0)
 if K.indexOf('officer',p) then return p end
end
function K.clan()
 local p=K.player();if not p then return nil end
 local d=readQword(p+0x88);if not K.indexOf('district',d) then return nil end
 local generation=readInteger(p+0x90)
 if not generation or generation==0 or generation~=readInteger(d+0x114) then return nil end
 local c=readQword(d+0x10)
 if K.indexOf('clan',c) and readQword(c+0x30)==p then return c end
end
function K.homeCity()
 local officer=K.player();if not officer then return nil end
 local city=readQword(officer+0xA0)
 if K.indexOf('city',city) then return city end
end
function K.key()
 local r,s,p=K.root(),K.scenario(),K.player()
 if r and s and p then return tostring(getOpenedProcessID())..':'..r..':'..s..':'..p end
end
function K.stringEntry(index,secondary)
 if type(index)~='number' or index&lt;0 or index&gt;(secondary and 0x13EB or 0x7221) or index%1~=0 then return '' end
 local b=K.base();if not b then return '' end
 local t=readQword(b+0x21AB500);if not t or t&lt;0x10000 then return '' end
 t=readQword(t+(secondary and 0x90 or 0x80));if not t or t&lt;0x10000 then return '' end
 local stride,offset=readSmallInteger(t+0xA),readInteger(t+0xC)
 if not stride or stride&lt;4 or stride&gt;0x100 or not offset or offset&lt;0x10 or offset&gt;0x100000 then return '' end
 local pool=t+offset;local off=readInteger(pool+index*stride)
 if not off or off&lt;0 or off&gt;0x4000000 then return '' end
 return readString(pool+off,256,true) or ''
end
function K.namePart(i)
 if not i or i&lt;0 or i&gt;0x22DB then return '' end
 if i&lt;=0xD03 then return K.stringEntry(i) end
 if i&lt;=0xD67 then return K.stringEntry(i-0xD04+0x1A08) end
 if i&lt;=0x11D8 then return K.stringEntry(i-0xD68+0x1AD0) end
 local s=K.scenario();if not s then return '' end
 if i&lt;=0x12E6 then return readString(s+0x198+(i-0x11D9)*30,30,true) or '' end
 if i&lt;=0x13AE then return readString(s+0x40E2+(i-0x12E7)*30,30,true) or '' end
 if i&lt;=0x1B7E then return readString(s+0xFD8E+(i-0x13AF)*30,30,true) or '' end
 local countyIndex=i-0x1B7F
 if countyIndex==0x75B then return K.stringEntry(0x7768-0x7223,true) end
 if countyIndex==0x75C then return K.stringEntry(0x776A-0x7223,true) end
 local county=K.object('county',countyIndex)
 if county then
  local city=readQword(county+0x168)
  if K.indexOf('city',city) then
   local district=readQword(city+0x18);local generation=readInteger(city+0x20)
   if K.indexOf('district',district) and generation and generation~=0
    and generation==readInteger(district+0x114) then return K.name('city',city) end
  end
  return K.name('county',county)
 end
 return ''
end
function K.name(kind,p)
 if not K.indexOf(kind,p) then return '' end
 if kind=='officer' then return K.namePart(readSmallInteger(p+8))..K.namePart(readSmallInteger(p+10)) end
 if kind=='army' then
  local leader=K.armyLeader and K.armyLeader(p)
  return leader and K.name('officer',leader) or ''
 end
 if kind=='city' then local i=readInteger(p+8);if i and i&gt;=0 and i&lt;=0x187 then return K.stringEntry(i+0x23BF) end end
 if kind=='county' then
  local i=readInteger(p+0x138)
  if i and i&gt;=0 and i&lt;=0x7DD then return K.stringEntry(i+0x26DB) end
 end
 if kind=='treasure' then
  local i=readSmallInteger(p+8)
  if not i or i&lt;0 or i&gt;0xC7 then return '' end
  if i&lt;0xB4 then return K.stringEntry(i+0x3727) end
  local s=K.scenario()
  return s and (readString(s+0xEEC7A+(i-0xB4)*0x2E,0x2E,true) or '') or ''
 end
 return ''
end

end

do
local K=NB.K16
function K.buildMatches()
 local b=K.base();if not b then return false end
 local pe=readInteger(b+0x3C)
 return pe and pe&gt;=0x40 and pe&lt;0x1000 and readInteger(b+pe)==0x4550
  and readInteger(b+pe+8)==0x68495A9E and readInteger(b+pe+0x50)==0x2653000 or false
end
function K.context()
 local pid=getOpenedProcessID()
 if not pid or pid==0 or not K.buildMatches() then return nil end
 local b=K.base();local r=K.root();if not r then return nil end
 local s=readQword(r+0x1B260)
 if not s or s&lt;0x10000 or readQword(s)~=b+0x13D1070 then return nil end
 local p=readQword(s+0x1047E0)
 local index=K.indexOf('officer',p);if index==nil then return nil end
 if pid~=getOpenedProcessID() or b~=K.base() or readQword(b+0x213CB08)~=r
  or readQword(r+0x1B260)~=s or readQword(s+0x1047E0)~=p then return nil end
 return {pid=pid,base=b,root=r,scenario=s,player=p,index=index,
  key=('%d:%X:%X:%X:%X'):format(pid,b,r,s,p)}
end
function K.key()
 local c=K.context();return c and c.key
end
function K.ready()
 assert(NB.game==5,'Select Awakening first.')
 assert(K.pid and K.pid==getOpenedProcessID(),'Attach to Awakening first.')
 local c=assert(K.context(),'Load an Awakening scenario first.')
 assert(c.key==K.sessionKey,'The loaded scenario changed. Attach again.')
 return c
end
function K.objects(kind)
 local t=assert(K.types[kind],'Unknown Awakening object type')
 local c=K.ready();local first=readQword(c.root+t.off);local result={}
 if not first or first&lt;0x10000 then return result end
 for i=0,t.count-1 do
  local p=readQword(c.root+t.off+i*8)
  if p==first+i*t.stride and readQword(p)==c.base+t.vt then
   result[#result+1]={index=i,address=p}
  end
 end
 assert(K.key()==c.key,'The loaded scenario changed during enumeration.')
 return result
end
function K.bind()
 local c=assert(K.context(),'Load an Awakening scenario first.')
 assert(not K.native or K.native.pid==c.pid,'Release the previous Awakening session first.')
 K.pid=c.pid;K.sessionKey=c.key
 return c
end

end

do
local K=NB.K16
function K.armyActive(p)
 if K.indexOf('army',p)==nil then return false end
 local flags=readInteger(p+0x2F4);local generation=readInteger(p+0x374)
 return flags~=nil and (flags&amp;1)~=0 and generation~=nil and generation~=0
end
function K.armyLeader(p)
 if not K.armyActive(p) then return nil end
 local h=readQword(p+0x50);if not h or h&lt;0x10000 then return nil end
 local slot=readInteger(h);local b=K.base()
 local pool=readQword(b+0x21AB410);local limit=readInteger(b+0x21AB440)
 if not slot or not limit or slot&lt;0 or slot&gt;=limit or not pool or pool&lt;0x10000 then return nil end
 local node=readQword(pool+slot*8);if not node or node&lt;0x10000 then return nil end
 local officer=readQword(node)
 if K.indexOf('officer',officer)~=nil then return officer end
end
function K.armyDistrict(p)
 if not K.armyActive(p) then return nil end
 local override=readQword(p+0x238)
 if K.indexOf('district',override)~=nil then
  local generation=readInteger(override+0x114)
  if generation and generation~=0 and readQword(override+0x10)~=0 then return override end
 end
 local district=readQword(p+8)
 if K.indexOf('district',district)==nil then return nil end
 local generation=readInteger(p+0x10)
 if generation and generation~=0 and generation==readInteger(district+0x114) then return district end
end
function K.ownsArmy(p)
 local district=K.armyDistrict(p)
 return district~=nil and readQword(district+0x10)==K.clan()
end
function K.armies(ownedOnly)
 local out={}
 for _,v in ipairs(K.objects('army')) do
  if K.armyActive(v.address) and (not ownedOnly or K.ownsArmy(v.address)) then
   local leader=K.armyLeader(v.address)
   out[#out+1]={index=v.index,address=v.address,leader=leader,
    name=leader and K.name('officer',leader) or tostring(v.index),
    soldiers=readInteger(v.address+0x18),generation=readInteger(v.address+0x374)}
  end
 end
 return out
end

end

do
-- Calls execute on the game window thread; pending calls retain their code.
local K=NB.K16
K.nativeDefinitions={
 officerAbility0={rva=0x630230,bytes='88 91 DE 00 00 00 C3 CC CC CC CC CC CC CC CC CC',kind='officer',after='officerRecalculate'},
 officerAbility1={rva=0x627DD0,bytes='88 91 DF 00 00 00 C3 CC CC CC CC CC CC CC CC CC',kind='officer',after='officerRecalculate'},
 officerAbility2={rva=0x627F60,bytes='88 91 E0 00 00 00 C3 CC CC CC CC CC CC CC CC CC',kind='officer',after='officerRecalculate'},
 officerAbility3={rva=0x62E010,bytes='88 91 E1 00 00 00 C3 CC CC CC CC CC CC CC CC CC',kind='officer',after='officerRecalculate'},
 officerRecalculate={rva=0x602320,bytes='40 57 48 83 EC 20 0F B6 91 E1 00 00 00 33 C0 44',kind='officer'},
 officerDeathYear={rva=0x62E020,bytes='66 89 91 DC 00 00 00 C3 CC CC CC CC CC CC CC CC',kind='officer'},
 officerDeathEdited={rva=0x627DE0,bytes='48 83 A1 00 02 00 00 FB 8B C2 83 E0 01 48 C1 E0',kind='officer'},
 officerMerit={rva=0x62C2C0,bytes='81 FA FF FF 00 00 77 06 89 91 E4 00 00 00 C3 CC',kind='officer'}}
K.nativeDefinitions.officerDeathYear.after='officerDeathEdited'
K.nativeDefinitions.officerDeathYear.afterArgument=1
K.nativeDefinitions.officerMerit.after='officerRecalculate'
K.nativeDefinitions.officerMerit.postFlagsOffset=0x200
K.nativeDefinitions.officerMerit.postFlagsMask=0x4000000000
K.nativeDefinitions.districtMoneySet={rva=0x5849C0,bytes='48 83 EC 28 48 8B 05 0D 08 73 01 48 33 C4 48 89',kind='district',relativeOffset=0x18}
K.nativeDefinitions.treasureTransfer={rva=0x69EDF0,bytes='48 89 5C 24 20 55 56 57 41 56 41 57 48 83 EC 30',kind='officer',argumentType='treasure',argument2From=0x20}
K.nativeDefinitions.citySoldiersSet={rva=0x62A110,bytes='81 FA 20 A1 07 00 77 03 89 51 48 C3 CC CC CC CC',kind='city'}
K.nativeDefinitions.citySuppliesSet={rva=0x62A9A0,bytes='81 FA 40 42 0F 00 77 06 89 91 E4 00 00 00 C3 CC',kind='city'}
K.nativeDefinitions.cityDurabilitySet={rva=0x62A170,bytes='48 89 5C 24 08 57 48 83 EC 20 8B FA 48 8B D9 E8',kind='city'}
K.nativeDefinitions.cityDurabilityMax={rva=0x59C100,bytes='48 89 5C 24 10 48 89 6C 24 18 48 89 74 24 20 57',kind='city'}
K.nativeDefinitions.armySoldiersSet={rva=0x6D5CE0,bytes='81 FA 20 A1 07 00 7C 12 C7 41 18 20 A1 07 00 C7',kind='army'}
K.nativeDefinitions.armyProvisionsSet={rva=0x6D6480,bytes='81 FA 50 C3 00 00 77 07 66 89 91 D8 02 00 00 C3',kind='army'}
K.nativeDefinitions.districtLaborChange={rva=0x5A0C30,bytes='48 85 C9 0F 84 26 01 00 00 56 41 56 41 57 48 83',kind='district'}
K.nativeDefinitions.facilityUpgrade={rva=0x589A80,bytes='48 85 C9 0F 84 4F 08 00 00 48 89 5C 24 18 55 56',kind='city',argumentType='facility'}
K.nativeDefinitions.constructionFinish={rva=0x62C380,bytes='85 D2 79 08 C7 41 68 00 00 00 00 C3 B8 3F 42 0F',kind='city',cityOrder=true,after='constructionUpdate'}
K.nativeDefinitions.constructionUpdate={rva=0x6528C0,bytes='40 56 48 83 EC 20 48 8B 01 48 8B F1 FF 50 48 83',kind='city'}
K.nativeDefinitions.officerGrade={rva=0x62BF70,bytes='85 D2 79 04 33 C0 EB 0C B8 04 00 00 00 3B D0 0F',kind='officer',after='officerRecalculate'}
K.nativeDefinitions.officerVoice={rva=0x630610,bytes='48 81 A1 00 02 00 00 3F F8 FF FF 8B C2 83 E0 1F',kind='officer'}
K.nativeDefinitions.officerIdeology={rva=0x62C9A0,bytes='83 FA 03 77 07 66 89 91 7C 01 00 00 C3 CC CC CC',kind='officer',after='officerRecalculate'}
K.nativeDefinitions.officerOrigin={rva=0x62E180,bytes='83 FA 0C 77 06 88 91 7E 01 00 00 C3 CC CC CC CC',kind='officer',after='officerRecalculate'}
K.nativeDefinitions.officerFaith={rva=0x62E160,bytes='83 FA 03 77 06 88 91 7F 01 00 00 C3 CC CC CC CC',kind='officer',after='officerRecalculate'}
K.nativeDefinitions.officerLoyaltyFactor={rva=0x627FB0,bytes='85 D2 0F 88 96 00 00 00 48 83 EC 28 48 8B 05 15',kind='officer'}
K.nativeDefinitions.officerTrait={rva=0x62FFB0,bytes='83 FA 03 73 73 48 89 5C 24 08 48 89 74 24 10 57',kind='officer',argumentType='trait',argumentPosition=2,argumentNullable=true,after='officerRecalculate'}
K.nativeDefinitions.officerConservator={rva=0x626790,bytes='48 89 5C 24 08 48 89 74 24 10 57 48 83 EC 20 33',kind='officer',argumentType='conservator',argumentNullable=true,after='officerRecalculate'}
K.nativeDefinitions.officerOverseer={rva=0x6301E0,bytes='48 89 5C 24 08 48 89 74 24 10 57 48 83 EC 20 33',kind='officer',argumentType='overseer',argumentNullable=true,after='officerRecalculate'}
K.nativeDefinitions.cityFacilityLevel={rva=0x626830,bytes='48 83 EC 28 83 FA 0A 73 3A 41 83 F8 04 77 34 48',kind='city'}
K.nativeDefinitions.cityFacilityType={rva=0x6267E0,bytes='83 FA 0A 73 3B 53 48 83 EC 20 41 8D 40 01 41 8B',kind='city'}
K.nativeDefinitions.cityFacilityRecalculate={rva=0x642000,bytes='48 89 5C 24 18 48 89 6C 24 20 56 57 41 54 41 56',kind='city',argumentType='facility'}
K.nativeDefinitions.cityRecalculate={rva=0x63CD10,bytes='48 85 C9 0F 84 80 01 00 00 48 89 5C 24 08 48 89',kind='city'}
K.nativeDefinitions.countyDevelop={rva=0x65E450,bytes='40 55 41 55 41 57 48 8D 6C 24 F0 48 81 EC 10 01',kind='county'}
K.nativeDefinitions.countyDevelopmentRead={rva=0x6864E0,bytes='48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57',kind='county'}
K.nativeDefinitions.countyRiceRead={rva=0x67FCF0,bytes='40 53 41 54 41 55 48 81 EC 90 00 00 00 48 8B 05',kind='county'}
function K.nativeBusy()
 local n=K.native;if not n or n.pid~=getOpenedProcessID() then return false end
 local s=readInteger(n.q);return s==1 or s==2
end
function K.installNative()
 if K.native then return end
 K.ready()
 local at=K.base()+0x9C54A0
 local original={0x48,0x83,0xEC,0x38,0x81,0xFA,0x0D,0x01,0x00,0x00}
 local current=readBytes(at,#original,true)
 for i,v in ipairs(original) do
  assert(current and current[i]==v,NB.T(
   'The game-call dispatcher is occupied by another table or an earlier CE session.',
   'ゲーム内呼び出し箇所に別テーブルまたは以前のCEの処理が残っています。'))
 end
 local symbol=('nb16Native_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=([[
[ENABLE]
assert(%X,48 83 EC 38 81 FA 0D 01 00 00)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
label(cancel)
label(done)
label(guarded)
label(argumentsOK)
label(afterCall)
label(valueReady)
label(secondArgumentReady)
label(postFlagsDone)
label(targetValid)
label(generationValid)
label(orderLoop)
label(orderFound)
label(orderReady)
label(countyOrderReady)
@N@:
dq 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
@N@+100:
cmp edx,83D6
jne original
mov rax,@N@
cmp r8,rax
jne original
push rbx
sub rsp,40
mov rbx,@N@
cmp dword ptr [rbx],1
jne done
mov rax,[%X]
cmp rax,[rbx+40]
jne cancel
test rax,rax
jz cancel
mov rdx,[rax+1B260]
cmp rdx,[rbx+48]
jne cancel
test rdx,rdx
jz cancel
mov rdx,[rdx+1047E0]
cmp rdx,[rbx+50]
jne cancel
mov rdx,[rbx+58]
mov r9,[rbx+60]
mov rcx,[rax+rdx]
test rcx,rcx
jz cancel
add rdx,rax
mov rcx,[rdx+r9*8]
cmp rcx,[rbx+10]
jne cancel
test rcx,rcx
jz cancel
mov rdx,[rcx]
cmp rdx,[rbx+68]
jne cancel
targetValid:
mov rax,[rbx+B0]
test rax,rax
jz generationValid
mov edx,[rcx+rax]
cmp edx,[rbx+B8]
jne cancel
generationValid:
mov rax,[rbx+70]
test rax,rax
jz guarded
movzx edx,byte ptr [rcx+rax]
cmp edx,[rbx+78]
jne cancel
guarded:
mov r10,[rbx+80]
test r10,r10
jz argumentsOK
mov rax,[rbx+40]
add rax,r10
mov r10d,[rbx+88]
mov rax,[rax+r10*8]
mov r10d,[rbx+8C]
cmp rax,[rbx+r10]
jne cancel
test rax,rax
jz cancel
mov r10,[rax]
cmp r10,[rbx+90]
jne cancel
argumentsOK:
mov [rbx+F0],rcx
mov r11,[rbx+E0]
test r11,r11
jz orderReady
mov rax,[rcx+18]
cmp rax,[rbx+F8]
jne cancel
mov r10,[rcx+470]
test r10,r10
jz cancel
mov rax,[r10]
mov edx,100
orderLoop:
cmp rax,r10
je cancel
test rax,rax
jz cancel
cmp [rax+10],r11
je orderFound
mov rax,[rax]
dec edx
jnz orderLoop
jmp cancel
orderFound:
mov rax,[r11]
cmp rax,[rbx+E8]
jne cancel
cmp [r11+30],rcx
jne cancel
cmp dword ptr [r11+8],1
jne cancel
mov eax,[r11+70]
cmp rax,[rbx+60]
jne cancel
mov rcx,r11
mov [rbx+F0],rcx
orderReady:
mov rax,[rbx+38]
test rax,rax
jz countyOrderReady
cmp byte ptr [rcx+104],al
jne cancel
shr rax,8
cmp byte ptr [rcx+106],al
jne cancel
mov r10,[rcx+8]
cmp r10,[rbx+F8]
jne cancel
mov r11,[r10+18]
cmp r11,[rbx+E8]
jne cancel
mov eax,[r10+20]
test eax,eax
jz cancel
cmp eax,[r11+114]
jne cancel
mov r11,[r11+10]
cmp r11,[rbx+C0]
jne cancel
mov byte ptr [rcx+105],0
countyOrderReady:
mov dword ptr [rbx],2
mov rdx,[rbx+18]
mov rax,[rbx+A0]
test rax,rax
jz valueReady
sub edx,[rcx+rax]
valueReady:
mov r8,[rbx+20]
mov rax,[rbx+A8]
test rax,rax
jz secondArgumentReady
mov r8,[rdx+rax]
secondArgumentReady:
mov r9,[rbx+28]
mov qword ptr [rsp+20],0
mov qword ptr [rsp+28],0
call qword ptr [rbx+8]
mov [rbx+30],rax
mov rax,[rbx+C8]
test rax,rax
jz postFlagsDone
mov rcx,[rbx+10]
mov rdx,[rbx+D8]
not rdx
and [rcx+rax],rdx
mov rdx,[rbx+D0]
or [rcx+rax],rdx
postFlagsDone:
mov rax,[rbx+98]
test rax,rax
jz afterCall
mov rcx,[rbx+F0]
mov rdx,[rbx+C0]
call rax
afterCall:
mov dword ptr [rbx],3
jmp done
cancel:
mov dword ptr [rbx],4
done:
add rsp,40
pop rbx
xor eax,eax
ret
original:
sub rsp,38
cmp edx,10D
jmp %X
%X:
jmp @N@+100
nop 5
[DISABLE]
%X:
db 48 83 EC 38 81 FA 0D 01 00 00
unregistersymbol(@N@)
// Keep code until process exit: completion state is published before the
// dispatcher epilogue, so a timed-out sender must not free an in-flight tail.
]]):format(at,at,K.base()+0x213CB08,at+10,at,at):gsub('@N@',symbol)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 K.native={q=assert(getAddressSafe(symbol)),script=script,info=info,pid=K.pid,
  buffer=assert(allocateSharedMemoryLocal(symbol..'_local',4096)),site=at}
 K.native.installed=assert(readBytes(at,10,true))
end
function K.nativeCall(name,kind,index,...)
 K.ready();local d=assert(K.nativeDefinitions[name],'Unknown N16 operation')
 assert(d.kind==kind,'N16 operation target mismatch')
 local p=assert(K.object(kind,index),'N16 object unavailable')
 local expected={};for b in d.bytes:gmatch('%x%x') do expected[#expected+1]=tonumber(b,16) end
 local actual=readBytes(K.base()+d.rva,#expected,true);assert(actual,'Unreadable N16 method')
 local matches=true
 for i,b in ipairs(expected) do if actual[i]~=b then matches=false;break end end
 assert(matches or (K.ownedMethodPatch and K.ownedMethodPatch(d.rva,actual,expected)),
  'N16 method code changed: '..name)
 K.installNative();assert(not K.nativeBusy(),'Previous N16 operation is pending')
 local n=K.native;local q=n.q;local args={...};assert(#args&lt;=3,'Too many N16 arguments')
 if d.cityOrder then
  assert(K.ownsObject('city',p),'N16 city owner changed')
  local order=assert(K.findConstruction(index,args[2]),'N16 construction no longer active')
  writeQword(q+0xE0,order);writeQword(q+0xE8,K.base()+0x1376AE0)
  writeQword(q+0xF8,readQword(p+0x18))
  args[2]=0
 else writeQword(q+0xE0,0);writeQword(q+0xE8,0) end
 writeQword(q+8,K.base()+d.rva);writeQword(q+0x10,p)
 for i=1,3 do writeQword(q+0x10+i*8,args[i] or 0) end
 writeQword(q+0x40,K.root());writeQword(q+0x48,K.scenario());writeQword(q+0x50,K.player())
 writeQword(q+0x58,K.types[kind].off);writeQword(q+0x60,index)
 writeQword(q+0x68,K.base()+K.types[kind].vt)
 writeQword(q+0x70,d.guardByte and d.guardByte[1] or 0);writeInteger(q+0x78,d.guardByte and d.guardByte[2] or 0)
 if d.argumentType and not (d.argumentNullable and args[d.argumentPosition or 1]==0) then
  local t=assert(K.types[d.argumentType]);local argumentIndex=assert(K.indexOf(d.argumentType,args[d.argumentPosition or 1]),'N16 argument object unavailable')
  writeQword(q+0x80,t.off);writeQword(q+0x88,argumentIndex);writeInteger(q+0x8C,0x10+8*(d.argumentPosition or 1));writeQword(q+0x90,K.base()+t.vt)
 else writeQword(q+0x80,0) end
 if d.after then
  local follow=assert(K.nativeDefinitions[d.after])
  local bytes=readBytes(K.base()+follow.rva,16,true)
  local pos=0;for b in follow.bytes:gmatch('%x%x') do
   pos=pos+1;assert(bytes and bytes[pos]==tonumber(b,16),'N16 update method changed')
  end
  writeQword(q+0x98,K.base()+follow.rva)
 else writeQword(q+0x98,0) end
 writeQword(q+0xA0,d.relativeOffset or 0)
 writeQword(q+0xA8,d.argument2From or 0)
 writeQword(q+0xC0,d.afterArgument or 0)
 writeQword(q+0xC8,d.postFlagsOffset or 0)
 writeQword(q+0xD0,d.postFlagsMask or 0)
 writeQword(q+0xD8,d.postFlagsClear or 0)
 if d.cityOrder then
  writeQword(q+0xB0,0x20);writeInteger(q+0xB8,readInteger(p+0x20))
 elseif kind=='army' then
  assert(K.armyActive(p),'N16 army is no longer active')
  writeQword(q+0xB0,0x374);writeInteger(q+0xB8,readInteger(p+0x374))
 else writeQword(q+0xB0,0);writeInteger(q+0xB8,0) end
 writeQword(q+0x38,0)
 if d.countyOrder then
  local county,slot,definition=K.countyWork(index)
  assert(county==p,'N16 county work changed')
  local city=readQword(p+8)
  assert(K.ownsObject('city',city),'N16 county owner changed')
  writeQword(q+0x38,0x10000+slot+definition*256)
  writeQword(q+0xF8,city);writeQword(q+0xE8,readQword(city+0x18))
  writeQword(q+0xC0,K.clan())
 end
 assert(K.key()==K.sessionKey,'N16 scenario changed before execution')
 writeInteger(q,1)
 local sent=0;local cached=n.window
 local function send(w)
  if getWindowProcessID(w)==K.pid and executeCodeLocalEx('user32.IsWindowVisible',w)~=0 then
   executeCodeLocalEx('user32.SendMessageTimeoutW',w,0x83D6,q,0,2,2000,n.buffer);sent=sent+1
   if readInteger(q)~=1 then n.window=w;return true end
  end
  return false
 end
 if not cached or not send(cached) then
  local w=executeCodeLocalEx('user32.GetTopWindow',0)
  for _=1,10000 do
   if not w or w==0 then break end
   if w~=cached and send(w) then break end
   w=getWindow(w,2)
  end
 end
 local state=readInteger(q)
 if (d.cityOrder or d.allowPending) and state==2 then return nil,'pending' end
 assert(state==3,('N16 operation failed (%s; state %s; windows %d)'):format(name,tostring(state),sent))
 return readQword(q+0x30)
end
function K.removeNative()
 local n=K.native;if not n then return end
 assert(not K.nativeBusy(),'Pending N16 operation must retain its dispatcher')
 if n.pid==getOpenedProcessID() and K.buildMatches() then
  local b=readBytes(n.site,10,true);assert(b,'Cannot read N16 dispatcher')
  for i,v in ipairs(n.installed) do assert(b[i]==v,'N16 dispatcher ownership changed') end
  assert((K.assemble or autoAssemble)(n.script,n.info),'Cannot restore N16 dispatcher')
 end
 K.native=nil
end

end

do
local K=NB.K16
K.battleSites={
 soldierSet={rva=0x6D5CC0,bytes='81 FA 20 A1 07 00',length=6,
  change='cmp edx,[rcx+18]\njge original\nmov edx,[rcx+18]',
  original='cmp edx,7A120'},
 soldierDamage={rva=0x6D72D0,bytes='8B 41 18 2B C2',length=5,
  change='test edx,edx\njle original\nxor edx,edx',
  original='mov eax,[rcx+18]\nsub eax,edx'},
 provisionsSet={rva=0x6D6480,bytes='81 FA 50 C3 00 00',length=6,
  change='movzx eax,word ptr [rcx+2D8]\ncmp edx,eax\njge original\nmov edx,eax',
  original='cmp edx,C350'}}
function K.battleScript(name,symbol,definition)
 local d=assert(definition or K.battleSites[name]);local c=K.ready()
 local clan=assert(K.clan());local at=c.base+d.rva
 local script=([[
[ENABLE]
assert(%X,%s)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(original)
label(baseDistrict)
label(districtReady)
@N@:
pushfq
push rax
push r10
push r11
mov rax,[%X]
mov r10,%X
cmp rax,r10
jne original
mov rax,[rax+1B260]
mov r10,%X
cmp rax,r10
jne original
mov rax,[rax+1047E0]
mov r10,%X
cmp rax,r10
jne original
mov rax,%X
mov r11,[rax+DC60]
cmp rcx,r11
jb original
add r11,9CB30
cmp rcx,r11
jae original
mov rax,%X
cmp [rcx],rax
jne original
test byte ptr [rcx+2F4],1
jz original
cmp dword ptr [rcx+374],0
je original
mov r10,[rcx+238]
mov rax,%X
mov r11,[rax+C670]
cmp r10,r11
jb baseDistrict
add r11,189C0
cmp r10,r11
jae baseDistrict
mov rax,%X
cmp [r10],rax
jne baseDistrict
cmp dword ptr [r10+114],0
je baseDistrict
cmp qword ptr [r10+10],0
je baseDistrict
jmp districtReady
baseDistrict:
mov r10,[rcx+8]
mov rax,%X
mov r11,[rax+C670]
cmp r10,r11
jb original
add r11,189C0
cmp r10,r11
jae original
mov rax,%X
cmp [r10],rax
jne original
mov eax,[rcx+10]
test eax,eax
jz original
cmp eax,[r10+114]
jne original
districtReady:
mov rax,%X
cmp [r10+10],rax
jne original
%s
original:
pop r11
pop r10
pop rax
popfq
%s
jmp %X
%X:
jmp @N@
%s
[DISABLE]
%X:
db %s
unregistersymbol(@N@)
// The trampoline remains allocated until process exit for in-flight calls.
]]):format(at,d.bytes,at,c.base+0x213CB08,c.root,c.scenario,c.player,
 c.root,c.base+K.types.army.vt,c.root,c.base+K.types.district.vt,
 c.root,c.base+K.types.district.vt,clan,d.change,
 d.original,at+d.length,at,d.length&gt;5 and ('nop '..(d.length-5)) or '',at,d.bytes)
 return script:gsub('@N@',symbol)
end
function K.installBattleHook(name)
 K.ready();K.battleHooks=K.battleHooks or {}
 if K.battleHooks[name] then return end
 K.battleSerial=(K.battleSerial or 0)+1
 local script=K.battleScript(name,'nb16Battle_'..name..'_'..K.battleSerial)
 local ok,info=(K.assemble or autoAssemble)(script)
 assert(ok,tostring(info))
 local d=K.battleSites[name];local site=K.base()+d.rva
 K.battleHooks[name]={script=script,info=info,site=site,pid=K.pid,
  installed=assert(readBytes(site,d.length,true))}
end
function K.removeBattleHook(name)
 local h=K.battleHooks and K.battleHooks[name];if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.site,#h.installed,true))
  for i,b in ipairs(h.installed) do assert(bytes[i]==b,'N16 battle hook ownership changed') end
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N16 battle hook')
 end
 K.battleHooks[name]=nil
end
function K.ownedMethodPatch(rva,actual,expected)
 for name,h in pairs(K.battleHooks or {}) do
  local d=K.battleSites[name]
  if d.rva==rva and h.pid==getOpenedProcessID() and h.site==K.base()+rva then
   local original={}
   for b in d.bytes:gmatch('%x%x') do original[#original+1]=tonumber(b,16) end
   for i=1,#expected do
    if i&lt;=#original then
     if expected[i]~=original[i] or actual[i]~=h.installed[i] then return false end
    elseif actual[i]~=expected[i] then return false end
   end
   return true
  end
 end
 return false
end

end

do
local K=NB.K16
K.movementSite={rva=0x7444B5,bytes='F3 41 0F 58 46 38',length=6,
 original='addss xmm0,[r14+38]'}
function K.movementScript(symbol)
 local d=K.movementSite
 local change=([[
mov r10,[r14+18]
test r10,r10
jz original
mov eax,[r10]
imul rax,rax,50
mov r10,%X
mov r10,[r10]
test r10,r10
jz original
mov r11,%X
mov r11,[r11]
cmp r11,r10
jbe original
add rax,r10
jc original
cmp rax,r11
jae original
lea r10,[rax+50]
cmp r10,r11
ja original
mov r10d,[rax+0C]
test r10d,r10d
jle original
cmp r10d,7F800000
jae original
mov r11d,[r14+38]
test r11d,r11d
js original
cmp r11d,r10d
jae original
movss xmm0,[rax+0C]
subss xmm0,[r14+38]
]]):format(K.base()+0x1CFE360,K.base()+0x1CFE368)
 local script=K.battleScript('movement',symbol,{rva=d.rva,bytes=d.bytes,
  length=d.length,original=d.original,change=change})
 script=script:gsub('push r11\n','push r11\npush rcx\nmov rcx,[r14]\n',1)
 return script:gsub('original:\npop r11','original:\npop rcx\npop r11',1)
end
function K.setMovement(enabled)
 K.ready()
 if not enabled then
  K.setSiegeProtection(false,'speed')
  local h=K.movementHook
  if h then
   if h.pid==getOpenedProcessID() and K.buildMatches() then
    local bytes=assert(readBytes(h.site,#h.installed,true))
    for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N16 movement hook ownership changed') end
    assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N16 movement hook')
   end
   K.movementHook=nil
  end
  K.on.armySpeed=nil
  return
 end
 K.setSiegeProtection(true,'speed')
 if K.movementHook then K.on.armySpeed=true;return end
 K.movementSerial=(K.movementSerial or 0)+1
 local script=K.movementScript('nb16Movement_'..K.movementSerial)
 local ok,info=(K.assemble or autoAssemble)(script)
 if not ok then K.setSiegeProtection(false,'speed');error(tostring(info),0) end
 local at=K.base()+K.movementSite.rva
 K.movementHook={script=script,info=info,site=at,pid=K.pid,
  installed=assert(readBytes(at,K.movementSite.length,true))}
 K.on.armySpeed=true
end

end

do
local K=NB.K16
function K.prepareSiegeRefill()
 if K.siegeRefill and K.siegeRefill.pid==K.pid then return end
 local b=K.base()
 local code=([[
[ENABLE]
assert(%X,48 8B 01 89 91 08 03 00 00 89 91 14 03 00 00 48 FF A0 80 00 00 00)
assert(%X,48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57)
alloc(nb16SiegeRefill,1024,%X)
registersymbol(nb16SiegeRefill)
label(nextUnit)
label(skipUnit)
label(stamina)
label(skill)
label(done)
nb16SiegeRefill:
push rbx
push rsi
push rdi
push rbp
sub rsp,28
mov ebp,edx
mov rbx,rcx
mov rsi,[%X]
test rsi,rsi
jz done
mov edi,20
nextUnit:
mov rcx,[rsi]
test rcx,rcx
jz skipUnit
mov rax,%X
cmp [rcx],rax
jne skipUnit
cmp [rcx+40],rbx
jne skipUnit
test ebp,1
jz skill
mov edx,[rcx+314]
test edx,edx
jle stamina
cmp edx,7A120
ja stamina
cmp [rcx+308],edx
jge stamina
call %X
stamina:
mov rcx,[rsi]
mov edx,[rcx+450]
test edx,edx
jle skill
cmp edx,F4240
ja skill
sub edx,[rcx+44C]
jle skill
call %X
skill:
test ebp,2
jz skipUnit
mov rcx,[rsi]
mov eax,[rcx+440]
test eax,eax
jle skipUnit
cmp eax,F4240
ja skipUnit
mov [rcx+43C],eax
skipUnit:
add rsi,8
dec edi
jnz nextUnit
done:
xor eax,eax
add rsp,28
pop rbp
pop rdi
pop rsi
pop rbx
ret
[DISABLE]
unregistersymbol(nb16SiegeRefill)
]]):format(b+0x1D62A0,b+0x1FF000,b,b+0x1CED6E8,b+0x1372720,b+0x1D62A0,b+0x1FF000)
 local ok,info=(K.assemble or autoAssemble)(code);assert(ok,tostring(info))
 local address=assert(getAddressSafe('nb16SiegeRefill'))
 local bytes={};for _,v in ipairs(assert(readBytes(address,16,true))) do bytes[#bytes+1]=('%02X'):format(v) end
 K.nativeDefinitions.siegeRefill={rva=address-b,bytes=table.concat(bytes,' '),kind='army'}
 K.siegeRefill={pid=K.pid,address=address,script=code,info=info}
end
function K.refillSiegeArmy(index,mode)
 local p=K.object('army',index)
 if not p or not K.ownsArmy(p) then return end
 K.prepareSiegeRefill()
 return K.nativeCall('siegeRefill','army',index,mode or 1)
end
K.siegeSkillSites={
 skillTick={rva=0x200373,obj='r15',value='eax',field='43C',maximum='440',bytes='41 89 87 3C 04 00 00',length=7},
 skillSpend={rva=0x12F720,obj='rdi',value='ecx',field='43C',maximum='440',bytes='89 8F 3C 04 00 00',length=6}}
K.siegeOneHitSites={siegeHit={rva=0x140430,obj='rcx',bytes='48 89 5C 24 08',length=5,
 original='mov [rsp+08],rbx',labels='label(targetLoop)\nlabel(targetFound)',
 change=function()
  return ([[
test r8d,r8d
jle original
mov r11,[%X]
test r11,r11
jz original
mov eax,20
targetLoop:
cmp [r11],rdx
je targetFound
add r11,8
dec eax
jnz targetLoop
jmp original
targetFound:
mov rax,%X
cmp [rdx],rax
jne original
mov r10,[rsp]
mov eax,[r10+30]
cmp eax,[rdx+30]
je original
mov eax,[rdx+308]
test eax,eax
jle original
mov r8d,eax
]]):format(K.base()+0x1CED6E8,K.base()+0x1372720)
 end}}
K.siegeOneHitSites.siegeNormalHit={rva=0x1DDFA7,obj='r14',length=8,
 bytes='41 0F B6 86 95 03 00 00',original='movzx eax,byte ptr [r14+395]',
 labels='label(targetLoop)\nlabel(targetFound)',change=function()
 return ([[
test r12d,r12d
jle original
mov r11,[%X]
test r11,r11
jz original
mov eax,20
targetLoop:
cmp [r11],rsi
je targetFound
add r11,8
dec eax
jnz targetLoop
jmp original
targetFound:
mov rax,%X
cmp [rsi],rax
jne original
mov eax,[r14+30]
cmp eax,[rsi+30]
je original
mov eax,[rsi+308]
test eax,eax
jle original
cmp r12d,eax
jge original
mov r12d,eax
]]):format(K.base()+0x1CED6E8,K.base()+0x1372720)
end}
K.siegeOneHitSites.siegeBuildingHit={rva=0x1DDCEC,obj='r14',length=9,
 bytes='4C 8B 16 41 B9 01 00 00 00',original='mov r10,[rsi]\nmov r9d,1',
 labels='label(buildingFound)',change=function()
 local s='cmp dword ptr [rsp+18],0\njle original\n'
 for _,vt in ipairs({0x13715E8,0x1371778,0x1371918,0x1371AC0,0x1371C68,0x1371E40,0x1372008}) do
  s=s..('mov rax,%X\ncmp [rsi],rax\nje buildingFound\n'):format(K.base()+vt)
 end
 return s..[[
jmp original
buildingFound:
mov eax,[rsi+58]
test eax,eax
jle original
cmp eax,[rsp+18]
jle original
mov [rsp+18],rax
]]
end}
K.siegeSites={
 siegeStamina={rva=0x1FF05C,obj='rbx',value='eax',field='44C',maximum='450'},
 siegeDamage={rva=0x1EAE02,obj='rcx',value='edx'},
 siegeAttack={rva=0x140490,obj='rbx',value='eax'},
 siegeEffect={rva=0x1300EA,obj='rbx',value='eax'},
 siegeTactic={rva=0x17FAC8,obj='rsi',value='eax'},
 siegeModifier={rva=0x12F864,obj='rdx',value='eax'}}
K.siegeMovementSites={siegeSpeed={rva=0x146A58,obj='rsi',length=5,
 bytes='48 8B 5C 24 68',original='mov rbx,[rsp+68]',
 change=[[
cmp dword ptr [rsi+308],0
jle original
mov eax,[rsp+18]
test eax,eax
jle original
cmp eax,400
ja original
shl eax,2
mov [rsp+18],rax
]]}}
function K.siegeScript(name,symbol,definition)
 local d=assert(definition or K.siegeSites[name])
 local field=d.field or '308'
 local op=d.original or ('mov [%s+%s],%s'):format(d.obj,field,d.value or 'eax')
 local bytes={siegeDamage='89 91 08 03 00 00',siegeAttack='89 83 08 03 00 00',
  siegeEffect='89 83 08 03 00 00',siegeTactic='89 86 08 03 00 00',siegeModifier='89 82 08 03 00 00',siegeStamina='89 83 4C 04 00 00'}
 d.bytes=d.bytes or bytes[name];d.length=d.length or 6
 local change
 -- RAX is saved by the common guard; adjust its saved result when required.
 if d.change then change=type(d.change)=='function' and d.change() or d.change
 elseif d.maximum then
  local saved=d.value=='ecx' and 'rsp' or 'rsp+18'
  change=('mov r10,%s\nmov eax,[r10+%s]\ntest eax,eax\njle original\ncmp eax,F4240\nja original\nmov [%s],rax'):format(d.obj,d.maximum,saved)
 elseif d.value=='eax' then
  change=('mov r10,%s\nmov eax,[rsp+18]\ncmp eax,[r10+308]\njge original\nmov eax,[r10+308]\nmov [rsp+18],rax'):format(d.obj)
 else
  change='mov r10,[rsp]\ncmp edx,[r10+308]\njge original\nmov edx,[r10+308]'
 end
 local script=K.battleScript(name,symbol,{rva=d.rva,bytes=d.bytes,length=d.length,original=op,change=change})
 local guard=([[
push rcx
mov r10,%s
mov r11,[%X]
test r11,r11
jz original
mov eax,20
unitLoop:
cmp [r11],r10
je unitFound
add r11,8
dec eax
jnz unitLoop
jmp original
unitFound:
mov rax,%X
cmp [r10],rax
jne original
mov rcx,[r10+40]
]]):format(d.obj,K.base()+0x1CED6E8,K.base()+0x1372720)
 script=script:gsub('label%(original%)','label(original)\nlabel(unitLoop)\nlabel(unitFound)',1)
 if d.labels then script=script:gsub('label%(original%)','label(original)\n'..d.labels,1) end
 script=script:gsub('push r11\n','push r11\n'..guard,1)
 script=script:gsub('original:\npop r11','original:\npop rcx\npop r11',1)
 return script
end
function K.setSiegeProtection(enabled,skills)
 K.ready()
 local key=skills=='speed' and 'siegeMovementHooks' or (skills=='onehit' and 'siegeOneHitHooks' or (skills and 'siegeSkillHooks' or 'siegeHooks'))
 K[key]=K[key] or {};local hooks=K[key]
 local sites=skills=='speed' and K.siegeMovementSites or (skills=='onehit' and K.siegeOneHitSites or (skills and K.siegeSkillSites or K.siegeSites))
 if not enabled then
  for name,h in pairs(hooks) do
   if h.pid==getOpenedProcessID() and K.buildMatches() then
    local bytes=assert(readBytes(h.site,#h.installed,true))
    for i,b in ipairs(h.installed) do assert(bytes[i]==b,'N16 siege hook ownership changed') end
    assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N16 siege hook')
   end
   hooks[name]=nil
  end
  return
 end
 local added={}
 -- Validate every target before installing any hook in this group.
 for name,d in pairs(sites) do
  if not hooks[name] then
   K.siegeScript(name,'nb16SiegeCheck',d)
   local expected={}
   for byte in d.bytes:gmatch('%x%x') do expected[#expected+1]=tonumber(byte,16) end
   local actual=readBytes(K.base()+d.rva,#expected,true)
   local valid=actual and #actual==#expected
   if valid then for i,v in ipairs(expected) do if actual[i]~=v then valid=false;break end end end
   assert(valid,NB.T('Battle code is already modified ('..name..'). Disable the table that owns it before enabling this feature.',
    '戦闘処理に別の書き換えが残っています（'..name..'）。管理しているテーブルの機能を解除してから有効にしてください。'))
  end
 end
 local ok,err=pcall(function()
  for name,d in pairs(sites) do if not hooks[name] then
   K.siegeSerial=(K.siegeSerial or 0)+1
   local script=K.siegeScript(name,'nb16Siege_'..name..'_'..K.siegeSerial,d)
   local good,info=(K.assemble or autoAssemble)(script);assert(good,tostring(info))
   local site=K.base()+d.rva
   hooks[name]={script=script,info=info,site=site,pid=K.pid,installed=assert(readBytes(site,d.length,true))}
   added[#added+1]=name
  end end
 end)
 if not ok then
  for _,name in ipairs(added) do local h=hooks[name];assert((K.assemble or autoAssemble)(h.script,h.info));hooks[name]=nil end
  error(err,0)
 end
end

end

do
local K=NB.K16
function K.oneHitScript(symbol)
 local c=K.ready();local clan=assert(K.clan());local site=c.base+0x6F6A55
 return (([[
[ENABLE]
assert(%X,45 89 66 10 45 89 6E 14)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(done)
label(nextArmy)
label(scan)
label(hit)
label(validArmy)
label(invalidArmy)
label(baseDistrict)
label(districtReady)
@N@:
dd 0 0
dq 0 0
@N@+100:
pushfq
push rax
push rcx
push rdx
push r8
push r9
push r10
push r11
mov rax,[%X]
mov r11,%X
cmp rax,r11
jne done
mov rax,[rax+1B260]
mov r11,%X
cmp rax,r11
jne done
mov rax,[rax+1047E0]
mov r11,%X
cmp rax,r11
jne done
mov r10,[r14]
call validArmy
test eax,eax
jz done
mov rax,%X
cmp [r11+10],rax
je done
mov r9d,[r10+18]
test r9d,r9d
jle done
mov eax,[r14+0C]
or eax,r12d
or eax,r13d
jz done
mov rdx,[rbp-80]
mov r8,[rdx]
mov rdx,[rdx+08]
cmp rdx,r8
jbe done
mov rax,rdx
sub rax,r8
cmp rax,4290
ja done
scan:
lea rax,[r8+18]
cmp rax,rdx
ja done
mov r10,[r8]
call validArmy
test eax,eax
jz nextArmy
mov rax,%X
cmp [r11+10],rax
je hit
nextArmy:
add r8,18
cmp r8,rdx
jb scan
jmp done
hit:
mov rax,@N@
inc dword ptr [rax+04]
mov rcx,[r14]
mov [rax+08],rcx
mov [rax+10],r10
cmp dword ptr [rax],1
jne done
mov r12d,r9d
xor r13d,r13d
done:
pop r11
pop r10
pop r9
pop r8
pop rdx
pop rcx
pop rax
popfq
mov [r14+10],r12d
mov [r14+14],r13d
jmp %X
validArmy:
mov rax,%X
mov r11,[rax+DC60]
cmp r10,r11
jb invalidArmy
add r11,9CB30
cmp r10,r11
jae invalidArmy
mov rax,%X
cmp [r10],rax
jne invalidArmy
test byte ptr [r10+2F4],1
jz invalidArmy
cmp dword ptr [r10+374],0
je invalidArmy
mov r11,[r10+238]
mov rax,%X
mov rax,[rax+C670]
cmp r11,rax
jb baseDistrict
add rax,189C0
cmp r11,rax
jae baseDistrict
mov rax,%X
cmp [r11],rax
jne baseDistrict
cmp dword ptr [r11+114],0
je baseDistrict
cmp qword ptr [r11+10],0
je baseDistrict
jmp districtReady
baseDistrict:
mov r11,[r10+08]
mov rax,%X
mov rax,[rax+C670]
cmp r11,rax
jb invalidArmy
add rax,189C0
cmp r11,rax
jae invalidArmy
mov rax,%X
cmp [r11],rax
jne invalidArmy
mov eax,[r10+10]
test eax,eax
jz invalidArmy
cmp eax,[r11+114]
jne invalidArmy
districtReady:
mov eax,1
ret
invalidArmy:
xor eax,eax
ret
%X:
jmp @N@+100
nop 3
[DISABLE]
%X:
db 45 89 66 10 45 89 6E 14
unregistersymbol(@N@)
// Retain the trampoline until process exit for in-flight calls.
]]):format(site,site,c.base+0x213CB08,c.root,c.scenario,c.player,clan,clan,
 site+8,c.root,c.base+K.types.army.vt,c.root,c.base+K.types.district.vt,
 c.root,c.base+K.types.district.vt,site,site)
 :gsub('@N@',symbol))
end
function K.installOneHit(observeOnly)
 K.ready()
 if not K.oneHitHook then
  K.oneHitSerial=(K.oneHitSerial or 0)+1
  local symbol='nb16OneHit_'..K.oneHitSerial
  local script=K.oneHitScript(symbol)
  local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
  local site=K.base()+0x6F6A55
  K.oneHitHook={script=script,info=info,site=site,pid=K.pid,q=assert(getAddressSafe(symbol)),
   installed=assert(readBytes(site,8,true))}
 end
 writeInteger(K.oneHitHook.q,observeOnly and 0 or 1)
end
function K.removeOneHit()
 local h=K.oneHitHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.site,8,true))
  for i,b in ipairs(h.installed) do assert(bytes[i]==b,'N16 one-hit hook ownership changed') end
  writeInteger(h.q,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N16 one-hit hook')
 end
 K.oneHitHook=nil
end

end

do
local K=NB.K16
function K.castleOneHitScript(symbol)
 local c=K.ready();local clan=assert(K.clan());local site=c.base+0x5C7B60
 local shared=K.oneHitScript(symbol..'_unused')
 local helper=assert(shared:match('(validArmy:\n.-\nret)\n%x+:\njmp'))
 local code=([[
[ENABLE]
assert(%X,40 55 53 56 57 41 54)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(done)
label(validArmy)
label(invalidArmy)
label(baseDistrict)
label(districtReady)
@N@:
dd 0 0
dq 0 0
@N@+100:
pushfq
push rax
push rcx
push rdx
push r8
push r9
push r10
push r11
test edx,edx
jle done
mov rax,[%X]
mov r11,%X
cmp rax,r11
jne done
mov rax,[rax+1B260]
mov r11,%X
cmp rax,r11
jne done
mov rax,[rax+1047E0]
mov r11,%X
cmp rax,r11
jne done
mov rax,%X
mov rax,[rax+D170]
cmp rcx,rax
jb done
add rax,%X
cmp rcx,rax
jae done
mov rax,%X
cmp [rcx],rax
jne done
mov r11,[rcx+18]
mov rax,%X
mov rax,[rax+C670]
cmp r11,rax
jb done
add rax,189C0
cmp r11,rax
jae done
mov rax,%X
cmp [r11],rax
jne done
mov eax,[rcx+20]
test eax,eax
jz done
cmp eax,[r11+114]
jne done
mov rax,%X
cmp [r11+10],rax
je done
mov r10,r8
call validArmy
test eax,eax
jz done
mov rax,%X
cmp [r11+10],rax
jne done
mov rax,@N@
inc dword ptr [rax+04]
mov [rax+08],rcx
mov [rax+10],r8
cmp dword ptr [rax],1
jne done
movzx eax,word ptr [rcx+4E]
cmp eax,edx
jle done
mov [rsp+20],eax
done:
pop r11
pop r10
pop r9
pop r8
pop rdx
pop rcx
pop rax
popfq
push rbp
push rbx
push rsi
push rdi
push r12
jmp %X
]]):format(site,site,c.base+0x213CB08,c.root,c.scenario,c.player,
 c.root,K.types.city.count*K.types.city.stride,c.base+K.types.city.vt,
 c.root,c.base+K.types.district.vt,clan,clan,site+7)
 code=code..helper..('\n%X:\njmp @N@+100\nnop 2\n[DISABLE]\n%X:\ndb 40 55 53 56 57 41 54\nunregistersymbol(@N@)\n'):format(site,site)
 return (code:gsub('@N@',symbol))
end
function K.installCastleOneHit(observeOnly)
 K.ready()
 if not K.castleOneHitHook then
  K.castleOneHitSerial=(K.castleOneHitSerial or 0)+1
  local symbol='nb16CastleOneHit_'..K.castleOneHitSerial
  local script=K.castleOneHitScript(symbol)
  local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
  local site=K.base()+0x5C7B60
  K.castleOneHitHook={script=script,info=info,site=site,pid=K.pid,
   q=assert(getAddressSafe(symbol)),installed=assert(readBytes(site,7,true))}
 end
 writeInteger(K.castleOneHitHook.q,observeOnly and 0 or 1)
end
function K.removeCastleOneHit()
 local h=K.castleOneHitHook;if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.site,7,true))
  for i,b in ipairs(h.installed) do assert(bytes[i]==b,'N16 castle hook ownership changed') end
  writeInteger(h.q,0)
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N16 castle hook')
 end
 K.castleOneHitHook=nil
end
function K.setOneHit(enabled)
 K.ready()
 if not enabled then
  K.setSiegeProtection(false,'onehit')
  K.removeOneHit()
  K.removeCastleOneHit()
  K.on.oneHit=nil
  return
 end
 local hadArmy=K.oneHitHook~=nil
 local hadCastle=K.castleOneHitHook~=nil
 local ok,err=pcall(function()
  K.installOneHit(false)
  K.installCastleOneHit(false)
  K.setSiegeProtection(true,'onehit')
 end)
 if not ok then
  if not hadArmy then K.removeOneHit() end
  if not hadCastle then K.removeCastleOneHit() end
  error(err,0)
 end
 K.on.oneHit=true
end

end

do
local K=NB.K16
K.actionSites={
 laborChange={rva=0x5A0CA9,bytes='66 89 6E 76 48 8B 7E 08',length=8,obj='rsi',value='ebp',
  original='mov [rsi+76],bp\nmov rdi,[rsi+08]'},
 laborCityOrder={rva=0x620220,bytes='66 44 89 66 76 48 8B 5E 08',length=9,obj='rsi',value='r12d',
  original='mov [rsi+76],r12w\nmov rbx,[rsi+08]'},
 commandCooldownRead={rva=0x5F4D7B,bytes='8B C2 0F BF 84 41 98 00 00 00',length=10,obj='rcx',value='eax',cooldown=true,
  original='mov eax,edx\nmovsx eax,word ptr [rcx+rax*2+98]'},
 laborRecalculate={rva=0x640058,bytes='66 89 47 76 48 8B 5B 08',length=8,obj='rdi',value='eax',
  original='mov [rdi+76],ax\nmov rbx,[rbx+08]'}}
function K.actionScript(name,symbol)
 local d=assert(K.actionSites[name]);local c=K.ready();local clan=assert(K.clan())
 local at=c.base+d.rva
 local script=(([[
[ENABLE]
assert(%X,%s)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(skip)
label(original)
@N@:
pushfq
push rax
push r10
push r11
mov rax,[%X]
mov r10,%X
cmp rax,r10
jne skip
mov rax,[rax+1B260]
mov r10,%X
cmp rax,r10
jne skip
mov rax,[rax+1047E0]
mov r10,%X
cmp rax,r10
jne skip
mov rax,%X
mov r11,[rax+C670]
mov r10,@O@
cmp r10,r11
jb skip
add r11,189C0
cmp r10,r11
jae skip
mov rax,%X
cmp [r10],rax
jne skip
cmp dword ptr [r10+114],0
je skip
mov rax,%X
cmp [r10+10],rax
jne skip
movzx eax,word ptr [r10+78]
cmp eax,3E8
ja skip
pop r11
pop r10
pop rax
popfq
movzx @V@,word ptr [@O@+78]
jmp original
skip:
pop r11
pop r10
pop rax
popfq
original:
%s
jmp %X
%X:
jmp @N@
nop %d
[DISABLE]
%X:
db %s
unregistersymbol(@N@)
// Retain the trampoline until process exit for in-flight calls.
]]):format(at,d.bytes,at,c.base+0x213CB08,c.root,c.scenario,c.player,
 c.root,c.base+K.types.district.vt,clan,d.original,at+d.length,at,d.length-5,at,d.bytes)
 :gsub('@N@',symbol):gsub('@O@',d.obj):gsub('@V@',d.value))
 if d.cooldown then
  script=script:gsub('movzx eax,word ptr %[rcx%+78%]\njmp original',
   ('mov eax,FFFFFFFF\njmp %X'):format(at+d.length),1)
 end
 return script
end
function K.installActionHook(name)
 K.ready();K.actionHooks=K.actionHooks or {}
 if K.actionHooks[name] then return end
 K.actionSerial=(K.actionSerial or 0)+1
 local script=K.actionScript(name,'nb16Action_'..name..'_'..K.actionSerial)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 local d=K.actionSites[name];local site=K.base()+d.rva
 K.actionHooks[name]={script=script,info=info,site=site,pid=K.pid,
  installed=assert(readBytes(site,d.length,true))}
end
function K.removeActionHook(name)
 local h=K.actionHooks and K.actionHooks[name];if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.site,#h.installed,true))
  for i,b in ipairs(h.installed) do assert(bytes[i]==b,'N16 action hook ownership changed') end
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N16 action hook')
 end
 K.actionHooks[name]=nil
end

end

do
local K=NB.K16
K.fields={officer={},district={},city={},army={}}
for i,names in ipairs({{'Leadership','統率'},{'Valor','武勇'},{'Intelligence','知略'},{'Politics','政務'}}) do
 K.fields.officer[#K.fields.officer+1]={en=names[1],jp=names[2],off=0xDD+i,
  size=1,min=0,max=255,method='officerAbility'..(i-1)}
end
K.fields.officer[#K.fields.officer+1]={en='Merit',jp='功績',off=0xE4,
 size=4,min=0,max=65535,method='officerMerit'}
K.fields.officer[#K.fields.officer+1]={en='Death year',jp='没年',off=0xDC,
 size=2,min=0,max=32767,method='officerDeathYear'}
K.fields.district={{en='Money',jp='金銭',off=0x18,size=4,min=0,max=10000000,method='districtMoneySet'}}
K.fields.city={
 {en='Soldiers',jp='兵士',off=0x48,size=4,min=0,max=500000,method='citySoldiersSet'},
 {en='Supplies',jp='兵糧',off=0xE4,size=4,min=0,max=1000000,method='citySuppliesSet'},
 {en='Durability',jp='耐久',off=0x4E,size=2,min=0,max=50000,method='cityDurabilitySet'}}
K.fields.army={
 {en='Soldiers',jp='兵士',off=0x18,size=4,min=0,max=500000,method='armySoldiersSet'},
 {en='Provisions',jp='携行兵糧',off=0x2D8,size=2,min=0,max=50000,method='armyProvisionsSet'}}
K.pendingEdits={}
function K.queueEdit(kind,index,field,value)
 local c=K.ready();local object=assert(K.object(kind,index),'Awakening edit target unavailable')
 local known=false
 for _,f in ipairs(K.fields[kind] or {}) do if f==field then known=true;break end end
 assert(known,'Unknown Awakening field')
 local v=tonumber(value)
 assert(v and v==v and math.abs(v)~=math.huge,'Enter a finite number')
 v=math.max(field.min,math.min(field.max,math.floor(v)))
 local id=kind..':'..index..':'..field.off..':'..(field.method or field.jp)
 local generation
 if kind=='army' then
  assert(K.armyActive(object),'Awakening army is no longer active')
  generation=readInteger(object+0x374)
 end
 K.pendingEdits[id]={kind=kind,index=index,field=field,value=v,key=c.key,object=object,generation=generation}
 return v,K.pendingEdits[id]
end
function K.applyNextEdit()
 if K.editBusy or K.nativeBusy() then return false end
 local id,e=next(K.pendingEdits);if not id then return false end
 K.pendingEdits[id]=nil
 if e.feature and not K.on[e.feature] then return false end
 local c=K.ready()
 assert(e.key==c.key and K.object(e.kind,e.index)==e.object,'Awakening edit context changed')
 if e.kind=='army' then
  assert(K.armyActive(e.object) and readInteger(e.object+0x374)==e.generation,'Awakening army was replaced')
 end
 if e.owned and not K.ownsObject(e.kind,e.object) then return false end
 K.editBusy=true
 local ok,result=pcall(function()
  if e.field.apply then return e.field.apply(e.kind,e.index,e.value) end
  return K.nativeCall(e.field.method,e.kind,e.index,e.value)
 end)
 K.editBusy=false
 if not ok then
  if e.feature then
   K.on[e.feature]=nil
   local timer=K.timers[e.feature]
   if timer then timer.Enabled=false end
   for queued,entry in pairs(K.pendingEdits) do
    if entry.feature==e.feature then K.pendingEdits[queued]=nil end
   end
   local ids={loyalty=404,cityMax=304,ownBattle=202,facilityMax=604}
   local record=ids[e.feature] and getAddressList().getMemoryRecordByID(ids[e.feature])
   if record then NB.deferOff(record) end
  end
  error(result,0)
 end
 return true
end
function K.cancelEdits() K.pendingEdits={} end

end

do
local K=NB.K16
K.types.trait={off=0x30BB0,count=255,stride=0x38,vt=0x13D1250}
K.types.conservator={off=0x33E78,count=256,stride=0x48,vt=0x13D1390}
K.types.overseer={off=0x34678,count=256,stride=0x80,vt=0x13D13E0}
local function enum(values)
 return function()
  local out={};for i,v in ipairs(values) do out[#out+1]=(i-1)..':'..v end
  return table.concat(out,'\n')
 end
end
local function add(field) K.fields.officer[#K.fields.officer+1]=field end
K.nativeDefinitions.officerAchievement={rva=0x62C260,bytes='83 FA 03 77 15 41 81 F8 FF FF 00 00 77 0C 48 63',kind='officer'}
K.nativeDefinitions.officerTraitProgress={rva=0x630030,bytes='83 FA 03 73 14 41 81 F8 FF 00 00 00 77 0B 8B C2',kind='officer'}
K.nativeDefinitions.officerTraitProgressReset={rva=0x5B7990,bytes='83 FA 03 73 0F 8B C2 BA FF FF FF FF 66 89 94 41',kind='officer'}
for slot,names in ipairs({{'Leadership achievement','統率実績'},{'Valor achievement','武勇実績'},
 {'Intelligence achievement','知略実績'},{'Politics achievement','政務実績'}}) do
 local position=slot-1
 add{en=names[1],jp=names[2],off=0x1E8+position*2,size=2,min=0,max=65535,
  apply=function(kind,index,value)return K.nativeCall('officerAchievement',kind,index,position,value) end}
end
K.fields.officer[5].jp='勲功'
add{en='Grade',jp='格付',off=0x200,size=8,min=0,max=3,method='officerGrade',
 decode=function(v)return (v&gt;&gt;11)&amp;7 end,options=enum{'C','B','A','S'}}
add{en='Voice',jp='音声',off=0x200,size=8,min=0,max=11,method='officerVoice',
 decode=function(v)return (v&gt;&gt;6)&amp;31 end,options=function()
  local out={};for i=0,11 do out[#out+1]=i..':'..K.stringEntry(0x519+i,true) end
  return table.concat(out,'\n')
 end}
add{en='Ideology',jp='主義',off=0x17C,size=2,min=1,max=3,method='officerIdeology',
 options=function()return '1:'..NB.T('Conservative','保守')..'\n2:'..NB.T('Neutral','中道')..'\n3:'..NB.T('Progressive','革新') end}
add{en='Origin',jp='出自',off=0x17E,size=1,min=0,max=9,method='officerOrigin',
 options=function()local t={};for i=0,9 do t[#t+1]=i..':'..K.stringEntry(0x5F4C+i) end;return table.concat(t,'\n') end}
add{en='Faith',jp='信仰',off=0x17F,size=1,min=0,max=3,method='officerFaith',
 options=function()local t={};for i=0,3 do t[#t+1]=i..':'..K.stringEntry(0x5F56+i) end;return table.concat(t,'\n') end}
add{en='Base loyalty bonus (0 = automatic)',jp='忠誠基礎補正（0＝自動計算）',off=0x142,size=1,min=0,max=20,
 apply=function(kind,index,value)return K.nativeCall('officerLoyaltyFactor',kind,index,0,value) end}
function K.definitionName(kind,p)
 local id=readSmallInteger(p+8)
 if not id or id&gt;=K.types[kind].count then return '' end
 if kind=='trait' then
  if id&gt;=180 then return readString(K.scenario()+0xDE690+(id-180)*0x3E,62,true) or '' end
  return K.stringEntry(0x5F60+id)
 end
 return K.stringEntry((kind=='conservator' and 0x67AE or 0x6AC3)+id)
end
local function definitions(kind)
 return function()
  if K.editorChoiceCache and K.editorChoiceCache[kind] then return K.editorChoiceCache[kind] end
  local out={'-1:'..NB.T('None','なし')}
  for i=0,K.types[kind].count-1 do
   local p=K.object(kind,i)
   if p then local name=K.definitionName(kind,p)
    if name~='' then out[#out+1]=i..':'..name end
   end
  end
  local text=table.concat(out,'\n')
  if K.editorChoiceCache then K.editorChoiceCache[kind]=text end
  return text
 end
end
local function pointerField(kind,off,en,jp,method,slot)
 add{en=en,jp=jp,off=off,size=8,min=-1,max=K.types[kind].count-1,options=definitions(kind),
 decode=function(v)return K.indexOf(kind,v) or -1 end,
 apply=function(target,index,value)
  local p=assert(K.object(target,index));local argument=0
  if value&gt;=0 then
   argument=assert(K.object(kind,value),'Definition is no longer available')
   assert(K.definitionName(kind,argument)~='','Empty definition cannot be selected')
  end
  if slot~=nil then
   if argument~=0 then for i=0,2 do
    assert(i==slot or readQword(p+0x188+i*8)~=argument,NB.T('This trait is already assigned.','同じ特性が別の枠に設定されています。'))
   end end
   K.nativeCall(method,target,index,slot,argument)
  else K.nativeCall(method,target,index,argument) end
  assert(readQword(p+off)==argument,'The game did not apply the selected definition')
 end}
end
for i=0,2 do
 pointerField('trait',0x188+i*8,'Trait '..(i+1),'特性'..(i+1),'officerTrait',i)
 add{en='Trait '..(i+1)..' progress',jp='特性'..(i+1)..'の進行値（-1＝リセット値）',off=0x1A0+i*2,size=2,min=-1,max=255,displaySignedText=true,
  visible=function(p)return K.indexOf('trait',readQword(p+0x188+i*8))~=nil end,
  decode=function(v)return v&gt;=0x8000 and v-0x10000 or v end,
  apply=function(kind,index,value)
   local p=assert(K.object(kind,index))
   assert(K.indexOf('trait',readQword(p+0x188+i*8))~=nil,'Trait slot is empty')
   if value==-1 then return K.nativeCall('officerTraitProgressReset',kind,index,i) end
   return K.nativeCall('officerTraitProgress',kind,index,i,value)
  end}
end
pointerField('conservator',0x1A8,'Conservator trait','家宰特性','officerConservator')
pointerField('overseer',0x1B0,'Overseer trait','奉行特性','officerOverseer')
for slot=0,9 do
 local function facility(p)
  if readSmallInteger(p+0xC4+slot*2)~=3 then return nil end
  return K.object('facility',readSmallInteger(p+0xB0+slot*2))
 end
 K.fields.city[#K.fields.city+1]={en='Facility '..(slot+1),jp='城下施設'..(slot+1),
  off=0xB0+slot*2,size=2,min=0,max=38,visible=function(p)return facility(p)~=nil end,
  options=function()
   local out={};for i=0,38 do out[#out+1]=i..':'..K.stringEntry(0x5E0C+i) end
   return table.concat(out,'\n')
  end,
  apply=function(kind,index,value)
   local p=assert(K.object(kind,index));local previous=assert(facility(p),'Facility is under construction or no longer exists')
   local replacement=assert(K.object('facility',value));local maximum=assert(readBytes(replacement+0x78,1))
   assert(maximum&lt;=4,'Unexpected facility limit')
   local level=math.min(readBytes(p+0xD8+slot,1),maximum)
   K.nativeCall('cityFacilityType',kind,index,slot,value)
   K.nativeCall('cityFacilityLevel',kind,index,slot,level)
   K.nativeCall('cityFacilityRecalculate',kind,index,previous)
   K.nativeCall('cityFacilityRecalculate',kind,index,replacement)
   K.nativeCall('cityRecalculate',kind,index)
   assert(readSmallInteger(p+0xB0+slot*2)==value,'Facility type was not applied')
   K.refreshEditorRows=true
  end}
 K.fields.city[#K.fields.city+1]={en='Facility '..(slot+1)..' level',jp='城下施設'..(slot+1)..'レベル',
  off=0xD8+slot,size=1,min=1,max=5,decode=function(v)return v+1 end,
  visible=function(p)return facility(p)~=nil end,
  options=function(p)
   local f=facility(p);local maximum=f and readBytes(f+0x78,1) or 0
   local out={};for i=1,math.min(4,maximum)+1 do out[#out+1]=i..':'..i end
   return table.concat(out,'\n')
  end,
  apply=function(kind,index,value)
   local p=assert(K.object(kind,index));local f=assert(facility(p),'Facility is under construction or no longer exists')
   local maximum=assert(readBytes(f+0x78,1));assert(maximum&lt;=4,'Unexpected facility limit')
   local level=math.min(value-1,maximum)
   K.nativeCall('cityFacilityLevel',kind,index,slot,level)
   K.nativeCall('cityFacilityRecalculate',kind,index,f)
   K.nativeCall('cityRecalculate',kind,index)
   assert(readBytes(p+0xD8+slot,1)==level,'Facility level was not applied')
  end}
end

end

do
local K=NB.K16
function K.preparePrestigeEdit()
 if K.prestigeEdit and K.prestigeEdit.pid==K.pid then return end
 local b=K.base()
 local code=([[
[ENABLE]
assert(%X,48 85 C9 0F 84 5E 03 00 00 48 89 5C 24 10)
alloc(nb16PrestigeEdit,256,%X)
registersymbol(nb16PrestigeEdit)
label(done)
nb16PrestigeEdit:
cmp edx,2710
ja done
mov [rcx+2BC],dx
sub rsp,38
xor edx,edx
xor r8d,r8d
xor r9d,r9d
mov qword ptr [rsp+20],1
mov qword ptr [rsp+28],1
call %X
add rsp,38
done:
xor eax,eax
ret
[DISABLE]
unregistersymbol(nb16PrestigeEdit)
]]):format(b+0x63C280,b,b+0x63C280)
 local ok,info=(K.assemble or autoAssemble)(code);assert(ok,tostring(info))
 local address=assert(getAddressSafe('nb16PrestigeEdit'))
 local bytes={};for _,v in ipairs(assert(readBytes(address,16,true))) do bytes[#bytes+1]=('%02X'):format(v) end
 K.nativeDefinitions.prestigeEdit={rva=address-b,bytes=table.concat(bytes,' '),kind='clan'}
 K.prestigeEdit={pid=K.pid,address=address,script=code,info=info}
end
K.fields.clan={{en='Prestige bonus',jp='威信加算',off=0x2BC,size=2,min=0,max=10000,
 apply=function(kind,index,value)
  K.preparePrestigeEdit()
  return K.nativeCall('prestigeEdit',kind,index,value)
 end}}

end

do
local K=NB.K16
K.types.policy={off=0x20F30,count=100,stride=0xB0,vt=0x13D1200}
K.nativeDefinitions.policyLevel={rva=0x62C810,bytes='83 FA 63 77 11 41 83 F8 04 77 0B 48 63 C2 44 88',kind='clan'}
K.nativeDefinitions.policyState={rva=0x62C980,bytes='83 FA 63 77 11 41 83 F8 05 77 0B 48 63 C2 44 88',kind='clan'}
K.nativeDefinitions.policyRefresh={rva=0x749760,bytes='48 89 5C 24 20 55 56 57 41 54 41 55 41 56 41 57',kind='clan'}
function K.policyLimit(index)
 local p=K.object('policy',index)
 if not p or readBytes(p+9,1)&gt;=128 then return end
 local cap=readBytes(p+0x8F,1)
 assert(cap and cap&lt;=4,'Policy level limit changed')
 return cap
end
function K.policyBatch(maximize)
 K.ready()
 assert(not K.timers.policies,NB.T('Policy changes are still running.','政策の変更処理が実行中です。'))
 local clan=assert(K.clan());local index=assert(K.indexOf('clan',clan));local key=K.key()
 local cursor,count=0,0
 local timer=createTimer(nil,false);timer.Interval=50;K.timers.policies=timer
 timer.OnTimer=function(t)
  if K.nativeBusy() then return end
  t.Enabled=false
  local ok,err=pcall(function()
   K.ready();assert(K.key()==key and K.clan()==clan,'Policy target changed')
   while cursor&lt;100 do
    local id=cursor;cursor=cursor+1
    local cap=K.policyLimit(id)
    if cap then
     local state=readBytes(clan+0x98+id,1)
     local level=readBytes(clan+0xFC+id,1)
     if maximize and state==1 and level&lt;cap then
      K.nativeCall('policyLevel','clan',index,id,cap)
      K.nativeCall('policyRefresh','clan',index,1,0);count=count+1;return
     elseif not maximize and state==0 then
      K.nativeCall('policyState','clan',index,id,1)
      K.nativeCall('policyRefresh','clan',index,1,0);count=count+1;return
     end
    end
   end
  end)
  if not ok or cursor&gt;=100 then
   K.timers.policies=nil;t.destroy()
   if not ok then NB.msg(tostring(err))
   else NB.msg(('Updated %d policies.'):format(count),('政策を%d件更新しました。'):format(count)) end
  else t.Enabled=true end
 end
 timer.Enabled=true
end
function K.preparePolicyFinish()
 if K.policyFinish and K.policyFinish.pid==K.pid then return end
 local b=K.base()
 local code=([[
[ENABLE]
assert(%X,40 56 48 83 EC 20 48 8B 01 48 8B F1 FF 50 48 83)
alloc(nb16PolicyFinish,512,%X)
registersymbol(nb16PolicyFinish)
label(reject)
label(findPolicy)
label(foundPolicy)
label(finish)
nb16PolicyFinish:
cmp edx,15B1
jae reject
mov r10,[%X]
test r10,r10
jz reject
mov r11,[r10+1B258]
test r11,r11
jz reject
mov eax,edx
imul rax,88
lea r11,[r11+rax+38]
mov rax,%X
cmp [r11],rax
jne reject
cmp [r11+44],edx
jne reject
test r8d,r8d
jz reject
cmp [r11+48],r8d
jne reject
cmp [r11+78],rcx
jne reject
mov r9,[r11+70]
xor edx,edx
findPolicy:
cmp [r10+rdx*8+20F30],r9
je foundPolicy
inc edx
cmp edx,64
jb findPolicy
jmp reject
foundPolicy:
mov rax,%X
cmp [r9],rax
jne reject
test byte ptr [r9+9],80
jnz reject
movzx eax,byte ptr [rcx+rdx+98]
cmp eax,2
je finish
cmp eax,4
jne reject
finish:
sub rsp,28
mov rcx,r11
mov dword ptr [rcx+68],0
call %X
add rsp,28
mov eax,1
ret
reject:
xor eax,eax
ret
[DISABLE]
unregistersymbol(nb16PolicyFinish)
]]):format(b+0x6528C0,b,b+0x213CB08,b+0x1377A70,b+0x13D1200,b+0x6528C0)
 local ok,info=(K.assemble or autoAssemble)(code);assert(ok,tostring(info))
 local address=assert(getAddressSafe('nb16PolicyFinish'));local bytes={}
 for _,v in ipairs(assert(readBytes(address,16,true))) do bytes[#bytes+1]=('%02X'):format(v) end
 K.nativeDefinitions.policyFinish={rva=address-b,bytes=table.concat(bytes,' '),kind='clan',allowPending=true}
 K.policyFinish={pid=K.pid,address=address,script=code,info=info}
end
function K.policyOrders(first,count)
 local r=K.root();local c=K.clan();if not r or not c then return {} end
 local pool=readQword(r+0x1B258);if not pool or pool&lt;0x10000 then return {} end
 local out={}
 first=first or 0;count=math.min(count or 128,5553-first)
 assert(first&gt;=0 and first&lt;5553 and count&gt;0 and count&lt;=5553,'Invalid policy pool range')
 local vt=K.base()+0x1377A70
 local raw=readBytes(pool+0x38+first*0x88,0x88*count,true);if not raw then return out end
 local function value(pos,n)
  local v=0;for i=0,n-1 do v=v|((raw[pos+i+1] or 0)&lt;&lt;(i*8)) end;return v
 end
 for i=first,first+count-1 do
  local off=(i-first)*0x88
  if value(off,8)==vt and value(off+0x78,8)==c
   and value(off+0x44,4)==i and value(off+0x48,4)~=0 then
   local policy=K.indexOf('policy',value(off+0x70,8))
   if policy then
    local state=readBytes(c+0x98+policy,1)
    if state==2 or state==4 then out[#out+1]={index=i,generation=value(off+0x48,4),policy=policy} end
   end
  end
 end
 return out
end
function K.setPolicyTimer(enabled)
 if K.timers.policyFinish then K.timers.policyFinish.destroy();K.timers.policyFinish=nil end
 K.on.instantPolicies=enabled or nil
 if not enabled then return end
 K.ready();K.preparePolicyFinish()
 local cursor=0
 local timer=createTimer(nil,false);timer.Interval=50;K.timers.policyFinish=timer
 timer.OnTimer=function(t)
  if K.nativeBusy() then return end
  t.Enabled=false
  local ok,err=pcall(function()
   K.ready()
   local orders=K.policyOrders(cursor,128)
   cursor=(cursor+128&gt;=5553) and 0 or cursor+128
   if #orders&gt;0 then
    local order=orders[1]
    local index=assert(K.indexOf('clan',K.clan()))
    K.nativeCall('policyFinish','clan',index,order.index,order.generation)
   end
  end)
  if not ok then K.on.instantPolicies=nil;NB.msg(tostring(err))
  else t.Enabled=true end
 end
 timer.Enabled=true
end

end

do
local K=NB.K16
K.types.court={off=0x19318,count=500,stride=0x28,vt=0x13D1608}
function K.courtName(p)
 local id=p and readSmallInteger(p+8)
 if not id or id&gt;270 then return '' end
 return K.stringEntry(0x400F+id)
end
function K.courtForOfficer(officer)
 local index=readSmallInteger(officer+0x140)
 local p=index and K.object('court',index)
 if p and readQword(p+0x10)==officer and K.courtName(p)~='' then return p,index end
 return nil
end
function K.courtAssignmentScript(symbol)
 local b=K.base()
 return (([[
[ENABLE]
assert(%X,48 89 5C 24 20 55 56 57 41 54 41 55 41 56 41 57)
assert(%X,40 53 48 83 EC 20 48 8B D9 E8 E2 25 04 00 48 8B)
assert(%X,48 85 C9 0F 84 5E 03 00 00 48 89 5C 24 10)
alloc(@N@,512,%X)
registersymbol(@N@)
label(reject)
label(assign)
label(done)
label(return)
@N@:
test rdx,rdx
jz assign
mov rax,[rdx+10]
test rax,rax
jz assign
cmp rax,rcx
jne reject
assign:
push rbx
push rsi
sub rsp,38
mov rbx,rcx
mov rsi,rdx
xor ecx,ecx
xor edx,edx
mov r8,rbx
mov r9d,2
mov qword ptr [rsp+20],0
call %X
test rsi,rsi
jz done
mov rcx,rsi
xor edx,edx
mov r8,rbx
xor r9d,r9d
mov qword ptr [rsp+20],0
call %X
done:
mov rcx,rbx
call %X
test rax,rax
jz return
mov rcx,rax
xor edx,edx
xor r8d,r8d
xor r9d,r9d
mov qword ptr [rsp+20],1
mov qword ptr [rsp+28],1
call %X
return:
add rsp,38
pop rsi
pop rbx
mov eax,1
ret
reject:
xor eax,eax
ret
[DISABLE]
unregistersymbol(@N@)
]]):format(b+0x640890,b+0x64E790,b+0x63C280,b,b+0x640890,b+0x640890,b+0x64E790,b+0x63C280):gsub('@N@',symbol))
end
function K.prepareCourtAssignment()
 if K.courtAssignment and K.courtAssignment.pid==K.pid then return end
 local symbol=('nb16Court_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.courtAssignmentScript(symbol)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 local address=assert(getAddressSafe(symbol));local bytes={}
 for _,v in ipairs(assert(readBytes(address,16,true))) do bytes[#bytes+1]=('%02X'):format(v) end
 K.nativeDefinitions.courtAssignment={rva=address-K.base(),bytes=table.concat(bytes,' '),kind='officer',
  argumentType='court',argumentNullable=true,allowPending=true}
 K.courtAssignment={pid=K.pid,address=address,symbol=symbol,script=script,info=info}
end
local field={en='Court office',jp='官職',off=0x140,size=2,min=-1,max=270,
 decode=function(index)
  local p=K.object('court',index)
  return p and readSmallInteger(p+8) or -1
 end,
 options=function(officer)
  local found={}
  for i=0,K.types.court.count-1 do
   local p=K.object('court',i)
   if p then
    local owner=readQword(p+0x10);local name=K.courtName(p)
    if name~='' and (owner==0 or owner==officer) then found[readSmallInteger(p+8)]=name end
   end
  end
  local out={'-1:'..NB.T('None','なし')}
  for id=0,270 do if found[id] then out[#out+1]=id..':'..found[id] end end
  return table.concat(out,'\n')
 end,
 apply=function(kind,index,value)
  local officer=assert(K.object(kind,index));local selected=0
  local current=K.courtForOfficer(officer)
  if current and readSmallInteger(current+8)==value then return 1 end
  if value&gt;=0 then
   for i=0,K.types.court.count-1 do
    local p=K.object('court',i)
    if p and readSmallInteger(p+8)==value and K.courtName(p)~='' then
     local owner=readQword(p+0x10)
     if owner==officer then selected=p;break end
     if owner==0 and selected==0 then selected=p end
    end
   end
   assert(selected~=0,NB.T('This court office has no available position.','この官職には空きがありません。'))
  end
  K.prepareCourtAssignment()
  return K.nativeCall('courtAssignment',kind,index,selected)
 end}
K.fields.officer[#K.fields.officer+1]=field

end

do
local K=NB.K16
K.sel=K.sel or {}
K.editors=K.editors or {}
function K.selected(kind)
 if kind=='player' then return K.player() end
 return K.object(kind,K.sel[kind])
end
function K.closeEditor(mr)
 local dead={}
 local function collect(parent)
  for i=0,parent.Count-1 do local child=parent.Child[i];dead[child.ID]=true;collect(child) end
 end
 collect(mr)
 if NB.dyn then
  local keep={};for _,entry in ipairs(NB.dyn) do if not dead[entry.mr.ID] then keep[#keep+1]=entry end end
  NB.dyn=keep
 end
 K.editors[mr.ID]=nil;NB.clearChildren(mr)
 for id in pairs(dead) do
  local custom=K.editorCustomTypes and K.editorCustomTypes[id]
  if custom then custom.destroy();K.editorCustomTypes[id]=nil end
 end
end
function K.refreshSuffix()
 for _,e in ipairs({{102,'player'},{403,'officer'},{303,'city'},{306,'county'},{210,'army'}}) do
  local p=K.selected(e[2])
  NB.suffix[e[1]]=p and K.name(e[2]=='player' and 'officer' or e[2],p) or NB.T('(not selected)','（未選択）')
 end
 NB.applyLang()
end
function K.startEditTimer()
 if K.editTimer then K.editTimer.Enabled=true;return end
 local timer=createTimer(nil,false);timer.Interval=25;K.editTimer=timer
 timer.OnTimer=function(t)
  t.Enabled=false
  local ok=NB.userRun(function() K.applyNextEdit() end)
  if not ok then K.cancelEdits() end
  if K.refreshEditorRows then
   K.refreshEditorRows=nil
   local editors={};for _,e in pairs(K.editors) do editors[#editors+1]=e end
   for _,e in ipairs(editors) do K.openEditor(e.mr,e.kind) end
  end
  if next(K.pendingEdits) then t.Enabled=true end
 end
 timer.Enabled=true
end
function K.addField(parent,kind,index,field)
 local p=assert(K.object(kind,index));local token=K.key()
 local generation=kind=='army' and readInteger(p+0x374) or nil
 K.typeSerial=(K.typeSerial or 0)+1
 local typeName=('NB16_%X_%X_%d'):format(K.pid,getTickCount(),K.typeSerial)
 local function decode(...)
  local b={...};local v=0;for i=1,field.size do v=v|((b[i] or 0)&lt;&lt;((i-1)*8)) end
  local value=field.decode and field.decode(v) or v
  if field.displaySignedText then return tostring(value) end
  return value
 end
 local function encode(value)
  local current=K.object(kind,index)
  local unchanged=current and readBytes(current+field.off,field.size,true) or {}
  if K.key()~=token or current~=p then return unchanged end
  if generation and (not K.armyActive(p) or readInteger(p+0x374)~=generation) then return unchanged end
  local ok=NB.userRun(function() K.queueEdit(kind,index,field,value) end)
  if ok then K.startEditTimer() end
  return unchanged
 end
 local custom=registerCustomTypeLua(typeName,field.size,decode,encode,false,field.displaySignedText==true)
 if custom then custom.InternalOnly=true end
 local en,jp=field.en,field.jp
 if field.label then en,jp=field.label(p) end
 local row=NB.addRec(parent,en,jp,K.exe..'+213CB08',vtCustom)
 if custom then
  K.editorCustomTypes=K.editorCustomTypes or {};K.editorCustomTypes[row.ID]=custom
 end
 row.OffsetCount=2;row.Offset[0]=field.off;row.Offset[1]=K.types[kind].off+index*8
 row.CustomTypeName=typeName
 if field.options then
  row.DropDownList.Text=field.options(p);row.DropDownReadOnly=true
  row.DropDownDescriptionOnly=true;row.DisplayAsDropDownListItem=true
 end
 row.OnActivate=function(_,before)
  if before then return K.key()==token and K.object(kind,index)==p
   and (not generation or (K.armyActive(p) and readInteger(p+0x374)==generation)) end
  return true
 end
 return row
end
function K.openEditor(mr,kind)
 K.ready();K.closeEditor(mr)
 K.editorChoiceCache={}
 local p=K.selected(kind)
 if not p then NB.msg('Select an officer/city first.','先に武将・都市を選択してください。');return end
 local target=kind=='player' and 'officer' or kind
 local index=assert(K.indexOf(target,p))
 for _,field in ipairs(K.fields[target] or {}) do
  if not field.visible or field.visible(p) then
   K.addField(mr,target,index,field)
  end
 end
 if kind=='player' then
  local d=assert(K.indexOf('district',readQword(p+0x88)))
  for _,field in ipairs(K.fields.district) do K.addField(mr,'district',d,field) end
  local c=assert(K.indexOf('clan',K.clan()))
  for _,field in ipairs(K.fields.clan or {}) do K.addField(mr,'clan',c,field) end
 end
 K.editors[mr.ID]={mr=mr,kind=kind};mr.Collapsed=false;K.refreshSuffix()
end
function K.select(kind,index)
 K.ready();assert(K.object(kind,index),'Awakening selection unavailable')
 local reopen={}
 for _,e in pairs(K.editors) do if e.kind==kind then reopen[#reopen+1]=e.mr end end
 for _,mr in ipairs(reopen) do K.closeEditor(mr) end
 K.sel[kind]=index
 for _,mr in ipairs(reopen) do K.openEditor(mr,kind) end
 K.refreshSuffix()
end
function K.search(kind)
 K.ready()
 local query=inputQuery(NB.T('Search name','名前を検索'),NB.T('Part of name; blank lists all:','名前の一部を入力。空欄は全件表示：'),'')
 if query==nil then return end
 local ids,names={},{}
 for _,item in ipairs(K.objects(kind)) do
  local name=K.name(kind,item.address)
  if name~='' and name:find(query,1,true) then
   ids[#ids+1]=item.index;names[#names+1]=('%s [ID %d]'):format(name,item.index)
  end
 end
 if #ids==0 then NB.msg('Not found.','見つかりません。');return end
 local n=NB.pick(NB.T('Select result','候補を選択'),names)
 if n then K.select(kind,ids[n]) end
end

end

do
local K=NB.K16
function K.ownsOfficer(p)
 if K.indexOf('officer',p)==nil then return false end
 local d=readQword(p+0x88)
 local gen=readInteger(p+0x90)
 return K.indexOf('district',d)~=nil and gen and gen~=0
  and readInteger(d+0x114)==gen and readQword(d+0x10)==K.clan() or false
end
function K.treasureRecipients()
 local c=K.ready();local clan=assert(K.clan())
 local function n(bytes,offset,size)
  local v=0;for i=size-1,0,-1 do v=(v&lt;&lt;8)|bytes[offset+i+1] end;return v
 end
 local districts={}
 for _,item in ipairs(K.objects('district')) do
  if readQword(item.address+0x10)==clan then
   districts[item.address]=readInteger(item.address+0x114)
  end
 end
 local typ=K.types.officer;local first=assert(readQword(c.root+typ.off))
 local vector=assert(readBytes(c.root+typ.off,typ.count*8,true))
 local out,names={},{}
 for start=0,typ.count-1,32 do
  local count=math.min(32,typ.count-start)
  local bytes=assert(readBytes(first+start*typ.stride,count*typ.stride,true))
  for i=0,count-1 do
   local id=start+i;local p=first+id*typ.stride;local off=i*typ.stride
   assert(n(vector,id*8,8)==p and n(bytes,off,8)==c.base+typ.vt,'Officer array changed')
   local district=n(bytes,off+0x88,8);local gen=n(bytes,off+0x90,4)
   if gen~=0 and districts[district]==gen then
    local name=K.name('officer',p)
    if name~='' then out[#out+1]={id=id,p=p};names[#names+1]=name end
   end
  end
 end
 assert(K.key()==c.key,'Scenario changed while listing recipients')
 return out,names
end
function K.giveTreasure(officer,treasure)
 assert(K.ownsOfficer(officer),'Recipient is no longer in your clan')
 return K.transferTreasure(assert(K.indexOf('treasure',treasure)),assert(K.indexOf('officer',officer)))
end
function K.treasureCategories()
 local labels={}
 local en={'Tea utensils','Weapons','Horses','Books','Paintings','Incense utensils','Western imports','Chinese imports'}
 local jp={'茶道具','武具','名馬','書物','絵画','香木・香道具','南蛮物','唐物'}
 for i=1,8 do labels[i]=NB.T(en[i],jp[i]) end
 local items=K.treasureCatalog()
 for _,item in ipairs(items) do item.p=K.object('treasure',item.id) end
 return labels,items,K.key()
end
function K.treasureCatalog()
 local out={}
 for _,item in ipairs(K.objects('treasure')) do
  local p=item.address
  local flags=readSmallInteger(p+0x3E)
  local name=K.name('treasure',p)
  local category=readInteger(p+0x38)
  if flags and (flags&amp;3)~=2 and name~='' and category and category&gt;=0 and category&lt;=7 then
   local owner=readQword(p+0x20)
   out[#out+1]={id=item.index,name=name,category=category,
    grade=readInteger(p+0x34),owner=K.indexOf('officer',owner)}
  end
 end
 return out
end
function K.transferTreasure(treasureIndex,officerIndex)
 K.ready()
 local treasure=assert(K.object('treasure',treasureIndex),'Awakening treasure unavailable')
 local officer=assert(K.object('officer',officerIndex),'Awakening officer unavailable')
 local flags=assert(readSmallInteger(treasure+0x3E))
 assert((flags&amp;3)~=2 and K.name('treasure',treasure)~='','Awakening treasure is not defined')
 local owner=readQword(treasure+0x20)
 assert(owner==0 or K.indexOf('officer',owner)~=nil,'Awakening treasure owner is invalid')
 if owner==officer then return false end
 K.nativeCall('treasureTransfer','officer',officerIndex,treasure,0,0)
 assert(readQword(treasure+0x20)==officer,'Awakening treasure transfer was not applied')
 return true
end

end

do
local K=NB.K16
function K.closeTreasureWizard()
 if not inMainThread()then synchronize(K.closeTreasureWizard);return end
 if K.treasureLaunchTimer then K.treasureLaunchTimer.destroy();K.treasureLaunchTimer=nil end
 local w=K.treasureWizard
 if w then w.form.close() end
end
function K.openTreasureWizard()
 if not inMainThread()then synchronize(K.openTreasureWizard);return end
 K.ready()
 if K.treasureWizard then K.treasureWizard.form.bringToFront();return end
 local labels,all,token=K.treasureCategories()
 local form=createForm(false)
 local w={form=form,token=token,page=1,remember={},all=all,categories=labels}
 K.treasureWizard=w
 form.Name='N16TreasureWizard';form.Position='poScreenCenter';form.BorderStyle='bsDialog'
 form.ClientWidth=700;form.ClientHeight=520
 form.OnClose=function()
  if w.inGrant then w.cancelRequested=true;return caNone or 0 end
  if w.grantTimer then w.grantTimer.destroy();w.grantTimer=nil end
  if K.treasureWizard==w then K.treasureWizard=nil end
  return caFree
 end
 local hint=createLabel(form);hint.Left=12;hint.Top=12;hint.Width=676
 local list=createListBox(form);list.Name='TreasureChoices';list.Left=12;list.Top=42;list.Width=676;list.Height=400
 w.list=list;w.hint=hint
 local function button(name,caption,left,width)
  local b=createButton(form);b.Name=name;b.Caption=caption;b.Left=left;b.Top=466;b.Width=width;b.Height=32;return b
 end
 local allButton=button('TreasureAll',NB.T('Select all','すべて選択'),12,112)
 local clearButton=button('TreasureClear',NB.T('Clear','選択解除'),132,100)
 local back=button('TreasureBack',NB.T('Back','戻る'),338,100)
 local nextButton=button('TreasureNext',NB.T('Next','次へ'),446,110)
 nextButton.Default=true
 local cancel=button('TreasureCancel',NB.T('Cancel','キャンセル'),564,124);cancel.Cancel=true
 w.next=nextButton;w.back=back;w.cancel=cancel;w.allButton=allButton;w.clearButton=clearButton
 local function selected()
  local result={}
  if w.page==2 then
   for i=0,list.Items.Count-1 do if list.Selected[i]then result[#result+1]=i+1 end end
  elseif list.ItemIndex&gt;=0 then result[1]=list.ItemIndex+1 end
  return result
 end
 local function show(page,names,remember)
  w.page=page;list.Items.beginUpdate()
  local ok,why=pcall(function()
   list.Items.clear();list.MultiSelect=page==2;list.ItemIndex=-1
   for _,name in ipairs(names)do list.Items.add(name)end
  end)
  list.Items.endUpdate();if not ok then error(why,0)end
  for _,i in ipairs(remember or {})do
   if i&gt;=1 and i&lt;=#names then if page==2 then list.Selected[i-1]=true else list.ItemIndex=i-1 end end
  end
  back.Enabled=page&gt;1;allButton.Visible=page==2;clearButton.Visible=page==2
  form.Caption=page==1 and NB.T('Treasure category','家宝の分類') or page==2 and NB.T('Select treasures','家宝を複数選択') or NB.T('Recipient officer','授与先の武将')
  hint.Caption=page==2 and NB.T('Ctrl / Shift: select multiple treasures','Ctrl / Shiftで複数の家宝を選択できます') or NB.T('Select an entry.','項目を選択してください。')
  nextButton.Caption=page==3 and NB.T('Assign','授与') or NB.T('Next','次へ')
 end
 local function itemPage()
  w.items={};w.itemNames={}
  for _,item in ipairs(w.all)do
   if item.category==w.category then
    w.items[#w.items+1]=item;w.itemNames[#w.itemNames+1]=item.name
   end
  end
  show(2,w.itemNames,w.remember[w.category])
 end
 local function guard()
  K.ready();assert(K.key()==token,NB.T('Game data changed; reopen the treasure list.','ゲームデータが変わりました。家宝一覧を開き直してください。'))
 end
 local function run(fn)
  if w.busy then return end
  local ok,why=pcall(fn)
  if not ok then hint.Caption=NB.T('Operation failed. See Lua Engine.','処理できませんでした。Lua Engineを確認してください。');NB.msg(tostring(why)) end
 end
 nextButton.OnClick=function()run(function()
  guard();local choices=selected()
  if #choices==0 then hint.Caption=NB.T('Select at least one entry.','項目を1件以上選択してください。');return end
  if w.page==1 then
   w.categoryChoice=choices;w.category=choices[1]-1;itemPage()
  elseif w.page==2 then
   w.remember[w.category]=choices
   if not w.officers then w.officers,w.officerNames=K.treasureRecipients()end
   show(3,w.officerNames,w.recipient)
  else
   w.recipient=choices;local officer=assert(w.officers[choices[1]])
   w.busy=true;nextButton.Enabled=false;back.Enabled=false
   local queue={};for _,i in ipairs(w.remember[w.category])do queue[#queue+1]=assert(w.items[i]).p end
   local done=0;local timer=createTimer(nil,false);w.grantTimer=timer;timer.Interval=25
   timer.OnTimer=function(t)
    t.Enabled=false
    if K.treasureWizard~=w then return end
    w.inGrant=true
    local ok,why=pcall(function()
     guard();K.giveTreasure(officer.p,queue[done+1]);done=done+1
    end)
    w.inGrant=false
    if w.cancelRequested then t.destroy();w.grantTimer=nil;w.busy=false;form.close();return end
    if not ok then
     t.destroy();w.grantTimer=nil;w.busy=false;nextButton.Enabled=true;back.Enabled=true
     hint.Caption=NB.T('Assignment stopped. See Lua Engine.','授与を中断しました。Lua Engineを確認してください。');NB.msg(tostring(why));return
    end
    hint.Caption=NB.T('Assigned: ','授与済み：')..done..' / '..#queue
    if done==#queue then
     t.destroy();w.grantTimer=nil;w.busy=false
     NB.msg(('Assigned %d treasures.'):format(done),('家宝を%d件授与しました。'):format(done));form.close()
    else t.Enabled=true end
   end
   timer.Enabled=true
  end
 end)end
 back.OnClick=function()run(function()
  if w.page==3 then w.recipient=selected();itemPage()
  elseif w.page==2 then w.remember[w.category]=selected();show(1,w.categories,w.categoryChoice)end
 end)end
 allButton.OnClick=function()list.selectAll()end
 clearButton.OnClick=function()list.clearSelection()end
 cancel.OnClick=function()form.close()end
 list.OnDblClick=function()if w.page~=2 then nextButton.OnClick()end end
 show(1,labels);form.show()
end
function K.assignTreasure()
 K.ready()
 if not inMainThread()then synchronize(K.assignTreasure);return end
 if K.treasureWizard then K.treasureWizard.form.bringToFront();return end
 if K.treasureLaunchTimer then return end
 -- AA checkbox execution must return before the interactive wizard opens.
 local timer=createTimer(nil,false);K.treasureLaunchTimer=timer;timer.Interval=1
 timer.OnTimer=function(t)
  t.destroy();K.treasureLaunchTimer=nil
  local ok,why=pcall(K.openTreasureWizard)
  if not ok then K.closeTreasureWizard();NB.msg(tostring(why))end
 end
 timer.Enabled=true
end

end

do
local K=NB.K16
K.VERSION='1.0.1.35977'
K.STEAMBUILD='18823764'
function K.processAlive(pid)
 if not pid then return false end
 local processes=getProcessList()
 return processes[pid]~=nil or processes[tostring(pid)]~=nil
end
function K.allOff()
 local alive=K.processAlive(K.pid)
 assert(not alive or getOpenedProcessID()==K.pid,
  NB.T('Reconnect to the previous Awakening process before releasing its features.',
   '機能を解除する前に、以前の新生プロセスへ接続してください。'))
 assert(not K.nativeBusy(),
  NB.T('An Awakening operation is still running. Wait for it to finish.',
   '新生の処理が実行中です。完了するまでお待ちください。'))
 if K.closeTreasureWizard then K.closeTreasureWizard() end
 assert(not K.treasureWizard or not K.treasureWizard.inGrant,
  NB.T('A treasure transfer is finishing. Try again after it finishes.',
   '家宝の授与処理が終了してから再実行してください。'))
 if K.editTimer then K.editTimer.destroy();K.editTimer=nil end
 for name,timer in pairs(K.timers) do timer.destroy();K.timers[name]=nil end
 K.cancelEdits()
 if K.setMovement then
  if alive then K.setMovement(false) else K.movementHook=nil;K.siegeMovementHooks={} end
 end
 if K.setSiegeProtection then
  if alive then K.setSiegeProtection(false);K.setSiegeProtection(false,true);K.setSiegeProtection(false,'onehit')
  else K.siegeHooks={};K.siegeSkillHooks={};K.siegeOneHitHooks={} end
 end
 local names={}
 for name in pairs(K.successHooks or {}) do names[#names+1]=name end
 for _,name in ipairs(names) do
  if alive then K.removeSuccessHook(name) else K.successHooks[name]=nil end
 end
 names={}
 for name in pairs(K.battleHooks or {}) do names[#names+1]=name end
 for _,name in ipairs(names) do
  if alive then K.removeBattleHook(name) else K.battleHooks[name]=nil end
 end
 names={}
 for name in pairs(K.actionHooks or {}) do names[#names+1]=name end
 for _,name in ipairs(names) do
  if alive then K.removeActionHook(name) else K.actionHooks[name]=nil end
 end
 if alive then
  K.removeOneHit()
  K.removeCastleOneHit()
 else K.oneHitHook=nil;K.castleOneHitHook=nil end
 if alive then K.removeNative() else K.native=nil end
 if K.siegeRefill then
  if getAddressSafe('nb16SiegeRefill')==K.siegeRefill.address then unregisterSymbol('nb16SiegeRefill') end
  K.siegeRefill=nil;K.nativeDefinitions.siegeRefill=nil
 end
 if K.prestigeEdit then
  if getAddressSafe('nb16PrestigeEdit')==K.prestigeEdit.address then unregisterSymbol('nb16PrestigeEdit') end
  K.prestigeEdit=nil;K.nativeDefinitions.prestigeEdit=nil
 end
 if K.policyFinish then
  if getAddressSafe('nb16PolicyFinish')==K.policyFinish.address then unregisterSymbol('nb16PolicyFinish') end
  K.policyFinish=nil;K.nativeDefinitions.policyFinish=nil
 end
 if K.goodwillFinish then
  if getAddressSafe(K.goodwillFinish.symbol)==K.goodwillFinish.address then unregisterSymbol(K.goodwillFinish.symbol) end
  K.goodwillFinish=nil;K.nativeDefinitions.goodwillFinish=nil
 end
 if K.courtAssignment then
  if getAddressSafe(K.courtAssignment.symbol)==K.courtAssignment.address then unregisterSymbol(K.courtAssignment.symbol) end
  K.courtAssignment=nil;K.nativeDefinitions.courtAssignment=nil
 end
 if K.missionFinish then
  if getAddressSafe(K.missionFinish.symbol)==K.missionFinish.address then unregisterSymbol(K.missionFinish.symbol) end
  K.missionFinish=nil;K.nativeDefinitions.missionFinish=nil
 end
 K.on={}
end
function K.disconnect()
 K.allOff()
 local rows={}
 for _,editor in pairs(K.editors) do rows[#rows+1]=editor.mr end
 for _,row in ipairs(rows) do K.closeEditor(row) end
 K.sel={};K.pid=nil;K.sessionKey=nil
end
function K.attachAndOff()
 if K.pid then K.disconnect() end
 local pid=getProcessIDFromProcessName(K.exe)
 assert(pid and pid~=0,NB.T('Start Awakening PK first.','先に新生PKを起動してください。'))
 openProcess(pid)
 assert(getOpenedProcessID()==pid and K.buildMatches(),
  NB.T('The Awakening executable does not match this table.','新生のEXEがこのテーブルの対応ビルドと一致しません。'))
 K.bind()
 NB.msg(('Attached to %s (PID %d), version %s, Steam build %s.'):format(
  K.exe,pid,K.VERSION,K.STEAMBUILD),
  ('%s（PID %d）へアタッチ。バージョン%s、Steam build %s。'):format(
  K.exe,pid,K.VERSION,K.STEAMBUILD))
end
function K.report()
 NB.msg(('Awakening PK: %s; version %s; Steam build %s; PE 68495A9E; SizeOfImage 2653000; PID %s.'):format(
  K.exe,K.VERSION,K.STEAMBUILD,tostring(K.pid)))
end

end

do
local K=NB.K16
function K.ownsObject(kind,p)
 if kind=='army' then return K.ownsArmy(p) end
 if kind=='officer' then return K.ownsOfficer(p) end
 if kind=='clan' then return p==K.clan() end
 if kind=='district' then return K.indexOf(kind,p)~=nil and readQword(p+0x10)==K.clan() end
 if kind=='city' and K.indexOf(kind,p)~=nil then
  local d=readQword(p+0x18);local g=readInteger(p+0x20)
  return g and g~=0 and K.indexOf('district',d)~=nil
   and readInteger(d+0x114)==g and readQword(d+0x10)==K.clan() or false
 end
 return false
end
function K.queueMaximum(kind,index,field,value,feature)
 local p=assert(K.object(kind,index))
 if not K.ownsObject(kind,p) then return end
 local current=field.size==2 and readSmallInteger(p+field.off) or readInteger(p+field.off)
 if current==value then return end
 local _,e=K.queueEdit(kind,index,field,value)
 e.owned=true;e.feature=feature
end
function K.refreshMaximum()
 K.ready()
 if K.nativeBusy() then return end
 if K.on.cityMax then
  for _,item in ipairs(K.objects('city')) do
   if K.ownsObject('city',item.address) then
    K.queueMaximum('city',item.index,K.fields.city[1],99999,'cityMax')
    K.queueMaximum('city',item.index,K.fields.city[2],99999,'cityMax')
    local maximum=K.nativeCall('cityDurabilityMax','city',item.index)
    if maximum and maximum&gt;=0 and maximum&lt;=50000 then
     K.queueMaximum('city',item.index,K.fields.city[3],maximum,'cityMax')
    end
   end
  end
 end
 if K.on.ownBattle then
  for _,item in ipairs(K.armies(true)) do
   K.refillSiegeArmy(item.index)
   local initial=readInteger(item.address+0x1B8)
   if initial and initial&gt;0 and initial&lt;=500000 then
    K.queueMaximum('army',item.index,K.fields.army[1],initial,'ownBattle')
   end
   K.queueMaximum('army',item.index,K.fields.army[2],50000,'ownBattle')
  end
 end
 if next(K.pendingEdits) then K.startEditTimer() end
end
function K.setMaximumTimer()
 local needed=K.on.cityMax or K.on.ownBattle
 if not needed then
  if K.timers.maximum then K.timers.maximum.destroy();K.timers.maximum=nil end
  return
 end
 if K.timers.maximum then return end
 local t=createTimer(nil,false);t.Interval=1000;K.timers.maximum=t
 t.OnTimer=function(timer)
  timer.Enabled=false
  local ok=NB.userRun(K.refreshMaximum)
  if ok then timer.Enabled=true end
 end
 t.Enabled=true
end

end

do
local K=NB.K16
function K.setLoyaltyTimer(enabled)
 K.on.loyalty=nil
 if K.timers.loyalty then K.timers.loyalty.destroy();K.timers.loyalty=nil end
 for id,e in pairs(K.pendingEdits) do if e.feature=='loyalty' then K.pendingEdits[id]=nil end end
 if not enabled then return end
 K.ready();K.installNative()
 local field
 for _,f in ipairs(K.fields.officer) do if f.off==0x142 then field=f;break end end
 assert(field,'Loyalty field unavailable')
 K.on.loyalty=true
 local cursor=0
 local timer=createTimer(nil,false);timer.Interval=100;K.timers.loyalty=timer
 timer.OnTimer=function()
  timer.Enabled=false
  local ok=NB.userRun(function()
   K.ready()
   for _=1,256 do
    local i=cursor;cursor=(cursor+1)%K.types.officer.count
    local p=K.object('officer',i)
    local status=p and readBytes(p+0x138,1)
    local eligible=status and status&lt;=13 and ((0x204B&gt;&gt;status)&amp;1)==0
    if eligible and p~=K.player() and K.ownsOfficer(p) and readBytes(p+0x142,1)~=20 then
     local _,e=K.queueEdit('officer',i,field,20)
     e.owned=true;e.feature='loyalty'
    end
   end
   if next(K.pendingEdits) then K.startEditTimer() end
  end)
  if ok then timer.Enabled=true else K.on.loyalty=nil end
 end
 timer.Enabled=true
end

end

do
local K=NB.K16
function K.countySlotLevel(p,slot)
 local value=readInteger(p+0xF8+math.floor(slot/8)*4)
 return value and ((value&gt;&gt;((slot%8)*4))&amp;15)
end
function K.maximizeCounty(index)
 local p=K.object('county',index)
 if not p or not K.ownsObject('city',readQword(p+8)) then return false end
 for slot=0,19 do
  local definition=readQword(p+0x58+slot*8)
  if definition and definition~=0 then
   local kind=readBytes(definition+0xC,1)
   if kind==0 or kind==1 or kind==5 then
    local level=K.countySlotLevel(p,slot)
    if level and level&lt;10 then
     K.nativeCall('countyDevelop','county',index,slot,10-level,1)
     return true
    end
   end
  end
 end
 return false
end
function K.setCountyTimer()
 if K.timers.counties then K.timers.counties.destroy();K.timers.counties=nil end
 if not K.on.cityMax and not K.on.instantDevelopment then return end
 local cursor=0
 local timer=createTimer(nil,false);timer.Interval=25;K.timers.counties=timer
 timer.OnTimer=function()
  if K.nativeBusy() then return end
  timer.Enabled=false
  local ok=NB.userRun(function()
   K.ready()
   for _=1,96 do
    local index=cursor
    cursor=(cursor+1)%K.types.county.count
    if K.finishCountyWork and K.finishCountyWork(index) then return end
    if K.on.cityMax and K.maximizeCounty(index) then return end
   end
  end)
  if ok then timer.Enabled=true end
 end
 timer.Enabled=true
end

end

do
local K=NB.K16
K.types.countyDevelopment={off=0x2B990,count=100,stride=0x20,vt=0x13D1988}
local english={'Farms','Market','Trading port','Gold mine town','Silver mine town','Large farms','Large market',
 'Horse ranch','Smithing town','Temple','Shrine','Christian church','Hot springs','Granary','Fort',
 'Sansai market','Common land','Garden','Branch castle','Not built'}
function K.countyDevelopmentDefinition(p,slot)
 local definition=readQword(p+0x58+slot*8)
 if not K.indexOf('countyDevelopment',definition) then return nil end
 local kind=readBytes(definition+0xC,1);local name=readSmallInteger(definition+0xA)
 if (kind~=0 and kind~=1 and kind~=5) or not name or name&gt;19 then return nil end
 return definition,name
end
K.fields.county={}
for slot=0,19 do
 local position=slot
 K.fields.county[#K.fields.county+1]={en='Development slot '..(position+1),jp='開発枠'..(position+1),
  off=0xF8+math.floor(position/8)*4,size=4,min=0,max=10,
  decode=function(value)return (value&gt;&gt;((position%8)*4))&amp;15 end,
  visible=function(p)return K.countyDevelopmentDefinition(p,position)~=nil end,
  label=function(p)
   local _,name=K.countyDevelopmentDefinition(p,position)
   return ('%s development [%d]'):format(english[(name or 19)+1],position+1),
    ('%s 開発度 [%d]'):format(K.stringEntry(0x5D8A+(name or 19)),position+1)
  end,
  apply=function(kind,index,value)
   local p=assert(K.object(kind,index));assert(K.countyDevelopmentDefinition(p,position),'Development slot changed')
   local current=assert(K.countySlotLevel(p,position))
   if current==value then return 1 end
   return K.nativeCall('countyDevelop',kind,index,position,value-current,1)
  end}
end

end

do
local K=NB.K16
K.nativeDefinitions.countyConstructionFinish={rva=0x660C10,
 bytes='48 89 5C 24 10 48 89 74 24 18 48 89 7C 24 20',kind='county',countyOrder=true,allowPending=true}
function K.countyWork(index)
 local p=K.object('county',index)
 if not p or not K.ownsObject('city',readQword(p+8)) then return nil end
 local slot=readBytes(p+0x104,1)
 local definition=readBytes(p+0x106,1)
 if not slot or slot&gt;=20 or not definition or definition&gt;=100 then return nil end
 local target=K.object('countyDevelopment',definition)
 if not target or readBytes(target+0xC,1)~=2 then return nil end
 return p,slot,definition,target
end
function K.finishCountyWork(index)
 local p,slot,definition,target=K.countyWork(index)
 if not p then return false end
 K.nativeCall('countyConstructionFinish','county',index)
 if K.nativeBusy() then return true end
 assert(readBytes(p+0x104,1)==255 and readBytes(p+0x105,1)==0
  and readBytes(p+0x106,1)==255 and readQword(p+0x58+slot*8)==target,
  NB.T('County facility completion did not apply.','郡施設の完成処理が反映されませんでした。'))
 return true
end

end

do
-- Resolve each order through the owning city's live list before execution.
local K=NB.K16
function K.findConstruction(index,wanted)
 local city=K.object('city',index)
 if not city or not K.ownsObject('city',city) then return end
 local head=readQword(city+0x470)
 if not head or head==0 then return end
 local node=readQword(head);local seen={}
 for _=1,256 do
  if not node or node==0 or node==head or seen[node] then return end
  seen[node]=true
  local p=readQword(node+0x10)
  if p and p~=0 and (not wanted or wanted==p)
   and readQword(p)==K.base()+0x1376AE0 and readInteger(p+8)==1
   and readQword(p+0x30)==city and readInteger(p+0x70)==index then
   return p
  end
  node=readQword(node)
 end
end
function K.finishConstruction(index)
 K.ready()
 local order=K.findConstruction(index)
 if not order then return false end
 if readInteger(order+0x68)==0 then return false end
 K.nativeCall('constructionFinish','city',index,0,order)
 return true
end
function K.setConstructionTimer(enabled)
 K.on.instantDevelopment=enabled or nil
 K.setTownTimer();K.setCountyTimer()
end
function K.setTownTimer()
 if K.timers.construction then
  K.timers.construction.destroy();K.timers.construction=nil
 end
 if not K.on.instantDevelopment and not K.on.facilityMax then return end
 local nextIndex=0
 local timer=createTimer(nil,false)
 K.timers.construction=timer;timer.Interval=250
 timer.OnTimer=function()
  if K.nativeBusy() then return end
  local ok,err=pcall(function()
   K.ready()
   -- Bound reads and complete at most one order per tick.
   for _=1,32 do
    local index=nextIndex
    nextIndex=(nextIndex+1)%K.types.city.count
    local changed=K.on.instantDevelopment and K.finishConstruction(index)
    if not changed and K.on.facilityMax then
     local city=K.object('city',index)
     if city and K.ownsObject('city',city) then
      for slot=0,9 do
       if K.upgradeFacility(index,slot) then changed=true;break end
      end
     end
    end
    if changed then break end
   end
  end)
  if not ok then
   timer.Enabled=false;K.on.instantDevelopment=nil;K.on.facilityMax=nil
   NB.msg(tostring(err))
  end
 end
 timer.Enabled=true
end
function K.upgradeFacility(index,slot)
 K.ready()
 assert(type(slot)=='number' and slot%1==0 and slot&gt;=0 and slot&lt;10,'Invalid facility slot')
 local city=K.object('city',index)
 if not city or not K.ownsObject('city',city) then return false end
 if readSmallInteger(city+0xC4+slot*2)~=3 then return false end
 local facility=K.object('facility',readSmallInteger(city+0xB0+slot*2))
 if not facility then return false end
 local level=readBytes(city+0xD8+slot,1)
 local maximum=readBytes(facility+0x78,1)
 if not level or not maximum or maximum&gt;4 or level&gt;=maximum then return false end
 K.nativeCall('facilityUpgrade','city',index,facility,1&lt;&lt;slot,1)
 return true
end

end

do
local K=NB.K16
K.successSites={
 supplyRaid={rva=0xCF5403,bytes='8B F8 3B FE 0F 8C 15 01 00 00',length=10,obj='[rbp+70]',kind=53,feature='strategySuccess',failure=0xCF5522,
  original='mov edi,eax\ncmp edi,esi\njl @F@'},
 massArson={rva=0xCE4566,bytes='39 44 24 64 7C 42',length=6,obj='[rbp-10]',kind=44,feature='strategySuccess',roll=true,failure=0xCE45AE,
  original='cmp [rsp+64],eax\njl @F@'},
 massRumor={rva=0xCECB62,bytes='39 85 B8 00 00 00',length=6,obj='[rsp+A8]',kind=45,feature='strategySuccess',roll=true,
  original='cmp [rbp+B8],eax'},
 massIncitement={rva=0xCD8DD5,bytes='39 45 84 7C 42',length=5,obj='[rbp-68]',kind=46,feature='strategySuccess',roll=true,failure=0xCD8E1C,
  original='cmp [rbp-7C],eax\njl @F@'},
 massAssassination={rva=0xCE5D59,bytes='39 85 E8 00 00 00',length=6,obj='[rbp-50]',kind=58,feature='strategySuccess',roll=true,
  original='cmp [rbp+E8],eax'},
 intimidation={rva=0xCE0CFE,bytes='3B C6 0F 8C EF 00 00 00',length=8,obj='r15',kind=55,feature='strategySuccess',failure=0xCE0DF5,
  original='cmp eax,esi\njl @F@'},
 falseReport={rva=0xCDC2F4,bytes='3B C6 0F 8C B7 00 00 00',length=8,obj='r14',kind=56,feature='strategySuccess',failure=0xCDC3B3,
  original='cmp eax,esi\njl @F@'},
 assassination={rva=0xD02D6A,bytes='3B C3 0F 9D C1',length=5,obj='r15',kind=15,feature='strategySuccess',
  original='cmp eax,ebx\nsetge cl'},
 sabotage={rva=0xCDEA3B,bytes='8B D8 45 33 E4',length=5,obj='r15',kind=7,feature='strategySuccess',
  original='mov ebx,eax\nxor r12d,r12d'},
 incitement={rva=0xCE30BA,bytes='33 C9 3B C3 0F 9D C1',length=7,obj='r14',kind=5,feature='strategySuccess',
  original='xor ecx,ecx\ncmp eax,ebx\nsetge cl'},
 estrangement={rva=0xCF72E4,bytes='33 FF 3B C3 40 0F 9D C7',length=8,obj='r15',kind=10,feature='strategySuccess',
  original='xor edi,edi\ncmp eax,ebx\nsetge dil'},
 surrender={rva=0xCE9AE5,bytes='41 8B FE 3B C3',length=5,obj='r13',kind=52,feature='strategySuccess',
  original='mov edi,r14d\ncmp eax,ebx'},
 poaching={rva=0xCD3B49,bytes='41 8B F7 3B C3',length=5,obj='[rbp-68]',kind=1,feature='recruitment',
  original='mov esi,r15d\ncmp eax,ebx'},
 recruit={rva=0xCFB452,bytes='8B C8 0F B6 54 24 50',length=7,obj='r15',kind=17,feature='recruitment',
  original='mov ecx,eax\nmovzx edx,byte ptr [rsp+50]'},
 siegeScheme={rva=0xCEB0AC,bytes='33 C9 3B C3 0F 9D C1',length=7,obj='r14',kind=13,feature='strategySuccess',
  original='xor ecx,ecx\ncmp eax,ebx\nsetge cl'},
 poisonScheme={rva=0xD01634,bytes='33 F6 8B CE 3B C3',length=6,obj='r13',kind=19,feature='strategySuccess',
  original='xor esi,esi\nmov ecx,esi\ncmp eax,ebx'},
 loyaltyScheme={rva=0xCF860B,bytes='41 8B F6 3B C3',length=5,obj='r15',kind=20,feature='strategySuccess',
  original='mov esi,r14d\ncmp eax,ebx'}}
function K.successScript(name,symbol)
 local d=assert(K.successSites[name]);local c=K.ready();local own=assert(K.clan());local b=c.base
 local script=(([[
[ENABLE]
assert(%X,%s)
alloc(@N@,4096,%X)
registersymbol(@N@)
label(skip)
@N@:
pushfq
push rax
push rcx
push rdx
push r10
push r11
mov rax,[%X]
mov r11,%X
cmp rax,r11
jne skip
mov rax,[rax+1B260]
mov r11,%X
cmp rax,r11
jne skip
mov rax,[rax+1047E0]
mov r11,%X
cmp rax,r11
jne skip
mov rax,%X
mov r11,[rax+1B270]
mov r10,@O@
cmp r10,r11
jb skip
mov rax,r10
sub rax,r11
cmp rax,1DB00
jae skip
xor edx,edx
mov r11,98
div r11
test rdx,rdx
jne skip
mov rax,%X
cmp [r10],rax
jne skip
cmp word ptr [r10+78],%X
jne skip
cmp qword ptr [r10+18],0
je skip
mov rcx,[r10+20]
mov rax,%X
mov r11,[rax+C670]
cmp rcx,r11
jb skip
mov rax,rcx
sub rax,r11
cmp rax,189C0
jae skip
xor edx,edx
mov r11,120
div r11
test rdx,rdx
jne skip
mov rax,%X
cmp [rcx],rax
jne skip
mov eax,[r10+28]
test eax,eax
jz skip
cmp eax,[rcx+114]
jne skip
mov rax,%X
cmp [rcx+10],rax
jne skip
mov qword ptr [rsp+20],64
skip:
pop r11
pop r10
pop rdx
pop rcx
pop rax
popfq
%s
jmp %X
%X:
jmp @N@
nop %d
[DISABLE]
%X:
db %s
unregistersymbol(@N@)
// Retain code until process exit for in-flight calls.
]]):format(b+d.rva,d.bytes,b+d.rva,b+0x213CB08,c.root,c.scenario,c.player,c.root,
 b+0x13D10B8,d.kind,c.root,b+K.types.district.vt,own,d.original,b+d.rva+d.length,
 b+d.rva,d.length-5,b+d.rva,d.bytes):gsub('@N@',symbol):gsub('@O@',d.obj))
 script=script:gsub('@F@',('%X'):format(b+(d.failure or 0)))
 if d.roll then script=script:gsub('mov qword ptr %[rsp%+20%],64','mov qword ptr [rsp+20],0') end
 return (script:gsub('\nnop 0\n','\n'))
end
function K.removeSuccessHook(name)
 local h=K.successHooks and K.successHooks[name];if not h then return end
 if h.pid==getOpenedProcessID() and K.buildMatches() then
  local bytes=assert(readBytes(h.site,#h.installed,true))
  for i,v in ipairs(h.installed) do assert(bytes[i]==v,'N16 success hook ownership changed') end
  assert((K.assemble or autoAssemble)(h.script,h.info),'Cannot restore N16 success hook')
 end
 K.successHooks[name]=nil
end
function K.setSuccess(feature,enabled)
 K.ready();K.successHooks=K.successHooks or {};local added={}
 if not enabled then
  for name,d in pairs(K.successSites) do if d.feature==feature then K.removeSuccessHook(name) end end
  K.on[feature]=nil;return
 end
 -- Refuse every conflicting site before installing the group.
 for name,d in pairs(K.successSites) do
  if d.feature==feature and not K.successHooks[name] then
   local bytes=assert(readBytes(K.base()+d.rva,d.length,true));local n=1
   for v in d.bytes:gmatch('%x%x') do assert(bytes[n]==tonumber(v,16),'N16 success code mismatch: '..name);n=n+1 end
  end
 end
 local ok,err=pcall(function()
  for name,d in pairs(K.successSites) do
   if d.feature==feature and not K.successHooks[name] then
    K.successSerial=(K.successSerial or 0)+1
    local script=K.successScript(name,'nb16Success_'..name..'_'..K.successSerial)
    local success,info=(K.assemble or autoAssemble)(script);assert(success,tostring(info))
    local at=K.base()+d.rva
    K.successHooks[name]={pid=K.pid,site=at,script=script,info=info,installed=assert(readBytes(at,d.length,true))}
    added[#added+1]=name
   end
  end
 end)
 if not ok then for i=#added,1,-1 do K.removeSuccessHook(added[i]) end;error(err,0) end
 K.on[feature]=true
end

end

do
local K=NB.K16
K.successSites.captiveRecruit={rva=0x645678,bytes='48 8D 96 42 01 00 00',length=7,feature='recruitment',captive=true}
K.successSites.captiveRefresh={rva=0xED1CD4,bytes='48 8B 89 00 01 00 00',length=7,feature='recruitment',captive=true}
local previous=K.successScript
local save='pushfq\npush rax\npush rcx\npush rdx\npush r8\npush r9\npush r10\npush r11\n'
local restore='pop r11\npop r10\npop r9\npop r8\npop rdx\npop rcx\npop rax\npopfq\n'
function K.captiveRecruitScript(name,symbol)
 local d=assert(K.successSites[name]);local c=K.ready();local b=c.base;local own=assert(K.clan())
 local refresh=name=='captiveRefresh'
 local guard=([[
mov rax,[%X]
mov r11,%X
cmp rax,r11
jne fallback
mov rax,[rax+1B260]
mov r11,%X
cmp rax,r11
jne fallback
mov rax,[rax+1047E0]
mov r11,%X
cmp rax,r11
jne fallback
]]):format(b+0x213CB08,c.root,c.scenario,c.player)
 if refresh then
  guard=guard..('mov rax,%X\ncmp [rcx],rax\njne fallback\nmov r10,[rcx+2A0]\n'):format(b+0x15CDCB0)
 else guard=guard..'mov r10,rdi\n' end
 local typ=refresh and K.types.district or K.types.clan
 guard=guard..([[
mov rax,%X
mov r11,[rax+%X]
cmp r10,r11
jb fallback
mov rax,r10
sub rax,r11
cmp rax,%X
jae fallback
xor edx,edx
mov r11,%X
div r11
test rdx,rdx
jne fallback
mov rax,%X
cmp [r10],rax
jne fallback
]]):format(c.root,typ.off,typ.count*typ.stride,typ.stride,b+typ.vt)
 if refresh then guard=guard..'cmp dword ptr [r10+114],0\nje fallback\n' end
 guard=guard..([[
mov rax,%X
cmp %s,rax
jne fallback
]]):format(own,refresh and '[r10+10]' or 'r10')
 if not refresh then
  guard=guard..([[
mov rax,%X
mov r11,[rax+E8]
cmp rsi,r11
jb fallback
mov rax,rsi
sub rax,r11
cmp rax,%X
jae fallback
xor edx,edx
mov r11,270
div r11
test rdx,rdx
jne fallback
mov rax,%X
cmp [rsi],rax
jne fallback
]]):format(c.root,K.types.officer.count*K.types.officer.stride,b+K.types.officer.vt)
 end
 local body,original,extra
 if refresh then
  extra=([[
assert(%X,48 89 5C 24 18 48 89 74 24 20 57 48)
assert(%X,48 89 5C 24 08 57 48 83 EC 20 48 8B D9 48 8D 05)
assert(%X,48 89 5C 24 10 4C 89 4C 24 20 44 89 44 24 18 48)
]]):format(b+0x3AA20,b+0x3C8F0,b+0x6EDD60)
  body=([[
sub rsp,C0
movdqu [rsp+60],xmm0
movdqu [rsp+70],xmm1
movdqu [rsp+80],xmm2
movdqu [rsp+90],xmm3
movdqu [rsp+A0],xmm4
movdqu [rsp+B0],xmm5
mov r11,[rsp+E8]
lea rdx,[r11+290]
lea rcx,[rsp+40]
call %X
mov r11,[rsp+E8]
lea rax,[r11+2F0]
mov [rsp+30],rax
lea rax,[r11+2E0]
mov [rsp+28],rax
lea rax,[r11+2D0]
mov [rsp+20],rax
lea r9,[r11+2C0]
mov r8d,[r11+2B0]
mov rdx,[r11+2A0]
lea rcx,[rsp+40]
call %X
lea rcx,[rsp+40]
call %X
movdqu xmm0,[rsp+60]
movdqu xmm1,[rsp+70]
movdqu xmm2,[rsp+80]
movdqu xmm3,[rsp+90]
movdqu xmm4,[rsp+A0]
movdqu xmm5,[rsp+B0]
add rsp,C0
]]):format(b+0x3AA20,b+0x6EDD60,b+0x3C8F0)
  body=body..restore..'mov rcx,[rcx+100]\n'..('jmp %X\n'):format(b+d.rva+d.length)
  original='mov rcx,[rcx+100]\n'
 else
  extra=('assert(%X,48 8B 4C 24 70 48 33 CC E8 17 81 CB 00)\n'):format(b+0x645B0C)
  body=restore..'mov eax,1\n'..('jmp %X\n'):format(b+0x645B0C)
  original='lea rdx,[rsi+142]\n'
 end
 return ('[ENABLE]\nassert(%X,%s)\n%salloc(%s,4096,%X)\nregistersymbol(%s)\nlabel(fallback)\n%s:\n'):format(
  b+d.rva,d.bytes,extra,symbol,b+d.rva,symbol,symbol)..save..guard..body..'fallback:\n'..restore..original..
  ('jmp %X\n%X:\njmp %s\nnop 2\n[DISABLE]\n%X:\ndb %s\nunregistersymbol(%s)\n'):format(
   b+d.rva+d.length,b+d.rva,symbol,b+d.rva,d.bytes,symbol)
end
function K.successScript(name,symbol)
 if K.successSites[name].captive then return K.captiveRecruitScript(name,symbol) end
 return previous(name,symbol)
end



end

do
local K=NB.K16
K.types.command={off=0x1B270,count=800,stride=0x98,vt=0x13D10B8}
local supported={[1]=true,[5]=true,[7]=true,[10]=true,[13]=true,[15]=true,[17]=true,[18]=true,[19]=true,[20]=true,[42]=true,
 [44]=true,[45]=true,[46]=true,[47]=true,[52]=true,[53]=true,[55]=true,[56]=true,[58]=true}
function K.instantMissionCandidates(first,count)
 K.ready();local out={};local own=assert(K.clan())
 for i=first,math.min(first+count-1,K.types.command.count-1) do
  local p=K.object('command',i)
  if p then
   local kind=readSmallInteger(p+0x78);local actor=readQword(p+0x18)
   local flags=readInteger(p+0x90)
   if supported[kind] and flags and (flags&amp;9)==0 and readSmallInteger(p+0x30)==0 and K.indexOf('officer',actor)
    and readQword(actor+0xC8)==p and K.ownsObject('officer',actor) then
    local district=readQword(p+0x20)
    if K.indexOf('district',district) and readQword(district+0x10)==own
     and readInteger(p+0x28)==readInteger(district+0x114) then
     out[#out+1]={index=i,address=p,actor=actor,kind=kind}
    end
   end
  end
 end
 return out
end
function K.missionFinishScript(symbol)
 local b=K.base();local own=assert(K.clan())
 return (([[
[ENABLE]
assert(%X,81 FA FF FF 00 00 B8 FF FF FF FF 66 0F 46 C2 66)
assert(%X,40 57 48 83 EC 30 48 8B F9 E8)
alloc(@N@,1024,%X)
registersymbol(@N@)
label(reject)
label(kindOK)
@N@:
cmp [rcx+18],rdx
jne reject
cmp [rdx+C8],rcx
jne reject
movzx eax,word ptr [rcx+78]
cmp eax,r8d
jne reject
cmp eax,1
je kindOK
cmp eax,5
je kindOK
cmp eax,7
je kindOK
cmp eax,A
je kindOK
cmp eax,D
je kindOK
cmp eax,F
je kindOK
cmp eax,11
je kindOK
cmp eax,12
je kindOK
cmp eax,13
je kindOK
cmp eax,14
je kindOK
cmp eax,2C
je kindOK
cmp eax,2D
je kindOK
cmp eax,2E
je kindOK
cmp eax,2F
je kindOK
cmp eax,34
je kindOK
cmp eax,35
je kindOK
cmp eax,37
je kindOK
cmp eax,38
je kindOK
cmp eax,3A
je kindOK
cmp eax,2A
jne reject
kindOK:
cmp word ptr [rcx+30],0
jne reject
test byte ptr [rcx+90],9
jne reject
mov r9,[rcx+20]
cmp r9,[rdx+88]
jne reject
mov r10,%X
mov r10,[r10+C670]
cmp r9,r10
jb reject
mov rax,r9
sub rax,r10
cmp rax,189C0
jae reject
push rdx
xor edx,edx
mov r10,120
div r10
test rdx,rdx
pop rdx
jne reject
mov rax,%X
cmp [r9],rax
jne reject
mov eax,[rcx+28]
test eax,eax
jz reject
cmp eax,[r9+114]
jne reject
cmp eax,[rdx+90]
jne reject
mov rax,%X
cmp [r9+10],rax
jne reject
push rbx
sub rsp,20
mov rbx,rcx
xor edx,edx
call %X
mov rcx,rbx
call %X
add rsp,20
pop rbx
mov eax,1
ret
reject:
xor eax,eax
ret
[DISABLE]
unregistersymbol(@N@)
]]):format(b+0x6D7260,b+0xCB7D80,b,K.root(),b+K.types.district.vt,own,b+0x6D7260,b+0xCB7D80):gsub('@N@',symbol))
end
function K.prepareMissionFinish()
 if K.missionFinish and K.missionFinish.pid==K.pid then return end
 local symbol=('nb16Mission_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.missionFinishScript(symbol)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 local address=assert(getAddressSafe(symbol));local bytes={}
 for _,v in ipairs(assert(readBytes(address,16,true))) do bytes[#bytes+1]=('%02X'):format(v) end
 K.nativeDefinitions.missionFinish={rva=address-K.base(),bytes=table.concat(bytes,' '),kind='command',
  argumentType='officer',allowPending=true}
 K.missionFinish={pid=K.pid,address=address,symbol=symbol,script=script,info=info}
end
function K.setMissionTimer(enabled)
 K.on.instantMissions=nil
 if K.timers.missions then K.timers.missions.destroy();K.timers.missions=nil end
 if not enabled then return end
 K.ready();K.installNative();K.prepareMissionFinish()
 local cursor=0;local t=createTimer(nil,false);t.Interval=100;K.timers.missions=t
 K.on.instantMissions=true
 t.OnTimer=function(timer)
  if K.nativeBusy() then return end
  timer.Enabled=false
  local ok=NB.userRun(function()
   local orders=K.instantMissionCandidates(cursor,64)
   cursor=cursor+64;if cursor&gt;=K.types.command.count then cursor=0 end
   if #orders&gt;0 then local o=orders[1];K.nativeCall('missionFinish','command',o.index,o.actor,o.kind) end
  end)
  if ok then timer.Enabled=true else
   K.on.instantMissions=nil
   local mr=getAddressList().getMemoryRecordByID(713);if mr then NB.deferOff(mr) end
  end
 end
 t.Enabled=true
end

end

do
local K=NB.K16
function K.feature(name,enabled)
 K.ready()
 if name=='schemes' then name='strategySuccess' end
 if name=='instantMissions' then return K.setMissionTimer(enabled) end
 if name=='recruitment' or name=='strategySuccess' then return K.setSuccess(name,enabled) end
 if name=='goodwill' then return K.setGoodwillTimer(enabled) end
 if name=='negotiationSuccess' then return K.setDiplomacyCreditTimer(enabled) end
 if name=='armySpeed' then return K.setMovement(enabled) end
 if name=='instantPolicies' then return K.setPolicyTimer(enabled) end
 if name=='loyalty' then return K.setLoyaltyTimer(enabled) end
 if name=='battleSkills' then
  K.setSiegeProtection(enabled,true)
  K.on.battleSkills=enabled or nil
  if enabled then for _,item in ipairs(K.armies(true)) do K.refillSiegeArmy(item.index,2) end end
  return
 end
 if name=='battleOneHit' then return K.setOneHit(enabled) end
 if name=='instantDevelopment' then return K.setConstructionTimer(enabled) end
 if name=='facilityMax' then
  K.on.facilityMax=enabled or nil;return K.setTownTimer()
 end
 if name=='cityMax' then
  K.on.cityMax=enabled or nil;K.setMaximumTimer();K.setCountyTimer()
  if enabled then K.refreshMaximum() end
  return
 end
 local sets={
  actions={sites=K.actionSites,install=K.installActionHook,remove=K.removeActionHook},
  ownBattle={sites=K.battleSites,install=K.installBattleHook,remove=K.removeBattleHook}}
 local set=assert(sets[name],'Unknown Awakening feature: '..tostring(name))
 local added={}
 if enabled then
  local ok,err=pcall(function()
   if name=='ownBattle' then K.setSiegeProtection(true) end
   for key in pairs(set.sites) do
    local existing=name=='actions' and K.actionHooks or K.battleHooks
    if not existing or not existing[key] then
     set.install(key);added[#added+1]=key
    end
   end
  end)
  if not ok then
   if name=='ownBattle' then K.setSiegeProtection(false) end
   for i=#added,1,-1 do set.remove(added[i]) end
   error(err,0)
  end
 else
  if name=='ownBattle' then K.setSiegeProtection(false) end
  for key in pairs(set.sites) do set.remove(key) end
 end
 K.on[name]=enabled or nil
 if name=='ownBattle' then
  K.setMaximumTimer()
  if enabled then K.refreshMaximum() end
 end
end

end

do
local K=NB.K16
K.types.relation={off=0x14458,count=1500,stride=0xE8,vt=0x13C3B50}
K.nativeDefinitions.relationCredit={rva=0x630240,bytes='83 FA 01 77 12 41 83 F8 64 77 0C 48 63 C2 48 6B',kind='relation'}
function K.relationParties(p)
 if not K.indexOf('relation',p) then return end
 local a,b=readQword(p+0x30),readQword(p+0x88)
 if a==b or not K.indexOf('clan',a) or not K.indexOf('clan',b) then return end
 return a,b
end
local originalName=K.name
function K.name(kind,p)
 if kind~='relation' then return originalName(kind,p) end
 local a,b=K.relationParties(p);if not a then return '' end
 local target=a==K.clan() and b or a
 local leader=readQword(target+0x30)
 return originalName('officer',leader)
end
function K.selectDiplomacy()
 K.ready()
 local own=assert(K.clan());local rows,ids={},{}
 for _,item in ipairs(K.objects('relation')) do
  local a,b=K.relationParties(item.address)
  if a and (a==own or b==own) then
   local name=K.name('relation',item.address)
   if name~='' then rows[#rows+1]=name;ids[#ids+1]=item.index end
  end
 end
 if #ids==0 then NB.msg('No active diplomatic relations.','有効な外交関係がありません。');return end
 local choice=NB.pick(NB.T('Select the other clan leader','相手勢力の大名を選択'),rows)
 if not choice then return end
 K.select('relation',ids[choice])
 local mr=getAddressList().getMemoryRecordByID(711)
 if mr then mr.Active=true;if mr.Active then K.openDiplomacy(mr) end end
end
function K.openDiplomacy(mr)
 K.ready()
 local p=K.selected('relation')
 local a,b=K.relationParties(p);local own=K.clan()
 if not a or (a~=own and b~=own) then
  NB.msg('Select the other clan first.','先に相手勢力を選択してください。');return
 end
 local index=K.indexOf('relation',p)
 K.closeEditor(mr)
 K.fields.relation={}
 for side=0,1 do
  local ownSide=(side==0 and a==own) or (side==1 and b==own)
  local field={off=0x38+side*0x58,size=1,min=0,max=100,
   en=ownSide and 'Credit: our side' or 'Credit: other side',
   jp=ownSide and '信用（自家側）' or '信用（相手側）',
   apply=function(kind,id,value)
    local current=K.object(kind,id);local x,y=K.relationParties(current)
    assert(current==p and x==a and y==b and K.clan()==own,'Diplomatic parties changed')
    K.nativeCall('relationCredit',kind,id,side,value)
   end}
  K.fields.relation[#K.fields.relation+1]=field
  K.addField(mr,'relation',index,field)
 end
 K.editors[mr.ID]={mr=mr,kind='relation'}
 NB.suffix[711]=K.name('relation',p);NB.applyLang();mr.Collapsed=false
end
local openEditor=K.openEditor
function K.openEditor(mr,kind)
 if kind=='relation' then return K.openDiplomacy(mr) end
 return openEditor(mr,kind)
end
function K.setDiplomacyCreditTimer(enabled)
 K.on.negotiationSuccess=nil
 if K.timers.diplomacyCredit then K.timers.diplomacyCredit.destroy();K.timers.diplomacyCredit=nil end
 if not enabled then return end
 K.ready();K.installNative()
 local cursor=0;local timer=createTimer(nil,false);timer.Interval=50;K.timers.diplomacyCredit=timer
 K.on.negotiationSuccess=true
 timer.OnTimer=function(t)
  if K.nativeBusy() then return end
  t.Enabled=false
  local ok=NB.userRun(function()
   K.ready();local own=assert(K.clan())
   for _=1,64 do
    local index=cursor;cursor=(cursor+1)%K.types.relation.count
    local p=K.object('relation',index);local a,b=K.relationParties(p)
    if a and (a==own or b==own) then
     local side=a==own and 0 or 1
     if readBytes(p+0x38+side*0x58,1)~=100 then
      K.nativeCall('relationCredit','relation',index,side,100);return
     end
    end
   end
  end)
  if ok then t.Enabled=true else
   K.on.negotiationSuccess=nil
   local mr=getAddressList().getMemoryRecordByID(701);if mr then NB.deferOff(mr) end
  end
 end
 timer.Enabled=true
end

end

do
local K=NB.K16
function K.goodwillOrders(first,count)
 local own=K.clan();local out={}
 if not own then return out end
 first=first or 0;count=math.min(count or 64,K.types.relation.count-first)
 for index=first,first+count-1 do
  local p=K.object('relation',index);local a,b=K.relationParties(p)
  if a and (a==own or b==own) then
   local side=a==own and 0 or 1;local part=p+side*0x58
   local officer=readQword(part+0x40);local goal=readBytes(part+0x39,1)
   if goal and goal&gt;0 and goal&lt;=100 and K.indexOf('officer',officer) and K.ownsOfficer(officer) then
    out[#out+1]={index=index,side=side,officer=officer,goal=goal}
   end
  end
 end
 return out
end
function K.goodwillFinishScript(symbol)
 local b=K.base();local own=assert(K.clan())
 return (([[
[ENABLE]
assert(%X,83 FA 01 77 12 41 83 F8 64 77 0C 48 63 C2 48 6B)
assert(%X,48 89 5C 24 20 55 56 57 41 54 41 55 41 56 41 57)
alloc(@N@,1024,%X)
registersymbol(@N@)
label(reject)
label(return)
@N@:
push rbx
push rsi
push rdi
sub rsp,20
cmp edx,1
ja reject
mov rbx,rcx
mov esi,edx
imul rax,rsi,58
lea r10,[rcx+rax]
mov rdi,%X
cmp [r10+30],rdi
jne reject
cmp [r10+40],r8
jne reject
mov r11,[r8+88]
mov rax,[%X]
mov rax,[rax+C670]
cmp r11,rax
jb reject
add rax,189C0
cmp r11,rax
jae reject
mov rax,%X
cmp [r11],rax
jne reject
mov eax,[r8+90]
test eax,eax
jz reject
cmp eax,[r11+114]
jne reject
cmp [r11+10],rdi
jne reject
movzx r8d,byte ptr [r10+39]
test r8d,r8d
jz reject
cmp r8d,64
ja reject
call %X
mov rcx,rbx
mov rdx,rdi
mov eax,esi
xor eax,1
imul rax,58
mov r8,[rbx+rax+30]
call %X
mov eax,1
jmp return
reject:
xor eax,eax
return:
add rsp,20
pop rdi
pop rsi
pop rbx
ret
[DISABLE]
unregistersymbol(@N@)
]]):format(b+0x630240,b+0x5D6430,b,own,b+0x213CB08,b+K.types.district.vt,b+0x630240,b+0x5D6430):gsub('@N@',symbol))
end
function K.prepareGoodwillFinish()
 if K.goodwillFinish and K.goodwillFinish.pid==K.pid then return end
 local symbol=('nb16GoodwillFinish_%X_%X'):format(getTickCount(),math.random(0x100000,0x7FFFFF))
 local script=K.goodwillFinishScript(symbol)
 local ok,info=(K.assemble or autoAssemble)(script);assert(ok,tostring(info))
 local address=assert(getAddressSafe(symbol));local bytes={}
 for _,v in ipairs(assert(readBytes(address,16,true))) do bytes[#bytes+1]=('%02X'):format(v) end
 K.nativeDefinitions.goodwillFinish={rva=address-K.base(),bytes=table.concat(bytes,' '),kind='relation',
  argumentType='officer',argumentPosition=2,allowPending=true}
 K.goodwillFinish={pid=K.pid,address=address,symbol=symbol,script=script,info=info}
end
function K.setGoodwillTimer(enabled)
 K.on.goodwill=nil
 if K.timers.goodwill then K.timers.goodwill.destroy();K.timers.goodwill=nil end
 if not enabled then return end
 K.ready();K.installNative();K.prepareGoodwillFinish()
 local cursor=0;local timer=createTimer(nil,false);timer.Interval=100;K.timers.goodwill=timer
 K.on.goodwill=true
 timer.OnTimer=function(t)
  if K.nativeBusy() then return end
  t.Enabled=false
  local ok=NB.userRun(function()
   K.ready()
   local orders=K.goodwillOrders(cursor,64)
   cursor=(cursor+64&gt;=K.types.relation.count) and 0 or cursor+64
   if #orders&gt;0 then local o=orders[1];K.nativeCall('goodwillFinish','relation',o.index,o.side,o.officer) end
  end)
  if ok then t.Enabled=true else
   K.on.goodwill=nil
   local mr=getAddressList().getMemoryRecordByID(712);if mr then NB.deferOff(mr) end
  end
 end
 timer.Enabled=true
end

end

do
local K=NB.K16
NB.GAMES[5]={'Awakening with Power Up Kit','新生 with パワーアップキット',K.exe}
NB.game=5;NB.EXE=K.exe;NB.MODULE=K.exe
local configLabels=NB.refreshConfigLabels
function NB.refreshConfigLabels()
 configLabels()
 local games=NB.configControls[24]
 if games then
  NB.uiUpdating=true
  games.Items.clear()
  for i=#NB.GAMES,1,-1 do games.Items.add(NB.T(NB.GAMES[i][1],NB.GAMES[i][2])) end
  games.ItemIndex=#NB.GAMES-NB.game
  NB.uiUpdating=false
 end
end
local changeConfig=NB.changeConfig
function NB.changeConfig(id,index)
 if NB.uiUpdating then return end
 if id==24 then
  if index&lt;0 or index&gt;=#NB.GAMES then return end
  index=#NB.GAMES-index-1
 end
 changeConfig(id,index)
 if id==24 and NB.game==5 then
  NB.displayStatus('Start the selected game, then ATTACH.','選択したゲームを起動してアタッチしてください。')
 end
end
local installConfig=NB.installConfigUI
function NB.installConfigUI()
 if NB.game~=5 then return installConfig() end
 local tree=getAddressList().List;NB.oldItemHeight=tree.DefaultItemHeight
 for _,id in ipairs({24,25,26}) do
  local combo=createComboBox(getMainForm());combo.Parent=tree
  combo.Style='csDropDownList';combo.Font.assign(tree.Font)
  combo.OnChange=function(sender)
   if sender.ItemIndex&gt;=0 then NB.changeConfig(id,sender.ItemIndex) end
  end
  NB.configControls[id]=combo
  tree.DefaultItemHeight=math.max(tree.DefaultItemHeight,combo.Height)
 end
 NB.configItemHeight=tree.DefaultItemHeight
 NB.refreshConfigLabels()
 NB.uiTimer=createTimer(nil,false);NB.uiTimer.Interval=120
 NB.uiTimer.OnTimer=function() NB.layoutConfigControls() end
 NB.uiTimer.Enabled=true;NB.layoutConfigControls()
end
local function wrap(name,handler)
 local previous=assert(NB[name],name)
 NB[name]=function(...)
  if NB.game==5 then return handler(...) end
  return previous(...)
 end
end
wrap('search',K.search)
wrap('selectPlayer',function() K.ready();return K.select('officer',assert(K.indexOf('officer',K.player()))) end)
wrap('selectHomeCity',function() K.ready();return K.select('city',assert(K.indexOf('city',K.homeCity()))) end)
wrap('openEditor',K.openEditor)
wrap('closeEditor',K.closeEditor)
wrap('feature',K.feature)
wrap('refreshSuffix',K.refreshSuffix)
wrap('assignTreasure',K.assignTreasure)
wrap('envReport',K.report)
wrap('statusReport',K.report)
wrap('progressReport',function() end)
wrap('attachAndConfigure',function(self)
 K.attachAndOff()
 local al=getAddressList()
 for i=al.Count-1,0,-1 do
  local row=al.getMemoryRecord(i)
  if NB.NAMES[row.ID] and not NB.CONFIG_IDS[row.ID] and row.Active and row~=self then row.Active=false end
 end
end)
wrap('scanSelfTest',function()
 K.ready();local count=0
 for kind,t in pairs(K.types) do assert(#K.objects(kind)==t.count,'Object layout mismatch: '..kind);count=count+1 end
 NB.msg(('Awakening object checks passed: %d arrays.'):format(count),
  ('新生PKのオブジェクト照合完了：%d配列。'):format(count))
 return count,count
end)
local release=NB.releaseGameSelection
function NB.releaseGameSelection()
 if K.pid then K.disconnect() end
 return release()
end
local shutdown=NB.shutdown
function NB.shutdown(gone)
 if K.pid then K.disconnect() end
 return shutdown(gone)
end

end

do
local K=NB.K16
local previous=NB.applyProfileRecords
local savedNames
local names={
 [7]={'1) Start Awakening PK, load a scenario, select this title, then ATTACH.','1) 新生PKでシナリオをロードし、作品を選択してアタッチします。'},
 [19]={'2) Select an officer/city and open its editor.','2) 武将・都市を選択してエディタを開きます。'},
 [302]={'Select: player daimyo’s affiliated castle','選択：主人公の所属城'},
 [101]={'Unlimited labor / no command reuse wait','労力無限・命令の再使用待ちなし'},
 [202]={'Own units invulnerable + MAX','部隊無敵＋MAX（自勢力）'},
 [206]={'Battle tactic gauge always MAX (own units)','戦法ゲージMAX（自勢力）'},
 [207]={'Fast movement (own forces: world map / siege x4)','部隊の高速移動（自勢力・全国／攻城戦4倍）'},
 [209]={'Select army...','部隊を選択...'},
 [210]={'Army editor (check to display)','部隊エディタ（チェックで表示）'},
 [304]={'Maximize own cities: soldiers, supplies, durability and county development','規模最大（自勢力の都市・郡）'},
 [305]={'Select county...','郡を選択...'},
 [306]={'County editor (check to display)','郡エディタ（チェックで表示）'},
 [602]={'Instant town facility construction / expansion and county facility development','城下施設の建設・増築／郡開発 即完了'},
 [604]={'Town facilities: maximum level (own cities)','城下施設レベル最大（自勢力の都市）'},
 [606]={'Enact all unissued policies','未発令の全政策を発令'},
 [607]={'Maximize enacted policy levels','発令済み政策レベル最大化'},
 [608]={'Instant policy enactment / upgrade','政策の発令・強化 即完了'},
 [501]={'Assign treasures (multiple selection)...','家宝をまとめて授与（複数選択）...'},
 [710]={'Select diplomatic counterpart...','外交の相手勢力を選択...'},
 [711]={'Diplomacy editor','外交エディタ'},
 [712]={'Instant goodwill missions','親善 即完了'},
 [713]={'Instant officer search / recruitment / scheme missions','武将探索・登用・計略 即完了'},
 [701]={'Diplomatic credit always MAX (own side)','外交信用MAX（自勢力）'},
 [702]={'Recruitment / poaching chance = 100%','登用・引抜の成功率100%'},
 [703]={'Schemes: positive result','計略の結果を成功にする'},
 [800]={'8. Other','8. その他'}}
local wanted={}
for _,id in ipairs({24,1,2,3,4,5,6,7,19,17,12,13,14,15,16,
 100,101,102,200,202,208,206,300,301,302,303,304,400,401,402,403,404,500,501,600,602,604,700,701,702,703}) do wanted[id]=true end
function NB.applyProfileRecords()
 if not savedNames then savedNames={};for id,v in pairs(NB.NAMES) do savedNames[id]=v end end
 for id in pairs(names) do NB.NAMES[id]=savedNames[id] end
 for id,v in pairs(savedNames) do NB.NAMES[id]=v end
 if NB.game~=5 then
  if NB.game&gt;=1 and NB.game&lt;=3 then
   local other=getAddressList().getMemoryRecordByID(800)
   if other then
    assert(not other.Active,'Cannot remove an active feature group')
    other.destroy()
   end
  end
  return previous()
 end
 local definitions={}
 for _,d in ipairs(NB.RECORDS) do
  if wanted[d.id] then
   local copy={};for key,v in pairs(d) do copy[key]=v end
   if d.id==604 then copy.script=copy.script:gsub("'[^']+',true","'facilityMax',true"):gsub("'[^']+',false","'facilityMax',false") end
   definitions[#definitions+1]=copy
  end
 end
 for i,d in ipairs(definitions) do
  if d.id==206 then
   table.insert(definitions,i+1,{id=207,parent=200,group=0,color='00A5FF',manual=0,
    script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.feature('armySpeed',true) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.feature('armySpeed',false) end)\n{$asm}\n"})
   break
  end
 end
 definitions[#definitions+1]={id=712,parent=700,group=0,color='00A5FF',manual=0,
  script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.feature('goodwill',true) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.feature('goodwill',false) end)\n{$asm}\n"}
 definitions[#definitions+1]={id=713,parent=700,group=0,color='00A5FF',manual=0,
  script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.feature('instantMissions',true) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.feature('instantMissions',false) end)\n{$asm}\n"}
 definitions[#definitions+1]={id=710,parent=700,group=0,color='00A5FF',manual=0,
  script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.K16.selectDiplomacy() end)\n{$asm}\n[DISABLE]\n"}
 definitions[#definitions+1]={id=711,parent=700,group=0,color='FFFF00',manual=0,
  script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.K16.openDiplomacy(memrec) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.K16.closeEditor(memrec) end)\n{$asm}\n"}
 local function policyAction(id,maximize)
  definitions[#definitions+1]={id=id,parent=600,group=0,color='00A5FF',manual=0,
   script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.K16.policyBatch("..tostring(maximize)..") end)\n{$asm}\n[DISABLE]\n"}
 end
 definitions[#definitions+1]={id=305,parent=300,group=0,color='00A5FF',manual=0,
  script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.K16.search('county') end)\n{$asm}\n[DISABLE]\n"}
 definitions[#definitions+1]={id=209,parent=200,group=0,color='00A5FF',manual=0,
  script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.K16.search('army') end)\n{$asm}\n[DISABLE]\n"}
 definitions[#definitions+1]={id=210,parent=200,group=0,color='FFFF00',manual=1,
  script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.K16.openEditor(memrec,'army') end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.K16.closeEditor(memrec) end)\n{$asm}\n"}
 definitions[#definitions+1]={id=306,parent=300,group=0,color='FFFF00',manual=1,
  script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.K16.openEditor(memrec,'county') end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.K16.closeEditor(memrec) end)\n{$asm}\n"}
 policyAction(606,false);policyAction(607,true)
 definitions[#definitions+1]={id=608,parent=600,group=0,color='00A5FF',manual=0,
  script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.feature('instantPolicies',true) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.feature('instantPolicies',false) end)\n{$asm}\n"}
 definitions[#definitions+1]={id=800,parent=0,group=1,manual=1,color='FFFF00',script=''}
 for _,d in ipairs(NB.RECORDS) do
  if d.id==30 then
   local copy={};for key,v in pairs(d) do copy[key]=v end
   copy.parent=800;definitions[#definitions+1]=copy
  end
 end
 for id,v in pairs(names) do NB.NAMES[id]=v end
 local al=getAddressList();local expected,current={},{}
 for _,d in ipairs(definitions) do expected[#expected+1]=d.id end
 for i=0,al.Count-1 do local r=al.getMemoryRecord(i);if NB.NAMES[r.ID] then current[#current+1]=r.ID end end
 local rebuild=#expected~=#current
 for i,id in ipairs(expected) do if current[i]~=id then rebuild=true;break end end
 if rebuild then
  for i=al.Count-1,0,-1 do
   local r=al.getMemoryRecord(i)
   if NB.NAMES[r.ID] then assert(not r.Active,'Cannot rebuild an active feature');r.destroy() end
  end
 end
 for _,d in ipairs(definitions) do
  local r=al.getMemoryRecordByID(d.id)
  if not r then
   r=al.createMemoryRecord();r.ID=d.id
   if d.group==1 then r.IsGroupHeader=true;r.Type=vtByte else r.Type=vtAutoAssembler;r.Script=d.script end
   r.Color=d.color~='' and tonumber(d.color,16) or -2147483640
   r.Options=d.manual==1 and '[moManualExpandCollapse]' or '[]'
  end
  if d.group~=1 and r.Script~=d.script then r.Script=d.script end
  if d.parent~=0 and (not r.Parent or r.Parent.ID~=d.parent) then r.appendToEntry(assert(al.getMemoryRecordByID(d.parent))) end
 end
 NB.applyLang()
 for i=0,al.Count-1 do
  local r=al.getMemoryRecord(i)
  if r.Count&gt;0 then
   local p=r;local settings=false
   while p do if p.ID==NB.ID_TOP0 then settings=true;break end;p=p.Parent end
   r.Collapsed=not settings
  end
 end
end

end

-- END AWAKENING PROFILE MODULES

-- BEGIN SHARED SELECTION UI

do
-- Shared selection controls; colors and Ctrl/Shift interaction follow WP10_2026.CT.
NB.UI={background=0x252525,input=0x353535,text=0xFFFFFF,muted=0xCFCFCF,selected=0x805020,dynamicIds={}}
local UI=NB.UI
NB.C_VALUE=0xFFFFFF
function UI.styleForm(form)
 form.Position='poScreenCenter';form.BorderStyle='bsSizeable'
 form.Color=UI.background;form.Font.Name='Yu Gothic UI';form.Font.Size=10;form.Font.Color=UI.text
 pcall(function()form.Constraints.MinWidth=700;form.Constraints.MinHeight=380 end)
end
function UI.track(row)
 UI.dynamicIds[row.ID]=true
 row.Color=row.Type==vtAutoAssembler and NB.C_SCRIPT or NB.C_VALUE
end
function UI.recolor()
 local al=getAddressList()
 for id in pairs(UI.dynamicIds)do
  local row=al.getMemoryRecordByID(id)
  if not row then UI.dynamicIds[id]=nil
  else row.Color=row.IsGroupHeader and NB.C_GROUP or (row.Type==vtAutoAssembler and NB.C_SCRIPT or NB.C_VALUE)end
 end
end
function UI.createList(form,options)
 options=options or {}
 local state={names={},shown={},chosen={},multiple=false,rendering=false,sortColumn=0,ascending=true}
 local prefix=options.name or 'NobunagaChoices'
 local search=createEdit(form);state.search=search;search.Name=prefix..'Search';search.Text=''
 search.Color=UI.input;search.Font.Color=UI.text
 pcall(function()search.TextHint=NB.T('Search name...','名前で検索...')end)
 local reset=createButton(form);state.reset=reset;reset.Name=prefix..'Reset';reset.Caption=NB.T('Clear filter','検索解除')
 local list=createListView(form);state.list=list;list.Name=prefix
 list.ViewStyle='vsReport';list.RowSelect=true;list.HideSelection=false;list.ReadOnly=true;list.OwnerData=true
 list.ShowColumnHeaders=true;list.Color=UI.background;list.Font.Color=UI.text
 local number=list.Columns.add();number.Caption='No.';number.Width=70
 local name=list.Columns.add();name.Caption=NB.T('Name','名前');name.Width=690
 local count=createLabel(form);state.count=count;count.Name=prefix..'Count';count.Font.Color=UI.muted
 local function recount()local n=0;for _ in pairs(state.chosen)do n=n+1 end;state.totalSelected=n end
 local function status()
  local n=state.totalSelected or 0
  count.Caption=NB.T(('Shown: %d / %d    Selected: %d'):format(#state.shown,#state.names,n),('表示：%d / %d件    選択：%d件'):format(#state.shown,#state.names,n))
  if state.onSelectionChanged then state.onSelectionChanged(n)end
 end
 local function capture()
  if state.rendering then return end
  if not state.multiple then
   state.chosen={};local item=list.Selected
   if item then local id=state.shown[item.Index+1];if id then state.chosen[id]=true end end
  else
   for i,id in ipairs(state.shown)do state.chosen[id]=list.Items[i-1].Selected and true or nil end
  end
  recount()
 end
 function state.selected()
  capture();local out={}
  for i=1,#state.names do if state.chosen[i]then out[#out+1]=i end end
  return out
 end
 list.OnData=function(_,item)
  local id=state.shown[item.Index+1]
  if not id then return end
  item.Caption=tostring(id);item.SubItems.clear();item.SubItems.add(state.names[id])
 end
 list.OnCustomDrawItem=function(sender,item)
  sender.Canvas.Font.Color=UI.text;sender.Canvas.Brush.Color=item.Selected and UI.selected or UI.background
  return true
 end
 function state.render(keep)
  if keep then capture()end
  local query=search.Text:lower();local shown={}
  for i,value in ipairs(state.names)do if query==''or value:lower():find(query,1,true)then shown[#shown+1]=i end end
  if state.sortColumn==1 then
   table.sort(shown,function(a,b)local x,y=state.names[a]:lower(),state.names[b]:lower();if x==y then return a&lt;b end;return state.ascending and x&lt;y or (not state.ascending and x&gt;y)end)
  elseif not state.ascending then table.sort(shown,function(a,b)return a&gt;b end)end
  state.rendering=true;list.beginUpdate()
  local ok,why=pcall(function()
   list.Items.clear();state.shown=shown;list.Items.Count=#shown
   local visibleChoice=false
   for i,id in ipairs(shown)do if state.chosen[id]then list.Items[i-1].Selected=true;visibleChoice=true end end
   if not state.multiple and not visibleChoice then
    state.chosen={};if #shown&gt;0 then state.chosen[shown[1]]=true;list.Items[0].Selected=true end
   end
  end)
  list.endUpdate();state.rendering=false
  if not ok then error(why,0)end
  recount();status()
 end
 function state.setRows(names,multiple,remember)
  state.names={};for i,value in ipairs(names)do state.names[i]=tostring(value)end
  state.multiple=multiple==true;state.chosen={};state.shown={};state.sortColumn=0;state.ascending=true
  for _,id in ipairs(remember or {})do if id&gt;=1 and id&lt;=#state.names then state.chosen[id]=true;if not state.multiple then break end end end
  state.rendering=true;search.Text='';list.MultiSelect=state.multiple;state.rendering=false
  state.render(false)
 end
 function state.selectVisible()
  if not state.multiple then return end
  capture();for _,id in ipairs(state.shown)do state.chosen[id]=true end;state.render(false)
 end
 function state.clearAll()state.chosen={};state.render(false)end
 search.OnChange=function()if not state.rendering then state.render(true)end end
 reset.OnClick=function()search.Text='';state.render(true)end
 list.OnSelectItem=function(_,item,selected)
  if state.rendering then return end
  local id=state.shown[item.Index+1];if not id then return end
  if not state.multiple and selected then state.chosen={};state.totalSelected=0 end
  local old=state.chosen[id]==true
  if selected and not old then state.chosen[id]=true;state.totalSelected=(state.totalSelected or 0)+1
  elseif not selected and old then state.chosen[id]=nil;state.totalSelected=(state.totalSelected or 1)-1 end
  status()
 end
 list.OnColumnClick=function(_,column)
  capture();local index=column.Index
  if state.sortColumn==index then state.ascending=not state.ascending else state.sortColumn=index;state.ascending=true end
  state.render(false)
 end
 function state.layout()
  local w,h=form.ClientWidth,form.ClientHeight;local top=options.top or 12
  search.Left=12;search.Top=top;search.Width=w-152;search.Height=28
  reset.Left=w-132;reset.Top=top;reset.Width=120;reset.Height=28
  list.Left=12;list.Top=top+38;list.Width=w-24;list.Height=math.max(140,h-(top+38)-88)
  count.Left=12;count.Top=h-80;count.Width=w-24;name.Width=math.max(400,w-118)
 end
 local previousShow=form.OnShow
 form.OnShow=function(sender)if previousShow then previousShow(sender)end;state.render(false)end
 state.layout();return state
end
function UI.choose(title,names,multiple,back,remember,accept)
 local form=createForm(false);UI.styleForm(form);form.Name='NobunagaChoice';form.Caption=title;form.ClientWidth=840;form.ClientHeight=620
 local hint=createLabel(form);hint.Font.Color=UI.muted;hint.Left=12;hint.Top=12
 hint.Caption=multiple and NB.T('Ctrl / Shift: select multiple entries','Ctrl / Shiftで複数選択できます')or NB.T('Select one entry.','項目を1件選択してください。')
 local state=UI.createList(form,{top=40,name='NobunagaChoiceList'})
 local function button(name,caption,width)
  local b=createButton(form);b.Name=name;b.Caption=caption;b.Width=width;b.Height=32;return b
 end
 local all=button('ChoiceAll',NB.T('Select shown','表示中を選択'),140);all.Visible=multiple==true
 local clear=button('ChoiceClear',NB.T('Clear selection','選択解除'),116);clear.Visible=multiple==true
 local previous=button('ChoiceBack',NB.T('Back','戻る'),100);previous.Visible=back==true
 local nextButton=button('ChoiceNext',accept or NB.T('Next','次へ'),110);nextButton.Default=true
 local cancel=button('ChoiceCancel',NB.T('Cancel','キャンセル'),124);cancel.Cancel=true
 state.onSelectionChanged=function(n)nextButton.Enabled=n&gt;0 end
 all.OnClick=state.selectVisible;clear.OnClick=state.clearAll
 previous.OnClick=function()form.ModalResult=3 end
 nextButton.OnClick=function()if #state.selected()&gt;0 then form.ModalResult=1 end end
 cancel.OnClick=function()form.ModalResult=2 end
 if not multiple then state.list.OnDblClick=nextButton.OnClick end
 form.OnClose=function()if not form.ModalResult or form.ModalResult==0 then form.ModalResult=2 end;return caHide end
 local function layout()
  state.layout();local w,h=form.ClientWidth,form.ClientHeight
  all.Left=12;clear.Left=160;previous.Left=w-362;nextButton.Left=w-254;cancel.Left=w-136
  for _,b in ipairs({all,clear,previous,nextButton,cancel})do b.Top=h-46 end
 end
 form.OnResize=layout;layout();state.setRows(names,multiple,remember)
 local ok,result=pcall(function()return form.showModal()end)
 local selected=state.selected();form.destroy();if not ok then error(result,0)end
 return selected,result==1 and 'next'or(result==3 and 'back'or'cancel')
end
function UI.pick(title,names)
 if #names==0 then return end
 local selected,action=UI.choose(title,names,false,false,nil,NB.T('Select','選択'))
 if action=='next'then return selected[1]end
end
local applyLanguage=NB.applyLang
function NB.applyLang()applyLanguage();UI.recolor()end
local openEditor=NB.openEditor
function NB.openEditor(mr,kind)local result=openEditor(mr,kind);UI.recolor();return result end

end

-- END SHARED SELECTION UI

-- BEGIN BASE STAT ADDITION
-- One-shot base-stat addition. Byte-sized native fields saturate at 255.
NB.baseStatAdd={settings={[4]={ability=1,amount=100},[5]={ability=1,amount=100}}}
local B=NB.baseStatAdd
B.ids={16020,16021,16022,16023}
B.names={{'Leadership (base)','統率基本値'},{'Valor (base)','武勇基本値'},
 {'Intelligence (base)','知略基本値'},{'Domestic affairs (base)','内政基本値'},{'Foreign affairs (base)','外政基本値'}}
function B.adapter()
 assert(NB.game==4 or NB.game==5,NB.T('Select Taishi or Awakening first.','大志または新生を選択してください。'))
 return NB.game==4 and NB.K15 or NB.K16
end
function B.options()
 local result={};local count=NB.game==4 and 5 or 4
 for i=1,count do
  local n=B.names[i]
  result[i]=i==4 and NB.game==5 and NB.T('Politics (base)','政務基本値')or NB.T(n[1],n[2])
 end
 return result
end
function B.setAmount(value)
 local n=tonumber(value)
 assert(n and n==n and n~=math.huge and n~=-math.huge and n&gt;=0 and n%1==0,
  NB.T('Enter a non-negative whole number.','0以上の整数を入力してください。'))
 B.settings[NB.game].amount=math.min(255,n)
end
function B.cancel()
 if B.timer then B.timer.destroy();B.timer=nil end
 B.running=nil
 if B.combo then B.combo.Enabled=true end
end
function B.validateCode(K,ability)
 local at,off
 if NB.game==4 then
  local jp={0x388D30,0x3844B0,0x3844F0,0x387410,0x384FD0}
  local tc={0x2E965C,0x2E5E8C,0x2E5EBC,0x2E82EC,0x2E6770}
  at=K.base()+(K.EXE=='NOBU15PK_TC.exe'and tc or jp)[ability];off=0x131+ability
 else
  off=0xDD+ability
  local d=assert(K.nativeDefinitions['officerAbility'..(ability-1)])
  at=K.base()+d.rva
 end
 local bytes=assert(readBytes(at,7,true));local expected={0x88,0x91,off&amp;255,(off&gt;&gt;8)&amp;255,0,0,0xC3}
 for i,v in ipairs(expected)do assert(bytes[i]==v,NB.T('Base-stat setter code does not match this build.','基本能力設定処理が対応ビルドと一致しません。'))end
 return off
end
function B.start()
 assert(not B.running,NB.T('Base-stat addition is already running.','基本能力への加算を実行中です。'))
 local K=B.adapter();K.ready();local game=NB.game;local key=assert(K.key());local clan=assert(K.clan());local player=assert(K.player())
 local cfg=B.settings[game];local ability,amount=cfg.ability,cfg.amount
 assert(ability&gt;=1 and ability&lt;=(game==4 and 5 or 4)and ability%1==0,'Invalid base ability')
 assert(amount&gt;=0 and amount&lt;=255 and amount%1==0,'Invalid addition')
 local off=B.validateCode(K,ability);local todo={};local seen={}
 for _,e in ipairs(K.objects('officer'))do
  local p=e.p or e.address;local id=e.id or e.index
  local status=game==5 and readBytes(p+0x138,1)or nil
  local eligible=game==4 or (status and status&lt;=13 and ((0x204B&gt;&gt;status)&amp;1)==0)
  if eligible and p~=player and K.ownsOfficer(p)and not seen[p]then
   seen[p]=true;local old=assert(readBytes(p+off,1));local value=math.min(255,old+amount)
   if old~=value then todo[#todo+1]={p=p,id=id,old=old,value=value}end
  end
 end
 assert(K.key()==key and K.clan()==clan,'Game context changed')
 if #todo==0 then NB.msg(NB.T('No base-stat changes required.','加算が必要な配下武将はいません。'));return end
 if game==5 then assert(not K.nativeBusy(),'A game operation is pending');K.installNative()end
 local job={key=key,game=game,clan=clan,off=off,ability=ability,amount=amount,todo=todo,cursor=1,changed=0,skipped=0}
 B.running=job
 if B.combo then B.combo.Enabled=false end
 local timer=createTimer(nil,false);B.timer=timer;timer.Interval=25
 timer.OnTimer=function(t)
  t.Enabled=false
  local ok=NB.userRun(function()
   assert(B.running==job and NB.game==game and K.key()==key and K.clan()==clan,
    NB.T('Game context changed; remaining additions cancelled.','ゲームの状態が変わったため、残りの加算を中止しました。'))
   K.ready()
   if game==5 and K.nativeBusy()then t.Enabled=true;return end
   local e=job.todo[job.cursor]
   if not e then
    local changed,skipped=job.changed,job.skipped;B.cancel()
    NB.msg(NB.T(('Added to %d officers; skipped %d. Base-stat maximum: 255.'):format(changed,skipped),
     ('配下武将%d人に加算、%d人を除外しました。基本値の保存上限：255。'):format(changed,skipped)))
    return
   end
   job.cursor=job.cursor+1
   local p=K.object('officer',e.id)
   local status=p and game==5 and readBytes(p+0x138,1)or nil
   local eligible=game==4 or (status and status&lt;=13 and ((0x204B&gt;&gt;status)&amp;1)==0)
   if p~=e.p or p==K.player()or not eligible or not K.ownsOfficer(p)or readBytes(p+off,1)~=e.old then job.skipped=job.skipped+1
   else
    if game==5 then K.nativeCall('officerAbility'..(ability-1),'officer',e.id,e.value)
    else assert(writeBytes(p+off,e.value),'Base-stat write failed')end
    assert(readBytes(p+off,1)==e.value,'Base-stat readback failed')
    job.changed=job.changed+1
   end
   if B.running==job then t.Enabled=true end
  end)
  if not ok then B.cancel()end
 end
 timer.Enabled=true
end
function B.refreshCombo()
 if not B.combo then return end
 if not B.settings[NB.game]then B.combo.Visible=false;return end
 B.updating=true;B.combo.Items.clear()
 for _,name in ipairs(B.options())do B.combo.Items.add(name)end
 B.combo.ItemIndex=B.settings[NB.game].ability-1;B.updating=false
end
function B.ensureCombo()
 if not NB.configControls or not getMainForm then return end
 if not B.combo then
  local combo=createComboBox(getMainForm());combo.Parent=getAddressList().List
  combo.Style='csDropDownList';combo.Font.assign(getAddressList().List.Font)
  combo.OnChange=function(sender)
   if not B.updating and not B.running and sender.ItemIndex&gt;=0 then B.settings[NB.game].ability=sender.ItemIndex+1 end
  end
  NB.configControls[B.ids[2]]=combo;B.combo=combo
 end
 B.refreshCombo()
end
local applyLanguage=NB.applyLang
function NB.applyLang(...)local result=applyLanguage(...);B.refreshCombo();return result end
local installConfig=NB.installConfigUI
function NB.installConfigUI(...)
 local result=installConfig(...)
 if NB.game==4 or NB.game==5 then B.ensureCombo()end
 return result
end
local profile=NB.applyProfileRecords
function NB.applyProfileRecords()
 B.cancel()
 if B.combo then B.combo.OnChange=nil;B.combo.destroy();B.combo=nil;NB.configControls[B.ids[2]]=nil end
 local al=getAddressList();local group=al.getMemoryRecordByID(B.ids[1])
 if group then group.destroy()end
 for _,id in ipairs(B.ids)do NB.NAMES[id]=nil end
 profile()
 if NB.game~=4 and NB.game~=5 then return end
 local parent=assert(al.getMemoryRecordByID(400));local collapsed=parent.Collapsed
 local group=al.createMemoryRecord();group.ID=B.ids[1]
 group.IsGroupHeader=true;group.Options='[moManualExpandCollapse]';group.Color=NB.C_GROUP;group.appendToEntry(parent)
 NB.NAMES[B.ids[1]]={'Add to subordinate officers’ base stats','配下武将の基本能力に指定値を加算'}
 for i=2,3 do
  local row=al.createMemoryRecord();row.ID=B.ids[i];row.Type=vtDword;row.Address='0';row.Color=NB.C_VALUE or 0xFFFFFF;row.appendToEntry(group)
  row.OnActivate=function()return false end
  row.OnGetDisplayValue=function()
   local cfg=B.settings[NB.game];if not cfg then return true,''end
   return true,i==2 and B.options()[cfg.ability]or tostring(cfg.amount)
  end
 end
 NB.NAMES[B.ids[2]]={'Target','加算先'};NB.NAMES[B.ids[3]]={'Amount to add (0–255)','指定値（0～255）'}
 local run=al.createMemoryRecord();run.ID=B.ids[4];run.Type=vtAutoAssembler;run.Color=NB.C_SCRIPT;run.appendToEntry(group)
 run.Script='[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.baseStatAdd.start() end)\n{$asm}\n[DISABLE]\n'
 NB.NAMES[B.ids[4]]={'Apply once (adds again each time)','加算を実行（再実行すると再加算）'}
 NB.applyLang();B.ensureCombo();group.Collapsed=true;parent.Collapsed=collapsed
end
local al=getAddressList();local valueChange=al.OnValueChange
local function editValue(sender,row)
 if (NB.game==4 or NB.game==5)and (row.ID==B.ids[2]or row.ID==B.ids[3])then
  NB.userRun(function()
   assert(not B.running,NB.T('Wait for the current addition to finish.','加算が完了するまでお待ちください。'))
   local cfg=B.settings[NB.game]
   if row.ID==B.ids[2]then
    local id=NB.UI.pick(NB.T('Select base ability','加算先の基本能力を選択'),B.options())
    if id then cfg.ability=id end
   else
    local v=inputQuery(NB.T('Add to base stats','基本能力への加算'),NB.T('Amount to add (0–255)','加算する指定値（0～255）'),tostring(cfg.amount))
    if v~=nil then B.setAmount(v)end
   end
  end)
  return true
 end
 if valueChange then return valueChange(sender,row)end
 return false
end
al.OnValueChange=editValue
for _,name in ipairs({'attachAndConfigure','releaseGameSelection','forgetProcess'})do
 local previous=NB[name]
 NB[name]=function(...)B.cancel();return previous(...)end
end
local shutdown=NB.shutdown
function NB.shutdown(...)
 B.cancel()
 B.combo=nil
 if getAddressList().OnValueChange==editValue then getAddressList().OnValueChange=valueChange end
 return shutdown(...)
end

-- END BASE STAT ADDITION
NB.RECORDS={{id=24,parent=0,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.openConfigDropdown(24) end)\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\n{$asm}\n",color="00A5FF",manual=0},{id=1,parent=0,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.attachAndConfigure(memrec) end)\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\n{$asm}\n",color="00A5FF",manual=0},{id=2,parent=0,group=1,script="",color="FFFF00",manual=1},{id=3,parent=2,group=1,script="",color="FFFF00",manual=1},{id=4,parent=3,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.setLang('en') end)\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\n{$asm}\n",color="00A5FF",manual=0},{id=5,parent=3,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.setLang('ja') end)\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\n{$asm}\n",color="00A5FF",manual=0},{id=20,parent=2,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.startConfiguredDisplay() end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.stopConfiguredDisplay() end)\n{$asm}\n",color="FFFF00",manual=1},{id=25,parent=20,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.openConfigDropdown(25) end)\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\n{$asm}\n",color="00A5FF",manual=0},{id=26,parent=20,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.openConfigDropdown(26) end)\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\n{$asm}\n",color="00A5FF",manual=0},{id=27,parent=20,group=1,script="",color="",manual=0},{id=28,parent=2,group=1,script="",color="FFFF00",manual=1},{id=18,parent=28,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.feature('wasd',true) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.feature('wasd',false) end)\n{$asm}\n",color="00A5FF",manual=0},{id=29,parent=28,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.feature('cameraZoom',true) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.feature('cameraZoom',false) end)\n{$asm}\n",color="00A5FF",manual=0},{id=6,parent=2,group=1,script="",color="FFFF00",manual=1},{id=7,parent=6,group=1,script="",color="",manual=0},{id=19,parent=6,group=1,script="",color="",manual=0},{id=17,parent=6,group=1,script="",color="",manual=0},{id=30,parent=2,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.unlockSteamAchievements() end)\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\n{$asm}\n",color="00A5FF",manual=0},{id=12,parent=2,group=1,script="",color="FFFF00",manual=1},{id=13,parent=12,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.openLuaEngine() end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.closeLuaEngine() end)\n{$asm}\n",color="00A5FF",manual=0},{id=14,parent=12,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.scanSelfTest() end)\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\n{$asm}\n",color="00A5FF",manual=0},{id=15,parent=12,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.envReport() end)\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\n{$asm}\n",color="00A5FF",manual=0},{id=16,parent=12,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.statusReport();NB.progressReport() end)\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\n{$asm}\n",color="00A5FF",manual=0},{id=100,parent=0,group=1,script="",color="FFFF00",manual=1},{id=101,parent=100,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.feature('actions',true) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.feature('actions',false) end)\n{$asm}\n",color="00A5FF",manual=0},{id=102,parent=100,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.openEditor(memrec,'player') end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.closeEditor(memrec) end)\n{$asm}\n",color="FFFF00",manual=1},{id=704,parent=100,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.openCourtEditor(memrec) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.closeEditor(memrec) end)\n{$asm}\n",color="FFFF00",manual=1},{id=200,parent=0,group=1,script="",color="FFFF00",manual=1},{id=201,parent=200,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.feature('playerBattle',true) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.feature('playerBattle',false) end)\n{$asm}\n",color="00A5FF",manual=0},{id=202,parent=200,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.feature('ownBattle',true) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.feature('ownBattle',false) end)\n{$asm}\n",color="00A5FF",manual=0},{id=208,parent=200,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.feature('battleOneHit',true) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.feature('battleOneHit',false) end)\n{$asm}\n",color="00A5FF",manual=0},{id=206,parent=200,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.feature('battleSkills',true) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.feature('battleSkills',false) end)\n{$asm}\n",color="00A5FF",manual=0},{id=207,parent=200,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.feature('armySpeed',true) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.feature('armySpeed',false) end)\n{$asm}\n",color="00A5FF",manual=0},{id=300,parent=0,group=1,script="",color="FFFF00",manual=1},{id=301,parent=300,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.search('city') end)\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\n{$asm}\n",color="00A5FF",manual=0},{id=302,parent=300,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.selectHomeCity() end)\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\n{$asm}\n",color="00A5FF",manual=0},{id=303,parent=300,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.openEditor(memrec,'city') end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.closeEditor(memrec) end)\n{$asm}\n",color="FFFF00",manual=1},{id=304,parent=300,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.feature('cityMax',true) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.feature('cityMax',false) end)\n{$asm}\n",color="00A5FF",manual=0},{id=400,parent=0,group=1,script="",color="FFFF00",manual=1},{id=401,parent=400,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.search('officer') end)\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\n{$asm}\n",color="00A5FF",manual=0},{id=402,parent=400,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.selectPlayer() end)\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\n{$asm}\n",color="00A5FF",manual=0},{id=403,parent=400,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.openEditor(memrec,'officer') end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.closeEditor(memrec) end)\n{$asm}\n",color="FFFF00",manual=1},{id=404,parent=400,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.feature('loyalty',true) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.feature('loyalty',false) end)\n{$asm}\n",color="00A5FF",manual=0},{id=500,parent=0,group=1,script="",color="FFFF00",manual=1},{id=501,parent=500,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.assignTreasure() end)\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\n{$asm}\n",color="00A5FF",manual=0},{id=600,parent=0,group=1,script="",color="FFFF00",manual=1},{id=602,parent=600,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.feature('instantDevelopment',true) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.feature('instantDevelopment',false) end)\n{$asm}\n",color="00A5FF",manual=0},{id=603,parent=600,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.unlockCityDevelopment() end)\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\n{$asm}\n",color="00A5FF",manual=0},{id=604,parent=600,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.feature('maxInvestment',true) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.feature('maxInvestment',false) end)\n{$asm}\n",color="00A5FF",manual=0},{id=605,parent=600,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nNB.oneShot(memrec,function() NB.reportDevelopment() end)\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\n{$asm}\n",color="00A5FF",manual=0},{id=700,parent=0,group=1,script="",color="FFFF00",manual=1},{id=701,parent=700,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.feature('negotiationSuccess',true) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.feature('negotiationSuccess',false) end)\n{$asm}\n",color="00A5FF",manual=0},{id=702,parent=700,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.feature('recruitment',true) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.feature('recruitment',false) end)\n{$asm}\n",color="00A5FF",manual=0},{id=703,parent=700,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.feature('schemes',true) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.feature('schemes',false) end)\n{$asm}\n",color="00A5FF",manual=0},{id=705,parent=700,group=0,script="[ENABLE]\n{$lua}\nif syntaxcheck then return end\nif not NB.userRun(function() NB.feature('instantExploration',true) end) then NB.deferOff(memrec) end\n{$asm}\n[DISABLE]\n{$lua}\nif syntaxcheck then return end\nNB.userRun(function() NB.feature('instantExploration',false) end)\n{$asm}\n",color="00A5FF",manual=0}}
NB.NAMES={[24]={"Select game :","作品を選択 :"},[1]={"[ATTACH / ALL OFF]","【アタッチ／一括解除】"},[2]={"0. Settings &amp; README","0. 設定・説明"},[3]={"Language / 言語設定","言語設定 / Language"},[4]={"English (default)","English（既定）"},[5]={"日本語 / Japanese","日本語 / Japanese"},[20]={"Screen mode (check = launch / apply)","画面モード（チェックで起動／適用）"},[25]={"Display :","表示 :"},[26]={"Scale :","倍率 :"},[27]={"Status","状態"},[28]={"Controls","操作設定"},[18]={"WASD map controls (strategy / battle)","WASD操作（内政・合戦）"},[29]={"Extended zoom out (3x distance limit)","ズームアウト範囲拡張（距離上限3倍）"},[6]={"README","はじめに"},[7]={"1) Select game, display and scale; check Screen mode to launch/apply; then ATTACH.","1) 作品・表示・倍率を選び、画面モードをチェックして起動／適用後、アタッチします。"},[19]={"2) Attach / All OFF connects and disables game cheats; display settings are retained.","2) アタッチ／一括解除は接続とゲーム内機能の解除です。画面設定は維持します。"},[17]={"3) Save before edits. All OFF does not undo committed data edits.","3) 編集前に保存してください。一括解除で確定済みの編集値は戻りません。"},[30]={"Unlock all Steam achievements","Steam実績一括解除"},[12]={"Diagnostics","診断"},[13]={"Lua Engine (check = open)","Lua Engine（チェックで開く）"},[14]={"AOB scan self-test","AOBスキャンテスト"},[15]={"Environment / connection info","環境・接続情報"},[16]={"Status / implementation progress","状態・実装状況"},[100]={"1. Player (daimyo officer only)","1. 主人公（大名武将本人のみ）"},[101]={"Unlimited commands/actions","命令・行動制限解除"},[102]={"Player editor (check to show)","主人公エディタ（チェックで表示）"},[704]={"Court editor (court / own force)","朝廷エディタ（朝廷・自勢力）"},[200]={"2. Battle","2. 戦闘"},[201]={"Player invulnerability + MAX (daimyo unit)","主人公無敵＋MAX（大名の部隊）"},[202]={"Own units invulnerable + MAX","部隊無敵＋MAX（自勢力）"},[208]={"One-hit kill (enemy units / buildings)","一撃必殺（自勢力部隊の攻撃）"},[206]={"Combat skills / tactics: no cooldown (own units)","合戦特技・戦法 再使用待ちなし（自勢力）"},[207]={"Army movement speed MAX (own forces)","部隊の移動速度最大（自勢力）"},[300]={"3. City","3. 都市"},[301]={"Select: search city name...","選択：都市名で検索..."},[302]={"Select: player's home castle","選択：主人公の所属城"},[303]={"City editor (check to show)","都市エディタ（チェックで表示）"},[304]={"Maximize city resources / public stats (own cities)","規模最大（自勢力の都市）"},[400]={"4. Officers","4. 武将"},[401]={"Select: search officer name...","選択：武将名で検索..."},[402]={"Select: player daimyo","選択：主人公の大名武将"},[403]={"Officer editor (check to show)","武将エディタ（チェックで表示）"},[404]={"Subordinate loyalty MAX","配下武将忠誠MAX"},[500]={"5. Items / treasures","5. アイテム・家宝"},[501]={"Assign treasures: category -&gt; multiple treasures -&gt; officer...","家宝をまとめて付与：分類→複数選択→武将..."},[600]={"6. Research &amp; development","6. 研究開発"},[602]={"Instant development / investment / construction / castle building","開発・投資・建設・築城 即完了"},[603]={"Unlock all town types (own cities)","開発可能な町並み 全解除（自勢力の都市）"},[604]={"Maximize investment (existing towns of own cities)","投資最大化"},[605]={"Development status (check to inspect pending orders)","開発状態（チェックで処理待ちを確認）"},[700]={"7. Diplomacy, schemes &amp; personnel","7. 交渉・計略・人事"},[701]={"Guaranteed negotiation","交渉を必ず成功"},[702]={"Recruitment / poaching chance = 100%","登用・引抜の成功率100%"},[703]={"Schemes: positive result","計略の結果を成功にする"},[705]={"Instant exploration (own forces)","探索 即終了（自勢力）"}}
NB.initializeUI()
</LuaScript>
</CheatTable>