Closed jabdownsmash closed 8 years ago
Ah right, this was an issue lurking in the back of my mind that I didn't want to acknowledge. Are you going to work on a fix? It should hopefully be a simple check. I'd be fine with resetting to the default.
Enums are pretty limited in python it seems. The simplest fix looks like this:
def handle(value):
transformed = (struct.unpack('>i', value)[0] >> shift) & mask
wrapped = transformed
if wrapper is not None:
try:
wrapper(transformed)
except:
wrapper = default
setattr(obj, name, wrapped)
Little weird to handle it that way, but it makes sense to revert to default if the wrapper throws an error. An alternative would be to use a customized class instead of Enum
and pass in a validation function to the handlers.
I think the simple fix is fine, but make sure to do except ValueError:
, update the comment saying that the wrapper should raise ValueError
in case the input is bad, and add a test :)
For global addresses, this will likely not be an issue, but this is an issue for
player[i].action_state
and will be for any addresses that chase pointers. If a game ends, the pointer isn't guaranteed to be pointing at char data anymore, and p3 ends up trying to parse some random value from the memory into theaction_state
fields, and theActionState
enum conversion fails.For
action_state
specifically, a solution would be to ignore these addresses from Dolphin ifmenu
isn'tGame
, but implementing a solution like that might not work for all addresses. A more general but less predictable solution would be to set the field to the default value when the enum conversion error is caught.