Advertisement
Guest User

Untitled

a guest
May 5th, 2021
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 36.42 KB | None | 0 0
  1. -- This Lua Script is for Romancing SaGa 2 on BizHawk.
  2.  
  3. memory.usememorydomain("CARTROM")
  4. rng = {}
  5. for i = 0, 0xFF do
  6.     rng[i+1] = memory.read_u8(0x02EF04+i)   --rng[i] = i-1 (rng[0] = 1, ... , rng[256] = 255)
  7.     -- 0x02EF04-0x02F003
  8. end
  9. memory.usememorydomain("WRAM")
  10.  
  11. --~ gui.defaultPixelFont("gens")
  12. --~ gui.defaultPixelFont("fceux")
  13.  
  14. --https://msdn.microsoft.com/en-us/library/system.drawing.color.aspx    <-- color name/value
  15. local pink = 0xFFFFC0CB
  16. local orange = 0xFFFFA500
  17. local yellow = 0xFFFFFF00
  18. local light_green = 0xFF90EE90
  19. local blue = 0xFF0000FF
  20. local white = 0xFFFFFFFF
  21. local red = 0xFFFF0000
  22. local green = 0xFF008000
  23. local black = 0xFF000000
  24. local dark_green = 0xFF006400
  25. local aqua = 0xFF00FFFF
  26. local gray = 0xFF808080
  27. local brown = 0xFFA52A2A
  28.  
  29. --dofile("filePath")
  30.  
  31. local msg1
  32. local msg0
  33. function msg()  --for supporting scrollng text messages, imputting battle command
  34.     msg1 = mainmemory.read_u8(0x1F01)
  35.     if msg1 ==  0 and msg0 ~= 0 then
  36.         print(emu.framecount())
  37.     end
  38.     msg0 = msg1
  39. end
  40.  
  41. local EP
  42. local totalBattle
  43. local battle
  44. local safe
  45. local safe2 = {}
  46. local Hiraga
  47. function getParameter()
  48.     EP = mainmemory.read_u8(0xF693)
  49.     totalBattle = mainmemory.read_u16_le(0xF8AE)
  50.     battle = mainmemory.read_u8(0xF694)
  51.     safe = mainmemory.read_u8(0xF7A2) + 0x100 * mainmemory.read_u8(0xF7A3) + 0x10000 * mainmemory.read_u8(0xF7A4)
  52.     safe2[1] = math.floor(safe/1000000)
  53.     safe2[2] = math.floor((safe-(safe2[1]*1000000))/1000)
  54.     safe2[3] = safe - (safe2[1]*1000000)-(safe2[2]*1000)
  55.     Hiraga = mainmemory.read_u8(0xF697)
  56. end
  57.  
  58. function dispParameter()
  59.     if safe2[1] ~= 0 then
  60.         gui.pixelText(216, 12, string.format("%3d,%03d,%03d", safe2[1], safe2[2], safe2[3]))
  61.     elseif safe2[2] ~= 0 then
  62.         gui.pixelText(224, 12, string.format("%3d,%03d", safe2[2], safe2[3]))
  63.     else
  64.         gui.pixelText(234, 12, string.format("%3d", safe2[3]))
  65.     end
  66.     gui.pixelText(236, 20, string.format("EP %d", EP))
  67.     gui.pixelText(236, 28, string.format("%d/%d", battle, totalBattle))
  68.     gui.pixelText(236, 36, string.format("%dsei", Hiraga))
  69.     local jump
  70.     local battle16 = battle % 0x10
  71.  
  72.     if EP >= battle16 then
  73.         if battle < 0x30 then
  74.             jump = battle16 + 0x30
  75.         else
  76.             jump = battle
  77.         end
  78. --~         gui.pixelText(230, 68, string.format("jump%d", jump))
  79. --~         gui.pixelText(218, 76, string.format("tBtl%d->%d", totalBattle, totalBattle + math.floor(jump/4)))
  80. --~         gui.pixelText(216, 84, string.format("%dsei->%dsei", Hiraga, Hiraga + math.floor((jump/0x20) + (1/2))))
  81.     end
  82. end
  83.  
  84.  
  85. rngMod = {}
  86. rngModCol = {}
  87. function rngMOD(x)  -- for computing SP
  88.     for i = 0, 0xFF do
  89.         rngMod[i+1] = (rng[i+1] % x)
  90.     end
  91. end
  92.  
  93. rngCol = {}
  94. for i = 0, 0xFF do
  95.     residue20 = (rng[i+1] % 0x20)
  96.     residue40 = (rng[i+1] % 0x40)
  97.     if residue20 == 0 then  -- normal drop
  98.         rngCol[i+1] = light_green
  99.     elseif rng[i+1] < 0x1F then -- waza 7
  100.         rngCol[i+1] = pink
  101.     elseif rng[i+1] < 0x32 then -- waza same level
  102.         rngCol[i+1] = yellow
  103.     else
  104.         rngCol[i+1] = white
  105.     end
  106.     if residue40 == 0 then  -- rare drop
  107.         rngCol[i+1] = blue
  108.     end
  109. end
  110.  
  111.  
  112. function rngDisp()
  113.     for j = 0, 0xF do
  114.         for i = 0, 0xF do
  115.             gui.pixelText(32+i*12, 26+j*12, string.format("%2X", rng[1+i+0x10*j]), rngCol[1+i+0x10*j])
  116.         end
  117.     end
  118.     local currentRNG = mainmemory.read_u8(0x0D1F)
  119.     gui.drawBox(31+(currentRNG-16*math.floor(currentRNG/16))*12, 24+12*math.floor(currentRNG/16), 32+(currentRNG-16*math.floor(currentRNG/16))*12+9, 24+12*math.floor(currentRNG/16)+10, yellow)
  120. end
  121.  
  122. function rngDispMod()
  123.     for j = 0, 0xF do
  124.         for i = 0, 0xF do
  125.                 gui.pixelText(32+i*12, 26+j*12, string.format("%2X", rngMod[1+i+0x10*j]), rngModCol[1+i+0x10*j])
  126.         end
  127.     end
  128.     local currentRNG = mainmemory.read_u8(0x0D1F)
  129.     gui.drawBox(31+(currentRNG-16*math.floor(currentRNG/16))*12, 24+12*math.floor(currentRNG/16), 32+(currentRNG-16*math.floor(currentRNG/16))*12+9, 24+12*math.floor(currentRNG/16)+10, yellow)
  130. end
  131.  
  132. function dispRNG2()
  133.     local comSelect = mainmemory.read_u8(0x0D1A)
  134.     local numParty = mainmemory.read_u8(0xF618)
  135.     local countSP = 0
  136.     for i = 1, numParty do
  137.         gotSP[i] = mainmemory.read_u8(0x0DD7 + (i-1))
  138.         if gotSP[i] == 0 then
  139.             countSP = countSP + 1
  140.         end
  141.     end
  142.     if countSP == numParty or comSelect > numParty then
  143.         rngDisp()
  144.     end
  145. end
  146.  
  147. function rngBar(n)  -- n = 1 or 3
  148.     local currentRNG = mainmemory.read_u8(0x0D1F)
  149.     gui.drawRectangle(128, 223-math.floor(rng[currentRNG+1]/8), 2*n, math.floor(rng[currentRNG+1]/8), black, rngCol[currentRNG+1])
  150.     for i=0, 63/n do
  151.         k = (currentRNG+i+1+1) % 0x100
  152.         if k == 0 then
  153.             k = 0x100
  154.         end
  155.         gui.drawRectangle(130+i*2*n, 223-math.floor(rng[k]/8), 2*n, math.floor(rng[k]/8), black, rngCol[k])
  156.     end
  157.     for j=0, 63/n do
  158.         k = (currentRNG-j-1+1) % 0x100
  159.         if k == 0 then
  160.             k = 0x100
  161.         end
  162.         gui.drawRectangle(126-j*2*n, 223-math.floor(rng[k]/8), 2*n, math.floor(rng[k]/8), black, rngCol[k])
  163.     end
  164.     gui.drawRectangle(130, 176, n-1, 48, light_green, light_green)
  165.     gui.pixelText(134,176,string.format("%2X->%2X", currentRNG, rng[currentRNG+1]), light_green)
  166. end
  167.  
  168. gotSP = {}
  169. function dispRNGBar2()
  170.     local comSelect = mainmemory.read_u8(0x0D1A)
  171.     local numParty = mainmemory.read_u8(0xF618)
  172.     local countSP = 0
  173.     for i = 1, numParty do
  174.         gotSP[i] = mainmemory.read_u8(0x0DD7 + (i-1))
  175.         if gotSP[i] == 0 then
  176.             countSP = countSP + 1
  177.         end
  178.     end
  179.     if countSP == numParty or comSelect > numParty then
  180.         rngBar(1)
  181.     end
  182. end
  183.  
  184. agility = {}
  185. SP = {}
  186. SPCol = {}
  187. function getAgi()
  188.     for i = 1, 5 do
  189.         agility[i] = mainmemory.read_u8(0xAA65+0x0100*(i-1))
  190.         SP[i] = {}
  191.         SPCol[i] = {}
  192.         for j = 0, 0xFF do
  193.             SP[i][j+1] = (agility[i])*2 + math.mod(rng[1+(j)], ((agility[i])*2)) + 1
  194.             if (SP[i][j+1] > math.floor( agility[i] * (7/2)) ) then
  195.                 SPCol[i][j+1] = aqua
  196.             elseif (SP[i][j+1] < math.floor( agility[i] * 5/2) ) then
  197.                 SPCol[i][j+1] = pink
  198.             else
  199.                 SPCol[i][j+1] = white
  200.             end
  201.         end
  202.     end
  203. end
  204.  
  205. function dispSP()
  206.     local comSelect = mainmemory.read_u8(0x0D1A)
  207.     local numParty = mainmemory.read_u8(0xF618)
  208.     if comSelect >= 0 and comSelect < numParty then
  209.         for j = 0, 0xF do
  210.             for i = 0, 0xF do
  211.                 gui.pixelText(32+i*12, 26+j*12, string.format("%2d", SP[comSelect+1][1+i+0x10*j]), SPCol[comSelect+1][1+i+0x10*j])
  212.             end
  213.         end
  214.         local currentRNG = mainmemory.read_u8(0x0D1F)
  215.         gui.drawBox(31+(currentRNG-16*math.floor(currentRNG/16))*12, 24+12*math.floor(currentRNG/16), 32+(currentRNG-16*math.floor(currentRNG/16))*12+9, 24+12*math.floor(currentRNG/16)+10, yellow)
  216.     end
  217. end
  218.  
  219. gotSP = {}
  220. valueSP = { 0, 0, 0, 0, 0 }
  221. function gottenSP()
  222.     local comSelect = mainmemory.read_u8(0x0D1A)
  223.     for i = 1, comSelect do
  224.         gotSP[i] = mainmemory.read_u8(0x0DD7 + (i-1))
  225.         if gotSP[i] ~= 0 then
  226.             valueSP[i] = gotSP[i]
  227.         end
  228.     end
  229.  
  230.     local numParty = mainmemory.read_u8(0xF618)
  231.     if countSP ~= numParty then
  232.         if comSelect >= 0 and comSelect < numParty+1 then
  233.             for i = 1, comSelect do
  234.                 gui.pixelText(240, 172+(i-1)*8, string.format("%3d", valueSP[i]))
  235.             end
  236.         end
  237.     end
  238. end
  239.  
  240. local comparisonSP = 0
  241. function compSP(x)
  242.     gottenSP()
  243.     local numParty = mainmemory.read_u8(0xF618)
  244.     if x == 1 then
  245.         for i = 2, numParty do
  246.             if valueSP[1] < valueSP[i] then
  247.                 comparisonSP = comparisonSP + 1
  248.             end
  249.         end
  250.     elseif x ~= 1 and x ~= numParty then
  251.         for i = 1, x-1 do
  252.             if valueSP[x] <= valueSP[i] then
  253.                 comparisonSP = comparisonSP + 1
  254.             end
  255.         end
  256.         for i = x+1, numParty do
  257.             if valueSP[x] < valueSP[i] then
  258.                 comparisonSP = comparisonSP + 1
  259.             end
  260.         end
  261.     elseif x == numParty then
  262.         for i = 1, x-1 do
  263.             if valueSP[x] <= valueSP[i] then
  264.                 comparisonSP = comparisonSP + 1
  265.             end
  266.         end
  267.     end
  268. end
  269.  
  270.  
  271. function gottenSPcoerce()
  272.     local numParty = mainmemory.read_u8(0xF618)
  273.     for i = 1, numParty do
  274.         gotSP[i] = mainmemory.read_u8(0x0DD7 + (i-1))
  275.         if gotSP[i] ~= 0 then
  276.             valueSP[i] = gotSP[i]
  277.         end
  278.     end
  279. end
  280.  
  281. function SPBar(n, a)    -- n = 1, 3
  282.     local currentRNG = mainmemory.read_u8(0x0D1F)
  283.     local comSelect = mainmemory.read_u8(0x0D1A)
  284.     numParty = mainmemory.read_u8(0xF618)
  285.     if comSelect >= 0 and comSelect < numParty then
  286.         if currentRNG == 0xFF then
  287.             currentRNG = 0
  288.         end
  289.         gui.drawRectangle(128, 223-math.floor(SP[comSelect+1][currentRNG+1]/a), 2*n, math.floor(SP[comSelect+1][currentRNG+1]/a), black, SPCol[comSelect+1][currentRNG+1])
  290.         local currentRNG = mainmemory.read_u8(0x0D1F)
  291.         for i=0, 63/n do
  292.             k = (currentRNG+i+1+1) % 0x100
  293.             if k == 0 then
  294.                 k = 0x100
  295.             end
  296.             gui.drawRectangle(130+i*2*n, 223-math.floor(SP[comSelect+1][k]/a), 2*n, math.floor(SP[comSelect+1][k]/a), black, SPCol[comSelect+1][k])
  297.         end
  298.         for j=0, 63/n do
  299.             k = (currentRNG-j-1+1) % 0x100
  300.             if k == 0 then
  301.                 k = 0x100
  302.             end
  303.             gui.drawRectangle(126-j*2*n, 223-math.floor(SP[comSelect+1][k]/a), 2*n, math.floor(SP[comSelect+1][k]/a), black, SPCol[comSelect+1][k])
  304.         end
  305.         gui.drawRectangle(130, 176, n-1, 48, light_green, light_green)
  306.         local comSelect = mainmemory.read_u8(0x0D1A)
  307.         numParty = mainmemory.read_u8(0xF618)
  308.         if comSelect >= 0 and comSelect < numParty then
  309.             if currentRNG == 0xFF then
  310.                 currentRNG = 0
  311.             end
  312.         end
  313.         gui.pixelText(134,176,string.format("%2X->%2d", currentRNG, SP[comSelect+1][currentRNG+1]), light_green)
  314.     end
  315. end
  316.  
  317. SPTest = {}
  318. SPTestCol = {}
  319. function getTestAgi(x)
  320.     local agilityTest = x
  321.     for j = 0, 0xFF do
  322.         SPTest[j+1] = (agilityTest)*2 + math.mod(rng[1+(j)], ((agilityTest)*2)) + 1
  323.         if (SPTest[j+1] > math.floor( agilityTest * (7/2)) ) then
  324.             SPTestCol[j+1] = aqua
  325.         elseif (SPTest[j+1] < math.floor( agilityTest * 5/2) ) then
  326.             SPTestCol[j+1] = pink
  327.         else
  328.             SPTestCol[j+1] = white
  329.         end
  330.     end
  331. end
  332.  
  333. function dispTestSP()
  334.         for j = 0, 0xF do
  335.             for i = 0, 0xF do
  336.                 gui.pixelText(32+i*12, 26+j*12, string.format("%2d", SPTest[1+i+0x10*j]), SPTestCol[1+i+0x10*j])
  337.             end
  338.         end
  339.         local currentRNG = mainmemory.read_u8(0x0D1F)
  340.         gui.drawBox(31+(currentRNG-16*math.floor(currentRNG/16))*12, 24+12*math.floor(currentRNG/16), 32+(currentRNG-16*math.floor(currentRNG/16))*12+9, 24+12*math.floor(currentRNG/16)+10, yellow)
  341. end
  342.  
  343. function SPTestBar(n, a)    -- n = 1, 3
  344.     local currentRNG = mainmemory.read_u8(0x0D1F)
  345.     gui.drawRectangle(128, 223-math.floor(SPTest[currentRNG+1]/a), 2*n, math.floor(SPTest[currentRNG+1]/a), black, SPTestCol[currentRNG+1])
  346.     for i=0, 63/n do
  347.         k = (currentRNG+i+1+1) % 0x100
  348.         if k == 0 then
  349.             k = 0x100
  350.         end
  351.         gui.drawRectangle(130+i*2*n, 223-math.floor(SPTest[k]/a), 2*n, math.floor(SPTest[k]/a), black, SPTestCol[k])
  352.     end
  353.     for j=0, 63/n do
  354.         k = (currentRNG-j-1+1) % 0x100
  355.         if k == 0 then
  356.             k = 0x100
  357.         end
  358.         gui.drawRectangle(126-j*2*n, 223-math.floor((SPTest[k]/a)), 2*n, math.floor((SPTest[k]/a)), black, SPTestCol[k])
  359.     end
  360.     gui.drawRectangle(130, 176, n-1, 48, light_green, light_green)
  361.     gui.pixelText(134,176,string.format("%2X->%2d", currentRNG, SPTest[currentRNG+1]), light_green)
  362. end
  363.  
  364. local gameMode
  365. function gMode()
  366.     gameMode = mainmemory.read_u8(0x1AFC7)
  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] = mainmemory.read_u8(0xAA3D + 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] = mainmemory.read_u8(0xAA3D + 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] = mainmemory.read_u16_le(0xAA0E + 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] = mainmemory.read_u8(0xAA04 + 0x100*(i-1))
  460.         condB[i] = mainmemory.read_u8(0xAA05 + 0x100*(i-1))
  461.         condC[i] = mainmemory.read_u8(0xAA06 + 0x100*(i-1))
  462.     end
  463.     for j = 1, 3 do
  464.         eCond[j] = mainmemory.read_u8(0xA004 + (j-1))
  465.     end
  466. end
  467.  
  468. local expHP = {}
  469. function getExpHP()
  470.     for i = 1, 5 do
  471.         expHP[i] = mainmemory.read_u8(0xF068 + (i-1)*0x100)
  472.     end
  473. end
  474.  
  475. local item ={}
  476. function getItem()
  477.     for i=1, 32 do
  478.         item[i] = mainmemory.read_u8(0xF621 + (i-1)*2)
  479.     end
  480. end
  481.  
  482. local newItem ={}
  483. function getNewItem()
  484.     for i=1, 32 do
  485.         newItem[i] = mainmemory.read_u8(0xF621 + (i-1)*2)
  486.     end
  487. end
  488.  
  489. local numItem = {}
  490. function getNumItem()
  491.     for j = 1, 32 do
  492.         numItem[j] = mainmemory.read_u8(0xF622 + (j-1)*2)
  493.     end
  494. end
  495.  
  496. local numNewItem = {}
  497. function getNumNewItem()
  498.     for j = 1, 32 do
  499.         numNewItem[j] = mainmemory.read_u8(0xF622 + (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 = mainmemory.read_u8(0x0D22)
  513.     --for i=1, monNum do
  514.     for i=1, 6 do
  515.         eHP[i] = mainmemory.read_u16_le(0xA00E+0x100*(i-1))
  516.         eMHP[i] = mainmemory.read_u16_le(0xA010+0x100*(i-1))
  517.         eAgi[i] = mainmemory.read_u8(0xA065 + 0x100*(i-1))
  518.         eWaza[i] = mainmemory.read_u8(0xA018 + 0x100*(i-1))
  519.         monsID[i] = mainmemory.read_u16_be(0x1203 + 0x5*(i))
  520.     end
  521. end
  522.  
  523. eHP2 = {}
  524. function getEHP2()
  525.     monNum = mainmemory.read_u8(0x0D22)
  526.     for i=1, 6 do
  527.         eHP2[i] = mainmemory.read_u16_le(0xA00E+0x100*(i-1))
  528.     end
  529. end
  530.  
  531. function dispEnemyData()
  532.     monNum = mainmemory.read_u8(0x0D22)
  533.     getEnemyData()
  534.     if monNum > 6 then
  535.         monNum = 6
  536.     end
  537.     for i=1, monNum do
  538.         gui.pixelText(222, 96 + 8*(i-1), string.format("%2d", eHP[i]))
  539.         gui.pixelText(2, 96+8*(i-1), string.format("%d", eAgi[i]))
  540.         gui.pixelText(244, 96 + 8*(i-1), string.format("%2d", eWaza[i]))
  541.     end
  542. end
  543.  
  544.  
  545. function chkMons(x)
  546.     if eWaza[x] ~= 0xFF then
  547.         return true
  548.     end
  549. end
  550.  
  551. function chkMonsID(x)
  552.     if monsID[x] >= 0 and monsID[x] <= 0x133 then
  553.         return true
  554.     else
  555.         return false
  556.     end
  557. end
  558.  
  559.  
  560. function killCount()
  561.     getEnemyData()
  562.     local deathCount = 0
  563.     for i=1, monNum do
  564.         if eHP[i] == 0 then
  565.             deathCount = deathCount + 1
  566.         end
  567.     end
  568.     return deathCount
  569. end
  570.  
  571. function killCountAlly()
  572.     local numParty = mainmemory.read_u8(0xF618)
  573.     getHP()
  574.     deathCountAlly = 0
  575.     for i = 1, numParty do
  576.         if HP[i] == 0 then
  577.             deathCountAlly = deathCountAlly + 1
  578.         end
  579.     end
  580.     return deathCountAlly
  581. end
  582.  
  583. local btlOn = 1
  584. local lastStart = 0
  585. local lastEnd = 0
  586. function btlEnd()
  587.     local gameMode = mainmemory.read_u8(0x1AFC7)
  588.     local t = emu.framecount()
  589.     if btlOn ~= gameMode and gameMode ~= 1 then
  590.         lastEnd = t
  591.         btlTime = lastEnd - lastStart
  592.         print(string.format("btlEnd %d, btlTime %d", t, btlTime))
  593.     end
  594.     if btlOn ~= gameMode and gameMode ~= 0 then
  595.         lastStart = t
  596.         print(string.format("btlStart %d", t))
  597.     end
  598.     btlOn = gameMode
  599. end
  600.  
  601.  
  602. take = 0
  603. function skip(x)
  604.     while x > 0 do
  605.         emu.frameadvance()
  606.         local currentRNG = mainmemory.read_u8(0x0D1F)
  607.         gui.pixelText(4,32, string.format("take %3d", take))
  608.         gui.pixelText(12,44, string.format("RNG %2X", currentRNG))
  609.         x = x-1
  610.     end
  611. end
  612.  
  613. function skips(x)
  614.     while x > 0 do
  615.         emu.frameadvance()
  616.         x = x-1
  617.     end
  618. end
  619.  
  620. function AB(x)
  621.     while x>0 do
  622.         joypad.set({A=1}, 1)
  623.         skips(20)
  624.         joypad.set({B=1}, 1)
  625.         skips(20)
  626.         x = x-1
  627.     end
  628.     currentRNG = mainmemory.read_u8(0x0D1F)
  629.     print(string.format("RNG %X", currentRNG))
  630.     client.pause()
  631. end
  632.  
  633. function ABtil(x)
  634.     local currentRNG = mainmemory.read_u8(0x0D1F)
  635.     while currentRNG ~= x do
  636.         joypad.set({A=1}, 1)
  637.         skips(20)
  638.         joypad.set({B=1}, 1)
  639.         skips(20)
  640.         currentRNG = mainmemory.read_u8(0x0D1F)
  641.     end
  642.     print(string.format("RNG %X", currentRNG))
  643.     client.pause()
  644. end
  645.  
  646. function ABnonStop(x)
  647.     while x>0 do
  648.         joypad.set({A=1}, 1)
  649.         skips(20)
  650.         joypad.set({B=1}, 1)
  651.         skips(20)
  652.         x = x-1
  653.     end
  654. end
  655.  
  656. function btlCommand(left, right, up, down, R, A)
  657.     if left > 0 then
  658.         for i = 1, left do
  659.             joypad.set({Left=1}, 1)
  660.             skip(20)
  661.         end
  662.     end
  663.     if right > 0 then
  664.         for i = 1, right do
  665.             joypad.set({Right=1}, 1)
  666.             skip(20)
  667.         end
  668.     end
  669.     if up > 0 then
  670.         for i = 1, up do
  671.             joypad.set({Up=1}, 1)
  672.             skip(20)
  673.         end
  674.     end
  675.     if down > 0 then
  676.         for i = 1, down do
  677.             joypad.set({Down=1}, 1)
  678.             skip(20)
  679.         end
  680.     end
  681.     if R == 1 then
  682.         joypad.set({R=1}, 1)
  683.         skip(20)
  684.     end
  685.     if A == 1 then
  686.         joypad.set({A=1}, 1)
  687.     end
  688.     if A == 2 then
  689.         joypad.set({A=1}, 1)
  690.         skip(20)
  691.         joypad.set({A=1}, 1)
  692.     end
  693.     local comSelect = mainmemory.read_u8(0x0D1A)
  694.     local numParty = mainmemory.read_u8(0xF618)
  695.     if comSelect ~= numParty - 1 then
  696.         skip(60)
  697.     end
  698. end
  699.  
  700. function btlComOnlyMov(left, right, up, down)
  701.     if left > 0 then
  702.         for i = 1, left do
  703.             joypad.set({Left=1}, 1)
  704.             skip(20)
  705.         end
  706.     end
  707.     if right > 0 then
  708.         for i = 1, right do
  709.             joypad.set({Right=1}, 1)
  710.             skip(20)
  711.         end
  712.     end
  713.     if up > 0 then
  714.         for i = 1, up do
  715.             joypad.set({Up=1}, 1)
  716.             skip(20)
  717.         end
  718.     end
  719.     if down > 0 then
  720.         for i = 1, down do
  721.             joypad.set({Down=1}, 1)
  722.             skip(20)
  723.         end
  724.     end
  725.     joypad.set({A=1}, 1)
  726.     skip(20)
  727. end
  728.  
  729. function attack()
  730.     joypad.set({A=1}, 1)
  731.     skip(20)
  732.     joypad.set({A=1}, 1)
  733.     local comSelect = mainmemory.read_u8(0x0D1A)
  734.     local numParty = mainmemory.read_u8(0xF618)
  735.     if comSelect ~= numParty - 1 then
  736.         skip(60)
  737.     end
  738. end
  739.  
  740. function attackALL()
  741.     joypad.set({A=1}, 1)
  742.     local comSelect = mainmemory.read_u8(0x0D1A)
  743.     local numParty = mainmemory.read_u8(0xF618)
  744.     if comSelect ~= numParty - 1 then
  745.         skip(60)
  746.     end
  747. end
  748.  
  749. function defence()
  750.     joypad.set({R=1}, 1)
  751.     skip(20)
  752.     joypad.set({A=1}, 1)
  753.     local comSelect = mainmemory.read_u8(0x0D1A)
  754.     local numParty = mainmemory.read_u8(0xF618)
  755.     if comSelect ~= numParty - 1 then
  756.         skip(60)
  757.     end
  758. end
  759.  
  760. local numParty
  761. function dispComSelect()
  762.     local comSelect = mainmemory.read_u8(0x0D1A)
  763.     local currentRNG = mainmemory.read_u8(0x0D1F)
  764.     local numParty = mainmemory.read_u8(0xF618)
  765.  
  766.     if numParty < 6 then
  767.         if comSelect >=0 and comSelect <  numParty then
  768.             gui.pixelText(228, 164, string.format("%2X->%2d", currentRNG, SP[comSelect+1][currentRNG+1]), SPCol[comSelect+1][currentRNG+1])
  769.         end
  770.     end
  771. end
  772.  
  773. local Xpos
  774. local Ypos
  775. function playerPos()
  776.     Xpos = mainmemory.read_u8(0x1342)
  777.     Ypos = mainmemory.read_u8(0x13D6)
  778.     gui.pixelText(228, 4, string.format("(%X,%X)", Xpos, Ypos))
  779. end
  780.  
  781.  
  782. function dispChiretsugeki()
  783.     local chiretsugeki = mainmemory.read_u8(0x0D80)
  784.     gui.pixelText(228, 140, string.format("chi %d", chiretsugeki))
  785. end
  786.  
  787. function dispCurrentRNG()
  788.     local currentRNG = mainmemory.read_u8(0x0D1F)
  789.     gui.pixelText(228, 148, string.format("%2X->%2X", currentRNG, rng[currentRNG+1]), yellow)
  790.     local preRNG = (currentRNG-1) % 0x100
  791.     gui.pixelText(228, 156, string.format("%2X->%2X", preRNG, rng[preRNG+1]), gray)
  792. end
  793.  
  794. local take = 0
  795. function encParty(direction)
  796.  
  797.     function skip(x)
  798.         while x > 0 do
  799.             emu.frameadvance()
  800.             local currentRNG = mainmemory.read_u8(0x0D1F)
  801.             gui.pixelText(4,32, string.format("take %3d", take))
  802.             gui.pixelText(12,44, string.format("RNG %2X", currentRNG))
  803.             x = x-1
  804.         end
  805.     end
  806.  
  807.     print("Script start ! ")
  808.  
  809.     label = string.format("tBtl\ttake\tinitial RNG\tmonNum\teHP[1]\teHP[2]\teHP[3]\teHP[4]\teHP[5]\teHP[6]\tfinal RNG")
  810.     print(label)
  811.     --emu.speedmode("turbo") -- snes9x only
  812.  
  813.     savestate.save(1)
  814.     savestate.load(1)
  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 = mainmemory.read_u8(0x0D1F)
  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 = mainmemory.read_u8(0x0D1F)
  844.         local tBtl = mainmemory.read_u8(0xF8AE)
  845.         local monNum = mainmemory.read_u8(0x0D22)
  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(1)
  855.         emu.frameadvance()
  856.         savestate.save(1)
  857.     end
  858.     gui.text(74, 42, "Done !")
  859.     print("Done !")
  860.     client.pause()
  861. end
  862.  
  863. function chk7HeroForm()
  864.     heroForm = mainmemory.read_u8(0x0D64)
  865.     if heroForm == 2 then
  866.         printHero = "Bokuoon"
  867.     elseif heroForm == 3 then
  868.         printHero = "Kujinshii"
  869.     elseif heroForm == 4 then
  870.         printHero = "Wagnus"
  871.     elseif heroForm == 5 then
  872.         printHero = "Dantaagu"
  873.     else
  874.         printHero = "Others"
  875.     end
  876. end
  877.  
  878.  
  879. function btlSim()
  880.     local take = 0
  881.  
  882.     function skip(x)
  883.         while x > 0 do
  884.             emu.frameadvance()
  885.             local currentRNG = mainmemory.read_u8(0x0D1F)
  886.             gui.pixelText(4,32, string.format("take %3d", take))
  887.             gui.pixelText(12,44, string.format("RNG %2X", currentRNG))
  888.             x = x-1
  889.         end
  890.     end
  891.  
  892.     print("Script start ! ")
  893.  
  894.     local comSelect = mainmemory.read_u8(0x0D1A)
  895.     local numParty = mainmemory.read_u8(0xF618)
  896.     getEHP2()
  897.     getEnemyData()
  898.     preEHP = eHP[1]
  899.  
  900.     if comSelect == 0 or comSelect == 59 then
  901.         print("A zurashi")
  902.     elseif comSelect == numParty - 1 then
  903.         print("ABC")
  904.     end
  905.  
  906.     print(action)
  907.     print(label)
  908.     --emu.speedmode("turbo")    -- snes9x only
  909.     --rngDisp()
  910.     savestate.save(1)
  911.     savestate.load(1)
  912.  
  913.     while take < 0x102 do
  914.         emu.frameadvance()
  915.         local currentRNG = mainmemory.read_u8(0x0D1F)
  916.         local initialFr = emu.framecount()
  917.         local comSelect = mainmemory.read_u8(0x0D1A)
  918.  
  919.         if comSelect == 0 or comSelect == 59 then
  920. --~         if comSelect == 0 or comSelect == 59 or comSelect == 5 then --Kujinshii2
  921.             joypad.set({A=1}, 1)
  922.             skip(100)
  923.  
  924.             --1
  925.             btlCommand(0, 1, 0, 0, 0, 2)
  926. --~             attack()
  927. --~             btlComOnlyMov(0, 1, 0, 1)
  928. --~             attackALL()
  929.             --2
  930.             btlCommand(0, 1, 0, 0, 0, 2)
  931. --~             defence()
  932.             --3
  933. --~             defence()
  934.             btlCommand(0, 1, 0, 0, 0, 2)
  935. --~             attack()
  936.             --4
  937.             btlCommand(0, 1, 0, 0, 0, 2)
  938. --~             defence()
  939.         end
  940.         --5
  941. --~         btlCommand(0, 1, 0, 0, 0, 2)
  942. --~         defence()
  943.         attack()
  944.  
  945.         getWaza()
  946.         getItem()
  947.         getNumItem()
  948.  
  949.         for i = 1, 30 do
  950.             getAgi()
  951.             gottenSP()
  952.             getHP()
  953.             emu.frameadvance()
  954.         end
  955.  
  956.         local startHP = {}
  957.         for i = 1, 5 do
  958.             startHP[i] = HP[i]
  959.         end
  960.  
  961.         local comparisonSP = 0
  962.  
  963.         compSP(1)
  964.  
  965.         local numParty = mainmemory.read_u8(0xF618)
  966.         local comSelect = numParty
  967.  
  968.         local chiretsugeki = mainmemory.read_u8(0x0D80)
  969.  
  970.         local gameMode = mainmemory.read_u8(0x1AFC7)
  971.         local chkHP = 0
  972.         local chkHP1 = 0
  973.         local chkHP3 = 0
  974.  
  975.         local dC = 0
  976.         local reverse = 0
  977.         local chkEHP = 0
  978. --~         while (chiretsugeki > 99 or chiretsugeki == 0) and (gameMode == 1 and comSelect == numParty) do
  979. --~         while (chiretsugeki > 99 or chiretsugeki == 0) and (gameMode == 1 and comSelect == numParty) and chkHP == 0 do
  980. --~         while gameMode == 1 and HP[1] > 0 do
  981.         while gameMode == 1 and comSelect == numParty do
  982. --~         while gameMode == 1 and comSelect == numParty and valueSP[5] > 52 do
  983.  
  984.             gui.pixelText(4,32, string.format("take %3d", take))
  985.             gui.pixelText(12,44, string.format("RNG %2X", currentRNG))
  986.  
  987.             emu.frameadvance()
  988.             joypad.set({A=1}, 1)
  989.             gui.pixelText(4,32, string.format("take %3d", take))
  990.             gui.pixelText(12,44, string.format("RNG %2X", currentRNG))
  991.  
  992.             emu.frameadvance()
  993.             comSelect = mainmemory.read_u8(0x0D1A)
  994.             gameMode = mainmemory.read_u8(0x1AFC7)
  995.  
  996.             chiretsugeki = mainmemory.read_u8(0x0D80)
  997.  
  998.             getHP()
  999.             for i = 1, numParty do
  1000.                 if startHP[i] > HP[i] then
  1001.                     chkHP = chkHP + 1
  1002.                 end
  1003.             end
  1004.             if startHP[1] > HP[1] then
  1005.                 chkHP1 = chkHP1 + 1
  1006.             end
  1007.             if startHP[3] > HP[3] then
  1008.                 chkHP3 = chkHP3 + 1
  1009.             end
  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.         end
  1019.  
  1020.         local t = emu.framecount()
  1021.         local time = t - initialFr
  1022.  
  1023.         getEnemyData()
  1024.  
  1025.         getNewWaza()
  1026.         getNewItem()
  1027.         getNumNewItem()
  1028.         getHP()
  1029.         getAgi()
  1030.         getCondition()
  1031.  
  1032.         chk7HeroForm()
  1033.  
  1034.         local printWaza = {}
  1035.         local wazaCount = 0
  1036.         for i = 1, 5 do
  1037.             printWaza[i] = 0xFF
  1038.             for j = 1, 8 do
  1039.                 if newWaza[i][j] ~= waza[i][j] then
  1040.                     printWaza[i] = newWaza[i][j]
  1041.                     wazaCount = wazaCount + 1
  1042. --~                     break
  1043.                 end
  1044.             end
  1045.         end
  1046.  
  1047.         local printItem = 0xFF
  1048.         local itemCount = 0
  1049.         for i = 1, 32 do
  1050.             if newItem[i] ~= item[i] then
  1051.                 printItem = newItem[i]
  1052.                 itemCount = itemCount + 1
  1053.             end
  1054.         end
  1055.  
  1056.         local printNumItem = 0
  1057.         local itemNumCount = 0
  1058.         for i = 1, 32 do
  1059.             if numNewItem[i] ~= numItem[i] then
  1060.                 printNumItem = newItem[i]
  1061.                 itemNumCount = itemNumCount + 1
  1062.             end
  1063.         end
  1064.  
  1065.         damage = {}
  1066.         for i = 1, monNum do
  1067.             damage[i] = eHP2[i]-eHP[i]
  1068.         end
  1069.  
  1070.         local chiretsugeki = mainmemory.read_u8(0x0D80)
  1071.  
  1072.         local deathCount = killCount()
  1073.         local endRNG = mainmemory.read_u8(0x0D1F)
  1074.  
  1075.         local muddleCount = 0
  1076.         for i = 1, numParty do
  1077.             if condA[i] == 0x01 then
  1078.                 muddleCount = muddleCount + 1
  1079.             end
  1080.         end
  1081.  
  1082.         dC = killCountAlly()
  1083.  
  1084.         local MeiRyoku = mainmemory.read_u8(0xA064)
  1085.  
  1086.         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)
  1087.  
  1088. --~         if dC == 0 and MeiRyoku == 9 then
  1089. --~         if (wazaCount ~= 0 or dC < 2) and wazaCount ~= 40 then
  1090. --~         if chkEHP == 2 and dC == 0 and eHP[1] < 3000 then
  1091.             print(result)
  1092. --~         end
  1093.  
  1094.         take = take + 1
  1095.         savestate.load(1)
  1096.  
  1097.         local comSelect = mainmemory.read_u8(0x0D1A)
  1098.         local numParty = mainmemory.read_u8(0xF618)
  1099.         getEnemyData()
  1100.         preEHP = eHP[1]
  1101.         local reverse = 0
  1102.  
  1103.         if comSelect == numParty - 1 then
  1104.             emu.frameadvance()
  1105.             ABnonStop(1)
  1106.         end
  1107.  
  1108.         emu.frameadvance()
  1109.         savestate.save(1)
  1110.     end
  1111.     gui.text(74,42, "Done !")
  1112.     print("Done !")
  1113.     client.pause()
  1114. end
  1115.  
  1116.  
  1117. function btlStart(n)
  1118.     take = 1
  1119.     print("Script start ! ")
  1120.     --emu.speedmode("turbo")    -- only snes9x
  1121.     local currentRNG = mainmemory.read_u8(0x0D1F)
  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.     gui.text(74, 42, "Done !")
  1144.     print("Done !")
  1145.     client.pause()
  1146. end
  1147.  
  1148. function btlSim2(a, b, c, d, e)
  1149.  
  1150.     function skip(x)
  1151.         while x > 0 do
  1152.             emu.frameadvance()
  1153.             local currentRNG = mainmemory.read_u8(0x0D1F)
  1154.             gui.pixelText(4,32, string.format("take %3d/%d  (%d, %d, %d, %d, %d)", take, totalTake, a, b, c, d, e))
  1155.             gui.pixelText(12,44, string.format("RNG %2X", currentRNG))
  1156.             x = x-1
  1157.         end
  1158.     end
  1159.  
  1160.     local comSelect = mainmemory.read_u8(0x0D1A)
  1161.     local numParty = mainmemory.read_u8(0xF618)
  1162.     getEHP2()
  1163.     getEnemyData()
  1164.     preEHP = eHP[1]
  1165.  
  1166.     --rngDisp()
  1167.  
  1168.     savestate.save(1)
  1169.     savestate.load(1)
  1170.  
  1171.     emu.frameadvance()
  1172.     local initialFr = emu.framecount()
  1173.     local comSelect = mainmemory.read_u8(0x0D1A)
  1174.  
  1175.     --1
  1176.     local firstRNG = mainmemory.read_u8(0x0D1F)
  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, 1, 0, 2)
  1186.     attack()
  1187. --~ btlComOnlyMov(0, 1, 0, 0)
  1188. --~ defence()
  1189.     --3
  1190.     ABnonStop(c)
  1191. --~ btlCommand(0, 1, 0, 0, 0, 2)
  1192. --~ btlComOnlyMov(0, 1, 0, 0)
  1193. --~ defence()
  1194.     attack()
  1195.     --4
  1196.     ABnonStop(d)
  1197. --~ btlCommand(0, 2, 1, 0, 0, 2)
  1198.     attack()
  1199. --~ defence()
  1200.     --5
  1201.     ABnonStop(e)
  1202.     local currentRNG = mainmemory.read_u8(0x0D1F)
  1203. --~ btlCommand(0, 2, 0, 1, 0, 2)
  1204. --~ defence()
  1205.     attack()
  1206.  
  1207.     getWaza()
  1208.     getItem()
  1209.     getNumItem()
  1210.     for i = 1, 30 do
  1211.         getAgi()
  1212.         gottenSP()
  1213.         getHP()
  1214.         emu.frameadvance()
  1215.     end
  1216.  
  1217.     local startHP = {}
  1218.     for i = 1, 5 do
  1219.         startHP[i] = HP[i]
  1220.     end
  1221.  
  1222.     local comparisonSP = 0
  1223.  
  1224.     compSP(1)
  1225.  
  1226.     local numParty = mainmemory.read_u8(0xF618)
  1227.     local comSelect = numParty
  1228.  
  1229.     local chiretsugeki = mainmemory.read_u8(0x0D80)
  1230.  
  1231.     local gameMode = mainmemory.read_u8(0x1AFC7)
  1232.     local chkHP = 0
  1233.     local chkHP1 = 0
  1234.     local chkHP3 = 0
  1235.     local dC = 0
  1236.     local reverse = 0
  1237.     local chkEHP = 0
  1238.  
  1239.     while gameMode == 1 and comSelect == numParty do
  1240. --~ while gameMode == 1 and comSelect ~= 0 do
  1241. --~ while gameMode == 1 and comSelect == numParty and dC < 2 and reverse == 0 do
  1242. --~     while gameMode == 1 and comSelect == numParty and dC < 2 do
  1243.         gui.pixelText(4,32, string.format("take %3d/%d  (%d, %d, %d, %d, %d)", take, totalTake, a, b, c, d, e))
  1244.         gui.pixelText(12,44, string.format("RNG %2X/%2X", firstRNG, currentRNG))
  1245.  
  1246.         emu.frameadvance()
  1247.  
  1248.         gui.pixelText(4,32, string.format("take %3d/%d  (%d, %d, %d, %d, %d)", take, totalTake, a, b, c, d, e))
  1249.         gui.pixelText(12,44, string.format("RNG %2X/%2X", firstRNG, currentRNG))
  1250.         joypad.set({A=1}, 1)
  1251.         emu.frameadvance()
  1252.         comSelect = mainmemory.read_u8(0x0D1A)
  1253.         gameMode = mainmemory.read_u8(0x1AFC7)
  1254.         getHP()
  1255. --~         for i = 1, numParty do
  1256. --~             if startHP[i] > HP[i] then
  1257. --~                 chkHP = chkHP + 1
  1258. --~             end
  1259. --~         end
  1260.  
  1261.         if startHP[1] > HP[1] then
  1262.             chkHP1 = chkHP1 + 1
  1263.         end
  1264.         if startHP[3] > HP[3] then
  1265.             chkHP3 = chkHP3 + 1
  1266.         end
  1267.         dC = killCountAlly()
  1268.         getEnemyData()
  1269.         if preEHP < eHP[1] then
  1270.             reverse = reverse + 1
  1271.         end
  1272.         if preEHP < 6000 and eHP[1] == 6000 then
  1273.             chkEHP = chkEHP + 1
  1274.         end
  1275.         preEHP = eHP[1]
  1276.     end
  1277.  
  1278.     local t = emu.framecount()
  1279.     local time = t - initialFr
  1280.  
  1281.     getEnemyData()
  1282.  
  1283.     getNewWaza()
  1284.     getNewItem()
  1285.     getNumNewItem()
  1286.     getHP()
  1287.     getAgi()
  1288.     getCondition()
  1289.  
  1290.     chk7HeroForm()
  1291.  
  1292.     local printWaza = {}
  1293.     local wazaCount = 0
  1294.     for i = 1, 5 do
  1295.         printWaza[i] = 0xFF
  1296.         for j = 1, 8 do
  1297.             if newWaza[i][j] ~= waza[i][j] then
  1298.                 printWaza[i] = newWaza[i][j]
  1299.                 wazaCount = wazaCount + 1
  1300. --~                 break
  1301.             end
  1302.         end
  1303.     end
  1304.  
  1305.     local printItem = 0xFF
  1306.     local itemCount = 0
  1307.     for i = 1, 32 do
  1308.         if newItem[i] ~= item[i] then
  1309.             printItem = newItem[i]
  1310.             itemCount = itemCount + 1
  1311.         end
  1312.     end
  1313.  
  1314.     local printNumItem = 0
  1315.     local itemNumCount = 0
  1316.     for i = 1, 32 do
  1317.         if numNewItem[i] ~= numItem[i] then
  1318.             printNumItem = newItem[i]
  1319.             itemNumCount = itemNumCount + 1
  1320.         end
  1321.     end
  1322.  
  1323.     damage = {}
  1324.     for i = 1, monNum do
  1325.         damage[i] = eHP2[i]-eHP[i]
  1326.     end
  1327.  
  1328.     local chiretsugeki = mainmemory.read_u8(0x0D80)
  1329.  
  1330.     local deathCount = killCount()
  1331.     local endRNG = mainmemory.read_u8(0x0D1F)
  1332.  
  1333.     local muddleCount = 0
  1334.     for i = 1, numParty do
  1335.         if condA[i] == 0x01 then
  1336.             muddleCount = muddleCount + 1
  1337.         end
  1338.     end
  1339.  
  1340.     dC = killCountAlly()
  1341.  
  1342.     local MeiRyoku = mainmemory.read_u8(0xA064)
  1343.  
  1344.     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)
  1345.  
  1346. --~ if (wazaCount ~= 0 or dC < 2) and wazaCount ~= 40 then
  1347. --~     if ((wazaCount ~= 0 or dC < 2) and wazaCount ~= 40) or killCount == 1 then
  1348.         print(result)
  1349. --~     end
  1350.  
  1351.     take = take + 1
  1352.     savestate.load(1)
  1353.  
  1354.     local comSelect = mainmemory.read_u8(0x0D1A)
  1355.     local numParty = mainmemory.read_u8(0xF618)
  1356.     getEnemyData()
  1357.     preEHP = eHP[1]
  1358.     local reverse = 0
  1359.  
  1360.     if comSelect == numParty - 1 then
  1361.         emu.frameadvance()
  1362.         ABnonStop(1)
  1363.     end
  1364.  
  1365.     emu.frameadvance()
  1366.     savestate.save(1)
  1367. end
  1368.  
  1369. function chkInitialHP()
  1370.     local take = 0
  1371.     print("Script start !")
  1372.     print("take\tLeon\tGerard\tBear\tJames\tTherese")
  1373.     local HP = {}
  1374.     local function getInitialHP()
  1375.         for i = 1, 5 do
  1376.             HP[i] = mainmemory.read_u16_le(0xF010 + 0x100*(i-1))
  1377.         end
  1378.     end
  1379.  
  1380.     --emu.speedmode("turbo") -- snes9x only
  1381.  
  1382.     savestate.save(1)
  1383.     savestate.load(1)
  1384.  
  1385.     while take < 0x102 do
  1386.         gui.pixelText(4, 32, string.format("take %3d", take))
  1387.         joypad.set({Start=1}, 1)
  1388.         emu.frameadvance()
  1389.         getInitialHP()
  1390.  
  1391.         while HP[5] == 0 do
  1392.             emu.frameadvance()
  1393.             gui.pixelText(4, 32, string.format("take %3d", take))
  1394.             getInitialHP()
  1395.         end
  1396.  
  1397. --~     if HP[3] > 79 then
  1398.             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]))
  1399. --~             client.pause()
  1400. --~     end
  1401.  
  1402.         take = take + 1
  1403.         savestate.load(1)
  1404.         emu.frameadvance()
  1405.         savestate.save(1)
  1406.     end
  1407.     print("Done !")
  1408.     client.pause()
  1409. end
  1410.  
  1411. function makeSaves(x, y)
  1412.     t = emu.framecount()
  1413.     for i = 0, 9 do
  1414.         if t == x + y*i then
  1415.             savestate.saveslot(i)
  1416.             print("Saved at "..t.."f.")
  1417.         end
  1418.     end
  1419.     if t >= x + y*9 then
  1420.         emu.frameadvance()
  1421.         pause(x + y*9)
  1422.     end
  1423. end
  1424.  
  1425. local t
  1426. function Fr()
  1427.     local t = emu.framecount()
  1428.     local color = white
  1429.     if emu.islagged() == true then
  1430.         color = red
  1431.     end
  1432.     gui.text(0, 14, "" ..t, color)
  1433. end
  1434.  
  1435. local lag
  1436. function LagCount()
  1437.     local t = emu.lagcount()
  1438.     gui.text(0, 42, "" ..t, red)
  1439. end
  1440.  
  1441. local suubieHP
  1442. function suubie()
  1443.     getEnemyData()
  1444.     suubieHP = string.format("%5d/%5d", eHP[1], eMHP[1])
  1445.     local gameMode = mainmemory.read_u8(0x1AFC7)
  1446.     if gameMode == 1 then
  1447.         gui.drawText(30, 180, suubieHP)
  1448.     end
  1449. end
  1450.  
  1451. function pause(x)
  1452.     local t = emu.framecount()
  1453.     if t >= x then
  1454.         print("Paused at "..t.."f.")
  1455.         client.pause()
  1456.     end
  1457. end
  1458.  
  1459. defP = {}
  1460. function getDefP()
  1461.     for i = 1, 5 do
  1462.         defP[i] = {}
  1463.             for j = 1, 8 do
  1464.                 defP[i][j] = mainmemory.read_u8(0xF055 + 0x100*(i-1) + j-1) -- joined order
  1465. --~                 defP[i][j] = mainmemory.read_u8(0xAA55 + 0x100*(i-1) + j-1) -- order in battles
  1466.             end
  1467.     end
  1468. end
  1469.  
  1470. function dispDefP()
  1471.     local x = 58
  1472.     local y = 60
  1473.     local gap = 10
  1474.     gui.pixelText(x, y, "sword")
  1475.     gui.pixelText(x, y+gap, "axe")
  1476.     gui.pixelText(x, y+gap*2, "spear")
  1477.     gui.pixelText(x, y+gap*3, "arrow")
  1478.     gui.pixelText(x, y+gap*4, "heat")
  1479.     gui.pixelText(x, y+gap*5, "cold")
  1480.     gui.pixelText(x, y+gap*6, "elec")
  1481.     gui.pixelText(x, y+gap*7, "spirit")
  1482.     getDefP()
  1483.     for i = 1, 5 do
  1484.         for j = 1, 8 do
  1485.             gui.pixelText(x+20+24*i, y+gap*(j-1), defP[i][j])
  1486.         end
  1487.     end
  1488. end
  1489.  
  1490. while true do
  1491.     --[[ --for encoding
  1492.     gui.drawRectangle(0,0,256,224,black,black)
  1493.     Fr()
  1494.     LagCount()
  1495.     ]]
  1496.  
  1497. --~     gui.drawRectangle(0,0,256,224,black,black)  -- for encoding
  1498.  
  1499. --~     pause(255551) -- movie end
  1500.     pause(310000)   -- end screen
  1501. --~     pause(260000)   -- around defeating 7 heroes
  1502. --~     pause(125000)   -- for error of luascripting
  1503.  
  1504. --~     makeSaves(210000, 10000)
  1505.  
  1506. --~     dispDefP()
  1507.  
  1508.     playerPos()
  1509. --~     msg()
  1510.     btlEnd()
  1511.  
  1512.     getParameter()
  1513.     dispParameter()
  1514.  
  1515.     --dispChiretsugeki()
  1516.     dispCurrentRNG()
  1517.  
  1518. --~     getBtlParameter()
  1519. --~     getBtlParameter2()
  1520.     selAdd()
  1521.     dispBtlParameter()
  1522.  
  1523. --~     getTestAgi(15)
  1524. --~     dispTestSP()
  1525. --~     SPTestBar(1, 4)
  1526.  
  1527. --~     rngMOD(18)
  1528. --~     rngDispMod()
  1529.  
  1530. --~     AB(240)
  1531. --~     ABtil(0xB1)
  1532.  
  1533.     --encParty("down")
  1534.  
  1535.     action = "chiretsugeki\tchiretsugeki\tchiretsugeki\tchiretsugeki\tchiretsugeki"
  1536.     label = "take\tinitial RNG\tinitial Fr\t7HeroForm\tchkEHP\teHP[1]\tdeathCount\tHP[1]\tHP[2]\tHP[3]\tHP[4]\tHP[5]\tSP[1]\tSP[2]\tSP[3]\tSP[4]\tSP[5]\twC\tWaza[1]\tWaza[2]\tWaza[3]\tWaza[4]\tWaza[5]\tCond[1]\tCond[2]\tCond[3]\tCond[4]\tCond[5]\teCond\tfinal RNG\tFr\tTime\tdamage\thast drop\tnew drop"
  1537.  
  1538. --~     btlSim()
  1539. --~     suubie()
  1540.  
  1541.     label2 = "take\tRNG[1]\ta\tb\tc\td\te\tRNG[5]\tinitial Fr\t7HeroForm\tchkEHP\teHP[1]\tdeathCount\tHP[1]\tHP[2]\tHP[3]\tHP[4]\tHP[5]\tSP[1]\tSP[2]\tSP[3]\tSP[4]\tSP[5]\twC\tWaza[1]\tWaza[2]\tWaza[3]\tWaza[4]\tWaza[5]\tCond[1]\tCond[2]\tCond[3]\tCond[4]\tCond[5]\teCond\tfinal RNG\tFr\tTime\tdamage\thast drop\tnew drop"
  1542.  
  1543.     -- 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)
  1544. --~     btlStart(0xB7)
  1545.  
  1546. --~     chkInitialHP()
  1547.  
  1548.     emu.frameadvance();
  1549. end
  1550.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement