forked from az64/mm-rando
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResource.cs
108 lines (101 loc) · 3.83 KB
/
Resource.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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
namespace MMRando
{
public partial class ROMFuncs
{
public static void ApplyHack_File(string name, byte[] data)
{
BinaryReader hack_file = new BinaryReader(File.Open(name, FileMode.Open));
int hack_len = (int)hack_file.BaseStream.Length;
byte[] hack_content = new byte[hack_len];
hack_file.Read(hack_content, 0, hack_len);
hack_file.Close();
int addr = 0;
while (hack_content[addr] != 0xFF)
{
//Debug.WriteLine(addr.ToString("X4"));
uint dest = Arr_ReadU32(hack_content, addr);
addr += 4;
uint len = Arr_ReadU32(hack_content, addr);
addr += 4;
Arr_Insert(hack_content, addr, (int)len, data, (int)dest);
addr += (int)len;
};
}
public static void ApplyHack(string name)
{
BinaryReader hack_file = new BinaryReader(File.Open(name, FileMode.Open));
int hack_len = (int)hack_file.BaseStream.Length;
byte[] hack_content = new byte[hack_len];
hack_file.Read(hack_content, 0, hack_len);
hack_file.Close();
if (name.EndsWith("title-screen"))
{
Random R = new Random();
int rot = R.Next(360);
Color l;
float h;
for (int i = 0; i < 144 * 64; i++)
{
int p = (i * 4) + 8;
l = Color.FromArgb(hack_content[p + 3], hack_content[p], hack_content[p + 1], hack_content[p + 2]);
h = l.GetHue();
h += rot;
h %= 360f;
l = FromAHSB(l.A, h, l.GetSaturation(), l.GetBrightness());
hack_content[p] = l.R;
hack_content[p + 1] = l.G;
hack_content[p + 2] = l.B;
hack_content[p + 3] = l.A;
};
l = Color.FromArgb(hack_content[0x1FE72], hack_content[0x1FE73], hack_content[0x1FE76]);
h = l.GetHue();
h += rot;
h %= 360f;
l = FromAHSB(255, h, l.GetSaturation(), l.GetBrightness());
hack_content[0x1FE72] = l.R;
hack_content[0x1FE73] = l.G;
hack_content[0x1FE76] = l.B;
};
int addr = 0;
while (hack_content[addr] != 0xFF)
{
//Debug.WriteLine(addr.ToString("X4"));
uint dest = Arr_ReadU32(hack_content, addr);
addr += 4;
uint len = Arr_ReadU32(hack_content, addr);
addr += 4;
int f = AddrToFile(dest);
dest -= (uint)MMFileList[f].Addr;
CheckCompressed(f);
Arr_Insert(hack_content, addr, (int)len, MMFileList[f].Data, (int)dest);
addr += (int)len;
};
}
public static List<int[]> GetAddresses(string name)
{
List<int[]> Addrs = new List<int[]>();
BinaryReader AddrFile = new BinaryReader(File.Open(name, FileMode.Open));
byte[] a = new byte[AddrFile.BaseStream.Length];
AddrFile.Read(a, 0, a.Length);
AddrFile.Close();
int i = 0;
while (a[i] != 0xFF)
{
int count = (int)Arr_ReadU32(a, i);
int[] alist = new int[count];
i += 4;
for (int j = 0; j < count; j++)
{
alist[j] = (int)Arr_ReadU32(a, i);
i += 4;
};
Addrs.Add(alist);
};
return Addrs;
}
}
}