forked from az64/mm-rando
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessage.cs
More file actions
93 lines (84 loc) · 2.84 KB
/
Copy pathMessage.cs
File metadata and controls
93 lines (84 loc) · 2.84 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
namespace MMRando
{
public partial class ROMFuncs
{
//todo - allow rebuilding text file
private static void WriteMsg(int addr, byte[] msg)
{
int f = AddrToFile((uint)TxTFile);
CheckCompressed(f);
Arr_Insert(msg, 0, msg.Length, MMFileList[f].Data, addr);
}
private static MMMsg FindMsg(int n)
{
int f = AddrToFile((uint)TxtTable);
CheckCompressed(f);
int basea = TxtTable - MMFileList[f].Addr;
MMMsg m = new MMMsg();
while (true)
{
int x = (MMFileList[f].Data[basea] << 8) + MMFileList[f].Data[basea + 1];
if (n == x)
{
m.Addr = (int)(Arr_ReadU32(MMFileList[f].Data, basea + 4) & 0xFFFFFF);
m.Size = (int)(Arr_ReadU32(MMFileList[f].Data, basea + 12) & 0xFFFFFF) - m.Addr;
break;
};
if (x > n)
{
return null;
};
basea += 8;
};
return m;
}
public static bool IsBadMsg(string msg)
{
return msg.Contains("a segment of health") || msg.Contains("currency") ||
msg.Contains("money") || msg.Contains("cash") ||
msg.Contains("wealth") || msg.Contains("riches and stuff") ||
msg.Contains("increased life");
}
public static void WriteGossipMsg(List<string> msg, Random RNG)
{
byte[] msgheader = new byte[] { 2, 0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
for (int i = GossipStart; i < GossipEnd; i++)
{
if (GossipExclude.Contains(i))
{
continue;
};
MMMsg m = FindMsg(i);
if (m == null)
{
continue;
};
int j;
int l = m.Size + 1;
do
{
j = RNG.Next(msg.Count);
if (IsBadMsg(msg[j]))
{
if (RNG.Next(8) != 0)
{
continue;
};
};
l = msg[j].Length + msgheader.Length;
} while (l > m.Size);
byte[] data = new byte[l];
Arr_Insert(msgheader, 0, msgheader.Length, data, 0);
for (int k = 0; k < msg[j].Length; k++)
{
data[k + msgheader.Length] = (byte)msg[j][k];
};
WriteMsg(m.Addr, data);
msg.RemoveAt(j);
};
}
}
}