From 67f081b1a992f43814d996266f0002297f60d67b Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Sun, 28 Dec 2025 12:42:46 +0100 Subject: [PATCH] rft fucking works --- plugin.lua | 6 +++++- scripts/1-rft.lua | 36 ++++++++++-------------------------- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/plugin.lua b/plugin.lua index 7e05918..32d74e0 100644 --- a/plugin.lua +++ b/plugin.lua @@ -350,4 +350,8 @@ function set_oda_id_data_rds2(oda_id, data) end ---@param data integer ---@param file_related boolean ---@return integer oda_id -function register_oda_rds2(aid, data, file_related) end \ No newline at end of file +function register_oda_rds2(aid, data, file_related) end + +---Loads the file into RFT and initializes it if needed, note that this needs RDR2 mode 2 +---@param path string +function load_rft_file(path) end diff --git a/scripts/1-rft.lua b/scripts/1-rft.lua index 33805a2..9a84111 100644 --- a/scripts/1-rft.lua +++ b/scripts/1-rft.lua @@ -7,30 +7,21 @@ local function start_rft() if _Rft_oda_id == nil then _Rft_oda_id = register_oda_rds2(0xFF7F, 0, true) set_oda_handler_rds2(_Rft_oda_id, function () - if #_Rft_file == 0 then - return false, 0, 0, 0, 0 - end + if #_Rft_file == 0 then return false, 0, 0, 0, 0 end local total_segments = math.ceil(#_Rft_file / 5) local seg = _Rft_file_segment local base = seg * 5 + 1 - local function b(i) - return string.byte(_Rft_file, base + i) or 0 - end + local function b(i) return string.byte(_Rft_file, base + i) or 0 end - local word1 = - (((_Rft_toggle and 1 or 0) << 7) | - ((seg >> 8) & 0x7F)) + local word1 = (((_Rft_toggle and 1 or 0) << 7) | ((seg >> 8) & 0x7F)) - local word2 = - ((seg & 0xFF) << 8) | b(0) + local word2 = ((seg & 0xFF) << 8) | b(0) - local word3 = - (b(1) << 8) | b(2) + local word3 = (b(1) << 8) | b(2) - local word4 = - (b(3) << 8) | b(4) + local word4 = (b(3) << 8) | b(4) _Rft_file_segment = seg + 1 if _Rft_file_segment >= total_segments then @@ -40,23 +31,16 @@ local function start_rft() return true, (2 << 12) | word1, word2, word3, word4 end) - set_rds2_mode(2) end end -local function load_rft_file() - local file = io.open("/tmp/rft_test", "rb") +function load_rft_file(path) + local file = io.open(path, "rb") if not file then error("Could not open file") end _Rft_file = file:read("*a") file:close() if #_Rft_file > 262143 then error("The file is too large", 2) end if _Rft_oda_id == nil then start_rft() end ---@diagnostic disable-next-line: param-type-mismatch - set_oda_id_data_rds2(_Rft_oda_id, #_Rft_file | 48 << 18) --- 48 for testing, change to 0 or something else in the future -end - --- local _old_on_state_rft = on_state --- function on_state() --- start_rft() --- if type(_old_on_state_rft) == "function" then _old_on_state_rft() end --- end \ No newline at end of file + set_oda_id_data_rds2(_Rft_oda_id, #_Rft_file | 0 << 18) +end \ No newline at end of file