forked from Luffyyy/DieselEngineFormats
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrings.cs
More file actions
115 lines (98 loc) · 3 KB
/
Strings.cs
File metadata and controls
115 lines (98 loc) · 3 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using DieselEngineFormats.Bundle;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DieselEngineFormats
{
public class StringEntry
{
public uint StringPosition { get; set; }
public Idstring ID { get; set; }
public string Text { get; set; }
public StringEntry(BinaryReader br)
{
br.ReadUInt64();
ulong HashedID = br.ReadUInt64();
br.ReadUInt32();
this.StringPosition = br.ReadUInt32();
this.ID = HashIndex.Get(HashedID);
}
}
public class StringsFile
{
public List<StringEntry> LocalizationStrings = new List<StringEntry>();
public List<StringEntry> ModifiedStrings = new List<StringEntry>();
public StringsFile(string filepath)
{
using (FileStream str = new FileStream(filepath, FileMode.Open, FileAccess.Read))
{
using (BinaryReader br = new BinaryReader(str))
{
try
{
this.Load(br);
}
catch (Exception exc)
{
Console.WriteLine(exc.Message);
}
}
}
}
public StringsFile(Stream str)
{
using (BinaryReader br = new BinaryReader(str))
{
try
{
this.Load(br);
}
catch (Exception exc)
{
Console.WriteLine(exc.Message);
}
}
}
public StringsFile(BinaryReader br)
{
try
{
this.Load(br);
}
catch (Exception exc)
{
Console.WriteLine(exc.Message);
}
}
public void Load(BinaryReader br)
{
br.BaseStream.Position = 0;
br.ReadUInt32(); //Empty 4 bytes
uint stringCount = br.ReadUInt32();
br.ReadUInt32(); // String Count
br.ReadUInt32(); //Unknown
br.ReadUInt32(); //Unknown
br.ReadUInt32(); //Unknown
br.ReadUInt32(); //Unknown
br.ReadUInt32(); //Unknown
for (uint i = 0; i < stringCount; i++)
{
StringEntry strEntry = new StringEntry(br);
//if (strEntry.ID.HasUnHashed)
this.LocalizationStrings.Add(strEntry);
}
for (int i = 0; i < this.LocalizationStrings.Count; i++ )
{
StringEntry strEntry = this.LocalizationStrings[i];
br.BaseStream.Position = strEntry.StringPosition;
strEntry.Text = "";
char ch;
while ((int)(ch = br.ReadChar()) != 0)
strEntry.Text += ch;
}
}
}
}