def f_blockpatch_epd(dstepd, srcepd, dwn): """ Patch 4*dwn bytes of memory at dstepd with memory of srcepd. .. note:: After calling this function, contents at srcepd memory may change. Since new contents are required for :py:`f_unpatchall` to run, you shouldn't use the memory for any other means. """ global dws_top # Push to stack pushpatchstack(dstepd) pushpatchstack(srcepd) pushpatchstack(dwn) dws_top += 1 # Swap contents btw dstepd, srcepd tmpbuffer = c.Db(1024) if cs.EUDWhile()(dwn > 0): copydwn = c.EUDVariable() copydwn << 256 t.Trigger(dwn <= 256, copydwn.SetNumber(dwn)) dwn -= copydwn f_repmovsd_epd(ut.EPD(tmpbuffer), dstepd, copydwn) f_repmovsd_epd(dstepd, srcepd, copydwn) f_repmovsd_epd(srcepd, ut.EPD(tmpbuffer), copydwn) cs.EUDEndWhile()
def EUDLoopSprite(): y_epd = c.EUDVariable() y_epd << ut.EPD(0x629688) ut.EUDCreateBlock('spriteloop', 'sprlo') if cs.EUDWhile()(y_epd < ut.EPD(0x629688) + 256): ptr, epd = f_dwepdread_epd(y_epd) if cs.EUDWhile()(ptr >= 1): yield ptr, epd cs.EUDSetContinuePoint() c.SetVariables([ptr, epd], f_dwepdread_epd(epd + 1)) cs.EUDEndWhile() y_epd += 1 cs.EUDEndWhile() ut.EUDPopBlock('spriteloop')
def f_unpatchall(): global ps_top, dws_top if cs.EUDWhile()(ps_top >= 1): dws_top -= 1 dwn = poppatchstack() unpatchsrcepd = poppatchstack() dstepd = poppatchstack() f_repmovsd_epd(dstepd, unpatchsrcepd, dwn) cs.EUDEndWhile()
def EUDEndPlayerLoop(): block = ut.EUDPopBlock('ploopblock')[1] playerv = block['playerv'] origcp = block['origcp'] if not cs.EUDIsContinuePointSet(): cs.EUDSetContinuePoint() playerv += 1 cs.EUDEndWhile() f_setcurpl(origcp)
def EUDLoopUnit(): ut.EUDCreateBlock('unitloop', 0x628430) ptr, epd = f_cunitepdread_epd(ut.EPD(0x628430)) if cs.EUDWhile()(ptr >= 1): yield ptr, epd cs.EUDSetContinuePoint() c.SetVariables([ptr, epd], f_cunitepdread_epd(epd + 1)) cs.EUDEndWhile() ut.EUDPopBlock('unitloop')
def EUDLoopPlayerUnit(player): player = c.EncodePlayer(player) first_player_unit = 0x6283F8 ut.EUDCreateBlock('playerunitloop', first_player_unit) ptr, epd = f_cunitepdread_epd(ut.EPD(first_player_unit) + player) if cs.EUDWhile()(ptr >= 1): yield ptr, epd cs.EUDSetContinuePoint() # /*0x06C*/ BW::CUnit* nextPlayerUnit; c.SetVariables([ptr, epd], f_cunitepdread_epd(epd + 0x6C // 4)) cs.EUDEndWhile() ut.EUDPopBlock('playerunitloop')
def QueueGameCommand_Select(n, ptrList): ptrList = EUDArray.cast(ptrList) buf = c.Db(b'\x090123456789012345678901234') bw.seekoffset(buf + 1) bw.writebyte(n) i = c.EUDVariable() i << 0 if cs.EUDWhile()(i < n): unitptr = ptrList[i] unitIndex = (unitptr - 0x59CCA8) // 336 + 1 uniquenessIdentifier = f_bread(unitptr + 0xA5) targetID = unitIndex | c.f_bitlshift(uniquenessIdentifier, 11) b0, b1 = f_dwbreak(targetID)[2:4] bw.writebyte(b0) bw.writebyte(b1) i += 1 cs.EUDEndWhile() QueueGameCommand(buf, 2 * (n + 1))
def EUDLoopList(header_offset, break_offset=None): blockname = 'listloop' ut.EUDCreateBlock(blockname, header_offset) ptr, epd = f_dwepdread_epd(ut.EPD(header_offset)) if break_offset is not None: cs.EUDWhileNot()(ptr == break_offset) else: cs.EUDWhile()([ptr > 0, ptr <= 0x7FFFFFFF]) yield ptr, epd cs.EUDSetContinuePoint() c.SetVariables([ptr, epd], f_dwepdread_epd(epd + 1)) cs.EUDEndWhile() ut.ep_assert( ut.EUDPopBlock(blockname)[1] is header_offset, 'listloop mismatch' )