Пример #1
0
def test_assemble_with_label():
    start_address = 0x80085760 + 0x9C

    patch = [
        ppc.bl(8, relative=True),
        ppc.bl("other"),
        ppc.nop(),
        ppc.nop().with_label("other"),
    ]

    assembled_bytes = list(
        assembler.assemble_instructions(start_address, patch))

    assert assembled_bytes == [
        0x48,
        0x00,
        0x00,
        0x09,
        0x48,
        0x00,
        0x00,
        0x09,
        0x60,
        0x00,
        0x00,
        0x00,
        0x60,
        0x00,
        0x00,
        0x00,
    ]
Пример #2
0
def set_artifact_layer_active_patch(addresses: Prime1DolVersion, layer_id: int, active: bool,
                                    ) -> List[assembler.BaseInstruction]:
    # g_GameState->StateForWorld(0x39F2DE28)->GetLayerState()->SetLayerActive(templeAreaIndex, artifactLayer, true)
    result = []

    for_another_world = [
        # Get the LayerState via the CGameState
        lwz(r3, addresses.game_state_pointer - addresses.sda13_base, r13),  # get g_GameState
        # r4 already have the asset id
        bl(addresses.state_for_world),  # CGameState::StateForWorld
        lwz(r3, 0x14, r3),  # worldState->layerState
    ]

    result.extend([
        # Get the LayerState of current world. We'll overwrite if it's another world, it's just 1 instruction bigger
        lwz(r3, 0x8c8, r31),  # mgr->worldLayerState

        # Tallon Overworld asset id
        custom_ppc.load_unsigned_32bit(r4, 0x39f2de28),

        # Load current asset id in r5
        lwz(r5, 0x850, r31),  # mgr->world
        lwz(r5, 0x8, r5),  # world->mlvlId

        cmpw(0, r4, r5),  # compare asset ids
        beq(4 + assembler.byte_count(for_another_world), relative=True),
        *for_another_world,
        lwz(r3, 0x0, r3),

        # Set layer
        li(r4, 16),  # Artifact Layer
        stw(r4, 0x10, r1),

        # Set layer
        li(r5, layer_id),  # Artifact Layer
        stw(r5, 0x14, r1),

        # Make the layer change via SetLayerActive
        addi(r4, r1, 0x10),
        addi(r5, r1, 0x14),
        li(r6, int(active)),
        bl(addresses.set_layer_active),  # CWorldLayerState::SetLayerActive
    ])

    return result
Пример #3
0
def test_composite_bl_double():
    target_address = 0x80085760
    start_address = 0x80085760 + 0x9C

    inc = ppc.bl(target_address)
    comp = custom_ppc.CompositeInstruction((inc, inc))

    composite_bytes = list(comp.bytes_for(start_address, symbols={}))
    assembled_bytes = list(
        assembler.assemble_instructions(start_address, [inc, inc]))

    assert composite_bytes == [0x4b, 0xff, 0xff, 0x65, 0x4b, 0xff, 0xff, 0x61]
    assert composite_bytes == assembled_bytes
Пример #4
0
def test_composite_bl_single():
    inc = ppc.bl(0x80085760)
    comp = custom_ppc.CompositeInstruction((inc, ))

    assert list(comp.bytes_for(0x80085760 + 0x9C,
                               symbols={})) == [0x4b, 0xff, 0xff, 0x65]
Пример #5
0
def test_bl():
    assert _b(ppc.bl(0x80085760),
              address=0x80085760 + 0x9C) == [0x4b, 0xff, 0xff, 0x65]
Пример #6
0
def test_bl():
    assert list(ppc.bl(0x80085760)(0x80085760 +
                                   0x9C)) == [0x4b, 0xff, 0xff, 0x65]