#pragma once

#include "game.hpp"

namespace xassets
{
	struct raw_file_header
	{
		uint64_t name{};
		uint64_t pad8{};
		uint64_t size{};
		const char* buffer{};
	};

	struct scriptparsetree_header
	{
		uint64_t name{};
		uint64_t pad8{};
		game::GSC_OBJ* buffer{};
		uint32_t size{};
		uint32_t pad20{};
	};

	struct lua_file_header
	{
		uint64_t name{};
		uint64_t pad8{};
		uint64_t size{};
		byte* buffer{};
	};

	struct localize_entry_header {
		const char* string = "";
		uint64_t name{};
		uint64_t namepad{};
	};

	union stringtable_cell_value
	{
		byte bytes[0x10];
		const char* string_value;
		int64_t int_value;
		float float_value;
		byte bool_value;
		uint64_t hash_value;
	};

	enum stringtable_cell_type : byte
	{
		STC_TYPE_UNDEFINED = 0,
		STC_TYPE_STRING = 1,
		STC_TYPE_HASHED2 = 2,
		STC_TYPE_INT = 4,
		STC_TYPE_FLOAT = 5,
		STC_TYPE_BOOL = 6,
		STC_TYPE_HASHED7 = 7,
		STC_TYPE_HASHED8 = 8,
	};

	struct stringtable_cell
	{
		stringtable_cell_value value{};
		uint32_t pad10{};
		stringtable_cell_type type{};
	};

	struct stringtable_header
	{
		uint64_t name{};
		int32_t pad8{};
		int32_t pad12{};
		int32_t columns_count{};
		int32_t rows_count{};
		int32_t cells_count{}; // 0
		int32_t unk24{};
		uintptr_t cells{}; // empty
		stringtable_cell* values{};
		uintptr_t unk48{};
		uintptr_t unk56{};
	};

	union xasset_header
	{
		raw_file_header* raw_file;
		lua_file_header* lua_file;
		scriptparsetree_header* scriptparsetree;
		stringtable_header* stringtable;
		localize_entry_header* localize;
		void* ptr;
	};

	enum XAssetType : byte
	{
		ASSET_TYPE_PHYSPRESET = 0x0,
		ASSET_TYPE_PHYSCONSTRAINTS = 0x1,
		ASSET_TYPE_DESTRUCTIBLEDEF = 0x2,
		ASSET_TYPE_XANIM = 0x3,
		ASSET_TYPE_XMODEL = 0x4,
		ASSET_TYPE_XMODELMESH = 0x5,
		ASSET_TYPE_MATERIAL = 0x6,
		ASSET_TYPE_COMPUTE_SHADER_SET = 0x7,
		ASSET_TYPE_TECHNIQUE_SET = 0x8,
		ASSET_TYPE_IMAGE = 0x9,
		ASSET_TYPE_SOUND = 0xA,
		ASSET_TYPE_CLIPMAP = 0xB,
		ASSET_TYPE_COMWORLD = 0xC,
		ASSET_TYPE_GAMEWORLD = 0xD,
		ASSET_TYPE_GFXWORLD = 0xE,
		ASSET_TYPE_FONTICON = 0xF,
		ASSET_TYPE_LOCALIZE_ENTRY = 0x10,
		ASSET_TYPE_LOCALIZE_LIST = 0x11,
		ASSET_TYPE_GESTURE = 0x12,
		ASSET_TYPE_GESTURE_TABLE = 0x13,
		ASSET_TYPE_WEAPON = 0x14,
		ASSET_TYPE_WEAPON_FULL = 0x15,
		ASSET_TYPE_WEAPON_TUNABLES = 0x16,
		ASSET_TYPE_CGMEDIA = 0x17,
		ASSET_TYPE_PLAYERSOUNDS = 0x18,
		ASSET_TYPE_PLAYERFX = 0x19,
		ASSET_TYPE_SHAREDWEAPONSOUNDS = 0x1A,
		ASSET_TYPE_ATTACHMENT = 0x1B,
		ASSET_TYPE_ATTACHMENT_UNIQUE = 0x1C,
		ASSET_TYPE_WEAPON_CAMO = 0x1D,
		ASSET_TYPE_CUSTOMIZATION_TABLE = 0x1E,
		ASSET_TYPE_CUSTOMIZATION_TABLE_FE_IMAGES = 0x1F,
		ASSET_TYPE_SNDDRIVER_GLOBALS = 0x20,
		ASSET_TYPE_FX = 0x21,
		ASSET_TYPE_TAGFX = 0x22,
		ASSET_TYPE_KLF = 0x23,
		ASSET_TYPE_IMPACT_FX = 0x24,
		ASSET_TYPE_IMPACT_SOUND = 0x25,
		ASSET_TYPE_AITYPE = 0x26,
		ASSET_TYPE_CHARACTER = 0x27,
		ASSET_TYPE_XMODELALIAS = 0x28,
		ASSET_TYPE_RAWFILE = 0x29,
		ASSET_TYPE_XANIM_TREE = 0x2A,
		ASSET_TYPE_STRINGTABLE = 0x2B,
		ASSET_TYPE_STRUCTURED_TABLE = 0x2C,
		ASSET_TYPE_LEADERBOARD = 0x2D,
		ASSET_TYPE_DDL = 0x2E,
		ASSET_TYPE_GLASSES = 0x2F,
		ASSET_TYPE_SCRIPTPARSETREE = 0x30,
		ASSET_TYPE_SCRIPTPARSETREEDBG = 0x31,
		ASSET_TYPE_SCRIPTPARSETREEFORCED = 0x32,
		ASSET_TYPE_KEYVALUEPAIRS = 0x33,
		ASSET_TYPE_VEHICLEDEF = 0x34,
		ASSET_TYPE_TRACER = 0x35,
		ASSET_TYPE_SURFACEFX_TABLE = 0x36,
		ASSET_TYPE_SURFACESOUNDDEF = 0x37,
		ASSET_TYPE_FOOTSTEP_TABLE = 0x38,
		ASSET_TYPE_ENTITYFXIMPACTS = 0x39,
		ASSET_TYPE_ENTITYSOUNDIMPACTS = 0x3A,
		ASSET_TYPE_ZBARRIER = 0x3B,
		ASSET_TYPE_VEHICLEFXDEF = 0x3C,
		ASSET_TYPE_VEHICLESOUNDDEF = 0x3D,
		ASSET_TYPE_TYPEINFO = 0x3E,
		ASSET_TYPE_SCRIPTBUNDLE = 0x3F,
		ASSET_TYPE_SCRIPTBUNDLELIST = 0x40,
		ASSET_TYPE_RUMBLE = 0x41,
		ASSET_TYPE_BULLETPENETRATION = 0x42,
		ASSET_TYPE_LOCDMGTABLE = 0x43,
		ASSET_TYPE_AIMTABLE = 0x44,
		ASSET_TYPE_SHOOTTABLE = 0x45,
		ASSET_TYPE_PLAYERGLOBALTUNABLES = 0x46,
		ASSET_TYPE_ANIMSELECTORTABLESET = 0x47,
		ASSET_TYPE_ANIMMAPPINGTABLE = 0x48,
		ASSET_TYPE_ANIMSTATEMACHINE = 0x49,
		ASSET_TYPE_BEHAVIORTREE = 0x4A,
		ASSET_TYPE_BEHAVIORSTATEMACHINE = 0x4B,
		ASSET_TYPE_TTF = 0x4C,
		ASSET_TYPE_SANIM = 0x4D,
		ASSET_TYPE_LIGHT_DESCRIPTION = 0x4E,
		ASSET_TYPE_SHELLSHOCK = 0x4F,
		ASSET_TYPE_STATUS_EFFECT = 0x50,
		ASSET_TYPE_CINEMATIC_CAMERA = 0x51,
		ASSET_TYPE_CINEMATIC_SEQUENCE = 0x52,
		ASSET_TYPE_SPECTATE_CAMERA = 0x53,
		ASSET_TYPE_XCAM = 0x54,
		ASSET_TYPE_BG_CACHE = 0x55,
		ASSET_TYPE_TEXTURE_COMBO = 0x56,
		ASSET_TYPE_FLAMETABLE = 0x57,
		ASSET_TYPE_BITFIELD = 0x58,
		ASSET_TYPE_MAPTABLE = 0x59,
		ASSET_TYPE_MAPTABLE_LIST = 0x5A,
		ASSET_TYPE_MAPTABLE_LOADING_IMAGES = 0x5B,
		ASSET_TYPE_MAPTABLE_PREVIEW_IMAGES = 0x5C,
		ASSET_TYPE_MAPTABLEENTRY_LEVEL_ASSETS = 0x5D,
		ASSET_TYPE_OBJECTIVE = 0x5E,
		ASSET_TYPE_OBJECTIVE_LIST = 0x5F,
		ASSET_TYPE_NAVMESH = 0x60,
		ASSET_TYPE_NAVVOLUME = 0x61,
		ASSET_TYPE_LASER = 0x62,
		ASSET_TYPE_BEAM = 0x63,
		ASSET_TYPE_STREAMER_HINT = 0x64,
		ASSET_TYPE_FLOWGRAPH = 0x65,
		ASSET_TYPE_POSTFXBUNDLE = 0x66,
		ASSET_TYPE_LUAFILE = 0x67,
		ASSET_TYPE_LUAFILE_DBG = 0x68,
		ASSET_TYPE_RENDEROVERRIDEBUNDLE = 0x69,
		ASSET_TYPE_STATIC_LEVEL_FX_LIST = 0x6A,
		ASSET_TYPE_TRIGGER_LIST = 0x6B,
		ASSET_TYPE_PLAYER_ROLE_TEMPLATE = 0x6C,
		ASSET_TYPE_PLAYER_ROLE_CATEGORY_TABLE = 0x6D,
		ASSET_TYPE_PLAYER_ROLE_CATEGORY = 0x6E,
		ASSET_TYPE_CHARACTER_BODY_TYPE = 0x6F,
		ASSET_TYPE_PLAYER_OUTFIT = 0x70,
		ASSET_TYPE_GAMETYPETABLE = 0x71,
		ASSET_TYPE_FEATURE = 0x72,
		ASSET_TYPE_FEATURETABLE = 0x73,
		ASSET_TYPE_UNLOCKABLE_ITEM = 0x74,
		ASSET_TYPE_UNLOCKABLE_ITEM_TABLE = 0x75,
		ASSET_TYPE_ENTITY_LIST = 0x76,
		ASSET_TYPE_PLAYLISTS = 0x77,
		ASSET_TYPE_PLAYLIST_GLOBAL_SETTINGS = 0x78,
		ASSET_TYPE_PLAYLIST_SCHEDULE = 0x79,
		ASSET_TYPE_MOTION_MATCHING_INPUT = 0x7A,
		ASSET_TYPE_BLACKBOARD = 0x7B,
		ASSET_TYPE_TACTICALQUERY = 0x7C,
		ASSET_TYPE_PLAYER_MOVEMENT_TUNABLES = 0x7D,
		ASSET_TYPE_HIERARCHICAL_TASK_NETWORK = 0x7E,
		ASSET_TYPE_RAGDOLL = 0x7F,
		ASSET_TYPE_STORAGEFILE = 0x80,
		ASSET_TYPE_STORAGEFILELIST = 0x81,
		ASSET_TYPE_CHARMIXER = 0x82,
		ASSET_TYPE_STOREPRODUCT = 0x83,
		ASSET_TYPE_STORECATEGORY = 0x84,
		ASSET_TYPE_STORECATEGORYLIST = 0x85,
		ASSET_TYPE_RANK = 0x86,
		ASSET_TYPE_RANKTABLE = 0x87,
		ASSET_TYPE_PRESTIGE = 0x88,
		ASSET_TYPE_PRESTIGETABLE = 0x89,
		ASSET_TYPE_FIRSTPARTYENTITLEMENT = 0x8A,
		ASSET_TYPE_FIRSTPARTYENTITLEMENTLIST = 0x8B,
		ASSET_TYPE_ENTITLEMENT = 0x8C,
		ASSET_TYPE_ENTITLEMENTLIST = 0x8D,
		ASSET_TYPE_SKU = 0x8E,
		ASSET_TYPE_LABELSTORE = 0x8F,
		ASSET_TYPE_LABELSTORELIST = 0x90,
		ASSET_TYPE_CPU_OCCLUSION_DATA = 0x91,
		ASSET_TYPE_LIGHTING = 0x92,
		ASSET_TYPE_STREAMERWORLD = 0x93,
		ASSET_TYPE_TALENT = 0x94,
		ASSET_TYPE_PLAYERTALENTTEMPLATE = 0x95,
		ASSET_TYPE_PLAYERANIMATION = 0x96,
		ASSET_TYPE_ERR_UNUSED = 0x97,
		ASSET_TYPE_TERRAINGFX = 0x98,
		ASSET_TYPE_HIGHLIGHTREELINFODEFINES = 0x99,
		ASSET_TYPE_HIGHLIGHTREELPROFILEWEIGHTING = 0x9A,
		ASSET_TYPE_HIGHLIGHTREELSTARLEVELS = 0x9B,
		ASSET_TYPE_DLOGEVENT = 0x9C,
		ASSET_TYPE_RAWSTRING = 0x9D,
		ASSET_TYPE_BALLISTICDESC = 0x9E,
		ASSET_TYPE_STREAMKEY = 0x9F,
		ASSET_TYPE_RENDERTARGETS = 0xA0,
		ASSET_TYPE_DRAWNODES = 0xA1,
		ASSET_TYPE_GROUPLODMODEL = 0xA2,
		ASSET_TYPE_FXLIBRARYVOLUME = 0xA3,
		ASSET_TYPE_ARENASEASONS = 0xA4,
		ASSET_TYPE_SPRAYORGESTUREITEM = 0xA5,
		ASSET_TYPE_SPRAYORGESTURELIST = 0xA6,
		ASSET_TYPE_HWPLATFORM = 0xA7,
		ASSET_TYPE_COUNT = 0xA8,
		ASSET_TYPE_ASSETLIST = 0xA8,
		ASSET_TYPE_REPORT = 0xA9,
		ASSET_TYPE_FULL_COUNT = 0xAA,
	};

	enum BGCacheTypes : byte
	{
		BG_CACHE_TYPE_INVALID = 0,
		BG_CACHE_TYPE_VEHICLE = 1,
		BG_CACHE_TYPE_MODEL = 2,
		BG_CACHE_TYPE_AITYPE = 3,
		BG_CACHE_TYPE_CHARACTER = 4,
		BG_CACHE_TYPE_XMODELALIAS = 5,
		BG_CACHE_TYPE_WEAPON = 6,
		BG_CACHE_TYPE_GESTURE = 7,
		BG_CACHE_TYPE_GESTURETABLE = 8,
		BG_CACHE_TYPE_ZBARRIER = 9,
		BG_CACHE_TYPE_RUMBLE = 10,
		BG_CACHE_TYPE_SHELLSHOCK = 11,
		BG_CACHE_TYPE_STATUSEFFECT = 12,
		BG_CACHE_TYPE_XCAM = 13,
		BG_CACHE_TYPE_DESTRUCTIBLE = 14,
		BG_CACHE_TYPE_STREAMERHINT = 15,
		BG_CACHE_TYPE_FLOWGRAPH = 16,
		BG_CACHE_TYPE_XANIM = 17,
		BG_CACHE_TYPE_SANIM = 18,
		BG_CACHE_TYPE_SCRIPTBUNDLE = 19,
		BG_CACHE_TYPE_TALENT = 20,
		BG_CACHE_TYPE_STATUSICON = 21,
		BG_CACHE_TYPE_LOCATIONSELECTOR = 22,
		BG_CACHE_TYPE_MENU = 23,
		BG_CACHE_TYPE_MATERIAL = 24,
		BG_CACHE_TYPE_STRING = 25,
		BG_CACHE_TYPE_EVENTSTRING = 26,
		BG_CACHE_TYPE_MOVIEFILE = 27,
		BG_CACHE_TYPE_OBJECTIVE = 28,
		BG_CACHE_TYPE_FX = 29,
		BG_CACHE_TYPE_LUI_MENU_DATA = 30,
		BG_CACHE_TYPE_LUI_ELEM = 31,
		BG_CACHE_TYPE_LUI_ELEM_UID = 32,
		BG_CACHE_TYPE_RADIANT_EXPLODER = 33,
		BG_CACHE_TYPE_SOUNDALIAS = 34,
		BG_CACHE_TYPE_CLIENT_FX = 35,
		BG_CACHE_TYPE_CLIENT_TAGFXSET = 36,
		BG_CACHE_TYPE_CLIENT_LUI_ELEM = 37,
		BG_CACHE_TYPE_CLIENT_LUI_ELEM_UID = 38,
		BG_CACHE_TYPE_REQUIRES_IMPLEMENTS = 39,
		BG_CACHE_TYPE_COUNT
	};

	struct bg_cache_info_def
	{
		BGCacheTypes type;
		game::BO4_AssetRef_t name;
		uint64_t asset;
	};

	struct bg_cache_info
	{
		game::BO4_AssetRef_t name{};
		bg_cache_info_def* def{};
		int defCount{};
	};

	struct xasset_type_info {
		const char* name;
		uint64_t unk8;
		uint64_t unk10;
		game::BO4_AssetRef_t* (*get_name)(game::BO4_AssetRef_t* name, const void* header);
		void(*set_name)(void* header, game::BO4_AssetRef_t* name);
	};

	WEAK game::symbol<xasset_type_info> s_XAssetTypeInfo{ 0x14498BB00_g };

	WEAK game::symbol<void(bg_cache_info* cache, int32_t flags)> Demo_AddBGCacheAndRegister{ 0x1405CF5A0_g };
	WEAK game::symbol<int(BGCacheTypes type, game::BO4_AssetRef_t* name)> BG_Cache_RegisterAndGet{ 0x1405CEC20_g };
	WEAK game::symbol<BGCacheTypes(const char* name)> BG_Cache_GetTypeIndexInternal{ 0x1405CDBD0_g };
	BGCacheTypes BG_Cache_GetTypeIndex(const char* name);
	const char* BG_Cache_GetTypeName(BGCacheTypes type);
	XAssetType DB_GetXAssetTypeIndex(const char* name);
	const char* DB_GetXAssetTypeName(XAssetType type);

	WEAK game::symbol<xasset_header(XAssetType type, game::BO4_AssetRef_t* name, bool errorIfMissing, int waittime)> DB_FindXAssetHeader{ 0x142EB75B0_g };
}