Advertisement
Jimmie1717

BizHawk: Tunic Color

Nov 12th, 2017
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.32 KB | None | 0 0
  1. -- Majora's Mask (U): Tunic Color
  2. -- by Jimmie1717
  3. -- BizHawk 2.2.1
  4. -- This will only work with the NTSC-U version of the game.
  5.  
  6. console.clear();
  7.  
  8. readByte                = mainmemory.read_u8;
  9. readWord                = mainmemory.read_u16_be;
  10. readSWord               = mainmemory.read_s16_be;
  11. readDWord               = mainmemory.read_u32_be;
  12. readFloat               = mainmemory.readfloat;
  13. writeByte               = mainmemory.write_u8;
  14. writeWord               = mainmemory.write_u16_be;
  15. writeSWord              = mainmemory.write_s16_be;
  16. writeDWord              = mainmemory.write_u32_be;
  17. writeFloat              = mainmemory.writefloat;
  18.  
  19. version                 = "u";
  20.  
  21. function tunicForm()
  22.     TUNIC               = forms.newform(217, 148, "Tunic");
  23.     r                   = forms.textbox(TUNIC, "30", 25, 20, "UNSIGNED", 24, 30, false, false);
  24.     g                   = forms.textbox(TUNIC, "105", 25, 20, "UNSIGNED", 73, 30, false, false);
  25.     b                   = forms.textbox(TUNIC, "27", 25, 20, "UNSIGNED", 122, 30, false, false);
  26.     a                   = forms.textbox(TUNIC, "255", 25, 20, "UNSIGNED", 171, 30, false, false);
  27.     red                 = forms.label(TUNIC, "R:", 5, 33, 18, 13, false);
  28.     green               = forms.label(TUNIC, "G:", 54, 33, 18, 13, false);
  29.     blue                = forms.label(TUNIC, "B:", 103, 33, 18, 13, false);
  30.     alpha               = forms.label(TUNIC, "A:", 152, 33, 18, 13, false);
  31.     update              = forms.button(TUNIC, "Update", updateColor, 4, 55, 193, 22);
  32.     default             = forms.button(TUNIC, "Default", resetColor, 4, 81, 193, 22);
  33.    
  34.     newSample           = forms.pictureBox(TUNIC, 5, 5, 93, 20);
  35.     newBorder           = forms.drawRectangle(newSample, 0, 0, 92, 19, "BLACK", "TRANSPARENT");
  36.    
  37.     currentSample       = forms.pictureBox(TUNIC, 103, 5, 93, 20);
  38.     currentBorder       = forms.drawRectangle(currentSample, 0, 0, 92, 19, "BLACK", "TRANSPARENT");
  39.    
  40.     color               = {
  41.         r               = 0x1E,
  42.         g               = 0x69,
  43.         b               = 0x1B,
  44.         a               = 0xFF
  45.     };
  46. end
  47.  
  48. function updateAddress()
  49.    
  50.     address             = {
  51.         ["u"]           = readDWord(0x3FFFF4) - 0x80012E58,
  52.         ["j"]           = readDWord(0x4004A4) - 0x80013064
  53.     };
  54.  
  55. end
  56.  
  57. function updateColor()
  58.  
  59.     if (address[version] ~= nil) then
  60.         forms.setproperty(currentSample, "BackColor", forms.createcolor(color.r, color.g, color.b, color.a));
  61.         if (tonumber(forms.gettext(r)) ~= nil and tonumber(forms.gettext(g)) ~= nil and tonumber(forms.gettext(b)) ~= nil) then
  62.             color.r = tonumber(forms.gettext(r));
  63.             color.g = tonumber(forms.gettext(g));
  64.             color.b = tonumber(forms.gettext(b));
  65.             color.a = tonumber(forms.gettext(a));
  66.         else
  67.             gui.addmessage("Error: Reset to default color.");
  68.             color.r = 0x1E;
  69.             color.g = 0x69;
  70.             color.b = 0x1B;
  71.             color.a = 0xFF;
  72.         end
  73.     end
  74.    
  75. end
  76.  
  77. function resetColor()
  78.  
  79.     if (address[version] ~= nil) then
  80.         if (tonumber(forms.gettext(r)) ~= nil and tonumber(forms.gettext(g)) ~= nil and tonumber(forms.gettext(b)) ~= nil) then
  81.             forms.settext(r, 0x1E);
  82.             forms.settext(g, 0x69);
  83.             forms.settext(b, 0x1B);
  84.             forms.settext(a, 0xFF);
  85.             color.r = 0x1E;
  86.             color.g = 0x69;
  87.             color.b = 0x1B;
  88.             color.a = 0xFF;
  89.             tunic();
  90.         end
  91.     end
  92.    
  93. end
  94.  
  95. function limitRGBA()
  96.  
  97.     if (tonumber(forms.gettext(a)) ~= 255) then
  98.         forms.settext(a, 255);
  99.     end
  100.  
  101.     if (tonumber(forms.gettext(r)) ~= nil and tonumber(forms.gettext(g)) ~= nil and tonumber(forms.gettext(b)) ~= nil) then
  102.         if (tonumber(forms.gettext(r)) > 255) then
  103.             forms.settext(r, 255);
  104.         end
  105.         if (tonumber(forms.gettext(g)) > 255) then
  106.             forms.settext(g, 255);
  107.         end
  108.         if (tonumber(forms.gettext(b)) > 255) then
  109.             forms.settext(b, 255);
  110.         end
  111.        
  112.         forms.setproperty(newSample, "BackColor", forms.createcolor(tonumber(forms.gettext(r)), tonumber(forms.gettext(g)), tonumber(forms.gettext(b)), 255));
  113.         forms.setproperty(currentSample, "BackColor", forms.createcolor(color.r, color.g, color.b, color.a));
  114.        
  115.     end
  116.  
  117. end
  118.  
  119. function tunic()
  120.    
  121.     local color = (color.r * 0x1000000) + (color.g * 0x10000) + (color.b * 0x100) + color.a;
  122.    
  123.     if (readDWord(address[version]) == 0xFA0000FF) then
  124.         writeDWord(address[version] + 0x0004, color);
  125.         writeDWord(address[version] + 0x052C, color);
  126.         writeDWord(address[version] + 0x0A34, color);
  127.         writeDWord(address[version] + 0x0C0C, color);
  128.         writeDWord(address[version] + 0x0CCC, color);
  129.         writeDWord(address[version] + 0x12D4, color);
  130.         writeDWord(address[version] + 0x174C, color);
  131.         writeDWord(address[version] + 0x1984, color);
  132.         writeDWord(address[version] + 0x1E54, color);
  133.     end
  134.  
  135. end
  136.  
  137. tunicForm();
  138.  
  139. while true do
  140.    
  141.     updateAddress();
  142.     limitRGBA();
  143.     tunic();
  144.    
  145.     emu.frameadvance();
  146.        
  147. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement