예제 #1
0
    // METHODS
    public static SourceStaticProps createLump(byte[] data, mapType type, int version)
    {
        int structLength = 0;

        string[]          dictionary = new string[0];
        SourceStaticProps lump;

        if (data.Length > 0)
        {
            /*switch(type) { // It's possible to determine structlength using arithmetic rather than version numbering
             * case mapType.TYPE_SOURCE17:
             * case mapType.TYPE_SOURCE18:
             * case mapType.TYPE_SOURCE19:
             * case mapType.TYPE_SOURCE20:
             * case mapType.TYPE_SOURCE21:
             * case mapType.TYPE_SOURCE22:
             * case mapType.TYPE_SOURCE23:
             *      switch(version) {
             *              case 4:
             *                      structLength=56;
             *                      break;
             *              case 5:
             *                      structLength=60;
             *                      break;
             *              case 6:
             *                      structLength=64;
             *                      break;
             *              case 7:
             *                      structLength=68;
             *                      break;
             *              case 8:
             *                      structLength=72;
             *                      break;
             *              case 9:
             *                      structLength=73; // ??? The last entry is a boolean, is it stored as a byte?
             *                      break;
             *              default:
             *                      structLength=0;
             *                      break;
             *              default:
             *                      structLength=0;
             *      }*/
            int offset = 0;
            dictionary = new string[DataReader.readInt(data[offset++], data[offset++], data[offset++], data[offset++])];
            for (int i = 0; i < dictionary.Length; i++)
            {
                byte[] temp = new byte[128];
                for (int j = 0; j < 128; j++)
                {
                    temp[j] = data[offset++];
                }
                dictionary[i] = DataReader.readNullTerminatedString(temp);
            }
            int numLeafDefinitions = DataReader.readInt(data[offset++], data[offset++], data[offset++], data[offset++]);
            for (int i = 0; i < numLeafDefinitions; i++)
            {
                offset += 2;                 // Each leaf index is an unsigned short, which i just want to skip
            }
            int numProps = DataReader.readInt(data[offset++], data[offset++], data[offset++], data[offset++]);
            lump = new SourceStaticProps(new List <SourceStaticProp>(numProps), dictionary, data.Length);
            if (numProps > 0)
            {
                structLength = (data.Length - offset) / numProps;
                byte[] bytes = new byte[structLength];
                for (int i = 0; i < numProps; i++)
                {
                    for (int j = 0; j < structLength; j++)
                    {
                        bytes[j] = data[offset + j];
                    }
                    lump.Add(new SourceStaticProp(bytes, type, version));
                    offset += structLength;
                }
            }
        }
        else
        {
            lump = new SourceStaticProps(new List <SourceStaticProp>(), dictionary, data.Length);
        }
        return(lump);
    }
	// METHODS
	public static SourceStaticProps createLump(byte[] data, mapType type, int version) {
		int structLength = 0;
		string[] dictionary = new string[0];
		SourceStaticProps lump;
		if (data.Length > 0) {
			/*switch(type) { // It's possible to determine structlength using arithmetic rather than version numbering
			case mapType.TYPE_SOURCE17:
			case mapType.TYPE_SOURCE18:
			case mapType.TYPE_SOURCE19:
			case mapType.TYPE_SOURCE20:
			case mapType.TYPE_SOURCE21:
			case mapType.TYPE_SOURCE22:
			case mapType.TYPE_SOURCE23:
				switch(version) {
					case 4:
						structLength=56;
						break;
					case 5:
						structLength=60;
						break;
					case 6:
						structLength=64;
						break;
					case 7:
						structLength=68;
						break;
					case 8:
						structLength=72;
						break;
					case 9:
						structLength=73; // ??? The last entry is a boolean, is it stored as a byte?
						break;
					default:
						structLength=0;
						break;
					default:
						structLength=0;
				}*/
			int offset = 0;
			dictionary = new string[DataReader.readInt(data[offset++], data[offset++], data[offset++], data[offset++])];
			for (int i = 0; i < dictionary.Length; i++) {
				byte[] temp = new byte[128];
				for (int j = 0; j < 128; j++) {
					temp[j] = data[offset++];
				}
				dictionary[i] = DataReader.readNullTerminatedString(temp);
			}
			int numLeafDefinitions = DataReader.readInt(data[offset++], data[offset++], data[offset++], data[offset++]);
			for (int i = 0; i < numLeafDefinitions; i++) {
				offset += 2; // Each leaf index is an unsigned short, which i just want to skip
			}
			int numProps = DataReader.readInt(data[offset++], data[offset++], data[offset++], data[offset++]);
			lump = new SourceStaticProps(new List<SourceStaticProp>(numProps), dictionary, data.Length);
			if (numProps > 0) {
				structLength = (data.Length - offset) / numProps;
				byte[] bytes = new byte[structLength];
				for (int i = 0; i < numProps; i++) {
					for (int j = 0; j < structLength; j++) {
						bytes[j] = data[offset + j];
					}
					lump.Add(new SourceStaticProp(bytes, type, version));
					offset += structLength;
				}
			}
		} else {
			lump = new SourceStaticProps(new List<SourceStaticProp>(), dictionary, data.Length);
		}
		return lump;
	}