Esempio n. 1
0
        public Texture2D GetWeapon(bool isBow = false)
        {
            WeaponSpriteType type = WeaponSpriteType.Standing;

            switch (charRef.State)
            {
            case CharacterActionState.Walking:
                switch (_data.walkFrame)
                {
                case 1: type = WeaponSpriteType.WalkFrame1; break;

                case 2: type = WeaponSpriteType.WalkFrame2; break;

                case 3: type = WeaponSpriteType.WalkFrame3; break;

                case 4: type = WeaponSpriteType.WalkFrame4; break;
                }
                break;

            case CharacterActionState.Attacking:
                if (isBow)
                {
                    switch (_data.attackFrame)
                    {
                    case 1: type = WeaponSpriteType.Shooting; break;

                    case 2: type = WeaponSpriteType.Standing; break;
                    }
                }
                else
                {
                    switch (_data.attackFrame)
                    {
                    case 1: type = WeaponSpriteType.SwingFrame1; break;

                    case 2:
                        type = _data.facing == EODirection.Down || _data.facing == EODirection.Right
                                                                        ? WeaponSpriteType.SwingFrame2Spec
                                                                        : WeaponSpriteType.SwingFrame2;
                        break;
                    }
                }
                break;

            case CharacterActionState.SpellCast:
                type = WeaponSpriteType.SpellCast;
                break;

            case CharacterActionState.Sitting: return(null);                    //no weapon when sitting
            }

            short    baseWeaponValue = (short)((_data.weapon - 1) * 100);
            GFXTypes gfxFile         = _data.gender == 0 ? GFXTypes.FemaleWeapons : GFXTypes.MaleWeapons;
            int      factor          = (_data.facing == EODirection.Down || _data.facing == EODirection.Right) ? 0 : 1;

            factor *= getFactor(type);
            int gfxNumber = baseWeaponValue + (int)type + factor;

            return(GFXLoader.TextureFromResource(gfxFile, gfxNumber, true));
        }
Esempio n. 2
0
		public Texture2D TextureFromResource(GFXTypes file, int resourceVal, bool transparent = false, bool reloadFromFile = false)
		{
			Texture2D ret;

			var key = new LibraryGraphicPair((int)file, 100 + resourceVal);
			if (!reloadFromFile && cache.ContainsKey(key))
			{
				return cache[key];
			}

			if (cache.ContainsKey(key) && reloadFromFile)
			{
				if (cache[key] != null) cache[key].Dispose();
				cache.Remove(key);
			}

			using (var mem = new System.IO.MemoryStream())
			{
				using (var i = BitmapFromResource(file, resourceVal, transparent))
					i.Save(mem, System.Drawing.Imaging.ImageFormat.Png);

				ret = Texture2D.FromStream(_device, mem);
			}

			//need to double-check that the key isn't already in the cache:
			//  	multiple threads can enter this method simultaneously
			//avoiding a lock because this method is used for every graphic
			if (!cache.ContainsKey(key))
				cache.Add(key, ret);

			return ret;
		}
Esempio n. 3
0
        /// <summary>
        /// Gets the hair texture from the GFX file based on gender, direction, style, and color
        /// </summary>
        /// <param name="refresh">True to refresh from the GFX file, false to use the hair texture cached in this EOSpriteSheet instance</param>
        /// <returns>Texture2D with the hair data</returns>
        public Texture2D GetHair(bool refresh)
        {
            byte     turnedOffset = (byte)((_data.facing == EODirection.Left || _data.facing == EODirection.Up) ? 2 : 0);
            GFXTypes gfxFile      = (_data.gender == 0) ? GFXTypes.FemaleHair : GFXTypes.MaleHair;
            int      gfxNumber    = 2 + ((_data.hairstyle - 1) * 40) + (_data.haircolor * 4) + turnedOffset;

            return(GFXLoader.TextureFromResource(gfxFile, gfxNumber, true, refresh));
        }
Esempio n. 4
0
		public LibraryLoadException(string libraryNumber, GFXTypes which)
			: base(string.Format("Error {1} when loading library {0}\n{2}",
				libraryNumber,
				Marshal.GetLastWin32Error(),
				new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error()).Message))
		{
			WhichGFX = which;
		}
Esempio n. 5
0
 public LibraryLoadException(string libraryNumber, GFXTypes which)
     : base(string.Format("Error {1} when loading library {0}\n{2}",
                          libraryNumber,
                          Marshal.GetLastWin32Error(),
                          new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error()).Message))
 {
     WhichGFX = which;
 }
Esempio n. 6
0
        public Texture2D GetHat()
        {
            short    baseHatValue = (short)((_data.hat - 1) * 10);
            GFXTypes gfxFile      = _data.gender == 0 ? GFXTypes.FemaleHat : GFXTypes.MaleHat;
            int      factor       = (_data.facing == EODirection.Down || _data.facing == EODirection.Right) ? 0 : 2;
            int      gfxNumber    = baseHatValue + factor + 1;

            return(GFXLoader.TextureFromResource(gfxFile, gfxNumber, true));
        }
Esempio n. 7
0
		public Bitmap LoadGFX(GFXTypes file, int resourceVal)
		{
			var library = _modules[file];
			var image = LoadLibraryImage(file, library, resourceVal);
			
			Bitmap ret = Image.FromHbitmap(image);

			Win32.DeleteObject(image);

			return ret;
		}
Esempio n. 8
0
		private IntPtr LoadLibraryModule(GFXTypes file)
		{
			var number = ((int)file).ToString("D3");
			var fName = System.IO.Path.Combine("gfx", "gfx" + number + ".egf");

			var library = Win32.LoadLibrary(fName);

			if (library == IntPtr.Zero)
				throw new LibraryLoadException(number, file);

			return library;
		}
        private Mock <IPEFile> SetupPEFileForGFXType(GFXTypes type, byte[] array)
        {
            var collectionMock = Mock.Get(_modules);
            var peFile         = new Mock <IPEFile>();

            collectionMock.Setup(x => x[type]).Returns(peFile.Object);

            peFile.Setup(x => x.GetEmbeddedBitmapResourceByID(It.IsAny <int>(), It.IsAny <int>()))
            .Returns(array);

            return(peFile);
        }
Esempio n. 10
0
        public Bitmap LoadGFX(GFXTypes file, int resourceValue)
        {
            var fileBytes = _modules[file].GetEmbeddedBitmapResourceByID(resourceValue + 100);

            if (fileBytes.Length == 0)
            {
                throw new GFXLoadException(resourceValue, file);
            }

            var ms = new MemoryStream(fileBytes);

            return((Bitmap)Image.FromStream(ms));
        }
Esempio n. 11
0
        private static Bitmap BitmapFromResource(GFXTypes file, int resourceVal, bool transparent)
        {
            if (device == null)
            {
                throw new NullReferenceException("The GFX loader must be initialized with a graphics device by calling GFXLoader.Initialize() in your game class.");
            }

            string number = ((int)file).ToString("D3");
            string fName  = System.IO.Path.Combine(new [] { "gfx", "gfx" + number + ".egf" });

            IntPtr library = LoadLibrary(fName);

            if (library == IntPtr.Zero)
            {
                int err = Marshal.GetLastWin32Error();
                throw new Exception(string.Format("Error {1} when loading library {0}\n{2}", number, err, new System.ComponentModel.Win32Exception(err).Message));
            }

            IntPtr image = LoadImage(library, (uint)(100 + resourceVal), 0 /*IMAGE_BITMAP*/, 0, 0, 0x00008000 | 0x00002000 /*LR_DEFAULT*/);

            if (image == IntPtr.Zero)
            {
                throw new GFXLoadException(resourceVal, file);
            }
            Bitmap ret = Image.FromHbitmap(image);

            if (transparent)
            {
                if (file != GFXTypes.FemaleHat && file != GFXTypes.MaleHat)
                {
                    ret.MakeTransparent(Color.Black);
                }

                // for hats: 0x080000 is transparent, 0x000000 is supposed to clip hair below it
                if (file == GFXTypes.FemaleHat || file == GFXTypes.MaleHat)
                {
                    //ret.MakeTransparent(Color.Black);
                    ret.MakeTransparent(Color.FromArgb(0xFF, 0x08, 0x00, 0x00));
                }
            }

            FreeLibrary(library);
            DeleteObject(image);
            return(ret);
        }
Esempio n. 12
0
        public Texture2D GetBoots(bool isBow = false)
        {
            BootsSpriteType type = BootsSpriteType.Standing;

            switch (charRef.State)
            {
            case CharacterActionState.Walking:
                switch (_data.walkFrame)
                {
                case 1: type = BootsSpriteType.WalkFrame1; break;

                case 2: type = BootsSpriteType.WalkFrame2; break;

                case 3: type = BootsSpriteType.WalkFrame3; break;

                case 4: type = BootsSpriteType.WalkFrame4; break;
                }
                break;

            case CharacterActionState.Attacking:
                if (!isBow && _data.attackFrame == 2 ||
                    isBow && _data.attackFrame == 1)
                {
                    type = BootsSpriteType.Attack;
                }
                break;

            case CharacterActionState.Sitting:
                switch (_data.sitting)
                {
                case SitState.Chair: type = BootsSpriteType.SitChair; break;

                case SitState.Floor: type = BootsSpriteType.SitGround; break;
                }
                break;
            }
            short    baseBootsValue = (short)((_data.boots - 1) * 40);
            GFXTypes gfxFile        = _data.gender == 0 ? GFXTypes.FemaleShoes : GFXTypes.MaleShoes;
            int      factor         = (_data.facing == EODirection.Down || _data.facing == EODirection.Right) ? 0 : 1;

            factor *= getFactor(type);
            int gfxNumber = baseBootsValue + (int)type + factor;

            return(GFXLoader.TextureFromResource(gfxFile, gfxNumber, true));
        }
Esempio n. 13
0
        private static void TryInitializePEFiles(GFXTypes file, IPEFile peFile)
        {
            var number = ((int)file).ToString("D3");

            try
            {
                peFile.Initialize();
            }
            catch (IOException)
            {
                throw new LibraryLoadException(number, file);
            }

            if (!peFile.Initialized)
            {
                throw new LibraryLoadException(number, file);
            }
        }
Esempio n. 14
0
		private Bitmap BitmapFromResource(GFXTypes file, int resourceVal, bool transparent)
		{
			var ret = _gfxLoader.LoadGFX(file, resourceVal);

			if (transparent)
			{
				if (file != GFXTypes.FemaleHat && file != GFXTypes.MaleHat)
					ret.MakeTransparent(Color.Black);

				// for hats: 0x080000 is transparent, 0x000000 is supposed to clip hair below it
				if (file == GFXTypes.FemaleHat || file == GFXTypes.MaleHat)
				{
					//ret.MakeTransparent(Color.Black);
					ret.MakeTransparent(Color.FromArgb(0xFF, 0x08, 0x00, 0x00));
				}
			}

			return ret;
		}
Esempio n. 15
0
        public Texture2D TextureFromResource(GFXTypes file, int resourceVal, bool transparent = false, bool reloadFromFile = false)
        {
            Texture2D ret;

            var key = new LibraryGraphicPair((int)file, 100 + resourceVal);

            if (!reloadFromFile && _cache.ContainsKey(key))
            {
                return(_cache[key]);
            }

            if (_cache.ContainsKey(key) && reloadFromFile)
            {
                if (_cache[key] != null)
                {
                    _cache[key].Dispose();
                }
                _cache.Remove(key);
            }

            using (var mem = new System.IO.MemoryStream())
            {
                using (var i = BitmapFromResource(file, resourceVal, transparent))
                    i.Save(mem, ImageFormat.Png);

                ret = Texture2D.FromStream(_graphicsDeviceProvider.GraphicsDevice, mem);
            }

            //need to double-check that the key isn't already in the cache:
            //      multiple threads can enter this method simultaneously
            //avoiding a lock because this method is used for every graphic
            if (!_cache.ContainsKey(key))
            {
                _cache.Add(key, ret);
            }
            else
            {
                ret.Dispose();
                ret = _cache[key];
            }

            return(ret);
        }
Esempio n. 16
0
        private Bitmap BitmapFromResource(GFXTypes file, int resourceVal, bool transparent)
        {
            var ret = _gfxLoader.LoadGFX(file, resourceVal);

            if (transparent)
            {
                if (file != GFXTypes.FemaleHat && file != GFXTypes.MaleHat)
                {
                    ret.MakeTransparent(Color.Black);
                }

                // for hats: 0x080000 is transparent, 0x000000 is supposed to clip hair below it
                if (file == GFXTypes.FemaleHat || file == GFXTypes.MaleHat)
                {
                    //ret.MakeTransparent(Color.Black);
                    ret.MakeTransparent(Color.FromArgb(0xFF, 0x08, 0x00, 0x00));
                }
            }

            return(ret);
        }
        private Bitmap BitmapFromResource(GFXTypes file, int resourceVal, bool transparent)
        {
            var ret = _gfxLoader.LoadGFX(file, resourceVal);

            if (transparent)
            {
                // TODO: 0x000000 is supposed to clip hair below it
                //       need to figure out how to clip this
                // if (file != GFXTypes.FemaleHat && file != GFXTypes.MaleHat)
                CrossPlatformMakeTransparent(ret, Color.Black);

                // for hats: 0x080000 is transparent
                if (file == GFXTypes.FemaleHat || file == GFXTypes.MaleHat)
                {
                    CrossPlatformMakeTransparent(ret, Color.FromArgb(0xFF, 0x08, 0x00, 0x00));
                    CrossPlatformMakeTransparent(ret, Color.FromArgb(0xFF, 0x00, 0x08, 0x00));
                    CrossPlatformMakeTransparent(ret, Color.FromArgb(0xFF, 0x00, 0x00, 0x08));
                }
            }

            return(ret);
        }
        public Texture2D TextureFromResource(GFXTypes file, int resourceVal, bool transparent = false, bool reloadFromFile = false)
        {
            Texture2D ret;

            var key = new LibraryGraphicPair((int)file, 100 + resourceVal);

            lock (__cachelock__)
            {
                if (!reloadFromFile && _cache.ContainsKey(key))
                {
                    return(_cache[key]);
                }

                if (_cache.ContainsKey(key) && reloadFromFile)
                {
                    if (_cache[key] != null)
                    {
                        _cache[key].Dispose();
                    }
                    _cache.Remove(key);
                }
            }

            using (var mem = new System.IO.MemoryStream())
            {
                using (var i = BitmapFromResource(file, resourceVal, transparent))
                    i.Save(mem, ImageFormat.Png);

                ret = Texture2D.FromStream(_graphicsDeviceProvider.GraphicsDevice, mem);
            }

            lock (__cachelock__)
            {
                _cache.Add(key, ret);
            }

            return(ret);
        }
Esempio n. 19
0
        protected override void Initialize()
        {
            try
            {
                //yup. class named the same as a namespace. #whut #rekt
                XNAControls.XNAControls.Initialize(this);
            }
            catch (ArgumentNullException ex)
            {
                MessageBox.Show("Something super weird happened: " + ex.Message);
                Exit();
                return;
            }

            IsMouseVisible = true;
            Dispatcher     = new KeyboardDispatcher(Window);
            ResetPeopleIndices();

            try
            {
                GFXLoader.Initialize(GraphicsDevice);
                World w = World.Instance;                 //set up the world
                w.Init();

                host = World.Instance.Host;
                port = World.Instance.Port;
            }
            catch (WorldLoadException wle)             //could be thrown from World's constructor
            {
                MessageBox.Show(wle.Message, "Error");
                Exit();
                return;
            }
            catch (ConfigStringLoadException csle)
            {
                host = World.Instance.Host;
                port = World.Instance.Port;
                switch (csle.WhichString)
                {
                case ConfigStrings.Host:
                    MessageBox.Show(
                        string.Format("There was an error loading the host/port from the config file. Defaults will be used: {0}:{1}",
                                      host, port),
                        "Config Load Failed",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning);
                    break;

                case ConfigStrings.Port:
                    MessageBox.Show(
                        string.Format("There was an error loading the port from the config file. Default will be used: {0}:{1}",
                                      host, port),
                        "Config Load Failed",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning);
                    break;
                }
            }
            catch (ArgumentException ex)             //could be thrown from GFXLoader.Initialize
            {
                MessageBox.Show("Error initializing GFXLoader: " + ex.Message, "Error");
                Exit();
                return;
            }

            if (World.Instance.EIF != null && World.Instance.EIF.Version == 0)
            {
                MessageBox.Show("The item pub file you are using is using an older format of the EIF specification. Some features may not work properly. Run the file through a batch processor or use updated pub files.", "Warning");
            }

            GFXTypes curValue = 0;

            try
            {
                Array values = Enum.GetValues(typeof(GFXTypes));
                foreach (GFXTypes value in values)
                {
                    curValue = value;
                    //check for GFX files. Each file has a GFX 1.
                    using (Texture2D throwAway = GFXLoader.TextureFromResource(value, -99))
                    {
                        throwAway.Name = "";                         //no-op to keep resharper happy
                    }
                }
            }
            catch
            {
                MessageBox.Show(string.Format("There was an error loading GFX{0:000}.EGF : {1}. Place all .GFX files in .\\gfx\\", (int)curValue, curValue.ToString()), "Error");
                Exit();
                return;
            }

            try
            {
                SoundManager = new EOSoundManager();
            }
            catch
            {
                MessageBox.Show(string.Format("There was an error initializing the sound manager."), "Error");
                Exit();
                return;
            }

            if (World.Instance.MusicEnabled)
            {
                SoundManager.PlayBackgroundMusic(1);                 //mfx001 == main menu theme
            }

            base.Initialize();
        }
Esempio n. 20
0
        private static Bitmap BitmapFromResource(GFXTypes file, int resourceVal, bool transparent)
        {
            if (device == null)
            {
                throw new NullReferenceException("The GFX loader must be initialized with a graphics device by calling GFXLoader.Initialize() in your game class.");
            }

            string number = ((int)file).ToString("D3");
            string fName = System.IO.Path.Combine(new [] { "gfx", "gfx" + number + ".egf" });

            IntPtr library = LoadLibrary(fName);

            if (library == IntPtr.Zero)
            {
                int err = Marshal.GetLastWin32Error();
                throw new Exception(string.Format("Error {1} when loading library {0}\n{2}", number, err, new System.ComponentModel.Win32Exception(err).Message));
            }

            IntPtr image = LoadImage(library, (uint)(100 + resourceVal), 0 /*IMAGE_BITMAP*/, 0, 0, 0x00008000 | 0x00002000 /*LR_DEFAULT*/);

            if (image == IntPtr.Zero)
            {
                throw new GFXLoadException(resourceVal, file);
            }
            Bitmap ret = Image.FromHbitmap(image);

            if (transparent)
            {
                if (file != GFXTypes.FemaleHat && file != GFXTypes.MaleHat)
                    ret.MakeTransparent(Color.Black);

                // for hats: 0x080000 is transparent, 0x000000 is supposed to clip hair below it
                if (file == GFXTypes.FemaleHat || file == GFXTypes.MaleHat)
                {
                    //ret.MakeTransparent(Color.Black);
                    ret.MakeTransparent(Color.FromArgb(0xFF, 0x08, 0x00, 0x00));
                }
            }

            FreeLibrary(library);
            DeleteObject(image);
            return ret;
        }
Esempio n. 21
0
 public GFXLoadException(int resource, GFXTypes gfx)
     : base(string.Format("Unable to load graphic {0} from file gfx{1:000}.egf", resource + 100, (int)gfx))
 {
 }
 public GFXLoadException(int resource, GFXTypes gfx)
     : base($"Unable to load graphic {resource + 100} from file gfx{(int) gfx:000}.egf")
 {
 }
Esempio n. 23
0
        public Texture2D GetShield(bool shieldIsOnBack)
        {
            //front shields have one size gfx, back arrows/wings have another size.
            ArmorShieldSpriteType type = ArmorShieldSpriteType.Standing;
            int factor;

            if (!shieldIsOnBack)
            {
                if (charRef.State == CharacterActionState.Walking)
                {
                    switch (_data.walkFrame)
                    {
                    case 1: type = ArmorShieldSpriteType.WalkFrame1; break;

                    case 2: type = ArmorShieldSpriteType.WalkFrame2; break;

                    case 3: type = ArmorShieldSpriteType.WalkFrame3; break;

                    case 4: type = ArmorShieldSpriteType.WalkFrame4; break;
                    }
                }
                else if (charRef.State == CharacterActionState.Attacking)
                {
                    switch (_data.attackFrame)
                    {
                    case 1: type = ArmorShieldSpriteType.PunchFrame1; break;

                    case 2: type = ArmorShieldSpriteType.PunchFrame2; break;
                    }
                }
                else if (charRef.State == CharacterActionState.SpellCast)
                {
                    type = ArmorShieldSpriteType.SpellCast;
                }
                else
                {
                    //hide shield graphic when sitting
                    return(null);
                }

                factor  = (_data.facing == EODirection.Down || _data.facing == EODirection.Right) ? 0 : 1;
                factor *= getFactor(type);
            }
            else
            {
                //sitting is valid for arrows and wings and bag
                //Standing = 1/2
                //Attacking = 3/4
                //Extra = 5 (unused?)
                if (charRef.State == CharacterActionState.Attacking && _data.attackFrame == 1)
                {
                    type = (ArmorShieldSpriteType)3;
                }
                factor = (_data.facing == EODirection.Down || _data.facing == EODirection.Right) ? 0 : 1;
            }

            short    baseShieldValue = (short)((_data.shield - 1) * 50);
            GFXTypes gfxFile         = _data.gender == 0 ? GFXTypes.FemaleBack : GFXTypes.MaleBack;
            int      gfxNumber       = baseShieldValue + (int)type + factor;

            return(GFXLoader.TextureFromResource(gfxFile, gfxNumber, true));
        }
Esempio n. 24
0
        public Texture2D GetArmor(bool isBow = false)
        {
            ArmorShieldSpriteType type = ArmorShieldSpriteType.Standing;

            switch (charRef.State)
            {
            case CharacterActionState.Walking:
                switch (_data.walkFrame)
                {
                case 1: type = ArmorShieldSpriteType.WalkFrame1; break;

                case 2: type = ArmorShieldSpriteType.WalkFrame2; break;

                case 3: type = ArmorShieldSpriteType.WalkFrame3; break;

                case 4: type = ArmorShieldSpriteType.WalkFrame4; break;
                }
                break;

            case CharacterActionState.Attacking:
                if (isBow)
                {
                    switch (_data.attackFrame)
                    {
                    case 1: type = ArmorShieldSpriteType.Bow; break;

                    case 2: type = ArmorShieldSpriteType.Standing; break;
                    }
                }
                else
                {
                    switch (_data.attackFrame)
                    {
                    case 1: type = ArmorShieldSpriteType.PunchFrame1; break;

                    case 2: type = ArmorShieldSpriteType.PunchFrame2; break;
                    }
                }
                break;

            case CharacterActionState.SpellCast:
                type = ArmorShieldSpriteType.SpellCast;
                break;

            case CharacterActionState.Sitting:
                switch (_data.sitting)
                {
                case SitState.Chair:
                    type = ArmorShieldSpriteType.SitChair;
                    break;

                case SitState.Floor:
                    type = ArmorShieldSpriteType.SitGround;
                    break;
                }
                break;
            }

            short    baseArmorValue = (short)((_data.armor - 1) * 50);
            GFXTypes gfxFile        = (_data.gender == 0) ? GFXTypes.FemaleArmor : GFXTypes.MaleArmor;
            int      factor         = (_data.facing == EODirection.Down || _data.facing == EODirection.Right) ? 0 : 1; //multiplier for the direction faced

            factor *= getFactor(type);
            int gfxNumber = baseArmorValue + (int)type + factor;

            return(GFXLoader.TextureFromResource(gfxFile, gfxNumber, true));
        }
Esempio n. 25
0
 public GFXLoadException(int resource, GFXTypes gfx)
     : base(string.Format("Unable to load graphic {0} from file gfx{1:000}.egf", resource + 100, (int)gfx))
 {
 }
Esempio n. 26
0
		private IntPtr LoadLibraryImage(GFXTypes file, IntPtr library, int resourceVal)
		{
			var image = Win32.LoadImage(library, (uint)(100 + resourceVal), 0 /*IMAGE_BITMAP*/, 0, 0, 0x00008000 | 0x00002000 /*LR_DEFAULT*/);

			if (image == IntPtr.Zero)
			{
				throw new GFXLoadException(resourceVal, file);
			}

			return image;
		}