Skip to content

Commit

Permalink
Music support (#270) + update version to 4.2
Browse files Browse the repository at this point in the history
* Add initial music decompilation support

A lot of work still needs to be done, and a big refactor. But you should
be able to extract music out of a vanilla rom with this.

* Fix error with filename processing in MusicModule

* Add `songs.yml` output

* Add support for in-engine songs in `songs.yml`

* I think it works

* Output instrument pack numbers as hex

* Tighten up some error messages

* Deal with phrase list jumps properly

* Bugfix

* Finalize music support, including in-engine songs

* JK it's not done. Add todo comment

* Add support for editing engine.bin

* Code cleanup to address pylint warnings

* Nvm. Change version name to beta

* Windows build fixes + fix gas station + debug messages

* Fix palette bug and bump version number

* Add Gas Station instrument pack fix

See comment in MusicModule for more info.

* Fix bug with splitting Gas Station Pt. 2

Turns out, hash() of a 32-bit int does not give the same result on different platforms (32 vs 64 bit). Use crc32() directly instead.

* Update CCScript version

* Update version string in preparation for release

* Update CCScript link to 1.500 instead of master

* Use new upgrade code with recursive structure

* Update release date
  • Loading branch information
charasyn authored Mar 20, 2023
1 parent eeac186 commit f35b0dd
Show file tree
Hide file tree
Showing 10 changed files with 1,359 additions and 8 deletions.
Binary file not shown.
4 changes: 4 additions & 0 deletions coilsnake/assets/ips/Earthbound/gas_station_pack_fix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Title: Fix pack variable initialization to allow for custom instrument packs on the Gas Station (Part 1) song
Author: cooprocks123e
Hidden: True
Ranges: []
1 change: 1 addition & 0 deletions coilsnake/assets/modulelist.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
common.UsedRangeModule
common.PatchModule
eb.MusicModule
eb.CharacterSubstitutionsModule
eb.CccInterfaceModule
eb.SkipNamingModule
Expand Down
21 changes: 20 additions & 1 deletion coilsnake/model/common/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ def check_range_validity(range, size):
elif (begin < 0) or (end >= size):
raise OutOfBoundsError("Invalid range[(%#x,%#x)] provided" % (begin, end))

def fix_slice(key, size):
if not (key.step == 1 or key.step is None):
raise InvalidArgumentError("Slice step must be 1 or None, but is {}".format(key.step))
start, stop = key.start, key.stop
def fix_single_index(x, default):
if x is None:
x = default
elif x < 0:
x += size
return x
start = fix_single_index(start, 0)
stop = fix_single_index(stop, size)
return slice(start, stop)

class Block(object):
def __init__(self, size=0):
Expand Down Expand Up @@ -105,6 +118,7 @@ def write_multi(self, key, item, size):

def __getitem__(self, key):
if isinstance(key, slice):
key = fix_slice(key, self.size)
if key.start > key.stop:
raise InvalidArgumentError("Second argument of slice %s must be greater than the first" % key)
elif (key.start < 0) or (key.stop - 1 >= self.size):
Expand Down Expand Up @@ -132,6 +146,7 @@ def __setitem__(self, key, item):
self.data[key] = item
elif isinstance(key, slice) and \
(isinstance(item, list) or isinstance(item, array.array) or isinstance(item, Block)):
key = fix_slice(key, self.size)
if key.start > key.stop:
raise InvalidArgumentError("Second argument of slice %s must be greater than the first" % key)
elif (key.start < 0) or (key.stop - 1 >= self.size):
Expand Down Expand Up @@ -164,9 +179,13 @@ def __eq__(self, other):
def __ne__(self, other):
return not (self == other)

def __hash__(self):
def crc32(self):
return crc32(self.data)

# Don't rely on this having the same result on different machines!
# Use self.crc32() if you're comparing with a known CRC value.
def __hash__(self):
return self.crc32()

class AllocatableBlock(Block):
def reset(self, size=0):
Expand Down
Loading

0 comments on commit f35b0dd

Please sign in to comment.