Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bit = (require "migration_helpers").EmuHawk_pre_2_9_bit();
- enable_draw_map = false
- enable_wmrng = false
- enable_ffmode = false
- TARGETS = {}
- SELECTIONS = {}
- CURRENT_MODULE = 0x9c560
- PLAYER_POINTER = 0x10AD38
- function u8(ptr)
- return memory.read_u8(ptr)
- end
- function u16(ptr)
- return memory.read_u16_le(ptr)
- end
- function s32(ptr)
- return memory.read_s32_le(ptr)
- end
- function u32(ptr)
- return memory.read_u32_le(ptr)
- end
- CLOUD = u32(PLAYER_POINTER)
- function set_player()
- CLOUD = u32(PLAYER_POINTER)
- console.clear()
- end
- function select(_c)
- if SELECTIONS[_c] == nil then
- SELECTIONS[_c] = true
- else
- SELECTIONS[_c] = nil
- end
- console.clear()
- end
- function target(_x, _z, _val)
- local idx = 36 * _z + _x
- if _val == nil then
- if TARGETS[idx] == nil then
- TARGETS[idx] = "blue"
- else
- TARGETS[idx] = nil
- end
- else
- if TARGETS[idx] == _val then
- TARGETS[idx] = nil
- else
- TARGETS[idx] = _val
- end
- end
- console.clear()
- end
- function buf_ff()
- local k
- k = 0x10AE5C
- while k < 0x10AE5C + 521 do
- memory.write_u8(k, 0xFF)
- k = k + 1
- end
- end
- function ff7_wmtris_main()
- local MINIMAP_MODE = 0x1164f8
- local WORLD_CHUNK_HEADERS = 0x80109a38
- local WORLD_CHUNK_HEADER_SIZE = 0x18
- local WORLD_CHUNK_HEADER_COUNT = 32
- local WORLD_CHUNK_LL_HEAD = 0x109D5C
- local WORLD_CHUNK_LOAD_LL_HEAD = 0x109D40
- local WORLD_CHUNK_NEXT_FREE_LL_HEAD = 0x109D38
- local WORLD_CHUNK_LOADED_LL_HEAD = 0x109D3C
- local MAP_X = 190
- local MAP_Y = 72
- local st = {}
- local wmcx = {}
- local wmcz = {}
- local wmc_tri = {}
- local wmc_vert = {}
- local wm_ll_order = {}
- local vlc_cache = {}
- CLOUD = u32(PLAYER_POINTER)
- function get_vlc_cache(_x, _z)
- return vlc_cache[36 * _z + _x]
- end
- function populate_vlc_cache(_x, _z, vertex_pointer)
- local cache_idx = 36 * _z + _x
- local i
- if vlc_cache[cache_idx] == nil then
- vlc_cache[cache_idx] = {}
- i = 0
- while i < 0x7a * 4 do
- vlc_cache[cache_idx][i] = u16(vertex_pointer + i * 2)
- i = i + 1
- end
- end
- end
- function clear_vlc_cache()
- for k in pairs (vlc_cache) do
- vlc_cache[k] = nil
- end
- console.clear()
- end
- function draw_wmtris()
- local i
- local x, z, x_chunk, z_chunk, x_sub, z_sub
- local real_idx, real_x, real_z
- local sto_idx, sto_x, sto_z
- local v0i, v1i, v2i, v0x, v0z, v1x, v1z, v2x, v2z
- local color, ws, draw_map, tri_num
- local vlc
- local chunk_ptr
- PLAYER = u32(PLAYER_POINTER)
- if PLAYER ~= 0 then
- x = u32(PLAYER + 0xC)
- z = u32(PLAYER + 0x14)
- x_chunk = math.floor(x / 8192)
- z_chunk = math.floor(z / 8192)
- x_sub = x % 8192
- z_sub = z % 8192
- st[0] = u32(CLOUD + 0x60)
- st[1] = u32(CLOUD + 0x68)
- st[2] = u32(CLOUD + 0x70)
- st[3] = u32(CLOUD + 0x78)
- st[4] = u32(CLOUD + 0x80)
- st[5] = u32(CLOUD + 0x88)
- i = 0
- while i < WORLD_CHUNK_HEADER_COUNT do
- wmcx[i] = u16(WORLD_CHUNK_HEADERS + i * WORLD_CHUNK_HEADER_SIZE + 0x10)
- wmcz[i] = u16(WORLD_CHUNK_HEADERS + i * WORLD_CHUNK_HEADER_SIZE + 0x12)
- wmc_tri[i] = u32(WORLD_CHUNK_HEADERS + i * WORLD_CHUNK_HEADER_SIZE + 0x4)
- wmc_vert[i] = u32(WORLD_CHUNK_HEADERS + i * WORLD_CHUNK_HEADER_SIZE + 0x8)
- wm_ll_order[i] = -1
- populate_vlc_cache(wmcx[i], wmcz[i], wmc_vert[i])
- i = i + 1
- end
- i = 0
- chunk_ptr = u32(WORLD_CHUNK_LL_HEAD)
- while i < 32 and chunk_ptr ~= 0 do
- wm_ll_order[(chunk_ptr - WORLD_CHUNK_HEADERS) / 0x18] = i
- i = i + 1
- chunk_ptr = u32(chunk_ptr)
- end
- gui.text(0, 0, string.format("(%2d-%2d) [%04X %04X]", x_chunk, z_chunk, x_sub, z_sub), nil, "topright")
- i = 0
- while i < 6 do
- if st[i] ~= 0 then
- sto_x = u16(CLOUD + 0x64 + i * 8)
- sto_z = u16(CLOUD + 0x66 + i * 8)
- tri_num = math.floor(((st[i] - 0x800e5a3c) % 0x1200) / 12)
- real_x = -1
- real_z = -1
- real_idx = -1
- sto_idx = -1
- j = 0
- while (real_idx < 0 or sto_idx < 0) and j < WORLD_CHUNK_HEADER_COUNT do
- if wmc_tri[j] == st[i] - (tri_num * 12) then
- real_x = wmcx[j]
- real_z = wmcz[j]
- real_idx = j
- end
- if wmcx[j] == sto_x and wmcz[j] == sto_z then
- sto_idx = j
- end
- j = j + 1
- end
- if real_idx >= 0 then
- if real_x ~= sto_x or real_z ~= sto_z then
- v0i = u8(st[i])
- v1i = u8(st[i] + 1)
- v2i = u8(st[i] + 2)
- if v0i >= 0x7a or v1i >= 0x7a or v2i >= 0x7a then
- color = "red"
- else
- vlc = get_vlc_cache(sto_x, sto_z)
- if vlc ~= nil then
- v0x = vlc[v0i * 4]
- v0z = vlc[v0i * 4 + 2]
- v1x = vlc[v1i * 4]
- v1z = vlc[v1i * 4 + 2]
- v2x = vlc[v2i * 4]
- v2z = vlc[v2i * 4 + 2]
- if (v0x == v1x) and (v1x == v2x) and (v0z == v1z) and (v1z == v2z) then
- ws = u8(st[i] + 3)
- if bit.band(bit.lshift(1, bit.band(ws, 0x1f)), 0x721b6f83) ~= 0 then
- color = "lime"
- else
- color = "orange"
- end
- else
- color = "yellow"
- end
- else
- color = "pink"
- end
- end
- else
- color = "white"
- end
- if sto_idx >= 0 then
- gui.text(0, (i+2)*16, string.format("st%d (c%02d %02d-%02d) [%03d c%02d %02d-%02d] %08X", i, sto_idx, sto_x, sto_z, tri_num, real_idx, real_x, real_z, st[i]), color, "topright")
- else
- gui.text(0, (i+2)*16, string.format("st%d (cXX %02d-%02d) [%03d c%02d %02d-%02d] %08X", i, sto_x, sto_z, tri_num, real_idx, real_x, real_z, st[i]), color, "topright")
- end
- end
- end
- i = i + 1
- end
- i = 0
- while i < WORLD_CHUNK_HEADER_COUNT do
- if x_chunk == wmcx[i] and z_chunk == wmcz[i] then
- color = "lime"
- elseif math.abs(x_chunk - wmcx[i]) <= 1 and math.abs(z_chunk - wmcz[i]) <= 1 then
- color = "white"
- elseif math.abs(x_chunk - wmcx[i]) <= 2 and math.abs(z_chunk - wmcz[i]) <= 2 then
- color = "yellow"
- else
- color = "red"
- end
- if enable_draw_map then
- gui.drawRectangle(MAP_X + 12 * wmcx[i], MAP_Y + 12 * wmcz[i],11,11,color)
- local textColor = color
- if SELECTIONS[i] ~= nil then
- textColor = "pink"
- end
- gui.drawText(MAP_X + 12 * wmcx[i], MAP_Y + 12 * wmcz[i], string.format("%02d", i), textColor, nil, 8)
- end
- local nextPtr = u32(WORLD_CHUNK_HEADERS + i * WORLD_CHUNK_HEADER_SIZE)
- local nextIdx
- if nextPtr == 0 then
- nextIdx = -1
- else
- nextIdx = math.floor((nextPtr - WORLD_CHUNK_HEADERS) / WORLD_CHUNK_HEADER_SIZE)
- end
- gui.text(0, (31-i)*16, string.format("c%02d %02d-%02d %02d -> c%02d", i, wmcx[i], wmcz[i], wm_ll_order[i], nextIdx), color, "bottomright")
- i = i + 1
- end
- local auxPtr = u32(WORLD_CHUNK_LOAD_LL_HEAD)
- if auxPtr == 0 then
- gui.text(0, 33*16, "No load list", "white", "bottomright")
- else
- gui.text(0, 33*16, string.format("Load: c%02d", math.floor((auxPtr - WORLD_CHUNK_HEADERS) / WORLD_CHUNK_HEADER_SIZE)), "white", "bottomright")
- end
- local mainPtr = u32(WORLD_CHUNK_LL_HEAD)
- if mainPtr == 0 then
- gui.text(0, 34*16, "No main list", "white", "bottomright")
- else
- gui.text(0, 34*16, string.format("Main: c%02d", math.floor((mainPtr - WORLD_CHUNK_HEADERS) / WORLD_CHUNK_HEADER_SIZE)), "white", "bottomright")
- end
- local nfPtr = u32(0x109D38)
- if nfPtr == 0 then
- gui.text(0, 35*16, "No Next Free", "white", "bottomright")
- else
- gui.text(0, 35*16, string.format("Next Free: c%02d", math.floor((nfPtr - WORLD_CHUNK_HEADERS) / WORLD_CHUNK_HEADER_SIZE)), "white", "bottomright")
- end
- local loadedPtr = u32(WORLD_CHUNK_LOADED_LL_HEAD)
- if loadedPtr == 0 then
- gui.text(0, 36*16, "No Loaded", "white", "bottomright")
- else
- gui.text(0, 36*16, string.format("Loaded: c%02d", math.floor((loadedPtr - WORLD_CHUNK_HEADERS) / WORLD_CHUNK_HEADER_SIZE)), "white", "bottomright")
- end
- if enable_draw_map then
- local target_x, target_z, target_idx
- for target_idx in pairs(TARGETS) do
- target_x = math.floor(target_idx % 36)
- target_z = math.floor(target_idx / 36)
- gui.drawRectangle(MAP_X + 12 * target_x, MAP_Y + 12 * target_z, 11, 11, TARGETS[target_idx])
- end
- end
- end
- end
- function draw_wmrng()
- local WMRNG_IDX = 0x10AE58
- local WMRNG_BUF = 0x10AE5C
- local WM_FRACTION = 0x11627C
- local WM_DANGER = 0x116284
- local ROWS = 30
- local COLUMNS = 18
- local MAIN_COL_POS = 17
- local i, j
- local danger = s32(WM_DANGER)
- local frac = s32(WM_FRACTION)
- local curr_idx = u32(WMRNG_IDX)
- local idx = curr_idx - frac + COLUMNS - MAIN_COL_POS
- local val = nil
- local color = nil
- local danger_increase = 512
- if PLAYER == 0 then
- return
- end
- function rng(_idx)
- local k = 0
- if _idx < 0 then
- return nil
- elseif _idx < 0x209 then
- return u8(WMRNG_BUF + _idx)
- elseif _idx < 0x412 then
- while _idx >= 0x209 do
- k = bit.bxor(k, u8(WMRNG_BUF + (_idx - 0x209)))
- _idx = _idx - 32
- end
- return bit.bxor(k, u8(WMRNG_BUF + _idx))
- else
- return nil
- end
- end
- gui.text(0, 16*(ROWS+3), string.format("danger: %d", danger), nil, "bottomleft")
- gui.text(0, 16*(ROWS+2), string.format("frac: %d", frac), nil, "bottomleft")
- gui.text(0, 16*(ROWS+1), string.format("idx: %03d", curr_idx), nil, "bottomleft")
- if enable_wmrng then
- i = 0
- while i < ROWS do
- j = 0
- while j < COLUMNS do
- val = rng(idx)
- if val ~= nil then
- if j % 18 == MAIN_COL_POS or (idx - curr_idx == 1) then
- if i * ROWS + j >= 0 then
- if val < bit.rshift(danger + (i + 1) * danger_increase, 8) then
- color = "red"
- else
- color = "lime"
- end
- end
- else
- if i * ROWS + j >= 0 then
- if val < bit.rshift(danger + (i + 1) * danger_increase, 8) then
- color = "pink"
- else
- color = "lightgreen"
- end
- end
- end
- gui.text(30*j, 16*(ROWS - i - 1), string.format("%02X ", val), color, "bottomleft")
- end
- j = j + 1
- idx = idx + 1
- end
- i = i + 1
- end
- end
- end
- function frame()
- gui.clearGraphics()
- if u8(CURRENT_MODULE) == 3 then
- if enable_ffmode then
- buf_ff()
- end
- draw_wmtris()
- draw_wmrng()
- end
- emu.frameadvance()
- end
- while true do
- frame()
- end
- end
- ff7_wmtris_main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement