Skip to content

Commit fcaacb6

Browse files
committed
bug fix: Fixes bug where all files would corrupt
1 parent 117b2e5 commit fcaacb6

File tree

4 files changed

+25
-28
lines changed

4 files changed

+25
-28
lines changed

JPKDecoder.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ namespace MHFQuestEditor
88
{
99
class JPKDecoder
1010
{
11-
public static int m_shiftIndex = 0;
12-
public static byte m_flag = 0;
11+
public int m_shiftIndex = 0;
12+
public byte m_flag = 0;
1313

14-
public static byte[] UnpackSimple(byte[] data)
14+
public byte[] UnpackSimple(byte[] data)
1515
{
1616
MemoryStream msInput = new MemoryStream(data);
1717
BinaryReader brInput = new BinaryReader(msInput);
@@ -36,15 +36,15 @@ public static byte[] UnpackSimple(byte[] data)
3636
return data;
3737
}
3838

39-
public static void jpkcpy_lz(byte[] outBuffer, int offset, int length, ref int index)
39+
public void jpkcpy_lz(byte[] outBuffer, int offset, int length, ref int index)
4040
{
4141
for (int i = 0; i < length; i++, index++)
4242
{
4343
outBuffer[index] = outBuffer[index - offset - 1];
4444
}
4545
}
4646

47-
public static byte jpkbit_lz(Stream s)
47+
public byte jpkbit_lz(Stream s)
4848
{
4949
m_shiftIndex--;
5050
if (m_shiftIndex < 0)
@@ -56,7 +56,7 @@ public static byte jpkbit_lz(Stream s)
5656
return (byte)((m_flag >> m_shiftIndex) & 1);
5757
}
5858

59-
public static void ProcessOnDecode(Stream inStream, byte[] outBuffer)//implements jpkdec_lz
59+
public void ProcessOnDecode(Stream inStream, byte[] outBuffer)//implements jpkdec_lz
6060
{
6161
int outIndex = 0;
6262
while (inStream.Position < inStream.Length && outIndex < outBuffer.Length)
@@ -120,7 +120,7 @@ public static void ProcessOnDecode(Stream inStream, byte[] outBuffer)//implement
120120
}
121121
}
122122

123-
public static byte ReadByte(Stream s)
123+
public byte ReadByte(Stream s)
124124
{
125125
int value = s.ReadByte();
126126
if (value < 0)

JPKEncoder.cs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,18 @@ namespace MHFQuestEditor
88
{
99
class JPKEncoder
1010
{
11-
public static byte m_flag;
12-
public static int m_shiftIndex;
13-
public static int m_ind;
14-
public static byte[] m_inp;
15-
public static int m_level = 280;
16-
public static int m_maxdist = 0x300;//0x1fff;
17-
public static Stream m_outstream;
18-
public static byte[] m_towrite = new byte[1000];
19-
public static int m_itowrite;
11+
public byte m_flag;
12+
public int m_shiftIndex;
13+
public int m_ind;
14+
public byte[] m_inp;
15+
public int m_level = 280;
16+
public int m_maxdist = 0x300;//0x1fff;
17+
public Stream m_outstream;
18+
public byte[] m_towrite = new byte[1000];
19+
public int m_itowrite;
2020

21-
public static void JPKEncode(byte[] data, UInt16 atype, string otPath, int level)
21+
public void JPKEncode(byte[] data, UInt16 atype, string otPath, int level)
2222
{
23-
Directory.CreateDirectory("output");
24-
2523
UInt16 type = atype;
2624
byte[] buffer = data;
2725
int insize = buffer.Length;
@@ -44,7 +42,7 @@ public static void JPKEncode(byte[] data, UInt16 atype, string otPath, int level
4442
fsot.Close();
4543
}
4644

47-
public static unsafe int FindRep(int ind, out uint ofs)
45+
public unsafe int FindRep(int ind, out uint ofs)
4846
{
4947
int nlen = Math.Min(m_level, m_inp.Length - ind);
5048
ofs = 0;
@@ -78,7 +76,7 @@ public static unsafe int FindRep(int ind, out uint ofs)
7876
return len;
7977
}
8078
}
81-
public static void flushflag(bool final)
79+
public void flushflag(bool final)
8280
{
8381
if (!final || m_itowrite > 0)
8482
WriteByte(m_outstream, m_flag);
@@ -87,7 +85,7 @@ public static void flushflag(bool final)
8785
WriteByte(m_outstream, m_towrite[i]);
8886
m_itowrite = 0;
8987
}
90-
public static void SetFlag(byte b)
88+
public void SetFlag(byte b)
9189
{
9290
m_shiftIndex--;
9391
if (m_shiftIndex < 0)
@@ -97,14 +95,14 @@ public static void SetFlag(byte b)
9795
}
9896
m_flag |= (byte)(b << m_shiftIndex);
9997
}
100-
public static void SetFlagsL(byte b, int cnt)
98+
public void SetFlagsL(byte b, int cnt)
10199
{
102100
for (int i = cnt - 1; i >= 0; i--)
103101
{
104102
SetFlag((byte)((b >> i) & 1));
105103
}
106104
}
107-
public static void ProcessOnEncode(byte[] inBuffer, Stream outStream, int level = 1000)
105+
public void ProcessOnEncode(byte[] inBuffer, Stream outStream, int level = 1000)
108106
{
109107
long perc, perc0 = 0;
110108
long percbord = 0;
@@ -172,7 +170,7 @@ public static void ProcessOnEncode(byte[] inBuffer, Stream outStream, int level
172170
}
173171
flushflag(true);
174172
}
175-
public static void WriteByte(Stream s, byte b)
173+
public void WriteByte(Stream s, byte b)
176174
{
177175
s.WriteByte(b);
178176
}

Quest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void Load (string questId, string meta)
3030
byte[] data = new byte[file.Length];
3131
file.Read(data, 0, data.Length);
3232

33-
data = JPKDecoder.UnpackSimple(data);
33+
data = new JPKDecoder().UnpackSimple(data);
3434
MemoryStream decryptedData = new MemoryStream(data);
3535

3636
int mainPropsPointer = decryptedData.ReadByte();

QuestEditor.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ void RewriteFile()
185185

186186
writer.Close();
187187

188-
JPKEncoder.JPKEncode(data, 3, f.fileName, 10);
189-
188+
new JPKEncoder().JPKEncode(data, 3, f.fileName, 100);
190189
});
191190
}
192191

0 commit comments

Comments
 (0)