Index: CoreLibrary/alignhash/alignhash_tpl.h
===================================================================
--- CoreLibrary/alignhash/alignhash_tpl.h	(revision 0)
+++ CoreLibrary/alignhash/alignhash_tpl.h	(working copy)
@@ -0,0 +1,426 @@
+/* The MIT License
+
+   Copyright (C) 2011 Zilong Tan (eric.zltan@gmail.com)
+   Copyright (c) 2008, 2009, 2011 by Attractive Chaos <attractor@live.co.uk>
+
+   Permission is hereby granted, free of charge, to any person obtaining
+   a copy of this software and associated documentation files (the
+   "Software"), to deal in the Software without restriction, including
+   without limitation the rights to use, copy, modify, merge, publish,
+   distribute, sublicense, and/or sell copies of the Software, and to
+   permit persons to whom the Software is furnished to do so, subject to
+   the following conditions:
+
+   The above copyright notice and this permission notice shall be
+   included in all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+   BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+   ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+   SOFTWARE.
+*/
+
+#ifndef __ULIB_ALIGN_HASHING_H
+#define __ULIB_ALIGN_HASHING_H
+
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef AH_64BIT  /* specify if you are handling >4G keys */
+
+typedef uint64_t ah_iter_t;
+typedef uint64_t ah_size_t;
+
+#define AH_ISDEL(flag, i)        ( ((flag)[(i) >> 5] >> (((i) & 0x1fU) << 1)) & 1      )
+#define AH_ISEMPTY(flag, i)      ( ((flag)[(i) >> 5] >> (((i) & 0x1fU) << 1)) & 2      )
+#define AH_ISEITHER(flag, i)     ( ((flag)[(i) >> 5] >> (((i) & 0x1fU) << 1)) & 3      )
+#define AH_CLEAR_DEL(flag, i)    (  (flag)[(i) >> 5] &= ~(1ul << (((i) & 0x1fU) << 1)) )
+#define AH_CLEAR_EMPTY(flag, i)  (  (flag)[(i) >> 5] &= ~(2ul << (((i) & 0x1fU) << 1)) )
+#define AH_CLEAR_BOTH(flag, i)   (  (flag)[(i) >> 5] &= ~(3ul << (((i) & 0x1fU) << 1)) )
+#define AH_SET_DEL(flag, i)      (  (flag)[(i) >> 5] |=  (1ul << (((i) & 0x1fU) << 1)) )
+
+#define AH_FLAGS_BYTE(nb)        ( (nb) < 32? 8: (nb) >> 2 )
+
+#else  /* by default, the 32-bit version is used */
+
+typedef uint32_t ah_iter_t;
+typedef uint32_t ah_size_t;
+
+#define AH_ISDEL(flag, i)        ( ((flag)[(i) >> 4] >> (((i) & 0xfU) << 1)) & 1      )
+#define AH_ISEMPTY(flag, i)      ( ((flag)[(i) >> 4] >> (((i) & 0xfU) << 1)) & 2      )
+#define AH_ISEITHER(flag, i)     ( ((flag)[(i) >> 4] >> (((i) & 0xfU) << 1)) & 3      )
+#define AH_CLEAR_DEL(flag, i)    (  (flag)[(i) >> 4] &= ~(1ul << (((i) & 0xfU) << 1)) )
+#define AH_CLEAR_EMPTY(flag, i)  (  (flag)[(i) >> 4] &= ~(2ul << (((i) & 0xfU) << 1)) )
+#define AH_CLEAR_BOTH(flag, i)   (  (flag)[(i) >> 4] &= ~(3ul << (((i) & 0xfU) << 1)) )
+#define AH_SET_DEL(flag, i)      (  (flag)[(i) >> 4] |=  (1ul << (((i) & 0xfU) << 1)) )
+
+#define AH_FLAGS_BYTE(nb)        ( (nb) < 16? 4: (nb) >> 2 )
+
+#endif
+
+/* return codes for alignhash_set() */
+enum {
+	AH_INS_ERR = 0,  /**< insertion failed, the element to insert exists */
+	AH_INS_NEW = 1,  /**< inserted element is placed at a new bucket */
+	AH_INS_DEL = 2   /**< inserted element is placed at a deleted bucket */
+};
+
+/* Two probing methods are available, tier probing and linear probing.
+ * Tier probing, to some extent, balances the lookup cost both in the
+ * best and worst cases. This is preferable when keys are not randomly
+ * distributed thus resulting in many collisions. By contrast, linear
+ * probing precedes tier probing especially when there are a lot of
+ * <key,value> pairs stored in hash table due to better locality is
+ * achieved. Please specify AH_TIER_PROBING to enable tier probing,
+ * otherwise linear probing is used by default. */
+#ifdef AH_TIER_PROBING
+/* tier probing step, preferable for memory-efficient situations */
+#define AH_PROBE_STEP(h)         ( ((h) * 0xc6a4a7935bd1e995ULL >> 47) | 1 )
+#define AH_LOAD_FACTOR           0.80
+#else
+/* linear probing, for fast lookups */
+#define AH_PROBE_STEP(h)         ( 1 )
+#define AH_LOAD_FACTOR           0.50
+#endif
+
+#define DEFINE_ALIGNHASH(_name, _key_t, _val_t, _ismap, _hashfn, _hasheq) \
+	typedef struct {						\
+		ah_size_t nbucket;					\
+		ah_size_t size;     /* number of elements */		\
+		ah_size_t nused;    /* number of bucket used */		\
+		ah_size_t sup;      /* upper bound */			\
+		ah_size_t *flags;					\
+		_key_t    *keys;					\
+		_val_t    *vals;					\
+	} alignhash_##_name##_t;					\
+                                                                        \
+	static inline alignhash_##_name##_t *				\
+	alignhash_init_##_name() {					\
+		return (alignhash_##_name##_t*)				\
+			calloc(1, sizeof(alignhash_##_name##_t));	\
+	}								\
+                                                                        \
+	static inline void						\
+	alignhash_destroy_##_name(alignhash_##_name##_t *h)		\
+	{								\
+		if (h) {						\
+			free(h->flags);					\
+			free(h->keys);					\
+			free(h->vals);					\
+			free(h);					\
+		}							\
+	}								\
+                                                                        \
+	static inline void						\
+	alignhash_clear_##_name(alignhash_##_name##_t *h)		\
+	{								\
+		if (h && h->flags) {					\
+			memset(h->flags, 0xaa, AH_FLAGS_BYTE(h->nbucket)); \
+			h->size  = 0;					\
+			h->nused = 0;					\
+		}							\
+	}								\
+                                                                        \
+	static inline ah_iter_t						\
+	alignhash_get_##_name(const alignhash_##_name##_t *h, _key_t key) \
+	{								\
+		if (h->nbucket) {					\
+			register ah_size_t i, step;			\
+			ah_size_t mask = h->nbucket - 1;		\
+			ah_size_t k, last;				\
+			k = _hashfn(key);				\
+			i = k & mask;					\
+			step = AH_PROBE_STEP(k);			\
+			last = i;					\
+			while (!AH_ISEMPTY(h->flags, i) &&		\
+			       (AH_ISDEL(h->flags, i) || !_hasheq(h->keys[i], key))) { \
+				i = (i + step) & mask;			\
+				if (i == last)				\
+					return h->nbucket;		\
+			}						\
+			return AH_ISEMPTY(h->flags, i)? h->nbucket : i;	\
+		} else							\
+			return 0;					\
+	}								\
+                                                                        \
+	static inline int						\
+	alignhash_resize_##_name(alignhash_##_name##_t *h, ah_size_t new_nbucket) \
+	{								\
+		ah_size_t *new_flags = 0;				\
+		_key_t    *new_keys  = 0;				\
+		_val_t    *new_vals  = 0;				\
+		ah_size_t  new_mask  = new_nbucket - 1;			\
+		ah_size_t  j, flaglen;					\
+		if (h->size >= (ah_size_t)(new_nbucket * AH_LOAD_FACTOR + 0.5))	\
+			return -1;					\
+		flaglen = AH_FLAGS_BYTE(new_nbucket);			\
+		new_flags = (ah_size_t *) malloc(flaglen);		\
+		if (new_flags == 0)					\
+			return -1;					\
+		memset(new_flags, 0xaa, flaglen);			\
+		if (h->nbucket < new_nbucket) {				\
+			new_keys = (_key_t*)				\
+				realloc(h->keys, new_nbucket * sizeof(_key_t));	\
+			if (new_keys == 0) {				\
+				free(new_flags);			\
+				return -1;				\
+			}						\
+			h->keys = new_keys;				\
+			if (_ismap) {					\
+				new_vals = (_val_t*)			\
+					realloc(h->vals, new_nbucket * sizeof(_val_t)); \
+				if (new_vals == 0) {			\
+					free(new_flags);		\
+					return -1;			\
+				}					\
+				h->vals = new_vals;			\
+			}						\
+		}							\
+		for (j = 0; j != h->nbucket; ++j) {			\
+			if (AH_ISEITHER(h->flags, j) == 0) {		\
+				_key_t key = h->keys[j];		\
+				_val_t val;				\
+				if (_ismap)				\
+					val = h->vals[j];		\
+				AH_SET_DEL(h->flags, j);		\
+				for (;;) {				\
+					register ah_size_t i, step;	\
+					ah_size_t k;			\
+					k = _hashfn(key);		\
+					i = k & new_mask;		\
+					step = AH_PROBE_STEP(k);	\
+					while (!AH_ISEMPTY(new_flags, i)) \
+						i = (i + step) & new_mask; \
+					AH_CLEAR_EMPTY(new_flags, i);	\
+					if (i < h->nbucket && AH_ISEITHER(h->flags, i) == 0) { \
+						swap(h->keys[i], key);	\
+						if (_ismap)		\
+							swap(h->vals[i], val); \
+						AH_SET_DEL(h->flags, i); \
+					} else {			\
+						h->keys[i] = key;	\
+						if (_ismap)		\
+							h->vals[i] = val; \
+						break;			\
+					}				\
+				}					\
+			}						\
+		}							\
+		if (h->nbucket > new_nbucket) {				\
+			new_keys = (_key_t*)				\
+				realloc(h->keys, new_nbucket * sizeof(_key_t));	\
+			if (new_keys)					\
+				h->keys = new_keys;			\
+			if (_ismap) {					\
+				new_vals = (_val_t*)			\
+					realloc(h->vals, new_nbucket * sizeof(_val_t)); \
+				if (new_vals)				\
+					h->vals = new_vals;		\
+			}						\
+		}							\
+		free(h->flags);						\
+		h->flags = new_flags;					\
+		h->nbucket = new_nbucket;				\
+		h->nused = h->size;					\
+		h->sup = (ah_size_t)(h->nbucket * AH_LOAD_FACTOR + 0.5); \
+		return 0;						\
+	}								\
+                                                                        \
+	static inline ah_iter_t						\
+	alignhash_set_##_name(alignhash_##_name##_t *h, _key_t key, int *ret) \
+	{								\
+		register ah_size_t i, step;				\
+		ah_size_t x, k, mask, site, last;			\
+		if (h->nused >= h->sup) {				\
+			if (h->nbucket) {				\
+				if (alignhash_resize_##_name(h, h->nbucket * 2)) \
+					return h->nbucket;		\
+			} else {					\
+				if (alignhash_resize_##_name(h, 2))	\
+					return h->nbucket;		\
+			}						\
+		}							\
+		site = h->nbucket;					\
+		mask = h->nbucket - 1;					\
+		x = site;						\
+		k = _hashfn(key);					\
+		i = k & mask;						\
+		if (AH_ISEMPTY(h->flags, i))				\
+			x = i;						\
+		else {							\
+			step = AH_PROBE_STEP(k);			\
+			last = i;					\
+			while (!AH_ISEMPTY(h->flags, i) &&		\
+			       (AH_ISDEL(h->flags, i) || !_hasheq(h->keys[i], key))) { \
+				if (AH_ISDEL(h->flags, i))		\
+					site = i;			\
+				i = (i + step) & mask;			\
+				if (i == last) {			\
+					x = site;			\
+					break;				\
+				}					\
+			}						\
+			if (x == h->nbucket) {				\
+				if (AH_ISEMPTY(h->flags, i) && site != h->nbucket) \
+					x = site;			\
+				else					\
+					x = i;				\
+			}						\
+		}							\
+		if (AH_ISEMPTY(h->flags, x)) {				\
+			h->keys[x] = key;				\
+			AH_CLEAR_BOTH(h->flags, x);			\
+			++h->size;					\
+			++h->nused;					\
+			*ret = AH_INS_NEW;				\
+		} else if (AH_ISDEL(h->flags, x)) {			\
+			h->keys[x] = key;				\
+			AH_CLEAR_BOTH(h->flags, x);			\
+			++h->size;					\
+			*ret = AH_INS_DEL;				\
+		} else							\
+			*ret = AH_INS_ERR;				\
+		return x;						\
+	}								\
+                                                                        \
+	static inline void						\
+	alignhash_del_##_name(alignhash_##_name##_t *h, ah_iter_t x)	\
+	{								\
+		if (x != h->nbucket && !AH_ISEITHER(h->flags, x)) {	\
+			AH_SET_DEL(h->flags, x);			\
+			--h->size;					\
+		}							\
+	}
+
+
+/*------------------------- Human Interfaces -------------------------*/
+
+
+/**
+ * alignhash_hashfn - naive hash function
+ * NOTE: does no mixing of bits
+ */
+#define alignhash_hashfn(key) (ah_size_t)(key)
+
+/**
+ * alignhash_equalfn - naive equality test function
+ */
+#define alignhash_equalfn(a, b) ((a) == (b))
+
+/**
+ * alignhash_t - aligned hash type
+ */
+#define alignhash_t(name) alignhash_##name##_t
+
+/**
+ * alignhash_key - retrieves the key of a iterator
+ * @h: pointer to aligned hash
+ * @x: the iterator
+ */
+#define alignhash_key(h, x) ((h)->keys[x])
+
+/**
+ * alignhash_value - retrieves the value of a iterator
+ * @h: pointer to aligned hash
+ * @x: the iterator
+ */
+#define alignhash_value(h, x) ((h)->vals[x])
+
+/**
+ * alignhash_init - initializes an aligned hash
+ * @name:   name of the aligned hash
+ * @return: returns allocated aligned hash
+ */
+#define alignhash_init(name) alignhash_init_##name()
+
+/**
+ * alignhash_destroy - destroys an aligned hash
+ * @name: name of the aligned hash
+ * @h:    pointer to allocated aligned hash
+ */
+#define alignhash_destroy(name, h) alignhash_destroy_##name(h)
+
+/**
+ * alignhash_clear - clears an aligned hash without memory remapping
+ * @name: name of the aligned hash
+ * @h:    pointer to allocated aligned hash
+ */
+#define alignhash_clear(name, h) alignhash_clear_##name(h)
+
+/**
+ * alignhash_resize - resizes an aligned hash
+ * @name: name of the aligned hash
+ * @h:    pointer to allocated aligned hash
+ * @s:    new number of buckets
+ * @r:    ln(new_nbucket/2)/ln2
+ * NOTE:  bucket size should be in power of 2
+ *        In general, this function should never be called outside
+ */
+#define alignhash_resize(name, h, s, r) alignhash_resize_##name(h, s, r)
+
+/**
+ * alignhash_set - inserts an element
+ * @name:  name of the aligned hash
+ * @h:     pointer to allocated aligned hash
+ * @k:     key of the element to insert
+ * @r:     where to store the insertion result
+ * NOTE:   the insertion result, which is defined as AH_INS_*, will be
+ * returned through @r. This function does not displace an existing
+ * element. Displacement can be implemented using 'get' operation.
+ * @return:returns a iterator to the new element
+ */
+#define alignhash_set(name, h, k, r) alignhash_set_##name(h, k, r)
+
+/**
+ * alignhash_get - retrieves the iterator of an element
+ * @name:  name of the aligned hash
+ * @h:     pointer to allocated aligned hash
+ * @k:     key of the element to retrieve
+ * @return:returns a iterator to the specified element
+ */
+#define alignhash_get(name, h, k) alignhash_get_##name(h, k)
+
+/**
+ * alignhash_del - deletes an element via its iterator
+ * @name:  name of the aligned hash
+ * @h:     pointer to allocated aligned hash
+ * @x:     iterator of the element to delete
+ */
+#define alignhash_del(name, h, x) alignhash_del_##name(h, x)
+
+/**
+ * alignhash_exist - tests if a iterator contains data
+ * @h: pointer to allocated aligned hash
+ * @x: iterator to the bucket
+ */
+#define alignhash_exist(h, x) (!AH_ISEITHER((h)->flags, (x)))
+
+/**
+ * alignhash_begin - gets the start iterator
+ * @h: pointer to allocated aligned hash
+ */
+#define alignhash_begin(h) (ah_iter_t)(0)
+
+/**
+ * alignhash_end - returns the sentinel/invalid iterator
+ * @h: pointer to allocated aligned hash
+ */
+#define alignhash_end(h) ((h)->nbucket)
+
+/**
+ * alignhash_size - retrieves the size of an aligned hash
+ * @h: pointer to allocated aligned hash
+ */
+#define alignhash_size(h) ((h)->size)
+
+/**
+ * alignhash_nbucket - retrieves the number of buckets
+ * @h: pointer to allocated aligned hash
+ */
+#define alignhash_nbucket(h) ((h)->nbucket)
+
+#endif  /* __ULIB_ALIGN_HASHING_H */
Index: CoreLibrary/alignhash/version.txt
===================================================================
--- CoreLibrary/alignhash/version.txt	(revision 0)
+++ CoreLibrary/alignhash/version.txt	(working copy)
@@ -0,0 +1 @@
+alignhash from ULIB 1.2.1 Beta - http://code.google.com/p/ulib/
\ No newline at end of file
Index: Myth2.vcproj
===================================================================
--- Myth2.vcproj	(revision 5740)
+++ Myth2.vcproj	(working copy)
@@ -25,7 +25,7 @@
 				Optimization="2"
 				InlineFunctionExpansion="1"
 				OptimizeForProcessor="2"
-				AdditionalIncludeDirectories="Myth2Code\;Myth2Code\bitmap_dialogs;Myth2Code\console;Myth2Code\cseries;Myth2Code\cutscenes;Myth2Code\hardware;Myth2Code\hardware\Direct3D;Myth2Code\hardware\OpenGL;Myth2Code\hardware\3DFX;Myth2Code\hardware\DirectX11;Myth2Code\input;Myth2Code\map_actions;Myth2Code\map_actions\ambient_life;Myth2Code\metaserver;Myth2Code\myth_networking;Myth2Code\networking;Myth2Code\render;Myth2Code\smacker;Myth2Code\sound;Myth2Code\tag_files;Myth2Stuff\WindowsStuff;Myth2Stuff\WindowsStuff\curl;Myth2Stuff\WindowsStuff\gl;Myth2Stuff\WindowsStuff\Glide;Myth2Stuff\WindowsStuff\QuickTime7.3SDK\CIncludes;Myth2Stuff\WindowsStuff\OpenAL\include\;Myth2Stuff\WindowsStuff\zlib\;Myth2Stuff\WindowsStuff\Direct3D;Myth2Stuff\WindowsStuff\DirectX11;CoreLibrary\bitmap_dialogs;CoreLibrary\boost;CoreLibrary\cseries;CoreLibrary\iniparser3.0b\src\;CoreLibrary\input;CoreLibrary\jpeg;&quot;CoreLibrary\jpeg-6b&quot;;CoreLibrary\logo;CoreLibrary\map_actions;CoreLibrary\map_actions\ambient_life;CoreLibrary\md5;CoreLibrary\metaserver;CoreLibrary\metaserver_lib;CoreLibrary\minizip;CoreLibrary\mouse_cursor;CoreLibrary\myth;CoreLibrary\myth_networking;CoreLibrary\networking;CoreLibrary\sound;CoreLibrary\sound_utils;CoreLibrary\tag_files;CoreLibrary\openplay;CoreLibrary\uber;CoreLibrary\uber\NetModules;CoreLibrary\uber\NetModules\common;CoreLibrary\pix0r1;..\BuildTools\EncodeMap\"
+				AdditionalIncludeDirectories="Myth2Code\;Myth2Code\bitmap_dialogs;Myth2Code\console;Myth2Code\cseries;Myth2Code\cutscenes;Myth2Code\hardware;Myth2Code\hardware\Direct3D;Myth2Code\hardware\OpenGL;Myth2Code\hardware\3DFX;Myth2Code\hardware\DirectX11;Myth2Code\input;Myth2Code\map_actions;Myth2Code\map_actions\ambient_life;Myth2Code\metaserver;Myth2Code\myth_networking;Myth2Code\networking;Myth2Code\render;Myth2Code\smacker;Myth2Code\sound;Myth2Code\tag_files;Myth2Stuff\WindowsStuff;Myth2Stuff\WindowsStuff\curl;Myth2Stuff\WindowsStuff\gl;Myth2Stuff\WindowsStuff\Glide;Myth2Stuff\WindowsStuff\QuickTime7.3SDK\CIncludes;Myth2Stuff\WindowsStuff\OpenAL\include\;Myth2Stuff\WindowsStuff\zlib\;Myth2Stuff\WindowsStuff\Direct3D;Myth2Stuff\WindowsStuff\DirectX11;CoreLibrary\alignhash;CoreLibrary\bitmap_dialogs;CoreLibrary\cseries;CoreLibrary\iniparser3.0b\src\;CoreLibrary\input;CoreLibrary\jpeg;&quot;CoreLibrary\jpeg-6b&quot;;CoreLibrary\logo;CoreLibrary\map_actions;CoreLibrary\map_actions\ambient_life;CoreLibrary\md5;CoreLibrary\metaserver;CoreLibrary\metaserver_lib;CoreLibrary\minizip;CoreLibrary\mouse_cursor;CoreLibrary\myth;CoreLibrary\myth_networking;CoreLibrary\networking;CoreLibrary\sound;CoreLibrary\sound_utils;CoreLibrary\tag_files;CoreLibrary\openplay;CoreLibrary\uber;CoreLibrary\uber\NetModules;CoreLibrary\uber\NetModules\common;CoreLibrary\pix0r1;..\BuildTools\EncodeMap\"
 				PreprocessorDefinitions="WIN32;MYTH2;NDEBUG;"
 				StringPooling="TRUE"
 				ExceptionHandling="FALSE"
@@ -110,7 +110,7 @@
 				Name="VCCLCompilerTool"
 				AdditionalOptions=""
 				Optimization="0"
-				AdditionalIncludeDirectories="Myth2Code\;Myth2Code\bitmap_dialogs;Myth2Code\console;Myth2Code\cseries;Myth2Code\cutscenes;Myth2Code\hardware;Myth2Code\hardware\Direct3D;Myth2Code\hardware\OpenGL;Myth2Code\hardware\3DFX;Myth2Code\hardware\DirectX11;Myth2Code\input;Myth2Code\map_actions;Myth2Code\map_actions\ambient_life;Myth2Code\metaserver;Myth2Code\myth_networking;Myth2Code\networking;Myth2Code\render;Myth2Code\smacker;Myth2Code\sound;Myth2Code\tag_files;Myth2Stuff\WindowsStuff;Myth2Stuff\WindowsStuff\curl;Myth2Stuff\WindowsStuff\gl;Myth2Stuff\WindowsStuff\Glide;Myth2Stuff\WindowsStuff\QuickTime7.3SDK\CIncludes;Myth2Stuff\WindowsStuff\OpenAL\include\;Myth2Stuff\WindowsStuff\zlib\;Myth2Stuff\WindowsStuff\Direct3D;Myth2Stuff\WindowsStuff\DirectX11;CoreLibrary\bitmap_dialogs;CoreLibrary\boost;CoreLibrary\cseries;CoreLibrary\iniparser3.0b\src\;CoreLibrary\input;CoreLibrary\jpeg;&quot;CoreLibrary\jpeg-6b&quot;;CoreLibrary\logo;CoreLibrary\map_actions;CoreLibrary\map_actions\ambient_life;CoreLibrary\md5;CoreLibrary\metaserver;CoreLibrary\metaserver_lib;CoreLibrary\minizip;CoreLibrary\mouse_cursor;CoreLibrary\myth;CoreLibrary\myth_networking;CoreLibrary\networking;CoreLibrary\sound;CoreLibrary\sound_utils;CoreLibrary\tag_files;CoreLibrary\openplay;CoreLibrary\uber;CoreLibrary\uber\NetModules;CoreLibrary\uber\NetModules\common;CoreLibrary\pix0r1;..\BuildTools\EncodeMap\"
+				AdditionalIncludeDirectories="Myth2Code\;Myth2Code\bitmap_dialogs;Myth2Code\console;Myth2Code\cseries;Myth2Code\cutscenes;Myth2Code\hardware;Myth2Code\hardware\Direct3D;Myth2Code\hardware\OpenGL;Myth2Code\hardware\3DFX;Myth2Code\hardware\DirectX11;Myth2Code\input;Myth2Code\map_actions;Myth2Code\map_actions\ambient_life;Myth2Code\metaserver;Myth2Code\myth_networking;Myth2Code\networking;Myth2Code\render;Myth2Code\smacker;Myth2Code\sound;Myth2Code\tag_files;Myth2Stuff\WindowsStuff;Myth2Stuff\WindowsStuff\curl;Myth2Stuff\WindowsStuff\gl;Myth2Stuff\WindowsStuff\Glide;Myth2Stuff\WindowsStuff\QuickTime7.3SDK\CIncludes;Myth2Stuff\WindowsStuff\OpenAL\include\;Myth2Stuff\WindowsStuff\zlib\;Myth2Stuff\WindowsStuff\Direct3D;Myth2Stuff\WindowsStuff\DirectX11;CoreLibrary\alignhash;CoreLibrary\bitmap_dialogs;CoreLibrary\cseries;CoreLibrary\iniparser3.0b\src\;CoreLibrary\input;CoreLibrary\jpeg;&quot;CoreLibrary\jpeg-6b&quot;;CoreLibrary\logo;CoreLibrary\map_actions;CoreLibrary\map_actions\ambient_life;CoreLibrary\md5;CoreLibrary\metaserver;CoreLibrary\metaserver_lib;CoreLibrary\minizip;CoreLibrary\mouse_cursor;CoreLibrary\myth;CoreLibrary\myth_networking;CoreLibrary\networking;CoreLibrary\sound;CoreLibrary\sound_utils;CoreLibrary\tag_files;CoreLibrary\openplay;CoreLibrary\uber;CoreLibrary\uber\NetModules;CoreLibrary\uber\NetModules\common;CoreLibrary\pix0r1;..\BuildTools\EncodeMap\"
 				PreprocessorDefinitions="WIN32;MYTH2;DEBUG;"
 				ExceptionHandling="FALSE"
 				RuntimeLibrary="1"
@@ -179,7 +179,7 @@
 				Optimization="2"
 				InlineFunctionExpansion="1"
 				OptimizeForProcessor="2"
-				AdditionalIncludeDirectories="Myth2Code\;Myth2Code\bitmap_dialogs;Myth2Code\console;Myth2Code\cseries;Myth2Code\cutscenes;Myth2Code\hardware;Myth2Code\hardware\Direct3D;Myth2Code\hardware\OpenGL;Myth2Code\hardware\3DFX;Myth2Code\hardware\DirectX11;Myth2Code\input;Myth2Code\map_actions;Myth2Code\map_actions\ambient_life;Myth2Code\metaserver;Myth2Code\myth_networking;Myth2Code\networking;Myth2Code\render;Myth2Code\smacker;Myth2Code\sound;Myth2Code\tag_files;Myth2Stuff\WindowsStuff;Myth2Stuff\WindowsStuff\curl;Myth2Stuff\WindowsStuff\gl;Myth2Stuff\WindowsStuff\Glide;Myth2Stuff\WindowsStuff\QuickTime7.3SDK\CIncludes;Myth2Stuff\WindowsStuff\OpenAL\include\;Myth2Stuff\WindowsStuff\zlib\;Myth2Stuff\WindowsStuff\Direct3D;Myth2Stuff\WindowsStuff\DirectX11;CoreLibrary\bitmap_dialogs;CoreLibrary\boost;CoreLibrary\cseries;CoreLibrary\iniparser3.0b\src\;CoreLibrary\input;CoreLibrary\jpeg;&quot;CoreLibrary\jpeg-6b&quot;;CoreLibrary\logo;CoreLibrary\map_actions;CoreLibrary\map_actions\ambient_life;CoreLibrary\md5;CoreLibrary\metaserver;CoreLibrary\metaserver_lib;CoreLibrary\minizip;CoreLibrary\mouse_cursor;CoreLibrary\myth;CoreLibrary\myth_networking;CoreLibrary\networking;CoreLibrary\sound;CoreLibrary\sound_utils;CoreLibrary\tag_files;CoreLibrary\openplay;CoreLibrary\uber;CoreLibrary\uber\NetModules;CoreLibrary\uber\NetModules\common;CoreLibrary\pix0r1;..\BuildTools\EncodeMap\"
+				AdditionalIncludeDirectories="Myth2Code\;Myth2Code\bitmap_dialogs;Myth2Code\console;Myth2Code\cseries;Myth2Code\cutscenes;Myth2Code\hardware;Myth2Code\hardware\Direct3D;Myth2Code\hardware\OpenGL;Myth2Code\hardware\3DFX;Myth2Code\hardware\DirectX11;Myth2Code\input;Myth2Code\map_actions;Myth2Code\map_actions\ambient_life;Myth2Code\metaserver;Myth2Code\myth_networking;Myth2Code\networking;Myth2Code\render;Myth2Code\smacker;Myth2Code\sound;Myth2Code\tag_files;Myth2Stuff\WindowsStuff;Myth2Stuff\WindowsStuff\curl;Myth2Stuff\WindowsStuff\gl;Myth2Stuff\WindowsStuff\Glide;Myth2Stuff\WindowsStuff\QuickTime7.3SDK\CIncludes;Myth2Stuff\WindowsStuff\OpenAL\include\;Myth2Stuff\WindowsStuff\zlib\;Myth2Stuff\WindowsStuff\Direct3D;Myth2Stuff\WindowsStuff\DirectX11;CoreLibrary\alignhash;CoreLibrary\bitmap_dialogs;CoreLibrary\cseries;CoreLibrary\iniparser3.0b\src\;CoreLibrary\input;CoreLibrary\jpeg;&quot;CoreLibrary\jpeg-6b&quot;;CoreLibrary\logo;CoreLibrary\map_actions;CoreLibrary\map_actions\ambient_life;CoreLibrary\md5;CoreLibrary\metaserver;CoreLibrary\metaserver_lib;CoreLibrary\minizip;CoreLibrary\mouse_cursor;CoreLibrary\myth;CoreLibrary\myth_networking;CoreLibrary\networking;CoreLibrary\sound;CoreLibrary\sound_utils;CoreLibrary\tag_files;CoreLibrary\openplay;CoreLibrary\uber;CoreLibrary\uber\NetModules;CoreLibrary\uber\NetModules\common;CoreLibrary\pix0r1;..\BuildTools\EncodeMap\"
 				PreprocessorDefinitions="WIN32;MYTH2;DEBUG;DEMO_NEW"
 				StringPooling="TRUE"
 				ExceptionHandling="FALSE"
Index: Myth2_vc10.vcxproj
===================================================================
--- Myth2_vc10.vcxproj	(revision 5740)
+++ Myth2_vc10.vcxproj	(working copy)
@@ -50,7 +50,7 @@
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
       <AdditionalOptions>/Zm1000</AdditionalOptions>
-      <AdditionalIncludeDirectories>./CoreLibrary/bitmap_dialogs;./CoreLibrary/boost;./CoreLibrary/cseries;./CoreLibrary/iniparser3.0b/src;./CoreLibrary/input;./CoreLibrary/map_actions;./CoreLibrary/map_actions/ambient_life;./CoreLibrary/md5;./CoreLibrary/metaserver;./CoreLibrary/metaserver_lib;./CoreLibrary/minizip;./CoreLibrary/mouse_cursor;./CoreLibrary/myth;./CoreLibrary/myth_networking;./CoreLibrary/networking;./CoreLibrary/openplay;./CoreLibrary/pix0r1;./CoreLibrary/sound;./CoreLibrary/sound_utils;./CoreLibrary/tag_files;./CoreLibrary/uber;./CoreLibrary/uber/NetModules;./CoreLibrary/uber/NetModules/common;./Myth2Code;./Myth2Code/bitmap_dialogs;./Myth2Code/console;./Myth2Code/cseries;./Myth2Code/cutscenes;./Myth2Code/hardware;./Myth2Code/hardware/3DFX;./Myth2Code/hardware/OpenGL;./Myth2Code/hardware/DirectX11;./Myth2Code/input;./Myth2Code/map_actions;./Myth2Code/map_actions/ambient_life;./Myth2Code/metaserver;./Myth2Code/myth_networking;./Myth2Code/networking;./Myth2Code/render;./Myth2Code/smacker;./Myth2Code/sound;./Myth2Code/tag_files;./Myth2Code/hardware/Direct3D;./Myth2Stuff/WindowsStuff;./Myth2Stuff/WindowsStuff/DirectX;./Myth2Stuff/WindowsStuff/DirectX11;./Myth2Stuff/WindowsStuff/Glide;./Myth2Stuff/WindowsStuff/OpenAL/include;./Myth2Stuff/WindowsStuff/QuickTime7.3SDK/CIncludes;./Myth2Stuff/WindowsStuff/curl;./Myth2Stuff/WindowsStuff/gl;./Myth2Stuff/WindowsStuff/SDL/include;./Myth2Stuff/WindowsStuff/zlib;./Myth2Stuff/WindowsStuff/nvToolsExt/include;../BuildTools/EncodeMap;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>./CoreLibrary/alignhash;./CoreLibrary/bitmap_dialogs;./CoreLibrary/boost;./CoreLibrary/cseries;./CoreLibrary/iniparser3.0b/src;./CoreLibrary/input;./CoreLibrary/map_actions;./CoreLibrary/map_actions/ambient_life;./CoreLibrary/md5;./CoreLibrary/metaserver;./CoreLibrary/metaserver_lib;./CoreLibrary/minizip;./CoreLibrary/mouse_cursor;./CoreLibrary/myth;./CoreLibrary/myth_networking;./CoreLibrary/networking;./CoreLibrary/openplay;./CoreLibrary/pix0r1;./CoreLibrary/sound;./CoreLibrary/sound_utils;./CoreLibrary/tag_files;./CoreLibrary/uber;./CoreLibrary/uber/NetModules;./CoreLibrary/uber/NetModules/common;./Myth2Code;./Myth2Code/bitmap_dialogs;./Myth2Code/console;./Myth2Code/cseries;./Myth2Code/cutscenes;./Myth2Code/hardware;./Myth2Code/hardware/3DFX;./Myth2Code/hardware/OpenGL;./Myth2Code/hardware/DirectX11;./Myth2Code/input;./Myth2Code/map_actions;./Myth2Code/map_actions/ambient_life;./Myth2Code/metaserver;./Myth2Code/myth_networking;./Myth2Code/networking;./Myth2Code/render;./Myth2Code/smacker;./Myth2Code/sound;./Myth2Code/tag_files;./Myth2Code/hardware/Direct3D;./Myth2Stuff/WindowsStuff;./Myth2Stuff/WindowsStuff/DirectX;./Myth2Stuff/WindowsStuff/DirectX11;./Myth2Stuff/WindowsStuff/Glide;./Myth2Stuff/WindowsStuff/OpenAL/include;./Myth2Stuff/WindowsStuff/QuickTime7.3SDK/CIncludes;./Myth2Stuff/WindowsStuff/curl;./Myth2Stuff/WindowsStuff/gl;./Myth2Stuff/WindowsStuff/SDL/include;./Myth2Stuff/WindowsStuff/zlib;./Myth2Stuff/WindowsStuff/nvToolsExt/include;../BuildTools/EncodeMap;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
       <ExceptionHandling>false</ExceptionHandling>
       <InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
@@ -80,7 +80,7 @@
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <ClCompile>
       <AdditionalOptions>/Zm1000</AdditionalOptions>
-      <AdditionalIncludeDirectories>./CoreLibrary/bitmap_dialogs;./CoreLibrary/boost;./CoreLibrary/cseries;./CoreLibrary/iniparser3.0b/src;./CoreLibrary/input;./CoreLibrary/map_actions;./CoreLibrary/map_actions/ambient_life;./CoreLibrary/md5;./CoreLibrary/metaserver;./CoreLibrary/metaserver_lib;./CoreLibrary/minizip;./CoreLibrary/mouse_cursor;./CoreLibrary/myth;./CoreLibrary/myth_networking;./CoreLibrary/networking;./CoreLibrary/openplay;./CoreLibrary/pix0r1;./CoreLibrary/sound;./CoreLibrary/sound_utils;./CoreLibrary/tag_files;./CoreLibrary/uber;./CoreLibrary/uber/NetModules;./CoreLibrary/uber/NetModules/common;./Myth2Code;./Myth2Code/bitmap_dialogs;./Myth2Code/console;./Myth2Code/cseries;./Myth2Code/cutscenes;./Myth2Code/hardware;./Myth2Code/hardware/3DFX;./Myth2Code/hardware/OpenGL;./Myth2Code/hardware/DirectX11;./Myth2Code/input;./Myth2Code/map_actions;./Myth2Code/map_actions/ambient_life;./Myth2Code/metaserver;./Myth2Code/myth_networking;./Myth2Code/networking;./Myth2Code/render;./Myth2Code/smacker;./Myth2Code/sound;./Myth2Code/tag_files;./Myth2Code/hardware/Direct3D;./Myth2Stuff/WindowsStuff;./Myth2Stuff/WindowsStuff/DirectX;./Myth2Stuff/WindowsStuff/DirectX11;./Myth2Stuff/WindowsStuff/Glide;./Myth2Stuff/WindowsStuff/OpenAL/include;./Myth2Stuff/WindowsStuff/QuickTime7.3SDK/CIncludes;./Myth2Stuff/WindowsStuff/curl;./Myth2Stuff/WindowsStuff/gl;./Myth2Stuff/WindowsStuff/SDL/include;./Myth2Stuff/WindowsStuff/zlib;./Myth2Stuff/WindowsStuff/nvToolsExt/include;../BuildTools/EncodeMap;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>./CoreLibrary/alignhash;./CoreLibrary/bitmap_dialogs;./CoreLibrary/boost;./CoreLibrary/cseries;./CoreLibrary/iniparser3.0b/src;./CoreLibrary/input;./CoreLibrary/map_actions;./CoreLibrary/map_actions/ambient_life;./CoreLibrary/md5;./CoreLibrary/metaserver;./CoreLibrary/metaserver_lib;./CoreLibrary/minizip;./CoreLibrary/mouse_cursor;./CoreLibrary/myth;./CoreLibrary/myth_networking;./CoreLibrary/networking;./CoreLibrary/openplay;./CoreLibrary/pix0r1;./CoreLibrary/sound;./CoreLibrary/sound_utils;./CoreLibrary/tag_files;./CoreLibrary/uber;./CoreLibrary/uber/NetModules;./CoreLibrary/uber/NetModules/common;./Myth2Code;./Myth2Code/bitmap_dialogs;./Myth2Code/console;./Myth2Code/cseries;./Myth2Code/cutscenes;./Myth2Code/hardware;./Myth2Code/hardware/3DFX;./Myth2Code/hardware/OpenGL;./Myth2Code/hardware/DirectX11;./Myth2Code/input;./Myth2Code/map_actions;./Myth2Code/map_actions/ambient_life;./Myth2Code/metaserver;./Myth2Code/myth_networking;./Myth2Code/networking;./Myth2Code/render;./Myth2Code/smacker;./Myth2Code/sound;./Myth2Code/tag_files;./Myth2Code/hardware/Direct3D;./Myth2Stuff/WindowsStuff;./Myth2Stuff/WindowsStuff/DirectX;./Myth2Stuff/WindowsStuff/DirectX11;./Myth2Stuff/WindowsStuff/Glide;./Myth2Stuff/WindowsStuff/OpenAL/include;./Myth2Stuff/WindowsStuff/QuickTime7.3SDK/CIncludes;./Myth2Stuff/WindowsStuff/curl;./Myth2Stuff/WindowsStuff/gl;./Myth2Stuff/WindowsStuff/SDL/include;./Myth2Stuff/WindowsStuff/zlib;./Myth2Stuff/WindowsStuff/nvToolsExt/include;../BuildTools/EncodeMap;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <ExceptionHandling>false</ExceptionHandling>
       <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
       <MultiProcessorCompilation>true</MultiProcessorCompilation>
Index: Myth2Code/hardware/generic_texture_cache.cpp
===================================================================
--- Myth2Code/hardware/generic_texture_cache.cpp	(revision 5740)
+++ Myth2Code/hardware/generic_texture_cache.cpp	(working copy)
@@ -18,14 +18,9 @@
 #include "generic_texture_cache_decompress.h"
 #include <vector>
 
-#ifdef __MEMORY_WRAPPERS_H__
-// horrible hack to make boost compile with our malloc define
-namespace std { inline void *new_pointer(size_t size) { return ::new_pointer(size); } }
-#endif
+typedef unsigned int uint32_t;
+#include "alignhash_tpl.h"
 
-#undef assert // fixes "#error assert has been defined before inclusion of assert.h header." on android
-#include <boost/unordered/unordered_map.hpp>
-
 using namespace std;
 
 static void decompress_and_huechange_pixel64_sprite_rle_texture(
@@ -105,12 +100,50 @@
 	T * m_first, * m_last;
 };
 
+template<class K, class V>
+class alignhash_wrapper
+{
+	DEFINE_ALIGNHASH(_, K, V, 1, alignhash_hashfn, alignhash_equalfn);
+	alignhash_t(_) *hash;
+
+public:
+
+	alignhash_wrapper() {
+		hash = alignhash_init(_);
+	}
+
+	~alignhash_wrapper() {
+		alignhash_destroy(_, hash);
+	}
+
+	void erase(const K& key) {
+		alignhash_del(_, hash, alignhash_get(_, hash, key));
+	}
+
+	V& operator[](const K& key) {
+		int ret = AH_INS_ERR;
+		ah_iter_t where = alignhash_set(_, hash, key, &ret);
+		V& val = alignhash_value(hash, where);
+		if (ret != AH_INS_ERR) {
+			val = V();
+		}
+		return val;
+	}
+};
+
 struct cache_key
 {
 	cache_key() : bitmap_id(0), bitmap(0), shading_table(0) {}
 	cache_key(long bitmap_id, bitmap_data *bitmap, void *shading_table)
 		: bitmap_id(bitmap_id), bitmap(bitmap), shading_table(shading_table) {}
-	
+
+	// hash function
+	operator ah_size_t () {
+		// Simple linear congruential hash with constants from here:
+		//   http://en.wikipedia.org/wiki/Linear_congruential_generator
+		return (1664525 * (std::size_t)bitmap_id + 1013904223);
+	}
+
 	bool operator == (const cache_key& rhs) const {
 		     if(bitmap_id != rhs.bitmap_id) return FALSE;
 		else if(bitmap != rhs.bitmap) return FALSE;
@@ -122,20 +155,6 @@
 	void *shading_table;
 };
 
-struct cache_key_hash
-{
-	size_t operator () (const cache_key &k) const {
-		// Simple linear congruential hash with constants from here:
-		//   http://en.wikipedia.org/wiki/Linear_congruential_generator
-		return (1664525 * (std::size_t)k.bitmap_id + 1013904223);
-	}
-};
-
-struct cache_value;
-
-typedef boost::unordered_map<cache_key, cache_value, cache_key_hash> cache_map;
-typedef linked_list<cache_value> cache_list;
-
 struct cache_value
 {
 	cache_value()
@@ -150,13 +169,16 @@
 		this->in_map = TRUE;
 	}
 
+	boolean in_map;
 	cache_key map_key;
 	cache_value *prev, *next;
 	struct cached_texture_data texture;
 	int memory_use;
-	boolean in_map;
 };
 
+typedef linked_list<cache_value> cache_list;
+typedef alignhash_wrapper<cache_key, cache_value*> cache_map;
+
 struct cache
 {
 	cache(void *user_context,
@@ -165,7 +187,7 @@
 	~cache();
 
 	cache_value *new_preallocated_item(struct cached_texture_descriptor *descriptor);
-	cache_value *lookup(struct cached_texture_descriptor *descriptor, boolean insert_if_not_found);
+	cached_texture_data *lookup(struct cached_texture_descriptor *descriptor);
 	void clear();
 
 	int texture_memory_size(struct cached_texture_data *texture);
@@ -226,46 +248,42 @@
 	return NULL;
 }
 
-cache_value *cache::lookup(struct cached_texture_descriptor *descriptor, boolean insert_if_not_found)
+struct cached_texture_data *cache::lookup(struct cached_texture_descriptor *descriptor)
 {
 	cache_key key(descriptor->identifier.bits, (descriptor->usage_flags & _texture_lookup_by_pixels_flag) ?
 		(bitmap_data*)descriptor->bitmap->row_addresses[0] : descriptor->bitmap, descriptor->shading_table);
-	cache_value *value = NULL;
+	cache_value *&value = cache_items[key];
 
-	cache_map::iterator it = cache_items.find(key);
-
-	if(it != cache_items.end())
+	if(value)
 	{
 		// already exists - update if necessary
-		value = &it->second;
 		// NOTE: textures looked up by identifier are currently considered static (not checked for _bitmap_changed_flag)
 		// If we wish to add that in the future, it should be done by checking value->texture.bitmap
 		struct bitmap_data *bitmap = descriptor->bitmap;
 		if((bitmap && (bitmap->flags & _bitmap_changed_flag)) &&
 			!update_cache_item(value, descriptor))
 		{
-			delete_cache_item(value);
-			value = NULL;
+			goto _exit_with_error;
 		}
 	}
-	else if(insert_if_not_found)
+	else
 	{
-		// insert new value
-		cache_value temp(key);
-		if(initialize_cache_item(&temp, descriptor))
+		// not found - initialize new item
+		value = new cache_value(key);
+		if(!initialize_cache_item(value, descriptor))
 		{
-			cache_map::iterator i = cache_items.insert(make_pair(key, temp)).first;
-			value = &i->second;
+			goto _exit_with_error;
 		}
 	}
 
-	if(value)
-	{
-		// move to front
-		cache_lru.mtf(value);
-	}
+	// move to front
+	cache_lru.mtf(value);
+	return &value->texture;
 
-	return value;
+_exit_with_error:
+
+	delete_cache_item(value);
+	return NULL;
 }
 
 void cache::clear()
@@ -419,12 +437,9 @@
 	{
 		cache_lru.unlink(item);
 		cache_items.erase(item->map_key);
-		//delete item; // this memory lives in the map, so erase() frees it.
 	}
-	else
-	{
-		delete item;
-	}
+
+	delete item;
 }
 
 void cache::compute_bitmap_decompression_mode(
@@ -741,8 +756,7 @@
 
 const struct cached_texture_data *texture_cache_lookup(struct cached_texture_descriptor *descriptor)
 {
-	cache_value *value = cache_singleton->lookup(descriptor, TRUE);
-	return value ? &value->texture : NULL;
+	return cache_singleton->lookup(descriptor);
 }
 
 int texture_cache_memory_use(void)
