local LOG_DEBUG = false

sdk.hook(sdk.find_type_definition("app.EnemyRewardUtil"):get_method("getRewardItemData(app.EnemyDef.ID, app.EnemyReward.RewardType, System.Int32, System.Int32)"), function(args) end, function (retval)
    FixRewards(retval, Mode.EnemyRewardUtil_getRewardItemDataPost)
    return retval
end)

sdk.hook(sdk.find_type_definition("app.EnemyRewardUtil"):get_method("getAddRewardItemData(app.EnemyDef.ID, app.EnemyReward.RewardType, System.Int32)"), function(args) end, function (retval)
    FixRewards(retval, Mode.EnemyRewardUtil_getAddRewardItemDataPost)
    return retval
end)

sdk.hook(sdk.find_type_definition("app.QuestGeneralRewardUtil"):get_method("getRewardItemData(System.UInt32, app.QuestGeneralRewardUtil.GeneralRewardType, app.cQuestDirector.TIME_RANK, System.Int32)"), function(args) end, function (retval)
    FixRewards(retval, Mode.QuestGeneralRewardUtil_getRewardItemDataPost)
    return retval
end)

sdk.hook(sdk.find_type_definition("app.QuestRewardUtil"):get_method("getTargetReward(app.EnemyDef.ID, app.EnemyDef.ROLE_ID, System.Int32)"), function(args) end, function (retval)
    FixRewards(retval, Mode.QuestRewardUtil_getTargetRewardPost)
    return retval
end)

function FixRewards(ptr, mode) -- List<cSendItemInfo>
    if (LOG_DEBUG) then log.info(mode .. ": Changing rewards.") end

    if (ptr == 0) then return end
    local sendItemInfo = sdk.to_managed_object(ptr)
    if (sendItemInfo == nil) then return end

    local count = sendItemInfo:get_Count()

--  if (LOG_DEBUG and count > 0) then
--      local isCarveType    = sendItemInfo[0]:get_field("<LogType>k__BackingField") == LogType.HAGITORI
--      local enemyId        = sendItemInfo[0]:get_field("<EnemyId>k__BackingField")
--      local isLargeMonster = tableContains(EnemyConstants, sendItemInfo[0]:get_field("<EnemyId>k__BackingField"))

--      log.info(mode .. ": isCarveType:    " .. toStrinOrNull(isCarveType))
--      log.info(mode .. ": enemyId:        " .. toStrinOrNull(enemyId))
--      log.info(mode .. ": isLargeMonster: " .. toStrinOrNull(isLargeMonster))
--  end

    if (LOG_DEBUG) then log.info(mode .. ": Starting item dump.") end
    if (LOG_DEBUG) then log.info(mode .. ": Item count: " .. count) end

    if (mode == Mode.QuestGeneralRewardUtil_getRewardItemDataPost and count > 0) then
        log.info(mode .. ": Clearing extra rewards.")
        sendItemInfo:Clear()
    elseif (mode == Mode.QuestRewardUtil_getTargetRewardPost and count > 0) then
        log.info(mode .. ": Changing rewards for Bingo Brawlers.")

        local enemyId             = sendItemInfo[0]:get_field("<EnemyId>k__BackingField")
        local monsterSpecificItem = GetMonsterSpecificReward(enemyId) -- Defaults to mega potion if there's nothing for the given monster.

        sendItemInfo[0]:set_field("<ItemId>k__BackingField", ItemConstants.GOLD_MELDING_TICKET)
        sendItemInfo[1]:set_field("<ItemId>k__BackingField", ItemConstants.SILVER_MELDING_TICKET)
        sendItemInfo[2]:set_field("<ItemId>k__BackingField", ItemConstants.HEAVY_ARMOR_SPHERE)
        sendItemInfo[3]:set_field("<ItemId>k__BackingField", monsterSpecificItem) -- Replace with monster item.

        sendItemInfo[0]:set_field("<Num>k__BackingField", 1)
        sendItemInfo[1]:set_field("<Num>k__BackingField", 1)
        sendItemInfo[2]:set_field("<Num>k__BackingField", 1)
        sendItemInfo[3]:set_field("<Num>k__BackingField", 1)

        while (sendItemInfo:get_Count() > 4) do sendItemInfo:RemoveAt(4) end
    elseif (mode == Mode.EnemyRewardUtil_getRewardItemDataPost and count > 0
            and (sendItemInfo[0]:get_field("<LogType>k__BackingField") == LogType.HAGITORI
                 or sendItemInfo[0]:get_field("<LogType>k__BackingField") == LogType.PARTS_HAGITORI)
            and tableContains(EnemyConstants, sendItemInfo[0]:get_field("<EnemyId>k__BackingField"))) then
        log.info(mode .. ": Making carves mega potions.")

        for i = 0, count - 1 do
            sendItemInfo[i]:set_field("<ItemId>k__BackingField", ItemConstants.MEGA_POTION)
        end
    end

    if (LOG_DEBUG and count > 0) then
        for i = 0, count - 1 do
            log.info(mode .. ": ItemId: " .. toStrinOrNull(sendItemInfo[i]:get_field("<ItemId>k__BackingField"))
                .. ", EnemyId: " .. toStrinOrNull(sendItemInfo[i]:get_field("<EnemyId>k__BackingField"))
                .. ", IsReceived: " .. toStrinOrNull(sendItemInfo[i]:get_field("<IsReceived>k__BackingField"))
                .. ", LogType: " .. toStrinOrNull(sendItemInfo[i]:get_field("<LogType>k__BackingField"))
                .. ", Param: " .. toStrinOrNull(sendItemInfo[i]:get_field("<Param>k__BackingField"))
                .. ", Num: " .. toStrinOrNull(sendItemInfo[i]:get_field("<Num>k__BackingField"))
                .. ", OverNum: " .. toStrinOrNull(sendItemInfo[i]:get_field("<OverNum>k__BackingField")));
        end
    end
end

function GetMonsterSpecificReward(enemyId)
    if (enemyId == EnemyConstants.AJARAKAN) then return ItemConstants.AJARAKAN_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.ARKVELD or enemyId == EnemyConstants.GUARDIAN_ARKVELD) then return ItemConstants.ARKVELD_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.BALAHARA) then return ItemConstants.BALAHARA_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.BLANGONGA) then return ItemConstants.BLANGONGA_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.CHATACABRA) then return ItemConstants.CHATACABRA_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.CONGALALA) then return ItemConstants.CONGALALA_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.DOSHAGUMA) then return ItemConstants.DOSHAGUMA_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.GORE_MAGALA) then return ItemConstants.GORE_MAGALA_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.GRAVIOS) then return ItemConstants.GRAVIOS_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.GUARDIAN_DOSHAGUMA) then return ItemConstants.G_DOSHAGUMA_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.GUARDIAN_EBONY_ODOGARON) then return ItemConstants.G_EBONY_ODOGARON_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.GUARDIAN_FULGUR_ANJANATH) then return ItemConstants.GUARDIAN_FULGUR_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.GUARDIAN_RATHALOS) then return ItemConstants.G_RATHALOS_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.GYPCEROS) then return ItemConstants.GYPCEROS_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.HIRABAMI) then return ItemConstants.HIRABAMI_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.JIN_DAHAAD) then return ItemConstants.JIN_DAHAAD_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.LALA_BARINA) then return ItemConstants.LALA_BARINA_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.LAGIACRUS) then return ItemConstants.LAGIACRUS_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.MIZUTSUNE) then return ItemConstants.MIZUTSUNE_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.NERSCYLLA) then return ItemConstants.NERSCYLLA_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.NU_UDRA) then return ItemConstants.NU_UDRA_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.QUEMATRICE) then return ItemConstants.QUEMATRICE_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.RATHALOS) then return ItemConstants.RATHALOS_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.RATHIAN) then return ItemConstants.RATHIAN_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.REY_DAU) then return ItemConstants.REY_DAU_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.ROMPOPOLO) then return ItemConstants.ROMPOPOLO_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.SEREGIOS) then return ItemConstants.SEREGIOS_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.UTH_DUNA) then return ItemConstants.UTH_DUNA_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.XU_WU) then return ItemConstants.XU_WU_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.YIAN_KUT_KU) then return ItemConstants.YIAN_KUT_KU_CERTIFICATE_S
    elseif (enemyId == EnemyConstants.ZOH_SHIA) then return ItemConstants.ZOH_SHIA_CERTIFICATE_S
    else
        -- Includes EnemyConstants.ZOH_SHIA for now, not re-fight-able.
        log.info("Not adding special rewards for EnemyID: " .. toStrinOrNull(enemyId))
        return ItemConstants.MEGA_POTION
    end
end

function tableContains(data, value)
    for k, v in pairs(data) do
        if (v == value) then
            return true
        end
    end
    return false
end

function tableGetNameOfValue(data, value)
    for k, v in pairs(data) do
        if (v == value) then
            return k
        end
    end
    return nil
end

function toStrinOrNull(obj)
    if (obj == nil) then return "null" end
    return tostring(obj)
end

Mode = {
    EnemyRewardUtil_getRewardItemDataPost        = "EnemyRewardUtil_getRewardItemDataPost",        -- Called for scar and carve rewards.
    EnemyRewardUtil_getAddRewardItemDataPost     = "EnemyRewardUtil_getAddRewardItemDataPost",     -- Called at the start of a quest to set up capture and carve rewards for small/endemic life.
    QuestGeneralRewardUtil_getRewardItemDataPost = "QuestGeneralRewardUtil_getRewardItemDataPost", -- Called at the end, is the 'rewards' section, but `EnemyId` is 0.
    QuestRewardUtil_getTargetRewardPost          = "QuestRewardUtil_getTargetRewardPost"           -- Called at the end, is the 'target rewards' section, and `EnemyId` is set.
}

ItemConstants = {
    ACUTE_FANG = 97,
    ADAMANT_PILL = 171,
    ADAMANT_SEED = 126,
    ADVANCED_ARMOR_SPHERE = 623,
    AIRY_EGG = 219,
    AJARAKAN_CARAPACE = 370,
    AJARAKAN_CERTIFICATE = 368,
    AJARAKAN_CERTIFICATE_S = 374,
    AJARAKAN_JEWEL = 366,
    AJARAKAN_JEWEL_PLUS = 372,
    AJARAKAN_MARROW = 367,
    AJARAKAN_MEDULLA = 373,
    AJARAKAN_RIDGE = 364,
    AJARAKAN_RIDGE_PLUS = 371,
    AJARAKAN_SCALE = 362,
    AJARAKAN_SCALE_PLUS = 369,
    AJARAKAN_SHELL = 363,
    AJARAKAN_TAIL = 365,
    AMSTRIGIAN_TICKET = 789,
    ANCIENT_FOSSIL = 260,
    ANCIENT_ORB___ARMOR = 157,
    ANCIENT_ORB___SWORD = 620,
    ANCIENT_POTION = 5,
    ANCIENT_WEAPON_FRAGMENT = 478,
    ANCIENT_WYVERN_COIN = 473,
    ANTIDOTE = 3,
    ANTIDOTE_HERB = 26,
    ANTIMITE = 246,
    ANTIMITE_MASS = 248,
    AQUA_SAC = 594,
    ARGECITE = 667,
    ARKVELD_ARMORPLATE = 459,
    ARKVELD_CALLOUSHELL = 462,
    ARKVELD_CERTIFICATE_S = 465,
    ARKVELD_GEM = 464,
    ARKVELD_HORN_PLUS = 463,
    ARKVELD_SCALE_PLUS = 458,
    ARKVELD_TAIL = 455,
    ARMOR_AMMO = 413,
    ARMOR_SPHERE = 621,
    ARMOR_SPHERE_PLUS = 622,
    ARMORCHARM = 152,
    ARMORSKIN = 170,
    ASSISTED_COMBO__AKUMA = 780,
    AURIC_OIL = 245,
    AZUZ_MEAL_VOUCHER = 807,
    AZUZ_TANNED_LEATHER = 610,
    BALAHARA_BLACK_PEARL = 703,
    BALAHARA_CARAPACE = 312,
    BALAHARA_CERTIFICATE = 310,
    BALAHARA_CERTIFICATE_S = 314,
    BALAHARA_SCALE = 80,
    BALAHARA_SCALE_PLUS = 311,
    BALAHARA_SHELL = 79,
    BALAHARA_SKULL = 81,
    BALAHARA_SKULL_PLUS = 313,
    BALAHARA_TAIL = 82,
    BARREL_BOMB = 13,
    BARREL_BOWLING_VOUCHER = 783,
    BASIC_MATERIAL = 469,
    BEACH_BARREL_BOMB = 802,
    BEAST_GEM = 36,
    BINOCULARS = 22,
    BIRD_WYVERN_GEM = 533,
    BITTERBUG_BROTH = 28,
    BLACKEMBER_MASS = 718,
    BLADESCALE_POD = 812,
    BLANGO_PELT_PLUS = 576,
    BLANGONGA_CERTIFICATE_S = 540,
    BLANGONGA_FANG_PLUS = 537,
    BLANGONGA_PELT_PLUS = 536,
    BLANGONGA_TAIL = 539,
    BLANGONGA_WHISKER = 538,
    BLAST_COATING = 681,
    BLASTNUT = 129,
    BLEEDING_POD = 70,
    BLOSSOM_BARREL_BOMB = 801,
    BLOSSOM_TICKET = 762,
    BLOSSOMDANCE_CATALOG = 763,
    BLOSSOMDANCE_TICKET = 761,
    BLOSSOMDANCE_VOUCHER = 784,
    BLUE_MUSHROOM = 66,
    BOMB_AROWANA_SCALE = 641,
    BOMB_POD = 190,
    BOMBERRY = 290,
    BRIGHTMOSS = 187,
    BRUTE_BONE = 59,
    BUBBLEFOAM_PLUS = 725,
    BULAQCHI_CARAPACE = 487,
    BULAQCHI_SHELL = 93,
    BULKY_TREASURE = 244,
    BURNT_MEAT = 10,
    BURST_AROWANA_SCALE = 640,
    BURST_POD = 68,
    CAMPING_KIT = 23,
    CAPTURE_NET = 17,
    CARBALITE_ORE = 55,
    CATALYST = 633,
    CHALICEWEED = 264,
    CHARRED_LIZARD = 630,
    CHARRED_OILBONE = 585,
    CHATA_COIN = 776,
    CHATACABRA_CARAPACE = 295,
    CHATACABRA_CERTIFICATE = 291,
    CHATACABRA_CERTIFICATE_S = 296,
    CHATACABRA_HIDE = 84,
    CHATACABRA_HIDE_PLUS = 294,
    CHATACABRA_JAW = 83,
    CHATACABRA_JAW_PLUS = 293,
    CHATACABRA_SCALE = 86,
    CHATACABRA_SCALE_PLUS = 292,
    CHATACABRA_SHELL = 85,
    CHILLSHROOM = 476,
    CLEANSER = 178,
    CLOSE_RANGE_COATING = 675,
    CLOUDY_CRYSTAL = 590,
    CLUSTER_BOMB = 41,
    COLOSSAL_BONE = 60,
    COMA_SAC = 605,
    COMAQCHI_CARAPACE = 498,
    COMAQCHI_SHELL = 497,
    COMMISSION_TICKET = 615,
    COMMON_WOOD_MINNOW = 669,
    CONGA_PELT = 570,
    CONGA_PELT_PLUS = 571,
    CONGALALA_CERTIFICATE = 507,
    CONGALALA_CERTIFICATE_S = 584,
    CONGALALA_CLAW = 504,
    CONGALALA_CLAW_PLUS = 509,
    CONGALALA_FANG = 505,
    CONGALALA_FANG_PLUS = 510,
    CONGALALA_PELT = 503,
    CONGALALA_PELT_PLUS = 508,
    COOL_DRINK = 165,
    CORRUPTED_MANTLE = 628,
    CORUSCATING_CRYSTAL = 591,
    CRUSHED_CRYSTAL = 589,
    DALTHYDON_WOOL = 609,
    DAMAGED_WEAPON_SHARD = 158,
    DASH_EXTRACT = 534,
    DASH_JUICE = 163,
    DELISHROOM = 215,
    DEMON_AMMO = 412,
    DEMON_POWDER = 175,
    DEMONDRUG = 167,
    DEODORANT = 211,
    DEVILS_BLIGHT = 128,
    DIVING_TICKET = 765,
    DOSHAGUMA_CERTIFICATE = 315,
    DOSHAGUMA_CERTIFICATE_S = 320,
    DOSHAGUMA_CLAW = 34,
    DOSHAGUMA_CLAW_PLUS = 318,
    DOSHAGUMA_FANG = 35,
    DOSHAGUMA_FANG_PLUS = 319,
    DOSHAGUMA_FUR = 33,
    DOSHAGUMA_FUR_PLUS = 316,
    DOSHAGUMA_HIDE = 32,
    DOSHAGUMA_HIDE_PLUS = 317,
    DOSHAGUMA_SKETCH = 793,
    DRAGON_AMMO = 46,
    DRAGON_POD = 286,
    DRAGONBONE_RELIC = 61,
    DRAGONFELL_BERRY = 118,
    DRAGONITE_ORE = 54,
    DRAGONSCALE_VASE = 251,
    DRAGONSTRIKE_NUT = 289,
    DREARISITE = 665,
    DREARISITE_SCRAPS = 471,
    DRIFTING_SEA_POT = 261,
    DRIVE_IMPACT = 782,
    DROOLSHROOM = 214,
    DRUGGED_MEAT = 185,
    DUNG = 98,
    DUNG_POD = 71,
    DUST_OF_LIFE = 177,
    DUSTER_RIG = 673,
    EARTH_CRYSTAL = 56,
    EASTERN_HONEY = 223,
    EMERALD_JITTERBAIT = 671,
    ENERGY_DRINK = 162,
    EQUIPPED_MANTLES = 408,
    ETERNAL_SCARLET_AMBER = 240,
    EVASION_MANTLE = 627,
    EXCITESHROOM = 73,
    EXHAUST_AMMO = 416,
    EXHAUST_COATING = 682,
    EXPEDITION_HEADGEAR_TICKET = 707,
    EZ_DEMON_POWDER = 201,
    EZ_DUNG_POD = 205,
    EZ_DUST_OF_LIFE = 203,
    EZ_FARCASTER = 209,
    EZ_FLASH_BOMB = 121,
    EZ_HARDSHELL_POWDER = 202,
    EZ_HERBAL_POWDER = 200,
    EZ_LARGE_BARREL_BOMB = 208,
    EZ_LARGE_DUNG_POD = 457,
    EZ_LIFEPOWDER = 199,
    EZ_MAX_POTION = 198,
    EZ_PITFALL_TRAP = 123,
    EZ_RATION = 120,
    EZ_SHOCK_TRAP = 122,
    EZ_SONIC_BOMB = 206,
    EZ_TRANQ_BOMB = 204,
    FARCASTER = 76,
    FAUX_WHITEGLEAM_ORB = 716,
    FELYNE_TICKET = 778,
    FIERY_SANDPEPPER = 234,
    FINE_ANTIMITE = 247,
    FINE_SCARLET_AMBER = 239,
    FINE_WINDWARD_ALOE = 231,
    FIRE_HERB = 115,
    FIRECELL_STONE = 580,
    FIRESTONE = 579,
    FIRST_AID_MED = 119,
    FIRST_AID_MED_PLUS = 197,
    FISHING_ROD = 161,
    FLAME_SAC = 592,
    FLAMEFETE_CATALOG = 766,
    FLAMEFETE_TICKET = 764,
    FLAMEFETE_VOUCHER = 785,
    FLAMING_AMMO = 42,
    FLASH_POD = 15,
    FLASHBUG_PHOSPHOR = 29,
    FLOWFERN = 116,
    FLUFFY_EGG = 218,
    FOSSILIZED_FIRE_OPAL = 267,
    FOSSILIZED_OPAL = 266,
    FREEZE_AMMO = 45,
    FREEZER_SAC = 599,
    FRENZY_CRYSTAL = 569,
    FRENZY_SHARD = 417,
    FRESH_HONEY = 287,
    FROST_POD = 285,
    FROST_SAC = 598,
    FROSTBURST = 288,
    FROZEN_ICEBONE = 586,
    FUCIUM_ORE = 581,
    FULGURITE_SHARD = 235,
    G_DOSHAGUMA_CERTIFICATE = 393,
    G_DOSHAGUMA_CERTIFICATE_S = 398,
    G_EBONY_ODOGARON_CERTIFICATE = 431,
    G_EBONY_ODOGARON_CERTIFICATE_S = 437,
    G_RATHALOS_CERTIFICATE = 404,
    G_RATHALOS_CERTIFICATE_S = 409,
    GAJAU_HIDE = 613,
    GENESIS_OPAL = 268,
    GHILLIE_MANTLE = 160,
    GIANT_BEAK = 524,
    GILDED_SCALE = 642,
    GLOAMGRASS_BUD = 124,
    GLOWING_ORB___ARMOR = 156,
    GLOWING_ORB___SWORD = 619,
    GOBLETWEED = 263,
    GODBUG_ESSENCE = 30,
    GOLD_MELDING_TICKET = 661,
    GOLD_RELIC_TICKET = 662,
    GOLDEN_BUGHEAD = 670,
    GOLDEN_CORNEUM = 440,
    GOLDEN_CORNEUM_PLUS = 447,
    GOLDEN_EGG = 652,
    GOLDEN_SCALE = 643,
    GORE_MAGALA_CARAPACE = 562,
    GORE_MAGALA_CERTIFICATE_S = 568,
    GORE_MAGALA_FEELER_PLUS = 566,
    GORE_MAGALA_NYCTGEM = 567,
    GORE_MAGALA_RIPCLAW_PLUS = 564,
    GORE_MAGALA_SCALE_PLUS = 561,
    GORE_MAGALA_TAIL = 565,
    GORE_MAGALA_WING_PLUS = 563,
    GOU_HADOKEN = 781,
    GRACIUM = 697,
    GRAVIOS_CARAPACE = 541,
    GRAVIOS_CERTIFICATE_S = 546,
    GRAVIOS_MEDULLA = 544,
    GRAVIOS_PLEURA_PLUS = 543,
    GRAVIOS_SKULL = 542,
    GRAVIOS_WING = 545,
    GREAT_HIBISCUS = 608,
    GREAT_HORNFLY = 229,
    GREAT_STOUTBONE = 657,
    GREAT_SUSHIFISH_SCALE = 684,
    GREAT_WINDWARD_ALOE = 232,
    GROUNDING_POD = 154,
    GUARDIAN_BLOOD = 606,
    GUARDIAN_BLOOD_PLUS = 607,
    GUARDIAN_DOSHAGUMA_CLAW = 391,
    GUARDIAN_DOSHAGUMA_CLAW_PLUS = 396,
    GUARDIAN_DOSHAGUMA_FANG = 392,
    GUARDIAN_DOSHAGUMA_FANG_PLUS = 397,
    GUARDIAN_DOSHAGUMA_FUR = 389,
    GUARDIAN_DOSHAGUMA_FUR_PLUS = 394,
    GUARDIAN_DOSHAGUMA_HIDE = 390,
    GUARDIAN_DOSHAGUMA_HIDE_PLUS = 395,
    GUARDIAN_EBONY_CLAW = 427,
    GUARDIAN_EBONY_CLAW_PLUS = 434,
    GUARDIAN_EBONY_FANG = 428,
    GUARDIAN_EBONY_FANG_PLUS = 435,
    GUARDIAN_EBONY_GEM = 436,
    GUARDIAN_EBONY_PLATE = 430,
    GUARDIAN_EBONY_SCALE = 425,
    GUARDIAN_EBONY_SCALE_PLUS = 432,
    GUARDIAN_EBONY_SINEW = 426,
    GUARDIAN_EBONY_SINEW_PLUS = 433,
    GUARDIAN_EBONY_TAIL = 429,
    GUARDIAN_FULGUR_CERTIFICATE_S = 583,
    GUARDIAN_FULGUR_FANG_PLUS = 482,
    GUARDIAN_FULGUR_GEM = 485,
    GUARDIAN_FULGUR_NOSEBONE_PLUS = 483,
    GUARDIAN_FULGUR_PELT_PLUS = 481,
    GUARDIAN_FULGUR_SCALE_PLUS = 480,
    GUARDIAN_FULGUR_TAIL = 484,
    GUARDIAN_PELT = 663,
    GUARDIAN_PELT_PLUS = 664,
    GUARDIAN_RATHALOS_CARAPACE = 406,
    GUARDIAN_RATHALOS_PLATE = 705,
    GUARDIAN_RATHALOS_RUBY = 704,
    GUARDIAN_RATHALOS_SCALE = 399,
    GUARDIAN_RATHALOS_SCALE_PLUS = 405,
    GUARDIAN_RATHALOS_SHELL = 400,
    GUARDIAN_RATHALOS_TAIL = 402,
    GUARDIAN_RATHALOS_WEBBING = 401,
    GUARDIAN_RATHALOS_WING = 407,
    GUARDIAN_SCALE = 453,
    GUARDIAN_SCALE_PLUS = 454,
    GUARDIAN_SEIKRET_FEATHER = 501,
    GUARDIAN_SEIKRET_FEATHER_PLUS = 502,
    GUNPOWDER = 634,
    GUNPOWDERFISH_SCALE = 639,
    GYPCEROS_CERTIFICATE_S = 532,
    GYPCEROS_HEAD = 530,
    GYPCEROS_TAIL = 531,
    GYPCEROS_WING = 529,
    HARD_ARMOR_SPHERE = 624,
    HARDSHELL_POWDER = 176,
    HEAVY_ARMOR_SPHERE = 653,
    HEAVY_BLUNT_POD = 466,
    HEAVY_EXPLOSION_POD = 468,
    HEAVY_PIERCING_POD = 474,
    HEAVY_SLICING_POD = 467,
    HELIX_PIERCING_POD = 811,
    HERB = 25,
    HERBAL_MEDICINE = 173,
    HERBAL_POWDER = 174,
    HERBIVORE_CARAPACE = 486,
    HERBIVORE_SHELL = 92,
    HIRABAMI_CERTIFICATE = 356,
    HIRABAMI_CERTIFICATE_S = 361,
    HIRABAMI_HIDE = 353,
    HIRABAMI_HIDE_PLUS = 358,
    HIRABAMI_MOLTING = 249,
    HIRABAMI_SCALE = 352,
    HIRABAMI_SCALE_PLUS = 357,
    HIRABAMI_TAIL_CLAW = 355,
    HIRABAMI_TAIL_CLAW_PLUS = 360,
    HIRABAMI_WEBBING = 354,
    HIRABAMI_WEBBING_PLUS = 359,
    HONEY = 27,
    HOT_DRINK = 166,
    HOT_PEPPER = 477,
    HUNTER_SYMBOL_I = 658,
    HUNTER_SYMBOL_II = 659,
    HUNTER_SYMBOL_III = 660,
    ICIUM = 582,
    IMMUNIZER = 164,
    INFERNO_SAC = 593,
    IRON_ORE = 52,
    IVY = 75,
    JEWELED_MULLET_ROE = 225,
    JIN_DAHAAD_CARAPACE = 419,
    JIN_DAHAAD_CERTIFICATE_S = 424,
    JIN_DAHAAD_CLAW_PLUS = 421,
    JIN_DAHAAD_HORN = 422,
    JIN_DAHAAD_ICEGEM = 423,
    JIN_DAHAAD_ICEPLATE = 420,
    JIN_DAHAAD_SCALE_PLUS = 418,
    JIN_DAHAAD_TAIL = 706,
    KRANO_COPPER = 280,
    KRANO_PYRITE = 281,
    KRANODATH_SKULL = 495,
    KRANODATH_SKULL_PLUS = 496,
    KUNAFA_CHEESE = 212,
    KUNAFA_MEAL_VOUCHER = 806,
    KUT_KU_CARAPACE = 522,
    KUT_KU_EAR = 523,
    KUT_KU_SCALE_PLUS = 521,
    KUT_KU_WING = 525,
    LAGIACRUS_CERTIFICATE_S = 727,
    LAGIACRUS_CLAW_PLUS = 733,
    LAGIACRUS_HIDE_PLUS = 729,
    LAGIACRUS_HORN_PLUS = 731,
    LAGIACRUS_SAPPHIRE = 734,
    LAGIACRUS_SCALE_PLUS = 728,
    LAGIACRUS_SHOCKSPIKE = 730,
    LAGIACRUS_TAIL = 732,
    LALA_BARINA_CARAPACE = 306,
    LALA_BARINA_CERTIFICATE = 275,
    LALA_BARINA_CERTIFICATE_S = 309,
    LALA_BARINA_CLAW = 273,
    LALA_BARINA_CLAW_PLUS = 307,
    LALA_BARINA_FLORET = 276,
    LALA_BARINA_FLORET_PLUS = 305,
    LALA_BARINA_MUCUS = 602,
    LALA_BARINA_MUCUS_PLUS = 603,
    LALA_BARINA_SHELL = 272,
    LALA_BARINA_STINGER = 274,
    LALA_BARINA_STINGER_PLUS = 308,
    LARGE_BARREL = 636,
    LARGE_BARREL_BOMB = 14,
    LARGE_DUNG_POD = 456,
    LARGE_GOLDENSCALE_VASE = 252,
    LIFEPOWDER = 11,
    LIGHTCRYSTAL = 577,
    LURING_POD = 195,
    MACHALITE_ORE = 53,
    MANDRAGORA = 65,
    MATURE_WYVERIA_LANTERN = 254,
    MAX_POTION = 4,
    MEGA_ARMORSKIN = 172,
    MEGA_BARREL_BOMB = 196,
    MEGA_DEMONDRUG = 169,
    MEGA_POTION = 2,
    MENDING_MANTLE = 626,
    MIGHT_PILL = 168,
    MIGHT_SEED = 125,
    MILKY_COCOON_WEB = 256,
    MIMIPHYTA_TICKET = 617,
    MIZUTSUNE_CERTIFICATE_S = 719,
    MIZUTSUNE_CLAW_PLUS = 722,
    MIZUTSUNE_FIN_PLUS = 723,
    MIZUTSUNE_PURPLEFUR_PLUS = 721,
    MIZUTSUNE_SCALE_PLUS = 720,
    MIZUTSUNE_TAIL = 724,
    MIZUTSUNE_WATER_ORB = 726,
    MONSTER_BROTH = 489,
    MONSTER_CHILI = 224,
    MONSTER_FLUID = 488,
    MONSTER_HARDBONE = 655,
    MONSTER_KEENBONE = 654,
    MUD_SHRIMP = 216,
    MYSTERY_BONE = 57,
    MYSTERY_ORB___ARMOR = 155,
    MYSTERY_ORB___SWORD = 618,
    NECKLACE_TICKET = 792,
    NERSCYLLA_CARAPACE = 517,
    NERSCYLLA_CERTIFICATE = 516,
    NERSCYLLA_CERTIFICATE_S = 520,
    NERSCYLLA_CHELICERA = 513,
    NERSCYLLA_CLAW = 514,
    NERSCYLLA_CLAW_PLUS = 518,
    NERSCYLLA_SHEAR = 479,
    NERSCYLLA_SHELL = 512,
    NERSCYLLA_SPIKE = 515,
    NERSCYLLA_SPIKE_PLUS = 519,
    NET = 638,
    NIGHTFLOWER_POLLEN = 265,
    NITROSHROOM = 127,
    NORMAL_AMMO = 37,
    NOURISHING_EXTRACT = 438,
    NOVACRYSTAL = 578,
    NU_UDRA_CEREBROSPINAL_FLUID = 380,
    NU_UDRA_CERTIFICATE = 381,
    NU_UDRA_CERTIFICATE_S = 388,
    NU_UDRA_FLAMEGEM = 387,
    NU_UDRA_HIDE = 375,
    NU_UDRA_HIDE_PLUS = 382,
    NU_UDRA_HORN = 377,
    NU_UDRA_HORN_PLUS = 384,
    NU_UDRA_OILMUCUS = 379,
    NU_UDRA_OILMUCUS_PLUS = 386,
    NU_UDRA_SPIKE = 376,
    NU_UDRA_SPIKE_PLUS = 383,
    NU_UDRA_TENTACLE = 378,
    NU_UDRA_TENTACLE_PLUS = 385,
    NULBERRY = 6,
    OLD_WEAPON_SHARD___BLADE = 685,
    OLD_WEAPON_SHARD___DEVICE = 688,
    OLD_WEAPON_SHARD___DISC = 687,
    OLD_WEAPON_SHARD___TUBE = 686,
    ORICALCITE = 668,
    ORIGIN_WYLK_GEM = 255,
    PAINT_POD = 194,
    PARA_POD = 183,
    PARALYSIS_AMMO = 48,
    PARALYSIS_COATING = 678,
    PARALYSIS_KNIFE = 146,
    PARASHROOM = 113,
    PICK_A_MEAL_VOUCHER = 645,
    PIERCE_AMMO = 38,
    PIERCE_COATING = 677,
    PIERCING_POD = 191,
    PINNACLE_COIN = 805,
    PIRAGILL_FIN = 492,
    PIRAGILL_FIN_PLUS = 493,
    PITFALL_TRAP = 18,
    PLATINUM_SCALE = 644,
    POISON_AMMO = 47,
    POISON_COATING = 679,
    POISON_KNIFE = 145,
    POISON_POD = 182,
    POISON_SAC = 600,
    POISON_SMOKE_BOMB = 179,
    POISONED_MEAT = 210,
    PORTABLE_BBQ_GRILL = 24,
    POTION = 1,
    POWER_COATING = 676,
    POWERCHARM = 151,
    PUDDLE_POD = 189,
    PURE_FULGURITE = 236,
    QUALITY_BONE = 588,
    QUEENSBLOOM_POLLEN = 241,
    QUEMATRICE_CERTIFICATE = 299,
    QUEMATRICE_CERTIFICATE_S = 304,
    QUEMATRICE_CREST = 89,
    QUEMATRICE_CREST_PLUS = 303,
    QUEMATRICE_HIDE = 88,
    QUEMATRICE_HIDE_PLUS = 301,
    QUEMATRICE_IGNITER = 298,
    QUEMATRICE_IGNITER_PLUS = 302,
    QUEMATRICE_SCALE = 87,
    QUEMATRICE_SCALE_PLUS = 300,
    QUEMATRICE_TAIL = 90,
    RARE_STEAK = 9,
    RATH_MEDULLA = 410,
    RATHALOS_CARAPACE = 556,
    RATHALOS_CERTIFICATE_S = 560,
    RATHALOS_RUBY = 559,
    RATHALOS_SCALE_PLUS = 555,
    RATHALOS_TAIL = 558,
    RATHALOS_WING = 557,
    RATHIAN_CARAPACE = 102,
    RATHIAN_CERTIFICATE_S = 535,
    RATHIAN_COIN = 777,
    RATHIAN_RUBY = 105,
    RATHIAN_SCALE_PLUS = 101,
    RATHIAN_SPIKE_PLUS = 104,
    RATHIAN_WEBBING = 103,
    RATION = 7,
    RAW_MEAT = 12,
    RECOVER_AMMO = 414,
    REY_DAU_BOLTGEM = 350,
    REY_DAU_BOLTHORN = 348,
    REY_DAU_CARAPACE = 347,
    REY_DAU_CERTIFICATE = 345,
    REY_DAU_CERTIFICATE_S = 351,
    REY_DAU_CERTIFICATE_GAMMA = 756,
    REY_DAU_FULGURTALON = 349,
    REY_DAU_PLATE = 143,
    REY_DAU_SCALE = 138,
    REY_DAU_SCALE_PLUS = 346,
    REY_DAU_SHELL = 139,
    REY_DAU_TAIL = 142,
    REY_DAU_THUNDERHORN = 140,
    REY_DAU_WINGTALON = 141,
    ROCKSTEADY_MANTLE = 625,
    ROLLED_UP_DUNG = 100,
    ROMPOPOLO_BEAK = 338,
    ROMPOPOLO_BEAK_PLUS = 343,
    ROMPOPOLO_CERTIFICATE = 339,
    ROMPOPOLO_CERTIFICATE_S = 344,
    ROMPOPOLO_CLAW = 336,
    ROMPOPOLO_CLAW_PLUS = 341,
    ROMPOPOLO_HIDE = 335,
    ROMPOPOLO_HIDE_PLUS = 340,
    ROYAL_SEA_POT = 262,
    RUBBERY_HIDE = 527,
    RUBBERY_HIDE_PLUS = 528,
    RUSTED_WEAPON_SHARD = 159,
    SANDPEPPER = 233,
    SCARLET_AMBER_SHARD = 238,
    SCARRED_SCALE = 472,
    SCREAMER_POD = 69,
    SCREAMER_POD_2 = 277,
    SEALED_DRAGON_CLOTH = 790,
    SEREGIOS_AIRBLADE = 548,
    SEREGIOS_BREACHER = 551,
    SEREGIOS_CARVER = 549,
    SEREGIOS_CERTIFICATE_S = 554,
    SEREGIOS_DISSENTER = 553,
    SEREGIOS_IMPALER = 550,
    SEREGIOS_SCRAPER = 552,
    SEREGIOS_SLAVESCALE = 547,
    SF6_TICKET = 779,
    SHARP_FANG = 95,
    SHARP_KUNAFA_CHEESE = 213,
    SHINY_TREASURE = 242,
    SHOCK_TRAP = 19,
    SILD_COTTON = 612,
    SILD_GARLIC = 220,
    SILD_MEAL_VOUCHER = 808,
    SILVER_EGG = 651,
    SILVER_MELDING_TICKET = 647,
    SILVER_RELIC_TICKET = 649,
    SINISTER_CLOTH = 228,
    SLASHBERRY = 130,
    SLEEP_AMMO = 49,
    SLEEP_COATING = 680,
    SLEEP_HERB = 114,
    SLEEP_KNIFE = 147,
    SLEEP_SAC = 604,
    SLICING_AMMO = 50,
    SMALL_BARREL = 635,
    SMOKE_BOMB = 150,
    SMOKENUT = 74,
    SNOW_HERB = 117,
    SPARKLY_TREASURE = 243,
    SPEARTUNA_FIN = 614,
    SPECIALTY_SILD_GARLIC = 221,
    SPECKLITE = 666,
    SPIDER_WEB = 637,
    SPOTTED_POISON_HIDE = 337,
    SPOTTED_POISON_HIDE_PLUS = 342,
    SPREAD_AMMO = 39,
    STEEL_EGG = 650,
    STEEL_MELDING_TICKET = 646,
    STEEL_RELIC_TICKET = 648,
    STICKY_AMMO = 40,
    STONE = 16,
    STOUTBONE = 656,
    STURDY_BONE = 58,
    SUJA_MEAL_VOUCHER = 809,
    SUJA_TEXTILES = 611,
    SUSHIFISH_SCALE = 271,
    TALIOTH_SCALE = 94,
    TALIOTH_SCALE_PLUS = 490,
    TENTACLE_JIG = 674,
    THORNGRASS_POD = 51,
    THROWING_KNIFE = 181,
    THUNDER_AMMO = 44,
    THUNDER_POD = 284,
    THUNDER_SAC = 597,
    THUNDERBUG_CAPACITOR = 31,
    THUNDERING_FULGURITE = 237,
    TIME_HONED_WYLK_GEM = 259,
    TINGED_MEAT = 207,
    TOADSTOOL = 112,
    TOE_BEAN_TICKET = 794,
    TORCH_POD = 188,
    TORRENT_SAC = 595,
    TOUGH_GUARDIAN_BONE = 587,
    TOXIN_SAC = 601,
    TRANQ_AMMO = 415,
    TRANQ_BLADE = 144,
    TRANQ_BOMB = 180,
    TRAP_TOOL = 72,
    TRUFFLE_DU_CONGA = 227,
    TUFF_JOINT_BAIT = 672,
    TURBID_SHRIMP = 217,
    UTH_DUNA_CERTIFICATE = 327,
    UTH_DUNA_CERTIFICATE_S = 334,
    UTH_DUNA_CERTIFICATE_GAMMA = 757,
    UTH_DUNA_CILIA = 323,
    UTH_DUNA_CILIA_PLUS = 330,
    UTH_DUNA_CLAW = 325,
    UTH_DUNA_CLAW_PLUS = 332,
    UTH_DUNA_HIDE = 322,
    UTH_DUNA_HIDE_PLUS = 329,
    UTH_DUNA_PLATE = 326,
    UTH_DUNA_SCALE = 321,
    UTH_DUNA_SCALE_PLUS = 328,
    UTH_DUNA_TENTACLE = 324,
    UTH_DUNA_TENTACLE_PLUS = 331,
    UTH_DUNA_WATERGEM = 333,
    VALUABLE_MATERIAL = 470,
    VESPOID_CARAPACE = 573,
    VESPOID_INNERWING = 575,
    VESPOID_SHELL = 572,
    VESPOID_WING = 574,
    VIBRANT_PELT = 506,
    VIBRANT_PELT_PLUS = 511,
    WATER_AMMO = 43,
    WELL_DONE_STEAK = 8,
    WHETFISH_FIN = 270,
    WHETFISH_FIN_PLUS = 683,
    WHETSTONE = 20,
    WHITE_ARKVELD_PELT = 461,
    WILD_HERB = 222,
    WILD_JERKY = 631,
    WILD_SEED_OIL = 226,
    WINDWARD_ALOE = 230,
    WINGDRAKE_HIDE = 96,
    WINGDRAKE_HIDE_PLUS = 491,
    WORN_PICKAXE = 767,
    WUDWUD_TREASURE = 632,
    WYLK_GEM = 258,
    WYLK_PEBBLE = 257,
    WYVERIA_LANTERN = 253,
    WYVERIAN_BLOODSTONE = 700,
    WYVERIAN_BLOODSTONE_L = 701,
    WYVERIAN_BLOODSTONE_S = 699,
    WYVERIAN_BLOODSTONE_CHUNK = 702,
    WYVERIAN_BLOODSTONE_SHARD = 698,
    WYVERN_AMMO = 153,
    WYVERN_EGG = 629,
    WYVERN_GEM = 91,
    WYVERNSCALE_VASE = 250,
    WYVERNSPROUT = 269,
    XU_WU_CEREBROSPINAL_FLUID = 444,
    XU_WU_CERTIFICATE = 445,
    XU_WU_CERTIFICATE_S = 297,
    XU_WU_CLAW = 442,
    XU_WU_CLAW_PLUS = 449,
    XU_WU_FANG = 443,
    XU_WU_FANG_PLUS = 450,
    XU_WU_HIDE = 439,
    XU_WU_HIDE_PLUS = 446,
    XU_WU_TENTACLE = 441,
    XU_WU_TENTACLE_PLUS = 448,
    XU_WU_UMBRAGEM = 451,
    YIAN_KUT_KU_CERTIFICATE_S = 526,
    ZOH_SHIA_CERTIFICATE_S = 709,
    ZOH_SHIA_CRYSTALHORN = 713,
    ZOH_SHIA_CRYSTALSCALE = 710,
    ZOH_SHIA_CRYSTALTAIL = 714,
    ZOH_SHIA_LAYERSHELL = 711,
    ZOH_SHIA_STAKECLAW = 712,
}

EnemyConstants = {
    AJARAKAN = 26,
    ARKVELD = 27,
    BALAHARA = 18,
    BLANGONGA = 7,
    CHATACABRA = 19,
    CONGALALA = 6,
    DOSHAGUMA = 16,
    GORE_MAGALA = 10,
    GRAVIOS = 3,
    GUARDIAN_ARKVELD = 28,
    GUARDIAN_DOSHAGUMA = 17,
    GUARDIAN_EBONY_ODOGARON = 15,
    GUARDIAN_FULGUR_ANJANATH = 14,
    GUARDIAN_RATHALOS = 2,
    GYPCEROS = 5,
    HIGH_PURRFORMANCE_BARREL_PUNCHER = 33,
    HIRABAMI = 29,
    JIN_DAHAAD = 30,
    LAGIACRUS = 8,
    LALA_BARINA = 21,
    MIZUTSUNE = 13,
    NERSCYLLA = 9,
    NU_UDRA = 25,
    QUEMATRICE = 20,
    RATHALOS = 1,
    RATHIAN = 0,
    REY_DAU = 23,
    ROMPOPOLO = 22,
    SEREGIOS = 11,
    UTH_DUNA = 24,
    XU_WU = 31,
    YIAN_KUT_KU = 4,
    ZOH_SHIA = 32,
}

LogType = {
    INVALID = -1,
    HUNT = 0,
    HUND_ADD = 1,
    EVENT = 2,
    HELP = 3,
    LUCKY = 4,
    SKILL = 5,
    MEAL_SKILL = 6,
    QUEST_RANK = 7,
    FIELD = 8,
    ANIMAL = 9,
    HAGITORI = 10,
    CAPTURE = 11,
    BREAK = 12,
    DROP = 13,
    PARTS_HAGITORI = 14,
    SCAR = 15,
    BUNDORI = 16,
    SCAR01 = 17,
}