This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathL2WorldMapBlock.cs
156 lines (131 loc) · 4.27 KB
/
L2WorldMapBlock.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Text;
namespace LEdit
{
public class L2WorldMapBlock
{
#region STATIC
public const long Offset = 0xF3000;
public const int Count = 0x4C8;
static L2WorldMapBlock[] WMB = new L2WorldMapBlock[Count];
public static L2WorldMapBlock Get(int n)
{
if (n >= 0 && n < Count)
return WMB[n];
else
return null;
}
public static void InitROM(BinaryReader br)
{
br.BaseStream.Seek(Offset, SeekOrigin.Begin);
for (int i = 0; i < Count; i++)
WMB[i] = new L2WorldMapBlock(br);
}
#endregion
public enum PassabilityType
{
Plain, Desert, Forest, Water, Mountain
};
Bitmap bmp;
bool drawn;
byte[,] tiles = new byte[2, 2];
PassabilityType pass;
public PassabilityType Passability { get { return pass; } set { pass = value; } }
~L2WorldMapBlock()
{
if (bmp != null) bmp.Dispose();
}
public L2WorldMapBlock(BinaryReader br)
{
drawn = false; FromStream(br);
}
public void FromStream(BinaryReader br)
{
if (br != null)
{
for (int x = 0; x < 2; x++)
{
for (int y = 0; y < 2; y++)
tiles[x, y] = br.ReadByte();
}
byte p = br.ReadByte();
switch (p)
{
case 0x00:
pass = PassabilityType.Plain;
break;
case 0x10:
pass = PassabilityType.Desert;
break;
case 0x20:
pass = PassabilityType.Forest;
break;
case 0x30:
pass = PassabilityType.Water;
break;
case 0x40:
pass = PassabilityType.Mountain;
break;
default:
Console.WriteLine("Unknown PassabilityType 0x" + p.ToString("X2") + " at 0x" + (br.BaseStream.Position - 1).ToString("X6"));
break;
}
}
}
public void PreDraw(SNESTileset8 set, SNESPalette[] pals)
{
if (!drawn)
{
bmp = new Bitmap(16, 16, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bmp);
for (int y = 0; y < 2; y++)
{
for (int x = 0; x < 2; x++)
{
set.tiles8[tiles[x, y]].Draw(
g,
pals,
x << 3,
y << 3,
1,
false,
false,
false);
}
drawn = true;
}
}
}
public void Draw(Graphics dst, SNESTileset8 set, SNESPalette[] pals, int dx, int dy)
{ Draw(dst, set, pals, dx, dy, 1); }
public void Draw(Graphics dst, SNESTileset8 set, SNESPalette[] pals, int dx, int dy, int zoom)
{
if (zoom < 1) zoom = 1;
PreDraw(set,pals);
if (zoom == 1 && drawn)
dst.DrawImage(bmp, dx, dy);
else
{
for (int y = 0; y < 2; y++)
{
for (int x = 0; x < 2; x++)
{
set.tiles8[tiles[x, y]].Draw(
dst,
pals,
dx + x * (zoom << 3),
dy + y * (zoom << 3),
zoom,
false,
false, //tiles[x, y].flip_x,
false); //tiles[x, y].flip_y);
}
}
}
}
}
}