void load(uint32 offset) {
		byte *item = getData(offset);
		id = offset;
		// Only save the hashes instead of the full names
		bgFilename1 = calcHash(getStringP(READ_LE_UINT32(item + 0)));
		bgFilename2 = calcHash(getStringP(READ_LE_UINT32(item + 4)));
		txFilename = calcHash(getStringP(READ_LE_UINT32(item + 8)));
		bgFilename3 = calcHash(getStringP(READ_LE_UINT32(item + 12)));
		xPosIndex = item[16];
		count = item[17];
	}
STATIC bool calcHMac(const SecureStorageS *storage, unsigned char *caData) {
  unsigned char tmpHash[SHA256_LEN], hash[SHA256_LEN];
  int16_t len = 0;
  int16_t secretLen = 0;

  if (storage == NULL) {
    assert(LIB_NAME "Storage structure must not be NULL" && (false || Storage_TestMode));
    return false;
  }
  memset(hash, 0, SHA256_LEN);
  calcHash(storage, hash);
  if (SECURE_DEBUG) {
    Utils_PrintHexStr(stderr, "Base hash:", hash, SHA256_LEN);
  }
  Utils_GetCharArrayLen(storage->caSalt, &len, MIN_SALT_LEN, KEY_VAL_MAX_STR_LEN);

  if (Utils_GetCharArrayLen(storage->caSecret, &secretLen, KEY_VAL_MIN_STR_LEN, KEY_VAL_MAX_STR_LEN) == false) {
    return false;
  }
  if (Crypto_CalcHmac(&(storage->caSecret[UTILS_STR_LEN_SIZE]), secretLen, storage->caSalt, len + UTILS_STR_LEN_SIZE, tmpHash) == false)
    return false;
  calcHashXor(hash, tmpHash, SHA256_LEN);
  memcpy(caData + UTILS_STR_LEN_SIZE, hash, SHA256_LEN);
  Utils_SetCharArrayLen(caData, SHA256_LEN);
  caData[SIGN_LEN] = 0;
  return true;
}
Beispiel #3
0
int arrayAtIdentityHashInPairs(PyrObject *array, PyrSlot *key)
{
	PyrSlot *slots, *test;
	unsigned int i, start, end, hash, maxHash;

	hash = calcHash(key);
	maxHash = array->size >> 1;
	start = (hash % maxHash) << 1;
	end = array->size;
	slots = array->slots;
	for (i=start; i<end; i+=2) {
		test = slots + i;
		if (IsNil(test) || (test->utag == key->utag && test->ui == key->ui)) {
			return i;
		}
	}
	end = start - 2;
	for (i=0; i<=end; i+=2) {
		test = slots + i;
		if (IsNil(test) || (test->utag == key->utag && test->ui == key->ui)) {
			return i;
		}
	}
	return -2;
}
Beispiel #4
0
Palette::Palette(NeverhoodEngine *vm, const char *filename) : Entity(vm, 0) {
	PaletteResource paletteResource(_vm);
	init();
	paletteResource.load(calcHash(filename));
	paletteResource.copyPalette(_palette);
	SetUpdateHandler(&Palette::update);
}
void AsScene1308JaggyDoor::stCloseDoor() {
	startAnimation(0xBA0AE050, -1, -1);
	_playBackwards = true;
	setVisible(true);
	playSound(0, calcHash("fxDoorClose38"));
	NextState(&AsScene1308JaggyDoor::stCloseDoorDone);
}
Beispiel #6
0
void AsScene2101Door::stCloseDoor() {
	startAnimation(0xC222A8D4, 0, -1);
	_newStickFrameIndex = STICK_LAST_FRAME;
	setVisible(true);
	playSound(0, calcHash("fxDoorClose32"));
	NextState(&AsScene2101Door::stCloseDoorDone);
}
	long find(float * const &vertex, const unsigned int &size, float * const &vertices, unsigned int * const &hashes, const unsigned int &count) {
		const unsigned int hash = calcHash(vertex, size);
		for (unsigned int i = 0; i < count; i++)
			if (hashes[i] == hash && compare(&vertices[i*size], vertex, size))
				return (long)i;
		return -1;
	}
Beispiel #8
0
void insert(IntHashMap* m, int32_t value, u_int64_t count)
{
	u_int32_t hash = calcHash(m->module, value);
	
	u_int32_t c;
	u_int32_t h = hash;
	for(c = 0; c < m->maxDups; c++, h += m->module)
	{
		if(m->hash2count[h] == 0)
		{
			if(c == 0)
			{
				m->idx2hash[m->numPlaces] = hash;
				m->numPlaces++;
			}
			m->numEntries++;
			m->hash2value[h] = value;
		}
		
		if(m->hash2value[h] == value)
		{
			m->hash2count[h] += count;
			return;
		}
	}
	int x = 3;
	int y = 0;
	printf("%d\n", x/y);
	err(-1, "No more places left to store inserted value %d with hash %d!\n", value, hash);
}
Beispiel #9
0
StringValue *StringTable::lookup(const char *s, size_t length)
{
    const hash_t hash = calcHash(s, length);
    const size_t i = findSlot(hash, s, length);
    // printf("lookup %.*s %p\n", (int)length, s, table[i].value ?: NULL);
    return getValue(table[i].vptr);
}
Beispiel #10
0
QString BD::calcHash(QString nomeImagem) const
{
	QImage imagem(nomeImagem);
	if (imagem.isNull())
		return QString();
	else
		return calcHash(imagem);
}
Beispiel #11
0
void insertFile(char name[], struct linknode **hashTable)
{
	int hash;
	char init;
	init = name[0];
	hash = calcHash(init);
	hashTable[hash] = insertNode(hashTable[hash], name);
}
Beispiel #12
0
void deleteFile(char name[], struct linknode **hashTable)
{
	int hash;
	char init;
	init = name[0];
	hash = calcHash(init);
	hashTable[hash] = deleteNode(hashTable[hash], name);
}
Beispiel #13
0
StringEntry *StringEntry::alloc(const char *s, size_t len)
{
    StringEntry *se;

    se = (StringEntry *) mem.calloc(1,sizeof(StringEntry) + len + 1);
    se->value.ctor(s, len);
    se->hash = calcHash(s,len);
    return se;
}
static void run() {
	int lineN;

	scanf("%d", &lineN);
	for (int line = 0; line < lineN; ++line) {
		int command;
		int parentId, childId, elementId;
		int height, width;
		int hash, resultHash;

		Element element;

		scanf("%d", &command);
		switch (command) {
		case INIT:
			scanf("%d", &expected);
			init();
			break;
		case CREATE:
			scanf("%d %d", &elementId, &(element.type));
			readElement(&element);
			id[elementId] = create(&element);
			break;
		case ADD:
			scanf("%d %d", &parentId, &childId);
			add(id[parentId], id[childId]);
			break;
		case SHOW:
			scanf("%d %d %d %d", &elementId, &height, &width, &hash);
			show(id[elementId], screen);
			resultHash = calcHash(screen, height, width);

#if 0
			printf ("Expected W %d H %d\n", width, height);
			for (int y = 0; y < height; ++y)
			{
				for (int x = 0; x < width; ++x)
					printf("%c", screen[y][x]);
				printf("\n");
			}
#endif

			if (resultHash == hash)
			{
				point++;
	//			printf ("%d \n", point);
			}
			else
			{
				printf("FAILED %d %d\n", hash, resultHash);
				exit (0);
				return;
			}
			break;
		}
	}
}
Beispiel #15
0
uint Utils::calcHash(const QString &str)
{
    if(str.isNull())  // handle null string as "", prevents crash
        return calcHash("");
    const char *s = str.ascii();
    uint hash = 5381;
    int c;
    while((c = *s++)) hash = ((hash << 5) + hash) + c;      // hash*33 + c
    return hash;
}
Beispiel #16
0
unsigned int DocumentSource::hash() const
{
    if (!d->calculatedHash)
    {
        d->hash = calcHash(d->array);
        d->calculatedHash = true;
    }
    
    return d->hash;
}
Beispiel #17
0
int prEvent_IsRest(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot *dictslots = slotRawObject(g->sp)->slots;
	PyrSlot *arraySlot = dictslots + ivxIdentDict_array;

	if (isKindOfSlot(arraySlot, class_array)) {
		PyrSlot key, typeSlot;
		static PyrSymbol *s_type = getsym("type");
		static PyrSymbol *s_rest = getsym("rest");
		PyrSymbol *typeSym;
		// test 'this[\type] == \rest' first
		SetSymbol(&key, s_type);
		identDict_lookup(slotRawObject(g->sp), &key, calcHash(&key), &typeSlot);
		if(!slotSymbolVal(&typeSlot, &typeSym) && typeSym == s_rest) {
			SetBool(g->sp, 1);
			return errNone;
		} else {
			PyrObject *array = slotRawObject(arraySlot);
			PyrSymbol *slotSym;
			static PyrSymbol *s_empty = getsym("");
			static PyrSymbol *s_r = getsym("r");
			static PyrClass *class_rest = getsym("Rest")->u.classobj;
			static PyrClass *class_metarest = getsym("Meta_Rest")->u.classobj;
			PyrSlot *slot;
			int32 size = array->size;
			int32 i;

			slot = array->slots + 1;  // scan only the odd items

			for (i = 1; i < size; i += 2, slot += 2) {
				if (isKindOfSlot(slot, class_rest)
				    || isKindOfSlot(slot, class_metarest)
				) {
					SetBool(g->sp, 1);
					return errNone;
				} else if(!slotSymbolVal(slot, &slotSym)) {
					if(slotSym == s_empty
						|| slotSym == s_r
						|| slotSym == s_rest
					) {
						SetBool(g->sp, 1);
						return errNone;
					}
				}  // why no 'else'?
				// slotSymbolVal nonzero return = not a symbol;
				// non-symbols don't indicate rests, so, ignore them.
			}
		}
	} else {
		return errWrongType;
	}

	SetBool(g->sp, 0);
	return errNone;
}
void AsScene2402Door::update() {
	if (_isOpen && _countdown != 0 && (--_countdown) == 0) {
		_isOpen = false;
		setVisible(true);
		startAnimation(0x80495831, -1, -1);
		_playBackwards = true;
		playSound(0, calcHash("fxDoorClose38"));
		NextState(&AsScene2402Door::stDoorClosingFinished);
	}
	AnimatedSprite::update();
}
void AsScene2401Door::update() {
	if (_isOpen && _countdown != 0 && (--_countdown) == 0) {
		_isOpen = false;
		setVisible(true);
		startAnimation(0x44687810, -1, -1);
		_newStickFrameIndex = 0;
		_playBackwards = true;
		playSound(0, calcHash("fxDoorClose38"));
	}
	AnimatedSprite::update();
}
Beispiel #20
0
inline Hvl calcHash(C const * theCs)
{
	WatchError
	Hvl tHvl = 0;
	while(*theCs)
	{
		tHvl = mixHash(tHvl, calcHash(*theCs));
		++theCs;
	}
	return tHvl;
	CatchError
}
Beispiel #21
0
    void clear()
    {
      for(auto i : myElements) delete i;
      myElements.clear();
//       myMeta.clear();
      myTemp = 294.15; // Kelvins = 21c
      myPressure = 101325; // pascals
      myVolume = 0;
      myGeneratedFlag = false;
      mySeenFlag = false;
      myCachedHash = calcHash();
    }
Beispiel #22
0
int prEvent_Delta(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot *a, key, dur, stretch, delta;
	double fdur, fstretch;
	int err;

	a = g->sp;  // dict

	SetSymbol(&key, s_delta);
	identDict_lookup(slotRawObject(a), &key, calcHash(&key), &delta);

	if (NotNil(&delta)) {
		slotCopy(a,&delta);
	} else {
		SetSymbol(&key, s_dur);
		identDict_lookup(slotRawObject(a), &key, calcHash(&key), &dur);

		err = slotDoubleVal(&dur, &fdur);
		if (err) {
			if (NotNil(&dur)) return err;
			SetNil(a);
			return errNone;
		}

		SetSymbol(&key, s_stretch);
		identDict_lookup(slotRawObject(a), &key, calcHash(&key), &stretch);

		err = slotDoubleVal(&stretch, &fstretch);
		if (err) {
			if (NotNil(&stretch)) return err;
			SetFloat(a, fdur);
			return errNone;
		}

		SetFloat(a, fdur * fstretch );
	}

	return errNone;
}
	void load(uint32 offset) {
		byte *item = getData(offset);
		id = offset;
		// Only save the hashes instead of the full names
		bgFilename = calcHash(getStringP(READ_LE_UINT32(item + 0)));
		class437Filename = calcHash(getStringP(READ_LE_UINT32(item + 4)));
		dataResourceFilename = calcHash(getStringP(READ_LE_UINT32(item + 8)));
		pointListName = calcHash(getStringP(READ_LE_UINT32(item + 12)));
		rectListName = calcHash(getStringP(READ_LE_UINT32(item + 16)));
		exPaletteFilename2 = calcHash(getStringP(READ_LE_UINT32(item + 20)));
		exPaletteFilename1 = calcHash(getStringP(READ_LE_UINT32(item + 24)));
		mouseCursorFilename = calcHash(getStringP(READ_LE_UINT32(item + 28)));
		which1 = READ_LE_UINT16(item + 32);
		which2 = READ_LE_UINT16(item + 34);
	}
Beispiel #24
0
void Particles::Update()
{
	assert(initFlag);
	float *dPos;
	dPos = (float *)mapGLBufferObject(&m_cuda_posvbo_resource);

	setParameters(&mparams);
	integrateSystem(dPos, velGpu, mparams.timeStep, numParticles);
	calcHash(gridParticleHash, gridParticleIndex,dPos,numParticles);
	sortParticles(gridParticleHash,gridParticleIndex,numParticles);
	reorderDataAndFindCellStart(cellStart,cellEnd,sortedPos,sortedVel,gridParticleHash,gridParticleIndex,dPos,velGpu,numParticles,mparams.wholeNumCells);
	simFluid(velGpu, sortedPos, sortedVel, gridParticleIndex, cellStart, cellEnd, numParticles, solidPosGpu, solidVelGpu, buoyancyGpu, buoyancyAngGpu);
	unmapGLBufferObject(m_cuda_posvbo_resource);
}
Beispiel #25
0
u_int64_t get(IntHashMap* m, int32_t value)
{
	u_int32_t c;
	u_int32_t h = calcHash(m->module, value);
	for(c = 0; c < m->maxDups; c++, h+= m->module)
	{
		if(m->hash2count[h] == 0)
			return 0;
			
		if(m->hash2value[h] == value)
			return m->hash2count[h];
	}
	return 0;
}
Beispiel #26
0
void Worm::move(const WormPart& destiny, const bool& moveHead){
    if(moveHead){
        if(--posHead < 0) {
            posHead = length -1;
        }

        wormparts[posHead] = destiny;
    } else{
        wormparts[posHead] = destiny;
        posHead++;
        posHead %= length;
    }
    calcHash();
}
Beispiel #27
0
int prEvent_IsRest(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot *dictslots = slotRawObject(g->sp)->slots;
	PyrSlot *arraySlot = dictslots + ivxIdentDict_array;
	static int isRestCount = 0;

	if (!isKindOfSlot(arraySlot, class_array)) {
		return errWrongType;
	}

	PyrSlot key, typeSlot;
	PyrSymbol *typeSym;
	// easy tests first: 'this[\type] == \rest'
	SetSymbol(&key, s_type);
	identDict_lookup(slotRawObject(g->sp), &key, calcHash(&key), &typeSlot);
	if(!slotSymbolVal(&typeSlot, &typeSym) && typeSym == s_rest) {
		SetBool(g->sp, 1);
		return errNone;
	}

	// and, 'this[\isRest] == true'
	SetSymbol(&key, s_isRest);
	identDict_lookup(slotRawObject(g->sp), &key, calcHash(&key), &typeSlot);
	if(IsTrue(&typeSlot)) {
		if (isRestCount == 0)
			post("\nWARNING: Setting isRest to true in an event is deprecated. See the Rest helpfile for supported ways to specify rests.\n\n");
		isRestCount = (isRestCount + 1) % 100;
		SetBool(g->sp, 1);
		return errNone;
	}

	// failing those, scan slot values for something rest-like
	PyrObject *array = slotRawObject(arraySlot);
	SetBool(g->sp, dictHasRestlikeValue(array) ? 1 : 0);
	return errNone;
}
Beispiel #28
0
StringValue *StringTable::insert(const char *s, size_t length)
{
    const hash_t hash = calcHash(s, length);
    size_t i = findSlot(hash, s, length);
    if (table[i].vptr)
        return NULL; // already in table
    if (++count > tabledim * loadFactor)
    {
        grow();
        i = findSlot(hash, s, length);
    }
    table[i].hash = hash;
    table[i].vptr = allocValue(s, length);
    // printf("insert %.*s %p\n", (int)length, s, table[i].value ?: NULL);
    return getValue(table[i].vptr);
}
Beispiel #29
0
StringValue *StringTable::update(const char *s, size_t length)
{
    const hash_t hash = calcHash(s, length);
    size_t i = findSlot(hash, s, length);
    if (!table[i].vptr)
    {
        if (++count > tabledim * loadFactor)
        {
            grow();
            i = findSlot(hash, s, length);
        }
        table[i].hash = hash;
        table[i].vptr = allocValue(s, length);
    }
    // printf("update %.*s %p\n", (int)length, s, table[i].value ?: NULL);
    return getValue(table[i].vptr);
}
Beispiel #30
0
	void StringID::construct(T const& name)
	{
		assert(StringIDUtil<T>::size(name) <= STRING_SIZE);

		UINT32 hash = calcHash(name) & (sizeof(mStringHashTable) / sizeof(mStringHashTable[0]) - 1);
		InternalData* existingEntry = mStringHashTable[hash];
		
		while (existingEntry != nullptr)
		{
			if (StringIDUtil<T>::compare(name, existingEntry->chars))
			{
				mData = existingEntry;
				return;
			}

			existingEntry = existingEntry->next;
		}

		ScopedSpinLock lock(mSync);

		// Search for the value again in case other thread just added it
		existingEntry = mStringHashTable[hash];
		InternalData* lastEntry = nullptr;
		while (existingEntry != nullptr)
		{
			if (StringIDUtil<T>::compare(name, existingEntry->chars))
			{
				mData = existingEntry;
				return;
			}

			lastEntry = existingEntry;
			existingEntry = existingEntry->next;
		}

		mData = allocEntry();
		StringIDUtil<T>::copy(name, mData->chars);

		if (lastEntry == nullptr)
			mStringHashTable[hash] = mData;
		else
			lastEntry->next = mData;
	}