Advertisement
Guest User

Untitled

a guest
May 5th, 2021
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 35.54 KB | None | 0 0
  1. -- This Lua Script is for Romancing SaGa 2 on snes9x.
  2.  
  3. --memory.usememorydomain("CARTROM") -- BizHawk
  4. rng = {}
  5. for i = 0, 0xFF do
  6.     rng[i+1] = memory.readbyte(0xC2EF04+i)  --rng[i] = i-1 (rng[0] = 1, ... , rng[256] = 255)
  7.     -- 0x02EF04-0x02F003
  8. end
  9. --memory.usememorydomain("WRAM")    -- BizHawk
  10.  
  11. black         = 0x000000FF
  12. red           = 0xC41F3BFF
  13. pink          = 0xF58CBAFF
  14. orange        = 0xFF7D0AFF
  15. yellow        = 0xFFF569FF
  16. green         = 0xABD473FF
  17. light_green   = 0x00FF96FF
  18. dark_green    = 0x008833FF
  19. aqua          = 0x00FFFFFF
  20. blue          = 0x0070DEFF
  21. light_blue    = 0x69CCF0FF
  22. purple        = 0x9482C9FF
  23. fuchsia       = 0xFF00FFFF
  24. brown         = 0xC79C6EFF
  25. gray          = 0x808080FF
  26. white         = 0xFFFFFFFF
  27.  
  28.  
  29. local msg1
  30. local msg0
  31. function msg()  --for supporting scrollng text messages, imputting battle command
  32.     msg1 = memory.readbyte(0x7E1F01)
  33.     if msg1 ==  0 and msg0 ~= 0 then
  34.         print(emu.framecount())
  35.     end
  36.     msg0 = msg1
  37. end
  38.  
  39. local EP
  40. local totalBattle
  41. local battle
  42. local safe
  43. local safe2 = {}
  44. local Hiraga
  45. function getParameter()
  46.     EP = memory.readbyte(0x7EF693)
  47.     totalBattle = memory.readword(0x7EF8AE)
  48.     battle = memory.readbyte(0x7EF694)
  49.     safe = memory.readbyte(0x7EF7A2) + 0x100 * memory.readbyte(0x7EF7A3) + 0x10000 * memory.readbyte(0x7EF7A4)
  50.     safe2[1] = math.floor(safe/1000000)
  51.     safe2[2] = math.floor((safe-(safe2[1]*1000000))/1000)
  52.     safe2[3] = safe - (safe2[1]*1000000)-(safe2[2]*1000)
  53.     Hiraga = memory.readbyte(0x7EF697)
  54. end
  55.  
  56. function dispParameter()
  57.     if safe2[1] ~= 0 then
  58.         gui.text(216, 12, string.format("%3d,%03d,%03d", safe2[1], safe2[2], safe2[3]))
  59.     elseif safe2[2] ~= 0 then
  60.         gui.text(224, 12, string.format("%3d,%03d", safe2[2], safe2[3]))
  61.     else
  62.         gui.text(234, 12, string.format("%3d", safe2[3]))
  63.     end
  64.     gui.text(236, 20, string.format("EP %d", EP))
  65.     gui.text(236, 28, string.format("%d/%d", battle, totalBattle))
  66.     gui.text(236, 36, string.format("%dsei", Hiraga))
  67.     local jump
  68.     local battle16 = battle % 0x10
  69.  
  70.     if EP >= battle16 then
  71.         if battle < 0x30 then
  72.             jump = battle16 + 0x30
  73.         else
  74.             jump = battle
  75.         end
  76. --~         gui.text(230, 68, string.format("jump%d", jump))
  77. --~         gui.text(218, 76, string.format("tBtl%d->%d", totalBattle, totalBattle + math.floor(jump/4)))
  78. --~         gui.text(216, 84, string.format("%dsei->%dsei", Hiraga, Hiraga + math.floor((jump/0x20) + (1/2))))
  79.     end
  80. end
  81.  
  82.  
  83. rngMod = {}
  84. rngModCol = {}
  85. function rngMOD(x)  -- for computing SP
  86.     for i = 0, 0xFF do
  87.         rngMod[i+1] = (rng[i+1] % x)
  88.     end
  89. end
  90.  
  91. rngCol = {}
  92. for i = 0, 0xFF do
  93.     residue20 = (rng[i+1] % 0x20)
  94.     residue40 = (rng[i+1] % 0x40)
  95.     if residue20 == 0 then  -- normal drop
  96.         rngCol[i+1] = light_green
  97.     elseif rng[i+1] < 0x1F then -- waza 7
  98.         rngCol[i+1] = pink
  99.     elseif rng[i+1] < 0x32 then -- waza same level
  100.         rngCol[i+1] = yellow
  101.     else
  102.         rngCol[i+1] = white
  103.     end
  104.     if residue40 == 0 then  -- rare drop
  105.         rngCol[i+1] = blue
  106.     end
  107. end
  108.  
  109.  
  110. function rngDisp()
  111.     for j = 0, 0xF do
  112.         for i = 0, 0xF do
  113.             gui.text(32+i*12, 26+j*12, string.format("%2X", rng[1+i+0x10*j]), rngCol[1+i+0x10*j])
  114.         end
  115.     end
  116.     local currentRNG = memory.readbyte(0x7E0D1F)
  117.     gui.box(31-1+(currentRNG-16*math.floor(currentRNG/16))*12, 24+12*math.floor(currentRNG/16), 32-1+(currentRNG-16*math.floor(currentRNG/16))*12+9, 24+12*math.floor(currentRNG/16)+10, clear, yellow)
  118. end
  119.  
  120. function rngDispMod()
  121.     for j = 0, 0xF do
  122.         for i = 0, 0xF do
  123.                 gui.text(32+i*12, 26+j*12, string.format("%2X", rngMod[1+i+0x10*j]), rngModCol[1+i+0x10*j])
  124.         end
  125.     end
  126.     local currentRNG = memory.readbyte(0x7E0D1F)
  127.     gui.box(31-1+(currentRNG-16*math.floor(currentRNG/16))*12, 24+12*math.floor(currentRNG/16), 32-1+(currentRNG-16*math.floor(currentRNG/16))*12+9, 24+12*math.floor(currentRNG/16)+10, clear, yellow)
  128. end
  129.  
  130. function dispRNG2()
  131.     local comSelect = memory.readbyte(0x7E0D1A)
  132.     local numParty = memory.readbyte(0x7EF618)
  133.     local countSP = 0
  134.     for i = 1, numParty do
  135.         gotSP[i] = memory.readbyte(0x7E0DD7 + (i-1))
  136.         if gotSP[i] == 0 then
  137.             countSP = countSP + 1
  138.         end
  139.     end
  140.     if countSP == numParty or comSelect > numParty then
  141.         rngDisp()
  142.     end
  143. end
  144.  
  145. function rngBar(n)  -- n = 1 or 3
  146.     local currentRNG = memory.readbyte(0x7E0D1F)
  147.     gui.drawrect(128, 223-math.floor(rng[currentRNG+1]/8), 128+2*n, 223, rngCol[currentRNG+1], black)
  148.     for i=0, 60/n do
  149.         local k = (currentRNG+i+1+1) % 0x100
  150.         if k == 0 then
  151.             k = 0x100
  152.         end
  153.         gui.drawrect(130+i*2*n, 223-math.floor(rng[k]/8), 130+i*2*n+2*n, 223, rngCol[k], black)
  154.     end
  155.     for j=0, 63/n do
  156.         local k = (currentRNG-j-1+1) % 0x100
  157.         if k == 0 then
  158.             k = 0x100
  159.         end
  160.         gui.drawrect(126-j*2*n, 223-math.floor(rng[k]/8), 126-j*2*n+2*n, 223, rngCol[k], black)
  161.     end
  162.     gui.drawrect(130, 176, 130+n-1, 176+48, light_green, light_green)
  163.     gui.text(134,176,string.format("%2X->%2X", currentRNG, rng[currentRNG+1]), light_green)
  164. end
  165.  
  166. gotSP = {}
  167. function dispRNGBar2()
  168.     local comSelect = memory.readbyte(0x7E0D1A)
  169.     local numParty = memory.readbyte(0x7EF618)
  170.     local countSP = 0
  171.     for i = 1, numParty do
  172.         gotSP[i] = memory.readbyte(0x7E0DD7 + (i-1))
  173.         if gotSP[i] == 0 then
  174.             countSP = countSP + 1
  175.         end
  176.     end
  177.     if countSP == numParty or comSelect > numParty then
  178.         rngBar(1)
  179.     end
  180. end
  181.  
  182. agility = {}
  183. SP = {}
  184. SPCol = {}
  185. function getAgi()
  186.     for i = 1, 5 do
  187.         agility[i] = memory.readbyte(0x7EAA65+0x0100*(i-1))
  188.         SP[i] = {}
  189.         SPCol[i] = {}
  190.         for j = 0, 0xFF do
  191.             SP[i][j+1] = (agility[i])*2 + math.mod(rng[1+(j)], ((agility[i])*2)) + 1
  192.             if (SP[i][j+1] > math.floor( agility[i] * (7/2)) ) then
  193.                 SPCol[i][j+1] = aqua
  194.             elseif (SP[i][j+1] < math.floor( agility[i] * 5/2) ) then
  195.                 SPCol[i][j+1] = pink
  196.             else
  197.                 SPCol[i][j+1] = white
  198.             end
  199.         end
  200.     end
  201. end
  202.  
  203. function dispSP()
  204.     local comSelect = memory.readbyte(0x7E0D1A)
  205.     local numParty = memory.readbyte(0x7EF618)
  206.     if comSelect >= 0 and comSelect < numParty then
  207.         for j = 0, 0xF do
  208.             for i = 0, 0xF do
  209.                 gui.text(32+i*12, 26+j*12, string.format("%2d", SP[comSelect+1][1+i+0x10*j]), SPCol[comSelect+1][1+i+0x10*j])
  210.             end
  211.         end
  212.         local currentRNG = memory.readbyte(0x7E0D1F)
  213.         gui.box(31-1+(currentRNG-16*math.floor(currentRNG/16))*12, 24+12*math.floor(currentRNG/16), 32-1+(currentRNG-16*math.floor(currentRNG/16))*12+9, 24+12*math.floor(currentRNG/16)+10, clear, yellow)
  214.     end
  215. end
  216.  
  217. gotSP = {}
  218. valueSP = { 0, 0, 0, 0, 0 }
  219. function gottenSP()
  220.     local comSelect = memory.readbyte(0x7E0D1A)
  221.     for i = 1, comSelect do
  222.         gotSP[i] = memory.readbyte(0x7E0DD7 + (i-1))
  223.         if gotSP[i] ~= 0 then
  224.             valueSP[i] = gotSP[i]
  225.         end
  226.     end
  227.  
  228.     local numParty = memory.readbyte(0x7EF618)
  229.     if countSP ~= numParty then
  230.         if comSelect >= 0 and comSelect < numParty+1 then
  231.             for i = 1, comSelect do
  232.                 gui.text(240, 172+(i-1)*8, string.format("%3d", valueSP[i]))
  233.             end
  234.         end
  235.     end
  236. end
  237.  
  238. local comparisonSP = 0
  239. function compSP(x)
  240.     gottenSP()
  241.     local numParty = memory.readbyte(0x7EF618)
  242.     if x == 1 then
  243.         for i = 2, numParty do
  244.             if valueSP[1] < valueSP[i] then
  245.                 comparisonSP = comparisonSP + 1
  246.             end
  247.         end
  248.     elseif x ~= 1 and x ~= numParty then
  249.         for i = 1, x-1 do
  250.             if valueSP[x] <= valueSP[i] then
  251.                 comparisonSP = comparisonSP + 1
  252.             end
  253.         end
  254.         for i = x+1, numParty do
  255.             if valueSP[x] < valueSP[i] then
  256.                 comparisonSP = comparisonSP + 1
  257.             end
  258.         end
  259.     elseif x == numParty then
  260.         for i = 1, x-1 do
  261.             if valueSP[x] <= valueSP[i] then
  262.                 comparisonSP = comparisonSP + 1
  263.             end
  264.         end
  265.     end
  266. end
  267.  
  268.  
  269. function gottenSPcoerce()
  270.     local numParty = memory.readbyte(0x7EF618)
  271.     for i = 1, numParty do
  272.         gotSP[i] = memory.readbyte(0x7E0DD7 + (i-1))
  273.         if gotSP[i] ~= 0 then
  274.             valueSP[i] = gotSP[i]
  275.         end
  276.     end
  277. end
  278.  
  279. function SPBar(n, a)
  280.     local currentRNG = memory.readbyte(0x7E0D1F)
  281.     local comSelect = memory.readbyte(0x7E0D1A)
  282.     local numParty = memory.readbyte(0x7EF618)
  283.     if comSelect >= 0 and comSelect < numParty then
  284.         if currentRNG == 0xFF then
  285.             currentRNG = 0
  286.         end
  287.         gui.drawrect(128, 223-math.floor(SP[comSelect+1][currentRNG+1]/a), 128+2*n, 223, SPCol[comSelect+1][currentRNG+1], black)
  288.         local currentRNG = memory.readbyte(0x7E0D1F)
  289.         for i=0, 60/n do
  290.             k = (currentRNG+i+1+1) % 0x100
  291.             if k == 0 then
  292.                 k = 0x100
  293.             end
  294.             gui.drawrect(130+i*2*n, 223-math.floor(SP[comSelect+1][k]/a), 130+i*2*n+2*n, 223, SPCol[comSelect+1][k], black)
  295.         end
  296.         for j=0, 63/n do
  297.             k = (currentRNG-j-1+1) % 0x100
  298.             if k == 0 then
  299.                 k = 0x100
  300.             end
  301.             gui.drawrect(126-j*2*n, 223-math.floor(SP[comSelect+1][k]/a), 126-j*2*n+2*n, 223, SPCol[comSelect+1][k], black)
  302.         end
  303.         gui.drawrect(130, 176, 130+n-1, 176+48, light_green, light_green)
  304.         local comSelect = memory.readbyte(0x7E0D1A)
  305.         numParty = memory.readbyte(0x7EF618)
  306.         if comSelect >= 0 and comSelect < numParty then
  307.             if currentRNG == 0xFF then
  308.                 currentRNG = 0
  309.             end
  310.         end
  311.         gui.text(134,176,string.format("%2X->%2d", currentRNG, SP[comSelect+1][currentRNG+1]), light_green)
  312.     end
  313. end
  314.  
  315. SPTest = {}
  316. SPTestCol = {}
  317. function getTestAgi(x)
  318.     local agilityTest = x
  319.     for j = 0, 0xFF do
  320.         SPTest[j+1] = (agilityTest)*2 + math.mod(rng[1+(j)], ((agilityTest)*2)) + 1
  321.         if (SPTest[j+1] > math.floor( agilityTest * (7/2)) ) then
  322.             SPTestCol[j+1] = aqua
  323.         elseif (SPTest[j+1] < math.floor( agilityTest * 5/2) ) then
  324.             SPTestCol[j+1] = pink
  325.         else
  326.             SPTestCol[j+1] = white
  327.         end
  328.     end
  329. end
  330.  
  331. function dispTestSP()
  332.     for j = 0, 0xF do
  333.         for i = 0, 0xF do
  334.             gui.text(32+i*12, 26+j*12, string.format("%2d", SPTest[1+i+0x10*j]), SPTestCol[1+i+0x10*j])
  335.         end
  336.     end
  337.     local currentRNG = memory.readbyte(0x7E0D1F)
  338.     gui.box(31-1+(currentRNG-16*math.floor(currentRNG/16))*12, 24+12*math.floor(currentRNG/16), 32-1+(currentRNG-16*math.floor(currentRNG/16))*12+9, 24+12*math.floor(currentRNG/16)+10, clear, yellow)
  339. end
  340.  
  341.  
  342. function SPTestBar(n, a)
  343.     local currentRNG = memory.readbyte(0x7E0D1F)
  344.     gui.drawrect(128, 223-math.floor(SPTest[currentRNG+1]/a), 128+2*n, 223, SPTestCol[currentRNG+1], black)
  345.     for i=0, 60/n do
  346.         local k = (currentRNG+i+1+1) % 0x100
  347.         if k == 0 then
  348.             k = 0x100
  349.         end
  350.         gui.drawrect(130+i*2*n, 223-math.floor(SPTest[k]/a), 130+i*2*n+2*n, 223, SPTestCol[k], black)
  351.     end
  352.     for j=0, 63/n do
  353.         local k = (currentRNG-j-1+1) % 0x100
  354.         if k == 0 then
  355.             k = 0x100
  356.         end
  357.         gui.drawrect(126-j*2*n, 223-math.floor(SPTest[k]/a), 126-j*2*n+2*n, 223, SPTestCol[k], black)
  358.     end
  359.     gui.drawrect(130, 176, 130+n-1, 176+48, light_green, light_green)
  360.     gui.text(134,176,string.format("%2X->%2d", currentRNG, SPTest[currentRNG+1]), light_green)
  361. end
  362.  
  363.  
  364. local gameMode
  365. function gMode()
  366.     gameMode = memory.readbyte(0x7FAFC7)
  367. end
  368.  
  369. function getBtlParameter()
  370.     gMode()
  371.     if gameMode == 1 then
  372.         getAgi()
  373.  
  374.         dispRNGBar2()
  375.         SPBar(1, 4)
  376.  
  377.         dispRNG2()
  378.         dispSP()
  379.  
  380.         dispComSelect()
  381.         gottenSP()
  382.  
  383.         getEnemyData()
  384.         dispEnemyData()
  385.     end
  386.     dispCurrentRNG()
  387. end
  388.  
  389. function getBtlParameter2()
  390.     gMode()
  391.     if gameMode == 1 then
  392.         getAgi()
  393.  
  394.         rngBar(1)
  395.         rngDisp()
  396.  
  397.         dispComSelect()
  398.         gottenSP()
  399.  
  400.         getEnemyData()
  401.         dispEnemyData()
  402.     end
  403.     dispCurrentRNG()
  404. end
  405.  
  406. sel = 0
  407. ipg0 = {}
  408. ipg1 = {}
  409. function selAdd()
  410.     gMode()
  411.     ipg1 = joypad.get(1)
  412.     if gameMode == 1 and ipg0.select == false and ipg1.select == true then
  413.         sel = sel + 1
  414.     end
  415.     ipg0 = joypad.get(1)
  416. end
  417.  
  418. function dispBtlParameter()
  419.     if (sel % 2) == 0 then
  420.         getBtlParameter()
  421.     else
  422.         getBtlParameter2()
  423.     end
  424. end
  425.  
  426. local waza = {}
  427. function getWaza()
  428.     for i = 1, 5 do
  429.         waza[i] = {}
  430.         for j = 1, 8 do
  431.             waza[i][j] = memory.readbyte(0x7EAA3D + 0x100*(i-1) + (j-1))
  432.         end
  433.     end
  434. end
  435.  
  436. local newWaza = {}
  437. function getNewWaza()
  438.     for i = 1, 5 do
  439.         newWaza[i] = {}
  440.         for j = 1, 8 do
  441.             newWaza[i][j] = memory.readbyte(0x7EAA3D + 0x100*(i-1) + (j-1))
  442.         end
  443.     end
  444. end
  445.  
  446. HP = {}
  447. function getHP()
  448.     for i = 1, 5 do
  449.         HP[i] = memory.readword(0x7EAA0E + 0x100*(i-1))
  450.     end
  451. end
  452.  
  453. condA = {}
  454. condB = {}
  455. condC = {}
  456. eCond = {}
  457. function getCondition()
  458.     for i = 1, 5 do
  459.         condA[i] = memory.readbyte(0x7EAA04 + 0x100*(i-1))
  460.         condB[i] = memory.readbyte(0x7EAA05 + 0x100*(i-1))
  461.         condC[i] = memory.readbyte(0x7EAA06 + 0x100*(i-1))
  462.     end
  463.     for j = 1, 3 do
  464.         eCond[j] = memory.readbyte(0x7EA004 + (j-1))
  465.     end
  466. end
  467.  
  468. local expHP = {}
  469. function getExpHP()
  470.     for i = 1, 5 do
  471.         expHP[i] = memory.readbyte(0xF068 + (i-1)*0x100)
  472.     end
  473. end
  474.  
  475. local item ={}
  476. function getItem()
  477.     for i=1, 32 do
  478.         item[i] = memory.readbyte(0x7EF621 + (i-1)*2)
  479.     end
  480. end
  481.  
  482. local newItem ={}
  483. function getNewItem()
  484.     for i=1, 32 do
  485.         newItem[i] = memory.readbyte(0x7EF621 + (i-1)*2)
  486.     end
  487. end
  488.  
  489. local numItem = {}
  490. function getNumItem()
  491.     for j = 1, 32 do
  492.         numItem[j] = memory.readbyte(0x7EF622 + (j-1)*2)
  493.     end
  494. end
  495.  
  496. local numNewItem = {}
  497. function getNumNewItem()
  498.     for j = 1, 32 do
  499.         numNewItem[j] = memory.readbyte(0x7EF622 + (j-1)*2)
  500.     end
  501. end
  502.  
  503.  
  504. eHP = {}
  505. eMHP = {}
  506. eAgi = {}
  507. eEXP = {}
  508. eWaza={}
  509. monsID = {}
  510. local monNum
  511. function getEnemyData()
  512.     monNum = memory.readbyte(0x7E0D22)
  513.     --for i=1, monNum do
  514.     for i=1, 6 do
  515.         eHP[i] = memory.readword(0x7EA00E+0x100*(i-1))
  516.         eMHP[i] = memory.readbyte(0x7EA010+0x100*(i-1))
  517.         eAgi[i] = memory.readbyte(0x7EA065 + 0x100*(i-1))
  518.         eWaza[i] = memory.readbyte(0x7EA018 + 0x100*(i-1))
  519.         monsID[i] = memory.readword(0x7E1203 + 0x5*(i))
  520.     end
  521. end
  522.  
  523. eHP2 = {}
  524. function getEHP2()
  525.     monNum = memory.readbyte(0x7E0D22)
  526.     for i=1, 6 do
  527.         eHP2[i] = memory.readword(0x7EA00E+0x100*(i-1))
  528.     end
  529. end
  530.  
  531. function dispEnemyData()
  532.     monNum = memory.readbyte(0x7E0D22)
  533.     getEnemyData()
  534.     if monNum > 6 then
  535.         monNum = 6
  536.     end
  537.     for i=1, monNum do
  538.         gui.text(222, 100 + 8*(i-1), string.format("%2d", eHP[i]))
  539.         gui.text(2, 100+8*(i-1), string.format("%d", eAgi[i]))
  540.         gui.text(244, 100 + 8*(i-1), string.format("%2d", eWaza[i]))
  541.     end
  542. end
  543.  
  544. function chkMons(x)
  545.     if eWaza[x] ~= 0xFF then
  546.         return true
  547.     end
  548. end
  549.  
  550. function chkMonsID(x)
  551.     if monsID[x] >= 0 and monsID[x] <= 0x133 then
  552.         return true
  553.     else
  554.         return false
  555.     end
  556. end
  557.  
  558. function killCount()
  559.     getEnemyData()
  560.     local deathCount = 0
  561.     for i=1, monNum do
  562.         if eHP[i] == 0 then
  563.             deathCount = deathCount + 1
  564.         end
  565.     end
  566.     return deathCount
  567. end
  568.  
  569. function killCountAlly()
  570.     local numParty = memory.readbyte(0x7EF618)
  571.     getHP()
  572.     deathCountAlly = 0
  573.     for i = 1, numParty do
  574.         if HP[i] == 0 then
  575.             deathCountAlly = deathCountAlly + 1
  576.         end
  577.     end
  578.     return deathCountAlly
  579. end
  580.  
  581. local btlOn = 1
  582. local lastStart = 0
  583. local lastEnd = 0
  584. function btlEnd()
  585.     local gameMode = memory.readbyte(0x7FAFC7)
  586.     local t = emu.framecount()
  587.     if btlOn ~= gameMode and gameMode ~= 1 then
  588.         lastEnd = t
  589.         btlTime = lastEnd - lastStart
  590.         print(string.format("btlEnd %d, btlTime %d", t, btlTime))
  591.     end
  592.     if btlOn ~= gameMode and gameMode ~= 0 then
  593.         lastStart = t
  594.         print(string.format("btlStart %d", t))
  595.     end
  596.     btlOn = gameMode
  597. end
  598.  
  599.  
  600. take = 0
  601. function skip(x)
  602.     while x > 0 do
  603.         emu.frameadvance()
  604.         local currentRNG = memory.readbyte(0x7E0D1F)
  605.         gui.text(4,32, string.format("take %3d", take))
  606.         gui.text(12,44, string.format("RNG %2X", currentRNG))
  607.         x = x-1
  608.     end
  609. end
  610.  
  611. function skips(x)
  612.     while x > 0 do
  613.         emu.frameadvance()
  614.         x = x-1
  615.     end
  616. end
  617.  
  618. function AB(x)
  619.     while x>0 do
  620.         joypad.set({A=1}, 1)
  621.         skips(20)
  622.         joypad.set({B=1}, 1)
  623.         skips(20)
  624.         x = x-1
  625.     end
  626.     currentRNG = memory.readbyte(0x7E0D1F)
  627.     print(string.format("RNG %X", currentRNG))
  628.     emu.pause()
  629. end
  630.  
  631. function ABtil(x)
  632.     local currentRNG = memory.readbyte(0x7E0D1F)
  633.     while currentRNG ~= x do
  634.         joypad.set({A=1}, 1)
  635.         skips(20)
  636.         joypad.set({B=1}, 1)
  637.         skips(20)
  638.     currentRNG = memory.readbyte(0x7E0D1F)
  639.     end
  640.     print(string.format("RNG %X", currentRNG))
  641.     emu.pause()
  642. end
  643.  
  644. function ABnonStop(x)
  645.     while x>0 do
  646.         joypad.set({A=1}, 1)
  647.         skips(20)
  648.         joypad.set({B=1}, 1)
  649.         skips(20)
  650.         x = x-1
  651.     end
  652. end
  653.  
  654. function btlCommand(left, right, up, down, R, A)
  655.     if left > 0 then
  656.         for i = 1, left do
  657.             joypad.set({left=1}, 1)
  658.             skip(20)
  659.         end
  660.     end
  661.     if right > 0 then
  662.         for i = 1, right do
  663.             joypad.set({right=1}, 1)
  664.             skip(20)
  665.         end
  666.     end
  667.     if up > 0 then
  668.         for i = 1, up do
  669.             joypad.set({up=1}, 1)
  670.             skip(20)
  671.         end
  672.     end
  673.     if down > 0 then
  674.         for i = 1, down do
  675.             joypad.set({down=1}, 1)
  676.             skip(20)
  677.         end
  678.     end
  679.     if R == 1 then
  680.         joypad.set({R=1}, 1)
  681.         skip(20)
  682.     end
  683.     if A == 1 then
  684.         joypad.set({A=1}, 1)
  685.     end
  686.     if A == 2 then
  687.         joypad.set({A=1}, 1)
  688.         skip(20)
  689.         joypad.set({A=1}, 1)
  690.     end
  691.     local comSelect = memory.readbyte(0x7E0D1A)
  692.     local numParty = memory.readbyte(0x7EF618)
  693.     if comSelect ~= numParty - 1 then
  694.         skip(60)
  695.     end
  696. end
  697.  
  698. function btlComOnlyMov(left, right, up, down)
  699.     if left > 0 then
  700.         for i = 1, left do
  701.             joypad.set({left=1}, 1)
  702.             skip(20)
  703.         end
  704.     end
  705.     if right > 0 then
  706.         for i = 1, right do
  707.             joypad.set({right=1}, 1)
  708.             skip(20)
  709.         end
  710.     end
  711.     if up > 0 then
  712.         for i = 1, up do
  713.             joypad.set({up=1}, 1)
  714.             skip(20)
  715.         end
  716.     end
  717.     if down > 0 then
  718.         for i = 1, down do
  719.             joypad.set({down=1}, 1)
  720.             skip(20)
  721.         end
  722.     end
  723.     joypad.set({A=1}, 1)
  724.     skip(20)
  725. end
  726.  
  727. function attack()
  728.     joypad.set({A=1}, 1)
  729.     skip(20)
  730.     joypad.set({A=1}, 1)
  731.     local comSelect = memory.readbyte(0x7E0D1A)
  732.     local numParty = memory.readbyte(0x7EF618)
  733.     if comSelect ~= numParty - 1 then
  734.         skip(60)
  735.     end
  736. end
  737.  
  738. function attackALL()
  739.     joypad.set({A=1}, 1)
  740.     local comSelect = memory.readbyte(0x7E0D1A)
  741.     local numParty = memory.readbyte(0x7EF618)
  742.     if comSelect ~= numParty - 1 then
  743.         skip(60)
  744.     end
  745. end
  746.  
  747. function defence()
  748.     joypad.set({R=1}, 1)
  749.     skip(20)
  750.     joypad.set({A=1}, 1)
  751.     local comSelect = memory.readbyte(0x7E0D1A)
  752.     local numParty = memory.readbyte(0x7EF618)
  753.     if comSelect ~= numParty - 1 then
  754.         skip(60)
  755.     end
  756. end
  757.  
  758. local numParty
  759. function dispComSelect()
  760.     local comSelect = memory.readbyte(0x7E0D1A)
  761.     local currentRNG = memory.readbyte(0x7E0D1F)
  762.     local numParty = memory.readbyte(0x7EF618)
  763.  
  764.     if numParty < 6 then
  765.         if comSelect >=0 and comSelect <  numParty then
  766.             gui.text(228, 164, string.format("%2X->%2d", currentRNG, SP[comSelect+1][currentRNG+1]), SPCol[comSelect+1][currentRNG+1])
  767.         end
  768.     end
  769. end
  770.  
  771.  
  772. local Xpos
  773. local Ypos
  774. function playerPos()
  775.     Xpos = memory.readbyte(0x7E1342)
  776.     Ypos = memory.readbyte(0x7E13D6)
  777.     gui.text(228, 4, string.format("(%X,%X)", Xpos, Ypos))
  778. end
  779.  
  780.  
  781. function dispChiretsugeki()
  782.     local chiretsugeki = memory.readbyte(0x7E0D80)
  783.     gui.text(228, 140, string.format("chi %d", chiretsugeki))
  784. end
  785.  
  786. function dispCurrentRNG()
  787.     local currentRNG = memory.readbyte(0x7E0D1F)
  788.     gui.text(228, 148, string.format("%2X->%2X", currentRNG, rng[currentRNG+1]), yellow)
  789.     local preRNG = (currentRNG-1) % 0x100
  790.     gui.text(228, 156, string.format("%2X->%2X", preRNG, rng[preRNG+1]), gray)
  791. end
  792.  
  793. local take = 0
  794. function encParty(direction)
  795.  
  796.     function skip(x)
  797.         while x > 0 do
  798.             emu.frameadvance()
  799.             local currentRNG = memory.readbyte(0x7E0D1F)
  800.             gui.text(4,32, string.format("take %3d", take))
  801.             gui.text(12,44, string.format("RNG %2X", currentRNG))
  802.             x = x-1
  803.         end
  804.     end
  805.  
  806.     print("Script start ! ")
  807.  
  808.     label = string.format("tBtl\ttake\tinitial RNG\tmonNum\teHP[1]\teHP[2]\teHP[3]\teHP[4]\teHP[5]\teHP[6]\tfinal RNG")
  809.     print(label)
  810.     emu.speedmode("turbo")
  811.  
  812.     save = savestate.create()
  813.     savestate.save(save)
  814.     savestate.load(save)
  815.  
  816.     while take < 0x102 do
  817.         joypad.set({A=1}, 1)
  818.         skip(100)
  819.  
  820.         --1 run
  821.         joypad.set({L=1}, 1)
  822.         skip(20)
  823.         joypad.set({A=1}, 1)
  824.         skip(10)
  825.  
  826.         local currentRNG = memory.readbyte(0x7E0D1F)
  827.  
  828.         for i = 1, 391 do
  829.             if direction == "up" then
  830.                 joypad.set({up=1}, 1)
  831.             elseif direction == "down" then
  832.                 joypad.set({down=1}, 1)
  833.             elseif direction == "left" then
  834.                 joypad.set({left=1}, 1)
  835.             elseif direction == "right" then
  836.                 joypad.set({right=1}, 1)
  837.             end
  838.             emu.frameadvance()
  839.         end
  840.  
  841.         getEnemyData()
  842.  
  843.         local endRNG = memory.readbyte(0x7E0D1F)
  844.         local tBtl = memory.readbyte(0x7EF8AE)
  845.         local monNum = memory.readbyte(0x7E0D22)
  846.  
  847.         local result = string.format("%d\t%d\t%X\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%X", tBtl, take, currentRNG, monNum, eHP[1], eHP[2], eHP[3], eHP[4], eHP[5], eHP[6], endRNG)
  848.  
  849.         --if (eHP[2] >1000 and eHP[2] < 2000) then  -- for NightHead
  850.         print(result)
  851.         --end
  852.  
  853.         take = take + 1
  854.         savestate.load(save)
  855.         emu.frameadvance()
  856.         savestate.save(save)
  857.     end
  858.     print("Done !")
  859.     emu.pause()
  860. end
  861.  
  862. function chk7HeroForm()
  863.     heroForm = memory.readbyte(0x7E0D64)
  864.     if heroForm == 2 then
  865.         printHero = "Bokuoon"
  866.     elseif heroForm == 3 then
  867.         printHero = "Kujinshii"
  868.     elseif heroForm == 4 then
  869.         printHero = "Wagnus"
  870.     elseif heroForm == 5 then
  871.         printHero = "Dantaagu"
  872.     else
  873.         printHero = "Others"
  874.     end
  875. end
  876.  
  877. function btlSim()
  878. local take = 0
  879.  
  880.     function skip(x)
  881.         while x > 0 do
  882.             emu.frameadvance()
  883.             local currentRNG = memory.readbyte(0x7E0D1F)
  884.             gui.text(4,32, string.format("take %3d", take))
  885.             gui.text(12,44, string.format("RNG %2X", currentRNG))
  886.             x = x-1
  887.         end
  888.     end
  889.  
  890.     print("Script start ! ")
  891.  
  892.     local comSelect = memory.readbyte(0x7E0D1A)
  893.     local numParty = memory.readbyte(0x7EF618)
  894.     getEHP2()
  895.     getEnemyData()
  896.     preEHP = eHP[1]
  897.  
  898.     if comSelect == 0 or comSelect == 85 then
  899.         print("Aずらし")
  900.     elseif comSelect == numParty - 1 then
  901.         print("ABC")
  902.     end
  903.  
  904.     print(action)
  905.     print(label)
  906.     emu.speedmode("turbo")
  907.     --rngDisp()
  908.     save = savestate.create()
  909.     savestate.save(save)
  910.     savestate.load(save)
  911.  
  912.     while take < 0x102 do
  913.         emu.frameadvance()
  914.         local currentRNG = memory.readbyte(0x7E0D1F)
  915.         local initialFr = emu.framecount()
  916.         local comSelect = memory.readbyte(0x7E0D1A)
  917.  
  918. --~         if comSelect == 0 or comSelect == 85 then
  919.         if comSelect == 0 or comSelect == 85 or comSelect == 5 then
  920.             joypad.set({A=1}, 1)
  921.             skip(100)
  922.  
  923.             --1
  924. --~             btlCommand(0, 0, 1, 0, 0, 2)
  925. --~             btlComOnlyMov(0, 0, 0, 1)
  926. --~             attackALL()
  927.             attack()
  928. --~             defence()
  929.             --2
  930. --~             btlCommand(1, 0, 1, 0, 0, 2)
  931. --~             attack()
  932. --~             btlComOnlyMov(0, 1, 0, 0)
  933.             defence()
  934.             --3 taiken
  935. --~             btlCommand(1, 0, 0, 1, 0, 2)
  936. --~             btlComOnlyMov(0, 1, 0, 0)
  937.             defence()
  938. --~             attack()
  939.             --4
  940. --~             btlCommand(2, 0, 1, 0, 0, 2)
  941. --~             attack()
  942.             defence()
  943.         end
  944.         --5
  945. --~             btlCommand(1, 0, 0, 1, 0, 2)
  946. --~         defence()
  947.         attack()
  948.  
  949.         getWaza()
  950.         getItem()
  951.         getNumItem()
  952.         for i = 1, 30 do
  953.             getAgi()
  954.             gottenSP()
  955.             getHP()
  956.             emu.frameadvance()
  957.         end
  958.  
  959.         local startHP = {}
  960.         for i = 1, 5 do
  961.             startHP[i] = HP[i]
  962.         end
  963.  
  964.         local comparisonSP = 0
  965.  
  966.         compSP(1)
  967.  
  968.         local numParty = memory.readbyte(0x7EF618)
  969.         local comSelect = numParty
  970.  
  971.         local chiretsugeki = memory.readbyte(0x7E0D80)
  972.  
  973.         local gameMode = memory.readbyte(0x7FAFC7)
  974.         local chkHP = 0
  975.         local chkHP1 = 0
  976.         local chkHP3 = 0
  977.         local dC = 0
  978.         local reverse = 0
  979.         local chkEHP = 0
  980.  
  981.         while gameMode == 1 and comSelect == numParty do
  982. --~         while gameMode == 1 and comSelect == numParty and dC < 2 and reverse == 0 do
  983. --~         while gameMode == 1 and comSelect == numParty and dC < 2 do
  984.             gui.text(4,32, string.format("take %3d", take))
  985.             gui.text(12,44, string.format("RNG %2X", currentRNG))
  986.  
  987.             emu.frameadvance()
  988.  
  989.             gui.text(4,32, string.format("take %3d", take))
  990.             gui.text(12,44, string.format("RNG %2X", currentRNG))
  991.             joypad.set({A=1}, 1)
  992.             emu.frameadvance()
  993.             comSelect = memory.readbyte(0x7E0D1A)
  994.             gameMode = memory.readbyte(0x7FAFC7)
  995.             getHP()
  996.  
  997. --~             for i = 1, numParty do
  998. --~                 if startHP[i] > HP[i] then
  999. --~                     chkHP = chkHP + 1
  1000. --~                 end
  1001. --~             end
  1002.  
  1003.             if startHP[1] > HP[1] then
  1004.                 chkHP1 = chkHP1 + 1
  1005.             end
  1006.             if startHP[3] > HP[3] then
  1007.                 chkHP3 = chkHP3 + 1
  1008.             end
  1009.             dC = killCountAlly()
  1010.             getEnemyData()
  1011.             if preEHP < eHP[1] then
  1012.                 reverse = reverse + 1
  1013.             end
  1014.             if preEHP < 6000 and eHP[1] == 6000 then
  1015.                 chkEHP = chkEHP + 1
  1016.             end
  1017.         preEHP = eHP[1]
  1018.  
  1019.         preEHP = eHP[1]
  1020.         end
  1021.  
  1022.         local t = emu.framecount()
  1023.         local time = t - initialFr
  1024.  
  1025.         getEnemyData()
  1026.  
  1027.         getNewWaza()
  1028.         getNewItem()
  1029.         getNumNewItem()
  1030.         getHP()
  1031.         getAgi()
  1032.         getCondition()
  1033.  
  1034.         chk7HeroForm()
  1035.  
  1036.         local printWaza = {}
  1037.         local wazaCount = 0
  1038.         for i = 1, 5 do
  1039.             printWaza[i] = 0xFF
  1040.             for j = 1, 8 do
  1041.                 if newWaza[i][j] ~= waza[i][j] then
  1042.                     printWaza[i] = newWaza[i][j]
  1043.                     wazaCount = wazaCount + 1
  1044. --~                     break
  1045.                 end
  1046.             end
  1047.         end
  1048.  
  1049.         local printItem = 0xFF
  1050.         local itemCount = 0
  1051.         for i = 1, 32 do
  1052.             if newItem[i] ~= item[i] then
  1053.                 printItem = newItem[i]
  1054.                 itemCount = itemCount + 1
  1055.             end
  1056.         end
  1057.  
  1058.         local printNumItem = 0
  1059.         local itemNumCount = 0
  1060.         for i = 1, 32 do
  1061.             if numNewItem[i] ~= numItem[i] then
  1062.                 printNumItem = newItem[i]
  1063.                 itemNumCount = itemNumCount + 1
  1064.             end
  1065.         end
  1066.  
  1067.         damage = {}
  1068.         for i = 1, monNum do
  1069.             damage[i] = eHP2[i]-eHP[i]
  1070.         end
  1071.  
  1072.         local chiretsugeki = memory.readbyte(0x7E0D80)
  1073.  
  1074.         local deathCount = killCount()
  1075.         local endRNG = memory.readbyte(0x7E0D1F)
  1076.  
  1077.         local muddleCount = 0
  1078.         for i = 1, numParty do
  1079.             if condA[i] == 0x01 then
  1080.                 muddleCount = muddleCount + 1
  1081.             end
  1082.         end
  1083.  
  1084.         local result = string.format("%d\t%X\t%d\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%X\t%X\t%X\t%X\t%X\t%02X%02X%02X\t%02X%02X%02X\t%02X%02X%02X\t%02X%02X%02X\t%02X%02X%02X\t%d\t%X\t%d\t%d\t%d\t%d\t%X", take, currentRNG, initialFr, printHero, chkEHP, eHP[1], dC, HP[1], HP[2], HP[3], HP[4], HP[5], valueSP[1], valueSP[2], valueSP[3], valueSP[4], valueSP[5], wazaCount, printWaza[1], printWaza[2], printWaza[3], printWaza[4], printWaza[5], condA[1], condB[1], condC[1], condA[2], condB[2], condC[2], condA[3], condB[3], condC[3], condA[4], condB[4], condC[4], condA[5], condB[5], condC[5], reverse, endRNG, t, time, damage[1], printNumItem, printItem)
  1085.  
  1086.         local MeiRyoku = memory.readbyte(0x7EA064)
  1087.  
  1088.         dC = killCountAlly()
  1089.  
  1090. --~         if (wazaCount ~= 0 or dC < 2) and wazaCount ~= 40 then
  1091. --~         if ((wazaCount ~= 0 or dC < 2) and wazaCount ~= 40) or killCount == 1 then
  1092. --~         if  wazaCount ~= 40 and (wazaCount ~= 0 or killCount == 1) then
  1093.             print(result)
  1094. --~         end
  1095.  
  1096.         take = take + 1
  1097.         savestate.load(save)
  1098.  
  1099.         local comSelect = memory.readbyte(0x7E0D1A)
  1100.         local numParty = memory.readbyte(0x7EF618)
  1101.         getEnemyData()
  1102.         preEHP = eHP[1]
  1103.         local reverse = 0
  1104.  
  1105.         if comSelect == numParty - 1 then
  1106.             emu.frameadvance()
  1107.             ABnonStop(1)
  1108.         end
  1109.  
  1110.         emu.frameadvance()
  1111.         savestate.save(save)
  1112.     end
  1113.     print("Done !")
  1114.     emu.pause()
  1115. end
  1116.  
  1117. function btlStart(n)
  1118.     take = 1
  1119.     print("Script start ! ")
  1120.     emu.speedmode("turbo")
  1121.     local currentRNG = memory.readbyte(0x7E0D1F)
  1122.     local N = n-4-currentRNG
  1123.     if N < 0 then
  1124.         N = N + 0x100 - 1
  1125.     end
  1126.  
  1127.     totalTake = (N+4)*(N+3)*(N+2)*(N+1)/24  -- max: 180352320
  1128.     print(string.format("total Take\t%d\t%2X/%2X", totalTake, currentRNG, n))
  1129.  
  1130.     print(action)
  1131.     print(label2)
  1132.  
  1133.     for a = 0, N do
  1134.         for b = 0, N-a do
  1135.             for c = 0, N-a-b do
  1136.                 for d = 0, N-a-b-c do
  1137.                     e =  N-a-b-c-d
  1138.                     btlSim2(a, b, c, d, e)
  1139.                 end
  1140.             end
  1141.         end
  1142.     end
  1143.     print("Done !")
  1144.     emu.pause()
  1145. end
  1146.  
  1147. function btlSim2(a, b, c, d, e)
  1148.  
  1149.     function skip(x)
  1150.         while x > 0 do
  1151.             emu.frameadvance()
  1152.             local currentRNG = memory.readbyte(0x7E0D1F)
  1153.             gui.text(4,32, string.format("take %3d/%d  (%d, %d, %d, %d, %d)", take, totalTake, a, b, c, d, e))
  1154.             gui.text(12,44, string.format("RNG %2X", currentRNG))
  1155.             x = x-1
  1156.         end
  1157.     end
  1158.  
  1159.     local comSelect = memory.readbyte(0x7E0D1A)
  1160.     local numParty = memory.readbyte(0x7EF618)
  1161.     getEHP2()
  1162.     getEnemyData()
  1163.     preEHP = eHP[1]
  1164.  
  1165.     --rngDisp()
  1166.  
  1167.     save = savestate.create()
  1168.     savestate.save(save)
  1169.     savestate.load(save)
  1170.  
  1171.     emu.frameadvance()
  1172.     local comSelect = memory.readbyte(0x7E0D1A)
  1173.     local initialFr = emu.framecount()
  1174.  
  1175.     --1
  1176.     local firstRNG = memory.readbyte(0x7E0D1F)
  1177.     ABnonStop(a)
  1178. --~ btlCommand(2, 0, 0, 1, 0, 2)
  1179. --~     btlComOnlyMov(0, 2, 0, 1)
  1180. --~     attackALL()
  1181.     attack()
  1182. --~     defence()
  1183.     --2
  1184.     ABnonStop(b)
  1185.     btlCommand(0, 1, 0, 0, 0, 2)
  1186. --~     attack()
  1187. --~ btlComOnlyMov(0, 1, 0, 0)
  1188. --~ defence()
  1189.     --3
  1190.     skip(10)
  1191.     ABnonStop(c)
  1192.     btlCommand(0, 0, 1, 0, 0, 2)
  1193. --~ btlComOnlyMov(0, 1, 0, 0)
  1194. --~ defence()
  1195. --~     attack()
  1196.     --4
  1197.     ABnonStop(d)
  1198. --~ btlCommand(0, 2, 1, 0, 0, 2)
  1199.     attack()
  1200. --~ defence()
  1201.     --5
  1202.     ABnonStop(e)
  1203.     local currentRNG = memory.readbyte(0x7E0D1F)
  1204.     btlCommand(1, 0, 0, 0, 0, 2)
  1205. --~ defence()
  1206. --~     attack()
  1207.  
  1208.     getWaza()
  1209.     getItem()
  1210.     getNumItem()
  1211.     for i = 1, 30 do
  1212.         getAgi()
  1213.         gottenSP()
  1214.         getHP()
  1215.         emu.frameadvance()
  1216.     end
  1217.  
  1218.     local startHP = {}
  1219.     for i = 1, 5 do
  1220.         startHP[i] = HP[i]
  1221.     end
  1222.  
  1223.     local comparisonSP = 0
  1224.  
  1225.     compSP(1)
  1226.  
  1227.     local numParty = memory.readbyte(0x7EF618)
  1228.     local comSelect = numParty
  1229.  
  1230.     local chiretsugeki = memory.readbyte(0x7E0D80)
  1231.  
  1232.     local gameMode = memory.readbyte(0x7FAFC7)
  1233.     local chkHP = 0
  1234.     local chkHP1 = 0
  1235.     local chkHP3 = 0
  1236.     local dC = 0
  1237.     local reverse = 0
  1238.     local chkEHP = 0
  1239.  
  1240.     while gameMode == 1 and comSelect == numParty do
  1241. --~ while gameMode == 1 and comSelect ~= 0 do
  1242. --~ while gameMode == 1 and comSelect == numParty and dC < 2 and reverse == 0 do
  1243. --~     while gameMode == 1 and comSelect == numParty and dC < 2 do
  1244.         gui.text(4,32, string.format("take %3d/%d  (%d, %d, %d, %d, %d)", take, totalTake, a, b, c, d, e))
  1245.         gui.text(12,44, string.format("RNG %2X/%2X", firstRNG, currentRNG))
  1246.  
  1247.         emu.frameadvance()
  1248.  
  1249.         gui.text(4,32, string.format("take %3d/%d  (%d, %d, %d, %d, %d)", take, totalTake, a, b, c, d, e))
  1250.         gui.text(12,44, string.format("RNG %2X/%2X", firstRNG, currentRNG))
  1251.         joypad.set({A=1}, 1)
  1252.         emu.frameadvance()
  1253.         comSelect = memory.readbyte(0x7E0D1A)
  1254.         gameMode = memory.readbyte(0x7FAFC7)
  1255.         getHP()
  1256. --~         for i = 1, numParty do
  1257. --~             if startHP[i] > HP[i] then
  1258. --~                 chkHP = chkHP + 1
  1259. --~             end
  1260. --~         end
  1261.  
  1262.         if startHP[1] > HP[1] then
  1263.             chkHP1 = chkHP1 + 1
  1264.         end
  1265.         if startHP[3] > HP[3] then
  1266.             chkHP3 = chkHP3 + 1
  1267.         end
  1268.         dC = killCountAlly()
  1269.         getEnemyData()
  1270.         if preEHP < eHP[1] then
  1271.             reverse = reverse + 1
  1272.         end
  1273.         if preEHP < 6000 and eHP[1] == 6000 then
  1274.             chkEHP = chkEHP + 1
  1275.         end
  1276.         preEHP = eHP[1]
  1277.     end
  1278.  
  1279.     local t = emu.framecount()
  1280.     local time = t - initialFr
  1281.  
  1282.     getEnemyData()
  1283.  
  1284.     getNewWaza()
  1285.     getNewItem()
  1286.     getNumNewItem()
  1287.     getHP()
  1288.     getAgi()
  1289.     getCondition()
  1290.  
  1291.     chk7HeroForm()
  1292.  
  1293.     local printWaza = {}
  1294.     local wazaCount = 0
  1295.     for i = 1, 5 do
  1296.         printWaza[i] = 0xFF
  1297.         for j = 1, 8 do
  1298.             if newWaza[i][j] ~= waza[i][j] then
  1299.                 printWaza[i] = newWaza[i][j]
  1300.                 wazaCount = wazaCount + 1
  1301. --~                 break
  1302.             end
  1303.         end
  1304.     end
  1305.  
  1306.     local printItem = 0xFF
  1307.     local itemCount = 0
  1308.     for i = 1, 32 do
  1309.         if newItem[i] ~= item[i] then
  1310.             printItem = newItem[i]
  1311.             itemCount = itemCount + 1
  1312.         end
  1313.     end
  1314.  
  1315.     local printNumItem = 0
  1316.     local itemNumCount = 0
  1317.     for i = 1, 32 do
  1318.         if numNewItem[i] ~= numItem[i] then
  1319.             printNumItem = newItem[i]
  1320.             itemNumCount = itemNumCount + 1
  1321.         end
  1322.     end
  1323.  
  1324.     damage = {}
  1325.     for i = 1, monNum do
  1326.         damage[i] = eHP2[i]-eHP[i]
  1327.     end
  1328.  
  1329.     local chiretsugeki = memory.readbyte(0x7E0D80)
  1330.  
  1331.     local deathCount = killCount()
  1332.     local endRNG = memory.readbyte(0x7E0D1F)
  1333.  
  1334.     local muddleCount = 0
  1335.     for i = 1, numParty do
  1336.         if condA[i] == 0x01 then
  1337.             muddleCount = muddleCount + 1
  1338.         end
  1339.     end
  1340.  
  1341.     local MeiRyoku = memory.readbyte(0x7EA064)
  1342.  
  1343.     dC = killCountAlly()
  1344.  
  1345.     local result = string.format("%d\t%2X\t%d\t%d\t%d\t%d\t%d\t%X\t%d\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%X\t%X\t%X\t%X\t%X\t%02X%02X%02X\t%02X%02X%02X\t%02X%02X%02X\t%02X%02X%02X\t%02X%02X%02X\t%d\t%X\t%d\t%d\t%d\t%d\t%X", take, firstRNG, a, b, c, d, e, currentRNG, initialFr, printHero, chkEHP, eHP[1], dC, HP[1], HP[2], HP[3], HP[4], HP[5], valueSP[1], valueSP[2], valueSP[3], valueSP[4], valueSP[5], wazaCount, printWaza[1], printWaza[2], printWaza[3], printWaza[4], printWaza[5], condA[1], condB[1], condC[1], condA[2], condB[2], condC[2], condA[3], condB[3], condC[3], condA[4], condB[4], condC[4], condA[5], condB[5], condC[5], reverse, endRNG, t, time, damage[1], printNumItem, printItem)
  1346.  
  1347.  
  1348. --~     if (wazaCount ~= 0 or dC < 2) and wazaCount ~= 40 then
  1349. --~     if ((wazaCount ~= 0 or dC < 2) and wazaCount ~= 40) or killCount == 1 then
  1350.         print(result)
  1351. --~     end
  1352.  
  1353.     take = take + 1
  1354.     savestate.load(save)
  1355.  
  1356.     local comSelect = memory.readbyte(0x7E0D1A)
  1357.     local numParty = memory.readbyte(0x7EF618)
  1358.     getEnemyData()
  1359.     preEHP = eHP[1]
  1360.     local reverse = 0
  1361.  
  1362.     if comSelect == numParty - 1 then
  1363.         emu.frameadvance()
  1364.         ABnonStop(1)
  1365.     end
  1366.  
  1367.     emu.frameadvance()
  1368.     savestate.save(save)
  1369. end
  1370.  
  1371. function chkInitialHP()
  1372.     local take = 0
  1373.     print("Script start !")
  1374.     print("take\tレオン\tジェラール\tベア\tジェイムズ\tテレーズ")
  1375.     local HP = {}
  1376.     local function getInitialHP()
  1377.         for i = 1, 5 do
  1378.             HP[i] = memory.readword(0x7EF010 + 0x100*(i-1))
  1379.         end
  1380.     end
  1381.  
  1382.     emu.speedmode("turbo")
  1383.  
  1384.     save = savestate.create()
  1385.     savestate.save(save)
  1386.     savestate.load(save)
  1387.  
  1388.     while take < 0x102 do
  1389.         gui.text(4, 32, string.format("take %3d", take))
  1390.         joypad.set({start=1}, 1)
  1391.         emu.frameadvance()
  1392.         getInitialHP()
  1393.  
  1394.         while HP[5] == 0 do
  1395.             emu.frameadvance()
  1396.             gui.text(4, 32, string.format("take %3d", take))
  1397.             getInitialHP()
  1398.         end
  1399.  
  1400. --~     if HP[3] > 79 then
  1401.             print(string.format("%d\t%d\t%d\t%d\t%d\t%d", take, HP[1], HP[2], HP[3], HP[4],HP[5]))
  1402. --~             emu.pause()
  1403. --~     end
  1404.  
  1405.         take = take + 1
  1406.         savestate.load(save)
  1407.         emu.frameadvance()
  1408.         savestate.save(save)
  1409.     end
  1410.     print("Done !")
  1411.     emu.pause()
  1412. end
  1413.  
  1414. function makeSaves(x, y)
  1415.     t = emu.framecount()
  1416.     for i = 1, 10 do
  1417.         if t == x + y*i then
  1418.             save = savestate.create(i)
  1419.             savestate.save(save)
  1420.             print("Saved at "..t.."f.")
  1421.         end
  1422.     end
  1423.     if t >= x + y*10 then
  1424.         emu.frameadvance()
  1425.         pause(x + y*9)
  1426.     end
  1427. end
  1428.  
  1429. function pause(x)
  1430.     local t = emu.framecount()
  1431.     if t >= x-1 then
  1432.         t = t+1
  1433.         print("Paused at "..t.."f.")
  1434.         emu.pause()
  1435.     end
  1436. end
  1437.  
  1438. defP = {}
  1439. function getDefP()
  1440.     for i = 1, 5 do
  1441.         defP[i] = {}
  1442.             for j = 1, 8 do
  1443.                 defP[i][j] = memory.readbyte(0x7EF055 + 0x100*(i-1) + j-1)  -- joined order
  1444. --~                 defP[i][j] = memory.readbyte(0x7EAA55 + 0x100*(i-1) + j-1)  -- order in battles
  1445.             end
  1446.     end
  1447. end
  1448.  
  1449. function dispDefP()
  1450.     local x = 58
  1451.     local y = 60
  1452.     local gap = 10
  1453.     gui.text(x, y, "sword")
  1454.     gui.text(x, y+gap, "axe")
  1455.     gui.text(x, y+gap*2, "spear")
  1456.     gui.text(x, y+gap*3, "arrow")
  1457.     gui.text(x, y+gap*4, "heat")
  1458.     gui.text(x, y+gap*5, "cold")
  1459.     gui.text(x, y+gap*6, "elec")
  1460.     gui.text(x, y+gap*7, "spirit")
  1461.     getDefP()
  1462.     for i = 1, 5 do
  1463.         for j = 1, 8 do
  1464.             gui.text(x+20+24*i, y+gap*(j-1), defP[i][j])
  1465.         end
  1466.     end
  1467. end
  1468.  
  1469. while true do
  1470. --~     makeSaves(400, 100)
  1471.  
  1472. --~     pause(1500)
  1473.  
  1474. --~     dispDefP()
  1475.  
  1476.     playerPos()
  1477.     --msg()
  1478.     btlEnd()
  1479.  
  1480.     getParameter()
  1481.     dispParameter()
  1482.  
  1483.     --dispChiretsugeki()
  1484.     dispCurrentRNG()
  1485.  
  1486. --~     getBtlParameter()
  1487. --~     getBtlParameter2()
  1488.     selAdd()
  1489.     dispBtlParameter()
  1490.  
  1491. --~     rngMOD(4)
  1492. --~     rngDispMod()
  1493.  
  1494. --~     getTestAgi(16)
  1495. --~     SPTestBar(1, 4)
  1496. --~     dispTestSP()
  1497.  
  1498. --~     AB(0x50)
  1499. --~     ABtil(0xD4)
  1500.  
  1501.     --encParty("down")
  1502.  
  1503.     action = "nabla\tnabla\tnabla\tnabla\tnabla"
  1504.     label = "take\tinitial RNG\tinitial Fr\t七英雄形態\t形態変化数\teHP[1]\t死者数\t\tイングリット\tジャンヌ\tパーシアス\tフランクリン\tあSP[1]\tイングリットP[2]\tジャンヌP[3]\tパーシアスP[4]\tPランクリンSP[5]\t新技数\tあ技\tイングリット\tジャンヌ技\tパーシアス技\tフランクリン技\tあ状態\tイングリット状態\tジャンヌ状態\tパーシアス状態\tフランクリン状態\t敵状態\tfinal RNG\tFr\tTime\tダメージ\t既持ドロップ\tドロップ\(new\)"
  1505.  
  1506. --~     btlSim()
  1507.  
  1508.     label2 = "take\t皇帝RNG\ta\tb\tc\td\te\t5人目RNG\tinitial Fr\t七英雄形態\t形態変化数\teHP[1]\t死者数\t\tイングリット\tジャンヌ\tパーシアス\tフランクリン\tあSP[1]\tイングリットSP[2]\tジャンヌSP[3]\tパーシアスSP[4]\tフランクリンSP[5]\t新技数\tあ技\tイングリット技\tジャンヌ技\tパーシアス技\tフランクリン技\tあ状態\tイングリット状態\tジャンヌ状態\tパーシアス状態\tフランクリン状態\t敵状態\tfinal RNG\tFr\tTime\tダメージ\t既持ドロップ\tドロップ\(new\)"
  1509.  
  1510.     -- Wagnus Prism Light (0x01, 0x09, 0x0B, 0x14, 0x22, 0x25, 0x27, 0x34, 0x3B, 0x40, 0x4E, 0x54, 0x55, 0x65, 0x6A, 0x93, 0x94, 0xAC, 0xBC, 0xBD, 0xBE, 0xCB, 0xE0, 0xE2, 0xE3, 0xE6, 0xE7)
  1511. --~     btlStart(0x5E)
  1512.  
  1513. --~     chkInitialHP()
  1514.  
  1515.     emu.frameadvance();
  1516. end
  1517.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement