Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using MapleLib.WzLib;
  10. using MapleLib.WzLib.WzProperties;
  11. using Microsoft.DirectX.Direct3D;
  12. using WzExplorer.Mapping;
  13. using Microsoft.DirectX.DirectInput;
  14.  
  15. namespace WzExplorer
  16. {
  17.     public partial class Mapper : Form
  18.     {
  19.         public WzFile wz;
  20.         WzMapleVersion ver;
  21.         IDirectObject render;
  22.         public Microsoft.DirectX.Direct3D.Device DxDevice;
  23.         public Microsoft.DirectX.DirectInput.Device Mouse;
  24.         public Microsoft.DirectX.DirectInput.Device Keyboard;
  25.         public static Sprite sprite = null;
  26.         D2DObject Main;
  27.         List<MapLink> mapLink = new List<MapLink>();
  28.         List<MapList> mapList = new List<MapList>();
  29.         public static Mapper obj;
  30.         public Point pos;
  31.         public bool change = false;
  32.  
  33.         public Mapper(WzMapleVersion version)
  34.         {
  35.             InitializeComponent();
  36.             ver = version;
  37.             SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque | ControlStyles.ResizeRedraw, true);
  38.             InitDX();
  39.             obj = this;
  40.             #if DEBUG
  41.             miniMaps.Visible = true;
  42.             test.Visible = true;
  43.             #endif
  44.         }
  45.  
  46.         private void InitDX()
  47.         {
  48.             PresentParameters presentParams = new PresentParameters();
  49.             presentParams.Windowed = true;
  50.             presentParams.SwapEffect = SwapEffect.Discard; // After the current screen is drawn, it will be automatically deleted from memory
  51.             DxDevice = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, Map, CreateFlags.SoftwareVertexProcessing, presentParams); // Put everything into the device
  52.             sprite = new Sprite(DxDevice);
  53.             Mouse = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Mouse);
  54.             Mouse.SetCooperativeLevel(this, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
  55.             Mouse.Acquire();
  56.             Keyboard = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard);
  57.             Keyboard.SetCooperativeLevel(this, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
  58.             Keyboard.Acquire();
  59.             timer1.Start();
  60.         }
  61.  
  62.         private void openToolStripMenuItem_Click(object sender, EventArgs e)
  63.         {
  64.             OpenFileDialog ofd = new OpenFileDialog();
  65.             ofd.Filter = "MapleStory Map file (Map.wz)|Map.wz";
  66.             if (ofd.ShowDialog() == DialogResult.OK)
  67.             {
  68.                 wz = new WzFile(ofd.FileName, ver);
  69.                 wz.ParseWzFile();
  70.                 miniMaps.Items.Clear();
  71.                
  72.                 foreach (WzImage img in ((WzDirectory)wz.GetObjectFromPath(wz.Name + "/WorldMap")).WzImages)
  73.                 {
  74.                     miniMaps.Items.Add(img.Name.Replace(".img", ""));
  75.                 }
  76.                 miniMaps.SelectedItem = "WorldMap";
  77.             }
  78.         }
  79.  
  80.         public void miniMaps_SelectedIndexChanged(object sender, EventArgs e)
  81.         {
  82.             change = false;
  83.             mapLink.Clear();
  84.             mapList.Clear();
  85.             WzImage img = ((WzImage)wz.GetObjectFromPath(wz.Name + "/WorldMap/" + miniMaps.SelectedItem.ToString() + ".img"));
  86.             WzCanvasProperty can = ((WzCanvasProperty)img.GetFromPath("BaseImg/0"));
  87.             Main = new D2DObject(DxDevice, can.PngProperty.PNG);
  88.             WzVectorProperty baseorigin = ((WzVectorProperty)can["origin"]);
  89.             if (img.GetFromPath("MapLink") != null)
  90.             {
  91.                 foreach (WzSubProperty sub in img.GetFromPath("MapLink").WzProperties)
  92.                 {
  93.                     string toolTip = ((WzStringProperty)sub["toolTip"]).Value;
  94.                     string LinkMap = ((WzStringProperty)sub.GetFromPath("link/linkMap")).Value;
  95.                     WzCanvasProperty canvas = ((WzCanvasProperty)sub.GetFromPath("link/linkImg"));
  96.                     Bitmap image = canvas.PngProperty.PNG;
  97.                     WzVectorProperty origin = ((WzVectorProperty)canvas["origin"]);
  98.                     MapLink mLink = new MapLink(DxDevice, Mouse, toolTip, LinkMap, image, baseorigin, origin);
  99.                     mapLink.Add(mLink);
  100.                 }
  101.             }
  102.             if (img.GetFromPath("MapList") != null)
  103.             {
  104.                 foreach (WzSubProperty sub in img.GetFromPath("MapList").WzProperties)
  105.                 {
  106.                     int type = ((WzCompressedIntProperty)sub["type"]).Value;
  107.                     WzVectorProperty spot = ((WzVectorProperty)sub["spot"]);
  108.                     MapList mlist = new MapList(DxDevice, Mouse, type, spot, baseorigin);
  109.                     mapList.Add(mlist);
  110.                 }
  111.             }
  112.         }
  113.         #region dx
  114.         private void Map_Paint(object sender, PaintEventArgs e)
  115.         {
  116.             if (DxDevice == null)
  117.                 return;
  118.             DxDevice.Clear(ClearFlags.Target, Color.Black, 0f, 0); // Clear the window to white
  119.             DxDevice.BeginScene();
  120.             sprite.Begin(SpriteFlags.AlphaBlend);
  121.             if (Main != null)
  122.                 Main.StaticDraw();
  123.             foreach (MapLink ml in mapLink)
  124.             {
  125.                 ml.Update();
  126.                 if (ml.canDraw == true)
  127.                 {
  128.                     ml.StaticDraw();
  129.                 }
  130.             }
  131.             if (change)
  132.             {
  133.                 miniMaps.SelectedItem = test.Text;
  134.             }
  135.             foreach (MapList mlst in mapList)
  136.             {
  137.                 mlst.Update();
  138.                 mlst.StaticDraw();
  139.             }
  140.             sprite.End();
  141.             DxDevice.EndScene();
  142.             DxDevice.Present();
  143.             Invalidate();
  144.             KeyPresses();
  145.         }
  146.  
  147.         public void KeyPresses()
  148.         {
  149.             KeyboardState keys = Keyboard.GetCurrentKeyboardState();
  150.             if (keys[Key.Escape])
  151.             {
  152.                 miniMaps.SelectedItem = "WorldMap";
  153.             }
  154.         }
  155.  
  156.         public interface IDirectObject
  157.         {
  158.             void Draw();
  159.             void StaticDraw();
  160.         }
  161.  
  162.         public class D2DObject : IDirectObject
  163.         {
  164.             internal Texture texture;
  165.             internal Microsoft.DirectX.Direct3D.Device DxDevice;
  166.             internal Bitmap image;
  167.             public int x = 0, y = 0;
  168.             public D2DObject(Microsoft.DirectX.Direct3D.Device DxDevice, Bitmap image)
  169.             {
  170.                 this.DxDevice = DxDevice;
  171.                 this.image = image;
  172.                 this.texture = Texture.FromBitmap(DxDevice, image, Usage.Dynamic, Pool.Default);
  173.             }
  174.  
  175.             public D2DObject(Microsoft.DirectX.Direct3D.Device DxDevice, Bitmap image, int x, int y)
  176.             {
  177.                 this.DxDevice = DxDevice;
  178.                 this.image = image;
  179.                 this.texture = Texture.FromBitmap(DxDevice, image, Usage.Dynamic, Pool.Default);
  180.                 //sprite = new Sprite(DxDevice);
  181.                 this.x = x;
  182.                 this.y = y;
  183.             }
  184.  
  185.             public void StaticDraw()
  186.             {
  187.                 sprite.Draw2D(texture, new Point(0, 0), 0f, new Point(0, 0), Color.White);
  188.             }
  189.  
  190.             public void Draw()
  191.             {
  192.                 sprite.Draw2D(texture, new Point(0, 0), 0f, new Point(x, y), Color.White);
  193.             }
  194.  
  195.             public Bitmap BMP
  196.             {
  197.                 get
  198.                 {
  199.                     return this.image;
  200.                 }
  201.                 set
  202.                 {
  203.                     this.image = value;
  204.                     this.texture = Texture.FromBitmap(DxDevice, image, Usage.SoftwareProcessing, Pool.Default);
  205.                 }
  206.             }
  207.         }
  208.  
  209.         private void timer1_Tick(object sender, EventArgs e)
  210.         {
  211.             Map_Paint(null,null);
  212.         }
  213. #endregion
  214.  
  215.         private void Map_MouseMove(object sender, MouseEventArgs e)
  216.         {
  217.             pos = new Point(e.X, e.Y);
  218.         }
  219.     }
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement