-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quest.cs
123 lines (100 loc) · 4.81 KB
/
Quest.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
121
122
123
using MHFQuestEditor.JPK;
using MHFQuestEditor.Utils;
namespace MHFQuestEditor
{
public class Quest
{
public string fileName = "";
public string safeName = "";
public string title = "";
public string mainObjective = "";
public string subObjective1 = "";
public string subObjective2 = "";
public string clearConditions = "";
public string failureConditions = "";
public string questContractor = "";
public string questDescription = "";
public string extraText = "";
private MemoryStream? decryptedData;
public byte[] questCode = new byte[0];
public Quest (string questId, string meta)
{
this.safeName = string.Format("{0}{1}", questId.Substring(questId.Length-5), meta);
Stream questData = LoadFileAndInitializeData(questId, meta);
DecryptData(questData);
LocatePointersAndReadBody();
ReadQuestStrings();
questData.Close();
}
Stream LoadFileAndInitializeData (string questId, string meta)
{
Stream file = File.Open(string.Format("{0}{1}.bin", questId, meta), FileMode.Open);
fileName = string.Format("{0}{1}.bin", questId, meta);
return file;
}
void DecryptData (Stream file)
{
byte[] data = new byte[file.Length];
file.Read(data, 0, data.Length);
data = new JPKDecoder().UnpackSimple(data);
decryptedData = new MemoryStream(data);
}
void LocatePointersAndReadBody ()
{
if (decryptedData == null) return;
int mainPropsPointer = decryptedData.ReadByte();
decryptedData.Seek(mainPropsPointer, SeekOrigin.Begin);
decryptedData.Seek(40, SeekOrigin.Current);
byte[] stringPointer = new byte[4];
decryptedData.Read(stringPointer, 0, 4);
// Seek to zero and read all the way to the string pointer - this will be copied one to one.
decryptedData.Seek(0, SeekOrigin.Begin);
questCode = new byte[BitConverter.ToInt32(stringPointer)];
decryptedData.Read(questCode, 0, BitConverter.ToInt32(stringPointer));
}
void ReadQuestStrings ()
{
if (decryptedData == null) return;
byte[] titlePointer = new byte[4];
decryptedData.Read(titlePointer, 0, 4);
byte[] mainObjectivePointer = new byte[4];
decryptedData.Read(mainObjectivePointer, 0, 4);
byte[] subObjectiveAPointer = new byte[4];
decryptedData.Read(subObjectiveAPointer, 0, 4);
byte[] subObjectiveBPointer = new byte[4];
decryptedData.Read(subObjectiveBPointer, 0, 4);
byte[] clearConditionsPointer = new byte[4];
decryptedData.Read(clearConditionsPointer, 0, 4);
byte[] failConditionsPointer = new byte[4];
decryptedData.Read(failConditionsPointer, 0, 4);
byte[] questContractorPointer = new byte[4];
decryptedData.Read(questContractorPointer, 0, 4);
byte[] questDescriptionPointer = new byte[4];
decryptedData.Read(questDescriptionPointer, 0, 4);
// Quest title
decryptedData.Seek(BitConverter.ToInt32(titlePointer), SeekOrigin.Begin);
title = Utility.ReadNullTerminated(decryptedData);
// Quest main
decryptedData.Seek(BitConverter.ToInt32(mainObjectivePointer), SeekOrigin.Begin);
mainObjective = Utility.ReadNullTerminated(decryptedData);
// Quest subobjective 1
decryptedData.Seek(BitConverter.ToInt32(subObjectiveAPointer), SeekOrigin.Begin);
subObjective1 = Utility.ReadNullTerminated(decryptedData);
// Quest subobjective 2
decryptedData.Seek(BitConverter.ToInt32(subObjectiveBPointer), SeekOrigin.Begin);
subObjective2 = Utility.ReadNullTerminated(decryptedData);
// Quest clear conditions
decryptedData.Seek(BitConverter.ToInt32(clearConditionsPointer), SeekOrigin.Begin);
clearConditions = Utility.ReadNullTerminated(decryptedData);
// Quest failure conditions
decryptedData.Seek(BitConverter.ToInt32(failConditionsPointer), SeekOrigin.Begin);
failureConditions = Utility.ReadNullTerminated(decryptedData);
// Quest contractor
decryptedData.Seek(BitConverter.ToInt32(questContractorPointer), SeekOrigin.Begin);
questContractor = Utility.ReadNullTerminated(decryptedData);
// Quest description
decryptedData.Seek(BitConverter.ToInt32(questDescriptionPointer), SeekOrigin.Begin);
questDescription = Utility.ReadNullTerminated(decryptedData);
}
}
}