Example #1
0
def f_dwepdread_cp_safe(cpo):
    if cpo != 0:
        cs.DoActions(c.SetMemory(0x6509B0, c.Add, cpo))
    ptr, epd = _reader()
    if cpo != 0:
        cs.DoActions(c.SetMemory(0x6509B0, c.Add, -cpo))
    return ptr, epd
Example #2
0
def EUDLoopUnit2():
    """EUDLoopUnit보다 약간? 빠릅니다. 유닛 리스트를 따라가지 않고
    1700개 유닛을 도는 방식으로 작동합니다.
    """
    ptr, epd = c.EUDCreateVariables(2)
    cs.DoActions([
        ptr.SetNumber(0x59CCA8),
        epd.SetNumber(ut.EPD(0x59CCA8)),
    ])
    if cs.EUDLoopN()(1700):
        # orderID가 0(Die)이면 없는 유닛으로 판단.
        cs.EUDContinueIf(c.MemoryXEPD(epd + (0x4C // 4), Exactly, 0, 0xFF00))
        yield ptr, epd
        cs.EUDSetContinuePoint()
        cs.DoActions([ptr.AddNumber(336), epd.AddNumber(336 // 4)])
    cs.EUDEndLoopN()
Example #3
0
def f_addcurpl(cp):
    """Add current player value.

    eudplib internally caches the current player value,
    so this function add to that value.
    """
    cs.DoActions(c.AddCurrentPlayer(cp))
Example #4
0
def f_wread_cp(cpo, subp):
    w = c.EUDVariable()
    k = c.EUDVariable()
    cs.DoActions([
        [[] if cpo is 0 else c.SetMemory(0x6509B0, c.Add, cpo)],
        w.SetNumber(0),
        k.SetNumber(0),
    ])
    cs.EUDSwitch(subp)
    for i in range(3):
        cs.EUDSwitchCase()(i)
        for j in range(31, -1, -1):
            if 8 * i <= j < 8 * (i + 2):
                c.RawTrigger(conditions=c.Deaths(c.CurrentPlayer, c.AtLeast,
                                                 2**j, 0),
                             actions=[
                                 c.SetDeaths(c.CurrentPlayer, c.Subtract, 2**j,
                                             0),
                                 k.AddNumber(2**j),
                                 w.AddNumber(2**(j - 8 * i))
                             ])

            else:
                c.RawTrigger(conditions=c.Deaths(c.CurrentPlayer, c.AtLeast,
                                                 2**j, 0),
                             actions=[
                                 c.SetDeaths(c.CurrentPlayer, c.Subtract, 2**j,
                                             0),
                                 k.AddNumber(2**j),
                             ])

            if j == 8 * i:
                break

        c.SeqCompute([(c.EncodePlayer(c.CurrentPlayer), c.Add, k)])
        cs.EUDBreak()

    if cs.EUDSwitchCase()(3):
        dw0 = cpm.f_dwread_cp(0)
        dw1 = cpm.f_dwread_cp(1)
        w << dwm.f_dwbreak(dw0)[5] + dwm.f_dwbreak(dw1)[2] * 256

    cs.EUDEndSwitch()
    cs.DoActions([
        [[] if cpo is 0 else c.SetMemory(0x6509B0, c.Add, -cpo)],
    ])
    return w
Example #5
0
def f_wwrite_cp(cpo, subp, w):
    k = c.EUDVariable()
    cs.DoActions([
        [[] if cpo is 0 else c.SetMemory(0x6509B0, c.Add, cpo)],
        k.SetNumber(0),
    ])
    cs.EUDSwitch(subp)
    for i in range(3):
        cs.EUDSwitchCase()(i)
        for j in range(31, -1, -1):
            if 8 * (i + 2) <= j:
                c.RawTrigger(conditions=c.Deaths(c.CurrentPlayer, c.AtLeast,
                                                 2**j, 0),
                             actions=[
                                 c.SetDeaths(c.CurrentPlayer, c.Subtract, 2**j,
                                             0),
                                 k.AddNumber(2**j),
                             ])

            else:
                c.RawTrigger(conditions=c.Deaths(c.CurrentPlayer, c.AtLeast,
                                                 2**j, 0),
                             actions=[
                                 c.SetDeaths(c.CurrentPlayer, c.Subtract, 2**j,
                                             0),
                             ])

            if j == 8 * i:
                break

        c.SeqCompute([
            (c.CurrentPlayer, c.Add, k),
            (c.CurrentPlayer, c.Add, w * (256**i)),
        ])
        cs.EUDBreak()

    if cs.EUDSwitchCase()(3):
        b0, b1 = dwm.f_dwbreak(w)[2:4]
        f_bwrite_cp(0, 3, b0)
        f_bwrite_cp(1, 0, b1)

    cs.EUDEndSwitch()
    cs.DoActions([
        [[] if cpo is 0 else c.SetMemory(0x6509B0, c.Add, -cpo)],
    ])
Example #6
0
    def Display(self):
        sp = c.EUDVariable(0)
        strId = c.EncodeString("_" * 2048)
        if cs.EUDExecuteOnce()():
            sp << GetMapStringAddr(strId)
        cs.EUDEndExecuteOnce()

        f_cp949_to_utf8_cpy(sp, self.GetStringMemoryAddr())
        cs.DoActions(c.DisplayText(strId))
Example #7
0
    def PlayWAV(dbs):
        sp = c.EUDVariable(0)
        strId = c.EncodeString("_" * 2048)
        if cs.EUDExecuteOnce()():
            strp = f_dwread_epd(ut.EPD(0x5993D4))
            sp << strp + f_wread(strp + strId * 2)
        cs.EUDEndExecuteOnce()

        f_cp949_to_utf8_cpy(sp, dbs.GetStringMemoryAddr())
        cs.DoActions(c.DisplayText(strId))
Example #8
0
def f_dwCUnitread_epd(targetplayer):
    origcp = f_getcurpl()
    ptr = c.EUDVariable()
    cs.DoActions([ptr.SetNumber(0x59CCA8), c.SetCurrentPlayer(targetplayer)])
    for i in range(10, -1, -1):
        c.RawTrigger(conditions=[
            c.Deaths(c.CurrentPlayer, c.AtLeast, 0x59CCA8 + 336 * 2**i, 0)
        ],
                     actions=[
                         c.SetDeaths(c.CurrentPlayer, c.Subtract, 336 * 2**i,
                                     0),
                         ptr.AddNumber(336 * 2**i),
                     ])

    cs.DoActions([
        c.SetDeaths(c.CurrentPlayer, c.SetTo, ptr, 0),
        c.SetCurrentPlayer(origcp),
    ])

    return ptr
Example #9
0
def f_bread_cp(cpo, subp):
    b = c.EUDVariable()
    k = c.EUDVariable()
    cs.DoActions([
        [[] if cpo is 0 else c.SetMemory(0x6509B0, c.Add, cpo)],
        b.SetNumber(0),
        k.SetNumber(0),
    ])
    cs.EUDSwitch(subp)
    for i in range(4):
        cs.EUDSwitchCase()(i)
        for j in range(31, -1, -1):
            if 8 * i <= j < 8 * (i + 1):
                c.RawTrigger(conditions=c.Deaths(c.CurrentPlayer, c.AtLeast,
                                                 2**j, 0),
                             actions=[
                                 c.SetDeaths(c.CurrentPlayer, c.Subtract, 2**j,
                                             0),
                                 k.AddNumber(2**j),
                                 b.AddNumber(2**(j - 8 * i))
                             ])

            else:
                c.RawTrigger(conditions=c.Deaths(c.CurrentPlayer, c.AtLeast,
                                                 2**j, 0),
                             actions=[
                                 c.SetDeaths(c.CurrentPlayer, c.Subtract, 2**j,
                                             0),
                                 k.AddNumber(2**j),
                             ])

            if j == 8 * i:
                break

        c.SeqCompute([(c.EncodePlayer(c.CurrentPlayer), c.Add, k)])
        cs.EUDBreak()
    cs.EUDEndSwitch()
    cs.DoActions([
        [[] if cpo is 0 else c.SetMemory(0x6509B0, c.Add, -cpo)],
    ])
    return b
Example #10
0
def _f_updatecpcache():
    cpcache = c.curpl.GetCPCache()
    cpcache << 0
    for i in range(31, -1, -1):
        c.RawTrigger(
            conditions=[c.Memory(0x6509B0, c.AtLeast, 2**i)],
            actions=[
                c.SetMemory(0x6509B0, c.Subtract, 2**i),
                cpcache.AddNumber(2**i)
            ]
        )
    cs.DoActions(c.SetCurrentPlayer(cpcache))
Example #11
0
def EUDBinaryMin(cond, minv=0, maxv=0xFFFFFFFF):
    """ Find minimum x satisfying cond(x) using binary search

    :param cond: Test condition
    :param minv: Minimum value in domain
    :param maxv: Maximum value in domain

    Cond should be binary classifier, meaning that for some N
        for all x < N, cond(x) is false.
        for all x >= N, cond(x) is true
    Then EUDBinaryMin will find such N

    .. note:: If none of the value satisfies condition, then this
        function will return maxv.
    """
    x = c.EUDVariable()
    x << maxv

    if isinstance(minv, int) and isinstance(maxv, int):
        r = maxv - minv
        if r == 0:
            return minv

    else:
        r = None

    for i in range(31, -1, -1):
        if r and 2**i > r:
            continue

        if cs.EUDIf()([x >= 2**i]):
            cs.DoActions(x.SubtractNumber(2**i))
            if cs.EUDIfNot()([x >= minv, cond(x)]):
                cs.DoActions(x.AddNumber(2**i))
            cs.EUDEndIf()
        cs.EUDEndIf()

    return x
Example #12
0
def f_dwpatch_epd(dstepd, value):
    global patchstack, ps_top, dws_top

    prev_value = f_dwread_epd(dstepd)
    f_dwwrite_epd(dstepd, value)
    cs.DoActions([
        c.SetMemoryEPD(dstepd, c.SetTo, value),
        c.SetMemoryEPD(ut.EPD(dwstack) + dws_top, c.SetTo, prev_value)
    ])

    pushpatchstack(dstepd)
    pushpatchstack(ut.EPD(dwstack) + dws_top)
    pushpatchstack(1)
    dws_top += 1
Example #13
0
def f_randomize():
    global _seed

    # Store switch 1
    sw1 = c.EUDVariable()
    if cs.EUDIf()(c.Switch("Switch 1", c.Set)):
        sw1 << c.EncodeSwitchAction(c.Set)
    if cs.EUDElse()():
        sw1 << c.EncodeSwitchAction(c.Clear)
    cs.EUDEndIf()

    _seed << 0
    dseed = c.EUDVariable()
    dseed << 1

    if cs.EUDLoopN()(32):
        cs.DoActions(c.SetSwitch("Switch 1", c.Random))
        if cs.EUDIf()(c.Switch("Switch 1", c.Set)):
            _seed += dseed
        cs.EUDEndIf()
        dseed += dseed
    cs.EUDEndLoopN()

    cs.DoActions(c.SetSwitch("Switch 1", sw1))
Example #14
0
def f_setcurpl(cp):
    cs.DoActions(c.SetCurrentPlayer(cp))