forked from az64/mm-rando
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Obj.cs
53 lines (47 loc) · 1.81 KB
/
Obj.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
using System;
namespace MMRando
{
public partial class ROMFuncs
{
public static int GetObjSize(int obj)
{
int f = AddrToFile((uint)ObjTable);
CheckCompressed(f);
int basea = ObjTable - MMFileList[f].Addr;
return (int)(Arr_ReadU32(MMFileList[f].Data, basea + (obj * 8) + 4) - Arr_ReadU32(MMFileList[f].Data, basea + (obj * 8)));
}
public static void InsertObj(byte[] obj, int replace)
{
int f = AddrToFile((uint)ObjTable);
CheckCompressed(f);
int basea = ObjTable - MMFileList[f].Addr;
uint replaceaddr = Arr_ReadU32(MMFileList[f].Data, basea + (replace * 8));
int objf = MMFileList.FindIndex(u => u.Addr == replaceaddr);
if (objf == -1)
{
return;
};
if (obj.Length > (MMFileList[objf].End - MMFileList[objf].Addr))
{
MMFile newfile = new MMFile();
newfile.Addr = MMFileList[MMFileList.Count - 1].End;
newfile.End = newfile.Addr + obj.Length;
newfile.IsCompressed = true;
newfile.WasEdited = true;
newfile.Data = obj;
MMFileList[objf].Cmp_Addr = -1;
MMFileList[objf].Cmp_End = -1;
MMFileList[objf].Data = null;
MMFileList[objf].IsCompressed = false;
MMFileList.Add(newfile);
Arr_WriteU32(MMFileList[f].Data, basea + (replace * 8), (uint)newfile.Addr);
Arr_WriteU32(MMFileList[f].Data, basea + (replace * 8) + 4, (uint)newfile.End);
}
else
{
MMFileList[objf].Data = obj;
MMFileList[objf].WasEdited = true;
};
}
}
}