This repository has been archived by the owner on Dec 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathStoryManager.cs
120 lines (103 loc) · 4.46 KB
/
StoryManager.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
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace Elroy
{
internal static class StoryManager
{
internal static List<long> SkipOffset = new List<long>
{
//Yu-Gi-Oh!
0x16F8, /* DLC */
0x1740, /* DLC */
0x18A8, /* Blank? */
0x18C0, /* Blank? */
0x18D8, /* Blank? */
0x18F0, /* Blank? */
0x1908, /* Blank? */
/*Yu-Gi-Oh! GX*/
0x1C40, /* DLC */
0x1C70, /* DLC */
/*Yu-Gi-Oh! 5D's*/
//I Didn't See Any For This Game, If You Notice Any Please Let Me Know In Discord or Github Issues.
/*Yu-Gi-Oh! ZEXAL*/
0x24C0, /* DLC */
0x2658 /* DLC */
};
internal static List<StoryLookup> StoryLengths = new List<StoryLookup>
{
/*Yu-Gi-Oh!*/
new StoryLookup(0x1650, 0x1920, 23),
/*Yu-Gi-Oh! GX*/
new StoryLookup(0x1B08, 0x1DC0, 26),
/*Yu-Gi-Oh! 5D's*/
new StoryLookup(0x1FC0, 0x2260, 27),
/*Yu-Gi-Oh! ZEXAL*/
new StoryLookup(0x2478, 0x26D0, 22)
};
internal static void UpdateCampaignFromSave(ref TabPage Page, string SaveName)
{
using (var CampaignReader = new BinaryReader(File.Open(SaveName, FileMode.Open, FileAccess.Read)))
{
var CurrentStory = 0;
foreach (var GroupBox in Page.Controls.OfType<GroupBox>().Reverse())
foreach (var CheckBoxList in GroupBox.Controls.OfType<CheckedListBox>())
{
CampaignReader.BaseStream.Position = StoryLengths[CurrentStory].Start;
var CurrentLevel = 0;
do
{
if (CurrentLevel > StoryLengths[CurrentStory].Missions) break;
if (SkipOffset.Any(Offset => CampaignReader.BaseStream.Position == Offset))
{
CampaignReader.BaseStream.Position += 0x18;
continue;
}
CheckBoxList.SetItemChecked(CurrentLevel, ValidateStory(CampaignReader.ReadBytes(0x18)));
CurrentLevel++;
} while (CampaignReader.BaseStream.Position <= StoryLengths[CurrentStory].End);
CurrentStory++;
}
}
}
internal static void WriteCampaignToSave(ref TabPage Page, string SaveName)
{
using (var CampaignWriter = new BinaryWriter(File.Open(SaveName, FileMode.Open, FileAccess.Write)))
{
var CurrentStory = 0;
foreach (var GroupBox in Page.Controls.OfType<GroupBox>().Reverse())
foreach (var CheckBoxList in GroupBox.Controls.OfType<CheckedListBox>())
{
CampaignWriter.BaseStream.Position = StoryLengths[CurrentStory].Start;
var CurrentLevel = 0;
do
{
if (CurrentLevel > StoryLengths[CurrentStory].Missions) break;
if (SkipOffset.Any(Offset => CampaignWriter.BaseStream.Position == Offset))
{
CampaignWriter.BaseStream.Position += 0x18;
continue;
}
if (CheckBoxList.GetItemChecked(CurrentLevel))
{
CampaignWriter.Write(new byte[] {0x3, 0x0, 0x0, 0x0, 0x3});
CampaignWriter.Write(new byte[19]);
}
else
{
CampaignWriter.Write(new byte[24]);
}
CurrentLevel++;
} while (CampaignWriter.BaseStream.Position <= StoryLengths[CurrentStory].End);
CurrentStory++;
}
}
}
internal static bool ValidateStory(byte[] DataChunk)
{
return DataChunk[0] == 0x01 || DataChunk[0] == 0x02 ||
DataChunk[0] == 0x03; //0x01 - Not Yet Played, 0x02 - Draw, 0x03 - Win, 0x00 - Default / Locked.
}
}
}