 /* This program is free software. It comes without any warranty, to
 * the extent permitted by applicable law. You can redistribute it
 * and/or modify it under the terms of the Do What The Fuck You Want
 * To Public License, Version 2, as published by Sam Hocevar. See
 * http://sam.zoy.org/wtfpl/COPYING for more details. */

#define BIG_ENDIAN 1

// Types...
#if BIG_ENDIAN == 0
	#define SECTION_STRING 0x00030400
	#define SECTION_ARRAY 0x000C0400
	#define SECTION_STRUCT_BI 0x000A0400
	#define SECTION_SCRIPT 0x00070400

	#define ARRAY_VECTOR 0x00000100
	#define ARRAY_QBKEY 0x000D0100

	#define STRUCT_INIT 0x00010000
	#define STRUCT_SUBITEM 0x00001500
	#define STRUCT_CRC 0x00003500
	#define STRUCT_CRC_BI 0x00001B00
	#define STRUCT_STRING 0x00000700
	#define STRUCT_INTEGER 0x00000300
	#define STRUCT_FLOAT 0x00000500
#elif BIG_ENDIAN == 1
	#define SECTION_STRING 0x00032000
	#define SECTION_ARRAY 0x000C2000
	#define SECTION_STRUCT_BI 0x000A2000
	#define SECTION_SCRIPT 0x00072000

	#define ARRAY_VECTOR 0x00000100
	#define ARRAY_QBKEY 0x000D0100

	#define STRUCT_INIT 0x00010000
	#define STRUCT_SUBITEM 0x00008A00
	#define STRUCT_CRC 0x00009A00
	#define STRUCT_CRC_BI 0x00008D00
	#define STRUCT_STRING 0x00008300
	#define STRUCT_INTEGER 0x00008100
	#define STRUCT_FLOAT 0x00008200
#endif

// A songlist entry
typedef struct
{
	unsigned int internalFlags; // internal "flags" to show the present values

	unsigned int songNameChecksum;
	char songInternalName[DEFAULT_BUFFER];
	char songName[DEFAULT_BUFFER];
	char songAuthor[DEFAULT_BUFFER];
	char songYear[DEFAULT_BUFFER];
	unsigned int artistTextKey;
	char artistText[DEFAULT_BUFFER];
	signed int isOriginalArtist;
	unsigned int startupScript;
	unsigned int gameVersion;
	signed int useLeaderboard;
	signed int gemOffset;
	signed int fretbarOffset;
	signed int inputOffset;
	unsigned int bossId;
	char forcedBassist[DEFAULT_BUFFER];
	unsigned int singerType;
	unsigned int useKeyboard;
	unsigned int exitScript;
	unsigned int nullParam;
	char countOff[DEFAULT_BUFFER];
	signed int useRhythmTrack;
	float bandVolume;
	float guitarVolume;
	float hammerOnMeasureScale;
} QBSongInfo;

typedef struct
{
	unsigned int sectionName;
	unsigned int unknownNumber;
	unsigned int uncompressedSize;
	unsigned int compressedSize;
	char *scriptData;
} ScriptInfo;

// QB return info, a compact structure with all required info in one variable.
typedef struct
{
	char textBy[DEFAULT_BUFFER];
	char textAsMadeFamousBy[DEFAULT_BUFFER];
	int numSongIdentifiers;
	unsigned int *songIdentifiers;
	int numSongs;
	QBSongInfo **songs;
	int numScripts;
	ScriptInfo **scripts;
} QBReturnInfo;

// QB header
typedef struct
{
	unsigned int magic;
	int fileSize;
} QBHeader;

// Flags...
#define IS_SONGNAMECHECKSUM 1
#define IS_SONGINTERNALNAME 2
#define IS_SONGNAME 4
#define IS_SONGAUTHOR 8
#define IS_SONGYEAR 16
#define IS_ARTISTTEXTKEY 32
#define IS_ARTISTTEXT 64
#define IS_ISORIGINALARTIST 128
#define IS_STARTUPSCRIPT 256
#define IS_GAMEVERSION 512
#define IS_USELEADERBOARD 1024
#define IS_GEMOFFSET 2048
#define IS_FRETBAROFFSET 4096
#define IS_INPUTOFFSET 8192
#define IS_BOSSID 16384
#define IS_FORCEDBASSIST 32768
#define IS_SINGERTYPE 65536
#define IS_USEKEYBOARD 131072
#define IS_EXITSCRIPT 262144
#define IS_NULLPARAM 524288
#define IS_COUNTOFF 1048576
#define IS_USERHYTHMTRACK 2097152
#define IS_BANDVOLUME 4194304
#define IS_GUITARVOLUME 8388608
#define IS_HAMMERONMEASURESCALE 16777216
