-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCreateMapData.ps1
92 lines (77 loc) · 1.9 KB
/
CreateMapData.ps1
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
$lines = [System.IO.File]::ReadAllLines( $args[0] );
$numStages = $lines.Length / 2;
$stageNames = @();
$stageDatas = @();
for ( $s = 0; $s -lt $numStages; ++$s )
{
$stageName = $lines[$s * 2].Trim();
$stageData = $lines[$s * 2 + 1].Trim();
$stageNames += "MAP_" + $s.ToString();
$data = "";
$stageData = $stageData.Substring( 6, $stageData.Length - 6 - 1 );
if ( $stageData.length -ne 480 )
{
throw ( "Stage " + $stageName + ", Nr. " + $s.ToString() + " is malformed" )
}
$prevByte = -1;
$equCount = 0;
for ( $b = 0; $b -lt 240; ++$b )
{
$byteHex = "0x" + $stageData.Substring( $b * 2, 2 )
$byte = [int]$byteHex;
if ( $byte -ne $prevByte )
{
if ( $prevByte -ge 0 )
{
if ( $equCount -gt 1 )
{
# rle
$data += ( $equCount + 0x80 ).ToString( "X2" );
$data += $prevByte.ToString( "X2" );
}
else
{
$data += $prevByte.ToString( "X2" );
}
}
$prevByte = $byte;
$equCount = 1;
}
else
{
++$equCount;
}
}
if ( $equCount -gt 1 )
{
$data += ( $equCount + 0x80 ).ToString( "X2" );
$data += $prevByte.ToString( "X2" );
}
else
{
$data += $prevByte.ToString( "X2" );
}
$stageDatas += $data;
#echo ( $stageName )
#echo ( " !hex """ + $data + """" )
}
$maxStages = $stageNames.Count;
echo ( "MAX_STAGE_COUNT = " + $maxStages )
echo "`n"
echo ( "MAPS_LO" )
for ( $s = 0; $s -lt $stageNames.Length; ++$s )
{
echo( " !byte <" + $stageNames[$s] );
}
echo "`n"
echo ( "MAPS_HI" )
for ( $s = 0; $s -lt $stageNames.Length; ++$s )
{
echo( " !byte >" + $stageNames[$s] );
}
echo "`n"
for ( $s = 0; $s -lt $stageNames.Count; ++$s )
{
echo ( $stageNames[$s] )
echo ( " !hex """ + $stageDatas[$s] + """" )
}