Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local allManagersRetrieved = false
- local gm = {}
- gm.FacilityDataManager = {}
- gm.FacilityDataManager.n = "snow.data.FacilityDataManager"
- gm.ProgressManager = {}
- gm.ProgressManager.n = "snow.progress.ProgressManager"
- gm.PlayerManager = {}
- gm.PlayerManager.n = "snow.player.PlayerManager"
- gm.ChatManager = {}
- gm.ChatManager.n = "snow.gui.ChatManager"
- gm.ContentsIdDataManager = {}
- gm.ContentsIdDataManager.n = "snow.data.ContentsIdDataManager"
- gm.QuestManager = {}
- gm.QuestManager.n = "snow.QuestManager"
- for i,v in pairs(gm) do
- v.d = sdk.get_managed_singleton(v.n)
- end
- -- == -- == -- == -- == --
- local DataShortcut = sdk.create_instance("snow.data.DataShortcut", true):add_ref()
- local isOrdering = false
- local settings = json.load_file("AutoDangoSettings.json") or {}
- settings.Enabled = settings.Enabled == nil and true or settings.Enabled
- settings.Sounds = settings.Sounds == nil and true or settings.Sounds
- settings.UseVoucher = settings.UseVoucher == nil and false or settings.UseVoucher
- settings.UseHoppingSkewers = settings.UseHoppingSkewers == nil and false or settings.UseHoppingSkewers
- settings.Points = settings.Points == nil and false or settings.Points
- settings.EnableNotification = settings.EnableNotification == nil and true or settings.EnableNotification
- settings.CurrentSet = settings.CurrentSet or 1
- --settings.CurrentSet = math.floor(settings.CurrentSet)
- -- == -- == -- == -- == --
- local function CreateOrder(setID)
- local Kitchen = gm.FacilityDataManager.d:call("get_Kitchen")
- if not Kitchen then return end
- Kitchen = Kitchen:call("get_MealFunc")
- if not Kitchen then return end
- return Kitchen:call("getMySetList"):call("get_Item", setID - 1)
- end
- local function OrderFood(order)
- -- Variables here
- local Kitchen = gm.FacilityDataManager.d:call("get_Kitchen")
- -- No Kitchen means no go
- if not Kitchen then return end
- Kitchen = Kitchen:call("get_MealFunc")
- if not Kitchen then return end
- local Player = gm.PlayerManager.d:call("findMasterPlayer")
- local PlayerData = Player:get_field("_refPlayerData")
- local PlayerSkillData = Player:get_field("_refPlayerSkillList")
- local PlayerKitchenSkillData = PlayerSkillData:call("get_KitchenSkillData")
- local DataManager = sdk.get_managed_singleton("snow.data.DataManager");
- local ItemBox = DataManager:get_field("_PlItemBox")
- local facilityLevel = Kitchen:call("get_FacilityLv")
- local Vouchers = gm.ContentsIdDataManager.d:call("getItemData", 0x410007c)
- local VoucherCount = Vouchers:call("getCountInBox")
- local OrderName = order:call("get_OrderName")
- 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>"
- local lscount = 0
- -- Daily Dango does not seem to reset
- Kitchen:call("resetDailyDango")
- -- If the kitchen timer is 'on', return
- if Kitchen:get_field("_AvailableWaitTimer") > 0.0 then
- if settings.EnableNotification then
- gm.ChatManager.d:call("reqAddChatInfomation", "<COL RED>You have already eaten! Auto-Dango aborted.</COL>", settings.Sounds and 2289944406 or 0)
- end
- log.debug("AutoDango.lua --- Wait Timer (" .. Kitchen:call("get_WaitTime") .. "): Eaten already, skipping auto-eat.")
- return
- end
- -- If attempting to order from an empty set, return
- if order:call("get__DangoId"):call("get_Item", 0) == 65 then
- gm.ChatManager.d:call("reqAddChatInfomation", "<COL RED>Cannot order from an empty set.</COL>", settings.Sounds and 2412657311 or 0)
- log.debug("AutoDango.lua --- Error: Attempted to order from an empty set.")
- return
- end
- -- Voucher Check
- if VoucherCount > 0 then
- Kitchen:set_field("_MealTicketFlag", settings.UseVoucher)
- else
- Kitchen:set_field("_MealTicketFlag", false)
- end
- order:set_field("IsSpecialSkewer", settings.UseHoppingSkewers)
- -- Create Food Order
- isOrdering = true
- Kitchen:call("order", order, settings.Points and 1 or 0, facilityLevel)
- isOrdering = false
- -- Set Player Max Health / Stamina
- PlayerData:set_field("_vitalMax", (100 + Kitchen:getVitalBuff(facilityLevel)))
- PlayerData:set_field("_staminaMax", (3000 + (Kitchen:getStaminaBuff(facilityLevel) * 30)))
- Message = Message .. "\nHealth: <COL YEL>" .. PlayerData:get_field("_vitalMax") .. "</COL> Stamina: <COL YEL>" .. math.floor(PlayerData:get_field("_staminaMax") / 30) .. "</COL>"
- Message = Message .. "\n<COL YEL>Skills activated:</COL>"
- log.debug("AutoDango.lua --- Dango Skills")
- -- Kitchen Skill Check
- PlayerSkillData = Player:get_field("_refPlayerSkillList")
- PlayerKitchenSkillData = PlayerSkillData:call("get_KitchenSkillData")
- for i,v in pairs(PlayerKitchenSkillData:get_elements()) do
- if v:get_field("_SkillId") ~= 0 then
- 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 "")
- lscount = lscount + 1
- log.debug("--- Skill(".. lscount .."): " .. DataShortcut:call("getName(snow.data.DataDef.PlKitchenSkillId)", v:get_field("_SkillId")) .. (settings.UseHoppingSkewers and (" lv (" .. v:get_field("_SkillLv") .. ")") or ""))
- end
- end
- -- If no dango skills activated...
- if lscount == 0 then
- Message = Message .. "\n<COL RED>No dango skills activated.</COL>"
- log.debug("AutoDango.lua --- No dango skills activated.")
- -- If the original order did not use a voucher try again with a free voucher
- if settings.UseVoucher == false then
- Message = Message .. (settings.UseHoppingSkewers and "\n<COL YEL>(Hopping skewer was used)</COL>" or "")
- Message = Message .. "\n<COL YEL>Using a </COL><COL RED>FREE</COL><COL YEL> Voucher.</COL>"
- if settings.EnableNotification then
- gm.ChatManager.d:call("reqAddChatInfomation", Message, settings.Sounds and 2289944406 or 0)
- end
- log.debug("AutoDango.lua --- Using a FREE voucher.")
- -- Add free voucher here
- ItemBox:call("tryAddGameItem(snow.data.ContentsIdSystem.ItemId, System.Int32)", 68157564, 1)
- Kitchen:set_field("_AvailableWaitTimer", 0)
- -- Order again with a voucher
- settings.UseVoucher = true
- Kitchen:set_field("_MealTicketFlag", settings.UseVoucher)
- isOrdering = true
- Kitchen:call("order", order, settings.Points and 1 or 0, facilityLevel)
- isOrdering = false
- -- Health and Stamina do not need to be reapplied
- Message = "<COL YEL>Automatically ate " .. OrderName .. " with a voucher (" .. VoucherCount .. " remaining).</COL>"
- Message = Message .. "\nHealth: <COL YEL>" .. PlayerData:get_field("_vitalMax") .. "</COL> Stamina: <COL YEL>" .. math.floor(PlayerData:get_field("_staminaMax") / 30) .. "</COL>"
- Message = Message .. "\n<COL YEL>Skills activated:</COL>"
- settings.UseVoucher = false
- Kitchen:set_field("_MealTicketFlag", false)
- lscount = 0
- log.debug("AutoDango.lua --- Second Attempt Dango Skills")
- -- Get Kitchen Skills again
- PlayerSkillData = Player:get_field("_refPlayerSkillList")
- PlayerKitchenSkillData = PlayerSkillData:call("get_KitchenSkillData")
- for i,v in pairs(PlayerKitchenSkillData:get_elements()) do
- if v:get_field("_SkillId") ~= 0 then
- 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 "")
- lscount = lscount + 1
- log.debug("--- Skill(".. lscount .."): " .. DataShortcut:call("getName(snow.data.DataDef.PlKitchenSkillId)", v:get_field("_SkillId")) .. (settings.UseHoppingSkewers and (" lv (" .. v:get_field("_SkillLv") .. ")") or ""))
- end
- end
- end
- -- If no dango skills activated at all even with a voucher
- if lscount == 0 then
- 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>"
- Message = Message .. "\nHealth: <COL YEL>" .. PlayerData:get_field("_vitalMax") .. "</COL> Stamina: <COL YEL>" .. math.floor(PlayerData:get_field("_staminaMax") / 30) .. "</COL>"
- Message = Message .. "\n<COL YEL>Skills activated:</COL>"
- Message = Message .. "\n<COL RED> No dango skills activated.</COL>"
- Message = Message .. (settings.UseHoppingSkewers and "\n<COL YEL>(Hopping skewer was used)</COL>" or "")
- Message = Message .. "\nTry ordering a different saved set!"
- if settings.EnableNotification then
- gm.ChatManager.d:call("reqAddChatInfomation", Message, settings.Sounds and 2289944406 or 0)
- end
- Message = ""
- if settings.UseVoucher and (VoucherCount > 0) then
- Message = "Voucher <COL RED> Refunded</COL>.\n"
- -- Refund voucher here
- ItemBox:call("tryAddGameItem(snow.data.ContentsIdSystem.ItemId, System.Int32)", 68157564, 1)
- log.debug("AutoDango.lua --- Voucher Refunded.")
- end
- Kitchen:set_field("_AvailableWaitTimer", 0)
- Message = Message .. "<COL YEL>You are able to eat again.</COL>"
- if settings.EnableNotification then
- gm.ChatManager.d:call("reqAddChatInfomation", Message, 0)
- end
- log.debug("AutoDango.lua --- No Skills Error with Voucher")
- log.debug("--- Player: " .. tostring(Player))
- log.debug("--- Health Max: " .. PlayerData:get_field("_vitalMax"))
- log.debug("--- Stamina Max: " .. math.floor(PlayerData:get_field("_staminaMax") / 30) .. "(" .. PlayerData:get_field("_staminaMax") .. ")")
- log.debug("---")
- log.debug("--- OrderName: " .. tostring(OrderName))
- log.debug("--- facilityLevel: " .. tostring(facilityLevel))
- log.debug("--- Kitchen: " .. tostring(gm.FacilityDataManager.d:call("get_Kitchen")))
- log.debug("--- Voucher Setting: " .. (settings.UseVoucher and (VoucherCount > 0 and (" Yes(" .. VoucherCount .. " remaining)") or ", but you are out of vouchers") or "No"))
- log.debug("--- HoppingSkewers: " .. (settings.UseHoppingSkewers and "Yes" or "No"))
- return
- end
- end
- Message = Message .. (settings.UseHoppingSkewers and "\n<COL YEL>(Hopping skewer was used)</COL>" or "")
- -- Final Chat Message (if dango skills activated)
- if settings.EnableNotification then
- gm.ChatManager.d:call("reqAddChatInfomation", Message, settings.Sounds and 2289944406 or 0)
- end
- -- Set Kitchen Timer
- Kitchen:set_field("_AvailableWaitTimer", Kitchen:call("get_WaitTime"))
- end
- -- == -- == -- == -- == --
- sdk.hook(
- sdk.find_type_definition("snow.QuestManager"):get_method("questActivate(snow.LobbyManager.QuestIdentifier)"),
- function(args)
- OrderFood(CreateOrder(settings.CurrentSet))
- end
- )
- sdk.hook(
- sdk.find_type_definition("snow.facility.MealOrderData"):get_method("canOrder"),
- function()end,
- function(ret)
- local bool
- if isOrdering then
- bool = sdk.create_instance("System.Boolean"):add_ref()
- bool:set_field("mValue", true)
- ret = sdk.to_ptr(bool)
- end
- -- Spams the debug console
- --log.debug(sdk.to_int64(ret))
- return ret end
- )
- -- == -- == -- == -- == --
- re.on_frame(function()
- if allManagersRetrieved == false then
- local success = true
- for i,v in pairs(gm) do
- v.d = sdk.get_managed_singleton(v.n)
- if v.d == nil then success = false end
- end
- allManagersRetrieved = success
- end
- end)
- -- == -- == -- == -- == --
- re.on_draw_ui(function()
- if imgui.tree_node("AutoDango")then
- if allManagersRetrieved then
- local Kitchen = gm.FacilityDataManager.d:call("get_Kitchen")
- if Kitchen then
- Kitchen = Kitchen:call("get_MealFunc")
- if Kitchen then
- _, settings.Enabled = imgui.checkbox("Automatically eat", settings.Enabled)
- imgui.new_line()
- _, 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"))
- _, settings.UseHoppingSkewers = imgui.checkbox("Use hopping skewers", settings.UseHoppingSkewers)
- _, settings.Points = imgui.checkbox("Pay with Kamura Points", settings.Points)
- _, settings.UseVoucher = imgui.checkbox("Use voucher on eating", settings.UseVoucher)
- imgui.new_line()
- _, settings.EnableNotification = imgui.checkbox("Enable eating notification", settings.EnableNotification)
- _, settings.Sounds = imgui.checkbox("Enable notification sounds", settings.Sounds)
- imgui.new_line()
- if Kitchen._AvailableWaitTimer > 0 then
- imgui.text("WARNING: You have eaten already!")
- if imgui.button("Manually trigger eating") then
- Kitchen:set_field("_AvailableWaitTimer", 0)
- OrderFood(CreateOrder(settings.CurrentSet))
- end
- else
- imgui.text("Ready to eat!")
- if imgui.button("Manually trigger eating") then
- OrderFood(CreateOrder(settings.CurrentSet))
- end
- end
- else
- imgui.text("Loading...")
- end
- else
- imgui.text("Loading...")
- end
- else
- imgui.text("Loading...")
- end
- imgui.tree_pop();
- end
- end)
- -- == -- == -- == -- == --
- re.on_config_save(function()
- json.dump_file("AutoDangoSettings.json", settings)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement