1414 hueShift ,
1515 hueShiftImageContainer ,
1616)
17- from randomizer .Patching .Library .Assets import getPointerLocation , TableNames
17+ from randomizer .Patching .Library .Assets import getPointerLocation , TableNames , getRawFile , writeRawFile
1818from randomizer .Settings import CharacterColors , KongModels , ColorOptions
1919
2020
21- def changeBarrelColor (settings , ROM_COPY : ROM , barrel_color : tuple = None , metal_color : tuple = None , brighten_barrel : bool = False ):
21+ def changeBarrelColor (settings , ROM_COPY : ROM , barrel_color : list [ tuple ] = [ None ] * 6 , metal_color : tuple = None , brighten_barrel : bool = False ):
2222 """Change the colors of the various barrels."""
23+ if settings .color_coded_powerups :
24+ barrel_color = [
25+ (0xFF , 0xD7 , 0x00 ),
26+ (0xFF , 0x00 , 0x00 ),
27+ (0x16 , 0x99 , 0xFF ),
28+ (0xB0 , 0x45 , 0xFF ),
29+ (0x41 , 0xFF , 0x25 ),
30+ barrel_color [5 ],
31+ ]
2332 wood_img = getImageFile (ROM_COPY , 25 , getBonusSkinOffset (ExtraTextures .ShellWood ), True , 32 , 64 , TextureFormat .RGBA5551 )
2433 metal_img = getImageFile (ROM_COPY , 25 , getBonusSkinOffset (ExtraTextures .ShellMetal ), True , 32 , 64 , TextureFormat .RGBA5551 )
2534 qmark_img = getImageFile (ROM_COPY , 25 , getBonusSkinOffset (ExtraTextures .ShellQMark ), True , 32 , 64 , TextureFormat .RGBA5551 )
26- if barrel_color is not None :
27- if brighten_barrel :
28- enhancer = ImageEnhance .Brightness (wood_img )
29- wood_img = enhancer .enhance (2 )
30- wood_img = maskImageWithColor (wood_img , barrel_color )
35+ wood_imgs = []
36+ for x in range (6 ):
37+ wood_tmp = wood_img
38+ if barrel_color [x ] is not None :
39+ if brighten_barrel :
40+ enhancer = ImageEnhance .Brightness (wood_tmp )
41+ wood_tmp = enhancer .enhance (2 )
42+ wood_tmp = maskImageWithColor (wood_tmp , barrel_color [x ])
43+ wood_imgs .append (wood_tmp )
3144 if metal_color is not None :
3245 metal_img = maskImageWithColor (metal_img , metal_color )
33- wood_img .paste (metal_img , (0 , 0 ), metal_img )
34- writeColorImageToROM (wood_img , 25 , getBonusSkinOffset (ExtraTextures .BonusShell ), 32 , 64 , False , TextureFormat .RGBA5551 , ROM_COPY ) # Bonus Barrel
46+ for x in range (6 ):
47+ wood_imgs [x ].paste (metal_img , (0 , 0 ), metal_img )
48+ writeColorImageToROM (wood_imgs [5 ], 25 , getBonusSkinOffset (ExtraTextures .BonusShell ), 32 , 64 , False , TextureFormat .RGBA5551 , ROM_COPY ) # Bonus Barrel
3549 tag_img = Image .new (mode = "RGBA" , size = (32 , 64 ))
36- tag_img .paste (wood_img , (0 , 0 ), wood_img )
50+ tag_img .paste (wood_imgs [ 5 ] , (0 , 0 ), wood_imgs [ 5 ] )
3751 tag_img .paste (qmark_img , (0 , 0 ), qmark_img )
3852 writeColorImageToROM (tag_img , 25 , 4938 , 32 , 64 , False , TextureFormat .RGBA5551 , ROM_COPY ) # Tag Barrel
3953 # Compose Transform Barrels
@@ -44,7 +58,7 @@ def changeBarrelColor(settings, ROM_COPY: ROM, barrel_color: tuple = None, metal
4458 {"face_left" : 0x276 , "face_right" : 0x275 , "barrel_tex_start" : 4769 , "targ_width" : 24 }, # Tiny
4559 {"face_left" : 0x273 , "face_right" : 0x274 , "barrel_tex_start" : 4747 , "targ_width" : 24 }, # Chunky
4660 ]
47- for kong in kongs :
61+ for kong_index , kong in enumerate ( kongs ) :
4862 bar_left = Image .new (mode = "RGBA" , size = (32 , 64 ))
4963 bar_right = Image .new (mode = "RGBA" , size = (32 , 64 ))
5064 face_left = getImageFile (ROM_COPY , 25 , kong ["face_left" ], True , 32 , 64 , TextureFormat .RGBA5551 )
@@ -55,22 +69,22 @@ def changeBarrelColor(settings, ROM_COPY: ROM, barrel_color: tuple = None, metal
5569 face_right = face_right .resize ((width , height ))
5670 right_w_offset = 32 - width
5771 top_h_offset = (64 - height ) >> 1
58- bar_left .paste (wood_img , (0 , 0 ), wood_img )
59- bar_right .paste (wood_img , (0 , 0 ), wood_img )
72+ bar_left .paste (wood_imgs [ kong_index ] , (0 , 0 ), wood_imgs [ kong_index ] )
73+ bar_right .paste (wood_imgs [ kong_index ] , (0 , 0 ), wood_imgs [ kong_index ] )
6074 bar_left .paste (face_left , (right_w_offset , top_h_offset ), face_left )
6175 bar_right .paste (face_right , (0 , top_h_offset ), face_right )
6276 writeColorImageToROM (bar_left , 25 , kong ["barrel_tex_start" ], 32 , 64 , False , TextureFormat .RGBA5551 , ROM_COPY )
6377 writeColorImageToROM (bar_right , 25 , kong ["barrel_tex_start" ] + 1 , 32 , 64 , False , TextureFormat .RGBA5551 , ROM_COPY )
6478 # Cannons
6579 barrel_left = Image .new (mode = "RGBA" , size = (32 , 64 ))
6680 barrel_right = Image .new (mode = "RGBA" , size = (32 , 64 ))
67- barrel_left .paste (wood_img , (0 , 0 ), wood_img )
68- barrel_right .paste (wood_img , (0 , 0 ), wood_img )
81+ barrel_left .paste (wood_imgs [ 5 ] , (0 , 0 ), wood_imgs [ 5 ] )
82+ barrel_right .paste (wood_imgs [ 5 ] , (0 , 0 ), wood_imgs [ 5 ] )
6983 barrel_left = barrel_left .crop ((0 , 0 , 16 , 64 ))
7084 barrel_right = barrel_right .crop ((16 , 0 , 32 , 64 ))
7185 writeColorImageToROM (barrel_left , 25 , 0x12B3 , 16 , 64 , False , TextureFormat .RGBA5551 , ROM_COPY )
7286 writeColorImageToROM (barrel_right , 25 , 0x12B4 , 16 , 64 , False , TextureFormat .RGBA5551 , ROM_COPY )
73- if barrel_color is not None :
87+ if barrel_color [ 5 ] is not None :
7488 tex_data = {
7589 getBonusSkinOffset (ExtraTextures .RocketTop ): (1 , 1372 ),
7690 0x12B5 : (48 , 32 ),
@@ -80,10 +94,10 @@ def changeBarrelColor(settings, ROM_COPY: ROM, barrel_color: tuple = None, metal
8094 dim_x = tex_data [img ][0 ]
8195 dim_y = tex_data [img ][1 ]
8296 img_output = getImageFile (ROM_COPY , 25 , img , True , dim_x , dim_y , TextureFormat .RGBA5551 )
83- img_output = maskImageWithColor (img_output , barrel_color )
97+ img_output = maskImageWithColor (img_output , barrel_color [ 5 ] )
8498 writeColorImageToROM (img_output , 25 , img , dim_x , dim_y , False , TextureFormat .RGBA5551 , ROM_COPY )
8599 # Barrel Palette
86- if barrel_color is not None :
100+ if barrel_color [ 5 ] is not None :
87101 palette_files = {
88102 0x145 : [],
89103 0x147 : [1 , 3 , 4 , 6 , 9 , 10 , 12 , 15 ],
@@ -95,7 +109,7 @@ def changeBarrelColor(settings, ROM_COPY: ROM, barrel_color: tuple = None, metal
95109 }
96110 for img in palette_files :
97111 initial_img = getImageFile (ROM_COPY , 25 , img , True , 16 , 1 , TextureFormat .RGBA5551 )
98- img_output = maskImageWithColor (initial_img , barrel_color ).convert ("RGB" )
112+ img_output = maskImageWithColor (initial_img , barrel_color [ 5 ] ).convert ("RGB" )
99113 pixels = palette_files [img ]
100114 for px in pixels :
101115 img_output .putpixel ((px , 0 ), initial_img .getpixel ((px , 0 )))
@@ -152,6 +166,39 @@ def applyCelebrationRims(ROM_COPY: ROM, hue_shift: int, enabled_bananas: list[bo
152166def applyHolidayMode (settings , ROM_COPY : ROM ):
153167 """Change grass texture to snow."""
154168 HOLIDAY = getHoliday (settings )
169+ if settings .color_coded_powerups :
170+ pad_data = [
171+ {"move_pad" : 0x0097 , "ins_pad" : 0x00A8 , "move_tex" : [0xDEE , 0xDEF ], "ins_tex" : [getBonusSkinOffset (ExtraTextures .DonkeyPadLeft ), getBonusSkinOffset (ExtraTextures .DonkeyPadRight )]},
172+ {"move_pad" : 0x00D4 , "ins_pad" : 0x00A9 , "move_tex" : [0xDF4 , 0xDF5 ], "ins_tex" : [getBonusSkinOffset (ExtraTextures .DiddyPadLeft ), getBonusSkinOffset (ExtraTextures .DiddyPadRight )]},
173+ {"move_pad" : 0x010C , "ins_pad" : 0x00AC , "move_tex" : [0xBB0 , 0xBB1 ], "ins_tex" : [getBonusSkinOffset (ExtraTextures .LankyPadLeft ), getBonusSkinOffset (ExtraTextures .LankyPadRight )]},
174+ {"move_pad" : 0x010B , "ins_pad" : 0x00AA , "move_tex" : [0xDF1 , 0xDF2 ], "ins_tex" : [0xBC5 , 0xBC4 ]},
175+ {"move_pad" : 0x010A , "ins_pad" : 0x00AB , "move_tex" : [0xDF6 , 0xDF7 ], "ins_tex" : [getBonusSkinOffset (ExtraTextures .ChunkyPadLeft ), getBonusSkinOffset (ExtraTextures .ChunkyPadRight )]},
176+ ]
177+ for kong in pad_data :
178+ # Move pads: 0xEC (0), 0x164 (1)
179+ # Instrument pads: 0xDC (1), 0x14C (0)
180+ # Move Pads
181+ data = getRawFile (ROM_COPY , TableNames .ModelTwoGeometry , kong ["move_pad" ], True )
182+ num_data = [] # data, but represented as nums rather than b strings
183+ for d in data :
184+ num_data .append (d )
185+ num_data [0x0EE ] = (kong ["move_tex" ][0 ] >> 8 ) & 0xFF
186+ num_data [0x0EF ] = (kong ["move_tex" ][0 ] >> 0 ) & 0xFF
187+ num_data [0x166 ] = (kong ["move_tex" ][1 ] >> 8 ) & 0xFF
188+ num_data [0x167 ] = (kong ["move_tex" ][1 ] >> 0 ) & 0xFF
189+ data = bytearray (num_data ) # convert num_data back to binary string
190+ writeRawFile (TableNames .ModelTwoGeometry , kong ["move_pad" ], True , data , ROM_COPY )
191+ # Instrument Pads
192+ data = getRawFile (ROM_COPY , TableNames .ModelTwoGeometry , kong ["ins_pad" ], True )
193+ num_data = [] # data, but represented as nums rather than b strings
194+ for d in data :
195+ num_data .append (d )
196+ num_data [0x14E ] = (kong ["ins_tex" ][0 ] >> 8 ) & 0xFF
197+ num_data [0x14F ] = (kong ["ins_tex" ][0 ] >> 0 ) & 0xFF
198+ num_data [0x0DE ] = (kong ["ins_tex" ][1 ] >> 8 ) & 0xFF
199+ num_data [0x0DF ] = (kong ["ins_tex" ][1 ] >> 0 ) & 0xFF
200+ data = bytearray (num_data ) # convert num_data back to binary string
201+ writeRawFile (TableNames .ModelTwoGeometry , kong ["ins_pad" ], True , data , ROM_COPY )
155202 if HOLIDAY == Holidays .no_holiday :
156203 barrel_color = None
157204 change_barrel_color = IsColorOptionSelected (settings , ColorOptions .barrels_and_boulders )
@@ -160,7 +207,7 @@ def applyHolidayMode(settings, ROM_COPY: ROM):
160207 for _ in range (3 ):
161208 col_array .append (settings .random .randint (0 , 0xFF ))
162209 barrel_color = tuple (col_array )
163- changeBarrelColor (settings , ROM_COPY , barrel_color , None , change_barrel_color ) # Fixes some Krusha stuff
210+ changeBarrelColor (settings , ROM_COPY , [ barrel_color ] * 6 , None , change_barrel_color ) # Fixes some Krusha stuff
164211 return
165212 if HOLIDAY == Holidays .Christmas :
166213 # Set season to Christmas
@@ -258,14 +305,14 @@ def applyHolidayMode(settings, ROM_COPY: ROM):
258305 ROM_COPY .seek (getPointerLocation (TableNames .TexturesGeometry , 0xE68 ))
259306 ROM_COPY .writeBytes (tiny_hair_data )
260307 # Tag Barrel, Bonus Barrel & Transform Barrels
261- changeBarrelColor (settings , ROM_COPY , None , (0x00 , 0xC0 , 0x00 ))
308+ changeBarrelColor (settings , ROM_COPY , [ None ] * 6 , (0x00 , 0xC0 , 0x00 ))
262309 elif HOLIDAY == Holidays .Halloween :
263310 ROM_COPY .seek (settings .rom_data + 0xDB )
264311 ROM_COPY .writeMultipleBytes (1 , 1 )
265312 # Pad Rim
266313 applyCelebrationRims (ROM_COPY , - 12 )
267314 # Tag Barrel, Bonus Barrel & Transform Barrels
268- changeBarrelColor (settings , ROM_COPY , (0x8D , 0xB3 , 0x93 ))
315+ changeBarrelColor (settings , ROM_COPY , [ (0x8D , 0xB3 , 0x93 )] * 6 )
269316 # Turn Ice Tomato Orange
270317 sizes = {
271318 0x1237 : 700 ,
@@ -283,7 +330,7 @@ def applyHolidayMode(settings, ROM_COPY: ROM):
283330 for img in range (0x1237 , 0x1241 + 1 ):
284331 hueShiftImageContainer (25 , img , 1 , sizes [img ], TextureFormat .RGBA5551 , 171 , ROM_COPY )
285332 elif HOLIDAY == Holidays .Anniv25 :
286- changeBarrelColor (settings , ROM_COPY , (0xFF , 0xFF , 0x00 ), None , True )
333+ changeBarrelColor (settings , ROM_COPY , [ (0xFF , 0xFF , 0x00 )] * 6 , None , True )
287334 sticker_im = getImageFile (ROM_COPY , 25 , getBonusSkinOffset (ExtraTextures .Anniv25Sticker ), True , 1 , 1372 , TextureFormat .RGBA5551 )
288335 vanilla_sticker_im = getImageFile (ROM_COPY , 25 , 0xB7D , True , 1 , 1372 , TextureFormat .RGBA5551 )
289336 sticker_im_snipped = sticker_im .crop ((0 , 0 , 1 , 1360 ))
0 commit comments