Jimmie1717 icon

BizHawk: Tunic Color

Jimmie1717 | PRO | 11/13/17 01:01:36 AM UTC | 0 ⭐ | 1330 👁️ | Never ⏰ | []
Lua |

4.32 KB

|

None

|

0 👍

/

0 👎

-- Majora's Mask (U): Tunic Color
-- by Jimmie1717
-- BizHawk 2.2.1
-- This will only work with the NTSC-U version of the game.
 
console.clear();
 
readByte                = mainmemory.read_u8;
readWord                = mainmemory.read_u16_be;
readSWord               = mainmemory.read_s16_be;
readDWord               = mainmemory.read_u32_be;
readFloat               = mainmemory.readfloat;
writeByte               = mainmemory.write_u8;
writeWord               = mainmemory.write_u16_be;
writeSWord              = mainmemory.write_s16_be;
writeDWord              = mainmemory.write_u32_be;
writeFloat              = mainmemory.writefloat;
 
version                 = "u";
 
function tunicForm()
    TUNIC               = forms.newform(217, 148, "Tunic");
    r                   = forms.textbox(TUNIC, "30", 25, 20, "UNSIGNED", 24, 30, false, false);
    g                   = forms.textbox(TUNIC, "105", 25, 20, "UNSIGNED", 73, 30, false, false);
    b                   = forms.textbox(TUNIC, "27", 25, 20, "UNSIGNED", 122, 30, false, false);
    a                   = forms.textbox(TUNIC, "255", 25, 20, "UNSIGNED", 171, 30, false, false);
    red                 = forms.label(TUNIC, "R:", 5, 33, 18, 13, false);
    green               = forms.label(TUNIC, "G:", 54, 33, 18, 13, false);
    blue                = forms.label(TUNIC, "B:", 103, 33, 18, 13, false);
    alpha               = forms.label(TUNIC, "A:", 152, 33, 18, 13, false);
    update              = forms.button(TUNIC, "Update", updateColor, 4, 55, 193, 22);
    default             = forms.button(TUNIC, "Default", resetColor, 4, 81, 193, 22);
    
    newSample           = forms.pictureBox(TUNIC, 5, 5, 93, 20);
    newBorder           = forms.drawRectangle(newSample, 0, 0, 92, 19, "BLACK", "TRANSPARENT");
    
    currentSample       = forms.pictureBox(TUNIC, 103, 5, 93, 20);
    currentBorder       = forms.drawRectangle(currentSample, 0, 0, 92, 19, "BLACK", "TRANSPARENT");
    
    color               = {
        r               = 0x1E,
        g               = 0x69,
        b               = 0x1B,
        a               = 0xFF
    };
end
 
function updateAddress()
    
    address             = {
        ["u"]           = readDWord(0x3FFFF4) - 0x80012E58,
        ["j"]           = readDWord(0x4004A4) - 0x80013064
    };
 
end
 
function updateColor()
 
    if (address[version] ~= nil) then
        forms.setproperty(currentSample, "BackColor", forms.createcolor(color.r, color.g, color.b, color.a));
        if (tonumber(forms.gettext(r)) ~= nil and tonumber(forms.gettext(g)) ~= nil and tonumber(forms.gettext(b)) ~= nil) then
            color.r = tonumber(forms.gettext(r));
            color.g = tonumber(forms.gettext(g));
            color.b = tonumber(forms.gettext(b));
            color.a = tonumber(forms.gettext(a));
        else
            gui.addmessage("Error: Reset to default color.");
            color.r = 0x1E;
            color.g = 0x69;
            color.b = 0x1B;
            color.a = 0xFF;
        end
    end
    
end
 
function resetColor()
 
    if (address[version] ~= nil) then
        if (tonumber(forms.gettext(r)) ~= nil and tonumber(forms.gettext(g)) ~= nil and tonumber(forms.gettext(b)) ~= nil) then
            forms.settext(r, 0x1E);
            forms.settext(g, 0x69);
            forms.settext(b, 0x1B);
            forms.settext(a, 0xFF);
            color.r = 0x1E;
            color.g = 0x69;
            color.b = 0x1B;
            color.a = 0xFF;
            tunic();
        end
    end
    
end
 
function limitRGBA()
 
    if (tonumber(forms.gettext(a)) ~= 255) then
        forms.settext(a, 255);
    end
 
    if (tonumber(forms.gettext(r)) ~= nil and tonumber(forms.gettext(g)) ~= nil and tonumber(forms.gettext(b)) ~= nil) then
        if (tonumber(forms.gettext(r)) > 255) then
            forms.settext(r, 255);
        end
        if (tonumber(forms.gettext(g)) > 255) then
            forms.settext(g, 255);
        end
        if (tonumber(forms.gettext(b)) > 255) then
            forms.settext(b, 255);
        end
        
        forms.setproperty(newSample, "BackColor", forms.createcolor(tonumber(forms.gettext(r)), tonumber(forms.gettext(g)), tonumber(forms.gettext(b)), 255));
        forms.setproperty(currentSample, "BackColor", forms.createcolor(color.r, color.g, color.b, color.a));
        
    end
 
end
 
function tunic()
    
    local color = (color.r * 0x1000000) + (color.g * 0x10000) + (color.b * 0x100) + color.a;
    
    if (readDWord(address[version]) == 0xFA0000FF) then
        writeDWord(address[version] + 0x0004, color);
        writeDWord(address[version] + 0x052C, color);
        writeDWord(address[version] + 0x0A34, color);
        writeDWord(address[version] + 0x0C0C, color);
        writeDWord(address[version] + 0x0CCC, color);
        writeDWord(address[version] + 0x12D4, color);
        writeDWord(address[version] + 0x174C, color);
        writeDWord(address[version] + 0x1984, color);
        writeDWord(address[version] + 0x1E54, color);
    end
 
end
 
tunicForm();
 
while true do
    
    updateAddress();
    limitRGBA();
    tunic();
    
    emu.frameadvance();
        
end

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎