Advertisement
Guest User

Untitled

a guest
May 21st, 2021
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.63 KB | None | 0 0
  1. -- This Lua Script is for Romancing SaGa 2 on lsnes.
  2.  
  3. -- 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)
  4.  
  5. --[[    -- I don't know how to translate below six lines.
  6. --memory.usememorydomain("CARTROM") -- BizHawk
  7. --~     rng = {}
  8. --~ for i = 0, 0xFF do
  9. --~     rng[i+1] = memory.readbyte(0xC2EF04+i)  --rng[i] = i-1 (rng[0] = 1, ... , rng[256] = 255)
  10.     -- 0x02EF04-0x02F003
  11. --~ end
  12. ]]  -- instead the above,
  13. rng = {234, 101,    90, 123,    244,    71, 14, 170,    71, 159,    57, 155,    90, 227,    177,    132,    141,    238,    114,    128,    84, 52, 51, 24, 121,    169,    210,    228,    35, 25, 34, 97, 9,  215,    93, 202,    3,  40, 220,    43, 94, 179,    201,    232,    39, 102,    102,    248,    80, 158,    48, 13, 100,    242,    235,    220,    46, 132,    231,    103,    7,  35, 122,    191,    174,    48, 147,    206,    96, 142,    226,    152,    145,    12, 97, 236,    252,    137,    209,    20, 115,    216,    245,    222,    144,    145,    147,    43, 77, 80, 10, 68, 142,    40, 10, 45, 166,    182,    185,    191,    241,    30, 209,    51, 246,    96, 0,  229,    59, 208,    152,    12, 182,    37, 102,    28, 20, 210,    34, 17, 34, 66, 223,    104,    46, 137,    124,    236,    168,    176,    88, 177,    200,    184,    104,    86, 17, 228,    113,    111,    236,    124,    108,    52, 72, 133,    239,    70, 85, 181,    155,    182,    228,    141,    90, 156,    8,  229,    9,  223,    215,    223,    68, 148,    33, 122,    240,    248,    205,    74, 204,    127,    74, 8,  11, 249,    192,    122,    78, 60, 102,    244,    144,    226,    58, 96, 56, 6,  105,    150,    115,    3,  67, 1,  30, 52, 226,    188,    193,    174,    135,    188,    246,    106,    182,    43, 188,    231,    165,    254,    135,    183,    134,    134,    157,    118,    177,    100,    130,    165,    204,    49, 10, 110,    101,    205,    83, 56, 163,    147,    188,    39, 131,    227,    31, 94, 193,    89, 215,    37, 103,    137,    238,    205,    32, 30, 106,    238,    71, 191,    143,    88, 86, 135,    41, 86,}
  14.  
  15. --memory.usememorydomain("WRAM")    -- BizHawk
  16.  
  17. sel = 0
  18. valueSP = {}
  19. ipg0 = 0
  20. ipg1 = 0
  21. msg1 = 0
  22. msg0 = 0
  23. btlOn = 1
  24. lastStart = 0
  25. lastEnd = 0
  26.  
  27. on_paint = function()
  28.     gui.right_gap(600);
  29.  
  30.     -- for supporting scrolling text messages and inputting battle commands. If you'd like to use it, uncomment below five lines, please.
  31. --~     msg1 = memory.readbyte(0x7E1F01)
  32. --~     if msg1 ==  0 and msg0 ~= 0 then
  33. --~         print("msg ", movie.framecount())
  34. --~     end
  35. --~     msg0 = msg1
  36.  
  37.     local Xpos
  38.     local Ypos
  39.     Xpos = memory.readbyte(0x7E1342)
  40.     Ypos = memory.readbyte(0x7E13D6)
  41.     gui.text(970, 0, string.format("(%X,%X)", Xpos, Ypos))
  42.  
  43.     local EP
  44.     local totalBattle
  45.     local battle
  46.     local safe
  47.     local safe2 = {}
  48.     local Hiraga
  49.     EP = memory.readbyte(0x7EF693)
  50.     totalBattle = memory.readword(0x7EF8AE)
  51.     battle = memory.readbyte(0x7EF694)
  52.     safe = memory.readbyte(0x7EF7A2) + 0x100 * memory.readbyte(0x7EF7A3) + 0x10000 * memory.readbyte(0x7EF7A4)
  53.     safe2[1] = math.floor(safe/1000000)
  54.     safe2[2] = math.floor((safe-(safe2[1]*1000000))/1000)
  55.     safe2[3] = safe - (safe2[1]*1000000)-(safe2[2]*1000)
  56.     Hiraga = memory.readbyte(0x7EF697)
  57.  
  58.     if safe2[1] ~= 0 then
  59.         gui.text(970, 12, string.format("%3d,%03d,%03d", safe2[1], safe2[2], safe2[3]))
  60.     elseif safe2[2] ~= 0 then
  61.         gui.text(970, 12, string.format("%3d,%03d", safe2[2], safe2[3]))
  62.     else
  63.         gui.text(970, 12, string.format("%3d", safe2[3]))
  64.     end
  65.     gui.text(970, 24, string.format("EP %d", EP))
  66.     gui.text(970, 36, string.format("%d/%d", battle, totalBattle))
  67.     gui.text(970, 48, string.format("%dsei", Hiraga))
  68.     local jump
  69.     local battle16 = battle % 0x10
  70.  
  71.     if EP >= battle16 then
  72.         if battle < 0x30 then
  73.             jump = battle16 + 0x30
  74.         else
  75.             jump = battle
  76.         end
  77. --~         gui.text(512, 50, string.format("jump%d", jump))
  78. --~         gui.text(512, 62, string.format("tBtl%d->%d", totalBattle, totalBattle + math.floor(jump/4)))
  79. --~         gui.text(512, 74, string.format("%dsei->%dsei", Hiraga, Hiraga + math.floor((jump/0x20) + (1/2))))
  80.     end
  81.  
  82.     local gameMode
  83.     gameMode = memory.readbyte(0x7FAFC7)
  84. --~     gui.text(512, 0, sel)
  85.     selectKey = memory.readbyte(0x7E0D12)
  86.     if  gameMode == 1 and selectKey == 0x20 then
  87.         ipg1 = 1
  88.     else
  89.         ipg1 = 0
  90.     end
  91.     if gameMode == 1 and ipg1 == 1 and ipg0 == 0 then
  92.         sel = sel + 1
  93.     end
  94.     ipg0 = ipg1
  95.  
  96.     local comSelect = memory.readbyte(0x7E0D1A)
  97.     local numParty = memory.readbyte(0x7EF618)
  98.     if comSelect < 0 or comSelect >= numParty then
  99.         for j = 0, 0xF do
  100.             for i = 0, 0xF do
  101.                 gui.text(545+i*26, 28, string.format("%2X", i))
  102.                 gui.text(545+i*26, 50+j*20, string.format("%2X", rng[1+i+0x10*j]))
  103.                 gui.text(520, 50+j*20, string.format("%2X", 0x10*j))
  104.             end
  105.         end
  106.     end
  107.     local currentRNG = memory.readbyte(0x7E0D1F)
  108.     gui.rectangle(545-2+(currentRNG-16*math.floor(currentRNG/16))*26, 50+20*math.floor(currentRNG/16), 26, 20)
  109.  
  110.     local EV = memory.readbyte(0x7E0D80)
  111.     gui.text(970, 329, string.format("EV %d", EV))
  112.  
  113.     local currentRNG = memory.readbyte(0x7E0D1F)
  114.     gui.text(970, 341, string.format("RNG %2X->%2X", currentRNG, rng[currentRNG+1]))
  115.     local preRNG = (currentRNG-1) % 0x100
  116.     gui.text(970, 353, string.format("    %2X->%2X", preRNG, rng[preRNG+1]))
  117.  
  118.     defP = {}
  119.     for i = 1, 5 do
  120.         defP[i] = {}
  121.             for j = 1, 8 do
  122. --~                 defP[i][j] = memory.readbyte(0x7EF055 + 0x100*(i-1) + j-1)  -- joined order
  123.                 defP[i][j] = memory.readbyte(0x7EAA55 + 0x100*(i-1) + j-1)  -- order in battles
  124.             end
  125.     end
  126.  
  127.     local x = 965
  128.     local y = 90
  129.     local gap = 12
  130.     gui.text(x, y, "srd")
  131.     gui.text(x, y+gap, "axe")
  132.     gui.text(x, y+gap*2, "spr")
  133.     gui.text(x, y+gap*3, "arw")
  134.     gui.text(x, y+gap*4, "heat")
  135.     gui.text(x, y+gap*5, "cold")
  136.     gui.text(x, y+gap*6, "elec")
  137.     gui.text(x, y+gap*7, "sprt")
  138.  
  139.     for i = 1, 5 do
  140.         for j = 1, 8 do
  141.             gui.text(x+12+24*i, y+gap*(j-1), defP[i][j])
  142.         end
  143.     end
  144.  
  145.     agility = {}
  146.     SP = {}
  147.     SPCol = {}
  148.     HP = {}
  149.     nonbtlHP = {}
  150.     for i = 1, 5 do
  151.         agility[i] = memory.readbyte(0x7EAA65+0x0100*(i-1))
  152.         HP[i] = memory.readword(0x7EAA0E + 0x100*(i-1))
  153.         nonbtlHP[i] = memory.readword(0x7EF010 + 0x100*(i-1))
  154.     end
  155.  
  156.     -- for checking the first characters' HP, especially Bear(3rd). If you'd like to use it, uncomment below three lines, please.
  157. --~     for i = 1, 5 do
  158. --~         gui.text(1080, 0+12*(i-1), HP[i])
  159. --~     end
  160.  
  161.     eHP = {}
  162.     eMHP = {}
  163.     eAgi = {}
  164.     eEXP = {}
  165.     eWaza={}
  166.     monsID = {}
  167.     local monNum
  168.     monNum = memory.readbyte(0x7E0D22)
  169.     --for i=1, monNum do
  170.     for i=1, 6 do
  171.         eHP[i] = memory.readword(0x7EA00E+0x100*(i-1))
  172.         eMHP[i] = memory.readbyte(0x7EA010+0x100*(i-1))
  173.         eAgi[i] = memory.readbyte(0x7EA065 + 0x100*(i-1))
  174.         eWaza[i] = memory.readbyte(0x7EA018 + 0x100*(i-1))
  175.         monsID[i] = memory.readword(0x7E1203 + 0x5*(i))
  176.     end
  177.  
  178.     if monNum > 6 then
  179.         monNum = 6
  180.     end
  181.     local gameMode
  182.     gameMode = memory.readbyte(0x7FAFC7)
  183.     if gameMode == 1 then
  184.         gui.text(970, 245, "HP")
  185.         gui.text(1010, 245, "Agi")
  186.         gui.text(1040, 245, "WLvl")
  187.         for i=1, monNum do
  188.             gui.text(970, 260+12*(i-1), string.format("%2d", eHP[i]))
  189.             gui.text(1015, 260+12*(i-1), string.format("%d", eAgi[i]))
  190.             gui.text(1035, 260+12*(i-1), string.format("%2d", eWaza[i]))
  191.         end
  192.     end
  193.  
  194.     for i = 1, 5 do
  195.         agility[i] = memory.readbyte(0x7EAA65+0x0100*(i-1))
  196.         SP[i] = {}
  197.         SPCol[i] = {}
  198.         for j = 0, 0xFF do
  199.             SP[i][j+1] = (agility[i])*2 + (rng[1+(j)] % ((agility[i])*2)) + 1
  200.         end
  201.     end
  202.  
  203.     local comSelect = memory.readbyte(0x7E0D1A)
  204.     local numParty = memory.readbyte(0x7EF618)
  205.     if comSelect >= 0 and comSelect < numParty then
  206.         for j = 0, 0xF do
  207.             for i = 0, 0xF do
  208.                 gui.text(545+i*26, 28, string.format("%2X", i))
  209.                 if sel % 2 == 0 then
  210.                     gui.text(545+i*26, 50+j*20, string.format("%2d", SP[comSelect+1][1+i+0x10*j]))
  211.                 else
  212.                     gui.text(545+i*26, 50+j*20, string.format("%2X", rng[1+i+0x10*j]))
  213.                 end
  214.                 gui.text(520, 50+j*20, string.format("%2X", 0x10*j))
  215.             end
  216.         end
  217.         local currentRNG = memory.readbyte(0x7E0D1F)
  218.         gui.rectangle(545-2+(currentRNG-16*math.floor(currentRNG/16))*26, 50+20*math.floor(currentRNG/16), 26, 20)
  219.     end
  220.  
  221.     gotSP = {}
  222.     local comSelect = memory.readbyte(0x7E0D1A)
  223.     for i = 1, comSelect do
  224.         gotSP[i] = memory.readbyte(0x7E0DD7 + (i-1))
  225.         if gotSP[i] ~= 0 then
  226.             valueSP[i] = gotSP[i]
  227.         end
  228.     end
  229.  
  230.     local numParty = memory.readbyte(0x7EF618)
  231.     local gameMode
  232.     gameMode = memory.readbyte(0x7FAFC7)
  233.     if gameMode == 1 then
  234.         if countSP ~= numParty then
  235.             if comSelect >= 0 and comSelect < numParty+1 then
  236.                 for i = 1, comSelect do
  237.                     if valueSP[i] ~= 0 then
  238.                         gui.text(970, 380+(i-1)*12, string.format("       %3d", valueSP[i]))
  239.                     end
  240.                 end
  241.             end
  242.         end
  243.     end
  244.  
  245.     local gameMode = memory.readbyte(0x7FAFC7)
  246.     local t = movie.framecount()
  247.     if btlOn ~= gameMode and gameMode ~= 1 then
  248.         lastEnd = t
  249.         btlTime = lastEnd - lastStart
  250.         print(string.format("btlEnd %d, btlTime %d", t, btlTime))
  251.     end
  252.     if btlOn ~= gameMode and gameMode ~= 0 then
  253.         lastStart = t
  254.         print(string.format("btlStart %d", t))
  255.     end
  256.     btlOn = gameMode
  257.  
  258.     local numParty
  259.     local comSelect = memory.readbyte(0x7E0D1A)
  260.     local currentRNG = memory.readbyte(0x7E0D1F)
  261.     local numParty = memory.readbyte(0x7EF618)
  262.  
  263.     if numParty < 6 then
  264.         if comSelect >=0 and comSelect <  numParty then
  265.             gui.text(970, 365, string.format("SP  %2X->%2d", currentRNG, SP[comSelect+1][currentRNG+1]))
  266.         end
  267.     end
  268.  
  269.     --[[
  270.     local comSelect = memory.readbyte(0x7E0D1A)
  271.     local numParty = memory.readbyte(0x7EF618)
  272.     local agilityTest = 20
  273.     local SPtest = {}
  274.     local rngMod = {}
  275.     agilityTest = 20
  276.     print(agilityTest)
  277.     for j = 0, 0xFF do
  278.         SPtest[j+1] = (agilityTest)*2 + (rng[1+(j)] % (agilityTest*2)) + 1
  279.         rngMod[j+1] = rng[1+(j)] % 4
  280.     end
  281.     for j = 0, 0xF do
  282.         for i = 0, 0xF do
  283.             gui.text(545+i*26, 28, string.format("%2X", i))
  284.             gui.text(545+i*26, 50+j*20, string.format("%2d", SPtest[1+i+0x10*j]))
  285.             gui.text(545+i*26, 50+j*20, string.format("%2d", rngMod[1+i+0x10*j]))
  286.             gui.text(520, 50+j*20, string.format("%2X", 0x10*j))
  287.         end
  288.     end
  289.     local currentRNG = memory.readbyte(0x7E0D1F)
  290.     gui.rectangle(545-2+(currentRNG-16*math.floor(currentRNG/16))*26, 50+20*math.floor(currentRNG/16), 26, 20)
  291.     ]]
  292. end
  293.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement