Advertisement
justgamingaway

AutoDango.lua

Nov 13th, 2024 (edited)
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.09 KB | Gaming | 0 0
  1. local allManagersRetrieved = false
  2. local gm = {}
  3. gm.FacilityDataManager = {}
  4. gm.FacilityDataManager.n = "snow.data.FacilityDataManager"
  5. gm.ProgressManager = {}
  6. gm.ProgressManager.n = "snow.progress.ProgressManager"
  7. gm.PlayerManager = {}
  8. gm.PlayerManager.n = "snow.player.PlayerManager"
  9. gm.ChatManager = {}
  10. gm.ChatManager.n = "snow.gui.ChatManager"
  11. gm.ContentsIdDataManager = {}
  12. gm.ContentsIdDataManager.n = "snow.data.ContentsIdDataManager"
  13. gm.QuestManager = {}
  14. gm.QuestManager.n = "snow.QuestManager"
  15.  
  16. for i,v in pairs(gm) do
  17.     v.d = sdk.get_managed_singleton(v.n)
  18. end
  19.  
  20.  
  21. -- == -- == -- == -- == --
  22.  
  23.  
  24. local DataShortcut = sdk.create_instance("snow.data.DataShortcut", true):add_ref()
  25.  
  26. local isOrdering = false
  27.  
  28. local settings = json.load_file("AutoDangoSettings.json") or {}
  29. settings.Enabled = settings.Enabled == nil and true or settings.Enabled
  30. settings.Sounds = settings.Sounds == nil and true or settings.Sounds
  31. settings.UseVoucher = settings.UseVoucher == nil and false or settings.UseVoucher
  32. settings.UseHoppingSkewers = settings.UseHoppingSkewers == nil and false or settings.UseHoppingSkewers
  33. settings.Points = settings.Points == nil and false or settings.Points
  34. settings.EnableNotification = settings.EnableNotification == nil and true or settings.EnableNotification
  35. settings.CurrentSet = settings.CurrentSet or 1
  36. --settings.CurrentSet = math.floor(settings.CurrentSet)
  37.  
  38.  
  39. -- == -- == -- == -- == --
  40.  
  41.  
  42. local function CreateOrder(setID)
  43.     local Kitchen = gm.FacilityDataManager.d:call("get_Kitchen")
  44.     if not Kitchen then return end
  45.     Kitchen = Kitchen:call("get_MealFunc")
  46.     if not Kitchen then return end
  47.  
  48.     return Kitchen:call("getMySetList"):call("get_Item", setID - 1)
  49. end
  50.  
  51. local function OrderFood(order)
  52.     -- Variables here
  53.     local Kitchen = gm.FacilityDataManager.d:call("get_Kitchen")
  54.  
  55.     -- No Kitchen means no go
  56.     if not Kitchen then return end
  57.     Kitchen = Kitchen:call("get_MealFunc")
  58.     if not Kitchen then return end
  59.  
  60.     local Player = gm.PlayerManager.d:call("findMasterPlayer")
  61.     local PlayerData = Player:get_field("_refPlayerData")
  62.     local PlayerSkillData = Player:get_field("_refPlayerSkillList")
  63.     local PlayerKitchenSkillData = PlayerSkillData:call("get_KitchenSkillData")
  64.  
  65.     local DataManager = sdk.get_managed_singleton("snow.data.DataManager");
  66.     local ItemBox = DataManager:get_field("_PlItemBox")
  67.  
  68.     local facilityLevel = Kitchen:call("get_FacilityLv")
  69.  
  70.     local Vouchers = gm.ContentsIdDataManager.d:call("getItemData", 0x410007c)
  71.     local VoucherCount = Vouchers:call("getCountInBox")
  72.  
  73.     local OrderName = order:call("get_OrderName")
  74.  
  75.     local Message = "<COL YEL>Automatically ate " .. OrderName .. (settings.UseVoucher and (VoucherCount > 0 and (" with a voucher (" .. VoucherCount .. " remaining)") or ", but you are out of vouchers") or "") .. ".</COL>"
  76.  
  77.     local lscount = 0
  78.  
  79.     -- Daily Dango does not seem to reset
  80.     Kitchen:call("resetDailyDango")
  81.  
  82.     -- If the kitchen timer is 'on', return
  83.     if Kitchen:get_field("_AvailableWaitTimer") > 0.0 then
  84.             if settings.EnableNotification then
  85.                 gm.ChatManager.d:call("reqAddChatInfomation", "<COL RED>You have already eaten! Auto-Dango aborted.</COL>", settings.Sounds and 2289944406 or 0)
  86.             end
  87.             log.debug("AutoDango.lua --- Wait Timer (" .. Kitchen:call("get_WaitTime") .. "): Eaten already, skipping auto-eat.")
  88.         return
  89.     end
  90.  
  91.     -- If attempting to order from an empty set, return
  92.     if order:call("get__DangoId"):call("get_Item", 0) == 65 then
  93.         gm.ChatManager.d:call("reqAddChatInfomation", "<COL RED>Cannot order from an empty set.</COL>", settings.Sounds and 2412657311 or 0)
  94.  
  95.         log.debug("AutoDango.lua --- Error: Attempted to order from an empty set.")
  96.         return
  97.     end
  98.  
  99.     -- Voucher Check
  100.     if VoucherCount > 0 then
  101.         Kitchen:set_field("_MealTicketFlag", settings.UseVoucher)
  102.     else
  103.         Kitchen:set_field("_MealTicketFlag", false)
  104.     end
  105.  
  106.     order:set_field("IsSpecialSkewer", settings.UseHoppingSkewers)
  107.  
  108.     -- Create Food Order
  109.     isOrdering = true
  110.     Kitchen:call("order", order, settings.Points and 1 or 0, facilityLevel)
  111.     isOrdering = false
  112.  
  113.     -- Set Player Max Health / Stamina
  114.     PlayerData:set_field("_vitalMax", (100 + Kitchen:getVitalBuff(facilityLevel)))
  115.     PlayerData:set_field("_staminaMax", (3000 + (Kitchen:getStaminaBuff(facilityLevel) * 30)))
  116.  
  117.     Message = Message .. "\nHealth: <COL YEL>" .. PlayerData:get_field("_vitalMax") .. "</COL> Stamina: <COL YEL>" .. math.floor(PlayerData:get_field("_staminaMax") / 30) .. "</COL>"
  118.     Message = Message .. "\n<COL YEL>Skills activated:</COL>"
  119.  
  120.     log.debug("AutoDango.lua --- Dango Skills")
  121.  
  122.     -- Kitchen Skill Check
  123.     PlayerSkillData = Player:get_field("_refPlayerSkillList")
  124.     PlayerKitchenSkillData = PlayerSkillData:call("get_KitchenSkillData")
  125.     for i,v in pairs(PlayerKitchenSkillData:get_elements()) do
  126.         if v:get_field("_SkillId") ~= 0 then
  127.             Message = Message .. "\n  " .. DataShortcut:call("getName(snow.data.DataDef.PlKitchenSkillId)", v:get_field("_SkillId")) .. (settings.UseHoppingSkewers and (" <COL YEL>(lv " .. v:get_field("_SkillLv") .. ")</COL>") or "")
  128.             lscount = lscount + 1
  129.  
  130.             log.debug("--- Skill(".. lscount .."): " .. DataShortcut:call("getName(snow.data.DataDef.PlKitchenSkillId)", v:get_field("_SkillId")) .. (settings.UseHoppingSkewers and (" lv (" .. v:get_field("_SkillLv") .. ")") or ""))
  131.         end
  132.     end
  133.  
  134.     -- If no dango skills activated...
  135.     if lscount == 0 then
  136.         Message = Message .. "\n<COL RED>No dango skills activated.</COL>"
  137.  
  138.         log.debug("AutoDango.lua --- No dango skills activated.")
  139.  
  140.         -- If the original order did not use a voucher try again with a free voucher
  141.         if settings.UseVoucher == false then
  142.             Message = Message .. (settings.UseHoppingSkewers and "\n<COL YEL>(Hopping skewer was used)</COL>" or "")
  143.             Message = Message .. "\n<COL YEL>Using a </COL><COL RED>FREE</COL><COL YEL> Voucher.</COL>"
  144.  
  145.             if settings.EnableNotification then
  146.                 gm.ChatManager.d:call("reqAddChatInfomation", Message, settings.Sounds and 2289944406 or 0)
  147.             end
  148.  
  149.             log.debug("AutoDango.lua --- Using a FREE voucher.")
  150.  
  151.             -- Add free voucher here
  152.             ItemBox:call("tryAddGameItem(snow.data.ContentsIdSystem.ItemId, System.Int32)", 68157564, 1)
  153.  
  154.             Kitchen:set_field("_AvailableWaitTimer", 0)
  155.  
  156.             -- Order again with a voucher
  157.             settings.UseVoucher = true
  158.             Kitchen:set_field("_MealTicketFlag", settings.UseVoucher)
  159.  
  160.             isOrdering = true
  161.             Kitchen:call("order", order, settings.Points and 1 or 0, facilityLevel)
  162.             isOrdering = false
  163.  
  164.             -- Health and Stamina do not need to be reapplied
  165.  
  166.             Message = "<COL YEL>Automatically ate " .. OrderName .. " with a voucher (" .. VoucherCount .. " remaining).</COL>"
  167.             Message = Message .. "\nHealth: <COL YEL>" .. PlayerData:get_field("_vitalMax") .. "</COL> Stamina: <COL YEL>" .. math.floor(PlayerData:get_field("_staminaMax") / 30) .. "</COL>"
  168.             Message = Message .. "\n<COL YEL>Skills activated:</COL>"
  169.  
  170.             settings.UseVoucher = false
  171.             Kitchen:set_field("_MealTicketFlag", false)
  172.  
  173.             lscount = 0
  174.  
  175.             log.debug("AutoDango.lua --- Second Attempt Dango Skills")
  176.  
  177.             -- Get Kitchen Skills again
  178.             PlayerSkillData = Player:get_field("_refPlayerSkillList")
  179.             PlayerKitchenSkillData = PlayerSkillData:call("get_KitchenSkillData")
  180.  
  181.             for i,v in pairs(PlayerKitchenSkillData:get_elements()) do
  182.                 if v:get_field("_SkillId") ~= 0 then
  183.                     Message = Message .. "\n  " .. DataShortcut:call("getName(snow.data.DataDef.PlKitchenSkillId)", v:get_field("_SkillId")) .. (settings.UseHoppingSkewers and (" <COL YEL>(lv " .. v:get_field("_SkillLv") .. ")</COL>") or "")
  184.                     lscount = lscount + 1
  185.  
  186.                     log.debug("--- Skill(".. lscount .."): " .. DataShortcut:call("getName(snow.data.DataDef.PlKitchenSkillId)", v:get_field("_SkillId")) .. (settings.UseHoppingSkewers and (" lv (" .. v:get_field("_SkillLv") .. ")") or ""))
  187.                 end
  188.             end
  189.         end
  190.  
  191.         -- If no dango skills activated at all even with a voucher
  192.         if lscount == 0 then
  193.             Message = "<COL YEL>Tried to eat " .. OrderName .. (settings.UseVoucher and (VoucherCount > 0 and (" with a voucher (" .. VoucherCount .. " remaining)") or ", but you are out of vouchers") or "") .. ".</COL>"
  194.             Message = Message .. "\nHealth: <COL YEL>" .. PlayerData:get_field("_vitalMax") .. "</COL> Stamina: <COL YEL>" .. math.floor(PlayerData:get_field("_staminaMax") / 30) .. "</COL>"
  195.             Message = Message .. "\n<COL YEL>Skills activated:</COL>"
  196.             Message = Message .. "\n<COL RED>  No dango skills activated.</COL>"
  197.             Message = Message .. (settings.UseHoppingSkewers and "\n<COL YEL>(Hopping skewer was used)</COL>" or "")
  198.             Message = Message .. "\nTry ordering a different saved set!"
  199.  
  200.             if settings.EnableNotification then
  201.                 gm.ChatManager.d:call("reqAddChatInfomation", Message, settings.Sounds and 2289944406 or 0)
  202.             end
  203.  
  204.             Message = ""
  205.  
  206.             if settings.UseVoucher and (VoucherCount > 0) then
  207.                 Message = "Voucher <COL RED> Refunded</COL>.\n"
  208.  
  209.                 -- Refund voucher here
  210.                 ItemBox:call("tryAddGameItem(snow.data.ContentsIdSystem.ItemId, System.Int32)", 68157564, 1)
  211.                 log.debug("AutoDango.lua --- Voucher Refunded.")
  212.             end
  213.  
  214.             Kitchen:set_field("_AvailableWaitTimer", 0)
  215.             Message = Message .. "<COL YEL>You are able to eat again.</COL>"
  216.  
  217.             if settings.EnableNotification then
  218.                 gm.ChatManager.d:call("reqAddChatInfomation", Message, 0)
  219.             end
  220.  
  221.             log.debug("AutoDango.lua --- No Skills Error with Voucher")
  222.             log.debug("--- Player: " .. tostring(Player))
  223.             log.debug("--- Health  Max: " .. PlayerData:get_field("_vitalMax"))
  224.             log.debug("--- Stamina Max: " .. math.floor(PlayerData:get_field("_staminaMax") / 30) .. "(" .. PlayerData:get_field("_staminaMax") .. ")")
  225.             log.debug("---")
  226.             log.debug("--- OrderName: " .. tostring(OrderName))
  227.             log.debug("--- facilityLevel: " .. tostring(facilityLevel))
  228.             log.debug("--- Kitchen: " .. tostring(gm.FacilityDataManager.d:call("get_Kitchen")))
  229.             log.debug("--- Voucher Setting: " .. (settings.UseVoucher and (VoucherCount > 0 and (" Yes(" .. VoucherCount .. " remaining)") or ", but you are out of vouchers") or "No"))
  230.             log.debug("--- HoppingSkewers: " .. (settings.UseHoppingSkewers and "Yes" or "No"))
  231.  
  232.             return
  233.         end
  234.     end
  235.  
  236.     Message = Message .. (settings.UseHoppingSkewers and "\n<COL YEL>(Hopping skewer was used)</COL>" or "")
  237.  
  238.     -- Final Chat Message (if dango skills activated)
  239.     if settings.EnableNotification then
  240.         gm.ChatManager.d:call("reqAddChatInfomation", Message, settings.Sounds and 2289944406 or 0)
  241.     end
  242.  
  243.     -- Set Kitchen Timer
  244.     Kitchen:set_field("_AvailableWaitTimer", Kitchen:call("get_WaitTime"))
  245. end
  246.  
  247.  
  248.  
  249. -- == -- == -- == -- == --
  250.  
  251.  
  252.  
  253. sdk.hook(
  254.     sdk.find_type_definition("snow.QuestManager"):get_method("questActivate(snow.LobbyManager.QuestIdentifier)"),
  255.     function(args)
  256.         OrderFood(CreateOrder(settings.CurrentSet))
  257.     end
  258. )
  259.  
  260. sdk.hook(
  261.     sdk.find_type_definition("snow.facility.MealOrderData"):get_method("canOrder"),
  262.     function()end,
  263.     function(ret)
  264.         local bool
  265.         if isOrdering then
  266.             bool = sdk.create_instance("System.Boolean"):add_ref()
  267.             bool:set_field("mValue", true)
  268.             ret = sdk.to_ptr(bool)
  269.         end
  270.         -- Spams the debug console
  271.         --log.debug(sdk.to_int64(ret))
  272.     return ret end
  273. )
  274.  
  275.  
  276.  
  277. -- == -- == -- == -- == --
  278.  
  279.  
  280.  
  281. re.on_frame(function()
  282.     if allManagersRetrieved == false then
  283.         local success = true
  284.         for i,v in pairs(gm) do
  285.             v.d = sdk.get_managed_singleton(v.n)
  286.             if v.d == nil then success = false end
  287.         end
  288.         allManagersRetrieved = success
  289.     end
  290. end)
  291.  
  292.  
  293.  
  294. -- == -- == -- == -- == --
  295.  
  296.  
  297. re.on_draw_ui(function()
  298.     if imgui.tree_node("AutoDango")then
  299.         if allManagersRetrieved then
  300.             local Kitchen = gm.FacilityDataManager.d:call("get_Kitchen")
  301.             if Kitchen then
  302.                 Kitchen = Kitchen:call("get_MealFunc")
  303.                 if Kitchen then
  304.                     _, settings.Enabled = imgui.checkbox("Automatically eat", settings.Enabled)
  305.                     imgui.new_line()
  306.                     _, settings.CurrentSet = imgui.slider_int("Current dango set", settings.CurrentSet, 1,32, Kitchen:call("get_MySetDataList"):call("get_Item", settings.CurrentSet - 1):call("get_OrderName"))
  307.                     _, settings.UseHoppingSkewers = imgui.checkbox("Use hopping skewers", settings.UseHoppingSkewers)
  308.                     _, settings.Points = imgui.checkbox("Pay with Kamura Points", settings.Points)
  309.                     _, settings.UseVoucher = imgui.checkbox("Use voucher on eating", settings.UseVoucher)
  310.                     imgui.new_line()
  311.                     _, settings.EnableNotification = imgui.checkbox("Enable eating notification", settings.EnableNotification)
  312.                     _, settings.Sounds = imgui.checkbox("Enable notification sounds", settings.Sounds)
  313.                     imgui.new_line()
  314.                     if Kitchen._AvailableWaitTimer > 0 then
  315.                         imgui.text("WARNING: You have eaten already!")
  316.                         if imgui.button("Manually trigger eating") then
  317.                             Kitchen:set_field("_AvailableWaitTimer", 0)
  318.                             OrderFood(CreateOrder(settings.CurrentSet))
  319.                         end
  320.  
  321.                     else
  322.                         imgui.text("Ready to eat!")
  323.                         if imgui.button("Manually trigger eating") then
  324.                             OrderFood(CreateOrder(settings.CurrentSet))
  325.                         end
  326.                     end
  327.                 else
  328.                     imgui.text("Loading...")
  329.                 end
  330.             else
  331.                 imgui.text("Loading...")
  332.             end
  333.         else
  334.             imgui.text("Loading...")
  335.         end
  336.         imgui.tree_pop();
  337.     end
  338. end)
  339.  
  340.  
  341. -- == -- == -- == -- == --
  342.  
  343.  
  344. re.on_config_save(function()
  345.     json.dump_file("AutoDangoSettings.json", settings)
  346. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement