function split (inputstr, sep)
  if sep == nil then
          sep = "%s"
  end
  local t={}
  for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
          table.insert(t, str)
  end
  return t
end


function isMulti()

  return false

end
function isReady()


  return true
end

function isBoss()

  return false
end

timed = {}
hidden = false

oldsprint = 0
oldwalk = 0

totalexp = {6,15,29,57,99,162,257,400,643,959,1370,1904,2641,3604,4711,5929,7269,8743,10600,12643,14890,17362,20081,23534,27332,31510,36106,41162,47634,54753,62584,71198,80673,92517,105545,119876,135640,152980,174828,198861,225297,254377,286365,326990,371678,420835,474908,534388,607548,688024,776548,873924,981038,1110646,1253215,1410041,1582550,1772310,2005715,2262461,2544882,2855545,3197274,3614183,4072783,4577243,5132149,5742546,6462814,7255109,8126634,9085312,10139858,11394768,12775169,14293610,15963895,17801209,19969243,22797169,26002151,29772718,33618696,37577791,41536886,45609098,49756722,53904346,58094860,62285374,66475888,70666402,74856916,79047430,83237944,87428458,91618972,95809486,100000000}
nextexp = {6,9,14,28,42,63,95,143,243,316,411,534,737,963,1107,1218,1340,1474,1857,2043,2247,2472,2719,3453,3798,4178,4596,5056,5472,6181,7831,8611,8614,9485,11844,13028,13964,17340,21848,24033,26436,29080,31988,40775,44688,49157,54073,59480,59560,73160,80476,88524,97400,107114,129608,142569,156826,172509,189760,233405,257746,282421,311663,340909,417909,458600,504960,555506,616597,720631,789926,871525,958678,1054546,1254910,1380391,1530341,1690295,1867105,2083904,2367926,2650722,2971067,3845978,3845978,3845978,3845978,3845978,3845978,4072512,4072512,4072512,4072512,4072512,4072512,4072512,4072512,4072512,4072512,4072512,4072512,4072512,4072512,4072512,4072512,4072512,4072512,4072512,4072512,4072512,4072512,4072512,4072512,4072512,4072512,4190514}


function dump(o)


     for k,v in pairs(o) do
        print(k)
     end

end

function spawn()
  local util = StaticFindObject("/Script/DP1Project.Default__BPGameDataUtilityItem")  
  if not util or not util:IsValid() then
    return 0
  end

  local opts = {}
  opts[1] = 0
  opts[2] = 0
  opts[3] = 0
  opts[4] = 0
  opts[5] = 0
  opts[6] = 0

  --util:AddItems(FName("iam01001050"), 1, opts);
  util:AddItems(FName("ics01000580"), 50, opts);


  
  return 1

end

function spawn2()
  
  local cheat = StaticFindObject("/Script/Engine.Default__CheatManager")  
  if not cheat or not cheat:IsValid() then
    return 0
  end

  cheat:Summon("para_enm10d00401")
  cheat:Summon("Enemy_100220_00")

  return 1
  
end

function updatehp(cur, max)
  local menus = FindAllOf("MenuTop_RPG_CharaMain_C")
  if not menus then
    return
  end  

  local menu = nil

  for Index,item in pairs(menus) do
    if item:IsValid() then
      menu = item
      item:UpdateHP_BP(cur,max,true)

      if cur <= max/4 then
        item:PlayHPAlertAnimation_BP()
      else
        item:StopHPAlertAnimation_BP()
      end

    end
  end

  if cur == 0 then

    local util = StaticFindObject("/Script/DP1Project.Default__MenuGameUtility")  
    if not util or not util:IsValid() then
      return
    else
      util:OpenLifeGetMenu(FName("Hunter"))
      ExecuteWithDelay(250, function()
        local lmenu = util:GetLifeGetMenu()
        lmenu:CloseSendEvent()
        util:CloseLifeGetMenu()
      end)  
      
    end
  end

end

function getState()
    local util = StaticFindObject("/Script/DP1Project.Default__MenuGameUtility")  
    if not util or not util:IsValid() then
      return -1
    else
      local menu

      menu = util:GetMainMenu()

      if menu and menu:IsValid() then
          return 20
      end

      menu = util:GetTutorialGuideMenu()

      if menu and menu:IsValid() then
          return 21
      end

      menu = util:GetTutorialArrowMenu()

      if menu and menu:IsValid() then
          return 22
      end

      menu = util:GetShopMenu()

      if menu and menu:IsValid() then
          return 23
      end

      menu = util:GetLifeSelectMenu()

      if menu and menu:IsValid() then
          return 24
      end

      menu = util:GetInventoryMenu()

      if menu and menu:IsValid() then
          return 25
      end

      local setting = FindFirstOf("EventManagerSubsystem")
      if setting and setting:IsValid() then
        list = setting.m_eventPlayerList
        
        local item = list[1]
        if item:IsValid() then
          return 2
        end
    
      end

      if util:IsTransition() then return 1 end
      if util:IsFadeOut() then return 1 end
      if util:IsFade() then return 1 end
      if util:IsWipe() then return 1 end
      if util:IsProcessingTextBox() then return 1 end
      if util:IsProcessingHelpWindow() then return 1 end      

    end

    return 0
end

function updateexp(cur, max)
  local menus = FindAllOf("MenuTop_RPG_CharaMain_C")
  if not menus then
    return
  end  

  local menu = nil

  for Index,item in pairs(menus) do
    if item:IsValid() then
      menu = item
      item:UpdateEXP_BP(cur,max,true)
    end
  end

end

function temppppp()
  local setting = FindFirstOf("WorldSettings")
  if not setting or not setting:IsValid() then
    return
  end

  local statics = StaticFindObject("/Script/Engine.Default__GameplayStatics")  
  if not statics or not statics:IsValid() then

  else
    --statics:SetSubtitlesEnabled(true)
  end

  local cheat = StaticFindObject("/Script/Engine.Default__CheatManager")  
  if not cheat or not cheat:IsValid() then

  end
end

function getEngine()
  local engine = FindFirstOf("GameEngine")

  if not engine or not engine:IsValid() then
    return 0, 0
  end

  local a1 = engine:GetAddress()
  local a2 = engine:GetAddress() >> 32

  return a1, a2
end

function testing()
  local ind, func = getfunc()
  local cur, val = gettwo()
  local msg = getmsg()

  ExecuteInGameThread(function()
    local succ, ret = pcall(
      function()
        return _G[func](cur,val,msg)
      end
    )

    if succ then
      setvalue(ind, ret)
    end
  end)

  return 1
end

function getStatus()
  local Datas = FindAllOf("DynamicDataManager")
  local Data = nil

  for Index,item in pairs(Datas) do
    if item:IsValid() then
      Data = item
    end
  end

  if not Data or not Data:IsValid() then
    return 0, 0
  end
 
   
  local Chara = Data:GetPropertyValue("GDDCharaStatus")
  if not Chara or not Chara:IsValid() then
    return 0, 0
  end  

  local Group = Chara:GetPropertyValue("m_permanent")
  if not Group or not Group:IsValid() then
    return 0, 0
  end  

  
  return Chara:GetAddress()

end



function getLife()
  local Datas = FindAllOf("DynamicDataManager")
  local Data = nil

  for Index,item in pairs(Datas) do
    if item:IsValid() then
      Data = item
    end
  end

  if not Data or not Data:IsValid() then
    return 0
  end
   
  local Chara = Data:GetPropertyValue("GDDCharaStatus")
  if not Chara or not Chara:IsValid() then
    return 0
  end  

  local Group = Chara:GetPropertyValue("m_permanent")
  if not Group or not Group:IsValid() then
    return 0
  end  

  --dump(Group)

  local Avatars = Group:GetPropertyValue("m_stAvatarP")
  if not Avatars or not Avatars:IsValid() then
    return 0
  end  

  local item = Avatars[1]
  if not item or not item:IsValid() then
    return 0
  end  

  local name = item.m_lifeId


  local lifes = FindFirstOf("GDSLifeData")
  if not lifes or not lifes:IsValid() then
    return 0
  end

  return 0

end

function getPlayData()
  local Datas = FindAllOf("DynamicDataManager")
  local Data = nil

  for Index,item in pairs(Datas) do
    if item:IsValid() then
      Data = item
    end
  end

  if not Data or not Data:IsValid() then
    return nil
  end
 
   
  local Play = Data:GetPropertyValue("GDDPlayData")
  if not Play or not Play:IsValid() then
    return nil
  end  

  return Play:GetAddress()
end

function getEXP()

  local config = FindFirstOf("FGDCharaLevelConfig")
  if not engine or not engine:IsValid() then
    return 0
  end


  local engine = StaticFindObject("/Script/DP1Project.Default__GuildQuestMenuTop")  

  if not engine or not engine:IsValid() then
    return 0
  end

  engine:AddCurrentEXP(10)

  return 1
end

function getMovement()

  local engine = FindFirstOf("GameEngine")

  if not engine or not engine:IsValid() then
    return 0
  end

  local instance = engine.GameInstance
  if not instance or not instance:IsValid() then
    return 0
  end

  local players = instance.LocalPlayers
  if not players or not players:IsValid() then
    return 0
  end

  local player = players[1]
  if not player or not player:IsValid() then
    return 0
  end

  local controller = player.PlayerController
  if not controller or not controller:IsValid() then
    return 0
  end

  local character = controller.Character
  if not character or not character:IsValid() then
    return 0
  end

  local movement = character.CharacterMovement
  if not movement or not movement:IsValid() then
    return 0
  end

  return movement:GetAddress()

end

function getPlayerRoot()  
  local engine = FindFirstOf("GameEngine")

  if not engine or not engine:IsValid() then
    return 0
  end

  local instance = engine.GameInstance
  if not instance or not instance:IsValid() then
    return 0
  end

  local players = instance.LocalPlayers
  if not players or not players:IsValid() then
    return 0
  end

  local player = players[1]
  if not player or not player:IsValid() then
    return 0
  end

  local controller = player.PlayerController
  if not controller or not controller:IsValid() then
    return 0
  end

  local pawn = controller.Pawn
  if not pawn then
    return 0 
  end  

  local root = pawn.RootComponent

  if not root then
    return 0 
  end  

  return root:GetAddress()
end

function getCamera()  
  local engine = FindFirstOf("GameEngine")

  if not engine or not engine:IsValid() then
    return 0
  end

  local instance = engine.GameInstance
  if not instance or not instance:IsValid() then
    return 0
  end

  local players = instance.LocalPlayers
  if not players or not players:IsValid() then
    return 0
  end

  local player = players[1]
  if not player or not player:IsValid() then
    return 0
  end

  local controller = player.PlayerController
  if not controller or not controller:IsValid() then
    return 0
  end

  local camera = controller.PlayerCameraManager
  if not camera then
    return 0 
  end  



  return camera:GetAddress()
end

function setFOV(cur,val)  
  local engine = FindFirstOf("GameEngine")

  if not engine or not engine:IsValid() then
    return 0
  end

  local instance = engine.GameInstance
  if not instance or not instance:IsValid() then
    return 0
  end

  local players = instance.LocalPlayers
  if not players or not players:IsValid() then
    return 0
  end

  local player = players[1]
  if not player or not player:IsValid() then
    return 0
  end

  local controller = player.PlayerController
  if not controller or not controller:IsValid() then
    return 0
  end

  controller:FOV(cur)

  return 1
end


function showmsg(val)
  
  local engine = FindFirstOf("GameEngine")

  if not engine or not engine:IsValid() then
    return 0
  end

  local instance = engine.GameInstance
  if not instance or not instance:IsValid() then
    return 0
  end

  local players = instance.LocalPlayers
  if not players or not players:IsValid() then
    return 0
  end

  local player = players[1]
  if not player or not player:IsValid() then
    return 0
  end

  local controller = player.PlayerController
  if not controller or not controller:IsValid() then
    return 0
  end

  local menu = nil

  local menus = FindAllOf("HUD")
  if not menus then
    return 0 
  end  

  local pawn = controller.Pawn

  if not pawn then
    return 0 
  end  

  local root = pawn.RootComponent

  if not root then
    return 0 
  end  

  local relp = root.RelativeLocation
  if not relp then
    return 0 
  end  

  local pos = {}
  pos["X"] = relp.X
  pos["Y"] = relp.Y
  pos["Z"] = relp.Z



  local color = {}
  color["A"] = 255
  color["R"] = 255
  color["G"] = 255
  color["B"] = 255      

  for Index,item in pairs(menus) do
    if item:IsValid() then
      menu = item
      item:AddDebugText(val, controller, 5.0, pos, pos, color, true, true, true, engine.LargeFont, 2.0, true)
      return 1
    end
  end

  return 0
end

function teststr()
  local msg = getmsg()

  ExecuteInGameThread(function()
    local succ, ret = pcall(
      function()
        showmsg(msg)
      end
    )
  end)

  return 1
  
end

function giveItem(qty, val, str)
  local util = StaticFindObject("/Script/DP1Project.Default__BPGameDataUtilityItem")  
  if not util or not util:IsValid() then
    return 0
  end

  local opts = {}
  opts[1] = 0
  opts[2] = 0
  opts[3] = 0
  opts[4] = 0
  opts[5] = 0
  opts[6] = 0

  util:AddItems(FName(str), qty, opts);
  
  return 1

end

function takeItem(qty, val, str)
  local util = StaticFindObject("/Script/DP1Project.Default__BPGameDataUtilityItem")  
  if not util or not util:IsValid() then
    return 0
  end

  util:DeleteItemsByItemId(FName(str), qty);
  
  return 1

end

function getItem(qty, val, str)
  local util = StaticFindObject("/Script/DP1Project.Default__BPGameDataUtilityItem")  
  if not util or not util:IsValid() then
    return 0
  end

  local opts = {}
  opts[1] = 0
  opts[2] = 0
  opts[3] = 0
  opts[4] = 0
  opts[5] = 0
  opts[6] = 0

  local handle = util:AddItems(FName(str), 0, opts);
  if not handle then
    return 0
  end 

  local num = util:GetItemNumByInvHdl(handle) - 1


  util:DeleteItemsByInvHdl(handle, 1)
  return num

end


function tryexe()
  local menus = FindAllOf("ExeCommandSubsystem")
  if not menus then
    return 0
  end  


  local param = {}
  local args = { 1 }
  local params = { 1 }  
  param["args"] = args
  param["State"] = 2
  param["Params"] = params
  param["DeltaTime"] = 1.0 

  for Index,item in pairs(menus) do
    if item:IsValid() then
      --item:RegistRPGGotNotification(cur, 0, 0, 0, 0)
      item:ExeCmd_WeaponSheathe(param)
      return 1
    end
  end

  return 0
end


function respawn()
  if isBoss() then return end
  local PlayerState = FindFirstOf("PlayerState")
  PlayerState:RequestRespawn()
  return true
end

