Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using MapleLib.WzLib;
- using MapleLib.WzLib.WzProperties;
- using Microsoft.DirectX.Direct3D;
- using WzExplorer.Mapping;
- using Microsoft.DirectX.DirectInput;
- namespace WzExplorer
- {
- public partial class Mapper : Form
- {
- public WzFile wz;
- WzMapleVersion ver;
- IDirectObject render;
- public Microsoft.DirectX.Direct3D.Device DxDevice;
- public Microsoft.DirectX.DirectInput.Device Mouse;
- public Microsoft.DirectX.DirectInput.Device Keyboard;
- public static Sprite sprite = null;
- D2DObject Main;
- List<MapLink> mapLink = new List<MapLink>();
- List<MapList> mapList = new List<MapList>();
- public static Mapper obj;
- public Point pos;
- public bool change = false;
- public Mapper(WzMapleVersion version)
- {
- InitializeComponent();
- ver = version;
- SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque | ControlStyles.ResizeRedraw, true);
- InitDX();
- obj = this;
- #if DEBUG
- miniMaps.Visible = true;
- test.Visible = true;
- #endif
- }
- private void InitDX()
- {
- PresentParameters presentParams = new PresentParameters();
- presentParams.Windowed = true;
- presentParams.SwapEffect = SwapEffect.Discard; // After the current screen is drawn, it will be automatically deleted from memory
- DxDevice = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, Map, CreateFlags.SoftwareVertexProcessing, presentParams); // Put everything into the device
- sprite = new Sprite(DxDevice);
- Mouse = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Mouse);
- Mouse.SetCooperativeLevel(this, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
- Mouse.Acquire();
- Keyboard = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard);
- Keyboard.SetCooperativeLevel(this, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
- Keyboard.Acquire();
- timer1.Start();
- }
- private void openToolStripMenuItem_Click(object sender, EventArgs e)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "MapleStory Map file (Map.wz)|Map.wz";
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- wz = new WzFile(ofd.FileName, ver);
- wz.ParseWzFile();
- miniMaps.Items.Clear();
- foreach (WzImage img in ((WzDirectory)wz.GetObjectFromPath(wz.Name + "/WorldMap")).WzImages)
- {
- miniMaps.Items.Add(img.Name.Replace(".img", ""));
- }
- miniMaps.SelectedItem = "WorldMap";
- }
- }
- public void miniMaps_SelectedIndexChanged(object sender, EventArgs e)
- {
- change = false;
- mapLink.Clear();
- mapList.Clear();
- WzImage img = ((WzImage)wz.GetObjectFromPath(wz.Name + "/WorldMap/" + miniMaps.SelectedItem.ToString() + ".img"));
- WzCanvasProperty can = ((WzCanvasProperty)img.GetFromPath("BaseImg/0"));
- Main = new D2DObject(DxDevice, can.PngProperty.PNG);
- WzVectorProperty baseorigin = ((WzVectorProperty)can["origin"]);
- if (img.GetFromPath("MapLink") != null)
- {
- foreach (WzSubProperty sub in img.GetFromPath("MapLink").WzProperties)
- {
- string toolTip = ((WzStringProperty)sub["toolTip"]).Value;
- string LinkMap = ((WzStringProperty)sub.GetFromPath("link/linkMap")).Value;
- WzCanvasProperty canvas = ((WzCanvasProperty)sub.GetFromPath("link/linkImg"));
- Bitmap image = canvas.PngProperty.PNG;
- WzVectorProperty origin = ((WzVectorProperty)canvas["origin"]);
- MapLink mLink = new MapLink(DxDevice, Mouse, toolTip, LinkMap, image, baseorigin, origin);
- mapLink.Add(mLink);
- }
- }
- if (img.GetFromPath("MapList") != null)
- {
- foreach (WzSubProperty sub in img.GetFromPath("MapList").WzProperties)
- {
- int type = ((WzCompressedIntProperty)sub["type"]).Value;
- WzVectorProperty spot = ((WzVectorProperty)sub["spot"]);
- MapList mlist = new MapList(DxDevice, Mouse, type, spot, baseorigin);
- mapList.Add(mlist);
- }
- }
- }
- #region dx
- private void Map_Paint(object sender, PaintEventArgs e)
- {
- if (DxDevice == null)
- return;
- DxDevice.Clear(ClearFlags.Target, Color.Black, 0f, 0); // Clear the window to white
- DxDevice.BeginScene();
- sprite.Begin(SpriteFlags.AlphaBlend);
- if (Main != null)
- Main.StaticDraw();
- foreach (MapLink ml in mapLink)
- {
- ml.Update();
- if (ml.canDraw == true)
- {
- ml.StaticDraw();
- }
- }
- if (change)
- {
- miniMaps.SelectedItem = test.Text;
- }
- foreach (MapList mlst in mapList)
- {
- mlst.Update();
- mlst.StaticDraw();
- }
- sprite.End();
- DxDevice.EndScene();
- DxDevice.Present();
- Invalidate();
- KeyPresses();
- }
- public void KeyPresses()
- {
- KeyboardState keys = Keyboard.GetCurrentKeyboardState();
- if (keys[Key.Escape])
- {
- miniMaps.SelectedItem = "WorldMap";
- }
- }
- public interface IDirectObject
- {
- void Draw();
- void StaticDraw();
- }
- public class D2DObject : IDirectObject
- {
- internal Texture texture;
- internal Microsoft.DirectX.Direct3D.Device DxDevice;
- internal Bitmap image;
- public int x = 0, y = 0;
- public D2DObject(Microsoft.DirectX.Direct3D.Device DxDevice, Bitmap image)
- {
- this.DxDevice = DxDevice;
- this.image = image;
- this.texture = Texture.FromBitmap(DxDevice, image, Usage.Dynamic, Pool.Default);
- }
- public D2DObject(Microsoft.DirectX.Direct3D.Device DxDevice, Bitmap image, int x, int y)
- {
- this.DxDevice = DxDevice;
- this.image = image;
- this.texture = Texture.FromBitmap(DxDevice, image, Usage.Dynamic, Pool.Default);
- //sprite = new Sprite(DxDevice);
- this.x = x;
- this.y = y;
- }
- public void StaticDraw()
- {
- sprite.Draw2D(texture, new Point(0, 0), 0f, new Point(0, 0), Color.White);
- }
- public void Draw()
- {
- sprite.Draw2D(texture, new Point(0, 0), 0f, new Point(x, y), Color.White);
- }
- public Bitmap BMP
- {
- get
- {
- return this.image;
- }
- set
- {
- this.image = value;
- this.texture = Texture.FromBitmap(DxDevice, image, Usage.SoftwareProcessing, Pool.Default);
- }
- }
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- Map_Paint(null,null);
- }
- #endregion
- private void Map_MouseMove(object sender, MouseEventArgs e)
- {
- pos = new Point(e.X, e.Y);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement