Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
17 kB
2
Indexable
Never
namespace Newtopia {
    struct ItemInfo {
        uint32_t ID;
        uint8_t Properties;
        uint8_t PropertiesAlt;
        uint8_t Type;
        uint8_t Material;
        std::string Name = "";

        std::string Texture = "";
        uint32_t FileHash;

        uint8_t VisualType;
        uint32_t CookTime;
        uint8_t TexCoordX;
        uint8_t TexCoordY;

        uint8_t StorageType;
        uint8_t Layer;
        uint8_t CollistionType;

        uint8_t Hardness;
        uint8_t RegenTime;
        uint8_t ClothingType;
        uint16_t Rarity;
        uint8_t MaxHold;

        std::string Texture2 = "";
        uint32_t File2Hash;
        uint32_t AnimMS;

        std::string PetName; //V4
        std::string PetPrefix; //V4
        std::string PetSuffix; //V4
        std::string PetAbility; //V5

        uint8_t SeedBase;
        uint8_t SeedOver;
        uint8_t TreeBase;
        uint8_t TreeOver;
        uint32_t SeedColor;
        uint32_t TreeColor;
        uint16_t Seed1;
        uint16_t Seed2;
        uint32_t BloomTime;

        uint32_t AnimType; //V7
        std::string AnimString = ""; //V7
        std::string AnimTex = ""; //V8
        std::string AnimString2 = ""; //V8

        uint32_t DLayer1; //V8
        uint32_t DLayer2; //V8
        uint16_t Properties2; //V9

        uint8_t UnwantedV9[62] = { 0 }; //V9
        uint32_t TileRange; //V10
        uint32_t PileRange; //V10
        std::string CustomPunch = ""; //V11

        uint8_t UnwantedV12[13] = { 0 }; //V12

        uint32_t ClockDivider; //V13

        uint32_t Unk; //V14

        uint8_t CanPlayerSit; //V15
        uint32_t SitOffsetX; //V15
        uint32_t SitOffsetY; //V15
        uint32_t SitOverlayX; //V15
        uint32_t SitOverlayY; //V15
        uint32_t SitOverlayOffsetX; //V15
        uint32_t SitOverlayOffsetY; //V15
        std::string SitFile = ""; //V15

        //custom info:

        struct BattleInfo {
            uint8_t Element;
            std::string Ability;
            std::string CooldownEffect;
            std::chrono::seconds Cooldown;
            std::string Suffix;
        } BattlePet;
        bool HasPetInfo = false;

        bool ExtraData = false;
        uint8_t RenderTexCoordX = 0;
        uint8_t RenderTexCoordY = 0;
        std::string m_render_texture = "";
        std::string m_render_texture_icon = "";

        uint32_t EffectMods = 0;
        std::string Description = "This item has no description.";

        bool LockeInfo = false;
        uint32_t LockePrice = 0;
        bool LockeSale = false;
        uint32_t LockeItem = 0;

        bool Blocked = false;

        uint8_t PunchEffect = 0;
        
        bool OneHit = false;
        uint32_t RarityHit = 0;

        bool SuperPunch = false;
        uint8_t FarHit = 1;
        
        bool SuperPlace = false;
        uint8_t FarPlace = 1;

        static std::string Cypher(const std::string& input, uint32_t item_id) {
            constexpr std::string_view key{ "PBG892FXX982ABC*" };
            std::string ret(input.size(), 0);

            for (uint32_t i = 0; i < input.size(); i++)
                ret[i] = static_cast<char>(input[i] ^ key[(i + item_id) % key.size()]);
            return ret;
        }

        bool IsBackground() const {
            return Type == ITEMTYPE_BACKGROUND || Type == ITEMTYPE_BACK_BOOMBOX || Type == ITEMTYPE_MUSIC_NOTE;
        }
        bool IsWorldLock() const {
            return Type == ITEMTYPE_LOCK && ID != ITEM_SMALL_LOCK && ID != ITEM_BIG_LOCK && ID != ITEM_HUGE_LOCK && ID != ITEM_BUILDERS_LOCK && ID != ITEM_BOXED_LOCK && ID != ITEM_MEDIUM_LOCK;
        }

        std::size_t GetMemoryUsage(uint16_t DatVersion) const {
            std::size_t ret{};
            ret += sizeof(ID);
            ret += sizeof(Properties);
            ret += sizeof(PropertiesAlt);
            ret += sizeof(Type);
            ret += sizeof(Material);
            ret += sizeof(uint16_t) + Name.size();
            ret += sizeof(uint16_t) + Texture.size();
            ret += sizeof(FileHash);
            ret += sizeof(VisualType);
            ret += sizeof(CookTime);
            ret += sizeof(TexCoordX);
            ret += sizeof(TexCoordY);
            ret += sizeof(StorageType);
            ret += sizeof(Layer);
            ret += sizeof(CollistionType);
            ret += sizeof(Hardness);
            ret += sizeof(RegenTime);
            ret += sizeof(ClothingType);
            ret += sizeof(Rarity);
            ret += sizeof(MaxHold);
            ret += sizeof(uint16_t) + Texture2.size();
            ret += sizeof(File2Hash);
            ret += sizeof(AnimMS);
            if (DatVersion >= 4) {
                ret += sizeof(uint16_t) + PetName.size();
                ret += sizeof(uint16_t) + PetPrefix.size();
                ret += sizeof(uint16_t) + PetSuffix.size();
            }
            if (DatVersion >= 5) {
                ret += sizeof(uint16_t) + PetAbility.size();
            }
            ret += sizeof(SeedBase);
            ret += sizeof(SeedOver);
            ret += sizeof(TreeBase);
            ret += sizeof(TreeOver);
            ret += sizeof(SeedColor);
            ret += sizeof(TreeColor);
            ret += sizeof(Seed1);
            ret += sizeof(Seed2);
            ret += sizeof(BloomTime);
            if (DatVersion >= 7) {
                ret += sizeof(AnimType);
                ret += sizeof(uint16_t) + AnimString.size();
            }
            if (DatVersion >= 8) {
                ret += sizeof(uint16_t) + AnimTex.size();
                ret += sizeof(uint16_t) + AnimString2.size();
                ret += sizeof(DLayer1);
                ret += sizeof(DLayer2);
            }
            if (DatVersion >= 9) {
                ret += sizeof(Properties2);
                for (auto index = 0; index < 62; index++)
                    ret += sizeof(UnwantedV9[index]);
            }
            if (DatVersion >= 10) {
                ret += sizeof(TileRange);
                ret += sizeof(PileRange);
            }
            if (DatVersion >= 11) {
                ret += sizeof(uint16_t) + CustomPunch.size();
            }
            if (DatVersion >= 12) {
                for (auto index = 0; index < 13; index++)
                    ret += sizeof(UnwantedV12[index]);
            }
            if (DatVersion >= 13) {
                ret += sizeof(ClockDivider);
            }
            if (DatVersion >= 14) {
                ret += sizeof(Unk);
            }
            if (DatVersion >= 15) {
                ret += sizeof(CanPlayerSit);
                ret += sizeof(SitOffsetX);
                ret += sizeof(SitOffsetY);
                ret += sizeof(SitOverlayX);
                ret += sizeof(SitOverlayY);
                ret += sizeof(SitOverlayOffsetX);
                ret += sizeof(SitOverlayOffsetY);
                ret += sizeof(uint16_t) + SitFile.size();
            }
            return ret;
        }
        void Pack(BinaryWriter& Buf, uint16_t DatVersion) {
            Buf.write<uint32_t>(ID);
            Buf.write<uint8_t>(Properties);
            Buf.write<uint8_t>(PropertiesAlt);
            Buf.write<uint8_t>(Type);
            Buf.write<uint8_t>(Material);
            (DatVersion >= 3 ? Buf.write(this->Cypher(Name, ID)) : Buf.write(Name));
            Buf.write(Texture);
            Buf.write<uint32_t>(FileHash);
            Buf.write<uint8_t>(VisualType);
            Buf.write<uint32_t>(CookTime);
            Buf.write<uint8_t>(TexCoordX);
            Buf.write<uint8_t>(TexCoordY);
            Buf.write<uint8_t>(StorageType);
            Buf.write<uint8_t>(Layer);
            Buf.write<uint8_t>(CollistionType);
            Buf.write<uint8_t>(Hardness * 6);
            Buf.write<uint32_t>(RegenTime);
            Buf.write<uint8_t>(ClothingType);
            Buf.write<uint16_t>(Rarity);
            Buf.write<uint8_t>(MaxHold);
            Buf.write(Texture2);
            Buf.write<uint32_t>(File2Hash);
            Buf.write<uint32_t>(AnimMS);
            if (DatVersion >= 4) {
                Buf.write(PetName);
                Buf.write(PetPrefix);
                Buf.write(PetSuffix);
            }
            if (DatVersion >= 5) {
                Buf.write(PetAbility);
            }
            Buf.write<uint8_t>(SeedBase);
            Buf.write<uint8_t>(SeedOver);
            Buf.write<uint8_t>(TreeBase);
            Buf.write<uint8_t>(TreeOver);
            Buf.write<uint32_t>(SeedColor);
            Buf.write<uint32_t>(TreeColor);
            Buf.write<uint16_t>(Seed1);
            Buf.write<uint16_t>(Seed2);
            Buf.write<uint32_t>(BloomTime);
            if (DatVersion >= 7) {
                Buf.write<uint32_t>(AnimType);
                Buf.write(AnimString);
            }
            if (DatVersion >= 8) {
                Buf.write(AnimTex);
                Buf.write(AnimString2);
                Buf.write<uint32_t>(DLayer1);
                Buf.write<uint32_t>(DLayer2);
            }
            if (DatVersion >= 9) {
                Buf.write<uint16_t>(Properties2);
                for (auto index = 0; index < 62; index++)
                    Buf.write<uint8_t>(UnwantedV9[index]);
            }
            if (DatVersion >= 10) {
                Buf.write<uint32_t>(TileRange);
                Buf.write<uint32_t>(PileRange);
            }
            if (DatVersion >= 11) {
                Buf.write(CustomPunch);
            }
            if (DatVersion >= 12) {
                for (auto index = 0; index < 13; index++)
                    Buf.write<uint8_t>(UnwantedV12[index]);
            }
            if (DatVersion >= 13) {
                Buf.write<uint32_t>(ClockDivider);
            }
            if (DatVersion >= 14) {
                Buf.write<uint32_t>(Unk);
            }
            if (DatVersion >= 15) {
                Buf.write<uint8_t>(CanPlayerSit);
                Buf.write<uint32_t>(SitOffsetX);
                Buf.write<uint32_t>(SitOffsetY);
                Buf.write<uint32_t>(SitOverlayX);
                Buf.write<uint32_t>(SitOverlayY);
                Buf.write<uint32_t>(SitOverlayOffsetX);
                Buf.write<uint32_t>(SitOverlayOffsetY);
                Buf.write(SitFile);
            }
        }
        void Serialize(BinaryReader& br, uint16_t DatVersion) {
            ID = br.read<uint32_t>();
            Properties = br.read<uint8_t>();
            PropertiesAlt = br.read<uint8_t>();
            Type = br.read<uint8_t>();
            Material = br.read<uint8_t>();
            Name = (DatVersion >= 3 ? this->Cypher(br.read_string(), ID) : br.read_string());
            Texture = br.read_string();
            FileHash = br.read<uint32_t>();
            VisualType = br.read<uint8_t>();
            CookTime = br.read<uint32_t>();
            TexCoordX = br.read<uint8_t>();
            TexCoordY = br.read<uint8_t>();
            StorageType = br.read<uint8_t>();
            Layer = br.read<uint8_t>();
            CollistionType = br.read<uint8_t>();
            Hardness = br.read<uint8_t>() / 6;
            RegenTime = br.read<uint32_t>();
            ClothingType = br.read<uint8_t>();
            Rarity = br.read<uint16_t>();
            MaxHold = br.read<uint8_t>();
            Texture2 = br.read_string();
            File2Hash = br.read<uint32_t>();
            AnimMS = br.read<uint32_t>();
            if (DatVersion >= 4) {
                PetName = br.read_string();
                PetPrefix = br.read_string();
                PetSuffix = br.read_string();
            }
            if (DatVersion >= 5) {
                PetAbility = br.read_string();
            }
            SeedBase = br.read<uint8_t>();
            SeedOver = br.read<uint8_t>();
            TreeBase = br.read<uint8_t>();
            TreeOver = br.read<uint8_t>();
            SeedColor = br.read<uint32_t>();
            TreeColor = br.read<uint32_t>();
            Seed1 = br.read<uint16_t>();
            Seed2 = br.read<uint16_t>();
            BloomTime = br.read<uint32_t>();
            BloomTime = BloomTime / 3;
            if (DatVersion >= 7) {
                AnimType = br.read<uint32_t>();
                AnimString = br.read_string();
            }
            if (DatVersion >= 8) {
                AnimTex = br.read_string();
                AnimString2 = br.read_string();
                DLayer1 = br.read<uint32_t>();
                DLayer2 = br.read<uint32_t>();
            }
            if (DatVersion >= 9) {
                Properties2 = br.read<uint16_t>();
                for (auto index = 0; index < 62; index++)
                    UnwantedV9[index] = br.read<uint8_t>();
            }
            if (DatVersion >= 10) {
                TileRange = br.read<uint32_t>();
                PileRange = br.read<uint32_t>();
            }
            if (DatVersion >= 11) {
                CustomPunch = br.read_string();
            }
            if (DatVersion >= 12) {
                for (auto index = 0; index < 13; index++)
                    UnwantedV12[index] = br.read<uint8_t>();
            }
            if (DatVersion >= 13) {
                ClockDivider = br.read<uint32_t>();
            }
            if (DatVersion >= 14) {
                Unk = br.read<uint32_t>();
            }
            if (DatVersion >= 15) {
                CanPlayerSit = br.read<uint8_t>();
                SitOffsetX = br.read<uint32_t>();
                SitOffsetY = br.read<uint32_t>();
                SitOverlayX = br.read<uint32_t>();
                SitOverlayY = br.read<uint32_t>();
                SitOverlayOffsetX = br.read<uint32_t>();
                SitOverlayOffsetY = br.read<uint32_t>();
                SitFile = br.read_string();
            }
            switch (Type)
            {
                case ITEMTYPE_DOOR: case ITEMTYPE_LOCK: case ITEMTYPE_SIGN:
                case ITEMTYPE_MAIN_DOOR: case ITEMTYPE_SEED: case ITEMTYPE_PORTAL:
                case ITEMTYPE_MAILBOX: case ITEMTYPE_BULLETIN: case ITEMTYPE_DICE:
                case ITEMTYPE_PROVIDER: case ITEMTYPE_ACHIEVEMENT: case ITEMTYPE_SUNGATE:
                case ITEMTYPE_HEART_MONITOR: case ITEMTYPE_DONATION_BOX: case ITEMTYPE_TOYBOX:
                case ITEMTYPE_MANNEQUIN: case ITEMTYPE_SECURITY_CAMERA: case ITEMTYPE_MAGIC_EGG:
                case ITEMTYPE_GAME_RESOURCES: case ITEMTYPE_GAME_GENERATOR: case ITEMTYPE_XENONITE:
                case ITEMTYPE_DRESSUP: case ITEMTYPE_CRYSTAL: case ITEMTYPE_BURGLAR:
                case ITEMTYPE_SPOTLIGHT: case ITEMTYPE_DISPLAY_BLOCK: case ITEMTYPE_VENDING_MACHINE:
                case ITEMTYPE_FISHTANK: case ITEMTYPE_SOLAR: case ITEMTYPE_FORGE: case ITEMTYPE_GIVING_TREE:
                case ITEMTYPE_GIVING_TREE_STUMP: case ITEMTYPE_STEAM_ORGAN: case ITEMTYPE_TAMAGOTCHI: case ITEMTYPE_SWING:
                case ITEMTYPE_FLAG: case ITEMTYPE_LOBSTER_TRAP: case ITEMTYPE_ART_CANVAS: case ITEMTYPE_BATTLE_CAGE:
                case ITEMTYPE_PET_TRAINER: case ITEMTYPE_STEAM_ENGINE: case ITEMTYPE_LOCKBOT: case ITEMTYPE_WEATHER_SPECIAL:
                case ITEMTYPE_SPIRIT_STORAGE: case ITEMTYPE_DISPLAY_SHELF: case ITEMTYPE_VIP_ENTRANCE: case ITEMTYPE_CHALLENGE_TIMER:
                case ITEMTYPE_CHALLENGE_FLAG: case ITEMTYPE_FISH_MOUNT: case ITEMTYPE_PORTRAIT: case ITEMTYPE_WEATHER_SPECIAL2:
                case ITEMTYPE_FOSSIL_PREP: case ITEMTYPE_DNA_MACHINE: case ITEMTYPE_BLASTER: case ITEMTYPE_CHEMTANK:
                case ITEMTYPE_STORAGE: case ITEMTYPE_OVEN: case ITEMTYPE_SUPER_MUSIC: case ITEMTYPE_GEIGER_CHARGER:
                case ITEMTYPE_ADVENTURE_RESET: case ITEMTYPE_TOMB_ROBBER: case ITEMTYPE_FACTION: case ITEMTYPE_RED_FACTION:
                case ITEMTYPE_GREEN_FACTION: case ITEMTYPE_BLUE_FACTION: case ITEMTYPE_FISHGOTCHI_TANK: case ITEMTYPE_ITEM_SUCKER:
                case ITEMTYPE_ROBOT: case ITEMTYPE_TICKET: case ITEMTYPE_STATS_BLOCK: case ITEMTYPE_FIELD_NODE: case ITEMTYPE_OUIJA_BOARD:
                case ITEMTYPE_AUTO_ACTION_BREAK: case ITEMTYPE_AUTO_ACTION_HARVEST: case ITEMTYPE_AUTO_ACTION_HARVEST_SUCK: case ITEMTYPE_LIGHTNING_IF_ON:
                case ITEMTYPE_PHASED_BLOCK: case ITEMTYPE_PASSWORD_STORAGE: case ITEMTYPE_PHASED_BLOCK_2: case ITEMTYPE_WEATHER_INFINITY:
                case ITEMTYPE_KRANKENS_BLOCK: case ITEMTYPE_FRIENDS_ENTRANCE: case 30: case 133: {
                    ExtraData = true;
                } break;
            }
        }
    };
}
Leave a Comment