Advertisement
Israel007

[GTA SA] In-Game Commands Changer

Jan 16th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.86 KB | None | 0 0
  1. local activation_cheat = "CHANGE"
  2. local reload_cheat     = "CRLD"
  3.  
  4. script_author("Israel")
  5. script_name("In-Game Commands Changer")
  6. script_description("Changes commands (cheats, game keys and virtual keys) of scripts (cs, cm and scm) without exit the game.")
  7. script_url("https://www.mixmods.com.br/2017/03/in-game-key-changer-mudar-trocar-escolher-comandos-mods.html")
  8.  
  9. local gk  = require "game/keys"
  10. local vk  = require "vkeys"
  11.  
  12. local onfoot = gk.player
  13. local gk_names = {
  14.     "Left Right", "Forward Backward",
  15.     "Special CTRL Left Right", "Special CTRL UP Down",
  16.     "Action secondary fire",
  17.     "Previous weapon zoom in", "Aim weapon", "Next weapon zoom out",
  18.     "Group CTRL forward", "Group CTRL back",
  19.     "Conversation NO", "Conversation YES",
  20.     "Not exist",
  21.     "Change camera",
  22.     "Jump", "Enter vehicle", "Sprint", "Fire", "Crouch",
  23.     "Look behind"
  24. }
  25.  
  26. local scripts_names, scripts_paths = {}, {}
  27.  
  28. function main()    
  29.     while true do
  30.         findScripts(getGameDirectory() .. "\\cleo")
  31.         findScripts(getGameDirectory() .. "\\modloader")
  32.  
  33.         setGxtEntry("IJ_TTL",  "Commands Changer") --> Panel title
  34.         setGxtEntry("IJ_KH",   "~y~Alterar Key")   --> Column header
  35.         setGxtEntry("IJ_CH",   "~y~Alterar Cheat") --> Column header
  36.         setGxtEntry("IJ_CK",   "Deseja alterar")   --> Key or Cheat
  37.         setGxtEntry("IJ_CKK",  "Key")              --> Key
  38.         setGxtEntry("IJ_CKC",  "Cheat")            --> Cheat
  39.         setGxtEntry("IJ_HK",   "Erro")             --> No keys error header
  40.         setGxtEntry("IJ_CS",   "Confirmar")        --> Key change confirmation
  41.         setGxtEntry("IJ_CN",   "Cancelar")         --> Key change cancel
  42.         setGxtEntry("IJ_P1",   "Pad 1")            --> Pad Selection (1)
  43.         setGxtEntry("IJ_P2",   "Pad 2")            --> Pad Selection (2)
  44.         setGxtEntry("IJ_MSG",  "Pressione a nova Tecla !") --> Key change help msg
  45.         setGxtEntry("IJ_MSG2", "Use ~y~ENTER~s~ para confirmar.~n~Delete tudo para cancelar.") --> Cheat change help msg
  46.        
  47.         local sc_pages = math.floor(#scripts_names / 10) + ((#scripts_names % 10) ~= 0 and 1 or 0)
  48.  
  49.         -- Add scripts panel headers FXT Keys
  50.         for i = 1, sc_pages do
  51.             setGxtEntry("IJ_H" .. i, "Scripts " .. i .. '/' .. sc_pages)
  52.         end
  53.  
  54.         -- Add scripts FXT Keys
  55.         for i, v in ipairs(scripts_names) do
  56.             setGxtEntry("IJ_S" .. i, v)
  57.         end
  58.        
  59.         --/--> MAIN LOOP <--\--
  60.         repeat
  61.             wait(0)
  62.            
  63.             if testCheat(activation_cheat) then
  64.                 if #scripts_names == 0 then
  65.                     printStringNow("~r~Nenhum script encontrado !", 2000)
  66.                 else               
  67.                     setPlayerControl(PLAYER_HANDLE, false)
  68.                     printHelpForever("WARDH3") --> Help text
  69.  
  70.                     local current_page = 1
  71.                     menu = createMenu("IJ_TTL", 20.0, 115.0, 250.0, 1, true, true, 1)
  72.  
  73.                     -- Script selection panel
  74.                     while not isButtonPressed(PLAYER_HANDLE, onfoot.ENTERVEHICLE) do
  75.                         wait(0)
  76.  
  77.                         local sc, lvl = {}, 10
  78.  
  79.                         if current_page == sc_pages and #scripts_names % 10 ~= 0 then
  80.                             lvl = #scripts_names % 10
  81.                         end
  82.                         for i = 1, 10 do
  83.                             sc[i] = (i <= lvl) and "IJ_S" .. 10 * (current_page - 1) + i or "DUMMY"
  84.                         end
  85.  
  86.                         setMenuColumn(menu, 0, "IJ_H" .. current_page, sc[1], sc[2], sc[3], sc[4], sc[5], sc[6], sc[7], sc[8], sc[9], sc[10])
  87.                         setActiveMenuItem(menu, 0)
  88.  
  89.                         while not isButtonPressed(PLAYER_HANDLE, onfoot.ENTERVEHICLE) do
  90.                             wait(0)
  91.  
  92.                             if wasKeyPressed(vk.VK_LEFT) then
  93.                                 if current_page > 1 then current_page = current_page - 1 else current_page = sc_pages end
  94.                                 break
  95.                             elseif wasKeyPressed(vk.VK_RIGHT) then
  96.                                 if current_page < sc_pages then current_page = current_page + 1 else current_page = 1 end
  97.                                 break
  98.                             end
  99.  
  100.                             if isButtonPressed(PLAYER_HANDLE, onfoot.SPRINT) then
  101.                                 while isButtonPressed(PLAYER_HANDLE, onfoot.SPRINT) do wait(0) end
  102.                                 decompileScript(10 * (current_page - 1) + (getMenuItemSelected(menu) + 1))
  103.                                 break
  104.                             end
  105.  
  106.                             printStringNow("Use ~<~ e ~>~ para navegar entre as paginas.", 300)
  107.                         end
  108.                     end
  109.                    
  110.                     while isButtonPressed(PLAYER_HANDLE, onfoot.ENTERVEHICLE) do wait(0) end
  111.                    
  112.                     setPlayerControl(PLAYER_HANDLE, true)
  113.                     clearHelp()
  114.                     deleteMenu(menu)
  115.                 end
  116.             end
  117.         until testCheat(reload_cheat)
  118.  
  119.         scripts_names, scripts_paths = {}, {} --> Clear scripts lists
  120.         printStringNow("~y~In-Game Key Changer~s~ foi recarregado !", 2000) --> Reload msg
  121.     end
  122. end
  123.  
  124. function findScripts(path)
  125.     local loaded, lib = loadDynamicLibrary("kernel32.dll")
  126.     local result, proc = getDynamicLibraryProcedure("GetFileAttributesA", lib)
  127.    
  128.     local hFind, filename = findFirstFile(path .. "\\*")
  129.    
  130.     while filename do
  131.         if filename ~= "." and filename ~= ".." then
  132.             local fullpath = path .. "\\" .. filename
  133.             local attr = callFunction(proc, 1, 1, fullpath)
  134.  
  135.             if attr == 0x10 then --> Directory
  136.                 findScripts(fullpath)
  137.             elseif attr == 0x20 then --> File
  138.                 if filename:sub(-3) == ".cs" or filename:sub(-3) == ".cm" or filename:sub(-4) == ".scm" then --> Filter
  139.                     if filename:len() > 29 then
  140.                         filename = filename:sub(1, 30) .. " ..."
  141.                     end
  142.                     scripts_names[#scripts_names + 1] = filename
  143.                     scripts_paths[#scripts_paths + 1] = fullpath
  144.                 end
  145.             end
  146.         end
  147.        
  148.         filename = findNextFile(hFind)
  149.     end
  150. end
  151.  
  152. function decompileScript(index)
  153.     currentScriptPath = scripts_paths[index]
  154.  
  155.     local input = io.open(currentScriptPath, "rb")
  156.     sc_struct = input:read("*all")
  157.     sc_struct = sc_struct:tohex()
  158.  
  159.     sc_end = string.find(sc_struct, "56415200F1020000") --> SB extra info start point
  160.     if sc_end == nil then
  161.         sc_end = sc_struct:len()
  162.     end
  163.  
  164.     store_commands_pos()   
  165.     input:close()
  166.  
  167.     while not isButtonPressed(PLAYER_HANDLE, onfoot.ENTERVEHICLE) do
  168.         setMenuColumn(menu, 0, "IJ_CK", "IJ_CKK", "IJ_CKC")
  169.         setActiveMenuItem(menu, 0)
  170.        
  171.         while not isButtonPressed(PLAYER_HANDLE, onfoot.ENTERVEHICLE) do
  172.             wait(0)
  173.            
  174.             if isButtonPressed(PLAYER_HANDLE, onfoot.SPRINT) then
  175.                 if getMenuItemSelected(menu) == 0 then
  176.                     k_pages = math.floor(#keys_pos / 10) + ((#keys_pos % 10) ~= 0 and 1 or 0)
  177.                    
  178.                     for i = 1, k_pages do
  179.                         setGxtEntry("IJ_HK" .. i, "Keys " .. i .. '/' .. k_pages)
  180.                     end
  181.                     keysMenu()
  182.                     break
  183.                 else
  184.                     c_pages = math.floor(#cheats_pos / 10) + ((#cheats_pos % 10) ~= 0 and 1 or 0)
  185.                    
  186.                     for i = 1, c_pages do
  187.                         setGxtEntry("IJ_HC" .. i, "Cheats " .. i .. '/' .. c_pages)
  188.                     end
  189.                     cheatsMenu()
  190.                     break
  191.                 end
  192.             end
  193.            
  194.             printStringNow("Selecione o tipo de comando que deseja alterar.", 150)
  195.         end
  196.     end
  197.    
  198.     keys_pos = {} --> Clear
  199.     while isButtonPressed(PLAYER_HANDLE, onfoot.ENTERVEHICLE) do wait(0) end
  200. end
  201.  
  202. function store_commands_pos()
  203.     cheats_pos = {}
  204.     keys_pos = {}
  205.    
  206.     for i = 1, sc_end, 2 do
  207.         -- Virtual Keys
  208.         if sc_struct:sub(i, i + 5) == "B00A04" or   --> 0AB0: IS_KEY_PRESSED
  209.         sc_struct:sub(i, i + 5) == "B08A04" then    --> 8AB0: NOT IS_KEY_PRESSED
  210.             keys_pos[#keys_pos + 1] = i + 6
  211.  
  212.             local vkey_id = string.todec(sc_struct:sub(i + 6, i + 7)) * 1
  213.             setGxtEntry("IJ_B" .. #keys_pos, vk.id_to_name(vkey_id))
  214.         end
  215.     end
  216.  
  217.     gk_Spos = #keys_pos
  218.    
  219.     for i = 1, sc_end, 2 do
  220.         -- Game Keys
  221.         if (sc_struct:sub(i, i + 5) == "E10004" or  --> 00E1: IS_BUTTON_PRESSED
  222.         sc_struct:sub(i, i + 5) == "E18004") and    --> 80E1: NOT IS_BUTTON_PRESSED
  223.         sc_struct:sub(i + 8, i + 9) == "04" then
  224.             keys_pos[#keys_pos + 1] = i + 10
  225.  
  226.             local gkey = string.todec(sc_struct:sub(i + 10, i + 11)) + 1
  227.             setGxtEntry("IJ_B" .. #keys_pos, gk_names[gkey])
  228.         end
  229.        
  230.         -- Cheats
  231.         if sc_struct:sub(i, i + 5) == "DC0A0E" or   --> 0ADC: TEST_CHEAT
  232.         sc_struct:sub(i, i + 5) == "DC8A0E" then    --> 8ADC: NOT TEST_CHEAT
  233.             cheats_pos[#cheats_pos + 1] = i + 8
  234.            
  235.             local cheat_len = string.todec(sc_struct:sub(i + 6, i + 7))
  236.             str_cheat = string.upper(string.fromhex(sc_struct:sub(i + 8, i + 7 + (cheat_len * 2))))
  237.            
  238.             setGxtEntry("IJ_C" .. #cheats_pos, str_cheat)
  239.         end
  240.     end
  241. end
  242.  
  243. function keysMenu()
  244.     local keys, current_page = {}, 1
  245.  
  246.     while not isButtonPressed(PLAYER_HANDLE, onfoot.ENTERVEHICLE) do
  247.         wait(0)
  248.  
  249.         local lvl = 10
  250.         if current_page == k_pages and #keys_pos % 10 ~= 0 then
  251.             lvl = #keys_pos % 10
  252.         end
  253.         for i = 1, 10 do
  254.             keys[i] = (i <= lvl) and "IJ_B" .. 10 * (current_page - 1) + i or "DUMMY"
  255.         end
  256.  
  257.         if #keys_pos ~= 0 then
  258.             setMenuColumn(menu, 0, "IJ_HK" .. current_page, keys[1], keys[2], keys[3], keys[4], keys[5], keys[6], keys[7], keys[8], keys[9], keys[10])
  259.             setActiveMenuItem(menu, 0)
  260.         end
  261.        
  262.         while isButtonPressed(PLAYER_HANDLE, onfoot.SPRINT) do wait(0) end
  263.  
  264.         while not isButtonPressed(PLAYER_HANDLE, onfoot.ENTERVEHICLE) do
  265.             wait(0)
  266.  
  267.             if wasKeyPressed(vk.VK_LEFT) then
  268.                 if current_page > 1 then current_page = current_page - 1 else current_page = k_pages end
  269.                 break
  270.             elseif wasKeyPressed(vk.VK_RIGHT) then
  271.                 if current_page < k_pages then current_page = current_page + 1 else current_page = 1 end
  272.                 break
  273.             end
  274.  
  275.             if isButtonPressed(PLAYER_HANDLE, onfoot.SPRINT) then
  276.                 if #keys_pos ~= 0 then     
  277.                     changeKey(current_page, (getMenuItemSelected(menu) + (current_page - 1) * 10 >= gk_Spos) and 1 or 2)
  278.  
  279.                     while isButtonPressed(PLAYER_HANDLE, onfoot.ENTERVEHICLE) do wait(0) end
  280.                     break
  281.                 end
  282.             end
  283.  
  284.             if #keys_pos == 0 then
  285.                 setGxtEntry("IJ_F", "~r~Nenhuma Tecla")
  286.                 setMenuColumn(menu, 0, "IJ_HK", "IJ_F")
  287.                
  288.                 while not isButtonPressed(PLAYER_HANDLE, onfoot.ENTERVEHICLE) do
  289.                     wait(0)
  290.                     printStringNow("~r~Undefined", 300)
  291.                 end
  292.             else
  293.                 local msg = "Use ~<~ e ~>~ para navegar entre as paginas.~n~KeyType: "
  294.                
  295.                 if getMenuItemSelected(menu) + (current_page - 1) * 10 >= gk_Spos then
  296.                     local pos = keys_pos[(getMenuItemSelected(menu) + (current_page - 1) * 10) + 1] - 3
  297.                     printStringNow(msg .. "~g~Game Key~n~~s~Pad: ~y~" .. sc_struct:sub(pos, pos) + 1, 300)
  298.                 else           
  299.                     printStringNow(msg .. "~b~Virtual Key", 300)
  300.                 end
  301.             end
  302.         end
  303.     end
  304.  
  305.     while isButtonPressed(PLAYER_HANDLE, onfoot.ENTERVEHICLE) do wait(0) end
  306. end
  307.  
  308. function changeKey(page, key_type)
  309.     local selected = getMenuItemSelected(menu)
  310.  
  311.     while isButtonPressed(PLAYER_HANDLE, onfoot.SPRINT) do wait(0) end
  312.    
  313.     setMenuColumn(menu, 0, "IJ_KH", "IJ_B" .. 10 * (page - 1) + (selected + 1))
  314.     setActiveMenuItem(menu, 0)
  315.  
  316.     printHelpForever("IJ_MSG") --> Help message
  317.  
  318.     while true do
  319.         wait(0)
  320.  
  321.         for i = 0, (key_type == 1) and 19 or 0xFF do
  322.             if key_type == 1 then
  323.                 if isButtonPressed(PLAYER_HANDLE, i) then
  324.                     while isButtonPressed(PLAYER_HANDLE, i) do wait(0) end
  325.  
  326.                     inline(page, key_type, selected, i)
  327.                     return
  328.                 end
  329.             else
  330.                 if vk.id_to_name(i) ~= nil and wasKeyPressed(i) then
  331.                     while wasKeyPressed(i) do wait(0) end
  332.  
  333.                     inline(page, key_type, selected, i)
  334.                     return
  335.                 end
  336.             end
  337.         end
  338.        
  339.         printStringNow("~y~Aguardando nova tecla...", 150)
  340.     end
  341. end
  342.  
  343. -- Confirmation of change and script write
  344. function inline(page, key_type, selected, i)
  345.     local new = (key_type == 1) and gk_names[i + 1] or vk.id_to_name(i)
  346.     local pad
  347.    
  348.     printHelpForever("WARDH3") --> Help
  349.  
  350.     setGxtEntry("IJ_KHK", "Alterar para ~g~\"" .. new .. "\"~s~ ?")
  351.  
  352.     if key_type == 1 then
  353.         setMenuColumn(menu, 0, "IJ_KHK", "IJ_P1", "IJ_P2", "IJ_CN")
  354.     else
  355.         setMenuColumn(menu, 0, "IJ_KHK", "IJ_CS", "IJ_CN")
  356.     end
  357.    
  358.     while isButtonPressed(PLAYER_HANDLE, onfoot.ENTERVEHICLE) or isButtonPressed(PLAYER_HANDLE, onfoot.SPRINT) do wait(0) end
  359.  
  360.     while true do
  361.         wait(0)
  362.  
  363.         if isButtonPressed(PLAYER_HANDLE, onfoot.ENTERVEHICLE) then
  364.             return
  365.         elseif isButtonPressed(PLAYER_HANDLE, onfoot.SPRINT) then
  366.             pad = "0" .. getMenuItemSelected(menu)
  367.             if getMenuItemSelected(menu) == 0 then
  368.                 break
  369.             elseif getMenuItemSelected(menu) == 1 then
  370.                 if key_type == 1 then
  371.                     break
  372.                 end
  373.                 return
  374.             else return
  375.             end
  376.         end
  377.        
  378.         if key_type == 1 then
  379.             printStringNow("~y~Selecione um pad para confirmar a alteracao.", 150)
  380.         else
  381.             printStringNow("~y~Confirme a alteracao.", 150)
  382.         end
  383.     end
  384.  
  385.     local new_value = string.format("%02X", i)
  386.     local pos = keys_pos[(selected + (page - 1) * 10) + 1]
  387.    
  388.     sc_struct = sc_struct:sub(1, pos - 1) .. new_value .. sc_struct:sub(pos + 2)
  389.     if key_type == 1 then
  390.         sc_struct = sc_struct:sub(1, pos - 5) .. pad .. sc_struct:sub(pos - 2)
  391.     end
  392.  
  393.     local output = io.open(currentScriptPath, "wb")
  394.     output:write(sc_struct:fromhex())
  395.     output:close()
  396.  
  397.     setGxtEntry("IJ_B" .. (selected + (page - 1) * 10) + 1, (key_type == 1) and gk_names[i + 1] or vk.id_to_name(i))
  398. end
  399.  
  400. function cheatsMenu()
  401.     local cheats, current_page = {}, 1
  402.  
  403.     while not isButtonPressed(PLAYER_HANDLE, onfoot.ENTERVEHICLE) do
  404.         wait(0)
  405.  
  406.         local lvl = 10
  407.         if current_page == c_pages and #cheats_pos % 10 ~= 0 then
  408.             lvl = #cheats_pos % 10
  409.         end
  410.         for i = 1, 10 do
  411.             cheats[i] = (i <= lvl) and "IJ_C" .. 10 * (current_page - 1) + i or "DUMMY"
  412.         end
  413.  
  414.         if #cheats_pos ~= 0 then
  415.             setMenuColumn(menu, 0, "IJ_HC" .. current_page, cheats[1], cheats[2], cheats[3], cheats[4], cheats[5], cheats[6], cheats[7], cheats[8], cheats[9], cheats[10])
  416.             setActiveMenuItem(menu, 0)
  417.         end
  418.        
  419.         while isButtonPressed(PLAYER_HANDLE, onfoot.SPRINT) do wait(0) end
  420.  
  421.         while not isButtonPressed(PLAYER_HANDLE, onfoot.ENTERVEHICLE) do
  422.             wait(0)
  423.  
  424.             if wasKeyPressed(vk.VK_LEFT) then
  425.                 if current_page > 1 then current_page = current_page - 1 else current_page = c_pages end
  426.                 break
  427.             elseif wasKeyPressed(vk.VK_RIGHT) then
  428.                 if current_page < c_pages then current_page = current_page + 1 else current_page = 1 end
  429.                 break
  430.             end
  431.  
  432.             if isButtonPressed(PLAYER_HANDLE, onfoot.SPRINT) then
  433.                 if #cheats_pos ~= 0 then       
  434.                     changeCheat(current_page)
  435.  
  436.                     while isButtonPressed(PLAYER_HANDLE, onfoot.ENTERVEHICLE) do wait(0) end
  437.                     break
  438.                 end
  439.             end
  440.  
  441.             if #cheats_pos == 0 then
  442.                 setGxtEntry("IJ_F2", "~r~Nenhum Cheat")
  443.                 setMenuColumn(menu, 0, "IJ_HK", "IJ_F2")
  444.                
  445.                 while not isButtonPressed(PLAYER_HANDLE, onfoot.ENTERVEHICLE) do
  446.                     wait(0)
  447.                     printStringNow("~r~Undefined", 300)
  448.                 end
  449.             else
  450.                 printStringNow("Use ~<~ e ~>~ para navegar entre as paginas.", 300)        
  451.             end
  452.         end
  453.     end
  454.  
  455.     while isButtonPressed(PLAYER_HANDLE, onfoot.ENTERVEHICLE) do wait(0) end   
  456. end
  457.  
  458. function changeCheat(page)
  459.     local selected = getMenuItemSelected(menu)
  460.  
  461.     while isButtonPressed(PLAYER_HANDLE, onfoot.SPRINT) do wait(0) end
  462.    
  463.     setMenuColumn(menu, 0, "IJ_CH", "IJ_C" .. 10 * (page - 1) + (selected + 1))
  464.     setActiveMenuItem(menu, 0)
  465.  
  466.     printHelpForever("IJ_MSG2") --> Help message
  467.  
  468.     local new_cheat, fake_cheat = "", ""
  469.     while not wasKeyPressed(vk.VK_RETURN) do
  470.         wait(0)
  471.  
  472.         -- Alpha (0~9)
  473.         for i = 0x30, 0x39 do
  474.             if wasKeyPressed(i) and new_cheat:len() < 29 then
  475.                 fake_cheat = new_cheat .. string.char(i)
  476.                 new_cheat = fake_cheat
  477.             end
  478.         end
  479.         -- Numpad (0~9)
  480.         for i = 0x60, 0x69 do
  481.             if wasKeyPressed(i) and new_cheat:len() < 29 then
  482.                 fake_cheat = new_cheat .. string.char(i - 0x30)
  483.                 new_cheat = fake_cheat
  484.             end
  485.         end
  486.         -- A~Z
  487.         for i = 0x41, 0x5A do
  488.             if wasKeyPressed(i) and new_cheat:len() < 29 then
  489.                 fake_cheat = new_cheat .. string.char(i)
  490.                 new_cheat = fake_cheat
  491.             end
  492.         end
  493.         -- Space
  494.         if wasKeyPressed(vk.VK_SPACE) and new_cheat:len() < 29 then
  495.             fake_cheat = new_cheat .. string.char(0xFF)
  496.             new_cheat = new_cheat .. string.char(0x20)
  497.         end
  498.         -- Backspace
  499.         if wasKeyPressed(vk.VK_BACK) then
  500.             if new_cheat:len() > 0 then
  501.                 fake_cheat = new_cheat:sub(1, new_cheat:len() - 1)
  502.                 new_cheat = fake_cheat
  503.             else
  504.                 break
  505.             end
  506.         end
  507.        
  508.         printStringNow("~y~Novo Cheat:~s~ " .. fake_cheat .. "~n~~y~Length: ~s~" .. new_cheat:len() .. "/29", 150)
  509.     end
  510.    
  511.     if wasKeyPressed(vk.VK_RETURN) and new_cheat:len() > 0 then
  512.         local new_value = new_cheat:tohex()
  513.         local pos = cheats_pos[(selected + (page - 1) * 10) + 1]
  514.                
  515.         local cheat_len = string.todec(sc_struct:sub(pos - 2, pos - 1))
  516.        
  517.         sc_struct = sc_struct:sub(1, pos + 1) .. new_value .. sc_struct:sub(pos + (cheat_len * 2))
  518.         sc_struct = sc_struct:sub(1, pos - 3) .. string.format("%02X", new_cheat:len()) .. sc_struct:sub(pos + 2)
  519.        
  520.         local value = new_cheat:len() - cheat_len
  521.        
  522.         for i = 1, sc_end, 2 do
  523.             if sc_struct:sub(i, i + 5) == "4D0001" --> 004D: GOTO_IF_FALSE
  524.             or sc_struct:sub(i, i + 5) == "020001" --> 0002: GOTO
  525.             or sc_struct:sub(i, i + 5) == "500001" --> 0050: GOSUB
  526.             or sc_struct:sub(i, i + 5) == "A00A01" --> 0AA0: ELSE_GOSUB
  527.             or sc_struct:sub(i, i + 5) == "710801" --> 0871: SWITCH_START
  528.             or sc_struct:sub(i, i + 5) == "720801" --> 0872: SWITCH_CONTINUED
  529.             or sc_struct:sub(i, i + 5) == "B10A01" --> 0AB1: CLEO_CALL
  530.             or sc_struct:sub(i, i + 5) == "070701" --> 0707: SKIP_CUTSCENE_START_INTERNAL
  531.             or sc_struct:sub(i, i + 5) == "C60A01" --> 0AC6: GET_LABEL_POINTER
  532.             or sc_struct:sub(i, i + 5) == "4F0001" --> 004F: START_NEW_SCRIPT
  533.             or sc_struct:sub(i, i + 5) == "D70001" then --> 00D7: LAUNCH_MISSION
  534.                 local prev = sc_struct:sub(i + 12, i + 13) .. sc_struct:sub(i + 10, i + 11) .. sc_struct:sub(i + 8, i + 9) .. sc_struct:sub(i + 6, i + 7)
  535.                 prev = string.format("%08X", tonumber("0x" .. prev) - value)
  536.                
  537.                 local label_point = string.format("%i", 0xFFFFFFFF - tonumber("0x" .. prev))
  538.                 prev = prev:sub(7, 8) .. prev:sub(5, 6) .. prev:sub(3, 4) .. prev:sub(1, 2)
  539.                
  540.                 if tonumber(label_point) > math.floor(pos / 2) then
  541.                     sc_struct = sc_struct:sub(1, i + 5) .. prev .. sc_struct:sub(i + 14)
  542.                 end
  543.             end
  544.         end
  545.        
  546.         local output = io.open(currentScriptPath, "wb")
  547.         output:write(sc_struct:fromhex())
  548.         output:close()
  549.  
  550.         setGxtEntry("IJ_C" .. (selected + (page - 1) * 10) + 1, new_cheat)
  551.     end
  552.  
  553.     store_commands_pos()
  554.    
  555.     printHelpForever("WARDH3") --> Help text
  556.     while wasKeyPressed(vk.VK_RETURN) do wait(0) end
  557. end
  558.  
  559. -- String funcs
  560. function string.todec(str)
  561.     return (str:gsub("..", function (cc)
  562.         return tonumber(cc, 16)
  563.     end))
  564. end
  565. function string.tohex(str)
  566.     return (str:gsub(".", function (c)
  567.         return string.format("%02X", string.byte(c))
  568.     end))
  569. end
  570. function string.fromhex(str)
  571.     return (str:gsub("..", function (cc)
  572.         return string.char(tonumber(cc, 16))
  573.     end))
  574. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement