Guest User

Untitled

a guest
Mar 27th, 2024
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.43 KB | None | 0 0
  1. local hotkeys = require("Hotkeys/Hotkeys")
  2. local default_settings = {
  3. weapon_table = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } },
  4. skill_table = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } },
  5. now_skill_table = 1,
  6. hotkeys = {
  7. ["Rearmament"] = "E",
  8. ["Modifier"] = "Control",
  9. },
  10. }
  11.  
  12.  
  13. local function recurse_def_settings(tbl, defaults_tbl)
  14. for key, value in pairs(defaults_tbl) do
  15. if type(tbl[key]) ~= type(value) then
  16. if type(value) == "table" then
  17. tbl[key] = recurse_def_settings({}, value)
  18. else
  19. tbl[key] = value
  20. end
  21. elseif type(value) == "table" then
  22. tbl[key] = recurse_def_settings(tbl[key], value)
  23. end
  24. end
  25. return tbl
  26. end
  27. local settings = recurse_def_settings(json.load_file("RearmamentPlus.json") or {}, default_settings)
  28.  
  29. hotkeys.setup_hotkeys(settings.hotkeys)
  30.  
  31. local function isActiveLoadout(slot)
  32. if settings.weapon_table[slot][1] == 0 and settings.weapon_table[slot][2] == 0 then
  33. return false
  34. elseif settings.skill_table[slot][1] == 0 and settings.skill_table[slot][2] == 0 and settings.skill_table[slot][3] == 0 and settings.skill_table[slot][4] == 0 then
  35. return false
  36. else return true end
  37. end
  38.  
  39. local function getCurrentJob()
  40. return Human:get_JobContext():get_field("CurrentJob")
  41. end
  42.  
  43. local function switch_skill_table(skill_table_id)
  44. for i = 1, 4 do
  45. HumanSkillContext:setSkill(getCurrentJob(), settings.skill_table[skill_table_id][i], i - 1)
  46. end
  47. GuiManager:setupKeyGuideCustomSkill()
  48. end
  49.  
  50. local function switch_weapon_table(weapon_table_id)
  51. if settings.weapon_table[weapon_table_id][1] == 0 and settings.weapon_table[weapon_table_id][2] == 0 then return end
  52.  
  53. local job10Mgr = Human:call("get_Job10WeaponManager()")
  54. if not job10Mgr then return end
  55.  
  56. local holder = ManualPlayer:call("get_WeaponAndItemHolder()")
  57. if not holder then return end
  58.  
  59. local leftSlot = holder:call("get_LeftWeapon()")
  60. local rightSlot = holder:call("get_RightWeapon()")
  61.  
  62. job10Mgr:call("requestEquipToMainHolder(app.WeaponAndItemHolder.WeaponSlot, app.WeaponID)", leftSlot, settings.weapon_table[weapon_table_id][1])
  63. job10Mgr:call("requestEquipToMainHolder(app.WeaponAndItemHolder.WeaponSlot, app.WeaponID)", rightSlot, settings.weapon_table[weapon_table_id][2])
  64. job10Mgr:call("generateBodyEffect()")
  65. end
  66. -- sdk.get_managed_singleton('app.AppSingleton`1<app.CharacterManager>'):call('get_Instance'):call("get_ManualPlayer"):call("get_Human"):call("get_Job10WeaponManager()")
  67. -- :call("equipWeapon", 3176146805):call("equipWeapon(app.WeaponID)",3176146805)
  68. local function get_skill_table()
  69. local skill_list = {}
  70. for i = 1, 4 do
  71. skill_list[i] = HumanSkillContext:getSkillID(getCurrentJob(), i - 1)
  72. end
  73. return skill_list
  74. end
  75.  
  76. local function get_next_valid_loadout()
  77. local currentLoadout = settings.now_skill_table;
  78. local nextLoadout = 0
  79. if currentLoadout == 4 then
  80. nextLoadout = 1
  81. else
  82. nextLoadout = currentLoadout + 1
  83. end
  84.  
  85. settings.now_skill_table = nextLoadout
  86. json.dump_file("RearmamentPlus.json", settings)
  87.  
  88. return nextLoadout
  89. end
  90. local function get_total_loadouts()
  91. local count = 0
  92. if isActiveLoadout(1) then count = count + 1 end;
  93. if isActiveLoadout(2) then count = count + 1 end;
  94. if isActiveLoadout(3) then count = count + 1 end;
  95. if isActiveLoadout(4) then count = count + 1 end;
  96. return count
  97. end
  98.  
  99. re.on_frame(
  100. function()
  101. if not CharacterManagerSingleton then
  102. CharacterManagerSingleton = sdk.get_managed_singleton('app.AppSingleton`1<app.CharacterManager>')
  103.  
  104. if not CharacterManagerSingleton then return end
  105. end
  106.  
  107. if not CharacterManager then
  108. CharacterManager = CharacterManagerSingleton:call('get_Instance')
  109.  
  110. if not CharacterManager then return end
  111. end
  112.  
  113. if not GuiManager then
  114. GuiManager = sdk.get_managed_singleton('app.GuiManager')
  115.  
  116. if not GuiManager then return end
  117. end
  118.  
  119.  
  120. if not ManualPlayer then
  121. ManualPlayer = CharacterManager:call("get_ManualPlayer")
  122.  
  123. if not ManualPlayer then return end
  124. end
  125.  
  126. if not Human then
  127. Human = ManualPlayer:call("get_Human")
  128.  
  129. if not Human then return end
  130. end
  131.  
  132. if not HumanSkillContext then
  133. HumanSkillContext = Human:call("get_SkillContext")
  134.  
  135. if not HumanSkillContext then return end
  136. end
  137.  
  138. if getCurrentJob() == 10 then
  139. if hotkeys.check_hotkey("Modifier", true) or hotkeys.hotkeys["Modifier"] == "[Not Bound]" then
  140. if hotkeys.check_hotkey("Rearmament") then
  141. if get_total_loadouts() <= 1 then return end
  142.  
  143. local loadoutIndex = get_next_valid_loadout();
  144.  
  145. if not isActiveLoadout(loadoutIndex) then loadoutIndex = get_next_valid_loadout() end
  146.  
  147. switch_skill_table(loadoutIndex)
  148. switch_weapon_table(loadoutIndex)
  149. end
  150. end
  151. end
  152. end)
  153.  
  154. sdk.hook(
  155. sdk.find_type_definition('app.GuiManager'):get_method('OnChangeSceneType'),
  156. function() end,
  157. function()
  158. if CharacterManager then
  159. ManualPlayer = CharacterManager:call('get_ManualPlayer')
  160. end
  161. if ManualPlayer then
  162. Human = ManualPlayer:call('get_Human')
  163. end
  164. if Human then
  165. HumanSkillContext = Human:call('get_SkillContext')
  166. end
  167.  
  168. if HumanSkillContext then
  169. if getCurrentJob() == 10 then
  170. if isActiveLoadout(settings.now_skill_table) then
  171. switch_skill_table(settings.now_skill_table)
  172. switch_weapon_table(settings.now_skill_table)
  173. end
  174. end
  175. end
  176. end
  177. )
  178.  
  179. local function load_skills(skill_table_id)
  180. if getCurrentJob() ~= 10 then return end
  181.  
  182. local skill_list = {}
  183. for i = 1, 4 do
  184. skill_list[i] = HumanSkillContext:getSkillID(getCurrentJob(), i - 1)
  185. end
  186. settings.skill_table[skill_table_id] = skill_list
  187.  
  188. local weapon_list = {}
  189. weapon_list[1] = ManualPlayer:call("get_LeftWeaponID()")
  190. weapon_list[2] = ManualPlayer:call("get_RightWeaponID()")
  191.  
  192. settings.weapon_table[skill_table_id] = weapon_list
  193.  
  194. json.dump_file("RearmamentPlus.json", settings)
  195. end
  196.  
  197. local function clear_skills(skill_table_id)
  198. local skill_list = { 0, 0, 0, 0 }
  199. settings.skill_table[skill_table_id] = skill_list
  200.  
  201. local weapon_list = { 0, 0 }
  202. settings.weapon_table[skill_table_id] = weapon_list
  203.  
  204. json.dump_file("RearmamentPlus.json", settings)
  205. end
  206.  
  207. re.on_draw_ui(
  208. function()
  209. local changed
  210. if not HumanSkillContext then
  211. return
  212. end
  213.  
  214. if imgui.tree_node("Rearmament Plus") then
  215. if imgui.button("Reset to Defaults") then
  216. settings = recurse_def_settings({}, default_settings)
  217. hotkeys.reset_from_defaults_tbl(default_settings.hotkeys)
  218. clear_skills(1)
  219. clear_skills(2)
  220. clear_skills(3)
  221. clear_skills(4)
  222. end
  223. imgui.spacing()
  224. imgui.spacing()
  225. changed = hotkeys.hotkey_setter("Modifier")
  226. changed = hotkeys.hotkey_setter("Rearmament", "Modifier")
  227. imgui.spacing()
  228. imgui.spacing()
  229.  
  230.  
  231. if changed then
  232. hotkeys.update_hotkey_table(settings.hotkeys)
  233. json.dump_file("RearmamentPlus.json", settings)
  234. end
  235.  
  236. if imgui.tree_node("How to Use") then
  237. imgui.text("Basic Usage:")
  238. imgui.text("1. Equip the weapon and Skills you wish to save")
  239. imgui.text("2. Click Remember Loadout.")
  240. imgui.text("3. Use hotkey (You must have at least 2 loadouts).")
  241. imgui.new_line()
  242. imgui.text("NOTE: You can only set or swap skills as a Wayfarer.")
  243. imgui.new_line()
  244. imgui.text("For best results, equip the item and then")
  245. imgui.text("Exit the pause menu entirely before saving loadouts")
  246. imgui.tree_pop()
  247. end
  248.  
  249. imgui.spacing()
  250. imgui.spacing()
  251.  
  252. imgui.text("Save/Clear currently equipped Weapons and Skills:")
  253.  
  254. if isActiveLoadout(1) then
  255. imgui.text("[READY]")
  256. imgui.same_line()
  257. end
  258. if imgui.button("Save Loadout 1") then
  259. load_skills(1)
  260. end
  261. imgui.same_line()
  262. if imgui.button("Load Loadout 1") then
  263. if isActiveLoadout(1) then
  264. switch_skill_table(1)
  265. switch_weapon_table(1)
  266. end
  267. end
  268. imgui.same_line()
  269. if imgui.button("Clear Loadout 1") then
  270. clear_skills(1)
  271. end
  272. imgui.spacing()
  273.  
  274.  
  275. if isActiveLoadout(2) then
  276. imgui.text("[READY]")
  277. imgui.same_line()
  278. end
  279. if imgui.button("Save Loadout 2") then
  280. load_skills(2)
  281. end
  282. imgui.same_line()
  283. if imgui.button("Load Loadout 2") then
  284. if isActiveLoadout(2) then
  285. switch_skill_table(2)
  286. switch_weapon_table(2)
  287. end
  288. end
  289. imgui.same_line()
  290. if imgui.button("Clear Loadout 2") then
  291. clear_skills(2)
  292. end
  293. imgui.spacing()
  294.  
  295. if isActiveLoadout(3) then
  296. imgui.text("[READY]")
  297. imgui.same_line()
  298. end
  299. if imgui.button("Save Loadout 3") then
  300. load_skills(3)
  301. end
  302. imgui.same_line()
  303. if imgui.button("Load Loadout 3") then
  304. if isActiveLoadout(3) then
  305. switch_skill_table(3)
  306. switch_weapon_table(3)
  307. end
  308. end
  309. imgui.same_line()
  310. if imgui.button("Clear Loadout 3") then
  311. clear_skills(3)
  312. end
  313. imgui.spacing()
  314.  
  315. if isActiveLoadout(4) then
  316. imgui.text("[READY]")
  317. imgui.same_line()
  318. end
  319. if imgui.button("Save Loadout 4") then
  320. load_skills(4)
  321. end
  322. imgui.same_line()
  323. if imgui.button("Load Loadout 4") then
  324. if isActiveLoadout(4) then
  325. switch_skill_table(4)
  326. switch_weapon_table(4)
  327. end
  328. end
  329. imgui.same_line()
  330. if imgui.button("Clear Loadout 4") then
  331. clear_skills(4)
  332. end
  333. imgui.spacing()
  334.  
  335. imgui.tree_pop()
  336. end
  337. end)
  338.  
Advertisement
Add Comment
Please, Sign In to add comment